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];
94 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
95 static int acpi_no_initrd_override;
99 * "Ode to _OSI(Linux)"
101 * osi_linux -- Control response to BIOS _OSI(Linux) query.
103 * As Linux evolves, the features that it supports change.
104 * So an OSI string such as "Linux" is not specific enough
105 * to be useful across multiple versions of Linux. It
106 * doesn't identify any particular feature, interface,
107 * or even any particular version of Linux...
109 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
110 * to a BIOS _OSI(Linux) query. When
111 * a reference mobile BIOS started using it, its use
112 * started to spread to many vendor platforms.
113 * As it is not supportable, we need to halt that spread.
115 * Today, most BIOS references to _OSI(Linux) are noise --
116 * they have no functional effect and are just dead code
117 * carried over from the reference BIOS.
119 * The next most common case is that _OSI(Linux) harms Linux,
120 * usually by causing the BIOS to follow paths that are
121 * not tested during Windows validation.
123 * Finally, there is a short list of platforms
124 * where OSI(Linux) benefits Linux.
126 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
127 * DMI is used to disable the dmesg warning about OSI(Linux)
128 * on platforms where it is known to have no effect.
129 * But a dmesg warning remains for systems where
130 * we do not know if OSI(Linux) is good or bad for the system.
131 * DMI is also used to enable OSI(Linux) for the machines
132 * that are known to need it.
134 * BIOS writers should NOT query _OSI(Linux) on future systems.
135 * It will be ignored by default, and to get Linux to
136 * not ignore it will require a kernel source update to
137 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
139 #define OSI_LINUX_ENABLE 0
141 static struct osi_linux {
142 unsigned int enable:1;
144 unsigned int cmdline:1;
145 unsigned int known:1;
146 } osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0};
148 static void __init acpi_request_region (struct acpi_generic_address *addr,
149 unsigned int length, char *desc)
151 struct resource *res;
153 if (!addr->address || !length)
156 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
157 res = request_region(addr->address, length, desc);
158 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
159 res = request_mem_region(addr->address, length, desc);
162 static int __init acpi_reserve_resources(void)
164 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
165 "ACPI PM1a_EVT_BLK");
167 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
168 "ACPI PM1b_EVT_BLK");
170 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
171 "ACPI PM1a_CNT_BLK");
173 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
174 "ACPI PM1b_CNT_BLK");
176 if (acpi_gbl_FADT.pm_timer_length == 4)
177 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
179 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
182 /* Length of GPE blocks must be a non-negative multiple of 2 */
184 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
185 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
186 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
188 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
189 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
190 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
194 device_initcall(acpi_reserve_resources);
196 acpi_status __init acpi_os_initialize(void)
201 acpi_status acpi_os_initialize1(void)
204 * Initialize PCI configuration space access, as we'll need to access
205 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
208 printk(KERN_ERR PREFIX
209 "Access to PCI configuration space unavailable\n");
210 return AE_NULL_ENTRY;
212 kacpid_wq = create_singlethread_workqueue("kacpid");
213 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
215 BUG_ON(!kacpi_notify_wq);
219 acpi_status acpi_os_terminate(void)
221 if (acpi_irq_handler) {
222 acpi_os_remove_interrupt_handler(acpi_irq_irq,
226 destroy_workqueue(kacpid_wq);
227 destroy_workqueue(kacpi_notify_wq);
232 void acpi_os_printf(const char *fmt, ...)
236 acpi_os_vprintf(fmt, args);
240 void acpi_os_vprintf(const char *fmt, va_list args)
242 static char buffer[512];
244 vsprintf(buffer, fmt, args);
246 #ifdef ENABLE_DEBUGGER
247 if (acpi_in_debugger) {
248 kdb_printf("%s", buffer);
250 printk("%s", buffer);
253 printk("%s", buffer);
257 acpi_physical_address __init acpi_os_get_root_pointer(void)
260 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
262 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
265 printk(KERN_ERR PREFIX
266 "System description tables not found\n");
270 acpi_physical_address pa = 0;
272 acpi_find_root_pointer(&pa);
277 void __iomem *__init_refok
278 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
280 if (phys > ULONG_MAX) {
281 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
284 if (acpi_gbl_permanent_mmap)
286 * ioremap checks to ensure this is in reserved space
288 return ioremap((unsigned long)phys, size);
290 return __acpi_map_table((unsigned long)phys, size);
292 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
294 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
296 if (acpi_gbl_permanent_mmap) {
300 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
302 #ifdef ACPI_FUTURE_USAGE
304 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
307 return AE_BAD_PARAMETER;
309 *phys = virt_to_phys(virt);
315 #define ACPI_MAX_OVERRIDE_LEN 100
317 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
320 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
321 acpi_string * new_val)
323 if (!init_val || !new_val)
324 return AE_BAD_PARAMETER;
327 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
328 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
330 *new_val = acpi_os_name;
336 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
337 struct acpi_table_header *acpi_find_dsdt_initrd(void)
339 struct file *firmware_file;
341 unsigned long len, len2;
342 struct acpi_table_header *dsdt_buffer, *ret = NULL;
344 char *ramfs_dsdt_name = "/DSDT.aml";
346 printk(KERN_INFO PREFIX "Checking initramfs for custom DSDT");
349 * Never do this at home, only the user-space is allowed to open a file.
350 * The clean way would be to use the firmware loader.
351 * But this code must be run before there is any userspace available.
352 * A static/init firmware infrastructure doesn't exist yet...
354 if (vfs_stat(ramfs_dsdt_name, &stat) < 0)
358 /* check especially against empty files */
360 printk(KERN_ERR PREFIX "Failed: DSDT only %lu bytes.\n", len);
364 firmware_file = filp_open(ramfs_dsdt_name, O_RDONLY, 0);
365 if (IS_ERR(firmware_file)) {
366 printk(KERN_ERR PREFIX "Failed to open %s.\n", ramfs_dsdt_name);
370 dsdt_buffer = kmalloc(len, GFP_ATOMIC);
372 printk(KERN_ERR PREFIX "Failed to allocate %lu bytes.\n", len);
378 len2 = vfs_read(firmware_file, (char __user *)dsdt_buffer, len,
379 &firmware_file->f_pos);
382 printk(KERN_ERR PREFIX "Failed to read %lu bytes from %s.\n",
383 len, ramfs_dsdt_name);
384 ACPI_FREE(dsdt_buffer);
388 printk(KERN_INFO PREFIX "Found %lu byte DSDT in %s.\n",
389 len, ramfs_dsdt_name);
392 filp_close(firmware_file, NULL);
398 acpi_os_table_override(struct acpi_table_header * existing_table,
399 struct acpi_table_header ** new_table)
401 if (!existing_table || !new_table)
402 return AE_BAD_PARAMETER;
406 #ifdef CONFIG_ACPI_CUSTOM_DSDT
407 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
408 *new_table = (struct acpi_table_header *)AmlCode;
410 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
411 if ((strncmp(existing_table->signature, "DSDT", 4) == 0) &&
412 !acpi_no_initrd_override) {
413 struct acpi_table_header *initrd_table;
415 initrd_table = acpi_find_dsdt_initrd();
417 *new_table = initrd_table;
420 if (*new_table != NULL) {
421 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
422 "this is unsafe: tainting kernel\n",
423 existing_table->signature,
424 existing_table->oem_table_id);
425 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
430 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
431 int __init acpi_no_initrd_override_setup(char *s)
433 acpi_no_initrd_override = 1;
436 __setup("acpi_no_initrd_override", acpi_no_initrd_override_setup);
439 static irqreturn_t acpi_irq(int irq, void *dev_id)
443 handled = (*acpi_irq_handler) (acpi_irq_context);
453 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
458 acpi_irq_stats_init();
461 * Ignore the GSI from the core, and use the value in our copy of the
462 * FADT. It may not be the same if an interrupt source override exists
465 gsi = acpi_gbl_FADT.sci_interrupt;
466 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
467 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
472 acpi_irq_handler = handler;
473 acpi_irq_context = context;
474 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
475 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
476 return AE_NOT_ACQUIRED;
483 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
486 free_irq(irq, acpi_irq);
487 acpi_irq_handler = NULL;
495 * Running in interpreter thread context, safe to sleep
498 void acpi_os_sleep(acpi_integer ms)
500 schedule_timeout_interruptible(msecs_to_jiffies(ms));
503 void acpi_os_stall(u32 us)
511 touch_nmi_watchdog();
517 * Support ACPI 3.0 AML Timer operand
518 * Returns 64-bit free-running, monotonically increasing timer
519 * with 100ns granularity
521 u64 acpi_os_get_timer(void)
526 /* TBD: use HPET if available */
529 #ifdef CONFIG_X86_PM_TIMER
530 /* TBD: default to PM timer if HPET was not available */
533 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
538 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
547 *(u8 *) value = inb(port);
548 } else if (width <= 16) {
549 *(u16 *) value = inw(port);
550 } else if (width <= 32) {
551 *(u32 *) value = inl(port);
559 EXPORT_SYMBOL(acpi_os_read_port);
561 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
565 } else if (width <= 16) {
567 } else if (width <= 32) {
576 EXPORT_SYMBOL(acpi_os_write_port);
579 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
582 void __iomem *virt_addr;
584 virt_addr = ioremap(phys_addr, width);
590 *(u8 *) value = readb(virt_addr);
593 *(u16 *) value = readw(virt_addr);
596 *(u32 *) value = readl(virt_addr);
608 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
610 void __iomem *virt_addr;
612 virt_addr = ioremap(phys_addr, width);
616 writeb(value, virt_addr);
619 writew(value, virt_addr);
622 writel(value, virt_addr);
634 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
635 void *value, u32 width)
640 return AE_BAD_PARAMETER;
656 BUG_ON(!raw_pci_ops);
658 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
659 PCI_DEVFN(pci_id->device, pci_id->function),
662 return (result ? AE_ERROR : AE_OK);
666 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
667 acpi_integer value, u32 width)
685 BUG_ON(!raw_pci_ops);
687 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
688 PCI_DEVFN(pci_id->device, pci_id->function),
691 return (result ? AE_ERROR : AE_OK);
694 /* TODO: Change code to take advantage of driver model more */
695 static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
696 acpi_handle chandle, /* current node */
697 struct acpi_pci_id **id,
698 int *is_bridge, u8 * bus_number)
701 struct acpi_pci_id *pci_id = *id;
704 acpi_object_type type;
707 acpi_get_parent(chandle, &handle);
708 if (handle != rhandle) {
709 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
712 status = acpi_get_type(handle, &type);
713 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
717 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
719 if (ACPI_SUCCESS(status)) {
720 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
721 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
724 pci_id->bus = *bus_number;
726 /* any nicer way to get bus number of bridge ? */
728 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
730 if (ACPI_SUCCESS(status)
731 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
733 acpi_os_read_pci_configuration(pci_id, 0x18,
735 if (!ACPI_SUCCESS(status)) {
736 /* Certainly broken... FIX ME */
742 acpi_os_read_pci_configuration(pci_id, 0x19,
744 if (ACPI_SUCCESS(status)) {
753 void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
754 acpi_handle chandle, /* current node */
755 struct acpi_pci_id **id)
758 u8 bus_number = (*id)->bus;
760 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
763 static void acpi_os_execute_deferred(struct work_struct *work)
765 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
767 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
771 dpc->function(dpc->context);
777 /*******************************************************************************
779 * FUNCTION: acpi_os_execute
781 * PARAMETERS: Type - Type of the callback
782 * Function - Function to be executed
783 * Context - Function parameters
787 * DESCRIPTION: Depending on type, either queues function for deferred execution or
788 * immediately executes function on a separate thread.
790 ******************************************************************************/
792 acpi_status acpi_os_execute(acpi_execute_type type,
793 acpi_osd_exec_callback function, void *context)
795 acpi_status status = AE_OK;
796 struct acpi_os_dpc *dpc;
797 struct workqueue_struct *queue;
798 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
799 "Scheduling function [%p(%p)] for deferred execution.\n",
803 return AE_BAD_PARAMETER;
806 * Allocate/initialize DPC structure. Note that this memory will be
807 * freed by the callee. The kernel handles the work_struct list in a
808 * way that allows us to also free its memory inside the callee.
809 * Because we may want to schedule several tasks with different
810 * parameters we can't use the approach some kernel code uses of
811 * having a static work_struct.
814 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
816 return_ACPI_STATUS(AE_NO_MEMORY);
818 dpc->function = function;
819 dpc->context = context;
821 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
822 queue = (type == OSL_NOTIFY_HANDLER) ? kacpi_notify_wq : kacpid_wq;
823 if (!queue_work(queue, &dpc->work)) {
824 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
825 "Call to queue_work() failed.\n"));
829 return_ACPI_STATUS(status);
832 EXPORT_SYMBOL(acpi_os_execute);
834 void acpi_os_wait_events_complete(void *context)
836 flush_workqueue(kacpid_wq);
839 EXPORT_SYMBOL(acpi_os_wait_events_complete);
842 * Allocate the memory for a spinlock and initialize it.
844 acpi_status acpi_os_create_lock(acpi_spinlock * handle)
846 spin_lock_init(*handle);
852 * Deallocate the memory for a spinlock.
854 void acpi_os_delete_lock(acpi_spinlock handle)
860 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
862 struct semaphore *sem = NULL;
865 sem = acpi_os_allocate(sizeof(struct semaphore));
868 memset(sem, 0, sizeof(struct semaphore));
870 sema_init(sem, initial_units);
872 *handle = (acpi_handle *) sem;
874 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
875 *handle, initial_units));
881 * TODO: A better way to delete semaphores? Linux doesn't have a
882 * 'delete_semaphore()' function -- may result in an invalid
883 * pointer dereference for non-synchronized consumers. Should
884 * we at least check for blocked threads and signal/cancel them?
887 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
889 struct semaphore *sem = (struct semaphore *)handle;
893 return AE_BAD_PARAMETER;
895 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
904 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
905 * improvise. The process is to sleep for one scheduler quantum
906 * until the semaphore becomes available. Downside is that this
907 * may result in starvation for timeout-based waits when there's
908 * lots of semaphore activity.
910 * TODO: Support for units > 1?
912 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
914 acpi_status status = AE_OK;
915 struct semaphore *sem = (struct semaphore *)handle;
919 if (!sem || (units < 1))
920 return AE_BAD_PARAMETER;
925 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
926 handle, units, timeout));
929 * This can be called during resume with interrupts off.
930 * Like boot-time, we should be single threaded and will
931 * always get the lock if we try -- timeout or not.
932 * If this doesn't succeed, then we will oops courtesy of
933 * might_sleep() in down().
935 if (!down_trylock(sem))
942 * A zero timeout value indicates that we shouldn't wait - just
943 * acquire the semaphore if available otherwise return AE_TIME
944 * (a.k.a. 'would block').
947 if (down_trylock(sem))
955 case ACPI_WAIT_FOREVER:
964 // TODO: A better timeout algorithm?
967 static const int quantum_ms = 1000 / HZ;
969 ret = down_trylock(sem);
970 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
971 schedule_timeout_interruptible(1);
972 ret = down_trylock(sem);
981 if (ACPI_FAILURE(status)) {
982 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
983 "Failed to acquire semaphore[%p|%d|%d], %s",
984 handle, units, timeout,
985 acpi_format_exception(status)));
987 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
988 "Acquired semaphore[%p|%d|%d]", handle,
996 * TODO: Support for units > 1?
998 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
1000 struct semaphore *sem = (struct semaphore *)handle;
1003 if (!sem || (units < 1))
1004 return AE_BAD_PARAMETER;
1009 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
1017 #ifdef ACPI_FUTURE_USAGE
1018 u32 acpi_os_get_line(char *buffer)
1021 #ifdef ENABLE_DEBUGGER
1022 if (acpi_in_debugger) {
1025 kdb_read(buffer, sizeof(line_buf));
1027 /* remove the CR kdb includes */
1028 chars = strlen(buffer) - 1;
1029 buffer[chars] = '\0';
1035 #endif /* ACPI_FUTURE_USAGE */
1037 acpi_status acpi_os_signal(u32 function, void *info)
1040 case ACPI_SIGNAL_FATAL:
1041 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
1043 case ACPI_SIGNAL_BREAKPOINT:
1046 * ACPI spec. says to treat it as a NOP unless
1047 * you are debugging. So if/when we integrate
1048 * AML debugger into the kernel debugger its
1049 * hook will go here. But until then it is
1050 * not useful to print anything on breakpoints.
1060 static int __init acpi_os_name_setup(char *str)
1062 char *p = acpi_os_name;
1063 int count = ACPI_MAX_OVERRIDE_LEN - 1;
1068 for (; count-- && str && *str; str++) {
1069 if (isalnum(*str) || *str == ' ' || *str == ':')
1071 else if (*str == '\'' || *str == '"')
1082 __setup("acpi_os_name=", acpi_os_name_setup);
1084 static void __init set_osi_linux(unsigned int enable)
1086 if (osi_linux.enable != enable) {
1087 osi_linux.enable = enable;
1088 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1089 enable ? "Add": "Delet");
1094 static void __init acpi_cmdline_osi_linux(unsigned int enable)
1096 osi_linux.cmdline = 1; /* cmdline set the default */
1097 set_osi_linux(enable);
1102 void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1104 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1106 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1111 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1113 set_osi_linux(enable);
1119 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1121 * empty string disables _OSI
1122 * string starting with '!' disables that string
1123 * otherwise string is added to list, augmenting built-in strings
1125 static int __init acpi_osi_setup(char *str)
1127 if (str == NULL || *str == '\0') {
1128 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1129 acpi_gbl_create_osi_method = FALSE;
1130 } else if (!strcmp("!Linux", str)) {
1131 acpi_cmdline_osi_linux(0); /* !enable */
1132 } else if (*str == '!') {
1133 if (acpi_osi_invalidate(++str) == AE_OK)
1134 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1135 } else if (!strcmp("Linux", str)) {
1136 acpi_cmdline_osi_linux(1); /* enable */
1137 } else if (*osi_additional_string == '\0') {
1138 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1139 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1145 __setup("acpi_osi=", acpi_osi_setup);
1147 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1148 static int __init acpi_serialize_setup(char *str)
1150 printk(KERN_INFO PREFIX "serialize enabled\n");
1152 acpi_gbl_all_methods_serialized = TRUE;
1157 __setup("acpi_serialize", acpi_serialize_setup);
1160 * Wake and Run-Time GPES are expected to be separate.
1161 * We disable wake-GPEs at run-time to prevent spurious
1164 * However, if a system exists that shares Wake and
1165 * Run-time events on the same GPE this flag is available
1166 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1168 static int __init acpi_wake_gpes_always_on_setup(char *str)
1170 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1172 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1177 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1179 /* Check of resource interference between native drivers and ACPI
1180 * OperationRegions (SystemIO and System Memory only).
1181 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1182 * in arbitrary AML code and can interfere with legacy drivers.
1183 * acpi_enforce_resources= can be set to:
1186 * -> further driver trying to access the resources will not load
1187 * - lax (default) (1)
1188 * -> further driver trying to access the resources will load, but you
1189 * get a system message that something might go wrong...
1192 * -> ACPI Operation Region resources will not be registered
1195 #define ENFORCE_RESOURCES_STRICT 2
1196 #define ENFORCE_RESOURCES_LAX 1
1197 #define ENFORCE_RESOURCES_NO 0
1199 static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1201 static int __init acpi_enforce_resources_setup(char *str)
1203 if (str == NULL || *str == '\0')
1206 if (!strcmp("strict", str))
1207 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1208 else if (!strcmp("lax", str))
1209 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1210 else if (!strcmp("no", str))
1211 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1216 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1218 /* Check for resource conflicts between ACPI OperationRegions and native
1220 int acpi_check_resource_conflict(struct resource *res)
1222 struct acpi_res_list *res_list_elem;
1226 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1228 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1231 ioport = res->flags & IORESOURCE_IO;
1233 spin_lock(&acpi_res_lock);
1234 list_for_each_entry(res_list_elem, &resource_list_head,
1236 if (ioport && (res_list_elem->resource_type
1237 != ACPI_ADR_SPACE_SYSTEM_IO))
1239 if (!ioport && (res_list_elem->resource_type
1240 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1243 if (res->end < res_list_elem->start
1244 || res_list_elem->end < res->start)
1249 spin_unlock(&acpi_res_lock);
1252 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1253 printk(KERN_INFO "%sACPI: %s resource %s [0x%llx-0x%llx]"
1254 " conflicts with ACPI region %s"
1255 " [0x%llx-0x%llx]\n",
1256 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1257 ? KERN_WARNING : KERN_ERR,
1258 ioport ? "I/O" : "Memory", res->name,
1259 (long long) res->start, (long long) res->end,
1260 res_list_elem->name,
1261 (long long) res_list_elem->start,
1262 (long long) res_list_elem->end);
1263 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1265 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1270 EXPORT_SYMBOL(acpi_check_resource_conflict);
1272 int acpi_check_region(resource_size_t start, resource_size_t n,
1275 struct resource res = {
1277 .end = start + n - 1,
1279 .flags = IORESOURCE_IO,
1282 return acpi_check_resource_conflict(&res);
1284 EXPORT_SYMBOL(acpi_check_region);
1286 int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1289 struct resource res = {
1291 .end = start + n - 1,
1293 .flags = IORESOURCE_MEM,
1296 return acpi_check_resource_conflict(&res);
1299 EXPORT_SYMBOL(acpi_check_mem_region);
1302 * Acquire a spinlock.
1304 * handle is a pointer to the spinlock_t.
1307 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1309 acpi_cpu_flags flags;
1310 spin_lock_irqsave(lockp, flags);
1315 * Release a spinlock. See above.
1318 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1320 spin_unlock_irqrestore(lockp, flags);
1323 #ifndef ACPI_USE_LOCAL_CACHE
1325 /*******************************************************************************
1327 * FUNCTION: acpi_os_create_cache
1329 * PARAMETERS: name - Ascii name for the cache
1330 * size - Size of each cached object
1331 * depth - Maximum depth of the cache (in objects) <ignored>
1332 * cache - Where the new cache object is returned
1336 * DESCRIPTION: Create a cache object
1338 ******************************************************************************/
1341 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1343 *cache = kmem_cache_create(name, size, 0, 0, NULL);
1350 /*******************************************************************************
1352 * FUNCTION: acpi_os_purge_cache
1354 * PARAMETERS: Cache - Handle to cache object
1358 * DESCRIPTION: Free all objects within the requested cache.
1360 ******************************************************************************/
1362 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1364 kmem_cache_shrink(cache);
1368 /*******************************************************************************
1370 * FUNCTION: acpi_os_delete_cache
1372 * PARAMETERS: Cache - Handle to cache object
1376 * DESCRIPTION: Free all objects within the requested cache and delete the
1379 ******************************************************************************/
1381 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1383 kmem_cache_destroy(cache);
1387 /*******************************************************************************
1389 * FUNCTION: acpi_os_release_object
1391 * PARAMETERS: Cache - Handle to cache object
1392 * Object - The object to be released
1396 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1397 * the object is deleted.
1399 ******************************************************************************/
1401 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1403 kmem_cache_free(cache, object);
1408 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1410 * Returns 0 on success
1412 static int acpi_dmi_dump(void)
1418 printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
1419 dmi_get_system_info(DMI_SYS_VENDOR));
1420 printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
1421 dmi_get_system_info(DMI_PRODUCT_NAME));
1422 printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
1423 dmi_get_system_info(DMI_PRODUCT_VERSION));
1424 printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
1425 dmi_get_system_info(DMI_BOARD_NAME));
1426 printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
1427 dmi_get_system_info(DMI_BIOS_VENDOR));
1428 printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
1429 dmi_get_system_info(DMI_BIOS_DATE));
1435 /******************************************************************************
1437 * FUNCTION: acpi_os_validate_interface
1439 * PARAMETERS: interface - Requested interface to be validated
1441 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1443 * DESCRIPTION: Match an interface string to the interfaces supported by the
1444 * host. Strings originate from an AML call to the _OSI method.
1446 *****************************************************************************/
1449 acpi_os_validate_interface (char *interface)
1451 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1453 if (!strcmp("Linux", interface)) {
1455 printk(KERN_NOTICE PREFIX
1456 "BIOS _OSI(Linux) query %s%s\n",
1457 osi_linux.enable ? "honored" : "ignored",
1458 osi_linux.cmdline ? " via cmdline" :
1459 osi_linux.dmi ? " via DMI" : "");
1461 if (!osi_linux.dmi) {
1462 if (acpi_dmi_dump())
1463 printk(KERN_NOTICE PREFIX
1464 "[please extract dmidecode output]\n");
1465 printk(KERN_NOTICE PREFIX
1466 "Please send DMI info above to "
1467 "linux-acpi@vger.kernel.org\n");
1469 if (!osi_linux.known && !osi_linux.cmdline) {
1470 printk(KERN_NOTICE PREFIX
1471 "If \"acpi_osi=%sLinux\" works better, "
1472 "please notify linux-acpi@vger.kernel.org\n",
1473 osi_linux.enable ? "!" : "");
1476 if (osi_linux.enable)
1482 /******************************************************************************
1484 * FUNCTION: acpi_os_validate_address
1486 * PARAMETERS: space_id - ACPI space ID
1487 * address - Physical address
1488 * length - Address length
1490 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1491 * should return AE_AML_ILLEGAL_ADDRESS.
1493 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1494 * the addresses accessed by AML operation regions.
1496 *****************************************************************************/
1499 acpi_os_validate_address (
1501 acpi_physical_address address,
1505 struct acpi_res_list *res;
1506 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1510 case ACPI_ADR_SPACE_SYSTEM_IO:
1511 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1512 /* Only interference checks against SystemIO and SytemMemory
1514 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1517 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1518 strlcpy(res->name, name, 5);
1519 res->start = address;
1520 res->end = address + length - 1;
1521 res->resource_type = space_id;
1522 spin_lock(&acpi_res_lock);
1523 list_add(&res->resource_list, &resource_list_head);
1524 spin_unlock(&acpi_res_lock);
1525 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1526 "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1527 ? "SystemIO" : "System Memory",
1528 (unsigned long long)res->start,
1529 (unsigned long long)res->end,
1532 case ACPI_ADR_SPACE_PCI_CONFIG:
1533 case ACPI_ADR_SPACE_EC:
1534 case ACPI_ADR_SPACE_SMBUS:
1535 case ACPI_ADR_SPACE_CMOS:
1536 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1537 case ACPI_ADR_SPACE_DATA_TABLE:
1538 case ACPI_ADR_SPACE_FIXED_HARDWARE: