Skip to contentSkip to conversation

libata-acpi: add ACPI _PSx method

PATCH In review Shaohua Li 6 participants 16 messages Sep 14, 2007 – Nov 5, 2007

Subsystems (2)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 libata-acpi: add ACPI _PSx method

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method, but executing _PSx for SATA should be ok I think.

---
 drivers/ata/libata-acpi.c |   34 ++++++++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 39 insertions(+)
drivers/ata/libata-acpi.c +34 -0
Index: linux/drivers/ata/libata-acpi.c
===================================================================
@@ -523,6 +523,40 @@ void ata_acpi_on_resume(struct ata_port 
 }
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
+{
+	int max_devices = 1, i;
+
+	if (!ap->acpi_handle)
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	if (ap->flags & ATA_FLAG_SLAVE_POSS)
+		max_devices++;
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->device[i];
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *
drivers/ata/libata-eh.c +3 -0
Index: linux/drivers/ata/libata-eh.c
===================================================================
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 
drivers/ata/libata.h +2 -0
Index: linux/drivers/ata/libata.h
===================================================================
@@ -102,11 +102,13 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */
#1 lore raw
Quoted 6 lines · Shaohua Li

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method, but executing _PSx for SATA should be ok I think.

Where/how can a need for this change be produced?

Jeff

author
#2 lore raw
Quoted 9 lines · Jeff Garzik
Quoted 6 lines · Shaohua Li

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method, but executing _PSx for SATA should be ok I think.

Where/how can a need for this change be produced?

I run suspend/resume test in a Thinkpad R40 laptop, which implements _PSx method in IDE devices. But I'd say I didn't see visible difference in the suspend/resume circle w/wo the patch in the test laptop. This is just to make Linux match with ACPI spec. Maybe this changes other laptops.

Thanks,
Shaohua

#3 lore raw
In reply to Shaohua Li
Quoted 6 lines · Shaohua Li

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method, but executing _PSx for SATA should be ok I think.

ahci and sata_sil24 directly power off components, so it seems quite unwise for "modern" SATA controllers.

ISTR Tejun, when he cleaned up libata-acpi, finally figured out a good way to distinguish ACPI's idea of "IDE" -- which sometimes includes the legacy programming mode of SATA controllers, and a controller running a modern programming mode.

Your best bet is to use a similar test when deciding when to execute _PSx. Or, you could simply be conservative and only do it for PATA.

outside of those issues, the rest of the patch looks ok.

author
#4 lore raw
Quoted 16 lines · Jeff Garzik
Quoted 6 lines · Shaohua Li

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method, but executing _PSx for SATA should be ok I think.

ahci and sata_sil24 directly power off components, so it seems quite unwise for "modern" SATA controllers.

ISTR Tejun, when he cleaned up libata-acpi, finally figured out a good way to distinguish ACPI's idea of "IDE" -- which sometimes includes the legacy programming mode of SATA controllers, and a controller running a modern programming mode.

Quoted 4 lines

Your best bet is to use a similar test when deciding when to execute _PSx. Or, you could simply be conservative and only do it for PATA.

outside of those issues, the rest of the patch looks ok.

Then how about this one? I added a check in ata_acpi_set_state to skip SATA device, assume this is what you are talking about.

Thanks,
Shaohua

---
 drivers/ata/libata-acpi.c |   34 ++++++++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 39 insertions(+)
drivers/ata/libata-acpi.c +34 -0
Index: linux/drivers/ata/libata-acpi.c
===================================================================
@@ -523,6 +523,40 @@ void ata_acpi_on_resume(struct ata_port 
 }
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
+{
+	int max_devices = 1, i;
+
+	if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA))
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	if (ap->flags & ATA_FLAG_SLAVE_POSS)
+		max_devices++;
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->device[i];
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *
drivers/ata/libata-eh.c +3 -0
Index: linux/drivers/ata/libata-eh.c
===================================================================
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 
drivers/ata/libata.h +2 -0
Index: linux/drivers/ata/libata.h
===================================================================
@@ -102,11 +102,13 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */
#5 lore raw

Hello,

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port · line 545

