Skip to contentSkip to conversation

Cleanup PCI power states

PATCH Applied Pavel Machek 5 participants 26 messages Nov 16, 2004 – Dec 22, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi!

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

Pavel

[amd8111e.c piece below shows exactly why this is needed; feel free to apply it or not...]

include/linux/pci.h +8 -0
@@ -480,6 +480,14 @@
 #define DEVICE_COUNT_COMPATIBLE	4
 #define DEVICE_COUNT_RESOURCE	12
 
+typedef int __bitwise pci_power_t;
+
+#define PCI_D0	((pci_power_t __force) 0)
+#define PCI_D1	((pci_power_t __force) 1)
+#define PCI_D2	((pci_power_t __force) 2)
+#define PCI_D3hot	((pci_power_t __force) 3)
+#define PCI_D3cold	((pci_power_t __force) 4)
+
 /*
  * The pci_dev structure is used to describe PCI devices.
  */
drivers/net/amd8111e.c +8 -8
@@ -1865,17 +1865,17 @@
 		if(lp->options & OPTION_WAKE_PHY_ENABLE)
 			amd8111e_enable_link_change(lp);	
 		
-		pci_enable_wake(pci_dev, 3, 1);
-		pci_enable_wake(pci_dev, 4, 1); /* D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 1);
+		pci_enable_wake(pci_dev, PCI_D3cold, 1);
 
 	}
 	else{		
-		pci_enable_wake(pci_dev, 3, 0);
-		pci_enable_wake(pci_dev, 4, 0); /* 4 == D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 0);
+		pci_enable_wake(pci_dev, PCI_D3cold, 0);
 	}
 	
 	pci_save_state(pci_dev, lp->pm_state);
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 
 	return 0;
 }
@@ -1887,11 +1887,11 @@
 	if (!netif_running(dev))
 		return 0;
 
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev, lp->pm_state);
 
-	pci_enable_wake(pci_dev, 3, 0);
-	pci_enable_wake(pci_dev, 4, 0); /* D3 cold */
+	pci_enable_wake(pci_dev, PCI_D3hot, 0);
+	pci_enable_wake(pci_dev, PCI_D3cold, 0);
 
 	netif_device_attach(dev);
 
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#1 lore raw
Quoted 5 lines · Pavel Machek

Hi!

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

thanks,

greg k-h

#2 lore raw

Hi!

Quoted 10 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
Pavel

Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         
#3 lore raw
Quoted 6 lines · Pavel Machek

Hi!

Quoted 4 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

Quoted 8 lines
Quoted 6 lines

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

thanks,

greg k-h

#4 lore raw

Hi!

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Pavel

include/linux/pci.h +12 -4
@@ -480,6 +480,14 @@
 #define DEVICE_COUNT_COMPATIBLE	4
 #define DEVICE_COUNT_RESOURCE	12
 
+typedef int __bitwise pci_power_t;
+
+#define PCI_D0	((pci_power_t __force) 0)
+#define PCI_D1	((pci_power_t __force) 1)
+#define PCI_D2	((pci_power_t __force) 2)
+#define PCI_D3hot	((pci_power_t __force) 3)
+#define PCI_D3cold	((pci_power_t __force) 4)
+
 /*
  * The pci_dev structure is used to describe PCI devices.
  */
@@ -508,7 +516,7 @@
 					   this if your device has broken DMA
 					   or supports 64-bit transfers.  */
 
-	u32             current_state;  /* Current operating state. In ACPI-speak,
+	pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
 					   this is D0-D3, D0 being fully functional,
 					   and D3 being off. */
 
@@ -645,7 +653,7 @@
 	struct pci_dynids dynids;
 };
 
-#define	to_pci_driver(drv) container_of(drv,struct pci_driver, driver)
+#define	to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
 
 /**
  * PCI_DEVICE - macro used to describe a specific pci device
@@ -781,8 +789,8 @@
 /* Power management related routines */
 int pci_save_state(struct pci_dev *dev, u32 *buffer);
 int pci_restore_state(struct pci_dev *dev, u32 *buffer);
-int pci_set_power_state(struct pci_dev *dev, int state);
-int pci_enable_wake(struct pci_dev *dev, u32 state, int enable);
+int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
+int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
 
 /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
 void pci_bus_assign_resources(struct pci_bus *bus);
drivers/pci/pci.c +4 -4
@@ -229,7 +229,7 @@
 /**
  * pci_set_power_state - Set the power state of a PCI device
  * @dev: PCI device to be suspended
- * @state: Power state we're entering
+ * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
  *
  * Transition a device to a new power state, using the Power Management 
  * Capabilities in the device's config space.
@@ -242,7 +242,7 @@
  */
 
 int
-pci_set_power_state(struct pci_dev *dev, int state)
+pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
 	int pm;
 	u16 pmcsr;
