PCI PM: Fix radeonfb vs pci_set_power_state() problem
Subsystems (2)
cover PCI PM: Fix radeonfb vs pci_set_power_state() problem
Hi,
The following two patches are intended to fix the problem that will arise when the PM patches queued up for 2.6.30 are merged and which is that pci_set_power_state() called by radeonfb to complete the transition into D2 will return immediately due to the device's current_state being already PCI_D2.
1/2 introduces low level PM core functions one of which may be called by the radeonfb driver to complete the power transition.
2/2 actually makes radeonfb use the new function.
The patches (on top of the linux-next branch of suspend-2.6) have not been tested yet, but they compile (at least on x86_64).
Comments welcome.
Thanks,
Rafael
RFC PATCH 1/2 PCI PM: Introduce __pci_[start|complete]_power_transition()
From: Rafael J. Wysocki <[email protected]>
The radeonfb driver needs to program the device's PMCSR directly due to some quirky hardware it has to handle (see
http://bugzilla.kernel.org/show_bug.cgi?id=12846 for details) and after doing that it needs to call the platform (usually ACPI) to finish the power transition of the device. Currently it uses pci_set_power_state() for this purpose, however making a specific assumption about the internal behavior of this function, which has changed recently so that this assumption is no longer satisfied. For this reason, introduce __pci_complete_power_transition() that may be called by the radeonfb driver to complete the power transition of the device. For symmetry, introduce __pci_start_power_transition().
--- drivers/pci/pci.c | 66 +++++++++++++++++++++++++++++++++++++--------------- include/linux/pci.h | 1 2 files changed, 49 insertions(+), 18 deletions(-)
drivers/pci/pci.c +48 -18
@@ -540,6 +540,50 @@ void pci_update_current_state(struct pci }/** +* pci_platform_power_transition - Use platform to change device power state +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static int pci_platform_power_transition ( +struct pci_dev *dev,pci_power_t state) +{ +int error =0 ; + +if (platform_pci_power_manageable (dev)) + error =platform_pci_set_power_state (dev, state); + +if (!error) +pci_update_current_state (dev, state); + +return error; +} + +/** +* __pci_start_power_transition - Start power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static void __pci_start_power_transition (struct pci_dev *dev,pci_power_t state) +{ +if (state ==PCI_D0 ) +pci_platform_power_transition (dev,PCI_D0 ); +} + +/** +* __pci_complete_power_transition - Complete power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +* +* This function should not be called directly by device drivers. +*/ +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state) +{ +return state >PCI_D0 ? +pci_platform_power_transition (dev, state) : -ENODEV ; +} +EXPORT_SYMBOL_GPL (__pci_complete_power_transition); + +/** * pci_set_power_state - Set the power state of a PCI device * @dev: PCI device to handle. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
@@ -575,16 +619,8 @@ int pci_set_power_state(struct pci_dev *if (dev->current_state == state)return 0 ; -if (state ==PCI_D0 ) { -/* -* Allow the platform to change the state, for example via ACPI -* _PR0, _PS0 and some such, but do not trust it. -*/ -int ret =platform_pci_power_manageable (dev) ? -platform_pci_set_power_state (dev,PCI_D0 ) :0 ; -if (!ret) -pci_update_current_state (dev,PCI_D0 ); - } +__pci_start_power_transition (dev, state); +/* This device is quirked not to be put into D3, so don't put it in D3 */ if (state == PCI_D3hot && (dev->dev_flags &PCI_DEV_FLAGS_NO_D3 ))
@@ -592,14 +628,8 @@ int pci_set_power_state(struct pci_dev * error =pci_raw_set_power_state (dev, state); -if (state >PCI_D0 &&platform_pci_power_manageable (dev)) { -/* Allow the platform to finalize the transition */ -int ret =platform_pci_set_power_state (dev, state); -if (!ret) { -pci_update_current_state (dev, state); - error =0 ; - } - } +if (!__pci_complete_power_transition (dev, state)) + error =0 ;return error; }
include/linux/pci.h +1 -0
@@ -689,6 +689,7 @@ size_t pci_get_rom_size(struct pci_dev */* Power management related routines */ int pci_save_state (struct pci_dev *dev);int pci_restore_state (struct pci_dev *dev); +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state);int pci_set_power_state (struct pci_dev *dev,pci_power_t state);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);
RFC PATCH 1/2 PCI PM: Introduce __pci_[start|complete]_power_transition()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The radeonfb driver needs to program the device's PMCSR directly due to some quirky hardware it has to handle (see
http://bugzilla.kernel.org/show_bug.cgi?id=12846 for details) and after doing that it needs to call the platform (usually ACPI) to finish the power transition of the device. Currently it uses pci_set_power_state() for this purpose, however making a specific assumption about the internal behavior of this function, which has changed recently so that this assumption is no longer satisfied. For this reason, introduce __pci_complete_power_transition() that may be called by the radeonfb driver to complete the power transition of the device. For symmetry, introduce __pci_start_power_transition().
--- drivers/pci/pci.c | 66 +++++++++++++++++++++++++++++++++++++--------------- include/linux/pci.h | 1 2 files changed, 49 insertions(+), 18 deletions(-)
drivers/pci/pci.c +48 -18
@@ -540,6 +540,50 @@ void pci_update_current_state(struct pci }/** +* pci_platform_power_transition - Use platform to change device power state +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static int pci_platform_power_transition ( +struct pci_dev *dev,pci_power_t state) +{ +int error =0 ; + +if (platform_pci_power_manageable (dev)) + error =platform_pci_set_power_state (dev, state); + +if (!error) +pci_update_current_state (dev, state); + +return error; +} + +/** +* __pci_start_power_transition - Start power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static void __pci_start_power_transition (struct pci_dev *dev,pci_power_t state) +{ +if (state ==PCI_D0 ) +pci_platform_power_transition (dev,PCI_D0 ); +} + +/** +* __pci_complete_power_transition - Complete power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +* +* This function should not be called directly by device drivers. +*/ +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state) +{ +return state >PCI_D0 ? +pci_platform_power_transition (dev, state) : -ENODEV ; +} +EXPORT_SYMBOL_GPL (__pci_complete_power_transition); + +/** * pci_set_power_state - Set the power state of a PCI device * @dev: PCI device to handle. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
@@ -575,16 +619,8 @@ int pci_set_power_state(struct pci_dev *if (dev->current_state == state)return 0 ; -if (state ==PCI_D0 ) { -/* -* Allow the platform to change the state, for example via ACPI -* _PR0, _PS0 and some such, but do not trust it. -*/ -int ret =platform_pci_power_manageable (dev) ? -platform_pci_set_power_state (dev,PCI_D0 ) :0 ; -if (!ret) -pci_update_current_state (dev,PCI_D0 ); - } +__pci_start_power_transition (dev, state); +/* This device is quirked not to be put into D3, so don't put it in D3 */ if (state == PCI_D3hot && (dev->dev_flags &PCI_DEV_FLAGS_NO_D3 ))
@@ -592,14 +628,8 @@ int pci_set_power_state(struct pci_dev * error =pci_raw_set_power_state (dev, state); -if (state >PCI_D0 &&platform_pci_power_manageable (dev)) { -/* Allow the platform to finalize the transition */ -int ret =platform_pci_set_power_state (dev, state); -if (!ret) { -pci_update_current_state (dev, state); - error =0 ; - } - } +if (!__pci_complete_power_transition (dev, state)) + error =0 ;return error; }
include/linux/pci.h +1 -0
@@ -689,6 +689,7 @@ size_t pci_get_rom_size(struct pci_dev */* Power management related routines */ int pci_save_state (struct pci_dev *dev);int pci_restore_state (struct pci_dev *dev); +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state);int pci_set_power_state (struct pci_dev *dev,pci_power_t state);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);
Re: [RFC][PATCH 1/2] PCI PM: Introduce __pci_[start|complete]_power_transition()
Quoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The radeonfb driver needs to program the device's PMCSR directly due to some quirky hardware it has to handle (see
http://bugzilla.kernel.org/show_bug.cgi?id=12846 for details) and after doing that it needs to call the platform (usually ACPI) to finish the power transition of the device. Currently it usespci_set_power_state()for this purpose, however making a specific assumption about the internal behavior of this function, which has changed recently so that this assumption is no longer satisfied. For this reason, introduce__pci_complete_power_transition()that may be called by the radeonfb driver to complete the power transition of the device. For symmetry, introduce__pci_start_power_transition().
Quoted 1 line
Signed-off-by Rafael J. Wysocki <[email protected]>
Sorry, with this version of the patch the following failure scenarion is possible:
* a caller of pci_set_power_state() wants to put a device into D3
* pci_raw_set_power_state() fails and returns error code
* device is not power manageable by the platform, so __pci_complete_power_transition() returns 0
* pci_set_power_state() returns 0, although it should return the error code from pci_raw_set_power_state().
Also, if the device doesn't support the native PM and is not power manageable by the platform, we should always fall back to D0.
The updated patch below has these problems fixed.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PCI PM: Introduce __pci_[start|complete]_power_transition() (rev. 2)
The radeonfb driver needs to program the device's PMCSR directly due to some quirky hardware it has to handle (see
http://bugzilla.kernel.org/show_bug.cgi?id=12846 for details) and after doing that it needs to call the platform (usually ACPI) to finish the power transition of the device. Currently it uses pci_set_power_state() for this purpose, however making a specific assumption about the internal behavior of this function, which has changed recently so that this assumption is no longer satisfied. For this reason, introduce __pci_complete_power_transition() that may be called by the radeonfb driver to complete the power transition of the device. For symmetry, introduce __pci_start_power_transition().
--- drivers/pci/pci.c | 69 ++++++++++++++++++++++++++++++++++++++-------------- include/linux/pci.h | 1 2 files changed, 52 insertions(+), 18 deletions(-)
drivers/pci/pci.c +51 -18
@@ -540,6 +540,53 @@ void pci_update_current_state(struct pci }/** +* pci_platform_power_transition - Use platform to change device power state +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static int pci_platform_power_transition ( +struct pci_dev *dev,pci_power_t state) +{ +int error; + +if (platform_pci_power_manageable (dev)) { + error =platform_pci_set_power_state (dev, state); +if (!error) +pci_update_current_state (dev, state); + }else { + error = -ENODEV ; +pci_update_current_state (dev,PCI_D0 ); + } + +return error; +} + +/** +* __pci_start_power_transition - Start power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static void __pci_start_power_transition (struct pci_dev *dev,pci_power_t state) +{ +if (state ==PCI_D0 ) +pci_platform_power_transition (dev,PCI_D0 ); +} + +/** +* __pci_complete_power_transition - Complete power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +* +* This function should not be called directly by device drivers. +*/ +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state) +{ +return state >PCI_D0 ? +pci_platform_power_transition (dev, state) : -ENODEV ; +} +EXPORT_SYMBOL_GPL (__pci_complete_power_transition); + +/** * pci_set_power_state - Set the power state of a PCI device * @dev: PCI device to handle. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
@@ -575,16 +622,8 @@ int pci_set_power_state(struct pci_dev *if (dev->current_state == state)return 0 ; -if (state ==PCI_D0 ) { -/* -* Allow the platform to change the state, for example via ACPI -* _PR0, _PS0 and some such, but do not trust it. -*/ -int ret =platform_pci_power_manageable (dev) ? -platform_pci_set_power_state (dev,PCI_D0 ) :0 ; -if (!ret) -pci_update_current_state (dev,PCI_D0 ); - } +__pci_start_power_transition (dev, state); +/* This device is quirked not to be put into D3, so don't put it in D3 */ if (state == PCI_D3hot && (dev->dev_flags &PCI_DEV_FLAGS_NO_D3 ))
@@ -592,14 +631,8 @@ int pci_set_power_state(struct pci_dev * error =pci_raw_set_power_state (dev, state); -if (state >PCI_D0 &&platform_pci_power_manageable (dev)) { -/* Allow the platform to finalize the transition */ -int ret =platform_pci_set_power_state (dev, state); -if (!ret) { -pci_update_current_state (dev, state); - error =0 ; - } - } +if (!__pci_complete_power_transition (dev, state)) + error =0 ;return error; }
include/linux/pci.h +1 -0
@@ -689,6 +689,7 @@ size_t pci_get_rom_size(struct pci_dev */* Power management related routines */ int pci_save_state (struct pci_dev *dev);int pci_restore_state (struct pci_dev *dev); +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state);int pci_set_power_state (struct pci_dev *dev,pci_power_t state);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);
Re: [RFC][PATCH 1/2] PCI PM: Introduce __pci_[start|complete]_power_transition()
In reply to Rafael J. WysockiQuoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The radeonfb driver needs to program the device's PMCSR directly due to some quirky hardware it has to handle (see
http://bugzilla.kernel.org/show_bug.cgi?id=12846 for details) and after doing that it needs to call the platform (usually ACPI) to finish the power transition of the device. Currently it usespci_set_power_state()for this purpose, however making a specific assumption about the internal behavior of this function, which has changed recently so that this assumption is no longer satisfied. For this reason, introduce__pci_complete_power_transition()that may be called by the radeonfb driver to complete the power transition of the device. For symmetry, introduce__pci_start_power_transition().
Quoted 1 line
Signed-off-by Rafael J. Wysocki <[email protected]>
Sorry, with this version of the patch the following failure scenarion is possible:
* a caller of pci_set_power_state() wants to put a device into D3
* pci_raw_set_power_state() fails and returns error code
* device is not power manageable by the platform, so __pci_complete_power_transition() returns 0
* pci_set_power_state() returns 0, although it should return the error code from pci_raw_set_power_state().
Also, if the device doesn't support the native PM and is not power manageable by the platform, we should always fall back to D0.
The updated patch below has these problems fixed.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PCI PM: Introduce __pci_[start|complete]_power_transition() (rev. 2)
The radeonfb driver needs to program the device's PMCSR directly due to some quirky hardware it has to handle (see
http://bugzilla.kernel.org/show_bug.cgi?id=12846 for details) and after doing that it needs to call the platform (usually ACPI) to finish the power transition of the device. Currently it uses pci_set_power_state() for this purpose, however making a specific assumption about the internal behavior of this function, which has changed recently so that this assumption is no longer satisfied. For this reason, introduce __pci_complete_power_transition() that may be called by the radeonfb driver to complete the power transition of the device. For symmetry, introduce __pci_start_power_transition().
--- drivers/pci/pci.c | 69 ++++++++++++++++++++++++++++++++++++++-------------- include/linux/pci.h | 1 2 files changed, 52 insertions(+), 18 deletions(-)
drivers/pci/pci.c +51 -18
@@ -540,6 +540,53 @@ void pci_update_current_state(struct pci }/** +* pci_platform_power_transition - Use platform to change device power state +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static int pci_platform_power_transition ( +struct pci_dev *dev,pci_power_t state) +{ +int error; + +if (platform_pci_power_manageable (dev)) { + error =platform_pci_set_power_state (dev, state); +if (!error) +pci_update_current_state (dev, state); + }else { + error = -ENODEV ; +pci_update_current_state (dev,PCI_D0 ); + } + +return error; +} + +/** +* __pci_start_power_transition - Start power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +*/ +static void __pci_start_power_transition (struct pci_dev *dev,pci_power_t state) +{ +if (state ==PCI_D0 ) +pci_platform_power_transition (dev,PCI_D0 ); +} + +/** +* __pci_complete_power_transition - Complete power transition of a PCI device +* @dev: PCI device to handle. +* @state: State to put the device into. +* +* This function should not be called directly by device drivers. +*/ +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state) +{ +return state >PCI_D0 ? +pci_platform_power_transition (dev, state) : -ENODEV ; +} +EXPORT_SYMBOL_GPL (__pci_complete_power_transition); + +/** * pci_set_power_state - Set the power state of a PCI device * @dev: PCI device to handle. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
@@ -575,16 +622,8 @@ int pci_set_power_state(struct pci_dev *if (dev->current_state == state)return 0 ; -if (state ==PCI_D0 ) { -/* -* Allow the platform to change the state, for example via ACPI -* _PR0, _PS0 and some such, but do not trust it. -*/ -int ret =platform_pci_power_manageable (dev) ? -platform_pci_set_power_state (dev,PCI_D0 ) :0 ; -if (!ret) -pci_update_current_state (dev,PCI_D0 ); - } +__pci_start_power_transition (dev, state); +/* This device is quirked not to be put into D3, so don't put it in D3 */ if (state == PCI_D3hot && (dev->dev_flags &PCI_DEV_FLAGS_NO_D3 ))
@@ -592,14 +631,8 @@ int pci_set_power_state(struct pci_dev * error =pci_raw_set_power_state (dev, state); -if (state >PCI_D0 &&platform_pci_power_manageable (dev)) { -/* Allow the platform to finalize the transition */ -int ret =platform_pci_set_power_state (dev, state); -if (!ret) { -pci_update_current_state (dev, state); - error =0 ; - } - } +if (!__pci_complete_power_transition (dev, state)) + error =0 ;return error; }
include/linux/pci.h +1 -0
@@ -689,6 +689,7 @@ size_t pci_get_rom_size(struct pci_dev */* Power management related routines */ int pci_save_state (struct pci_dev *dev);int pci_restore_state (struct pci_dev *dev); +int __pci_complete_power_transition (struct pci_dev *dev,pci_power_t state);int pci_set_power_state (struct pci_dev *dev,pci_power_t state);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);
RFC PATCH 2/2 radeonfb: Use __pci_complete_power_transition()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Use __pci_complete_power_transition() to finalize the transition into D2 after programming the PMCSR of the device directly.
--- drivers/video/aty/radeon_pm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/aty/radeon_pm.c +1 -1
@@ -2582,7 +2582,7 @@ static void radeon_set_suspend(struct ra* calling pci_set_power_state() */ radeonfb_whack_power_state (rinfo,PCI_D2 ); -pci_set_power_state (rinfo->pdev,PCI_D2 ); +__pci_complete_power_transition (rinfo->pdev,PCI_D2 ); }else {printk (KERN_DEBUG "radeonfb (%s): switching to D0 state...\n" ,pci_name (rinfo->pdev));