Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp4779296imd; Tue, 30 Oct 2018 07:19:13 -0700 (PDT) X-Google-Smtp-Source: AJdET5eC7fPH5mKmKoGF/tLNb/FDJtbdftrMp+kgHvB57T7ZtB5l1RcBDasU3NQsqeGhLa8pe8a+ X-Received: by 2002:a17:902:6bc9:: with SMTP id m9-v6mr19225173plt.106.1540909153370; Tue, 30 Oct 2018 07:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540909153; cv=none; d=google.com; s=arc-20160816; b=DWEMqUVm/pLlDGBv56citVJ5i2+jJ0vqODGXrSMQJKY4QnCoXdr3BbwCOgl+6G+JEl lr1m0PHGzKwzdCabFNrX3paF3I+hRWBVpsm09shc6RdHth2/EX9QtAm9WXlTUl7d3m+C 1mltPvryp3BmLFsy84rVXlBSeKr1NdJ21zp8Z9j8KdVRP4VyrLdQSGl3mOl9/CCoxCVm k4z+A7Qm9XIR2vy5He+D4n8QcGp66T4x63qnsOChJv0AIoZQfUmXg8Yn9hJVmd4dd57f CWmGQLSXqFBODo/gJ7EVLtpEuLXBMSYEZjKaojanvEES9BpuykbHVsFCfx903x0a3CtH 1Ebw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=8HD4C9ZXFA+2GH085siNZndrNkis/RWXkmxhFnPERqc=; b=RudSq4K7CE6+jTi0OgC4aPb0QHzBizZj97PwXSQYsRtDfuoxsroFL152hgHnmpo81Q p+ylkJ3D0q5CCQ7ZGONet7EaQywfkwzbb0rk1FPuzxW7Sv42XJO9vA+eul5fIXpeWOtV On49AxzTTqGp3AKEcMxrsVpRRNZEegF8qMy7R14HcNVtg7yHL9QVnloizxJrkUWA7QpC BK3hVcfBbeuuCfgb0o7V4ZYuTwnMY7MqUonr68vqbWaekNDaZYkKFhP4QE2fT8aHula1 VfnU/Wb7psTyr5zpbWauglSQ9abEoCIhJ7urubBGYtAx7RVZ1rItrdj3YK6z2peMYfkz ZrXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o24-v6si22511854pgv.242.2018.10.30.07.18.57; Tue, 30 Oct 2018 07:19:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728253AbeJ3XLq (ORCPT + 99 others); Tue, 30 Oct 2018 19:11:46 -0400 Received: from ozlabs.org ([203.11.71.1]:58699 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728033AbeJ3XLq (ORCPT ); Tue, 30 Oct 2018 19:11:46 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42ktpz4z82z9s8r; Wed, 31 Oct 2018 01:18:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au From: Michael Ellerman To: Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Frank Rowand Subject: Re: [PATCH 01/21] of: Add cpu node iterator for_each_of_cpu_node() In-Reply-To: <20180905193738.19325-2-robh@kernel.org> References: <20180905193738.19325-1-robh@kernel.org> <20180905193738.19325-2-robh@kernel.org> Date: Wed, 31 Oct 2018 01:18:00 +1100 Message-ID: <874ld3jz6v.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Rob, Sorry I missed this when you posted it. Rob Herring writes: > Iterating thru cpu nodes is a common pattern. Create a common iterator > which can find child nodes either by node name or device_type == cpu. > Using the former will allow for eventually dropping device_type > properties which are deprecated for FDT. Device trees we see on powerpc generally don't (never?) use "cpu" as the node name for CPU nodes. And many of those device trees come from firmware, so we can't update them. So dropping support for device_type is a non-starter from our POV. cheers > Cc: Frank Rowand > Signed-off-by: Rob Herring > --- > drivers/of/base.c | 39 +++++++++++++++++++++++++++++++++++++++ > include/linux/of.h | 11 +++++++++++ > 2 files changed, 50 insertions(+) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index a055cd1ef96d..4807db0a35b3 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -741,6 +741,45 @@ struct device_node *of_get_next_available_child(const struct device_node *node, > } > EXPORT_SYMBOL(of_get_next_available_child); > > +/** > + * of_get_next_cpu_node - Iterate on cpu nodes > + * @prev: previous child of the /cpus node, or NULL to get first > + * > + * Returns a cpu node pointer with refcount incremented, use of_node_put() > + * on it when done. Returns NULL when prev is the last child. Decrements > + * the refcount of prev. > + */ > +struct device_node *of_get_next_cpu_node(struct device_node *prev) > +{ > + struct device_node *next = NULL; > + unsigned long flags; > + struct device_node *node; > + > + if (!prev) > + node = of_find_node_by_path("/cpus"); > + > + raw_spin_lock_irqsave(&devtree_lock, flags); > + if (prev) > + next = prev->sibling; > + else if (node) { > + next = node->child; > + of_node_put(node); > + } > + for (; next; next = next->sibling) { > + if (!(of_node_name_eq(next, "cpu") || > + (next->type && !of_node_cmp(next->type, "cpu")))) > + continue; > + if (!__of_device_is_available(next)) > + continue; > + if (of_node_get(next)) > + break; > + } > + of_node_put(prev); > + raw_spin_unlock_irqrestore(&devtree_lock, flags); > + return next; > +} > +EXPORT_SYMBOL(of_get_next_cpu_node); > + > /** > * of_get_compatible_child - Find compatible child node > * @parent: parent node > diff --git a/include/linux/of.h b/include/linux/of.h > index 99b0ebf49632..1aca0dbd35df 100644 > --- a/include/linux/of.h > +++ b/include/linux/of.h > @@ -353,6 +353,8 @@ extern const void *of_get_property(const struct device_node *node, > const char *name, > int *lenp); > extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); > +extern struct device_node *of_get_next_cpu_node(struct device_node *prev); > + > #define for_each_property_of_node(dn, pp) \ > for (pp = dn->properties; pp != NULL; pp = pp->next) > > @@ -754,6 +756,11 @@ static inline struct device_node *of_get_cpu_node(int cpu, > return NULL; > } > > +static inline struct device_node *of_get_next_cpu_node(struct device_node *prev) > +{ > + return NULL; > +} > + > static inline int of_n_addr_cells(struct device_node *np) > { > return 0; > @@ -1217,6 +1224,10 @@ static inline int of_property_read_s32(const struct device_node *np, > for (child = of_get_next_available_child(parent, NULL); child != NULL; \ > child = of_get_next_available_child(parent, child)) > > +#define for_each_of_cpu_node(cpu) \ > + for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \ > + cpu = of_get_next_cpu_node(cpu)) > + > #define for_each_node_with_property(dn, prop_name) \ > for (dn = of_find_node_with_property(NULL, prop_name); dn; \ > dn = of_find_node_with_property(dn, prop_name)) > -- > 2.17.1