PCI run-time PM support (rev. 4)
Subsystems (6)
cover PCI run-time PM support (rev. 4)
Hi,
The following (updated) series of patches provides basic run-time power management support for PCI devices through ACPI and/or the native PCIe PME.
Patches [1/8] and [3/8] are unchanged, the other patches have been modified to address the reviewers' comments and/or to fix reported bugs.
[1/8] - Add function for checking PME status of devices
[2/8][Updated] - PCIe PME root port service driver
[3/8] - "Don't use MSIs for PME signaling" switch for PCIe
[4/8][New] - ACPI GPE refcounting, based on 3 patches from Matthew Garrett
[5/8][Updated] - ACPI, add fields for handling run-wake devices
[6/8][New] - ACPI, make it possible to use more than 1 notify handler per node
[7/8][Updated] - PCI / ACPI platform support for run-time power management
[8/8] - Runtime PM callbacks for the PCI bus type
Bob, Len, patches [4/8] and [6/8] are vitally important for this feature, but they cannot be merged without your approval. Please let me know if you have any objections to these patches.
Thanks,
Rafael
PATCH 1/8 PCI PM: Add function for checking PME status of devices
From: Rafael J. Wysocki <[email protected]>
Add function pci_check_pme_status() that will check the PME status bit of given device and clear it along with the PME enable bit. It will be necessary for PCI run-time power management.
Based on a patch from Shaohua Li <[email protected]>
--- drivers/pci/pci.c | 35 +++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 1 + 2 files changed, 36 insertions(+)
drivers/pci/pci.h +1 -0
@@ -49,6 +49,7 @@ struct pci_platform_pm_ops {extern int pci_set_platform_pm (struct pci_platform_pm_ops *ops);extern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_disable_enabled_device (struct pci_dev *dev); +extern bool pci_check_pme_status (struct pci_dev *dev);extern void pci_pm_init (struct pci_dev *dev);extern void platform_pci_wakeup_init (struct pci_dev *dev);extern void pci_allocate_cap_save_buffers (struct pci_dev *dev);
drivers/pci/pci.c +35 -0
@@ -1195,6 +1195,41 @@ int pci_set_pcie_reset_state(struct pci_ }/** +* pci_check_pme_status - Check if given device has generated PME. +* @dev: Device to check. +* +* Check the PME status of the device and if set, clear it and clear PME enable +* (if set). Return 'true' if PME status and PME enable were both set or +* 'false' otherwise. +*/ +bool pci_check_pme_status (struct pci_dev *dev) +{ +int pmcsr_pos; +u16 pmcsr; +bool ret = false; + +if (!dev->pm_cap) +return false; + + pmcsr_pos = dev->pm_cap +PCI_PM_CTRL ; +pci_read_config_word (dev, pmcsr_pos, &pmcsr); +if (!(pmcsr &PCI_PM_CTRL_PME_STATUS )) +return false; + +/* Clear PME status. */ + pmcsr |=PCI_PM_CTRL_PME_STATUS ; +if (pmcsr &PCI_PM_CTRL_PME_ENABLE ) { +/* Disable PME to avoid interrupt flood. */ + pmcsr &= ~PCI_PM_CTRL_PME_ENABLE ; + ret = true; + } + +pci_write_config_word (dev, pmcsr_pos, pmcsr); + +return ret; +} + +/** * pci_pme_capable - check the capability of PCI device to generate PME# * @dev: PCI device to handle. * @state: PCI state from which device will issue PME#.
Jesse Barnes
AppliedRe: [PATCH 1/8] PCI PM: Add function for checking PME status of devices
Quoted 10 lines · On Wed, 17 Feb 2010 23:36:58 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
Add function
pci_check_pme_status()that will check the PME status bit of given device and clear it along with the PME enable bit. It will be necessary for PCI run-time power management.Based on a patch from Shaohua Li <[email protected]>
Signed-off-by Rafael J. Wysocki <[email protected]>---
Applied this series and dropped the old patches, thanks Rafael.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Re: [PATCH 1/8] PCI PM: Add function for checking PME status of devices
Quoted 9 lines · Jesse Barnes
Quoted 6 lines · On Wed, 17 Feb 2010 23:36:58 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
Add function
pci_check_pme_status()that will check the PME status bit of given device and clear it along with the PME enable bit. It will be necessary for PCI run-time power management.
Quoted 6 lines
Quoted 4 lines
Based on a patch from Shaohua Li <[email protected]>
Signed-off-by Rafael J. Wysocki <[email protected]>---
Applied this series and dropped the old patches, thanks Rafael.
Great, thanks Jesse.
Re: [PATCH 1/8] PCI PM: Add function for checking PME status of devices
In reply to Jesse BarnesQuoted 9 lines · Jesse Barnes
Quoted 6 lines · On Wed, 17 Feb 2010 23:36:58 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
Add function
pci_check_pme_status()that will check the PME status bit of given device and clear it along with the PME enable bit. It will be necessary for PCI run-time power management.
Quoted 6 lines
Quoted 4 lines
Based on a patch from Shaohua Li <[email protected]>
Signed-off-by Rafael J. Wysocki <[email protected]>---
Applied this series and dropped the old patches, thanks Rafael.
Great, thanks Jesse.
Jesse Barnes
AppliedRe: [PATCH 1/8] PCI PM: Add function for checking PME status of devices
In reply to Rafael J. WysockiQuoted 10 lines · On Wed, 17 Feb 2010 23:36:58 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
Add function
pci_check_pme_status()that will check the PME status bit of given device and clear it along with the PME enable bit. It will be necessary for PCI run-time power management.Based on a patch from Shaohua Li <[email protected]>
Signed-off-by Rafael J. Wysocki <[email protected]>---
Applied this series and dropped the old patches, thanks Rafael.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
PATCH 1/8 PCI PM: Add function for checking PME status of devices
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Add function pci_check_pme_status() that will check the PME status bit of given device and clear it along with the PME enable bit. It will be necessary for PCI run-time power management.
Based on a patch from Shaohua Li <[email protected]>
--- drivers/pci/pci.c | 35 +++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 1 + 2 files changed, 36 insertions(+)
drivers/pci/pci.h +1 -0
@@ -49,6 +49,7 @@ struct pci_platform_pm_ops {extern int pci_set_platform_pm (struct pci_platform_pm_ops *ops);extern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_disable_enabled_device (struct pci_dev *dev); +extern bool pci_check_pme_status (struct pci_dev *dev);extern void pci_pm_init (struct pci_dev *dev);extern void platform_pci_wakeup_init (struct pci_dev *dev);extern void pci_allocate_cap_save_buffers (struct pci_dev *dev);
drivers/pci/pci.c +35 -0
@@ -1195,6 +1195,41 @@ int pci_set_pcie_reset_state(struct pci_ }/** +* pci_check_pme_status - Check if given device has generated PME. +* @dev: Device to check. +* +* Check the PME status of the device and if set, clear it and clear PME enable +* (if set). Return 'true' if PME status and PME enable were both set or +* 'false' otherwise. +*/ +bool pci_check_pme_status (struct pci_dev *dev) +{ +int pmcsr_pos; +u16 pmcsr; +bool ret = false; + +if (!dev->pm_cap) +return false; + + pmcsr_pos = dev->pm_cap +PCI_PM_CTRL ; +pci_read_config_word (dev, pmcsr_pos, &pmcsr); +if (!(pmcsr &PCI_PM_CTRL_PME_STATUS )) +return false; + +/* Clear PME status. */ + pmcsr |=PCI_PM_CTRL_PME_STATUS ; +if (pmcsr &PCI_PM_CTRL_PME_ENABLE ) { +/* Disable PME to avoid interrupt flood. */ + pmcsr &= ~PCI_PM_CTRL_PME_ENABLE ; + ret = true; + } + +pci_write_config_word (dev, pmcsr_pos, pmcsr); + +return ret; +} + +/** * pci_pme_capable - check the capability of PCI device to generate PME# * @dev: PCI device to handle. * @state: PCI state from which device will issue PME#.
PATCH 2/8 PCI PM: PCIe PME root port service driver (rev. 5)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
PCIe native PME detection mechanism is based on interrupts generated by root ports or event collectors every time a PCIe device sends a PME message upstream.
Once a PME message has been sent by an endpoint device and received by its root port (or event collector in the case of root complex integrated endpoints), the Requester ID from the message header is registered in the root port's Root Status register. At the same time, the PME Status bit of the Root Status register is set to indicate that there's a PME to handle. If PCIe PME interrupt is enabled for the root port, it generates an interrupt once the PME Status has been set. After receiving the interrupt, the kernel can identify the PCIe device that generated the PME using the Requester ID from the root port's Root Status register. [For details, see PCI Express Base Specification, Rev. 2.0.]
Implement a driver for the PCIe PME root port service working in accordance with the above description.
Based on a patch from Shaohua Li <[email protected]>.
--- Documentation/kernel-parameters.txt | 6 drivers/pci/pcie/Kconfig | 4 drivers/pci/pcie/Makefile | 2 drivers/pci/pcie/pme/Makefile | 8 drivers/pci/pcie/pme/pcie_pme.c | 493 +++++++++++++++++++++++++++++++++++ drivers/pci/pcie/pme/pcie_pme.h | 28 + drivers/pci/pcie/pme/pcie_pme_acpi.c | 54 +++ include/linux/pci.h | 1 8 files changed, 596 insertions(+)
drivers/pci/pcie/Kconfig +4 -0
@@ -46,3 +46,7 @@ config PCIEASPM_DEBUG help This enables PCI Express ASPM debug support. It will add per-device interface to control ASPM. + +config PCIE_PME + def_bool y + depends on PCIEPORTBUS && PM_RUNTIME && EXPERIMENTAL && ACPI
drivers/pci/pcie/Makefile +2 -0
@@ -11,3 +11,5 @@ obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv # Build PCI Express AER if needed obj-$(CONFIG_PCIEAER) += aer/ + +obj-$(CONFIG_PCIE_PME) += pme/
drivers/pci/pcie/pme/pcie_pme.c new file +493 -0
493 lines not on this page · raw message
drivers/pci/pcie/pme/pcie_pme_acpi.c new file +54 -0
54 lines not on this page · raw message
drivers/pci/pcie/pme/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Makefile for PCI-Express Root Port PME signaling driver +# + +obj-$(CONFIG_PCIE_PME) += pmedriver.o + +pmedriver-objs := pcie_pme.o +pmedriver-$(CONFIG_ACPI) += pcie_pme_acpi.o
drivers/pci/pcie/pme/pcie_pme.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* drivers/pci/pcie/pme/pcie_pme.h +* +* PCI Express Root Port PME signaling support +* +* Copyright (C) 2009 Rafael J. Wysocki <[email protected]>, Novell Inc. +*/ + +#ifndef _PCIE_PME_H_ +#define _PCIE_PME_H_ + +struct pcie_device ; + +#ifdef CONFIG_ACPI +extern int pcie_pme_acpi_setup (struct pcie_device *srv); + +static inline int pcie_pme_platform_notify (struct pcie_device *srv) +{ +return pcie_pme_acpi_setup (srv); +} +#else /* !CONFIG_ACPI */ +static inline int pcie_pme_platform_notify (struct pcie_device *srv) +{ +return 0 ; +} +#endif /* !CONFIG_ACPI */ + +#endif
include/linux/pci.h +1 -0
@@ -239,6 +239,7 @@ struct pci_dev {configuration space */ unsigned int pme_support:5; /* Bitmask of states from which PME#can be generated */ + unsigned int pme_interrupt:1; unsigned int d1_support:1; /* Low power state D1 is supported */ unsigned int d2_support:1; /* Low power state D2 is supported */ unsigned int no_d1d2:1; /* Only allow D0 and D3 */
Documentation/kernel-parameters.txt +6 -0
@@ -1989,6 +1989,12 @@ and is between 256 and 4096 characters. force Enable ASPM even on devices that claim not to support it. WARNING: Forcing ASPM on may cause system lockups. + pcie_pme= [PCIE,PM] Native PCIe PME signaling options: + off Do not use native PCIe PME signaling. + force Use native PCIe PME signaling even if the BIOS refuses + to allow the kernel to control the relevant PCIe config + registers. + pcmv= [HW,PCMCIA] BadgePAD 4 pd. [PARIDE]
Re: [PATCH 2/8] PCI PM: PCIe PME root port service driver (rev. 5)
Hi,
I'm sorry for the delayed comments.
drivers/pci/pcie/pme/pcie_pme.c line 96
Quoted 12 lines
drivers/pci/pcie/pme/pcie_pme.c new file +12
-0+ +/** +* pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation. +* @dev: PCIe root port or event collector. +* @enable: Enable or disable the interrupt. +*/ +static void pcie_pme_interrupt_enable (struct pci_dev *dev,bool enable) +{ +int rtctl_pos; +u16 rtctl; + + rtctl_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTCTL ;
How about
rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
?
The pci_pcie_cap() returns PCIe capability offset saved in struct pci_dev. By using this, we can avoid redundant search in PCI configuration space.
drivers/pci/pcie/pme/pcie_pme.c line 115
Quoted 11 lines
drivers/pci/pcie/pme/pcie_pme.c new file +11
-0+ +/** +* pcie_pme_clear_status - Clear root port PME interrupt status. +* @dev: PCIe root port or event collector. +*/ +static void pcie_pme_clear_status (struct pci_dev *dev) +{ +int rtsta_pos; +u32 rtsta; + + rtsta_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTSTA ;
Ditto.
drivers/pci/pcie/pme/pcie_pme.c line 269
Quoted 13 lines
drivers/pci/pcie/pme/pcie_pme.c new file +13
-0+/** +* pcie_pme_work_fn - Work handler for PCIe PME interrupt. +* @work: Work structure giving access to service data. +*/ +static void pcie_pme_work_fn (struct work_struct *work) +{ +struct pcie_pme_service_data *data = + container_of(work, struct pcie_pme_service_data, work); +struct pci_dev *port = data->srv->port; +int rtsta_pos; +u32 rtsta; + + rtsta_pos =pci_find_capability (port,PCI_CAP_ID_EXP ) +PCI_EXP_RTSTA ;
Ditto.
Quoted 7 lines
drivers/pci/pcie/pme/pcie_pme.c new file +7
-0+/** +* pcie_pme_irq - Interrupt handler for PCIe root port PME interrupt. +* @irq: Interrupt vector. +* @context: Interrupt context pointer. +*/ +static irqreturn_t pcie_pme_irq (int irq,void *context) +{
drivers/pci/pcie/pme/pcie_pme.c line 323
Quoted 10 lines
drivers/pci/pcie/pme/pcie_pme.c new file +10
-0+struct pci_dev *port; +struct pcie_pme_service_data *data; +int rtsta_pos; +u32 rtsta; +unsigned long flags; + + port = ((struct pcie_device *)context)->port; + data =get_service_data ((struct pcie_device *)context); + + rtsta_pos =pci_find_capability (port,PCI_CAP_ID_EXP ) +PCI_EXP_RTSTA ;
Ditto.
Thanks,
Kenji Kaneshige
Re: [PATCH 2/8] PCI PM: PCIe PME root port service driver (rev. 5)
Quoted 19 lines · Kenji Kaneshige
Hi,
I'm sorry for the delayed comments.
drivers/pci/pcie/pme/pcie_pme.c line 96
Quoted 12 lines
drivers/pci/pcie/pme/pcie_pme.c new file +12
-0+ +/** +* pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation. +* @dev: PCIe root port or event collector. +* @enable: Enable or disable the interrupt. +*/ +static void pcie_pme_interrupt_enable (struct pci_dev *dev,bool enable) +{ +int rtctl_pos; +u16 rtctl; + + rtctl_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTCTL ;How about
Quoted 6 lines
rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;?
The
pci_pcie_cap()returns PCIe capability offset saved in structpci_dev. By using this, we can avoid redundant search in PCI configuration space.
While I agree with the comment, I'd prefer to change this with a separate patch, unless the entire patchset misses the merge window.
Rafael
Re: [PATCH 2/8] PCI PM: PCIe PME root port service driver (rev. 5)
Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Kenji Kaneshige
Hi,
I'm sorry for the delayed comments.
drivers/pci/pcie/pme/pcie_pme.c line 96
Quoted 12 lines
drivers/pci/pcie/pme/pcie_pme.c new file +12
-0+ +/** +* pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation. +* @dev: PCIe root port or event collector. +* @enable: Enable or disable the interrupt. +*/ +static void pcie_pme_interrupt_enable (struct pci_dev *dev,bool enable) +{ +int rtctl_pos; +u16 rtctl; + + rtctl_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTCTL ;How about
rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
Quoted 8 lines
Quoted 4 lines
?
The
pci_pcie_cap()returns PCIe capability offset saved in structpci_dev. By using this, we can avoid redundant search in PCI configuration space.While I agree with the comment, I'd prefer to change this with a separate patch, unless the entire patchset misses the merge window.
Ok. Actually, I didn't realize your set of patches was already in linux-next, sorry. I'll send a patch as a separate one.
Thanks,
Kenji Kaneshige
Re: [PATCH 2/8] PCI PM: PCIe PME root port service driver (rev. 5)
In reply to Rafael J. WysockiQuoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Kenji Kaneshige
Hi,
I'm sorry for the delayed comments.
drivers/pci/pcie/pme/pcie_pme.c line 96
Quoted 12 lines
drivers/pci/pcie/pme/pcie_pme.c new file +12
-0+ +/** +* pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation. +* @dev: PCIe root port or event collector. +* @enable: Enable or disable the interrupt. +*/ +static void pcie_pme_interrupt_enable (struct pci_dev *dev,bool enable) +{ +int rtctl_pos; +u16 rtctl; + + rtctl_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTCTL ;How about
rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
Quoted 8 lines
Quoted 4 lines
?
The
pci_pcie_cap()returns PCIe capability offset saved in structpci_dev. By using this, we can avoid redundant search in PCI configuration space.While I agree with the comment, I'd prefer to change this with a separate patch, unless the entire patchset misses the merge window.
Ok. Actually, I didn't realize your set of patches was already in linux-next, sorry. I'll send a patch as a separate one.
Thanks,
Kenji Kaneshige
Re: [PATCH 2/8] PCI PM: PCIe PME root port service driver (rev. 5)
In reply to Kenji KaneshigeQuoted 19 lines · Kenji Kaneshige
Hi,
I'm sorry for the delayed comments.
drivers/pci/pcie/pme/pcie_pme.c line 96
Quoted 12 lines
drivers/pci/pcie/pme/pcie_pme.c new file +12
-0+ +/** +* pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation. +* @dev: PCIe root port or event collector. +* @enable: Enable or disable the interrupt. +*/ +static void pcie_pme_interrupt_enable (struct pci_dev *dev,bool enable) +{ +int rtctl_pos; +u16 rtctl; + + rtctl_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTCTL ;How about
Quoted 6 lines
rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;?
The
pci_pcie_cap()returns PCIe capability offset saved in structpci_dev. By using this, we can avoid redundant search in PCI configuration space.
While I agree with the comment, I'd prefer to change this with a separate patch, unless the entire patchset misses the merge window.
Rafael
Re: [PATCH 2/8] PCI PM: PCIe PME root port service driver (rev. 5)
In reply to Rafael J. WysockiHi,
I'm sorry for the delayed comments.
drivers/pci/pcie/pme/pcie_pme.c line 96
Quoted 12 lines
drivers/pci/pcie/pme/pcie_pme.c new file +12
-0+ +/** +* pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation. +* @dev: PCIe root port or event collector. +* @enable: Enable or disable the interrupt. +*/ +static void pcie_pme_interrupt_enable (struct pci_dev *dev,bool enable) +{ +int rtctl_pos; +u16 rtctl; + + rtctl_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTCTL ;
How about
rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
?
The pci_pcie_cap() returns PCIe capability offset saved in struct pci_dev. By using this, we can avoid redundant search in PCI configuration space.
drivers/pci/pcie/pme/pcie_pme.c line 115
Quoted 11 lines
drivers/pci/pcie/pme/pcie_pme.c new file +11
-0+ +/** +* pcie_pme_clear_status - Clear root port PME interrupt status. +* @dev: PCIe root port or event collector. +*/ +static void pcie_pme_clear_status (struct pci_dev *dev) +{ +int rtsta_pos; +u32 rtsta; + + rtsta_pos =pci_find_capability (dev,PCI_CAP_ID_EXP ) +PCI_EXP_RTSTA ;
Ditto.
drivers/pci/pcie/pme/pcie_pme.c line 269
Quoted 13 lines
drivers/pci/pcie/pme/pcie_pme.c new file +13
-0+/** +* pcie_pme_work_fn - Work handler for PCIe PME interrupt. +* @work: Work structure giving access to service data. +*/ +static void pcie_pme_work_fn (struct work_struct *work) +{ +struct pcie_pme_service_data *data = + container_of(work, struct pcie_pme_service_data, work); +struct pci_dev *port = data->srv->port; +int rtsta_pos; +u32 rtsta; + + rtsta_pos =pci_find_capability (port,PCI_CAP_ID_EXP ) +PCI_EXP_RTSTA ;
Ditto.
Quoted 7 lines
drivers/pci/pcie/pme/pcie_pme.c new file +7
-0+/** +* pcie_pme_irq - Interrupt handler for PCIe root port PME interrupt. +* @irq: Interrupt vector. +* @context: Interrupt context pointer. +*/ +static irqreturn_t pcie_pme_irq (int irq,void *context) +{
drivers/pci/pcie/pme/pcie_pme.c line 323
Quoted 10 lines
drivers/pci/pcie/pme/pcie_pme.c new file +10
-0+struct pci_dev *port; +struct pcie_pme_service_data *data; +int rtsta_pos; +u32 rtsta; +unsigned long flags; + + port = ((struct pcie_device *)context)->port; + data =get_service_data ((struct pcie_device *)context); + + rtsta_pos =pci_find_capability (port,PCI_CAP_ID_EXP ) +PCI_EXP_RTSTA ;
Ditto.
Thanks,
Kenji Kaneshige
PATCH 3/8 PCI PM: Make it possible to force using INTx for PCIe PME signaling
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Apparently, some machines may have problems with PCI run-time power management if MSIs are used for the native PCIe PME signaling. In particular, on the MSI Wind U-100 PCIe PME interrupts are not generated by a PCIe root port after a resume from suspend to RAM, if the system wake-up was triggered by a PME from the device attached to this port. [It doesn't help to free the interrupt on suspend and request it back on resume, even if that is done along with disabling the MSI and re-enabling it, respectively.] However, if INTx interrupts are used for this purpose on the same machine, everything works just fine.
For this reason, add a kernel command line switch allowing one to request that MSIs be not used for the native PCIe PME signaling, introduce a DMI table allowing us to blacklist machines that need this switch to be set by default and put the MSI Wind U-100 into this table.
--- Documentation/kernel-parameters.txt | 2 ++ drivers/pci/pcie/pme/pcie_pme.c | 14 +++++++++++++- drivers/pci/pcie/portdrv.h | 17 +++++++++++++++++ drivers/pci/pcie/portdrv_core.c | 12 ++++++++++-- drivers/pci/pcie/portdrv_pci.c | 27 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-)
drivers/pci/pcie/pme/pcie_pme.c +13 -1
@@ -53,12 +53,22 @@ static bool pcie_pme_disabled;*/ static bool pcie_pme_force_enable; +/* +* If this switch is set, MSI will not be used for PCIe PME signaling. This +* causes the PCIe port driver to use INTx interrupts only, but it turns out +* that using MSI for PCIe PME signaling doesn't play well with PCIe PME-based +* wake-up from system sleep states. +*/ +bool pcie_pme_msi_disabled; +static int __init pcie_pme_setup (char *str) {if (!strcmp (str,"off" )) pcie_pme_disabled = true;else if (!strcmp (str,"force" )) pcie_pme_force_enable = true; +else if (!strcmp (str,"nomsi" )) + pcie_pme_msi_disabled = true;return 1 ; }__setup ("pcie_pme=" , pcie_pme_setup);
@@ -73,7 +83,9 @@ __setup("pcie_pme=", pcie_pme_setup);*/ static bool pcie_pme_platform_setup (struct pcie_device *srv) { -return !pcie_pme_platform_notify (srv) || pcie_pme_force_enable; +if (!pcie_pme_platform_notify (srv)) +return true; +return pcie_pme_force_enable; }struct pcie_pme_service_data {
drivers/pci/pcie/portdrv_core.c +10 -2
@@ -186,16 +186,24 @@ static int pcie_port_enable_msix(struct*/ static int init_service_irqs (struct pci_dev *dev,int *irqs,int mask) { -int i, irq; +int i, irq =-1 ; + +/* We have to use INTx if MSI cannot be used for PCIe PME. */ +if ((mask &PCIE_PORT_SERVICE_PME ) &&pcie_pme_no_msi ()) { +if (dev->pin) + irq = dev->irq; + goto no_msi; + }/* Try to use MSI-X if supported */ if (!pcie_port_enable_msix (dev, irqs, mask))return 0 ; +/* We're not going to use MSI-X, so try MSI and fall back to INTx */ - irq =-1 ;if (!pci_enable_msi (dev) || dev->pin) irq = dev->irq; + no_msi:for (i =0 ; i <PCIE_PORT_DEVICE_MAXSERVICES ; i++) irqs[i] = irq; irqs[PCIE_PORT_SERVICE_VC_SHIFT ] =-1 ;
drivers/pci/pcie/portdrv_pci.c +27 -0
@@ -15,6 +15,7 @@#include <linux/slab.h> #include <linux/pcieport_if.h> #include <linux/aer.h> +#include <linux/dmi.h> #include "portdrv.h" #include "aer/aerdrv.h"
@@ -273,10 +274,36 @@ static struct pci_driver pcie_portdriver .driver.pm = PCIE_PORTDRV_PM_OPS, }; +static int __init dmi_pcie_pme_disable_msi (const struct dmi_system_id *d) +{ +pr_notice ("%s detected: will not use MSI for PCIe PME signaling\n" , + d->ident); +pcie_pme_disable_msi (); +return 0 ; +} + +static struct dmi_system_id __initdata pcie_portdrv_dmi_table[] = { +/* +* Boxes that should not use MSI for PCIe PME signaling. +*/ + { + .callback = dmi_pcie_pme_disable_msi, + .ident ="MSI Wind U-100" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR , +"MICRO-STAR INTERNATIONAL CO., LTD" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"U-100" ), + }, + }, + {} +}; +static int __init pcie_portdrv_init (void ) {int retval; +dmi_check_system (pcie_portdrv_dmi_table); + retval =pcie_port_bus_register ();if (retval) {printk (KERN_WARNING "PCIE: bus_register error: %d\n" , retval);
drivers/pci/pcie/portdrv.h +17 -0
@@ -30,4 +30,21 @@ extern void pcie_port_device_remove(struextern int __must_check pcie_port_bus_register (void );extern void pcie_port_bus_unregister (void ); +#ifdef CONFIG_PCIE_PME +extern bool pcie_pme_msi_disabled; + +static inline void pcie_pme_disable_msi (void ) +{ + pcie_pme_msi_disabled = true; +} + +static inline bool pcie_pme_no_msi (void ) +{ +return pcie_pme_msi_disabled; +} +#else /* !CONFIG_PCIE_PME */ +static inline void pcie_pme_disable_msi (void ) {} +static inline bool pcie_pme_no_msi (void ) {return false; } +#endif /* !CONFIG_PCIE_PME */ +#endif /* _PORTDRV_H_ */
Documentation/kernel-parameters.txt +2 -0
@@ -1994,6 +1994,8 @@ and is between 256 and 4096 characters. force Use native PCIe PME signaling even if the BIOS refuses to allow the kernel to control the relevant PCIe config registers. + nomsi Do not use MSI for native PCIe PME signaling (this makes + all PCIe root ports use INTx for everything). pcmv= [HW,PCMCIA] BadgePAD 4
PATCH 3/8 PCI PM: Make it possible to force using INTx for PCIe PME signaling
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Apparently, some machines may have problems with PCI run-time power management if MSIs are used for the native PCIe PME signaling. In particular, on the MSI Wind U-100 PCIe PME interrupts are not generated by a PCIe root port after a resume from suspend to RAM, if the system wake-up was triggered by a PME from the device attached to this port. [It doesn't help to free the interrupt on suspend and request it back on resume, even if that is done along with disabling the MSI and re-enabling it, respectively.] However, if INTx interrupts are used for this purpose on the same machine, everything works just fine.
For this reason, add a kernel command line switch allowing one to request that MSIs be not used for the native PCIe PME signaling, introduce a DMI table allowing us to blacklist machines that need this switch to be set by default and put the MSI Wind U-100 into this table.
--- Documentation/kernel-parameters.txt | 2 ++ drivers/pci/pcie/pme/pcie_pme.c | 14 +++++++++++++- drivers/pci/pcie/portdrv.h | 17 +++++++++++++++++ drivers/pci/pcie/portdrv_core.c | 12 ++++++++++-- drivers/pci/pcie/portdrv_pci.c | 27 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-)
drivers/pci/pcie/pme/pcie_pme.c +13 -1
@@ -53,12 +53,22 @@ static bool pcie_pme_disabled;*/ static bool pcie_pme_force_enable; +/* +* If this switch is set, MSI will not be used for PCIe PME signaling. This +* causes the PCIe port driver to use INTx interrupts only, but it turns out +* that using MSI for PCIe PME signaling doesn't play well with PCIe PME-based +* wake-up from system sleep states. +*/ +bool pcie_pme_msi_disabled; +static int __init pcie_pme_setup (char *str) {if (!strcmp (str,"off" )) pcie_pme_disabled = true;else if (!strcmp (str,"force" )) pcie_pme_force_enable = true; +else if (!strcmp (str,"nomsi" )) + pcie_pme_msi_disabled = true;return 1 ; }__setup ("pcie_pme=" , pcie_pme_setup);
@@ -73,7 +83,9 @@ __setup("pcie_pme=", pcie_pme_setup);*/ static bool pcie_pme_platform_setup (struct pcie_device *srv) { -return !pcie_pme_platform_notify (srv) || pcie_pme_force_enable; +if (!pcie_pme_platform_notify (srv)) +return true; +return pcie_pme_force_enable; }struct pcie_pme_service_data {
drivers/pci/pcie/portdrv_core.c +10 -2
@@ -186,16 +186,24 @@ static int pcie_port_enable_msix(struct*/ static int init_service_irqs (struct pci_dev *dev,int *irqs,int mask) { -int i, irq; +int i, irq =-1 ; + +/* We have to use INTx if MSI cannot be used for PCIe PME. */ +if ((mask &PCIE_PORT_SERVICE_PME ) &&pcie_pme_no_msi ()) { +if (dev->pin) + irq = dev->irq; + goto no_msi; + }/* Try to use MSI-X if supported */ if (!pcie_port_enable_msix (dev, irqs, mask))return 0 ; +/* We're not going to use MSI-X, so try MSI and fall back to INTx */ - irq =-1 ;if (!pci_enable_msi (dev) || dev->pin) irq = dev->irq; + no_msi:for (i =0 ; i <PCIE_PORT_DEVICE_MAXSERVICES ; i++) irqs[i] = irq; irqs[PCIE_PORT_SERVICE_VC_SHIFT ] =-1 ;
drivers/pci/pcie/portdrv_pci.c +27 -0
@@ -15,6 +15,7 @@#include <linux/slab.h> #include <linux/pcieport_if.h> #include <linux/aer.h> +#include <linux/dmi.h> #include "portdrv.h" #include "aer/aerdrv.h"
@@ -273,10 +274,36 @@ static struct pci_driver pcie_portdriver .driver.pm = PCIE_PORTDRV_PM_OPS, }; +static int __init dmi_pcie_pme_disable_msi (const struct dmi_system_id *d) +{ +pr_notice ("%s detected: will not use MSI for PCIe PME signaling\n" , + d->ident); +pcie_pme_disable_msi (); +return 0 ; +} + +static struct dmi_system_id __initdata pcie_portdrv_dmi_table[] = { +/* +* Boxes that should not use MSI for PCIe PME signaling. +*/ + { + .callback = dmi_pcie_pme_disable_msi, + .ident ="MSI Wind U-100" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR , +"MICRO-STAR INTERNATIONAL CO., LTD" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"U-100" ), + }, + }, + {} +}; +static int __init pcie_portdrv_init (void ) {int retval; +dmi_check_system (pcie_portdrv_dmi_table); + retval =pcie_port_bus_register ();if (retval) {printk (KERN_WARNING "PCIE: bus_register error: %d\n" , retval);
drivers/pci/pcie/portdrv.h +17 -0
@@ -30,4 +30,21 @@ extern void pcie_port_device_remove(struextern int __must_check pcie_port_bus_register (void );extern void pcie_port_bus_unregister (void ); +#ifdef CONFIG_PCIE_PME +extern bool pcie_pme_msi_disabled; + +static inline void pcie_pme_disable_msi (void ) +{ + pcie_pme_msi_disabled = true; +} + +static inline bool pcie_pme_no_msi (void ) +{ +return pcie_pme_msi_disabled; +} +#else /* !CONFIG_PCIE_PME */ +static inline void pcie_pme_disable_msi (void ) {} +static inline bool pcie_pme_no_msi (void ) {return false; } +#endif /* !CONFIG_PCIE_PME */ +#endif /* _PORTDRV_H_ */
Documentation/kernel-parameters.txt +2 -0
@@ -1994,6 +1994,8 @@ and is between 256 and 4096 characters. force Use native PCIe PME signaling even if the BIOS refuses to allow the kernel to control the relevant PCIe config registers. + nomsi Do not use MSI for native PCIe PME signaling (this makes + all PCIe root ports use INTx for everything). pcmv= [HW,PCMCIA] BadgePAD 4
PATCH 4/8 ACPI: Use GPE reference counting to support shared GPEs
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
ACPI GPEs may map to multiple devices. The current GPE interface only provides a mechanism for enabling and disabling GPEs, making it difficult to change the state of GPEs at runtime without extensive cooperation between devices.
Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.
Remove the old GPE type handling entirely, which gets rid of various quirks, like the implicit disabling with GPE type setting. This requires a small amount of rework in order to ensure that non-wake GPEs are enabled by default to preserve existing behaviour.
Based on patches from Matthew Garrett <[email protected]>.
--- drivers/acpi/acpica/acevents.h | 6 - drivers/acpi/acpica/aclocal.h | 2 drivers/acpi/acpica/evgpe.c | 153 ++++------------------------------------- drivers/acpi/acpica/evgpeblk.c | 87 ++++++++--------------- drivers/acpi/acpica/evxface.c | 14 --- drivers/acpi/acpica/evxfevnt.c | 90 +++++++++++++++++------- drivers/acpi/button.c | 13 ++- drivers/acpi/ec.c | 14 ++- drivers/acpi/sleep.c | 15 +++- drivers/acpi/system.c | 4 - drivers/acpi/wakeup.c | 81 +++++++-------------- include/acpi/acpixf.h | 6 - include/acpi/actypes.h | 28 ++----- 13 files changed, 188 insertions(+), 325 deletions(-)
drivers/acpi/acpica/aclocal.h +2 -0
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {struct acpi_gpe_register_info *register_info;/* Backpointer to register info */ u8 flags;/* Misc info about this GPE */ u8 gpe_number;/* This GPE */ +u8 runtime_count; +u8 wakeup_count; };/* Information about a GPE register pair, one per each status/enable pair in an array */
drivers/acpi/acpica/evxfevnt.c +65 -25
165 lines not on this page · raw message
include/acpi/acpixf.h +3 -3
@@ -281,11 +281,11 @@ acpi_status acpi_get_event_status(u32 ev/* * GPE Interfaces */ -acpi_status acpi_set_gpe_type (acpi_handle gpe_device,u32 gpe_number,u8 type); +acpi_status acpi_set_gpe (acpi_handle gpe_device,u32 gpe_number,u8 action); -acpi_status acpi_enable_gpe (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_enable_gpe (acpi_handle gpe_device,u32 gpe_number,u8 type); -acpi_status acpi_disable_gpe (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_disable_gpe (acpi_handle gpe_device,u32 gpe_number,u8 type);acpi_status acpi_clear_gpe (acpi_handle gpe_device,u32 gpe_number,u32 flags);
drivers/acpi/button.c +9 -4
@@ -422,11 +422,9 @@ static int acpi_button_add(struct acpi_dif (device->wakeup.flags.valid) {/* Button's GPE is run-wake GPE */ -acpi_set_gpe_type (device->wakeup.gpe_device, - device->wakeup.gpe_number, -ACPI_GPE_TYPE_WAKE_RUN );acpi_enable_gpe (device->wakeup.gpe_device, - device->wakeup.gpe_number); + device->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE_RUN ); device->wakeup.state.enabled =1 ; }
@@ -446,6 +444,13 @@ static int acpi_button_remove(struct acp {struct acpi_button *button =acpi_driver_data (device); +if (device->wakeup.flags.valid) { +acpi_disable_gpe (device->wakeup.gpe_device, + device->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE_RUN ); + device->wakeup.state.enabled =0 ; + } +acpi_button_remove_fs (device);input_unregister_device (button->input);kfree (button);
drivers/acpi/ec.c +8 -6
@@ -307,7 +307,7 @@ static int acpi_ec_transaction(struct acpr_debug (PREFIX "transaction start\n" );/* disable GPE during transaction if storm is detected */ if (test_bit (EC_FLAGS_GPE_STORM , &ec->flags)) { -acpi_disable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_DISABLE ); } status =acpi_ec_transaction_unlocked (ec, t);
@@ -317,7 +317,7 @@ static int acpi_ec_transaction(struct acif (test_bit (EC_FLAGS_GPE_STORM , &ec->flags)) {msleep (1 );/* it is safe to enable GPE outside of transaction */ -acpi_enable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_ENABLE ); }else if (t->irq_count >ACPI_EC_STORM_THRESHOLD ) {pr_info (PREFIX "GPE storm detected, " "transactions will use polling mode\n" );
@@ -788,8 +788,8 @@ static int ec_install_handlers(struct ac &acpi_ec_gpe_handler, ec);if (ACPI_FAILURE (status))return -ENODEV ; -acpi_set_gpe_type (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME ); -acpi_enable_gpe (NULL , ec->gpe); + +acpi_enable_gpe (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME ); status = acpi_install_address_space_handler(ec->handle, ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
@@ -806,6 +806,7 @@ static int ec_install_handlers(struct ac }else {acpi_remove_gpe_handler (NULL , ec->gpe, &acpi_ec_gpe_handler); +acpi_disable_gpe (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME );return -ENODEV ; } }
@@ -816,6 +817,7 @@ static int ec_install_handlers(struct acstatic void ec_remove_handlers (struct acpi_ec *ec) { +acpi_disable_gpe (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME );if (ACPI_FAILURE (acpi_remove_address_space_handler (ec->handle,ACPI_ADR_SPACE_EC , &acpi_ec_space_handler)))pr_err (PREFIX "failed to remove space handler\n" );
@@ -1058,7 +1060,7 @@ static int acpi_ec_suspend(struct acpi_d {struct acpi_ec *ec =acpi_driver_data (device);/* Stop using GPE */ -acpi_disable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_DISABLE );return 0 ; }
@@ -1066,7 +1068,7 @@ static int acpi_ec_resume(struct acpi_de {struct acpi_ec *ec =acpi_driver_data (device);/* Enable use of GPE back */ -acpi_enable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_ENABLE );return 0 ; }
drivers/acpi/sleep.c +12 -3
@@ -745,9 +745,18 @@ int acpi_pm_device_sleep_wake(struct devreturn -ENODEV ; } - error = enable ? -acpi_enable_wakeup_device_power (adev, acpi_target_sleep_state) : -acpi_disable_wakeup_device_power (adev); +if (enable) { + error =acpi_enable_wakeup_device_power (adev, + acpi_target_sleep_state); +if (!error) +acpi_enable_gpe (adev->wakeup.gpe_device, + adev->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE ); + }else { +acpi_disable_gpe (adev->wakeup.gpe_device, adev->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE ); + error =acpi_disable_wakeup_device_power (adev); + }if (!error)dev_info (dev,"wake-up capability %s by ACPI\n" , enable ?"enabled" :"disabled" );
drivers/acpi/wakeup.c +27 -54
127 lines not on this page · raw message
drivers/acpi/acpica/acevents.h +1 -5
@@ -76,8 +76,7 @@ acpi_ev_queue_notify_request(struct acpi* evgpe - GPE handling and dispatch */ acpi_status -acpi_ev_update_gpe_enable_masks (struct acpi_gpe_event_info *gpe_event_info, -u8 type); +acpi_ev_update_gpe_enable_masks (struct acpi_gpe_event_info *gpe_event_info); acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
@@ -122,9 +121,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_eveu32 acpi_ev_gpe_detect (struct acpi_gpe_xrupt_info *gpe_xrupt_list);acpi_status -acpi_ev_set_gpe_type (struct acpi_gpe_event_info *gpe_event_info,u8 type); - -acpi_status acpi_ev_check_for_wake_only_gpe (struct acpi_gpe_event_info *gpe_event_info);acpi_status acpi_ev_gpe_initialize (void );
drivers/acpi/acpica/evgpe.c +16 -137
196 lines not on this page · raw message
drivers/acpi/acpica/evgpeblk.c +33 -54
150 lines not on this page · raw message
drivers/acpi/acpica/evxface.c +0 -14
@@ -617,13 +617,6 @@ acpi_install_gpe_handler(acpi_handle gpe handler->context = context; handler->method_node = gpe_event_info->dispatch.method_node; -/* Disable the GPE before installing the handler */ - - status =acpi_ev_disable_gpe (gpe_event_info); -if (ACPI_FAILURE (status)) { - goto unlock_and_exit; - } -/* Install the handler */ flags =acpi_os_acquire_lock (acpi_gbl_gpe_lock);
@@ -707,13 +700,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_ goto unlock_and_exit; } -/* Disable the GPE before removing the handler */ - - status =acpi_ev_disable_gpe (gpe_event_info); -if (ACPI_FAILURE (status)) { - goto unlock_and_exit; - } -/* Make sure all deferred tasks are completed */ (void )acpi_ut_release_mutex (ACPI_MTX_EVENTS );
include/acpi/actypes.h +10 -18
@@ -668,15 +668,16 @@ typedef u32 acpi_event_status;/* * GPE info flags - Per GPE -* +-+-+-+---+---+-+ -* |7|6|5|4:3|2:1|0| -* +-+-+-+---+---+-+ -* | | | | | | -* | | | | | +--- Interrupt type: Edge or Level Triggered -* | | | | +--- Type: Wake-only, Runtime-only, or wake/runtime +* +-+-+-+---+-+-+-+ +* |7|6|5|4:3|2|1|0| +* +-+-+-+---+-+-+-+ +* | | | | | | | +* | | | | | | +--- Interrupt type: Edge or Level Triggered +* | | | | | +--- GPE can wake the system +* | | | | +--- Unused * | | | +--- Type of dispatch -- to method, handler, or none -* | | +--- Enabled for runtime? -* | +--- Enabled for wake? +* | | +--- Unused +* | +--- Unused * +--- Unused */ #define ACPI_GPE_XRUPT_TYPE_MASK (u8) 0x01
@@ -687,22 +688,13 @@ typedef u32 acpi_event_status;#define ACPI_GPE_TYPE_WAKE_RUN (u8) 0x06#define ACPI_GPE_TYPE_WAKE (u8) 0x02#define ACPI_GPE_TYPE_RUNTIME (u8) 0x04/* Default */ +#define ACPI_GPE_CAN_WAKE (u8) 0x02#define ACPI_GPE_DISPATCH_MASK (u8) 0x18#define ACPI_GPE_DISPATCH_HANDLER (u8) 0x08#define ACPI_GPE_DISPATCH_METHOD (u8) 0x10#define ACPI_GPE_DISPATCH_NOT_USED (u8) 0x00/* Default */ -#define ACPI_GPE_RUN_ENABLE_MASK (u8) 0x20 -#define ACPI_GPE_RUN_ENABLED (u8) 0x20 -#define ACPI_GPE_RUN_DISABLED (u8) 0x00/* Default */ - -#define ACPI_GPE_WAKE_ENABLE_MASK (u8) 0x40 -#define ACPI_GPE_WAKE_ENABLED (u8) 0x40 -#define ACPI_GPE_WAKE_DISABLED (u8) 0x00/* Default */ - -#define ACPI_GPE_ENABLE_MASK (u8) 0x60/* Both run/wake */ -/* * Flags for GPE and Lock interfaces */
drivers/acpi/system.c +2 -2
@@ -387,10 +387,10 @@ static ssize_t counter_set(struct kobjecif (index < num_gpes) {if (!strcmp (buf,"disable\n" ) && (status &ACPI_EVENT_FLAG_ENABLED )) - result =acpi_disable_gpe (handle, index); + result =acpi_set_gpe (handle, index,ACPI_GPE_DISABLE );else if (!strcmp (buf,"enable\n" ) && !(status &ACPI_EVENT_FLAG_ENABLED )) - result =acpi_enable_gpe (handle, index); + result =acpi_set_gpe (handle, index,ACPI_GPE_ENABLE );else if (!strcmp (buf,"clear\n" ) && (status &ACPI_EVENT_FLAG_SET )) result =acpi_clear_gpe (handle, index,ACPI_NOT_ISR );
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
Hi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Best Regards,
Jin Dongming
Quoted 8 lines
drivers/acpi/acpica/evgpeblk.c +1
-2-ACPI_DEBUG_PRINT ((ACPI_DB_LOAD ,"Registered GPE method %s as GPE number 0x%.2X\n" , name, gpe_number)); -return_ACPI_STATUS (status); +return_ACPI_STATUS (AE_OK ); }
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
Quoted 4 lines · Jin Dongming
Hi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);
You could preserve some more context.
Quoted 2 lines
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Why would it? The GPE is still disabled at the hardware level at this point.
Rafael
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
Hi, Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines · Jin Dongming
Hi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);You could preserve some more context.
Quoted 8 lines
Quoted 2 lines
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Why would it? The GPE is still disabled at the hardware level at this point.
Rafael
I am very sorry for my wrong comment. The GPE is still disabled as you wrote.
The error message what I got was not caused by GPE event, it was caused by the "status" variable which had not been deleted on x86-next tree. And it is also deleted at this file. So I don't there is problem here.
Best regards,
Jin Dongming
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
Quoted 16 lines · Jin Dongming
Hi, Rafael J. Wysocki
Quoted 13 lines · Rafael J. Wysocki
Quoted 4 lines · Jin Dongming
Hi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);You could preserve some more context.
Quoted 2 lines
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Why would it? The GPE is still disabled at the hardware level at this point.
Quoted 8 lines
Quoted 3 lines
Rafael
I am very sorry for my wrong comment. The GPE is still disabled as you wrote.
The error message what I got was not caused by GPE event, it was caused by the "status" variable which had not been deleted on x86-next tree. And it is also deleted at this file. So I don't there is problem here.
Great, thanks for the review.
Rafael
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
In reply to Jin DongmingQuoted 16 lines · Jin Dongming
Hi, Rafael J. Wysocki
Quoted 13 lines · Rafael J. Wysocki
Quoted 4 lines · Jin Dongming
Hi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);You could preserve some more context.
Quoted 2 lines
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Why would it? The GPE is still disabled at the hardware level at this point.
Quoted 8 lines
Quoted 3 lines
Rafael
I am very sorry for my wrong comment. The GPE is still disabled as you wrote.
The error message what I got was not caused by GPE event, it was caused by the "status" variable which had not been deleted on x86-next tree. And it is also deleted at this file. So I don't there is problem here.
Great, thanks for the review.
Rafael
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
In reply to Rafael J. WysockiHi, Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines · Jin Dongming
Hi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);You could preserve some more context.
Quoted 8 lines
Quoted 2 lines
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Why would it? The GPE is still disabled at the hardware level at this point.
Rafael
I am very sorry for my wrong comment. The GPE is still disabled as you wrote.
The error message what I got was not caused by GPE event, it was caused by the "status" variable which had not been deleted on x86-next tree. And it is also deleted at this file. So I don't there is problem here.
Best regards,
Jin Dongming
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
In reply to Jin DongmingQuoted 4 lines · Jin Dongming
Hi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);
You could preserve some more context.
Quoted 2 lines
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Why would it? The GPE is still disabled at the hardware level at this point.
Rafael
Re: [PATCH 4/8] ACPI: Use GPE reference counting to support shared GPEs
In reply to Rafael J. WysockiHi, Rafael J. Wysocki
drivers/acpi/acpica/evgpeblk.c acpi_ev_save_method_info(acpi_handle obj · line 342
Quoted 3 lines
drivers/acpi/acpica/evgpeblk.c +0
-3-/* Update enable mask, but don't enable the HW GPE as of yet */ - - status =acpi_ev_enable_gpe (gpe_event_info, FALSE);
I think the above line code should be remained. If it is deleted, the exception event will be raised on some machine.
Best Regards,
Jin Dongming
Quoted 8 lines
drivers/acpi/acpica/evgpeblk.c +1
-2-ACPI_DEBUG_PRINT ((ACPI_DB_LOAD ,"Registered GPE method %s as GPE number 0x%.2X\n" , name, gpe_number)); -return_ACPI_STATUS (status); +return_ACPI_STATUS (AE_OK ); }
PATCH 4/8 ACPI: Use GPE reference counting to support shared GPEs
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
ACPI GPEs may map to multiple devices. The current GPE interface only provides a mechanism for enabling and disabling GPEs, making it difficult to change the state of GPEs at runtime without extensive cooperation between devices.
Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.
Remove the old GPE type handling entirely, which gets rid of various quirks, like the implicit disabling with GPE type setting. This requires a small amount of rework in order to ensure that non-wake GPEs are enabled by default to preserve existing behaviour.
Based on patches from Matthew Garrett <[email protected]>.
--- drivers/acpi/acpica/acevents.h | 6 - drivers/acpi/acpica/aclocal.h | 2 drivers/acpi/acpica/evgpe.c | 153 ++++------------------------------------- drivers/acpi/acpica/evgpeblk.c | 87 ++++++++--------------- drivers/acpi/acpica/evxface.c | 14 --- drivers/acpi/acpica/evxfevnt.c | 90 +++++++++++++++++------- drivers/acpi/button.c | 13 ++- drivers/acpi/ec.c | 14 ++- drivers/acpi/sleep.c | 15 +++- drivers/acpi/system.c | 4 - drivers/acpi/wakeup.c | 81 +++++++-------------- include/acpi/acpixf.h | 6 - include/acpi/actypes.h | 28 ++----- 13 files changed, 188 insertions(+), 325 deletions(-)
drivers/acpi/acpica/aclocal.h +2 -0
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {struct acpi_gpe_register_info *register_info;/* Backpointer to register info */ u8 flags;/* Misc info about this GPE */ u8 gpe_number;/* This GPE */ +u8 runtime_count; +u8 wakeup_count; };/* Information about a GPE register pair, one per each status/enable pair in an array */
drivers/acpi/acpica/evxfevnt.c +65 -25
165 lines not on this page · raw message
include/acpi/acpixf.h +3 -3
@@ -281,11 +281,11 @@ acpi_status acpi_get_event_status(u32 ev/* * GPE Interfaces */ -acpi_status acpi_set_gpe_type (acpi_handle gpe_device,u32 gpe_number,u8 type); +acpi_status acpi_set_gpe (acpi_handle gpe_device,u32 gpe_number,u8 action); -acpi_status acpi_enable_gpe (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_enable_gpe (acpi_handle gpe_device,u32 gpe_number,u8 type); -acpi_status acpi_disable_gpe (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_disable_gpe (acpi_handle gpe_device,u32 gpe_number,u8 type);acpi_status acpi_clear_gpe (acpi_handle gpe_device,u32 gpe_number,u32 flags);
drivers/acpi/button.c +9 -4
@@ -422,11 +422,9 @@ static int acpi_button_add(struct acpi_dif (device->wakeup.flags.valid) {/* Button's GPE is run-wake GPE */ -acpi_set_gpe_type (device->wakeup.gpe_device, - device->wakeup.gpe_number, -ACPI_GPE_TYPE_WAKE_RUN );acpi_enable_gpe (device->wakeup.gpe_device, - device->wakeup.gpe_number); + device->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE_RUN ); device->wakeup.state.enabled =1 ; }
@@ -446,6 +444,13 @@ static int acpi_button_remove(struct acp {struct acpi_button *button =acpi_driver_data (device); +if (device->wakeup.flags.valid) { +acpi_disable_gpe (device->wakeup.gpe_device, + device->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE_RUN ); + device->wakeup.state.enabled =0 ; + } +acpi_button_remove_fs (device);input_unregister_device (button->input);kfree (button);
drivers/acpi/ec.c +8 -6
@@ -307,7 +307,7 @@ static int acpi_ec_transaction(struct acpr_debug (PREFIX "transaction start\n" );/* disable GPE during transaction if storm is detected */ if (test_bit (EC_FLAGS_GPE_STORM , &ec->flags)) { -acpi_disable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_DISABLE ); } status =acpi_ec_transaction_unlocked (ec, t);
@@ -317,7 +317,7 @@ static int acpi_ec_transaction(struct acif (test_bit (EC_FLAGS_GPE_STORM , &ec->flags)) {msleep (1 );/* it is safe to enable GPE outside of transaction */ -acpi_enable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_ENABLE ); }else if (t->irq_count >ACPI_EC_STORM_THRESHOLD ) {pr_info (PREFIX "GPE storm detected, " "transactions will use polling mode\n" );
@@ -788,8 +788,8 @@ static int ec_install_handlers(struct ac &acpi_ec_gpe_handler, ec);if (ACPI_FAILURE (status))return -ENODEV ; -acpi_set_gpe_type (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME ); -acpi_enable_gpe (NULL , ec->gpe); + +acpi_enable_gpe (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME ); status = acpi_install_address_space_handler(ec->handle, ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
@@ -806,6 +806,7 @@ static int ec_install_handlers(struct ac }else {acpi_remove_gpe_handler (NULL , ec->gpe, &acpi_ec_gpe_handler); +acpi_disable_gpe (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME );return -ENODEV ; } }
@@ -816,6 +817,7 @@ static int ec_install_handlers(struct acstatic void ec_remove_handlers (struct acpi_ec *ec) { +acpi_disable_gpe (NULL , ec->gpe,ACPI_GPE_TYPE_RUNTIME );if (ACPI_FAILURE (acpi_remove_address_space_handler (ec->handle,ACPI_ADR_SPACE_EC , &acpi_ec_space_handler)))pr_err (PREFIX "failed to remove space handler\n" );
@@ -1058,7 +1060,7 @@ static int acpi_ec_suspend(struct acpi_d {struct acpi_ec *ec =acpi_driver_data (device);/* Stop using GPE */ -acpi_disable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_DISABLE );return 0 ; }
@@ -1066,7 +1068,7 @@ static int acpi_ec_resume(struct acpi_de {struct acpi_ec *ec =acpi_driver_data (device);/* Enable use of GPE back */ -acpi_enable_gpe (NULL , ec->gpe); +acpi_set_gpe (NULL , ec->gpe,ACPI_GPE_ENABLE );return 0 ; }
drivers/acpi/sleep.c +12 -3
@@ -745,9 +745,18 @@ int acpi_pm_device_sleep_wake(struct devreturn -ENODEV ; } - error = enable ? -acpi_enable_wakeup_device_power (adev, acpi_target_sleep_state) : -acpi_disable_wakeup_device_power (adev); +if (enable) { + error =acpi_enable_wakeup_device_power (adev, + acpi_target_sleep_state); +if (!error) +acpi_enable_gpe (adev->wakeup.gpe_device, + adev->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE ); + }else { +acpi_disable_gpe (adev->wakeup.gpe_device, adev->wakeup.gpe_number, +ACPI_GPE_TYPE_WAKE ); + error =acpi_disable_wakeup_device_power (adev); + }if (!error)dev_info (dev,"wake-up capability %s by ACPI\n" , enable ?"enabled" :"disabled" );
drivers/acpi/wakeup.c +27 -54
127 lines not on this page · raw message
drivers/acpi/acpica/acevents.h +1 -5
@@ -76,8 +76,7 @@ acpi_ev_queue_notify_request(struct acpi* evgpe - GPE handling and dispatch */ acpi_status -acpi_ev_update_gpe_enable_masks (struct acpi_gpe_event_info *gpe_event_info, -u8 type); +acpi_ev_update_gpe_enable_masks (struct acpi_gpe_event_info *gpe_event_info); acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
@@ -122,9 +121,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_eveu32 acpi_ev_gpe_detect (struct acpi_gpe_xrupt_info *gpe_xrupt_list);acpi_status -acpi_ev_set_gpe_type (struct acpi_gpe_event_info *gpe_event_info,u8 type); - -acpi_status acpi_ev_check_for_wake_only_gpe (struct acpi_gpe_event_info *gpe_event_info);acpi_status acpi_ev_gpe_initialize (void );
drivers/acpi/acpica/evgpe.c +16 -137
196 lines not on this page · raw message
drivers/acpi/acpica/evgpeblk.c +33 -54
150 lines not on this page · raw message
drivers/acpi/acpica/evxface.c +0 -14
@@ -617,13 +617,6 @@ acpi_install_gpe_handler(acpi_handle gpe handler->context = context; handler->method_node = gpe_event_info->dispatch.method_node; -/* Disable the GPE before installing the handler */ - - status =acpi_ev_disable_gpe (gpe_event_info); -if (ACPI_FAILURE (status)) { - goto unlock_and_exit; - } -/* Install the handler */ flags =acpi_os_acquire_lock (acpi_gbl_gpe_lock);
@@ -707,13 +700,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_ goto unlock_and_exit; } -/* Disable the GPE before removing the handler */ - - status =acpi_ev_disable_gpe (gpe_event_info); -if (ACPI_FAILURE (status)) { - goto unlock_and_exit; - } -/* Make sure all deferred tasks are completed */ (void )acpi_ut_release_mutex (ACPI_MTX_EVENTS );
include/acpi/actypes.h +10 -18
@@ -668,15 +668,16 @@ typedef u32 acpi_event_status;/* * GPE info flags - Per GPE -* +-+-+-+---+---+-+ -* |7|6|5|4:3|2:1|0| -* +-+-+-+---+---+-+ -* | | | | | | -* | | | | | +--- Interrupt type: Edge or Level Triggered -* | | | | +--- Type: Wake-only, Runtime-only, or wake/runtime +* +-+-+-+---+-+-+-+ +* |7|6|5|4:3|2|1|0| +* +-+-+-+---+-+-+-+ +* | | | | | | | +* | | | | | | +--- Interrupt type: Edge or Level Triggered +* | | | | | +--- GPE can wake the system +* | | | | +--- Unused * | | | +--- Type of dispatch -- to method, handler, or none -* | | +--- Enabled for runtime? -* | +--- Enabled for wake? +* | | +--- Unused +* | +--- Unused * +--- Unused */ #define ACPI_GPE_XRUPT_TYPE_MASK (u8) 0x01
@@ -687,22 +688,13 @@ typedef u32 acpi_event_status;#define ACPI_GPE_TYPE_WAKE_RUN (u8) 0x06#define ACPI_GPE_TYPE_WAKE (u8) 0x02#define ACPI_GPE_TYPE_RUNTIME (u8) 0x04/* Default */ +#define ACPI_GPE_CAN_WAKE (u8) 0x02#define ACPI_GPE_DISPATCH_MASK (u8) 0x18#define ACPI_GPE_DISPATCH_HANDLER (u8) 0x08#define ACPI_GPE_DISPATCH_METHOD (u8) 0x10#define ACPI_GPE_DISPATCH_NOT_USED (u8) 0x00/* Default */ -#define ACPI_GPE_RUN_ENABLE_MASK (u8) 0x20 -#define ACPI_GPE_RUN_ENABLED (u8) 0x20 -#define ACPI_GPE_RUN_DISABLED (u8) 0x00/* Default */ - -#define ACPI_GPE_WAKE_ENABLE_MASK (u8) 0x40 -#define ACPI_GPE_WAKE_ENABLED (u8) 0x40 -#define ACPI_GPE_WAKE_DISABLED (u8) 0x00/* Default */ - -#define ACPI_GPE_ENABLE_MASK (u8) 0x60/* Both run/wake */ -/* * Flags for GPE and Lock interfaces */
drivers/acpi/system.c +2 -2
@@ -387,10 +387,10 @@ static ssize_t counter_set(struct kobjecif (index < num_gpes) {if (!strcmp (buf,"disable\n" ) && (status &ACPI_EVENT_FLAG_ENABLED )) - result =acpi_disable_gpe (handle, index); + result =acpi_set_gpe (handle, index,ACPI_GPE_DISABLE );else if (!strcmp (buf,"enable\n" ) && !(status &ACPI_EVENT_FLAG_ENABLED )) - result =acpi_enable_gpe (handle, index); + result =acpi_set_gpe (handle, index,ACPI_GPE_ENABLE );else if (!strcmp (buf,"clear\n" ) && (status &ACPI_EVENT_FLAG_SET )) result =acpi_clear_gpe (handle, index,ACPI_NOT_ISR );
PATCH 5/8 ACPI / PM: Add more run-time wake-up fields (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Use the run_wake flag to mark all devices for which run-time wake-up events may be generated by the platform. Introduce a new wake-up flag, always_enabled, for marking devices that should be permanently enabled to generate run-time events. Also, introduce a reference counter for run-wake devices and a function that will initialize all of the run-time wake-up fields for given device.
--- drivers/acpi/button.c | 2 ++ drivers/acpi/scan.c | 37 +++++++++++++++++++++++++++---------- drivers/acpi/wakeup.c | 3 ++- include/acpi/acpi_bus.h | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)
drivers/acpi/wakeup.c +2 -1
@@ -110,7 +110,8 @@ int __init acpi_wakeup_device_init(void) struct acpi_device, wakeup_list);/* In case user doesn't load button driver */ -if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) +if (!dev->wakeup.flags.always_enabled || + dev->wakeup.state.enabled)continue ;acpi_enable_gpe (dev->wakeup.gpe_device, dev->wakeup.gpe_number,ACPI_GPE_TYPE_WAKE );
include/acpi/acpi_bus.h +2 -0
@@ -242,6 +242,7 @@ struct acpi_device_perf {struct acpi_device_wakeup_flags {u8 valid:1 ;/* Can successfully enable wakeup? */ u8 run_wake:1 ;/* Run-Wake GPE devices */ +u8 always_enabled:1 ;/* Run-wake devices that are always enabled */ };struct acpi_device_wakeup_state {
@@ -256,6 +257,7 @@ struct acpi_device_wakeup {struct acpi_device_wakeup_state state;struct acpi_device_wakeup_flags flags;int prepare_count; +int run_wake_count; };/* Device */
drivers/acpi/button.c +2 -0
@@ -425,6 +425,7 @@ static int acpi_button_add(struct acpi_dacpi_enable_gpe (device->wakeup.gpe_device, device->wakeup.gpe_number,ACPI_GPE_TYPE_WAKE_RUN ); + device->wakeup.run_wake_count++; device->wakeup.state.enabled =1 ; }
@@ -448,6 +449,7 @@ static int acpi_button_remove(struct acpacpi_disable_gpe (device->wakeup.gpe_device, device->wakeup.gpe_number,ACPI_GPE_TYPE_WAKE_RUN ); + device->wakeup.run_wake_count--; device->wakeup.state.enabled =0 ; }
drivers/acpi/scan.c +27 -10
@@ -741,19 +741,39 @@ acpi_bus_extract_wakeup_device_power_pacreturn AE_OK ; } -static int acpi_bus_get_wakeup_device_flags (struct acpi_device *device) +static void acpi_bus_set_run_wake_flags (struct acpi_device *device) { -acpi_status status =0 ; -struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; -union acpi_object *package =NULL ; -int psw_error; -struct acpi_device_id button_device_ids[] = { {"PNP0C0D" ,0 }, {"PNP0C0C" ,0 }, {"PNP0C0E" ,0 }, {"" ,0 }, }; +acpi_status status; +acpi_event_status event_status; + + device->wakeup.run_wake_count =0 ; + +/* Power button, Lid switch always enable wakeup */ +if (!acpi_match_device_ids (device, button_device_ids)) { + device->wakeup.flags.run_wake =1 ; + device->wakeup.flags.always_enabled =1 ; +return ; + } + + status =acpi_get_gpe_status (NULL , device->wakeup.gpe_number, +ACPI_NOT_ISR , &event_status); +if (status ==AE_OK ) + device->wakeup.flags.run_wake = + !!(event_status &ACPI_EVENT_FLAG_HANDLE ); +} + +static int acpi_bus_get_wakeup_device_flags (struct acpi_device *device) +{ +acpi_status status =0 ; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *package =NULL ; +int psw_error;/* _PRW */ status =acpi_evaluate_object (device->handle,"_PRW" ,NULL , &buffer);
@@ -773,6 +793,7 @@ static int acpi_bus_get_wakeup_device_fl device->wakeup.flags.valid =1 ; device->wakeup.prepare_count =0 ; +acpi_bus_set_run_wake_flags (device);/* Call _PSW/_DSW object to disable its ability to wake the sleeping * system for the ACPI device with the _PRW object. * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
@@ -784,10 +805,6 @@ static int acpi_bus_get_wakeup_device_flACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"error in _DSW or _PSW evaluation\n" )); -/* Power button, Lid switch always enable wakeup */ -if (!acpi_match_device_ids (device, button_device_ids)) - device->wakeup.flags.run_wake =1 ; - end:if (ACPI_FAILURE (status)) device->flags.wake_capable =0 ;
PATCH 5/8 ACPI / PM: Add more run-time wake-up fields (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Use the run_wake flag to mark all devices for which run-time wake-up events may be generated by the platform. Introduce a new wake-up flag, always_enabled, for marking devices that should be permanently enabled to generate run-time events. Also, introduce a reference counter for run-wake devices and a function that will initialize all of the run-time wake-up fields for given device.
--- drivers/acpi/button.c | 2 ++ drivers/acpi/scan.c | 37 +++++++++++++++++++++++++++---------- drivers/acpi/wakeup.c | 3 ++- include/acpi/acpi_bus.h | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)
drivers/acpi/wakeup.c +2 -1
@@ -110,7 +110,8 @@ int __init acpi_wakeup_device_init(void) struct acpi_device, wakeup_list);/* In case user doesn't load button driver */ -if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) +if (!dev->wakeup.flags.always_enabled || + dev->wakeup.state.enabled)continue ;acpi_enable_gpe (dev->wakeup.gpe_device, dev->wakeup.gpe_number,ACPI_GPE_TYPE_WAKE );
include/acpi/acpi_bus.h +2 -0
@@ -242,6 +242,7 @@ struct acpi_device_perf {struct acpi_device_wakeup_flags {u8 valid:1 ;/* Can successfully enable wakeup? */ u8 run_wake:1 ;/* Run-Wake GPE devices */ +u8 always_enabled:1 ;/* Run-wake devices that are always enabled */ };struct acpi_device_wakeup_state {
@@ -256,6 +257,7 @@ struct acpi_device_wakeup {struct acpi_device_wakeup_state state;struct acpi_device_wakeup_flags flags;int prepare_count; +int run_wake_count; };/* Device */
drivers/acpi/button.c +2 -0
@@ -425,6 +425,7 @@ static int acpi_button_add(struct acpi_dacpi_enable_gpe (device->wakeup.gpe_device, device->wakeup.gpe_number,ACPI_GPE_TYPE_WAKE_RUN ); + device->wakeup.run_wake_count++; device->wakeup.state.enabled =1 ; }
@@ -448,6 +449,7 @@ static int acpi_button_remove(struct acpacpi_disable_gpe (device->wakeup.gpe_device, device->wakeup.gpe_number,ACPI_GPE_TYPE_WAKE_RUN ); + device->wakeup.run_wake_count--; device->wakeup.state.enabled =0 ; }
drivers/acpi/scan.c +27 -10
@@ -741,19 +741,39 @@ acpi_bus_extract_wakeup_device_power_pacreturn AE_OK ; } -static int acpi_bus_get_wakeup_device_flags (struct acpi_device *device) +static void acpi_bus_set_run_wake_flags (struct acpi_device *device) { -acpi_status status =0 ; -struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; -union acpi_object *package =NULL ; -int psw_error; -struct acpi_device_id button_device_ids[] = { {"PNP0C0D" ,0 }, {"PNP0C0C" ,0 }, {"PNP0C0E" ,0 }, {"" ,0 }, }; +acpi_status status; +acpi_event_status event_status; + + device->wakeup.run_wake_count =0 ; + +/* Power button, Lid switch always enable wakeup */ +if (!acpi_match_device_ids (device, button_device_ids)) { + device->wakeup.flags.run_wake =1 ; + device->wakeup.flags.always_enabled =1 ; +return ; + } + + status =acpi_get_gpe_status (NULL , device->wakeup.gpe_number, +ACPI_NOT_ISR , &event_status); +if (status ==AE_OK ) + device->wakeup.flags.run_wake = + !!(event_status &ACPI_EVENT_FLAG_HANDLE ); +} + +static int acpi_bus_get_wakeup_device_flags (struct acpi_device *device) +{ +acpi_status status =0 ; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *package =NULL ; +int psw_error;/* _PRW */ status =acpi_evaluate_object (device->handle,"_PRW" ,NULL , &buffer);
@@ -773,6 +793,7 @@ static int acpi_bus_get_wakeup_device_fl device->wakeup.flags.valid =1 ; device->wakeup.prepare_count =0 ; +acpi_bus_set_run_wake_flags (device);/* Call _PSW/_DSW object to disable its ability to wake the sleeping * system for the ACPI device with the _PRW object. * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
@@ -784,10 +805,6 @@ static int acpi_bus_get_wakeup_device_flACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"error in _DSW or _PSW evaluation\n" )); -/* Power button, Lid switch always enable wakeup */ -if (!acpi_match_device_ids (device, button_device_ids)) - device->wakeup.flags.run_wake =1 ; - end:if (ACPI_FAILURE (status)) device->flags.wake_capable =0 ;
PATCH 6/8 ACPI / ACPICA: Multiple system notify handlers per device
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Currently it only is possible to install one system notify handler per namespace node, but this is not enough for PCI run-time power management, because we need to install power management notifiers for devices that already have hotplug notifiers installed. While in principle this could be handled at the PCI level, that would be suboptimal due to the way in which the ACPI-based PCI hotplug code is designed.
For this reason, modify ACPICA so that it is possible to install more than one system notify handler per namespace node. Namely, make acpi_install_notify_handler(), acpi_remove_notify_handler() and acpi_ev_notify_dispatch() use a list of system notify handler objects associated with a namespace node.
Make acpi_remove_notify_handler() call acpi_os_wait_events_complete() upfront to avoid a situation in which concurrent instance of acpi_remove_notify_handler() removes the handler from under us while we're waiting for the event queues to flush.
--- drivers/acpi/acpica/acobject.h | 2 drivers/acpi/acpica/evmisc.c | 12 ++ drivers/acpi/acpica/evxface.c | 175 ++++++++++++++++++++++++++++++++--------- 3 files changed, 150 insertions(+), 39 deletions(-)
drivers/acpi/acpica/acobject.h +2 -0
@@ -287,8 +287,10 @@ struct acpi_object_buffer_field {struct acpi_object_notify_handler { ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node; /* Parent device */ +u32 handler_type;acpi_notify_handler handler;void *context; +struct acpi_object_notify_handler *next; };struct acpi_object_addr_handler {
drivers/acpi/acpica/evxface.c +139 -36
232 lines not on this page · raw message
drivers/acpi/acpica/evmisc.c +9 -3
@@ -259,9 +259,15 @@ static void ACPI_SYSTEM_XFACE acpi_ev_no handler_obj = notify_info->notify.handler_obj;if (handler_obj) { - handler_obj->notify.handler (notify_info->notify.node, - notify_info->notify.value, - handler_obj->notify.context); +struct acpi_object_notify_handler *notifier; + + notifier = &handler_obj->notify; +while (notifier) { + notifier->handler (notify_info->notify.node, + notify_info->notify.value, + notifier->context); + notifier = notifier->next; + } }/* All done with the info object */
PATCH 6/8 ACPI / ACPICA: Multiple system notify handlers per device
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Currently it only is possible to install one system notify handler per namespace node, but this is not enough for PCI run-time power management, because we need to install power management notifiers for devices that already have hotplug notifiers installed. While in principle this could be handled at the PCI level, that would be suboptimal due to the way in which the ACPI-based PCI hotplug code is designed.
For this reason, modify ACPICA so that it is possible to install more than one system notify handler per namespace node. Namely, make acpi_install_notify_handler(), acpi_remove_notify_handler() and acpi_ev_notify_dispatch() use a list of system notify handler objects associated with a namespace node.
Make acpi_remove_notify_handler() call acpi_os_wait_events_complete() upfront to avoid a situation in which concurrent instance of acpi_remove_notify_handler() removes the handler from under us while we're waiting for the event queues to flush.
--- drivers/acpi/acpica/acobject.h | 2 drivers/acpi/acpica/evmisc.c | 12 ++ drivers/acpi/acpica/evxface.c | 175 ++++++++++++++++++++++++++++++++--------- 3 files changed, 150 insertions(+), 39 deletions(-)
drivers/acpi/acpica/acobject.h +2 -0
@@ -287,8 +287,10 @@ struct acpi_object_buffer_field {struct acpi_object_notify_handler { ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node; /* Parent device */ +u32 handler_type;acpi_notify_handler handler;void *context; +struct acpi_object_notify_handler *next; };struct acpi_object_addr_handler {
drivers/acpi/acpica/evxface.c +139 -36
232 lines not on this page · raw message
drivers/acpi/acpica/evmisc.c +9 -3
@@ -259,9 +259,15 @@ static void ACPI_SYSTEM_XFACE acpi_ev_no handler_obj = notify_info->notify.handler_obj;if (handler_obj) { - handler_obj->notify.handler (notify_info->notify.node, - notify_info->notify.value, - handler_obj->notify.context); +struct acpi_object_notify_handler *notifier; + + notifier = &handler_obj->notify; +while (notifier) { + notifier->handler (notify_info->notify.node, + notify_info->notify.value, + notifier->context); + notifier = notifier->next; + } }/* All done with the info object */
PATCH 7/8 PCI / ACPI / PM: Platform support for PCI PME wake-up (rev. 9)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Although the majority of PCI devices can generate PMEs that in principle may be used to wake up devices suspended at run time, platform support is generally necessary to convert PMEs into wake-up events that can be delivered to the kernel. If ACPI is used for this purpose, PME signals generated by a PCI device will trigger the ACPI GPE associated with the device to generate an ACPI wake-up event that we can set up a handler for, provided that everything is configured correctly.
Unfortunately, the subset of PCI devices that have GPEs associated with them is quite limited. The devices without dedicated GPEs have to rely on the GPEs associated with other devices (in the majority of cases their upstream bridges and, possibly, the root bridge) to generate ACPI wake-up events in response to PME signals from them.
Add ACPI platform support for PCI PME wake-up:
o Add a framework making is possible to use ACPI system notify handlers for run-time PM.
o Add new PCI platform callback ->run_wake() to struct pci_platform_pm_ops allowing us to enable/disable the platform to generate wake-up events for given device. Implemet this callback for the ACPI platform.
o Define ACPI wake-up handlers for PCI devices and PCI root buses and make the PCI-ACPI binding code register wake-up notifiers for all PCI devices present in the ACPI tables.
o Add function pci_dev_run_wake() which can be used by PCI drivers to check if given device is capable of generating wake-up events at run time.
Developed in cooperation with Matthew Garrett <[email protected]>.
--- drivers/acpi/internal.h | 2 drivers/acpi/pci_bind.c | 14 ++- drivers/acpi/pci_root.c | 8 + drivers/acpi/scan.c | 1 drivers/pci/pci-acpi.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.c | 67 ++++++++++++++ drivers/pci/pci.h | 7 + include/acpi/acpi_bus.h | 4 include/linux/pci-acpi.h | 7 + include/linux/pci.h | 1 10 files changed, 319 insertions(+), 3 deletions(-)
drivers/pci/pci.h +7 -0
@@ -35,6 +35,10 @@ int pci_probe_reset_function(struct pci_* * @sleep_wake: enables/disables the system wake up capability of given device * +* @run_wake: enables/disables the platform to generate run-time wake-up events +* for given device (the device's wake-up capability has to be +* enabled by @sleep_wake for this feature to work) +* * If given platform is generally capable of power managing PCI devices, all of * these callbacks are mandatory. */
@@ -44,12 +48,15 @@ struct pci_platform_pm_ops {pci_power_t (*choose_state)(struct pci_dev *dev);bool (*can_wakeup)(struct pci_dev *dev);int (*sleep_wake)(struct pci_dev *dev,bool enable); +int (*run_wake)(struct pci_dev *dev,bool enable); };extern int pci_set_platform_pm (struct pci_platform_pm_ops *ops);extern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_disable_enabled_device (struct pci_dev *dev);extern bool pci_check_pme_status (struct pci_dev *dev); +extern int __pci_pme_wakeup (struct pci_dev *dev,void *ign); +extern void pci_pme_wakeup_bus (struct pci_bus *bus);extern void pci_pm_init (struct pci_dev *dev);extern void platform_pci_wakeup_init (struct pci_dev *dev);extern void pci_allocate_cap_save_buffers (struct pci_dev *dev);
drivers/pci/pci-acpi.c +211 -0
231 lines not on this page · raw message
drivers/pci/pci.c +67 -0
91 lines not on this page · raw message
include/linux/pci.h +1 -0
@@ -756,6 +756,7 @@ int pci_wake_from_d3(struct pci_dev *devpci_power_t pci_target_state (struct pci_dev *dev);int pci_prepare_to_sleep (struct pci_dev *dev);int pci_back_from_sleep (struct pci_dev *dev); +bool pci_dev_run_wake (struct pci_dev *dev);/* For use by arch with custom probe code */ void set_pcie_port_type (struct pci_dev *pdev);
include/linux/pci-acpi.h +7 -0
@@ -11,6 +11,13 @@#include <linux/acpi.h> #ifdef CONFIG_ACPI +extern acpi_status pci_acpi_add_bus_pm_notifier (struct acpi_device *dev, +struct pci_bus *pci_bus); +extern acpi_status pci_acpi_remove_bus_pm_notifier (struct acpi_device *dev); +extern acpi_status pci_acpi_add_pm_notifier (struct acpi_device *dev, +struct pci_dev *pci_dev); +extern acpi_status pci_acpi_remove_pm_notifier (struct acpi_device *dev); +static inline acpi_handle acpi_find_root_bridge_handle (struct pci_dev *pdev) {struct pci_bus *pbus = pdev->bus;
include/acpi/acpi_bus.h +4 -0
@@ -243,6 +243,7 @@ struct acpi_device_wakeup_flags { u8 valid:1; /* Can successfully enable wakeup? */ u8 run_wake:1; /* Run-Wake GPE devices */ u8 always_enabled:1; /* Run-wake devices that are always enabled */ + u8 notifier_present:1; /* Wake-up notify handler has been installed */ };struct acpi_device_wakeup_state {
@@ -388,6 +389,9 @@ acpi_handle acpi_get_pci_rootbridge_handstruct acpi_pci_root *acpi_pci_find_root (acpi_handle handle);#define DEVICE_ACPI_HANDLE (dev) ((acpi_handle)((dev)->archdata.acpi_handle)) +int acpi_enable_wakeup_device_power (struct acpi_device *dev,int state); +int acpi_disable_wakeup_device_power (struct acpi_device *dev); +#ifdef CONFIG_PM_SLEEP int acpi_pm_device_sleep_state (struct device *,int *);int acpi_pm_device_sleep_wake (struct device *,bool );
drivers/acpi/internal.h +0 -2
@@ -36,8 +36,6 @@ static inline int acpi_debug_init(void)int acpi_power_init (void );int acpi_device_sleep_wake (struct acpi_device *dev,int enable,int sleep_state,int dev_state); -int acpi_enable_wakeup_device_power (struct acpi_device *dev,int sleep_state); -int acpi_disable_wakeup_device_power (struct acpi_device *dev);int acpi_power_get_inferred_state (struct acpi_device *device);int acpi_power_transition (struct acpi_device *device,int state);extern int acpi_power_nocheck;
drivers/acpi/scan.c +1 -0
@@ -753,6 +753,7 @@ static void acpi_bus_set_run_wake_flags(acpi_event_status event_status; device->wakeup.run_wake_count =0 ; + device->wakeup.flags.notifier_present =0 ;/* Power button, Lid switch always enable wakeup */ if (!acpi_match_device_ids (device, button_device_ids)) {
drivers/acpi/pci_root.c +8 -0
@@ -30,6 +30,7 @@#include <linux/proc_fs.h> #include <linux/spinlock.h> #include <linux/pm.h> +#include <linux/pm_runtime.h> #include <linux/pci.h> #include <linux/pci-acpi.h> #include <linux/acpi.h>
@@ -528,6 +529,10 @@ static int __devinit acpi_pci_root_add(sif (flags != base_flags)acpi_pci_osc_support (root, flags); +pci_acpi_add_bus_pm_notifier (device, root->bus); +if (device->wakeup.flags.run_wake) +device_set_run_wake (root->bus->bridge, true); +return 0 ; end:
@@ -549,6 +554,9 @@ static int acpi_pci_root_remove(struct a {struct acpi_pci_root *root =acpi_driver_data (device); +device_set_run_wake (root->bus->bridge, false); +pci_acpi_remove_bus_pm_notifier (device); +kfree (root);return 0 ; }
drivers/acpi/pci_bind.c +13 -1
@@ -26,7 +26,9 @@#include <linux/kernel.h> #include <linux/types.h> #include <linux/pci.h> +#include <linux/pci-acpi.h> #include <linux/acpi.h> +#include <linux/pm_runtime.h> #include <acpi/acpi_bus.h> #include <acpi/acpi_drivers.h>
@@ -38,7 +40,13 @@ static int acpi_pci_unbind(struct acpi_dstruct pci_dev *dev; dev =acpi_get_pci_dev (device->handle); -if (!dev || !dev->subordinate) +if (!dev) + goto out; + +device_set_run_wake (&dev->dev, false); +pci_acpi_remove_pm_notifier (device); + +if (!dev->subordinate) goto out;acpi_pci_irq_del_prt (dev->subordinate);
@@ -62,6 +70,10 @@ static int acpi_pci_bind(struct acpi_devif (!dev)return 0 ; +pci_acpi_add_pm_notifier (device, dev); +if (device->wakeup.flags.run_wake) +device_set_run_wake (&dev->dev, true); +/* * Install the 'bind' function to facilitate callbacks for * children of the P2P bridge.
PATCH 7/8 PCI / ACPI / PM: Platform support for PCI PME wake-up (rev. 9)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Although the majority of PCI devices can generate PMEs that in principle may be used to wake up devices suspended at run time, platform support is generally necessary to convert PMEs into wake-up events that can be delivered to the kernel. If ACPI is used for this purpose, PME signals generated by a PCI device will trigger the ACPI GPE associated with the device to generate an ACPI wake-up event that we can set up a handler for, provided that everything is configured correctly.
Unfortunately, the subset of PCI devices that have GPEs associated with them is quite limited. The devices without dedicated GPEs have to rely on the GPEs associated with other devices (in the majority of cases their upstream bridges and, possibly, the root bridge) to generate ACPI wake-up events in response to PME signals from them.
Add ACPI platform support for PCI PME wake-up:
o Add a framework making is possible to use ACPI system notify handlers for run-time PM.
o Add new PCI platform callback ->run_wake() to struct pci_platform_pm_ops allowing us to enable/disable the platform to generate wake-up events for given device. Implemet this callback for the ACPI platform.
o Define ACPI wake-up handlers for PCI devices and PCI root buses and make the PCI-ACPI binding code register wake-up notifiers for all PCI devices present in the ACPI tables.
o Add function pci_dev_run_wake() which can be used by PCI drivers to check if given device is capable of generating wake-up events at run time.
Developed in cooperation with Matthew Garrett <[email protected]>.
--- drivers/acpi/internal.h | 2 drivers/acpi/pci_bind.c | 14 ++- drivers/acpi/pci_root.c | 8 + drivers/acpi/scan.c | 1 drivers/pci/pci-acpi.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.c | 67 ++++++++++++++ drivers/pci/pci.h | 7 + include/acpi/acpi_bus.h | 4 include/linux/pci-acpi.h | 7 + include/linux/pci.h | 1 10 files changed, 319 insertions(+), 3 deletions(-)
drivers/pci/pci.h +7 -0
@@ -35,6 +35,10 @@ int pci_probe_reset_function(struct pci_* * @sleep_wake: enables/disables the system wake up capability of given device * +* @run_wake: enables/disables the platform to generate run-time wake-up events +* for given device (the device's wake-up capability has to be +* enabled by @sleep_wake for this feature to work) +* * If given platform is generally capable of power managing PCI devices, all of * these callbacks are mandatory. */
@@ -44,12 +48,15 @@ struct pci_platform_pm_ops {pci_power_t (*choose_state)(struct pci_dev *dev);bool (*can_wakeup)(struct pci_dev *dev);int (*sleep_wake)(struct pci_dev *dev,bool enable); +int (*run_wake)(struct pci_dev *dev,bool enable); };extern int pci_set_platform_pm (struct pci_platform_pm_ops *ops);extern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_disable_enabled_device (struct pci_dev *dev);extern bool pci_check_pme_status (struct pci_dev *dev); +extern int __pci_pme_wakeup (struct pci_dev *dev,void *ign); +extern void pci_pme_wakeup_bus (struct pci_bus *bus);extern void pci_pm_init (struct pci_dev *dev);extern void platform_pci_wakeup_init (struct pci_dev *dev);extern void pci_allocate_cap_save_buffers (struct pci_dev *dev);
drivers/pci/pci-acpi.c +211 -0
231 lines not on this page · raw message
drivers/pci/pci.c +67 -0
91 lines not on this page · raw message
include/linux/pci.h +1 -0
@@ -756,6 +756,7 @@ int pci_wake_from_d3(struct pci_dev *devpci_power_t pci_target_state (struct pci_dev *dev);int pci_prepare_to_sleep (struct pci_dev *dev);int pci_back_from_sleep (struct pci_dev *dev); +bool pci_dev_run_wake (struct pci_dev *dev);/* For use by arch with custom probe code */ void set_pcie_port_type (struct pci_dev *pdev);
include/linux/pci-acpi.h +7 -0
@@ -11,6 +11,13 @@#include <linux/acpi.h> #ifdef CONFIG_ACPI +extern acpi_status pci_acpi_add_bus_pm_notifier (struct acpi_device *dev, +struct pci_bus *pci_bus); +extern acpi_status pci_acpi_remove_bus_pm_notifier (struct acpi_device *dev); +extern acpi_status pci_acpi_add_pm_notifier (struct acpi_device *dev, +struct pci_dev *pci_dev); +extern acpi_status pci_acpi_remove_pm_notifier (struct acpi_device *dev); +static inline acpi_handle acpi_find_root_bridge_handle (struct pci_dev *pdev) {struct pci_bus *pbus = pdev->bus;
include/acpi/acpi_bus.h +4 -0
@@ -243,6 +243,7 @@ struct acpi_device_wakeup_flags { u8 valid:1; /* Can successfully enable wakeup? */ u8 run_wake:1; /* Run-Wake GPE devices */ u8 always_enabled:1; /* Run-wake devices that are always enabled */ + u8 notifier_present:1; /* Wake-up notify handler has been installed */ };struct acpi_device_wakeup_state {
@@ -388,6 +389,9 @@ acpi_handle acpi_get_pci_rootbridge_handstruct acpi_pci_root *acpi_pci_find_root (acpi_handle handle);#define DEVICE_ACPI_HANDLE (dev) ((acpi_handle)((dev)->archdata.acpi_handle)) +int acpi_enable_wakeup_device_power (struct acpi_device *dev,int state); +int acpi_disable_wakeup_device_power (struct acpi_device *dev); +#ifdef CONFIG_PM_SLEEP int acpi_pm_device_sleep_state (struct device *,int *);int acpi_pm_device_sleep_wake (struct device *,bool );
drivers/acpi/internal.h +0 -2
@@ -36,8 +36,6 @@ static inline int acpi_debug_init(void)int acpi_power_init (void );int acpi_device_sleep_wake (struct acpi_device *dev,int enable,int sleep_state,int dev_state); -int acpi_enable_wakeup_device_power (struct acpi_device *dev,int sleep_state); -int acpi_disable_wakeup_device_power (struct acpi_device *dev);int acpi_power_get_inferred_state (struct acpi_device *device);int acpi_power_transition (struct acpi_device *device,int state);extern int acpi_power_nocheck;
drivers/acpi/scan.c +1 -0
@@ -753,6 +753,7 @@ static void acpi_bus_set_run_wake_flags(acpi_event_status event_status; device->wakeup.run_wake_count =0 ; + device->wakeup.flags.notifier_present =0 ;/* Power button, Lid switch always enable wakeup */ if (!acpi_match_device_ids (device, button_device_ids)) {
drivers/acpi/pci_root.c +8 -0
@@ -30,6 +30,7 @@#include <linux/proc_fs.h> #include <linux/spinlock.h> #include <linux/pm.h> +#include <linux/pm_runtime.h> #include <linux/pci.h> #include <linux/pci-acpi.h> #include <linux/acpi.h>
@@ -528,6 +529,10 @@ static int __devinit acpi_pci_root_add(sif (flags != base_flags)acpi_pci_osc_support (root, flags); +pci_acpi_add_bus_pm_notifier (device, root->bus); +if (device->wakeup.flags.run_wake) +device_set_run_wake (root->bus->bridge, true); +return 0 ; end:
@@ -549,6 +554,9 @@ static int acpi_pci_root_remove(struct a {struct acpi_pci_root *root =acpi_driver_data (device); +device_set_run_wake (root->bus->bridge, false); +pci_acpi_remove_bus_pm_notifier (device); +kfree (root);return 0 ; }
drivers/acpi/pci_bind.c +13 -1
@@ -26,7 +26,9 @@#include <linux/kernel.h> #include <linux/types.h> #include <linux/pci.h> +#include <linux/pci-acpi.h> #include <linux/acpi.h> +#include <linux/pm_runtime.h> #include <acpi/acpi_bus.h> #include <acpi/acpi_drivers.h>
@@ -38,7 +40,13 @@ static int acpi_pci_unbind(struct acpi_dstruct pci_dev *dev; dev =acpi_get_pci_dev (device->handle); -if (!dev || !dev->subordinate) +if (!dev) + goto out; + +device_set_run_wake (&dev->dev, false); +pci_acpi_remove_pm_notifier (device); + +if (!dev->subordinate) goto out;acpi_pci_irq_del_prt (dev->subordinate);
@@ -62,6 +70,10 @@ static int acpi_pci_bind(struct acpi_devif (!dev)return 0 ; +pci_acpi_add_pm_notifier (device, dev); +if (device->wakeup.flags.run_wake) +device_set_run_wake (&dev->dev, true); +/* * Install the 'bind' function to facilitate callbacks for * children of the P2P bridge.
PATCH 8/8 PCI PM: Run-time callbacks for PCI bus type (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Introduce run-time PM callbacks for the PCI bus type. Make the new callbacks work in analogy with the existing system sleep PM callbacks, so that the drivers already converted to struct dev_pm_ops can use their suspend and resume routines for run-time PM without modifications.
--- drivers/pci/pci-driver.c | 160 +++++++++++++++++++++++++++++++++++++++-------- drivers/pci/pci.c | 43 ++++++++++-- drivers/pci/pci.h | 1 include/linux/pci.h | 9 ++ kernel/power/Kconfig | 5 + 5 files changed, 184 insertions(+), 34 deletions(-)
kernel/power/Kconfig +5 -0
@@ -222,3 +222,8 @@ config PM_RUNTIME and the bus type drivers of the buses the devices are on are responsible for the actual handling of the autosuspend requests and wake-up events. + +config PM_OPS + bool + depends on PM_SLEEP || PM_RUNTIME + default y
drivers/pci/pci-driver.c +133 -27
221 lines not on this page · raw message
drivers/pci/pci.c +37 -6
89 lines not on this page · raw message
include/linux/pci.h +8 -1
@@ -751,13 +751,20 @@ int pci_set_power_state(struct pci_dev *pci_power_t pci_choose_state (struct pci_dev *dev,pm_message_t state);bool pci_pme_capable (struct pci_dev *dev,pci_power_t state);void pci_pme_active (struct pci_dev *dev,bool enable); -int pci_enable_wake (struct pci_dev *dev,pci_power_t state,bool enable); +int __pci_enable_wake (struct pci_dev *dev,pci_power_t state, +bool runtime,bool enable);int pci_wake_from_d3 (struct pci_dev *dev,bool enable);pci_power_t pci_target_state (struct pci_dev *dev);int pci_prepare_to_sleep (struct pci_dev *dev);int pci_back_from_sleep (struct pci_dev *dev);bool pci_dev_run_wake (struct pci_dev *dev); +static inline int pci_enable_wake (struct pci_dev *dev,pci_power_t state, +bool enable) +{ +return __pci_enable_wake (dev, state, false, enable); +} +/* For use by arch with custom probe code */ void set_pcie_port_type (struct pci_dev *pdev);void set_pcie_hotplug_bridge (struct pci_dev *pdev);
drivers/pci/pci.h +1 -0
@@ -55,6 +55,7 @@ extern int pci_set_platform_pm(struct pcextern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_disable_enabled_device (struct pci_dev *dev);extern bool pci_check_pme_status (struct pci_dev *dev); +extern int pci_finish_runtime_suspend (struct pci_dev *dev);extern int __pci_pme_wakeup (struct pci_dev *dev,void *ign);extern void pci_pme_wakeup_bus (struct pci_bus *bus);extern void pci_pm_init (struct pci_dev *dev);
PATCH 8/8 PCI PM: Run-time callbacks for PCI bus type (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Introduce run-time PM callbacks for the PCI bus type. Make the new callbacks work in analogy with the existing system sleep PM callbacks, so that the drivers already converted to struct dev_pm_ops can use their suspend and resume routines for run-time PM without modifications.
--- drivers/pci/pci-driver.c | 160 +++++++++++++++++++++++++++++++++++++++-------- drivers/pci/pci.c | 43 ++++++++++-- drivers/pci/pci.h | 1 include/linux/pci.h | 9 ++ kernel/power/Kconfig | 5 + 5 files changed, 184 insertions(+), 34 deletions(-)
kernel/power/Kconfig +5 -0
@@ -222,3 +222,8 @@ config PM_RUNTIME and the bus type drivers of the buses the devices are on are responsible for the actual handling of the autosuspend requests and wake-up events. + +config PM_OPS + bool + depends on PM_SLEEP || PM_RUNTIME + default y
drivers/pci/pci-driver.c +133 -27
221 lines not on this page · raw message
drivers/pci/pci.c +37 -6
89 lines not on this page · raw message
include/linux/pci.h +8 -1
@@ -751,13 +751,20 @@ int pci_set_power_state(struct pci_dev *pci_power_t pci_choose_state (struct pci_dev *dev,pm_message_t state);bool pci_pme_capable (struct pci_dev *dev,pci_power_t state);void pci_pme_active (struct pci_dev *dev,bool enable); -int pci_enable_wake (struct pci_dev *dev,pci_power_t state,bool enable); +int __pci_enable_wake (struct pci_dev *dev,pci_power_t state, +bool runtime,bool enable);int pci_wake_from_d3 (struct pci_dev *dev,bool enable);pci_power_t pci_target_state (struct pci_dev *dev);int pci_prepare_to_sleep (struct pci_dev *dev);int pci_back_from_sleep (struct pci_dev *dev);bool pci_dev_run_wake (struct pci_dev *dev); +static inline int pci_enable_wake (struct pci_dev *dev,pci_power_t state, +bool enable) +{ +return __pci_enable_wake (dev, state, false, enable); +} +/* For use by arch with custom probe code */ void set_pcie_port_type (struct pci_dev *pdev);void set_pcie_hotplug_bridge (struct pci_dev *pdev);
drivers/pci/pci.h +1 -0
@@ -55,6 +55,7 @@ extern int pci_set_platform_pm(struct pcextern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_disable_enabled_device (struct pci_dev *dev);extern bool pci_check_pme_status (struct pci_dev *dev); +extern int pci_finish_runtime_suspend (struct pci_dev *dev);extern int __pci_pme_wakeup (struct pci_dev *dev,void *ign);extern void pci_pme_wakeup_bus (struct pci_bus *bus);extern void pci_pm_init (struct pci_dev *dev);