Quoted 6 lines · Shaohua Li
drivers/ata/libata-acpi.c +6 -0
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	if (ap->flags & ATA_FLAG_SLAVE_POSS)
+		max_devices++;

ata_port_max_devices()?

Quoted 13 lines

Index: linux/drivers/ata/libata-eh.c
===================================================================

drivers/ata/libata-eh.c +1 -0
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);

drivers/ata/libata-eh.c static void ata_eh_handle_port_resume(st · line 2401

Quoted 7 lines
drivers/ata/libata-eh.c +2 -0
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);

Can these be moved into ata_acpi_on_suspend() and ata_acpi_on_resume()?
Or do they have to be placed on the other side of ->port_suspend/resume
callbacks?

Thanks.

Signature · 1 line
tejun
author
#6 lore raw
Quoted 11 lines · Tejun Heo

Hello,

Review

Quoted 6 lines · Shaohua Li
(quoted diff) +6 -0
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	if (ap->flags & ATA_FLAG_SLAVE_POSS)
+		max_devices++;

ata_port_max_devices()?

ok, fixed.

Quoted 17 lines
Quoted 17 lines

Index: linux/drivers/ata/libata-eh.c
===================================================================

drivers/ata/libata-eh.c +1 -0
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
Quoted 8 lines

drivers/ata/libata-eh.c static void ata_eh_handle_port_resume(st · line 2401

Quoted 4 lines
drivers/ata/libata-eh.c +2 -0
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);

Can these be moved into ata_acpi_on_suspend() and ata_acpi_on_resume()?
Or do they have to be placed on the other side of ->port_suspend/resume
callbacks?

I suppose _PSx will shutdown ports. So I want to do PS3 as later as possible in suspend, and vice versa in resume.

Thanks,
Shaohua

---
 drivers/ata/libata-acpi.c |   34 ++++++++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 39 insertions(+)
drivers/ata/libata-acpi.c +33 -0
Index: linux/drivers/ata/libata-acpi.c
===================================================================
@@ -523,6 +523,39 @@ void ata_acpi_on_resume(struct ata_port 
 }
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
+{
+	int max_devices, i;
+
+	if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA))
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	max_devices = ata_port_max_devices(ap);
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->device[i];
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *
drivers/ata/libata-eh.c +3 -0
Index: linux/drivers/ata/libata-eh.c
===================================================================
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 
drivers/ata/libata.h +2 -0
Index: linux/drivers/ata/libata.h
===================================================================
@@ -102,11 +102,13 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */
reviewer Acked-by
#7 lore raw

It would be interseting if any of the folks having power consumption problems when suspended see an improvement with this patch.

Are there plans to refresh this patch and get it upstream?

thanks,
-Len

Quoted 135 lines · Shaohua Li
Quoted 11 lines · Tejun Heo

Hello,

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port

Quoted 6 lines · Shaohua Li
drivers/ata/libata-acpi.c +6 -0
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	if (ap->flags & ATA_FLAG_SLAVE_POSS)
+		max_devices++;

ata_port_max_devices()?

ok, fixed.

Quoted 17 lines
Quoted 17 lines

Index: linux/drivers/ata/libata-eh.c
===================================================================

drivers/ata/libata-eh.c +1 -0
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
Quoted 8 lines

drivers/ata/libata-eh.c static void ata_eh_handle_port_resume(st · line 2401

Quoted 4 lines
drivers/ata/libata-eh.c +2 -0
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);

Can these be moved into ata_acpi_on_suspend() and ata_acpi_on_resume()?
Or do they have to be placed on the other side of ->port_suspend/resume
callbacks?

I suppose _PSx will shutdown ports. So I want to do PS3 as later as possible in suspend, and vice versa in resume.

Thanks,
Shaohua

---
 drivers/ata/libata-acpi.c |   34 ++++++++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 39 insertions(+)

Index: linux/drivers/ata/libata-acpi.c
===================================================================

drivers/ata/libata-acpi.c +33 -0
@@ -523,6 +523,39 @@ void ata_acpi_on_resume(struct ata_port 
 }
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
+{
+	int max_devices, i;
+
+	if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA))
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	max_devices = ata_port_max_devices(ap);
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->device[i];
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *

Index: linux/drivers/ata/libata-eh.c
===================================================================

drivers/ata/libata-eh.c +3 -0
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 

Index: linux/drivers/ata/libata.h
===================================================================

drivers/ata/libata.h +2 -0
@@ -102,11 +102,13 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */
#8 lore raw
Quoted 6 lines · Len Brown

It would be interseting if any of the folks having power consumption problems when suspended see an improvement with this patch.

Are there plans to refresh this patch and get it upstream?

There was a discussion regarding this patch, IIRC, and it was argued that _PSx are only applicable to IDE/PATA devices.

I wonder if this has been addressed.

Greetings,
Rafael

Quoted 142 lines · Shaohua Li
Quoted 125 lines · Tejun Heo
Quoted 11 lines

Hello,

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port

Quoted 6 lines · Shaohua Li
drivers/ata/libata-acpi.c +6 -0
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	if (ap->flags & ATA_FLAG_SLAVE_POSS)
+		max_devices++;

ata_port_max_devices()?

ok, fixed.

Quoted 17 lines
Quoted 17 lines

Index: linux/drivers/ata/libata-eh.c
===================================================================

drivers/ata/libata-eh.c +1 -0
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
Quoted 8 lines

drivers/ata/libata-eh.c static void ata_eh_handle_port_resume(st · line 2401

Quoted 4 lines
drivers/ata/libata-eh.c +2 -0
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);

Can these be moved into ata_acpi_on_suspend() and ata_acpi_on_resume()?
Or do they have to be placed on the other side of ->port_suspend/resume
callbacks?

I suppose _PSx will shutdown ports. So I want to do PS3 as later as possible in suspend, and vice versa in resume.

Thanks,
Shaohua

---
 drivers/ata/libata-acpi.c |   34 ++++++++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 39 insertions(+)

Index: linux/drivers/ata/libata-acpi.c
===================================================================

drivers/ata/libata-acpi.c +33 -0
@@ -523,6 +523,39 @@ void ata_acpi_on_resume(struct ata_port 
 }
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
+{
+	int max_devices, i;
+
+	if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA))
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	max_devices = ata_port_max_devices(ap);
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->device[i];
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *

Index: linux/drivers/ata/libata-eh.c
===================================================================

drivers/ata/libata-eh.c +3 -0
@@ -2349,6 +2349,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2394,6 +2395,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 

Index: linux/drivers/ata/libata.h
===================================================================

drivers/ata/libata.h +0 -0
@@ -102,11 +102,13 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);

drivers/ata/libata.h extern void ata_acpi_associate(struct at · line 114

Quoted 10 lines
drivers/ata/libata.h +2 -0
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
author Acked-by Len Brown
#9 lore raw
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Len Brown

It would be interseting if any of the folks having power consumption problems when suspended see an improvement with this patch.

Quoted 8 lines
Quoted 3 lines

Are there plans to refresh this patch and get it upstream?

There was a discussion regarding this patch, IIRC, and it was argued that _PSx are only applicable to IDE/PATA devices.

I wonder if this has been addressed.

Sure, there is a check for PATA. I refreshed the patch to against latest git tree.

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method.

---
 drivers/ata/libata-acpi.c |   33 +++++++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 38 insertions(+)
drivers/ata/libata-acpi.c +33 -0
Index: linux/drivers/ata/libata-acpi.c
===================================================================
@@ -652,6 +652,39 @@ void ata_acpi_on_resume(struct ata_port 
 }
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
+{
+	int max_devices, i;
+
+	if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA))
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	max_devices = ata_link_max_devices(&ap->link);
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->link.device[i];
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *
drivers/ata/libata-eh.c +3 -0
Index: linux/drivers/ata/libata-eh.c
===================================================================
@@ -2796,6 +2796,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2841,6 +2842,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 
drivers/ata/libata.h +2 -0
Index: linux/drivers/ata/libata.h
===================================================================
@@ -111,12 +111,14 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate_sata_port(struct ata_port *ap) { }
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */
#10 lore raw

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port · line 676

Quoted 5 lines
drivers/ata/libata-acpi.c +4 -0
+	max_devices = ata_link_max_devices(&ap->link);
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->link.device[i];

Better to use:

	ata_link_for_each_dev(dev, &ap->link) {		

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port · line 682

Quoted 6 lines
drivers/ata/libata-acpi.c +6 -0
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}

Also should you not check ata_dev_enabled(dev) ?

Alan

author Acked-by Len Brown
#11 lore raw
Quoted 6 lines · Alan Cox

Review

Quoted 4 lines
(quoted diff) +4 -0
+	max_devices = ata_link_max_devices(&ap->link);
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->link.device[i];

Better to use:

ok.

Quoted 10 lines
	ata_link_for_each_dev(dev, &ap->link) {		

Review

Quoted 6 lines
(quoted diff) +6 -0
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}

Also should you not check ata_dev_enabled(dev) ?

Not sure, this is just to call a BIOS routine, but a check should be safer. Thanks!

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method.

---
 drivers/ata/libata-acpi.c |   29 +++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 34 insertions(+)
drivers/ata/libata-acpi.c +29 -0
Index: linux/drivers/ata/libata-acpi.c
===================================================================
@@ -652,6 +652,35 @@ void ata_acpi_on_resume(struct ata_port 
 }
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
+{
+	struct ata_device *dev;
+
+	if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA))
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	ata_link_for_each_dev(dev, &ap->link) {
+		if (dev->acpi_handle && ata_dev_enabled(dev))
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *
drivers/ata/libata-eh.c +3 -0
Index: linux/drivers/ata/libata-eh.c
===================================================================
@@ -2796,6 +2796,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2841,6 +2842,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 
drivers/ata/libata.h +2 -0
Index: linux/drivers/ata/libata.h
===================================================================
@@ -111,12 +111,14 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate_sata_port(struct ata_port *ap) { }
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */
#12 lore raw
Quoted 40 lines · Shaohua Li
Quoted 6 lines · Alan Cox

Review

Quoted 4 lines
(quoted diff) +4 -0
+	max_devices = ata_link_max_devices(&ap->link);
+
+	for (i = 0; i < max_devices; ++i) {
+		struct ata_device *dev = &ap->link.device[i];

Better to use:

ok.

Quoted 10 lines
	ata_link_for_each_dev(dev, &ap->link) {		

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port · line 678

Quoted 6 lines
drivers/ata/libata-acpi.c +6 -0
+
+		if (dev->acpi_handle)
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}

Also should you not check ata_dev_enabled(dev) ?

Not sure, this is just to call a BIOS routine, but a check should be safer. Thanks!

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method.

---
 drivers/ata/libata-acpi.c |   29 +++++++++++++++++++++++++++++
 drivers/ata/libata-eh.c   |    3 +++
 drivers/ata/libata.h      |    2 ++
 3 files changed, 34 insertions(+)

Index: linux/drivers/ata/libata-acpi.c
===================================================================

drivers/ata/libata-acpi.c +0 -0
@@ -652,6 +652,35 @@ void ata_acpi_on_resume(struct ata_port 
 }

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port · line 662

Quoted 10 lines
drivers/ata/libata-acpi.c +8 -0
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)

I wouldn't use pm_message_t here.

We're seriously considering removing it in the future and the caller passes constants explicitly anyway.

IMO, it might be cleaner to define two separate functions, one for switching to D0 and one for switching to D3, and call them as appropriate. Then, you could get rid of some conditionals below.

Quoted 65 lines
drivers/ata/libata-acpi.c +21 -0
+{
+	struct ata_device *dev;
+
+	if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA))
+		return;
+
+	/* channel first and then drives for power on and verse versa for power off */
+	if (state.event == PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
+
+	ata_link_for_each_dev(dev, &ap->link) {
+		if (dev->acpi_handle && ata_dev_enabled(dev))
+			acpi_bus_set_power(dev->acpi_handle,
+				state.event == PM_EVENT_ON ?
+				ACPI_STATE_D0: ACPI_STATE_D3);
+	}
+	if (state.event != PM_EVENT_ON)
+		acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3);
+}
+
+/**
  * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  * @dev: target ATA device
  *

Index: linux/drivers/ata/libata-eh.c
===================================================================

drivers/ata/libata-eh.c +3 -0
@@ -2796,6 +2796,7 @@ static void ata_eh_handle_port_suspend(s
 	if (ap->ops->port_suspend)
 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
 
+	ata_acpi_set_state(ap, PMSG_SUSPEND);
  out:
 	/* report result */
 	spin_lock_irqsave(ap->lock, flags);
