[ACPI] ACPICA 20060317
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / osl.c
blob006b31a5655902c9bec6d54d69dae790057a6323
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/config.h>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/mm.h>
33 #include <linux/pci.h>
34 #include <linux/smp_lock.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 <acpi/acpi.h>
41 #include <asm/io.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/processor.h>
44 #include <asm/uaccess.h>
46 #include <linux/efi.h>
48 #define _COMPONENT ACPI_OS_SERVICES
49 ACPI_MODULE_NAME("osl")
50 #define PREFIX "ACPI: "
51 struct acpi_os_dpc {
52 acpi_osd_exec_callback function;
53 void *context;
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 int acpi_specific_hotkey_enabled = TRUE;
71 EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
73 static unsigned int acpi_irq_irq;
74 static acpi_osd_handler acpi_irq_handler;
75 static void *acpi_irq_context;
76 static struct workqueue_struct *kacpid_wq;
78 acpi_status acpi_os_initialize(void)
80 return AE_OK;
83 acpi_status acpi_os_initialize1(void)
86 * Initialize PCI configuration space access, as we'll need to access
87 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
89 if (!raw_pci_ops) {
90 printk(KERN_ERR PREFIX
91 "Access to PCI configuration space unavailable\n");
92 return AE_NULL_ENTRY;
94 kacpid_wq = create_singlethread_workqueue("kacpid");
95 BUG_ON(!kacpid_wq);
97 return AE_OK;
100 acpi_status acpi_os_terminate(void)
102 if (acpi_irq_handler) {
103 acpi_os_remove_interrupt_handler(acpi_irq_irq,
104 acpi_irq_handler);
107 destroy_workqueue(kacpid_wq);
109 return AE_OK;
112 void acpi_os_printf(const char *fmt, ...)
114 va_list args;
115 va_start(args, fmt);
116 acpi_os_vprintf(fmt, args);
117 va_end(args);
120 EXPORT_SYMBOL(acpi_os_printf);
122 void acpi_os_vprintf(const char *fmt, va_list args)
124 static char buffer[512];
126 vsprintf(buffer, fmt, args);
128 #ifdef ENABLE_DEBUGGER
129 if (acpi_in_debugger) {
130 kdb_printf("%s", buffer);
131 } else {
132 printk("%s", buffer);
134 #else
135 printk("%s", buffer);
136 #endif
139 extern int acpi_in_resume;
140 void *acpi_os_allocate(acpi_size size)
142 if (acpi_in_resume)
143 return kmalloc(size, GFP_ATOMIC);
144 else
145 return kmalloc(size, GFP_KERNEL);
148 void acpi_os_free(void *ptr)
150 kfree(ptr);
153 EXPORT_SYMBOL(acpi_os_free);
155 acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
157 if (efi_enabled) {
158 addr->pointer_type = ACPI_PHYSICAL_POINTER;
159 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
160 addr->pointer.physical = efi.acpi20;
161 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
162 addr->pointer.physical = efi.acpi;
163 else {
164 printk(KERN_ERR PREFIX
165 "System description tables not found\n");
166 return AE_NOT_FOUND;
168 } else {
169 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
170 printk(KERN_ERR PREFIX
171 "System description tables not found\n");
172 return AE_NOT_FOUND;
176 return AE_OK;
179 acpi_status
180 acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
181 void __iomem ** virt)
183 if (phys > ULONG_MAX) {
184 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
185 return AE_BAD_PARAMETER;
188 * ioremap checks to ensure this is in reserved space
190 *virt = ioremap((unsigned long)phys, size);
192 if (!*virt)
193 return AE_NO_MEMORY;
195 return AE_OK;
197 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
199 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
201 iounmap(virt);
203 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
205 #ifdef ACPI_FUTURE_USAGE
206 acpi_status
207 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
209 if (!phys || !virt)
210 return AE_BAD_PARAMETER;
212 *phys = virt_to_phys(virt);
214 return AE_OK;
216 #endif
218 #define ACPI_MAX_OVERRIDE_LEN 100
220 static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
222 acpi_status
223 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
224 acpi_string * new_val)
226 if (!init_val || !new_val)
227 return AE_BAD_PARAMETER;
229 *new_val = NULL;
230 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
231 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
232 acpi_os_name);
233 *new_val = acpi_os_name;
236 return AE_OK;
239 acpi_status
240 acpi_os_table_override(struct acpi_table_header * existing_table,
241 struct acpi_table_header ** new_table)
243 if (!existing_table || !new_table)
244 return AE_BAD_PARAMETER;
246 #ifdef CONFIG_ACPI_CUSTOM_DSDT
247 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
248 *new_table = (struct acpi_table_header *)AmlCode;
249 else
250 *new_table = NULL;
251 #else
252 *new_table = NULL;
253 #endif
254 return AE_OK;
257 static irqreturn_t acpi_irq(int irq, void *dev_id, struct pt_regs *regs)
259 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
262 acpi_status
263 acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
264 void *context)
266 unsigned int irq;
269 * Ignore the GSI from the core, and use the value in our copy of the
270 * FADT. It may not be the same if an interrupt source override exists
271 * for the SCI.
273 gsi = acpi_fadt.sci_int;
274 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
275 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
276 gsi);
277 return AE_OK;
280 acpi_irq_handler = handler;
281 acpi_irq_context = context;
282 if (request_irq(irq, acpi_irq, SA_SHIRQ, "acpi", acpi_irq)) {
283 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
284 return AE_NOT_ACQUIRED;
286 acpi_irq_irq = irq;
288 return AE_OK;
291 acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
293 if (irq) {
294 free_irq(irq, acpi_irq);
295 acpi_irq_handler = NULL;
296 acpi_irq_irq = 0;
299 return AE_OK;
303 * Running in interpreter thread context, safe to sleep
306 void acpi_os_sleep(acpi_integer ms)
308 schedule_timeout_interruptible(msecs_to_jiffies(ms));
311 EXPORT_SYMBOL(acpi_os_sleep);
313 void acpi_os_stall(u32 us)
315 while (us) {
316 u32 delay = 1000;
318 if (delay > us)
319 delay = us;
320 udelay(delay);
321 touch_nmi_watchdog();
322 us -= delay;
326 EXPORT_SYMBOL(acpi_os_stall);
329 * Support ACPI 3.0 AML Timer operand
330 * Returns 64-bit free-running, monotonically increasing timer
331 * with 100ns granularity
333 u64 acpi_os_get_timer(void)
335 static u64 t;
337 #ifdef CONFIG_HPET
338 /* TBD: use HPET if available */
339 #endif
341 #ifdef CONFIG_X86_PM_TIMER
342 /* TBD: default to PM timer if HPET was not available */
343 #endif
344 if (!t)
345 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
347 return ++t;
350 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
352 u32 dummy;
354 if (!value)
355 value = &dummy;
357 switch (width) {
358 case 8:
359 *(u8 *) value = inb(port);
360 break;
361 case 16:
362 *(u16 *) value = inw(port);
363 break;
364 case 32:
365 *(u32 *) value = inl(port);
366 break;
367 default:
368 BUG();
371 return AE_OK;
374 EXPORT_SYMBOL(acpi_os_read_port);
376 acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
378 switch (width) {
379 case 8:
380 outb(value, port);
381 break;
382 case 16:
383 outw(value, port);
384 break;
385 case 32:
386 outl(value, port);
387 break;
388 default:
389 BUG();
392 return AE_OK;
395 EXPORT_SYMBOL(acpi_os_write_port);
397 acpi_status
398 acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
400 u32 dummy;
401 void __iomem *virt_addr;
403 virt_addr = ioremap(phys_addr, width);
404 if (!value)
405 value = &dummy;
407 switch (width) {
408 case 8:
409 *(u8 *) value = readb(virt_addr);
410 break;
411 case 16:
412 *(u16 *) value = readw(virt_addr);
413 break;
414 case 32:
415 *(u32 *) value = readl(virt_addr);
416 break;
417 default:
418 BUG();
421 iounmap(virt_addr);
423 return AE_OK;
426 acpi_status
427 acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
429 void __iomem *virt_addr;
431 virt_addr = ioremap(phys_addr, width);
433 switch (width) {
434 case 8:
435 writeb(value, virt_addr);
436 break;
437 case 16:
438 writew(value, virt_addr);
439 break;
440 case 32:
441 writel(value, virt_addr);
442 break;
443 default:
444 BUG();
447 iounmap(virt_addr);
449 return AE_OK;
452 acpi_status
453 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
454 void *value, u32 width)
456 int result, size;
458 if (!value)
459 return AE_BAD_PARAMETER;
461 switch (width) {
462 case 8:
463 size = 1;
464 break;
465 case 16:
466 size = 2;
467 break;
468 case 32:
469 size = 4;
470 break;
471 default:
472 return AE_ERROR;
475 BUG_ON(!raw_pci_ops);
477 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
478 PCI_DEVFN(pci_id->device, pci_id->function),
479 reg, size, value);
481 return (result ? AE_ERROR : AE_OK);
484 EXPORT_SYMBOL(acpi_os_read_pci_configuration);
486 acpi_status
487 acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
488 acpi_integer value, u32 width)
490 int result, size;
492 switch (width) {
493 case 8:
494 size = 1;
495 break;
496 case 16:
497 size = 2;
498 break;
499 case 32:
500 size = 4;
501 break;
502 default:
503 return AE_ERROR;
506 BUG_ON(!raw_pci_ops);
508 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
509 PCI_DEVFN(pci_id->device, pci_id->function),
510 reg, size, value);
512 return (result ? AE_ERROR : AE_OK);
515 /* TODO: Change code to take advantage of driver model more */
516 static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
517 acpi_handle chandle, /* current node */
518 struct acpi_pci_id **id,
519 int *is_bridge, u8 * bus_number)
521 acpi_handle handle;
522 struct acpi_pci_id *pci_id = *id;
523 acpi_status status;
524 unsigned long temp;
525 acpi_object_type type;
526 u8 tu8;
528 acpi_get_parent(chandle, &handle);
529 if (handle != rhandle) {
530 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
531 bus_number);
533 status = acpi_get_type(handle, &type);
534 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
535 return;
537 status =
538 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
539 &temp);
540 if (ACPI_SUCCESS(status)) {
541 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
542 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
544 if (*is_bridge)
545 pci_id->bus = *bus_number;
547 /* any nicer way to get bus number of bridge ? */
548 status =
549 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
551 if (ACPI_SUCCESS(status)
552 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
553 status =
554 acpi_os_read_pci_configuration(pci_id, 0x18,
555 &tu8, 8);
556 if (!ACPI_SUCCESS(status)) {
557 /* Certainly broken... FIX ME */
558 return;
560 *is_bridge = 1;
561 pci_id->bus = tu8;
562 status =
563 acpi_os_read_pci_configuration(pci_id, 0x19,
564 &tu8, 8);
565 if (ACPI_SUCCESS(status)) {
566 *bus_number = tu8;
568 } else
569 *is_bridge = 0;
574 void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
575 acpi_handle chandle, /* current node */
576 struct acpi_pci_id **id)
578 int is_bridge = 1;
579 u8 bus_number = (*id)->bus;
581 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
584 static void acpi_os_execute_deferred(void *context)
586 struct acpi_os_dpc *dpc = NULL;
588 ACPI_FUNCTION_TRACE("os_execute_deferred");
590 dpc = (struct acpi_os_dpc *)context;
591 if (!dpc) {
592 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n"));
593 return_VOID;
596 dpc->function(dpc->context);
598 kfree(dpc);
600 return_VOID;
603 acpi_status
604 acpi_os_queue_for_execution(u32 priority,
605 acpi_osd_exec_callback function, void *context)
607 acpi_status status = AE_OK;
608 struct acpi_os_dpc *dpc;
609 struct work_struct *task;
611 ACPI_FUNCTION_TRACE("os_queue_for_execution");
613 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
614 "Scheduling function [%p(%p)] for deferred execution.\n",
615 function, context));
617 if (!function)
618 return_ACPI_STATUS(AE_BAD_PARAMETER);
621 * Allocate/initialize DPC structure. Note that this memory will be
622 * freed by the callee. The kernel handles the tq_struct list in a
623 * way that allows us to also free its memory inside the callee.
624 * Because we may want to schedule several tasks with different
625 * parameters we can't use the approach some kernel code uses of
626 * having a static tq_struct.
627 * We can save time and code by allocating the DPC and tq_structs
628 * from the same memory.
631 dpc =
632 kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct),
633 GFP_ATOMIC);
634 if (!dpc)
635 return_ACPI_STATUS(AE_NO_MEMORY);
637 dpc->function = function;
638 dpc->context = context;
640 task = (void *)(dpc + 1);
641 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
643 if (!queue_work(kacpid_wq, task)) {
644 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
645 "Call to queue_work() failed.\n"));
646 kfree(dpc);
647 status = AE_ERROR;
650 return_ACPI_STATUS(status);
653 EXPORT_SYMBOL(acpi_os_queue_for_execution);
655 void acpi_os_wait_events_complete(void *context)
657 flush_workqueue(kacpid_wq);
660 EXPORT_SYMBOL(acpi_os_wait_events_complete);
663 * Allocate the memory for a spinlock and initialize it.
665 acpi_status acpi_os_create_lock(acpi_handle * out_handle)
667 spinlock_t *lock_ptr;
669 ACPI_FUNCTION_TRACE("os_create_lock");
671 lock_ptr = acpi_os_allocate(sizeof(spinlock_t));
673 spin_lock_init(lock_ptr);
675 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr));
677 *out_handle = lock_ptr;
679 return_ACPI_STATUS(AE_OK);
683 * Deallocate the memory for a spinlock.
685 void acpi_os_delete_lock(acpi_handle handle)
687 ACPI_FUNCTION_TRACE("os_create_lock");
689 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle));
691 acpi_os_free(handle);
693 return_VOID;
696 acpi_status
697 acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
699 struct semaphore *sem = NULL;
701 ACPI_FUNCTION_TRACE("os_create_semaphore");
703 sem = acpi_os_allocate(sizeof(struct semaphore));
704 if (!sem)
705 return_ACPI_STATUS(AE_NO_MEMORY);
706 memset(sem, 0, sizeof(struct semaphore));
708 sema_init(sem, initial_units);
710 *handle = (acpi_handle *) sem;
712 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
713 *handle, initial_units));
715 return_ACPI_STATUS(AE_OK);
718 EXPORT_SYMBOL(acpi_os_create_semaphore);
721 * TODO: A better way to delete semaphores? Linux doesn't have a
722 * 'delete_semaphore()' function -- may result in an invalid
723 * pointer dereference for non-synchronized consumers. Should
724 * we at least check for blocked threads and signal/cancel them?
727 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
729 struct semaphore *sem = (struct semaphore *)handle;
731 ACPI_FUNCTION_TRACE("os_delete_semaphore");
733 if (!sem)
734 return_ACPI_STATUS(AE_BAD_PARAMETER);
736 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
738 acpi_os_free(sem);
739 sem = NULL;
741 return_ACPI_STATUS(AE_OK);
744 EXPORT_SYMBOL(acpi_os_delete_semaphore);
747 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
748 * improvise. The process is to sleep for one scheduler quantum
749 * until the semaphore becomes available. Downside is that this
750 * may result in starvation for timeout-based waits when there's
751 * lots of semaphore activity.
753 * TODO: Support for units > 1?
755 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
757 acpi_status status = AE_OK;
758 struct semaphore *sem = (struct semaphore *)handle;
759 int ret = 0;
761 ACPI_FUNCTION_TRACE("os_wait_semaphore");
763 if (!sem || (units < 1))
764 return_ACPI_STATUS(AE_BAD_PARAMETER);
766 if (units > 1)
767 return_ACPI_STATUS(AE_SUPPORT);
769 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
770 handle, units, timeout));
772 if (in_atomic())
773 timeout = 0;
775 switch (timeout) {
777 * No Wait:
778 * --------
779 * A zero timeout value indicates that we shouldn't wait - just
780 * acquire the semaphore if available otherwise return AE_TIME
781 * (a.k.a. 'would block').
783 case 0:
784 if (down_trylock(sem))
785 status = AE_TIME;
786 break;
789 * Wait Indefinitely:
790 * ------------------
792 case ACPI_WAIT_FOREVER:
793 down(sem);
794 break;
797 * Wait w/ Timeout:
798 * ----------------
800 default:
801 // TODO: A better timeout algorithm?
803 int i = 0;
804 static const int quantum_ms = 1000 / HZ;
806 ret = down_trylock(sem);
807 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
808 schedule_timeout_interruptible(1);
809 ret = down_trylock(sem);
812 if (ret != 0)
813 status = AE_TIME;
815 break;
818 if (ACPI_FAILURE(status)) {
819 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
820 "Failed to acquire semaphore[%p|%d|%d], %s\n",
821 handle, units, timeout,
822 acpi_format_exception(status)));
823 } else {
824 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
825 "Acquired semaphore[%p|%d|%d]\n", handle,
826 units, timeout));
829 return_ACPI_STATUS(status);
832 EXPORT_SYMBOL(acpi_os_wait_semaphore);
835 * TODO: Support for units > 1?
837 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
839 struct semaphore *sem = (struct semaphore *)handle;
841 ACPI_FUNCTION_TRACE("os_signal_semaphore");
843 if (!sem || (units < 1))
844 return_ACPI_STATUS(AE_BAD_PARAMETER);
846 if (units > 1)
847 return_ACPI_STATUS(AE_SUPPORT);
849 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
850 units));
852 up(sem);
854 return_ACPI_STATUS(AE_OK);
857 EXPORT_SYMBOL(acpi_os_signal_semaphore);
859 #ifdef ACPI_FUTURE_USAGE
860 u32 acpi_os_get_line(char *buffer)
863 #ifdef ENABLE_DEBUGGER
864 if (acpi_in_debugger) {
865 u32 chars;
867 kdb_read(buffer, sizeof(line_buf));
869 /* remove the CR kdb includes */
870 chars = strlen(buffer) - 1;
871 buffer[chars] = '\0';
873 #endif
875 return 0;
877 #endif /* ACPI_FUTURE_USAGE */
879 /* Assumes no unreadable holes inbetween */
880 u8 acpi_os_readable(void *ptr, acpi_size len)
882 #if defined(__i386__) || defined(__x86_64__)
883 char tmp;
884 return !__get_user(tmp, (char __user *)ptr)
885 && !__get_user(tmp, (char __user *)ptr + len - 1);
886 #endif
887 return 1;
890 #ifdef ACPI_FUTURE_USAGE
891 u8 acpi_os_writable(void *ptr, acpi_size len)
893 /* could do dummy write (racy) or a kernel page table lookup.
894 The later may be difficult at early boot when kmap doesn't work yet. */
895 return 1;
897 #endif
899 acpi_status acpi_os_signal(u32 function, void *info)
901 switch (function) {
902 case ACPI_SIGNAL_FATAL:
903 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
904 break;
905 case ACPI_SIGNAL_BREAKPOINT:
907 * AML Breakpoint
908 * ACPI spec. says to treat it as a NOP unless
909 * you are debugging. So if/when we integrate
910 * AML debugger into the kernel debugger its
911 * hook will go here. But until then it is
912 * not useful to print anything on breakpoints.
914 break;
915 default:
916 break;
919 return AE_OK;
922 EXPORT_SYMBOL(acpi_os_signal);
924 static int __init acpi_os_name_setup(char *str)
926 char *p = acpi_os_name;
927 int count = ACPI_MAX_OVERRIDE_LEN - 1;
929 if (!str || !*str)
930 return 0;
932 for (; count-- && str && *str; str++) {
933 if (isalnum(*str) || *str == ' ' || *str == ':')
934 *p++ = *str;
935 else if (*str == '\'' || *str == '"')
936 continue;
937 else
938 break;
940 *p = 0;
942 return 1;
946 __setup("acpi_os_name=", acpi_os_name_setup);
949 * _OSI control
950 * empty string disables _OSI
951 * TBD additional string adds to _OSI
953 static int __init acpi_osi_setup(char *str)
955 if (str == NULL || *str == '\0') {
956 printk(KERN_INFO PREFIX "_OSI method disabled\n");
957 acpi_gbl_create_osi_method = FALSE;
958 } else {
959 /* TBD */
960 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
961 str);
964 return 1;
967 __setup("acpi_osi=", acpi_osi_setup);
969 /* enable serialization to combat AE_ALREADY_EXISTS errors */
970 static int __init acpi_serialize_setup(char *str)
972 printk(KERN_INFO PREFIX "serialize enabled\n");
974 acpi_gbl_all_methods_serialized = TRUE;
976 return 1;
979 __setup("acpi_serialize", acpi_serialize_setup);
982 * Wake and Run-Time GPES are expected to be separate.
983 * We disable wake-GPEs at run-time to prevent spurious
984 * interrupts.
986 * However, if a system exists that shares Wake and
987 * Run-time events on the same GPE this flag is available
988 * to tell Linux to keep the wake-time GPEs enabled at run-time.
990 static int __init acpi_wake_gpes_always_on_setup(char *str)
992 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
994 acpi_gbl_leave_wake_gpes_disabled = FALSE;
996 return 1;
999 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1001 static int __init acpi_hotkey_setup(char *str)
1003 acpi_specific_hotkey_enabled = FALSE;
1004 return 1;
1007 __setup("acpi_generic_hotkey", acpi_hotkey_setup);
1010 * max_cstate is defined in the base kernel so modules can
1011 * change it w/o depending on the state of the processor module.
1013 unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1015 EXPORT_SYMBOL(max_cstate);
1018 * Acquire a spinlock.
1020 * handle is a pointer to the spinlock_t.
1023 acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)
1025 acpi_cpu_flags flags;
1026 spin_lock_irqsave((spinlock_t *) handle, flags);
1027 return flags;
1031 * Release a spinlock. See above.
1034 void acpi_os_release_lock(acpi_handle handle, acpi_cpu_flags flags)
1036 spin_unlock_irqrestore((spinlock_t *) handle, flags);
1039 #ifndef ACPI_USE_LOCAL_CACHE
1041 /*******************************************************************************
1043 * FUNCTION: acpi_os_create_cache
1045 * PARAMETERS: CacheName - Ascii name for the cache
1046 * ObjectSize - Size of each cached object
1047 * MaxDepth - Maximum depth of the cache (in objects)
1048 * ReturnCache - Where the new cache object is returned
1050 * RETURN: Status
1052 * DESCRIPTION: Create a cache object
1054 ******************************************************************************/
1056 acpi_status
1057 acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1059 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
1060 return AE_OK;
1063 /*******************************************************************************
1065 * FUNCTION: acpi_os_purge_cache
1067 * PARAMETERS: Cache - Handle to cache object
1069 * RETURN: Status
1071 * DESCRIPTION: Free all objects within the requested cache.
1073 ******************************************************************************/
1075 acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1077 (void)kmem_cache_shrink(cache);
1078 return (AE_OK);
1081 /*******************************************************************************
1083 * FUNCTION: acpi_os_delete_cache
1085 * PARAMETERS: Cache - Handle to cache object
1087 * RETURN: Status
1089 * DESCRIPTION: Free all objects within the requested cache and delete the
1090 * cache object.
1092 ******************************************************************************/
1094 acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1096 (void)kmem_cache_destroy(cache);
1097 return (AE_OK);
1100 /*******************************************************************************
1102 * FUNCTION: acpi_os_release_object
1104 * PARAMETERS: Cache - Handle to cache object
1105 * Object - The object to be released
1107 * RETURN: None
1109 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1110 * the object is deleted.
1112 ******************************************************************************/
1114 acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1116 kmem_cache_free(cache, object);
1117 return (AE_OK);
1120 /*******************************************************************************
1122 * FUNCTION: acpi_os_acquire_object
1124 * PARAMETERS: Cache - Handle to cache object
1125 * ReturnObject - Where the object is returned
1127 * RETURN: Status
1129 * DESCRIPTION: Return a zero-filled object.
1131 ******************************************************************************/
1133 void *acpi_os_acquire_object(acpi_cache_t * cache)
1135 void *object = kmem_cache_zalloc(cache, GFP_KERNEL);
1136 WARN_ON(!object);
1137 return object;
1140 #endif