Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1037976imm; Wed, 20 Jun 2018 10:30:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKAqnq58P4Ll8RBgFGEvbL/cibwG0QBqtlQqq6DQUi4rEus351U8lKClXP9h59qCJWwOn6c X-Received: by 2002:aa7:81d3:: with SMTP id c19-v6mr23950069pfn.224.1529515835444; Wed, 20 Jun 2018 10:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529515835; cv=none; d=google.com; s=arc-20160816; b=JdvR+TFrmWetX4hsgNFHd15ngSgSONzYetDNBogCga7Ms1POZKyXuBT/u+C8Oq+2KV LU4S/ANbZ9TymAnMJQyc5Vcu8/Y+ANKVAmARcY9R+tdgOr/C0oRsuc+s8XHwoVsmy9C2 gs7uSjYAvm//WFcuqSTlyaJuLSnKCejy2WYEuw0/LDz0WHcWooFwZCUHW0uB1iB9D6/X uHV9qOcaNvVRVK/b6MvnCfBhUlxyDsJzeIhyi23VWilSLGeKcrTvaXWvExCMbZ7MfFqy qcvJXvW76jHkJoAhvN4/BRlNjHKnqRXml+CkQR34KlYJMWf6Me+SZaG4zzfVyp15GdAz gyQQ== 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=40LOjQ+YPGx6FLKxOB2XtXKEBIZOB0eV+AE7c0B9P1E=; b=adT7pzp+N6pI5uZZib/icG85Gmo+NeG0yL7Yt06WW5VV/rRXa4RO557UflZOCkFpLT wQtyvhFMwRDDSVSBhOOrd7xPdJDrOo0KL1OjhSMXIlOsLxs5i95M8PIZr1YsLr/1VRTm hVIh+CryFF2uG1fkoqPVT+RfwC1nvJeLoWvmQ06Vb+Z7ehlS6jZIbhkSC8u+QKLxUSnz 41HH1kyrqWzRoNUDyUO/LdMSxEMzMzTPbozG4bQqrMaOu7X8roEGs/AQNP9YaL+J9UC5 1I1BW0MHb80m5uUTzRX/TWIrmsf6jG3OBsVJM953plElN1P4NnhNtCKSg1cyiX6vLCAS gjwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aWFax21m; 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 c12-v6si2394256pgu.26.2018.06.20.10.30.20; Wed, 20 Jun 2018 10:30:35 -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=aWFax21m; 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 S932872AbeFTR2Z (ORCPT + 99 others); Wed, 20 Jun 2018 13:28:25 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36805 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754458AbeFTRWq (ORCPT ); Wed, 20 Jun 2018 13:22:46 -0400 Received: by mail-lf0-f68.google.com with SMTP id n24-v6so485751lfh.3 for ; Wed, 20 Jun 2018 10:22:45 -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=40LOjQ+YPGx6FLKxOB2XtXKEBIZOB0eV+AE7c0B9P1E=; b=aWFax21mb/OlcZ7istRxEXtPKUgExdCY0cZkrEYF2+Jr5f3yKt7cA4JqeDOe8p1AJY NNUJv+K8Al6QpPca5OFrRctUKi+y1W6JOcechSQQAEBT+F3kXon2QFO3P8WiL1gAl/Jp QxV1m/BbjaPYRQ1CJfXLnW72fnBPVUOcxglkk= 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=40LOjQ+YPGx6FLKxOB2XtXKEBIZOB0eV+AE7c0B9P1E=; b=anjnaZ8adOKPyT0jOOlQxvS885uM39VADXVQ+uy85SRkt1+nzKj2dUIjEj8ydHSnA/ ba9wYIblgEbX06ch9kBO1Ia7yuHIauwZixIdM6HFI8J9u4vI8Q8FmG4R7SjvM+b6a0bi g5WLNn60G6h2pV7FM6HVkRJpgdmbXWCn0mR0xHvzxVDzQ95vde5Q05KMuZIX9/MKfvnX Sac0vVIZPvlD6K/dUgJJ5vjgcXtcaDhkobdVdpksgITz21NNXaRxntHl13yzQkcmWNJT rusLhEvEpbiHJbub4MHyr0wjpid3M7QRdKiBd5C5rXxiiezgoSasOQHTvpQFjD1Q3bmK p0qw== X-Gm-Message-State: APt69E0Ajt3jAIApSMeyOZ3jckfSEKv/YBGx/U3qDd/0gyiNGP8XE2Wf UxfE+ySTuwfLwEFgSphzqWNJsw== X-Received: by 2002:a2e:1d59:: with SMTP id d86-v6mr15375209ljd.104.1529515364476; Wed, 20 Jun 2018 10:22:44 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:22:43 -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 05/26] PM / Domains: Add helper functions to attach/detach CPUs to/from genpd Date: Wed, 20 Jun 2018 19:22:05 +0200 Message-Id: <20180620172226.15012-6-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 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 | 69 +++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 9 +++++ 2 files changed, 78 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 6149ce0bfa7b..299fa2febbec 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2445,6 +2445,75 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id); +/* + * of_genpd_attach_cpu() - Attach a CPU to its PM domain + * @cpu: The CPU to be attached. + * + * Parses the OF node of the CPU's device, to find a PM domain specifier. If + * such is found, attaches the CPU's device to the retrieved pm_domain ops and + * enables runtime PM for it. This to allow the CPU to be power managed through + * its PM domain. + * + * Returns zero when successfully attached the CPU's device to its PM domain, + * 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 != 1) { + dev_warn(dev, "genpd: attach cpu failed %d\n", ret); + return ret < 0 ? ret : -ENODEV; + } + + 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 3f67ff0c1c69..2c09cf80b285 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -243,6 +243,8 @@ unsigned int of_genpd_opp_to_performance_state(struct device *dev, int genpd_dev_pm_attach(struct device *dev); struct device *genpd_dev_pm_attach_by_id(struct device *dev, unsigned int index); +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) @@ -294,6 +296,13 @@ static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev, return NULL; } +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) { -- 2.17.1