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