From patchwork Thu Apr 12 11:14:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 133243 Delivered-To: patches@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1573492ljb; Thu, 12 Apr 2018 04:14:47 -0700 (PDT) X-Received: by 10.46.115.8 with SMTP id o8mr385341ljc.99.1523531687340; Thu, 12 Apr 2018 04:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531687; cv=none; d=google.com; s=arc-20160816; b=wvPAp4qu7zshMDPE+pN1NEQxUAFuRdgp5K+NHdEIlsCbyIVnBD9ani5qxPg8/yFS9Y EZl6PLDS1mfhABELypsurz3YzJdSp+TX/fg/ULsRKyXjwFNHzw5wvqSgBNR+E7eKXLsB zp9yi8QwrKqszlNLPtzhQNnpRNXwu/vW+FLd6XyWU5KH12d13J3ejB8sa10DjRwfM87Q 9/0Z22DoBaO+IHR3pSG0Rzw102xf5OsvW88R1tOsjFTX6KPnDx6p8kuII69/qKhrYsQ4 ZRzaeWT8qQOk1tftl50+XlJzduwquo9LxDl+1tzgnxzBgIua6wnuBsQ+U98ChlYnynde PplA== 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=1O11apE6tR+MdI607Y0iNJFhJF3NsEpjqwr8dBVhhK4=; b=q0+tm9zVYNsZqrvy7JJ5Z7aKT6d4MXgB3Qn4tUzPm4qZzektkuzHKCYh8yTMj38TH3 qGNapGzCmHmwR5lssdkQTzsMECbzqSXUtHm1wceDuuZC6WJsh0rrcGvOXCJ3LOHxfZiU 8Ctnwbn61OHyR6drpF9/z4D1FPw1HfRAoEIJ4Pl9eWtJUDlkz9UAFQAUnpoOcD0aEwwe xBJeQGIwcvb0yvqJNDh9y6DKYZu2JoKhPzC+VvnTDHL+idZHLxNwaYXqC8Brd4Ctw/ow 2JE9r9L2Zr2Pyq4ACml1zUvyD3JTmtMrP+RLqigBECo1F30yg9auaeS/+gzWmntiuHjL 2N7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VZfh+xXH; 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 c8sor873983lji.23.2018.04.12.04.14.47 for (Google Transport Security); Thu, 12 Apr 2018 04:14:47 -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=VZfh+xXH; 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=1O11apE6tR+MdI607Y0iNJFhJF3NsEpjqwr8dBVhhK4=; b=VZfh+xXHn0dlNDSUDSmubXn13syh5V6LnILJj5xoBMJ/neglG7/+/mn9fvW4wv6smD GaAQGwqbZpp5DbQuN8EAyMJ2mmwKk1jj9CSHB3oWVljxA/CyBUDYaUbFyNY7RquYAfbS ofhvnv3WPd8hZTeu+fyV/RljksUMHmJ/9kr3o= 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=1O11apE6tR+MdI607Y0iNJFhJF3NsEpjqwr8dBVhhK4=; b=EqZFcDo9P5fP+6cUc1KVREjUpgas6AVAI2DelxfTurWKMPl4YSPnwAe1Jk2SUN+3bg wodtvjwhqgPkryX2mZFya0y2BQccVwsNh5cnEyCqcpxlqj6KOoqdv2a3lv3lGeqzisYF rnNL67/ytkEYnU6XdPRvlKclf5xfMxMtB63oJysVSgHIP8lnwksAWEIwrXZed/8tf10Q XLKtrrigssOzKlMmA8Jp8gejefiVK9cuRCogBi2lKo9vv1374lOWZOMbTPwp5o1b4WrE j+uS45XmAoFKvClkCe0EsqGajFcxwDnS3Wyu3X6ZNIJvY6WYCN2uRXcKWsLH/kTzu8gV plZQ== X-Gm-Message-State: ALQs6tDAb2POHkVoSdpUElh5mmWEpZwXR5juI7S3YM9M572vQ8quk7Up umBrx/yKp5fZrQsPRzTVFSBLoCnD X-Google-Smtp-Source: AIpwx4/0V8HZN70rL8Fj2S07bx6mTOUose1TvpSMjV9sifAFsQzQaJ36wminW7+TuUo7tGGarCYssQ== X-Received: by 10.46.128.132 with SMTP id i4mr364037ljg.51.1523531687073; Thu, 12 Apr 2018 04:14:47 -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.14.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Apr 2018 04:14:46 -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 05/26] PM / Domains: Add helper functions to attach/detach CPUs to/from genpd Date: Thu, 12 Apr 2018 13:14:10 +0200 Message-Id: <1523531671-27491-6-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> Introduce two new genpd helper functions, of_genpd_attach|detach_cpu(), which takes the CPU-number as an in-parameter. To attach a CPU to a genpd, of_genpd_attach_cpu() starts by fetching the struct device belonging to the CPU. Then it calls genpd_dev_pm_attach(), which via DT tries to hook up the CPU device to its corresponding PM domain. If it succeeds, of_genpd_attach_cpu() continues to prepare/enable runtime PM of the device. To detach a CPU from its PM domain, of_genpd_attach_cpu() reverse the operations made from of_genpd_attach_cpu(). However, first it checks that the CPU device has a valid PM domain pointer assigned, as to make sure it belongs to genpd. Cc: Lina Iyer Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 9 ++++++ 2 files changed, 76 insertions(+) -- 2.7.4 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index e178521..91ea9b2 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2324,6 +2324,73 @@ int genpd_dev_pm_attach(struct device *dev) } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); +/** + * of_genpd_attach_cpu() - Attach a CPU to its PM domain + * @cpu: The CPU to be attached. + * + * Try to find the corresponding PM domain provider for the CPU's device. Use + * it to attach the CPU's device to its PM domain. If attaching is completed + * successfully, we enable runtime PM for the CPU's device. + * + * Returns zero on success else a negative error code. + */ +int of_genpd_attach_cpu(int cpu) +{ + struct device *dev = get_cpu_device(cpu); + int ret; + + if (!dev) { + pr_warn("genpd: no dev for cpu%d\n", cpu); + return -ENODEV; + } + + ret = genpd_dev_pm_attach(dev); + if (ret) { + dev_warn(dev, "genpd: attach cpu failed %d\n", ret); + return ret; + } + + pm_runtime_irq_safe(dev); + pm_runtime_get_noresume(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + dev_info(dev, "genpd: attached cpu\n"); + return 0; +} +EXPORT_SYMBOL(of_genpd_attach_cpu); + +/** + * of_genpd_detach_cpu() - Detach a CPU from its PM domain + * @cpu: The CPU to be detached. + * + * Detach the CPU's device from its corresponding PM domain. If detaching is + * completed successfully, disable runtime PM and restore the runtime PM usage + * count for the CPU's device. + */ +void of_genpd_detach_cpu(int cpu) +{ + struct device *dev = get_cpu_device(cpu); + + if (!dev) { + pr_warn("genpd: no dev for cpu%d\n", cpu); + return; + } + + /* Check that the device is attached to a genpd. */ + if (!(dev->pm_domain && dev->pm_domain->detach == genpd_dev_pm_detach)) + return; + + genpd_dev_pm_detach(dev, true); + + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + pm_runtime_reinit(dev); + + dev_info(dev, "genpd: detached cpu\n"); +} +EXPORT_SYMBOL(of_genpd_detach_cpu); + static const struct of_device_id idle_state_match[] = { { .compatible = "domain-idle-state", }, { } diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 29ab00c..ccd7c94 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -249,6 +249,8 @@ extern int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n); int genpd_dev_pm_attach(struct device *dev); +int of_genpd_attach_cpu(int cpu); +void of_genpd_detach_cpu(int cpu); #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ static inline int of_genpd_add_provider_simple(struct device_node *np, struct generic_pm_domain *genpd) @@ -287,6 +289,13 @@ static inline int genpd_dev_pm_attach(struct device *dev) return -ENODEV; } +static inline int of_genpd_attach_cpu(int cpu) +{ + return -ENODEV; +} + +static inline void of_genpd_detach_cpu(int cpu) {} + static inline struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) {