@@ -365,7 +389,7 @@
 {
 	int err;
 
-	pci_set_power_state(dev, 0);
+	pci_set_power_state(dev, PCI_D0);
 	if ((err = pcibios_enable_device(dev, bars)) < 0)
 		return err;
 	return 0;
@@ -422,7 +446,7 @@
  * 0 if operation is successful.
  * 
  */
-int pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
+int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
 {
 	int pm;
 	u16 value;
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#5 lore raw
Quoted 13 lines · Pavel Machek

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Hm, ok, can everyone agree (especially the linux-pm list people) that the patch below is the way we are all moving toward?

Because, if so, I'll apply this and then start working on fixing all of the sparse warnings this will cause.

thanks,

greg k-h

Quoted 89 lines
include/linux/pci.h +12 -4
@@ -480,6 +480,14 @@
 #define DEVICE_COUNT_COMPATIBLE	4
 #define DEVICE_COUNT_RESOURCE	12
 
+typedef int __bitwise pci_power_t;
+
+#define PCI_D0	((pci_power_t __force) 0)
+#define PCI_D1	((pci_power_t __force) 1)
+#define PCI_D2	((pci_power_t __force) 2)
+#define PCI_D3hot	((pci_power_t __force) 3)
+#define PCI_D3cold	((pci_power_t __force) 4)
+
 /*
  * The pci_dev structure is used to describe PCI devices.
  */
@@ -508,7 +516,7 @@
 					   this if your device has broken DMA
 					   or supports 64-bit transfers.  */
 
-	u32             current_state;  /* Current operating state. In ACPI-speak,
+	pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
 					   this is D0-D3, D0 being fully functional,
 					   and D3 being off. */
 
@@ -645,7 +653,7 @@
 	struct pci_dynids dynids;
 };
 
-#define	to_pci_driver(drv) container_of(drv,struct pci_driver, driver)
+#define	to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
 
 /**
  * PCI_DEVICE - macro used to describe a specific pci device
@@ -781,8 +789,8 @@
 /* Power management related routines */
 int pci_save_state(struct pci_dev *dev, u32 *buffer);
 int pci_restore_state(struct pci_dev *dev, u32 *buffer);
-int pci_set_power_state(struct pci_dev *dev, int state);
-int pci_enable_wake(struct pci_dev *dev, u32 state, int enable);
+int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
+int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
 
 /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
 void pci_bus_assign_resources(struct pci_bus *bus);
drivers/pci/pci.c +4 -4
@@ -229,7 +229,7 @@
 /**
  * pci_set_power_state - Set the power state of a PCI device
  * @dev: PCI device to be suspended
- * @state: Power state we're entering
+ * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
  *
  * Transition a device to a new power state, using the Power Management 
  * Capabilities in the device's config space.
@@ -242,7 +242,7 @@
  */
 
 int
-pci_set_power_state(struct pci_dev *dev, int state)
+pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
 	int pm;
 	u16 pmcsr;
@@ -365,7 +389,7 @@
 {
 	int err;
 
-	pci_set_power_state(dev, 0);
+	pci_set_power_state(dev, PCI_D0);
 	if ((err = pcibios_enable_device(dev, bars)) < 0)
 		return err;
 	return 0;
@@ -422,7 +446,7 @@
  * 0 if operation is successful.
  * 
  */
-int pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
+int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
 {
 	int pm;
 	u16 value;
Signature · 3 lines
-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#6 lore raw

Hi!

Quoted 8 lines
Quoted 2 lines

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Hm, ok, can everyone agree (especially the linux-pm list people) that the patch below is the way we are all moving toward?

Because, if so, I'll apply this and then start working on fixing all of the sparse warnings this will cause.

I do have some warning-fixes here, too. So if you apply it tell me and I'll generate a copy for you.

Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#7 lore raw
In reply to Greg KH
Quoted 2 lines · Greg KH

Hm, ok, can everyone agree (especially the linux-pm list people) that the patch below is the way we are all moving toward?

Yes, provided it is clear that this code only gives a _default_ mapping and that drivers will have access to the complete pm_message_t data so they can choose a different mapping if they want.

Alan Stern

#8 lore raw

Hi!

Quoted 6 lines
Quoted 2 lines

Hm, ok, can everyone agree (especially the linux-pm list people) that the patch below is the way we are all moving toward?

Yes, provided it is clear that this code only gives a _default_ mapping and that drivers will have access to the complete pm_message_t data so they can choose a different mapping if they want.

Yes, that's the plan.
Pavel

Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
#9 lore raw
In reply to Pavel Machek
Quoted 13 lines · Pavel Machek

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Now, care to send patches to fix up all of the new sparse warnings in the drivers/pci/* directory?

Also, next time I need a "Signed-off-by:" line for the patch.

thanks,

greg k-h

#10 lore raw

Hi!

Quoted 6 lines
Quoted 2 lines

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Thanks... Hopefully I guessed the change right, otherwise this will need to be applied by hand.

This adds missing prototype for pci_choose_state.

include/linux/pci.h renamed from /include/linux/pci.h +2 -0
@@ -790,6 +790,7 @@
 int pci_save_state(struct pci_dev *dev, u32 *buffer);
 int pci_restore_state(struct pci_dev *dev, u32 *buffer);
 int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
+pci_power_t pci_choose_state(struct pci_dev *dev, u32 state);
 int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
 
 /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
@@ -924,6 +925,7 @@
 static inline int pci_save_state(struct pci_dev *dev, u32 *buffer) { return 0; }
 static inline int pci_restore_state(struct pci_dev *dev, u32 *buffer) { return 0; }
 static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { return 0; }
+static inline pci_power_t pci_choose_state(struct pci_dev *dev, u32 state) { return PCI_D0; }
 static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) { return 0; }
 
 #define	isa_bridge	((struct pci_dev *)NULL)
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Applied
#11 lore raw
Quoted 11 lines · Pavel Machek

Hi!

Quoted 6 lines
Quoted 2 lines

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Thanks... Hopefully I guessed the change right, otherwise this will need to be applied by hand.

You guessed right :)

Quoted 3 lines

This adds missing prototype for pci_choose_state.

Applied, thanks.

greg k-h

#12 lore raw
In reply to Greg KH

Hi!

Quoted 9 lines
Quoted 2 lines

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Now, care to send patches to fix up all of the new sparse warnings in the drivers/pci/* directory?

This should reduce number of warnings in pci.c. It will still warn on comparison (because we are using __bitwise, but in fact we want something like "this is unique but arithmetic is still ok"), but that probably needs to be fixed in sparse.

Also killed "function does not return anything" warning.

Please apply,
Pavel

drivers/pci/pci.c renamed from /drivers/pci/pci.c +9 -8
@@ -248,13 +248,13 @@
 	u16 pmcsr;
 
 	/* bound the state we're entering */
-	if (state > 3) state = 3;
+	if (state > PCI_D3hot) state = PCI_D3hot;
 
 	/* Validate current state:
 	 * Can enter D0 from any state, but if we can only go deeper 
 	 * to sleep if we're already in a low power state
 	 */
-	if (state > 0 && dev->current_state > state)
+	if (state != PCI_D0 && dev->current_state > state)
 		return -EINVAL;
 	else if (dev->current_state == state) 
 		return 0;        /* we're already there */
@@ -266,18 +266,18 @@
 	if (!pm) return -EIO; 
 
 	/* check if this device supports the desired state */
-	if (state == 1 || state == 2) {
+	if (state == PCI_D1 || state == PCI_D2) {
 		u16 pmc;
 		pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
-		if (state == 1 && !(pmc & PCI_PM_CAP_D1)) return -EIO;
-		else if (state == 2 && !(pmc & PCI_PM_CAP_D2)) return -EIO;
+		if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1)) return -EIO;
+		else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2)) return -EIO;
 	}
 
 	/* If we're in D3, force entire word to 0.
 	 * This doesn't affect PME_Status, disables PME_En, and
 	 * sets PowerState to 0.
 	 */
