Skip to contentSkip to conversation

PCI PM: Two patches for 2.6.31

PATCH Applied Rafael J. Wysocki 2 participants 14 messages May 18, 2009 – Jun 11, 2009 PCI

lore
Share & tools
lore
#0 lore raw

cover PCI PM: Two patches for 2.6.31

Hi,

The following two patches change the behavior of pci_raw_set_power_state() slightly to make if follow the PCI PM specification [1/2] and to prevent it from setting current_state in a wrong way [2/2].

Please consider for applying.

Best,
Rafael

#1 lore raw

PATCH 1/2 PCI PM: Follow PCI_PM_CTRL_NO_SOFT_RESET during transitions from D3

From: Rafael J. Wysocki <[email protected]>

According to the PCI PM specification (PCI Bus Power Management Interface Specification, Rev. 1.2, Section 5.4.1) we are supposed to reinitialize devices that have PCI_PM_CTRL_NO_SOFT_RESET clear during all transitions from PCI_D3hot to PCI_D0, but we only do it if the device's current_state field is equal to PCI_UNKNOWN.

This may lead to problems if a device with PCI_PM_CTRL_NO_SOFT_RESET unset is put into PCI_D3hot at run time by its driver and pci_set_power_state() is used to put it back into PCI_D0, because in that case the device will remain uninitialized after pci_set_power_state() has returned. Prevent that from happening by modifying pci_raw_set_power_state() to reinitialize devices with PCI_PM_CTRL_NO_SOFT_RESET unset during all transitions from D3 to D0.

---
 drivers/pci/pci.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/pci/pci.c +2 -0