@@ -2841,6 +2842,8 @@ static void ata_eh_handle_port_resume(st
 
 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
 
+	ata_acpi_set_state(ap, PMSG_ON);
+
 	if (ap->ops->port_resume)
 		rc = ap->ops->port_resume(ap);
 

Index: linux/drivers/ata/libata.h
===================================================================

drivers/ata/libata.h +2 -1
@@ -111,12 +111,14 @@ extern void ata_acpi_associate(struct at
 extern int ata_acpi_on_suspend(struct ata_port *ap);
 extern void ata_acpi_on_resume(struct ata_port *ap);
 extern int ata_acpi_on_devcfg(struct ata_device *adev);
+extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 #else
 static inline void ata_acpi_associate_sata_port(struct ata_port *ap) { }
 static inline void ata_acpi_associate(struct ata_host *host) { }
 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
 static inline void ata_acpi_on_resume(struct ata_port *ap) { }
 static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
+static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }
 #endif
 
 /* libata-scsi.c */
-
Quoted 5 lines

To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Greetings,
Rafael

author
#13 lore raw
Quoted 20 lines · Rafael J. Wysocki
Quoted 7 lines

Index: linux/drivers/ata/libata-acpi.c
===================================================================

drivers/ata/libata-acpi.c +0 -0
@@ -652,6 +652,35 @@ void ata_acpi_on_resume(struct ata_port 
 }

drivers/ata/libata-acpi.c void ata_acpi_on_resume(struct ata_port · line 662

Quoted 10 lines
drivers/ata/libata-acpi.c +8 -0
 
 /**
+ * ata_acpi_set_state - set the port power state
+ * @ap: target ATA port
+ * @state: state, on/off
+ *
+ * This function executes the _PS0/_PS3 ACPI method to set the power state.
+ * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
+ */
+void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)

I wouldn't use pm_message_t here.

Quoted 6 lines

We're seriously considering removing it in the future and the caller passes constants explicitly anyway.

IMO, it might be cleaner to define two separate functions, one for switching to D0 and one for switching to D3, and call them as appropriate. Then, you could get rid of some conditionals below.

It doesn't make sense to add a new one just for ata_acpi and we don't misuse pm_message_t here. If you will remove it, lets clean up it then.

Thanks,
Shaohua

#14 lore raw
In reply to Shaohua Li
Quoted 10 lines · Shaohua Li

Not sure, this is just to call a BIOS routine, but a check should be safer. Thanks!

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method.

What is the safety factor on this patch? :)

Since we are into 2.6.24-rc, my preference would be to let this get some testing in -mm, and push it upstream for 2.6.25. Comments?

Jeff

author
#15 lore raw
Quoted 9 lines · Jeff Garzik
Quoted 8 lines · Shaohua Li

Not sure, this is just to call a BIOS routine, but a check should be safer. Thanks!

ACPI spec (ver 3.0a, p289) requires IDE power on/off executes ACPI _PSx methods. As recently most PATA drivers use libata, this patch adds _PSx method support in libata. ACPI spec doesn't mention if SATA requires the same _PSx method.

Quoted 5 lines
Quoted 2 lines

What is the safety factor on this patch? :)

Not sure, but it depends on BIOS, I just guess ignoring disabled device might be safe :)

Quoted 2 lines

Since we are into 2.6.24-rc, my preference would be to let this get some testing in -mm, and push it upstream for 2.6.25. Comments?

Sure, Thanks, taking either this patch or previous patch is ok to me.

Thanks,
Shaohua