-	if (dev->current_state >= 3)
+	if (dev->current_state >= PCI_D3hot)
 		pmcsr = 0;
 	else {
 		pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
@@ -290,9 +290,9 @@
 
 	/* Mandatory power management transition delays */
 	/* see PCI PM 1.1 5.6.1 table 18 */
-	if(state == 3 || dev->current_state == 3)
+	if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
 		msleep(10);
-	else if(state == 2 || dev->current_state == 2)
+	else if (state == PCI_D2 || dev->current_state == PCI_D2)
 		udelay(200);
 	dev->current_state = state;
 
@@ -319,6 +319,7 @@
 	case 3: return PCI_D3hot;
 	default: BUG();
 	}
+	return PCI_D0;
 }
 
 EXPORT_SYMBOL(pci_choose_state);
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#13 lore raw
Quoted 12 lines · Pavel Machek

Hi!

Quoted 9 lines
Quoted 2 lines

Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes.

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Now, care to send patches to fix up all of the new sparse warnings in the drivers/pci/* directory?

Quoted 8 lines

This should reduce number of warnings in pci.c. It will still warn on comparison (because we are using __bitwise, but in fact we want something like "this is unique but arithmetic is still ok"), but that probably needs to be fixed in sparse.

Also killed "function does not return anything" warning.

Please apply,

What kernel tree is this against? I get rejects in the second hunk.

thanks,

greg k-h

#14 lore raw

Hi!

Quoted 10 lines
Quoted 8 lines

This should reduce number of warnings in pci.c. It will still warn on comparison (because we are using __bitwise, but in fact we want something like "this is unique but arithmetic is still ok"), but that probably needs to be fixed in sparse.

Also killed "function does not return anything" warning.

Please apply,

What kernel tree is this against? I get rejects in the second hunk.

Strange, it applied okay here over latest -bk. What tree should I generate it against?
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#15 lore raw
Quoted 7 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 5 lines

This should reduce number of warnings in pci.c. It will still warn on comparison (because we are using __bitwise, but in fact we want something like "this is unique but arithmetic is still ok"), but that probably needs to be fixed in sparse.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Also killed "function does not return anything" warning.

Please apply,

What kernel tree is this against? I get rejects in the second hunk.

Strange, it applied okay here over latest -bk. What tree should I generate it against?

Ah, ok, it's my fault, I have some changes by someone else in my tree. I'll merge it in by hand. Sorry about that.

greg k-h

#16 lore raw
In reply to Greg KH

Hi!

Quoted 6 lines

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Now, care to send patches to fix up all of the new sparse warnings in the drivers/pci/* directory?

This should fix warnings in drivers/net/* and bttv (with exception of via-rhine, which I'll do separately). Do you think you could apply it, or shall I ask Andrew, or... ?

Pavel

drivers/media/video/bttv-driver.c +2 -2
@@ -3945,7 +3945,7 @@
 
 	/* save pci state */
 	pci_save_state(pci_dev, btv->state.pci_cfg);
-	if (0 != pci_set_power_state(pci_dev, state)) {
+	if (0 != pci_set_power_state(pci_dev, device_to_pci_power(pci_dev, state))) {
 		pci_disable_device(pci_dev);
 		btv->state.disabled = 1;
 	}
@@ -3964,7 +3964,7 @@
 		pci_enable_device(pci_dev);
 		btv->state.disabled = 0;
 	}
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev, btv->state.pci_cfg);
 
 	/* restore bt878 state */
drivers/net/3c59x.c +4 -4
@@ -1550,7 +1550,7 @@
 	int i;
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		pci_restore_state(VORTEX_PCI(vp), vp->power_state);
 	}
 
@@ -2942,7 +2942,7 @@
 	/* The kernel core really should have pci_get_power_state() */
 
 	if(state != 0)
-		pci_set_power_state(VORTEX_PCI(vp), 0);
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
 	err = vortex_do_ioctl(dev, rq, cmd);
 	if(state != 0)
 		pci_set_power_state(VORTEX_PCI(vp), state);
@@ -3141,7 +3141,7 @@
 
 	/* Change the power state to D3; RxEnable doesn't take effect. */
 	pci_enable_wake(VORTEX_PCI(vp), 0, 1);
-	pci_set_power_state(VORTEX_PCI(vp), 3);
+	pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot);
 }
 
 
@@ -3164,7 +3164,7 @@
 	unregister_netdev(dev);
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		if (vp->pm_state_valid)
 			pci_restore_state(VORTEX_PCI(vp), vp->power_state);
 	}
