ACPI: extend "acpi_osi=" boot option
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / osl.c
blobf4760cfa61e18dd63a0128ea39ec7b68607409d1
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>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
31 #include <linux/mm.h>
32 #include <linux/pci.h>
33 #include <linux/interrupt.h>
34 #include <linux/kmod.h>
35 #include <linux/delay.h>
36 #include <linux/workqueue.h>
37 #include <linux/nmi.h>
38 #include <linux/acpi.h>
39 #include <acpi/acpi.h>
40 #include <asm/io.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/processor.h>
43 #include <asm/uaccess.h>
45 #include <linux/efi.h>
47 #define _COMPONENT ACPI_OS_SERVICES
48 ACPI_MODULE_NAME("osl");
49 #define PREFIX "ACPI: "
50 struct acpi_os_dpc {
51 acpi_osd_exec_callback function;
52 void *context;
53 struct work_struct work;
56 #ifdef CONFIG_ACPI_CUSTOM_DSDT
57 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
58 #endif
60 #ifdef ENABLE_DEBUGGER
61 #include <linux/kdb.h>
63 /* stuff for debugger support */
64 int acpi_in_debugger;
65 EXPORT_SYMBOL(acpi_in_debugger);
67 extern char line_buf[80];
68 #endif /*ENABLE_DEBUGGER */
70 static unsigned int acpi_irq_irq;
71 static acpi_osd_handler acpi_irq_handler;
72 static void *acpi_irq_context;
73 static struct workqueue_struct *kacpid_wq;
74 static struct workqueue_struct *kacpi_notify_wq;
76 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
77 static char osi_additional_string[OSI_STRING_LENGTH_MAX];
79 static void __init acpi_request_region (struct acpi_generic_address *addr,
80 unsigned int length, char *desc)
82 struct resource *res;
84 if (!addr->address || !length)
85 return;
87 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
88 res = request_region(addr->address, length, desc);
89 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
90 res = request_mem_region(addr->address, length, desc);
93 static int __init acpi_reserve_resources(void)
95 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
96 "ACPI PM1a_EVT_BLK");
98 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
99 "ACPI PM1b_EVT_BLK");
101 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
102 "ACPI PM1a_CNT_BLK");
104 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
105 "ACPI PM1b_CNT_BLK");
107 if (acpi_gbl_FADT.pm_timer_length == 4)
108 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
110 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
111 "ACPI PM2_CNT_BLK");
113 /* Length of GPE blocks must be a non-negative multiple of 2 */
115 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
116 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
117 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
119 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
120 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
121 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
123 return 0;
125 device_initcall(acpi_reserve_resources);
127 acpi_status acpi_os_initialize(void)
129 return AE_OK;
132 acpi_status acpi_os_initialize1(void)
135 * Initialize PCI configuration space access, as we'll need to access
136 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
138 if (!raw_pci_ops) {
139 printk(KERN_ERR PREFIX
140 "Access to PCI configuration space unavailable\n");
141 return AE_NULL_ENTRY;
143 kacpid_wq = create_singlethread_workqueue("kacpid");
144 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
145 BUG_ON(!kacpid_wq);
146 BUG_ON(!kacpi_notify_wq);
147 return AE_OK;
150 acpi_status acpi_os_terminate(void)
152 if (acpi_irq_handler) {
153 acpi_os_remove_interrupt_handler(acpi_irq_irq,
154 acpi_irq_handler);
157 destroy_workqueue(kacpid_wq);
158 destroy_workqueue(kacpi_notify_wq);
160 return AE_OK;
163 void acpi_os_printf(const char *fmt, ...)
165 va_list args;
166 va_start(args, fmt);
167 acpi_os_vprintf(fmt, args);
168 va_end(args);
171 EXPORT_SYMBOL(acpi_os_printf);
173 void acpi_os_vprintf(const char *fmt, va_list args)
175 static char buffer[512];
177 vsprintf(buffer, fmt, args);
179 #ifdef ENABLE_DEBUGGER
180 if (acpi_in_debugger) {
181 kdb_printf("%s", buffer);
182 } else {
183 printk("%s", buffer);
185 #else
186 printk("%s", buffer);
187 #endif
190 acpi_physical_address __init acpi_os_get_root_pointer(void)
192 if (efi_enabled) {
193 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
194 return efi.acpi20;
195 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
196 return efi.acpi;
197 else {
198 printk(KERN_ERR PREFIX
199 "System description tables not found\n");
200 return 0;
202 } else
203 return acpi_find_rsdp();
206 void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
208 if (phys > ULONG_MAX) {
209 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
210 return NULL;
212 if (acpi_gbl_permanent_mmap)
214 * ioremap checks to ensure this is in reserved space
216 return ioremap((unsigned long)phys, size);
217 else
218 return __acpi_map_table((unsigned long)phys, size);
220 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
222 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
224 if (acpi_gbl_permanent_mmap) {
225 iounmap(virt);
228 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
230 #ifdef ACPI_FUTURE_USAGE
231 acpi_status
232 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
234 if (!phys || !virt)
235 return AE_BAD_PARAMETER;
237 *phys = virt_to_phys(virt);
239 return AE_OK;
241 #endif
243 #define ACPI_MAX_OVERRIDE_LEN 100
245 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
247 acpi_status
248 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
249 acpi_string * new_val)
251 if (!init_val || !new_val)
252 return AE_BAD_PARAMETER;
254 *new_val = NULL;
255 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
256 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
257 acpi_os_name);
258 *new_val = acpi_os_name;
261 return AE_OK;
264 acpi_status
265 acpi_os_table_override(struct acpi_table_header * existing_table,
266 struct acpi_table_header ** new_table)
268 if (!existing_table || !new_table)
269 return AE_BAD_PARAMETER;
271 #ifdef CONFIG_ACPI_CUSTOM_DSDT
272 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
273 *new_table = (struct acpi_table_header *)AmlCode;
274 else
275 *new_table = NULL;
276 #else
277 *new_table = NULL;
278 #endif
279 return AE_OK;
282 static irqreturn_t acpi_irq(int irq, void *dev_id)
284 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
287 acpi_status
288 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
289 void *context)
291 unsigned int irq;
294 * Ignore the GSI from the core, and use the value in our copy of the
295 * FADT. It may not be the same if an interrupt source override exists
296 * for the SCI.
298 gsi = acpi_gbl_FADT.sci_interrupt;
299 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
300 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
301 gsi);
302 return AE_OK;
305 acpi_irq_handler = handler;
306 acpi_irq_context = context;
307 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
308 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
309 return AE_NOT_ACQUIRED;
311 acpi_irq_irq = irq;
313 return AE_OK;
316 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
318 if (irq) {
319 free_irq(irq, acpi_irq);
320 acpi_irq_handler = NULL;
321 acpi_irq_irq = 0;
324 return AE_OK;
328 * Running in interpreter thread context, safe to sleep
331 void acpi_os_sleep(acpi_integer ms)
333 schedule_timeout_interruptible(msecs_to_jiffies(ms));
336 EXPORT_SYMBOL(acpi_os_sleep);
338 void acpi_os_stall(u32 us)
340 while (us) {
341 u32 delay = 1000;
343 if (delay > us)
344 delay = us;
345 udelay(delay);
346 touch_nmi_watchdog();
347 us -= delay;
351 EXPORT_SYMBOL(acpi_os_stall);
354 * Support ACPI 3.0 AML Timer operand
355 * Returns 64-bit free-running, monotonically increasing timer
356 * with 100ns granularity
358 u64 acpi_os_get_timer(void)
360 static u64 t;
362 #ifdef CONFIG_HPET
363 /* TBD: use HPET if available */
364 #endif
366 #ifdef CONFIG_X86_PM_TIMER
367 /* TBD: default to PM timer if HPET was not available */
368 #endif
369 if (!t)
370 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
372 return ++t;
375 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
377 u32 dummy;
379 if (!value)
380 value = &dummy;
382 switch (width) {
383 case 8:
384 *(u8 *) value = inb(port);
385 break;
386 case 16:
387 *(u16 *) value = inw(port);
388 break;
389 case 32:
390 *(u32 *) value = inl(port);
391 break;
392 default:
393 BUG();
396 return AE_OK;
399 EXPORT_SYMBOL(acpi_os_read_port);
401 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
403 switch (width) {
404 case 8:
405 outb(value, port);
406 break;
407 case 16:
408 outw(value, port);
409 break;
410 case 32:
411 outl(value, port);
412 break;
413 default:
414 BUG();
417 return AE_OK;
420 EXPORT_SYMBOL(acpi_os_write_port);
422 acpi_status
423 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
425 u32 dummy;
426 void __iomem *virt_addr;
428 virt_addr = ioremap(phys_addr, width);
429 if (!value)
430 value = &dummy;
432 switch (width) {
433 case 8:
434 *(u8 *) value = readb(virt_addr);
435 break;
436 case 16:
437 *(u16 *) value = readw(virt_addr);
438 break;
439 case 32:
440 *(u32 *) value = readl(virt_addr);
441 break;
442 default:
443 BUG();
446 iounmap(virt_addr);
448 return AE_OK;
451 acpi_status
452 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
454 void __iomem *virt_addr;
456 virt_addr = ioremap(phys_addr, width);
458 switch (width) {
459 case 8:
460 writeb(value, virt_addr);
461 break;
462 case 16:
463 writew(value, virt_addr);
464 break;
465 case 32:
466 writel(value, virt_addr);
467 break;
468 default:
469 BUG();
472 iounmap(virt_addr);
474 return AE_OK;
477 acpi_status
478 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
479 void *value, u32 width)
481 int result, size;
483 if (!value)
484 return AE_BAD_PARAMETER;
486 switch (width) {
487 case 8:
488 size = 1;
489 break;
490 case 16:
491 size = 2;
492 break;
493 case 32:
494 size = 4;
495 break;
496 default:
497 return AE_ERROR;
500 BUG_ON(!raw_pci_ops);
502 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
503 PCI_DEVFN(pci_id->device, pci_id->function),
504 reg, size, value);
506 return (result ? AE_ERROR : AE_OK);
509 EXPORT_SYMBOL(acpi_os_read_pci_configuration);
511 acpi_status
512 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
513 acpi_integer value, u32 width)
515 int result, size;
517 switch (width) {
518 case 8:
519 size = 1;
520 break;
521 case 16:
522 size = 2;
523 break;
524 case 32:
525 size = 4;
526 break;
527 default:
528 return AE_ERROR;
531 BUG_ON(!raw_pci_ops);
533 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
534 PCI_DEVFN(pci_id->device, pci_id->function),
535 reg, size, value);
537 return (result ? AE_ERROR : AE_OK);
540 /* TODO: Change code to take advantage of driver model more */
541 static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
542 acpi_handle chandle, /* current node */
543 struct acpi_pci_id **id,
544 int *is_bridge, u8 * bus_number)
546 acpi_handle handle;
547 struct acpi_pci_id *pci_id = *id;
548 acpi_status status;
549 unsigned long temp;
550 acpi_object_type type;
551 u8 tu8;
553 acpi_get_parent(chandle, &handle);
554 if (handle != rhandle) {
555 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
556 bus_number);
558 status = acpi_get_type(handle, &type);
559 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
560 return;
562 status =
563 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
564 &temp);
565 if (ACPI_SUCCESS(status)) {
566 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
567 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
569 if (*is_bridge)
570 pci_id->bus = *bus_number;
572 /* any nicer way to get bus number of bridge ? */
573 status =
574 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
576 if (ACPI_SUCCESS(status)
577 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
578 status =
579 acpi_os_read_pci_configuration(pci_id, 0x18,
580 &tu8, 8);
581 if (!ACPI_SUCCESS(status)) {
582 /* Certainly broken... FIX ME */
583 return;
585 *is_bridge = 1;
586 pci_id->bus = tu8;
587 status =
588 acpi_os_read_pci_configuration(pci_id, 0x19,
589 &tu8, 8);
590 if (ACPI_SUCCESS(status)) {
591 *bus_number = tu8;
593 } else
594 *is_bridge = 0;
599 void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
600 acpi_handle chandle, /* current node */
601 struct acpi_pci_id **id)
603 int is_bridge = 1;
604 u8 bus_number = (*id)->bus;
606 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
609 static void acpi_os_execute_deferred(struct work_struct *work)
611 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
612 if (!dpc) {
613 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
614 return;
617 dpc->function(dpc->context);
618 kfree(dpc);
620 /* Yield cpu to notify thread */
621 cond_resched();
623 return;
626 static void acpi_os_execute_notify(struct work_struct *work)
628 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
630 if (!dpc) {
631 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
632 return;
635 dpc->function(dpc->context);
637 kfree(dpc);
639 return;
642 /*******************************************************************************
644 * FUNCTION: acpi_os_execute
646 * PARAMETERS: Type - Type of the callback
647 * Function - Function to be executed
648 * Context - Function parameters
650 * RETURN: Status
652 * DESCRIPTION: Depending on type, either queues function for deferred execution or
653 * immediately executes function on a separate thread.
655 ******************************************************************************/
657 acpi_status acpi_os_execute(acpi_execute_type type,
658 acpi_osd_exec_callback function, void *context)
660 acpi_status status = AE_OK;
661 struct acpi_os_dpc *dpc;
663 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
664 "Scheduling function [%p(%p)] for deferred execution.\n",
665 function, context));
667 if (!function)
668 return AE_BAD_PARAMETER;
671 * Allocate/initialize DPC structure. Note that this memory will be
672 * freed by the callee. The kernel handles the work_struct list in a
673 * way that allows us to also free its memory inside the callee.
674 * Because we may want to schedule several tasks with different
675 * parameters we can't use the approach some kernel code uses of
676 * having a static work_struct.
679 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
680 if (!dpc)
681 return_ACPI_STATUS(AE_NO_MEMORY);
683 dpc->function = function;
684 dpc->context = context;
686 if (type == OSL_NOTIFY_HANDLER) {
687 INIT_WORK(&dpc->work, acpi_os_execute_notify);
688 if (!queue_work(kacpi_notify_wq, &dpc->work)) {
689 status = AE_ERROR;
690 kfree(dpc);
692 } else {
693 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
694 if (!queue_work(kacpid_wq, &dpc->work)) {
695 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
696 "Call to queue_work() failed.\n"));
697 status = AE_ERROR;
698 kfree(dpc);
701 return_ACPI_STATUS(status);
704 EXPORT_SYMBOL(acpi_os_execute);
706 void acpi_os_wait_events_complete(void *context)
708 flush_workqueue(kacpid_wq);
711 EXPORT_SYMBOL(acpi_os_wait_events_complete);
714 * Allocate the memory for a spinlock and initialize it.
716 acpi_status acpi_os_create_lock(acpi_spinlock * handle)
718 spin_lock_init(*handle);
720 return AE_OK;
724 * Deallocate the memory for a spinlock.
726 void acpi_os_delete_lock(acpi_spinlock handle)
728 return;
731 acpi_status
732 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
734 struct semaphore *sem = NULL;
737 sem = acpi_os_allocate(sizeof(struct semaphore));
738 if (!sem)
739 return AE_NO_MEMORY;
740 memset(sem, 0, sizeof(struct semaphore));
742 sema_init(sem, initial_units);
744 *handle = (acpi_handle *) sem;
746 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
747 *handle, initial_units));
749 return AE_OK;
752 EXPORT_SYMBOL(acpi_os_create_semaphore);
755 * TODO: A better way to delete semaphores? Linux doesn't have a
756 * 'delete_semaphore()' function -- may result in an invalid
757 * pointer dereference for non-synchronized consumers. Should
758 * we at least check for blocked threads and signal/cancel them?
761 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
763 struct semaphore *sem = (struct semaphore *)handle;
766 if (!sem)
767 return AE_BAD_PARAMETER;
769 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
771 kfree(sem);
772 sem = NULL;
774 return AE_OK;
777 EXPORT_SYMBOL(acpi_os_delete_semaphore);
780 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
781 * improvise. The process is to sleep for one scheduler quantum
782 * until the semaphore becomes available. Downside is that this
783 * may result in starvation for timeout-based waits when there's
784 * lots of semaphore activity.
786 * TODO: Support for units > 1?
788 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
790 acpi_status status = AE_OK;
791 struct semaphore *sem = (struct semaphore *)handle;
792 int ret = 0;
795 if (!sem || (units < 1))
796 return AE_BAD_PARAMETER;
798 if (units > 1)
799 return AE_SUPPORT;
801 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
802 handle, units, timeout));
805 * This can be called during resume with interrupts off.
806 * Like boot-time, we should be single threaded and will
807 * always get the lock if we try -- timeout or not.
808 * If this doesn't succeed, then we will oops courtesy of
809 * might_sleep() in down().
811 if (!down_trylock(sem))
812 return AE_OK;
814 switch (timeout) {
816 * No Wait:
817 * --------
818 * A zero timeout value indicates that we shouldn't wait - just
819 * acquire the semaphore if available otherwise return AE_TIME
820 * (a.k.a. 'would block').
822 case 0:
823 if (down_trylock(sem))
824 status = AE_TIME;
825 break;
828 * Wait Indefinitely:
829 * ------------------
831 case ACPI_WAIT_FOREVER:
832 down(sem);
833 break;
836 * Wait w/ Timeout:
837 * ----------------
839 default:
840 // TODO: A better timeout algorithm?
842 int i = 0;
843 static const int quantum_ms = 1000 / HZ;
845 ret = down_trylock(sem);
846 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
847 schedule_timeout_interruptible(1);
848 ret = down_trylock(sem);
851 if (ret != 0)
852 status = AE_TIME;
854 break;
857 if (ACPI_FAILURE(status)) {
858 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
859 "Failed to acquire semaphore[%p|%d|%d], %s",
860 handle, units, timeout,
861 acpi_format_exception(status)));
862 } else {
863 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
864 "Acquired semaphore[%p|%d|%d]", handle,
865 units, timeout));
868 return status;
871 EXPORT_SYMBOL(acpi_os_wait_semaphore);
874 * TODO: Support for units > 1?
876 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
878 struct semaphore *sem = (struct semaphore *)handle;
881 if (!sem || (units < 1))
882 return AE_BAD_PARAMETER;
884 if (units > 1)
885 return AE_SUPPORT;
887 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
888 units));
890 up(sem);
892 return AE_OK;
895 EXPORT_SYMBOL(acpi_os_signal_semaphore);
897 #ifdef ACPI_FUTURE_USAGE
898 u32 acpi_os_get_line(char *buffer)
901 #ifdef ENABLE_DEBUGGER
902 if (acpi_in_debugger) {
903 u32 chars;
905 kdb_read(buffer, sizeof(line_buf));
907 /* remove the CR kdb includes */
908 chars = strlen(buffer) - 1;
909 buffer[chars] = '\0';
911 #endif
913 return 0;
915 #endif /* ACPI_FUTURE_USAGE */
917 acpi_status acpi_os_signal(u32 function, void *info)
919 switch (function) {
920 case ACPI_SIGNAL_FATAL:
921 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
922 break;
923 case ACPI_SIGNAL_BREAKPOINT:
925 * AML Breakpoint
926 * ACPI spec. says to treat it as a NOP unless
927 * you are debugging. So if/when we integrate
928 * AML debugger into the kernel debugger its
929 * hook will go here. But until then it is
930 * not useful to print anything on breakpoints.
932 break;
933 default:
934 break;
937 return AE_OK;
940 EXPORT_SYMBOL(acpi_os_signal);
942 static int __init acpi_os_name_setup(char *str)
944 char *p = acpi_os_name;
945 int count = ACPI_MAX_OVERRIDE_LEN - 1;
947 if (!str || !*str)
948 return 0;
950 for (; count-- && str && *str; str++) {
951 if (isalnum(*str) || *str == ' ' || *str == ':')
952 *p++ = *str;
953 else if (*str == '\'' || *str == '"')
954 continue;
955 else
956 break;
958 *p = 0;
960 return 1;
964 __setup("acpi_os_name=", acpi_os_name_setup);
967 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
969 * empty string disables _OSI
970 * string starting with '!' disables that string
971 * otherwise string is added to list, augmenting built-in strings
973 static int __init acpi_osi_setup(char *str)
975 if (str == NULL || *str == '\0') {
976 printk(KERN_INFO PREFIX "_OSI method disabled\n");
977 acpi_gbl_create_osi_method = FALSE;
978 } else if (*str == '!') {
979 if (acpi_osi_invalidate(++str) == AE_OK)
980 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
981 } else if (*osi_additional_string == '\0') {
982 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
983 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
986 return 1;
989 __setup("acpi_osi=", acpi_osi_setup);
991 /* enable serialization to combat AE_ALREADY_EXISTS errors */
992 static int __init acpi_serialize_setup(char *str)
994 printk(KERN_INFO PREFIX "serialize enabled\n");
996 acpi_gbl_all_methods_serialized = TRUE;
998 return 1;
1001 __setup("acpi_serialize", acpi_serialize_setup);
1004 * Wake and Run-Time GPES are expected to be separate.
1005 * We disable wake-GPEs at run-time to prevent spurious
1006 * interrupts.
1008 * However, if a system exists that shares Wake and
1009 * Run-time events on the same GPE this flag is available
1010 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1012 static int __init acpi_wake_gpes_always_on_setup(char *str)
1014 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1016 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1018 return 1;
1021 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1024 * max_cstate is defined in the base kernel so modules can
1025 * change it w/o depending on the state of the processor module.
1027 unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1029 EXPORT_SYMBOL(max_cstate);
1032 * Acquire a spinlock.
1034 * handle is a pointer to the spinlock_t.
1037 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1039 acpi_cpu_flags flags;
1040 spin_lock_irqsave(lockp, flags);
1041 return flags;
1045 * Release a spinlock. See above.
1048 void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1050 spin_unlock_irqrestore(lockp, flags);
1053 #ifndef ACPI_USE_LOCAL_CACHE
1055 /*******************************************************************************
1057 * FUNCTION: acpi_os_create_cache
1059 * PARAMETERS: name - Ascii name for the cache
1060 * size - Size of each cached object
1061 * depth - Maximum depth of the cache (in objects) <ignored>
1062 * cache - Where the new cache object is returned
1064 * RETURN: status
1066 * DESCRIPTION: Create a cache object
1068 ******************************************************************************/
1070 acpi_status
1071 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1073 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
1074 if (*cache == NULL)
1075 return AE_ERROR;
1076 else
1077 return AE_OK;
1080 /*******************************************************************************
1082 * FUNCTION: acpi_os_purge_cache
1084 * PARAMETERS: Cache - Handle to cache object
1086 * RETURN: Status
1088 * DESCRIPTION: Free all objects within the requested cache.
1090 ******************************************************************************/
1092 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1094 kmem_cache_shrink(cache);
1095 return (AE_OK);
1098 /*******************************************************************************
1100 * FUNCTION: acpi_os_delete_cache
1102 * PARAMETERS: Cache - Handle to cache object
1104 * RETURN: Status
1106 * DESCRIPTION: Free all objects within the requested cache and delete the
1107 * cache object.
1109 ******************************************************************************/
1111 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1113 kmem_cache_destroy(cache);
1114 return (AE_OK);
1117 /*******************************************************************************
1119 * FUNCTION: acpi_os_release_object
1121 * PARAMETERS: Cache - Handle to cache object
1122 * Object - The object to be released
1124 * RETURN: None
1126 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1127 * the object is deleted.
1129 ******************************************************************************/
1131 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1133 kmem_cache_free(cache, object);
1134 return (AE_OK);
1137 /******************************************************************************
1139 * FUNCTION: acpi_os_validate_interface
1141 * PARAMETERS: interface - Requested interface to be validated
1143 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1145 * DESCRIPTION: Match an interface string to the interfaces supported by the
1146 * host. Strings originate from an AML call to the _OSI method.
1148 *****************************************************************************/
1150 acpi_status
1151 acpi_os_validate_interface (char *interface)
1153 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1154 return AE_OK;
1155 return AE_SUPPORT;
1158 /******************************************************************************
1160 * FUNCTION: acpi_os_validate_address
1162 * PARAMETERS: space_id - ACPI space ID
1163 * address - Physical address
1164 * length - Address length
1166 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1167 * should return AE_AML_ILLEGAL_ADDRESS.
1169 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1170 * the addresses accessed by AML operation regions.
1172 *****************************************************************************/
1174 acpi_status
1175 acpi_os_validate_address (
1176 u8 space_id,
1177 acpi_physical_address address,
1178 acpi_size length)
1181 return AE_OK;
1185 #endif