2 * acpi_osl.c - OS-dependent functions ($Revision: 83 $)
4 * Copyright (C) 2000 Andrew Henroid
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * Copyright (c) 2008 Intel Corporation
8 * Author: Matthew Wilcox <willy@linux.intel.com>
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
34 #include <linux/pci.h>
35 #include <linux/interrupt.h>
36 #include <linux/kmod.h>
37 #include <linux/delay.h>
38 #include <linux/workqueue.h>
39 #include <linux/nmi.h>
40 #include <linux/acpi.h>
41 #include <linux/efi.h>
42 #include <linux/ioport.h>
43 #include <linux/list.h>
44 #include <linux/jiffies.h>
45 #include <linux/semaphore.h>
48 #include <asm/uaccess.h>
50 #include <acpi/acpi.h>
51 #include <acpi/acpi_bus.h>
52 #include <acpi/processor.h>
54 #define _COMPONENT ACPI_OS_SERVICES
55 ACPI_MODULE_NAME("osl");
56 #define PREFIX "ACPI: "
58 acpi_osd_exec_callback function;
60 struct work_struct work;
64 #ifdef CONFIG_ACPI_CUSTOM_DSDT
65 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
68 #ifdef ENABLE_DEBUGGER
69 #include <linux/kdb.h>
71 /* stuff for debugger support */
73 EXPORT_SYMBOL(acpi_in_debugger);
75 extern char line_buf[80];
76 #endif /*ENABLE_DEBUGGER */
78 static unsigned int acpi_irq_irq;
79 static acpi_osd_handler acpi_irq_handler;
80 static void *acpi_irq_context;
81 static struct workqueue_struct *kacpid_wq;
82 static struct workqueue_struct *kacpi_notify_wq;
83 static struct workqueue_struct *kacpi_hotplug_wq;
85 struct acpi_res_list {
86 resource_size_t start;
88 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
89 char name[5]; /* only can have a length of 4 chars, make use of this
90 one instead of res->name, no need to kalloc then */
91 struct list_head resource_list;
95 static LIST_HEAD(resource_list_head);
96 static DEFINE_SPINLOCK(acpi_res_lock);
99 * This list of permanent mappings is for memory that may be accessed from
100 * interrupt context, where we can't do the ioremap().
102 struct acpi_ioremap {
103 struct list_head list;
105 acpi_physical_address phys;
110 static LIST_HEAD(acpi_ioremaps);
111 static DEFINE_SPINLOCK(acpi_ioremap_lock);
113 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
114 static char osi_setup_string[OSI_STRING_LENGTH_MAX];
116 static void __init acpi_osi_setup_late(void);
119 * The story of _OSI(Linux)
121 * From pre-history through Linux-2.6.22,
122 * Linux responded TRUE upon a BIOS OSI(Linux) query.
124 * Unfortunately, reference BIOS writers got wind of this
125 * and put OSI(Linux) in their example code, quickly exposing
126 * this string as ill-conceived and opening the door to
127 * an un-bounded number of BIOS incompatibilities.
129 * For example, OSI(Linux) was used on resume to re-POST a
130 * video card on one system, because Linux at that time
131 * could not do a speedy restore in its native driver.
132 * But then upon gaining quick native restore capability,
133 * Linux has no way to tell the BIOS to skip the time-consuming
134 * POST -- putting Linux at a permanent performance disadvantage.
135 * On another system, the BIOS writer used OSI(Linux)
136 * to infer native OS support for IPMI! On other systems,
137 * OSI(Linux) simply got in the way of Linux claiming to
138 * be compatible with other operating systems, exposing
139 * BIOS issues such as skipped device initialization.
141 * So "Linux" turned out to be a really poor chose of
142 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
144 * BIOS writers should NOT query _OSI(Linux) on future systems.
145 * Linux will complain on the console when it sees it, and return FALSE.
146 * To get Linux to return TRUE for your system will require
147 * a kernel source update to add a DMI entry,
148 * or boot with "acpi_osi=Linux"
151 static struct osi_linux {
152 unsigned int enable:1;
154 unsigned int cmdline:1;
155 unsigned int known:1;
156 } osi_linux = { 0, 0, 0, 0};
158 static u32 acpi_osi_handler(acpi_string interface, u32 supported)
160 if (!strcmp("Linux", interface)) {
162 printk(KERN_NOTICE FW_BUG PREFIX
163 "BIOS _OSI(Linux) query %s%s\n",
164 osi_linux.enable ? "honored" : "ignored",
165 osi_linux.cmdline ? " via cmdline" :
166 osi_linux.dmi ? " via DMI" : "");
172 static void __init acpi_request_region (struct acpi_generic_address *addr,
173 unsigned int length, char *desc)
175 if (!addr->address || !length)
178 /* Resources are never freed */
179 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
180 request_region(addr->address, length, desc);
181 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
182 request_mem_region(addr->address, length, desc);
185 static int __init acpi_reserve_resources(void)
187 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
188 "ACPI PM1a_EVT_BLK");
190 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
191 "ACPI PM1b_EVT_BLK");
193 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
194 "ACPI PM1a_CNT_BLK");
196 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
197 "ACPI PM1b_CNT_BLK");
199 if (acpi_gbl_FADT.pm_timer_length == 4)
200 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
202 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
205 /* Length of GPE blocks must be a non-negative multiple of 2 */
207 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
208 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
209 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
211 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
212 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
213 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
217 device_initcall(acpi_reserve_resources);
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(KERN_CONT "%s", buffer);
240 printk(KERN_CONT "%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 /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
265 static struct acpi_ioremap *
266 acpi_map_lookup(acpi_physical_address phys, acpi_size size)
268 struct acpi_ioremap *map;
270 list_for_each_entry_rcu(map, &acpi_ioremaps, list)
271 if (map->phys <= phys &&
272 phys + size <= map->phys + map->size)
278 /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
279 static void __iomem *
280 acpi_map_vaddr_lookup(acpi_physical_address phys, unsigned int size)
282 struct acpi_ioremap *map;
284 map = acpi_map_lookup(phys, size);
286 return map->virt + (phys - map->phys);
291 /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
292 static struct acpi_ioremap *
293 acpi_map_lookup_virt(void __iomem *virt, acpi_size size)
295 struct acpi_ioremap *map;
297 list_for_each_entry_rcu(map, &acpi_ioremaps, list)
298 if (map->virt <= virt &&
299 virt + size <= map->virt + map->size)
305 void __iomem *__init_refok
306 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
308 struct acpi_ioremap *map, *tmp_map;
309 unsigned long flags, pg_sz;
313 if (phys > ULONG_MAX) {
314 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
318 if (!acpi_gbl_permanent_mmap)
319 return __acpi_map_table((unsigned long)phys, size);
321 map = kzalloc(sizeof(*map), GFP_KERNEL);
325 pg_off = round_down(phys, PAGE_SIZE);
326 pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off;
327 virt = ioremap(pg_off, pg_sz);
333 INIT_LIST_HEAD(&map->list);
337 kref_init(&map->ref);
339 spin_lock_irqsave(&acpi_ioremap_lock, flags);
340 /* Check if page has already been mapped. */
341 tmp_map = acpi_map_lookup(phys, size);
343 kref_get(&tmp_map->ref);
344 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
347 return tmp_map->virt + (phys - tmp_map->phys);
349 list_add_tail_rcu(&map->list, &acpi_ioremaps);
350 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
352 return map->virt + (phys - map->phys);
354 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
356 static void acpi_kref_del_iomap(struct kref *ref)
358 struct acpi_ioremap *map;
360 map = container_of(ref, struct acpi_ioremap, ref);
361 list_del_rcu(&map->list);
364 void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
366 struct acpi_ioremap *map;
370 if (!acpi_gbl_permanent_mmap) {
371 __acpi_unmap_table(virt, size);
375 spin_lock_irqsave(&acpi_ioremap_lock, flags);
376 map = acpi_map_lookup_virt(virt, size);
378 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
379 printk(KERN_ERR PREFIX "%s: bad address %p\n", __func__, virt);
384 del = kref_put(&map->ref, acpi_kref_del_iomap);
385 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
394 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
396 void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
398 if (!acpi_gbl_permanent_mmap)
399 __acpi_unmap_table(virt, size);
402 int acpi_os_map_generic_address(struct acpi_generic_address *addr)
406 if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
409 if (!addr->address || !addr->bit_width)
412 virt = acpi_os_map_memory(addr->address, addr->bit_width / 8);
418 EXPORT_SYMBOL_GPL(acpi_os_map_generic_address);
420 void acpi_os_unmap_generic_address(struct acpi_generic_address *addr)
424 acpi_size size = addr->bit_width / 8;
426 if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
429 if (!addr->address || !addr->bit_width)
432 spin_lock_irqsave(&acpi_ioremap_lock, flags);
433 virt = acpi_map_vaddr_lookup(addr->address, size);
434 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
436 acpi_os_unmap_memory(virt, size);
438 EXPORT_SYMBOL_GPL(acpi_os_unmap_generic_address);
440 #ifdef ACPI_FUTURE_USAGE
442 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
445 return AE_BAD_PARAMETER;
447 *phys = virt_to_phys(virt);
453 #define ACPI_MAX_OVERRIDE_LEN 100
455 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
458 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
459 acpi_string * new_val)
461 if (!init_val || !new_val)
462 return AE_BAD_PARAMETER;
465 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
466 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
468 *new_val = acpi_os_name;
475 acpi_os_table_override(struct acpi_table_header * existing_table,
476 struct acpi_table_header ** new_table)
478 if (!existing_table || !new_table)
479 return AE_BAD_PARAMETER;
483 #ifdef CONFIG_ACPI_CUSTOM_DSDT
484 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
485 *new_table = (struct acpi_table_header *)AmlCode;
487 if (*new_table != NULL) {
488 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
489 "this is unsafe: tainting kernel\n",
490 existing_table->signature,
491 existing_table->oem_table_id);
492 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
497 static irqreturn_t acpi_irq(int irq, void *dev_id)
501 handled = (*acpi_irq_handler) (acpi_irq_context);
507 acpi_irq_not_handled++;
513 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
518 acpi_irq_stats_init();
521 * Ignore the GSI from the core, and use the value in our copy of the
522 * FADT. It may not be the same if an interrupt source override exists
525 gsi = acpi_gbl_FADT.sci_interrupt;
526 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
527 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
532 acpi_irq_handler = handler;
533 acpi_irq_context = context;
534 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
535 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
536 return AE_NOT_ACQUIRED;
543 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
546 free_irq(irq, acpi_irq);
547 acpi_irq_handler = NULL;
555 * Running in interpreter thread context, safe to sleep
558 void acpi_os_sleep(u64 ms)
560 schedule_timeout_interruptible(msecs_to_jiffies(ms));
563 void acpi_os_stall(u32 us)
571 touch_nmi_watchdog();
577 * Support ACPI 3.0 AML Timer operand
578 * Returns 64-bit free-running, monotonically increasing timer
579 * with 100ns granularity
581 u64 acpi_os_get_timer(void)
586 /* TBD: use HPET if available */
589 #ifdef CONFIG_X86_PM_TIMER
590 /* TBD: default to PM timer if HPET was not available */
593 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
598 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
607 *(u8 *) value = inb(port);
608 } else if (width <= 16) {
609 *(u16 *) value = inw(port);
610 } else if (width <= 32) {
611 *(u32 *) value = inl(port);
619 EXPORT_SYMBOL(acpi_os_read_port);
621 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
625 } else if (width <= 16) {
627 } else if (width <= 32) {
636 EXPORT_SYMBOL(acpi_os_write_port);
639 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
642 void __iomem *virt_addr;
643 int size = width / 8, unmap = 0;
646 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
649 virt_addr = ioremap(phys_addr, size);
657 *(u8 *) value = readb(virt_addr);
660 *(u16 *) value = readw(virt_addr);
663 *(u32 *) value = readl(virt_addr);
676 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
678 void __iomem *virt_addr;
679 int size = width / 8, unmap = 0;
682 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
685 virt_addr = ioremap(phys_addr, size);
691 writeb(value, virt_addr);
694 writew(value, virt_addr);
697 writel(value, virt_addr);
710 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
711 u64 *value, u32 width)
717 return AE_BAD_PARAMETER;
733 result = raw_pci_read(pci_id->segment, pci_id->bus,
734 PCI_DEVFN(pci_id->device, pci_id->function),
735 reg, size, &value32);
738 return (result ? AE_ERROR : AE_OK);
742 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
743 u64 value, u32 width)
761 result = raw_pci_write(pci_id->segment, pci_id->bus,
762 PCI_DEVFN(pci_id->device, pci_id->function),
765 return (result ? AE_ERROR : AE_OK);
768 static void acpi_os_execute_deferred(struct work_struct *work)
770 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
773 acpi_os_wait_events_complete(NULL);
775 dpc->function(dpc->context);
779 /*******************************************************************************
781 * FUNCTION: acpi_os_execute
783 * PARAMETERS: Type - Type of the callback
784 * Function - Function to be executed
785 * Context - Function parameters
789 * DESCRIPTION: Depending on type, either queues function for deferred execution or
790 * immediately executes function on a separate thread.
792 ******************************************************************************/
794 static acpi_status __acpi_os_execute(acpi_execute_type type,
795 acpi_osd_exec_callback function, void *context, int hp)
797 acpi_status status = AE_OK;
798 struct acpi_os_dpc *dpc;
799 struct workqueue_struct *queue;
801 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
802 "Scheduling function [%p(%p)] for deferred execution.\n",
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);
818 dpc->function = function;
819 dpc->context = context;
822 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
823 * because the hotplug code may call driver .remove() functions,
824 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
825 * to flush these workqueues.
827 queue = hp ? kacpi_hotplug_wq :
828 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
829 dpc->wait = hp ? 1 : 0;
831 if (queue == kacpi_hotplug_wq)
832 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
833 else if (queue == kacpi_notify_wq)
834 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
836 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
839 * On some machines, a software-initiated SMI causes corruption unless
840 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
841 * typically it's done in GPE-related methods that are run via
842 * workqueues, so we can avoid the known corruption cases by always
845 ret = queue_work_on(0, queue, &dpc->work);
848 printk(KERN_ERR PREFIX
849 "Call to queue_work() failed.\n");
856 acpi_status acpi_os_execute(acpi_execute_type type,
857 acpi_osd_exec_callback function, void *context)
859 return __acpi_os_execute(type, function, context, 0);
861 EXPORT_SYMBOL(acpi_os_execute);
863 acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
866 return __acpi_os_execute(0, function, context, 1);
869 void acpi_os_wait_events_complete(void *context)
871 flush_workqueue(kacpid_wq);
872 flush_workqueue(kacpi_notify_wq);
875 EXPORT_SYMBOL(acpi_os_wait_events_complete);
878 * Deallocate the memory for a spinlock.
880 void acpi_os_delete_lock(acpi_spinlock handle)
886 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
888 struct semaphore *sem = NULL;
890 sem = acpi_os_allocate(sizeof(struct semaphore));
893 memset(sem, 0, sizeof(struct semaphore));
895 sema_init(sem, initial_units);
897 *handle = (acpi_handle *) sem;
899 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
900 *handle, initial_units));
906 * TODO: A better way to delete semaphores? Linux doesn't have a
907 * 'delete_semaphore()' function -- may result in an invalid
908 * pointer dereference for non-synchronized consumers. Should
909 * we at least check for blocked threads and signal/cancel them?
912 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
914 struct semaphore *sem = (struct semaphore *)handle;
917 return AE_BAD_PARAMETER;
919 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
921 BUG_ON(!list_empty(&sem->wait_list));
929 * TODO: Support for units > 1?
931 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
933 acpi_status status = AE_OK;
934 struct semaphore *sem = (struct semaphore *)handle;
938 if (!sem || (units < 1))
939 return AE_BAD_PARAMETER;
944 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
945 handle, units, timeout));
947 if (timeout == ACPI_WAIT_FOREVER)
948 jiffies = MAX_SCHEDULE_TIMEOUT;
950 jiffies = msecs_to_jiffies(timeout);
952 ret = down_timeout(sem, jiffies);
956 if (ACPI_FAILURE(status)) {
957 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
958 "Failed to acquire semaphore[%p|%d|%d], %s",
959 handle, units, timeout,
960 acpi_format_exception(status)));
962 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
963 "Acquired semaphore[%p|%d|%d]", handle,
971 * TODO: Support for units > 1?
973 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
975 struct semaphore *sem = (struct semaphore *)handle;
977 if (!sem || (units < 1))
978 return AE_BAD_PARAMETER;
983 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
991 #ifdef ACPI_FUTURE_USAGE
992 u32 acpi_os_get_line(char *buffer)
995 #ifdef ENABLE_DEBUGGER
996 if (acpi_in_debugger) {
999 kdb_read(buffer, sizeof(line_buf));
1001 /* remove the CR kdb includes */
1002 chars = strlen(buffer) - 1;
1003 buffer[chars] = '\0';
1009 #endif /* ACPI_FUTURE_USAGE */
1011 acpi_status acpi_os_signal(u32 function, void *info)
1014 case ACPI_SIGNAL_FATAL:
1015 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
1017 case ACPI_SIGNAL_BREAKPOINT:
1020 * ACPI spec. says to treat it as a NOP unless
1021 * you are debugging. So if/when we integrate
1022 * AML debugger into the kernel debugger its
1023 * hook will go here. But until then it is
1024 * not useful to print anything on breakpoints.
1034 static int __init acpi_os_name_setup(char *str)
1036 char *p = acpi_os_name;
1037 int count = ACPI_MAX_OVERRIDE_LEN - 1;
1042 for (; count-- && str && *str; str++) {
1043 if (isalnum(*str) || *str == ' ' || *str == ':')
1045 else if (*str == '\'' || *str == '"')
1056 __setup("acpi_os_name=", acpi_os_name_setup);
1058 static void __init set_osi_linux(unsigned int enable)
1060 if (osi_linux.enable != enable) {
1061 osi_linux.enable = enable;
1062 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1063 enable ? "Add": "Delet");
1066 if (osi_linux.enable)
1067 acpi_osi_setup("Linux");
1069 acpi_osi_setup("!Linux");
1074 static void __init acpi_cmdline_osi_linux(unsigned int enable)
1076 osi_linux.cmdline = 1; /* cmdline set the default */
1077 set_osi_linux(enable);
1082 void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1084 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1086 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1091 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1093 set_osi_linux(enable);
1099 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1101 * empty string disables _OSI
1102 * string starting with '!' disables that string
1103 * otherwise string is added to list, augmenting built-in strings
1105 static void __init acpi_osi_setup_late(void)
1107 char *str = osi_setup_string;
1112 if (!strcmp("!Linux", str)) {
1113 acpi_cmdline_osi_linux(0); /* !enable */
1114 } else if (*str == '!') {
1115 if (acpi_remove_interface(++str) == AE_OK)
1116 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1117 } else if (!strcmp("Linux", str)) {
1118 acpi_cmdline_osi_linux(1); /* enable */
1120 if (acpi_install_interface(str) == AE_OK)
1121 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1125 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;
1131 strncpy(osi_setup_string, str, OSI_STRING_LENGTH_MAX);
1137 __setup("acpi_osi=", acpi_osi_setup);
1139 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1140 static int __init acpi_serialize_setup(char *str)
1142 printk(KERN_INFO PREFIX "serialize enabled\n");
1144 acpi_gbl_all_methods_serialized = TRUE;
1149 __setup("acpi_serialize", acpi_serialize_setup);
1151 /* Check of resource interference between native drivers and ACPI
1152 * OperationRegions (SystemIO and System Memory only).
1153 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1154 * in arbitrary AML code and can interfere with legacy drivers.
1155 * acpi_enforce_resources= can be set to:
1157 * - strict (default) (2)
1158 * -> further driver trying to access the resources will not load
1160 * -> further driver trying to access the resources will load, but you
1161 * get a system message that something might go wrong...
1164 * -> ACPI Operation Region resources will not be registered
1167 #define ENFORCE_RESOURCES_STRICT 2
1168 #define ENFORCE_RESOURCES_LAX 1
1169 #define ENFORCE_RESOURCES_NO 0
1171 static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1173 static int __init acpi_enforce_resources_setup(char *str)
1175 if (str == NULL || *str == '\0')
1178 if (!strcmp("strict", str))
1179 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1180 else if (!strcmp("lax", str))
1181 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1182 else if (!strcmp("no", str))
1183 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1188 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1190 /* Check for resource conflicts between ACPI OperationRegions and native
1192 int acpi_check_resource_conflict(const struct resource *res)
1194 struct acpi_res_list *res_list_elem;
1195 int ioport = 0, clash = 0;
1197 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1199 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1202 ioport = res->flags & IORESOURCE_IO;
1204 spin_lock(&acpi_res_lock);
1205 list_for_each_entry(res_list_elem, &resource_list_head,
1207 if (ioport && (res_list_elem->resource_type
1208 != ACPI_ADR_SPACE_SYSTEM_IO))
1210 if (!ioport && (res_list_elem->resource_type
1211 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1214 if (res->end < res_list_elem->start
1215 || res_list_elem->end < res->start)
1220 spin_unlock(&acpi_res_lock);
1223 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1224 printk(KERN_WARNING "ACPI: resource %s %pR"
1225 " conflicts with ACPI region %s "
1226 "[%s 0x%zx-0x%zx]\n",
1227 res->name, res, res_list_elem->name,
1228 (res_list_elem->resource_type ==
1229 ACPI_ADR_SPACE_SYSTEM_IO) ? "io" : "mem",
1230 (size_t) res_list_elem->start,
1231 (size_t) res_list_elem->end);
1232 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1233 printk(KERN_NOTICE "ACPI: This conflict may"
1234 " cause random problems and system"
1236 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1237 " for this device, you should use it instead of"
1238 " the native driver\n");
1240 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1245 EXPORT_SYMBOL(acpi_check_resource_conflict);
1247 int acpi_check_region(resource_size_t start, resource_size_t n,
1250 struct resource res = {
1252 .end = start + n - 1,
1254 .flags = IORESOURCE_IO,
1257 return acpi_check_resource_conflict(&res);
1259 EXPORT_SYMBOL(acpi_check_region);
1262 * Let drivers know whether the resource checks are effective
1264 int acpi_resources_are_enforced(void)
1266 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1268 EXPORT_SYMBOL(acpi_resources_are_enforced);
1271 * Acquire a spinlock.
1273 * handle is a pointer to the spinlock_t.
1276 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1278 acpi_cpu_flags flags;
1279 spin_lock_irqsave(lockp, flags);
1284 * Release a spinlock. See above.
1287 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1289 spin_unlock_irqrestore(lockp, flags);
1292 #ifndef ACPI_USE_LOCAL_CACHE
1294 /*******************************************************************************
1296 * FUNCTION: acpi_os_create_cache
1298 * PARAMETERS: name - Ascii name for the cache
1299 * size - Size of each cached object
1300 * depth - Maximum depth of the cache (in objects) <ignored>
1301 * cache - Where the new cache object is returned
1305 * DESCRIPTION: Create a cache object
1307 ******************************************************************************/
1310 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1312 *cache = kmem_cache_create(name, size, 0, 0, NULL);
1319 /*******************************************************************************
1321 * FUNCTION: acpi_os_purge_cache
1323 * PARAMETERS: Cache - Handle to cache object
1327 * DESCRIPTION: Free all objects within the requested cache.
1329 ******************************************************************************/
1331 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1333 kmem_cache_shrink(cache);
1337 /*******************************************************************************
1339 * FUNCTION: acpi_os_delete_cache
1341 * PARAMETERS: Cache - Handle to cache object
1345 * DESCRIPTION: Free all objects within the requested cache and delete the
1348 ******************************************************************************/
1350 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1352 kmem_cache_destroy(cache);
1356 /*******************************************************************************
1358 * FUNCTION: acpi_os_release_object
1360 * PARAMETERS: Cache - Handle to cache object
1361 * Object - The object to be released
1365 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1366 * the object is deleted.
1368 ******************************************************************************/
1370 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1372 kmem_cache_free(cache, object);
1376 static inline int acpi_res_list_add(struct acpi_res_list *res)
1378 struct acpi_res_list *res_list_elem;
1380 list_for_each_entry(res_list_elem, &resource_list_head,
1383 if (res->resource_type == res_list_elem->resource_type &&
1384 res->start == res_list_elem->start &&
1385 res->end == res_list_elem->end) {
1388 * The Region(addr,len) already exist in the list,
1389 * just increase the count
1392 res_list_elem->count++;
1398 list_add(&res->resource_list, &resource_list_head);
1402 static inline void acpi_res_list_del(struct acpi_res_list *res)
1404 struct acpi_res_list *res_list_elem;
1406 list_for_each_entry(res_list_elem, &resource_list_head,
1409 if (res->resource_type == res_list_elem->resource_type &&
1410 res->start == res_list_elem->start &&
1411 res->end == res_list_elem->end) {
1414 * If the res count is decreased to 0,
1415 * remove and free it
1418 if (--res_list_elem->count == 0) {
1419 list_del(&res_list_elem->resource_list);
1420 kfree(res_list_elem);
1428 acpi_os_invalidate_address(
1430 acpi_physical_address address,
1433 struct acpi_res_list res;
1436 case ACPI_ADR_SPACE_SYSTEM_IO:
1437 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1438 /* Only interference checks against SystemIO and SystemMemory
1440 res.start = address;
1441 res.end = address + length - 1;
1442 res.resource_type = space_id;
1443 spin_lock(&acpi_res_lock);
1444 acpi_res_list_del(&res);
1445 spin_unlock(&acpi_res_lock);
1447 case ACPI_ADR_SPACE_PCI_CONFIG:
1448 case ACPI_ADR_SPACE_EC:
1449 case ACPI_ADR_SPACE_SMBUS:
1450 case ACPI_ADR_SPACE_CMOS:
1451 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1452 case ACPI_ADR_SPACE_DATA_TABLE:
1453 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1459 /******************************************************************************
1461 * FUNCTION: acpi_os_validate_address
1463 * PARAMETERS: space_id - ACPI space ID
1464 * address - Physical address
1465 * length - Address length
1467 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1468 * should return AE_AML_ILLEGAL_ADDRESS.
1470 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1471 * the addresses accessed by AML operation regions.
1473 *****************************************************************************/
1476 acpi_os_validate_address (
1478 acpi_physical_address address,
1482 struct acpi_res_list *res;
1484 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1488 case ACPI_ADR_SPACE_SYSTEM_IO:
1489 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1490 /* Only interference checks against SystemIO and SystemMemory
1492 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1495 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1496 strlcpy(res->name, name, 5);
1497 res->start = address;
1498 res->end = address + length - 1;
1499 res->resource_type = space_id;
1500 spin_lock(&acpi_res_lock);
1501 added = acpi_res_list_add(res);
1502 spin_unlock(&acpi_res_lock);
1503 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1504 "name: %s\n", added ? "Added" : "Already exist",
1505 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1506 ? "SystemIO" : "System Memory",
1507 (unsigned long long)res->start,
1508 (unsigned long long)res->end,
1513 case ACPI_ADR_SPACE_PCI_CONFIG:
1514 case ACPI_ADR_SPACE_EC:
1515 case ACPI_ADR_SPACE_SMBUS:
1516 case ACPI_ADR_SPACE_CMOS:
1517 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1518 case ACPI_ADR_SPACE_DATA_TABLE:
1519 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1526 acpi_status __init acpi_os_initialize(void)
1528 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
1529 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
1530 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
1531 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
1536 acpi_status acpi_os_initialize1(void)
1538 kacpid_wq = create_workqueue("kacpid");
1539 kacpi_notify_wq = create_workqueue("kacpi_notify");
1540 kacpi_hotplug_wq = create_workqueue("kacpi_hotplug");
1542 BUG_ON(!kacpi_notify_wq);
1543 BUG_ON(!kacpi_hotplug_wq);
1544 acpi_install_interface_handler(acpi_osi_handler);
1545 acpi_osi_setup_late();
1549 acpi_status acpi_os_terminate(void)
1551 if (acpi_irq_handler) {
1552 acpi_os_remove_interrupt_handler(acpi_irq_irq,
1556 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
1557 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
1558 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
1559 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
1561 destroy_workqueue(kacpid_wq);
1562 destroy_workqueue(kacpi_notify_wq);
1563 destroy_workqueue(kacpi_hotplug_wq);