Skip to contentSkip to conversation

ACPI / PM: Fix error message in __acpi_bus_set_power()

PATCH In review Rafael J. Wysocki 2 participants 7 messages May 14, 2012 – May 20, 2012 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI / PM: Fix error message in __acpi_bus_set_power()

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

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).

---
 drivers/acpi/bus.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/bus.c +3 -1
Index: 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)) {
#1 lore raw
Quoted 6 lines · Rafael J. Wysocki

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

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

Quoted 27 lines
---
 drivers/acpi/bus.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: linux/drivers/acpi/bus.c
===================================================================

drivers/acpi/bus.c +3 -2
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw

cover ACPI / PM: Fixes related to new definitions of device power states

In reply to Rafael J. Wysocki

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

#3 lore raw

PATCH 1/2 ACPI / PM: Fix error messages in drivers/acpi/bus.c

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

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).

---
 drivers/acpi/bus.c |   37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)
drivers/acpi/bus.c +28 -9
Index: 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;
#4 lore raw

Re: [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c

Hi,

drivers/acpi/bus.c EXPORT_SYMBOL(acpi_bus_get_private_data) · line 191

Quoted 13 lines
drivers/acpi/bus.c +7 -0
@@ -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

#5 lore raw

Re: [PATCH 1/2] ACPI / PM: Fix error messages in drivers/acpi/bus.c

Quoted 8 lines · Andreas Mohr

Hi,

Quoted 6 lines
drivers/acpi/bus.c +0 -0
@@ -182,6 +182,24 @@ EXPORT_SYMBOL(acpi_bus_get_private_data)
                                  Power Management
    -------------------------------------------------------------------------- */
 
Quoted 9 lines

drivers/acpi/bus.c EXPORT_SYMBOL(acpi_bus_get_private_data) · line 191

Quoted 7 lines
drivers/acpi/bus.c +7 -0
+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.

Quoted 1 line

In general: nice work, thanks!

Well, thanks! :-)

---
From: Rafael J. Wysocki <[email protected]>
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).

---
 drivers/acpi/bus.c |   37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)
drivers/acpi/bus.c +28 -9
Index: 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;
#6 lore raw

PATCH 2/2 ACPI / PM: Make __acpi_bus_get_power() cover D3cold correctly

In reply to Rafael J. Wysocki

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

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.

---
 drivers/acpi/bus.c   |   51 +++++++++++++++++++++++++++++----------------------
 drivers/acpi/power.c |    2 +-
 2 files changed, 30 insertions(+), 23 deletions(-)
drivers/acpi/bus.c +29 -22
Index: 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)));
 
drivers/acpi/power.c +1 -1
Index: 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;