Merge branch 'acpi-cleanup' into acpi-hotplug
[deliverable/linux.git] / drivers / acpi / bus.c
1 /*
2 * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
3 *
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/ioport.h>
28 #include <linux/kernel.h>
29 #include <linux/list.h>
30 #include <linux/sched.h>
31 #include <linux/pm.h>
32 #include <linux/device.h>
33 #include <linux/proc_fs.h>
34 #include <linux/acpi.h>
35 #include <linux/slab.h>
36 #ifdef CONFIG_X86
37 #include <asm/mpspec.h>
38 #endif
39 #include <linux/pci.h>
40 #include <acpi/apei.h>
41 #include <linux/dmi.h>
42 #include <linux/suspend.h>
43
44 #include "internal.h"
45
46 #define _COMPONENT ACPI_BUS_COMPONENT
47 ACPI_MODULE_NAME("bus");
48
49 struct acpi_device *acpi_root;
50 struct proc_dir_entry *acpi_root_dir;
51 EXPORT_SYMBOL(acpi_root_dir);
52
53 #ifdef CONFIG_X86
54 static int set_copy_dsdt(const struct dmi_system_id *id)
55 {
56 printk(KERN_NOTICE "%s detected - "
57 "force copy of DSDT to local memory\n", id->ident);
58 acpi_gbl_copy_dsdt_locally = 1;
59 return 0;
60 }
61
62 static struct dmi_system_id dsdt_dmi_table[] __initdata = {
63 /*
64 * Invoke DSDT corruption work-around on all Toshiba Satellite.
65 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
66 */
67 {
68 .callback = set_copy_dsdt,
69 .ident = "TOSHIBA Satellite",
70 .matches = {
71 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
72 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
73 },
74 },
75 {}
76 };
77 #else
78 static struct dmi_system_id dsdt_dmi_table[] __initdata = {
79 {}
80 };
81 #endif
82
83 /* --------------------------------------------------------------------------
84 Device Management
85 -------------------------------------------------------------------------- */
86
87 acpi_status acpi_bus_get_status_handle(acpi_handle handle,
88 unsigned long long *sta)
89 {
90 acpi_status status;
91
92 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
93 if (ACPI_SUCCESS(status))
94 return AE_OK;
95
96 if (status == AE_NOT_FOUND) {
97 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
98 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
99 return AE_OK;
100 }
101 return status;
102 }
103
104 int acpi_bus_get_status(struct acpi_device *device)
105 {
106 acpi_status status;
107 unsigned long long sta;
108
109 status = acpi_bus_get_status_handle(device->handle, &sta);
110 if (ACPI_FAILURE(status))
111 return -ENODEV;
112
113 acpi_set_device_status(device, sta);
114
115 if (device->status.functional && !device->status.present) {
116 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
117 "functional but not present;\n",
118 device->pnp.bus_id, (u32)sta));
119 }
120
121 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
122 device->pnp.bus_id, (u32)sta));
123 return 0;
124 }
125 EXPORT_SYMBOL(acpi_bus_get_status);
126
127 void acpi_bus_private_data_handler(acpi_handle handle,
128 void *context)
129 {
130 return;
131 }
132 EXPORT_SYMBOL(acpi_bus_private_data_handler);
133
134 int acpi_bus_get_private_data(acpi_handle handle, void **data)
135 {
136 acpi_status status;
137
138 if (!*data)
139 return -EINVAL;
140
141 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
142 if (ACPI_FAILURE(status) || !*data) {
143 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
144 handle));
145 return -ENODEV;
146 }
147
148 return 0;
149 }
150 EXPORT_SYMBOL(acpi_bus_get_private_data);
151
152 static void acpi_print_osc_error(acpi_handle handle,
153 struct acpi_osc_context *context, char *error)
154 {
155 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
156 int i;
157
158 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
159 printk(KERN_DEBUG "%s\n", error);
160 else {
161 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
162 kfree(buffer.pointer);
163 }
164 printk(KERN_DEBUG"_OSC request data:");
165 for (i = 0; i < context->cap.length; i += sizeof(u32))
166 printk("%x ", *((u32 *)(context->cap.pointer + i)));
167 printk("\n");
168 }
169
170 acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
171 {
172 int i;
173 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
174 24, 26, 28, 30, 32, 34};
175
176 if (strlen(str) != 36)
177 return AE_BAD_PARAMETER;
178 for (i = 0; i < 36; i++) {
179 if (i == 8 || i == 13 || i == 18 || i == 23) {
180 if (str[i] != '-')
181 return AE_BAD_PARAMETER;
182 } else if (!isxdigit(str[i]))
183 return AE_BAD_PARAMETER;
184 }
185 for (i = 0; i < 16; i++) {
186 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
187 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
188 }
189 return AE_OK;
190 }
191 EXPORT_SYMBOL_GPL(acpi_str_to_uuid);
192
193 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
194 {
195 acpi_status status;
196 struct acpi_object_list input;
197 union acpi_object in_params[4];
198 union acpi_object *out_obj;
199 u8 uuid[16];
200 u32 errors;
201 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
202
203 if (!context)
204 return AE_ERROR;
205 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
206 return AE_ERROR;
207 context->ret.length = ACPI_ALLOCATE_BUFFER;
208 context->ret.pointer = NULL;
209
210 /* Setting up input parameters */
211 input.count = 4;
212 input.pointer = in_params;
213 in_params[0].type = ACPI_TYPE_BUFFER;
214 in_params[0].buffer.length = 16;
215 in_params[0].buffer.pointer = uuid;
216 in_params[1].type = ACPI_TYPE_INTEGER;
217 in_params[1].integer.value = context->rev;
218 in_params[2].type = ACPI_TYPE_INTEGER;
219 in_params[2].integer.value = context->cap.length/sizeof(u32);
220 in_params[3].type = ACPI_TYPE_BUFFER;
221 in_params[3].buffer.length = context->cap.length;
222 in_params[3].buffer.pointer = context->cap.pointer;
223
224 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
225 if (ACPI_FAILURE(status))
226 return status;
227
228 if (!output.length)
229 return AE_NULL_OBJECT;
230
231 out_obj = output.pointer;
232 if (out_obj->type != ACPI_TYPE_BUFFER
233 || out_obj->buffer.length != context->cap.length) {
234 acpi_print_osc_error(handle, context,
235 "_OSC evaluation returned wrong type");
236 status = AE_TYPE;
237 goto out_kfree;
238 }
239 /* Need to ignore the bit0 in result code */
240 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
241 if (errors) {
242 if (errors & OSC_REQUEST_ERROR)
243 acpi_print_osc_error(handle, context,
244 "_OSC request failed");
245 if (errors & OSC_INVALID_UUID_ERROR)
246 acpi_print_osc_error(handle, context,
247 "_OSC invalid UUID");
248 if (errors & OSC_INVALID_REVISION_ERROR)
249 acpi_print_osc_error(handle, context,
250 "_OSC invalid revision");
251 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
252 if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD]
253 & OSC_QUERY_ENABLE)
254 goto out_success;
255 status = AE_SUPPORT;
256 goto out_kfree;
257 }
258 status = AE_ERROR;
259 goto out_kfree;
260 }
261 out_success:
262 context->ret.length = out_obj->buffer.length;
263 context->ret.pointer = kmemdup(out_obj->buffer.pointer,
264 context->ret.length, GFP_KERNEL);
265 if (!context->ret.pointer) {
266 status = AE_NO_MEMORY;
267 goto out_kfree;
268 }
269 status = AE_OK;
270
271 out_kfree:
272 kfree(output.pointer);
273 if (status != AE_OK)
274 context->ret.pointer = NULL;
275 return status;
276 }
277 EXPORT_SYMBOL(acpi_run_osc);
278
279 bool osc_sb_apei_support_acked;
280 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
281 static void acpi_bus_osc_support(void)
282 {
283 u32 capbuf[2];
284 struct acpi_osc_context context = {
285 .uuid_str = sb_uuid_str,
286 .rev = 1,
287 .cap.length = 8,
288 .cap.pointer = capbuf,
289 };
290 acpi_handle handle;
291
292 capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
293 capbuf[OSC_SUPPORT_DWORD] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
294 #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
295 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
296 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PAD_SUPPORT;
297 #endif
298
299 #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
300 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
301 #endif
302
303 #ifdef ACPI_HOTPLUG_OST
304 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
305 #endif
306
307 if (!ghes_disable)
308 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
309 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
310 return;
311 if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
312 u32 *capbuf_ret = context.ret.pointer;
313 if (context.ret.length > OSC_SUPPORT_DWORD)
314 osc_sb_apei_support_acked =
315 capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
316 kfree(context.ret.pointer);
317 }
318 /* do we need to check other returned cap? Sounds no */
319 }
320
321 /* --------------------------------------------------------------------------
322 Notification Handling
323 -------------------------------------------------------------------------- */
324
325 /**
326 * acpi_bus_notify
327 * ---------------
328 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
329 */
330 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
331 {
332 struct acpi_device *device = NULL;
333 struct acpi_driver *driver;
334
335 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
336 type, handle));
337
338 switch (type) {
339
340 case ACPI_NOTIFY_BUS_CHECK:
341 /* TBD */
342 break;
343
344 case ACPI_NOTIFY_DEVICE_CHECK:
345 /* TBD */
346 break;
347
348 case ACPI_NOTIFY_DEVICE_WAKE:
349 /* TBD */
350 break;
351
352 case ACPI_NOTIFY_EJECT_REQUEST:
353 /* TBD */
354 break;
355
356 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
357 /* TBD: Exactly what does 'light' mean? */
358 break;
359
360 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
361 /* TBD */
362 break;
363
364 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
365 /* TBD */
366 break;
367
368 case ACPI_NOTIFY_POWER_FAULT:
369 /* TBD */
370 break;
371
372 default:
373 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
374 "Received unknown/unsupported notification [%08x]\n",
375 type));
376 break;
377 }
378
379 acpi_bus_get_device(handle, &device);
380 if (device) {
381 driver = device->driver;
382 if (driver && driver->ops.notify &&
383 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
384 driver->ops.notify(device, type);
385 }
386 }
387
388 /* --------------------------------------------------------------------------
389 Initialization/Cleanup
390 -------------------------------------------------------------------------- */
391
392 static int __init acpi_bus_init_irq(void)
393 {
394 acpi_status status;
395 char *message = NULL;
396
397
398 /*
399 * Let the system know what interrupt model we are using by
400 * evaluating the \_PIC object, if exists.
401 */
402
403 switch (acpi_irq_model) {
404 case ACPI_IRQ_MODEL_PIC:
405 message = "PIC";
406 break;
407 case ACPI_IRQ_MODEL_IOAPIC:
408 message = "IOAPIC";
409 break;
410 case ACPI_IRQ_MODEL_IOSAPIC:
411 message = "IOSAPIC";
412 break;
413 case ACPI_IRQ_MODEL_PLATFORM:
414 message = "platform specific model";
415 break;
416 default:
417 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
418 return -ENODEV;
419 }
420
421 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
422
423 status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
424 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
425 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
426 return -ENODEV;
427 }
428
429 return 0;
430 }
431
432 u8 acpi_gbl_permanent_mmap;
433
434
435 void __init acpi_early_init(void)
436 {
437 acpi_status status;
438
439 if (acpi_disabled)
440 return;
441
442 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
443
444 /* enable workarounds, unless strict ACPI spec. compliance */
445 if (!acpi_strict)
446 acpi_gbl_enable_interpreter_slack = TRUE;
447
448 acpi_gbl_permanent_mmap = 1;
449
450 /*
451 * If the machine falls into the DMI check table,
452 * DSDT will be copied to memory
453 */
454 dmi_check_system(dsdt_dmi_table);
455
456 status = acpi_reallocate_root_table();
457 if (ACPI_FAILURE(status)) {
458 printk(KERN_ERR PREFIX
459 "Unable to reallocate ACPI tables\n");
460 goto error0;
461 }
462
463 status = acpi_initialize_subsystem();
464 if (ACPI_FAILURE(status)) {
465 printk(KERN_ERR PREFIX
466 "Unable to initialize the ACPI Interpreter\n");
467 goto error0;
468 }
469
470 status = acpi_load_tables();
471 if (ACPI_FAILURE(status)) {
472 printk(KERN_ERR PREFIX
473 "Unable to load the System Description Tables\n");
474 goto error0;
475 }
476
477 #ifdef CONFIG_X86
478 if (!acpi_ioapic) {
479 /* compatible (0) means level (3) */
480 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
481 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
482 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
483 }
484 /* Set PIC-mode SCI trigger type */
485 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
486 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
487 } else {
488 /*
489 * now that acpi_gbl_FADT is initialized,
490 * update it with result from INT_SRC_OVR parsing
491 */
492 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
493 }
494 #endif
495
496 status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
497 if (ACPI_FAILURE(status)) {
498 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
499 goto error0;
500 }
501
502 return;
503
504 error0:
505 disable_acpi();
506 return;
507 }
508
509 static int __init acpi_bus_init(void)
510 {
511 int result;
512 acpi_status status;
513
514 acpi_os_initialize1();
515
516 status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
517 if (ACPI_FAILURE(status)) {
518 printk(KERN_ERR PREFIX
519 "Unable to start the ACPI Interpreter\n");
520 goto error1;
521 }
522
523 /*
524 * ACPI 2.0 requires the EC driver to be loaded and work before
525 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
526 * is called).
527 *
528 * This is accomplished by looking for the ECDT table, and getting
529 * the EC parameters out of that.
530 */
531 status = acpi_ec_ecdt_probe();
532 /* Ignore result. Not having an ECDT is not fatal. */
533
534 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
535 if (ACPI_FAILURE(status)) {
536 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
537 goto error1;
538 }
539
540 /*
541 * _OSC method may exist in module level code,
542 * so it must be run after ACPI_FULL_INITIALIZATION
543 */
544 acpi_bus_osc_support();
545
546 /*
547 * _PDC control method may load dynamic SSDT tables,
548 * and we need to install the table handler before that.
549 */
550 acpi_sysfs_init();
551
552 acpi_early_processor_set_pdc();
553
554 /*
555 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
556 * is necessary to enable it as early as possible.
557 */
558 acpi_boot_ec_enable();
559
560 printk(KERN_INFO PREFIX "Interpreter enabled\n");
561
562 /* Initialize sleep structures */
563 acpi_sleep_init();
564
565 /*
566 * Get the system interrupt model and evaluate \_PIC.
567 */
568 result = acpi_bus_init_irq();
569 if (result)
570 goto error1;
571
572 /*
573 * Register the for all standard device notifications.
574 */
575 status =
576 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
577 &acpi_bus_notify, NULL);
578 if (ACPI_FAILURE(status)) {
579 printk(KERN_ERR PREFIX
580 "Unable to register for device notifications\n");
581 goto error1;
582 }
583
584 /*
585 * Create the top ACPI proc directory
586 */
587 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
588
589 return 0;
590
591 /* Mimic structured exception handling */
592 error1:
593 acpi_terminate();
594 return -ENODEV;
595 }
596
597 struct kobject *acpi_kobj;
598 EXPORT_SYMBOL_GPL(acpi_kobj);
599
600 static int __init acpi_init(void)
601 {
602 int result;
603
604 if (acpi_disabled) {
605 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
606 return -ENODEV;
607 }
608
609 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
610 if (!acpi_kobj) {
611 printk(KERN_WARNING "%s: kset create error\n", __func__);
612 acpi_kobj = NULL;
613 }
614
615 init_acpi_device_notify();
616 result = acpi_bus_init();
617 if (result) {
618 disable_acpi();
619 return result;
620 }
621
622 pci_mmcfg_late_init();
623 acpi_scan_init();
624 acpi_ec_init();
625 acpi_debugfs_init();
626 acpi_sleep_proc_init();
627 acpi_wakeup_device_init();
628 return 0;
629 }
630
631 subsys_initcall(acpi_init);
This page took 0.0594 seconds and 5 git commands to generate.