linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Andi Kleen <andi@firstfloor.org>,
	pm list <linux-pm@lists.linux-foundation.org>,
	Zhang Rui <rui.zhang@intel.com>,
	Zhao Yakui <yakui.zhao@intel.com>, Pavel Machek <pavel@suse.cz>
Subject: [PATCH 2/8] PCI: Introduce platform_pci_power_manageable function
Date: Mon, 7 Jul 2008 03:32:02 +0200	[thread overview]
Message-ID: <200807070332.03032.rjw@sisk.pl> (raw)
In-Reply-To: <200807070330.02849.rjw@sisk.pl>

From: Rafael J. Wysocki <rjw@sisk.pl>

PCI: Introduce platform_pci_power_manageable function

Introduce function pointer platform_pci_power_manageable to be used
by the platform-related code to point to a function allowing us to
check if given device is power manageable by the platform.

Introduce acpi_pci_power_manageable() playing that role for ACPI.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/pci/pci-acpi.c |   19 +++++++++++++------
 drivers/pci/pci.c      |   40 ++++++++++++++++++++++++++++++----------
 drivers/pci/pci.h      |   26 ++++++++++++++++++++++----
 3 files changed, 65 insertions(+), 20 deletions(-)

Index: linux-next/drivers/pci/pci-acpi.c
===================================================================
--- linux-next.orig/drivers/pci/pci-acpi.c
+++ linux-next/drivers/pci/pci-acpi.c
@@ -215,7 +215,6 @@ acpi_status pci_osc_control_set(acpi_han
 }
 EXPORT_SYMBOL(pci_osc_control_set);
 
-#ifdef CONFIG_ACPI_SLEEP
 /*
  * _SxD returns the D-state with the highest power
  * (lowest D-state number) supported in the S-state "x".
@@ -259,7 +258,13 @@ static pci_power_t acpi_pci_choose_state
 	}
 	return PCI_POWER_ERROR;
 }
-#endif
+
+static bool acpi_pci_power_manageable(struct pci_dev *dev)
+{
+	acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
+
+	return handle ? acpi_bus_power_manageable(handle) : false;
+}
 
 static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
@@ -290,6 +295,11 @@ static int acpi_pci_set_power_state(stru
 	return -EINVAL;
 }
 
+static struct pci_platform_pm_ops acpi_pci_platform_pm = {
+	.is_manageable = acpi_pci_power_manageable,
+	.set_state = acpi_pci_set_power_state,
+	.choose_state = acpi_pci_choose_state,
+};
 
 /* ACPI bus type */
 static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
@@ -341,10 +351,7 @@ static int __init acpi_pci_init(void)
 	ret = register_acpi_bus_type(&acpi_pci_bus);
 	if (ret)
 		return 0;
-#ifdef	CONFIG_ACPI_SLEEP
-	platform_pci_choose_state = acpi_pci_choose_state;
-#endif
-	platform_pci_set_power_state = acpi_pci_set_power_state;
+	pci_set_platform_pm(&acpi_pci_platform_pm);
 	return 0;
 }
 arch_initcall(acpi_pci_init);
Index: linux-next/drivers/pci/pci.c
===================================================================
--- linux-next.orig/drivers/pci/pci.c
+++ linux-next/drivers/pci/pci.c
@@ -376,7 +376,32 @@ pci_restore_bars(struct pci_dev *dev)
 		pci_update_resource(dev, &dev->resource[i], i);
 }
 
-int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
+static struct pci_platform_pm_ops *pci_platform_pm;
+
+int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
+{
+	if (!ops->is_manageable || !ops->set_state || !ops->choose_state)
+		return -EINVAL;
+	pci_platform_pm = ops;
+	return 0;
+}
+
+static inline bool platform_pci_power_manageable(struct pci_dev *dev)
+{
+	return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false;
+}
+
+static inline int platform_pci_set_power_state(struct pci_dev *dev,
+                                                pci_power_t t)
+{
+	return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS;
+}
+
+static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
+{
+	return pci_platform_pm ?
+			pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR;
+}
 
 /**
  * pci_set_power_state - Set the power state of a PCI device
@@ -479,8 +504,7 @@ pci_set_power_state(struct pci_dev *dev,
 	 * Give firmware a chance to be called, such as ACPI _PRx, _PSx
 	 * Firmware method after native method ?
 	 */
-	if (platform_pci_set_power_state)
-		platform_pci_set_power_state(dev, state);
+	platform_pci_set_power_state(dev, state);
 
 	dev->current_state = state;
 
@@ -505,8 +529,6 @@ pci_set_power_state(struct pci_dev *dev,
 	return 0;
 }
 
-pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev);
- 
 /**
  * pci_choose_state - Choose the power state of a PCI device
  * @dev: PCI device to be suspended
@@ -524,11 +546,9 @@ pci_power_t pci_choose_state(struct pci_
 	if (!pci_find_capability(dev, PCI_CAP_ID_PM))
 		return PCI_D0;
 
-	if (platform_pci_choose_state) {
-		ret = platform_pci_choose_state(dev);
-		if (ret != PCI_POWER_ERROR)
-			return ret;
-	}
+	ret = platform_pci_choose_state(dev);
+	if (ret != PCI_POWER_ERROR)
+		return ret;
 
 	switch (state.event) {
 	case PM_EVENT_ON:
Index: linux-next/drivers/pci/pci.h
===================================================================
--- linux-next.orig/drivers/pci/pci.h
+++ linux-next/drivers/pci/pci.h
@@ -5,10 +5,28 @@ extern int pci_create_sysfs_dev_files(st
 extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
 extern void pci_cleanup_rom(struct pci_dev *dev);
 
-/* Firmware callbacks */
-extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev);
-extern int (*platform_pci_set_power_state)(struct pci_dev *dev,
-						pci_power_t state);
+/**
+ * Firmware PM callbacks
+ *
+ * @is_manageable - returns 'true' if given device is power manageable by the
+ *                  platform firmware
+ *
+ * @set_state - invokes the platform firmware to set the device's power state
+ *
+ * @choose_state - returns PCI power state of given device preferred by the
+ *                 platform; to be used during system-wide transitions from a
+ *                 sleeping state to the working state and vice versa
+ *
+ * If given platform is generally capable of power managing PCI devices, all of
+ * these callbacks are mandatory.
+ */
+struct pci_platform_pm_ops {
+	bool (*is_manageable)(struct pci_dev *dev);
+	int (*set_state)(struct pci_dev *dev, pci_power_t state);
+	pci_power_t (*choose_state)(struct pci_dev *dev);
+};
+
+extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
 
 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);

  parent reply	other threads:[~2008-07-07  1:34 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-01 21:56 [PATCH 0/9] PCI PM: Handling of PCI devices wake-up functionality (rev. 3) Rafael J. Wysocki
2008-07-01 22:00 ` [PATCH 1/9] PCI ACPI: Remove acpi_platform_enable_wakeup Rafael J. Wysocki
2008-07-01 22:03 ` [PATCH 2/9] ACPI: Introduce acpi_bus_power_manageable function Rafael J. Wysocki
2008-07-01 22:04 ` [PATCH 3/9] PCI: Introduce platform_pci_power_manageable function Rafael J. Wysocki
2008-07-01 22:05 ` [PATCH 4/9] PCI: Rework pci_set_power_state function (rev. 3) Rafael J. Wysocki
2008-07-01 22:06 ` [PATCH 5/9] ACPI: Introduce acpi_device_sleep_wake function Rafael J. Wysocki
2008-07-01 22:07 ` [PATCH 6/9] ACPI: Introduce new device wakeup flag 'prepared' Rafael J. Wysocki
2008-07-01 22:08 ` [PATCH 7/9] PCI ACPI: Rework PCI handling of wake-up (rev. 4) Rafael J. Wysocki
2008-07-02  7:30   ` Zhao Yakui
2008-07-02 10:16     ` Rafael J. Wysocki
2008-07-01 22:09 ` [PATCH 8/9] PCI PM: Introduce pci_prepare_to_sleep and pci_back_from_sleep Rafael J. Wysocki
2008-07-01 22:10 ` [PATCH 9/9] PCI: Simplify PCI device PM code (rev. 4) Rafael J. Wysocki
2008-07-03 12:04 ` [PATCH 0/9] PCI PM: Handling of PCI devices wake-up functionality (rev. 3) Rafael J. Wysocki
2008-07-07  1:30 ` [PATCH 0/8] PCI PM: Handling of PCI devices wake-up functionality (rev. 4) Rafael J. Wysocki
2008-07-07  1:30   ` [PATCH 1/8] ACPI: Introduce acpi_bus_power_manageable function Rafael J. Wysocki
2008-07-07  1:32   ` Rafael J. Wysocki [this message]
2008-07-07  1:32   ` [PATCH 3/8] PCI: Rework pci_set_power_state function (rev. 4) Rafael J. Wysocki
2008-07-07  1:33   ` [PATCH 4/8] ACPI: Introduce acpi_device_sleep_wake function Rafael J. Wysocki
2008-07-07  1:34   ` [PATCH 5/8] ACPI: Introduce new device wakeup flag 'prepared' Rafael J. Wysocki
2008-07-07 14:08     ` Pavel Machek
2008-07-07  1:34   ` [PATCH 6/8] PCI ACPI: Rework PCI handling of wake-up (rev. 5) Rafael J. Wysocki
2008-07-11 20:30     ` Pavel Machek
2008-07-07  1:35   ` [PATCH 7/8] PCI PM: Introduce pci_prepare_to_sleep and pci_back_from_sleep Rafael J. Wysocki
2008-07-11 20:31     ` Pavel Machek
2008-07-07  1:36   ` [PATCH 8/8] PCI: Simplify PCI device PM code (rev. 4) Rafael J. Wysocki
2008-07-11 20:37     ` Pavel Machek
2008-07-11 20:45       ` Rafael J. Wysocki
2008-07-11 20:49         ` Pavel Machek
2008-07-08  0:49   ` [PATCH 0/8] PCI PM: Handling of PCI devices wake-up functionality " Jesse Barnes
2008-07-08 14:42     ` Rafael J. Wysocki
2008-07-13 20:45   ` PCI PM: Fix pci_prepare_to_sleep Rafael J. Wysocki
2008-07-14 21:27     ` Jesse Barnes
2008-07-14 21:40       ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2008-06-26 22:22 [PATCH 0/8] PCI PM: Handling of PCI devices wake-up functionality (rev. 2) Rafael J. Wysocki
2008-06-26 22:24 ` [PATCH 2/8] PCI: Introduce platform_pci_power_manageable function Rafael J. Wysocki

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=200807070332.03032.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=andi@firstfloor.org \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@suse.cz \
    --cc=rui.zhang@intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=yakui.zhao@intel.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).