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;
63 #ifdef CONFIG_ACPI_CUSTOM_DSDT
64 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
67 #ifdef ENABLE_DEBUGGER
68 #include <linux/kdb.h>
70 /* stuff for debugger support */
72 EXPORT_SYMBOL(acpi_in_debugger);
74 extern char line_buf[80];
75 #endif /*ENABLE_DEBUGGER */
77 static unsigned int acpi_irq_irq;
78 static acpi_osd_handler acpi_irq_handler;
79 static void *acpi_irq_context;
80 static struct workqueue_struct *kacpid_wq;
81 static struct workqueue_struct *kacpi_notify_wq;
82 static struct workqueue_struct *kacpi_hotplug_wq;
84 struct acpi_res_list {
85 resource_size_t start;
87 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
88 char name[5]; /* only can have a length of 4 chars, make use of this
89 one instead of res->name, no need to kalloc then */
90 struct list_head resource_list;
94 static LIST_HEAD(resource_list_head);
95 static DEFINE_SPINLOCK(acpi_res_lock);
97 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
98 static char osi_additional_string[OSI_STRING_LENGTH_MAX];
101 * The story of _OSI(Linux)
103 * From pre-history through Linux-2.6.22,
104 * Linux responded TRUE upon a BIOS OSI(Linux) query.
106 * Unfortunately, reference BIOS writers got wind of this
107 * and put OSI(Linux) in their example code, quickly exposing
108 * this string as ill-conceived and opening the door to
109 * an un-bounded number of BIOS incompatibilities.
111 * For example, OSI(Linux) was used on resume to re-POST a
112 * video card on one system, because Linux at that time
113 * could not do a speedy restore in its native driver.
114 * But then upon gaining quick native restore capability,
115 * Linux has no way to tell the BIOS to skip the time-consuming
116 * POST -- putting Linux at a permanent performance disadvantage.
117 * On another system, the BIOS writer used OSI(Linux)
118 * to infer native OS support for IPMI! On other systems,
119 * OSI(Linux) simply got in the way of Linux claiming to
120 * be compatible with other operating systems, exposing
121 * BIOS issues such as skipped device initialization.
123 * So "Linux" turned out to be a really poor chose of
124 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
126 * BIOS writers should NOT query _OSI(Linux) on future systems.
127 * Linux will complain on the console when it sees it, and return FALSE.
128 * To get Linux to return TRUE for your system will require
129 * a kernel source update to add a DMI entry,
130 * or boot with "acpi_osi=Linux"
133 static struct osi_linux {
134 unsigned int enable:1;
136 unsigned int cmdline:1;
137 unsigned int known:1;
138 } osi_linux = { 0, 0, 0, 0};
140 static void __init acpi_request_region (struct acpi_generic_address *addr,
141 unsigned int length, char *desc)
143 struct resource *res;
145 if (!addr->address || !length)
148 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
149 res = request_region(addr->address, length, desc);
150 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
151 res = request_mem_region(addr->address, length, desc);
154 static int __init acpi_reserve_resources(void)
156 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
157 "ACPI PM1a_EVT_BLK");
159 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
160 "ACPI PM1b_EVT_BLK");
162 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
163 "ACPI PM1a_CNT_BLK");
165 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
166 "ACPI PM1b_CNT_BLK");
168 if (acpi_gbl_FADT.pm_timer_length == 4)
169 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
171 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
174 /* Length of GPE blocks must be a non-negative multiple of 2 */
176 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
177 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
178 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
180 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
181 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
182 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
186 device_initcall(acpi_reserve_resources);
188 acpi_status __init acpi_os_initialize(void)
193 static void bind_to_cpu0(struct work_struct *work)
195 set_cpus_allowed(current, cpumask_of_cpu(0));
199 static void bind_workqueue(struct workqueue_struct *wq)
201 struct work_struct *work;
203 work = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
204 INIT_WORK(work, bind_to_cpu0);
205 queue_work(wq, work);
208 acpi_status acpi_os_initialize1(void)
211 * On some machines, a software-initiated SMI causes corruption unless
212 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
213 * typically it's done in GPE-related methods that are run via
214 * workqueues, so we can avoid the known corruption cases by binding
215 * the workqueues to CPU 0.
217 kacpid_wq = create_singlethread_workqueue("kacpid");
218 bind_workqueue(kacpid_wq);
219 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
220 bind_workqueue(kacpi_notify_wq);
221 kacpi_hotplug_wq = create_singlethread_workqueue("kacpi_hotplug");
222 bind_workqueue(kacpi_hotplug_wq);
224 BUG_ON(!kacpi_notify_wq);
225 BUG_ON(!kacpi_hotplug_wq);
229 acpi_status acpi_os_terminate(void)
231 if (acpi_irq_handler) {
232 acpi_os_remove_interrupt_handler(acpi_irq_irq,
236 destroy_workqueue(kacpid_wq);
237 destroy_workqueue(kacpi_notify_wq);
238 destroy_workqueue(kacpi_hotplug_wq);
243 void acpi_os_printf(const char *fmt, ...)
247 acpi_os_vprintf(fmt, args);
251 void acpi_os_vprintf(const char *fmt, va_list args)
253 static char buffer[512];
255 vsprintf(buffer, fmt, args);
257 #ifdef ENABLE_DEBUGGER
258 if (acpi_in_debugger) {
259 kdb_printf("%s", buffer);
261 printk(KERN_CONT "%s", buffer);
264 printk(KERN_CONT "%s", buffer);
268 acpi_physical_address __init acpi_os_get_root_pointer(void)
271 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
273 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
276 printk(KERN_ERR PREFIX
277 "System description tables not found\n");
281 acpi_physical_address pa = 0;
283 acpi_find_root_pointer(&pa);
288 void __iomem *__init_refok
289 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
291 if (phys > ULONG_MAX) {
292 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
295 if (acpi_gbl_permanent_mmap)
297 * ioremap checks to ensure this is in reserved space
299 return ioremap((unsigned long)phys, size);
301 return __acpi_map_table((unsigned long)phys, size);
303 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
305 void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
307 if (acpi_gbl_permanent_mmap)
310 __acpi_unmap_table(virt, size);
312 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
314 void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
316 if (!acpi_gbl_permanent_mmap)
317 __acpi_unmap_table(virt, size);
320 #ifdef ACPI_FUTURE_USAGE
322 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
325 return AE_BAD_PARAMETER;
327 *phys = virt_to_phys(virt);
333 #define ACPI_MAX_OVERRIDE_LEN 100
335 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
338 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
339 acpi_string * new_val)
341 if (!init_val || !new_val)
342 return AE_BAD_PARAMETER;
345 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
346 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
348 *new_val = acpi_os_name;
355 acpi_os_table_override(struct acpi_table_header * existing_table,
356 struct acpi_table_header ** new_table)
358 if (!existing_table || !new_table)
359 return AE_BAD_PARAMETER;
363 #ifdef CONFIG_ACPI_CUSTOM_DSDT
364 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
365 *new_table = (struct acpi_table_header *)AmlCode;
367 if (*new_table != NULL) {
368 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
369 "this is unsafe: tainting kernel\n",
370 existing_table->signature,
371 existing_table->oem_table_id);
372 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
377 static irqreturn_t acpi_irq(int irq, void *dev_id)
381 handled = (*acpi_irq_handler) (acpi_irq_context);
387 acpi_irq_not_handled++;
393 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
398 acpi_irq_stats_init();
401 * Ignore the GSI from the core, and use the value in our copy of the
402 * FADT. It may not be the same if an interrupt source override exists
405 gsi = acpi_gbl_FADT.sci_interrupt;
406 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
407 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
412 acpi_irq_handler = handler;
413 acpi_irq_context = context;
414 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
415 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
416 return AE_NOT_ACQUIRED;
423 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
426 free_irq(irq, acpi_irq);
427 acpi_irq_handler = NULL;
435 * Running in interpreter thread context, safe to sleep
438 void acpi_os_sleep(acpi_integer ms)
440 schedule_timeout_interruptible(msecs_to_jiffies(ms));
443 void acpi_os_stall(u32 us)
451 touch_nmi_watchdog();
457 * Support ACPI 3.0 AML Timer operand
458 * Returns 64-bit free-running, monotonically increasing timer
459 * with 100ns granularity
461 u64 acpi_os_get_timer(void)
466 /* TBD: use HPET if available */
469 #ifdef CONFIG_X86_PM_TIMER
470 /* TBD: default to PM timer if HPET was not available */
473 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
478 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
487 *(u8 *) value = inb(port);
488 } else if (width <= 16) {
489 *(u16 *) value = inw(port);
490 } else if (width <= 32) {
491 *(u32 *) value = inl(port);
499 EXPORT_SYMBOL(acpi_os_read_port);
501 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
505 } else if (width <= 16) {
507 } else if (width <= 32) {
516 EXPORT_SYMBOL(acpi_os_write_port);
519 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
522 void __iomem *virt_addr;
524 virt_addr = ioremap(phys_addr, width);
530 *(u8 *) value = readb(virt_addr);
533 *(u16 *) value = readw(virt_addr);
536 *(u32 *) value = readl(virt_addr);
548 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
550 void __iomem *virt_addr;
552 virt_addr = ioremap(phys_addr, width);
556 writeb(value, virt_addr);
559 writew(value, virt_addr);
562 writel(value, virt_addr);
574 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
575 u32 *value, u32 width)
580 return AE_BAD_PARAMETER;
596 result = raw_pci_read(pci_id->segment, pci_id->bus,
597 PCI_DEVFN(pci_id->device, pci_id->function),
600 return (result ? AE_ERROR : AE_OK);
604 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
605 acpi_integer value, u32 width)
623 result = raw_pci_write(pci_id->segment, pci_id->bus,
624 PCI_DEVFN(pci_id->device, pci_id->function),
627 return (result ? AE_ERROR : AE_OK);
630 /* TODO: Change code to take advantage of driver model more */
631 static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
632 acpi_handle chandle, /* current node */
633 struct acpi_pci_id **id,
634 int *is_bridge, u8 * bus_number)
637 struct acpi_pci_id *pci_id = *id;
639 unsigned long long temp;
640 acpi_object_type type;
642 acpi_get_parent(chandle, &handle);
643 if (handle != rhandle) {
644 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
647 status = acpi_get_type(handle, &type);
648 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
651 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
653 if (ACPI_SUCCESS(status)) {
655 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
656 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
659 pci_id->bus = *bus_number;
661 /* any nicer way to get bus number of bridge ? */
663 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
665 if (ACPI_SUCCESS(status)
666 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
668 acpi_os_read_pci_configuration(pci_id, 0x18,
670 if (!ACPI_SUCCESS(status)) {
671 /* Certainly broken... FIX ME */
677 acpi_os_read_pci_configuration(pci_id, 0x19,
679 if (ACPI_SUCCESS(status)) {
688 void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
689 acpi_handle chandle, /* current node */
690 struct acpi_pci_id **id)
693 u8 bus_number = (*id)->bus;
695 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
698 static void acpi_os_execute_deferred(struct work_struct *work)
700 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
702 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
706 dpc->function(dpc->context);
712 static void acpi_os_execute_hp_deferred(struct work_struct *work)
714 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
716 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
720 acpi_os_wait_events_complete(NULL);
722 dpc->function(dpc->context);
728 /*******************************************************************************
730 * FUNCTION: acpi_os_execute
732 * PARAMETERS: Type - Type of the callback
733 * Function - Function to be executed
734 * Context - Function parameters
738 * DESCRIPTION: Depending on type, either queues function for deferred execution or
739 * immediately executes function on a separate thread.
741 ******************************************************************************/
743 static acpi_status __acpi_os_execute(acpi_execute_type type,
744 acpi_osd_exec_callback function, void *context, int hp)
746 acpi_status status = AE_OK;
747 struct acpi_os_dpc *dpc;
748 struct workqueue_struct *queue;
751 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
752 "Scheduling function [%p(%p)] for deferred execution.\n",
756 return AE_BAD_PARAMETER;
759 * Allocate/initialize DPC structure. Note that this memory will be
760 * freed by the callee. The kernel handles the work_struct list in a
761 * way that allows us to also free its memory inside the callee.
762 * Because we may want to schedule several tasks with different
763 * parameters we can't use the approach some kernel code uses of
764 * having a static work_struct.
767 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
771 dpc->function = function;
772 dpc->context = context;
775 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
776 * because the hotplug code may call driver .remove() functions,
777 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
778 * to flush these workqueues.
780 queue = hp ? kacpi_hotplug_wq :
781 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
782 func = hp ? acpi_os_execute_hp_deferred : acpi_os_execute_deferred;
783 INIT_WORK(&dpc->work, func);
784 ret = queue_work(queue, &dpc->work);
787 printk(KERN_ERR PREFIX
788 "Call to queue_work() failed.\n");
795 acpi_status acpi_os_execute(acpi_execute_type type,
796 acpi_osd_exec_callback function, void *context)
798 return __acpi_os_execute(type, function, context, 0);
800 EXPORT_SYMBOL(acpi_os_execute);
802 acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
805 return __acpi_os_execute(0, function, context, 1);
808 void acpi_os_wait_events_complete(void *context)
810 flush_workqueue(kacpid_wq);
811 flush_workqueue(kacpi_notify_wq);
814 EXPORT_SYMBOL(acpi_os_wait_events_complete);
817 * Allocate the memory for a spinlock and initialize it.
819 acpi_status acpi_os_create_lock(acpi_spinlock * handle)
821 spin_lock_init(*handle);
827 * Deallocate the memory for a spinlock.
829 void acpi_os_delete_lock(acpi_spinlock handle)
835 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
837 struct semaphore *sem = NULL;
839 sem = acpi_os_allocate(sizeof(struct semaphore));
842 memset(sem, 0, sizeof(struct semaphore));
844 sema_init(sem, initial_units);
846 *handle = (acpi_handle *) sem;
848 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
849 *handle, initial_units));
855 * TODO: A better way to delete semaphores? Linux doesn't have a
856 * 'delete_semaphore()' function -- may result in an invalid
857 * pointer dereference for non-synchronized consumers. Should
858 * we at least check for blocked threads and signal/cancel them?
861 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
863 struct semaphore *sem = (struct semaphore *)handle;
866 return AE_BAD_PARAMETER;
868 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
870 BUG_ON(!list_empty(&sem->wait_list));
878 * TODO: Support for units > 1?
880 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
882 acpi_status status = AE_OK;
883 struct semaphore *sem = (struct semaphore *)handle;
887 if (!sem || (units < 1))
888 return AE_BAD_PARAMETER;
893 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
894 handle, units, timeout));
896 if (timeout == ACPI_WAIT_FOREVER)
897 jiffies = MAX_SCHEDULE_TIMEOUT;
899 jiffies = msecs_to_jiffies(timeout);
901 ret = down_timeout(sem, jiffies);
905 if (ACPI_FAILURE(status)) {
906 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
907 "Failed to acquire semaphore[%p|%d|%d], %s",
908 handle, units, timeout,
909 acpi_format_exception(status)));
911 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
912 "Acquired semaphore[%p|%d|%d]", handle,
920 * TODO: Support for units > 1?
922 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
924 struct semaphore *sem = (struct semaphore *)handle;
926 if (!sem || (units < 1))
927 return AE_BAD_PARAMETER;
932 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
940 #ifdef ACPI_FUTURE_USAGE
941 u32 acpi_os_get_line(char *buffer)
944 #ifdef ENABLE_DEBUGGER
945 if (acpi_in_debugger) {
948 kdb_read(buffer, sizeof(line_buf));
950 /* remove the CR kdb includes */
951 chars = strlen(buffer) - 1;
952 buffer[chars] = '\0';
958 #endif /* ACPI_FUTURE_USAGE */
960 acpi_status acpi_os_signal(u32 function, void *info)
963 case ACPI_SIGNAL_FATAL:
964 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
966 case ACPI_SIGNAL_BREAKPOINT:
969 * ACPI spec. says to treat it as a NOP unless
970 * you are debugging. So if/when we integrate
971 * AML debugger into the kernel debugger its
972 * hook will go here. But until then it is
973 * not useful to print anything on breakpoints.
983 static int __init acpi_os_name_setup(char *str)
985 char *p = acpi_os_name;
986 int count = ACPI_MAX_OVERRIDE_LEN - 1;
991 for (; count-- && str && *str; str++) {
992 if (isalnum(*str) || *str == ' ' || *str == ':')
994 else if (*str == '\'' || *str == '"')
1005 __setup("acpi_os_name=", acpi_os_name_setup);
1007 static void __init set_osi_linux(unsigned int enable)
1009 if (osi_linux.enable != enable) {
1010 osi_linux.enable = enable;
1011 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1012 enable ? "Add": "Delet");
1017 static void __init acpi_cmdline_osi_linux(unsigned int enable)
1019 osi_linux.cmdline = 1; /* cmdline set the default */
1020 set_osi_linux(enable);
1025 void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1027 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1029 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1034 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1036 set_osi_linux(enable);
1042 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1044 * empty string disables _OSI
1045 * string starting with '!' disables that string
1046 * otherwise string is added to list, augmenting built-in strings
1048 int __init acpi_osi_setup(char *str)
1050 if (str == NULL || *str == '\0') {
1051 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1052 acpi_gbl_create_osi_method = FALSE;
1053 } else if (!strcmp("!Linux", str)) {
1054 acpi_cmdline_osi_linux(0); /* !enable */
1055 } else if (*str == '!') {
1056 if (acpi_osi_invalidate(++str) == AE_OK)
1057 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1058 } else if (!strcmp("Linux", str)) {
1059 acpi_cmdline_osi_linux(1); /* enable */
1060 } else if (*osi_additional_string == '\0') {
1061 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1062 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1068 __setup("acpi_osi=", acpi_osi_setup);
1070 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1071 static int __init acpi_serialize_setup(char *str)
1073 printk(KERN_INFO PREFIX "serialize enabled\n");
1075 acpi_gbl_all_methods_serialized = TRUE;
1080 __setup("acpi_serialize", acpi_serialize_setup);
1083 * Wake and Run-Time GPES are expected to be separate.
1084 * We disable wake-GPEs at run-time to prevent spurious
1087 * However, if a system exists that shares Wake and
1088 * Run-time events on the same GPE this flag is available
1089 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1091 static int __init acpi_wake_gpes_always_on_setup(char *str)
1093 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1095 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1100 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1102 /* Check of resource interference between native drivers and ACPI
1103 * OperationRegions (SystemIO and System Memory only).
1104 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1105 * in arbitrary AML code and can interfere with legacy drivers.
1106 * acpi_enforce_resources= can be set to:
1108 * - strict (default) (2)
1109 * -> further driver trying to access the resources will not load
1111 * -> further driver trying to access the resources will load, but you
1112 * get a system message that something might go wrong...
1115 * -> ACPI Operation Region resources will not be registered
1118 #define ENFORCE_RESOURCES_STRICT 2
1119 #define ENFORCE_RESOURCES_LAX 1
1120 #define ENFORCE_RESOURCES_NO 0
1122 static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1124 static int __init acpi_enforce_resources_setup(char *str)
1126 if (str == NULL || *str == '\0')
1129 if (!strcmp("strict", str))
1130 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1131 else if (!strcmp("lax", str))
1132 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1133 else if (!strcmp("no", str))
1134 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1139 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1141 /* Check for resource conflicts between ACPI OperationRegions and native
1143 int acpi_check_resource_conflict(struct resource *res)
1145 struct acpi_res_list *res_list_elem;
1149 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1151 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1154 ioport = res->flags & IORESOURCE_IO;
1156 spin_lock(&acpi_res_lock);
1157 list_for_each_entry(res_list_elem, &resource_list_head,
1159 if (ioport && (res_list_elem->resource_type
1160 != ACPI_ADR_SPACE_SYSTEM_IO))
1162 if (!ioport && (res_list_elem->resource_type
1163 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1166 if (res->end < res_list_elem->start
1167 || res_list_elem->end < res->start)
1172 spin_unlock(&acpi_res_lock);
1175 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1176 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
1177 " conflicts with ACPI region %s"
1178 " [0x%llx-0x%llx]\n",
1179 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1180 ? KERN_WARNING : KERN_ERR,
1181 ioport ? "I/O" : "Memory", res->name,
1182 (long long) res->start, (long long) res->end,
1183 res_list_elem->name,
1184 (long long) res_list_elem->start,
1185 (long long) res_list_elem->end);
1186 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1188 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1193 EXPORT_SYMBOL(acpi_check_resource_conflict);
1195 int acpi_check_region(resource_size_t start, resource_size_t n,
1198 struct resource res = {
1200 .end = start + n - 1,
1202 .flags = IORESOURCE_IO,
1205 return acpi_check_resource_conflict(&res);
1207 EXPORT_SYMBOL(acpi_check_region);
1209 int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1212 struct resource res = {
1214 .end = start + n - 1,
1216 .flags = IORESOURCE_MEM,
1219 return acpi_check_resource_conflict(&res);
1222 EXPORT_SYMBOL(acpi_check_mem_region);
1225 * Acquire a spinlock.
1227 * handle is a pointer to the spinlock_t.
1230 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1232 acpi_cpu_flags flags;
1233 spin_lock_irqsave(lockp, flags);
1238 * Release a spinlock. See above.
1241 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1243 spin_unlock_irqrestore(lockp, flags);
1246 #ifndef ACPI_USE_LOCAL_CACHE
1248 /*******************************************************************************
1250 * FUNCTION: acpi_os_create_cache
1252 * PARAMETERS: name - Ascii name for the cache
1253 * size - Size of each cached object
1254 * depth - Maximum depth of the cache (in objects) <ignored>
1255 * cache - Where the new cache object is returned
1259 * DESCRIPTION: Create a cache object
1261 ******************************************************************************/
1264 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1266 *cache = kmem_cache_create(name, size, 0, 0, NULL);
1273 /*******************************************************************************
1275 * FUNCTION: acpi_os_purge_cache
1277 * PARAMETERS: Cache - Handle to cache object
1281 * DESCRIPTION: Free all objects within the requested cache.
1283 ******************************************************************************/
1285 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1287 kmem_cache_shrink(cache);
1291 /*******************************************************************************
1293 * FUNCTION: acpi_os_delete_cache
1295 * PARAMETERS: Cache - Handle to cache object
1299 * DESCRIPTION: Free all objects within the requested cache and delete the
1302 ******************************************************************************/
1304 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1306 kmem_cache_destroy(cache);
1310 /*******************************************************************************
1312 * FUNCTION: acpi_os_release_object
1314 * PARAMETERS: Cache - Handle to cache object
1315 * Object - The object to be released
1319 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1320 * the object is deleted.
1322 ******************************************************************************/
1324 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1326 kmem_cache_free(cache, object);
1330 /******************************************************************************
1332 * FUNCTION: acpi_os_validate_interface
1334 * PARAMETERS: interface - Requested interface to be validated
1336 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1338 * DESCRIPTION: Match an interface string to the interfaces supported by the
1339 * host. Strings originate from an AML call to the _OSI method.
1341 *****************************************************************************/
1344 acpi_os_validate_interface (char *interface)
1346 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1348 if (!strcmp("Linux", interface)) {
1350 printk(KERN_NOTICE PREFIX
1351 "BIOS _OSI(Linux) query %s%s\n",
1352 osi_linux.enable ? "honored" : "ignored",
1353 osi_linux.cmdline ? " via cmdline" :
1354 osi_linux.dmi ? " via DMI" : "");
1356 if (osi_linux.enable)
1362 static inline int acpi_res_list_add(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 * The Region(addr,len) already exist in the list,
1375 * just increase the count
1378 res_list_elem->count++;
1384 list_add(&res->resource_list, &resource_list_head);
1388 static inline void acpi_res_list_del(struct acpi_res_list *res)
1390 struct acpi_res_list *res_list_elem;
1392 list_for_each_entry(res_list_elem, &resource_list_head,
1395 if (res->resource_type == res_list_elem->resource_type &&
1396 res->start == res_list_elem->start &&
1397 res->end == res_list_elem->end) {
1400 * If the res count is decreased to 0,
1401 * remove and free it
1404 if (--res_list_elem->count == 0) {
1405 list_del(&res_list_elem->resource_list);
1406 kfree(res_list_elem);
1414 acpi_os_invalidate_address(
1416 acpi_physical_address address,
1419 struct acpi_res_list res;
1422 case ACPI_ADR_SPACE_SYSTEM_IO:
1423 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1424 /* Only interference checks against SystemIO and SytemMemory
1426 res.start = address;
1427 res.end = address + length - 1;
1428 res.resource_type = space_id;
1429 spin_lock(&acpi_res_lock);
1430 acpi_res_list_del(&res);
1431 spin_unlock(&acpi_res_lock);
1433 case ACPI_ADR_SPACE_PCI_CONFIG:
1434 case ACPI_ADR_SPACE_EC:
1435 case ACPI_ADR_SPACE_SMBUS:
1436 case ACPI_ADR_SPACE_CMOS:
1437 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1438 case ACPI_ADR_SPACE_DATA_TABLE:
1439 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1445 /******************************************************************************
1447 * FUNCTION: acpi_os_validate_address
1449 * PARAMETERS: space_id - ACPI space ID
1450 * address - Physical address
1451 * length - Address length
1453 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1454 * should return AE_AML_ILLEGAL_ADDRESS.
1456 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1457 * the addresses accessed by AML operation regions.
1459 *****************************************************************************/
1462 acpi_os_validate_address (
1464 acpi_physical_address address,
1468 struct acpi_res_list *res;
1470 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1474 case ACPI_ADR_SPACE_SYSTEM_IO:
1475 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1476 /* Only interference checks against SystemIO and SytemMemory
1478 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1481 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1482 strlcpy(res->name, name, 5);
1483 res->start = address;
1484 res->end = address + length - 1;
1485 res->resource_type = space_id;
1486 spin_lock(&acpi_res_lock);
1487 added = acpi_res_list_add(res);
1488 spin_unlock(&acpi_res_lock);
1489 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1490 "name: %s\n", added ? "Added" : "Already exist",
1491 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1492 ? "SystemIO" : "System Memory",
1493 (unsigned long long)res->start,
1494 (unsigned long long)res->end,
1499 case ACPI_ADR_SPACE_PCI_CONFIG:
1500 case ACPI_ADR_SPACE_EC:
1501 case ACPI_ADR_SPACE_SMBUS:
1502 case ACPI_ADR_SPACE_CMOS:
1503 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1504 case ACPI_ADR_SPACE_DATA_TABLE:
1505 case ACPI_ADR_SPACE_FIXED_HARDWARE: