From patchwork Tue Aug 5 10:47:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 34914 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D1AB920523 for ; Tue, 5 Aug 2014 10:49:22 +0000 (UTC) Received: by mail-oi0-f72.google.com with SMTP id a141sf2892991oig.3 for ; Tue, 05 Aug 2014 03:49:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=3ClUErqONT+wWjV6Nm70w9mQdaevWT1NisX2TFcoI+M=; b=N5q4gtZrntgnol7vhnMZnL7L9BxkV8JKpal0IZGyjGFiVuq/9q/hNH6JCTerfdmgTq Au3KrfBYH6md9Vg6wdvhzuv1OxU0xvJWQ1YeX222n+1VoRvJuMQtAMqEvf1EpT5MQIgG xoLP1cumqcDbEFQYCK7wZiFgwpTbysTvz+HzaINK2Kc9KFABkZ0y1YQLaTVxUfUTJCIw hnAyJKiBcQV2h9bgFnZhP+btOvkgdmWPdh7bzNIAOn5+HDLO7kevzYcGVbfddySo/QUH /pENtzKlhCjlWP0UaNwzcHZUAf0xM0DCPcOouW3Nbdo20u8+a7CcYRgCpw/VWhQq80ZE koUg== X-Gm-Message-State: ALoCoQmLa1zEwytQ6QfZO27yk5lRMjznu5v6R/SX92rlRIUUUX1s/x4CKiAA8AvkphtK3EJg6ZKh X-Received: by 10.182.66.68 with SMTP id d4mr1445438obt.39.1407235762476; Tue, 05 Aug 2014 03:49:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.38.175 with SMTP id t44ls187371qgt.60.gmail; Tue, 05 Aug 2014 03:49:22 -0700 (PDT) X-Received: by 10.220.49.10 with SMTP id t10mr2398312vcf.34.1407235762332; Tue, 05 Aug 2014 03:49:22 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id da3si767826vcb.102.2014.08.05.03.49.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 03:49:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ik5so1106705vcb.34 for ; Tue, 05 Aug 2014 03:49:22 -0700 (PDT) X-Received: by 10.220.131.207 with SMTP id y15mr49240vcs.71.1407235762154; Tue, 05 Aug 2014 03:49:22 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp374556vcb; Tue, 5 Aug 2014 03:49:21 -0700 (PDT) X-Received: by 10.140.46.55 with SMTP id j52mr4005261qga.27.1407235761360; Tue, 05 Aug 2014 03:49:21 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id x5si2123198qcj.11.2014.08.05.03.49.20 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 05 Aug 2014 03:49:21 -0700 (PDT) Received-SPF: none (google.com: linaro-mm-sig-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XEcIy-0005Hg-AF; Tue, 05 Aug 2014 10:49:20 +0000 Received: from mailout4.w1.samsung.com ([210.118.77.14]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XEcIb-0005Ed-8I for linaro-mm-sig@lists.linaro.org; Tue, 05 Aug 2014 10:48:57 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N9T00BHDY13JW00@mailout4.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 05 Aug 2014 11:48:40 +0100 (BST) X-AuditID: cbfec7f4-b7f156d0000063c7-9a-53e0b691c5c1 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 06.0C.25543.196B0E35; Tue, 05 Aug 2014 11:48:49 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N9T0057MY17SE80@eusync3.samsung.com>; Tue, 05 Aug 2014 11:48:49 +0100 (BST) From: Marek Szyprowski To: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Tue, 05 Aug 2014 12:47:29 +0200 Message-id: <1407235677-26324-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> References: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGLMWRmVeSWpSXmKPExsVy+t/xq7oTtz0INmibYmDxd9IxdovmxevZ LCbdn8BisWC/tUXn7A3sFr0LrrJZnG16w27ROXEJu8WXKw+ZLDY9vsZqcXnXHDaLGef3MVms PXKX3eLU9c9sFv96DzJanDl9idXi/54d7BaH37SzWhx5uJvdYtWuP4wWt3/zOYh6PDk4j8nj 969JjB47Z91l95jdMZPVY9OqTjaP/XPXsHtsXlLvcfvfY2aPyTeWM3pcOdHE6tHb/I7NY8vV dhaPvi2rGD0+b5IL4IvisklJzcksSy3St0vgyjgytZGxYJlDxbOl99gbGHeYdjFyckgImEis aF7OBGGLSVy4t54NxBYSWMoo8eWNehcjF5DdxySxvHk3C0iCTcBQouttFxtIQkSgl1Giv+kH E4jDLLCOVWJ/73WwKmEBM4nT7zuBbA4OFgFViYNfOUDCvAIeEttvXmCB2CYn8f/lCrDNnAKe EodvHmCF2Owh8XPDGvYJjLwLGBlWMYqmliYXFCel5xrqFSfmFpfmpesl5+duYoTEzZcdjIuP WR1iFOBgVOLhNTh9N1iINbGsuDL3EKMEB7OSCK/EmgfBQrwpiZVVqUX58UWlOanFhxiZODil Ghizcxb7bElXu5py+MtNeYfJ/9+qfrUyv3xJ6HOiTue7izUiMhGz1c8o2Sxb86o7YJlCOcfP dzwLmXqcW7QWsZ+RNzjKH7bQVm1+oPvBi+7h67Uf3pa9+Zb3ScsEtVO1hzkOxN5rFn9i+XBT upBgwlRbhXnrVMJDpkuVXRC4OtNTRyf7ct/mM4xKLMUZiYZazEXFiQDW5cWIeQIAAA== Cc: Rob Herring , Thierry Reding , Shaik Ameer Basha , Arnd Bergmann , Inki Dae , Greg Kroah-Hartman , Joerg Roedel , "Rafael J. Wysocki" , Tomasz Figa , linaro-mm-sig@lists.linaro.org, Kyungmin Park , Kukjin Kim , Laurent Pinchart , Sylwester Nawrocki , Olof Johansson , Cho KyongHo Subject: [Linaro-mm-sig] [PATCH 01/29] pm: Add PM domain notifications X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 --- Documentation/power/notifiers.txt | 14 ++++++++ drivers/base/power/domain.c | 70 ++++++++++++++++++++++++++++++++++++--- include/linux/pm.h | 2 ++ include/linux/pm_domain.h | 19 +++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) 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 eee55c1..5fe0966 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -70,6 +70,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); +} + #ifdef CONFIG_PM struct generic_pm_domain *dev_to_genpd(struct device *dev) @@ -231,10 +270,14 @@ static int __pm_genpd_poweron(struct generic_pm_domain *genpd) ktime_t time_start = ktime_get(); s64 elapsed_ns; + pm_genpd_notifier_call(PM_GENPD_POWER_ON_PREPARE, genpd); + ret = genpd->power_on(genpd); if (ret) goto err; + pm_genpd_notifier_call(PM_GENPD_POST_POWER_ON, genpd); + elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); if (elapsed_ns > genpd->power_on_latency_ns) { genpd->power_on_latency_ns = elapsed_ns; @@ -554,13 +597,17 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd) * the pm_genpd_poweron() restore power for us (this shouldn't * happen very often). */ + pm_genpd_notifier_call(PM_GENPD_POWER_OFF_PREPARE, genpd); + ret = genpd->power_off(genpd); if (ret == -EBUSY) { genpd_set_active(genpd); goto out; } - 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) { genpd->power_off_latency_ns = elapsed_ns; genpd->max_off_time_changed = true; @@ -837,9 +884,13 @@ static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) || atomic_read(&genpd->sd_count) > 0) return; - if (genpd->power_off) + if (genpd->power_off) { + pm_genpd_notifier_call(PM_GENPD_POWER_OFF_PREPARE, genpd); genpd->power_off(genpd); + pm_genpd_notifier_call(PM_GENPD_POST_POWER_OFF, genpd); + } + genpd->status = GPD_STATE_POWER_OFF; list_for_each_entry(link, &genpd->slave_links, slave_node) { @@ -869,8 +920,11 @@ static void pm_genpd_sync_poweron(struct generic_pm_domain *genpd) genpd_sd_counter_inc(link->master); } - if (genpd->power_on) + if (genpd->power_on) { + pm_genpd_notifier_call(PM_GENPD_POWER_ON_PREPARE, genpd); genpd->power_on(genpd); + pm_genpd_notifier_call(PM_GENPD_POST_POWER_ON, genpd); + } genpd->status = GPD_STATE_ACTIVE; } @@ -1292,9 +1346,16 @@ static int pm_genpd_restore_noirq(struct device *dev) * If the domain was off before the hibernation, make * sure it will be off going forward. */ - if (genpd->power_off) + if (genpd->power_off) { + pm_genpd_notifier_call(PM_GENPD_POWER_OFF_PREPARE, + genpd); + genpd->power_off(genpd); + pm_genpd_notifier_call(PM_GENPD_POST_POWER_OFF, + genpd); + } + return 0; } } @@ -1467,6 +1528,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, spin_unlock_irq(&dev->power.lock); 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 = genpd->status == GPD_STATE_POWER_OFF; diff --git a/include/linux/pm.h b/include/linux/pm.h index 72c0fe0..bfc55d4 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -22,6 +22,7 @@ #define _LINUX_PM_H #include +#include #include #include #include @@ -542,6 +543,7 @@ struct wakeup_source; struct pm_domain_data { struct list_head list_node; struct device *dev; + struct blocking_notifier_head notify_chain_head; }; struct pm_subsys_data { diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 7c1d252..569ab16 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -17,6 +17,12 @@ #include #include +/* 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 */ @@ -167,6 +173,11 @@ extern int pm_genpd_name_poweron(const char *domain_name); extern bool default_stop_ok(struct device *dev); +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 @@ -259,6 +270,14 @@ static inline bool default_stop_ok(struct device *dev) { return false; } +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