From patchwork Wed Mar 14 16:58:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 131680 Delivered-To: patches@linaro.org Received: by 10.80.210.197 with SMTP id q5csp410512edg; Wed, 14 Mar 2018 09:59:23 -0700 (PDT) X-Received: by 10.46.42.67 with SMTP id q64mr3967156ljq.133.1521046763351; Wed, 14 Mar 2018 09:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521046763; cv=none; d=google.com; s=arc-20160816; b=SBqzXzBSzK5/onJ06v9a6SgPlKxaCx0QN6seSSACqdPKWF/7zD+oQBgOYUXsV2FcjL XuyZwNPoofibkPkgtyjLjh2YS4S0jkW858ZAiVuMTciD6DzsVQDWu9Dxy6VHX5i38U8p 8IZe6PnBMk0XGbL8gJEmXtPO2BHjbu3ejsnGHj2nAMZ+yxdw0pwPnekvrgV9YW9heCbR TUWN+vvqPHSMvWlZS95EJ8G7W2OQ5jugwBcj28Cs2lI9+XX1JtK3fU2AEQYqJdZbIi4e KAs+F4Q78tfdjh5KXsJg8lo0MuQ+OVQDJgdHiUGvlxzOa+dxdiP/A7renAogjUfo9V/p gbww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9Hut8uxV9o4+GGyqitzbiLTfPeq/ETjSQ3OWzL2xcrU=; b=Sbv10tqGyxgABC25hRd8jjGWQmydOMLOLz1ee4wVQZL4l2TEbktxheDYJyyFh0N2oO cBuKuoR1IKV8SJHk1VNcn+T1W63CE2EoNcM6MP9PETPkButo0QBbZ8PVzRBI4JSt7FwC sBM4Qr7tpMX8O0N9477xAkC7RT4gFiwGQNGNENXoY72+yn1tWsTI4C1GeHHspVMUwYZn nezF7vvMoqfgJ/6ltYVjQnUpA2tYtR65ANLsEjO73s8GpshMghmXECumkZDZpBZ70qQs Wq9OxtBdl21fz50trMIoFfA2u5HQO1SDewA5+1oxURVDZpY4bj8OK/LY/36O/msTPBP8 j/cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WElXkpgU; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y7-v6sor859551lfd.106.2018.03.14.09.59.23 for (Google Transport Security); Wed, 14 Mar 2018 09:59:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WElXkpgU; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=9Hut8uxV9o4+GGyqitzbiLTfPeq/ETjSQ3OWzL2xcrU=; b=WElXkpgUTZAj1q/q8hJkarTQaWXBTIn6m4bJPQvq9DZ0jV+LgukZJkC8ywZYn4JvJU 8OirnsnOr6P3fPBzjn7r2Ddj3xUmZ4dwSTw7k2CaHeGztQMA/fiRBl7bYacBueZOzCGS xaR99wLurWuYcnDSzS7qnhmjEzz1sZS/hcPAs= 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=9Hut8uxV9o4+GGyqitzbiLTfPeq/ETjSQ3OWzL2xcrU=; b=DREqGeTYpIDiwAfMQIAYCwu/AJAKtQ56DUArYwMgAn/5T8xlFcZWzMcoWmP8tfXWKC Qav2fDm2RHbkFMavpWriuzXBGB06u2y6EeVRnOJvrkWOfDDEm1CzRR++0aROvKJa6wa5 iEfMKYW+80hV4gZkJnsigkV4ajufls9WYAeBalYVDkJ2LgGg3STnj0DtDTd2j2eM54Zx WNdE1/3pBzyP1pb0CmACuI6zM0sCUq7PNYwPiuXmYECNYTnmscICIXxSvnWPSi+kETRU drNFDSdgtv5+qhi8IHoM8Wm/i/Ff5kzGNvBozfvhdKHz4JQqn8nsaspmOD6sPxXrJcq3 o2Sw== X-Gm-Message-State: AElRT7E6hfvNV8MkY1uAYN+NGERXXBKoHxEZcB7CM7rdQGh/6GIx2YR0 V1XT4nJAC4dfyMpS+dbzPlaiHNTq X-Google-Smtp-Source: AG47ELuyhOyJV0EL2V4Xan2c19SvKeNx8mqwbPpPCZuAvuXLzemjeIFlI3fpdg0W1IBJ0ucW26IQXg== X-Received: by 2002:a19:d744:: with SMTP id o65-v6mr4080626lfg.90.1521046762802; Wed, 14 Mar 2018 09:59:22 -0700 (PDT) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t24-v6sm724849lfi.30.2018.03.14.09.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 09:59:21 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Kevin Hilman , Lina Iyer , Lina Iyer , Ulf Hansson , Rob Herring , Daniel Lezcano , Thomas Gleixner , Vincent Guittot , Stephen Boyd , Juri Lelli , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v6 11/25] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Date: Wed, 14 Mar 2018 17:58:21 +0100 Message-Id: <1521046715-30683-12-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.org> References: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.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 --- drivers/of/base.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/of.h | 8 ++++++++ 2 files changed, 43 insertions(+) -- 2.7.4 diff --git a/drivers/of/base.c b/drivers/of/base.c index ad28de9..88d36a3 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -338,6 +338,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 * @compat: required compatible string, NULL or "" for any match diff --git a/include/linux/of.h b/include/linux/of.h index da1ee95..288233c 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, const char *name, int *lenp); extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); +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) @@ -730,6 +732,12 @@ static inline struct device_node *of_get_cpu_node(int cpu, 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;