drivers/net/8139cp.c +3 -3
@@ -1623,7 +1623,7 @@
 static void cp_set_d3_state (struct cp_private *cp)
 {
 	pci_enable_wake (cp->pdev, 0, 1); /* Enable PME# generation */
-	pci_set_power_state (cp->pdev, 3);
+	pci_set_power_state (cp->pdev, PCI_D3hot);
 }
 
 static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -1813,7 +1813,7 @@
 		BUG();
 	unregister_netdev(dev);
 	iounmap(cp->regs);
-	if (cp->wol_enabled) pci_set_power_state (pdev, 0);
+	if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0);
 	pci_release_regions(pdev);
 	pci_clear_mwi(pdev);
 	pci_disable_device(pdev);
@@ -1863,7 +1863,7 @@
 	netif_device_attach (dev);
 	
 	if (cp->pdev && cp->wol_enabled) {
-		pci_set_power_state (cp->pdev, 0);
+		pci_set_power_state (cp->pdev, PCI_D0);
 		pci_restore_state (cp->pdev, cp->power_state);
 	}
 	
drivers/net/8139too.c +2 -2
@@ -2608,7 +2608,7 @@
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -2622,7 +2622,7 @@
 	pci_restore_state (pdev, tp->pci_state);
 	if (!netif_running (dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	rtl8139_init_ring (dev);
 	rtl8139_hw_start (dev);
 	netif_device_attach (dev);
drivers/net/amd8111e.c +8 -8
@@ -1865,17 +1865,17 @@
 		if(lp->options & OPTION_WAKE_PHY_ENABLE)
 			amd8111e_enable_link_change(lp);	
 		
-		pci_enable_wake(pci_dev, 3, 1);
-		pci_enable_wake(pci_dev, 4, 1); /* D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 1);
+		pci_enable_wake(pci_dev, PCI_D3cold, 1);
 
 	}
 	else{		
-		pci_enable_wake(pci_dev, 3, 0);
-		pci_enable_wake(pci_dev, 4, 0); /* 4 == D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 0);
+		pci_enable_wake(pci_dev, PCI_D3cold, 0);
 	}
 	
 	pci_save_state(pci_dev, lp->pm_state);
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 
 	return 0;
 }
@@ -1887,11 +1887,11 @@
 	if (!netif_running(dev))
 		return 0;
 
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev, lp->pm_state);
 
-	pci_enable_wake(pci_dev, 3, 0);
-	pci_enable_wake(pci_dev, 4, 0); /* D3 cold */
+	pci_enable_wake(pci_dev, PCI_D3hot, 0);
+	pci_enable_wake(pci_dev, PCI_D3cold, 0);
 
 	netif_device_attach(dev);
 
drivers/net/e100.c +2 -2
@@ -2313,7 +2313,7 @@
 	pci_save_state(pdev, nic->pm_state);
 	pci_enable_wake(pdev, state, nic->flags & (wol_magic | e100_asf(nic)));
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
 	return 0;
 }
@@ -2323,7 +2323,7 @@
 	struct net_device *netdev = pci_get_drvdata(pdev);
 	struct nic *nic = netdev_priv(netdev);
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, nic->pm_state);
 	e100_hw_init(nic);
 
drivers/net/eepro100.c +4 -4
@@ -1015,7 +1005,7 @@
 	if (netif_msg_ifup(sp))
 		printk(KERN_DEBUG "%s: speedo_open() irq %d.\n", dev->name, dev->irq);
 
-	pci_set_power_state(sp->pdev, 0);
+	pci_set_power_state(sp->pdev, PCI_D0);
 
 	/* Set up the Tx queue early.. */
 	sp->cur_tx = 0;
@@ -1964,7 +1954,7 @@
 	if (netif_msg_ifdown(sp))
 		printk(KERN_DEBUG "%s: %d multicast blocks dropped.\n", dev->name, i);
 
-	pci_set_power_state(sp->pdev, 2);
+	pci_set_power_state(sp->pdev, PCI_D2);
 
 	return 0;
 }
@@ -2103,7 +2093,7 @@
 		   access from the timeout handler.
 		   They are currently serialized only with MDIO access from the
 		   timer routine.  2000/05/09 SAW */
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
 		if (t)
@@ -2114,7 +2104,7 @@
 	case SIOCSMIIREG:		/* Write MII PHY register. */
 		if (!capable(CAP_NET_ADMIN))
 			return -EPERM;
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		mdio_write(dev, data->phy_id, data->reg_num, data->val_in);
 		if (t)
drivers/net/pci-skeleton.c +2 -2
@@ -1922,7 +1922,7 @@
 	spin_unlock_irqrestore (&tp->lock, flags);
 
 	pci_save_state (pdev, tp->pci_state);
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -1935,7 +1935,7 @@
 
 	if (!netif_running(dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	pci_restore_state (pdev, tp->pci_state);
 	netif_device_attach (dev);
 	netdrv_hw_start (dev);
drivers/net/sis900.c +2 -2
@@ -2212,7 +2212,7 @@
 	/* Stop the chip's Tx and Rx Status Machine */
 	outl(RxDIS | TxDIS | inl(ioaddr + cr), ioaddr + cr);
 
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 	pci_save_state(pci_dev, sis_priv->pci_state);
 
 	return 0;
@@ -2227,7 +2227,7 @@
 	if(!netif_running(net_dev))
 		return 0;
 	pci_restore_state(pci_dev, sis_priv->pci_state);
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 
 	sis900_init_rxfilter(net_dev);
 
drivers/net/starfire.c +1 -1
@@ -2186,7 +2186,7 @@
 	unregister_netdev(dev);
 
 	/* XXX: add wakeup code -- requires firmware for MagicPacket */
-	pci_set_power_state(pdev, 3);	/* go to sleep in D3 mode */
+	pci_set_power_state(pdev, PCI_D3hot);	/* go to sleep in D3 mode */
 	pci_disable_device(pdev);
 
 	iounmap((char *)dev->base_addr);
drivers/net/typhoon.c +3 -3
@@ -1884,7 +1884,7 @@
 
 	pci_enable_wake(tp->pdev, state, 1);
 	pci_disable_device(pdev);
-	return pci_set_power_state(pdev, state);
+	return pci_set_power_state(pdev, pci_choose_state(pdev, state));
 }
 
 static int
@@ -1893,7 +1893,7 @@
 	struct pci_dev *pdev = tp->pdev;
 	void __iomem *ioaddr = tp->ioaddr;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, tp->pci_state);
 
 	/* Post 2.x.x versions of the Sleep Image require a reset before
@@ -2541,7 +2541,7 @@
 	struct typhoon *tp = (struct typhoon *) (dev->priv);
 
 	unregister_netdev(dev);
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, tp->pci_state);
 	typhoon_reset(tp->ioaddr, NoWait);
 	iounmap(tp->ioaddr);
drivers/net/via-velocity.c +16 -16
@@ -804,7 +804,7 @@
 	
 	/* and leave the chip powered down */
 	
