diff options
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/acpi/bus.c | 270 | ||||
| -rw-r--r-- | drivers/acpi/device_pm.c | 357 | ||||
| -rw-r--r-- | drivers/acpi/internal.h | 20 | ||||
| -rw-r--r-- | drivers/acpi/power.c | 730 | ||||
| -rw-r--r-- | drivers/acpi/proc.c | 9 | ||||
| -rw-r--r-- | drivers/acpi/scan.c | 462 | ||||
| -rw-r--r-- | drivers/acpi/sleep.c | 89 | ||||
| -rw-r--r-- | drivers/acpi/sleep.h | 2 | ||||
| -rw-r--r-- | drivers/ata/libata-acpi.c | 18 | ||||
| -rw-r--r-- | drivers/pci/pci-acpi.c | 2 |
10 files changed, 1076 insertions, 883 deletions
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 1f0d457ecbcf..01708a165368 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
| @@ -178,276 +178,6 @@ int acpi_bus_get_private_data(acpi_handle handle, void **data) | |||
| 178 | } | 178 | } |
| 179 | EXPORT_SYMBOL(acpi_bus_get_private_data); | 179 | EXPORT_SYMBOL(acpi_bus_get_private_data); |
| 180 | 180 | ||
| 181 | /* -------------------------------------------------------------------------- | ||
| 182 | Power Management | ||
| 183 | -------------------------------------------------------------------------- */ | ||
| 184 | |||
| 185 | static const char *state_string(int state) | ||
| 186 | { | ||
| 187 | switch (state) { | ||
| 188 | case ACPI_STATE_D0: | ||
| 189 | return "D0"; | ||
| 190 | case ACPI_STATE_D1: | ||
| 191 | return "D1"; | ||
| 192 | case ACPI_STATE_D2: | ||
| 193 | return "D2"; | ||
| 194 | case ACPI_STATE_D3_HOT: | ||
| 195 | return "D3hot"; | ||
| 196 | case ACPI_STATE_D3_COLD: | ||
| 197 | return "D3"; | ||
| 198 | default: | ||
| 199 | return "(unknown)"; | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | static int __acpi_bus_get_power(struct acpi_device *device, int *state) | ||
| 204 | { | ||
| 205 | int result = ACPI_STATE_UNKNOWN; | ||
| 206 | |||
| 207 | if (!device || !state) | ||
| 208 | return -EINVAL; | ||
| 209 | |||
| 210 | if (!device->flags.power_manageable) { | ||
| 211 | /* TBD: Non-recursive algorithm for walking up hierarchy. */ | ||
| 212 | *state = device->parent ? | ||
| 213 | device->parent->power.state : ACPI_STATE_D0; | ||
| 214 | goto out; | ||
| 215 | } | ||
| 216 | |||
| 217 | /* | ||
| 218 | * Get the device's power state either directly (via _PSC) or | ||
| 219 | * indirectly (via power resources). | ||
| 220 | */ | ||
| 221 | if (device->power.flags.explicit_get) { | ||
| 222 | unsigned long long psc; | ||
| 223 | acpi_status status = acpi_evaluate_integer(device->handle, | ||
| 224 | "_PSC", NULL, &psc); | ||
| 225 | if (ACPI_FAILURE(status)) | ||
| 226 | return -ENODEV; | ||
| 227 | |||
| 228 | result = psc; | ||
| 229 | } | ||
| 230 | /* The test below covers ACPI_STATE_UNKNOWN too. */ | ||
| 231 | if (result <= ACPI_STATE_D2) { | ||
| 232 | ; /* Do nothing. */ | ||
| 233 | } else if (device->power.flags.power_resources) { | ||
| 234 | int error = acpi_power_get_inferred_state(device, &result); | ||
| 235 | if (error) | ||
| 236 | return error; | ||
| 237 | } else if (result == ACPI_STATE_D3_HOT) { | ||
| 238 | result = ACPI_STATE_D3; | ||
| 239 | } | ||
| 240 | |||
| 241 | /* | ||
| 242 | * If we were unsure about the device parent's power state up to this | ||
| 243 | * point, the fact that the device is in D0 implies that the parent has | ||
| 244 | * to be in D0 too. | ||
| 245 | */ | ||
| 246 | if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN | ||
| 247 | && result == ACPI_STATE_D0) | ||
| 248 | device->parent->power.state = ACPI_STATE_D0; | ||
| 249 | |||
| 250 | *state = result; | ||
| 251 | |||
| 252 | out: | ||
| 253 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n", | ||
| 254 | device->pnp.bus_id, state_string(*state))); | ||
| 255 | |||
| 256 | return 0; | ||
| 257 | } | ||
| 258 | |||
| 259 | |||
| 260 | /** | ||
| 261 | * acpi_device_set_power - Set power state of an ACPI device. | ||
| 262 | * @device: Device to set the power state of. | ||
| 263 | * @state: New power state to set. | ||
| 264 | * | ||
| 265 | * Callers must ensure that the device is power manageable before using this | ||
| 266 | * function. | ||
| 267 | */ | ||
| 268 | int acpi_device_set_power(struct acpi_device *device, int state) | ||
| 269 | { | ||
| 270 | int result = 0; | ||
| 271 | acpi_status status = AE_OK; | ||
| 272 | char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' }; | ||
| 273 | |||
| 274 | if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD)) | ||
| 275 | return -EINVAL; | ||
| 276 | |||
| 277 | /* Make sure this is a valid target state */ | ||
| 278 | |||
| 279 | if (state == device->power.state) { | ||
| 280 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n", | ||
| 281 | state_string(state))); | ||
| 282 | return 0; | ||
| 283 | } | ||
| 284 | |||
| 285 | if (!device->power.states[state].flags.valid) { | ||
| 286 | printk(KERN_WARNING PREFIX "Device does not support %s\n", | ||
| 287 | state_string(state)); | ||
| 288 | return -ENODEV; | ||
| 289 | } | ||
| 290 | if (device->parent && (state < device->parent->power.state)) { | ||
| 291 | printk(KERN_WARNING PREFIX | ||
| 292 | "Cannot set device to a higher-powered" | ||
| 293 | " state than parent\n"); | ||
| 294 | return -ENODEV; | ||
| 295 | } | ||
| 296 | |||
| 297 | /* For D3cold we should execute _PS3, not _PS4. */ | ||
| 298 | if (state == ACPI_STATE_D3_COLD) | ||
| 299 | object_name[3] = '3'; | ||
| 300 | |||
| 301 | /* | ||
| 302 | * Transition Power | ||
| 303 | * ---------------- | ||
| 304 | * On transitions to a high-powered state we first apply power (via | ||
| 305 | * power resources) then evalute _PSx. Conversly for transitions to | ||
| 306 | * a lower-powered state. | ||
| 307 | */ | ||
| 308 | if (state < device->power.state) { | ||
| 309 | if (device->power.state >= ACPI_STATE_D3_HOT && | ||
| 310 | state != ACPI_STATE_D0) { | ||
| 311 | printk(KERN_WARNING PREFIX | ||
| 312 | "Cannot transition to non-D0 state from D3\n"); | ||
| 313 | return -ENODEV; | ||
| 314 | } | ||
| 315 | if (device->power.flags.power_resources) { | ||
| 316 | result = acpi_power_transition(device, state); | ||
| 317 | if (result) | ||
| 318 | goto end; | ||
| 319 | } | ||
| 320 | if (device->power.states[state].flags.explicit_set) { | ||
| 321 | status = acpi_evaluate_object(device->handle, | ||
| 322 | object_name, NULL, NULL); | ||
| 323 | if (ACPI_FAILURE(status)) { | ||
| 324 | result = -ENODEV; | ||
| 325 | goto end; | ||
| 326 | } | ||
| 327 | } | ||
| 328 | } else { | ||
| 329 | if (device->power.states[state].flags.explicit_set) { | ||
| 330 | status = acpi_evaluate_object(device->handle, | ||
| 331 | object_name, NULL, NULL); | ||
| 332 | if (ACPI_FAILURE(status)) { | ||
| 333 | result = -ENODEV; | ||
| 334 | goto end; | ||
| 335 | } | ||
| 336 | } | ||
| 337 | if (device->power.flags.power_resources) { | ||
| 338 | result = acpi_power_transition(device, state); | ||
| 339 | if (result) | ||
| 340 | goto end; | ||
| 341 | } | ||
| 342 | } | ||
| 343 | |||
| 344 | end: | ||
| 345 | if (result) | ||
| 346 | printk(KERN_WARNING PREFIX | ||
| 347 | "Device [%s] failed to transition to %s\n", | ||
| 348 | device->pnp.bus_id, state_string(state)); | ||
| 349 | else { | ||
| 350 | device->power.state = state; | ||
| 351 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 352 | "Device [%s] transitioned to %s\n", | ||
| 353 | device->pnp.bus_id, state_string(state))); | ||
| 354 | } | ||
| 355 | |||
| 356 | return result; | ||
| 357 | } | ||
| 358 | EXPORT_SYMBOL(acpi_device_set_power); | ||
| 359 | |||
| 360 | |||
| 361 | int acpi_bus_set_power(acpi_handle handle, int state) | ||
| 362 | { | ||
| 363 | struct acpi_device *device; | ||
| 364 | int result; | ||
| 365 | |||
| 366 | result = acpi_bus_get_device(handle, &device); | ||
| 367 | if (result) | ||
| 368 | return result; | ||
| 369 | |||
| 370 | if (!device->flags.power_manageable) { | ||
| 371 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 372 | "Device [%s] is not power manageable\n", | ||
| 373 | dev_name(&device->dev))); | ||
| 374 | return -ENODEV; | ||
| 375 | } | ||
| 376 | |||
| 377 | return acpi_device_set_power(device, state); | ||
| 378 | } | ||
| 379 | EXPORT_SYMBOL(acpi_bus_set_power); | ||
| 380 | |||
| 381 | |||
| 382 | int acpi_bus_init_power(struct acpi_device *device) | ||
| 383 | { | ||
| 384 | int state; | ||
| 385 | int result; | ||
| 386 | |||
| 387 | if (!device) | ||
| 388 | return -EINVAL; | ||
| 389 | |||
| 390 | device->power.state = ACPI_STATE_UNKNOWN; | ||
| 391 | |||
| 392 | result = __acpi_bus_get_power(device, &state); | ||
| 393 | if (result) | ||
| 394 | return result; | ||
| 395 | |||
| 396 | if (device->power.flags.power_resources) | ||
| 397 | result = acpi_power_on_resources(device, state); | ||
| 398 | |||
| 399 | if (!result) | ||
| 400 | device->power.state = state; | ||
| 401 | |||
| 402 | return result; | ||
| 403 | } | ||
| 404 | |||
| 405 | |||
| 406 | int acpi_bus_update_power(acpi_handle handle, int *state_p) | ||
| 407 | { | ||
| 408 | struct acpi_device *device; | ||
| 409 | int state; | ||
| 410 | int result; | ||
| 411 | |||
| 412 | result = acpi_bus_get_device(handle, &device); | ||
| 413 | if (result) | ||
| 414 | return result; | ||
| 415 | |||
| 416 | result = __acpi_bus_get_power(device, &state); | ||
| 417 | if (result) | ||
| 418 | return result; | ||
| 419 | |||
| 420 | result = acpi_device_set_power(device, state); | ||
| 421 | if (!result && state_p) | ||
| 422 | *state_p = state; | ||
| 423 | |||
| 424 | return result; | ||
| 425 | } | ||
| 426 | EXPORT_SYMBOL_GPL(acpi_bus_update_power); | ||
| 427 | |||
| 428 | |||
| 429 | bool acpi_bus_power_manageable(acpi_handle handle) | ||
| 430 | { | ||
| 431 | struct acpi_device *device; | ||
| 432 | int result; | ||
| 433 | |||
| 434 | result = acpi_bus_get_device(handle, &device); | ||
| 435 | return result ? false : device->flags.power_manageable; | ||
| 436 | } | ||
| 437 | |||
| 438 | EXPORT_SYMBOL(acpi_bus_power_manageable); | ||
| 439 | |||
| 440 | bool acpi_bus_can_wakeup(acpi_handle handle) | ||
| 441 | { | ||
| 442 | struct acpi_device *device; | ||
| 443 | int result; | ||
| 444 | |||
| 445 | result = acpi_bus_get_device(handle, &device); | ||
| 446 | return result ? false : device->wakeup.flags.valid; | ||
| 447 | } | ||
| 448 | |||
| 449 | EXPORT_SYMBOL(acpi_bus_can_wakeup); | ||
| 450 | |||
| 451 | static void acpi_print_osc_error(acpi_handle handle, | 181 | static void acpi_print_osc_error(acpi_handle handle, |
| 452 | struct acpi_osc_context *context, char *error) | 182 | struct acpi_osc_context *context, char *error) |
| 453 | { | 183 | { |
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 995019063f64..dd314ef9bff1 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c | |||
| @@ -30,6 +30,12 @@ | |||
| 30 | 30 | ||
| 31 | #include <acpi/acpi.h> | 31 | #include <acpi/acpi.h> |
| 32 | #include <acpi/acpi_bus.h> | 32 | #include <acpi/acpi_bus.h> |
| 33 | #include <acpi/acpi_drivers.h> | ||
| 34 | |||
| 35 | #include "internal.h" | ||
| 36 | |||
| 37 | #define _COMPONENT ACPI_POWER_COMPONENT | ||
| 38 | ACPI_MODULE_NAME("device_pm"); | ||
| 33 | 39 | ||
| 34 | static DEFINE_MUTEX(acpi_pm_notifier_lock); | 40 | static DEFINE_MUTEX(acpi_pm_notifier_lock); |
| 35 | 41 | ||
| @@ -94,6 +100,293 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev, | |||
| 94 | } | 100 | } |
| 95 | 101 | ||
| 96 | /** | 102 | /** |
| 103 | * acpi_power_state_string - String representation of ACPI device power state. | ||
| 104 | * @state: ACPI device power state to return the string representation of. | ||
| 105 | */ | ||
| 106 | const char *acpi_power_state_string(int state) | ||
| 107 | { | ||
| 108 | switch (state) { | ||
| 109 | case ACPI_STATE_D0: | ||
| 110 | return "D0"; | ||
| 111 | case ACPI_STATE_D1: | ||
| 112 | return "D1"; | ||
| 113 | case ACPI_STATE_D2: | ||
| 114 | return "D2"; | ||
| 115 | case ACPI_STATE_D3_HOT: | ||
| 116 | return "D3hot"; | ||
| 117 | case ACPI_STATE_D3_COLD: | ||
| 118 | return "D3cold"; | ||
| 119 | default: | ||
| 120 | return "(unknown)"; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | /** | ||
| 125 | * acpi_device_get_power - Get power state of an ACPI device. | ||
| 126 | * @device: Device to get the power state of. | ||
| 127 | * @state: Place to store the power state of the device. | ||
| 128 | * | ||
| 129 | * This function does not update the device's power.state field, but it may | ||
| 130 | * update its parent's power.state field (when the parent's power state is | ||
| 131 | * unknown and the device's power state turns out to be D0). | ||
| 132 | */ | ||
| 133 | int acpi_device_get_power(struct acpi_device *device, int *state) | ||
| 134 | { | ||
| 135 | int result = ACPI_STATE_UNKNOWN; | ||
| 136 | |||
| 137 | if (!device || !state) | ||
| 138 | return -EINVAL; | ||
| 139 | |||
| 140 | if (!device->flags.power_manageable) { | ||
| 141 | /* TBD: Non-recursive algorithm for walking up hierarchy. */ | ||
| 142 | *state = device->parent ? | ||
| 143 | device->parent->power.state : ACPI_STATE_D0; | ||
| 144 | goto out; | ||
| 145 | } | ||
| 146 | |||
| 147 | /* | ||
| 148 | * Get the device's power state either directly (via _PSC) or | ||
| 149 | * indirectly (via power resources). | ||
| 150 | */ | ||
| 151 | if (device->power.flags.explicit_get) { | ||
| 152 | unsigned long long psc; | ||
| 153 | acpi_status status = acpi_evaluate_integer(device->handle, | ||
| 154 | "_PSC", NULL, &psc); | ||
| 155 | if (ACPI_FAILURE(status)) | ||
| 156 | return -ENODEV; | ||
| 157 | |||
| 158 | result = psc; | ||
| 159 | } | ||
| 160 | /* The test below covers ACPI_STATE_UNKNOWN too. */ | ||
| 161 | if (result <= ACPI_STATE_D2) { | ||
| 162 | ; /* Do nothing. */ | ||
| 163 | } else if (device->power.flags.power_resources) { | ||
| 164 | int error = acpi_power_get_inferred_state(device, &result); | ||
| 165 | if (error) | ||
| 166 | return error; | ||
| 167 | } else if (result == ACPI_STATE_D3_HOT) { | ||
| 168 | result = ACPI_STATE_D3; | ||
| 169 | } | ||
| 170 | |||
| 171 | /* | ||
| 172 | * If we were unsure about the device parent's power state up to this | ||
| 173 | * point, the fact that the device is in D0 implies that the parent has | ||
| 174 | * to be in D0 too. | ||
| 175 | */ | ||
| 176 | if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN | ||
| 177 | && result == ACPI_STATE_D0) | ||
| 178 | device->parent->power.state = ACPI_STATE_D0; | ||
| 179 | |||
| 180 | *state = result; | ||
| 181 | |||
| 182 | out: | ||
| 183 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n", | ||
| 184 | device->pnp.bus_id, acpi_power_state_string(*state))); | ||
| 185 | |||
| 186 | return 0; | ||
| 187 | } | ||
| 188 | |||
| 189 | static int acpi_dev_pm_explicit_set(struct acpi_device *adev, int state) | ||
| 190 | { | ||
| 191 | if (adev->power.states[state].flags.explicit_set) { | ||
| 192 | char method[5] = { '_', 'P', 'S', '0' + state, '\0' }; | ||
| 193 | acpi_status status; | ||
| 194 | |||
| 195 | status = acpi_evaluate_object(adev->handle, method, NULL, NULL); | ||
| 196 | if (ACPI_FAILURE(status)) | ||
| 197 | return -ENODEV; | ||
| 198 | } | ||
| 199 | return 0; | ||
| 200 | } | ||
| 201 | |||
| 202 | /** | ||
| 203 | * acpi_device_set_power - Set power state of an ACPI device. | ||
| 204 | * @device: Device to set the power state of. | ||
| 205 | * @state: New power state to set. | ||
| 206 | * | ||
| 207 | * Callers must ensure that the device is power manageable before using this | ||
| 208 | * function. | ||
| 209 | */ | ||
| 210 | int acpi_device_set_power(struct acpi_device *device, int state) | ||
| 211 | { | ||
| 212 | int result = 0; | ||
| 213 | bool cut_power = false; | ||
| 214 | |||
| 215 | if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD)) | ||
| 216 | return -EINVAL; | ||
| 217 | |||
| 218 | /* Make sure this is a valid target state */ | ||
| 219 | |||
| 220 | if (state == device->power.state) { | ||
| 221 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n", | ||
| 222 | acpi_power_state_string(state))); | ||
| 223 | return 0; | ||
| 224 | } | ||
| 225 | |||
| 226 | if (!device->power.states[state].flags.valid) { | ||
| 227 | printk(KERN_WARNING PREFIX "Device does not support %s\n", | ||
| 228 | acpi_power_state_string(state)); | ||
| 229 | return -ENODEV; | ||
| 230 | } | ||
| 231 | if (device->parent && (state < device->parent->power.state)) { | ||
| 232 | printk(KERN_WARNING PREFIX | ||
| 233 | "Cannot set device to a higher-powered" | ||
| 234 | " state than parent\n"); | ||
| 235 | return -ENODEV; | ||
| 236 | } | ||
| 237 | |||
| 238 | /* For D3cold we should first transition into D3hot. */ | ||
| 239 | if (state == ACPI_STATE_D3_COLD | ||
| 240 | && device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible) { | ||
| 241 | state = ACPI_STATE_D3_HOT; | ||
| 242 | cut_power = true; | ||
| 243 | } | ||
| 244 | |||
| 245 | if (state < device->power.state && state != ACPI_STATE_D0 | ||
| 246 | && device->power.state >= ACPI_STATE_D3_HOT) { | ||
| 247 | printk(KERN_WARNING PREFIX | ||
| 248 | "Cannot transition to non-D0 state from D3\n"); | ||
| 249 | return -ENODEV; | ||
| 250 | } | ||
| 251 | |||
| 252 | /* | ||
| 253 | * Transition Power | ||
| 254 | * ---------------- | ||
| 255 | * In accordance with the ACPI specification first apply power (via | ||
| 256 | * power resources) and then evalute _PSx. | ||
| 257 | */ | ||
| 258 | if (device->power.flags.power_resources) { | ||
| 259 | result = acpi_power_transition(device, state); | ||
| 260 | if (result) | ||
| 261 | goto end; | ||
| 262 | } | ||
| 263 | result = acpi_dev_pm_explicit_set(device, state); | ||
| 264 | if (result) | ||
| 265 | goto end; | ||
| 266 | |||
| 267 | if (cut_power) { | ||
| 268 | device->power.state = state; | ||
| 269 | state = ACPI_STATE_D3_COLD; | ||
| 270 | result = acpi_power_transition(device, state); | ||
| 271 | } | ||
| 272 | |||
| 273 | end: | ||
| 274 | if (result) { | ||
| 275 | printk(KERN_WARNING PREFIX | ||
| 276 | "Device [%s] failed to transition to %s\n", | ||
| 277 | device->pnp.bus_id, | ||
| 278 | acpi_power_state_string(state)); | ||
| 279 | } else { | ||
| 280 | device->power.state = state; | ||
| 281 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 282 | "Device [%s] transitioned to %s\n", | ||
| 283 | device->pnp.bus_id, | ||
| 284 | acpi_power_state_string(state))); | ||
| 285 | } | ||
| 286 | |||
| 287 | return result; | ||
| 288 | } | ||
| 289 | EXPORT_SYMBOL(acpi_device_set_power); | ||
| 290 | |||
| 291 | int acpi_bus_set_power(acpi_handle handle, int state) | ||
| 292 | { | ||
| 293 | struct acpi_device *device; | ||
| 294 | int result; | ||
| 295 | |||
| 296 | result = acpi_bus_get_device(handle, &device); | ||
| 297 | if (result) | ||
| 298 | return result; | ||
| 299 | |||
| 300 | if (!device->flags.power_manageable) { | ||
| 301 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 302 | "Device [%s] is not power manageable\n", | ||
| 303 | dev_name(&device->dev))); | ||
| 304 | return -ENODEV; | ||
| 305 | } | ||
| 306 | |||
| 307 | return acpi_device_set_power(device, state); | ||
| 308 | } | ||
| 309 | EXPORT_SYMBOL(acpi_bus_set_power); | ||
| 310 | |||
| 311 | int acpi_bus_init_power(struct acpi_device *device) | ||
| 312 | { | ||
| 313 | int state; | ||
| 314 | int result; | ||
| 315 | |||
| 316 | if (!device) | ||
| 317 | return -EINVAL; | ||
| 318 | |||
| 319 | device->power.state = ACPI_STATE_UNKNOWN; | ||
| 320 | |||
| 321 | result = acpi_device_get_power(device, &state); | ||
| 322 | if (result) | ||
| 323 | return result; | ||
| 324 | |||
| 325 | if (state < ACPI_STATE_D3_COLD && device->power.flags.power_resources) { | ||
| 326 | result = acpi_power_on_resources(device, state); | ||
| 327 | if (result) | ||
| 328 | return result; | ||
| 329 | |||
| 330 | result = acpi_dev_pm_explicit_set(device, state); | ||
| 331 | if (result) | ||
| 332 | return result; | ||
| 333 | } else if (state == ACPI_STATE_UNKNOWN) { | ||
| 334 | /* No power resources and missing _PSC? Try to force D0. */ | ||
| 335 | state = ACPI_STATE_D0; | ||
| 336 | result = acpi_dev_pm_explicit_set(device, state); | ||
| 337 | if (result) | ||
| 338 | return result; | ||
| 339 | } | ||
| 340 | device->power.state = state; | ||
| 341 | return 0; | ||
| 342 | } | ||
| 343 | |||
| 344 | int acpi_bus_update_power(acpi_handle handle, int *state_p) | ||
| 345 | { | ||
| 346 | struct acpi_device *device; | ||
| 347 | int state; | ||
| 348 | int result; | ||
| 349 | |||
| 350 | result = acpi_bus_get_device(handle, &device); | ||
| 351 | if (result) | ||
| 352 | return result; | ||
| 353 | |||
| 354 | result = acpi_device_get_power(device, &state); | ||
| 355 | if (result) | ||
| 356 | return result; | ||
| 357 | |||
| 358 | if (state == ACPI_STATE_UNKNOWN) | ||
| 359 | state = ACPI_STATE_D0; | ||
| 360 | |||
| 361 | result = acpi_device_set_power(device, state); | ||
| 362 | if (!result && state_p) | ||
| 363 | *state_p = state; | ||
| 364 | |||
| 365 | return result; | ||
| 366 | } | ||
| 367 | EXPORT_SYMBOL_GPL(acpi_bus_update_power); | ||
| 368 | |||
| 369 | bool acpi_bus_power_manageable(acpi_handle handle) | ||
| 370 | { | ||
| 371 | struct acpi_device *device; | ||
| 372 | int result; | ||
| 373 | |||
| 374 | result = acpi_bus_get_device(handle, &device); | ||
| 375 | return result ? false : device->flags.power_manageable; | ||
| 376 | } | ||
| 377 | EXPORT_SYMBOL(acpi_bus_power_manageable); | ||
| 378 | |||
| 379 | bool acpi_bus_can_wakeup(acpi_handle handle) | ||
| 380 | { | ||
| 381 | struct acpi_device *device; | ||
| 382 | int result; | ||
| 383 | |||
| 384 | result = acpi_bus_get_device(handle, &device); | ||
| 385 | return result ? false : device->wakeup.flags.valid; | ||
| 386 | } | ||
| 387 | EXPORT_SYMBOL(acpi_bus_can_wakeup); | ||
| 388 | |||
| 389 | /** | ||
| 97 | * acpi_device_power_state - Get preferred power state of ACPI device. | 390 | * acpi_device_power_state - Get preferred power state of ACPI device. |
| 98 | * @dev: Device whose preferred target power state to return. | 391 | * @dev: Device whose preferred target power state to return. |
| 99 | * @adev: ACPI device node corresponding to @dev. | 392 | * @adev: ACPI device node corresponding to @dev. |
| @@ -213,7 +506,7 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) | |||
| 213 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); | 506 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); |
| 214 | struct acpi_device *adev; | 507 | struct acpi_device *adev; |
| 215 | 508 | ||
| 216 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | 509 | if (!handle || acpi_bus_get_device(handle, &adev)) { |
| 217 | dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); | 510 | dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); |
| 218 | return -ENODEV; | 511 | return -ENODEV; |
| 219 | } | 512 | } |
| @@ -290,7 +583,7 @@ int acpi_pm_device_run_wake(struct device *phys_dev, bool enable) | |||
| 290 | return -EINVAL; | 583 | return -EINVAL; |
| 291 | 584 | ||
| 292 | handle = DEVICE_ACPI_HANDLE(phys_dev); | 585 | handle = DEVICE_ACPI_HANDLE(phys_dev); |
| 293 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | 586 | if (!handle || acpi_bus_get_device(handle, &adev)) { |
| 294 | dev_dbg(phys_dev, "ACPI handle without context in %s!\n", | 587 | dev_dbg(phys_dev, "ACPI handle without context in %s!\n", |
| 295 | __func__); | 588 | __func__); |
| 296 | return -ENODEV; | 589 | return -ENODEV; |
| @@ -304,7 +597,7 @@ static inline void acpi_wakeup_device(acpi_handle handle, u32 event, | |||
| 304 | void *context) {} | 597 | void *context) {} |
| 305 | #endif /* CONFIG_PM_RUNTIME */ | 598 | #endif /* CONFIG_PM_RUNTIME */ |
| 306 | 599 | ||
| 307 | #ifdef CONFIG_PM_SLEEP | 600 | #ifdef CONFIG_PM_SLEEP |
| 308 | /** | 601 | /** |
| 309 | * __acpi_device_sleep_wake - Enable or disable device to wake up the system. | 602 | * __acpi_device_sleep_wake - Enable or disable device to wake up the system. |
| 310 | * @dev: Device to enable/desible to wake up the system. | 603 | * @dev: Device to enable/desible to wake up the system. |
| @@ -334,7 +627,7 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable) | |||
| 334 | return -EINVAL; | 627 | return -EINVAL; |
| 335 | 628 | ||
| 336 | handle = DEVICE_ACPI_HANDLE(dev); | 629 | handle = DEVICE_ACPI_HANDLE(dev); |
| 337 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | 630 | if (!handle || acpi_bus_get_device(handle, &adev)) { |
| 338 | dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); | 631 | dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); |
| 339 | return -ENODEV; | 632 | return -ENODEV; |
| 340 | } | 633 | } |
| @@ -665,3 +958,59 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off) | |||
| 665 | } | 958 | } |
| 666 | } | 959 | } |
| 667 | EXPORT_SYMBOL_GPL(acpi_dev_pm_detach); | 960 | EXPORT_SYMBOL_GPL(acpi_dev_pm_detach); |
| 961 | |||
| 962 | /** | ||
| 963 | * acpi_dev_pm_add_dependent - Add physical device depending for PM. | ||
| 964 | * @handle: Handle of ACPI device node. | ||
| 965 | * @depdev: Device depending on that node for PM. | ||
| 966 | */ | ||
| 967 | void acpi_dev_pm_add_dependent(acpi_handle handle, struct device *depdev) | ||
| 968 | { | ||
| 969 | struct acpi_device_physical_node *dep; | ||
| 970 | struct acpi_device *adev; | ||
| 971 | |||
| 972 | if (!depdev || acpi_bus_get_device(handle, &adev)) | ||
| 973 | return; | ||
| 974 | |||
| 975 | mutex_lock(&adev->physical_node_lock); | ||
| 976 | |||
| 977 | list_for_each_entry(dep, &adev->power_dependent, node) | ||
| 978 | if (dep->dev == depdev) | ||
| 979 | goto out; | ||
| 980 | |||
| 981 | dep = kzalloc(sizeof(*dep), GFP_KERNEL); | ||
| 982 | if (dep) { | ||
| 983 | dep->dev = depdev; | ||
| 984 | list_add_tail(&dep->node, &adev->power_dependent); | ||
| 985 | } | ||
| 986 | |||
| 987 | out: | ||
| 988 | mutex_unlock(&adev->physical_node_lock); | ||
| 989 | } | ||
| 990 | EXPORT_SYMBOL_GPL(acpi_dev_pm_add_dependent); | ||
| 991 | |||
| 992 | /** | ||
| 993 | * acpi_dev_pm_remove_dependent - Remove physical device depending for PM. | ||
| 994 | * @handle: Handle of ACPI device node. | ||
| 995 | * @depdev: Device depending on that node for PM. | ||
| 996 | */ | ||
| 997 | void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev) | ||
| 998 | { | ||
| 999 | struct acpi_device_physical_node *dep; | ||
| 1000 | struct acpi_device *adev; | ||
| 1001 | |||
| 1002 | if (!depdev || acpi_bus_get_device(handle, &adev)) | ||
| 1003 | return; | ||
| 1004 | |||
| 1005 | mutex_lock(&adev->physical_node_lock); | ||
| 1006 | |||
| 1007 | list_for_each_entry(dep, &adev->power_dependent, node) | ||
| 1008 | if (dep->dev == depdev) { | ||
| 1009 | list_del(&dep->node); | ||
| 1010 | kfree(dep); | ||
| 1011 | break; | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | mutex_unlock(&adev->physical_node_lock); | ||
| 1015 | } | ||
| 1016 | EXPORT_SYMBOL_GPL(acpi_dev_pm_remove_dependent); | ||
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index e050254ae143..c5a61cd6c1a5 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h | |||
| @@ -35,15 +35,33 @@ static inline void acpi_debugfs_init(void) { return; } | |||
| 35 | #endif | 35 | #endif |
| 36 | 36 | ||
| 37 | /* -------------------------------------------------------------------------- | 37 | /* -------------------------------------------------------------------------- |
| 38 | Device Node Initialization / Removal | ||
| 39 | -------------------------------------------------------------------------- */ | ||
| 40 | #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ | ||
| 41 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) | ||
| 42 | |||
| 43 | int acpi_device_add(struct acpi_device *device, | ||
| 44 | void (*release)(struct device *)); | ||
| 45 | void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, | ||
| 46 | int type, unsigned long long sta); | ||
| 47 | void acpi_device_add_finalize(struct acpi_device *device); | ||
| 48 | void acpi_free_ids(struct acpi_device *device); | ||
| 49 | |||
| 50 | /* -------------------------------------------------------------------------- | ||
| 38 | Power Resource | 51 | Power Resource |
| 39 | -------------------------------------------------------------------------- */ | 52 | -------------------------------------------------------------------------- */ |
| 40 | int acpi_power_init(void); | 53 | int acpi_power_init(void); |
| 54 | void acpi_power_resources_list_free(struct list_head *list); | ||
| 55 | int acpi_extract_power_resources(union acpi_object *package, unsigned int start, | ||
| 56 | struct list_head *list); | ||
| 57 | int acpi_add_power_resource(acpi_handle handle); | ||
| 58 | void acpi_power_add_remove_device(struct acpi_device *adev, bool add); | ||
| 59 | int acpi_power_min_system_level(struct list_head *list); | ||
| 41 | int acpi_device_sleep_wake(struct acpi_device *dev, | 60 | int acpi_device_sleep_wake(struct acpi_device *dev, |
| 42 | int enable, int sleep_state, int dev_state); | 61 | int enable, int sleep_state, int dev_state); |
| 43 | int acpi_power_get_inferred_state(struct acpi_device *device, int *state); | 62 | int acpi_power_get_inferred_state(struct acpi_device *device, int *state); |
| 44 | int acpi_power_on_resources(struct acpi_device *device, int state); | 63 | int acpi_power_on_resources(struct acpi_device *device, int state); |
| 45 | int acpi_power_transition(struct acpi_device *device, int state); | 64 | int acpi_power_transition(struct acpi_device *device, int state); |
| 46 | int acpi_bus_init_power(struct acpi_device *device); | ||
| 47 | 65 | ||
| 48 | int acpi_wakeup_device_init(void); | 66 | int acpi_wakeup_device_init(void); |
| 49 | void acpi_early_processor_set_pdc(void); | 67 | void acpi_early_processor_set_pdc(void); |
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c index 6e7b9d523812..b820528a5fa3 100644 --- a/drivers/acpi/power.c +++ b/drivers/acpi/power.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include <linux/types.h> | 41 | #include <linux/types.h> |
| 42 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
| 43 | #include <linux/pm_runtime.h> | 43 | #include <linux/pm_runtime.h> |
| 44 | #include <linux/sysfs.h> | ||
| 44 | #include <acpi/acpi_bus.h> | 45 | #include <acpi/acpi_bus.h> |
| 45 | #include <acpi/acpi_drivers.h> | 46 | #include <acpi/acpi_drivers.h> |
| 46 | #include "sleep.h" | 47 | #include "sleep.h" |
| @@ -58,88 +59,121 @@ ACPI_MODULE_NAME("power"); | |||
| 58 | #define ACPI_POWER_RESOURCE_STATE_ON 0x01 | 59 | #define ACPI_POWER_RESOURCE_STATE_ON 0x01 |
| 59 | #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF | 60 | #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF |
| 60 | 61 | ||
| 61 | static int acpi_power_add(struct acpi_device *device); | 62 | struct acpi_power_dependent_device { |
| 62 | static int acpi_power_remove(struct acpi_device *device, int type); | 63 | struct list_head node; |
| 63 | 64 | struct acpi_device *adev; | |
| 64 | static const struct acpi_device_id power_device_ids[] = { | 65 | struct work_struct work; |
| 65 | {ACPI_POWER_HID, 0}, | ||
| 66 | {"", 0}, | ||
| 67 | }; | ||
| 68 | MODULE_DEVICE_TABLE(acpi, power_device_ids); | ||
| 69 | |||
| 70 | #ifdef CONFIG_PM_SLEEP | ||
| 71 | static int acpi_power_resume(struct device *dev); | ||
| 72 | #endif | ||
| 73 | static SIMPLE_DEV_PM_OPS(acpi_power_pm, NULL, acpi_power_resume); | ||
| 74 | |||
| 75 | static struct acpi_driver acpi_power_driver = { | ||
| 76 | .name = "power", | ||
| 77 | .class = ACPI_POWER_CLASS, | ||
| 78 | .ids = power_device_ids, | ||
| 79 | .ops = { | ||
| 80 | .add = acpi_power_add, | ||
| 81 | .remove = acpi_power_remove, | ||
| 82 | }, | ||
| 83 | .drv.pm = &acpi_power_pm, | ||
| 84 | }; | ||
| 85 | |||
| 86 | /* | ||
| 87 | * A power managed device | ||
| 88 | * A device may rely on multiple power resources. | ||
| 89 | * */ | ||
| 90 | struct acpi_power_managed_device { | ||
| 91 | struct device *dev; /* The physical device */ | ||
| 92 | acpi_handle *handle; | ||
| 93 | }; | ||
| 94 | |||
| 95 | struct acpi_power_resource_device { | ||
| 96 | struct acpi_power_managed_device *device; | ||
| 97 | struct acpi_power_resource_device *next; | ||
| 98 | }; | 66 | }; |
| 99 | 67 | ||
| 100 | struct acpi_power_resource { | 68 | struct acpi_power_resource { |
| 101 | struct acpi_device * device; | 69 | struct acpi_device device; |
| 102 | acpi_bus_id name; | 70 | struct list_head list_node; |
| 71 | struct list_head dependent; | ||
| 72 | char *name; | ||
| 103 | u32 system_level; | 73 | u32 system_level; |
| 104 | u32 order; | 74 | u32 order; |
| 105 | unsigned int ref_count; | 75 | unsigned int ref_count; |
| 106 | struct mutex resource_lock; | 76 | struct mutex resource_lock; |
| 77 | }; | ||
| 107 | 78 | ||
| 108 | /* List of devices relying on this power resource */ | 79 | struct acpi_power_resource_entry { |
| 109 | struct acpi_power_resource_device *devices; | 80 | struct list_head node; |
| 110 | struct mutex devices_lock; | 81 | struct acpi_power_resource *resource; |
| 111 | }; | 82 | }; |
| 112 | 83 | ||
| 113 | static struct list_head acpi_power_resource_list; | 84 | static LIST_HEAD(acpi_power_resource_list); |
| 85 | static DEFINE_MUTEX(power_resource_list_lock); | ||
| 114 | 86 | ||
| 115 | /* -------------------------------------------------------------------------- | 87 | /* -------------------------------------------------------------------------- |
| 116 | Power Resource Management | 88 | Power Resource Management |
| 117 | -------------------------------------------------------------------------- */ | 89 | -------------------------------------------------------------------------- */ |
| 118 | 90 | ||
| 119 | static int | 91 | static inline |
| 120 | acpi_power_get_context(acpi_handle handle, | 92 | struct acpi_power_resource *to_power_resource(struct acpi_device *device) |
| 121 | struct acpi_power_resource **resource) | ||
| 122 | { | 93 | { |
| 123 | int result = 0; | 94 | return container_of(device, struct acpi_power_resource, device); |
| 124 | struct acpi_device *device = NULL; | 95 | } |
| 96 | |||
| 97 | static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle) | ||
| 98 | { | ||
| 99 | struct acpi_device *device; | ||
| 125 | 100 | ||
| 101 | if (acpi_bus_get_device(handle, &device)) | ||
| 102 | return NULL; | ||
| 126 | 103 | ||
| 127 | if (!resource) | 104 | return to_power_resource(device); |
| 128 | return -ENODEV; | 105 | } |
| 129 | 106 | ||
| 130 | result = acpi_bus_get_device(handle, &device); | 107 | static int acpi_power_resources_list_add(acpi_handle handle, |
| 131 | if (result) { | 108 | struct list_head *list) |
| 132 | printk(KERN_WARNING PREFIX "Getting context [%p]\n", handle); | 109 | { |
| 133 | return result; | 110 | struct acpi_power_resource *resource = acpi_power_get_context(handle); |
| 134 | } | 111 | struct acpi_power_resource_entry *entry; |
| 135 | 112 | ||
| 136 | *resource = acpi_driver_data(device); | 113 | if (!resource || !list) |
| 137 | if (!*resource) | 114 | return -EINVAL; |
| 138 | return -ENODEV; | 115 | |
| 116 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); | ||
| 117 | if (!entry) | ||
| 118 | return -ENOMEM; | ||
| 119 | |||
| 120 | entry->resource = resource; | ||
| 121 | if (!list_empty(list)) { | ||
| 122 | struct acpi_power_resource_entry *e; | ||
| 139 | 123 | ||
| 124 | list_for_each_entry(e, list, node) | ||
| 125 | if (e->resource->order > resource->order) { | ||
| 126 | list_add_tail(&entry->node, &e->node); | ||
| 127 | return 0; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | list_add_tail(&entry->node, list); | ||
| 140 | return 0; | 131 | return 0; |
| 141 | } | 132 | } |
| 142 | 133 | ||
| 134 | void acpi_power_resources_list_free(struct list_head *list) | ||
| 135 | { | ||
| 136 | struct acpi_power_resource_entry *entry, *e; | ||
| 137 | |||
| 138 | list_for_each_entry_safe(entry, e, list, node) { | ||
| 139 | list_del(&entry->node); | ||
| 140 | kfree(entry); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | int acpi_extract_power_resources(union acpi_object *package, unsigned int start, | ||
| 145 | struct list_head *list) | ||
| 146 | { | ||
| 147 | unsigned int i; | ||
| 148 | int err = 0; | ||
| 149 | |||
| 150 | for (i = start; i < package->package.count; i++) { | ||
| 151 | union acpi_object *element = &package->package.elements[i]; | ||
| 152 | acpi_handle rhandle; | ||
| 153 | |||
| 154 | if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { | ||
| 155 | err = -ENODATA; | ||
| 156 | break; | ||
| 157 | } | ||
| 158 | rhandle = element->reference.handle; | ||
| 159 | if (!rhandle) { | ||
| 160 | err = -ENODEV; | ||
| 161 | break; | ||
| 162 | } | ||
| 163 | err = acpi_add_power_resource(rhandle); | ||
| 164 | if (err) | ||
| 165 | break; | ||
| 166 | |||
| 167 | err = acpi_power_resources_list_add(rhandle, list); | ||
| 168 | if (err) | ||
| 169 | break; | ||
| 170 | } | ||
| 171 | if (err) | ||
| 172 | acpi_power_resources_list_free(list); | ||
| 173 | |||
| 174 | return err; | ||
| 175 | } | ||
| 176 | |||
| 143 | static int acpi_power_get_state(acpi_handle handle, int *state) | 177 | static int acpi_power_get_state(acpi_handle handle, int *state) |
| 144 | { | 178 | { |
| 145 | acpi_status status = AE_OK; | 179 | acpi_status status = AE_OK; |
| @@ -167,31 +201,23 @@ static int acpi_power_get_state(acpi_handle handle, int *state) | |||
| 167 | return 0; | 201 | return 0; |
| 168 | } | 202 | } |
| 169 | 203 | ||
| 170 | static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) | 204 | static int acpi_power_get_list_state(struct list_head *list, int *state) |
| 171 | { | 205 | { |
| 206 | struct acpi_power_resource_entry *entry; | ||
| 172 | int cur_state; | 207 | int cur_state; |
| 173 | int i = 0; | ||
| 174 | 208 | ||
| 175 | if (!list || !state) | 209 | if (!list || !state) |
| 176 | return -EINVAL; | 210 | return -EINVAL; |
| 177 | 211 | ||
| 178 | /* The state of the list is 'on' IFF all resources are 'on'. */ | 212 | /* The state of the list is 'on' IFF all resources are 'on'. */ |
| 179 | 213 | list_for_each_entry(entry, list, node) { | |
| 180 | for (i = 0; i < list->count; i++) { | 214 | struct acpi_power_resource *resource = entry->resource; |
| 181 | struct acpi_power_resource *resource; | 215 | acpi_handle handle = resource->device.handle; |
| 182 | acpi_handle handle = list->handles[i]; | ||
| 183 | int result; | 216 | int result; |
| 184 | 217 | ||
| 185 | result = acpi_power_get_context(handle, &resource); | ||
| 186 | if (result) | ||
| 187 | return result; | ||
| 188 | |||
| 189 | mutex_lock(&resource->resource_lock); | 218 | mutex_lock(&resource->resource_lock); |
| 190 | |||
| 191 | result = acpi_power_get_state(handle, &cur_state); | 219 | result = acpi_power_get_state(handle, &cur_state); |
| 192 | |||
| 193 | mutex_unlock(&resource->resource_lock); | 220 | mutex_unlock(&resource->resource_lock); |
| 194 | |||
| 195 | if (result) | 221 | if (result) |
| 196 | return result; | 222 | return result; |
| 197 | 223 | ||
| @@ -203,54 +229,52 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) | |||
| 203 | cur_state ? "on" : "off")); | 229 | cur_state ? "on" : "off")); |
| 204 | 230 | ||
| 205 | *state = cur_state; | 231 | *state = cur_state; |
| 206 | |||
| 207 | return 0; | 232 | return 0; |
| 208 | } | 233 | } |
| 209 | 234 | ||
| 210 | /* Resume the device when all power resources in _PR0 are on */ | 235 | static void acpi_power_resume_dependent(struct work_struct *work) |
| 211 | static void acpi_power_on_device(struct acpi_power_managed_device *device) | ||
| 212 | { | 236 | { |
| 213 | struct acpi_device *acpi_dev; | 237 | struct acpi_power_dependent_device *dep; |
| 214 | acpi_handle handle = device->handle; | 238 | struct acpi_device_physical_node *pn; |
| 239 | struct acpi_device *adev; | ||
| 215 | int state; | 240 | int state; |
| 216 | 241 | ||
| 217 | if (acpi_bus_get_device(handle, &acpi_dev)) | 242 | dep = container_of(work, struct acpi_power_dependent_device, work); |
| 243 | adev = dep->adev; | ||
| 244 | if (acpi_power_get_inferred_state(adev, &state)) | ||
| 218 | return; | 245 | return; |
| 219 | 246 | ||
| 220 | if(acpi_power_get_inferred_state(acpi_dev, &state)) | 247 | if (state > ACPI_STATE_D0) |
| 221 | return; | 248 | return; |
| 222 | 249 | ||
| 223 | if (state == ACPI_STATE_D0 && pm_runtime_suspended(device->dev)) | 250 | mutex_lock(&adev->physical_node_lock); |
| 224 | pm_request_resume(device->dev); | 251 | |
| 252 | list_for_each_entry(pn, &adev->physical_node_list, node) | ||
| 253 | pm_request_resume(pn->dev); | ||
| 254 | |||
| 255 | list_for_each_entry(pn, &adev->power_dependent, node) | ||
| 256 | pm_request_resume(pn->dev); | ||
| 257 | |||
| 258 | mutex_unlock(&adev->physical_node_lock); | ||
| 225 | } | 259 | } |
| 226 | 260 | ||
| 227 | static int __acpi_power_on(struct acpi_power_resource *resource) | 261 | static int __acpi_power_on(struct acpi_power_resource *resource) |
| 228 | { | 262 | { |
| 229 | acpi_status status = AE_OK; | 263 | acpi_status status = AE_OK; |
| 230 | 264 | ||
| 231 | status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL); | 265 | status = acpi_evaluate_object(resource->device.handle, "_ON", NULL, NULL); |
| 232 | if (ACPI_FAILURE(status)) | 266 | if (ACPI_FAILURE(status)) |
| 233 | return -ENODEV; | 267 | return -ENODEV; |
| 234 | 268 | ||
| 235 | /* Update the power resource's _device_ power state */ | ||
| 236 | resource->device->power.state = ACPI_STATE_D0; | ||
| 237 | |||
| 238 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n", | 269 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n", |
| 239 | resource->name)); | 270 | resource->name)); |
| 240 | 271 | ||
| 241 | return 0; | 272 | return 0; |
| 242 | } | 273 | } |
| 243 | 274 | ||
| 244 | static int acpi_power_on(acpi_handle handle) | 275 | static int acpi_power_on(struct acpi_power_resource *resource) |
| 245 | { | 276 | { |
| 246 | int result = 0; | 277 | int result = 0;; |
| 247 | bool resume_device = false; | ||
| 248 | struct acpi_power_resource *resource = NULL; | ||
| 249 | struct acpi_power_resource_device *device_list; | ||
| 250 | |||
| 251 | result = acpi_power_get_context(handle, &resource); | ||
| 252 | if (result) | ||
| 253 | return result; | ||
| 254 | 278 | ||
| 255 | mutex_lock(&resource->resource_lock); | 279 | mutex_lock(&resource->resource_lock); |
| 256 | 280 | ||
| @@ -260,39 +284,38 @@ static int acpi_power_on(acpi_handle handle) | |||
| 260 | resource->name)); | 284 | resource->name)); |
| 261 | } else { | 285 | } else { |
| 262 | result = __acpi_power_on(resource); | 286 | result = __acpi_power_on(resource); |
| 263 | if (result) | 287 | if (result) { |
| 264 | resource->ref_count--; | 288 | resource->ref_count--; |
| 265 | else | 289 | } else { |
| 266 | resume_device = true; | 290 | struct acpi_power_dependent_device *dep; |
| 291 | |||
| 292 | list_for_each_entry(dep, &resource->dependent, node) | ||
| 293 | schedule_work(&dep->work); | ||
| 294 | } | ||
| 267 | } | 295 | } |
| 268 | 296 | ||
| 269 | mutex_unlock(&resource->resource_lock); | 297 | mutex_unlock(&resource->resource_lock); |
| 270 | 298 | ||
| 271 | if (!resume_device) | 299 | return result; |
| 272 | return result; | 300 | } |
| 273 | |||
| 274 | mutex_lock(&resource->devices_lock); | ||
| 275 | 301 | ||
| 276 | device_list = resource->devices; | 302 | static int __acpi_power_off(struct acpi_power_resource *resource) |
| 277 | while (device_list) { | 303 | { |
| 278 | acpi_power_on_device(device_list->device); | 304 | acpi_status status; |
| 279 | device_list = device_list->next; | ||
| 280 | } | ||
| 281 | 305 | ||
| 282 | mutex_unlock(&resource->devices_lock); | 306 | status = acpi_evaluate_object(resource->device.handle, "_OFF", |
| 307 | NULL, NULL); | ||
| 308 | if (ACPI_FAILURE(status)) | ||
| 309 | return -ENODEV; | ||
| 283 | 310 | ||
| 284 | return result; | 311 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned off\n", |
| 312 | resource->name)); | ||
| 313 | return 0; | ||
| 285 | } | 314 | } |
| 286 | 315 | ||
| 287 | static int acpi_power_off(acpi_handle handle) | 316 | static int acpi_power_off(struct acpi_power_resource *resource) |
| 288 | { | 317 | { |
| 289 | int result = 0; | 318 | int result = 0; |
| 290 | acpi_status status = AE_OK; | ||
| 291 | struct acpi_power_resource *resource = NULL; | ||
| 292 | |||
| 293 | result = acpi_power_get_context(handle, &resource); | ||
| 294 | if (result) | ||
| 295 | return result; | ||
| 296 | 319 | ||
| 297 | mutex_lock(&resource->resource_lock); | 320 | mutex_lock(&resource->resource_lock); |
| 298 | 321 | ||
| @@ -307,19 +330,10 @@ static int acpi_power_off(acpi_handle handle) | |||
| 307 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 330 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 308 | "Power resource [%s] still in use\n", | 331 | "Power resource [%s] still in use\n", |
| 309 | resource->name)); | 332 | resource->name)); |
| 310 | goto unlock; | ||
| 311 | } | ||
| 312 | |||
| 313 | status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL); | ||
| 314 | if (ACPI_FAILURE(status)) { | ||
| 315 | result = -ENODEV; | ||
| 316 | } else { | 333 | } else { |
| 317 | /* Update the power resource's _device_ power state */ | 334 | result = __acpi_power_off(resource); |
| 318 | resource->device->power.state = ACPI_STATE_D3; | 335 | if (result) |
| 319 | 336 | resource->ref_count++; | |
| 320 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 321 | "Power resource [%s] turned off\n", | ||
| 322 | resource->name)); | ||
| 323 | } | 337 | } |
| 324 | 338 | ||
| 325 | unlock: | 339 | unlock: |
| @@ -328,148 +342,202 @@ static int acpi_power_off(acpi_handle handle) | |||
| 328 | return result; | 342 | return result; |
| 329 | } | 343 | } |
| 330 | 344 | ||
| 331 | static void __acpi_power_off_list(struct acpi_handle_list *list, int num_res) | 345 | static int acpi_power_off_list(struct list_head *list) |
| 332 | { | 346 | { |
| 333 | int i; | 347 | struct acpi_power_resource_entry *entry; |
| 348 | int result = 0; | ||
| 334 | 349 | ||
| 335 | for (i = num_res - 1; i >= 0 ; i--) | 350 | list_for_each_entry_reverse(entry, list, node) { |
| 336 | acpi_power_off(list->handles[i]); | 351 | result = acpi_power_off(entry->resource); |
| 337 | } | 352 | if (result) |
| 353 | goto err; | ||
| 354 | } | ||
| 355 | return 0; | ||
| 338 | 356 | ||
| 339 | static void acpi_power_off_list(struct acpi_handle_list *list) | 357 | err: |
| 340 | { | 358 | list_for_each_entry_continue(entry, list, node) |
| 341 | __acpi_power_off_list(list, list->count); | 359 | acpi_power_on(entry->resource); |
| 360 | |||
| 361 | return result; | ||
| 342 | } | 362 | } |
| 343 | 363 | ||
| 344 | static int acpi_power_on_list(struct acpi_handle_list *list) | 364 | static int acpi_power_on_list(struct list_head *list) |
| 345 | { | 365 | { |
| 366 | struct acpi_power_resource_entry *entry; | ||
| 346 | int result = 0; | 367 | int result = 0; |
| 347 | int i; | ||
| 348 | 368 | ||
| 349 | for (i = 0; i < list->count; i++) { | 369 | list_for_each_entry(entry, list, node) { |
| 350 | result = acpi_power_on(list->handles[i]); | 370 | result = acpi_power_on(entry->resource); |
| 351 | if (result) { | 371 | if (result) |
| 352 | __acpi_power_off_list(list, i); | 372 | goto err; |
| 353 | break; | ||
| 354 | } | ||
| 355 | } | 373 | } |
| 374 | return 0; | ||
| 375 | |||
| 376 | err: | ||
| 377 | list_for_each_entry_continue_reverse(entry, list, node) | ||
| 378 | acpi_power_off(entry->resource); | ||
| 356 | 379 | ||
| 357 | return result; | 380 | return result; |
| 358 | } | 381 | } |
| 359 | 382 | ||
| 360 | static void __acpi_power_resource_unregister_device(struct device *dev, | 383 | static void acpi_power_add_dependent(struct acpi_power_resource *resource, |
| 361 | acpi_handle res_handle) | 384 | struct acpi_device *adev) |
| 362 | { | 385 | { |
| 363 | struct acpi_power_resource *resource = NULL; | 386 | struct acpi_power_dependent_device *dep; |
| 364 | struct acpi_power_resource_device *prev, *curr; | ||
| 365 | 387 | ||
| 366 | if (acpi_power_get_context(res_handle, &resource)) | 388 | mutex_lock(&resource->resource_lock); |
| 367 | return; | 389 | |
| 390 | list_for_each_entry(dep, &resource->dependent, node) | ||
| 391 | if (dep->adev == adev) | ||
| 392 | goto out; | ||
| 393 | |||
| 394 | dep = kzalloc(sizeof(*dep), GFP_KERNEL); | ||
| 395 | if (!dep) | ||
| 396 | goto out; | ||
| 397 | |||
| 398 | dep->adev = adev; | ||
| 399 | INIT_WORK(&dep->work, acpi_power_resume_dependent); | ||
| 400 | list_add_tail(&dep->node, &resource->dependent); | ||
| 368 | 401 | ||
| 369 | mutex_lock(&resource->devices_lock); | 402 | out: |
| 370 | prev = NULL; | 403 | mutex_unlock(&resource->resource_lock); |
| 371 | curr = resource->devices; | 404 | } |
| 372 | while (curr) { | 405 | |
| 373 | if (curr->device->dev == dev) { | 406 | static void acpi_power_remove_dependent(struct acpi_power_resource *resource, |
| 374 | if (!prev) | 407 | struct acpi_device *adev) |
| 375 | resource->devices = curr->next; | 408 | { |
| 376 | else | 409 | struct acpi_power_dependent_device *dep; |
| 377 | prev->next = curr->next; | 410 | struct work_struct *work = NULL; |
| 378 | 411 | ||
| 379 | kfree(curr); | 412 | mutex_lock(&resource->resource_lock); |
| 413 | |||
| 414 | list_for_each_entry(dep, &resource->dependent, node) | ||
| 415 | if (dep->adev == adev) { | ||
| 416 | list_del(&dep->node); | ||
| 417 | work = &dep->work; | ||
| 380 | break; | 418 | break; |
| 381 | } | 419 | } |
| 382 | 420 | ||
| 383 | prev = curr; | 421 | mutex_unlock(&resource->resource_lock); |
| 384 | curr = curr->next; | 422 | |
| 423 | if (work) { | ||
| 424 | cancel_work_sync(work); | ||
| 425 | kfree(dep); | ||
| 385 | } | 426 | } |
| 386 | mutex_unlock(&resource->devices_lock); | ||
| 387 | } | 427 | } |
| 388 | 428 | ||
| 389 | /* Unlink dev from all power resources in _PR0 */ | 429 | static struct attribute *attrs[] = { |
| 390 | void acpi_power_resource_unregister_device(struct device *dev, acpi_handle handle) | 430 | NULL, |
| 391 | { | 431 | }; |
| 392 | struct acpi_device *acpi_dev; | ||
| 393 | struct acpi_handle_list *list; | ||
| 394 | int i; | ||
| 395 | 432 | ||
| 396 | if (!dev || !handle) | 433 | static struct attribute_group attr_groups[] = { |
| 397 | return; | 434 | [ACPI_STATE_D0] = { |
| 435 | .name = "power_resources_D0", | ||
| 436 | .attrs = attrs, | ||
| 437 | }, | ||
| 438 | [ACPI_STATE_D1] = { | ||
| 439 | .name = "power_resources_D1", | ||
| 440 | .attrs = attrs, | ||
| 441 | }, | ||
| 442 | [ACPI_STATE_D2] = { | ||
| 443 | .name = "power_resources_D2", | ||
| 444 | .attrs = attrs, | ||
| 445 | }, | ||
| 446 | [ACPI_STATE_D3_HOT] = { | ||
| 447 | .name = "power_resources_D3hot", | ||
| 448 | .attrs = attrs, | ||
| 449 | }, | ||
| 450 | }; | ||
| 398 | 451 | ||
| 399 | if (acpi_bus_get_device(handle, &acpi_dev)) | 452 | static void acpi_power_hide_list(struct acpi_device *adev, int state) |
| 453 | { | ||
| 454 | struct acpi_device_power_state *ps = &adev->power.states[state]; | ||
| 455 | struct acpi_power_resource_entry *entry; | ||
| 456 | |||
| 457 | if (list_empty(&ps->resources)) | ||
| 400 | return; | 458 | return; |
| 401 | 459 | ||
| 402 | list = &acpi_dev->power.states[ACPI_STATE_D0].resources; | 460 | list_for_each_entry_reverse(entry, &ps->resources, node) { |
| 461 | struct acpi_device *res_dev = &entry->resource->device; | ||
| 403 | 462 | ||
| 404 | for (i = 0; i < list->count; i++) | 463 | sysfs_remove_link_from_group(&adev->dev.kobj, |
| 405 | __acpi_power_resource_unregister_device(dev, | 464 | attr_groups[state].name, |
| 406 | list->handles[i]); | 465 | dev_name(&res_dev->dev)); |
| 466 | } | ||
| 467 | sysfs_remove_group(&adev->dev.kobj, &attr_groups[state]); | ||
| 407 | } | 468 | } |
| 408 | EXPORT_SYMBOL_GPL(acpi_power_resource_unregister_device); | ||
| 409 | 469 | ||
| 410 | static int __acpi_power_resource_register_device( | 470 | static void acpi_power_expose_list(struct acpi_device *adev, int state) |
| 411 | struct acpi_power_managed_device *powered_device, acpi_handle handle) | ||
| 412 | { | 471 | { |
| 413 | struct acpi_power_resource *resource = NULL; | 472 | struct acpi_device_power_state *ps = &adev->power.states[state]; |
| 414 | struct acpi_power_resource_device *power_resource_device; | 473 | struct acpi_power_resource_entry *entry; |
| 415 | int result; | 474 | int ret; |
| 416 | |||
| 417 | result = acpi_power_get_context(handle, &resource); | ||
| 418 | if (result) | ||
| 419 | return result; | ||
| 420 | 475 | ||
| 421 | power_resource_device = kzalloc( | 476 | if (list_empty(&ps->resources)) |
| 422 | sizeof(*power_resource_device), GFP_KERNEL); | 477 | return; |
| 423 | if (!power_resource_device) | ||
| 424 | return -ENOMEM; | ||
| 425 | 478 | ||
| 426 | power_resource_device->device = powered_device; | 479 | ret = sysfs_create_group(&adev->dev.kobj, &attr_groups[state]); |
| 480 | if (ret) | ||
| 481 | return; | ||
| 427 | 482 | ||
| 428 | mutex_lock(&resource->devices_lock); | 483 | list_for_each_entry(entry, &ps->resources, node) { |
| 429 | power_resource_device->next = resource->devices; | 484 | struct acpi_device *res_dev = &entry->resource->device; |
| 430 | resource->devices = power_resource_device; | ||
| 431 | mutex_unlock(&resource->devices_lock); | ||
| 432 | 485 | ||
| 433 | return 0; | 486 | ret = sysfs_add_link_to_group(&adev->dev.kobj, |
| 487 | attr_groups[state].name, | ||
| 488 | &res_dev->dev.kobj, | ||
| 489 | dev_name(&res_dev->dev)); | ||
| 490 | if (ret) { | ||
| 491 | acpi_power_hide_list(adev, state); | ||
| 492 | break; | ||
| 493 | } | ||
| 494 | } | ||
| 434 | } | 495 | } |
| 435 | 496 | ||
| 436 | /* Link dev to all power resources in _PR0 */ | 497 | void acpi_power_add_remove_device(struct acpi_device *adev, bool add) |
| 437 | int acpi_power_resource_register_device(struct device *dev, acpi_handle handle) | ||
| 438 | { | 498 | { |
| 439 | struct acpi_device *acpi_dev; | 499 | struct acpi_device_power_state *ps; |
| 440 | struct acpi_handle_list *list; | 500 | struct acpi_power_resource_entry *entry; |
| 441 | struct acpi_power_managed_device *powered_device; | 501 | int state; |
| 442 | int i, ret; | ||
| 443 | 502 | ||
| 444 | if (!dev || !handle) | 503 | if (!adev->power.flags.power_resources) |
| 445 | return -ENODEV; | 504 | return; |
| 446 | 505 | ||
| 447 | ret = acpi_bus_get_device(handle, &acpi_dev); | 506 | ps = &adev->power.states[ACPI_STATE_D0]; |
| 448 | if (ret || !acpi_dev->power.flags.power_resources) | 507 | list_for_each_entry(entry, &ps->resources, node) { |
| 449 | return -ENODEV; | 508 | struct acpi_power_resource *resource = entry->resource; |
| 450 | 509 | ||
| 451 | powered_device = kzalloc(sizeof(*powered_device), GFP_KERNEL); | 510 | if (add) |
| 452 | if (!powered_device) | 511 | acpi_power_add_dependent(resource, adev); |
| 453 | return -ENOMEM; | 512 | else |
| 513 | acpi_power_remove_dependent(resource, adev); | ||
| 514 | } | ||
| 454 | 515 | ||
| 455 | powered_device->dev = dev; | 516 | for (state = ACPI_STATE_D0; state <= ACPI_STATE_D3_HOT; state++) { |
| 456 | powered_device->handle = handle; | 517 | if (add) |
| 518 | acpi_power_expose_list(adev, state); | ||
| 519 | else | ||
| 520 | acpi_power_hide_list(adev, state); | ||
| 521 | } | ||
| 522 | } | ||
| 457 | 523 | ||
| 458 | list = &acpi_dev->power.states[ACPI_STATE_D0].resources; | 524 | int acpi_power_min_system_level(struct list_head *list) |
| 525 | { | ||
| 526 | struct acpi_power_resource_entry *entry; | ||
| 527 | int system_level = 5; | ||
| 459 | 528 | ||
| 460 | for (i = 0; i < list->count; i++) { | 529 | list_for_each_entry(entry, list, node) { |
| 461 | ret = __acpi_power_resource_register_device(powered_device, | 530 | struct acpi_power_resource *resource = entry->resource; |
| 462 | list->handles[i]); | ||
| 463 | 531 | ||
| 464 | if (ret) { | 532 | if (system_level > resource->system_level) |
| 465 | acpi_power_resource_unregister_device(dev, handle); | 533 | system_level = resource->system_level; |
| 466 | break; | ||
| 467 | } | ||
| 468 | } | 534 | } |
| 469 | 535 | return system_level; | |
| 470 | return ret; | ||
| 471 | } | 536 | } |
| 472 | EXPORT_SYMBOL_GPL(acpi_power_resource_register_device); | 537 | |
| 538 | /* -------------------------------------------------------------------------- | ||
| 539 | Device Power Management | ||
| 540 | -------------------------------------------------------------------------- */ | ||
| 473 | 541 | ||
| 474 | /** | 542 | /** |
| 475 | * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in | 543 | * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in |
| @@ -542,7 +610,7 @@ int acpi_device_sleep_wake(struct acpi_device *dev, | |||
| 542 | */ | 610 | */ |
| 543 | int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) | 611 | int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) |
| 544 | { | 612 | { |
| 545 | int i, err = 0; | 613 | int err = 0; |
| 546 | 614 | ||
| 547 | if (!dev || !dev->wakeup.flags.valid) | 615 | if (!dev || !dev->wakeup.flags.valid) |
| 548 | return -EINVAL; | 616 | return -EINVAL; |
| @@ -552,24 +620,17 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) | |||
| 552 | if (dev->wakeup.prepare_count++) | 620 | if (dev->wakeup.prepare_count++) |
| 553 | goto out; | 621 | goto out; |
| 554 | 622 | ||
| 555 | /* Open power resource */ | 623 | err = acpi_power_on_list(&dev->wakeup.resources); |
| 556 | for (i = 0; i < dev->wakeup.resources.count; i++) { | 624 | if (err) { |
| 557 | int ret = acpi_power_on(dev->wakeup.resources.handles[i]); | 625 | dev_err(&dev->dev, "Cannot turn wakeup power resources on\n"); |
| 558 | if (ret) { | 626 | dev->wakeup.flags.valid = 0; |
| 559 | printk(KERN_ERR PREFIX "Transition power state\n"); | 627 | } else { |
| 560 | dev->wakeup.flags.valid = 0; | 628 | /* |
| 561 | err = -ENODEV; | 629 | * Passing 3 as the third argument below means the device may be |
| 562 | goto err_out; | 630 | * put into arbitrary power state afterward. |
| 563 | } | 631 | */ |
| 632 | err = acpi_device_sleep_wake(dev, 1, sleep_state, 3); | ||
| 564 | } | 633 | } |
| 565 | |||
| 566 | /* | ||
| 567 | * Passing 3 as the third argument below means the device may be placed | ||
| 568 | * in arbitrary power state afterwards. | ||
| 569 | */ | ||
| 570 | err = acpi_device_sleep_wake(dev, 1, sleep_state, 3); | ||
| 571 | |||
| 572 | err_out: | ||
| 573 | if (err) | 634 | if (err) |
| 574 | dev->wakeup.prepare_count = 0; | 635 | dev->wakeup.prepare_count = 0; |
| 575 | 636 | ||
| @@ -586,7 +647,7 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) | |||
| 586 | */ | 647 | */ |
| 587 | int acpi_disable_wakeup_device_power(struct acpi_device *dev) | 648 | int acpi_disable_wakeup_device_power(struct acpi_device *dev) |
| 588 | { | 649 | { |
| 589 | int i, err = 0; | 650 | int err = 0; |
| 590 | 651 | ||
| 591 | if (!dev || !dev->wakeup.flags.valid) | 652 | if (!dev || !dev->wakeup.flags.valid) |
| 592 | return -EINVAL; | 653 | return -EINVAL; |
| @@ -607,15 +668,10 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev) | |||
| 607 | if (err) | 668 | if (err) |
| 608 | goto out; | 669 | goto out; |
| 609 | 670 | ||
| 610 | /* Close power resource */ | 671 | err = acpi_power_off_list(&dev->wakeup.resources); |
| 611 | for (i = 0; i < dev->wakeup.resources.count; i++) { | 672 | if (err) { |
| 612 | int ret = acpi_power_off(dev->wakeup.resources.handles[i]); | 673 | dev_err(&dev->dev, "Cannot turn wakeup power resources off\n"); |
| 613 | if (ret) { | 674 | dev->wakeup.flags.valid = 0; |
| 614 | printk(KERN_ERR PREFIX "Transition power state\n"); | ||
| 615 | dev->wakeup.flags.valid = 0; | ||
| 616 | err = -ENODEV; | ||
| 617 | goto out; | ||
| 618 | } | ||
| 619 | } | 675 | } |
| 620 | 676 | ||
| 621 | out: | 677 | out: |
| @@ -623,14 +679,9 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev) | |||
| 623 | return err; | 679 | return err; |
| 624 | } | 680 | } |
| 625 | 681 | ||
| 626 | /* -------------------------------------------------------------------------- | ||
| 627 | Device Power Management | ||
| 628 | -------------------------------------------------------------------------- */ | ||
| 629 | |||
| 630 | int acpi_power_get_inferred_state(struct acpi_device *device, int *state) | 682 | int acpi_power_get_inferred_state(struct acpi_device *device, int *state) |
| 631 | { | 683 | { |
| 632 | int result = 0; | 684 | int result = 0; |
| 633 | struct acpi_handle_list *list = NULL; | ||
| 634 | int list_state = 0; | 685 | int list_state = 0; |
| 635 | int i = 0; | 686 | int i = 0; |
| 636 | 687 | ||
| @@ -642,8 +693,9 @@ int acpi_power_get_inferred_state(struct acpi_device *device, int *state) | |||
| 642 | * required for a given D-state are 'on'. | 693 | * required for a given D-state are 'on'. |
| 643 | */ | 694 | */ |
| 644 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { | 695 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { |
| 645 | list = &device->power.states[i].resources; | 696 | struct list_head *list = &device->power.states[i].resources; |
| 646 | if (list->count < 1) | 697 | |
| 698 | if (list_empty(list)) | ||
| 647 | continue; | 699 | continue; |
| 648 | 700 | ||
| 649 | result = acpi_power_get_list_state(list, &list_state); | 701 | result = acpi_power_get_list_state(list, &list_state); |
| @@ -662,7 +714,7 @@ int acpi_power_get_inferred_state(struct acpi_device *device, int *state) | |||
| 662 | 714 | ||
| 663 | int acpi_power_on_resources(struct acpi_device *device, int state) | 715 | int acpi_power_on_resources(struct acpi_device *device, int state) |
| 664 | { | 716 | { |
| 665 | if (!device || state < ACPI_STATE_D0 || state > ACPI_STATE_D3) | 717 | if (!device || state < ACPI_STATE_D0 || state > ACPI_STATE_D3_HOT) |
| 666 | return -EINVAL; | 718 | return -EINVAL; |
| 667 | 719 | ||
| 668 | return acpi_power_on_list(&device->power.states[state].resources); | 720 | return acpi_power_on_list(&device->power.states[state].resources); |
| @@ -675,7 +727,7 @@ int acpi_power_transition(struct acpi_device *device, int state) | |||
| 675 | if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD)) | 727 | if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD)) |
| 676 | return -EINVAL; | 728 | return -EINVAL; |
| 677 | 729 | ||
| 678 | if (device->power.state == state) | 730 | if (device->power.state == state || !device->flags.power_manageable) |
| 679 | return 0; | 731 | return 0; |
| 680 | 732 | ||
| 681 | if ((device->power.state < ACPI_STATE_D0) | 733 | if ((device->power.state < ACPI_STATE_D0) |
| @@ -703,118 +755,126 @@ int acpi_power_transition(struct acpi_device *device, int state) | |||
| 703 | return result; | 755 | return result; |
| 704 | } | 756 | } |
| 705 | 757 | ||
| 706 | /* -------------------------------------------------------------------------- | 758 | static void acpi_release_power_resource(struct device *dev) |
| 707 | Driver Interface | 759 | { |
| 708 | -------------------------------------------------------------------------- */ | 760 | struct acpi_device *device = to_acpi_device(dev); |
| 761 | struct acpi_power_resource *resource; | ||
| 762 | |||
| 763 | resource = container_of(device, struct acpi_power_resource, device); | ||
| 764 | |||
| 765 | mutex_lock(&power_resource_list_lock); | ||
| 766 | list_del(&resource->list_node); | ||
| 767 | mutex_unlock(&power_resource_list_lock); | ||
| 768 | |||
| 769 | acpi_free_ids(device); | ||
| 770 | kfree(resource); | ||
| 771 | } | ||
| 709 | 772 | ||
| 710 | static int acpi_power_add(struct acpi_device *device) | 773 | static ssize_t acpi_power_in_use_show(struct device *dev, |
| 774 | struct device_attribute *attr, | ||
| 775 | char *buf) { | ||
| 776 | struct acpi_power_resource *resource; | ||
| 777 | |||
| 778 | resource = to_power_resource(to_acpi_device(dev)); | ||
| 779 | return sprintf(buf, "%u\n", !!resource->ref_count); | ||
| 780 | } | ||
| 781 | static DEVICE_ATTR(resource_in_use, 0444, acpi_power_in_use_show, NULL); | ||
| 782 | |||
| 783 | static void acpi_power_sysfs_remove(struct acpi_device *device) | ||
| 711 | { | 784 | { |
| 712 | int result = 0, state; | 785 | device_remove_file(&device->dev, &dev_attr_resource_in_use); |
| 713 | acpi_status status = AE_OK; | 786 | } |
| 714 | struct acpi_power_resource *resource = NULL; | 787 | |
| 788 | int acpi_add_power_resource(acpi_handle handle) | ||
| 789 | { | ||
| 790 | struct acpi_power_resource *resource; | ||
| 791 | struct acpi_device *device = NULL; | ||
| 715 | union acpi_object acpi_object; | 792 | union acpi_object acpi_object; |
| 716 | struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object }; | 793 | struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object }; |
| 794 | acpi_status status; | ||
| 795 | int state, result = -ENODEV; | ||
| 717 | 796 | ||
| 797 | acpi_bus_get_device(handle, &device); | ||
| 798 | if (device) | ||
| 799 | return 0; | ||
| 718 | 800 | ||
| 719 | if (!device) | 801 | resource = kzalloc(sizeof(*resource), GFP_KERNEL); |
| 720 | return -EINVAL; | ||
| 721 | |||
| 722 | resource = kzalloc(sizeof(struct acpi_power_resource), GFP_KERNEL); | ||
| 723 | if (!resource) | 802 | if (!resource) |
| 724 | return -ENOMEM; | 803 | return -ENOMEM; |
| 725 | 804 | ||
| 726 | resource->device = device; | 805 | device = &resource->device; |
| 806 | acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER, | ||
| 807 | ACPI_STA_DEFAULT); | ||
| 727 | mutex_init(&resource->resource_lock); | 808 | mutex_init(&resource->resource_lock); |
| 728 | mutex_init(&resource->devices_lock); | 809 | INIT_LIST_HEAD(&resource->dependent); |
| 729 | strcpy(resource->name, device->pnp.bus_id); | 810 | resource->name = device->pnp.bus_id; |
| 730 | strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); | 811 | strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); |
| 731 | strcpy(acpi_device_class(device), ACPI_POWER_CLASS); | 812 | strcpy(acpi_device_class(device), ACPI_POWER_CLASS); |
| 732 | device->driver_data = resource; | 813 | device->power.state = ACPI_STATE_UNKNOWN; |
| 733 | 814 | ||
| 734 | /* Evalute the object to get the system level and resource order. */ | 815 | /* Evalute the object to get the system level and resource order. */ |
| 735 | status = acpi_evaluate_object(device->handle, NULL, NULL, &buffer); | 816 | status = acpi_evaluate_object(handle, NULL, NULL, &buffer); |
| 736 | if (ACPI_FAILURE(status)) { | 817 | if (ACPI_FAILURE(status)) |
| 737 | result = -ENODEV; | 818 | goto err; |
| 738 | goto end; | 819 | |
| 739 | } | ||
| 740 | resource->system_level = acpi_object.power_resource.system_level; | 820 | resource->system_level = acpi_object.power_resource.system_level; |
| 741 | resource->order = acpi_object.power_resource.resource_order; | 821 | resource->order = acpi_object.power_resource.resource_order; |
| 742 | 822 | ||
| 743 | result = acpi_power_get_state(device->handle, &state); | 823 | result = acpi_power_get_state(handle, &state); |
| 744 | if (result) | 824 | if (result) |
| 745 | goto end; | 825 | goto err; |
| 746 | |||
| 747 | switch (state) { | ||
| 748 | case ACPI_POWER_RESOURCE_STATE_ON: | ||
| 749 | device->power.state = ACPI_STATE_D0; | ||
| 750 | break; | ||
| 751 | case ACPI_POWER_RESOURCE_STATE_OFF: | ||
| 752 | device->power.state = ACPI_STATE_D3; | ||
| 753 | break; | ||
| 754 | default: | ||
| 755 | device->power.state = ACPI_STATE_UNKNOWN; | ||
| 756 | break; | ||
| 757 | } | ||
| 758 | 826 | ||
| 759 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), | 827 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), |
| 760 | acpi_device_bid(device), state ? "on" : "off"); | 828 | acpi_device_bid(device), state ? "on" : "off"); |
| 761 | 829 | ||
| 762 | end: | 830 | device->flags.match_driver = true; |
| 831 | result = acpi_device_add(device, acpi_release_power_resource); | ||
| 763 | if (result) | 832 | if (result) |
| 764 | kfree(resource); | 833 | goto err; |
| 765 | 834 | ||
| 766 | return result; | 835 | if (!device_create_file(&device->dev, &dev_attr_resource_in_use)) |
| 767 | } | 836 | device->remove = acpi_power_sysfs_remove; |
| 768 | |||
| 769 | static int acpi_power_remove(struct acpi_device *device, int type) | ||
| 770 | { | ||
| 771 | struct acpi_power_resource *resource; | ||
| 772 | |||
| 773 | if (!device) | ||
| 774 | return -EINVAL; | ||
| 775 | |||
| 776 | resource = acpi_driver_data(device); | ||
| 777 | if (!resource) | ||
| 778 | return -EINVAL; | ||
| 779 | |||
| 780 | kfree(resource); | ||
| 781 | 837 | ||
| 838 | mutex_lock(&power_resource_list_lock); | ||
| 839 | list_add(&resource->list_node, &acpi_power_resource_list); | ||
| 840 | mutex_unlock(&power_resource_list_lock); | ||
| 841 | acpi_device_add_finalize(device); | ||
| 782 | return 0; | 842 | return 0; |
| 843 | |||
| 844 | err: | ||
| 845 | acpi_release_power_resource(&device->dev); | ||
| 846 | return result; | ||
| 783 | } | 847 | } |
| 784 | 848 | ||
| 785 | #ifdef CONFIG_PM_SLEEP | 849 | #ifdef CONFIG_ACPI_SLEEP |
| 786 | static int acpi_power_resume(struct device *dev) | 850 | void acpi_resume_power_resources(void) |
| 787 | { | 851 | { |
| 788 | int result = 0, state; | ||
| 789 | struct acpi_device *device; | ||
| 790 | struct acpi_power_resource *resource; | 852 | struct acpi_power_resource *resource; |
| 791 | 853 | ||
| 792 | if (!dev) | 854 | mutex_lock(&power_resource_list_lock); |
| 793 | return -EINVAL; | ||
| 794 | 855 | ||
| 795 | device = to_acpi_device(dev); | 856 | list_for_each_entry(resource, &acpi_power_resource_list, list_node) { |
| 796 | resource = acpi_driver_data(device); | 857 | int result, state; |
| 797 | if (!resource) | ||
| 798 | return -EINVAL; | ||
| 799 | 858 | ||
| 800 | mutex_lock(&resource->resource_lock); | 859 | mutex_lock(&resource->resource_lock); |
| 801 | 860 | ||
| 802 | result = acpi_power_get_state(device->handle, &state); | 861 | result = acpi_power_get_state(resource->device.handle, &state); |
| 803 | if (result) | 862 | if (result) |
| 804 | goto unlock; | 863 | continue; |
| 805 | 864 | ||
| 806 | if (state == ACPI_POWER_RESOURCE_STATE_OFF && resource->ref_count) | 865 | if (state == ACPI_POWER_RESOURCE_STATE_OFF |
| 807 | result = __acpi_power_on(resource); | 866 | && resource->ref_count) { |
| 867 | dev_info(&resource->device.dev, "Turning ON\n"); | ||
| 868 | __acpi_power_on(resource); | ||
| 869 | } else if (state == ACPI_POWER_RESOURCE_STATE_ON | ||
| 870 | && !resource->ref_count) { | ||
| 871 | dev_info(&resource->device.dev, "Turning OFF\n"); | ||
| 872 | __acpi_power_off(resource); | ||
| 873 | } | ||
| 808 | 874 | ||
| 809 | unlock: | 875 | mutex_unlock(&resource->resource_lock); |
| 810 | mutex_unlock(&resource->resource_lock); | 876 | } |
| 811 | 877 | ||
| 812 | return result; | 878 | mutex_unlock(&power_resource_list_lock); |
| 813 | } | 879 | } |
| 814 | #endif | 880 | #endif |
| 815 | |||
| 816 | int __init acpi_power_init(void) | ||
| 817 | { | ||
| 818 | INIT_LIST_HEAD(&acpi_power_resource_list); | ||
| 819 | return acpi_bus_register_driver(&acpi_power_driver); | ||
| 820 | } | ||
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c index ef98796b3824..52ce76725c20 100644 --- a/drivers/acpi/proc.c +++ b/drivers/acpi/proc.c | |||
| @@ -311,11 +311,12 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | |||
| 311 | dev->pnp.bus_id, | 311 | dev->pnp.bus_id, |
| 312 | (u32) dev->wakeup.sleep_state); | 312 | (u32) dev->wakeup.sleep_state); |
| 313 | 313 | ||
| 314 | if (!dev->physical_node_count) | 314 | if (!dev->physical_node_count) { |
| 315 | seq_printf(seq, "%c%-8s\n", | 315 | seq_printf(seq, "%c%-8s\n", |
| 316 | dev->wakeup.flags.run_wake ? | 316 | dev->wakeup.flags.run_wake ? '*' : ' ', |
| 317 | '*' : ' ', "disabled"); | 317 | device_may_wakeup(&dev->dev) ? |
| 318 | else { | 318 | "enabled" : "disabled"); |
| 319 | } else { | ||
| 319 | struct device *ldev; | 320 | struct device *ldev; |
| 320 | list_for_each_entry(entry, &dev->physical_node_list, | 321 | list_for_each_entry(entry, &dev->physical_node_list, |
| 321 | node) { | 322 | node) { |
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 83fe3bf4cdc8..cbf6e7729c39 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
| @@ -174,6 +174,32 @@ err_out: | |||
| 174 | } | 174 | } |
| 175 | EXPORT_SYMBOL(acpi_bus_hot_remove_device); | 175 | EXPORT_SYMBOL(acpi_bus_hot_remove_device); |
| 176 | 176 | ||
| 177 | static ssize_t real_power_state_show(struct device *dev, | ||
| 178 | struct device_attribute *attr, char *buf) | ||
| 179 | { | ||
| 180 | struct acpi_device *adev = to_acpi_device(dev); | ||
| 181 | int state; | ||
| 182 | int ret; | ||
| 183 | |||
| 184 | ret = acpi_device_get_power(adev, &state); | ||
| 185 | if (ret) | ||
| 186 | return ret; | ||
| 187 | |||
| 188 | return sprintf(buf, "%s\n", acpi_power_state_string(state)); | ||
| 189 | } | ||
| 190 | |||
| 191 | static DEVICE_ATTR(real_power_state, 0444, real_power_state_show, NULL); | ||
| 192 | |||
| 193 | static ssize_t power_state_show(struct device *dev, | ||
| 194 | struct device_attribute *attr, char *buf) | ||
| 195 | { | ||
| 196 | struct acpi_device *adev = to_acpi_device(dev); | ||
| 197 | |||
| 198 | return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state)); | ||
| 199 | } | ||
| 200 | |||
| 201 | static DEVICE_ATTR(power_state, 0444, power_state_show, NULL); | ||
| 202 | |||
| 177 | static ssize_t | 203 | static ssize_t |
| 178 | acpi_eject_store(struct device *d, struct device_attribute *attr, | 204 | acpi_eject_store(struct device *d, struct device_attribute *attr, |
| 179 | const char *buf, size_t count) | 205 | const char *buf, size_t count) |
| @@ -365,8 +391,22 @@ static int acpi_device_setup_files(struct acpi_device *dev) | |||
| 365 | * hot-removal function from userland. | 391 | * hot-removal function from userland. |
| 366 | */ | 392 | */ |
| 367 | status = acpi_get_handle(dev->handle, "_EJ0", &temp); | 393 | status = acpi_get_handle(dev->handle, "_EJ0", &temp); |
| 368 | if (ACPI_SUCCESS(status)) | 394 | if (ACPI_SUCCESS(status)) { |
| 369 | result = device_create_file(&dev->dev, &dev_attr_eject); | 395 | result = device_create_file(&dev->dev, &dev_attr_eject); |
| 396 | if (result) | ||
| 397 | return result; | ||
| 398 | } | ||
| 399 | |||
| 400 | if (dev->flags.power_manageable) { | ||
| 401 | result = device_create_file(&dev->dev, &dev_attr_power_state); | ||
| 402 | if (result) | ||
| 403 | return result; | ||
| 404 | |||
| 405 | if (dev->power.flags.power_resources) | ||
| 406 | result = device_create_file(&dev->dev, | ||
| 407 | &dev_attr_real_power_state); | ||
| 408 | } | ||
| 409 | |||
| 370 | end: | 410 | end: |
| 371 | return result; | 411 | return result; |
| 372 | } | 412 | } |
| @@ -376,6 +416,13 @@ static void acpi_device_remove_files(struct acpi_device *dev) | |||
| 376 | acpi_status status; | 416 | acpi_status status; |
| 377 | acpi_handle temp; | 417 | acpi_handle temp; |
| 378 | 418 | ||
| 419 | if (dev->flags.power_manageable) { | ||
| 420 | device_remove_file(&dev->dev, &dev_attr_power_state); | ||
| 421 | if (dev->power.flags.power_resources) | ||
| 422 | device_remove_file(&dev->dev, | ||
| 423 | &dev_attr_real_power_state); | ||
| 424 | } | ||
| 425 | |||
| 379 | /* | 426 | /* |
| 380 | * If device has _STR, remove 'description' file | 427 | * If device has _STR, remove 'description' file |
| 381 | */ | 428 | */ |
| @@ -460,7 +507,7 @@ int acpi_match_device_ids(struct acpi_device *device, | |||
| 460 | } | 507 | } |
| 461 | EXPORT_SYMBOL(acpi_match_device_ids); | 508 | EXPORT_SYMBOL(acpi_match_device_ids); |
| 462 | 509 | ||
| 463 | static void acpi_free_ids(struct acpi_device *device) | 510 | void acpi_free_ids(struct acpi_device *device) |
| 464 | { | 511 | { |
| 465 | struct acpi_hardware_id *id, *tmp; | 512 | struct acpi_hardware_id *id, *tmp; |
| 466 | 513 | ||
| @@ -468,6 +515,23 @@ static void acpi_free_ids(struct acpi_device *device) | |||
| 468 | kfree(id->id); | 515 | kfree(id->id); |
| 469 | kfree(id); | 516 | kfree(id); |
| 470 | } | 517 | } |
| 518 | kfree(device->pnp.unique_id); | ||
| 519 | } | ||
| 520 | |||
| 521 | static void acpi_free_power_resources_lists(struct acpi_device *device) | ||
| 522 | { | ||
| 523 | int i; | ||
| 524 | |||
| 525 | if (device->wakeup.flags.valid) | ||
| 526 | acpi_power_resources_list_free(&device->wakeup.resources); | ||
| 527 | |||
| 528 | if (!device->flags.power_manageable) | ||
| 529 | return; | ||
| 530 | |||
| 531 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { | ||
| 532 | struct acpi_device_power_state *ps = &device->power.states[i]; | ||
| 533 | acpi_power_resources_list_free(&ps->resources); | ||
| 534 | } | ||
| 471 | } | 535 | } |
| 472 | 536 | ||
| 473 | static void acpi_device_release(struct device *dev) | 537 | static void acpi_device_release(struct device *dev) |
| @@ -475,7 +539,7 @@ static void acpi_device_release(struct device *dev) | |||
| 475 | struct acpi_device *acpi_dev = to_acpi_device(dev); | 539 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
| 476 | 540 | ||
| 477 | acpi_free_ids(acpi_dev); | 541 | acpi_free_ids(acpi_dev); |
| 478 | kfree(acpi_dev->pnp.unique_id); | 542 | acpi_free_power_resources_lists(acpi_dev); |
| 479 | kfree(acpi_dev); | 543 | kfree(acpi_dev); |
| 480 | } | 544 | } |
| 481 | 545 | ||
| @@ -613,12 +677,25 @@ struct bus_type acpi_bus_type = { | |||
| 613 | .uevent = acpi_device_uevent, | 677 | .uevent = acpi_device_uevent, |
| 614 | }; | 678 | }; |
| 615 | 679 | ||
| 616 | static int acpi_device_register(struct acpi_device *device) | 680 | int acpi_device_add(struct acpi_device *device, |
| 681 | void (*release)(struct device *)) | ||
| 617 | { | 682 | { |
| 618 | int result; | 683 | int result; |
| 619 | struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; | 684 | struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; |
| 620 | int found = 0; | 685 | int found = 0; |
| 621 | 686 | ||
| 687 | if (device->handle) { | ||
| 688 | acpi_status status; | ||
| 689 | |||
| 690 | status = acpi_attach_data(device->handle, acpi_bus_data_handler, | ||
| 691 | device); | ||
| 692 | if (ACPI_FAILURE(status)) { | ||
| 693 | acpi_handle_err(device->handle, | ||
| 694 | "Unable to attach device data\n"); | ||
| 695 | return -ENODEV; | ||
| 696 | } | ||
| 697 | } | ||
| 698 | |||
| 622 | /* | 699 | /* |
| 623 | * Linkage | 700 | * Linkage |
| 624 | * ------- | 701 | * ------- |
| @@ -629,11 +706,13 @@ static int acpi_device_register(struct acpi_device *device) | |||
| 629 | INIT_LIST_HEAD(&device->wakeup_list); | 706 | INIT_LIST_HEAD(&device->wakeup_list); |
| 630 | INIT_LIST_HEAD(&device->physical_node_list); | 707 | INIT_LIST_HEAD(&device->physical_node_list); |
| 631 | mutex_init(&device->physical_node_lock); | 708 | mutex_init(&device->physical_node_lock); |
| 709 | INIT_LIST_HEAD(&device->power_dependent); | ||
| 632 | 710 | ||
| 633 | new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); | 711 | new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); |
| 634 | if (!new_bus_id) { | 712 | if (!new_bus_id) { |
| 635 | printk(KERN_ERR PREFIX "Memory allocation error\n"); | 713 | pr_err(PREFIX "Memory allocation error\n"); |
| 636 | return -ENOMEM; | 714 | result = -ENOMEM; |
| 715 | goto err_detach; | ||
| 637 | } | 716 | } |
| 638 | 717 | ||
| 639 | mutex_lock(&acpi_device_lock); | 718 | mutex_lock(&acpi_device_lock); |
| @@ -668,11 +747,11 @@ static int acpi_device_register(struct acpi_device *device) | |||
| 668 | if (device->parent) | 747 | if (device->parent) |
| 669 | device->dev.parent = &device->parent->dev; | 748 | device->dev.parent = &device->parent->dev; |
| 670 | device->dev.bus = &acpi_bus_type; | 749 | device->dev.bus = &acpi_bus_type; |
| 671 | device->dev.release = &acpi_device_release; | 750 | device->dev.release = release; |
| 672 | result = device_register(&device->dev); | 751 | result = device_add(&device->dev); |
| 673 | if (result) { | 752 | if (result) { |
| 674 | dev_err(&device->dev, "Error registering device\n"); | 753 | dev_err(&device->dev, "Error registering device\n"); |
| 675 | goto end; | 754 | goto err; |
| 676 | } | 755 | } |
| 677 | 756 | ||
| 678 | result = acpi_device_setup_files(device); | 757 | result = acpi_device_setup_files(device); |
| @@ -682,12 +761,16 @@ static int acpi_device_register(struct acpi_device *device) | |||
| 682 | 761 | ||
| 683 | device->removal_type = ACPI_BUS_REMOVAL_NORMAL; | 762 | device->removal_type = ACPI_BUS_REMOVAL_NORMAL; |
| 684 | return 0; | 763 | return 0; |
| 685 | end: | 764 | |
| 765 | err: | ||
| 686 | mutex_lock(&acpi_device_lock); | 766 | mutex_lock(&acpi_device_lock); |
| 687 | if (device->parent) | 767 | if (device->parent) |
| 688 | list_del(&device->node); | 768 | list_del(&device->node); |
| 689 | list_del(&device->wakeup_list); | 769 | list_del(&device->wakeup_list); |
| 690 | mutex_unlock(&acpi_device_lock); | 770 | mutex_unlock(&acpi_device_lock); |
| 771 | |||
| 772 | err_detach: | ||
| 773 | acpi_detach_data(device->handle, acpi_bus_data_handler); | ||
| 691 | return result; | 774 | return result; |
| 692 | } | 775 | } |
| 693 | 776 | ||
| @@ -702,8 +785,18 @@ static void acpi_device_unregister(struct acpi_device *device) | |||
| 702 | 785 | ||
| 703 | acpi_detach_data(device->handle, acpi_bus_data_handler); | 786 | acpi_detach_data(device->handle, acpi_bus_data_handler); |
| 704 | 787 | ||
| 788 | acpi_power_add_remove_device(device, false); | ||
| 705 | acpi_device_remove_files(device); | 789 | acpi_device_remove_files(device); |
| 706 | device_unregister(&device->dev); | 790 | if (device->remove) |
| 791 | device->remove(device); | ||
| 792 | |||
| 793 | device_del(&device->dev); | ||
| 794 | /* | ||
| 795 | * Drop the reference counts of all power resources the device depends | ||
| 796 | * on and turn off the ones that have no more references. | ||
| 797 | */ | ||
| 798 | acpi_power_transition(device, ACPI_STATE_D3_COLD); | ||
| 799 | put_device(&device->dev); | ||
| 707 | } | 800 | } |
| 708 | 801 | ||
| 709 | /* -------------------------------------------------------------------------- | 802 | /* -------------------------------------------------------------------------- |
| @@ -846,52 +939,43 @@ void acpi_bus_data_handler(acpi_handle handle, void *context) | |||
| 846 | return; | 939 | return; |
| 847 | } | 940 | } |
| 848 | 941 | ||
| 849 | static int acpi_bus_get_perf_flags(struct acpi_device *device) | 942 | static int acpi_bus_extract_wakeup_device_power_package(acpi_handle handle, |
| 850 | { | 943 | struct acpi_device_wakeup *wakeup) |
| 851 | device->performance.state = ACPI_STATE_UNKNOWN; | ||
| 852 | return 0; | ||
| 853 | } | ||
| 854 | |||
| 855 | static acpi_status | ||
| 856 | acpi_bus_extract_wakeup_device_power_package(acpi_handle handle, | ||
| 857 | struct acpi_device_wakeup *wakeup) | ||
| 858 | { | 944 | { |
| 859 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 945 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 860 | union acpi_object *package = NULL; | 946 | union acpi_object *package = NULL; |
| 861 | union acpi_object *element = NULL; | 947 | union acpi_object *element = NULL; |
| 862 | acpi_status status; | 948 | acpi_status status; |
| 863 | int i = 0; | 949 | int err = -ENODATA; |
| 864 | 950 | ||
| 865 | if (!wakeup) | 951 | if (!wakeup) |
| 866 | return AE_BAD_PARAMETER; | 952 | return -EINVAL; |
| 953 | |||
| 954 | INIT_LIST_HEAD(&wakeup->resources); | ||
| 867 | 955 | ||
| 868 | /* _PRW */ | 956 | /* _PRW */ |
| 869 | status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer); | 957 | status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer); |
| 870 | if (ACPI_FAILURE(status)) { | 958 | if (ACPI_FAILURE(status)) { |
| 871 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW")); | 959 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW")); |
| 872 | return status; | 960 | return err; |
| 873 | } | 961 | } |
| 874 | 962 | ||
| 875 | package = (union acpi_object *)buffer.pointer; | 963 | package = (union acpi_object *)buffer.pointer; |
| 876 | 964 | ||
| 877 | if (!package || (package->package.count < 2)) { | 965 | if (!package || package->package.count < 2) |
| 878 | status = AE_BAD_DATA; | ||
| 879 | goto out; | 966 | goto out; |
| 880 | } | ||
| 881 | 967 | ||
| 882 | element = &(package->package.elements[0]); | 968 | element = &(package->package.elements[0]); |
| 883 | if (!element) { | 969 | if (!element) |
| 884 | status = AE_BAD_DATA; | ||
| 885 | goto out; | 970 | goto out; |
| 886 | } | 971 | |
| 887 | if (element->type == ACPI_TYPE_PACKAGE) { | 972 | if (element->type == ACPI_TYPE_PACKAGE) { |
| 888 | if ((element->package.count < 2) || | 973 | if ((element->package.count < 2) || |
| 889 | (element->package.elements[0].type != | 974 | (element->package.elements[0].type != |
| 890 | ACPI_TYPE_LOCAL_REFERENCE) | 975 | ACPI_TYPE_LOCAL_REFERENCE) |
| 891 | || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) { | 976 | || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) |
| 892 | status = AE_BAD_DATA; | ||
| 893 | goto out; | 977 | goto out; |
| 894 | } | 978 | |
| 895 | wakeup->gpe_device = | 979 | wakeup->gpe_device = |
| 896 | element->package.elements[0].reference.handle; | 980 | element->package.elements[0].reference.handle; |
| 897 | wakeup->gpe_number = | 981 | wakeup->gpe_number = |
| @@ -900,38 +984,35 @@ acpi_bus_extract_wakeup_device_power_package(acpi_handle handle, | |||
| 900 | wakeup->gpe_device = NULL; | 984 | wakeup->gpe_device = NULL; |
| 901 | wakeup->gpe_number = element->integer.value; | 985 | wakeup->gpe_number = element->integer.value; |
| 902 | } else { | 986 | } else { |
| 903 | status = AE_BAD_DATA; | ||
| 904 | goto out; | 987 | goto out; |
| 905 | } | 988 | } |
| 906 | 989 | ||
| 907 | element = &(package->package.elements[1]); | 990 | element = &(package->package.elements[1]); |
| 908 | if (element->type != ACPI_TYPE_INTEGER) { | 991 | if (element->type != ACPI_TYPE_INTEGER) |
| 909 | status = AE_BAD_DATA; | ||
| 910 | goto out; | 992 | goto out; |
| 911 | } | 993 | |
| 912 | wakeup->sleep_state = element->integer.value; | 994 | wakeup->sleep_state = element->integer.value; |
| 913 | 995 | ||
| 914 | if ((package->package.count - 2) > ACPI_MAX_HANDLES) { | 996 | err = acpi_extract_power_resources(package, 2, &wakeup->resources); |
| 915 | status = AE_NO_MEMORY; | 997 | if (err) |
| 916 | goto out; | 998 | goto out; |
| 917 | } | ||
| 918 | wakeup->resources.count = package->package.count - 2; | ||
| 919 | for (i = 0; i < wakeup->resources.count; i++) { | ||
| 920 | element = &(package->package.elements[i + 2]); | ||
| 921 | if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { | ||
| 922 | status = AE_BAD_DATA; | ||
| 923 | goto out; | ||
| 924 | } | ||
| 925 | 999 | ||
| 926 | wakeup->resources.handles[i] = element->reference.handle; | 1000 | if (!list_empty(&wakeup->resources)) { |
| 927 | } | 1001 | int sleep_state; |
| 928 | 1002 | ||
| 1003 | sleep_state = acpi_power_min_system_level(&wakeup->resources); | ||
| 1004 | if (sleep_state < wakeup->sleep_state) { | ||
| 1005 | acpi_handle_warn(handle, "Overriding _PRW sleep state " | ||
| 1006 | "(S%d) by S%d from power resources\n", | ||
| 1007 | (int)wakeup->sleep_state, sleep_state); | ||
| 1008 | wakeup->sleep_state = sleep_state; | ||
| 1009 | } | ||
| 1010 | } | ||
| 929 | acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number); | 1011 | acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number); |
| 930 | 1012 | ||
| 931 | out: | 1013 | out: |
| 932 | kfree(buffer.pointer); | 1014 | kfree(buffer.pointer); |
| 933 | 1015 | return err; | |
| 934 | return status; | ||
| 935 | } | 1016 | } |
| 936 | 1017 | ||
| 937 | static void acpi_bus_set_run_wake_flags(struct acpi_device *device) | 1018 | static void acpi_bus_set_run_wake_flags(struct acpi_device *device) |
| @@ -971,17 +1052,17 @@ static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
| 971 | { | 1052 | { |
| 972 | acpi_handle temp; | 1053 | acpi_handle temp; |
| 973 | acpi_status status = 0; | 1054 | acpi_status status = 0; |
| 974 | int psw_error; | 1055 | int err; |
| 975 | 1056 | ||
| 976 | /* Presence of _PRW indicates wake capable */ | 1057 | /* Presence of _PRW indicates wake capable */ |
| 977 | status = acpi_get_handle(device->handle, "_PRW", &temp); | 1058 | status = acpi_get_handle(device->handle, "_PRW", &temp); |
| 978 | if (ACPI_FAILURE(status)) | 1059 | if (ACPI_FAILURE(status)) |
| 979 | return; | 1060 | return; |
| 980 | 1061 | ||
| 981 | status = acpi_bus_extract_wakeup_device_power_package(device->handle, | 1062 | err = acpi_bus_extract_wakeup_device_power_package(device->handle, |
| 982 | &device->wakeup); | 1063 | &device->wakeup); |
| 983 | if (ACPI_FAILURE(status)) { | 1064 | if (err) { |
| 984 | ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package")); | 1065 | dev_err(&device->dev, "_PRW evaluation error: %d\n", err); |
| 985 | return; | 1066 | return; |
| 986 | } | 1067 | } |
| 987 | 1068 | ||
| @@ -994,20 +1075,73 @@ static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
| 994 | * So it is necessary to call _DSW object first. Only when it is not | 1075 | * So it is necessary to call _DSW object first. Only when it is not |
| 995 | * present will the _PSW object used. | 1076 | * present will the _PSW object used. |
| 996 | */ | 1077 | */ |
| 997 | psw_error = acpi_device_sleep_wake(device, 0, 0, 0); | 1078 | err = acpi_device_sleep_wake(device, 0, 0, 0); |
| 998 | if (psw_error) | 1079 | if (err) |
| 999 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 1080 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 1000 | "error in _DSW or _PSW evaluation\n")); | 1081 | "error in _DSW or _PSW evaluation\n")); |
| 1001 | } | 1082 | } |
| 1002 | 1083 | ||
| 1003 | static void acpi_bus_add_power_resource(acpi_handle handle); | 1084 | static void acpi_bus_init_power_state(struct acpi_device *device, int state) |
| 1085 | { | ||
| 1086 | struct acpi_device_power_state *ps = &device->power.states[state]; | ||
| 1087 | char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' }; | ||
| 1088 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
| 1089 | acpi_handle handle; | ||
| 1090 | acpi_status status; | ||
| 1004 | 1091 | ||
| 1005 | static int acpi_bus_get_power_flags(struct acpi_device *device) | 1092 | INIT_LIST_HEAD(&ps->resources); |
| 1093 | |||
| 1094 | /* Evaluate "_PRx" to get referenced power resources */ | ||
| 1095 | status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer); | ||
| 1096 | if (ACPI_SUCCESS(status)) { | ||
| 1097 | union acpi_object *package = buffer.pointer; | ||
| 1098 | |||
| 1099 | if (buffer.length && package | ||
| 1100 | && package->type == ACPI_TYPE_PACKAGE | ||
| 1101 | && package->package.count) { | ||
| 1102 | int err = acpi_extract_power_resources(package, 0, | ||
| 1103 | &ps->resources); | ||
| 1104 | if (!err) | ||
| 1105 | device->power.flags.power_resources = 1; | ||
| 1106 | } | ||
| 1107 | ACPI_FREE(buffer.pointer); | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | /* Evaluate "_PSx" to see if we can do explicit sets */ | ||
| 1111 | pathname[2] = 'S'; | ||
| 1112 | status = acpi_get_handle(device->handle, pathname, &handle); | ||
| 1113 | if (ACPI_SUCCESS(status)) | ||
| 1114 | ps->flags.explicit_set = 1; | ||
| 1115 | |||
| 1116 | /* | ||
| 1117 | * State is valid if there are means to put the device into it. | ||
| 1118 | * D3hot is only valid if _PR3 present. | ||
| 1119 | */ | ||
| 1120 | if (!list_empty(&ps->resources) | ||
| 1121 | || (ps->flags.explicit_set && state < ACPI_STATE_D3_HOT)) { | ||
| 1122 | ps->flags.valid = 1; | ||
| 1123 | ps->flags.os_accessible = 1; | ||
| 1124 | } | ||
| 1125 | |||
| 1126 | ps->power = -1; /* Unknown - driver assigned */ | ||
| 1127 | ps->latency = -1; /* Unknown - driver assigned */ | ||
| 1128 | } | ||
| 1129 | |||
| 1130 | static void acpi_bus_get_power_flags(struct acpi_device *device) | ||
| 1006 | { | 1131 | { |
| 1007 | acpi_status status = 0; | 1132 | acpi_status status; |
| 1008 | acpi_handle handle = NULL; | 1133 | acpi_handle handle; |
| 1009 | u32 i = 0; | 1134 | u32 i; |
| 1135 | |||
| 1136 | /* Presence of _PS0|_PR0 indicates 'power manageable' */ | ||
| 1137 | status = acpi_get_handle(device->handle, "_PS0", &handle); | ||
| 1138 | if (ACPI_FAILURE(status)) { | ||
| 1139 | status = acpi_get_handle(device->handle, "_PR0", &handle); | ||
| 1140 | if (ACPI_FAILURE(status)) | ||
| 1141 | return; | ||
| 1142 | } | ||
| 1010 | 1143 | ||
| 1144 | device->flags.power_manageable = 1; | ||
| 1011 | 1145 | ||
| 1012 | /* | 1146 | /* |
| 1013 | * Power Management Flags | 1147 | * Power Management Flags |
| @@ -1022,40 +1156,10 @@ static int acpi_bus_get_power_flags(struct acpi_device *device) | |||
| 1022 | /* | 1156 | /* |
| 1023 | * Enumerate supported power management states | 1157 | * Enumerate supported power management states |
| 1024 | */ | 1158 | */ |
| 1025 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { | 1159 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) |
| 1026 | struct acpi_device_power_state *ps = &device->power.states[i]; | 1160 | acpi_bus_init_power_state(device, i); |
| 1027 | char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' }; | ||
| 1028 | |||
| 1029 | /* Evaluate "_PRx" to se if power resources are referenced */ | ||
| 1030 | acpi_evaluate_reference(device->handle, object_name, NULL, | ||
| 1031 | &ps->resources); | ||
| 1032 | if (ps->resources.count) { | ||
| 1033 | int j; | ||
| 1034 | 1161 | ||
| 1035 | device->power.flags.power_resources = 1; | 1162 | INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources); |
| 1036 | for (j = 0; j < ps->resources.count; j++) | ||
| 1037 | acpi_bus_add_power_resource(ps->resources.handles[j]); | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | /* Evaluate "_PSx" to see if we can do explicit sets */ | ||
| 1041 | object_name[2] = 'S'; | ||
| 1042 | status = acpi_get_handle(device->handle, object_name, &handle); | ||
| 1043 | if (ACPI_SUCCESS(status)) | ||
| 1044 | ps->flags.explicit_set = 1; | ||
| 1045 | |||
| 1046 | /* | ||
| 1047 | * State is valid if there are means to put the device into it. | ||
| 1048 | * D3hot is only valid if _PR3 present. | ||
| 1049 | */ | ||
| 1050 | if (ps->resources.count || | ||
| 1051 | (ps->flags.explicit_set && i < ACPI_STATE_D3_HOT)) { | ||
| 1052 | ps->flags.valid = 1; | ||
| 1053 | ps->flags.os_accessible = 1; | ||
| 1054 | } | ||
| 1055 | |||
| 1056 | ps->power = -1; /* Unknown - driver assigned */ | ||
| 1057 | ps->latency = -1; /* Unknown - driver assigned */ | ||
| 1058 | } | ||
| 1059 | 1163 | ||
| 1060 | /* Set defaults for D0 and D3 states (always valid) */ | 1164 | /* Set defaults for D0 and D3 states (always valid) */ |
| 1061 | device->power.states[ACPI_STATE_D0].flags.valid = 1; | 1165 | device->power.states[ACPI_STATE_D0].flags.valid = 1; |
| @@ -1072,17 +1176,17 @@ static int acpi_bus_get_power_flags(struct acpi_device *device) | |||
| 1072 | device->power.flags.power_resources) | 1176 | device->power.flags.power_resources) |
| 1073 | device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1; | 1177 | device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1; |
| 1074 | 1178 | ||
| 1075 | acpi_bus_init_power(device); | 1179 | if (acpi_bus_init_power(device)) { |
| 1076 | 1180 | acpi_free_power_resources_lists(device); | |
| 1077 | return 0; | 1181 | device->flags.power_manageable = 0; |
| 1182 | } | ||
| 1078 | } | 1183 | } |
| 1079 | 1184 | ||
| 1080 | static int acpi_bus_get_flags(struct acpi_device *device) | 1185 | static void acpi_bus_get_flags(struct acpi_device *device) |
| 1081 | { | 1186 | { |
| 1082 | acpi_status status = AE_OK; | 1187 | acpi_status status = AE_OK; |
| 1083 | acpi_handle temp = NULL; | 1188 | acpi_handle temp = NULL; |
| 1084 | 1189 | ||
| 1085 | |||
| 1086 | /* Presence of _STA indicates 'dynamic_status' */ | 1190 | /* Presence of _STA indicates 'dynamic_status' */ |
| 1087 | status = acpi_get_handle(device->handle, "_STA", &temp); | 1191 | status = acpi_get_handle(device->handle, "_STA", &temp); |
| 1088 | if (ACPI_SUCCESS(status)) | 1192 | if (ACPI_SUCCESS(status)) |
| @@ -1102,21 +1206,6 @@ static int acpi_bus_get_flags(struct acpi_device *device) | |||
| 1102 | if (ACPI_SUCCESS(status)) | 1206 | if (ACPI_SUCCESS(status)) |
| 1103 | device->flags.ejectable = 1; | 1207 | device->flags.ejectable = 1; |
| 1104 | } | 1208 | } |
| 1105 | |||
| 1106 | /* Power resources cannot be power manageable. */ | ||
| 1107 | if (device->device_type == ACPI_BUS_TYPE_POWER) | ||
| 1108 | return 0; | ||
| 1109 | |||
| 1110 | /* Presence of _PS0|_PR0 indicates 'power manageable' */ | ||
| 1111 | status = acpi_get_handle(device->handle, "_PS0", &temp); | ||
| 1112 | if (ACPI_FAILURE(status)) | ||
| 1113 | status = acpi_get_handle(device->handle, "_PR0", &temp); | ||
| 1114 | if (ACPI_SUCCESS(status)) | ||
| 1115 | device->flags.power_manageable = 1; | ||
| 1116 | |||
| 1117 | /* TBD: Performance management */ | ||
| 1118 | |||
| 1119 | return 0; | ||
| 1120 | } | 1209 | } |
| 1121 | 1210 | ||
| 1122 | static void acpi_device_get_busid(struct acpi_device *device) | 1211 | static void acpi_device_get_busid(struct acpi_device *device) |
| @@ -1341,27 +1430,25 @@ static void acpi_device_set_id(struct acpi_device *device) | |||
| 1341 | } | 1430 | } |
| 1342 | } | 1431 | } |
| 1343 | 1432 | ||
| 1344 | static int acpi_device_set_context(struct acpi_device *device) | 1433 | void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, |
| 1434 | int type, unsigned long long sta) | ||
| 1345 | { | 1435 | { |
| 1346 | acpi_status status; | 1436 | INIT_LIST_HEAD(&device->pnp.ids); |
| 1347 | 1437 | device->device_type = type; | |
| 1348 | /* | 1438 | device->handle = handle; |
| 1349 | * Context | 1439 | device->parent = acpi_bus_get_parent(handle); |
| 1350 | * ------- | 1440 | STRUCT_TO_INT(device->status) = sta; |
| 1351 | * Attach this 'struct acpi_device' to the ACPI object. This makes | 1441 | acpi_device_get_busid(device); |
| 1352 | * resolutions from handle->device very efficient. Fixed hardware | 1442 | acpi_device_set_id(device); |
| 1353 | * devices have no handles, so we skip them. | 1443 | acpi_bus_get_flags(device); |
| 1354 | */ | 1444 | device_initialize(&device->dev); |
| 1355 | if (!device->handle) | 1445 | dev_set_uevent_suppress(&device->dev, true); |
| 1356 | return 0; | 1446 | } |
| 1357 | |||
| 1358 | status = acpi_attach_data(device->handle, | ||
| 1359 | acpi_bus_data_handler, device); | ||
| 1360 | if (ACPI_SUCCESS(status)) | ||
| 1361 | return 0; | ||
| 1362 | 1447 | ||
| 1363 | printk(KERN_ERR PREFIX "Error attaching device data\n"); | 1448 | void acpi_device_add_finalize(struct acpi_device *device) |
| 1364 | return -ENODEV; | 1449 | { |
| 1450 | dev_set_uevent_suppress(&device->dev, false); | ||
| 1451 | kobject_uevent(&device->dev.kobj, KOBJ_ADD); | ||
| 1365 | } | 1452 | } |
| 1366 | 1453 | ||
| 1367 | static int acpi_add_single_object(struct acpi_device **child, | 1454 | static int acpi_add_single_object(struct acpi_device **child, |
| @@ -1378,90 +1465,26 @@ static int acpi_add_single_object(struct acpi_device **child, | |||
| 1378 | return -ENOMEM; | 1465 | return -ENOMEM; |
| 1379 | } | 1466 | } |
| 1380 | 1467 | ||
| 1381 | INIT_LIST_HEAD(&device->pnp.ids); | 1468 | acpi_init_device_object(device, handle, type, sta); |
| 1382 | device->device_type = type; | 1469 | acpi_bus_get_power_flags(device); |
| 1383 | device->handle = handle; | ||
| 1384 | device->parent = acpi_bus_get_parent(handle); | ||
| 1385 | STRUCT_TO_INT(device->status) = sta; | ||
| 1386 | |||
| 1387 | acpi_device_get_busid(device); | ||
| 1388 | |||
| 1389 | /* | ||
| 1390 | * Flags | ||
| 1391 | * ----- | ||
| 1392 | * Note that we only look for object handles -- cannot evaluate objects | ||
| 1393 | * until we know the device is present and properly initialized. | ||
| 1394 | */ | ||
| 1395 | result = acpi_bus_get_flags(device); | ||
| 1396 | if (result) | ||
| 1397 | goto end; | ||
| 1398 | |||
| 1399 | /* | ||
| 1400 | * Initialize Device | ||
| 1401 | * ----------------- | ||
| 1402 | * TBD: Synch with Core's enumeration/initialization process. | ||
| 1403 | */ | ||
| 1404 | acpi_device_set_id(device); | ||
| 1405 | |||
| 1406 | /* | ||
| 1407 | * Power Management | ||
| 1408 | * ---------------- | ||
| 1409 | */ | ||
| 1410 | if (device->flags.power_manageable) { | ||
| 1411 | result = acpi_bus_get_power_flags(device); | ||
| 1412 | if (result) | ||
| 1413 | goto end; | ||
| 1414 | } | ||
| 1415 | |||
| 1416 | /* | ||
| 1417 | * Wakeup device management | ||
| 1418 | *----------------------- | ||
| 1419 | */ | ||
| 1420 | acpi_bus_get_wakeup_device_flags(device); | 1470 | acpi_bus_get_wakeup_device_flags(device); |
| 1421 | 1471 | ||
| 1422 | /* | ||
| 1423 | * Performance Management | ||
| 1424 | * ---------------------- | ||
| 1425 | */ | ||
| 1426 | if (device->flags.performance_manageable) { | ||
| 1427 | result = acpi_bus_get_perf_flags(device); | ||
| 1428 | if (result) | ||
| 1429 | goto end; | ||
| 1430 | } | ||
| 1431 | |||
| 1432 | if ((result = acpi_device_set_context(device))) | ||
| 1433 | goto end; | ||
| 1434 | |||
| 1435 | device->flags.match_driver = match_driver; | 1472 | device->flags.match_driver = match_driver; |
| 1436 | result = acpi_device_register(device); | 1473 | result = acpi_device_add(device, acpi_device_release); |
| 1437 | 1474 | if (result) { | |
| 1438 | end: | ||
| 1439 | if (!result) { | ||
| 1440 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | ||
| 1441 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 1442 | "Adding %s [%s] parent %s\n", dev_name(&device->dev), | ||
| 1443 | (char *) buffer.pointer, | ||
| 1444 | device->parent ? dev_name(&device->parent->dev) : | ||
| 1445 | "(null)")); | ||
| 1446 | kfree(buffer.pointer); | ||
| 1447 | *child = device; | ||
| 1448 | } else | ||
| 1449 | acpi_device_release(&device->dev); | 1475 | acpi_device_release(&device->dev); |
| 1476 | return result; | ||
| 1477 | } | ||
| 1450 | 1478 | ||
| 1451 | return result; | 1479 | acpi_power_add_remove_device(device, true); |
| 1452 | } | 1480 | acpi_device_add_finalize(device); |
| 1453 | 1481 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | |
| 1454 | #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ | 1482 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n", |
| 1455 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) | 1483 | dev_name(&device->dev), (char *) buffer.pointer, |
| 1456 | 1484 | device->parent ? dev_name(&device->parent->dev) : "(null)")); | |
| 1457 | static void acpi_bus_add_power_resource(acpi_handle handle) | 1485 | kfree(buffer.pointer); |
| 1458 | { | 1486 | *child = device; |
| 1459 | struct acpi_device *device = NULL; | 1487 | return 0; |
| 1460 | |||
| 1461 | acpi_bus_get_device(handle, &device); | ||
| 1462 | if (!device) | ||
| 1463 | acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER, | ||
| 1464 | ACPI_STA_DEFAULT, true); | ||
| 1465 | } | 1488 | } |
| 1466 | 1489 | ||
| 1467 | static int acpi_bus_type_and_status(acpi_handle handle, int *type, | 1490 | static int acpi_bus_type_and_status(acpi_handle handle, int *type, |
| @@ -1520,20 +1543,26 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, | |||
| 1520 | if (result) | 1543 | if (result) |
| 1521 | return AE_OK; | 1544 | return AE_OK; |
| 1522 | 1545 | ||
| 1546 | if (type == ACPI_BUS_TYPE_POWER) { | ||
| 1547 | acpi_add_power_resource(handle); | ||
| 1548 | return AE_OK; | ||
| 1549 | } | ||
| 1550 | |||
| 1523 | if (!(sta & ACPI_STA_DEVICE_PRESENT) && | 1551 | if (!(sta & ACPI_STA_DEVICE_PRESENT) && |
| 1524 | !(sta & ACPI_STA_DEVICE_FUNCTIONING)) { | 1552 | !(sta & ACPI_STA_DEVICE_FUNCTIONING)) { |
| 1525 | struct acpi_device_wakeup wakeup; | 1553 | struct acpi_device_wakeup wakeup; |
| 1526 | acpi_handle temp; | 1554 | acpi_handle temp; |
| 1527 | 1555 | ||
| 1528 | status = acpi_get_handle(handle, "_PRW", &temp); | 1556 | status = acpi_get_handle(handle, "_PRW", &temp); |
| 1529 | if (ACPI_SUCCESS(status)) | 1557 | if (ACPI_SUCCESS(status)) { |
| 1530 | acpi_bus_extract_wakeup_device_power_package(handle, | 1558 | acpi_bus_extract_wakeup_device_power_package(handle, |
| 1531 | &wakeup); | 1559 | &wakeup); |
| 1560 | acpi_power_resources_list_free(&wakeup.resources); | ||
| 1561 | } | ||
| 1532 | return AE_CTRL_DEPTH; | 1562 | return AE_CTRL_DEPTH; |
| 1533 | } | 1563 | } |
| 1534 | 1564 | ||
| 1535 | acpi_add_single_object(&device, handle, type, sta, | 1565 | acpi_add_single_object(&device, handle, type, sta, false); |
| 1536 | type == ACPI_BUS_TYPE_POWER); | ||
| 1537 | if (!device) | 1566 | if (!device) |
| 1538 | return AE_CTRL_DEPTH; | 1567 | return AE_CTRL_DEPTH; |
| 1539 | 1568 | ||
| @@ -1687,7 +1716,6 @@ int __init acpi_scan_init(void) | |||
| 1687 | printk(KERN_ERR PREFIX "Could not register bus type\n"); | 1716 | printk(KERN_ERR PREFIX "Could not register bus type\n"); |
| 1688 | } | 1717 | } |
| 1689 | 1718 | ||
| 1690 | acpi_power_init(); | ||
| 1691 | acpi_pci_root_init(); | 1719 | acpi_pci_root_init(); |
| 1692 | 1720 | ||
| 1693 | /* | 1721 | /* |
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 2fcc67d34b11..277aa825edd9 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c | |||
| @@ -386,6 +386,8 @@ static void acpi_pm_finish(void) | |||
| 386 | 386 | ||
| 387 | acpi_target_sleep_state = ACPI_STATE_S0; | 387 | acpi_target_sleep_state = ACPI_STATE_S0; |
| 388 | 388 | ||
| 389 | acpi_resume_power_resources(); | ||
| 390 | |||
| 389 | /* If we were woken with the fixed power button, provide a small | 391 | /* If we were woken with the fixed power button, provide a small |
| 390 | * hint to userspace in the form of a wakeup event on the fixed power | 392 | * hint to userspace in the form of a wakeup event on the fixed power |
| 391 | * button device (if it can be found). | 393 | * button device (if it can be found). |
| @@ -577,7 +579,28 @@ static const struct platform_suspend_ops acpi_suspend_ops_old = { | |||
| 577 | .end = acpi_pm_end, | 579 | .end = acpi_pm_end, |
| 578 | .recover = acpi_pm_finish, | 580 | .recover = acpi_pm_finish, |
| 579 | }; | 581 | }; |
| 580 | #endif /* CONFIG_SUSPEND */ | 582 | |
| 583 | static void acpi_sleep_suspend_setup(void) | ||
| 584 | { | ||
| 585 | int i; | ||
| 586 | |||
| 587 | for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { | ||
| 588 | acpi_status status; | ||
| 589 | u8 type_a, type_b; | ||
| 590 | |||
| 591 | status = acpi_get_sleep_type_data(i, &type_a, &type_b); | ||
| 592 | if (ACPI_SUCCESS(status)) { | ||
| 593 | sleep_states[i] = 1; | ||
| 594 | pr_cont(" S%d", i); | ||
| 595 | } | ||
| 596 | } | ||
| 597 | |||
| 598 | suspend_set_ops(old_suspend_ordering ? | ||
| 599 | &acpi_suspend_ops_old : &acpi_suspend_ops); | ||
| 600 | } | ||
| 601 | #else /* !CONFIG_SUSPEND */ | ||
| 602 | static inline void acpi_sleep_suspend_setup(void) {} | ||
| 603 | #endif /* !CONFIG_SUSPEND */ | ||
| 581 | 604 | ||
| 582 | #ifdef CONFIG_HIBERNATION | 605 | #ifdef CONFIG_HIBERNATION |
| 583 | static unsigned long s4_hardware_signature; | 606 | static unsigned long s4_hardware_signature; |
| @@ -698,7 +721,30 @@ static const struct platform_hibernation_ops acpi_hibernation_ops_old = { | |||
| 698 | .restore_cleanup = acpi_pm_thaw, | 721 | .restore_cleanup = acpi_pm_thaw, |
| 699 | .recover = acpi_pm_finish, | 722 | .recover = acpi_pm_finish, |
| 700 | }; | 723 | }; |
| 701 | #endif /* CONFIG_HIBERNATION */ | 724 | |
| 725 | static void acpi_sleep_hibernate_setup(void) | ||
| 726 | { | ||
| 727 | acpi_status status; | ||
| 728 | u8 type_a, type_b; | ||
| 729 | |||
| 730 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); | ||
| 731 | if (ACPI_FAILURE(status)) | ||
| 732 | return; | ||
| 733 | |||
| 734 | hibernation_set_ops(old_suspend_ordering ? | ||
| 735 | &acpi_hibernation_ops_old : &acpi_hibernation_ops); | ||
| 736 | sleep_states[ACPI_STATE_S4] = 1; | ||
| 737 | pr_cont(KERN_CONT " S4"); | ||
| 738 | if (nosigcheck) | ||
| 739 | return; | ||
| 740 | |||
| 741 | acpi_get_table(ACPI_SIG_FACS, 1, (struct acpi_table_header **)&facs); | ||
| 742 | if (facs) | ||
| 743 | s4_hardware_signature = facs->hardware_signature; | ||
| 744 | } | ||
| 745 | #else /* !CONFIG_HIBERNATION */ | ||
| 746 | static inline void acpi_sleep_hibernate_setup(void) {} | ||
| 747 | #endif /* !CONFIG_HIBERNATION */ | ||
| 702 | 748 | ||
| 703 | int acpi_suspend(u32 acpi_state) | 749 | int acpi_suspend(u32 acpi_state) |
| 704 | { | 750 | { |
| @@ -734,9 +780,6 @@ int __init acpi_sleep_init(void) | |||
| 734 | { | 780 | { |
| 735 | acpi_status status; | 781 | acpi_status status; |
| 736 | u8 type_a, type_b; | 782 | u8 type_a, type_b; |
| 737 | #ifdef CONFIG_SUSPEND | ||
| 738 | int i = 0; | ||
| 739 | #endif | ||
| 740 | 783 | ||
| 741 | if (acpi_disabled) | 784 | if (acpi_disabled) |
| 742 | return 0; | 785 | return 0; |
| @@ -744,45 +787,19 @@ int __init acpi_sleep_init(void) | |||
| 744 | acpi_sleep_dmi_check(); | 787 | acpi_sleep_dmi_check(); |
| 745 | 788 | ||
| 746 | sleep_states[ACPI_STATE_S0] = 1; | 789 | sleep_states[ACPI_STATE_S0] = 1; |
| 747 | printk(KERN_INFO PREFIX "(supports S0"); | 790 | pr_info(PREFIX "(supports S0"); |
| 748 | 791 | ||
| 749 | #ifdef CONFIG_SUSPEND | 792 | acpi_sleep_suspend_setup(); |
| 750 | for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { | 793 | acpi_sleep_hibernate_setup(); |
| 751 | status = acpi_get_sleep_type_data(i, &type_a, &type_b); | ||
| 752 | if (ACPI_SUCCESS(status)) { | ||
| 753 | sleep_states[i] = 1; | ||
| 754 | printk(KERN_CONT " S%d", i); | ||
| 755 | } | ||
| 756 | } | ||
| 757 | 794 | ||
| 758 | suspend_set_ops(old_suspend_ordering ? | ||
| 759 | &acpi_suspend_ops_old : &acpi_suspend_ops); | ||
| 760 | #endif | ||
| 761 | |||
| 762 | #ifdef CONFIG_HIBERNATION | ||
| 763 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); | ||
| 764 | if (ACPI_SUCCESS(status)) { | ||
| 765 | hibernation_set_ops(old_suspend_ordering ? | ||
| 766 | &acpi_hibernation_ops_old : &acpi_hibernation_ops); | ||
| 767 | sleep_states[ACPI_STATE_S4] = 1; | ||
| 768 | printk(KERN_CONT " S4"); | ||
| 769 | if (!nosigcheck) { | ||
| 770 | acpi_get_table(ACPI_SIG_FACS, 1, | ||
| 771 | (struct acpi_table_header **)&facs); | ||
| 772 | if (facs) | ||
| 773 | s4_hardware_signature = | ||
| 774 | facs->hardware_signature; | ||
| 775 | } | ||
| 776 | } | ||
| 777 | #endif | ||
| 778 | status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); | 795 | status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); |
| 779 | if (ACPI_SUCCESS(status)) { | 796 | if (ACPI_SUCCESS(status)) { |
| 780 | sleep_states[ACPI_STATE_S5] = 1; | 797 | sleep_states[ACPI_STATE_S5] = 1; |
| 781 | printk(KERN_CONT " S5"); | 798 | pr_cont(" S5"); |
| 782 | pm_power_off_prepare = acpi_power_off_prepare; | 799 | pm_power_off_prepare = acpi_power_off_prepare; |
| 783 | pm_power_off = acpi_power_off; | 800 | pm_power_off = acpi_power_off; |
| 784 | } | 801 | } |
| 785 | printk(KERN_CONT ")\n"); | 802 | pr_cont(")\n"); |
| 786 | /* | 803 | /* |
| 787 | * Register the tts_notifier to reboot notifier list so that the _TTS | 804 | * Register the tts_notifier to reboot notifier list so that the _TTS |
| 788 | * object can also be evaluated when the system enters S5. | 805 | * object can also be evaluated when the system enters S5. |
diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h index 74d59c8f4678..0143540a2519 100644 --- a/drivers/acpi/sleep.h +++ b/drivers/acpi/sleep.h | |||
| @@ -6,3 +6,5 @@ extern void acpi_disable_wakeup_devices(u8 sleep_state); | |||
| 6 | 6 | ||
| 7 | extern struct list_head acpi_wakeup_device_list; | 7 | extern struct list_head acpi_wakeup_device_list; |
| 8 | extern struct mutex acpi_device_lock; | 8 | extern struct mutex acpi_device_lock; |
| 9 | |||
| 10 | extern void acpi_resume_power_resources(void); | ||
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c index ef01ac07502e..6fc67f7efb22 100644 --- a/drivers/ata/libata-acpi.c +++ b/drivers/ata/libata-acpi.c | |||
| @@ -1029,30 +1029,20 @@ static void ata_acpi_register_power_resource(struct ata_device *dev) | |||
| 1029 | { | 1029 | { |
| 1030 | struct scsi_device *sdev = dev->sdev; | 1030 | struct scsi_device *sdev = dev->sdev; |
| 1031 | acpi_handle handle; | 1031 | acpi_handle handle; |
| 1032 | struct device *device; | ||
| 1033 | 1032 | ||
| 1034 | handle = ata_dev_acpi_handle(dev); | 1033 | handle = ata_dev_acpi_handle(dev); |
| 1035 | if (!handle) | 1034 | if (handle) |
| 1036 | return; | 1035 | acpi_dev_pm_remove_dependent(handle, &sdev->sdev_gendev); |
| 1037 | |||
| 1038 | device = &sdev->sdev_gendev; | ||
| 1039 | |||
| 1040 | acpi_power_resource_register_device(device, handle); | ||
| 1041 | } | 1036 | } |
| 1042 | 1037 | ||
| 1043 | static void ata_acpi_unregister_power_resource(struct ata_device *dev) | 1038 | static void ata_acpi_unregister_power_resource(struct ata_device *dev) |
| 1044 | { | 1039 | { |
| 1045 | struct scsi_device *sdev = dev->sdev; | 1040 | struct scsi_device *sdev = dev->sdev; |
| 1046 | acpi_handle handle; | 1041 | acpi_handle handle; |
| 1047 | struct device *device; | ||
| 1048 | 1042 | ||
| 1049 | handle = ata_dev_acpi_handle(dev); | 1043 | handle = ata_dev_acpi_handle(dev); |
| 1050 | if (!handle) | 1044 | if (handle) |
| 1051 | return; | 1045 | acpi_dev_pm_remove_dependent(handle, &sdev->sdev_gendev); |
| 1052 | |||
| 1053 | device = &sdev->sdev_gendev; | ||
| 1054 | |||
| 1055 | acpi_power_resource_unregister_device(device, handle); | ||
| 1056 | } | 1046 | } |
| 1057 | 1047 | ||
| 1058 | void ata_acpi_bind(struct ata_device *dev) | 1048 | void ata_acpi_bind(struct ata_device *dev) |
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 42736e213f25..e407c61559ca 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c | |||
| @@ -345,7 +345,6 @@ static void pci_acpi_setup(struct device *dev) | |||
| 345 | acpi_pci_irq_add_prt(handle, pci_domain_nr(pci_dev->bus), bus); | 345 | acpi_pci_irq_add_prt(handle, pci_domain_nr(pci_dev->bus), bus); |
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | acpi_power_resource_register_device(dev, handle); | ||
| 349 | if (acpi_bus_get_device(handle, &adev) || !adev->wakeup.flags.valid) | 348 | if (acpi_bus_get_device(handle, &adev) || !adev->wakeup.flags.valid) |
| 350 | return; | 349 | return; |
| 351 | 350 | ||
| @@ -368,7 +367,6 @@ static void pci_acpi_cleanup(struct device *dev) | |||
| 368 | device_set_run_wake(dev, false); | 367 | device_set_run_wake(dev, false); |
| 369 | pci_acpi_remove_pm_notifier(adev); | 368 | pci_acpi_remove_pm_notifier(adev); |
| 370 | } | 369 | } |
| 371 | acpi_power_resource_unregister_device(dev, handle); | ||
| 372 | 370 | ||
| 373 | if (pci_dev->subordinate) | 371 | if (pci_dev->subordinate) |
| 374 | acpi_pci_irq_del_prt(pci_domain_nr(pci_dev->bus), | 372 | acpi_pci_irq_del_prt(pci_domain_nr(pci_dev->bus), |
