Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1032329imm; Wed, 20 Jun 2018 10:24:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI8I4kaYo6xa77HSzXDCeJLUDKBXXUvCvTofNfPVf2FcRBT4deMVQpQojrq1gzYq25g3P17 X-Received: by 2002:a17:902:8d91:: with SMTP id v17-v6mr11891053plo.9.1529515496358; Wed, 20 Jun 2018 10:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529515496; cv=none; d=google.com; s=arc-20160816; b=ejItNCQV2HV075YOLs5YkjmdC4M0l0n+8Br+SHj5xt9IVndsh392eLF/+fK3HXR2Bq 5FXmD89rmrK4J5gLuvfR1F5pAHAVYVpk6h1mQ7mnqBfGmkehahQ/zEAfkzrqAzVton2u FgmFg4Ixe4IHOqPo1gffnKFikFS1JkTfuWCyMZj7XP5kT1h7IHvPI5BgT811fFZNhKg5 ATXAvLLxyw+yfHqEbpH26NGfzseF1h2DTkxWCKEjiEIYQNrk8zPp6nVhe7bW5acBCNzF I+Usa8u7BIkkyNxtG897KCDleaqKEcwthhJU6qLRELuo/cF0YvvBxq7HJOlQX7IMSu22 OoNQ== 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:arc-authentication-results; bh=AMylSCkbzgDhVGAqXW5br7EGPsh0M0aMkU36t/fhU+E=; b=zKAE0heUHplH4YYEgkKzzYaldgMXwuLB9fqYDDmpTJr1d4uMe04MIjaN5HJPhxjImG Szw0PiUBPUBv+SaSENQwb/RAeqdZNYg+bvlTTwYkMRwtzMuq5BJ5vWiNeB+DoSLaoLbS j+8vOvHHX0rZL910BFHtcbQqR6orFmKaVNyKn9bh3Q6PNHU6ow9RJbL7uwolRSVtamUo FdjMRz67tRsrP+WtMHKF3qiSsk2B7T/iY1Uk0DXVhd3RrIBEZQQYVjhw9Z1x1UtzWf+L gMaDrRsIegKe2g8dcZGl/EOUhkX94m8zcBNbmam8SYsaejGk1c2p5vw/B/E7oJOxTYev GOHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SKGWxFzG; 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 o61-v6si2740666pld.109.2018.06.20.10.24.41; Wed, 20 Jun 2018 10:24:56 -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; dkim=pass header.i=@linaro.org header.s=google header.b=SKGWxFzG; 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 S932466AbeFTRXB (ORCPT + 99 others); Wed, 20 Jun 2018 13:23:01 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:34204 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932241AbeFTRW4 (ORCPT ); Wed, 20 Jun 2018 13:22:56 -0400 Received: by mail-lf0-f65.google.com with SMTP id e13-v6so503311lfc.1 for ; Wed, 20 Jun 2018 10:22:55 -0700 (PDT) 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=AMylSCkbzgDhVGAqXW5br7EGPsh0M0aMkU36t/fhU+E=; b=SKGWxFzGSktnyD6kaX9ouo+P/jXcqpXVh7WmiipKR4mu8eL4DLn1dlzEuJ1UVq8Isf nHglT92pBOG4HoKUm0EsljQ8CMQHU/y/4uqGOUybUW/3pWPBLcIG8lCYhELSWFIusRTq VjDEfxFljyJQu7hsl5Egey8JJ52Ttelgdra2Y= 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=AMylSCkbzgDhVGAqXW5br7EGPsh0M0aMkU36t/fhU+E=; b=MeMSMAcsfUy+C4S6nU+YdjfD9tcJpP+CByxZeWfTgT3VTqNd4GUx3NK29X7MAOwrL6 nZukvh1h62ceDuBX4P9deosoWSW9o35UGkPdv/0QmybR0dfzhlxvUVrFC00fySu7mfwd S+NXPbqYhzyN7AUxnfWpZiiCBUgiJOcrPCfLtcQgxXxBJrzaJXbKX9Rapdww6UQ+hUcH xWFc0H4Yw0c8EnoF7woSvOPkXGX+a8LfUVlLlH+XNrvl87iWKFuY2jBB4AtX9Qz6feDb zn+4rraFBGR7u99NuN0GfOeeKKzVSmL78Oa/hbrtE+BmHwVdJQlMOxOWZhpRjNYqtU7h okiQ== X-Gm-Message-State: APt69E23c85xof1p8dWEhEjktlRNZn7tmvrhbaoLpZ5syHlJ/oboTzv6 pDlG9Gg7JzTnMyq/32WLdWSTOw== X-Received: by 2002:a2e:870d:: with SMTP id m13-v6mr14276282lji.139.1529515374905; Wed, 20 Jun 2018 10:22:54 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b2-v6sm514441lji.85.2018.06.20.10.22.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:22:54 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , 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 v8 11/26] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Date: Wed, 20 Jun 2018 19:22:11 +0200 Message-Id: <20180620172226.15012-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180620172226.15012-1-ulf.hansson@linaro.org> References: <20180620172226.15012-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 --- 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 848f549164cd..97350cce1b8e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -399,6 +399,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 4d25e4f952d9..15072b10ef4d 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) @@ -733,6 +735,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; -- 2.17.1