-	pci_set_power_state(pdev, 3);
+	pci_set_power_state(pdev, PCI_D3hot);
 #ifdef CONFIG_PM
 	{
 		unsigned long flags;
@@ -1742,7 +1742,7 @@
 		goto err_free_rd_ring;
 	
 	/* Ensure chip is running */	
-	pci_set_power_state(vptr->pdev, 0);
+	pci_set_power_state(vptr->pdev, PCI_D0);
 	
 	velocity_init_registers(vptr, VELOCITY_INIT_COLD);
 
@@ -1750,7 +1750,7 @@
 			  dev->name, dev);
 	if (ret < 0) {
 		/* Power down the chip */
-		pci_set_power_state(vptr->pdev, 3);
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		goto err_free_td_ring;
 	}
 
@@ -1868,7 +1868,7 @@
 		free_irq(dev->irq, dev);
 		
 	/* Power down the chip */
-	pci_set_power_state(vptr->pdev, 3);
+	pci_set_power_state(vptr->pdev, PCI_D3hot);
 	
 	/* Free the resources */
 	velocity_free_td_ring(vptr);
@@ -2194,8 +2194,8 @@
 	/* If we are asked for information and the device is power
 	   saving then we need to bring the device back up to talk to it */
 	   	
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 		
 	switch (cmd) {
 	case SIOCGMIIPHY:	/* Get address of MII PHY in use. */
@@ -2207,8 +2207,8 @@
 	default:
 		ret = -EOPNOTSUPP;
 	}
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		
 		
 	return ret;
@@ -2818,8 +2818,8 @@
 static int velocity_ethtool_up(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 	return 0;
 }	
 
@@ -2834,8 +2834,8 @@
 static void velocity_ethtool_down(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 }
 
 static int velocity_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -3229,15 +3229,15 @@
 		velocity_shutdown(vptr);
 		velocity_set_wol(vptr);
 		pci_enable_wake(pdev, 3, 1);
-		pci_set_power_state(pdev, 3);
+		pci_set_power_state(pdev, PCI_D3hot);
 	} else {
 		velocity_save_context(vptr, &vptr->context);
 		velocity_shutdown(vptr);
 		pci_disable_device(pdev);
-		pci_set_power_state(pdev, state);
+		pci_set_power_state(pdev, pci_choose_state(pdev, state));
 	}
 #else
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 #endif
 	spin_unlock_irqrestore(&vptr->lock, flags);
 	return 0;
@@ -3252,7 +3252,7 @@
 	if(!netif_running(vptr->dev))
 		return 0;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_enable_wake(pdev, 0, 0);
 	pci_restore_state(pdev, vptr->pci_state);
 
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#17 lore raw
Quoted 6 lines · Pavel Machek

Hi!

Quoted 4 lines

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Quoted 8 lines
Quoted 2 lines

Now, care to send patches to fix up all of the new sparse warnings in the drivers/pci/* directory?

This should fix warnings in drivers/net/* and bttv (with exception of via-rhine, which I'll do separately). Do you think you could apply it, or shall I ask Andrew, or... ?

What kernel tree is this against? I get lots of rejects against the latest -bk tree.

thanks,

greg k-h

#18 lore raw

Hi!

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Now, care to send patches to fix up all of the new sparse warnings in the drivers/pci/* directory?

Quoted 8 lines
Quoted 5 lines

This should fix warnings in drivers/net/* and bttv (with exception of via-rhine, which I'll do separately). Do you think you could apply it, or shall I ask Andrew, or... ?

What kernel tree is this against? I get lots of rejects against the latest -bk tree.

It was against 2.6.9. pci_{save,restore}_state(), therefore it rejects in surrounding text. Here's version against latest -bk.

This should fix sparse warnings in drivers/net/* and bttv. Please apply,

Pavel

drivers/media/video/bttv-driver.c +2 -2
@@ -3942,7 +3942,7 @@
 
 	/* save pci state */
 	pci_save_state(pci_dev);
-	if (0 != pci_set_power_state(pci_dev, state)) {
+	if (0 != pci_set_power_state(pci_dev, device_to_pci_power(pci_dev, state))) {
 		pci_disable_device(pci_dev);
 		btv->state.disabled = 1;
 	}
@@ -3961,7 +3961,7 @@
 		pci_enable_device(pci_dev);
 		btv->state.disabled = 0;
 	}
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev);
 
 	/* restore bt878 state */
drivers/net/3c59x.c +4 -4
@@ -1549,7 +1549,7 @@
 	int i;
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		pci_restore_state(VORTEX_PCI(vp));
 	}
 
@@ -2941,7 +2941,7 @@
 	/* The kernel core really should have pci_get_power_state() */
 
 	if(state != 0)
