From patchwork Wed Mar 14 16:58:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 131674 Delivered-To: patches@linaro.org Received: by 10.80.210.197 with SMTP id q5csp410301edg; Wed, 14 Mar 2018 09:59:11 -0700 (PDT) X-Received: by 2002:a19:730d:: with SMTP id o13-v6mr4100825lfc.88.1521046751776; Wed, 14 Mar 2018 09:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521046751; cv=none; d=google.com; s=arc-20160816; b=H2oDhDbrSm0thihdBmlbJ04FlV/DVwLwueXgUqFBant1MDB07AVHiYlxvFNWyJsiHh sfETD4A43nYFqw1NYxWkxzOaGhOxAkMAKse3v1GEIn3mINEiTSEfwwLCCEJjffrd1W7J rj6oFIdc2XUGHOD5AUdDXuAxVZEw1gQfQmThhmNMKlbHgwRdzlxnxzeh9B3c1Wvo45ct zb6eDoi4rnpLeiQSngH9ORCWXP7foLVExKLpsV7/nXzTag5QAUCb57T6co5GrTPTgpjv relDOCxxpU02OMaDKsGZ6B+OxuIHM18WRyOlP/ZBapTP9VZq10yrbMB68cW+JoQiCVkd gHuA== 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=bZvrw8pC+k3f/FYH1hCWdID/PssUb+AzgpIqJ5q8DXA1knJo9/AatXAX8m49uUmp3L Kl8BGvi5sgzBHbPiHKQMvhXRnSnCBjNKexeQvvEBGoDPE//1bHpuG2vWUh0Um3SrkKUB vIl3BicOjEzHumNKG4TU9bleBXQufno/ENV79ud0kkZiDGASqk190FHZA27ZzrvuGDGG xmGFIxe5gthI7Wu/xORKwQhzHHINicIqdJjft14PnhcVcc1pLaox8qU559KemA80Yfw6 O+nB3L7BcCxmPD0onFVGUx5tTchIniN7UIRrHQDqjGkt3ToJ+OG9WxjTRgB4OU9p50bM QgvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LxD04/+t; 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 r86sor820092lja.24.2018.03.14.09.59.11 for (Google Transport Security); Wed, 14 Mar 2018 09:59:11 -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=LxD04/+t; 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=LxD04/+tvmTN2FGUbQRbG0w+J8iLObYFKSIdPUH2f0jPCNOkXl1n2mfgbG0K2A/N9a zdTSy9oV2laYm1++0zKmpZbtMyrmyFwGnz/QSVzqP6M501Aus4FRbIc88s5CFnPyNiXC TFj04l2foXSAIhstN3GA9mh/MRFr97qh9qCGQ= 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=F5I3ylZTs9QLQ7Li+KuEX8Xhtn7JsgvKKRMB9sjDwTfvwPm/1NhPdfywRbsKdC/2Vp Z7yBFZ5ma/cdQx+mBx72IWxa4+x5NLMTzeCLuliKAKRwoYyK8+qwbZ/ZXX7EG+r4DtKY Uov9tQnkBLRChRMxpeRbrVGeJS2cqqZLeWhOX9XPi0CxlykZ6ULzQNQ/9hrQFjIxiXcz wNil+tetccbcc5paO73CNUzPeRUqTh7Xn3p4YTPHJbNzGfflJ4uvdu+TWM3cFBfMUD3L EapdOIp89kNl9xqh9wnkQfHgoweENbMKJR0WfHQ9QBU5rB6RX5n1oHpPXntscpEOuBQS uUHQ== X-Gm-Message-State: AElRT7GA+y3EWCGdEr+zalf1hCNpwzICmxD+R5CeiSHrE0cCp3JP6VuH RwJ2F+qNfGNWoXZ9nmwaxNEVX5iV X-Google-Smtp-Source: AG47ELu6V3o4QSZEKsC/gCA9hVXoP+X1ZZ88qcB0ICIf8m5nnn08S4yV/5ggDgdWhWY98cvedFhmRA== X-Received: by 10.46.12.73 with SMTP id o9mr4010439ljd.68.1521046751472; Wed, 14 Mar 2018 09:59:11 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 09:59:10 -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 Subject: [PATCH v6 05/25] PM / Domains: Add helper functions to attach/detach CPUs to/from genpd Date: Wed, 14 Mar 2018 17:58:15 +0100 Message-Id: <1521046715-30683-6-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> 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) {