Index: linux-2.6/drivers/pci/pci.c
===================================================================
@@ -480,6 +480,8 @@ static int pci_raw_set_power_state(struc
 		pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
 		pmcsr |= state;
 		break;
+	case PCI_D3hot:
+	case PCI_D3cold:
 	case PCI_UNKNOWN: /* Boot-up */
 		if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
 		 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
#2 lore raw

PATCH 1/2 PCI PM: Follow PCI_PM_CTRL_NO_SOFT_RESET during transitions from D3

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

According to the PCI PM specification (PCI Bus Power Management Interface Specification, Rev. 1.2, Section 5.4.1) we are supposed to reinitialize devices that have PCI_PM_CTRL_NO_SOFT_RESET clear during all transitions from PCI_D3hot to PCI_D0, but we only do it if the device's current_state field is equal to PCI_UNKNOWN.

This may lead to problems if a device with PCI_PM_CTRL_NO_SOFT_RESET unset is put into PCI_D3hot at run time by its driver and pci_set_power_state() is used to put it back into PCI_D0, because in that case the device will remain uninitialized after pci_set_power_state() has returned. Prevent that from happening by modifying pci_raw_set_power_state() to reinitialize devices with PCI_PM_CTRL_NO_SOFT_RESET unset during all transitions from D3 to D0.

---
 drivers/pci/pci.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/pci/pci.c +2 -0
Index: linux-2.6/drivers/pci/pci.c
===================================================================
@@ -480,6 +480,8 @@ static int pci_raw_set_power_state(struc
 		pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
 		pmcsr |= state;
 		break;
+	case PCI_D3hot:
+	case PCI_D3cold:
 	case PCI_UNKNOWN: /* Boot-up */
 		if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
 		 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
Applied
#3 lore raw

Re: [PATCH 1/2] PCI PM: Follow PCI_PM_CTRL_NO_SOFT_RESET during transitions from D3

Quoted 27 lines · On Mon, 18 May 2009 22:51:12 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

From: Rafael J. Wysocki <[email protected]>

According to the PCI PM specification (PCI Bus Power Management Interface Specification, Rev. 1.2, Section 5.4.1) we are supposed to reinitialize devices that have PCI_PM_CTRL_NO_SOFT_RESET clear during all transitions from PCI_D3hot to PCI_D0, but we only do it if the device's current_state field is equal to PCI_UNKNOWN.

This may lead to problems if a device with PCI_PM_CTRL_NO_SOFT_RESET unset is put into PCI_D3hot at run time by its driver and pci_set_power_state() is used to put it back into PCI_D0, because in that case the device will remain uninitialized after pci_set_power_state() has returned. Prevent that from happening by modifying pci_raw_set_power_state() to reinitialize devices with PCI_PM_CTRL_NO_SOFT_RESET unset during all transitions from D3 to D0.

---
 drivers/pci/pci.c |    2 ++
 1 file changed, 2 insertions(+)

Index: linux-2.6/drivers/pci/pci.c
===================================================================

drivers/pci/pci.c static int pci_raw_set_power_state(struc · line 487

Quoted 8 lines
drivers/pci/pci.c +2 -0
@@ -480,6 +480,8 @@ static int pci_raw_set_power_state(struc
 		pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
 		pmcsr |= state;
 		break;
+	case PCI_D3hot:
+	case PCI_D3cold:
 	case PCI_UNKNOWN: /* Boot-up */
 		if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
 		 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))

Applied to my linux-next branch, thanks Rafael. I've also included [email protected] in the cc, since this is a small but important fix.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Applied
#4 lore raw

Re: [PATCH 1/2] PCI PM: Follow PCI_PM_CTRL_NO_SOFT_RESET during transitions from D3

In reply to Rafael J. Wysocki
Quoted 27 lines · On Mon, 18 May 2009 22:51:12 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

From: Rafael J. Wysocki <[email protected]>

According to the PCI PM specification (PCI Bus Power Management Interface Specification, Rev. 1.2, Section 5.4.1) we are supposed to reinitialize devices that have PCI_PM_CTRL_NO_SOFT_RESET clear during all transitions from PCI_D3hot to PCI_D0, but we only do it if the device's current_state field is equal to PCI_UNKNOWN.

This may lead to problems if a device with PCI_PM_CTRL_NO_SOFT_RESET unset is put into PCI_D3hot at run time by its driver and pci_set_power_state() is used to put it back into PCI_D0, because in that case the device will remain uninitialized after pci_set_power_state() has returned. Prevent that from happening by modifying pci_raw_set_power_state() to reinitialize devices with PCI_PM_CTRL_NO_SOFT_RESET unset during all transitions from D3 to D0.

---
 drivers/pci/pci.c |    2 ++
 1 file changed, 2 insertions(+)

Index: linux-2.6/drivers/pci/pci.c
===================================================================

drivers/pci/pci.c static int pci_raw_set_power_state(struc · line 487

Quoted 8 lines
drivers/pci/pci.c +2 -0
@@ -480,6 +480,8 @@ static int pci_raw_set_power_state(struc
 		pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
 		pmcsr |= state;
 		break;
+	case PCI_D3hot:
+	case PCI_D3cold:
 	case PCI_UNKNOWN: /* Boot-up */
 		if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
 		 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))

Applied to my linux-next branch, thanks Rafael. I've also included [email protected] in the cc, since this is a small but important fix.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#5 lore raw

PATCH 2/2 PCI PM: Read device power state from register after updating it

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

---
 drivers/pci/pci.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pci/pci.c +7 -3
Index: linux-2.6/drivers/pci/pci.c
===================================================================
@@ -446,7 +446,7 @@ static int pci_raw_set_power_state(struc
 		return 0;
 
 	if (!dev->pm_cap)
-		return -EIO;
+		return -ENOSYS;
 
 	if (state < PCI_D0 || state > PCI_D3hot)
 		return -EINVAL;
@@ -465,7 +465,7 @@ static int pci_raw_set_power_state(struc
 	/* check if this device supports the desired state */
 	if ((state == PCI_D1 && !dev->d1_support)
 	   || (state == PCI_D2 && !dev->d2_support))
-		return -EIO;
+		return -ENOSYS;
 
 	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
 
@@ -502,7 +502,11 @@ static int pci_raw_set_power_state(struc
 	else if (state == PCI_D2 || dev->current_state == PCI_D2)
 		udelay(PCI_PM_D2_DELAY);
 
-	dev->current_state = state;
+	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
+	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
+	/* Return error code if we have failed to change the state */
+	if (dev->current_state != state)
+		return -EIO;
 
 	/* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
 	 * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning
#6 lore raw

PATCH 2/2 PCI PM: Read device power state from register after updating it

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

---
 drivers/pci/pci.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pci/pci.c +7 -3
Index: linux-2.6/drivers/pci/pci.c
===================================================================
@@ -446,7 +446,7 @@ static int pci_raw_set_power_state(struc
 		return 0;
 
 	if (!dev->pm_cap)
-		return -EIO;
+		return -ENOSYS;
 
 	if (state < PCI_D0 || state > PCI_D3hot)
 		return -EINVAL;
@@ -465,7 +465,7 @@ static int pci_raw_set_power_state(struc
 	/* check if this device supports the desired state */
 	if ((state == PCI_D1 && !dev->d1_support)
 	   || (state == PCI_D2 && !dev->d2_support))
-		return -EIO;
+		return -ENOSYS;
 
 	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
 
@@ -502,7 +502,11 @@ static int pci_raw_set_power_state(struc
 	else if (state == PCI_D2 || dev->current_state == PCI_D2)
 		udelay(PCI_PM_D2_DELAY);
 
-	dev->current_state = state;
+	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
+	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
+	/* Return error code if we have failed to change the state */
+	if (dev->current_state != state)
+		return -EIO;
 
 	/* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
 	 * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning
#7 lore raw

Re: [PATCH 2/2] PCI PM: Read device power state from register after updating it

Quoted 16 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

Quoted 5 lines

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

Having reconsidered it I think that -ENODEV is probably better than -ENOSYS for this purpose. Updated patch follows.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PCI PM: Read device power state from register after updating it

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENODEV instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

---
 drivers/pci/pci.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pci/pci.c +7 -3
Index: linux-2.6/drivers/pci/pci.c
===================================================================
@@ -446,7 +446,7 @@ static int pci_raw_set_power_state(struc
 		return 0;
 
 	if (!dev->pm_cap)
-		return -EIO;
+		return -ENODEV;
 
 	if (state < PCI_D0 || state > PCI_D3hot)
 		return -EINVAL;
@@ -465,7 +465,7 @@ static int pci_raw_set_power_state(struc
 	/* check if this device supports the desired state */
 	if ((state == PCI_D1 && !dev->d1_support)
 	   || (state == PCI_D2 && !dev->d2_support))
-		return -EIO;
+		return -ENODEV;
 
 	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
 
@@ -502,7 +502,11 @@ static int pci_raw_set_power_state(struc
 	else if (state == PCI_D2 || dev->current_state == PCI_D2)
 		udelay(PCI_PM_D2_DELAY);
 
-	dev->current_state = state;
+	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
+	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
+	/* Return error code if we have failed to change the state */
+	if (dev->current_state != state)
+		return -EIO;
 
 	/* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
 	 * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning
Applied
#8 lore raw

Re: [PATCH 2/2] PCI PM: Read device power state from register after updating it

Quoted 17 lines · On Tue, 26 May 2009 21:52:29 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 16 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

Quoted 8 lines
Quoted 5 lines

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

Having reconsidered it I think that -ENODEV is probably better than -ENOSYS for this purpose. Updated patch follows.

Applied to linux-next, thanks Rafael.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Applied
#9 lore raw

Re: [PATCH 2/2] PCI PM: Read device power state from register after updating it

In reply to Rafael J. Wysocki
Quoted 17 lines · On Tue, 26 May 2009 21:52:29 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 16 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

Quoted 8 lines
Quoted 5 lines

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

Having reconsidered it I think that -ENODEV is probably better than -ENOSYS for this purpose. Updated patch follows.

Applied to linux-next, thanks Rafael.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#10 lore raw

Re: [PATCH 2/2] PCI PM: Read device power state from register after updating it

Quoted 26 lines · Jesse Barnes
Quoted 23 lines · On Tue, 26 May 2009 21:52:29 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 21 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

Quoted 4 lines
Quoted 2 lines

Having reconsidered it I think that -ENODEV is probably better than -ENOSYS for this purpose. Updated patch follows.

Applied to linux-next, thanks Rafael.

Please drop. It has been reported by Jiri to cause a regression to happen.

Best,
Rafael

#11 lore raw

Re: [PATCH 2/2] PCI PM: Read device power state from register after updating it

Quoted 28 lines · On Thu, 11 Jun 2009 12:53:16 -0700 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 27 lines · Jesse Barnes
Quoted 24 lines · On Tue, 26 May 2009 21:52:29 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 22 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Having reconsidered it I think that -ENODEV is probably better than -ENOSYS for this purpose. Updated patch follows.

Applied to linux-next, thanks Rafael.

Please drop. It has been reported by Jiri to cause a regression to happen.

Ah as I went through the rebase I thought I remembered something like that. Will drop.

Thanks,

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#12 lore raw

Re: [PATCH 2/2] PCI PM: Read device power state from register after updating it

In reply to Rafael J. Wysocki
Quoted 28 lines · On Thu, 11 Jun 2009 12:53:16 -0700 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 27 lines · Jesse Barnes
Quoted 24 lines · On Tue, 26 May 2009 21:52:29 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 22 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Having reconsidered it I think that -ENODEV is probably better than -ENOSYS for this purpose. Updated patch follows.

Applied to linux-next, thanks Rafael.

Please drop. It has been reported by Jiri to cause a regression to happen.

Ah as I went through the rebase I thought I remembered something like that. Will drop.

Thanks,

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#13 lore raw

Re: [PATCH 2/2] PCI PM: Read device power state from register after updating it

In reply to Jesse Barnes
Quoted 26 lines · Jesse Barnes
Quoted 23 lines · On Tue, 26 May 2009 21:52:29 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 21 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After attempting to change the power state of a PCI device pci_raw_set_power_state() doesn't check if the value it wrote into the device's PCI_PM_CTRL register has been stored in there. Still, it modifies the device's current_state field as though that's the case. This may cause the driver of the device to think that its power state has been changed while in fact it hasn't.

To prevent such situations from happening modify pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL register after writing into it and uses the value read from the register to update the device's current_state field. Also make it return -EIO if the new state of the device is not equal to the state requested by the called.

To distinguish this error condition from the other ones make pci_raw_set_power_state() return -ENOSYS instead of -EIO when it is impossible to change the power state of the device, because it doesn't support the native PCI PM at all or the requested target state is not supported by it.

Quoted 4 lines
Quoted 2 lines

Having reconsidered it I think that -ENODEV is probably better than -ENOSYS for this purpose. Updated patch follows.

Applied to linux-next, thanks Rafael.

Please drop. It has been reported by Jiri to cause a regression to happen.

Best,
Rafael