EHCI: don't rescan interrupt QHs needlessly
[linux-2.6.git] / drivers / acpi / bus.c
blob9749980ca6ca6c7669aa8c669a1102b881a2929f
1 /*
2 * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/ioport.h>
28 #include <linux/kernel.h>
29 #include <linux/list.h>
30 #include <linux/sched.h>
31 #include <linux/pm.h>
32 #include <linux/device.h>
33 #include <linux/proc_fs.h>
34 #include <linux/acpi.h>
35 #include <linux/slab.h>
36 #ifdef CONFIG_X86
37 #include <asm/mpspec.h>
38 #endif
39 #include <linux/pci.h>
40 #include <acpi/acpi_bus.h>
41 #include <acpi/acpi_drivers.h>
42 #include <linux/dmi.h>
43 #include <linux/suspend.h>
45 #include "internal.h"
47 #define _COMPONENT ACPI_BUS_COMPONENT
48 ACPI_MODULE_NAME("bus");
50 struct acpi_device *acpi_root;
51 struct proc_dir_entry *acpi_root_dir;
52 EXPORT_SYMBOL(acpi_root_dir);
54 #define STRUCT_TO_INT(s) (*((int*)&s))
57 #ifdef CONFIG_X86
58 static int set_copy_dsdt(const struct dmi_system_id *id)
60 printk(KERN_NOTICE "%s detected - "
61 "force copy of DSDT to local memory\n", id->ident);
62 acpi_gbl_copy_dsdt_locally = 1;
63 return 0;
66 static struct dmi_system_id dsdt_dmi_table[] __initdata = {
68 * Invoke DSDT corruption work-around on all Toshiba Satellite.
69 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
72 .callback = set_copy_dsdt,
73 .ident = "TOSHIBA Satellite",
74 .matches = {
75 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
76 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
81 #else
82 static struct dmi_system_id dsdt_dmi_table[] __initdata = {
85 #endif
87 /* --------------------------------------------------------------------------
88 Device Management
89 -------------------------------------------------------------------------- */
91 int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
93 acpi_status status = AE_OK;
96 if (!device)
97 return -EINVAL;
99 /* TBD: Support fixed-feature devices */
101 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
102 if (ACPI_FAILURE(status) || !*device) {
103 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
104 handle));
105 return -ENODEV;
108 return 0;
111 EXPORT_SYMBOL(acpi_bus_get_device);
113 acpi_status acpi_bus_get_status_handle(acpi_handle handle,
114 unsigned long long *sta)
116 acpi_status status;
118 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
119 if (ACPI_SUCCESS(status))
120 return AE_OK;
122 if (status == AE_NOT_FOUND) {
123 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
124 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
125 return AE_OK;
127 return status;
130 int acpi_bus_get_status(struct acpi_device *device)
132 acpi_status status;
133 unsigned long long sta;
135 status = acpi_bus_get_status_handle(device->handle, &sta);
136 if (ACPI_FAILURE(status))
137 return -ENODEV;
139 STRUCT_TO_INT(device->status) = (int) sta;
141 if (device->status.functional && !device->status.present) {
142 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
143 "functional but not present;\n",
144 device->pnp.bus_id,
145 (u32) STRUCT_TO_INT(device->status)));
148 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
149 device->pnp.bus_id,
150 (u32) STRUCT_TO_INT(device->status)));
151 return 0;
153 EXPORT_SYMBOL(acpi_bus_get_status);
155 void acpi_bus_private_data_handler(acpi_handle handle,
156 void *context)
158 return;
160 EXPORT_SYMBOL(acpi_bus_private_data_handler);
162 int acpi_bus_get_private_data(acpi_handle handle, void **data)
164 acpi_status status = AE_OK;
166 if (!*data)
167 return -EINVAL;
169 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
170 if (ACPI_FAILURE(status) || !*data) {
171 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
172 handle));
173 return -ENODEV;
176 return 0;
178 EXPORT_SYMBOL(acpi_bus_get_private_data);
180 /* --------------------------------------------------------------------------
181 Power Management
182 -------------------------------------------------------------------------- */
184 static int __acpi_bus_get_power(struct acpi_device *device, int *state)
186 int result = 0;
187 acpi_status status = 0;
188 unsigned long long psc = 0;
190 if (!device || !state)
191 return -EINVAL;
193 *state = ACPI_STATE_UNKNOWN;
195 if (device->flags.power_manageable) {
197 * Get the device's power state either directly (via _PSC) or
198 * indirectly (via power resources).
200 if (device->power.flags.power_resources) {
201 result = acpi_power_get_inferred_state(device, state);
202 if (result)
203 return result;
204 } else if (device->power.flags.explicit_get) {
205 status = acpi_evaluate_integer(device->handle, "_PSC",
206 NULL, &psc);
207 if (ACPI_FAILURE(status))
208 return -ENODEV;
209 *state = (int)psc;
211 } else {
212 /* TBD: Non-recursive algorithm for walking up hierarchy. */
213 *state = device->parent ?
214 device->parent->power.state : ACPI_STATE_D0;
217 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
218 device->pnp.bus_id, *state));
220 return 0;
224 static int __acpi_bus_set_power(struct acpi_device *device, int state)
226 int result = 0;
227 acpi_status status = AE_OK;
228 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
230 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
231 return -EINVAL;
233 /* Make sure this is a valid target state */
235 if (state == device->power.state) {
236 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
237 state));
238 return 0;
241 if (!device->power.states[state].flags.valid) {
242 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
243 return -ENODEV;
245 if (device->parent && (state < device->parent->power.state)) {
246 printk(KERN_WARNING PREFIX
247 "Cannot set device to a higher-powered"
248 " state than parent\n");
249 return -ENODEV;
253 * Transition Power
254 * ----------------
255 * On transitions to a high-powered state we first apply power (via
256 * power resources) then evalute _PSx. Conversly for transitions to
257 * a lower-powered state.
259 if (state < device->power.state) {
260 if (device->power.flags.power_resources) {
261 result = acpi_power_transition(device, state);
262 if (result)
263 goto end;
265 if (device->power.states[state].flags.explicit_set) {
266 status = acpi_evaluate_object(device->handle,
267 object_name, NULL, NULL);
268 if (ACPI_FAILURE(status)) {
269 result = -ENODEV;
270 goto end;
273 } else {
274 if (device->power.states[state].flags.explicit_set) {
275 status = acpi_evaluate_object(device->handle,
276 object_name, NULL, NULL);
277 if (ACPI_FAILURE(status)) {
278 result = -ENODEV;
279 goto end;
282 if (device->power.flags.power_resources) {
283 result = acpi_power_transition(device, state);
284 if (result)
285 goto end;
289 end:
290 if (result)
291 printk(KERN_WARNING PREFIX
292 "Device [%s] failed to transition to D%d\n",
293 device->pnp.bus_id, state);
294 else {
295 device->power.state = state;
296 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
297 "Device [%s] transitioned to D%d\n",
298 device->pnp.bus_id, state));
301 return result;
305 int acpi_bus_set_power(acpi_handle handle, int state)
307 struct acpi_device *device;
308 int result;
310 result = acpi_bus_get_device(handle, &device);
311 if (result)
312 return result;
314 if (!device->flags.power_manageable) {
315 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
316 "Device [%s] is not power manageable\n",
317 dev_name(&device->dev)));
318 return -ENODEV;
321 return __acpi_bus_set_power(device, state);
323 EXPORT_SYMBOL(acpi_bus_set_power);
326 int acpi_bus_init_power(struct acpi_device *device)
328 int state;
329 int result;
331 if (!device)
332 return -EINVAL;
334 device->power.state = ACPI_STATE_UNKNOWN;
336 result = __acpi_bus_get_power(device, &state);
337 if (result)
338 return result;
340 if (device->power.flags.power_resources)
341 result = acpi_power_on_resources(device, state);
343 if (!result)
344 device->power.state = state;
346 return result;
350 int acpi_bus_update_power(acpi_handle handle, int *state_p)
352 struct acpi_device *device;
353 int state;
354 int result;
356 result = acpi_bus_get_device(handle, &device);
357 if (result)
358 return result;
360 result = __acpi_bus_get_power(device, &state);
361 if (result)
362 return result;
364 result = __acpi_bus_set_power(device, state);
365 if (!result && state_p)
366 *state_p = state;
368 return result;
370 EXPORT_SYMBOL_GPL(acpi_bus_update_power);
373 bool acpi_bus_power_manageable(acpi_handle handle)
375 struct acpi_device *device;
376 int result;
378 result = acpi_bus_get_device(handle, &device);
379 return result ? false : device->flags.power_manageable;
382 EXPORT_SYMBOL(acpi_bus_power_manageable);
384 bool acpi_bus_can_wakeup(acpi_handle handle)
386 struct acpi_device *device;
387 int result;
389 result = acpi_bus_get_device(handle, &device);
390 return result ? false : device->wakeup.flags.valid;
393 EXPORT_SYMBOL(acpi_bus_can_wakeup);
395 static void acpi_print_osc_error(acpi_handle handle,
396 struct acpi_osc_context *context, char *error)
398 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
399 int i;
401 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
402 printk(KERN_DEBUG "%s\n", error);
403 else {
404 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
405 kfree(buffer.pointer);
407 printk(KERN_DEBUG"_OSC request data:");
408 for (i = 0; i < context->cap.length; i += sizeof(u32))
409 printk("%x ", *((u32 *)(context->cap.pointer + i)));
410 printk("\n");
413 static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
415 int i;
416 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
417 24, 26, 28, 30, 32, 34};
419 if (strlen(str) != 36)
420 return AE_BAD_PARAMETER;
421 for (i = 0; i < 36; i++) {
422 if (i == 8 || i == 13 || i == 18 || i == 23) {
423 if (str[i] != '-')
424 return AE_BAD_PARAMETER;
425 } else if (!isxdigit(str[i]))
426 return AE_BAD_PARAMETER;
428 for (i = 0; i < 16; i++) {
429 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
430 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
432 return AE_OK;
435 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
437 acpi_status status;
438 struct acpi_object_list input;
439 union acpi_object in_params[4];
440 union acpi_object *out_obj;
441 u8 uuid[16];
442 u32 errors;
443 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
445 if (!context)
446 return AE_ERROR;
447 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
448 return AE_ERROR;
449 context->ret.length = ACPI_ALLOCATE_BUFFER;
450 context->ret.pointer = NULL;
452 /* Setting up input parameters */
453 input.count = 4;
454 input.pointer = in_params;
455 in_params[0].type = ACPI_TYPE_BUFFER;
456 in_params[0].buffer.length = 16;
457 in_params[0].buffer.pointer = uuid;
458 in_params[1].type = ACPI_TYPE_INTEGER;
459 in_params[1].integer.value = context->rev;
460 in_params[2].type = ACPI_TYPE_INTEGER;
461 in_params[2].integer.value = context->cap.length/sizeof(u32);
462 in_params[3].type = ACPI_TYPE_BUFFER;
463 in_params[3].buffer.length = context->cap.length;
464 in_params[3].buffer.pointer = context->cap.pointer;
466 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
467 if (ACPI_FAILURE(status))
468 return status;
470 if (!output.length)
471 return AE_NULL_OBJECT;
473 out_obj = output.pointer;
474 if (out_obj->type != ACPI_TYPE_BUFFER
475 || out_obj->buffer.length != context->cap.length) {
476 acpi_print_osc_error(handle, context,
477 "_OSC evaluation returned wrong type");
478 status = AE_TYPE;
479 goto out_kfree;
481 /* Need to ignore the bit0 in result code */
482 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
483 if (errors) {
484 if (errors & OSC_REQUEST_ERROR)
485 acpi_print_osc_error(handle, context,
486 "_OSC request failed");
487 if (errors & OSC_INVALID_UUID_ERROR)
488 acpi_print_osc_error(handle, context,
489 "_OSC invalid UUID");
490 if (errors & OSC_INVALID_REVISION_ERROR)
491 acpi_print_osc_error(handle, context,
492 "_OSC invalid revision");
493 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
494 if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
495 & OSC_QUERY_ENABLE)
496 goto out_success;
497 status = AE_SUPPORT;
498 goto out_kfree;
500 status = AE_ERROR;
501 goto out_kfree;
503 out_success:
504 context->ret.length = out_obj->buffer.length;
505 context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
506 if (!context->ret.pointer) {
507 status = AE_NO_MEMORY;
508 goto out_kfree;
510 memcpy(context->ret.pointer, out_obj->buffer.pointer,
511 context->ret.length);
512 status = AE_OK;
514 out_kfree:
515 kfree(output.pointer);
516 if (status != AE_OK)
517 context->ret.pointer = NULL;
518 return status;
520 EXPORT_SYMBOL(acpi_run_osc);
522 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
523 static void acpi_bus_osc_support(void)
525 u32 capbuf[2];
526 struct acpi_osc_context context = {
527 .uuid_str = sb_uuid_str,
528 .rev = 1,
529 .cap.length = 8,
530 .cap.pointer = capbuf,
532 acpi_handle handle;
534 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
535 capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
536 #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
537 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
538 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
539 #endif
541 #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
542 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
543 #endif
544 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
545 return;
546 if (ACPI_SUCCESS(acpi_run_osc(handle, &context)))
547 kfree(context.ret.pointer);
548 /* do we need to check the returned cap? Sounds no */
551 /* --------------------------------------------------------------------------
552 Event Management
553 -------------------------------------------------------------------------- */
555 #ifdef CONFIG_ACPI_PROC_EVENT
556 static DEFINE_SPINLOCK(acpi_bus_event_lock);
558 LIST_HEAD(acpi_bus_event_list);
559 DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
561 extern int event_is_open;
563 int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
565 struct acpi_bus_event *event;
566 unsigned long flags = 0;
568 /* drop event on the floor if no one's listening */
569 if (!event_is_open)
570 return 0;
572 event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
573 if (!event)
574 return -ENOMEM;
576 strcpy(event->device_class, device_class);
577 strcpy(event->bus_id, bus_id);
578 event->type = type;
579 event->data = data;
581 spin_lock_irqsave(&acpi_bus_event_lock, flags);
582 list_add_tail(&event->node, &acpi_bus_event_list);
583 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
585 wake_up_interruptible(&acpi_bus_event_queue);
587 return 0;
591 EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
593 int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
595 if (!device)
596 return -EINVAL;
597 return acpi_bus_generate_proc_event4(device->pnp.device_class,
598 device->pnp.bus_id, type, data);
601 EXPORT_SYMBOL(acpi_bus_generate_proc_event);
603 int acpi_bus_receive_event(struct acpi_bus_event *event)
605 unsigned long flags = 0;
606 struct acpi_bus_event *entry = NULL;
608 DECLARE_WAITQUEUE(wait, current);
611 if (!event)
612 return -EINVAL;
614 if (list_empty(&acpi_bus_event_list)) {
616 set_current_state(TASK_INTERRUPTIBLE);
617 add_wait_queue(&acpi_bus_event_queue, &wait);
619 if (list_empty(&acpi_bus_event_list))
620 schedule();
622 remove_wait_queue(&acpi_bus_event_queue, &wait);
623 set_current_state(TASK_RUNNING);
625 if (signal_pending(current))
626 return -ERESTARTSYS;
629 spin_lock_irqsave(&acpi_bus_event_lock, flags);
630 if (!list_empty(&acpi_bus_event_list)) {
631 entry = list_entry(acpi_bus_event_list.next,
632 struct acpi_bus_event, node);
633 list_del(&entry->node);
635 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
637 if (!entry)
638 return -ENODEV;
640 memcpy(event, entry, sizeof(struct acpi_bus_event));
642 kfree(entry);
644 return 0;
647 #endif /* CONFIG_ACPI_PROC_EVENT */
649 /* --------------------------------------------------------------------------
650 Notification Handling
651 -------------------------------------------------------------------------- */
653 static void acpi_bus_check_device(acpi_handle handle)
655 struct acpi_device *device;
656 acpi_status status;
657 struct acpi_device_status old_status;
659 if (acpi_bus_get_device(handle, &device))
660 return;
661 if (!device)
662 return;
664 old_status = device->status;
667 * Make sure this device's parent is present before we go about
668 * messing with the device.
670 if (device->parent && !device->parent->status.present) {
671 device->status = device->parent->status;
672 return;
675 status = acpi_bus_get_status(device);
676 if (ACPI_FAILURE(status))
677 return;
679 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
680 return;
683 * Device Insertion/Removal
685 if ((device->status.present) && !(old_status.present)) {
686 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
687 /* TBD: Handle device insertion */
688 } else if (!(device->status.present) && (old_status.present)) {
689 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
690 /* TBD: Handle device removal */
694 static void acpi_bus_check_scope(acpi_handle handle)
696 /* Status Change? */
697 acpi_bus_check_device(handle);
700 * TBD: Enumerate child devices within this device's scope and
701 * run acpi_bus_check_device()'s on them.
705 static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
706 int register_acpi_bus_notifier(struct notifier_block *nb)
708 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
710 EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
712 void unregister_acpi_bus_notifier(struct notifier_block *nb)
714 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
716 EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
719 * acpi_bus_notify
720 * ---------------
721 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
723 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
725 struct acpi_device *device = NULL;
726 struct acpi_driver *driver;
728 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
729 type, handle));
731 blocking_notifier_call_chain(&acpi_bus_notify_list,
732 type, (void *)handle);
734 switch (type) {
736 case ACPI_NOTIFY_BUS_CHECK:
737 acpi_bus_check_scope(handle);
739 * TBD: We'll need to outsource certain events to non-ACPI
740 * drivers via the device manager (device.c).
742 break;
744 case ACPI_NOTIFY_DEVICE_CHECK:
745 acpi_bus_check_device(handle);
747 * TBD: We'll need to outsource certain events to non-ACPI
748 * drivers via the device manager (device.c).
750 break;
752 case ACPI_NOTIFY_DEVICE_WAKE:
753 /* TBD */
754 break;
756 case ACPI_NOTIFY_EJECT_REQUEST:
757 /* TBD */
758 break;
760 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
761 /* TBD: Exactly what does 'light' mean? */
762 break;
764 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
765 /* TBD */
766 break;
768 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
769 /* TBD */
770 break;
772 case ACPI_NOTIFY_POWER_FAULT:
773 /* TBD */
774 break;
776 default:
777 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
778 "Received unknown/unsupported notification [%08x]\n",
779 type));
780 break;
783 acpi_bus_get_device(handle, &device);
784 if (device) {
785 driver = device->driver;
786 if (driver && driver->ops.notify &&
787 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
788 driver->ops.notify(device, type);
792 /* --------------------------------------------------------------------------
793 Initialization/Cleanup
794 -------------------------------------------------------------------------- */
796 static int __init acpi_bus_init_irq(void)
798 acpi_status status = AE_OK;
799 union acpi_object arg = { ACPI_TYPE_INTEGER };
800 struct acpi_object_list arg_list = { 1, &arg };
801 char *message = NULL;
805 * Let the system know what interrupt model we are using by
806 * evaluating the \_PIC object, if exists.
809 switch (acpi_irq_model) {
810 case ACPI_IRQ_MODEL_PIC:
811 message = "PIC";
812 break;
813 case ACPI_IRQ_MODEL_IOAPIC:
814 message = "IOAPIC";
815 break;
816 case ACPI_IRQ_MODEL_IOSAPIC:
817 message = "IOSAPIC";
818 break;
819 case ACPI_IRQ_MODEL_PLATFORM:
820 message = "platform specific model";
821 break;
822 default:
823 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
824 return -ENODEV;
827 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
829 arg.integer.value = acpi_irq_model;
831 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
832 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
833 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
834 return -ENODEV;
837 return 0;
840 u8 acpi_gbl_permanent_mmap;
843 void __init acpi_early_init(void)
845 acpi_status status = AE_OK;
847 if (acpi_disabled)
848 return;
850 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
852 /* enable workarounds, unless strict ACPI spec. compliance */
853 if (!acpi_strict)
854 acpi_gbl_enable_interpreter_slack = TRUE;
856 acpi_gbl_permanent_mmap = 1;
859 * If the machine falls into the DMI check table,
860 * DSDT will be copied to memory
862 dmi_check_system(dsdt_dmi_table);
864 status = acpi_reallocate_root_table();
865 if (ACPI_FAILURE(status)) {
866 printk(KERN_ERR PREFIX
867 "Unable to reallocate ACPI tables\n");
868 goto error0;
871 status = acpi_initialize_subsystem();
872 if (ACPI_FAILURE(status)) {
873 printk(KERN_ERR PREFIX
874 "Unable to initialize the ACPI Interpreter\n");
875 goto error0;
878 status = acpi_load_tables();
879 if (ACPI_FAILURE(status)) {
880 printk(KERN_ERR PREFIX
881 "Unable to load the System Description Tables\n");
882 goto error0;
885 #ifdef CONFIG_X86
886 if (!acpi_ioapic) {
887 /* compatible (0) means level (3) */
888 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
889 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
890 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
892 /* Set PIC-mode SCI trigger type */
893 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
894 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
895 } else {
897 * now that acpi_gbl_FADT is initialized,
898 * update it with result from INT_SRC_OVR parsing
900 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
902 #endif
904 status =
905 acpi_enable_subsystem(~
906 (ACPI_NO_HARDWARE_INIT |
907 ACPI_NO_ACPI_ENABLE));
908 if (ACPI_FAILURE(status)) {
909 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
910 goto error0;
913 return;
915 error0:
916 disable_acpi();
917 return;
920 static int __init acpi_bus_init(void)
922 int result = 0;
923 acpi_status status = AE_OK;
924 extern acpi_status acpi_os_initialize1(void);
926 acpi_os_initialize1();
928 status =
929 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
930 if (ACPI_FAILURE(status)) {
931 printk(KERN_ERR PREFIX
932 "Unable to start the ACPI Interpreter\n");
933 goto error1;
937 * ACPI 2.0 requires the EC driver to be loaded and work before
938 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
939 * is called).
941 * This is accomplished by looking for the ECDT table, and getting
942 * the EC parameters out of that.
944 status = acpi_ec_ecdt_probe();
945 /* Ignore result. Not having an ECDT is not fatal. */
947 acpi_bus_osc_support();
949 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
950 if (ACPI_FAILURE(status)) {
951 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
952 goto error1;
956 * _PDC control method may load dynamic SSDT tables,
957 * and we need to install the table handler before that.
959 acpi_sysfs_init();
961 acpi_early_processor_set_pdc();
964 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
965 * is necessary to enable it as early as possible.
967 acpi_boot_ec_enable();
969 printk(KERN_INFO PREFIX "Interpreter enabled\n");
971 /* Initialize sleep structures */
972 acpi_sleep_init();
975 * Get the system interrupt model and evaluate \_PIC.
977 result = acpi_bus_init_irq();
978 if (result)
979 goto error1;
982 * Register the for all standard device notifications.
984 status =
985 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
986 &acpi_bus_notify, NULL);
987 if (ACPI_FAILURE(status)) {
988 printk(KERN_ERR PREFIX
989 "Unable to register for device notifications\n");
990 goto error1;
994 * Create the top ACPI proc directory
996 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
998 return 0;
1000 /* Mimic structured exception handling */
1001 error1:
1002 acpi_terminate();
1003 return -ENODEV;
1006 struct kobject *acpi_kobj;
1008 static int __init acpi_init(void)
1010 int result;
1012 if (acpi_disabled) {
1013 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
1014 return -ENODEV;
1017 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
1018 if (!acpi_kobj) {
1019 printk(KERN_WARNING "%s: kset create error\n", __func__);
1020 acpi_kobj = NULL;
1023 init_acpi_device_notify();
1024 result = acpi_bus_init();
1025 if (result) {
1026 disable_acpi();
1027 return result;
1030 pci_mmcfg_late_init();
1031 acpi_scan_init();
1032 acpi_ec_init();
1033 acpi_debugfs_init();
1034 acpi_sleep_proc_init();
1035 acpi_wakeup_device_init();
1036 return 0;
1039 subsys_initcall(acpi_init);