Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1033151imm; Wed, 20 Jun 2018 10:25:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJk+kXzFmvzUCw1i5xmKfX64AgShPFibKMyHmte+GzTEoFiwLmglze4UBRuf1h9fu8t+ftQ X-Received: by 2002:a65:5284:: with SMTP id y4-v6mr19188845pgp.297.1529515548430; Wed, 20 Jun 2018 10:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529515548; cv=none; d=google.com; s=arc-20160816; b=L/YIGaFmdLhWhM5gk1U0i1qjjvuIlkuCnq0ZI9N+7m0CKh3LSPIBrVIUG4mfJU2fuU uYJgOlACP9WfKjDA3B50FPEkYXJLN6Bvol57gfozhAFlsSPQhrGJaX4dERA+Q6QbD19w nnP49tmP6Ca56OE7eICRVvZzKfGIIj7ZL1JOyxmN1NKmAWGT+ybnjobjA1iM5expHsEi bVbnIdgvkggz73RoyD1aGc6x/Dqbo6TznxrqI27nGHs4uN+TF/URda0fAwYd1PZIJLjW mGcH8JcVNoMoLsaymuiegUVo6lsQ6IzTFniPGx/D4DllRue0f4Pj+2pTL+4z0b0haFW3 39cw== 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=dpRzWZ1lRV3PUFVF54+RtopoI+Qxx4PQOSnHva5FuG0=; b=pHG9ZM8xnuYJ+WgjopfRGOliisjSZ6mruj4oDoxTchjiR2espNg7uScXyOxmox+A4C DNpWS9NGxpniHGYyVUD/xmQWGcb+C286zljUe1zFacs4xdwP3ho9Yp/l6zd/3gr8eSFq /gT/l5tieIdoNUxiRxXN1zb63uXkN7VU97SmcppDE5N0Q9UOWZRSGg327lI28Xue/RD+ uHjD2cCdOPpq4dWbgXPGG1SMZmBL8T9EsdDzOBbugLwIoFJCnef0bwoPYTVwk0nY67JI ndPlw6YHEKcXfavHWzLr5QDpOgfHUTETAa4pSrQqsAHtjh9Nm08DfuFKd3TmxXEObO9d a2IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Eg0M4K1y; 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 q4-v6si2764829plb.251.2018.06.20.10.25.34; Wed, 20 Jun 2018 10:25:48 -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=Eg0M4K1y; 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 S932872AbeFTRXT (ORCPT + 99 others); Wed, 20 Jun 2018 13:23:19 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:40178 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932743AbeFTRXP (ORCPT ); Wed, 20 Jun 2018 13:23:15 -0400 Received: by mail-lf0-f68.google.com with SMTP id q11-v6so469815lfc.7 for ; Wed, 20 Jun 2018 10:23:14 -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=dpRzWZ1lRV3PUFVF54+RtopoI+Qxx4PQOSnHva5FuG0=; b=Eg0M4K1y1jPCN7GIdZAXDgAVpLPggcUYsLLm8zmicBLw9lxb5F2rFzBE/Il1E3g8NP 2plsB85rwB3kEaChU/AkeAoo4cKWGeyImYGUir3Nl/kOY9eC7esYJbCMcVJnQS+qccXh 0HOpUo0XXP0iPIig7ion/ai28kav03/03ZtiY= 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=dpRzWZ1lRV3PUFVF54+RtopoI+Qxx4PQOSnHva5FuG0=; b=EnDp9fp131umorLTdhhE163PBBZMw6YnZphzkFNz2mXnUHh3q+7JCBBSHVJ74w2VPG vY2uk4NfiFPJP0BsTczo2xzLn/7a2LZ1FgJRRHp5nAzCLyaj558gObeI+NibkDIb+bBC UrzaEJSvTgLxBXFZ8nP86QJAQ98EPzyvjFpHhmC7UkD+XufWgjU4JwEI80obq4+abE6H oKz8xK9xzgw1c+qQtnWiIVvejFi7FtngDGRMSmVcONGFOroKSgn6ZCTI7c3Zem2191nI VXSB2zSmdS8/U0i1RJj45c9G4WT2FWuyX9R/46mh5ID1lCFJPBZJ8gH3D/yK9g+xhrdL BOQA== X-Gm-Message-State: APt69E1E2i3107/Go0G865EPdl/cErNw8WhbH/+DkQbSsLr8wvxIgtfU Kjar7wPIyLeUakI9p2c1yWKJiw== X-Received: by 2002:a2e:428e:: with SMTP id h14-v6mr15515102ljf.136.1529515393686; Wed, 20 Jun 2018 10:23:13 -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.23.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:23:13 -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 Subject: [PATCH v8 21/26] drivers: firmware: psci: Add support for PM domains using genpd Date: Wed, 20 Jun 2018 19:22:21 +0200 Message-Id: <20180620172226.15012-22-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 When the hierarchical layout is used in DT, as to describe the PM topology for the CPUs, which are managed by PSCI, we want to be able to initialize and setup the corresponding PM domain data structures. Let's make this possible via adding a new file, psci_pm_domains.c and implement the needed interface towards the generic PM domain (aka genpd). Share a helper function, psci_dt_init_pm_domains(), which the regular PSCI firmware driver may call when it needs to initialize the PM topology using genpd. In principle, the implementation consists of allocating/initializing the genpd data structures, parsing the domain-idle states DT bindings via calling of_genpd_parse_idle_states() and to call pm_genpd_init() for the allocated genpds. Finally, one genpd OF provider is added per genpd. Via DT, this enables devices, including CPU devices, to be attached to the created genpds. Cc: Lina Iyer Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/firmware/psci/Makefile | 2 +- drivers/firmware/psci/psci.h | 6 + drivers/firmware/psci/psci_pm_domain.c | 180 +++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/psci/psci_pm_domain.c diff --git a/drivers/firmware/psci/Makefile b/drivers/firmware/psci/Makefile index 1956b882470f..ff300f1fec86 100644 --- a/drivers/firmware/psci/Makefile +++ b/drivers/firmware/psci/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 # -obj-$(CONFIG_ARM_PSCI_FW) += psci.o +obj-$(CONFIG_ARM_PSCI_FW) += psci.o psci_pm_domain.o obj-$(CONFIG_ARM_PSCI_CHECKER) += psci_checker.o diff --git a/drivers/firmware/psci/psci.h b/drivers/firmware/psci/psci.h index dc7b596daa2b..a22684b24902 100644 --- a/drivers/firmware/psci/psci.h +++ b/drivers/firmware/psci/psci.h @@ -10,4 +10,10 @@ void psci_set_domain_state(u32 state); int psci_dt_parse_state_node(struct device_node *np, u32 *state); +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF +int psci_dt_init_pm_domains(struct device_node *np); +#else +static inline int psci_dt_init_pm_domains(struct device_node *np) { return 0; } +#endif + #endif /* __PSCI_H */ diff --git a/drivers/firmware/psci/psci_pm_domain.c b/drivers/firmware/psci/psci_pm_domain.c new file mode 100644 index 000000000000..f54819e7e487 --- /dev/null +++ b/drivers/firmware/psci/psci_pm_domain.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PM domains for CPUs via genpd - managed by PSCI. + * + * Copyright (C) 2018 Linaro Ltd. + * Author: Ulf Hansson + * + */ + +#define pr_fmt(fmt) "psci: " fmt + +#include +#include +#include +#include +#include + +#include "psci.h" + +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF +static int psci_pd_power_off(struct generic_pm_domain *pd) +{ + struct genpd_power_state *state = &pd->states[pd->state_idx]; + u32 *pd_state; + u32 composite_pd_state; + + if (!state->data) + return 0; + + pd_state = state->data; + composite_pd_state = *pd_state | psci_get_domain_state(); + psci_set_domain_state(composite_pd_state); + + return 0; +} + +static int psci_dt_parse_pd_states(struct genpd_power_state *states, + int state_count) +{ + int i, err; + u32 *psci_states; + + if (!state_count) + return 0; + + psci_states = kcalloc(state_count, sizeof(psci_states), GFP_KERNEL); + if (!psci_states) + return -ENOMEM; + + for (i = 0; i < state_count; i++) { + err = psci_dt_parse_state_node(to_of_node(states[i].fwnode), + &psci_states[i]); + if (err) { + kfree(psci_states); + return err; + } + } + + for (i = 0; i < state_count; i++) + states[i].data = &psci_states[i]; + + return 0; +} + +static int psci_dt_init_genpd(struct device_node *np, + struct genpd_power_state *states, + unsigned int state_count) +{ + struct generic_pm_domain *pd; + struct dev_power_governor *pd_gov; + int ret = -ENOMEM; + + pd = kzalloc(sizeof(*pd), GFP_KERNEL); + if (!pd) + return -ENOMEM; + + pd->name = kasprintf(GFP_KERNEL, "%pOF", np); + if (!pd->name) + goto free_pd; + + pd->name = kbasename(pd->name); + pd->power_off = psci_pd_power_off; + pd->states = states; + pd->state_count = state_count; + pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; + + /* Use governor for CPU PM domains if it has some states to manage. */ + pd_gov = state_count > 0 ? &pm_domain_cpu_gov : NULL; + + ret = pm_genpd_init(pd, pd_gov, false); + if (ret) + goto free_name; + + ret = of_genpd_add_provider_simple(np, pd); + if (ret) + goto remove_pd; + + pr_info("init PM domain %s\n", pd->name); + return 0; + +remove_pd: + pm_genpd_remove(pd); +free_name: + kfree(pd->name); +free_pd: + kfree(pd); + pr_err("failed to init PM domain ret=%d %pOF\n", ret, np); + return ret; +} + +static int psci_dt_set_genpd_topology(struct device_node *np) +{ + struct device_node *node; + struct of_phandle_args child, parent; + int ret; + + for_each_child_of_node(np, node) { + if (of_parse_phandle_with_args(node, "power-domains", + "#power-domain-cells", 0, + &parent)) + continue; + + child.np = node; + child.args_count = 0; + + ret = of_genpd_add_subdomain(&parent, &child); + of_node_put(parent.np); + if (ret) { + of_node_put(node); + return ret; + } + } + + return 0; +} + +int psci_dt_init_pm_domains(struct device_node *np) +{ + struct device_node *node; + struct genpd_power_state *states; + int state_count; + int pd_count = 0; + int ret; + + /* Parse child nodes for "#power-domain-cells". */ + for_each_child_of_node(np, node) { + if (!of_find_property(node, "#power-domain-cells", NULL)) + continue; + + ret = of_genpd_parse_idle_states(node, &states, &state_count); + if (ret) + goto err_put; + + ret = psci_dt_parse_pd_states(states, state_count); + if (ret) + goto err_put; + + ret = psci_dt_init_genpd(node, states, state_count); + if (ret) + goto err_put; + + pd_count++; + } + + if (!pd_count) + return 0; + + ret = psci_dt_set_genpd_topology(np); + if (ret) + goto err_msg; + + return pd_count; + +err_put: + of_node_put(node); +err_msg: + pr_err("failed to create PM domains ret=%d\n", ret); + return ret; +} +#endif -- 2.17.1