aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/bus.c')
-rw-r--r--drivers/acpi/bus.c128
1 files changed, 57 insertions, 71 deletions
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index dd3983cece92..ea5a0496a4fd 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -60,21 +60,19 @@ int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
60{ 60{
61 acpi_status status = AE_OK; 61 acpi_status status = AE_OK;
62 62
63 ACPI_FUNCTION_TRACE("acpi_bus_get_device");
64 63
65 if (!device) 64 if (!device)
66 return_VALUE(-EINVAL); 65 return -EINVAL;
67 66
68 /* TBD: Support fixed-feature devices */ 67 /* TBD: Support fixed-feature devices */
69 68
70 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device); 69 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
71 if (ACPI_FAILURE(status) || !*device) { 70 if (ACPI_FAILURE(status) || !*device) {
72 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "No context for object [%p]\n", 71 ACPI_EXCEPTION((AE_INFO, status, "No context for object [%p]", handle));
73 handle)); 72 return -ENODEV;
74 return_VALUE(-ENODEV);
75 } 73 }
76 74
77 return_VALUE(0); 75 return 0;
78} 76}
79 77
80EXPORT_SYMBOL(acpi_bus_get_device); 78EXPORT_SYMBOL(acpi_bus_get_device);
@@ -84,10 +82,9 @@ int acpi_bus_get_status(struct acpi_device *device)
84 acpi_status status = AE_OK; 82 acpi_status status = AE_OK;
85 unsigned long sta = 0; 83 unsigned long sta = 0;
86 84
87 ACPI_FUNCTION_TRACE("acpi_bus_get_status");
88 85
89 if (!device) 86 if (!device)
90 return_VALUE(-EINVAL); 87 return -EINVAL;
91 88
92 /* 89 /*
93 * Evaluate _STA if present. 90 * Evaluate _STA if present.
@@ -96,7 +93,7 @@ int acpi_bus_get_status(struct acpi_device *device)
96 status = 93 status =
97 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta); 94 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
98 if (ACPI_FAILURE(status)) 95 if (ACPI_FAILURE(status))
99 return_VALUE(-ENODEV); 96 return -ENODEV;
100 STRUCT_TO_INT(device->status) = (int)sta; 97 STRUCT_TO_INT(device->status) = (int)sta;
101 } 98 }
102 99
@@ -120,7 +117,7 @@ int acpi_bus_get_status(struct acpi_device *device)
120 device->pnp.bus_id, 117 device->pnp.bus_id,
121 (u32) STRUCT_TO_INT(device->status))); 118 (u32) STRUCT_TO_INT(device->status)));
122 119
123 return_VALUE(0); 120 return 0;
124} 121}
125 122
126EXPORT_SYMBOL(acpi_bus_get_status); 123EXPORT_SYMBOL(acpi_bus_get_status);
@@ -136,11 +133,10 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
136 struct acpi_device *device = NULL; 133 struct acpi_device *device = NULL;
137 unsigned long psc = 0; 134 unsigned long psc = 0;
138 135
139 ACPI_FUNCTION_TRACE("acpi_bus_get_power");
140 136
141 result = acpi_bus_get_device(handle, &device); 137 result = acpi_bus_get_device(handle, &device);
142 if (result) 138 if (result)
143 return_VALUE(result); 139 return result;
144 140
145 *state = ACPI_STATE_UNKNOWN; 141 *state = ACPI_STATE_UNKNOWN;
146 142
@@ -159,12 +155,12 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
159 status = acpi_evaluate_integer(device->handle, "_PSC", 155 status = acpi_evaluate_integer(device->handle, "_PSC",
160 NULL, &psc); 156 NULL, &psc);
161 if (ACPI_FAILURE(status)) 157 if (ACPI_FAILURE(status))
162 return_VALUE(-ENODEV); 158 return -ENODEV;
163 device->power.state = (int)psc; 159 device->power.state = (int)psc;
164 } else if (device->power.flags.power_resources) { 160 } else if (device->power.flags.power_resources) {
165 result = acpi_power_get_inferred_state(device); 161 result = acpi_power_get_inferred_state(device);
166 if (result) 162 if (result)
167 return_VALUE(result); 163 return result;
168 } 164 }
169 165
170 *state = device->power.state; 166 *state = device->power.state;
@@ -173,7 +169,7 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
173 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", 169 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
174 device->pnp.bus_id, device->power.state)); 170 device->pnp.bus_id, device->power.state));
175 171
176 return_VALUE(0); 172 return 0;
177} 173}
178 174
179EXPORT_SYMBOL(acpi_bus_get_power); 175EXPORT_SYMBOL(acpi_bus_get_power);
@@ -185,21 +181,20 @@ int acpi_bus_set_power(acpi_handle handle, int state)
185 struct acpi_device *device = NULL; 181 struct acpi_device *device = NULL;
186 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' }; 182 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
187 183
188 ACPI_FUNCTION_TRACE("acpi_bus_set_power");
189 184
190 result = acpi_bus_get_device(handle, &device); 185 result = acpi_bus_get_device(handle, &device);
191 if (result) 186 if (result)
192 return_VALUE(result); 187 return result;
193 188
194 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) 189 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
195 return_VALUE(-EINVAL); 190 return -EINVAL;
196 191
197 /* Make sure this is a valid target state */ 192 /* Make sure this is a valid target state */
198 193
199 if (!device->flags.power_manageable) { 194 if (!device->flags.power_manageable) {
200 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 195 printk(KERN_DEBUG "Device `[%s]' is not power manageable",
201 "Device is not power manageable\n")); 196 device->kobj.name);
202 return_VALUE(-ENODEV); 197 return -ENODEV;
203 } 198 }
204 /* 199 /*
205 * Get device's current power state if it's unknown 200 * Get device's current power state if it's unknown
@@ -211,18 +206,18 @@ int acpi_bus_set_power(acpi_handle handle, int state)
211 if (state == device->power.state) { 206 if (state == device->power.state) {
212 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", 207 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
213 state)); 208 state));
214 return_VALUE(0); 209 return 0;
215 } 210 }
216 } 211 }
217 if (!device->power.states[state].flags.valid) { 212 if (!device->power.states[state].flags.valid) {
218 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device does not support D%d\n", 213 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
219 state)); 214 return -ENODEV;
220 return_VALUE(-ENODEV);
221 } 215 }
222 if (device->parent && (state < device->parent->power.state)) { 216 if (device->parent && (state < device->parent->power.state)) {
223 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 217 printk(KERN_WARNING PREFIX
224 "Cannot set device to a higher-powered state than parent\n")); 218 "Cannot set device to a higher-powered"
225 return_VALUE(-ENODEV); 219 " state than parent\n");
220 return -ENODEV;
226 } 221 }
227 222
228 /* 223 /*
@@ -264,15 +259,15 @@ int acpi_bus_set_power(acpi_handle handle, int state)
264 259
265 end: 260 end:
266 if (result) 261 if (result)
267 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 262 printk(KERN_WARNING PREFIX
268 "Error transitioning device [%s] to D%d\n", 263 "Transitioning device [%s] to D%d\n",
269 device->pnp.bus_id, state)); 264 device->pnp.bus_id, state);
270 else 265 else
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 266 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
272 "Device [%s] transitioned to D%d\n", 267 "Device [%s] transitioned to D%d\n",
273 device->pnp.bus_id, state)); 268 device->pnp.bus_id, state));
274 269
275 return_VALUE(result); 270 return result;
276} 271}
277 272
278EXPORT_SYMBOL(acpi_bus_set_power); 273EXPORT_SYMBOL(acpi_bus_set_power);
@@ -293,18 +288,17 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
293 struct acpi_bus_event *event = NULL; 288 struct acpi_bus_event *event = NULL;
294 unsigned long flags = 0; 289 unsigned long flags = 0;
295 290
296 ACPI_FUNCTION_TRACE("acpi_bus_generate_event");
297 291
298 if (!device) 292 if (!device)
299 return_VALUE(-EINVAL); 293 return -EINVAL;
300 294
301 /* drop event on the floor if no one's listening */ 295 /* drop event on the floor if no one's listening */
302 if (!event_is_open) 296 if (!event_is_open)
303 return_VALUE(0); 297 return 0;
304 298
305 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC); 299 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
306 if (!event) 300 if (!event)
307 return_VALUE(-ENOMEM); 301 return -ENOMEM;
308 302
309 strcpy(event->device_class, device->pnp.device_class); 303 strcpy(event->device_class, device->pnp.device_class);
310 strcpy(event->bus_id, device->pnp.bus_id); 304 strcpy(event->bus_id, device->pnp.bus_id);
@@ -317,7 +311,7 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
317 311
318 wake_up_interruptible(&acpi_bus_event_queue); 312 wake_up_interruptible(&acpi_bus_event_queue);
319 313
320 return_VALUE(0); 314 return 0;
321} 315}
322 316
323EXPORT_SYMBOL(acpi_bus_generate_event); 317EXPORT_SYMBOL(acpi_bus_generate_event);
@@ -329,10 +323,9 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
329 323
330 DECLARE_WAITQUEUE(wait, current); 324 DECLARE_WAITQUEUE(wait, current);
331 325
332 ACPI_FUNCTION_TRACE("acpi_bus_receive_event");
333 326
334 if (!event) 327 if (!event)
335 return_VALUE(-EINVAL); 328 return -EINVAL;
336 329
337 if (list_empty(&acpi_bus_event_list)) { 330 if (list_empty(&acpi_bus_event_list)) {
338 331
@@ -346,7 +339,7 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
346 set_current_state(TASK_RUNNING); 339 set_current_state(TASK_RUNNING);
347 340
348 if (signal_pending(current)) 341 if (signal_pending(current))
349 return_VALUE(-ERESTARTSYS); 342 return -ERESTARTSYS;
350 } 343 }
351 344
352 spin_lock_irqsave(&acpi_bus_event_lock, flags); 345 spin_lock_irqsave(&acpi_bus_event_lock, flags);
@@ -357,13 +350,13 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
357 spin_unlock_irqrestore(&acpi_bus_event_lock, flags); 350 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
358 351
359 if (!entry) 352 if (!entry)
360 return_VALUE(-ENODEV); 353 return -ENODEV;
361 354
362 memcpy(event, entry, sizeof(struct acpi_bus_event)); 355 memcpy(event, entry, sizeof(struct acpi_bus_event));
363 356
364 kfree(entry); 357 kfree(entry);
365 358
366 return_VALUE(0); 359 return 0;
367} 360}
368 361
369EXPORT_SYMBOL(acpi_bus_receive_event); 362EXPORT_SYMBOL(acpi_bus_receive_event);
@@ -378,10 +371,9 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
378 acpi_status status = 0; 371 acpi_status status = 0;
379 struct acpi_device_status old_status; 372 struct acpi_device_status old_status;
380 373
381 ACPI_FUNCTION_TRACE("acpi_bus_check_device");
382 374
383 if (!device) 375 if (!device)
384 return_VALUE(-EINVAL); 376 return -EINVAL;
385 377
386 if (status_changed) 378 if (status_changed)
387 *status_changed = 0; 379 *status_changed = 0;
@@ -398,15 +390,15 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
398 if (status_changed) 390 if (status_changed)
399 *status_changed = 1; 391 *status_changed = 1;
400 } 392 }
401 return_VALUE(0); 393 return 0;
402 } 394 }
403 395
404 status = acpi_bus_get_status(device); 396 status = acpi_bus_get_status(device);
405 if (ACPI_FAILURE(status)) 397 if (ACPI_FAILURE(status))
406 return_VALUE(-ENODEV); 398 return -ENODEV;
407 399
408 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status)) 400 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
409 return_VALUE(0); 401 return 0;
410 402
411 if (status_changed) 403 if (status_changed)
412 *status_changed = 1; 404 *status_changed = 1;
@@ -422,7 +414,7 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
422 /* TBD: Handle device removal */ 414 /* TBD: Handle device removal */
423 } 415 }
424 416
425 return_VALUE(0); 417 return 0;
426} 418}
427 419
428static int acpi_bus_check_scope(struct acpi_device *device) 420static int acpi_bus_check_scope(struct acpi_device *device)
@@ -430,25 +422,24 @@ static int acpi_bus_check_scope(struct acpi_device *device)
430 int result = 0; 422 int result = 0;
431 int status_changed = 0; 423 int status_changed = 0;
432 424
433 ACPI_FUNCTION_TRACE("acpi_bus_check_scope");
434 425
435 if (!device) 426 if (!device)
436 return_VALUE(-EINVAL); 427 return -EINVAL;
437 428
438 /* Status Change? */ 429 /* Status Change? */
439 result = acpi_bus_check_device(device, &status_changed); 430 result = acpi_bus_check_device(device, &status_changed);
440 if (result) 431 if (result)
441 return_VALUE(result); 432 return result;
442 433
443 if (!status_changed) 434 if (!status_changed)
444 return_VALUE(0); 435 return 0;
445 436
446 /* 437 /*
447 * TBD: Enumerate child devices within this device's scope and 438 * TBD: Enumerate child devices within this device's scope and
448 * run acpi_bus_check_device()'s on them. 439 * run acpi_bus_check_device()'s on them.
449 */ 440 */
450 441
451 return_VALUE(0); 442 return 0;
452} 443}
453 444
454/** 445/**
@@ -461,10 +452,9 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
461 int result = 0; 452 int result = 0;
462 struct acpi_device *device = NULL; 453 struct acpi_device *device = NULL;
463 454
464 ACPI_FUNCTION_TRACE("acpi_bus_notify");
465 455
466 if (acpi_bus_get_device(handle, &device)) 456 if (acpi_bus_get_device(handle, &device))
467 return_VOID; 457 return;
468 458
469 switch (type) { 459 switch (type) {
470 460
@@ -539,7 +529,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
539 break; 529 break;
540 } 530 }
541 531
542 return_VOID; 532 return;
543} 533}
544 534
545/* -------------------------------------------------------------------------- 535/* --------------------------------------------------------------------------
@@ -553,7 +543,6 @@ static int __init acpi_bus_init_irq(void)
553 struct acpi_object_list arg_list = { 1, &arg }; 543 struct acpi_object_list arg_list = { 1, &arg };
554 char *message = NULL; 544 char *message = NULL;
555 545
556 ACPI_FUNCTION_TRACE("acpi_bus_init_irq");
557 546
558 /* 547 /*
559 * Let the system know what interrupt model we are using by 548 * Let the system know what interrupt model we are using by
@@ -572,7 +561,7 @@ static int __init acpi_bus_init_irq(void)
572 break; 561 break;
573 default: 562 default:
574 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); 563 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
575 return_VALUE(-ENODEV); 564 return -ENODEV;
576 } 565 }
577 566
578 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); 567 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
@@ -581,11 +570,11 @@ static int __init acpi_bus_init_irq(void)
581 570
582 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL); 571 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
583 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 572 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
584 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PIC\n")); 573 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
585 return_VALUE(-ENODEV); 574 return -ENODEV;
586 } 575 }
587 576
588 return_VALUE(0); 577 return 0;
589} 578}
590 579
591void __init acpi_early_init(void) 580void __init acpi_early_init(void)
@@ -593,10 +582,9 @@ void __init acpi_early_init(void)
593 acpi_status status = AE_OK; 582 acpi_status status = AE_OK;
594 struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt }; 583 struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt };
595 584
596 ACPI_FUNCTION_TRACE("acpi_early_init");
597 585
598 if (acpi_disabled) 586 if (acpi_disabled)
599 return_VOID; 587 return;
600 588
601 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); 589 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
602 590
@@ -656,11 +644,11 @@ void __init acpi_early_init(void)
656 goto error0; 644 goto error0;
657 } 645 }
658 646
659 return_VOID; 647 return;
660 648
661 error0: 649 error0:
662 disable_acpi(); 650 disable_acpi();
663 return_VOID; 651 return;
664} 652}
665 653
666static int __init acpi_bus_init(void) 654static int __init acpi_bus_init(void)
@@ -669,7 +657,6 @@ static int __init acpi_bus_init(void)
669 acpi_status status = AE_OK; 657 acpi_status status = AE_OK;
670 extern acpi_status acpi_os_initialize1(void); 658 extern acpi_status acpi_os_initialize1(void);
671 659
672 ACPI_FUNCTION_TRACE("acpi_bus_init");
673 660
674 status = acpi_os_initialize1(); 661 status = acpi_os_initialize1();
675 662
@@ -731,12 +718,12 @@ static int __init acpi_bus_init(void)
731 */ 718 */
732 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL); 719 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
733 720
734 return_VALUE(0); 721 return 0;
735 722
736 /* Mimic structured exception handling */ 723 /* Mimic structured exception handling */
737 error1: 724 error1:
738 acpi_terminate(); 725 acpi_terminate();
739 return_VALUE(-ENODEV); 726 return -ENODEV;
740} 727}
741 728
742decl_subsys(acpi, NULL, NULL); 729decl_subsys(acpi, NULL, NULL);
@@ -745,11 +732,10 @@ static int __init acpi_init(void)
745{ 732{
746 int result = 0; 733 int result = 0;
747 734
748 ACPI_FUNCTION_TRACE("acpi_init");
749 735
750 if (acpi_disabled) { 736 if (acpi_disabled) {
751 printk(KERN_INFO PREFIX "Interpreter disabled.\n"); 737 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
752 return_VALUE(-ENODEV); 738 return -ENODEV;
753 } 739 }
754 740
755 firmware_register(&acpi_subsys); 741 firmware_register(&acpi_subsys);
@@ -770,7 +756,7 @@ static int __init acpi_init(void)
770 } else 756 } else
771 disable_acpi(); 757 disable_acpi();
772 758
773 return_VALUE(result); 759 return result;
774} 760}
775 761
776subsys_initcall(acpi_init); 762subsys_initcall(acpi_init);