-		pci_set_power_state(VORTEX_PCI(vp), 0);
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
 	err = vortex_do_ioctl(dev, rq, cmd);
 	if(state != 0)
 		pci_set_power_state(VORTEX_PCI(vp), state);
@@ -3140,7 +3140,7 @@
 
 	/* Change the power state to D3; RxEnable doesn't take effect. */
 	pci_enable_wake(VORTEX_PCI(vp), 0, 1);
-	pci_set_power_state(VORTEX_PCI(vp), 3);
+	pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot);
 }
 
 
@@ -3163,7 +3163,7 @@
 	unregister_netdev(dev);
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		if (vp->pm_state_valid)
 			pci_restore_state(VORTEX_PCI(vp));
 	}
drivers/net/8139cp.c +3 -3
@@ -1623,7 +1623,7 @@
 static void cp_set_d3_state (struct cp_private *cp)
 {
 	pci_enable_wake (cp->pdev, 0, 1); /* Enable PME# generation */
-	pci_set_power_state (cp->pdev, 3);
+	pci_set_power_state (cp->pdev, PCI_D3hot);
 }
 
 static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -1813,7 +1813,7 @@
 		BUG();
 	unregister_netdev(dev);
 	iounmap(cp->regs);
-	if (cp->wol_enabled) pci_set_power_state (pdev, 0);
+	if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0);
 	pci_release_regions(pdev);
 	pci_clear_mwi(pdev);
 	pci_disable_device(pdev);
@@ -1863,7 +1863,7 @@
 	netif_device_attach (dev);
 	
 	if (cp->pdev && cp->wol_enabled) {
-		pci_set_power_state (cp->pdev, 0);
+		pci_set_power_state (cp->pdev, PCI_D0);
 		pci_restore_state (cp->pdev);
 	}
 	
drivers/net/8139too.c +2 -2
@@ -2607,7 +2607,7 @@
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -2620,7 +2620,7 @@
 	pci_restore_state (pdev);
 	if (!netif_running (dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	rtl8139_init_ring (dev);
 	rtl8139_hw_start (dev);
 	netif_device_attach (dev);
drivers/net/amd8111e.c +8 -8
@@ -1826,17 +1826,17 @@
 		if(lp->options & OPTION_WAKE_PHY_ENABLE)
 			amd8111e_enable_link_change(lp);	
 		
-		pci_enable_wake(pci_dev, 3, 1);
-		pci_enable_wake(pci_dev, 4, 1); /* D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 1);
+		pci_enable_wake(pci_dev, PCI_D3cold, 1);
 
 	}
 	else{		
-		pci_enable_wake(pci_dev, 3, 0);
-		pci_enable_wake(pci_dev, 4, 0); /* 4 == D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 0);
+		pci_enable_wake(pci_dev, PCI_D3cold, 0);
 	}
 	
 	pci_save_state(pci_dev);
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 
 	return 0;
 }
@@ -1848,11 +1848,11 @@
 	if (!netif_running(dev))
 		return 0;
 
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev);
 
-	pci_enable_wake(pci_dev, 3, 0);
-	pci_enable_wake(pci_dev, 4, 0); /* D3 cold */
+	pci_enable_wake(pci_dev, PCI_D3hot, 0);
+	pci_enable_wake(pci_dev, PCI_D3cold, 0); /* D3 cold */
 
 	netif_device_attach(dev);
 
drivers/net/e100.c +2 -2
@@ -2326,7 +2326,7 @@
 	pci_save_state(pdev);
 	pci_enable_wake(pdev, state, nic->flags & (wol_magic | e100_asf(nic)));
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
 	return 0;
 }
@@ -2336,7 +2336,7 @@
 	struct net_device *netdev = pci_get_drvdata(pdev);
 	struct nic *nic = netdev_priv(netdev);
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 	e100_hw_init(nic);
 
drivers/net/eepro100.c +4 -4
@@ -1014,7 +1014,7 @@
 	if (netif_msg_ifup(sp))
 		printk(KERN_DEBUG "%s: speedo_open() irq %d.\n", dev->name, dev->irq);
 
-	pci_set_power_state(sp->pdev, 0);
+	pci_set_power_state(sp->pdev, PCI_D0);
 
 	/* Set up the Tx queue early.. */
 	sp->cur_tx = 0;
@@ -1963,7 +1963,7 @@
 	if (netif_msg_ifdown(sp))
 		printk(KERN_DEBUG "%s: %d multicast blocks dropped.\n", dev->name, i);
 
-	pci_set_power_state(sp->pdev, 2);
+	pci_set_power_state(sp->pdev, PCI_D2);
 
 	return 0;
 }
@@ -2088,7 +2088,7 @@
 		   access from the timeout handler.
 		   They are currently serialized only with MDIO access from the
 		   timer routine.  2000/05/09 SAW */
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
 		if (t)
@@ -2099,7 +2099,7 @@
 	case SIOCSMIIREG:		/* Write MII PHY register. */
 		if (!capable(CAP_NET_ADMIN))
 			return -EPERM;
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		mdio_write(dev, data->phy_id, data->reg_num, data->val_in);
 		if (t)
