From: Ian Campbell Subject: Re: [PATCH 7/7] xen/arm: get the number of cpus from device tree Date: Thu, 15 Nov 2012 10:09:39 +0000 Message-ID: <1352974179.3499.83.camel@zakaz.uk.xensource.com> References: <1352821336-25837-7-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1352821336-25837-7-git-send-email-stefano.stabellini@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: "xen-devel@lists.xensource.com" , "Tim (Xen.org)" List-Id: xen-devel@lists.xenproject.org On Tue, 2012-11-13 at 15:42 +0000, Stefano Stabellini wrote: > diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c > index 3d1f0f4..5b6dab9 100644 > --- a/xen/common/device_tree.c > +++ b/xen/common/device_tree.c > @@ -153,6 +153,25 @@ const char *device_tree_bootargs(const void *fdt) > return prop->data; > } > > +int device_tree_cpus(const void *fdt) > +{ > + int node = 0, depth = 1; > + int cpus = 0; > + > + node = fdt_path_offset(fdt, "/cpus/cpu"); > + if ( node < 0 ) > + return 1; /* we have at least one cpu */ > + > + while ( node >= 0 && depth >= 0 ) { > + if ( strncmp(fdt_get_name(fdt, node, NULL), "cpu", 3) ) > + continue; > + node = fdt_next_node(fdt, node, &depth); > + cpus++; Do we not need to track the largest for each cpu@ which we see, in order to handle systems with e.g. CPUs 0, 1, 4 & 5? There are some helpers in device_tree.c to walk over trees like this, are none of them suitable?