From: Ian Campbell Subject: Re: [PATCH 7/7] xen/arm: get the number of cpus from device tree Date: Thu, 25 Oct 2012 11:02:47 +0100 Message-ID: <1351159367.18035.149.camel@zakaz.uk.xensource.com> References: <1351091027-20740-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: <1351091027-20740-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 > diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c > index 3d1f0f4..3ae0f4d 100644 > --- a/xen/common/device_tree.c > +++ b/xen/common/device_tree.c > @@ -153,6 +153,26 @@ const char *device_tree_bootargs(const void *fdt) > return prop->data; > } > > +int device_tree_cpus(const void *fdt) > +{ > + int node, depth; > + int cpus = 0; > + > + node = fdt_path_offset(fdt, "/cpus"); > + if ( node < 0 ) > + return -1; With this we will stumble on with cpus == -1 (~4 billion, which would make a nice system ;-) ). Perhaps we should either assume UP (with a big printk) or BUG on failure here? > + do { > + node = fdt_next_node(fdt, node, &depth); > + if ( node < 0 ) > + break; > + if ( strncmp(fdt_get_name(fdt, node, NULL), "cpu", 3) ) > + break; If we find /cpus/foo (for any foo != "cpu*") then we stop counting, rather than just ignoring that node? > + cpus++; > + } while ( depth > 0 ); > + > + return cpus; > +} > + > static int dump_node(const void *fdt, int node, const char *name, int depth, > u32 address_cells, u32 size_cells, void *data) > { > diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h > index 4d010c0..46bc0f8 100644 > --- a/xen/include/xen/device_tree.h > +++ b/xen/include/xen/device_tree.h > @@ -49,6 +49,7 @@ bool_t device_tree_node_matches(const void *fdt, int node, const char *match); > int device_tree_for_each_node(const void *fdt, > device_tree_node_func func, void *data); > const char *device_tree_bootargs(const void *fdt); > +int device_tree_cpus(const void *fdt); > void device_tree_dump(const void *fdt); > > #endif