Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2765645imu; Thu, 29 Nov 2018 09:52:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/XJppMYT776WoLBqL3mB9EwMIz0sUHBvFQts1tYEwzfP+LR9weEo3WqtfmsxLQctCpOOLxI X-Received: by 2002:a63:db48:: with SMTP id x8mr1949681pgi.365.1543513946633; Thu, 29 Nov 2018 09:52:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543513946; cv=none; d=google.com; s=arc-20160816; b=LUU0cfKPBu8caNMurAY/OxpibCYJghw5tc/UYkvgd4y7BH+XLFtRAadE8pch734Ezm L69mBabTYD8StLDsdoS0VSVwqxsyjQPE8qj3u1yMpc0TgrSSiO+NRCVKSFhJoszIQi8Z eq73J/+smNhfcPJXqm5CdNcsOiVU9G0YrYaprYFl1LoFALfs9xCMfgn4sjKJoJmsSxj5 P/1e4rt7eXAGdh+XPROdGuQEL3TmgQ2kMq42//ZQzKNqpVzqWjg7IDH5vTccMWOT0PyL GZ/RYnurblVVi8s19gxNwqRwiHKC3o4D4HXaV4A1pUlIFNReFAS0bgV/ecelR7BLyoWF cBRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Ypw3E2cISa9isgMf/o7XITSEw9/wZqS4XM12LoMTkow=; b=zTM6YG4Oupb448qG+bcjNuN/BkESeHOCMZOXBNAgmPKxOArghDTYVQvOLViMc665xt RP7vPYAQhV5q2gNLdlZembcHIMv49GFxnfGYt5St6mVYtFyNoBPVX6TFrLzfxaz20vDN kQ44cGF0lYioi82BsXCwj4YkEvM700oa27qHOwLi1hR1V6Wn/7noPJTIqyPzQU2HGgnz nTqsuCzvOTpiciIJ9SGqjwKxhtCgbsSolQDvKVcfykfLdXCLrvgrVg2T79EXRHPVmBim DJhhFIR8LLOoQvg9IBkdfZ/2vsUQMvHghW5zXlP6kjIz/dcFYMRaZfCrvw+f7dNeJuYU mecw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQ6AMKNV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h33si2841720plh.228.2018.11.29.09.52.11; Thu, 29 Nov 2018 09:52:26 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=kQ6AMKNV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730860AbeK3Ezp (ORCPT + 99 others); Thu, 29 Nov 2018 23:55:45 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:37928 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730817AbeK3Exa (ORCPT ); Thu, 29 Nov 2018 23:53:30 -0500 Received: by mail-lf1-f66.google.com with SMTP id p86so2106954lfg.5 for ; Thu, 29 Nov 2018 09:47:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ypw3E2cISa9isgMf/o7XITSEw9/wZqS4XM12LoMTkow=; b=kQ6AMKNVLBIpJnHJzhxVxBdeq6p4dRybfKd57cLFV+11FP5f2nQ2zAotum0p+il6Iz Iu7IU385nMt69p6FNuUzimW1rcCMaGJIqXsH8MraCfMA4Cd+Bk9a2R6nL72vE6dH/Cfp jQdnCajc65WnxPqJTNJ8OVFtAPOEQ2cqKOa5k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ypw3E2cISa9isgMf/o7XITSEw9/wZqS4XM12LoMTkow=; b=JO48f2xhwVhrschXA6r3yJsyu/ZnXdM+rK8/okff3ZA2Hr9OPaEyqW7EelhhYPRSG1 ZIipOct3Z7vIr/SCN3Gb2LpAQqC3m6IPHPmdDxGwTHXovzp8Xu4Xo8MSr+Kez3+yqfi+ hbimZFQqoQfBhxVR4Lc7rf8zSw17KueNCtPMf338+pUtga13B88p9Naza1BKW+BhguJX 9BHLYn9u+sCNHnxLuBsFoRXidpOi51paiHw5LrxtgJiSY7C8tI1dSP+V9S/jMHjI+lLc q9tXvdqVlYpSnZ0srRFBjBramOgFLAX9/F6ATqmGoVq0Zwp6E5xbAjwmzp7petvRLbm5 ivFw== X-Gm-Message-State: AA+aEWa2zIT1slHwQVJ9NE6RdjcUQvEB7QzC+rRVJc8qrRFuFkVRw3Qi 5S0paS3oX7Y8+6JYQNG7gCAq8w== X-Received: by 2002:a19:6a13:: with SMTP id u19mr1590988lfu.46.1543513639324; Thu, 29 Nov 2018 09:47:19 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id j76-v6sm393983ljb.12.2018.11.29.09.47.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 09:47:18 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , linux-pm@vger.kernel.org Cc: "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v10 06/27] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Date: Thu, 29 Nov 2018 18:46:39 +0100 Message-Id: <20181129174700.16585-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181129174700.16585-1-ulf.hansson@linaro.org> References: <20181129174700.16585-1-ulf.hansson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The CPU's idle state nodes are currently parsed at the common cpuidle DT library, but also when initializing back-end data for the arch specific CPU operations, as in the PSCI driver case. To avoid open-coding, let's introduce of_get_cpu_state_node(), which takes the device node for the CPU and the index to the requested idle state node, as in-parameters. In case a corresponding idle state node is found, it returns the node with the refcount incremented for it, else it returns NULL. Moreover, for ARM, there are two generic methods, to describe the CPU's idle states, either via the flattened description through the "cpu-idle-states" binding [1] or via the hierarchical layout, using the "power-domains" and the "domain-idle-states" bindings [2]. Hence, let's take both options into account. [1] Documentation/devicetree/bindings/arm/idle-states.txt [2] Documentation/devicetree/bindings/arm/psci.txt Cc: Rob Herring Cc: devicetree@vger.kernel.org Cc: Lina Iyer Suggested-by: Sudeep Holla Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson Reviewed-by: Rob Herring --- Changes in v10: - None. --- drivers/of/base.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/of.h | 8 ++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 09692c9b32a7..8f6974a22006 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -429,6 +429,41 @@ int of_cpu_node_to_id(struct device_node *cpu_node) } EXPORT_SYMBOL(of_cpu_node_to_id); +/** + * of_get_cpu_state_node - Get CPU's idle state node at the given index + * + * @cpu_node: The device node for the CPU + * @index: The index in the list of the idle states + * + * Two generic methods can be used to describe a CPU's idle states, either via + * a flattened description through the "cpu-idle-states" binding or via the + * hierarchical layout, using the "power-domains" and the "domain-idle-states" + * bindings. This function check for both and returns the idle state node for + * the requested index. + * + * In case and idle state node is found at index, the refcount incremented for + * it, so call of_node_put() on it when done. Returns NULL if not found. + */ +struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + struct of_phandle_args args; + int err; + + err = of_parse_phandle_with_args(cpu_node, "power-domains", + "#power-domain-cells", 0, &args); + if (!err) { + struct device_node *state_node = + of_parse_phandle(args.np, "domain-idle-states", index); + + of_node_put(args.np); + return state_node; + } + + return of_parse_phandle(cpu_node, "cpu-idle-states", index); +} +EXPORT_SYMBOL(of_get_cpu_state_node); + /** * __of_device_is_compatible() - Check if the node matches given constraints * @device: pointer to node diff --git a/include/linux/of.h b/include/linux/of.h index a5aee3c438ad..f9f0c65c095c 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -348,6 +348,8 @@ extern const void *of_get_property(const struct device_node *node, 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); +extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index); #define for_each_property_of_node(dn, pp) \ for (pp = dn->properties; pp != NULL; pp = pp->next) @@ -762,6 +764,12 @@ static inline struct device_node *of_get_next_cpu_node(struct device_node *prev) return NULL; } +static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + return NULL; +} + static inline int of_n_addr_cells(struct device_node *np) { return 0; -- 2.17.1