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/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
43 #include <acpi/apei.h>
44 #include <linux/dmi.h>
45 #include <linux/suspend.h>
49 #define _COMPONENT ACPI_BUS_COMPONENT
50 ACPI_MODULE_NAME("bus");
52 struct acpi_device
*acpi_root
;
53 struct proc_dir_entry
*acpi_root_dir
;
54 EXPORT_SYMBOL(acpi_root_dir
);
56 #define STRUCT_TO_INT(s) (*((int*)&s))
60 static int set_copy_dsdt(const struct dmi_system_id
*id
)
62 printk(KERN_NOTICE
"%s detected - "
63 "force copy of DSDT to local memory\n", id
->ident
);
64 acpi_gbl_copy_dsdt_locally
= 1;
68 static struct dmi_system_id dsdt_dmi_table
[] __initdata
= {
70 * Invoke DSDT corruption work-around on all Toshiba Satellite.
71 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
74 .callback
= set_copy_dsdt
,
75 .ident
= "TOSHIBA Satellite",
77 DMI_MATCH(DMI_SYS_VENDOR
, "TOSHIBA"),
78 DMI_MATCH(DMI_PRODUCT_NAME
, "Satellite"),
84 static struct dmi_system_id dsdt_dmi_table
[] __initdata
= {
89 /* --------------------------------------------------------------------------
91 -------------------------------------------------------------------------- */
93 acpi_status
acpi_bus_get_status_handle(acpi_handle handle
,
94 unsigned long long *sta
)
98 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, sta
);
99 if (ACPI_SUCCESS(status
))
102 if (status
== AE_NOT_FOUND
) {
103 *sta
= ACPI_STA_DEVICE_PRESENT
| ACPI_STA_DEVICE_ENABLED
|
104 ACPI_STA_DEVICE_UI
| ACPI_STA_DEVICE_FUNCTIONING
;
110 int acpi_bus_get_status(struct acpi_device
*device
)
113 unsigned long long sta
;
115 status
= acpi_bus_get_status_handle(device
->handle
, &sta
);
116 if (ACPI_FAILURE(status
))
119 STRUCT_TO_INT(device
->status
) = (int) sta
;
121 if (device
->status
.functional
&& !device
->status
.present
) {
122 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device [%s] status [%08x]: "
123 "functional but not present;\n",
125 (u32
) STRUCT_TO_INT(device
->status
)));
128 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device [%s] status [%08x]\n",
130 (u32
) STRUCT_TO_INT(device
->status
)));
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 -------------------------------------------------------------------------- */
343 static void acpi_bus_check_device(acpi_handle handle
)
345 struct acpi_device
*device
;
347 struct acpi_device_status old_status
;
349 if (acpi_bus_get_device(handle
, &device
))
354 old_status
= device
->status
;
357 * Make sure this device's parent is present before we go about
358 * messing with the device.
360 if (device
->parent
&& !device
->parent
->status
.present
) {
361 device
->status
= device
->parent
->status
;
365 status
= acpi_bus_get_status(device
);
366 if (ACPI_FAILURE(status
))
369 if (STRUCT_TO_INT(old_status
) == STRUCT_TO_INT(device
->status
))
373 * Device Insertion/Removal
375 if ((device
->status
.present
) && !(old_status
.present
)) {
376 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device insertion detected\n"));
377 /* TBD: Handle device insertion */
378 } else if (!(device
->status
.present
) && (old_status
.present
)) {
379 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device removal detected\n"));
380 /* TBD: Handle device removal */
384 static void acpi_bus_check_scope(acpi_handle handle
)
387 acpi_bus_check_device(handle
);
390 * TBD: Enumerate child devices within this device's scope and
391 * run acpi_bus_check_device()'s on them.
398 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
400 static void acpi_bus_notify(acpi_handle handle
, u32 type
, void *data
)
402 struct acpi_device
*device
= NULL
;
403 struct acpi_driver
*driver
;
405 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Notification %#02x to handle %p\n",
410 case ACPI_NOTIFY_BUS_CHECK
:
411 acpi_bus_check_scope(handle
);
413 * TBD: We'll need to outsource certain events to non-ACPI
414 * drivers via the device manager (device.c).
418 case ACPI_NOTIFY_DEVICE_CHECK
:
419 acpi_bus_check_device(handle
);
421 * TBD: We'll need to outsource certain events to non-ACPI
422 * drivers via the device manager (device.c).
426 case ACPI_NOTIFY_DEVICE_WAKE
:
430 case ACPI_NOTIFY_EJECT_REQUEST
:
434 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT
:
435 /* TBD: Exactly what does 'light' mean? */
438 case ACPI_NOTIFY_FREQUENCY_MISMATCH
:
442 case ACPI_NOTIFY_BUS_MODE_MISMATCH
:
446 case ACPI_NOTIFY_POWER_FAULT
:
451 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
452 "Received unknown/unsupported notification [%08x]\n",
457 acpi_bus_get_device(handle
, &device
);
459 driver
= device
->driver
;
460 if (driver
&& driver
->ops
.notify
&&
461 (driver
->flags
& ACPI_DRIVER_ALL_NOTIFY_EVENTS
))
462 driver
->ops
.notify(device
, type
);
466 /* --------------------------------------------------------------------------
467 Initialization/Cleanup
468 -------------------------------------------------------------------------- */
470 static int __init
acpi_bus_init_irq(void)
473 char *message
= NULL
;
477 * Let the system know what interrupt model we are using by
478 * evaluating the \_PIC object, if exists.
481 switch (acpi_irq_model
) {
482 case ACPI_IRQ_MODEL_PIC
:
485 case ACPI_IRQ_MODEL_IOAPIC
:
488 case ACPI_IRQ_MODEL_IOSAPIC
:
491 case ACPI_IRQ_MODEL_PLATFORM
:
492 message
= "platform specific model";
495 printk(KERN_WARNING PREFIX
"Unknown interrupt routing model\n");
499 printk(KERN_INFO PREFIX
"Using %s for interrupt routing\n", message
);
501 status
= acpi_execute_simple_method(NULL
, "\\_PIC", acpi_irq_model
);
502 if (ACPI_FAILURE(status
) && (status
!= AE_NOT_FOUND
)) {
503 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _PIC"));
510 u8 acpi_gbl_permanent_mmap
;
513 void __init
acpi_early_init(void)
520 printk(KERN_INFO PREFIX
"Core revision %08x\n", ACPI_CA_VERSION
);
522 /* enable workarounds, unless strict ACPI spec. compliance */
524 acpi_gbl_enable_interpreter_slack
= TRUE
;
526 acpi_gbl_permanent_mmap
= 1;
529 * If the machine falls into the DMI check table,
530 * DSDT will be copied to memory
532 dmi_check_system(dsdt_dmi_table
);
534 status
= acpi_reallocate_root_table();
535 if (ACPI_FAILURE(status
)) {
536 printk(KERN_ERR PREFIX
537 "Unable to reallocate ACPI tables\n");
541 status
= acpi_initialize_subsystem();
542 if (ACPI_FAILURE(status
)) {
543 printk(KERN_ERR PREFIX
544 "Unable to initialize the ACPI Interpreter\n");
548 status
= acpi_load_tables();
549 if (ACPI_FAILURE(status
)) {
550 printk(KERN_ERR PREFIX
551 "Unable to load the System Description Tables\n");
557 /* compatible (0) means level (3) */
558 if (!(acpi_sci_flags
& ACPI_MADT_TRIGGER_MASK
)) {
559 acpi_sci_flags
&= ~ACPI_MADT_TRIGGER_MASK
;
560 acpi_sci_flags
|= ACPI_MADT_TRIGGER_LEVEL
;
562 /* Set PIC-mode SCI trigger type */
563 acpi_pic_sci_set_trigger(acpi_gbl_FADT
.sci_interrupt
,
564 (acpi_sci_flags
& ACPI_MADT_TRIGGER_MASK
) >> 2);
567 * now that acpi_gbl_FADT is initialized,
568 * update it with result from INT_SRC_OVR parsing
570 acpi_gbl_FADT
.sci_interrupt
= acpi_sci_override_gsi
;
574 status
= acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE
);
575 if (ACPI_FAILURE(status
)) {
576 printk(KERN_ERR PREFIX
"Unable to enable ACPI\n");
581 * If the system is using ACPI then we can be reasonably
582 * confident that any regulators are managed by the firmware
583 * so tell the regulator core it has everything it needs to
586 regulator_has_full_constraints();
595 static int __init
acpi_bus_init(void)
600 acpi_os_initialize1();
602 status
= acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE
);
603 if (ACPI_FAILURE(status
)) {
604 printk(KERN_ERR PREFIX
605 "Unable to start the ACPI Interpreter\n");
610 * ACPI 2.0 requires the EC driver to be loaded and work before
611 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
614 * This is accomplished by looking for the ECDT table, and getting
615 * the EC parameters out of that.
617 status
= acpi_ec_ecdt_probe();
618 /* Ignore result. Not having an ECDT is not fatal. */
620 status
= acpi_initialize_objects(ACPI_FULL_INITIALIZATION
);
621 if (ACPI_FAILURE(status
)) {
622 printk(KERN_ERR PREFIX
"Unable to initialize ACPI objects\n");
627 * _OSC method may exist in module level code,
628 * so it must be run after ACPI_FULL_INITIALIZATION
630 acpi_bus_osc_support();
633 * _PDC control method may load dynamic SSDT tables,
634 * and we need to install the table handler before that.
638 acpi_early_processor_set_pdc();
641 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
642 * is necessary to enable it as early as possible.
644 acpi_boot_ec_enable();
646 printk(KERN_INFO PREFIX
"Interpreter enabled\n");
648 /* Initialize sleep structures */
652 * Get the system interrupt model and evaluate \_PIC.
654 result
= acpi_bus_init_irq();
659 * Register the for all standard device notifications.
662 acpi_install_notify_handler(ACPI_ROOT_OBJECT
, ACPI_SYSTEM_NOTIFY
,
663 &acpi_bus_notify
, NULL
);
664 if (ACPI_FAILURE(status
)) {
665 printk(KERN_ERR PREFIX
666 "Unable to register for device notifications\n");
671 * Create the top ACPI proc directory
673 acpi_root_dir
= proc_mkdir(ACPI_BUS_FILE_ROOT
, NULL
);
677 /* Mimic structured exception handling */
683 struct kobject
*acpi_kobj
;
684 EXPORT_SYMBOL_GPL(acpi_kobj
);
686 static int __init
acpi_init(void)
691 printk(KERN_INFO PREFIX
"Interpreter disabled.\n");
695 acpi_kobj
= kobject_create_and_add("acpi", firmware_kobj
);
697 printk(KERN_WARNING
"%s: kset create error\n", __func__
);
701 init_acpi_device_notify();
702 result
= acpi_bus_init();
708 pci_mmcfg_late_init();
712 acpi_sleep_proc_init();
713 acpi_wakeup_device_init();
717 subsys_initcall(acpi_init
);