* [PATCH] ACPI / PM: Fix error message in __acpi_bus_set_power()
@ 2012-05-14 20:53 Rafael J. Wysocki
  2012-05-18 20:56 ` Rafael J. Wysocki
  2012-05-18 20:58 ` [PATCH 0/2] ACPI / PM: Fixes related to new definitions of device power states Rafael J. Wysocki
  0 siblings, 2 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2012-05-14 20:53 UTC (permalink / raw)
  To: ACPI Devel Mailing List; +Cc: LKML, Len Brown, Linux PM list
From: Rafael J. Wysocki <rjw@sisk.pl>
After recent changes of the ACPI device low-power states definitions
an error message in __acpi_bus_set_power() needs to be updated so
that it prints the correct name of the state that has been requested
(currently it will print "D3" for D3hot and "D4" for D3cold).
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/bus.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Index: linux/drivers/acpi/bus.c
===================================================================
--- linux.orig/drivers/acpi/bus.c
+++ linux/drivers/acpi/bus.c
@@ -240,7 +240,9 @@ static int __acpi_bus_set_power(struct a
 	}
 
 	if (!device->power.states[state].flags.valid) {
-		printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
+		printk(KERN_WARNING PREFIX "Device does not support D%d%s\n",
+			state == ACPI_STATE_D3_COLD ? 3 : state,
+			state == ACPI_STATE_D3_HOT ? "hot" : "");
 		return -ENODEV;
 	}
 	if (device->parent && (state < device->parent->power.state)) {
^ permalink raw reply	[flat|nested] 7+ messages in thread* Re: [PATCH] ACPI / PM: Fix error message in __acpi_bus_set_power() 2012-05-14 20:53 [PATCH] ACPI / PM: Fix error message in __acpi_bus_set_power() Rafael J. Wysocki @ 2012-05-18 20:56 ` Rafael J. Wysocki 2012-05-18 20:58 ` [PATCH 0/2] ACPI / PM: Fixes related to new definitions of device power states Rafael J. Wysocki 1 sibling, 0 replies; 7+ messages in thread From: Rafael J. Wysocki @ 2012-05-18 20:56 UTC (permalink / raw) To: ACPI Devel Mailing List; +Cc: LKML, Len Brown, Linux PM list On Monday, May 14, 2012, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rjw@sisk.pl> > > After recent changes of the ACPI device low-power states definitions > an error message in __acpi_bus_set_power() needs to be updated so > that it prints the correct name of the state that has been requested > (currently it will print "D3" for D3hot and "D4" for D3cold). Please disregard this patch, I'll send a better one in a little while. Thanks, Rafael > Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> > --- > drivers/acpi/bus.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > Index: linux/drivers/acpi/bus.c > =================================================================== > --- linux.orig/drivers/acpi/bus.c > +++ linux/drivers/acpi/bus.c > @@ -240,7 +240,9 @@ static int __acpi_bus_set_power(struct a > } > > if (!device->power.states[state].flags.valid) { > - printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); > + printk(KERN_WARNING PREFIX "Device does not support D%d%s\n", > + state == ACPI_STATE_D3_COLD ? 3 : state, > + state == ACPI_STATE_D3_HOT ? "hot" : ""); > return -ENODEV; > } > if (device->parent && (state < device->parent->power.state)) { > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 0/2] ACPI / PM: Fixes related to new definitions of device power states 2012-05-14 20:53 [PATCH] ACPI / PM: Fix error message in __acpi_bus_set_power() Rafael J. Wysocki 2012-05-18 20:56 ` Rafael J. Wysocki @ 2012-05-18 20:58 ` Rafael J. Wysocki 2012-05-18 21:00 ` [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c Rafael J. Wysocki 2012-05-18 21:01 ` [PATCH 2/2] ACPI / PM: Make __acpi_bus_get_power() cover D3cold correctly Rafael J. Wysocki 1 sibling, 2 replies; 7+ messages in thread From: Rafael J. Wysocki @ 2012-05-18 20:58 UTC (permalink / raw) To: ACPI Devel Mailing List; +Cc: LKML, Len Brown, Linux PM list, Lin Ming Hi, The following two patches fix a couple of remaining issues that appeared when the definitions of ACPI device power states were changed. [1/2] - Fix messages printing power states in drivers/acpi/bus.c. [2/2] - Fix the reading of device power states. Thanks, Rafael ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c 2012-05-18 20:58 ` [PATCH 0/2] ACPI / PM: Fixes related to new definitions of device power states Rafael J. Wysocki @ 2012-05-18 21:00 ` Rafael J. Wysocki 2012-05-20 10:01 ` Andreas Mohr 2012-05-18 21:01 ` [PATCH 2/2] ACPI / PM: Make __acpi_bus_get_power() cover D3cold correctly Rafael J. Wysocki 1 sibling, 1 reply; 7+ messages in thread From: Rafael J. Wysocki @ 2012-05-18 21:00 UTC (permalink / raw) To: ACPI Devel Mailing List; +Cc: LKML, Len Brown, Linux PM list, Lin Ming From: Rafael J. Wysocki <rjw@sisk.pl> After recent changes of the ACPI device low-power states definitions kernel messages in drivers/acpi/bus.c need to be updated so that they include the correct names of the states in question (currently that is "D3" for D3hot and "D4" for D3cold, which is incorrect). Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> --- drivers/acpi/bus.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) Index: linux/drivers/acpi/bus.c =================================================================== --- linux.orig/drivers/acpi/bus.c +++ linux/drivers/acpi/bus.c @@ -182,6 +182,24 @@ EXPORT_SYMBOL(acpi_bus_get_private_data) Power Management -------------------------------------------------------------------------- */ +static char *state_string(int state) +{ + switch (state) { + case ACPI_STATE_D0: + return "D0"; + case ACPI_STATE_D1: + return "D1"; + case ACPI_STATE_D2: + return "D2"; + case ACPI_STATE_D3_HOT: + return "D3hot"; + case ACPI_STATE_D3_COLD: + return "D3"; + default: + return "(unknown)"; + } +} + static int __acpi_bus_get_power(struct acpi_device *device, int *state) { int result = 0; @@ -215,8 +233,8 @@ static int __acpi_bus_get_power(struct a device->parent->power.state : ACPI_STATE_D0; } - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", - device->pnp.bus_id, *state)); + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n", + device->pnp.bus_id, state_string(*state))); return 0; } @@ -234,13 +252,14 @@ static int __acpi_bus_set_power(struct a /* Make sure this is a valid target state */ if (state == device->power.state) { - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", - state)); + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n", + state_string(state))); return 0; } if (!device->power.states[state].flags.valid) { - printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); + printk(KERN_WARNING PREFIX "Device does not support %s\n", + state_string(state)); return -ENODEV; } if (device->parent && (state < device->parent->power.state)) { @@ -294,13 +313,13 @@ static int __acpi_bus_set_power(struct a end: if (result) printk(KERN_WARNING PREFIX - "Device [%s] failed to transition to D%d\n", - device->pnp.bus_id, state); + "Device [%s] failed to transition to %s\n", + device->pnp.bus_id, state_string(state)); else { device->power.state = state; ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "Device [%s] transitioned to D%d\n", - device->pnp.bus_id, state)); + "Device [%s] transitioned to %s\n", + device->pnp.bus_id, state_string(state))); } return result; ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c 2012-05-18 21:00 ` [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c Rafael J. Wysocki @ 2012-05-20 10:01 ` Andreas Mohr 2012-05-20 12:10 ` Rafael J. Wysocki 0 siblings, 1 reply; 7+ messages in thread From: Andreas Mohr @ 2012-05-20 10:01 UTC (permalink / raw) To: Rafael J. Wysocki Cc: ACPI Devel Mailing List, LKML, Len Brown, Linux PM list, Lin Ming Hi, > --- linux.orig/drivers/acpi/bus.c > +++ linux/drivers/acpi/bus.c > @@ -182,6 +182,24 @@ EXPORT_SYMBOL(acpi_bus_get_private_data) > Power Management > -------------------------------------------------------------------------- */ > > +static char *state_string(int state) > +{ > + switch (state) { > + case ACPI_STATE_D0: > + return "D0"; > + case ACPI_STATE_D1: > + return "D1"; "const char", please? In general: nice work, thanks! Andreas Mohr ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c 2012-05-20 10:01 ` Andreas Mohr @ 2012-05-20 12:10 ` Rafael J. Wysocki 0 siblings, 0 replies; 7+ messages in thread From: Rafael J. Wysocki @ 2012-05-20 12:10 UTC (permalink / raw) To: Andreas Mohr, Len Brown Cc: ACPI Devel Mailing List, LKML, Linux PM list, Lin Ming On Sunday, May 20, 2012, Andreas Mohr wrote: > Hi, > > > --- linux.orig/drivers/acpi/bus.c > > +++ linux/drivers/acpi/bus.c > > @@ -182,6 +182,24 @@ EXPORT_SYMBOL(acpi_bus_get_private_data) > > Power Management > > -------------------------------------------------------------------------- */ > > > > +static char *state_string(int state) > > +{ > > + switch (state) { > > + case ACPI_STATE_D0: > > + return "D0"; > > + case ACPI_STATE_D1: > > + return "D1"; > > "const char", please? Sure, appended. I don't think it makes much difference, though. In case it does, please feel free to post a patch changing pm_verb() along this line. > In general: nice work, thanks! Well, thanks! :-) --- From: Rafael J. Wysocki <rjw@sisk.pl> Subject: ACPI / PM: Fix error messages in drivers/acpi/bus.c After recent changes of the ACPI device low-power states definitions kernel messages in drivers/acpi/bus.c need to be updated so that they include the correct names of the states in question (currently is "D3" for D3hot and "D4" for D3cold, which is incorrect). Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> --- drivers/acpi/bus.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) Index: linux/drivers/acpi/bus.c =================================================================== --- linux.orig/drivers/acpi/bus.c +++ linux/drivers/acpi/bus.c @@ -182,6 +182,24 @@ EXPORT_SYMBOL(acpi_bus_get_private_data) Power Management -------------------------------------------------------------------------- */ +static const char *state_string(int state) +{ + switch (state) { + case ACPI_STATE_D0: + return "D0"; + case ACPI_STATE_D1: + return "D1"; + case ACPI_STATE_D2: + return "D2"; + case ACPI_STATE_D3_HOT: + return "D3hot"; + case ACPI_STATE_D3_COLD: + return "D3"; + default: + return "(unknown)"; + } +} + static int __acpi_bus_get_power(struct acpi_device *device, int *state) { int result = 0; @@ -215,8 +233,8 @@ static int __acpi_bus_get_power(struct a device->parent->power.state : ACPI_STATE_D0; } - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", - device->pnp.bus_id, *state)); + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n", + device->pnp.bus_id, state_string(*state))); return 0; } @@ -234,13 +252,14 @@ static int __acpi_bus_set_power(struct a /* Make sure this is a valid target state */ if (state == device->power.state) { - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", - state)); + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n", + state_string(state))); return 0; } if (!device->power.states[state].flags.valid) { - printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); + printk(KERN_WARNING PREFIX "Device does not support %s\n", + state_string(state)); return -ENODEV; } if (device->parent && (state < device->parent->power.state)) { @@ -294,13 +313,13 @@ static int __acpi_bus_set_power(struct a end: if (result) printk(KERN_WARNING PREFIX - "Device [%s] failed to transition to D%d\n", - device->pnp.bus_id, state); + "Device [%s] failed to transition to %s\n", + device->pnp.bus_id, state_string(state)); else { device->power.state = state; ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "Device [%s] transitioned to D%d\n", - device->pnp.bus_id, state)); + "Device [%s] transitioned to %s\n", + device->pnp.bus_id, state_string(state))); } return result; ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] ACPI / PM: Make __acpi_bus_get_power() cover D3cold correctly 2012-05-18 20:58 ` [PATCH 0/2] ACPI / PM: Fixes related to new definitions of device power states Rafael J. Wysocki 2012-05-18 21:00 ` [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c Rafael J. Wysocki @ 2012-05-18 21:01 ` Rafael J. Wysocki 1 sibling, 0 replies; 7+ messages in thread From: Rafael J. Wysocki @ 2012-05-18 21:01 UTC (permalink / raw) To: ACPI Devel Mailing List; +Cc: LKML, Len Brown, Linux PM list, Lin Ming From: Rafael J. Wysocki <rjw@sisk.pl> After recent changes of the ACPI device power states definitions, if power resources are not used for the device's power management, the state returned by __acpi_bus_get_power() cannot exceed D3hot, because the return values of _PSC are 0 through 3. However, if the _PR3 method is not present for the device and _PS3 returns 3, we have to assume that the device is in D3cold, so the value returned by __acpi_bus_get_power() in that case should be 4. Similarly, acpi_power_get_inferred_state() should take the power resources for the D3hot state into account in general, so that it can return 3 if those resources are "on" or 4 (D3cold) otherwise. Fix the the above two issues and make sure that if both _PSC and _PR3 are present for the device, the power resources listed by _PR3 will be used to determine if the number 3 returned by _PSC is meant to represent D3cold or D3hot. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> --- drivers/acpi/bus.c | 51 +++++++++++++++++++++++++++++---------------------- drivers/acpi/power.c | 2 +- 2 files changed, 30 insertions(+), 23 deletions(-) Index: linux/drivers/acpi/bus.c =================================================================== --- linux.orig/drivers/acpi/bus.c +++ linux/drivers/acpi/bus.c @@ -202,37 +202,44 @@ static char *state_string(int state) static int __acpi_bus_get_power(struct acpi_device *device, int *state) { - int result = 0; - acpi_status status = 0; - unsigned long long psc = 0; + int result = ACPI_STATE_UNKNOWN; if (!device || !state) return -EINVAL; - *state = ACPI_STATE_UNKNOWN; - - if (device->flags.power_manageable) { - /* - * Get the device's power state either directly (via _PSC) or - * indirectly (via power resources). - */ - if (device->power.flags.power_resources) { - result = acpi_power_get_inferred_state(device, state); - if (result) - return result; - } else if (device->power.flags.explicit_get) { - status = acpi_evaluate_integer(device->handle, "_PSC", - NULL, &psc); - if (ACPI_FAILURE(status)) - return -ENODEV; - *state = (int)psc; - } - } else { + if (!device->flags.power_manageable) { /* TBD: Non-recursive algorithm for walking up hierarchy. */ *state = device->parent ? device->parent->power.state : ACPI_STATE_D0; + goto out; + } + + /* + * Get the device's power state either directly (via _PSC) or + * indirectly (via power resources). + */ + if (device->power.flags.explicit_get) { + unsigned long long psc; + acpi_status status = acpi_evaluate_integer(device->handle, + "_PSC", NULL, &psc); + if (ACPI_FAILURE(status)) + return -ENODEV; + + result = psc; + } + /* The test below covers ACPI_STATE_UNKNOWN too. */ + if (result <= ACPI_STATE_D2) { + ; /* Do nothing. */ + } else if (device->power.flags.power_resources) { + int error = acpi_power_get_inferred_state(device, &result); + if (error) + return error; + } else if (result == ACPI_STATE_D3_HOT) { + result = ACPI_STATE_D3; } + *state = result; + out: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n", device->pnp.bus_id, state_string(*state))); Index: linux/drivers/acpi/power.c =================================================================== --- linux.orig/drivers/acpi/power.c +++ linux/drivers/acpi/power.c @@ -631,7 +631,7 @@ int acpi_power_get_inferred_state(struct * We know a device's inferred power state when all the resources * required for a given D-state are 'on'. */ - for (i = ACPI_STATE_D0; i < ACPI_STATE_D3_HOT; i++) { + for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { list = &device->power.states[i].resources; if (list->count < 1) continue; ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-05-20 12:10 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-05-14 20:53 [PATCH] ACPI / PM: Fix error message in __acpi_bus_set_power() Rafael J. Wysocki 2012-05-18 20:56 ` Rafael J. Wysocki 2012-05-18 20:58 ` [PATCH 0/2] ACPI / PM: Fixes related to new definitions of device power states Rafael J. Wysocki 2012-05-18 21:00 ` [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c Rafael J. Wysocki 2012-05-20 10:01 ` Andreas Mohr 2012-05-20 12:10 ` Rafael J. Wysocki 2012-05-18 21:01 ` [PATCH 2/2] ACPI / PM: Make __acpi_bus_get_power() cover D3cold correctly Rafael J. Wysocki
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).