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>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
32 #include <linux/pci.h>
33 #include <linux/interrupt.h>
34 #include <linux/kmod.h>
35 #include <linux/delay.h>
36 #include <linux/dmi.h>
37 #include <linux/workqueue.h>
38 #include <linux/nmi.h>
39 #include <linux/acpi.h>
40 #include <acpi/acpi.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/processor.h>
44 #include <asm/uaccess.h>
46 #include <linux/efi.h>
47 #include <linux/ioport.h>
48 #include <linux/list.h>
50 #define _COMPONENT ACPI_OS_SERVICES
51 ACPI_MODULE_NAME("osl");
52 #define PREFIX "ACPI: "
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);
70 extern char line_buf[80];
71 #endif /*ENABLE_DEBUGGER */
73 static unsigned int acpi_irq_irq;
74 static acpi_osd_handler acpi_irq_handler;
75 static void *acpi_irq_context;
76 static struct workqueue_struct *kacpid_wq;
77 static struct workqueue_struct *kacpi_notify_wq;
79 struct acpi_res_list {
80 resource_size_t start;
82 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
83 char name[5]; /* only can have a length of 4 chars, make use of this
84 one instead of res->name, no need to kalloc then */
85 struct list_head resource_list;
88 static LIST_HEAD(resource_list_head);
89 static DEFINE_SPINLOCK(acpi_res_lock);
91 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
92 static char osi_additional_string[OSI_STRING_LENGTH_MAX];
95 * "Ode to _OSI(Linux)"
97 * osi_linux -- Control response to BIOS _OSI(Linux) query.
99 * As Linux evolves, the features that it supports change.
100 * So an OSI string such as "Linux" is not specific enough
101 * to be useful across multiple versions of Linux. It
102 * doesn't identify any particular feature, interface,
103 * or even any particular version of Linux...
105 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
106 * to a BIOS _OSI(Linux) query. When
107 * a reference mobile BIOS started using it, its use
108 * started to spread to many vendor platforms.
109 * As it is not supportable, we need to halt that spread.
111 * Today, most BIOS references to _OSI(Linux) are noise --
112 * they have no functional effect and are just dead code
113 * carried over from the reference BIOS.
115 * The next most common case is that _OSI(Linux) harms Linux,
116 * usually by causing the BIOS to follow paths that are
117 * not tested during Windows validation.
119 * Finally, there is a short list of platforms
120 * where OSI(Linux) benefits Linux.
122 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
123 * DMI is used to disable the dmesg warning about OSI(Linux)
124 * on platforms where it is known to have no effect.
125 * But a dmesg warning remains for systems where
126 * we do not know if OSI(Linux) is good or bad for the system.
127 * DMI is also used to enable OSI(Linux) for the machines
128 * that are known to need it.
130 * BIOS writers should NOT query _OSI(Linux) on future systems.
131 * It will be ignored by default, and to get Linux to
132 * not ignore it will require a kernel source update to
133 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
135 #define OSI_LINUX_ENABLE 0
137 static struct osi_linux {
138 unsigned int enable:1;
140 unsigned int cmdline:1;
141 unsigned int known:1;
142 } osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0};
144 static void __init acpi_request_region (struct acpi_generic_address *addr,
145 unsigned int length, char *desc)
147 struct resource *res;
149 if (!addr->address || !length)
152 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
153 res = request_region(addr->address, length, desc);
154 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
155 res = request_mem_region(addr->address, length, desc);
158 static int __init acpi_reserve_resources(void)
160 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
161 "ACPI PM1a_EVT_BLK");
163 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
164 "ACPI PM1b_EVT_BLK");
166 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
167 "ACPI PM1a_CNT_BLK");
169 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
170 "ACPI PM1b_CNT_BLK");
172 if (acpi_gbl_FADT.pm_timer_length == 4)
173 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
175 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
178 /* Length of GPE blocks must be a non-negative multiple of 2 */
180 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
181 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
182 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
184 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
185 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
186 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
190 device_initcall(acpi_reserve_resources);
192 acpi_status __init acpi_os_initialize(void)
197 acpi_status acpi_os_initialize1(void)
199 kacpid_wq = create_singlethread_workqueue("kacpid");
200 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
202 BUG_ON(!kacpi_notify_wq);
206 acpi_status acpi_os_terminate(void)
208 if (acpi_irq_handler) {
209 acpi_os_remove_interrupt_handler(acpi_irq_irq,
213 destroy_workqueue(kacpid_wq);
214 destroy_workqueue(kacpi_notify_wq);
219 void acpi_os_printf(const char *fmt, ...)
223 acpi_os_vprintf(fmt, args);
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("%s", buffer);
240 printk("%s", buffer);
244 acpi_physical_address __init acpi_os_get_root_pointer(void)
247 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
249 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
252 printk(KERN_ERR PREFIX
253 "System description tables not found\n");
257 acpi_physical_address pa = 0;
259 acpi_find_root_pointer(&pa);
264 void __iomem *__init_refok
265 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
267 if (phys > ULONG_MAX) {
268 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
271 if (acpi_gbl_permanent_mmap)
273 * ioremap checks to ensure this is in reserved space
275 return ioremap((unsigned long)phys, size);
277 return __acpi_map_table((unsigned long)phys, size);
279 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
281 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
283 if (acpi_gbl_permanent_mmap) {
287 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
289 #ifdef ACPI_FUTURE_USAGE
291 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
294 return AE_BAD_PARAMETER;
296 *phys = virt_to_phys(virt);
302 #define ACPI_MAX_OVERRIDE_LEN 100
304 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
307 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
308 acpi_string * new_val)
310 if (!init_val || !new_val)
311 return AE_BAD_PARAMETER;
314 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
315 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
317 *new_val = acpi_os_name;
324 acpi_os_table_override(struct acpi_table_header * existing_table,
325 struct acpi_table_header ** new_table)
327 if (!existing_table || !new_table)
328 return AE_BAD_PARAMETER;
332 #ifdef CONFIG_ACPI_CUSTOM_DSDT
333 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
334 *new_table = (struct acpi_table_header *)AmlCode;
336 if (*new_table != NULL) {
337 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
338 "this is unsafe: tainting kernel\n",
339 existing_table->signature,
340 existing_table->oem_table_id);
341 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
346 static irqreturn_t acpi_irq(int irq, void *dev_id)
350 handled = (*acpi_irq_handler) (acpi_irq_context);
360 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
365 acpi_irq_stats_init();
368 * Ignore the GSI from the core, and use the value in our copy of the
369 * FADT. It may not be the same if an interrupt source override exists
372 gsi = acpi_gbl_FADT.sci_interrupt;
373 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
374 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
379 acpi_irq_handler = handler;
380 acpi_irq_context = context;
381 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
382 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
383 return AE_NOT_ACQUIRED;
390 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
393 free_irq(irq, acpi_irq);
394 acpi_irq_handler = NULL;
402 * Running in interpreter thread context, safe to sleep
405 void acpi_os_sleep(acpi_integer ms)
407 schedule_timeout_interruptible(msecs_to_jiffies(ms));
410 void acpi_os_stall(u32 us)
418 touch_nmi_watchdog();
424 * Support ACPI 3.0 AML Timer operand
425 * Returns 64-bit free-running, monotonically increasing timer
426 * with 100ns granularity
428 u64 acpi_os_get_timer(void)
433 /* TBD: use HPET if available */
436 #ifdef CONFIG_X86_PM_TIMER
437 /* TBD: default to PM timer if HPET was not available */
440 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
445 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
454 *(u8 *) value = inb(port);
455 } else if (width <= 16) {
456 *(u16 *) value = inw(port);
457 } else if (width <= 32) {
458 *(u32 *) value = inl(port);
466 EXPORT_SYMBOL(acpi_os_read_port);
468 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
472 } else if (width <= 16) {
474 } else if (width <= 32) {
483 EXPORT_SYMBOL(acpi_os_write_port);
486 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
489 void __iomem *virt_addr;
491 virt_addr = ioremap(phys_addr, width);
497 *(u8 *) value = readb(virt_addr);
500 *(u16 *) value = readw(virt_addr);
503 *(u32 *) value = readl(virt_addr);
515 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
517 void __iomem *virt_addr;
519 virt_addr = ioremap(phys_addr, width);
523 writeb(value, virt_addr);
526 writew(value, virt_addr);
529 writel(value, virt_addr);
541 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
542 u32 *value, u32 width)
547 return AE_BAD_PARAMETER;
563 result = raw_pci_read(pci_id->segment, pci_id->bus,
564 PCI_DEVFN(pci_id->device, pci_id->function),
567 return (result ? AE_ERROR : AE_OK);
571 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
572 acpi_integer value, u32 width)
590 result = raw_pci_write(pci_id->segment, pci_id->bus,
591 PCI_DEVFN(pci_id->device, pci_id->function),
594 return (result ? AE_ERROR : AE_OK);
597 /* TODO: Change code to take advantage of driver model more */
598 static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
599 acpi_handle chandle, /* current node */
600 struct acpi_pci_id **id,
601 int *is_bridge, u8 * bus_number)
604 struct acpi_pci_id *pci_id = *id;
607 acpi_object_type type;
609 acpi_get_parent(chandle, &handle);
610 if (handle != rhandle) {
611 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
614 status = acpi_get_type(handle, &type);
615 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
619 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
621 if (ACPI_SUCCESS(status)) {
623 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
624 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
627 pci_id->bus = *bus_number;
629 /* any nicer way to get bus number of bridge ? */
631 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
633 if (ACPI_SUCCESS(status)
634 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
636 acpi_os_read_pci_configuration(pci_id, 0x18,
638 if (!ACPI_SUCCESS(status)) {
639 /* Certainly broken... FIX ME */
645 acpi_os_read_pci_configuration(pci_id, 0x19,
647 if (ACPI_SUCCESS(status)) {
656 void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
657 acpi_handle chandle, /* current node */
658 struct acpi_pci_id **id)
661 u8 bus_number = (*id)->bus;
663 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
666 static void acpi_os_execute_deferred(struct work_struct *work)
668 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
670 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
674 dpc->function(dpc->context);
680 /*******************************************************************************
682 * FUNCTION: acpi_os_execute
684 * PARAMETERS: Type - Type of the callback
685 * Function - Function to be executed
686 * Context - Function parameters
690 * DESCRIPTION: Depending on type, either queues function for deferred execution or
691 * immediately executes function on a separate thread.
693 ******************************************************************************/
695 acpi_status acpi_os_execute(acpi_execute_type type,
696 acpi_osd_exec_callback function, void *context)
698 acpi_status status = AE_OK;
699 struct acpi_os_dpc *dpc;
700 struct workqueue_struct *queue;
701 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
702 "Scheduling function [%p(%p)] for deferred execution.\n",
706 return AE_BAD_PARAMETER;
709 * Allocate/initialize DPC structure. Note that this memory will be
710 * freed by the callee. The kernel handles the work_struct list in a
711 * way that allows us to also free its memory inside the callee.
712 * Because we may want to schedule several tasks with different
713 * parameters we can't use the approach some kernel code uses of
714 * having a static work_struct.
717 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
719 return_ACPI_STATUS(AE_NO_MEMORY);
721 dpc->function = function;
722 dpc->context = context;
724 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
725 queue = (type == OSL_NOTIFY_HANDLER) ? kacpi_notify_wq : kacpid_wq;
726 if (!queue_work(queue, &dpc->work)) {
727 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
728 "Call to queue_work() failed.\n"));
732 return_ACPI_STATUS(status);
735 EXPORT_SYMBOL(acpi_os_execute);
737 void acpi_os_wait_events_complete(void *context)
739 flush_workqueue(kacpid_wq);
742 EXPORT_SYMBOL(acpi_os_wait_events_complete);
745 * Allocate the memory for a spinlock and initialize it.
747 acpi_status acpi_os_create_lock(acpi_spinlock * handle)
749 spin_lock_init(*handle);
755 * Deallocate the memory for a spinlock.
757 void acpi_os_delete_lock(acpi_spinlock handle)
763 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
765 struct semaphore *sem = NULL;
768 sem = acpi_os_allocate(sizeof(struct semaphore));
771 memset(sem, 0, sizeof(struct semaphore));
773 sema_init(sem, initial_units);
775 *handle = (acpi_handle *) sem;
777 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
778 *handle, initial_units));
784 * TODO: A better way to delete semaphores? Linux doesn't have a
785 * 'delete_semaphore()' function -- may result in an invalid
786 * pointer dereference for non-synchronized consumers. Should
787 * we at least check for blocked threads and signal/cancel them?
790 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
792 struct semaphore *sem = (struct semaphore *)handle;
796 return AE_BAD_PARAMETER;
798 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
807 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
808 * improvise. The process is to sleep for one scheduler quantum
809 * until the semaphore becomes available. Downside is that this
810 * may result in starvation for timeout-based waits when there's
811 * lots of semaphore activity.
813 * TODO: Support for units > 1?
815 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
817 acpi_status status = AE_OK;
818 struct semaphore *sem = (struct semaphore *)handle;
822 if (!sem || (units < 1))
823 return AE_BAD_PARAMETER;
828 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
829 handle, units, timeout));
832 * This can be called during resume with interrupts off.
833 * Like boot-time, we should be single threaded and will
834 * always get the lock if we try -- timeout or not.
835 * If this doesn't succeed, then we will oops courtesy of
836 * might_sleep() in down().
838 if (!down_trylock(sem))
845 * A zero timeout value indicates that we shouldn't wait - just
846 * acquire the semaphore if available otherwise return AE_TIME
847 * (a.k.a. 'would block').
850 if (down_trylock(sem))
858 case ACPI_WAIT_FOREVER:
867 // TODO: A better timeout algorithm?
870 static const int quantum_ms = 1000 / HZ;
872 ret = down_trylock(sem);
873 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
874 schedule_timeout_interruptible(1);
875 ret = down_trylock(sem);
884 if (ACPI_FAILURE(status)) {
885 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
886 "Failed to acquire semaphore[%p|%d|%d], %s",
887 handle, units, timeout,
888 acpi_format_exception(status)));
890 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
891 "Acquired semaphore[%p|%d|%d]", handle,
899 * TODO: Support for units > 1?
901 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
903 struct semaphore *sem = (struct semaphore *)handle;
906 if (!sem || (units < 1))
907 return AE_BAD_PARAMETER;
912 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
920 #ifdef ACPI_FUTURE_USAGE
921 u32 acpi_os_get_line(char *buffer)
924 #ifdef ENABLE_DEBUGGER
925 if (acpi_in_debugger) {
928 kdb_read(buffer, sizeof(line_buf));
930 /* remove the CR kdb includes */
931 chars = strlen(buffer) - 1;
932 buffer[chars] = '\0';
938 #endif /* ACPI_FUTURE_USAGE */
940 acpi_status acpi_os_signal(u32 function, void *info)
943 case ACPI_SIGNAL_FATAL:
944 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
946 case ACPI_SIGNAL_BREAKPOINT:
949 * ACPI spec. says to treat it as a NOP unless
950 * you are debugging. So if/when we integrate
951 * AML debugger into the kernel debugger its
952 * hook will go here. But until then it is
953 * not useful to print anything on breakpoints.
963 static int __init acpi_os_name_setup(char *str)
965 char *p = acpi_os_name;
966 int count = ACPI_MAX_OVERRIDE_LEN - 1;
971 for (; count-- && str && *str; str++) {
972 if (isalnum(*str) || *str == ' ' || *str == ':')
974 else if (*str == '\'' || *str == '"')
985 __setup("acpi_os_name=", acpi_os_name_setup);
987 static void __init set_osi_linux(unsigned int enable)
989 if (osi_linux.enable != enable) {
990 osi_linux.enable = enable;
991 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
992 enable ? "Add": "Delet");
997 static void __init acpi_cmdline_osi_linux(unsigned int enable)
999 osi_linux.cmdline = 1; /* cmdline set the default */
1000 set_osi_linux(enable);
1005 void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1007 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1009 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1014 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1016 set_osi_linux(enable);
1022 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1024 * empty string disables _OSI
1025 * string starting with '!' disables that string
1026 * otherwise string is added to list, augmenting built-in strings
1028 int __init acpi_osi_setup(char *str)
1030 if (str == NULL || *str == '\0') {
1031 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1032 acpi_gbl_create_osi_method = FALSE;
1033 } else if (!strcmp("!Linux", str)) {
1034 acpi_cmdline_osi_linux(0); /* !enable */
1035 } else if (*str == '!') {
1036 if (acpi_osi_invalidate(++str) == AE_OK)
1037 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1038 } else if (!strcmp("Linux", str)) {
1039 acpi_cmdline_osi_linux(1); /* enable */
1040 } else if (*osi_additional_string == '\0') {
1041 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1042 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1048 __setup("acpi_osi=", acpi_osi_setup);
1050 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1051 static int __init acpi_serialize_setup(char *str)
1053 printk(KERN_INFO PREFIX "serialize enabled\n");
1055 acpi_gbl_all_methods_serialized = TRUE;
1060 __setup("acpi_serialize", acpi_serialize_setup);
1063 * Wake and Run-Time GPES are expected to be separate.
1064 * We disable wake-GPEs at run-time to prevent spurious
1067 * However, if a system exists that shares Wake and
1068 * Run-time events on the same GPE this flag is available
1069 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1071 static int __init acpi_wake_gpes_always_on_setup(char *str)
1073 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1075 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1080 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1082 /* Check of resource interference between native drivers and ACPI
1083 * OperationRegions (SystemIO and System Memory only).
1084 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1085 * in arbitrary AML code and can interfere with legacy drivers.
1086 * acpi_enforce_resources= can be set to:
1089 * -> further driver trying to access the resources will not load
1090 * - lax (default) (1)
1091 * -> further driver trying to access the resources will load, but you
1092 * get a system message that something might go wrong...
1095 * -> ACPI Operation Region resources will not be registered
1098 #define ENFORCE_RESOURCES_STRICT 2
1099 #define ENFORCE_RESOURCES_LAX 1
1100 #define ENFORCE_RESOURCES_NO 0
1102 static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1104 static int __init acpi_enforce_resources_setup(char *str)
1106 if (str == NULL || *str == '\0')
1109 if (!strcmp("strict", str))
1110 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1111 else if (!strcmp("lax", str))
1112 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1113 else if (!strcmp("no", str))
1114 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1119 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1121 /* Check for resource conflicts between ACPI OperationRegions and native
1123 int acpi_check_resource_conflict(struct resource *res)
1125 struct acpi_res_list *res_list_elem;
1129 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1131 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1134 ioport = res->flags & IORESOURCE_IO;
1136 spin_lock(&acpi_res_lock);
1137 list_for_each_entry(res_list_elem, &resource_list_head,
1139 if (ioport && (res_list_elem->resource_type
1140 != ACPI_ADR_SPACE_SYSTEM_IO))
1142 if (!ioport && (res_list_elem->resource_type
1143 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1146 if (res->end < res_list_elem->start
1147 || res_list_elem->end < res->start)
1152 spin_unlock(&acpi_res_lock);
1155 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1156 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
1157 " conflicts with ACPI region %s"
1158 " [0x%llx-0x%llx]\n",
1159 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1160 ? KERN_WARNING : KERN_ERR,
1161 ioport ? "I/O" : "Memory", res->name,
1162 (long long) res->start, (long long) res->end,
1163 res_list_elem->name,
1164 (long long) res_list_elem->start,
1165 (long long) res_list_elem->end);
1166 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1168 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1173 EXPORT_SYMBOL(acpi_check_resource_conflict);
1175 int acpi_check_region(resource_size_t start, resource_size_t n,
1178 struct resource res = {
1180 .end = start + n - 1,
1182 .flags = IORESOURCE_IO,
1185 return acpi_check_resource_conflict(&res);
1187 EXPORT_SYMBOL(acpi_check_region);
1189 int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1192 struct resource res = {
1194 .end = start + n - 1,
1196 .flags = IORESOURCE_MEM,
1199 return acpi_check_resource_conflict(&res);
1202 EXPORT_SYMBOL(acpi_check_mem_region);
1205 * Acquire a spinlock.
1207 * handle is a pointer to the spinlock_t.
1210 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1212 acpi_cpu_flags flags;
1213 spin_lock_irqsave(lockp, flags);
1218 * Release a spinlock. See above.
1221 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1223 spin_unlock_irqrestore(lockp, flags);
1226 #ifndef ACPI_USE_LOCAL_CACHE
1228 /*******************************************************************************
1230 * FUNCTION: acpi_os_create_cache
1232 * PARAMETERS: name - Ascii name for the cache
1233 * size - Size of each cached object
1234 * depth - Maximum depth of the cache (in objects) <ignored>
1235 * cache - Where the new cache object is returned
1239 * DESCRIPTION: Create a cache object
1241 ******************************************************************************/
1244 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1246 *cache = kmem_cache_create(name, size, 0, 0, NULL);
1253 /*******************************************************************************
1255 * FUNCTION: acpi_os_purge_cache
1257 * PARAMETERS: Cache - Handle to cache object
1261 * DESCRIPTION: Free all objects within the requested cache.
1263 ******************************************************************************/
1265 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1267 kmem_cache_shrink(cache);
1271 /*******************************************************************************
1273 * FUNCTION: acpi_os_delete_cache
1275 * PARAMETERS: Cache - Handle to cache object
1279 * DESCRIPTION: Free all objects within the requested cache and delete the
1282 ******************************************************************************/
1284 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1286 kmem_cache_destroy(cache);
1290 /*******************************************************************************
1292 * FUNCTION: acpi_os_release_object
1294 * PARAMETERS: Cache - Handle to cache object
1295 * Object - The object to be released
1299 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1300 * the object is deleted.
1302 ******************************************************************************/
1304 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1306 kmem_cache_free(cache, object);
1311 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1313 * Returns 0 on success
1315 static int acpi_dmi_dump(void)
1321 printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
1322 dmi_get_system_info(DMI_SYS_VENDOR));
1323 printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
1324 dmi_get_system_info(DMI_PRODUCT_NAME));
1325 printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
1326 dmi_get_system_info(DMI_PRODUCT_VERSION));
1327 printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
1328 dmi_get_system_info(DMI_BOARD_NAME));
1329 printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
1330 dmi_get_system_info(DMI_BIOS_VENDOR));
1331 printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
1332 dmi_get_system_info(DMI_BIOS_DATE));
1338 /******************************************************************************
1340 * FUNCTION: acpi_os_validate_interface
1342 * PARAMETERS: interface - Requested interface to be validated
1344 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1346 * DESCRIPTION: Match an interface string to the interfaces supported by the
1347 * host. Strings originate from an AML call to the _OSI method.
1349 *****************************************************************************/
1352 acpi_os_validate_interface (char *interface)
1354 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1356 if (!strcmp("Linux", interface)) {
1358 printk(KERN_NOTICE PREFIX
1359 "BIOS _OSI(Linux) query %s%s\n",
1360 osi_linux.enable ? "honored" : "ignored",
1361 osi_linux.cmdline ? " via cmdline" :
1362 osi_linux.dmi ? " via DMI" : "");
1364 if (!osi_linux.dmi) {
1365 if (acpi_dmi_dump())
1366 printk(KERN_NOTICE PREFIX
1367 "[please extract dmidecode output]\n");
1368 printk(KERN_NOTICE PREFIX
1369 "Please send DMI info above to "
1370 "linux-acpi@vger.kernel.org\n");
1372 if (!osi_linux.known && !osi_linux.cmdline) {
1373 printk(KERN_NOTICE PREFIX
1374 "If \"acpi_osi=%sLinux\" works better, "
1375 "please notify linux-acpi@vger.kernel.org\n",
1376 osi_linux.enable ? "!" : "");
1379 if (osi_linux.enable)
1385 /******************************************************************************
1387 * FUNCTION: acpi_os_validate_address
1389 * PARAMETERS: space_id - ACPI space ID
1390 * address - Physical address
1391 * length - Address length
1393 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1394 * should return AE_AML_ILLEGAL_ADDRESS.
1396 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1397 * the addresses accessed by AML operation regions.
1399 *****************************************************************************/
1402 acpi_os_validate_address (
1404 acpi_physical_address address,
1408 struct acpi_res_list *res;
1409 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1413 case ACPI_ADR_SPACE_SYSTEM_IO:
1414 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1415 /* Only interference checks against SystemIO and SytemMemory
1417 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1420 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1421 strlcpy(res->name, name, 5);
1422 res->start = address;
1423 res->end = address + length - 1;
1424 res->resource_type = space_id;
1425 spin_lock(&acpi_res_lock);
1426 list_add(&res->resource_list, &resource_list_head);
1427 spin_unlock(&acpi_res_lock);
1428 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1429 "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1430 ? "SystemIO" : "System Memory",
1431 (unsigned long long)res->start,
1432 (unsigned long long)res->end,
1435 case ACPI_ADR_SPACE_PCI_CONFIG:
1436 case ACPI_ADR_SPACE_EC:
1437 case ACPI_ADR_SPACE_SMBUS:
1438 case ACPI_ADR_SPACE_CMOS:
1439 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1440 case ACPI_ADR_SPACE_DATA_TABLE:
1441 case ACPI_ADR_SPACE_FIXED_HARDWARE: