Merge branch 'writeback' of git://git.kernel.dk/linux-2.6-block
[pandora-kernel.git] / drivers / acpi / bus.c
1 /*
2  *  acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
3  *
4  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5  *
6  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7  *
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.
12  *
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.
17  *
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.
21  *
22  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23  */
24
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>
42
43 #include "internal.h"
44
45 #define _COMPONENT              ACPI_BUS_COMPONENT
46 ACPI_MODULE_NAME("bus");
47
48 struct acpi_device *acpi_root;
49 struct proc_dir_entry *acpi_root_dir;
50 EXPORT_SYMBOL(acpi_root_dir);
51
52 #define STRUCT_TO_INT(s)        (*((int*)&s))
53
54 static int set_power_nocheck(const struct dmi_system_id *id)
55 {
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;
60 }
61 static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
62         {
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         {},
68 };
69
70
71 /* --------------------------------------------------------------------------
72                                 Device Management
73    -------------------------------------------------------------------------- */
74
75 int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
76 {
77         acpi_status status = AE_OK;
78
79
80         if (!device)
81                 return -EINVAL;
82
83         /* TBD: Support fixed-feature devices */
84
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;
90         }
91
92         return 0;
93 }
94
95 EXPORT_SYMBOL(acpi_bus_get_device);
96
97 int acpi_bus_get_status(struct acpi_device *device)
98 {
99         acpi_status status = AE_OK;
100         unsigned long long sta = 0;
101
102
103         if (!device)
104                 return -EINVAL;
105
106         /*
107          * Evaluate _STA if present.
108          */
109         if (device->flags.dynamic_status) {
110                 status =
111                     acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
112                 if (ACPI_FAILURE(status))
113                         return -ENODEV;
114                 STRUCT_TO_INT(device->status) = (int)sta;
115         }
116
117         /*
118          * According to ACPI spec some device can be present and functional
119          * even if the parent is not present but functional.
120          * In such conditions the child device should not inherit the status
121          * from the parent.
122          */
123         else
124                 STRUCT_TO_INT(device->status) =
125                     ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
126                     ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING;
127
128         if (device->status.functional && !device->status.present) {
129                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
130                        "functional but not present;\n",
131                         device->pnp.bus_id,
132                         (u32) STRUCT_TO_INT(device->status)));
133         }
134
135         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
136                           device->pnp.bus_id,
137                           (u32) STRUCT_TO_INT(device->status)));
138
139         return 0;
140 }
141
142 EXPORT_SYMBOL(acpi_bus_get_status);
143
144 void acpi_bus_private_data_handler(acpi_handle handle,
145                                    void *context)
146 {
147         return;
148 }
149 EXPORT_SYMBOL(acpi_bus_private_data_handler);
150
151 int acpi_bus_get_private_data(acpi_handle handle, void **data)
152 {
153         acpi_status status = AE_OK;
154
155         if (!*data)
156                 return -EINVAL;
157
158         status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
159         if (ACPI_FAILURE(status) || !*data) {
160                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
161                                 handle));
162                 return -ENODEV;
163         }
164
165         return 0;
166 }
167 EXPORT_SYMBOL(acpi_bus_get_private_data);
168
169 /* --------------------------------------------------------------------------
170                                  Power Management
171    -------------------------------------------------------------------------- */
172
173 int acpi_bus_get_power(acpi_handle handle, int *state)
174 {
175         int result = 0;
176         acpi_status status = 0;
177         struct acpi_device *device = NULL;
178         unsigned long long psc = 0;
179
180
181         result = acpi_bus_get_device(handle, &device);
182         if (result)
183                 return result;
184
185         *state = ACPI_STATE_UNKNOWN;
186
187         if (!device->flags.power_manageable) {
188                 /* TBD: Non-recursive algorithm for walking up hierarchy */
189                 if (device->parent)
190                         *state = device->parent->power.state;
191                 else
192                         *state = ACPI_STATE_D0;
193         } else {
194                 /*
195                  * Get the device's power state either directly (via _PSC) or
196                  * indirectly (via power resources).
197                  */
198                 if (device->power.flags.explicit_get) {
199                         status = acpi_evaluate_integer(device->handle, "_PSC",
200                                                        NULL, &psc);
201                         if (ACPI_FAILURE(status))
202                                 return -ENODEV;
203                         device->power.state = (int)psc;
204                 } else if (device->power.flags.power_resources) {
205                         result = acpi_power_get_inferred_state(device);
206                         if (result)
207                                 return result;
208                 }
209
210                 *state = device->power.state;
211         }
212
213         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
214                           device->pnp.bus_id, device->power.state));
215
216         return 0;
217 }
218
219 EXPORT_SYMBOL(acpi_bus_get_power);
220
221 int acpi_bus_set_power(acpi_handle handle, int state)
222 {
223         int result = 0;
224         acpi_status status = AE_OK;
225         struct acpi_device *device = NULL;
226         char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
227
228
229         result = acpi_bus_get_device(handle, &device);
230         if (result)
231                 return result;
232
233         if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
234                 return -EINVAL;
235
236         /* Make sure this is a valid target state */
237
238         if (!device->flags.power_manageable) {
239                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
240                                 kobject_name(&device->dev.kobj)));
241                 return -ENODEV;
242         }
243         /*
244          * Get device's current power state
245          */
246         if (!acpi_power_nocheck) {
247                 /*
248                  * Maybe the incorrect power state is returned on the bogus
249                  * bios, which is different with the real power state.
250                  * For example: the bios returns D0 state and the real power
251                  * state is D3. OS expects to set the device to D0 state. In
252                  * such case if OS uses the power state returned by the BIOS,
253                  * the device can't be transisted to the correct power state.
254                  * So if the acpi_power_nocheck is set, it is unnecessary to
255                  * get the power state by calling acpi_bus_get_power.
256                  */
257                 acpi_bus_get_power(device->handle, &device->power.state);
258         }
259         if ((state == device->power.state) && !device->flags.force_power_state) {
260                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
261                                   state));
262                 return 0;
263         }
264
265         if (!device->power.states[state].flags.valid) {
266                 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
267                 return -ENODEV;
268         }
269         if (device->parent && (state < device->parent->power.state)) {
270                 printk(KERN_WARNING PREFIX
271                               "Cannot set device to a higher-powered"
272                               " state than parent\n");
273                 return -ENODEV;
274         }
275
276         /*
277          * Transition Power
278          * ----------------
279          * On transitions to a high-powered state we first apply power (via
280          * power resources) then evalute _PSx.  Conversly for transitions to
281          * a lower-powered state.
282          */
283         if (state < device->power.state) {
284                 if (device->power.flags.power_resources) {
285                         result = acpi_power_transition(device, state);
286                         if (result)
287                                 goto end;
288                 }
289                 if (device->power.states[state].flags.explicit_set) {
290                         status = acpi_evaluate_object(device->handle,
291                                                       object_name, NULL, NULL);
292                         if (ACPI_FAILURE(status)) {
293                                 result = -ENODEV;
294                                 goto end;
295                         }
296                 }
297         } else {
298                 if (device->power.states[state].flags.explicit_set) {
299                         status = acpi_evaluate_object(device->handle,
300                                                       object_name, NULL, NULL);
301                         if (ACPI_FAILURE(status)) {
302                                 result = -ENODEV;
303                                 goto end;
304                         }
305                 }
306                 if (device->power.flags.power_resources) {
307                         result = acpi_power_transition(device, state);
308                         if (result)
309                                 goto end;
310                 }
311         }
312
313       end:
314         if (result)
315                 printk(KERN_WARNING PREFIX
316                               "Device [%s] failed to transition to D%d\n",
317                               device->pnp.bus_id, state);
318         else {
319                 device->power.state = state;
320                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
321                                   "Device [%s] transitioned to D%d\n",
322                                   device->pnp.bus_id, state));
323         }
324
325         return result;
326 }
327
328 EXPORT_SYMBOL(acpi_bus_set_power);
329
330 bool acpi_bus_power_manageable(acpi_handle handle)
331 {
332         struct acpi_device *device;
333         int result;
334
335         result = acpi_bus_get_device(handle, &device);
336         return result ? false : device->flags.power_manageable;
337 }
338
339 EXPORT_SYMBOL(acpi_bus_power_manageable);
340
341 bool acpi_bus_can_wakeup(acpi_handle handle)
342 {
343         struct acpi_device *device;
344         int result;
345
346         result = acpi_bus_get_device(handle, &device);
347         return result ? false : device->wakeup.flags.valid;
348 }
349
350 EXPORT_SYMBOL(acpi_bus_can_wakeup);
351
352 /* --------------------------------------------------------------------------
353                                 Event Management
354    -------------------------------------------------------------------------- */
355
356 #ifdef CONFIG_ACPI_PROC_EVENT
357 static DEFINE_SPINLOCK(acpi_bus_event_lock);
358
359 LIST_HEAD(acpi_bus_event_list);
360 DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
361
362 extern int event_is_open;
363
364 int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
365 {
366         struct acpi_bus_event *event;
367         unsigned long flags = 0;
368
369         /* drop event on the floor if no one's listening */
370         if (!event_is_open)
371                 return 0;
372
373         event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
374         if (!event)
375                 return -ENOMEM;
376
377         strcpy(event->device_class, device_class);
378         strcpy(event->bus_id, bus_id);
379         event->type = type;
380         event->data = data;
381
382         spin_lock_irqsave(&acpi_bus_event_lock, flags);
383         list_add_tail(&event->node, &acpi_bus_event_list);
384         spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
385
386         wake_up_interruptible(&acpi_bus_event_queue);
387
388         return 0;
389
390 }
391
392 EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
393
394 int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
395 {
396         if (!device)
397                 return -EINVAL;
398         return acpi_bus_generate_proc_event4(device->pnp.device_class,
399                                              device->pnp.bus_id, type, data);
400 }
401
402 EXPORT_SYMBOL(acpi_bus_generate_proc_event);
403
404 int acpi_bus_receive_event(struct acpi_bus_event *event)
405 {
406         unsigned long flags = 0;
407         struct acpi_bus_event *entry = NULL;
408
409         DECLARE_WAITQUEUE(wait, current);
410
411
412         if (!event)
413                 return -EINVAL;
414
415         if (list_empty(&acpi_bus_event_list)) {
416
417                 set_current_state(TASK_INTERRUPTIBLE);
418                 add_wait_queue(&acpi_bus_event_queue, &wait);
419
420                 if (list_empty(&acpi_bus_event_list))
421                         schedule();
422
423                 remove_wait_queue(&acpi_bus_event_queue, &wait);
424                 set_current_state(TASK_RUNNING);
425
426                 if (signal_pending(current))
427                         return -ERESTARTSYS;
428         }
429
430         spin_lock_irqsave(&acpi_bus_event_lock, flags);
431         if (!list_empty(&acpi_bus_event_list)) {
432                 entry = list_entry(acpi_bus_event_list.next,
433                                    struct acpi_bus_event, node);
434                 list_del(&entry->node);
435         }
436         spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
437
438         if (!entry)
439                 return -ENODEV;
440
441         memcpy(event, entry, sizeof(struct acpi_bus_event));
442
443         kfree(entry);
444
445         return 0;
446 }
447
448 #endif  /* CONFIG_ACPI_PROC_EVENT */
449
450 /* --------------------------------------------------------------------------
451                              Notification Handling
452    -------------------------------------------------------------------------- */
453
454 static void acpi_bus_check_device(acpi_handle handle)
455 {
456         struct acpi_device *device;
457         acpi_status status;
458         struct acpi_device_status old_status;
459
460         if (acpi_bus_get_device(handle, &device))
461                 return;
462         if (!device)
463                 return;
464
465         old_status = device->status;
466
467         /*
468          * Make sure this device's parent is present before we go about
469          * messing with the device.
470          */
471         if (device->parent && !device->parent->status.present) {
472                 device->status = device->parent->status;
473                 return;
474         }
475
476         status = acpi_bus_get_status(device);
477         if (ACPI_FAILURE(status))
478                 return;
479
480         if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
481                 return;
482
483         /*
484          * Device Insertion/Removal
485          */
486         if ((device->status.present) && !(old_status.present)) {
487                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
488                 /* TBD: Handle device insertion */
489         } else if (!(device->status.present) && (old_status.present)) {
490                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
491                 /* TBD: Handle device removal */
492         }
493 }
494
495 static void acpi_bus_check_scope(acpi_handle handle)
496 {
497         /* Status Change? */
498         acpi_bus_check_device(handle);
499
500         /*
501          * TBD: Enumerate child devices within this device's scope and
502          *       run acpi_bus_check_device()'s on them.
503          */
504 }
505
506 static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
507 int register_acpi_bus_notifier(struct notifier_block *nb)
508 {
509         return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
510 }
511 EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
512
513 void unregister_acpi_bus_notifier(struct notifier_block *nb)
514 {
515         blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
516 }
517 EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
518
519 /**
520  * acpi_bus_notify
521  * ---------------
522  * Callback for all 'system-level' device notifications (values 0x00-0x7F).
523  */
524 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
525 {
526         struct acpi_device *device = NULL;
527         struct acpi_driver *driver;
528
529         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
530                           type, handle));
531
532         blocking_notifier_call_chain(&acpi_bus_notify_list,
533                 type, (void *)handle);
534
535         switch (type) {
536
537         case ACPI_NOTIFY_BUS_CHECK:
538                 acpi_bus_check_scope(handle);
539                 /*
540                  * TBD: We'll need to outsource certain events to non-ACPI
541                  *      drivers via the device manager (device.c).
542                  */
543                 break;
544
545         case ACPI_NOTIFY_DEVICE_CHECK:
546                 acpi_bus_check_device(handle);
547                 /*
548                  * TBD: We'll need to outsource certain events to non-ACPI
549                  *      drivers via the device manager (device.c).
550                  */
551                 break;
552
553         case ACPI_NOTIFY_DEVICE_WAKE:
554                 /* TBD */
555                 break;
556
557         case ACPI_NOTIFY_EJECT_REQUEST:
558                 /* TBD */
559                 break;
560
561         case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
562                 /* TBD: Exactly what does 'light' mean? */
563                 break;
564
565         case ACPI_NOTIFY_FREQUENCY_MISMATCH:
566                 /* TBD */
567                 break;
568
569         case ACPI_NOTIFY_BUS_MODE_MISMATCH:
570                 /* TBD */
571                 break;
572
573         case ACPI_NOTIFY_POWER_FAULT:
574                 /* TBD */
575                 break;
576
577         default:
578                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
579                                   "Received unknown/unsupported notification [%08x]\n",
580                                   type));
581                 break;
582         }
583
584         acpi_bus_get_device(handle, &device);
585         if (device) {
586                 driver = device->driver;
587                 if (driver && driver->ops.notify &&
588                     (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
589                         driver->ops.notify(device, type);
590         }
591 }
592
593 /* --------------------------------------------------------------------------
594                              Initialization/Cleanup
595    -------------------------------------------------------------------------- */
596
597 static int __init acpi_bus_init_irq(void)
598 {
599         acpi_status status = AE_OK;
600         union acpi_object arg = { ACPI_TYPE_INTEGER };
601         struct acpi_object_list arg_list = { 1, &arg };
602         char *message = NULL;
603
604
605         /*
606          * Let the system know what interrupt model we are using by
607          * evaluating the \_PIC object, if exists.
608          */
609
610         switch (acpi_irq_model) {
611         case ACPI_IRQ_MODEL_PIC:
612                 message = "PIC";
613                 break;
614         case ACPI_IRQ_MODEL_IOAPIC:
615                 message = "IOAPIC";
616                 break;
617         case ACPI_IRQ_MODEL_IOSAPIC:
618                 message = "IOSAPIC";
619                 break;
620         case ACPI_IRQ_MODEL_PLATFORM:
621                 message = "platform specific model";
622                 break;
623         default:
624                 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
625                 return -ENODEV;
626         }
627
628         printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
629
630         arg.integer.value = acpi_irq_model;
631
632         status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
633         if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
634                 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
635                 return -ENODEV;
636         }
637
638         return 0;
639 }
640
641 u8 acpi_gbl_permanent_mmap;
642
643
644 void __init acpi_early_init(void)
645 {
646         acpi_status status = AE_OK;
647
648         if (acpi_disabled)
649                 return;
650
651         printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
652
653         /* enable workarounds, unless strict ACPI spec. compliance */
654         if (!acpi_strict)
655                 acpi_gbl_enable_interpreter_slack = TRUE;
656
657         acpi_gbl_permanent_mmap = 1;
658
659         status = acpi_reallocate_root_table();
660         if (ACPI_FAILURE(status)) {
661                 printk(KERN_ERR PREFIX
662                        "Unable to reallocate ACPI tables\n");
663                 goto error0;
664         }
665
666         status = acpi_initialize_subsystem();
667         if (ACPI_FAILURE(status)) {
668                 printk(KERN_ERR PREFIX
669                        "Unable to initialize the ACPI Interpreter\n");
670                 goto error0;
671         }
672
673         status = acpi_load_tables();
674         if (ACPI_FAILURE(status)) {
675                 printk(KERN_ERR PREFIX
676                        "Unable to load the System Description Tables\n");
677                 goto error0;
678         }
679
680 #ifdef CONFIG_X86
681         if (!acpi_ioapic) {
682                 /* compatible (0) means level (3) */
683                 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
684                         acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
685                         acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
686                 }
687                 /* Set PIC-mode SCI trigger type */
688                 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
689                                          (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
690         } else {
691                 /*
692                  * now that acpi_gbl_FADT is initialized,
693                  * update it with result from INT_SRC_OVR parsing
694                  */
695                 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
696         }
697 #endif
698
699         status =
700             acpi_enable_subsystem(~
701                                   (ACPI_NO_HARDWARE_INIT |
702                                    ACPI_NO_ACPI_ENABLE));
703         if (ACPI_FAILURE(status)) {
704                 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
705                 goto error0;
706         }
707
708         return;
709
710       error0:
711         disable_acpi();
712         return;
713 }
714
715 static int __init acpi_bus_init(void)
716 {
717         int result = 0;
718         acpi_status status = AE_OK;
719         extern acpi_status acpi_os_initialize1(void);
720
721         acpi_os_initialize1();
722
723         status =
724             acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
725         if (ACPI_FAILURE(status)) {
726                 printk(KERN_ERR PREFIX
727                        "Unable to start the ACPI Interpreter\n");
728                 goto error1;
729         }
730
731         /*
732          * ACPI 2.0 requires the EC driver to be loaded and work before
733          * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
734          * is called).
735          *
736          * This is accomplished by looking for the ECDT table, and getting
737          * the EC parameters out of that.
738          */
739         status = acpi_ec_ecdt_probe();
740         /* Ignore result. Not having an ECDT is not fatal. */
741
742         status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
743         if (ACPI_FAILURE(status)) {
744                 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
745                 goto error1;
746         }
747
748         /*
749          * Maybe EC region is required at bus_scan/acpi_get_devices. So it
750          * is necessary to enable it as early as possible.
751          */
752         acpi_boot_ec_enable();
753
754         printk(KERN_INFO PREFIX "Interpreter enabled\n");
755
756         /* Initialize sleep structures */
757         acpi_sleep_init();
758
759         /*
760          * Get the system interrupt model and evaluate \_PIC.
761          */
762         result = acpi_bus_init_irq();
763         if (result)
764                 goto error1;
765
766         /*
767          * Register the for all standard device notifications.
768          */
769         status =
770             acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
771                                         &acpi_bus_notify, NULL);
772         if (ACPI_FAILURE(status)) {
773                 printk(KERN_ERR PREFIX
774                        "Unable to register for device notifications\n");
775                 goto error1;
776         }
777
778         /*
779          * Create the top ACPI proc directory
780          */
781         acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
782
783         return 0;
784
785         /* Mimic structured exception handling */
786       error1:
787         acpi_terminate();
788         return -ENODEV;
789 }
790
791 struct kobject *acpi_kobj;
792
793 static int __init acpi_init(void)
794 {
795         int result = 0;
796
797
798         if (acpi_disabled) {
799                 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
800                 return -ENODEV;
801         }
802
803         acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
804         if (!acpi_kobj) {
805                 printk(KERN_WARNING "%s: kset create error\n", __func__);
806                 acpi_kobj = NULL;
807         }
808
809         init_acpi_device_notify();
810         result = acpi_bus_init();
811
812         if (!result) {
813                 pci_mmcfg_late_init();
814                 if (!(pm_flags & PM_APM))
815                         pm_flags |= PM_ACPI;
816                 else {
817                         printk(KERN_INFO PREFIX
818                                "APM is already active, exiting\n");
819                         disable_acpi();
820                         result = -ENODEV;
821                 }
822         } else
823                 disable_acpi();
824
825         if (acpi_disabled)
826                 return result;
827
828         /*
829          * If the laptop falls into the DMI check table, the power state check
830          * will be disabled in the course of device power transistion.
831          */
832         dmi_check_system(power_nocheck_dmi_table);
833
834         acpi_scan_init();
835         acpi_ec_init();
836         acpi_power_init();
837         acpi_system_init();
838         acpi_debug_init();
839         acpi_sleep_proc_init();
840         acpi_wakeup_device_init();
841         return result;
842 }
843
844 subsys_initcall(acpi_init);