linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: iommu@lists.linux-foundation.org,
	linux-samsung-soc@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	linaro-mm-sig@lists.linaro.org, Arnd Bergmann <arnd@arndb.de>,
	Shaik Ameer Basha <shaik.ameer@samsung.com>,
	Cho KyongHo <pullip.cho@samsung.com>,
	Joerg Roedel <joro@8bytes.org>,
	Thierry Reding <treding@nvidia.com>,
	Olof Johansson <olof@lixom.net>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Rob Herring <robh@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Inki Dae <inki.dae@samsung.com>,
	Kukjin Kim <kgene.kim@samsung.com>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Tomasz Figa <tomasz.figa@gmail.com>,
	Kyungmin Park <kyungmin.park@samsung.com>
Subject: [PATCH 01/29] pm: Add PM domain notifications
Date: Tue, 05 Aug 2014 12:47:29 +0200	[thread overview]
Message-ID: <1407235677-26324-2-git-send-email-m.szyprowski@samsung.com> (raw)
In-Reply-To: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com>

From: Sylwester Nawrocki <s.nawrocki@samsung.com>

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 <s.nawrocki@samsung.com>
---
 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 <linux/list.h>
+#include <linux/notifier.h>
 #include <linux/workqueue.h>
 #include <linux/spinlock.h>
 #include <linux/wait.h>
@@ -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 <linux/notifier.h>
 #include <linux/cpuidle.h>
 
+/* 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
-- 
1.9.2


  reply	other threads:[~2014-08-05 10:48 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05 10:47 [PATCH 00/29] Exynos SYSMMU (IOMMU) integration with DT and DMA-mapping subsystem Marek Szyprowski
2014-08-05 10:47 ` Marek Szyprowski [this message]
2014-08-05 10:47 ` [PATCH 02/29] ARM: Exynos: bind power domains earlier, on device creation Marek Szyprowski
2014-08-05 10:47 ` [PATCH 03/29] clk: exynos: add missing smmu_g2d clock and update comments Marek Szyprowski
2014-08-18 11:26   ` Tomasz Figa
2014-08-05 10:47 ` [PATCH 04/29] drivers: base: add notifier for failed driver bind Marek Szyprowski
2014-08-21 19:46   ` Laurent Pinchart
2014-08-25 20:05   ` Greg Kroah-Hartman
2014-08-26  6:23     ` Marek Szyprowski
2014-08-25 21:18   ` Joerg Roedel
2014-08-26  6:30     ` Marek Szyprowski
2014-08-05 10:47 ` [PATCH 05/29] drivers: convert suppress_bind_attrs parameter into flags Marek Szyprowski
2014-08-05 10:47 ` [PATCH 06/29] drivers: iommu: add notify about failed bind Marek Szyprowski
2014-08-05 10:47 ` [PATCH 07/29] ARM: dma-mapping: arm_iommu_attach_device: automatically set max_seg_size Marek Szyprowski
2014-08-05 10:47 ` [PATCH 08/29] ARM: dma-mapping: add helpers for managing default per-device dma mappings Marek Szyprowski
2014-08-05 10:47 ` [PATCH 09/29] ARM: dma-mapping: provide stubs if no ARM_DMA_USE_IOMMU has been selected Marek Szyprowski
2014-08-05 10:47 ` [PATCH 10/29] drivers: add DRIVER_HAS_OWN_IOMMU_MANAGER flag Marek Szyprowski
2014-09-01  5:22   ` Marek Szyprowski
2014-09-01  7:07     ` Thierry Reding
2014-09-01  7:53       ` Marek Szyprowski
2014-09-01  9:38         ` Arnd Bergmann
2014-09-01 10:47           ` Marek Szyprowski
2014-09-01 11:56             ` Arnd Bergmann
2014-09-01 12:07               ` Marek Szyprowski
2014-09-01 13:14                 ` [Linaro-mm-sig] " Arnd Bergmann
2014-08-05 10:47 ` [PATCH 11/29] DRM: exynos: add DRIVER_HAS_OWN_IOMMU_MANAGER flag to all sub-drivers Marek Szyprowski
2014-08-05 10:47 ` [PATCH 12/29] DRM: Exynos: fix window clear code Marek Szyprowski
2014-09-01 13:37   ` Inki Dae
2014-08-05 10:47 ` [PATCH 13/29] temporary: media: s5p-mfc: remove DT hacks & initialization custom memory init code Marek Szyprowski
2014-08-05 10:47 ` [PATCH 14/29] devicetree: Update Exynos SYSMMU device tree bindings Marek Szyprowski
2014-08-05 10:47 ` [PATCH 15/29] ARM: DTS: Exynos4: add System MMU nodes Marek Szyprowski
2014-08-05 10:47 ` [PATCH 16/29] iommu: exynos: make driver multiarch friendly Marek Szyprowski
2014-08-05 10:47 ` [PATCH 17/29] iommu: exynos: don't read version register on every tlb operation Marek Szyprowski
2014-08-05 10:47 ` [PATCH 18/29] iommu: exynos: remove unused functions Marek Szyprowski
2014-08-05 10:47 ` [PATCH 19/29] iommu: exynos: remove useless spinlock Marek Szyprowski
2014-08-05 10:47 ` [PATCH 20/29] iommu: exynos: refactor function parameters to simplify code Marek Szyprowski
2014-08-05 10:47 ` [PATCH 21/29] iommu: exynos: remove unused functions, part 2 Marek Szyprowski
2014-08-05 10:47 ` [PATCH 22/29] iommu: exynos: add support for binding more than one sysmmu to master device Marek Szyprowski
2014-08-05 10:47 ` [PATCH 23/29] iommu: exynos: init iommu controllers from device tree Marek Szyprowski
2014-08-05 10:47 ` [PATCH 24/29] iommu: exynos: create default iommu-based dma-mapping for master devices Marek Szyprowski
2014-08-05 10:47 ` [PATCH 25/29] iommu: exynos: add support for runtime_pm Marek Szyprowski
2014-08-05 10:47 ` [PATCH 26/29] iommu: exynos: rename variables to reflect their purpose Marek Szyprowski
2014-08-05 10:47 ` [PATCH 27/29] iommu: exynos: document internal structures Marek Szyprowski
2014-08-05 10:47 ` [PATCH 28/29] iommu: exynos: remove excessive includes and sort others alphabetically Marek Szyprowski
2014-08-05 10:47 ` [PATCH 29/29] temporary: media: s5p-mfc: add support for IOMMU Marek Szyprowski
2014-08-18 23:32 ` [PATCH 00/29] Exynos SYSMMU (IOMMU) integration with DT and DMA-mapping subsystem Joerg Roedel
2014-08-19  6:07   ` Marek Szyprowski
2014-08-19 11:39     ` Andreas Färber
2014-08-19 12:01       ` Marek Szyprowski
2014-08-19 12:30         ` Andreas Färber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407235677-26324-2-git-send-email-m.szyprowski@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=inki.dae@samsung.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=kgene.kim@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=pullip.cho@samsung.com \
    --cc=rjw@rjwysocki.net \
    --cc=robh@kernel.org \
    --cc=s.nawrocki@samsung.com \
    --cc=shaik.ameer@samsung.com \
    --cc=tomasz.figa@gmail.com \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).