All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization
@ 2010-10-28 13:07 Rafael J. Wysocki
  2010-10-28 13:09 ` [RFC/RFT][PATCH 1/3] ACPI / PM: Register acpi_power_driver early Rafael J. Wysocki
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2010-10-28 13:07 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: Len Brown, Linux-pm mailing list, ACPI Devel Maling List

Hi,

The following series of patches attempts to fix the problems with the handling
of power resources during initialization.

[1/3] allows power resource devices to be initialized by acpi_power driver as
      soon as they are found.

[2/3] creates power resource device objects as soon as they appear in the _PRn
      output for any devices.

[3/3] uses acpi_power_transition() to set up the initial reference counting of
      power resources as appropriate.

I have only tested them on machines without ACPI power resource objects, so all
this is kind of theoretical at the moment, but I think the patches are simple
enough.

Please test if you can and let me know what's wrong. :-)

Thanks,
Rafael


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC/RFT][PATCH 1/3] ACPI / PM: Register acpi_power_driver early
  2010-10-28 13:07 [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization Rafael J. Wysocki
  2010-10-28 13:09 ` [RFC/RFT][PATCH 1/3] ACPI / PM: Register acpi_power_driver early Rafael J. Wysocki
@ 2010-10-28 13:09 ` Rafael J. Wysocki
  2010-10-28 13:10 ` [RFC/RFT][PATCH 2/3] ACPI / PM: Register power resource devices as soon as they are needed Rafael J. Wysocki
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2010-10-28 13:09 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: Len Brown, Linux-pm mailing list, ACPI Devel Maling List

From: Rafael J. Wysocki <rjw@sisk.pl>

The ACPI device driver used for handling power resources,
acpi_power_driver, creates a struct acpi_power_resource object for
each ACPI device representing a power resource.  These objects are
then used when setting and reading the power states of devices using
the corresponding power resources.  Unfortunately, acpi_power_driver
is registered after acpi_scan_init() that may add devices using the
power resources before acpi_power_driver has a chance to create
struct acpi_power_resource objects for them (specifically, the power
resources may be referred to during the scanning process through
acpi_bus_get_power() before they have been initialized).

As the first step towards fixing this issue, move the registration
of acpi_power_driver into acpi_scan_init() so that power resource
devices can be initialized by it as soon as they have been found in
the namespace.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/bus.c  |    1 -
 drivers/acpi/scan.c |    2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/acpi/bus.c
===================================================================
--- linux-2.6.orig/drivers/acpi/bus.c
+++ linux-2.6/drivers/acpi/bus.c
@@ -1025,7 +1025,6 @@ static int __init acpi_init(void)
 
 	acpi_scan_init();
 	acpi_ec_init();
-	acpi_power_init();
 	acpi_sysfs_init();
 	acpi_debugfs_init();
 	acpi_sleep_proc_init();
Index: linux-2.6/drivers/acpi/scan.c
===================================================================
--- linux-2.6.orig/drivers/acpi/scan.c
+++ linux-2.6/drivers/acpi/scan.c
@@ -1543,6 +1543,8 @@ int __init acpi_scan_init(void)
 		printk(KERN_ERR PREFIX "Could not register bus type\n");
 	}
 
