2 * acpi_osl.c - OS-dependent functions ($Revision: 83 $)
4 * Copyright (C) 2000 Andrew Henroid
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * Copyright (c) 2008 Intel Corporation
8 * Author: Matthew Wilcox <willy@linux.intel.com>
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/pci.h>
32 #include <linux/interrupt.h>
33 #include <linux/kmod.h>
34 #include <linux/delay.h>
35 #include <linux/workqueue.h>
36 #include <linux/nmi.h>
37 #include <linux/acpi.h>
38 #include <linux/efi.h>
39 #include <linux/ioport.h>
40 #include <linux/list.h>
41 #include <linux/jiffies.h>
42 #include <linux/semaphore.h>
45 #include <asm/uaccess.h>
46 #include <linux/io-64-nonatomic-lo-hi.h>
50 #define _COMPONENT ACPI_OS_SERVICES
51 ACPI_MODULE_NAME("osl");
54 acpi_osd_exec_callback function;
56 struct work_struct work;
59 #ifdef CONFIG_ACPI_CUSTOM_DSDT
60 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
63 #ifdef ENABLE_DEBUGGER
64 #include <linux/kdb.h>
66 /* stuff for debugger support */
68 EXPORT_SYMBOL(acpi_in_debugger);
69 #endif /*ENABLE_DEBUGGER */
71 static int (*__acpi_os_prepare_sleep)(u8 sleep_state, u32 pm1a_ctrl,
73 static int (*__acpi_os_prepare_extended_sleep)(u8 sleep_state, u32 val_a,
76 static acpi_osd_handler acpi_irq_handler;
77 static void *acpi_irq_context;
78 static struct workqueue_struct *kacpid_wq;
79 static struct workqueue_struct *kacpi_notify_wq;
80 static struct workqueue_struct *kacpi_hotplug_wq;
81 static bool acpi_os_initialized;
82 unsigned int acpi_sci_irq = INVALID_ACPI_IRQ;
85 * This list of permanent mappings is for memory that may be accessed from
86 * interrupt context, where we can't do the ioremap().
89 struct list_head list;
91 acpi_physical_address phys;
93 unsigned long refcount;
96 static LIST_HEAD(acpi_ioremaps);
97 static DEFINE_MUTEX(acpi_ioremap_lock);
99 static void __init acpi_osi_setup_late(void);
102 * The story of _OSI(Linux)
104 * From pre-history through Linux-2.6.22,
105 * Linux responded TRUE upon a BIOS OSI(Linux) query.
107 * Unfortunately, reference BIOS writers got wind of this
108 * and put OSI(Linux) in their example code, quickly exposing
109 * this string as ill-conceived and opening the door to
110 * an un-bounded number of BIOS incompatibilities.
112 * For example, OSI(Linux) was used on resume to re-POST a
113 * video card on one system, because Linux at that time
114 * could not do a speedy restore in its native driver.
115 * But then upon gaining quick native restore capability,
116 * Linux has no way to tell the BIOS to skip the time-consuming
117 * POST -- putting Linux at a permanent performance disadvantage.
118 * On another system, the BIOS writer used OSI(Linux)
119 * to infer native OS support for IPMI! On other systems,
120 * OSI(Linux) simply got in the way of Linux claiming to
121 * be compatible with other operating systems, exposing
122 * BIOS issues such as skipped device initialization.
124 * So "Linux" turned out to be a really poor chose of
125 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
127 * BIOS writers should NOT query _OSI(Linux) on future systems.
128 * Linux will complain on the console when it sees it, and return FALSE.
129 * To get Linux to return TRUE for your system will require
130 * a kernel source update to add a DMI entry,
131 * or boot with "acpi_osi=Linux"
134 static struct acpi_osi_config {
135 unsigned int linux_enable:1;
136 unsigned int linux_dmi:1;
137 unsigned int linux_cmdline:1;
138 unsigned int darwin_enable:1;
139 unsigned int darwin_dmi:1;
140 unsigned int darwin_cmdline:1;
141 u8 default_disabling;
144 static u32 acpi_osi_handler(acpi_string interface, u32 supported)
146 if (!strcmp("Linux", interface)) {
148 pr_notice_once(FW_BUG PREFIX
149 "BIOS _OSI(Linux) query %s%s\n",
150 osi_config.linux_enable ? "honored" : "ignored",
151 osi_config.linux_cmdline ? " via cmdline" :
152 osi_config.linux_dmi ? " via DMI" : "");
155 if (!strcmp("Darwin", interface)) {
157 pr_notice_once(PREFIX
158 "BIOS _OSI(Darwin) query %s%s\n",
159 osi_config.darwin_enable ? "honored" : "ignored",
160 osi_config.darwin_cmdline ? " via cmdline" :
161 osi_config.darwin_dmi ? " via DMI" : "");
167 static void __init acpi_request_region (struct acpi_generic_address *gas,
168 unsigned int length, char *desc)
172 /* Handle possible alignment issues */
173 memcpy(&addr, &gas->address, sizeof(addr));
174 if (!addr || !length)
177 /* Resources are never freed */
178 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
179 request_region(addr, length, desc);
180 else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
181 request_mem_region(addr, length, desc);
184 static int __init acpi_reserve_resources(void)
186 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
187 "ACPI PM1a_EVT_BLK");
189 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
190 "ACPI PM1b_EVT_BLK");
192 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
193 "ACPI PM1a_CNT_BLK");
195 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
196 "ACPI PM1b_CNT_BLK");
198 if (acpi_gbl_FADT.pm_timer_length == 4)
199 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
201 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
204 /* Length of GPE blocks must be a non-negative multiple of 2 */
206 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
207 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
208 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
210 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
211 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
212 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
216 fs_initcall_sync(acpi_reserve_resources);
218 void acpi_os_printf(const char *fmt, ...)
222 acpi_os_vprintf(fmt, args);
225 EXPORT_SYMBOL(acpi_os_printf);
227 void acpi_os_vprintf(const char *fmt, va_list args)
229 static char buffer[512];
231 vsprintf(buffer, fmt, args);
233 #ifdef ENABLE_DEBUGGER
234 if (acpi_in_debugger) {
235 kdb_printf("%s", buffer);
237 printk(KERN_CONT "%s", buffer);
240 if (acpi_debugger_write_log(buffer) < 0)
241 printk(KERN_CONT "%s", buffer);
246 static unsigned long acpi_rsdp;
247 static int __init setup_acpi_rsdp(char *arg)
249 if (kstrtoul(arg, 16, &acpi_rsdp))
253 early_param("acpi_rsdp", setup_acpi_rsdp);
256 acpi_physical_address __init acpi_os_get_root_pointer(void)
263 if (efi_enabled(EFI_CONFIG_TABLES)) {
264 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
266 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
269 printk(KERN_ERR PREFIX
270 "System description tables not found\n");
273 } else if (IS_ENABLED(CONFIG_ACPI_LEGACY_TABLES_LOOKUP)) {
274 acpi_physical_address pa = 0;
276 acpi_find_root_pointer(&pa);
283 /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
284 static struct acpi_ioremap *
285 acpi_map_lookup(acpi_physical_address phys, acpi_size size)
287 struct acpi_ioremap *map;
289 list_for_each_entry_rcu(map, &acpi_ioremaps, list)
290 if (map->phys <= phys &&
291 phys + size <= map->phys + map->size)
297 /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
298 static void __iomem *
299 acpi_map_vaddr_lookup(acpi_physical_address phys, unsigned int size)
301 struct acpi_ioremap *map;
303 map = acpi_map_lookup(phys, size);
305 return map->virt + (phys - map->phys);
310 void __iomem *acpi_os_get_iomem(acpi_physical_address phys, unsigned int size)
312 struct acpi_ioremap *map;
313 void __iomem *virt = NULL;
315 mutex_lock(&acpi_ioremap_lock);
316 map = acpi_map_lookup(phys, size);
318 virt = map->virt + (phys - map->phys);
321 mutex_unlock(&acpi_ioremap_lock);
324 EXPORT_SYMBOL_GPL(acpi_os_get_iomem);
326 /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
327 static struct acpi_ioremap *
328 acpi_map_lookup_virt(void __iomem *virt, acpi_size size)
330 struct acpi_ioremap *map;
332 list_for_each_entry_rcu(map, &acpi_ioremaps, list)
333 if (map->virt <= virt &&
334 virt + size <= map->virt + map->size)
340 #if defined(CONFIG_IA64) || defined(CONFIG_ARM64)
341 /* ioremap will take care of cache attributes */
342 #define should_use_kmap(pfn) 0
344 #define should_use_kmap(pfn) page_is_ram(pfn)
347 static void __iomem *acpi_map(acpi_physical_address pg_off, unsigned long pg_sz)
351 pfn = pg_off >> PAGE_SHIFT;
352 if (should_use_kmap(pfn)) {
353 if (pg_sz > PAGE_SIZE)
355 return (void __iomem __force *)kmap(pfn_to_page(pfn));
357 return acpi_os_ioremap(pg_off, pg_sz);
360 static void acpi_unmap(acpi_physical_address pg_off, void __iomem *vaddr)
364 pfn = pg_off >> PAGE_SHIFT;
365 if (should_use_kmap(pfn))
366 kunmap(pfn_to_page(pfn));
372 * acpi_os_map_iomem - Get a virtual address for a given physical address range.
373 * @phys: Start of the physical address range to map.
374 * @size: Size of the physical address range to map.
376 * Look up the given physical address range in the list of existing ACPI memory
377 * mappings. If found, get a reference to it and return a pointer to it (its
378 * virtual address). If not found, map it, add it to that list and return a
381 * During early init (when acpi_gbl_permanent_mmap has not been set yet) this
382 * routine simply calls __acpi_map_table() to get the job done.
384 void __iomem *__init_refok
385 acpi_os_map_iomem(acpi_physical_address phys, acpi_size size)
387 struct acpi_ioremap *map;
389 acpi_physical_address pg_off;
392 if (phys > ULONG_MAX) {
393 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
397 if (!acpi_gbl_permanent_mmap)
398 return __acpi_map_table((unsigned long)phys, size);
400 mutex_lock(&acpi_ioremap_lock);
401 /* Check if there's a suitable mapping already. */
402 map = acpi_map_lookup(phys, size);
408 map = kzalloc(sizeof(*map), GFP_KERNEL);
410 mutex_unlock(&acpi_ioremap_lock);
414 pg_off = round_down(phys, PAGE_SIZE);
415 pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off;
416 virt = acpi_map(pg_off, pg_sz);
418 mutex_unlock(&acpi_ioremap_lock);
423 INIT_LIST_HEAD(&map->list);
429 list_add_tail_rcu(&map->list, &acpi_ioremaps);
432 mutex_unlock(&acpi_ioremap_lock);
433 return map->virt + (phys - map->phys);
435 EXPORT_SYMBOL_GPL(acpi_os_map_iomem);
438 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
440 return (void *)acpi_os_map_iomem(phys, size);
442 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
444 static void acpi_os_drop_map_ref(struct acpi_ioremap *map)
446 if (!--map->refcount)
447 list_del_rcu(&map->list);
450 static void acpi_os_map_cleanup(struct acpi_ioremap *map)
452 if (!map->refcount) {
453 synchronize_rcu_expedited();
454 acpi_unmap(map->phys, map->virt);
460 * acpi_os_unmap_iomem - Drop a memory mapping reference.
461 * @virt: Start of the address range to drop a reference to.
462 * @size: Size of the address range to drop a reference to.
464 * Look up the given virtual address range in the list of existing ACPI memory
465 * mappings, drop a reference to it and unmap it if there are no more active
468 * During early init (when acpi_gbl_permanent_mmap has not been set yet) this
469 * routine simply calls __acpi_unmap_table() to get the job done. Since
470 * __acpi_unmap_table() is an __init function, the __ref annotation is needed
473 void __ref acpi_os_unmap_iomem(void __iomem *virt, acpi_size size)
475 struct acpi_ioremap *map;
477 if (!acpi_gbl_permanent_mmap) {
478 __acpi_unmap_table(virt, size);
482 mutex_lock(&acpi_ioremap_lock);
483 map = acpi_map_lookup_virt(virt, size);
485 mutex_unlock(&acpi_ioremap_lock);
486 WARN(true, PREFIX "%s: bad address %p\n", __func__, virt);
489 acpi_os_drop_map_ref(map);
490 mutex_unlock(&acpi_ioremap_lock);
492 acpi_os_map_cleanup(map);
494 EXPORT_SYMBOL_GPL(acpi_os_unmap_iomem);
496 void __ref acpi_os_unmap_memory(void *virt, acpi_size size)
498 return acpi_os_unmap_iomem((void __iomem *)virt, size);
500 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
502 void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
504 if (!acpi_gbl_permanent_mmap)
505 __acpi_unmap_table(virt, size);
508 int acpi_os_map_generic_address(struct acpi_generic_address *gas)
513 if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
516 /* Handle possible alignment issues */
517 memcpy(&addr, &gas->address, sizeof(addr));
518 if (!addr || !gas->bit_width)
521 virt = acpi_os_map_iomem(addr, gas->bit_width / 8);
527 EXPORT_SYMBOL(acpi_os_map_generic_address);
529 void acpi_os_unmap_generic_address(struct acpi_generic_address *gas)
532 struct acpi_ioremap *map;
534 if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
537 /* Handle possible alignment issues */
538 memcpy(&addr, &gas->address, sizeof(addr));
539 if (!addr || !gas->bit_width)
542 mutex_lock(&acpi_ioremap_lock);
543 map = acpi_map_lookup(addr, gas->bit_width / 8);
545 mutex_unlock(&acpi_ioremap_lock);
548 acpi_os_drop_map_ref(map);
549 mutex_unlock(&acpi_ioremap_lock);
551 acpi_os_map_cleanup(map);
553 EXPORT_SYMBOL(acpi_os_unmap_generic_address);
555 #ifdef ACPI_FUTURE_USAGE
557 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
560 return AE_BAD_PARAMETER;
562 *phys = virt_to_phys(virt);
568 #ifdef CONFIG_ACPI_REV_OVERRIDE_POSSIBLE
569 static bool acpi_rev_override;
571 int __init acpi_rev_override_setup(char *str)
573 acpi_rev_override = true;
576 __setup("acpi_rev_override", acpi_rev_override_setup);
578 #define acpi_rev_override false
581 #define ACPI_MAX_OVERRIDE_LEN 100
583 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
586 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
589 if (!init_val || !new_val)
590 return AE_BAD_PARAMETER;
593 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
594 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
596 *new_val = acpi_os_name;
599 if (!memcmp(init_val->name, "_REV", 4) && acpi_rev_override) {
600 printk(KERN_INFO PREFIX "Overriding _REV return value to 5\n");
601 *new_val = (char *)5;
607 static void acpi_table_taint(struct acpi_table_header *table)
610 "Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n",
611 table->signature, table->oem_table_id);
612 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
615 #ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
616 #include <linux/earlycpio.h>
617 #include <linux/memblock.h>
619 static u64 acpi_tables_addr;
620 static int all_tables_size;
622 /* Copied from acpica/tbutils.c:acpi_tb_checksum() */
623 static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
626 u8 *end = buffer + length;
629 sum = (u8) (sum + *(buffer++));
633 /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
634 static const char * const table_sigs[] = {
635 ACPI_SIG_BERT, ACPI_SIG_CPEP, ACPI_SIG_ECDT, ACPI_SIG_EINJ,
636 ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT, ACPI_SIG_MSCT,
637 ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT, ACPI_SIG_ASF,
638 ACPI_SIG_BOOT, ACPI_SIG_DBGP, ACPI_SIG_DMAR, ACPI_SIG_HPET,
639 ACPI_SIG_IBFT, ACPI_SIG_IVRS, ACPI_SIG_MCFG, ACPI_SIG_MCHI,
640 ACPI_SIG_SLIC, ACPI_SIG_SPCR, ACPI_SIG_SPMI, ACPI_SIG_TCPA,
641 ACPI_SIG_UEFI, ACPI_SIG_WAET, ACPI_SIG_WDAT, ACPI_SIG_WDDT,
642 ACPI_SIG_WDRT, ACPI_SIG_DSDT, ACPI_SIG_FADT, ACPI_SIG_PSDT,
643 ACPI_SIG_RSDT, ACPI_SIG_XSDT, ACPI_SIG_SSDT, NULL };
645 #define ACPI_HEADER_SIZE sizeof(struct acpi_table_header)
647 #define ACPI_OVERRIDE_TABLES 64
648 static struct cpio_data __initdata acpi_initrd_files[ACPI_OVERRIDE_TABLES];
649 static DECLARE_BITMAP(acpi_initrd_installed, ACPI_OVERRIDE_TABLES);
651 #define MAP_CHUNK_SIZE (NR_FIX_BTMAPS << PAGE_SHIFT)
653 void __init acpi_initrd_override(void *data, size_t size)
655 int sig, no, table_nr = 0, total_offset = 0;
657 struct acpi_table_header *table;
658 char cpio_path[32] = "kernel/firmware/acpi/";
659 struct cpio_data file;
661 if (data == NULL || size == 0)
664 for (no = 0; no < ACPI_OVERRIDE_TABLES; no++) {
665 file = find_cpio_data(cpio_path, data, size, &offset);
672 if (file.size < sizeof(struct acpi_table_header)) {
673 pr_err("ACPI OVERRIDE: Table smaller than ACPI header [%s%s]\n",
674 cpio_path, file.name);
680 for (sig = 0; table_sigs[sig]; sig++)
681 if (!memcmp(table->signature, table_sigs[sig], 4))
684 if (!table_sigs[sig]) {
685 pr_err("ACPI OVERRIDE: Unknown signature [%s%s]\n",
686 cpio_path, file.name);
689 if (file.size != table->length) {
690 pr_err("ACPI OVERRIDE: File length does not match table length [%s%s]\n",
691 cpio_path, file.name);
694 if (acpi_table_checksum(file.data, table->length)) {
695 pr_err("ACPI OVERRIDE: Bad table checksum [%s%s]\n",
696 cpio_path, file.name);
700 pr_info("%4.4s ACPI table found in initrd [%s%s][0x%x]\n",
701 table->signature, cpio_path, file.name, table->length);
703 all_tables_size += table->length;
704 acpi_initrd_files[table_nr].data = file.data;
705 acpi_initrd_files[table_nr].size = file.size;
712 memblock_find_in_range(0, max_low_pfn_mapped << PAGE_SHIFT,
713 all_tables_size, PAGE_SIZE);
714 if (!acpi_tables_addr) {
719 * Only calling e820_add_reserve does not work and the
720 * tables are invalid (memory got used) later.
721 * memblock_reserve works as expected and the tables won't get modified.
722 * But it's not enough on X86 because ioremap will
723 * complain later (used by acpi_os_map_memory) that the pages
724 * that should get mapped are not marked "reserved".
725 * Both memblock_reserve and e820_add_region (via arch_reserve_mem_area)
728 memblock_reserve(acpi_tables_addr, all_tables_size);
729 arch_reserve_mem_area(acpi_tables_addr, all_tables_size);
732 * early_ioremap only can remap 256k one time. If we map all
733 * tables one time, we will hit the limit. Need to map chunks
734 * one by one during copying the same as that in relocate_initrd().
736 for (no = 0; no < table_nr; no++) {
737 unsigned char *src_p = acpi_initrd_files[no].data;
738 phys_addr_t size = acpi_initrd_files[no].size;
739 phys_addr_t dest_addr = acpi_tables_addr + total_offset;
740 phys_addr_t slop, clen;
743 total_offset += size;
746 slop = dest_addr & ~PAGE_MASK;
748 if (clen > MAP_CHUNK_SIZE - slop)
749 clen = MAP_CHUNK_SIZE - slop;
750 dest_p = early_ioremap(dest_addr & PAGE_MASK,
752 memcpy(dest_p + slop, src_p, clen);
753 early_iounmap(dest_p, clen + slop);
762 acpi_os_physical_table_override(struct acpi_table_header *existing_table,
763 acpi_physical_address *address, u32 *length)
765 int table_offset = 0;
767 struct acpi_table_header *table;
772 if (!acpi_tables_addr)
775 while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
776 table = acpi_os_map_memory(acpi_tables_addr + table_offset,
778 if (table_offset + table->length > all_tables_size) {
779 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
784 table_length = table->length;
786 /* Only override tables matched */
787 if (test_bit(table_index, acpi_initrd_installed) ||
788 memcmp(existing_table->signature, table->signature, 4) ||
789 memcmp(table->oem_table_id, existing_table->oem_table_id,
790 ACPI_OEM_TABLE_ID_SIZE)) {
791 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
795 *length = table_length;
796 *address = acpi_tables_addr + table_offset;
797 acpi_table_taint(existing_table);
798 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
799 set_bit(table_index, acpi_initrd_installed);
803 table_offset += table_length;
809 void __init acpi_initrd_initialize_tables(void)
811 int table_offset = 0;
814 struct acpi_table_header *table;
816 if (!acpi_tables_addr)
819 while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
820 table = acpi_os_map_memory(acpi_tables_addr + table_offset,
822 if (table_offset + table->length > all_tables_size) {
823 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
828 table_length = table->length;
830 /* Skip RSDT/XSDT which should only be used for override */
831 if (test_bit(table_index, acpi_initrd_installed) ||
832 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_RSDT) ||
833 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_XSDT)) {
834 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
838 acpi_table_taint(table);
839 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
840 acpi_install_table(acpi_tables_addr + table_offset, TRUE);
841 set_bit(table_index, acpi_initrd_installed);
843 table_offset += table_length;
849 acpi_os_physical_table_override(struct acpi_table_header *existing_table,
850 acpi_physical_address *address,
858 void __init acpi_initrd_initialize_tables(void)
861 #endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */
864 acpi_os_table_override(struct acpi_table_header *existing_table,
865 struct acpi_table_header **new_table)
867 if (!existing_table || !new_table)
868 return AE_BAD_PARAMETER;
872 #ifdef CONFIG_ACPI_CUSTOM_DSDT
873 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
874 *new_table = (struct acpi_table_header *)AmlCode;
876 if (*new_table != NULL)
877 acpi_table_taint(existing_table);
881 static irqreturn_t acpi_irq(int irq, void *dev_id)
885 handled = (*acpi_irq_handler) (acpi_irq_context);
891 acpi_irq_not_handled++;
897 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
902 acpi_irq_stats_init();
905 * ACPI interrupts different from the SCI in our copy of the FADT are
908 if (gsi != acpi_gbl_FADT.sci_interrupt)
909 return AE_BAD_PARAMETER;
911 if (acpi_irq_handler)
912 return AE_ALREADY_ACQUIRED;
914 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
915 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
920 acpi_irq_handler = handler;
921 acpi_irq_context = context;
922 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
923 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
924 acpi_irq_handler = NULL;
925 return AE_NOT_ACQUIRED;
932 acpi_status acpi_os_remove_interrupt_handler(u32 gsi, acpi_osd_handler handler)
934 if (gsi != acpi_gbl_FADT.sci_interrupt || !acpi_sci_irq_valid())
935 return AE_BAD_PARAMETER;
937 free_irq(acpi_sci_irq, acpi_irq);
938 acpi_irq_handler = NULL;
939 acpi_sci_irq = INVALID_ACPI_IRQ;
945 * Running in interpreter thread context, safe to sleep
948 void acpi_os_sleep(u64 ms)
953 void acpi_os_stall(u32 us)
961 touch_nmi_watchdog();
967 * Support ACPI 3.0 AML Timer operand
968 * Returns 64-bit free-running, monotonically increasing timer
969 * with 100ns granularity
971 u64 acpi_os_get_timer(void)
973 u64 time_ns = ktime_to_ns(ktime_get());
974 do_div(time_ns, 100);
978 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
987 *(u8 *) value = inb(port);
988 } else if (width <= 16) {
989 *(u16 *) value = inw(port);
990 } else if (width <= 32) {
991 *(u32 *) value = inl(port);
999 EXPORT_SYMBOL(acpi_os_read_port);
1001 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
1005 } else if (width <= 16) {
1007 } else if (width <= 32) {
1016 EXPORT_SYMBOL(acpi_os_write_port);
1019 acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
1021 void __iomem *virt_addr;
1022 unsigned int size = width / 8;
1027 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
1030 virt_addr = acpi_os_ioremap(phys_addr, size);
1032 return AE_BAD_ADDRESS;
1041 *(u8 *) value = readb(virt_addr);
1044 *(u16 *) value = readw(virt_addr);
1047 *(u32 *) value = readl(virt_addr);
1050 *(u64 *) value = readq(virt_addr);
1065 acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
1067 void __iomem *virt_addr;
1068 unsigned int size = width / 8;
1072 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
1075 virt_addr = acpi_os_ioremap(phys_addr, size);
1077 return AE_BAD_ADDRESS;
1083 writeb(value, virt_addr);
1086 writew(value, virt_addr);
1089 writel(value, virt_addr);
1092 writeq(value, virt_addr);
1107 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
1108 u64 *value, u32 width)
1114 return AE_BAD_PARAMETER;
1130 result = raw_pci_read(pci_id->segment, pci_id->bus,
1131 PCI_DEVFN(pci_id->device, pci_id->function),
1132 reg, size, &value32);
1135 return (result ? AE_ERROR : AE_OK);
1139 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
1140 u64 value, u32 width)
1158 result = raw_pci_write(pci_id->segment, pci_id->bus,
1159 PCI_DEVFN(pci_id->device, pci_id->function),
1162 return (result ? AE_ERROR : AE_OK);
1165 static void acpi_os_execute_deferred(struct work_struct *work)
1167 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
1169 dpc->function(dpc->context);
1173 #ifdef CONFIG_ACPI_DEBUGGER
1174 static struct acpi_debugger acpi_debugger;
1175 static bool acpi_debugger_initialized;
1177 int acpi_register_debugger(struct module *owner,
1178 const struct acpi_debugger_ops *ops)
1182 mutex_lock(&acpi_debugger.lock);
1183 if (acpi_debugger.ops) {
1188 acpi_debugger.owner = owner;
1189 acpi_debugger.ops = ops;
1192 mutex_unlock(&acpi_debugger.lock);
1195 EXPORT_SYMBOL(acpi_register_debugger);
1197 void acpi_unregister_debugger(const struct acpi_debugger_ops *ops)
1199 mutex_lock(&acpi_debugger.lock);
1200 if (ops == acpi_debugger.ops) {
1201 acpi_debugger.ops = NULL;
1202 acpi_debugger.owner = NULL;
1204 mutex_unlock(&acpi_debugger.lock);
1206 EXPORT_SYMBOL(acpi_unregister_debugger);
1208 int acpi_debugger_create_thread(acpi_osd_exec_callback function, void *context)
1211 int (*func)(acpi_osd_exec_callback, void *);
1212 struct module *owner;
1214 if (!acpi_debugger_initialized)
1216 mutex_lock(&acpi_debugger.lock);
1217 if (!acpi_debugger.ops) {
1221 if (!try_module_get(acpi_debugger.owner)) {
1225 func = acpi_debugger.ops->create_thread;
1226 owner = acpi_debugger.owner;
1227 mutex_unlock(&acpi_debugger.lock);
1229 ret = func(function, context);
1231 mutex_lock(&acpi_debugger.lock);
1234 mutex_unlock(&acpi_debugger.lock);
1238 ssize_t acpi_debugger_write_log(const char *msg)
1241 ssize_t (*func)(const char *);
1242 struct module *owner;
1244 if (!acpi_debugger_initialized)
1246 mutex_lock(&acpi_debugger.lock);
1247 if (!acpi_debugger.ops) {
1251 if (!try_module_get(acpi_debugger.owner)) {
1255 func = acpi_debugger.ops->write_log;
1256 owner = acpi_debugger.owner;
1257 mutex_unlock(&acpi_debugger.lock);
1261 mutex_lock(&acpi_debugger.lock);
1264 mutex_unlock(&acpi_debugger.lock);
1268 ssize_t acpi_debugger_read_cmd(char *buffer, size_t buffer_length)
1271 ssize_t (*func)(char *, size_t);
1272 struct module *owner;
1274 if (!acpi_debugger_initialized)
1276 mutex_lock(&acpi_debugger.lock);
1277 if (!acpi_debugger.ops) {
1281 if (!try_module_get(acpi_debugger.owner)) {
1285 func = acpi_debugger.ops->read_cmd;
1286 owner = acpi_debugger.owner;
1287 mutex_unlock(&acpi_debugger.lock);
1289 ret = func(buffer, buffer_length);
1291 mutex_lock(&acpi_debugger.lock);
1294 mutex_unlock(&acpi_debugger.lock);
1298 int acpi_debugger_wait_command_ready(void)
1301 int (*func)(bool, char *, size_t);
1302 struct module *owner;
1304 if (!acpi_debugger_initialized)
1306 mutex_lock(&acpi_debugger.lock);
1307 if (!acpi_debugger.ops) {
1311 if (!try_module_get(acpi_debugger.owner)) {
1315 func = acpi_debugger.ops->wait_command_ready;
1316 owner = acpi_debugger.owner;
1317 mutex_unlock(&acpi_debugger.lock);
1319 ret = func(acpi_gbl_method_executing,
1320 acpi_gbl_db_line_buf, ACPI_DB_LINE_BUFFER_SIZE);
1322 mutex_lock(&acpi_debugger.lock);
1325 mutex_unlock(&acpi_debugger.lock);
1329 int acpi_debugger_notify_command_complete(void)
1333 struct module *owner;
1335 if (!acpi_debugger_initialized)
1337 mutex_lock(&acpi_debugger.lock);
1338 if (!acpi_debugger.ops) {
1342 if (!try_module_get(acpi_debugger.owner)) {
1346 func = acpi_debugger.ops->notify_command_complete;
1347 owner = acpi_debugger.owner;
1348 mutex_unlock(&acpi_debugger.lock);
1352 mutex_lock(&acpi_debugger.lock);
1355 mutex_unlock(&acpi_debugger.lock);
1359 int __init acpi_debugger_init(void)
1361 mutex_init(&acpi_debugger.lock);
1362 acpi_debugger_initialized = true;
1367 /*******************************************************************************
1369 * FUNCTION: acpi_os_execute
1371 * PARAMETERS: Type - Type of the callback
1372 * Function - Function to be executed
1373 * Context - Function parameters
1377 * DESCRIPTION: Depending on type, either queues function for deferred execution or
1378 * immediately executes function on a separate thread.
1380 ******************************************************************************/
1382 acpi_status acpi_os_execute(acpi_execute_type type,
1383 acpi_osd_exec_callback function, void *context)
1385 acpi_status status = AE_OK;
1386 struct acpi_os_dpc *dpc;
1387 struct workqueue_struct *queue;
1389 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
1390 "Scheduling function [%p(%p)] for deferred execution.\n",
1391 function, context));
1393 if (type == OSL_DEBUGGER_MAIN_THREAD) {
1394 ret = acpi_debugger_create_thread(function, context);
1396 pr_err("Call to kthread_create() failed.\n");
1403 * Allocate/initialize DPC structure. Note that this memory will be
1404 * freed by the callee. The kernel handles the work_struct list in a
1405 * way that allows us to also free its memory inside the callee.
1406 * Because we may want to schedule several tasks with different
1407 * parameters we can't use the approach some kernel code uses of
1408 * having a static work_struct.
1411 dpc = kzalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
1413 return AE_NO_MEMORY;
1415 dpc->function = function;
1416 dpc->context = context;
1419 * To prevent lockdep from complaining unnecessarily, make sure that
1420 * there is a different static lockdep key for each workqueue by using
1421 * INIT_WORK() for each of them separately.
1423 if (type == OSL_NOTIFY_HANDLER) {
1424 queue = kacpi_notify_wq;
1425 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
1426 } else if (type == OSL_GPE_HANDLER) {
1428 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
1430 pr_err("Unsupported os_execute type %d.\n", type);
1434 if (ACPI_FAILURE(status))
1438 * On some machines, a software-initiated SMI causes corruption unless
1439 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
1440 * typically it's done in GPE-related methods that are run via
1441 * workqueues, so we can avoid the known corruption cases by always
1442 * queueing on CPU 0.
1444 ret = queue_work_on(0, queue, &dpc->work);
1446 printk(KERN_ERR PREFIX
1447 "Call to queue_work() failed.\n");
1451 if (ACPI_FAILURE(status))
1456 EXPORT_SYMBOL(acpi_os_execute);
1458 void acpi_os_wait_events_complete(void)
1461 * Make sure the GPE handler or the fixed event handler is not used
1462 * on another CPU after removal.
1464 if (acpi_sci_irq_valid())
1465 synchronize_hardirq(acpi_sci_irq);
1466 flush_workqueue(kacpid_wq);
1467 flush_workqueue(kacpi_notify_wq);
1470 struct acpi_hp_work {
1471 struct work_struct work;
1472 struct acpi_device *adev;
1476 static void acpi_hotplug_work_fn(struct work_struct *work)
1478 struct acpi_hp_work *hpw = container_of(work, struct acpi_hp_work, work);
1480 acpi_os_wait_events_complete();
1481 acpi_device_hotplug(hpw->adev, hpw->src);
1485 acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src)
1487 struct acpi_hp_work *hpw;
1489 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
1490 "Scheduling hotplug event (%p, %u) for deferred execution.\n",
1493 hpw = kmalloc(sizeof(*hpw), GFP_KERNEL);
1495 return AE_NO_MEMORY;
1497 INIT_WORK(&hpw->work, acpi_hotplug_work_fn);
1501 * We can't run hotplug code in kacpid_wq/kacpid_notify_wq etc., because
1502 * the hotplug code may call driver .remove() functions, which may
1503 * invoke flush_scheduled_work()/acpi_os_wait_events_complete() to flush
1506 if (!queue_work(kacpi_hotplug_wq, &hpw->work)) {
1513 bool acpi_queue_hotplug_work(struct work_struct *work)
1515 return queue_work(kacpi_hotplug_wq, work);
1519 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
1521 struct semaphore *sem = NULL;
1523 sem = acpi_os_allocate_zeroed(sizeof(struct semaphore));
1525 return AE_NO_MEMORY;
1527 sema_init(sem, initial_units);
1529 *handle = (acpi_handle *) sem;
1531 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
1532 *handle, initial_units));
1538 * TODO: A better way to delete semaphores? Linux doesn't have a
1539 * 'delete_semaphore()' function -- may result in an invalid
1540 * pointer dereference for non-synchronized consumers. Should
1541 * we at least check for blocked threads and signal/cancel them?
1544 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
1546 struct semaphore *sem = (struct semaphore *)handle;
1549 return AE_BAD_PARAMETER;
1551 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
1553 BUG_ON(!list_empty(&sem->wait_list));
1561 * TODO: Support for units > 1?
1563 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
1565 acpi_status status = AE_OK;
1566 struct semaphore *sem = (struct semaphore *)handle;
1570 if (!acpi_os_initialized)
1573 if (!sem || (units < 1))
1574 return AE_BAD_PARAMETER;
1579 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
1580 handle, units, timeout));
1582 if (timeout == ACPI_WAIT_FOREVER)
1583 jiffies = MAX_SCHEDULE_TIMEOUT;
1585 jiffies = msecs_to_jiffies(timeout);
1587 ret = down_timeout(sem, jiffies);
1591 if (ACPI_FAILURE(status)) {
1592 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
1593 "Failed to acquire semaphore[%p|%d|%d], %s",
1594 handle, units, timeout,
1595 acpi_format_exception(status)));
1597 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
1598 "Acquired semaphore[%p|%d|%d]", handle,
1606 * TODO: Support for units > 1?
1608 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
1610 struct semaphore *sem = (struct semaphore *)handle;
1612 if (!acpi_os_initialized)
1615 if (!sem || (units < 1))
1616 return AE_BAD_PARAMETER;
1621 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
1629 acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read)
1631 #ifdef ENABLE_DEBUGGER
1632 if (acpi_in_debugger) {
1635 kdb_read(buffer, buffer_length);
1637 /* remove the CR kdb includes */
1638 chars = strlen(buffer) - 1;
1639 buffer[chars] = '\0';
1644 ret = acpi_debugger_read_cmd(buffer, buffer_length);
1653 EXPORT_SYMBOL(acpi_os_get_line);
1655 acpi_status acpi_os_wait_command_ready(void)
1659 ret = acpi_debugger_wait_command_ready();
1665 acpi_status acpi_os_notify_command_complete(void)
1669 ret = acpi_debugger_notify_command_complete();
1675 acpi_status acpi_os_signal(u32 function, void *info)
1678 case ACPI_SIGNAL_FATAL:
1679 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
1681 case ACPI_SIGNAL_BREAKPOINT:
1684 * ACPI spec. says to treat it as a NOP unless
1685 * you are debugging. So if/when we integrate
1686 * AML debugger into the kernel debugger its
1687 * hook will go here. But until then it is
1688 * not useful to print anything on breakpoints.
1698 static int __init acpi_os_name_setup(char *str)
1700 char *p = acpi_os_name;
1701 int count = ACPI_MAX_OVERRIDE_LEN - 1;
1706 for (; count-- && *str; str++) {
1707 if (isalnum(*str) || *str == ' ' || *str == ':')
1709 else if (*str == '\'' || *str == '"')
1720 __setup("acpi_os_name=", acpi_os_name_setup);
1722 #define OSI_STRING_LENGTH_MAX 64
1723 #define OSI_STRING_ENTRIES_MAX 16
1725 struct acpi_osi_entry {
1726 char string[OSI_STRING_LENGTH_MAX];
1730 static struct acpi_osi_entry
1731 osi_setup_entries[OSI_STRING_ENTRIES_MAX] __initdata = {
1732 {"Module Device", true},
1733 {"Processor Device", true},
1734 {"3.0 _SCP Extensions", true},
1735 {"Processor Aggregator Device", true},
1738 void __init acpi_osi_setup(char *str)
1740 struct acpi_osi_entry *osi;
1744 if (!acpi_gbl_create_osi_method)
1747 if (str == NULL || *str == '\0') {
1748 pr_info(PREFIX "_OSI method disabled\n");
1749 acpi_gbl_create_osi_method = FALSE;
1756 /* Do not override acpi_osi=!* */
1757 if (!osi_config.default_disabling)
1758 osi_config.default_disabling =
1759 ACPI_DISABLE_ALL_VENDOR_STRINGS;
1761 } else if (*str == '*') {
1762 osi_config.default_disabling = ACPI_DISABLE_ALL_STRINGS;
1763 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1764 osi = &osi_setup_entries[i];
1765 osi->enable = false;
1768 } else if (*str == '!') {
1769 osi_config.default_disabling = 0;
1775 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1776 osi = &osi_setup_entries[i];
1777 if (!strcmp(osi->string, str)) {
1778 osi->enable = enable;
1780 } else if (osi->string[0] == '\0') {
1781 osi->enable = enable;
1782 strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
1788 static void __init __acpi_osi_setup_darwin(bool enable)
1790 osi_config.darwin_enable = !!enable;
1792 acpi_osi_setup("!");
1793 acpi_osi_setup("Darwin");
1795 acpi_osi_setup("!!");
1796 acpi_osi_setup("!Darwin");
1800 static void __init acpi_osi_setup_darwin(bool enable)
1802 osi_config.darwin_cmdline = 1;
1803 osi_config.darwin_dmi = 0;
1804 __acpi_osi_setup_darwin(enable);
1807 void __init acpi_osi_dmi_darwin(bool enable, const struct dmi_system_id *d)
1809 pr_notice(PREFIX "DMI detected to setup _OSI(\"Darwin\"): %s\n",
1811 osi_config.darwin_dmi = 1;
1812 __acpi_osi_setup_darwin(enable);
1815 static void __init __acpi_osi_setup_linux(bool enable)
1817 osi_config.linux_enable = !!enable;
1819 acpi_osi_setup("Linux");
1821 acpi_osi_setup("!Linux");
1824 static void __init acpi_osi_setup_linux(bool enable)
1826 osi_config.linux_cmdline = 1;
1827 osi_config.linux_dmi = 0;
1828 __acpi_osi_setup_linux(enable);
1831 void __init acpi_osi_dmi_linux(bool enable, const struct dmi_system_id *d)
1833 pr_notice(PREFIX "DMI detected to setup _OSI(\"Linux\"): %s\n",
1835 osi_config.linux_dmi = 1;
1836 __acpi_osi_setup_linux(enable);
1840 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1842 * empty string disables _OSI
1843 * string starting with '!' disables that string
1844 * otherwise string is added to list, augmenting built-in strings
1846 static void __init acpi_osi_setup_late(void)
1848 struct acpi_osi_entry *osi;
1853 if (osi_config.default_disabling) {
1854 status = acpi_update_interfaces(osi_config.default_disabling);
1856 if (ACPI_SUCCESS(status))
1857 pr_info(PREFIX "Disabled all _OSI OS vendors%s\n",
1858 osi_config.default_disabling ==
1859 ACPI_DISABLE_ALL_STRINGS ?
1860 " and feature groups" : "");
1863 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1864 osi = &osi_setup_entries[i];
1870 status = acpi_install_interface(str);
1872 if (ACPI_SUCCESS(status))
1873 pr_info(PREFIX "Added _OSI(%s)\n", str);
1875 status = acpi_remove_interface(str);
1877 if (ACPI_SUCCESS(status))
1878 pr_info(PREFIX "Deleted _OSI(%s)\n", str);
1883 static int __init osi_setup(char *str)
1885 if (str && !strcmp("Linux", str))
1886 acpi_osi_setup_linux(true);
1887 else if (str && !strcmp("!Linux", str))
1888 acpi_osi_setup_linux(false);
1889 else if (str && !strcmp("Darwin", str))
1890 acpi_osi_setup_darwin(true);
1891 else if (str && !strcmp("!Darwin", str))
1892 acpi_osi_setup_darwin(false);
1894 acpi_osi_setup(str);
1899 __setup("acpi_osi=", osi_setup);
1902 * Disable the auto-serialization of named objects creation methods.
1904 * This feature is enabled by default. It marks the AML control methods
1905 * that contain the opcodes to create named objects as "Serialized".
1907 static int __init acpi_no_auto_serialize_setup(char *str)
1909 acpi_gbl_auto_serialize_methods = FALSE;
1910 pr_info("ACPI: auto-serialization disabled\n");
1915 __setup("acpi_no_auto_serialize", acpi_no_auto_serialize_setup);
1917 /* Check of resource interference between native drivers and ACPI
1918 * OperationRegions (SystemIO and System Memory only).
1919 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1920 * in arbitrary AML code and can interfere with legacy drivers.
1921 * acpi_enforce_resources= can be set to:
1923 * - strict (default) (2)
1924 * -> further driver trying to access the resources will not load
1926 * -> further driver trying to access the resources will load, but you
1927 * get a system message that something might go wrong...
1930 * -> ACPI Operation Region resources will not be registered
1933 #define ENFORCE_RESOURCES_STRICT 2
1934 #define ENFORCE_RESOURCES_LAX 1
1935 #define ENFORCE_RESOURCES_NO 0
1937 static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1939 static int __init acpi_enforce_resources_setup(char *str)
1941 if (str == NULL || *str == '\0')
1944 if (!strcmp("strict", str))
1945 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1946 else if (!strcmp("lax", str))
1947 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1948 else if (!strcmp("no", str))
1949 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1954 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1956 /* Check for resource conflicts between ACPI OperationRegions and native
1958 int acpi_check_resource_conflict(const struct resource *res)
1960 acpi_adr_space_type space_id;
1965 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1967 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1970 if (res->flags & IORESOURCE_IO)
1971 space_id = ACPI_ADR_SPACE_SYSTEM_IO;
1973 space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
1975 length = resource_size(res);
1976 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO)
1978 clash = acpi_check_address_range(space_id, res->start, length, warn);
1981 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1982 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1983 printk(KERN_NOTICE "ACPI: This conflict may"
1984 " cause random problems and system"
1986 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1987 " for this device, you should use it instead of"
1988 " the native driver\n");
1990 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1995 EXPORT_SYMBOL(acpi_check_resource_conflict);
1997 int acpi_check_region(resource_size_t start, resource_size_t n,
2000 struct resource res = {
2002 .end = start + n - 1,
2004 .flags = IORESOURCE_IO,
2007 return acpi_check_resource_conflict(&res);
2009 EXPORT_SYMBOL(acpi_check_region);
2012 * Let drivers know whether the resource checks are effective
2014 int acpi_resources_are_enforced(void)
2016 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
2018 EXPORT_SYMBOL(acpi_resources_are_enforced);
2020 bool acpi_osi_is_win8(void)
2022 return acpi_gbl_osi_data >= ACPI_OSI_WIN_8;
2024 EXPORT_SYMBOL(acpi_osi_is_win8);
2027 * Deallocate the memory for a spinlock.
2029 void acpi_os_delete_lock(acpi_spinlock handle)
2035 * Acquire a spinlock.
2037 * handle is a pointer to the spinlock_t.
2040 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
2042 acpi_cpu_flags flags;
2043 spin_lock_irqsave(lockp, flags);
2048 * Release a spinlock. See above.
2051 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
2053 spin_unlock_irqrestore(lockp, flags);
2056 #ifndef ACPI_USE_LOCAL_CACHE
2058 /*******************************************************************************
2060 * FUNCTION: acpi_os_create_cache
2062 * PARAMETERS: name - Ascii name for the cache
2063 * size - Size of each cached object
2064 * depth - Maximum depth of the cache (in objects) <ignored>
2065 * cache - Where the new cache object is returned
2069 * DESCRIPTION: Create a cache object
2071 ******************************************************************************/
2074 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
2076 *cache = kmem_cache_create(name, size, 0, 0, NULL);
2083 /*******************************************************************************
2085 * FUNCTION: acpi_os_purge_cache
2087 * PARAMETERS: Cache - Handle to cache object
2091 * DESCRIPTION: Free all objects within the requested cache.
2093 ******************************************************************************/
2095 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
2097 kmem_cache_shrink(cache);
2101 /*******************************************************************************
2103 * FUNCTION: acpi_os_delete_cache
2105 * PARAMETERS: Cache - Handle to cache object
2109 * DESCRIPTION: Free all objects within the requested cache and delete the
2112 ******************************************************************************/
2114 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
2116 kmem_cache_destroy(cache);
2120 /*******************************************************************************
2122 * FUNCTION: acpi_os_release_object
2124 * PARAMETERS: Cache - Handle to cache object
2125 * Object - The object to be released
2129 * DESCRIPTION: Release an object to the specified cache. If cache is full,
2130 * the object is deleted.
2132 ******************************************************************************/
2134 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
2136 kmem_cache_free(cache, object);
2141 static int __init acpi_no_static_ssdt_setup(char *s)
2143 acpi_gbl_disable_ssdt_table_install = TRUE;
2144 pr_info("ACPI: static SSDT installation disabled\n");
2149 early_param("acpi_no_static_ssdt", acpi_no_static_ssdt_setup);
2151 static int __init acpi_disable_return_repair(char *s)
2153 printk(KERN_NOTICE PREFIX
2154 "ACPI: Predefined validation mechanism disabled\n");
2155 acpi_gbl_disable_auto_repair = TRUE;
2160 __setup("acpica_no_return_repair", acpi_disable_return_repair);
2162 acpi_status __init acpi_os_initialize(void)
2164 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
2165 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
2166 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
2167 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
2168 if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) {
2170 * Use acpi_os_map_generic_address to pre-map the reset
2171 * register if it's in system memory.
2175 rv = acpi_os_map_generic_address(&acpi_gbl_FADT.reset_register);
2176 pr_debug(PREFIX "%s: map reset_reg status %d\n", __func__, rv);
2178 acpi_os_initialized = true;
2183 acpi_status __init acpi_os_initialize1(void)
2185 kacpid_wq = alloc_workqueue("kacpid", 0, 1);
2186 kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
2187 kacpi_hotplug_wq = alloc_ordered_workqueue("kacpi_hotplug", 0);
2189 BUG_ON(!kacpi_notify_wq);
2190 BUG_ON(!kacpi_hotplug_wq);
2191 acpi_install_interface_handler(acpi_osi_handler);
2192 acpi_osi_setup_late();
2196 acpi_status acpi_os_terminate(void)
2198 if (acpi_irq_handler) {
2199 acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt,
2203 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
2204 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
2205 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
2206 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
2207 if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER)
2208 acpi_os_unmap_generic_address(&acpi_gbl_FADT.reset_register);
2210 destroy_workqueue(kacpid_wq);
2211 destroy_workqueue(kacpi_notify_wq);
2212 destroy_workqueue(kacpi_hotplug_wq);
2217 acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control,
2221 if (__acpi_os_prepare_sleep)
2222 rc = __acpi_os_prepare_sleep(sleep_state,
2223 pm1a_control, pm1b_control);
2227 return AE_CTRL_SKIP;
2232 void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state,
2233 u32 pm1a_ctrl, u32 pm1b_ctrl))
2235 __acpi_os_prepare_sleep = func;
2238 acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, u32 val_a,
2242 if (__acpi_os_prepare_extended_sleep)
2243 rc = __acpi_os_prepare_extended_sleep(sleep_state,
2248 return AE_CTRL_SKIP;
2253 void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
2254 u32 val_a, u32 val_b))
2256 __acpi_os_prepare_extended_sleep = func;