From patchwork Tue Sep 10 14:48:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 19913 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f71.google.com (mail-vb0-f71.google.com [209.85.212.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 90144246A4 for ; Tue, 10 Sep 2013 14:49:38 +0000 (UTC) Received: by mail-vb0-f71.google.com with SMTP id g17sf8872946vbg.10 for ; Tue, 10 Sep 2013 07:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=dnLeEL57QqEKSQhy29txIZT/B1DzRzFRZxcFPc4lMNM=; b=hohhHIH+fkSDKln7X34hI8xqtAs6bScOjpxLS041+zdxamjGm8tSVvZDASWMLZIB5g KuGrLyM9ecmdIKpkzBQWV7ohO7x3VQr+3i8wWFafgb4P/vYfE2wWsw9ea29oIiv8pJ/o JwEXYwLC46heytHe727Ja/iXPIejAW1SI2Yzfn1I+iEDMjbMYYUS+4l6B6t5XrKqxYTk BTmNKgb4xrBWh4P5gPEdNSVZnhxInBZJbjkEGe+/u59utGpR1Rn5hNN4P/QNJLniWGiT IwZJ05gEvQK+lUVJhQE51o4uPj1vK2EXRWRti39TeskNRdTw46SgFr1IkMWZnmbEzFd6 1FLg== X-Received: by 10.236.18.196 with SMTP id l44mr736086yhl.52.1378824578259; Tue, 10 Sep 2013 07:49:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.87.36 with SMTP id u4ls2224875qez.56.gmail; Tue, 10 Sep 2013 07:49:38 -0700 (PDT) X-Received: by 10.58.97.238 with SMTP id ed14mr313557veb.34.1378824578035; Tue, 10 Sep 2013 07:49:38 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id zw10si4521571vdb.57.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 07:49:38 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ia10so5093872vcb.34 for ; Tue, 10 Sep 2013 07:49:38 -0700 (PDT) X-Gm-Message-State: ALoCoQksgY4bFAOxyNCZs6jz38rSUM2uvhtAadIhJ2s9hjodDDc+6YDfhhXaf9SUOPp3JZaMEcv8 X-Received: by 10.52.119.139 with SMTP id ku11mr253207vdb.42.1378824577958; Tue, 10 Sep 2013 07:49:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp4660vcz; Tue, 10 Sep 2013 07:49:37 -0700 (PDT) X-Received: by 10.15.98.9 with SMTP id bi9mr3513997eeb.67.1378824576650; Tue, 10 Sep 2013 07:49:36 -0700 (PDT) Received: from mail-ea0-f182.google.com (mail-ea0-f182.google.com [209.85.215.182]) by mx.google.com with ESMTPS id q8si15314264eem.150.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 07:49:36 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.182 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.215.182; Received: by mail-ea0-f182.google.com with SMTP id o10so3906050eaj.41 for ; Tue, 10 Sep 2013 07:49:36 -0700 (PDT) X-Received: by 10.14.207.4 with SMTP id m4mr2823160eeo.78.1378824575993; Tue, 10 Sep 2013 07:49:35 -0700 (PDT) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id i1sm31911644eeg.0.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 07:49:35 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, andre.przywara@linaro.org, Julien Grall Subject: [PATCH v3 11/27] xen/arm: Use dt_device_match to avoid multiple if conditions Date: Tue, 10 Sep 2013 15:48:59 +0100 Message-Id: <1378824555-16564-12-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1378824555-16564-1-git-send-email-julien.grall@linaro.org> References: <1378824555-16564-1-git-send-email-julien.grall@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , There is some place in Xen ARM code where multiple if conditions is used check the presence of a node or find a node. These pieces of code can be replace by an array and using proper device tree helpers. Signed-off-by: Julien Grall --- Changes in v3: - Create a macro DT_MATCH_TIMER. Will be use later - Remove spurious line in the patch Changes in v2: - Move skip_match and timer_ids within the appropriate functions --- xen/arch/arm/domain_build.c | 11 ++++++++--- xen/arch/arm/time.c | 9 ++++++--- xen/include/asm-arm/time.h | 4 ++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index bde041e..8ebe1bc 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -437,15 +437,20 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) static int handle_node(struct domain *d, const struct dt_device_node *np) { + static const struct dt_device_match skip_matches[] __initconst = + { + DT_MATCH_COMPATIBLE("xen,xen"), + DT_MATCH_TYPE("memory"), + DT_MATCH_PATH("/chosen"), + { /* sentinel */ }, + }; const struct dt_device_node *child; int res; DPRINT("handle %s\n", dt_node_full_name(np)); /* Skip theses nodes and the sub-nodes */ - if ( dt_device_is_compatible(np, "xen,xen") || - dt_device_type_is_equal(np, "memory") || - !strcmp("/chosen", dt_node_full_name(np)) ) + if ( dt_match_node(skip_matches, np ) ) return 0; if ( dt_device_used_by(np) != DOMID_XEN ) diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index 9c176cd..eb3ad5c 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -101,14 +101,17 @@ static uint32_t calibrate_timer(void) /* Set up the timer on the boot CPU */ int __init init_xen_time(void) { + static const struct dt_device_match timer_ids[] __initconst = + { + DT_MATCH_TIMER, + { /* sentinel */ }, + }; struct dt_device_node *dev; int res; unsigned int i; u32 rate; - dev = dt_find_compatible_node(NULL, NULL, "arm,armv7-timer"); - if ( !dev ) - dev = dt_find_compatible_node(NULL, NULL, "arm,armv8-timer"); + dev = dt_find_matching_node(NULL, timer_ids); if ( !dev ) panic("Unable to find a compatible timer in the device tree\n"); diff --git a/xen/include/asm-arm/time.h b/xen/include/asm-arm/time.h index f7aa868..9d302d3 100644 --- a/xen/include/asm-arm/time.h +++ b/xen/include/asm-arm/time.h @@ -1,6 +1,10 @@ #ifndef __ARM_TIME_H__ #define __ARM_TIME_H__ +#define DT_MATCH_TIMER \ + DT_MATCH_COMPATIBLE("arm,armv7-timer"), \ + DT_MATCH_COMPATIBLE("arm,armv8-timer") + typedef unsigned long cycles_t; static inline cycles_t get_cycles (void)