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 #ifdef CONFIG_ACPI_CUSTOM_DSDT
61 static inline int set_copy_dsdt(const struct dmi_system_id
*id
)
66 static int set_copy_dsdt(const struct dmi_system_id
*id
)
68 printk(KERN_NOTICE
"%s detected - "
69 "force copy of DSDT to local memory\n", id
->ident
);
70 acpi_gbl_copy_dsdt_locally
= 1;
75 static struct dmi_system_id dsdt_dmi_table
[] __initdata
= {
77 * Invoke DSDT corruption work-around on all Toshiba Satellite.
78 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
81 .callback
= set_copy_dsdt
,
82 .ident
= "TOSHIBA Satellite",
84 DMI_MATCH(DMI_SYS_VENDOR
, "TOSHIBA"),
85 DMI_MATCH(DMI_PRODUCT_NAME
, "Satellite"),
91 static struct dmi_system_id dsdt_dmi_table
[] __initdata
= {
96 /* --------------------------------------------------------------------------
98 -------------------------------------------------------------------------- */
100 acpi_status
acpi_bus_get_status_handle(acpi_handle handle
,
101 unsigned long long *sta
)
105 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, sta
);
106 if (ACPI_SUCCESS(status
))
109 if (status
== AE_NOT_FOUND
) {
110 *sta
= ACPI_STA_DEVICE_PRESENT
| ACPI_STA_DEVICE_ENABLED
|
111 ACPI_STA_DEVICE_UI
| ACPI_STA_DEVICE_FUNCTIONING
;
117 int acpi_bus_get_status(struct acpi_device
*device
)
120 unsigned long long sta
;
122 status
= acpi_bus_get_status_handle(device
->handle
, &sta
);
123 if (ACPI_FAILURE(status
))
126 STRUCT_TO_INT(device
->status
) = (int) sta
;
128 if (device
->status
.functional
&& !device
->status
.present
) {
129 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device [%s] status [%08x]: "
130 "functional but not present;\n",
132 (u32
) STRUCT_TO_INT(device
->status
)));
135 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device [%s] status [%08x]\n",
137 (u32
) STRUCT_TO_INT(device
->status
)));
140 EXPORT_SYMBOL(acpi_bus_get_status
);
142 void acpi_bus_private_data_handler(acpi_handle handle
,
147 EXPORT_SYMBOL(acpi_bus_private_data_handler
);
149 int acpi_bus_get_private_data(acpi_handle handle
, void **data
)
156 status
= acpi_get_data(handle
, acpi_bus_private_data_handler
, data
);
157 if (ACPI_FAILURE(status
) || !*data
) {
158 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No context for object [%p]\n",
165 EXPORT_SYMBOL(acpi_bus_get_private_data
);
167 void acpi_bus_no_hotplug(acpi_handle handle
)
169 struct acpi_device
*adev
= NULL
;
171 acpi_bus_get_device(handle
, &adev
);
173 adev
->flags
.no_hotplug
= true;
175 EXPORT_SYMBOL_GPL(acpi_bus_no_hotplug
);
177 static void acpi_print_osc_error(acpi_handle handle
,
178 struct acpi_osc_context
*context
, char *error
)
180 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
};
183 if (ACPI_FAILURE(acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
)))
184 printk(KERN_DEBUG
"%s\n", error
);
186 printk(KERN_DEBUG
"%s:%s\n", (char *)buffer
.pointer
, error
);
187 kfree(buffer
.pointer
);
189 printk(KERN_DEBUG
"_OSC request data:");
190 for (i
= 0; i
< context
->cap
.length
; i
+= sizeof(u32
))
191 printk("%x ", *((u32
*)(context
->cap
.pointer
+ i
)));
195 static acpi_status
acpi_str_to_uuid(char *str
, u8
*uuid
)
198 static int opc_map_to_uuid
[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
199 24, 26, 28, 30, 32, 34};
201 if (strlen(str
) != 36)
202 return AE_BAD_PARAMETER
;
203 for (i
= 0; i
< 36; i
++) {
204 if (i
== 8 || i
== 13 || i
== 18 || i
== 23) {
206 return AE_BAD_PARAMETER
;
207 } else if (!isxdigit(str
[i
]))
208 return AE_BAD_PARAMETER
;
210 for (i
= 0; i
< 16; i
++) {
211 uuid
[i
] = hex_to_bin(str
[opc_map_to_uuid
[i
]]) << 4;
212 uuid
[i
] |= hex_to_bin(str
[opc_map_to_uuid
[i
] + 1]);
217 acpi_status
acpi_run_osc(acpi_handle handle
, struct acpi_osc_context
*context
)
220 struct acpi_object_list input
;
221 union acpi_object in_params
[4];
222 union acpi_object
*out_obj
;
225 struct acpi_buffer output
= {ACPI_ALLOCATE_BUFFER
, NULL
};
229 if (ACPI_FAILURE(acpi_str_to_uuid(context
->uuid_str
, uuid
)))
231 context
->ret
.length
= ACPI_ALLOCATE_BUFFER
;
232 context
->ret
.pointer
= NULL
;
234 /* Setting up input parameters */
236 input
.pointer
= in_params
;
237 in_params
[0].type
= ACPI_TYPE_BUFFER
;
238 in_params
[0].buffer
.length
= 16;
239 in_params
[0].buffer
.pointer
= uuid
;
240 in_params
[1].type
= ACPI_TYPE_INTEGER
;
241 in_params
[1].integer
.value
= context
->rev
;
242 in_params
[2].type
= ACPI_TYPE_INTEGER
;
243 in_params
[2].integer
.value
= context
->cap
.length
/sizeof(u32
);
244 in_params
[3].type
= ACPI_TYPE_BUFFER
;
245 in_params
[3].buffer
.length
= context
->cap
.length
;
246 in_params
[3].buffer
.pointer
= context
->cap
.pointer
;
248 status
= acpi_evaluate_object(handle
, "_OSC", &input
, &output
);
249 if (ACPI_FAILURE(status
))
253 return AE_NULL_OBJECT
;
255 out_obj
= output
.pointer
;
256 if (out_obj
->type
!= ACPI_TYPE_BUFFER
257 || out_obj
->buffer
.length
!= context
->cap
.length
) {
258 acpi_print_osc_error(handle
, context
,
259 "_OSC evaluation returned wrong type");
263 /* Need to ignore the bit0 in result code */
264 errors
= *((u32
*)out_obj
->buffer
.pointer
) & ~(1 << 0);
266 if (errors
& OSC_REQUEST_ERROR
)
267 acpi_print_osc_error(handle
, context
,
268 "_OSC request failed");
269 if (errors
& OSC_INVALID_UUID_ERROR
)
270 acpi_print_osc_error(handle
, context
,
271 "_OSC invalid UUID");
272 if (errors
& OSC_INVALID_REVISION_ERROR
)
273 acpi_print_osc_error(handle
, context
,
274 "_OSC invalid revision");
275 if (errors
& OSC_CAPABILITIES_MASK_ERROR
) {
276 if (((u32
*)context
->cap
.pointer
)[OSC_QUERY_TYPE
]
286 context
->ret
.length
= out_obj
->buffer
.length
;
287 context
->ret
.pointer
= kmemdup(out_obj
->buffer
.pointer
,
288 context
->ret
.length
, GFP_KERNEL
);
289 if (!context
->ret
.pointer
) {
290 status
= AE_NO_MEMORY
;
296 kfree(output
.pointer
);
298 context
->ret
.pointer
= NULL
;
301 EXPORT_SYMBOL(acpi_run_osc
);
303 bool osc_sb_apei_support_acked
;
304 static u8 sb_uuid_str
[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
305 static void acpi_bus_osc_support(void)
308 struct acpi_osc_context context
= {
309 .uuid_str
= sb_uuid_str
,
312 .cap
.pointer
= capbuf
,
316 capbuf
[OSC_QUERY_TYPE
] = OSC_QUERY_ENABLE
;
317 capbuf
[OSC_SUPPORT_TYPE
] = OSC_SB_PR3_SUPPORT
; /* _PR3 is in use */
318 #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
319 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
320 capbuf
[OSC_SUPPORT_TYPE
] |= OSC_SB_PAD_SUPPORT
;
323 #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
324 capbuf
[OSC_SUPPORT_TYPE
] |= OSC_SB_PPC_OST_SUPPORT
;
327 #ifdef ACPI_HOTPLUG_OST
328 capbuf
[OSC_SUPPORT_TYPE
] |= OSC_SB_HOTPLUG_OST_SUPPORT
;
332 capbuf
[OSC_SUPPORT_TYPE
] |= OSC_SB_APEI_SUPPORT
;
333 if (ACPI_FAILURE(acpi_get_handle(NULL
, "\\_SB", &handle
)))
335 if (ACPI_SUCCESS(acpi_run_osc(handle
, &context
))) {
336 u32
*capbuf_ret
= context
.ret
.pointer
;
337 if (context
.ret
.length
> OSC_SUPPORT_TYPE
)
338 osc_sb_apei_support_acked
=
339 capbuf_ret
[OSC_SUPPORT_TYPE
] & OSC_SB_APEI_SUPPORT
;
340 kfree(context
.ret
.pointer
);
342 /* do we need to check other returned cap? Sounds no */
345 /* --------------------------------------------------------------------------
346 Notification Handling
347 -------------------------------------------------------------------------- */
349 static void acpi_bus_check_device(acpi_handle handle
)
351 struct acpi_device
*device
;
353 struct acpi_device_status old_status
;
355 if (acpi_bus_get_device(handle
, &device
))
360 old_status
= device
->status
;
363 * Make sure this device's parent is present before we go about
364 * messing with the device.
366 if (device
->parent
&& !device
->parent
->status
.present
) {
367 device
->status
= device
->parent
->status
;
371 status
= acpi_bus_get_status(device
);
372 if (ACPI_FAILURE(status
))
375 if (STRUCT_TO_INT(old_status
) == STRUCT_TO_INT(device
->status
))
379 * Device Insertion/Removal
381 if ((device
->status
.present
) && !(old_status
.present
)) {
382 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device insertion detected\n"));
383 /* TBD: Handle device insertion */
384 } else if (!(device
->status
.present
) && (old_status
.present
)) {
385 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Device removal detected\n"));
386 /* TBD: Handle device removal */
390 static void acpi_bus_check_scope(acpi_handle handle
)
393 acpi_bus_check_device(handle
);
396 * TBD: Enumerate child devices within this device's scope and
397 * run acpi_bus_check_device()'s on them.
404 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
406 static void acpi_bus_notify(acpi_handle handle
, u32 type
, void *data
)
408 struct acpi_device
*device
= NULL
;
409 struct acpi_driver
*driver
;
411 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Notification %#02x to handle %p\n",
416 case ACPI_NOTIFY_BUS_CHECK
:
417 acpi_bus_check_scope(handle
);
419 * TBD: We'll need to outsource certain events to non-ACPI
420 * drivers via the device manager (device.c).
424 case ACPI_NOTIFY_DEVICE_CHECK
:
425 acpi_bus_check_device(handle
);
427 * TBD: We'll need to outsource certain events to non-ACPI
428 * drivers via the device manager (device.c).
432 case ACPI_NOTIFY_DEVICE_WAKE
:
436 case ACPI_NOTIFY_EJECT_REQUEST
:
440 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT
:
441 /* TBD: Exactly what does 'light' mean? */
444 case ACPI_NOTIFY_FREQUENCY_MISMATCH
:
448 case ACPI_NOTIFY_BUS_MODE_MISMATCH
:
452 case ACPI_NOTIFY_POWER_FAULT
:
457 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
458 "Received unknown/unsupported notification [%08x]\n",
463 acpi_bus_get_device(handle
, &device
);
465 driver
= device
->driver
;
466 if (driver
&& driver
->ops
.notify
&&
467 (driver
->flags
& ACPI_DRIVER_ALL_NOTIFY_EVENTS
))
468 driver
->ops
.notify(device
, type
);
472 /* --------------------------------------------------------------------------
473 Initialization/Cleanup
474 -------------------------------------------------------------------------- */
476 static int __init
acpi_bus_init_irq(void)
479 char *message
= NULL
;
483 * Let the system know what interrupt model we are using by
484 * evaluating the \_PIC object, if exists.
487 switch (acpi_irq_model
) {
488 case ACPI_IRQ_MODEL_PIC
:
491 case ACPI_IRQ_MODEL_IOAPIC
:
494 case ACPI_IRQ_MODEL_IOSAPIC
:
497 case ACPI_IRQ_MODEL_PLATFORM
:
498 message
= "platform specific model";
501 printk(KERN_WARNING PREFIX
"Unknown interrupt routing model\n");
505 printk(KERN_INFO PREFIX
"Using %s for interrupt routing\n", message
);
507 status
= acpi_execute_simple_method(NULL
, "\\_PIC", acpi_irq_model
);
508 if (ACPI_FAILURE(status
) && (status
!= AE_NOT_FOUND
)) {
509 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _PIC"));
516 u8 acpi_gbl_permanent_mmap
;
519 void __init
acpi_early_init(void)
526 printk(KERN_INFO PREFIX
"Core revision %08x\n", ACPI_CA_VERSION
);
528 /* enable workarounds, unless strict ACPI spec. compliance */
530 acpi_gbl_enable_interpreter_slack
= TRUE
;
532 acpi_gbl_permanent_mmap
= 1;
535 * If the machine falls into the DMI check table,
536 * DSDT will be copied to memory
538 dmi_check_system(dsdt_dmi_table
);
540 status
= acpi_reallocate_root_table();
541 if (ACPI_FAILURE(status
)) {
542 printk(KERN_ERR PREFIX
543 "Unable to reallocate ACPI tables\n");
547 status
= acpi_initialize_subsystem();
548 if (ACPI_FAILURE(status
)) {
549 printk(KERN_ERR PREFIX
550 "Unable to initialize the ACPI Interpreter\n");
554 status
= acpi_load_tables();
555 if (ACPI_FAILURE(status
)) {
556 printk(KERN_ERR PREFIX
557 "Unable to load the System Description Tables\n");
563 /* compatible (0) means level (3) */
564 if (!(acpi_sci_flags
& ACPI_MADT_TRIGGER_MASK
)) {
565 acpi_sci_flags
&= ~ACPI_MADT_TRIGGER_MASK
;
566 acpi_sci_flags
|= ACPI_MADT_TRIGGER_LEVEL
;
568 /* Set PIC-mode SCI trigger type */
569 acpi_pic_sci_set_trigger(acpi_gbl_FADT
.sci_interrupt
,
570 (acpi_sci_flags
& ACPI_MADT_TRIGGER_MASK
) >> 2);
573 * now that acpi_gbl_FADT is initialized,
574 * update it with result from INT_SRC_OVR parsing
576 acpi_gbl_FADT
.sci_interrupt
= acpi_sci_override_gsi
;
580 status
= acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE
);
581 if (ACPI_FAILURE(status
)) {
582 printk(KERN_ERR PREFIX
"Unable to enable ACPI\n");
587 * If the system is using ACPI then we can be reasonably
588 * confident that any regulators are managed by the firmware
589 * so tell the regulator core it has everything it needs to
592 regulator_has_full_constraints();
601 static int __init
acpi_bus_init(void)
606 acpi_os_initialize1();
608 status
= acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE
);
609 if (ACPI_FAILURE(status
)) {
610 printk(KERN_ERR PREFIX
611 "Unable to start the ACPI Interpreter\n");
616 * ACPI 2.0 requires the EC driver to be loaded and work before
617 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
620 * This is accomplished by looking for the ECDT table, and getting
621 * the EC parameters out of that.
623 status
= acpi_ec_ecdt_probe();
624 /* Ignore result. Not having an ECDT is not fatal. */
626 status
= acpi_initialize_objects(ACPI_FULL_INITIALIZATION
);
627 if (ACPI_FAILURE(status
)) {
628 printk(KERN_ERR PREFIX
"Unable to initialize ACPI objects\n");
633 * _OSC method may exist in module level code,
634 * so it must be run after ACPI_FULL_INITIALIZATION
636 acpi_bus_osc_support();
639 * _PDC control method may load dynamic SSDT tables,
640 * and we need to install the table handler before that.
644 acpi_early_processor_set_pdc();
647 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
648 * is necessary to enable it as early as possible.
650 acpi_boot_ec_enable();
652 printk(KERN_INFO PREFIX
"Interpreter enabled\n");
654 /* Initialize sleep structures */
658 * Get the system interrupt model and evaluate \_PIC.
660 result
= acpi_bus_init_irq();
665 * Register the for all standard device notifications.
668 acpi_install_notify_handler(ACPI_ROOT_OBJECT
, ACPI_SYSTEM_NOTIFY
,
669 &acpi_bus_notify
, NULL
);
670 if (ACPI_FAILURE(status
)) {
671 printk(KERN_ERR PREFIX
672 "Unable to register for device notifications\n");
677 * Create the top ACPI proc directory
679 acpi_root_dir
= proc_mkdir(ACPI_BUS_FILE_ROOT
, NULL
);
683 /* Mimic structured exception handling */
689 struct kobject
*acpi_kobj
;
690 EXPORT_SYMBOL_GPL(acpi_kobj
);
692 static int __init
acpi_init(void)
697 printk(KERN_INFO PREFIX
"Interpreter disabled.\n");
701 acpi_kobj
= kobject_create_and_add("acpi", firmware_kobj
);
703 printk(KERN_WARNING
"%s: kset create error\n", __func__
);
707 init_acpi_device_notify();
708 result
= acpi_bus_init();
714 pci_mmcfg_late_init();
718 acpi_sleep_proc_init();
719 acpi_wakeup_device_init();
723 subsys_initcall(acpi_init
);