drivers/net/pci-skeleton.c +2 -2
@@ -1921,7 +1921,7 @@
 	spin_unlock_irqrestore (&tp->lock, flags);
 
 	pci_save_state (pdev);
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -1934,7 +1934,7 @@
 
 	if (!netif_running(dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	pci_restore_state (pdev);
 	netif_device_attach (dev);
 	netdrv_hw_start (dev);
drivers/net/sis900.c +2 -2
@@ -2238,7 +2238,7 @@
 	/* Stop the chip's Tx and Rx Status Machine */
 	outl(RxDIS | TxDIS | inl(ioaddr + cr), ioaddr + cr);
 
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3);
 	pci_save_state(pci_dev);
 
 	return 0;
@@ -2253,7 +2253,7 @@
 	if(!netif_running(net_dev))
 		return 0;
 	pci_restore_state(pci_dev);
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 
 	sis900_init_rxfilter(net_dev);
 
drivers/net/starfire.c +1 -1
@@ -2159,7 +2159,7 @@
 
 
 	/* XXX: add wakeup code -- requires firmware for MagicPacket */
-	pci_set_power_state(pdev, 3);	/* go to sleep in D3 mode */
+	pci_set_power_state(pdev, PCI_D3hot);	/* go to sleep in D3 mode */
 	pci_disable_device(pdev);
 
 	iounmap((char *)dev->base_addr);
drivers/net/typhoon.c +3 -3
@@ -1890,7 +1890,7 @@
 
 	pci_enable_wake(tp->pdev, state, 1);
 	pci_disable_device(pdev);
-	return pci_set_power_state(pdev, state);
+	return pci_set_power_state(pdev, pci_choose_state(pdev, state));
 }
 
 static int
@@ -1899,7 +1899,7 @@
 	struct pci_dev *pdev = tp->pdev;
 	void __iomem *ioaddr = tp->ioaddr;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 
 	/* Post 2.x.x versions of the Sleep Image require a reset before
@@ -2553,7 +2553,7 @@
 	struct typhoon *tp = netdev_priv(dev);
 
 	unregister_netdev(dev);
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 	typhoon_reset(tp->ioaddr, NoWait);
 	iounmap(tp->ioaddr);
drivers/net/via-rhine.c +1 -1
@@ -1974,7 +1974,7 @@
         if (request_irq(dev->irq, rhine_interrupt, SA_SHIRQ, dev->name, dev))
 		printk(KERN_ERR "via-rhine %s: request_irq failed\n", dev->name);
 
-	ret = pci_set_power_state(pdev, 0);
+	ret = pci_set_power_state(pdev, PCI_D0);
 	if (debug > 1)
 		printk(KERN_INFO "%s: Entering power state D0 %s (%d).\n",
 			dev->name, ret ? "failed" : "succeeded", ret);
drivers/net/via-velocity.c +16 -16
@@ -804,7 +804,7 @@
 	
 	/* and leave the chip powered down */
 	
-	pci_set_power_state(pdev, 3);
+	pci_set_power_state(pdev, PCI_D3hot);
 #ifdef CONFIG_PM
 	{
 		unsigned long flags;
@@ -1742,7 +1742,7 @@
 		goto err_free_rd_ring;
 	
 	/* Ensure chip is running */	
-	pci_set_power_state(vptr->pdev, 0);
+	pci_set_power_state(vptr->pdev, PCI_D0);
 	
 	velocity_init_registers(vptr, VELOCITY_INIT_COLD);
 
@@ -1750,7 +1750,7 @@
 			  dev->name, dev);
 	if (ret < 0) {
 		/* Power down the chip */
-		pci_set_power_state(vptr->pdev, 3);
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		goto err_free_td_ring;
 	}
 
@@ -1868,7 +1868,7 @@
 		free_irq(dev->irq, dev);
 		
 	/* Power down the chip */
-	pci_set_power_state(vptr->pdev, 3);
+	pci_set_power_state(vptr->pdev, PCI_D3hot);
 	
 	/* Free the resources */
 	velocity_free_td_ring(vptr);
@@ -2194,8 +2194,8 @@
 	/* If we are asked for information and the device is power
 	   saving then we need to bring the device back up to talk to it */
 	   	
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 		
 	switch (cmd) {
 	case SIOCGMIIPHY:	/* Get address of MII PHY in use. */
@@ -2207,8 +2207,8 @@
 	default:
 		ret = -EOPNOTSUPP;
 	}
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		
 		
 	return ret;
@@ -2818,8 +2818,8 @@
 static int velocity_ethtool_up(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 	return 0;
 }	
 
@@ -2834,8 +2834,8 @@
 static void velocity_ethtool_down(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 }
 
 static int velocity_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -3229,15 +3229,15 @@
 		velocity_shutdown(vptr);
 		velocity_set_wol(vptr);
 		pci_enable_wake(pdev, 3, 1);
-		pci_set_power_state(pdev, 3);
+		pci_set_power_state(pdev, PCI_D3hot);
 	} else {
 		velocity_save_context(vptr, &vptr->context);
 		velocity_shutdown(vptr);
 		pci_disable_device(pdev);
-		pci_set_power_state(pdev, state);
+		pci_set_power_state(pdev, pci_choose_state(pdev, state));
 	}
 #else
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 #endif
 	spin_unlock_irqrestore(&vptr->lock, flags);
 	return 0;
@@ -3252,7 +3252,7 @@
 	if(!netif_running(vptr->dev))
 		return 0;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_enable_wake(pdev, 0, 0);
 	pci_restore_state(pdev);
 
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Applied
#19 lore raw
Quoted 15 lines · Pavel Machek

Hi!

Quoted 13 lines
Quoted 12 lines
Quoted 6 lines

Alright, I've applied this, and it will show up in the next -mm release. I also fixed up pci.h for when CONFIG_PCI=N due to your changed functions.