+	acpi_power_init();
+
 	/*
 	 * Enumerate devices in the ACPI namespace.
 	 */


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC/RFT][PATCH 1/3] ACPI / PM: Register acpi_power_driver early
  2010-10-28 13:07 [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization Rafael J. Wysocki
@ 2010-10-28 13:09 ` Rafael J. Wysocki
  2010-10-28 13:09 ` Rafael J. Wysocki
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2010-10-28 13:09 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: ACPI Devel Maling List, Linux-pm mailing list

From: Rafael J. Wysocki <rjw@sisk.pl>

The ACPI device driver used for handling power resources,
acpi_power_driver, creates a struct acpi_power_resource object for
each ACPI device representing a power resource.  These objects are
then used when setting and reading the power states of devices using
the corresponding power resources.  Unfortunately, acpi_power_driver
is registered after acpi_scan_init() that may add devices using the
power resources before acpi_power_driver has a chance to create
struct acpi_power_resource objects for them (specifically, the power
resources may be referred to during the scanning process through
acpi_bus_get_power() before they have been initialized).

As the first step towards fixing this issue, move the registration
of acpi_power_driver into acpi_scan_init() so that power resource
devices can be initialized by it as soon as they have been found in
the namespace.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/bus.c  |    1 -
 drivers/acpi/scan.c |    2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/acpi/bus.c
===================================================================
--- linux-2.6.orig/drivers/acpi/bus.c
+++ linux-2.6/drivers/acpi/bus.c
@@ -1025,7 +1025,6 @@ static int __init acpi_init(void)
 
 	acpi_scan_init();
 	acpi_ec_init();
-	acpi_power_init();
 	acpi_sysfs_init();
 	acpi_debugfs_init();
 	acpi_sleep_proc_init();
Index: linux-2.6/drivers/acpi/scan.c
===================================================================
--- linux-2.6.orig/drivers/acpi/scan.c
+++ linux-2.6/drivers/acpi/scan.c
@@ -1543,6 +1543,8 @@ int __init acpi_scan_init(void)
 		printk(KERN_ERR PREFIX "Could not register bus type\n");
 	}
 
