Linux 2.6.34-rc3
[pohmelfs.git] / drivers / acpi / bus.c
blobb70cd37561423bc360c0f9bf15cdfdfe731a34a8
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 #ifdef CONFIG_X86
36 #include <asm/mpspec.h>
37 #endif
38 #include <linux/pci.h>
39 #include <acpi/acpi_bus.h>
40 #include <acpi/acpi_drivers.h>
41 #include <linux/dmi.h>
43 #include "internal.h"
45 #define _COMPONENT ACPI_BUS_COMPONENT
46 ACPI_MODULE_NAME("bus");
48 struct acpi_device *acpi_root;
49 struct proc_dir_entry *acpi_root_dir;
50 EXPORT_SYMBOL(acpi_root_dir);
52 #define STRUCT_TO_INT(s) (*((int*)&s))
54 static int set_power_nocheck(const struct dmi_system_id *id)
56 printk(KERN_NOTICE PREFIX "%s detected - "
57 "disable power check in power transistion\n", id->ident);
58 acpi_power_nocheck = 1;
59 return 0;
61 static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
63 set_power_nocheck, "HP Pavilion 05", {
64 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
65 DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
66 DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
67 {},
71 /* --------------------------------------------------------------------------
72 Device Management
73 -------------------------------------------------------------------------- */
75 int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
77 acpi_status status = AE_OK;
80 if (!device)
81 return -EINVAL;
83 /* TBD: Support fixed-feature devices */
85 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
86 if (ACPI_FAILURE(status) || !*device) {
87 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
88 handle));
89 return -ENODEV;
92 return 0;
95 EXPORT_SYMBOL(acpi_bus_get_device);
97 acpi_status acpi_bus_get_status_handle(acpi_handle handle,
98 unsigned long long *sta)
100 acpi_status status;
102 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
103 if (ACPI_SUCCESS(status))
104 return AE_OK;
106 if (status == AE_NOT_FOUND) {
107 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
108 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
109 return AE_OK;
111 return status;
114 int acpi_bus_get_status(struct acpi_device *device)
116 acpi_status status;
117 unsigned long long sta;
119 status = acpi_bus_get_status_handle(device->handle, &sta);
120 if (ACPI_FAILURE(status))
121 return -ENODEV;
123 STRUCT_TO_INT(device->status) = (int) sta;
125 if (device->status.functional && !device->status.present) {
126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
127 "functional but not present;\n",
128 device->pnp.bus_id,
129 (u32) STRUCT_TO_INT(device->status)));
132 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
133 device->pnp.bus_id,
134 (u32) STRUCT_TO_INT(device->status)));
135 return 0;
137 EXPORT_SYMBOL(acpi_bus_get_status);
139 void acpi_bus_private_data_handler(acpi_handle handle,
140 void *context)
142 return;
144 EXPORT_SYMBOL(acpi_bus_private_data_handler);
146 int acpi_bus_get_private_data(acpi_handle handle, void **data)
148 acpi_status status = AE_OK;
150 if (!*data)
151 return -EINVAL;
153 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
154 if (ACPI_FAILURE(status) || !*data) {
155 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
156 handle));
157 return -ENODEV;
160 return 0;
162 EXPORT_SYMBOL(acpi_bus_get_private_data);
164 /* --------------------------------------------------------------------------
165 Power Management
166 -------------------------------------------------------------------------- */
168 int acpi_bus_get_power(acpi_handle handle, int *state)
170 int result = 0;
171 acpi_status status = 0;
172 struct acpi_device *device = NULL;
173 unsigned long long psc = 0;
176 result = acpi_bus_get_device(handle, &device);
177 if (result)
178 return result;
180 *state = ACPI_STATE_UNKNOWN;
182 if (!device->flags.power_manageable) {
183 /* TBD: Non-recursive algorithm for walking up hierarchy */
184 if (device->parent)
185 *state = device->parent->power.state;
186 else
187 *state = ACPI_STATE_D0;
188 } else {
190 * Get the device's power state either directly (via _PSC) or
191 * indirectly (via power resources).
193 if (device->power.flags.power_resources) {
194 result = acpi_power_get_inferred_state(device);
195 if (result)
196 return result;
197 } else if (device->power.flags.explicit_get) {
198 status = acpi_evaluate_integer(device->handle, "_PSC",
199 NULL, &psc);
200 if (ACPI_FAILURE(status))
201 return -ENODEV;
202 device->power.state = (int)psc;
205 *state = device->power.state;
208 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
209 device->pnp.bus_id, device->power.state));
211 return 0;
214 EXPORT_SYMBOL(acpi_bus_get_power);
216 int acpi_bus_set_power(acpi_handle handle, int state)
218 int result = 0;
219 acpi_status status = AE_OK;
220 struct acpi_device *device = NULL;
221 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
224 result = acpi_bus_get_device(handle, &device);
225 if (result)
226 return result;
228 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
229 return -EINVAL;
231 /* Make sure this is a valid target state */
233 if (!device->flags.power_manageable) {
234 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
235 kobject_name(&device->dev.kobj)));
236 return -ENODEV;
239 * Get device's current power state
241 if (!acpi_power_nocheck) {
243 * Maybe the incorrect power state is returned on the bogus
244 * bios, which is different with the real power state.
245 * For example: the bios returns D0 state and the real power
246 * state is D3. OS expects to set the device to D0 state. In
247 * such case if OS uses the power state returned by the BIOS,
248 * the device can't be transisted to the correct power state.
249 * So if the acpi_power_nocheck is set, it is unnecessary to
250 * get the power state by calling acpi_bus_get_power.
252 acpi_bus_get_power(device->handle, &device->power.state);
254 if ((state == device->power.state) && !device->flags.force_power_state) {
255 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
256 state));
257 return 0;
260 if (!device->power.states[state].flags.valid) {
261 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
262 return -ENODEV;
264 if (device->parent && (state < device->parent->power.state)) {
265 printk(KERN_WARNING PREFIX
266 "Cannot set device to a higher-powered"
267 " state than parent\n");
268 return -ENODEV;
272 * Transition Power
273 * ----------------
274 * On transitions to a high-powered state we first apply power (via
275 * power resources) then evalute _PSx. Conversly for transitions to
276 * a lower-powered state.
278 if (state < device->power.state) {
279 if (device->power.flags.power_resources) {
280 result = acpi_power_transition(device, state);
281 if (result)
282 goto end;
284 if (device->power.states[state].flags.explicit_set) {
285 status = acpi_evaluate_object(device->handle,
286 object_name, NULL, NULL);
287 if (ACPI_FAILURE(status)) {
288 result = -ENODEV;
289 goto end;
292 } else {
293 if (device->power.states[state].flags.explicit_set) {
294 status = acpi_evaluate_object(device->handle,
295 object_name, NULL, NULL);
296 if (ACPI_FAILURE(status)) {
297 result = -ENODEV;
298 goto end;
301 if (device->power.flags.power_resources) {
302 result = acpi_power_transition(device, state);
303 if (result)
304 goto end;
308 end:
309 if (result)
310 printk(KERN_WARNING PREFIX
311 "Device [%s] failed to transition to D%d\n",
312 device->pnp.bus_id, state);
313 else {
314 device->power.state = state;
315 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
316 "Device [%s] transitioned to D%d\n",
317 device->pnp.bus_id, state));
320 return result;
323 EXPORT_SYMBOL(acpi_bus_set_power);
325 bool acpi_bus_power_manageable(acpi_handle handle)
327 struct acpi_device *device;
328 int result;
330 result = acpi_bus_get_device(handle, &device);
331 return result ? false : device->flags.power_manageable;
334 EXPORT_SYMBOL(acpi_bus_power_manageable);
336 bool acpi_bus_can_wakeup(acpi_handle handle)
338 struct acpi_device *device;
339 int result;
341 result = acpi_bus_get_device(handle, &device);
342 return result ? false : device->wakeup.flags.valid;
345 EXPORT_SYMBOL(acpi_bus_can_wakeup);
347 static void acpi_print_osc_error(acpi_handle handle,
348 struct acpi_osc_context *context, char *error)
350 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
351 int i;
353 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
354 printk(KERN_DEBUG "%s\n", error);
355 else {
356 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
357 kfree(buffer.pointer);
359 printk(KERN_DEBUG"_OSC request data:");
360 for (i = 0; i < context->cap.length; i += sizeof(u32))
361 printk("%x ", *((u32 *)(context->cap.pointer + i)));
362 printk("\n");
365 static u8 hex_val(unsigned char c)
367 return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10;
370 static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
372 int i;
373 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
374 24, 26, 28, 30, 32, 34};
376 if (strlen(str) != 36)
377 return AE_BAD_PARAMETER;
378 for (i = 0; i < 36; i++) {
379 if (i == 8 || i == 13 || i == 18 || i == 23) {
380 if (str[i] != '-')
381 return AE_BAD_PARAMETER;
382 } else if (!isxdigit(str[i]))
383 return AE_BAD_PARAMETER;
385 for (i = 0; i < 16; i++) {
386 uuid[i] = hex_val(str[opc_map_to_uuid[i]]) << 4;
387 uuid[i] |= hex_val(str[opc_map_to_uuid[i] + 1]);
389 return AE_OK;
392 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
394 acpi_status status;
395 struct acpi_object_list input;
396 union acpi_object in_params[4];
397 union acpi_object *out_obj;
398 u8 uuid[16];
399 u32 errors;
400 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
402 if (!context)
403 return AE_ERROR;
404 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
405 return AE_ERROR;
406 context->ret.length = ACPI_ALLOCATE_BUFFER;
407 context->ret.pointer = NULL;
409 /* Setting up input parameters */
410 input.count = 4;
411 input.pointer = in_params;
412 in_params[0].type = ACPI_TYPE_BUFFER;
413 in_params[0].buffer.length = 16;
414 in_params[0].buffer.pointer = uuid;
415 in_params[1].type = ACPI_TYPE_INTEGER;
416 in_params[1].integer.value = context->rev;
417 in_params[2].type = ACPI_TYPE_INTEGER;
418 in_params[2].integer.value = context->cap.length/sizeof(u32);
419 in_params[3].type = ACPI_TYPE_BUFFER;
420 in_params[3].buffer.length = context->cap.length;
421 in_params[3].buffer.pointer = context->cap.pointer;
423 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
424 if (ACPI_FAILURE(status))
425 return status;
427 if (!output.length)
428 return AE_NULL_OBJECT;
430 out_obj = output.pointer;
431 if (out_obj->type != ACPI_TYPE_BUFFER
432 || out_obj->buffer.length != context->cap.length) {
433 acpi_print_osc_error(handle, context,
434 "_OSC evaluation returned wrong type");
435 status = AE_TYPE;
436 goto out_kfree;
438 /* Need to ignore the bit0 in result code */
439 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
440 if (errors) {
441 if (errors & OSC_REQUEST_ERROR)
442 acpi_print_osc_error(handle, context,
443 "_OSC request failed");
444 if (errors & OSC_INVALID_UUID_ERROR)
445 acpi_print_osc_error(handle, context,
446 "_OSC invalid UUID");
447 if (errors & OSC_INVALID_REVISION_ERROR)
448 acpi_print_osc_error(handle, context,
449 "_OSC invalid revision");
450 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
451 if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
452 & OSC_QUERY_ENABLE)
453 goto out_success;
454 status = AE_SUPPORT;
455 goto out_kfree;
457 status = AE_ERROR;
458 goto out_kfree;
460 out_success:
461 context->ret.length = out_obj->buffer.length;
462 context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
463 if (!context->ret.pointer) {
464 status = AE_NO_MEMORY;
465 goto out_kfree;
467 memcpy(context->ret.pointer, out_obj->buffer.pointer,
468 context->ret.length);
469 status = AE_OK;
471 out_kfree:
472 kfree(output.pointer);
473 if (status != AE_OK)
474 context->ret.pointer = NULL;
475 return status;
477 EXPORT_SYMBOL(acpi_run_osc);
479 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
480 static void acpi_bus_osc_support(void)
482 u32 capbuf[2];
483 struct acpi_osc_context context = {
484 .uuid_str = sb_uuid_str,
485 .rev = 1,
486 .cap.length = 8,
487 .cap.pointer = capbuf,
489 acpi_handle handle;
491 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
492 capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
493 #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
494 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
495 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
496 #endif
498 #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
499 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
500 #endif
501 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
502 return;
503 if (ACPI_SUCCESS(acpi_run_osc(handle, &context)))
504 kfree(context.ret.pointer);
505 /* do we need to check the returned cap? Sounds no */
508 /* --------------------------------------------------------------------------
509 Event Management
510 -------------------------------------------------------------------------- */
512 #ifdef CONFIG_ACPI_PROC_EVENT
513 static DEFINE_SPINLOCK(acpi_bus_event_lock);
515 LIST_HEAD(acpi_bus_event_list);
516 DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
518 extern int event_is_open;
520 int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
522 struct acpi_bus_event *event;
523 unsigned long flags = 0;
525 /* drop event on the floor if no one's listening */
526 if (!event_is_open)
527 return 0;
529 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
530 if (!event)
531 return -ENOMEM;
533 strcpy(event->device_class, device_class);
534 strcpy(event->bus_id, bus_id);
535 event->type = type;
536 event->data = data;
538 spin_lock_irqsave(&acpi_bus_event_lock, flags);
539 list_add_tail(&event->node, &acpi_bus_event_list);
540 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
542 wake_up_interruptible(&acpi_bus_event_queue);
544 return 0;
548 EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
550 int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
552 if (!device)
553 return -EINVAL;
554 return acpi_bus_generate_proc_event4(device->pnp.device_class,
555 device->pnp.bus_id, type, data);
558 EXPORT_SYMBOL(acpi_bus_generate_proc_event);
560 int acpi_bus_receive_event(struct acpi_bus_event *event)
562 unsigned long flags = 0;
563 struct acpi_bus_event *entry = NULL;
565 DECLARE_WAITQUEUE(wait, current);
568 if (!event)
569 return -EINVAL;
571 if (list_empty(&acpi_bus_event_list)) {
573 set_current_state(TASK_INTERRUPTIBLE);
574 add_wait_queue(&acpi_bus_event_queue, &wait);
576 if (list_empty(&acpi_bus_event_list))
577 schedule();
579 remove_wait_queue(&acpi_bus_event_queue, &wait);
580 set_current_state(TASK_RUNNING);
582 if (signal_pending(current))
583 return -ERESTARTSYS;
586 spin_lock_irqsave(&acpi_bus_event_lock, flags);
587 if (!list_empty(&acpi_bus_event_list)) {
588 entry = list_entry(acpi_bus_event_list.next,
589 struct acpi_bus_event, node);
590 list_del(&entry->node);
592 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
594 if (!entry)
595 return -ENODEV;
597 memcpy(event, entry, sizeof(struct acpi_bus_event));
599 kfree(entry);
601 return 0;
604 #endif /* CONFIG_ACPI_PROC_EVENT */
606 /* --------------------------------------------------------------------------
607 Notification Handling
608 -------------------------------------------------------------------------- */
610 static void acpi_bus_check_device(acpi_handle handle)
612 struct acpi_device *device;
613 acpi_status status;
614 struct acpi_device_status old_status;
616 if (acpi_bus_get_device(handle, &device))
617 return;
618 if (!device)
619 return;
621 old_status = device->status;
624 * Make sure this device's parent is present before we go about
625 * messing with the device.
627 if (device->parent && !device->parent->status.present) {
628 device->status = device->parent->status;
629 return;
632 status = acpi_bus_get_status(device);
633 if (ACPI_FAILURE(status))
634 return;
636 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
637 return;
640 * Device Insertion/Removal
642 if ((device->status.present) && !(old_status.present)) {
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
644 /* TBD: Handle device insertion */
645 } else if (!(device->status.present) && (old_status.present)) {
646 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
647 /* TBD: Handle device removal */
651 static void acpi_bus_check_scope(acpi_handle handle)
653 /* Status Change? */
654 acpi_bus_check_device(handle);
657 * TBD: Enumerate child devices within this device's scope and
658 * run acpi_bus_check_device()'s on them.
662 static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
663 int register_acpi_bus_notifier(struct notifier_block *nb)
665 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
667 EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
669 void unregister_acpi_bus_notifier(struct notifier_block *nb)
671 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
673 EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
676 * acpi_bus_notify
677 * ---------------
678 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
680 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
682 struct acpi_device *device = NULL;
683 struct acpi_driver *driver;
685 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
686 type, handle));
688 blocking_notifier_call_chain(&acpi_bus_notify_list,
689 type, (void *)handle);
691 switch (type) {
693 case ACPI_NOTIFY_BUS_CHECK:
694 acpi_bus_check_scope(handle);
696 * TBD: We'll need to outsource certain events to non-ACPI
697 * drivers via the device manager (device.c).
699 break;
701 case ACPI_NOTIFY_DEVICE_CHECK:
702 acpi_bus_check_device(handle);
704 * TBD: We'll need to outsource certain events to non-ACPI
705 * drivers via the device manager (device.c).
707 break;
709 case ACPI_NOTIFY_DEVICE_WAKE:
710 /* TBD */
711 break;
713 case ACPI_NOTIFY_EJECT_REQUEST:
714 /* TBD */
715 break;
717 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
718 /* TBD: Exactly what does 'light' mean? */
719 break;
721 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
722 /* TBD */
723 break;
725 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
726 /* TBD */
727 break;
729 case ACPI_NOTIFY_POWER_FAULT:
730 /* TBD */
731 break;
733 default:
734 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
735 "Received unknown/unsupported notification [%08x]\n",
736 type));
737 break;
740 acpi_bus_get_device(handle, &device);
741 if (device) {
742 driver = device->driver;
743 if (driver && driver->ops.notify &&
744 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
745 driver->ops.notify(device, type);
749 /* --------------------------------------------------------------------------
750 Initialization/Cleanup
751 -------------------------------------------------------------------------- */
753 static int __init acpi_bus_init_irq(void)
755 acpi_status status = AE_OK;
756 union acpi_object arg = { ACPI_TYPE_INTEGER };
757 struct acpi_object_list arg_list = { 1, &arg };
758 char *message = NULL;
762 * Let the system know what interrupt model we are using by
763 * evaluating the \_PIC object, if exists.
766 switch (acpi_irq_model) {
767 case ACPI_IRQ_MODEL_PIC:
768 message = "PIC";
769 break;
770 case ACPI_IRQ_MODEL_IOAPIC:
771 message = "IOAPIC";
772 break;
773 case ACPI_IRQ_MODEL_IOSAPIC:
774 message = "IOSAPIC";
775 break;
776 case ACPI_IRQ_MODEL_PLATFORM:
777 message = "platform specific model";
778 break;
779 default:
780 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
781 return -ENODEV;
784 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
786 arg.integer.value = acpi_irq_model;
788 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
789 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
790 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
791 return -ENODEV;
794 return 0;
797 u8 acpi_gbl_permanent_mmap;
800 void __init acpi_early_init(void)
802 acpi_status status = AE_OK;
804 if (acpi_disabled)
805 return;
807 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
809 /* enable workarounds, unless strict ACPI spec. compliance */
810 if (!acpi_strict)
811 acpi_gbl_enable_interpreter_slack = TRUE;
813 acpi_gbl_permanent_mmap = 1;
815 status = acpi_reallocate_root_table();
816 if (ACPI_FAILURE(status)) {
817 printk(KERN_ERR PREFIX
818 "Unable to reallocate ACPI tables\n");
819 goto error0;
822 status = acpi_initialize_subsystem();
823 if (ACPI_FAILURE(status)) {
824 printk(KERN_ERR PREFIX
825 "Unable to initialize the ACPI Interpreter\n");
826 goto error0;
829 status = acpi_load_tables();
830 if (ACPI_FAILURE(status)) {
831 printk(KERN_ERR PREFIX
832 "Unable to load the System Description Tables\n");
833 goto error0;
836 #ifdef CONFIG_X86
837 if (!acpi_ioapic) {
838 /* compatible (0) means level (3) */
839 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
840 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
841 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
843 /* Set PIC-mode SCI trigger type */
844 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
845 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
846 } else {
848 * now that acpi_gbl_FADT is initialized,
849 * update it with result from INT_SRC_OVR parsing
851 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
853 #endif
855 status =
856 acpi_enable_subsystem(~
857 (ACPI_NO_HARDWARE_INIT |
858 ACPI_NO_ACPI_ENABLE));
859 if (ACPI_FAILURE(status)) {
860 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
861 goto error0;
864 return;
866 error0:
867 disable_acpi();
868 return;
871 static int __init acpi_bus_init(void)
873 int result = 0;
874 acpi_status status = AE_OK;
875 extern acpi_status acpi_os_initialize1(void);
877 acpi_os_initialize1();
879 status =
880 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
881 if (ACPI_FAILURE(status)) {
882 printk(KERN_ERR PREFIX
883 "Unable to start the ACPI Interpreter\n");
884 goto error1;
888 * ACPI 2.0 requires the EC driver to be loaded and work before
889 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
890 * is called).
892 * This is accomplished by looking for the ECDT table, and getting
893 * the EC parameters out of that.
895 status = acpi_ec_ecdt_probe();
896 /* Ignore result. Not having an ECDT is not fatal. */
898 acpi_bus_osc_support();
900 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
901 if (ACPI_FAILURE(status)) {
902 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
903 goto error1;
906 acpi_early_processor_set_pdc();
909 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
910 * is necessary to enable it as early as possible.
912 acpi_boot_ec_enable();
914 printk(KERN_INFO PREFIX "Interpreter enabled\n");
916 /* Initialize sleep structures */
917 acpi_sleep_init();
920 * Get the system interrupt model and evaluate \_PIC.
922 result = acpi_bus_init_irq();
923 if (result)
924 goto error1;
927 * Register the for all standard device notifications.
929 status =
930 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
931 &acpi_bus_notify, NULL);
932 if (ACPI_FAILURE(status)) {
933 printk(KERN_ERR PREFIX
934 "Unable to register for device notifications\n");
935 goto error1;
939 * Create the top ACPI proc directory
941 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
943 return 0;
945 /* Mimic structured exception handling */
946 error1:
947 acpi_terminate();
948 return -ENODEV;
951 struct kobject *acpi_kobj;
953 static int __init acpi_init(void)
955 int result = 0;
958 if (acpi_disabled) {
959 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
960 return -ENODEV;
963 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
964 if (!acpi_kobj) {
965 printk(KERN_WARNING "%s: kset create error\n", __func__);
966 acpi_kobj = NULL;
969 init_acpi_device_notify();
970 result = acpi_bus_init();
972 if (!result) {
973 pci_mmcfg_late_init();
974 if (!(pm_flags & PM_APM))
975 pm_flags |= PM_ACPI;
976 else {
977 printk(KERN_INFO PREFIX
978 "APM is already active, exiting\n");
979 disable_acpi();
980 result = -ENODEV;
982 } else
983 disable_acpi();
985 if (acpi_disabled)
986 return result;
989 * If the laptop falls into the DMI check table, the power state check
990 * will be disabled in the course of device power transistion.
992 dmi_check_system(power_nocheck_dmi_table);
994 acpi_scan_init();
995 acpi_ec_init();
996 acpi_power_init();
997 acpi_system_init();
998 acpi_debug_init();
999 acpi_sleep_proc_init();
1000 acpi_wakeup_device_init();
1001 return result;
1004 subsys_initcall(acpi_init);