From: Ian Campbell Subject: Re: [PATCH 7/7] xen/arm: get the number of cpus from device tree Date: Thu, 15 Nov 2012 15:34:43 +0000 Message-ID: <1352993683.3499.137.camel@zakaz.uk.xensource.com> References: <1352821336-25837-7-git-send-email-stefano.stabellini@eu.citrix.com> <1352974179.3499.83.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: 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 Thu, 2012-11-15 at 15:26 +0000, Stefano Stabellini wrote: > On Thu, 15 Nov 2012, Ian Campbell wrote: > > 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? > > Actually the hardware ID is expressed by the propery. > Maybe we should set the corresponding ID in cpu_present_map from > device_tree_cpus? I'm not sure what you mean. > > There are some helpers in device_tree.c to walk over trees like this, > > are none of them suitable? > > Do you mean device_tree_node_matches? > Yes, I can use that instead of strncmp. I'll do that. You should , but that's not what I was talkig about ;-) I was thinking of device_tree_for_each_node but I suppose that doesn't quite fit? But perhaps you can integrate with early_scan_node? Ian.