Now, care to send patches to fix up all of the new sparse warnings in the drivers/pci/* directory?

This should fix warnings in drivers/net/* and bttv (with exception of via-rhine, which I'll do separately). Do you think you could apply it, or shall I ask Andrew, or... ?

Quoted 8 lines
Quoted 2 lines

What kernel tree is this against? I get lots of rejects against the latest -bk tree.

It was against 2.6.9. pci_{save,restore}_state(), therefore it rejects in surrounding text. Here's version against latest -bk.

This should fix sparse warnings in drivers/net/* and bttv. Please apply,

Applied, thanks.

greg k-h

#20 lore raw
In reply to Greg KH

Hi!

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

Could this go to "after 2.6.10 tree", too? It is a helper that converts system state into PCI state. We really do not want to have this copied into every driver, because it will need to change when system state gets type-checked / expanded to struct.

Pavel

drivers/pci/pci.c +24 -0
@@ -300,6 +300,30 @@
 }
 
 /**
+ * pci_choose_state - Choose the power state of a PCI device
+ * @dev: PCI device to be suspended
+ * @state: target sleep state for the whole system
+ *
+ * Returns PCI power state suitable for given device and given system
+ * message.
+ */
+
+pci_power_t pci_choose_state(struct pci_dev *dev, u32 state)
+{
+	if (!pci_find_capability(dev, PCI_CAP_ID_PM))
+		return PCI_D0;
+
+	switch (state) {
+	case 0:	return PCI_D0;
+	case 2: return PCI_D2;
+	case 3: return PCI_D3hot;
+	default: BUG();
+	}
+}
+
+EXPORT_SYMBOL(pci_choose_state);
+
+/**
  * pci_save_state - save the PCI configuration space of a device before suspending
  * @dev: - PCI device that we're dealing with
  * @buffer: - buffer to hold config space context
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#21 lore raw
Quoted 13 lines · Pavel Machek

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

Could this go to "after 2.6.10 tree", too? It is a helper that converts system state into PCI state. We really do not want to have this copied into every driver, because it will need to change when system state gets type-checked / expanded to struct.

So this is how you want to switch stuff over? Can you give me an example of how this will be used?

Quoted 18 lines
drivers/pci/pci.c +12 -0
@@ -300,6 +300,30 @@
 }
 
 /**
+ * pci_choose_state - Choose the power state of a PCI device
+ * @dev: PCI device to be suspended
+ * @state: target sleep state for the whole system
+ *
+ * Returns PCI power state suitable for given device and given system
+ * message.
+ */
+
+pci_power_t pci_choose_state(struct pci_dev *dev, u32 state)
+{
+	if (!pci_find_capability(dev, PCI_CAP_ID_PM))
+		return PCI_D0;

drivers/pci/pci.c line 324

Quoted 10 lines
drivers/pci/pci.c +10 -0
+
+	switch (state) {
+	case 0:	return PCI_D0;
+	case 2: return PCI_D2;
+	case 3: return PCI_D3hot;
+	default: BUG();
+	}
+}
+
+EXPORT_SYMBOL(pci_choose_state);

EXPORT_SYMBOL_GPL() perhaps?

thanks,

greg k-h

#22 lore raw

Hi!

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

Care to resend this, I seem to have lost them :(

Could this go to "after 2.6.10 tree", too? It is a helper that converts system state into PCI state. We really do not want to have this copied into every driver, because it will need to change when system state gets type-checked / expanded to struct.

So this is how you want to switch stuff over? Can you give me an example of how this will be used?

Yes. Some way to convert between system-state and pci-state is needed; for now it only silences warning, but I guess it will get more complex in future.

Example is here:

drivers/net/e100.c +2 -2
@@ -2313,7 +2313,7 @@
 	pci_save_state(pdev, nic->pm_state);
 	pci_enable_wake(pdev, state, nic->flags & (wol_magic | e100_asf(nic)));
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
 	return 0;
 }
@@ -2323,7 +2323,7 @@
 	struct net_device *netdev = pci_get_drvdata(pdev);
 	struct nic *nic = netdev_priv(netdev);
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, nic->pm_state);
 	e100_hw_init(nic);
 
Quoted 22 lines
Quoted 22 lines
drivers/pci/pci.c +16 -0
@@ -300,6 +300,30 @@
 }
 
 /**
+ * pci_choose_state - Choose the power state of a PCI device
+ * @dev: PCI device to be suspended
+ * @state: target sleep state for the whole system
+ *
+ * Returns PCI power state suitable for given device and given system
+ * message.
+ */
+
+pci_power_t pci_choose_state(struct pci_dev *dev, u32 state)
+{
+	if (!pci_find_capability(dev, PCI_CAP_ID_PM))
+		return PCI_D0;
+
+	switch (state) {
+	case 0:	return PCI_D0;
+	case 2: return PCI_D2;
Quoted 8 lines

drivers/pci/pci.c line 324

Quoted 6 lines
drivers/pci/pci.c +6 -0
+	case 3: return PCI_D3hot;
+	default: BUG();
+	}
+}
+
+EXPORT_SYMBOL(pci_choose_state);

EXPORT_SYMBOL_GPL() perhaps?

Ugh, I do not have any strong feelings here, but I want nvidia etc to use this one so that they implement driver model properly.

Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#23 lore raw
In reply to Greg KH
Quoted 3 lines · Greg KH
Quoted 1 line

+EXPORT_SYMBOL(pci_choose_state);

EXPORT_SYMBOL_GPL() perhaps?

Ugh ? Why GPL only ? That's meant to be used by pretty much all pci_driver's

Ben.

#24 lore raw
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 3 lines · Greg KH
Quoted 1 line

+EXPORT_SYMBOL(pci_choose_state);

EXPORT_SYMBOL_GPL() perhaps?

Ugh ? Why GPL only ? That's meant to be used by pretty much all pci_driver's

Ok, fine. I just have to ask the question :)

greg k-h

Applied
#25 lore raw
In reply to Pavel Machek
Quoted 13 lines · Pavel Machek

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

This is step 0 before adding type-safety to PCI layer... It introduces constants and uses them to clean driver up. I'd like this to go in now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now. Changes like this need to wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while? Or I can add it to my "to apply after 2.6.10 comes out" tree, which will mean it will end up in the -mm releases till that happens.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

Could this go to "after 2.6.10 tree", too? It is a helper that converts system state into PCI state. We really do not want to have this copied into every driver, because it will need to change when system state gets type-checked / expanded to struct.

Applied, but you might want to modify pci.h so people can actually call this function :)

thanks,

greg k-h