From patchwork Fri Sep 13 12:49:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 20036 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5795228E9C for ; Fri, 13 Sep 2013 12:49:53 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id db12sf1202027veb.6 for ; Fri, 13 Sep 2013 05:49:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version: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=Lsfd36KW2Xoqxw/aqo/sjEIMlCb7ZOg8CRArhZUqdJUF8GtLg1PceLGz4Gip0h8fp/ mz8ssqFtyTHwJ4SD6AHPOh/6CK6qB0NYB9BVEDVumC3C0ixcuFJ6fQIGCIHWufN/0CVf 5xTMFu3qrSASVMKfu6iv15wuOqkQt7RV1d0g2Kfqqns/xk01CXJvlm+k12YUdj8KYb9N PNgPRx8bicgnjr1qe/rBXyOrPL/JtyfbrgLB6RqonIKQLndzNEpnv/SscZHfT3yN5nCC h4UdGY5eot5qvY0abQGcXzgilzJ2k8yYWJzFYILktGzauE/XZNper9hMfmd4D3sb7cFe nz9g== X-Gm-Message-State: ALoCoQnz3cu3bDgq+BzTqTMYoIBzUx+GvECjwj/o+9Gpptisxt3t0wb7cDC13+sZZ8J05fCWr2uS X-Received: by 10.236.4.69 with SMTP id 45mr4906194yhi.20.1379076593024; Fri, 13 Sep 2013 05:49:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.110.9 with SMTP id hw9ls1094886qeb.16.gmail; Fri, 13 Sep 2013 05:49:52 -0700 (PDT) X-Received: by 10.52.108.230 with SMTP id hn6mr1492714vdb.28.1379076592780; Fri, 13 Sep 2013 05:49:52 -0700 (PDT) Received: from mail-vb0-f51.google.com (mail-vb0-f51.google.com [209.85.212.51]) by mx.google.com with ESMTPS id 10si3089206vcs.30.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 05:49:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.51 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.51; Received: by mail-vb0-f51.google.com with SMTP id x16so852160vbf.38 for ; Fri, 13 Sep 2013 05:49:52 -0700 (PDT) X-Received: by 10.58.198.13 with SMTP id iy13mr11876742vec.11.1379076592673; Fri, 13 Sep 2013 05:49:52 -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 u4csp78776vcz; Fri, 13 Sep 2013 05:49:52 -0700 (PDT) X-Received: by 10.15.43.13 with SMTP id w13mr17923628eev.37.1379076591551; Fri, 13 Sep 2013 05:49:51 -0700 (PDT) Received: from mail-ee0-f48.google.com (mail-ee0-f48.google.com [74.125.83.48]) by mx.google.com with ESMTPS id 41si3777880eee.287.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 05:49:51 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.83.48 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.48; Received: by mail-ee0-f48.google.com with SMTP id l10so554347eei.21 for ; Fri, 13 Sep 2013 05:49:51 -0700 (PDT) X-Received: by 10.14.0.3 with SMTP id 3mr2459029eea.62.1379076590979; Fri, 13 Sep 2013 05:49:50 -0700 (PDT) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id p5sm14678420eeg.5.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 05:49:49 -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 v4 11/27] xen/arm: Use dt_device_match to avoid multiple if conditions Date: Fri, 13 Sep 2013 13:49:18 +0100 Message-Id: <1379076574-28316-12-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1379076574-28316-1-git-send-email-julien.grall@linaro.org> References: <1379076574-28316-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.212.51 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)