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