提交 c35923bc 编写于 作者: A Alexey Starikovskiy 提交者: Len Brown

ACPI: power: don't cache power resource state

ACPI may change power resource state behind our back, so don't
keep our local copy, which may not be valid.
Signed-off-by: NAlexey Starikovskiy <astarikovskiy@suse.de>
Signed-off-by: NLen Brown <len.brown@intel.com>
上级 95b937e3
...@@ -198,11 +198,9 @@ int acpi_bus_set_power(acpi_handle handle, int state) ...@@ -198,11 +198,9 @@ int acpi_bus_set_power(acpi_handle handle, int state)
return -ENODEV; return -ENODEV;
} }
/* /*
* Get device's current power state if it's unknown * Get device's current power state
* This means device power state isn't initialized or previous setting failed
*/ */
if ((device->power.state == ACPI_STATE_UNKNOWN) || device->flags.force_power_state) acpi_bus_get_power(device->handle, &device->power.state);
acpi_bus_get_power(device->handle, &device->power.state);
if ((state == device->power.state) && !device->flags.force_power_state) { if ((state == device->power.state) && !device->flags.force_power_state) {
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
state)); state));
......
...@@ -86,7 +86,6 @@ struct acpi_power_resource { ...@@ -86,7 +86,6 @@ struct acpi_power_resource {
acpi_bus_id name; acpi_bus_id name;
u32 system_level; u32 system_level;
u32 order; u32 order;
int state;
struct mutex resource_lock; struct mutex resource_lock;
struct list_head reference; struct list_head reference;
}; };
...@@ -128,33 +127,31 @@ acpi_power_get_context(acpi_handle handle, ...@@ -128,33 +127,31 @@ acpi_power_get_context(acpi_handle handle,
return 0; return 0;
} }
static int acpi_power_get_state(struct acpi_power_resource *resource) static int acpi_power_get_state(struct acpi_power_resource *resource, int *state)
{ {
acpi_status status = AE_OK; acpi_status status = AE_OK;
unsigned long sta = 0; unsigned long sta = 0;
if (!resource) if (!resource || !state)
return -EINVAL; return -EINVAL;
status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta); status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
if (sta & 0x01) *state = (sta & 0x01)?ACPI_POWER_RESOURCE_STATE_ON:
resource->state = ACPI_POWER_RESOURCE_STATE_ON; ACPI_POWER_RESOURCE_STATE_OFF;
else
resource->state = ACPI_POWER_RESOURCE_STATE_OFF;
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n", ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n",
resource->name, resource->state ? "on" : "off")); resource->name, state ? "on" : "off"));
return 0; return 0;
} }
static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
{ {
int result = 0; int result = 0, state1;
struct acpi_power_resource *resource = NULL; struct acpi_power_resource *resource = NULL;
u32 i = 0; u32 i = 0;
...@@ -168,11 +165,11 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) ...@@ -168,11 +165,11 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
result = acpi_power_get_context(list->handles[i], &resource); result = acpi_power_get_context(list->handles[i], &resource);
if (result) if (result)
return result; return result;
result = acpi_power_get_state(resource); result = acpi_power_get_state(resource, &state1);
if (result) if (result)
return result; return result;
*state = resource->state; *state = state1;
if (*state != ACPI_POWER_RESOURCE_STATE_ON) if (*state != ACPI_POWER_RESOURCE_STATE_ON)
break; break;
...@@ -186,7 +183,7 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) ...@@ -186,7 +183,7 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
{ {
int result = 0; int result = 0, state;
int found = 0; int found = 0;
acpi_status status = AE_OK; acpi_status status = AE_OK;
struct acpi_power_resource *resource = NULL; struct acpi_power_resource *resource = NULL;
...@@ -224,20 +221,14 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) ...@@ -224,20 +221,14 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
} }
mutex_unlock(&resource->resource_lock); mutex_unlock(&resource->resource_lock);
if (resource->state == ACPI_POWER_RESOURCE_STATE_ON) {
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n",
resource->name));
return 0;
}
status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL); status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
result = acpi_power_get_state(resource); result = acpi_power_get_state(resource, &state);
if (result) if (result)
return result; return result;
if (resource->state != ACPI_POWER_RESOURCE_STATE_ON) if (state != ACPI_POWER_RESOURCE_STATE_ON)
return -ENOEXEC; return -ENOEXEC;
/* Update the power resource's _device_ power state */ /* Update the power resource's _device_ power state */
...@@ -250,7 +241,7 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) ...@@ -250,7 +241,7 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
{ {
int result = 0; int result = 0, state;
acpi_status status = AE_OK; acpi_status status = AE_OK;
struct acpi_power_resource *resource = NULL; struct acpi_power_resource *resource = NULL;
struct list_head *node, *next; struct list_head *node, *next;
...@@ -281,20 +272,14 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) ...@@ -281,20 +272,14 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
} }
mutex_unlock(&resource->resource_lock); mutex_unlock(&resource->resource_lock);
if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) {
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n",
resource->name));
return 0;
}
status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL); status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
result = acpi_power_get_state(resource); result = acpi_power_get_state(resource, &state);
if (result) if (result)
return result; return result;
if (resource->state != ACPI_POWER_RESOURCE_STATE_OFF) if (state != ACPI_POWER_RESOURCE_STATE_OFF)
return -ENOEXEC; return -ENOEXEC;
/* Update the power resource's _device_ power state */ /* Update the power resource's _device_ power state */
...@@ -494,7 +479,7 @@ static struct proc_dir_entry *acpi_power_dir; ...@@ -494,7 +479,7 @@ static struct proc_dir_entry *acpi_power_dir;
static int acpi_power_seq_show(struct seq_file *seq, void *offset) static int acpi_power_seq_show(struct seq_file *seq, void *offset)
{ {
int count = 0; int count = 0;
int result = 0; int result = 0, state;
struct acpi_power_resource *resource = NULL; struct acpi_power_resource *resource = NULL;
struct list_head *node, *next; struct list_head *node, *next;
struct acpi_power_reference *ref; struct acpi_power_reference *ref;
...@@ -505,12 +490,12 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset) ...@@ -505,12 +490,12 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
if (!resource) if (!resource)
goto end; goto end;
result = acpi_power_get_state(resource); result = acpi_power_get_state(resource, &state);
if (result) if (result)
goto end; goto end;
seq_puts(seq, "state: "); seq_puts(seq, "state: ");
switch (resource->state) { switch (state) {
case ACPI_POWER_RESOURCE_STATE_ON: case ACPI_POWER_RESOURCE_STATE_ON:
seq_puts(seq, "on\n"); seq_puts(seq, "on\n");
break; break;
...@@ -591,7 +576,7 @@ static int acpi_power_remove_fs(struct acpi_device *device) ...@@ -591,7 +576,7 @@ static int acpi_power_remove_fs(struct acpi_device *device)
static int acpi_power_add(struct acpi_device *device) static int acpi_power_add(struct acpi_device *device)
{ {
int result = 0; int result = 0, state;
acpi_status status = AE_OK; acpi_status status = AE_OK;
struct acpi_power_resource *resource = NULL; struct acpi_power_resource *resource = NULL;
union acpi_object acpi_object; union acpi_object acpi_object;
...@@ -622,11 +607,11 @@ static int acpi_power_add(struct acpi_device *device) ...@@ -622,11 +607,11 @@ static int acpi_power_add(struct acpi_device *device)
resource->system_level = acpi_object.power_resource.system_level; resource->system_level = acpi_object.power_resource.system_level;
resource->order = acpi_object.power_resource.resource_order; resource->order = acpi_object.power_resource.resource_order;
result = acpi_power_get_state(resource); result = acpi_power_get_state(resource, &state);
if (result) if (result)
goto end; goto end;
switch (resource->state) { switch (state) {
case ACPI_POWER_RESOURCE_STATE_ON: case ACPI_POWER_RESOURCE_STATE_ON:
device->power.state = ACPI_STATE_D0; device->power.state = ACPI_STATE_D0;
break; break;
...@@ -643,7 +628,7 @@ static int acpi_power_add(struct acpi_device *device) ...@@ -643,7 +628,7 @@ static int acpi_power_add(struct acpi_device *device)
goto end; goto end;
printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device),
acpi_device_bid(device), resource->state ? "on" : "off"); acpi_device_bid(device), state ? "on" : "off");
end: end:
if (result) if (result)
...@@ -680,7 +665,7 @@ static int acpi_power_remove(struct acpi_device *device, int type) ...@@ -680,7 +665,7 @@ static int acpi_power_remove(struct acpi_device *device, int type)
static int acpi_power_resume(struct acpi_device *device) static int acpi_power_resume(struct acpi_device *device)
{ {
int result = 0; int result = 0, state;
struct acpi_power_resource *resource = NULL; struct acpi_power_resource *resource = NULL;
struct acpi_power_reference *ref; struct acpi_power_reference *ref;
...@@ -689,12 +674,12 @@ static int acpi_power_resume(struct acpi_device *device) ...@@ -689,12 +674,12 @@ static int acpi_power_resume(struct acpi_device *device)
resource = (struct acpi_power_resource *)acpi_driver_data(device); resource = (struct acpi_power_resource *)acpi_driver_data(device);
result = acpi_power_get_state(resource); result = acpi_power_get_state(resource, &state);
if (result) if (result)
return result; return result;
mutex_lock(&resource->resource_lock); mutex_lock(&resource->resource_lock);
if ((resource->state == ACPI_POWER_RESOURCE_STATE_OFF) && if (state == ACPI_POWER_RESOURCE_STATE_OFF &&
!list_empty(&resource->reference)) { !list_empty(&resource->reference)) {
ref = container_of(resource->reference.next, struct acpi_power_reference, node); ref = container_of(resource->reference.next, struct acpi_power_reference, node);
mutex_unlock(&resource->resource_lock); mutex_unlock(&resource->resource_lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册