2 * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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>
32 #include <linux/device.h>
33 #include <linux/proc_fs.h>
34 #include <linux/acpi.h>
35 #include <linux/slab.h>
36 #include <linux/regulator/machine.h>
38 #include <asm/mpspec.h>
40 #include <linux/pci.h>
41 #include <acpi/apei.h>
42 #include <linux/dmi.h>
43 #include <linux/suspend.h>
47 #define _COMPONENT ACPI_BUS_COMPONENT
48 ACPI_MODULE_NAME("bus");
50 struct acpi_device *acpi_root;
51 struct proc_dir_entry *acpi_root_dir;
52 EXPORT_SYMBOL(acpi_root_dir);
55 #ifdef CONFIG_ACPI_CUSTOM_DSDT
56 static inline int set_copy_dsdt(const struct dmi_system_id *id)
61 static int set_copy_dsdt(const struct dmi_system_id *id)
63 printk(KERN_NOTICE "%s detected - "
64 "force copy of DSDT to local memory\n", id->ident);
65 acpi_gbl_copy_dsdt_locally = 1;
70 static struct dmi_system_id dsdt_dmi_table[] __initdata = {
72 * Invoke DSDT corruption work-around on all Toshiba Satellite.
73 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
76 .callback = set_copy_dsdt,
77 .ident = "TOSHIBA Satellite",
79 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
80 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
86 static struct dmi_system_id dsdt_dmi_table[] __initdata = {
91 /* --------------------------------------------------------------------------
93 -------------------------------------------------------------------------- */
95 acpi_status acpi_bus_get_status_handle(acpi_handle handle,
96 unsigned long long *sta)
100 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
101 if (ACPI_SUCCESS(status))
104 if (status == AE_NOT_FOUND) {
105 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
106 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
112 int acpi_bus_get_status(struct acpi_device *device)
115 unsigned long long sta;
117 status = acpi_bus_get_status_handle(device->handle, &sta);
118 if (ACPI_FAILURE(status))
121 acpi_set_device_status(device, sta);
123 if (device->status.functional && !device->status.present) {
124 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
125 "functional but not present;\n",
126 device->pnp.bus_id, (u32)sta));
129 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
130 device->pnp.bus_id, (u32)sta));
133 EXPORT_SYMBOL(acpi_bus_get_status);
135 void acpi_bus_private_data_handler(acpi_handle handle,
140 EXPORT_SYMBOL(acpi_bus_private_data_handler);
142 int acpi_bus_get_private_data(acpi_handle handle, void **data)
149 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
150 if (ACPI_FAILURE(status) || !*data) {
151 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
158 EXPORT_SYMBOL(acpi_bus_get_private_data);
160 void acpi_bus_no_hotplug(acpi_handle handle)
162 struct acpi_device *adev = NULL;
164 acpi_bus_get_device(handle, &adev);
166 adev->flags.no_hotplug = true;
168 EXPORT_SYMBOL_GPL(acpi_bus_no_hotplug);
170 static void acpi_print_osc_error(acpi_handle handle,
171 struct acpi_osc_context *context, char *error)
173 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
176 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
177 printk(KERN_DEBUG "%s\n", error);
179 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
180 kfree(buffer.pointer);
182 printk(KERN_DEBUG"_OSC request data:");
183 for (i = 0; i < context->cap.length; i += sizeof(u32))
184 printk("%x ", *((u32 *)(context->cap.pointer + i)));
188 acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
191 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
192 24, 26, 28, 30, 32, 34};
194 if (strlen(str) != 36)
195 return AE_BAD_PARAMETER;
196 for (i = 0; i < 36; i++) {
197 if (i == 8 || i == 13 || i == 18 || i == 23) {
199 return AE_BAD_PARAMETER;
200 } else if (!isxdigit(str[i]))
201 return AE_BAD_PARAMETER;
203 for (i = 0; i < 16; i++) {
204 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
205 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
209 EXPORT_SYMBOL_GPL(acpi_str_to_uuid);
211 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
214 struct acpi_object_list input;
215 union acpi_object in_params[4];
216 union acpi_object *out_obj;
219 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
223 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
225 context->ret.length = ACPI_ALLOCATE_BUFFER;
226 context->ret.pointer = NULL;
228 /* Setting up input parameters */
230 input.pointer = in_params;
231 in_params[0].type = ACPI_TYPE_BUFFER;
232 in_params[0].buffer.length = 16;
233 in_params[0].buffer.pointer = uuid;
234 in_params[1].type = ACPI_TYPE_INTEGER;
235 in_params[1].integer.value = context->rev;
236 in_params[2].type = ACPI_TYPE_INTEGER;
237 in_params[2].integer.value = context->cap.length/sizeof(u32);
238 in_params[3].type = ACPI_TYPE_BUFFER;
239 in_params[3].buffer.length = context->cap.length;
240 in_params[3].buffer.pointer = context->cap.pointer;
242 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
243 if (ACPI_FAILURE(status))
247 return AE_NULL_OBJECT;
249 out_obj = output.pointer;
250 if (out_obj->type != ACPI_TYPE_BUFFER
251 || out_obj->buffer.length != context->cap.length) {
252 acpi_print_osc_error(handle, context,
253 "_OSC evaluation returned wrong type");
257 /* Need to ignore the bit0 in result code */
258 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
260 if (errors & OSC_REQUEST_ERROR)
261 acpi_print_osc_error(handle, context,
262 "_OSC request failed");
263 if (errors & OSC_INVALID_UUID_ERROR)
264 acpi_print_osc_error(handle, context,
265 "_OSC invalid UUID");
266 if (errors & OSC_INVALID_REVISION_ERROR)
267 acpi_print_osc_error(handle, context,
268 "_OSC invalid revision");
269 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
270 if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD]
280 context->ret.length = out_obj->buffer.length;
281 context->ret.pointer = kmemdup(out_obj->buffer.pointer,
282 context->ret.length, GFP_KERNEL);
283 if (!context->ret.pointer) {
284 status = AE_NO_MEMORY;
290 kfree(output.pointer);
292 context->ret.pointer = NULL;
295 EXPORT_SYMBOL(acpi_run_osc);
297 bool osc_sb_apei_support_acked;
298 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
299 static void acpi_bus_osc_support(void)
302 struct acpi_osc_context context = {
303 .uuid_str = sb_uuid_str,
306 .cap.pointer = capbuf,
310 capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
311 capbuf[OSC_SUPPORT_DWORD] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
312 #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
313 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
314 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PAD_SUPPORT;
317 #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
318 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
321 #ifdef ACPI_HOTPLUG_OST
322 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
326 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
327 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
329 if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
330 u32 *capbuf_ret = context.ret.pointer;
331 if (context.ret.length > OSC_SUPPORT_DWORD)
332 osc_sb_apei_support_acked =
333 capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
334 kfree(context.ret.pointer);
336 /* do we need to check other returned cap? Sounds no */
339 /* --------------------------------------------------------------------------
340 Notification Handling
341 -------------------------------------------------------------------------- */
346 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
348 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
350 struct acpi_device *device = NULL;
351 struct acpi_driver *driver;
353 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
358 case ACPI_NOTIFY_BUS_CHECK:
362 case ACPI_NOTIFY_DEVICE_CHECK:
366 case ACPI_NOTIFY_DEVICE_WAKE:
370 case ACPI_NOTIFY_EJECT_REQUEST:
374 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
375 /* TBD: Exactly what does 'light' mean? */
378 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
382 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
386 case ACPI_NOTIFY_POWER_FAULT:
391 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
392 "Received unknown/unsupported notification [%08x]\n",
397 acpi_bus_get_device(handle, &device);
399 driver = device->driver;
400 if (driver && driver->ops.notify &&
401 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
402 driver->ops.notify(device, type);
406 /* --------------------------------------------------------------------------
407 Initialization/Cleanup
408 -------------------------------------------------------------------------- */
410 static int __init acpi_bus_init_irq(void)
413 char *message = NULL;
417 * Let the system know what interrupt model we are using by
418 * evaluating the \_PIC object, if exists.
421 switch (acpi_irq_model) {
422 case ACPI_IRQ_MODEL_PIC:
425 case ACPI_IRQ_MODEL_IOAPIC:
428 case ACPI_IRQ_MODEL_IOSAPIC:
431 case ACPI_IRQ_MODEL_PLATFORM:
432 message = "platform specific model";
435 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
439 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
441 status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
442 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
443 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
450 u8 acpi_gbl_permanent_mmap;
453 void __init acpi_early_init(void)
460 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
462 /* enable workarounds, unless strict ACPI spec. compliance */
464 acpi_gbl_enable_interpreter_slack = TRUE;
466 acpi_gbl_permanent_mmap = 1;
469 * If the machine falls into the DMI check table,
470 * DSDT will be copied to memory
472 dmi_check_system(dsdt_dmi_table);
474 status = acpi_reallocate_root_table();
475 if (ACPI_FAILURE(status)) {
476 printk(KERN_ERR PREFIX
477 "Unable to reallocate ACPI tables\n");
481 status = acpi_initialize_subsystem();
482 if (ACPI_FAILURE(status)) {
483 printk(KERN_ERR PREFIX
484 "Unable to initialize the ACPI Interpreter\n");
488 status = acpi_load_tables();
489 if (ACPI_FAILURE(status)) {
490 printk(KERN_ERR PREFIX
491 "Unable to load the System Description Tables\n");
497 /* compatible (0) means level (3) */
498 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
499 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
500 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
502 /* Set PIC-mode SCI trigger type */
503 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
504 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
507 * now that acpi_gbl_FADT is initialized,
508 * update it with result from INT_SRC_OVR parsing
510 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
514 status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
515 if (ACPI_FAILURE(status)) {
516 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
521 * If the system is using ACPI then we can be reasonably
522 * confident that any regulators are managed by the firmware
523 * so tell the regulator core it has everything it needs to
526 regulator_has_full_constraints();
535 static int __init acpi_bus_init(void)
540 acpi_os_initialize1();
542 status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
543 if (ACPI_FAILURE(status)) {
544 printk(KERN_ERR PREFIX
545 "Unable to start the ACPI Interpreter\n");
550 * ACPI 2.0 requires the EC driver to be loaded and work before
551 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
554 * This is accomplished by looking for the ECDT table, and getting
555 * the EC parameters out of that.
557 status = acpi_ec_ecdt_probe();
558 /* Ignore result. Not having an ECDT is not fatal. */
560 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
561 if (ACPI_FAILURE(status)) {
562 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
567 * _OSC method may exist in module level code,
568 * so it must be run after ACPI_FULL_INITIALIZATION
570 acpi_bus_osc_support();
573 * _PDC control method may load dynamic SSDT tables,
574 * and we need to install the table handler before that.
578 acpi_early_processor_set_pdc();
581 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
582 * is necessary to enable it as early as possible.
584 acpi_boot_ec_enable();
586 printk(KERN_INFO PREFIX "Interpreter enabled\n");
588 /* Initialize sleep structures */
592 * Get the system interrupt model and evaluate \_PIC.
594 result = acpi_bus_init_irq();
599 * Register the for all standard device notifications.
602 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
603 &acpi_bus_notify, NULL);
604 if (ACPI_FAILURE(status)) {
605 printk(KERN_ERR PREFIX
606 "Unable to register for device notifications\n");
611 * Create the top ACPI proc directory
613 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
617 /* Mimic structured exception handling */
623 struct kobject *acpi_kobj;
624 EXPORT_SYMBOL_GPL(acpi_kobj);
626 static int __init acpi_init(void)
631 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
635 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
637 printk(KERN_WARNING "%s: kset create error\n", __func__);
641 init_acpi_device_notify();
642 result = acpi_bus_init();
648 pci_mmcfg_late_init();
652 acpi_sleep_proc_init();
653 acpi_wakeup_device_init();
657 subsys_initcall(acpi_init);