+	acpi_power_init();
+
 	/*
 	 * Enumerate devices in the ACPI namespace.
 	 */

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC/RFT][PATCH 2/3] ACPI / PM: Register power resource devices as soon as they are needed
  2010-10-28 13:07 [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization Rafael J. Wysocki
                   ` (2 preceding siblings ...)
  2010-10-28 13:10 ` [RFC/RFT][PATCH 2/3] ACPI / PM: Register power resource devices as soon as they are needed Rafael J. Wysocki
@ 2010-10-28 13:10 ` Rafael J. Wysocki
  2010-10-28 13:11 ` [RFC/RFT][PATCH 3/3] ACPI / PM: Fix initial reference counting of power resources Rafael J. Wysocki
  2010-10-28 13:11 ` Rafael J. Wysocki
  5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2010-10-28 13:10 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: Len Brown, Linux-pm mailing list, ACPI Devel Maling List

From: Rafael J. Wysocki <rjw@sisk.pl>

Depending on the organization of the ACPI namespace, power resource
device objects may generally be scanned after the "regular" device
objects they are referred from through _PRn.  This, in turn, may
cause acpi_bus_get_power_flags() to attempt to access them through
acpi_bus_get_power() before they are registered (and initialized by
acpi_power_driver).  In those cases, acpi_bus_get_power() called by
acpi_bus_get_power() will fail.

To fix this problem, make acpi_bus_get_power_flags() attempt to
register power resource devices as soon as they have been found in
the _PRn output for any other devices.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/scan.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Index: linux-2.6/drivers/acpi/scan.c
===================================================================
--- linux-2.6.orig/drivers/acpi/scan.c
+++ linux-2.6/drivers/acpi/scan.c
@@ -818,6 +818,8 @@ end:
 	return 0;
 }
 
+static void acpi_bus_add_power_resource(acpi_handle handle);
+
 static int acpi_bus_get_power_flags(struct acpi_device *device)
 {
 	acpi_status status = 0;
@@ -846,8 +848,12 @@ static int acpi_bus_get_power_flags(stru
 		acpi_evaluate_reference(device->handle, object_name, NULL,
 					&ps->resources);
 		if (ps->resources.count) {
+			int j;
+
 			device->power.flags.power_resources = 1;
 			ps->flags.valid = 1;
+			for (j = 0; j < ps->resources.count; j++)
+				acpi_bus_add_power_resource(ps->resources.handles[j]);
 		}
 
 		/* Evaluate "_PSx" to see if we can do explicit sets */
@@ -1304,6 +1310,20 @@ end:
 #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
 			  ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING)
 
+static void acpi_bus_add_power_resource(acpi_handle handle)
+{
+	struct acpi_bus_ops ops = {
+		.acpi_op_add = 1,
+		.acpi_op_start = 1,
+	};
+	struct acpi_device *device = NULL;
+
+	acpi_bus_get_device(handle, &device);
+	if (!device)
+		acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER,
+					ACPI_STA_DEFAULT, &ops);
+}
+
 static int acpi_bus_type_and_status(acpi_handle handle, int *type,
 				    unsigned long long *sta)
 {


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC/RFT][PATCH 2/3] ACPI / PM: Register power resource devices as soon as they are needed
  2010-10-28 13:07 [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization Rafael J. Wysocki
  2010-10-28 13:09 ` [RFC/RFT][PATCH 1/3] ACPI / PM: Register acpi_power_driver early Rafael J. Wysocki
  2010-10-28 13:09 ` Rafael J. Wysocki
@ 2010-10-28 13:10 ` Rafael J. Wysocki
  2010-10-28 13:10 ` Rafael J. Wysocki
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2010-10-28 13:10 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: ACPI Devel Maling List, Linux-pm mailing list

From: Rafael J. Wysocki <rjw@sisk.pl>

Depending on the organization of the ACPI namespace, power resource
device objects may generally be scanned after the "regular" device
objects they are referred from through _PRn.  This, in turn, may
cause acpi_bus_get_power_flags() to attempt to access them through
acpi_bus_get_power() before they are registered (and initialized by
acpi_power_driver).  In those cases, acpi_bus_get_power() called by
acpi_bus_get_power() will fail.

To fix this problem, make acpi_bus_get_power_flags() attempt to
register power resource devices as soon as they have been found in
the _PRn output for any other devices.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/scan.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Index: linux-2.6/drivers/acpi/scan.c
===================================================================
--- linux-2.6.orig/drivers/acpi/scan.c
+++ linux-2.6/drivers/acpi/scan.c
@@ -818,6 +818,8 @@ end:
 	return 0;
 }
 
+static void acpi_bus_add_power_resource(acpi_handle handle);
+
 static int acpi_bus_get_power_flags(struct acpi_device *device)
 {
 	acpi_status status = 0;
@@ -846,8 +848,12 @@ static int acpi_bus_get_power_flags(stru
 		acpi_evaluate_reference(device->handle, object_name, NULL,
 					&ps->resources);
 		if (ps->resources.count) {
+			int j;
+
 			device->power.flags.power_resources = 1;
 			ps->flags.valid = 1;
+			for (j = 0; j < ps->resources.count; j++)
+				acpi_bus_add_power_resource(ps->resources.handles[j]);
 		}
 
 		/* Evaluate "_PSx" to see if we can do explicit sets */
@@ -1304,6 +1310,20 @@ end:
 #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
 			  ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING)
 
+static void acpi_bus_add_power_resource(acpi_handle handle)
+{
+	struct acpi_bus_ops ops = {
+		.acpi_op_add = 1,
+		.acpi_op_start = 1,
+	};
+	struct acpi_device *device = NULL;
+
+	acpi_bus_get_device(handle, &device);
+	if (!device)
+		acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER,
+					ACPI_STA_DEFAULT, &ops);
+}
+
 static int acpi_bus_type_and_status(acpi_handle handle, int *type,
 				    unsigned long long *sta)
 {

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC/RFT][PATCH 3/3] ACPI / PM: Fix initial reference counting of power resources
  2010-10-28 13:07 [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization Rafael J. Wysocki
                   ` (3 preceding siblings ...)
  2010-10-28 13:10 ` Rafael J. Wysocki
@ 2010-10-28 13:11 ` Rafael J. Wysocki
  2010-10-28 13:11 ` Rafael J. Wysocki
  5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2010-10-28 13:11 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: Len Brown, Linux-pm mailing list, ACPI Devel Maling List

From: Rafael J. Wysocki <rjw@sisk.pl>

ACPI power resources are only reference counted during device power
state changes.  The initial device power states have no effect on
the reference counting of power resources.  This leads to the problem
that some power resources may be turned off too early when devices
are powered off during system suspend or via runtime PM.  Moreover,
the state of power resource reference counters after powering a
device on may be different than it had been before the device was
powered off.

To fix this issue, update power resource reference counting directly
during initialization by calling acpi_power_transition() for every
device using power resources.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/scan.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6/drivers/acpi/scan.c
===================================================================
--- linux-2.6.orig/drivers/acpi/scan.c
+++ linux-2.6/drivers/acpi/scan.c
@@ -880,8 +880,10 @@ static int acpi_bus_get_power_flags(stru
 
 	/* TBD: System wake support and resource requirements. */
 
-	device->power.state = ACPI_STATE_UNKNOWN;
-	acpi_bus_get_power(device->handle, &(device->power.state));
+	acpi_bus_get_power(device->handle, &device->power.state);
+	/* Update power resources reference counting. */
+	if (device->power.flags.power_resources)
+		acpi_power_transition(device, device->power.state);
 
 	return 0;
 }


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC/RFT][PATCH 3/3] ACPI / PM: Fix initial reference counting of power resources
  2010-10-28 13:07 [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization Rafael J. Wysocki
                   ` (4 preceding siblings ...)
  2010-10-28 13:11 ` [RFC/RFT][PATCH 3/3] ACPI / PM: Fix initial reference counting of power resources Rafael J. Wysocki
@ 2010-10-28 13:11 ` Rafael J. Wysocki
  5 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2010-10-28 13:11 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: ACPI Devel Maling List, Linux-pm mailing list

From: Rafael J. Wysocki <rjw@sisk.pl>

ACPI power resources are only reference counted during device power
state changes.  The initial device power states have no effect on
the reference counting of power resources.  This leads to the problem
that some power resources may be turned off too early when devices
are powered off during system suspend or via runtime PM.  Moreover,
the state of power resource reference counters after powering a
device on may be different than it had been before the device was
powered off.

To fix this issue, update power resource reference counting directly
during initialization by calling acpi_power_transition() for every
device using power resources.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/scan.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6/drivers/acpi/scan.c
===================================================================
--- linux-2.6.orig/drivers/acpi/scan.c
+++ linux-2.6/drivers/acpi/scan.c
@@ -880,8 +880,10 @@ static int acpi_bus_get_power_flags(stru
 
 	/* TBD: System wake support and resource requirements. */
 
-	device->power.state = ACPI_STATE_UNKNOWN;
-	acpi_bus_get_power(device->handle, &(device->power.state));
+	acpi_bus_get_power(device->handle, &device->power.state);
+	/* Update power resources reference counting. */
+	if (device->power.flags.power_resources)
+		acpi_power_transition(device, device->power.state);
 
 	return 0;
 }

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-10-28 13:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28 13:07 [RFC/RFT][PATCH 0/3] ACPI: Fix handling of power resources during initialization Rafael J. Wysocki
2010-10-28 13:09 ` [RFC/RFT][PATCH 1/3] ACPI / PM: Register acpi_power_driver early Rafael J. Wysocki
2010-10-28 13:09 ` Rafael J. Wysocki
2010-10-28 13:10 ` [RFC/RFT][PATCH 2/3] ACPI / PM: Register power resource devices as soon as they are needed Rafael J. Wysocki
2010-10-28 13:10 ` Rafael J. Wysocki
2010-10-28 13:11 ` [RFC/RFT][PATCH 3/3] ACPI / PM: Fix initial reference counting of power resources Rafael J. Wysocki
2010-10-28 13:11 ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.