From patchwork Thu Apr 12 11:14:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 133259 Delivered-To: patches@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1573941ljb; Thu, 12 Apr 2018 04:15:15 -0700 (PDT) X-Received: by 10.46.154.71 with SMTP id k7mr391516ljj.42.1523531715722; Thu, 12 Apr 2018 04:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531715; cv=none; d=google.com; s=arc-20160816; b=z4pNWm+Guq8zs7l59+bZkeYe4P1LLXpohJ8k8ERwqgijD0+NL4a/JBY9Dduvinh479 LoxxtRH4yrrVfylozqNucKI/XZ89DIoeI0qbW7FzLNPBWcu8x/wN52EF5pb9hMA3j5M9 403J8Dydd2glV+eoFvAkcWpWeveN+zzkAv2cPxMSVm/QE5Ve5zKEBamFEtmw0RY4Ta32 5v+aFT1ajJmI1dyuBRWDxq2xeybn33O9PpsQUAutu2jzJeks7BcRG5mAN6algu8HN3qs xKkPbGCmR1AdUuzpl6ZBdwDPi1pQSRH7qHmHVzUqBWO3u7jLZDxpd1H4vFgSHs/BjhYc s6kQ== 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=sUDYgpzj5UEmCSSCZ9crCjUGiIscG774f2rkxIW5KB4=; b=p41B3VLJEv2f1n7/g/p60B7m+KCs3oWg1fPmkKBqNKKH2xDarU4o+VlnopzUfgJpj7 aeSJf3IQKTgNBbaSCofYElC7hBpl61ZRx2MnM7gZ8Is1ujEjbHrr6vGZLzXLhZm3Kbxe qPFMcSPYP8WRmqoPbvjxWS1GjKOph2XrFeaLknkUMIZafwM2p72iAiegueEaiqxW7705 QROSTjQ5dq+jAFJ3KOhbahS94AVp4HX5MKWlKxLB63V31Ae8aq0svahNnTyQ8F+hJtCb pqm1zqsWtvqWtSlSymt75Z6oYU/Ip8spLnjO6AtHZlAaet7VOQXzfTNMdIxq7bUm7JBb Rg0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YlhQTWH8; 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 e21sor903100ljg.69.2018.04.12.04.15.15 for (Google Transport Security); Thu, 12 Apr 2018 04:15:15 -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=YlhQTWH8; 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=sUDYgpzj5UEmCSSCZ9crCjUGiIscG774f2rkxIW5KB4=; b=YlhQTWH8cln8qYjbcsgLR/SNd5P/HvcUQHKLvJtPfdLxF16O6UxC5Pmlmae6mOXFed in0xdh846+EH2TrpIhMljitdh13P6X01+XeatB6IPLnTaYMqP4o/hiNSiK4nlxVFMPE5 Kk6V+GNngd1lSS20oh/X+39CH2JXgoq8KEV1c= 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=sUDYgpzj5UEmCSSCZ9crCjUGiIscG774f2rkxIW5KB4=; b=HHnkrIWgP+ubBFz/xmPHUZNSYJF0++16xXCpymFR5qTECW4JQnYl30AyyN5IPfHiYR /ZugiMbda3nuUFJoHf05KHkWPyLVCF/UqcjdudIDdcBh7M3Jkc4unTikYcwMuShxFJAS ZWoAOHPxiQeXxaFopZBZ21HiVhloWcpnptaCanrOdRbLsppxzw9Safjoc3tZH3sD70j/ CCqvU3Qq6WBr6sAmBIPR8C4gwkhtVE3du858+fXwFUPibHNmhKL1WFIo9Zq6Dbzxb92c VhfBIyNsiHRA3/JeUlqf1x722BHWN5YDoYUjlxMp0biCh4cxk2gjjnbu/P7ty0tUFJ2G seDw== X-Gm-Message-State: ALQs6tDCuyM5oRtLmVbTCirrAszwNnlm8mdjmJ6AV/qWv0xfJnr8neAD 67RAaC1Y7jMDlLcmFGIiTHBISHd7 X-Google-Smtp-Source: AIpwx4/8ymmQwjHjuavmhtWzR0YzoPugxpuzJRCkBA/y9gVfbnzt2+5U24v02c77GQXeFHvn0IbT1g== X-Received: by 10.46.137.71 with SMTP id b7mr365006ljk.39.1523531715432; Thu, 12 Apr 2018 04:15:15 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id r29sm543187lje.72.2018.04.12.04.15.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Apr 2018 04:15:14 -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 v7 21/26] drivers: firmware: psci: Add support for PM domains using genpd Date: Thu, 12 Apr 2018 13:14:26 +0200 Message-Id: <1523531671-27491-22-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523531671-27491-1-git-send-email-ulf.hansson@linaro.org> References: <1523531671-27491-1-git-send-email-ulf.hansson@linaro.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 -- 2.7.4 diff --git a/drivers/firmware/psci/Makefile b/drivers/firmware/psci/Makefile index 1956b88..ff300f1 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 a2b4be5..8b6fe51 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 0000000..f54819e --- /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