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