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 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
34 #include <linux/pci.h>
35 #include <linux/interrupt.h>
36 #include <linux/kmod.h>
37 #include <linux/delay.h>
38 #include <linux/workqueue.h>
39 #include <linux/nmi.h>
40 #include <linux/acpi.h>
41 #include <linux/efi.h>
42 #include <linux/ioport.h>
43 #include <linux/list.h>
44 #include <linux/jiffies.h>
45 #include <linux/semaphore.h>
48 #include <asm/uaccess.h>
50 #include <acpi/acpi.h>
51 #include <acpi/acpi_bus.h>
52 #include <acpi/processor.h>
54 #define _COMPONENT ACPI_OS_SERVICES
55 ACPI_MODULE_NAME("osl");
56 #define PREFIX "ACPI: "
58 acpi_osd_exec_callback function;
60 struct work_struct work;
64 #ifdef CONFIG_ACPI_CUSTOM_DSDT
65 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
68 #ifdef ENABLE_DEBUGGER
69 #include <linux/kdb.h>
71 /* stuff for debugger support */
73 EXPORT_SYMBOL(acpi_in_debugger);
75 extern char line_buf[80];
76 #endif /*ENABLE_DEBUGGER */
78 static unsigned int acpi_irq_irq;
79 static acpi_osd_handler acpi_irq_handler;
80 static void *acpi_irq_context;
81 static struct workqueue_struct *kacpid_wq;
82 static struct workqueue_struct *kacpi_notify_wq;
83 static struct workqueue_struct *kacpi_hotplug_wq;
85 struct acpi_res_list {
86 resource_size_t start;
88 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
89 char name[5]; /* only can have a length of 4 chars, make use of this
90 one instead of res->name, no need to kalloc then */
91 struct list_head resource_list;
95 static LIST_HEAD(resource_list_head);
96 static DEFINE_SPINLOCK(acpi_res_lock);
98 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
99 static char osi_additional_string[OSI_STRING_LENGTH_MAX];
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 osi_linux {
135 unsigned int enable:1;
137 unsigned int cmdline:1;
138 unsigned int known:1;
139 } osi_linux = { 0, 0, 0, 0};
141 static void __init acpi_request_region (struct acpi_generic_address *addr,
142 unsigned int length, char *desc)
144 struct resource *res;
146 if (!addr->address || !length)
149 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
150 res = request_region(addr->address, length, desc);
151 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
152 res = request_mem_region(addr->address, length, desc);
155 static int __init acpi_reserve_resources(void)
157 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
158 "ACPI PM1a_EVT_BLK");
160 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
161 "ACPI PM1b_EVT_BLK");
163 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
164 "ACPI PM1a_CNT_BLK");
166 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
167 "ACPI PM1b_CNT_BLK");
169 if (acpi_gbl_FADT.pm_timer_length == 4)
170 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
172 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
175 /* Length of GPE blocks must be a non-negative multiple of 2 */
177 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
178 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
179 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
181 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
182 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
183 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
187 device_initcall(acpi_reserve_resources);
189 acpi_status __init acpi_os_initialize(void)
194 static void bind_to_cpu0(struct work_struct *work)
196 set_cpus_allowed_ptr(current, cpumask_of(0));
200 static void bind_workqueue(struct workqueue_struct *wq)
202 struct work_struct *work;
204 work = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
205 INIT_WORK(work, bind_to_cpu0);
206 queue_work(wq, work);
209 acpi_status acpi_os_initialize1(void)
212 * On some machines, a software-initiated SMI causes corruption unless
213 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
214 * typically it's done in GPE-related methods that are run via
215 * workqueues, so we can avoid the known corruption cases by binding
216 * the workqueues to CPU 0.
218 kacpid_wq = create_singlethread_workqueue("kacpid");
219 bind_workqueue(kacpid_wq);
220 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
221 bind_workqueue(kacpi_notify_wq);
222 kacpi_hotplug_wq = create_singlethread_workqueue("kacpi_hotplug");
223 bind_workqueue(kacpi_hotplug_wq);
225 BUG_ON(!kacpi_notify_wq);
226 BUG_ON(!kacpi_hotplug_wq);
230 acpi_status acpi_os_terminate(void)
232 if (acpi_irq_handler) {
233 acpi_os_remove_interrupt_handler(acpi_irq_irq,
237 destroy_workqueue(kacpid_wq);
238 destroy_workqueue(kacpi_notify_wq);
239 destroy_workqueue(kacpi_hotplug_wq);
244 void acpi_os_printf(const char *fmt, ...)
248 acpi_os_vprintf(fmt, args);
252 void acpi_os_vprintf(const char *fmt, va_list args)
254 static char buffer[512];
256 vsprintf(buffer, fmt, args);
258 #ifdef ENABLE_DEBUGGER
259 if (acpi_in_debugger) {
260 kdb_printf("%s", buffer);
262 printk(KERN_CONT "%s", buffer);
265 printk(KERN_CONT "%s", buffer);
269 acpi_physical_address __init acpi_os_get_root_pointer(void)
272 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
274 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
277 printk(KERN_ERR PREFIX
278 "System description tables not found\n");
282 acpi_physical_address pa = 0;
284 acpi_find_root_pointer(&pa);
289 void __iomem *__init_refok
290 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
292 if (phys > ULONG_MAX) {
293 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
296 if (acpi_gbl_permanent_mmap)
298 * ioremap checks to ensure this is in reserved space
300 return ioremap((unsigned long)phys, size);
302 return __acpi_map_table((unsigned long)phys, size);
304 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
306 void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
308 if (acpi_gbl_permanent_mmap)
311 __acpi_unmap_table(virt, size);
313 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
315 void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
317 if (!acpi_gbl_permanent_mmap)
318 __acpi_unmap_table(virt, size);
321 #ifdef ACPI_FUTURE_USAGE
323 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
326 return AE_BAD_PARAMETER;
328 *phys = virt_to_phys(virt);
334 #define ACPI_MAX_OVERRIDE_LEN 100
336 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
339 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
340 acpi_string * new_val)
342 if (!init_val || !new_val)
343 return AE_BAD_PARAMETER;
346 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
347 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
349 *new_val = acpi_os_name;
356 acpi_os_table_override(struct acpi_table_header * existing_table,
357 struct acpi_table_header ** new_table)
359 if (!existing_table || !new_table)
360 return AE_BAD_PARAMETER;
364 #ifdef CONFIG_ACPI_CUSTOM_DSDT
365 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
366 *new_table = (struct acpi_table_header *)AmlCode;
368 if (*new_table != NULL) {
369 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
370 "this is unsafe: tainting kernel\n",
371 existing_table->signature,
372 existing_table->oem_table_id);
373 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
378 static irqreturn_t acpi_irq(int irq, void *dev_id)
382 handled = (*acpi_irq_handler) (acpi_irq_context);
388 acpi_irq_not_handled++;
394 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
399 acpi_irq_stats_init();
402 * Ignore the GSI from the core, and use the value in our copy of the
403 * FADT. It may not be the same if an interrupt source override exists
406 gsi = acpi_gbl_FADT.sci_interrupt;
407 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
408 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
413 acpi_irq_handler = handler;
414 acpi_irq_context = context;
415 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
416 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
417 return AE_NOT_ACQUIRED;
424 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
427 free_irq(irq, acpi_irq);
428 acpi_irq_handler = NULL;
436 * Running in interpreter thread context, safe to sleep
439 void acpi_os_sleep(u64 ms)
441 schedule_timeout_interruptible(msecs_to_jiffies(ms));
444 void acpi_os_stall(u32 us)
452 touch_nmi_watchdog();
458 * Support ACPI 3.0 AML Timer operand
459 * Returns 64-bit free-running, monotonically increasing timer
460 * with 100ns granularity
462 u64 acpi_os_get_timer(void)
467 /* TBD: use HPET if available */
470 #ifdef CONFIG_X86_PM_TIMER
471 /* TBD: default to PM timer if HPET was not available */
474 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
479 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
488 *(u8 *) value = inb(port);
489 } else if (width <= 16) {
490 *(u16 *) value = inw(port);
491 } else if (width <= 32) {
492 *(u32 *) value = inl(port);
500 EXPORT_SYMBOL(acpi_os_read_port);
502 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
506 } else if (width <= 16) {
508 } else if (width <= 32) {
517 EXPORT_SYMBOL(acpi_os_write_port);
520 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
523 void __iomem *virt_addr;
525 virt_addr = ioremap(phys_addr, width);
531 *(u8 *) value = readb(virt_addr);
534 *(u16 *) value = readw(virt_addr);
537 *(u32 *) value = readl(virt_addr);
549 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
551 void __iomem *virt_addr;
553 virt_addr = ioremap(phys_addr, width);
557 writeb(value, virt_addr);
560 writew(value, virt_addr);
563 writel(value, virt_addr);
575 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
576 u32 *value, u32 width)
581 return AE_BAD_PARAMETER;
597 result = raw_pci_read(pci_id->segment, pci_id->bus,
598 PCI_DEVFN(pci_id->device, pci_id->function),
601 return (result ? AE_ERROR : AE_OK);
605 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
606 u64 value, u32 width)
624 result = raw_pci_write(pci_id->segment, pci_id->bus,
625 PCI_DEVFN(pci_id->device, pci_id->function),
628 return (result ? AE_ERROR : AE_OK);
631 /* TODO: Change code to take advantage of driver model more */
632 static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
633 acpi_handle chandle, /* current node */
634 struct acpi_pci_id **id,
635 int *is_bridge, u8 * bus_number)
638 struct acpi_pci_id *pci_id = *id;
640 unsigned long long temp;
641 acpi_object_type type;
643 acpi_get_parent(chandle, &handle);
644 if (handle != rhandle) {
645 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
648 status = acpi_get_type(handle, &type);
649 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
652 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
654 if (ACPI_SUCCESS(status)) {
656 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
657 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
660 pci_id->bus = *bus_number;
662 /* any nicer way to get bus number of bridge ? */
664 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
666 if (ACPI_SUCCESS(status)
667 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
669 acpi_os_read_pci_configuration(pci_id, 0x18,
671 if (!ACPI_SUCCESS(status)) {
672 /* Certainly broken... FIX ME */
678 acpi_os_read_pci_configuration(pci_id, 0x19,
680 if (ACPI_SUCCESS(status)) {
689 void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
690 acpi_handle chandle, /* current node */
691 struct acpi_pci_id **id)
694 u8 bus_number = (*id)->bus;
696 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
699 static void acpi_os_execute_deferred(struct work_struct *work)
701 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
704 acpi_os_wait_events_complete(NULL);
706 dpc->function(dpc->context);
710 /*******************************************************************************
712 * FUNCTION: acpi_os_execute
714 * PARAMETERS: Type - Type of the callback
715 * Function - Function to be executed
716 * Context - Function parameters
720 * DESCRIPTION: Depending on type, either queues function for deferred execution or
721 * immediately executes function on a separate thread.
723 ******************************************************************************/
725 static acpi_status __acpi_os_execute(acpi_execute_type type,
726 acpi_osd_exec_callback function, void *context, int hp)
728 acpi_status status = AE_OK;
729 struct acpi_os_dpc *dpc;
730 struct workqueue_struct *queue;
732 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
733 "Scheduling function [%p(%p)] for deferred execution.\n",
737 * Allocate/initialize DPC structure. Note that this memory will be
738 * freed by the callee. The kernel handles the work_struct list in a
739 * way that allows us to also free its memory inside the callee.
740 * Because we may want to schedule several tasks with different
741 * parameters we can't use the approach some kernel code uses of
742 * having a static work_struct.
745 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
749 dpc->function = function;
750 dpc->context = context;
753 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
754 * because the hotplug code may call driver .remove() functions,
755 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
756 * to flush these workqueues.
758 queue = hp ? kacpi_hotplug_wq :
759 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
760 dpc->wait = hp ? 1 : 0;
762 if (queue == kacpi_hotplug_wq)
763 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
764 else if (queue == kacpi_notify_wq)
765 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
767 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
769 ret = queue_work(queue, &dpc->work);
772 printk(KERN_ERR PREFIX
773 "Call to queue_work() failed.\n");
780 acpi_status acpi_os_execute(acpi_execute_type type,
781 acpi_osd_exec_callback function, void *context)
783 return __acpi_os_execute(type, function, context, 0);
785 EXPORT_SYMBOL(acpi_os_execute);
787 acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
790 return __acpi_os_execute(0, function, context, 1);
793 void acpi_os_wait_events_complete(void *context)
795 flush_workqueue(kacpid_wq);
796 flush_workqueue(kacpi_notify_wq);
799 EXPORT_SYMBOL(acpi_os_wait_events_complete);
802 * Allocate the memory for a spinlock and initialize it.
804 acpi_status acpi_os_create_lock(acpi_spinlock * handle)
806 spin_lock_init(*handle);
812 * Deallocate the memory for a spinlock.
814 void acpi_os_delete_lock(acpi_spinlock handle)
820 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
822 struct semaphore *sem = NULL;
824 sem = acpi_os_allocate(sizeof(struct semaphore));
827 memset(sem, 0, sizeof(struct semaphore));
829 sema_init(sem, initial_units);
831 *handle = (acpi_handle *) sem;
833 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
834 *handle, initial_units));
840 * TODO: A better way to delete semaphores? Linux doesn't have a
841 * 'delete_semaphore()' function -- may result in an invalid
842 * pointer dereference for non-synchronized consumers. Should
843 * we at least check for blocked threads and signal/cancel them?
846 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
848 struct semaphore *sem = (struct semaphore *)handle;
851 return AE_BAD_PARAMETER;
853 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
855 BUG_ON(!list_empty(&sem->wait_list));
863 * TODO: Support for units > 1?
865 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
867 acpi_status status = AE_OK;
868 struct semaphore *sem = (struct semaphore *)handle;
872 if (!sem || (units < 1))
873 return AE_BAD_PARAMETER;
878 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
879 handle, units, timeout));
881 if (timeout == ACPI_WAIT_FOREVER)
882 jiffies = MAX_SCHEDULE_TIMEOUT;
884 jiffies = msecs_to_jiffies(timeout);
886 ret = down_timeout(sem, jiffies);
890 if (ACPI_FAILURE(status)) {
891 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
892 "Failed to acquire semaphore[%p|%d|%d], %s",
893 handle, units, timeout,
894 acpi_format_exception(status)));
896 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
897 "Acquired semaphore[%p|%d|%d]", handle,
905 * TODO: Support for units > 1?
907 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
909 struct semaphore *sem = (struct semaphore *)handle;
911 if (!sem || (units < 1))
912 return AE_BAD_PARAMETER;
917 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
925 #ifdef ACPI_FUTURE_USAGE
926 u32 acpi_os_get_line(char *buffer)
929 #ifdef ENABLE_DEBUGGER
930 if (acpi_in_debugger) {
933 kdb_read(buffer, sizeof(line_buf));
935 /* remove the CR kdb includes */
936 chars = strlen(buffer) - 1;
937 buffer[chars] = '\0';
943 #endif /* ACPI_FUTURE_USAGE */
945 acpi_status acpi_os_signal(u32 function, void *info)
948 case ACPI_SIGNAL_FATAL:
949 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
951 case ACPI_SIGNAL_BREAKPOINT:
954 * ACPI spec. says to treat it as a NOP unless
955 * you are debugging. So if/when we integrate
956 * AML debugger into the kernel debugger its
957 * hook will go here. But until then it is
958 * not useful to print anything on breakpoints.
968 static int __init acpi_os_name_setup(char *str)
970 char *p = acpi_os_name;
971 int count = ACPI_MAX_OVERRIDE_LEN - 1;
976 for (; count-- && str && *str; str++) {
977 if (isalnum(*str) || *str == ' ' || *str == ':')
979 else if (*str == '\'' || *str == '"')
990 __setup("acpi_os_name=", acpi_os_name_setup);
992 static void __init set_osi_linux(unsigned int enable)
994 if (osi_linux.enable != enable) {
995 osi_linux.enable = enable;
996 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
997 enable ? "Add": "Delet");
1002 static void __init acpi_cmdline_osi_linux(unsigned int enable)
1004 osi_linux.cmdline = 1; /* cmdline set the default */
1005 set_osi_linux(enable);
1010 void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1012 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1014 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1019 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1021 set_osi_linux(enable);
1027 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1029 * empty string disables _OSI
1030 * string starting with '!' disables that string
1031 * otherwise string is added to list, augmenting built-in strings
1033 int __init acpi_osi_setup(char *str)
1035 if (str == NULL || *str == '\0') {
1036 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1037 acpi_gbl_create_osi_method = FALSE;
1038 } else if (!strcmp("!Linux", str)) {
1039 acpi_cmdline_osi_linux(0); /* !enable */
1040 } else if (*str == '!') {
1041 if (acpi_osi_invalidate(++str) == AE_OK)
1042 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1043 } else if (!strcmp("Linux", str)) {
1044 acpi_cmdline_osi_linux(1); /* enable */
1045 } else if (*osi_additional_string == '\0') {
1046 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1047 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1053 __setup("acpi_osi=", acpi_osi_setup);
1055 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1056 static int __init acpi_serialize_setup(char *str)
1058 printk(KERN_INFO PREFIX "serialize enabled\n");
1060 acpi_gbl_all_methods_serialized = TRUE;
1065 __setup("acpi_serialize", acpi_serialize_setup);
1067 /* Check of resource interference between native drivers and ACPI
1068 * OperationRegions (SystemIO and System Memory only).
1069 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1070 * in arbitrary AML code and can interfere with legacy drivers.
1071 * acpi_enforce_resources= can be set to:
1073 * - strict (default) (2)
1074 * -> further driver trying to access the resources will not load
1076 * -> further driver trying to access the resources will load, but you
1077 * get a system message that something might go wrong...
1080 * -> ACPI Operation Region resources will not be registered
1083 #define ENFORCE_RESOURCES_STRICT 2
1084 #define ENFORCE_RESOURCES_LAX 1
1085 #define ENFORCE_RESOURCES_NO 0
1087 static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1089 static int __init acpi_enforce_resources_setup(char *str)
1091 if (str == NULL || *str == '\0')
1094 if (!strcmp("strict", str))
1095 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1096 else if (!strcmp("lax", str))
1097 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1098 else if (!strcmp("no", str))
1099 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1104 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1106 /* Check for resource conflicts between ACPI OperationRegions and native
1108 int acpi_check_resource_conflict(const struct resource *res)
1110 struct acpi_res_list *res_list_elem;
1114 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1116 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1119 ioport = res->flags & IORESOURCE_IO;
1121 spin_lock(&acpi_res_lock);
1122 list_for_each_entry(res_list_elem, &resource_list_head,
1124 if (ioport && (res_list_elem->resource_type
1125 != ACPI_ADR_SPACE_SYSTEM_IO))
1127 if (!ioport && (res_list_elem->resource_type
1128 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1131 if (res->end < res_list_elem->start
1132 || res_list_elem->end < res->start)
1137 spin_unlock(&acpi_res_lock);
1140 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1141 printk(KERN_WARNING "ACPI: resource %s %pR"
1142 " conflicts with ACPI region %s %pR\n",
1143 res->name, res, res_list_elem->name,
1145 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1146 printk(KERN_NOTICE "ACPI: This conflict may"
1147 " cause random problems and system"
1149 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1150 " for this device, you should use it instead of"
1151 " the native driver\n");
1153 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1158 EXPORT_SYMBOL(acpi_check_resource_conflict);
1160 int acpi_check_region(resource_size_t start, resource_size_t n,
1163 struct resource res = {
1165 .end = start + n - 1,
1167 .flags = IORESOURCE_IO,
1170 return acpi_check_resource_conflict(&res);
1172 EXPORT_SYMBOL(acpi_check_region);
1174 int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1177 struct resource res = {
1179 .end = start + n - 1,
1181 .flags = IORESOURCE_MEM,
1184 return acpi_check_resource_conflict(&res);
1187 EXPORT_SYMBOL(acpi_check_mem_region);
1190 * Let drivers know whether the resource checks are effective
1192 int acpi_resources_are_enforced(void)
1194 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1196 EXPORT_SYMBOL(acpi_resources_are_enforced);
1199 * Acquire a spinlock.
1201 * handle is a pointer to the spinlock_t.
1204 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1206 acpi_cpu_flags flags;
1207 spin_lock_irqsave(lockp, flags);
1212 * Release a spinlock. See above.
1215 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1217 spin_unlock_irqrestore(lockp, flags);
1220 #ifndef ACPI_USE_LOCAL_CACHE
1222 /*******************************************************************************
1224 * FUNCTION: acpi_os_create_cache
1226 * PARAMETERS: name - Ascii name for the cache
1227 * size - Size of each cached object
1228 * depth - Maximum depth of the cache (in objects) <ignored>
1229 * cache - Where the new cache object is returned
1233 * DESCRIPTION: Create a cache object
1235 ******************************************************************************/
1238 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1240 *cache = kmem_cache_create(name, size, 0, 0, NULL);
1247 /*******************************************************************************
1249 * FUNCTION: acpi_os_purge_cache
1251 * PARAMETERS: Cache - Handle to cache object
1255 * DESCRIPTION: Free all objects within the requested cache.
1257 ******************************************************************************/
1259 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1261 kmem_cache_shrink(cache);
1265 /*******************************************************************************
1267 * FUNCTION: acpi_os_delete_cache
1269 * PARAMETERS: Cache - Handle to cache object
1273 * DESCRIPTION: Free all objects within the requested cache and delete the
1276 ******************************************************************************/
1278 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1280 kmem_cache_destroy(cache);
1284 /*******************************************************************************
1286 * FUNCTION: acpi_os_release_object
1288 * PARAMETERS: Cache - Handle to cache object
1289 * Object - The object to be released
1293 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1294 * the object is deleted.
1296 ******************************************************************************/
1298 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1300 kmem_cache_free(cache, object);
1304 /******************************************************************************
1306 * FUNCTION: acpi_os_validate_interface
1308 * PARAMETERS: interface - Requested interface to be validated
1310 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1312 * DESCRIPTION: Match an interface string to the interfaces supported by the
1313 * host. Strings originate from an AML call to the _OSI method.
1315 *****************************************************************************/
1318 acpi_os_validate_interface (char *interface)
1320 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1322 if (!strcmp("Linux", interface)) {
1324 printk(KERN_NOTICE PREFIX
1325 "BIOS _OSI(Linux) query %s%s\n",
1326 osi_linux.enable ? "honored" : "ignored",
1327 osi_linux.cmdline ? " via cmdline" :
1328 osi_linux.dmi ? " via DMI" : "");
1330 if (osi_linux.enable)
1336 static inline int acpi_res_list_add(struct acpi_res_list *res)
1338 struct acpi_res_list *res_list_elem;
1340 list_for_each_entry(res_list_elem, &resource_list_head,
1343 if (res->resource_type == res_list_elem->resource_type &&
1344 res->start == res_list_elem->start &&
1345 res->end == res_list_elem->end) {
1348 * The Region(addr,len) already exist in the list,
1349 * just increase the count
1352 res_list_elem->count++;
1358 list_add(&res->resource_list, &resource_list_head);
1362 static inline void acpi_res_list_del(struct acpi_res_list *res)
1364 struct acpi_res_list *res_list_elem;
1366 list_for_each_entry(res_list_elem, &resource_list_head,
1369 if (res->resource_type == res_list_elem->resource_type &&
1370 res->start == res_list_elem->start &&
1371 res->end == res_list_elem->end) {
1374 * If the res count is decreased to 0,
1375 * remove and free it
1378 if (--res_list_elem->count == 0) {
1379 list_del(&res_list_elem->resource_list);
1380 kfree(res_list_elem);
1388 acpi_os_invalidate_address(
1390 acpi_physical_address address,
1393 struct acpi_res_list res;
1396 case ACPI_ADR_SPACE_SYSTEM_IO:
1397 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1398 /* Only interference checks against SystemIO and SystemMemory
1400 res.start = address;
1401 res.end = address + length - 1;
1402 res.resource_type = space_id;
1403 spin_lock(&acpi_res_lock);
1404 acpi_res_list_del(&res);
1405 spin_unlock(&acpi_res_lock);
1407 case ACPI_ADR_SPACE_PCI_CONFIG:
1408 case ACPI_ADR_SPACE_EC:
1409 case ACPI_ADR_SPACE_SMBUS:
1410 case ACPI_ADR_SPACE_CMOS:
1411 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1412 case ACPI_ADR_SPACE_DATA_TABLE:
1413 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1419 /******************************************************************************
1421 * FUNCTION: acpi_os_validate_address
1423 * PARAMETERS: space_id - ACPI space ID
1424 * address - Physical address
1425 * length - Address length
1427 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1428 * should return AE_AML_ILLEGAL_ADDRESS.
1430 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1431 * the addresses accessed by AML operation regions.
1433 *****************************************************************************/
1436 acpi_os_validate_address (
1438 acpi_physical_address address,
1442 struct acpi_res_list *res;
1444 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1448 case ACPI_ADR_SPACE_SYSTEM_IO:
1449 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1450 /* Only interference checks against SystemIO and SystemMemory
1452 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1455 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1456 strlcpy(res->name, name, 5);
1457 res->start = address;
1458 res->end = address + length - 1;
1459 res->resource_type = space_id;
1460 spin_lock(&acpi_res_lock);
1461 added = acpi_res_list_add(res);
1462 spin_unlock(&acpi_res_lock);
1463 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1464 "name: %s\n", added ? "Added" : "Already exist",
1465 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1466 ? "SystemIO" : "System Memory",
1467 (unsigned long long)res->start,
1468 (unsigned long long)res->end,
1473 case ACPI_ADR_SPACE_PCI_CONFIG:
1474 case ACPI_ADR_SPACE_EC:
1475 case ACPI_ADR_SPACE_SMBUS:
1476 case ACPI_ADR_SPACE_CMOS:
1477 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1478 case ACPI_ADR_SPACE_DATA_TABLE:
1479 case ACPI_ADR_SPACE_FIXED_HARDWARE: