From patchwork Fri Oct 24 09:58:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 39413 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E767920341 for ; Fri, 24 Oct 2014 09:59:36 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf1636281lab.11 for ; Fri, 24 Oct 2014 02:59:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=LGt5jKPENwRLIiXvQzFUiseC3zBt7P885wpGT1nCMpM=; b=Y+hHDdwHWFNvm1R8kHV6ozdttyuICbevI8QlYQ2cQTDGT/Wbum3cAlDbueGX1MEUWo DRlDOwLqlccwGpKqsgnYDb/TURRBRkn1UnfloKi2Vs8D/NbpEKNfjfExoLaqR1cc1ayf oeWSyl8JVI4yjdjso09AJJBUR/OGG4ul8ptV9FXsncbKGGjxiymlRz0Gmfq5QQypkcAP 3GBIPQqTJDlRh3B+t7spdRamjOHOyYc5MnxLleetFnpOVzwFCwkoNJm5j35v8RgEMVvA PH6Xk7TJdtCmcz2ciF+A6qkb/28H0/aQoSFBntvDZ+WctdOxrrwe9mQ8lrYkeg6wPXds 3RFQ== X-Gm-Message-State: ALoCoQlSv5Y7SLf0iyGQ91vfND6Z5zuokVGunqkguzpiSmCJ1ett0ooXDfvJJwvKWegszukeiyjk X-Received: by 10.180.19.198 with SMTP id h6mr623085wie.5.1414144775453; Fri, 24 Oct 2014 02:59:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.230 with SMTP id m6ls459912laa.89.gmail; Fri, 24 Oct 2014 02:59:35 -0700 (PDT) X-Received: by 10.112.56.171 with SMTP id b11mr3224932lbq.65.1414144775262; Fri, 24 Oct 2014 02:59:35 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id pi7si6243607lbb.15.2014.10.24.02.59.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Oct 2014 02:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so951025lbj.13 for ; Fri, 24 Oct 2014 02:59:35 -0700 (PDT) X-Received: by 10.112.97.135 with SMTP id ea7mr3354805lbb.46.1414144774950; Fri, 24 Oct 2014 02:59:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp398309lbz; Fri, 24 Oct 2014 02:59:33 -0700 (PDT) X-Received: by 10.52.83.234 with SMTP id t10mr1919163vdy.11.1414144773264; Fri, 24 Oct 2014 02:59:33 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id qf2si2317346vdb.55.2014.10.24.02.59.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 24 Oct 2014 02:59:33 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xhbds-0001bx-14; Fri, 24 Oct 2014 09:58:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xhbdr-0001b9-9S for xen-devel@lists.xen.org; Fri, 24 Oct 2014 09:58:43 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id 7F/9D-02953-2D22A445; Fri, 24 Oct 2014 09:58:42 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1414144720!11355236!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.12.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20352 invoked from network); 24 Oct 2014 09:58:42 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 24 Oct 2014 09:58:42 -0000 X-IronPort-AV: E=Sophos;i="5.04,779,1406592000"; d="scan'208";a="185837469" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Fri, 24 Oct 2014 05:58:39 -0400 Received: from drall.uk.xensource.com ([10.80.16.71]) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1Xhbdm-0003vI-PD; Fri, 24 Oct 2014 10:58:39 +0100 Received: by drall.uk.xensource.com (sSMTP sendmail emulation); Fri, 24 Oct 2014 10:58:38 +0100 From: Ian Campbell To: Date: Fri, 24 Oct 2014 10:58:34 +0100 Message-ID: <1414144717-32328-2-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1414144694.15687.31.camel@citrix.com> References: <1414144694.15687.31.camel@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Campbell , stefano.stabellini@eu.citrix.com, julien.grall@linaro.org, tim@xen.org, Clark Laughlin , Pranavkumar Sawargaonkar Subject: [Xen-devel] [PATCH 2/5] xen: device-tree: add accessors for the addr/size-cells of a node's children. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: The existing dt_n_{addr,size}_cells functions tell you which sizes will apply to this node, which are the #address/size-cells properties of the node's *parent* (or grandparent, etc). In some cases we need to know what size applies to a nodes children, which can include the #address/size-cells properties of the node itself (or its parent). Refactor the existing function to allow both possibilities. Clean up the grammar of the existing doc comments a bit. Signed-off-by: Ian Campbell --- xen/common/device_tree.c | 35 ++++++++++++++++++++++++++---- xen/include/xen/device_tree.h | 47 ++++++++++++++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index f72b2e9..a4e4eb5 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -368,13 +368,17 @@ dt_find_matching_node(struct dt_device_node *from, return NULL; } -int dt_n_addr_cells(const struct dt_device_node *np) +/* If parent is true then start from the parent. */ +static int dt_n_addr_cells_common(const struct dt_device_node *np, bool parent) { const __be32 *ip; do { - if ( np->parent ) + if ( parent && np->parent ) np = np->parent; + else + parent = 1; + ip = dt_get_property(np, "#address-cells", NULL); if ( ip ) return be32_to_cpup(ip); @@ -383,13 +387,26 @@ int dt_n_addr_cells(const struct dt_device_node *np) return DT_ROOT_NODE_ADDR_CELLS_DEFAULT; } -int dt_n_size_cells(const struct dt_device_node *np) +int dt_n_addr_cells(const struct dt_device_node *np) +{ + return dt_n_addr_cells_common(np, true); +} + +int dt_n_addr_cells_children(const struct dt_device_node *np) +{ + return dt_n_addr_cells_common(np, false); +} + +/* If parent is true then start from the parent. */ +static int dt_n_size_cells_common(const struct dt_device_node *np, bool parent) { const __be32 *ip; do { - if ( np->parent ) + if ( parent && np->parent ) np = np->parent; + else + parent = 1; ip = dt_get_property(np, "#size-cells", NULL); if ( ip ) return be32_to_cpup(ip); @@ -398,6 +415,16 @@ int dt_n_size_cells(const struct dt_device_node *np) return DT_ROOT_NODE_SIZE_CELLS_DEFAULT; } +int dt_n_size_cells(const struct dt_device_node *np) +{ + return dt_n_size_cells_common(np, true); +} +int dt_n_size_cells_children(const struct dt_device_node *np) +{ + return dt_n_size_cells_common(np, false); +} + + /* * Default translator (generic bus) */ diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 08db8bc..ac2e876 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -513,24 +513,55 @@ int dt_device_get_raw_irq(const struct dt_device_node *device, int index, int dt_irq_translate(const struct dt_raw_irq *raw, struct dt_irq *out_irq); /** - * dt_n_size_cells - Helper to retrieve the number of cell for the size - * @np: node to get the value + * dt_n_size_cells - Helper to retrieve the number of cells used for + * size properties of a node (e.g. the size part of a reg property). + * + * @np: node to get the value for * - * This function retrieves for a give device-tree node the number of - * cell for the size field. + * This function retrieves for a given device-tree node the number of + * cells used for size properties, which is the #size-cells property of + * the node's parent (or grandparent etc). */ int dt_n_size_cells(const struct dt_device_node *np); /** - * dt_n_addr_cells - Helper to retrieve the number of cell for the address - * @np: node to get the value + * dt_n_size_cells_children - Helper to retrieve the number of cells + * used for size properties of child nodes. + * + * @np: node to get the value for + * + * This function retrieves the #size-cells field which will apply to + * this node's children, which may be specified by this node or its + * parent, grantparent etc. + */ +int dt_n_size_cells_children(const struct dt_device_node *node); + +/** + * dt_n_addr_cells - Helper to retrieve the number of cells for + * address properties of a node (e.g. the adddress part of a reg + * property). + * + * @np: node to get the value for * - * This function retrieves for a give device-tree node the number of - * cell for the address field. + * This function retrieves for a given device-tree node the number of + * cells used for address properties, which is the #address-cells + * property of the node's parent (or grantparent, etc). */ int dt_n_addr_cells(const struct dt_device_node *np); /** + * dt_n_size_cells_children - Helper to retrieve the number of cells + * used for size properties of child nodes. + * + * @np: node to get the value for + * + * This function retrieves the #address-cells field which will apply to + * this node's children, which may be specified by this node or its + * parent, grantparent etc. + */ +int dt_n_addr_cells_children(const struct dt_device_node *np); + +/** * dt_device_is_available - Check if a device is available for use * * @device: Node to check for availability