]>
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> | |
eb27cae8 | 41 | #include <linux/dmi.h> |
1da177e4 | 42 | |
e60cc7a6 BH |
43 | #include "internal.h" |
44 | ||
1da177e4 | 45 | #define _COMPONENT ACPI_BUS_COMPONENT |
f52fd66d | 46 | ACPI_MODULE_NAME("bus"); |
1da177e4 | 47 | |
4be44fcd LB |
48 | struct acpi_device *acpi_root; |
49 | struct proc_dir_entry *acpi_root_dir; | |
1da177e4 LT |
50 | EXPORT_SYMBOL(acpi_root_dir); |
51 | ||
52 | #define STRUCT_TO_INT(s) (*((int*)&s)) | |
53 | ||
6415e12b ZY |
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 | ||
1da177e4 LT |
71 | /* -------------------------------------------------------------------------- |
72 | Device Management | |
73 | -------------------------------------------------------------------------- */ | |
74 | ||
4be44fcd | 75 | int 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 |
95 | EXPORT_SYMBOL(acpi_bus_get_device); |
96 | ||
4be44fcd | 97 | int acpi_bus_get_status(struct acpi_device *device) |
1da177e4 | 98 | { |
4be44fcd | 99 | acpi_status status = AE_OK; |
27663c58 | 100 | unsigned long long sta = 0; |
4be44fcd | 101 | |
1da177e4 LT |
102 | |
103 | if (!device) | |
d550d98d | 104 | return -EINVAL; |
1da177e4 LT |
105 | |
106 | /* | |
107 | * Evaluate _STA if present. | |
108 | */ | |
109 | if (device->flags.dynamic_status) { | |
4be44fcd LB |
110 | status = |
111 | acpi_evaluate_integer(device->handle, "_STA", NULL, &sta); | |
1da177e4 | 112 | if (ACPI_FAILURE(status)) |
d550d98d | 113 | return -ENODEV; |
4be44fcd | 114 | STRUCT_TO_INT(device->status) = (int)sta; |
1da177e4 LT |
115 | } |
116 | ||
117 | /* | |
39a0ad87 ZY |
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. | |
1da177e4 | 122 | */ |
1da177e4 | 123 | else |
0c0e8921 BH |
124 | STRUCT_TO_INT(device->status) = |
125 | ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | | |
126 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; | |
1da177e4 LT |
127 | |
128 | if (device->status.functional && !device->status.present) { | |
39a0ad87 ZY |
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))); | |
1da177e4 LT |
133 | } |
134 | ||
4be44fcd LB |
135 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n", |
136 | device->pnp.bus_id, | |
137 | (u32) STRUCT_TO_INT(device->status))); | |
1da177e4 | 138 | |
d550d98d | 139 | return 0; |
1da177e4 | 140 | } |
1da177e4 | 141 | |
4be44fcd | 142 | EXPORT_SYMBOL(acpi_bus_get_status); |
1da177e4 | 143 | |
20733939 | 144 | void acpi_bus_private_data_handler(acpi_handle handle, |
8e4319c4 | 145 | void *context) |
20733939 ZR |
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 | ||
1da177e4 LT |
169 | /* -------------------------------------------------------------------------- |
170 | Power Management | |
171 | -------------------------------------------------------------------------- */ | |
172 | ||
4be44fcd | 173 | int acpi_bus_get_power(acpi_handle handle, int *state) |
1da177e4 | 174 | { |
4be44fcd LB |
175 | int result = 0; |
176 | acpi_status status = 0; | |
177 | struct acpi_device *device = NULL; | |
27663c58 | 178 | unsigned long long psc = 0; |
1da177e4 | 179 | |
1da177e4 LT |
180 | |
181 | result = acpi_bus_get_device(handle, &device); | |
182 | if (result) | |
d550d98d | 183 | return result; |
1da177e4 LT |
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; | |
4be44fcd | 193 | } else { |
1da177e4 | 194 | /* |
aafbcd16 | 195 | * Get the device's power state either directly (via _PSC) or |
1da177e4 LT |
196 | * indirectly (via power resources). |
197 | */ | |
198 | if (device->power.flags.explicit_get) { | |
4be44fcd LB |
199 | status = acpi_evaluate_integer(device->handle, "_PSC", |
200 | NULL, &psc); | |
1da177e4 | 201 | if (ACPI_FAILURE(status)) |
d550d98d | 202 | return -ENODEV; |
4be44fcd LB |
203 | device->power.state = (int)psc; |
204 | } else if (device->power.flags.power_resources) { | |
1da177e4 LT |
205 | result = acpi_power_get_inferred_state(device); |
206 | if (result) | |
d550d98d | 207 | return result; |
1da177e4 LT |
208 | } |
209 | ||
210 | *state = device->power.state; | |
211 | } | |
212 | ||
213 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", | |
4be44fcd | 214 | device->pnp.bus_id, device->power.state)); |
1da177e4 | 215 | |
d550d98d | 216 | return 0; |
1da177e4 | 217 | } |
1da177e4 | 218 | |
4be44fcd | 219 | EXPORT_SYMBOL(acpi_bus_get_power); |
1da177e4 | 220 | |
4be44fcd | 221 | int acpi_bus_set_power(acpi_handle handle, int state) |
1da177e4 | 222 | { |
4be44fcd LB |
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' }; | |
1da177e4 | 227 | |
1da177e4 LT |
228 | |
229 | result = acpi_bus_get_device(handle, &device); | |
230 | if (result) | |
d550d98d | 231 | return result; |
1da177e4 LT |
232 | |
233 | if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) | |
d550d98d | 234 | return -EINVAL; |
1da177e4 LT |
235 | |
236 | /* Make sure this is a valid target state */ | |
237 | ||
238 | if (!device->flags.power_manageable) { | |
9805cb76 | 239 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n", |
19c38de8 | 240 | kobject_name(&device->dev.kobj))); |
d550d98d | 241 | return -ENODEV; |
1da177e4 | 242 | } |
b913100d | 243 | /* |
c35923bc | 244 | * Get device's current power state |
b913100d | 245 | */ |
f5adfaa3 ZY |
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 | } | |
ec68373c | 259 | if ((state == device->power.state) && !device->flags.force_power_state) { |
b1028c54 KK |
260 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", |
261 | state)); | |
262 | return 0; | |
1da177e4 | 263 | } |
b1028c54 | 264 | |
1da177e4 | 265 | if (!device->power.states[state].flags.valid) { |
cece9296 | 266 | printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); |
d550d98d | 267 | return -ENODEV; |
1da177e4 LT |
268 | } |
269 | if (device->parent && (state < device->parent->power.state)) { | |
cece9296 | 270 | printk(KERN_WARNING PREFIX |
a6fc6720 | 271 | "Cannot set device to a higher-powered" |
cece9296 | 272 | " state than parent\n"); |
d550d98d | 273 | return -ENODEV; |
1da177e4 LT |
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. | |
b913100d | 282 | */ |
1da177e4 LT |
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) { | |
4be44fcd LB |
290 | status = acpi_evaluate_object(device->handle, |
291 | object_name, NULL, NULL); | |
1da177e4 LT |
292 | if (ACPI_FAILURE(status)) { |
293 | result = -ENODEV; | |
294 | goto end; | |
295 | } | |
296 | } | |
4be44fcd | 297 | } else { |
1da177e4 | 298 | if (device->power.states[state].flags.explicit_set) { |
4be44fcd LB |
299 | status = acpi_evaluate_object(device->handle, |
300 | object_name, NULL, NULL); | |
1da177e4 LT |
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 | ||
4be44fcd | 313 | end: |
1da177e4 | 314 | if (result) |
cece9296 | 315 | printk(KERN_WARNING PREFIX |
ddc50b6a | 316 | "Device [%s] failed to transition to D%d\n", |
cece9296 | 317 | device->pnp.bus_id, state); |
5e32132b SL |
318 | else { |
319 | device->power.state = state; | |
4be44fcd LB |
320 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
321 | "Device [%s] transitioned to D%d\n", | |
322 | device->pnp.bus_id, state)); | |
5e32132b | 323 | } |
1da177e4 | 324 | |
d550d98d | 325 | return result; |
1da177e4 | 326 | } |
1da177e4 | 327 | |
4be44fcd | 328 | EXPORT_SYMBOL(acpi_bus_set_power); |
1da177e4 | 329 | |
3737b2b1 RW |
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 | ||
eb9d0fe4 RW |
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 | ||
1da177e4 LT |
352 | /* -------------------------------------------------------------------------- |
353 | Event Management | |
354 | -------------------------------------------------------------------------- */ | |
355 | ||
14e04fb3 | 356 | #ifdef CONFIG_ACPI_PROC_EVENT |
1da177e4 LT |
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 | ||
4be44fcd | 362 | extern int event_is_open; |
1da177e4 | 363 | |
8db85d4c | 364 | int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data) |
1da177e4 | 365 | { |
8db85d4c | 366 | struct acpi_bus_event *event; |
4be44fcd | 367 | unsigned long flags = 0; |
1da177e4 | 368 | |
1da177e4 LT |
369 | /* drop event on the floor if no one's listening */ |
370 | if (!event_is_open) | |
d550d98d | 371 | return 0; |
1da177e4 LT |
372 | |
373 | event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC); | |
374 | if (!event) | |
d550d98d | 375 | return -ENOMEM; |
1da177e4 | 376 | |
8db85d4c AS |
377 | strcpy(event->device_class, device_class); |
378 | strcpy(event->bus_id, bus_id); | |
1da177e4 LT |
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 | ||
d550d98d | 388 | return 0; |
8db85d4c AS |
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); | |
1da177e4 | 400 | } |
4be44fcd | 401 | |
14e04fb3 | 402 | EXPORT_SYMBOL(acpi_bus_generate_proc_event); |
1da177e4 | 403 | |
4be44fcd | 404 | int acpi_bus_receive_event(struct acpi_bus_event *event) |
1da177e4 | 405 | { |
4be44fcd LB |
406 | unsigned long flags = 0; |
407 | struct acpi_bus_event *entry = NULL; | |
1da177e4 LT |
408 | |
409 | DECLARE_WAITQUEUE(wait, current); | |
410 | ||
1da177e4 LT |
411 | |
412 | if (!event) | |
d550d98d | 413 | return -EINVAL; |
1da177e4 LT |
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)) | |
d550d98d | 427 | return -ERESTARTSYS; |
1da177e4 LT |
428 | } |
429 | ||
430 | spin_lock_irqsave(&acpi_bus_event_lock, flags); | |
f0a37e00 CE |
431 | if (!list_empty(&acpi_bus_event_list)) { |
432 | entry = list_entry(acpi_bus_event_list.next, | |
433 | struct acpi_bus_event, node); | |
1da177e4 | 434 | list_del(&entry->node); |
f0a37e00 | 435 | } |
1da177e4 LT |
436 | spin_unlock_irqrestore(&acpi_bus_event_lock, flags); |
437 | ||
438 | if (!entry) | |
d550d98d | 439 | return -ENODEV; |
1da177e4 LT |
440 | |
441 | memcpy(event, entry, sizeof(struct acpi_bus_event)); | |
442 | ||
443 | kfree(entry); | |
444 | ||
d550d98d | 445 | return 0; |
1da177e4 | 446 | } |
1da177e4 | 447 | |
14e04fb3 | 448 | #endif /* CONFIG_ACPI_PROC_EVENT */ |
1da177e4 LT |
449 | |
450 | /* -------------------------------------------------------------------------- | |
451 | Notification Handling | |
452 | -------------------------------------------------------------------------- */ | |
453 | ||
ff754e2e | 454 | static void acpi_bus_check_device(acpi_handle handle) |
1da177e4 | 455 | { |
ff754e2e | 456 | struct acpi_device *device; |
cdd5b8ca | 457 | acpi_status status; |
1da177e4 LT |
458 | struct acpi_device_status old_status; |
459 | ||
ff754e2e BH |
460 | if (acpi_bus_get_device(handle, &device)) |
461 | return; | |
1da177e4 | 462 | if (!device) |
cdd5b8ca | 463 | return; |
1da177e4 | 464 | |
1da177e4 LT |
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; | |
cdd5b8ca | 473 | return; |
1da177e4 LT |
474 | } |
475 | ||
476 | status = acpi_bus_get_status(device); | |
477 | if (ACPI_FAILURE(status)) | |
cdd5b8ca | 478 | return; |
1da177e4 LT |
479 | |
480 | if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status)) | |
cdd5b8ca | 481 | return; |
1da177e4 | 482 | |
1da177e4 LT |
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 */ | |
4be44fcd | 489 | } else if (!(device->status.present) && (old_status.present)) { |
1da177e4 LT |
490 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n")); |
491 | /* TBD: Handle device removal */ | |
492 | } | |
1da177e4 LT |
493 | } |
494 | ||
ff754e2e | 495 | static void acpi_bus_check_scope(acpi_handle handle) |
1da177e4 | 496 | { |
1da177e4 | 497 | /* Status Change? */ |
ff754e2e | 498 | acpi_bus_check_device(handle); |
1da177e4 | 499 | |
1da177e4 LT |
500 | /* |
501 | * TBD: Enumerate child devices within this device's scope and | |
502 | * run acpi_bus_check_device()'s on them. | |
503 | */ | |
1da177e4 LT |
504 | } |
505 | ||
6bd00a61 SL |
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 | ||
1da177e4 LT |
519 | /** |
520 | * acpi_bus_notify | |
521 | * --------------- | |
522 | * Callback for all 'system-level' device notifications (values 0x00-0x7F). | |
523 | */ | |
4be44fcd | 524 | static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) |
1da177e4 | 525 | { |
4be44fcd | 526 | struct acpi_device *device = NULL; |
6d278131 | 527 | struct acpi_driver *driver; |
1da177e4 | 528 | |
02c37bd8 BH |
529 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n", |
530 | type, handle)); | |
531 | ||
6bd00a61 SL |
532 | blocking_notifier_call_chain(&acpi_bus_notify_list, |
533 | type, (void *)handle); | |
1da177e4 | 534 | |
1da177e4 LT |
535 | switch (type) { |
536 | ||
537 | case ACPI_NOTIFY_BUS_CHECK: | |
ff754e2e | 538 | acpi_bus_check_scope(handle); |
aafbcd16 | 539 | /* |
1da177e4 | 540 | * TBD: We'll need to outsource certain events to non-ACPI |
4be44fcd | 541 | * drivers via the device manager (device.c). |
1da177e4 LT |
542 | */ |
543 | break; | |
544 | ||
545 | case ACPI_NOTIFY_DEVICE_CHECK: | |
ff754e2e | 546 | acpi_bus_check_device(handle); |
aafbcd16 | 547 | /* |
1da177e4 | 548 | * TBD: We'll need to outsource certain events to non-ACPI |
4be44fcd | 549 | * drivers via the device manager (device.c). |
1da177e4 LT |
550 | */ |
551 | break; | |
552 | ||
553 | case ACPI_NOTIFY_DEVICE_WAKE: | |
1da177e4 LT |
554 | /* TBD */ |
555 | break; | |
556 | ||
557 | case ACPI_NOTIFY_EJECT_REQUEST: | |
1da177e4 LT |
558 | /* TBD */ |
559 | break; | |
560 | ||
561 | case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: | |
1da177e4 LT |
562 | /* TBD: Exactly what does 'light' mean? */ |
563 | break; | |
564 | ||
565 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: | |
1da177e4 LT |
566 | /* TBD */ |
567 | break; | |
568 | ||
569 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: | |
1da177e4 LT |
570 | /* TBD */ |
571 | break; | |
572 | ||
573 | case ACPI_NOTIFY_POWER_FAULT: | |
1da177e4 LT |
574 | /* TBD */ |
575 | break; | |
576 | ||
577 | default: | |
4be44fcd LB |
578 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
579 | "Received unknown/unsupported notification [%08x]\n", | |
580 | type)); | |
1da177e4 LT |
581 | break; |
582 | } | |
583 | ||
ff754e2e BH |
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 | } | |
1da177e4 LT |
591 | } |
592 | ||
593 | /* -------------------------------------------------------------------------- | |
594 | Initialization/Cleanup | |
595 | -------------------------------------------------------------------------- */ | |
596 | ||
4be44fcd | 597 | static int __init acpi_bus_init_irq(void) |
1da177e4 | 598 | { |
4be44fcd LB |
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; | |
1da177e4 | 603 | |
1da177e4 | 604 | |
aafbcd16 | 605 | /* |
1da177e4 LT |
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; | |
3948ec94 JK |
620 | case ACPI_IRQ_MODEL_PLATFORM: |
621 | message = "platform specific model"; | |
622 | break; | |
1da177e4 LT |
623 | default: |
624 | printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); | |
d550d98d | 625 | return -ENODEV; |
1da177e4 LT |
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)) { | |
a6fc6720 | 634 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC")); |
d550d98d | 635 | return -ENODEV; |
1da177e4 LT |
636 | } |
637 | ||
d550d98d | 638 | return 0; |
1da177e4 LT |
639 | } |
640 | ||
67a119f9 | 641 | u8 acpi_gbl_permanent_mmap; |
ad71860a AS |
642 | |
643 | ||
4be44fcd | 644 | void __init acpi_early_init(void) |
1da177e4 | 645 | { |
4be44fcd | 646 | acpi_status status = AE_OK; |
1da177e4 LT |
647 | |
648 | if (acpi_disabled) | |
d550d98d | 649 | return; |
1da177e4 | 650 | |
61686124 BM |
651 | printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); |
652 | ||
1da177e4 LT |
653 | /* enable workarounds, unless strict ACPI spec. compliance */ |
654 | if (!acpi_strict) | |
655 | acpi_gbl_enable_interpreter_slack = TRUE; | |
656 | ||
ad71860a AS |
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 | ||
1da177e4 LT |
666 | status = acpi_initialize_subsystem(); |
667 | if (ACPI_FAILURE(status)) { | |
4be44fcd LB |
668 | printk(KERN_ERR PREFIX |
669 | "Unable to initialize the ACPI Interpreter\n"); | |
1da177e4 LT |
670 | goto error0; |
671 | } | |
672 | ||
673 | status = acpi_load_tables(); | |
674 | if (ACPI_FAILURE(status)) { | |
4be44fcd LB |
675 | printk(KERN_ERR PREFIX |
676 | "Unable to load the System Description Tables\n"); | |
1da177e4 LT |
677 | goto error0; |
678 | } | |
679 | ||
1da177e4 LT |
680 | #ifdef CONFIG_X86 |
681 | if (!acpi_ioapic) { | |
1da177e4 | 682 | /* compatible (0) means level (3) */ |
5f3b1a8b AS |
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 | } | |
1da177e4 | 687 | /* Set PIC-mode SCI trigger type */ |
cee324b1 | 688 | acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt, |
5f3b1a8b | 689 | (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2); |
1da177e4 | 690 | } else { |
1da177e4 | 691 | /* |
cee324b1 | 692 | * now that acpi_gbl_FADT is initialized, |
1da177e4 LT |
693 | * update it with result from INT_SRC_OVR parsing |
694 | */ | |
cee324b1 | 695 | acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi; |
1da177e4 LT |
696 | } |
697 | #endif | |
698 | ||
4be44fcd LB |
699 | status = |
700 | acpi_enable_subsystem(~ | |
701 | (ACPI_NO_HARDWARE_INIT | | |
702 | ACPI_NO_ACPI_ENABLE)); | |
1da177e4 LT |
703 | if (ACPI_FAILURE(status)) { |
704 | printk(KERN_ERR PREFIX "Unable to enable ACPI\n"); | |
705 | goto error0; | |
706 | } | |
707 | ||
d550d98d | 708 | return; |
1da177e4 | 709 | |
4be44fcd | 710 | error0: |
1da177e4 | 711 | disable_acpi(); |
d550d98d | 712 | return; |
1da177e4 LT |
713 | } |
714 | ||
4be44fcd | 715 | static int __init acpi_bus_init(void) |
1da177e4 | 716 | { |
4be44fcd LB |
717 | int result = 0; |
718 | acpi_status status = AE_OK; | |
719 | extern acpi_status acpi_os_initialize1(void); | |
1da177e4 | 720 | |
176f9c18 | 721 | acpi_os_initialize1(); |
1da177e4 | 722 | |
4be44fcd LB |
723 | status = |
724 | acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE); | |
1da177e4 | 725 | if (ACPI_FAILURE(status)) { |
4be44fcd LB |
726 | printk(KERN_ERR PREFIX |
727 | "Unable to start the ACPI Interpreter\n"); | |
1da177e4 LT |
728 | goto error1; |
729 | } | |
730 | ||
1da177e4 LT |
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 | * | |
aafbcd16 | 736 | * This is accomplished by looking for the ECDT table, and getting |
1da177e4 LT |
737 | * the EC parameters out of that. |
738 | */ | |
739 | status = acpi_ec_ecdt_probe(); | |
740 | /* Ignore result. Not having an ECDT is not fatal. */ | |
1da177e4 LT |
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 | ||
455c8793 ZY |
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 | ||
1da177e4 LT |
754 | printk(KERN_INFO PREFIX "Interpreter enabled\n"); |
755 | ||
aafbcd16 AS |
756 | /* Initialize sleep structures */ |
757 | acpi_sleep_init(); | |
758 | ||
1da177e4 LT |
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 | */ | |
4be44fcd LB |
769 | status = |
770 | acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, | |
771 | &acpi_bus_notify, NULL); | |
1da177e4 | 772 | if (ACPI_FAILURE(status)) { |
4be44fcd LB |
773 | printk(KERN_ERR PREFIX |
774 | "Unable to register for device notifications\n"); | |
1da177e4 LT |
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 | ||
d550d98d | 783 | return 0; |
1da177e4 LT |
784 | |
785 | /* Mimic structured exception handling */ | |
4be44fcd | 786 | error1: |
1da177e4 | 787 | acpi_terminate(); |
d550d98d | 788 | return -ENODEV; |
1da177e4 LT |
789 | } |
790 | ||
99e0d2fc | 791 | struct kobject *acpi_kobj; |
1da177e4 | 792 | |
4be44fcd | 793 | static int __init acpi_init(void) |
1da177e4 | 794 | { |
4be44fcd | 795 | int result = 0; |
1da177e4 | 796 | |
1da177e4 | 797 | |
1da177e4 LT |
798 | if (acpi_disabled) { |
799 | printk(KERN_INFO PREFIX "Interpreter disabled.\n"); | |
d550d98d | 800 | return -ENODEV; |
1da177e4 LT |
801 | } |
802 | ||
f62ed9e3 | 803 | acpi_kobj = kobject_create_and_add("acpi", firmware_kobj); |
99e0d2fc | 804 | if (!acpi_kobj) { |
96b2dd1f | 805 | printk(KERN_WARNING "%s: kset create error\n", __func__); |
99e0d2fc GKH |
806 | acpi_kobj = NULL; |
807 | } | |
1da177e4 | 808 | |
0e46517d | 809 | init_acpi_device_notify(); |
1da177e4 LT |
810 | result = acpi_bus_init(); |
811 | ||
812 | if (!result) { | |
7752d5cf | 813 | pci_mmcfg_late_init(); |
9f9adecd LB |
814 | if (!(pm_flags & PM_APM)) |
815 | pm_flags |= PM_ACPI; | |
1da177e4 | 816 | else { |
4be44fcd LB |
817 | printk(KERN_INFO PREFIX |
818 | "APM is already active, exiting\n"); | |
1da177e4 LT |
819 | disable_acpi(); |
820 | result = -ENODEV; | |
821 | } | |
1da177e4 LT |
822 | } else |
823 | disable_acpi(); | |
81d0273d BH |
824 | |
825 | if (acpi_disabled) | |
826 | return result; | |
827 | ||
6415e12b ZY |
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); | |
e747f274 BH |
833 | |
834 | acpi_scan_init(); | |
a5f820fe | 835 | acpi_ec_init(); |
44515374 | 836 | acpi_power_init(); |
141a0af3 | 837 | acpi_system_init(); |
84f810c3 | 838 | acpi_debug_init(); |
9cee43e0 | 839 | acpi_sleep_proc_init(); |
201b8c65 | 840 | acpi_wakeup_device_init(); |
d550d98d | 841 | return result; |
1da177e4 LT |
842 | } |
843 | ||
844 | subsys_initcall(acpi_init); |