From patchwork Thu Dec 11 08:26:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 5474651 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D77AF9F472 for ; Thu, 11 Dec 2014 08:29:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D3F7E20166 for ; Thu, 11 Dec 2014 08:29:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6AA020173 for ; Thu, 11 Dec 2014 08:29:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xyz5v-0007ni-OU; Thu, 11 Dec 2014 08:27:31 +0000 Received: from mail-pd0-x22f.google.com ([2607:f8b0:400e:c02::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xyz5W-0007dA-RG for linux-arm-kernel@lists.infradead.org; Thu, 11 Dec 2014 08:27:10 +0000 Received: by mail-pd0-f175.google.com with SMTP id g10so2559614pdj.6 for ; Thu, 11 Dec 2014 00:26:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qbCpI24n9WEiUMaW5B40g5l6laoxNvnt5r/DggZyRZI=; b=ivp+57ekcKz6J2/iGGOPDP75b+Xx4BdBR5okp27zRzCIDXaPCZVVqS+J27LQohZu+E 4Kv4Ea0nZdworV1LGSs19J9dBIIoKpLVdfV7DsYLE9bK8jjN8aLfRvjgrxMAWsW0ff/8 mQk/4lt1f4Iy07zlJThWrA817tE3924QX8lVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qbCpI24n9WEiUMaW5B40g5l6laoxNvnt5r/DggZyRZI=; b=ah2PdarEmFzRAPxD0u9hm3eNJBGYIZycOFUcm+9JBFAOlaCELDuGhck+5nHJ6GehAc EFu4D/TEWoSPLnizN2pDZZrb2UX1ZyKIKiR86euXeoq4v7nGikJyFfEhqgDhMe8ifJ2P /Wy4OEKFEgo11xjtJnMl/JKxOI6LTTksin6xAm0eFAlR34VejUdT6AJEpa/OXzO+GEpJ Yc8KTgYUEwEdY/sb9ZrPdYV5xZKoTZeeInTrboKc5UdhRIYgTgXnL5hID+K9w9TSU7rw BsQD/5dnvjRxrthDzSizRe8RinPcYPVbU3LNZeWx9hMd7U8sCBQ5duXGQ9UGlHHAPZTq xhxw== X-Gm-Message-State: ALoCoQkD0ZxcGCRYEBCWEfo5M/0xf7NL1mV4ZeuXI6rQK9FUEIJBumhnwQCFnhRDsaHIzQJPLKlq X-Received: by 10.66.65.108 with SMTP id w12mr14509865pas.115.1418286405081; Thu, 11 Dec 2014 00:26:45 -0800 (PST) Received: from basement.tok.corp.google.com ([172.23.69.229]) by mx.google.com with ESMTPSA id fv4sm635611pbd.47.2014.12.11.00.26.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Dec 2014 00:26:44 -0800 (PST) From: Tomasz Figa To: linux-rockchip@lists.infradead.org Subject: [RFC PATCH 1/2] pm: Add PM domain notifications Date: Thu, 11 Dec 2014 17:26:26 +0900 Message-Id: <1418286387-9663-2-git-send-email-tfiga@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1418286387-9663-1-git-send-email-tfiga@chromium.org> References: <1418286387-9663-1-git-send-email-tfiga@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141211_002707_003204_2B7E4623 X-CRM114-Status: GOOD ( 17.78 ) X-Spam-Score: -0.8 (/) Cc: Len Brown , Ulf Hansson , Kevin Hilman , Heiko Stuebner , Geert Uytterhoeven , linux-pm@vger.kernel.org, Joerg Roedel , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Daniel Kurtz , Tomasz Figa , iommu@lists.linux-foundation.org, Pavel Machek , Sylwester Nawrocki , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sylwester Nawrocki This patch adds notifiers to the runtime PM/genpd subsystem. It is now possible to register a notifier, which will be called before and after the generic power domain subsystem calls the power domain's power_on and power_off callbacks. Signed-off-by: Sylwester Nawrocki [tfiga@chromium.org: rebased] Signed-off-by: Tomasz Figa --- Documentation/power/notifiers.txt | 14 +++++++++++ drivers/base/power/domain.c | 50 +++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 20 ++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/Documentation/power/notifiers.txt b/Documentation/power/notifiers.txt index a81fa25..62303f6 100644 --- a/Documentation/power/notifiers.txt +++ b/Documentation/power/notifiers.txt @@ -53,3 +53,17 @@ NULL). To register and/or unregister a suspend notifier use the functions register_pm_notifier() and unregister_pm_notifier(), respectively, defined in include/linux/suspend.h . If you don't need to unregister the notifier, you can also use the pm_notifier() macro defined in include/linux/suspend.h . + +Power Domain notifiers +---------------------- + +The power domain notifiers allow subsystems or drivers to register for power +domain on/off notifications, should they need to perform any actions right +before or right after the power domain on/off. The device must be already +added to a power domain before its subsystem or driver registers the notifier. +Following events are supported: + +PM_GENPD_POWER_ON_PREPARE The power domain is about to turn on. +PM_GENPD_POST_POWER_ON The power domain has just turned on. +PM_GENPD_POWER_OFF_PREPARE The power domain is about to turn off. +PM_GENPD_POST_POWER_OFF The power domain has just turned off. diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 6a103a3..0d6f84e 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -68,6 +68,45 @@ static struct generic_pm_domain *pm_genpd_lookup_name(const char *domain_name) return genpd; } +int pm_genpd_register_notifier(struct device *dev, struct notifier_block *nb) +{ + struct pm_domain_data *pdd; + int ret = -EINVAL; + + spin_lock_irq(&dev->power.lock); + if (dev->power.subsys_data) { + pdd = dev->power.subsys_data->domain_data; + ret = blocking_notifier_chain_register(&pdd->notify_chain_head, + nb); + } + spin_unlock_irq(&dev->power.lock); + return ret; +} +EXPORT_SYMBOL_GPL(pm_genpd_register_notifier); + +void pm_genpd_unregister_notifier(struct device *dev, struct notifier_block *nb) +{ + struct pm_domain_data *pdd; + + spin_lock_irq(&dev->power.lock); + if (dev->power.subsys_data) { + pdd = dev->power.subsys_data->domain_data; + blocking_notifier_chain_unregister(&pdd->notify_chain_head, nb); + } + spin_unlock_irq(&dev->power.lock); +} +EXPORT_SYMBOL_GPL(pm_genpd_unregister_notifier); + +static void pm_genpd_notifier_call(unsigned long event, + struct generic_pm_domain *genpd) +{ + struct pm_domain_data *pdd; + + list_for_each_entry(pdd, &genpd->dev_list, list_node) + blocking_notifier_call_chain(&pdd->notify_chain_head, + event, pdd->dev); +} + struct generic_pm_domain *dev_to_genpd(struct device *dev) { if (IS_ERR_OR_NULL(dev->pm_domain)) @@ -161,12 +200,17 @@ static int genpd_power_on(struct generic_pm_domain *genpd) if (!genpd->power_on) return 0; + pm_genpd_notifier_call(PM_GENPD_POWER_ON_PREPARE, genpd); + time_start = ktime_get(); ret = genpd->power_on(genpd); if (ret) return ret; elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); + + pm_genpd_notifier_call(PM_GENPD_POST_POWER_ON, genpd); + if (elapsed_ns <= genpd->power_on_latency_ns) return ret; @@ -188,12 +232,17 @@ static int genpd_power_off(struct generic_pm_domain *genpd) if (!genpd->power_off) return 0; + pm_genpd_notifier_call(PM_GENPD_POWER_OFF_PREPARE, genpd); + time_start = ktime_get(); ret = genpd->power_off(genpd); if (ret == -EBUSY) return ret; elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); + + pm_genpd_notifier_call(PM_GENPD_POST_POWER_OFF, genpd); + if (elapsed_ns <= genpd->power_off_latency_ns) return ret; @@ -1466,6 +1515,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, genpd->attach_dev(genpd, dev); mutex_lock(&gpd_data->lock); + BLOCKING_INIT_NOTIFIER_HEAD(&gpd_data->base.notify_chain_head); gpd_data->base.dev = dev; list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); gpd_data->need_restore = -1; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 6cd20d5..356a145 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -20,6 +20,12 @@ /* Defines used for the flags field in the struct generic_pm_domain */ #define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */ +/* PM domain state transition notifications */ +#define PM_GENPD_POWER_ON_PREPARE 0x01 +#define PM_GENPD_POST_POWER_ON 0x02 +#define PM_GENPD_POWER_OFF_PREPARE 0x03 +#define PM_GENPD_POST_POWER_OFF 0x04 + enum gpd_status { GPD_STATE_ACTIVE = 0, /* PM domain is active */ GPD_STATE_WAIT_MASTER, /* PM domain's master is being waited for */ @@ -107,6 +113,7 @@ struct gpd_timing_data { struct pm_domain_data { struct list_head list_node; struct device *dev; + struct blocking_notifier_head notify_chain_head; }; struct generic_pm_domain_data { @@ -159,6 +166,11 @@ extern int pm_genpd_name_poweron(const char *domain_name); extern void pm_genpd_poweroff_unused(void); extern struct dev_power_governor simple_qos_governor; +extern int pm_genpd_register_notifier(struct device *dev, + struct notifier_block *nb); +extern void pm_genpd_unregister_notifier(struct device *dev, + struct notifier_block *nb); + extern struct dev_power_governor pm_domain_always_on_gov; #else @@ -232,6 +244,14 @@ static inline int pm_genpd_name_poweron(const char *domain_name) return -ENOSYS; } static inline void pm_genpd_poweroff_unused(void) {} +static inline int pm_genpd_register_notifier(struct device *dev, + struct notifier_block *nb) +{ + return -ENOSYS; +} +static inline void pm_genpd_unregister_notifier(struct device *dev, + struct notifier_block *nb) {} + #define simple_qos_governor NULL #define pm_domain_always_on_gov NULL #endif