x86, cpa: no need to check alias for __set_pages_p/__set_pages_np
[linux-2.6/verdex.git] / drivers / acpi / osl.c
blob235a1386888a42fb19c59f6080155a6e774071b3
1 /*
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>
33 #include <linux/mm.h>
34 #include <linux/pci.h>
35 #include <linux/interrupt.h>
36 #include <linux/kmod.h>
37 #include <linux/delay.h>
38 #include <linux/dmi.h>
39 #include <linux/workqueue.h>
40 #include <linux/nmi.h>
41 #include <linux/acpi.h>
42 #include <linux/efi.h>
43 #include <linux/ioport.h>
44 #include <linux/list.h>
45 #include <linux/jiffies.h>
46 #include <linux/semaphore.h>
48 #include <asm/io.h>
49 #include <asm/uaccess.h>
51 #include <acpi/acpi.h>
52 #include <acpi/acpi_bus.h>
53 #include <acpi/processor.h>
55 #define _COMPONENT ACPI_OS_SERVICES
56 ACPI_MODULE_NAME("osl");
57 #define PREFIX "ACPI: "
58 struct acpi_os_dpc {
59 acpi_osd_exec_callback function;
60 void *context;
61 struct work_struct work;
64 #ifdef CONFIG_ACPI_CUSTOM_DSDT
65 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
66 #endif
68 #ifdef ENABLE_DEBUGGER
69 #include <linux/kdb.h>
71 /* stuff for debugger support */
72 int acpi_in_debugger;
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;
84 struct acpi_res_list {
85 resource_size_t start;
86 resource_size_t end;
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;
93 static LIST_HEAD(resource_list_head);
94 static DEFINE_SPINLOCK(acpi_res_lock);
96 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
97 static char osi_additional_string[OSI_STRING_LENGTH_MAX];
100 * "Ode to _OSI(Linux)"
102 * osi_linux -- Control response to BIOS _OSI(Linux) query.
104 * As Linux evolves, the features that it supports change.
105 * So an OSI string such as "Linux" is not specific enough
106 * to be useful across multiple versions of Linux. It
107 * doesn't identify any particular feature, interface,
108 * or even any particular version of Linux...
110 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
111 * to a BIOS _OSI(Linux) query. When
112 * a reference mobile BIOS started using it, its use
113 * started to spread to many vendor platforms.
114 * As it is not supportable, we need to halt that spread.
116 * Today, most BIOS references to _OSI(Linux) are noise --
117 * they have no functional effect and are just dead code
118 * carried over from the reference BIOS.
120 * The next most common case is that _OSI(Linux) harms Linux,
121 * usually by causing the BIOS to follow paths that are
122 * not tested during Windows validation.
124 * Finally, there is a short list of platforms
125 * where OSI(Linux) benefits Linux.
127 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
128 * DMI is used to disable the dmesg warning about OSI(Linux)
129 * on platforms where it is known to have no effect.
130 * But a dmesg warning remains for systems where
131 * we do not know if OSI(Linux) is good or bad for the system.
132 * DMI is also used to enable OSI(Linux) for the machines
133 * that are known to need it.
135 * BIOS writers should NOT query _OSI(Linux) on future systems.
136 * It will be ignored by default, and to get Linux to
137 * not ignore it will require a kernel source update to
138 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
140 #define OSI_LINUX_ENABLE 0
142 static struct osi_linux {
143 unsigned int enable:1;
144 unsigned int dmi:1;
145 unsigned int cmdline:1;
146 unsigned int known:1;
147 } osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0};
149 static void __init acpi_request_region (struct acpi_generic_address *addr,
150 unsigned int length, char *desc)
152 struct resource *res;
154 if (!addr->address || !length)
155 return;
157 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
158 res = request_region(addr->address, length, desc);
159 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
160 res = request_mem_region(addr->address, length, desc);
163 static int __init acpi_reserve_resources(void)
165 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
166 "ACPI PM1a_EVT_BLK");
168 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
169 "ACPI PM1b_EVT_BLK");
171 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
172 "ACPI PM1a_CNT_BLK");
174 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
175 "ACPI PM1b_CNT_BLK");
177 if (acpi_gbl_FADT.pm_timer_length == 4)
178 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
180 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
181 "ACPI PM2_CNT_BLK");
183 /* Length of GPE blocks must be a non-negative multiple of 2 */
185 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
186 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
187 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
189 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
190 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
191 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
193 return 0;
195 device_initcall(acpi_reserve_resources);
197 acpi_status __init acpi_os_initialize(void)
199 return AE_OK;
202 acpi_status acpi_os_initialize1(void)
204 kacpid_wq = create_singlethread_workqueue("kacpid");
205 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
206 BUG_ON(!kacpid_wq);
207 BUG_ON(!kacpi_notify_wq);
208 return AE_OK;
211 acpi_status acpi_os_terminate(void)
213 if (acpi_irq_handler) {
214 acpi_os_remove_interrupt_handler(acpi_irq_irq,
215 acpi_irq_handler);
218 destroy_workqueue(kacpid_wq);
219 destroy_workqueue(kacpi_notify_wq);
221 return AE_OK;
224 void acpi_os_printf(const char *fmt, ...)
226 va_list args;
227 va_start(args, fmt);
228 acpi_os_vprintf(fmt, args);
229 va_end(args);
232 void acpi_os_vprintf(const char *fmt, va_list args)
234 static char buffer[512];
236 vsprintf(buffer, fmt, args);
238 #ifdef ENABLE_DEBUGGER
239 if (acpi_in_debugger) {
240 kdb_printf("%s", buffer);
241 } else {
242 printk("%s", buffer);
244 #else
245 printk("%s", buffer);
246 #endif
249 acpi_physical_address __init acpi_os_get_root_pointer(void)
251 if (efi_enabled) {
252 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
253 return efi.acpi20;
254 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
255 return efi.acpi;
256 else {
257 printk(KERN_ERR PREFIX
258 "System description tables not found\n");
259 return 0;
261 } else {
262 acpi_physical_address pa = 0;
264 acpi_find_root_pointer(&pa);
265 return pa;
269 void __iomem *__init_refok
270 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
272 if (phys > ULONG_MAX) {
273 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
274 return NULL;
276 if (acpi_gbl_permanent_mmap)
278 * ioremap checks to ensure this is in reserved space
280 return ioremap((unsigned long)phys, size);
281 else
282 return __acpi_map_table((unsigned long)phys, size);
284 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
286 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
288 if (acpi_gbl_permanent_mmap) {
289 iounmap(virt);
292 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
294 #ifdef ACPI_FUTURE_USAGE
295 acpi_status
296 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
298 if (!phys || !virt)
299 return AE_BAD_PARAMETER;
301 *phys = virt_to_phys(virt);
303 return AE_OK;
305 #endif
307 #define ACPI_MAX_OVERRIDE_LEN 100
309 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
311 acpi_status
312 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
313 acpi_string * new_val)
315 if (!init_val || !new_val)
316 return AE_BAD_PARAMETER;
318 *new_val = NULL;
319 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
320 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
321 acpi_os_name);
322 *new_val = acpi_os_name;
325 return AE_OK;
328 acpi_status
329 acpi_os_table_override(struct acpi_table_header * existing_table,
330 struct acpi_table_header ** new_table)
332 if (!existing_table || !new_table)
333 return AE_BAD_PARAMETER;
335 *new_table = NULL;
337 #ifdef CONFIG_ACPI_CUSTOM_DSDT
338 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
339 *new_table = (struct acpi_table_header *)AmlCode;
340 #endif
341 if (*new_table != NULL) {
342 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
343 "this is unsafe: tainting kernel\n",
344 existing_table->signature,
345 existing_table->oem_table_id);
346 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
348 return AE_OK;
351 static irqreturn_t acpi_irq(int irq, void *dev_id)
353 u32 handled;
355 handled = (*acpi_irq_handler) (acpi_irq_context);
357 if (handled) {
358 acpi_irq_handled++;
359 return IRQ_HANDLED;
360 } else
361 return IRQ_NONE;
364 acpi_status
365 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
366 void *context)
368 unsigned int irq;
370 acpi_irq_stats_init();
373 * Ignore the GSI from the core, and use the value in our copy of the
374 * FADT. It may not be the same if an interrupt source override exists
375 * for the SCI.
377 gsi = acpi_gbl_FADT.sci_interrupt;
378 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
379 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
380 gsi);
381 return AE_OK;
384 acpi_irq_handler = handler;
385 acpi_irq_context = context;
386 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
387 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
388 return AE_NOT_ACQUIRED;
390 acpi_irq_irq = irq;
392 return AE_OK;
395 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
397 if (irq) {
398 free_irq(irq, acpi_irq);
399 acpi_irq_handler = NULL;
400 acpi_irq_irq = 0;
403 return AE_OK;
407 * Running in interpreter thread context, safe to sleep
410 void acpi_os_sleep(acpi_integer ms)
412 schedule_timeout_interruptible(msecs_to_jiffies(ms));
415 void acpi_os_stall(u32 us)
417 while (us) {
418 u32 delay = 1000;
420 if (delay > us)
421 delay = us;
422 udelay(delay);
423 touch_nmi_watchdog();
424 us -= delay;
429 * Support ACPI 3.0 AML Timer operand
430 * Returns 64-bit free-running, monotonically increasing timer
431 * with 100ns granularity
433 u64 acpi_os_get_timer(void)
435 static u64 t;
437 #ifdef CONFIG_HPET
438 /* TBD: use HPET if available */
439 #endif
441 #ifdef CONFIG_X86_PM_TIMER
442 /* TBD: default to PM timer if HPET was not available */
443 #endif
444 if (!t)
445 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
447 return ++t;
450 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
452 u32 dummy;
454 if (!value)
455 value = &dummy;
457 *value = 0;
458 if (width <= 8) {
459 *(u8 *) value = inb(port);
460 } else if (width <= 16) {
461 *(u16 *) value = inw(port);
462 } else if (width <= 32) {
463 *(u32 *) value = inl(port);
464 } else {
465 BUG();
468 return AE_OK;
471 EXPORT_SYMBOL(acpi_os_read_port);
473 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
475 if (width <= 8) {
476 outb(value, port);
477 } else if (width <= 16) {
478 outw(value, port);
479 } else if (width <= 32) {
480 outl(value, port);
481 } else {
482 BUG();
485 return AE_OK;
488 EXPORT_SYMBOL(acpi_os_write_port);
490 acpi_status
491 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
493 u32 dummy;
494 void __iomem *virt_addr;
496 virt_addr = ioremap(phys_addr, width);
497 if (!value)
498 value = &dummy;
500 switch (width) {
501 case 8:
502 *(u8 *) value = readb(virt_addr);
503 break;
504 case 16:
505 *(u16 *) value = readw(virt_addr);
506 break;
507 case 32:
508 *(u32 *) value = readl(virt_addr);
509 break;
510 default:
511 BUG();
514 iounmap(virt_addr);
516 return AE_OK;
519 acpi_status
520 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
522 void __iomem *virt_addr;
524 virt_addr = ioremap(phys_addr, width);
526 switch (width) {
527 case 8:
528 writeb(value, virt_addr);
529 break;
530 case 16:
531 writew(value, virt_addr);
532 break;
533 case 32:
534 writel(value, virt_addr);
535 break;
536 default:
537 BUG();
540 iounmap(virt_addr);
542 return AE_OK;
545 acpi_status
546 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
547 u32 *value, u32 width)
549 int result, size;
551 if (!value)
552 return AE_BAD_PARAMETER;
554 switch (width) {
555 case 8:
556 size = 1;
557 break;
558 case 16:
559 size = 2;
560 break;
561 case 32:
562 size = 4;
563 break;
564 default:
565 return AE_ERROR;
568 result = raw_pci_read(pci_id->segment, pci_id->bus,
569 PCI_DEVFN(pci_id->device, pci_id->function),
570 reg, size, value);
572 return (result ? AE_ERROR : AE_OK);
575 acpi_status
576 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
577 acpi_integer value, u32 width)
579 int result, size;
581 switch (width) {
582 case 8:
583 size = 1;
584 break;
585 case 16:
586 size = 2;
587 break;
588 case 32:
589 size = 4;
590 break;
591 default:
592 return AE_ERROR;
595 result = raw_pci_write(pci_id->segment, pci_id->bus,
596 PCI_DEVFN(pci_id->device, pci_id->function),
597 reg, size, value);
599 return (result ? AE_ERROR : AE_OK);
602 /* TODO: Change code to take advantage of driver model more */
603 static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
604 acpi_handle chandle, /* current node */
605 struct acpi_pci_id **id,
606 int *is_bridge, u8 * bus_number)
608 acpi_handle handle;
609 struct acpi_pci_id *pci_id = *id;
610 acpi_status status;
611 unsigned long temp;
612 acpi_object_type type;
614 acpi_get_parent(chandle, &handle);
615 if (handle != rhandle) {
616 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
617 bus_number);
619 status = acpi_get_type(handle, &type);
620 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
621 return;
623 status =
624 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
625 &temp);
626 if (ACPI_SUCCESS(status)) {
627 u32 val;
628 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
629 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
631 if (*is_bridge)
632 pci_id->bus = *bus_number;
634 /* any nicer way to get bus number of bridge ? */
635 status =
636 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
638 if (ACPI_SUCCESS(status)
639 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
640 status =
641 acpi_os_read_pci_configuration(pci_id, 0x18,
642 &val, 8);
643 if (!ACPI_SUCCESS(status)) {
644 /* Certainly broken... FIX ME */
645 return;
647 *is_bridge = 1;
648 pci_id->bus = val;
649 status =
650 acpi_os_read_pci_configuration(pci_id, 0x19,
651 &val, 8);
652 if (ACPI_SUCCESS(status)) {
653 *bus_number = val;
655 } else
656 *is_bridge = 0;
661 void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
662 acpi_handle chandle, /* current node */
663 struct acpi_pci_id **id)
665 int is_bridge = 1;
666 u8 bus_number = (*id)->bus;
668 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
671 static void acpi_os_execute_deferred(struct work_struct *work)
673 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
674 if (!dpc) {
675 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
676 return;
679 dpc->function(dpc->context);
680 kfree(dpc);
682 return;
685 /*******************************************************************************
687 * FUNCTION: acpi_os_execute
689 * PARAMETERS: Type - Type of the callback
690 * Function - Function to be executed
691 * Context - Function parameters
693 * RETURN: Status
695 * DESCRIPTION: Depending on type, either queues function for deferred execution or
696 * immediately executes function on a separate thread.
698 ******************************************************************************/
700 acpi_status acpi_os_execute(acpi_execute_type type,
701 acpi_osd_exec_callback function, void *context)
703 acpi_status status = AE_OK;
704 struct acpi_os_dpc *dpc;
705 struct workqueue_struct *queue;
706 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
707 "Scheduling function [%p(%p)] for deferred execution.\n",
708 function, context));
710 if (!function)
711 return AE_BAD_PARAMETER;
714 * Allocate/initialize DPC structure. Note that this memory will be
715 * freed by the callee. The kernel handles the work_struct list in a
716 * way that allows us to also free its memory inside the callee.
717 * Because we may want to schedule several tasks with different
718 * parameters we can't use the approach some kernel code uses of
719 * having a static work_struct.
722 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
723 if (!dpc)
724 return_ACPI_STATUS(AE_NO_MEMORY);
726 dpc->function = function;
727 dpc->context = context;
729 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
730 queue = (type == OSL_NOTIFY_HANDLER) ? kacpi_notify_wq : kacpid_wq;
731 if (!queue_work(queue, &dpc->work)) {
732 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
733 "Call to queue_work() failed.\n"));
734 status = AE_ERROR;
735 kfree(dpc);
737 return_ACPI_STATUS(status);
740 EXPORT_SYMBOL(acpi_os_execute);
742 void acpi_os_wait_events_complete(void *context)
744 flush_workqueue(kacpid_wq);
745 flush_workqueue(kacpi_notify_wq);
748 EXPORT_SYMBOL(acpi_os_wait_events_complete);
751 * Allocate the memory for a spinlock and initialize it.
753 acpi_status acpi_os_create_lock(acpi_spinlock * handle)
755 spin_lock_init(*handle);
757 return AE_OK;
761 * Deallocate the memory for a spinlock.
763 void acpi_os_delete_lock(acpi_spinlock handle)
765 return;
768 acpi_status
769 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
771 struct semaphore *sem = NULL;
773 sem = acpi_os_allocate(sizeof(struct semaphore));
774 if (!sem)
775 return AE_NO_MEMORY;
776 memset(sem, 0, sizeof(struct semaphore));
778 sema_init(sem, initial_units);
780 *handle = (acpi_handle *) sem;
782 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
783 *handle, initial_units));
785 return AE_OK;
789 * TODO: A better way to delete semaphores? Linux doesn't have a
790 * 'delete_semaphore()' function -- may result in an invalid
791 * pointer dereference for non-synchronized consumers. Should
792 * we at least check for blocked threads and signal/cancel them?
795 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
797 struct semaphore *sem = (struct semaphore *)handle;
799 if (!sem)
800 return AE_BAD_PARAMETER;
802 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
804 BUG_ON(!list_empty(&sem->wait_list));
805 kfree(sem);
806 sem = NULL;
808 return AE_OK;
812 * TODO: Support for units > 1?
814 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
816 acpi_status status = AE_OK;
817 struct semaphore *sem = (struct semaphore *)handle;
818 long jiffies;
819 int ret = 0;
821 if (!sem || (units < 1))
822 return AE_BAD_PARAMETER;
824 if (units > 1)
825 return AE_SUPPORT;
827 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
828 handle, units, timeout));
830 if (timeout == ACPI_WAIT_FOREVER)
831 jiffies = MAX_SCHEDULE_TIMEOUT;
832 else
833 jiffies = msecs_to_jiffies(timeout);
835 ret = down_timeout(sem, jiffies);
836 if (ret)
837 status = AE_TIME;
839 if (ACPI_FAILURE(status)) {
840 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
841 "Failed to acquire semaphore[%p|%d|%d], %s",
842 handle, units, timeout,
843 acpi_format_exception(status)));
844 } else {
845 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
846 "Acquired semaphore[%p|%d|%d]", handle,
847 units, timeout));
850 return status;
854 * TODO: Support for units > 1?
856 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
858 struct semaphore *sem = (struct semaphore *)handle;
860 if (!sem || (units < 1))
861 return AE_BAD_PARAMETER;
863 if (units > 1)
864 return AE_SUPPORT;
866 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
867 units));
869 up(sem);
871 return AE_OK;
874 #ifdef ACPI_FUTURE_USAGE
875 u32 acpi_os_get_line(char *buffer)
878 #ifdef ENABLE_DEBUGGER
879 if (acpi_in_debugger) {
880 u32 chars;
882 kdb_read(buffer, sizeof(line_buf));
884 /* remove the CR kdb includes */
885 chars = strlen(buffer) - 1;
886 buffer[chars] = '\0';
888 #endif
890 return 0;
892 #endif /* ACPI_FUTURE_USAGE */
894 acpi_status acpi_os_signal(u32 function, void *info)
896 switch (function) {
897 case ACPI_SIGNAL_FATAL:
898 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
899 break;
900 case ACPI_SIGNAL_BREAKPOINT:
902 * AML Breakpoint
903 * ACPI spec. says to treat it as a NOP unless
904 * you are debugging. So if/when we integrate
905 * AML debugger into the kernel debugger its
906 * hook will go here. But until then it is
907 * not useful to print anything on breakpoints.
909 break;
910 default:
911 break;
914 return AE_OK;
917 static int __init acpi_os_name_setup(char *str)
919 char *p = acpi_os_name;
920 int count = ACPI_MAX_OVERRIDE_LEN - 1;
922 if (!str || !*str)
923 return 0;
925 for (; count-- && str && *str; str++) {
926 if (isalnum(*str) || *str == ' ' || *str == ':')
927 *p++ = *str;
928 else if (*str == '\'' || *str == '"')
929 continue;
930 else
931 break;
933 *p = 0;
935 return 1;
939 __setup("acpi_os_name=", acpi_os_name_setup);
941 static void __init set_osi_linux(unsigned int enable)
943 if (osi_linux.enable != enable) {
944 osi_linux.enable = enable;
945 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
946 enable ? "Add": "Delet");
948 return;
951 static void __init acpi_cmdline_osi_linux(unsigned int enable)
953 osi_linux.cmdline = 1; /* cmdline set the default */
954 set_osi_linux(enable);
956 return;
959 void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
961 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
963 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
965 if (enable == -1)
966 return;
968 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
970 set_osi_linux(enable);
972 return;
976 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
978 * empty string disables _OSI
979 * string starting with '!' disables that string
980 * otherwise string is added to list, augmenting built-in strings
982 int __init acpi_osi_setup(char *str)
984 if (str == NULL || *str == '\0') {
985 printk(KERN_INFO PREFIX "_OSI method disabled\n");
986 acpi_gbl_create_osi_method = FALSE;
987 } else if (!strcmp("!Linux", str)) {
988 acpi_cmdline_osi_linux(0); /* !enable */
989 } else if (*str == '!') {
990 if (acpi_osi_invalidate(++str) == AE_OK)
991 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
992 } else if (!strcmp("Linux", str)) {
993 acpi_cmdline_osi_linux(1); /* enable */
994 } else if (*osi_additional_string == '\0') {
995 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
996 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
999 return 1;
1002 __setup("acpi_osi=", acpi_osi_setup);
1004 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1005 static int __init acpi_serialize_setup(char *str)
1007 printk(KERN_INFO PREFIX "serialize enabled\n");
1009 acpi_gbl_all_methods_serialized = TRUE;
1011 return 1;
1014 __setup("acpi_serialize", acpi_serialize_setup);
1017 * Wake and Run-Time GPES are expected to be separate.
1018 * We disable wake-GPEs at run-time to prevent spurious
1019 * interrupts.
1021 * However, if a system exists that shares Wake and
1022 * Run-time events on the same GPE this flag is available
1023 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1025 static int __init acpi_wake_gpes_always_on_setup(char *str)
1027 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1029 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1031 return 1;
1034 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1036 /* Check of resource interference between native drivers and ACPI
1037 * OperationRegions (SystemIO and System Memory only).
1038 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1039 * in arbitrary AML code and can interfere with legacy drivers.
1040 * acpi_enforce_resources= can be set to:
1042 * - strict (2)
1043 * -> further driver trying to access the resources will not load
1044 * - lax (default) (1)
1045 * -> further driver trying to access the resources will load, but you
1046 * get a system message that something might go wrong...
1048 * - no (0)
1049 * -> ACPI Operation Region resources will not be registered
1052 #define ENFORCE_RESOURCES_STRICT 2
1053 #define ENFORCE_RESOURCES_LAX 1
1054 #define ENFORCE_RESOURCES_NO 0
1056 static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1058 static int __init acpi_enforce_resources_setup(char *str)
1060 if (str == NULL || *str == '\0')
1061 return 0;
1063 if (!strcmp("strict", str))
1064 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1065 else if (!strcmp("lax", str))
1066 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1067 else if (!strcmp("no", str))
1068 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1070 return 1;
1073 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1075 /* Check for resource conflicts between ACPI OperationRegions and native
1076 * drivers */
1077 int acpi_check_resource_conflict(struct resource *res)
1079 struct acpi_res_list *res_list_elem;
1080 int ioport;
1081 int clash = 0;
1083 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1084 return 0;
1085 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1086 return 0;
1088 ioport = res->flags & IORESOURCE_IO;
1090 spin_lock(&acpi_res_lock);
1091 list_for_each_entry(res_list_elem, &resource_list_head,
1092 resource_list) {
1093 if (ioport && (res_list_elem->resource_type
1094 != ACPI_ADR_SPACE_SYSTEM_IO))
1095 continue;
1096 if (!ioport && (res_list_elem->resource_type
1097 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1098 continue;
1100 if (res->end < res_list_elem->start
1101 || res_list_elem->end < res->start)
1102 continue;
1103 clash = 1;
1104 break;
1106 spin_unlock(&acpi_res_lock);
1108 if (clash) {
1109 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1110 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
1111 " conflicts with ACPI region %s"
1112 " [0x%llx-0x%llx]\n",
1113 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1114 ? KERN_WARNING : KERN_ERR,
1115 ioport ? "I/O" : "Memory", res->name,
1116 (long long) res->start, (long long) res->end,
1117 res_list_elem->name,
1118 (long long) res_list_elem->start,
1119 (long long) res_list_elem->end);
1120 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1122 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1123 return -EBUSY;
1125 return 0;
1127 EXPORT_SYMBOL(acpi_check_resource_conflict);
1129 int acpi_check_region(resource_size_t start, resource_size_t n,
1130 const char *name)
1132 struct resource res = {
1133 .start = start,
1134 .end = start + n - 1,
1135 .name = name,
1136 .flags = IORESOURCE_IO,
1139 return acpi_check_resource_conflict(&res);
1141 EXPORT_SYMBOL(acpi_check_region);
1143 int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1144 const char *name)
1146 struct resource res = {
1147 .start = start,
1148 .end = start + n - 1,
1149 .name = name,
1150 .flags = IORESOURCE_MEM,
1153 return acpi_check_resource_conflict(&res);
1156 EXPORT_SYMBOL(acpi_check_mem_region);
1159 * Acquire a spinlock.
1161 * handle is a pointer to the spinlock_t.
1164 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1166 acpi_cpu_flags flags;
1167 spin_lock_irqsave(lockp, flags);
1168 return flags;
1172 * Release a spinlock. See above.
1175 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1177 spin_unlock_irqrestore(lockp, flags);
1180 #ifndef ACPI_USE_LOCAL_CACHE
1182 /*******************************************************************************
1184 * FUNCTION: acpi_os_create_cache
1186 * PARAMETERS: name - Ascii name for the cache
1187 * size - Size of each cached object
1188 * depth - Maximum depth of the cache (in objects) <ignored>
1189 * cache - Where the new cache object is returned
1191 * RETURN: status
1193 * DESCRIPTION: Create a cache object
1195 ******************************************************************************/
1197 acpi_status
1198 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1200 *cache = kmem_cache_create(name, size, 0, 0, NULL);
1201 if (*cache == NULL)
1202 return AE_ERROR;
1203 else
1204 return AE_OK;
1207 /*******************************************************************************
1209 * FUNCTION: acpi_os_purge_cache
1211 * PARAMETERS: Cache - Handle to cache object
1213 * RETURN: Status
1215 * DESCRIPTION: Free all objects within the requested cache.
1217 ******************************************************************************/
1219 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1221 kmem_cache_shrink(cache);
1222 return (AE_OK);
1225 /*******************************************************************************
1227 * FUNCTION: acpi_os_delete_cache
1229 * PARAMETERS: Cache - Handle to cache object
1231 * RETURN: Status
1233 * DESCRIPTION: Free all objects within the requested cache and delete the
1234 * cache object.
1236 ******************************************************************************/
1238 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1240 kmem_cache_destroy(cache);
1241 return (AE_OK);
1244 /*******************************************************************************
1246 * FUNCTION: acpi_os_release_object
1248 * PARAMETERS: Cache - Handle to cache object
1249 * Object - The object to be released
1251 * RETURN: None
1253 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1254 * the object is deleted.
1256 ******************************************************************************/
1258 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1260 kmem_cache_free(cache, object);
1261 return (AE_OK);
1265 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1267 * Returns 0 on success
1269 static int acpi_dmi_dump(void)
1272 if (!dmi_available)
1273 return -1;
1275 printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
1276 dmi_get_system_info(DMI_SYS_VENDOR));
1277 printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
1278 dmi_get_system_info(DMI_PRODUCT_NAME));
1279 printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
1280 dmi_get_system_info(DMI_PRODUCT_VERSION));
1281 printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
1282 dmi_get_system_info(DMI_BOARD_NAME));
1283 printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
1284 dmi_get_system_info(DMI_BIOS_VENDOR));
1285 printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
1286 dmi_get_system_info(DMI_BIOS_DATE));
1288 return 0;
1292 /******************************************************************************
1294 * FUNCTION: acpi_os_validate_interface
1296 * PARAMETERS: interface - Requested interface to be validated
1298 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1300 * DESCRIPTION: Match an interface string to the interfaces supported by the
1301 * host. Strings originate from an AML call to the _OSI method.
1303 *****************************************************************************/
1305 acpi_status
1306 acpi_os_validate_interface (char *interface)
1308 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1309 return AE_OK;
1310 if (!strcmp("Linux", interface)) {
1312 printk(KERN_NOTICE PREFIX
1313 "BIOS _OSI(Linux) query %s%s\n",
1314 osi_linux.enable ? "honored" : "ignored",
1315 osi_linux.cmdline ? " via cmdline" :
1316 osi_linux.dmi ? " via DMI" : "");
1318 if (!osi_linux.dmi) {
1319 if (acpi_dmi_dump())
1320 printk(KERN_NOTICE PREFIX
1321 "[please extract dmidecode output]\n");
1322 printk(KERN_NOTICE PREFIX
1323 "Please send DMI info above to "
1324 "linux-acpi@vger.kernel.org\n");
1326 if (!osi_linux.known && !osi_linux.cmdline) {
1327 printk(KERN_NOTICE PREFIX
1328 "If \"acpi_osi=%sLinux\" works better, "
1329 "please notify linux-acpi@vger.kernel.org\n",
1330 osi_linux.enable ? "!" : "");
1333 if (osi_linux.enable)
1334 return AE_OK;
1336 return AE_SUPPORT;
1339 /******************************************************************************
1341 * FUNCTION: acpi_os_validate_address
1343 * PARAMETERS: space_id - ACPI space ID
1344 * address - Physical address
1345 * length - Address length
1347 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1348 * should return AE_AML_ILLEGAL_ADDRESS.
1350 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1351 * the addresses accessed by AML operation regions.
1353 *****************************************************************************/
1355 acpi_status
1356 acpi_os_validate_address (
1357 u8 space_id,
1358 acpi_physical_address address,
1359 acpi_size length,
1360 char *name)
1362 struct acpi_res_list *res;
1363 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1364 return AE_OK;
1366 switch (space_id) {
1367 case ACPI_ADR_SPACE_SYSTEM_IO:
1368 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1369 /* Only interference checks against SystemIO and SytemMemory
1370 are needed */
1371 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1372 if (!res)
1373 return AE_OK;
1374 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1375 strlcpy(res->name, name, 5);
1376 res->start = address;
1377 res->end = address + length - 1;
1378 res->resource_type = space_id;
1379 spin_lock(&acpi_res_lock);
1380 list_add(&res->resource_list, &resource_list_head);
1381 spin_unlock(&acpi_res_lock);
1382 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1383 "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1384 ? "SystemIO" : "System Memory",
1385 (unsigned long long)res->start,
1386 (unsigned long long)res->end,
1387 res->name);
1388 break;
1389 case ACPI_ADR_SPACE_PCI_CONFIG:
1390 case ACPI_ADR_SPACE_EC:
1391 case ACPI_ADR_SPACE_SMBUS:
1392 case ACPI_ADR_SPACE_CMOS:
1393 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1394 case ACPI_ADR_SPACE_DATA_TABLE:
1395 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1396 break;
1398 return AE_OK;
1401 #endif