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>
32 #include <linux/pci.h>
33 #include <linux/interrupt.h>
34 #include <linux/kmod.h>
35 #include <linux/delay.h>
36 #include <linux/dmi.h>
37 #include <linux/workqueue.h>
38 #include <linux/nmi.h>
39 #include <linux/acpi.h>
40 #include <acpi/acpi.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: "
52 acpi_osd_exec_callback function
;
54 struct work_struct work
;
57 #ifdef CONFIG_ACPI_CUSTOM_DSDT
58 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
61 #ifdef ENABLE_DEBUGGER
62 #include <linux/kdb.h>
64 /* stuff for debugger support */
66 EXPORT_SYMBOL(acpi_in_debugger
);
68 extern char line_buf
[80];
69 #endif /*ENABLE_DEBUGGER */
71 static unsigned int acpi_irq_irq
;
72 static acpi_osd_handler acpi_irq_handler
;
73 static void *acpi_irq_context
;
74 static struct workqueue_struct
*kacpid_wq
;
75 static struct workqueue_struct
*kacpi_notify_wq
;
77 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
78 static char osi_additional_string
[OSI_STRING_LENGTH_MAX
];
81 * "Ode to _OSI(Linux)"
83 * osi_linux -- Control response to BIOS _OSI(Linux) query.
85 * As Linux evolves, the features that it supports change.
86 * So an OSI string such as "Linux" is not specific enough
87 * to be useful across multiple versions of Linux. It
88 * doesn't identify any particular feature, interface,
89 * or even any particular version of Linux...
91 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
92 * to a BIOS _OSI(Linux) query. When
93 * a reference mobile BIOS started using it, its use
94 * started to spread to many vendor platforms.
95 * As it is not supportable, we need to halt that spread.
97 * Today, most BIOS references to _OSI(Linux) are noise --
98 * they have no functional effect and are just dead code
99 * carried over from the reference BIOS.
101 * The next most common case is that _OSI(Linux) harms Linux,
102 * usually by causing the BIOS to follow paths that are
103 * not tested during Windows validation.
105 * Finally, there is a short list of platforms
106 * where OSI(Linux) benefits Linux.
108 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
109 * DMI is used to disable the dmesg warning about OSI(Linux)
110 * on platforms where it is known to have no effect.
111 * But a dmesg warning remains for systems where
112 * we do not know if OSI(Linux) is good or bad for the system.
113 * DMI is also used to enable OSI(Linux) for the machines
114 * that are known to need it.
116 * BIOS writers should NOT query _OSI(Linux) on future systems.
117 * It will be ignored by default, and to get Linux to
118 * not ignore it will require a kernel source update to
119 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
121 #define OSI_LINUX_ENABLE 0
124 unsigned int enable
:1;
126 unsigned int cmdline
:1;
127 unsigned int known
:1;
128 } osi_linux
= { OSI_LINUX_ENABLE
, 0, 0, 0};
130 static void __init
acpi_request_region (struct acpi_generic_address
*addr
,
131 unsigned int length
, char *desc
)
133 struct resource
*res
;
135 if (!addr
->address
|| !length
)
138 if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
139 res
= request_region(addr
->address
, length
, desc
);
140 else if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
141 res
= request_mem_region(addr
->address
, length
, desc
);
144 static int __init
acpi_reserve_resources(void)
146 acpi_request_region(&acpi_gbl_FADT
.xpm1a_event_block
, acpi_gbl_FADT
.pm1_event_length
,
147 "ACPI PM1a_EVT_BLK");
149 acpi_request_region(&acpi_gbl_FADT
.xpm1b_event_block
, acpi_gbl_FADT
.pm1_event_length
,
150 "ACPI PM1b_EVT_BLK");
152 acpi_request_region(&acpi_gbl_FADT
.xpm1a_control_block
, acpi_gbl_FADT
.pm1_control_length
,
153 "ACPI PM1a_CNT_BLK");
155 acpi_request_region(&acpi_gbl_FADT
.xpm1b_control_block
, acpi_gbl_FADT
.pm1_control_length
,
156 "ACPI PM1b_CNT_BLK");
158 if (acpi_gbl_FADT
.pm_timer_length
== 4)
159 acpi_request_region(&acpi_gbl_FADT
.xpm_timer_block
, 4, "ACPI PM_TMR");
161 acpi_request_region(&acpi_gbl_FADT
.xpm2_control_block
, acpi_gbl_FADT
.pm2_control_length
,
164 /* Length of GPE blocks must be a non-negative multiple of 2 */
166 if (!(acpi_gbl_FADT
.gpe0_block_length
& 0x1))
167 acpi_request_region(&acpi_gbl_FADT
.xgpe0_block
,
168 acpi_gbl_FADT
.gpe0_block_length
, "ACPI GPE0_BLK");
170 if (!(acpi_gbl_FADT
.gpe1_block_length
& 0x1))
171 acpi_request_region(&acpi_gbl_FADT
.xgpe1_block
,
172 acpi_gbl_FADT
.gpe1_block_length
, "ACPI GPE1_BLK");
176 device_initcall(acpi_reserve_resources
);
178 acpi_status __init
acpi_os_initialize(void)
183 acpi_status
acpi_os_initialize1(void)
186 * Initialize PCI configuration space access, as we'll need to access
187 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
190 printk(KERN_ERR PREFIX
191 "Access to PCI configuration space unavailable\n");
192 return AE_NULL_ENTRY
;
194 kacpid_wq
= create_singlethread_workqueue("kacpid");
195 kacpi_notify_wq
= create_singlethread_workqueue("kacpi_notify");
197 BUG_ON(!kacpi_notify_wq
);
201 acpi_status
acpi_os_terminate(void)
203 if (acpi_irq_handler
) {
204 acpi_os_remove_interrupt_handler(acpi_irq_irq
,
208 destroy_workqueue(kacpid_wq
);
209 destroy_workqueue(kacpi_notify_wq
);
214 void acpi_os_printf(const char *fmt
, ...)
218 acpi_os_vprintf(fmt
, args
);
222 EXPORT_SYMBOL(acpi_os_printf
);
224 void acpi_os_vprintf(const char *fmt
, va_list args
)
226 static char buffer
[512];
228 vsprintf(buffer
, fmt
, args
);
230 #ifdef ENABLE_DEBUGGER
231 if (acpi_in_debugger
) {
232 kdb_printf("%s", buffer
);
234 printk("%s", buffer
);
237 printk("%s", buffer
);
241 acpi_physical_address __init
acpi_os_get_root_pointer(void)
244 if (efi
.acpi20
!= EFI_INVALID_TABLE_ADDR
)
246 else if (efi
.acpi
!= EFI_INVALID_TABLE_ADDR
)
249 printk(KERN_ERR PREFIX
250 "System description tables not found\n");
254 return acpi_find_rsdp();
257 void __iomem
*acpi_os_map_memory(acpi_physical_address phys
, acpi_size size
)
259 if (phys
> ULONG_MAX
) {
260 printk(KERN_ERR PREFIX
"Cannot map memory that high\n");
263 if (acpi_gbl_permanent_mmap
)
265 * ioremap checks to ensure this is in reserved space
267 return ioremap((unsigned long)phys
, size
);
269 return __acpi_map_table((unsigned long)phys
, size
);
271 EXPORT_SYMBOL_GPL(acpi_os_map_memory
);
273 void acpi_os_unmap_memory(void __iomem
* virt
, acpi_size size
)
275 if (acpi_gbl_permanent_mmap
) {
279 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory
);
281 #ifdef ACPI_FUTURE_USAGE
283 acpi_os_get_physical_address(void *virt
, acpi_physical_address
* phys
)
286 return AE_BAD_PARAMETER
;
288 *phys
= virt_to_phys(virt
);
294 #define ACPI_MAX_OVERRIDE_LEN 100
296 static char acpi_os_name
[ACPI_MAX_OVERRIDE_LEN
];
299 acpi_os_predefined_override(const struct acpi_predefined_names
*init_val
,
300 acpi_string
* new_val
)
302 if (!init_val
|| !new_val
)
303 return AE_BAD_PARAMETER
;
306 if (!memcmp(init_val
->name
, "_OS_", 4) && strlen(acpi_os_name
)) {
307 printk(KERN_INFO PREFIX
"Overriding _OS definition to '%s'\n",
309 *new_val
= acpi_os_name
;
315 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
316 struct acpi_table_header
*acpi_find_dsdt_initrd(void)
318 struct file
*firmware_file
;
320 unsigned long len
, len2
;
321 struct acpi_table_header
*dsdt_buffer
, *ret
= NULL
;
323 char *ramfs_dsdt_name
= "/DSDT.aml";
325 printk(KERN_INFO PREFIX
"Looking for DSDT in initramfs... ");
328 * Never do this at home, only the user-space is allowed to open a file.
329 * The clean way would be to use the firmware loader. But this code must be run
330 * before there is any userspace available. So we need a static/init firmware
331 * infrastructure, which doesn't exist yet...
333 if (vfs_stat(ramfs_dsdt_name
, &stat
) < 0) {
334 printk("not found.\n");
339 /* check especially against empty files */
341 printk("error, file is too small: only %lu bytes.\n", len
);
345 firmware_file
= filp_open(ramfs_dsdt_name
, O_RDONLY
, 0);
346 if (IS_ERR(firmware_file
)) {
347 printk("error, could not open file %s.\n", ramfs_dsdt_name
);
351 dsdt_buffer
= ACPI_ALLOCATE(len
);
353 printk("error when allocating %lu bytes of memory.\n", len
);
359 len2
= vfs_read(firmware_file
, (char __user
*)dsdt_buffer
, len
, &firmware_file
->f_pos
);
362 printk("error trying to read %lu bytes from %s.\n", len
, ramfs_dsdt_name
);
363 ACPI_FREE(dsdt_buffer
);
367 printk("successfully read %lu bytes from %s.\n", len
, ramfs_dsdt_name
);
370 filp_close(firmware_file
, NULL
);
376 acpi_os_table_override(struct acpi_table_header
* existing_table
,
377 struct acpi_table_header
** new_table
)
379 if (!existing_table
|| !new_table
)
380 return AE_BAD_PARAMETER
;
384 #ifdef CONFIG_ACPI_CUSTOM_DSDT
385 if (strncmp(existing_table
->signature
, "DSDT", 4) == 0)
386 *new_table
= (struct acpi_table_header
*)AmlCode
;
388 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
389 if (strncmp(existing_table
->signature
, "DSDT", 4) == 0) {
390 struct acpi_table_header
*initrd_table
= acpi_find_dsdt_initrd();
392 *new_table
= initrd_table
;
395 if (*new_table
!= NULL
) {
396 printk(KERN_WARNING PREFIX
"Override [%4.4s-%8.8s], "
397 "this is unsafe: tainting kernel\n",
398 existing_table
->signature
,
399 existing_table
->oem_table_id
);
400 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE
);
405 static irqreturn_t
acpi_irq(int irq
, void *dev_id
)
407 return (*acpi_irq_handler
) (acpi_irq_context
) ? IRQ_HANDLED
: IRQ_NONE
;
411 acpi_os_install_interrupt_handler(u32 gsi
, acpi_osd_handler handler
,
417 * Ignore the GSI from the core, and use the value in our copy of the
418 * FADT. It may not be the same if an interrupt source override exists
421 gsi
= acpi_gbl_FADT
.sci_interrupt
;
422 if (acpi_gsi_to_irq(gsi
, &irq
) < 0) {
423 printk(KERN_ERR PREFIX
"SCI (ACPI GSI %d) not registered\n",
428 acpi_irq_handler
= handler
;
429 acpi_irq_context
= context
;
430 if (request_irq(irq
, acpi_irq
, IRQF_SHARED
, "acpi", acpi_irq
)) {
431 printk(KERN_ERR PREFIX
"SCI (IRQ%d) allocation failed\n", irq
);
432 return AE_NOT_ACQUIRED
;
439 acpi_status
acpi_os_remove_interrupt_handler(u32 irq
, acpi_osd_handler handler
)
442 free_irq(irq
, acpi_irq
);
443 acpi_irq_handler
= NULL
;
451 * Running in interpreter thread context, safe to sleep
454 void acpi_os_sleep(acpi_integer ms
)
456 schedule_timeout_interruptible(msecs_to_jiffies(ms
));
459 EXPORT_SYMBOL(acpi_os_sleep
);
461 void acpi_os_stall(u32 us
)
469 touch_nmi_watchdog();
474 EXPORT_SYMBOL(acpi_os_stall
);
477 * Support ACPI 3.0 AML Timer operand
478 * Returns 64-bit free-running, monotonically increasing timer
479 * with 100ns granularity
481 u64
acpi_os_get_timer(void)
486 /* TBD: use HPET if available */
489 #ifdef CONFIG_X86_PM_TIMER
490 /* TBD: default to PM timer if HPET was not available */
493 printk(KERN_ERR PREFIX
"acpi_os_get_timer() TBD\n");
498 acpi_status
acpi_os_read_port(acpi_io_address port
, u32
* value
, u32 width
)
507 *(u8
*) value
= inb(port
);
508 } else if (width
<= 16) {
509 *(u16
*) value
= inw(port
);
510 } else if (width
<= 32) {
511 *(u32
*) value
= inl(port
);
519 EXPORT_SYMBOL(acpi_os_read_port
);
521 acpi_status
acpi_os_write_port(acpi_io_address port
, u32 value
, u32 width
)
525 } else if (width
<= 16) {
527 } else if (width
<= 32) {
536 EXPORT_SYMBOL(acpi_os_write_port
);
539 acpi_os_read_memory(acpi_physical_address phys_addr
, u32
* value
, u32 width
)
542 void __iomem
*virt_addr
;
544 virt_addr
= ioremap(phys_addr
, width
);
550 *(u8
*) value
= readb(virt_addr
);
553 *(u16
*) value
= readw(virt_addr
);
556 *(u32
*) value
= readl(virt_addr
);
568 acpi_os_write_memory(acpi_physical_address phys_addr
, u32 value
, u32 width
)
570 void __iomem
*virt_addr
;
572 virt_addr
= ioremap(phys_addr
, width
);
576 writeb(value
, virt_addr
);
579 writew(value
, virt_addr
);
582 writel(value
, virt_addr
);
594 acpi_os_read_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
595 void *value
, u32 width
)
600 return AE_BAD_PARAMETER
;
616 BUG_ON(!raw_pci_ops
);
618 result
= raw_pci_ops
->read(pci_id
->segment
, pci_id
->bus
,
619 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
622 return (result
? AE_ERROR
: AE_OK
);
625 EXPORT_SYMBOL(acpi_os_read_pci_configuration
);
628 acpi_os_write_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
629 acpi_integer value
, u32 width
)
647 BUG_ON(!raw_pci_ops
);
649 result
= raw_pci_ops
->write(pci_id
->segment
, pci_id
->bus
,
650 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
653 return (result
? AE_ERROR
: AE_OK
);
656 /* TODO: Change code to take advantage of driver model more */
657 static void acpi_os_derive_pci_id_2(acpi_handle rhandle
, /* upper bound */
658 acpi_handle chandle
, /* current node */
659 struct acpi_pci_id
**id
,
660 int *is_bridge
, u8
* bus_number
)
663 struct acpi_pci_id
*pci_id
= *id
;
666 acpi_object_type type
;
669 acpi_get_parent(chandle
, &handle
);
670 if (handle
!= rhandle
) {
671 acpi_os_derive_pci_id_2(rhandle
, handle
, &pci_id
, is_bridge
,
674 status
= acpi_get_type(handle
, &type
);
675 if ((ACPI_FAILURE(status
)) || (type
!= ACPI_TYPE_DEVICE
))
679 acpi_evaluate_integer(handle
, METHOD_NAME__ADR
, NULL
,
681 if (ACPI_SUCCESS(status
)) {
682 pci_id
->device
= ACPI_HIWORD(ACPI_LODWORD(temp
));
683 pci_id
->function
= ACPI_LOWORD(ACPI_LODWORD(temp
));
686 pci_id
->bus
= *bus_number
;
688 /* any nicer way to get bus number of bridge ? */
690 acpi_os_read_pci_configuration(pci_id
, 0x0e, &tu8
,
692 if (ACPI_SUCCESS(status
)
693 && ((tu8
& 0x7f) == 1 || (tu8
& 0x7f) == 2)) {
695 acpi_os_read_pci_configuration(pci_id
, 0x18,
697 if (!ACPI_SUCCESS(status
)) {
698 /* Certainly broken... FIX ME */
704 acpi_os_read_pci_configuration(pci_id
, 0x19,
706 if (ACPI_SUCCESS(status
)) {
715 void acpi_os_derive_pci_id(acpi_handle rhandle
, /* upper bound */
716 acpi_handle chandle
, /* current node */
717 struct acpi_pci_id
**id
)
720 u8 bus_number
= (*id
)->bus
;
722 acpi_os_derive_pci_id_2(rhandle
, chandle
, id
, &is_bridge
, &bus_number
);
725 static void acpi_os_execute_deferred(struct work_struct
*work
)
727 struct acpi_os_dpc
*dpc
= container_of(work
, struct acpi_os_dpc
, work
);
729 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
733 dpc
->function(dpc
->context
);
736 /* Yield cpu to notify thread */
742 static void acpi_os_execute_notify(struct work_struct
*work
)
744 struct acpi_os_dpc
*dpc
= container_of(work
, struct acpi_os_dpc
, work
);
747 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
751 dpc
->function(dpc
->context
);
758 /*******************************************************************************
760 * FUNCTION: acpi_os_execute
762 * PARAMETERS: Type - Type of the callback
763 * Function - Function to be executed
764 * Context - Function parameters
768 * DESCRIPTION: Depending on type, either queues function for deferred execution or
769 * immediately executes function on a separate thread.
771 ******************************************************************************/
773 acpi_status
acpi_os_execute(acpi_execute_type type
,
774 acpi_osd_exec_callback function
, void *context
)
776 acpi_status status
= AE_OK
;
777 struct acpi_os_dpc
*dpc
;
779 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
780 "Scheduling function [%p(%p)] for deferred execution.\n",
784 return AE_BAD_PARAMETER
;
787 * Allocate/initialize DPC structure. Note that this memory will be
788 * freed by the callee. The kernel handles the work_struct list in a
789 * way that allows us to also free its memory inside the callee.
790 * Because we may want to schedule several tasks with different
791 * parameters we can't use the approach some kernel code uses of
792 * having a static work_struct.
795 dpc
= kmalloc(sizeof(struct acpi_os_dpc
), GFP_ATOMIC
);
797 return_ACPI_STATUS(AE_NO_MEMORY
);
799 dpc
->function
= function
;
800 dpc
->context
= context
;
802 if (type
== OSL_NOTIFY_HANDLER
) {
803 INIT_WORK(&dpc
->work
, acpi_os_execute_notify
);
804 if (!queue_work(kacpi_notify_wq
, &dpc
->work
)) {
809 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
810 if (!queue_work(kacpid_wq
, &dpc
->work
)) {
811 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
812 "Call to queue_work() failed.\n"));
817 return_ACPI_STATUS(status
);
820 EXPORT_SYMBOL(acpi_os_execute
);
822 void acpi_os_wait_events_complete(void *context
)
824 flush_workqueue(kacpid_wq
);
827 EXPORT_SYMBOL(acpi_os_wait_events_complete
);
830 * Allocate the memory for a spinlock and initialize it.
832 acpi_status
acpi_os_create_lock(acpi_spinlock
* handle
)
834 spin_lock_init(*handle
);
840 * Deallocate the memory for a spinlock.
842 void acpi_os_delete_lock(acpi_spinlock handle
)
848 acpi_os_create_semaphore(u32 max_units
, u32 initial_units
, acpi_handle
* handle
)
850 struct semaphore
*sem
= NULL
;
853 sem
= acpi_os_allocate(sizeof(struct semaphore
));
856 memset(sem
, 0, sizeof(struct semaphore
));
858 sema_init(sem
, initial_units
);
860 *handle
= (acpi_handle
*) sem
;
862 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Creating semaphore[%p|%d].\n",
863 *handle
, initial_units
));
868 EXPORT_SYMBOL(acpi_os_create_semaphore
);
871 * TODO: A better way to delete semaphores? Linux doesn't have a
872 * 'delete_semaphore()' function -- may result in an invalid
873 * pointer dereference for non-synchronized consumers. Should
874 * we at least check for blocked threads and signal/cancel them?
877 acpi_status
acpi_os_delete_semaphore(acpi_handle handle
)
879 struct semaphore
*sem
= (struct semaphore
*)handle
;
883 return AE_BAD_PARAMETER
;
885 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Deleting semaphore[%p].\n", handle
));
893 EXPORT_SYMBOL(acpi_os_delete_semaphore
);
896 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
897 * improvise. The process is to sleep for one scheduler quantum
898 * until the semaphore becomes available. Downside is that this
899 * may result in starvation for timeout-based waits when there's
900 * lots of semaphore activity.
902 * TODO: Support for units > 1?
904 acpi_status
acpi_os_wait_semaphore(acpi_handle handle
, u32 units
, u16 timeout
)
906 acpi_status status
= AE_OK
;
907 struct semaphore
*sem
= (struct semaphore
*)handle
;
911 if (!sem
|| (units
< 1))
912 return AE_BAD_PARAMETER
;
917 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Waiting for semaphore[%p|%d|%d]\n",
918 handle
, units
, timeout
));
921 * This can be called during resume with interrupts off.
922 * Like boot-time, we should be single threaded and will
923 * always get the lock if we try -- timeout or not.
924 * If this doesn't succeed, then we will oops courtesy of
925 * might_sleep() in down().
927 if (!down_trylock(sem
))
934 * A zero timeout value indicates that we shouldn't wait - just
935 * acquire the semaphore if available otherwise return AE_TIME
936 * (a.k.a. 'would block').
939 if (down_trylock(sem
))
947 case ACPI_WAIT_FOREVER
:
956 // TODO: A better timeout algorithm?
959 static const int quantum_ms
= 1000 / HZ
;
961 ret
= down_trylock(sem
);
962 for (i
= timeout
; (i
> 0 && ret
!= 0); i
-= quantum_ms
) {
963 schedule_timeout_interruptible(1);
964 ret
= down_trylock(sem
);
973 if (ACPI_FAILURE(status
)) {
974 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
975 "Failed to acquire semaphore[%p|%d|%d], %s",
976 handle
, units
, timeout
,
977 acpi_format_exception(status
)));
979 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
980 "Acquired semaphore[%p|%d|%d]", handle
,
987 EXPORT_SYMBOL(acpi_os_wait_semaphore
);
990 * TODO: Support for units > 1?
992 acpi_status
acpi_os_signal_semaphore(acpi_handle handle
, u32 units
)
994 struct semaphore
*sem
= (struct semaphore
*)handle
;
997 if (!sem
|| (units
< 1))
998 return AE_BAD_PARAMETER
;
1003 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Signaling semaphore[%p|%d]\n", handle
,
1011 EXPORT_SYMBOL(acpi_os_signal_semaphore
);
1013 #ifdef ACPI_FUTURE_USAGE
1014 u32
acpi_os_get_line(char *buffer
)
1017 #ifdef ENABLE_DEBUGGER
1018 if (acpi_in_debugger
) {
1021 kdb_read(buffer
, sizeof(line_buf
));
1023 /* remove the CR kdb includes */
1024 chars
= strlen(buffer
) - 1;
1025 buffer
[chars
] = '\0';
1031 #endif /* ACPI_FUTURE_USAGE */
1033 acpi_status
acpi_os_signal(u32 function
, void *info
)
1036 case ACPI_SIGNAL_FATAL
:
1037 printk(KERN_ERR PREFIX
"Fatal opcode executed\n");
1039 case ACPI_SIGNAL_BREAKPOINT
:
1042 * ACPI spec. says to treat it as a NOP unless
1043 * you are debugging. So if/when we integrate
1044 * AML debugger into the kernel debugger its
1045 * hook will go here. But until then it is
1046 * not useful to print anything on breakpoints.
1056 EXPORT_SYMBOL(acpi_os_signal
);
1058 static int __init
acpi_os_name_setup(char *str
)
1060 char *p
= acpi_os_name
;
1061 int count
= ACPI_MAX_OVERRIDE_LEN
- 1;
1066 for (; count
-- && str
&& *str
; str
++) {
1067 if (isalnum(*str
) || *str
== ' ' || *str
== ':')
1069 else if (*str
== '\'' || *str
== '"')
1080 __setup("acpi_os_name=", acpi_os_name_setup
);
1082 static void __init
set_osi_linux(unsigned int enable
)
1084 if (osi_linux
.enable
!= enable
) {
1085 osi_linux
.enable
= enable
;
1086 printk(KERN_NOTICE PREFIX
"%sed _OSI(Linux)\n",
1087 enable
? "Add": "Delet");
1092 static void __init
acpi_cmdline_osi_linux(unsigned int enable
)
1094 osi_linux
.cmdline
= 1; /* cmdline set the default */
1095 set_osi_linux(enable
);
1100 void __init
acpi_dmi_osi_linux(int enable
, const struct dmi_system_id
*d
)
1102 osi_linux
.dmi
= 1; /* DMI knows that this box asks OSI(Linux) */
1104 printk(KERN_NOTICE PREFIX
"DMI detected: %s\n", d
->ident
);
1109 osi_linux
.known
= 1; /* DMI knows which OSI(Linux) default needed */
1111 set_osi_linux(enable
);
1117 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1119 * empty string disables _OSI
1120 * string starting with '!' disables that string
1121 * otherwise string is added to list, augmenting built-in strings
1123 static int __init
acpi_osi_setup(char *str
)
1125 if (str
== NULL
|| *str
== '\0') {
1126 printk(KERN_INFO PREFIX
"_OSI method disabled\n");
1127 acpi_gbl_create_osi_method
= FALSE
;
1128 } else if (!strcmp("!Linux", str
)) {
1129 acpi_cmdline_osi_linux(0); /* !enable */
1130 } else if (*str
== '!') {
1131 if (acpi_osi_invalidate(++str
) == AE_OK
)
1132 printk(KERN_INFO PREFIX
"Deleted _OSI(%s)\n", str
);
1133 } else if (!strcmp("Linux", str
)) {
1134 acpi_cmdline_osi_linux(1); /* enable */
1135 } else if (*osi_additional_string
== '\0') {
1136 strncpy(osi_additional_string
, str
, OSI_STRING_LENGTH_MAX
);
1137 printk(KERN_INFO PREFIX
"Added _OSI(%s)\n", str
);
1143 __setup("acpi_osi=", acpi_osi_setup
);
1145 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1146 static int __init
acpi_serialize_setup(char *str
)
1148 printk(KERN_INFO PREFIX
"serialize enabled\n");
1150 acpi_gbl_all_methods_serialized
= TRUE
;
1155 __setup("acpi_serialize", acpi_serialize_setup
);
1158 * Wake and Run-Time GPES are expected to be separate.
1159 * We disable wake-GPEs at run-time to prevent spurious
1162 * However, if a system exists that shares Wake and
1163 * Run-time events on the same GPE this flag is available
1164 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1166 static int __init
acpi_wake_gpes_always_on_setup(char *str
)
1168 printk(KERN_INFO PREFIX
"wake GPEs not disabled\n");
1170 acpi_gbl_leave_wake_gpes_disabled
= FALSE
;
1175 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup
);
1178 * Acquire a spinlock.
1180 * handle is a pointer to the spinlock_t.
1183 acpi_cpu_flags
acpi_os_acquire_lock(acpi_spinlock lockp
)
1185 acpi_cpu_flags flags
;
1186 spin_lock_irqsave(lockp
, flags
);
1191 * Release a spinlock. See above.
1194 void acpi_os_release_lock(acpi_spinlock lockp
, acpi_cpu_flags flags
)
1196 spin_unlock_irqrestore(lockp
, flags
);
1199 #ifndef ACPI_USE_LOCAL_CACHE
1201 /*******************************************************************************
1203 * FUNCTION: acpi_os_create_cache
1205 * PARAMETERS: name - Ascii name for the cache
1206 * size - Size of each cached object
1207 * depth - Maximum depth of the cache (in objects) <ignored>
1208 * cache - Where the new cache object is returned
1212 * DESCRIPTION: Create a cache object
1214 ******************************************************************************/
1217 acpi_os_create_cache(char *name
, u16 size
, u16 depth
, acpi_cache_t
** cache
)
1219 *cache
= kmem_cache_create(name
, size
, 0, 0, NULL
);
1226 /*******************************************************************************
1228 * FUNCTION: acpi_os_purge_cache
1230 * PARAMETERS: Cache - Handle to cache object
1234 * DESCRIPTION: Free all objects within the requested cache.
1236 ******************************************************************************/
1238 acpi_status
acpi_os_purge_cache(acpi_cache_t
* cache
)
1240 kmem_cache_shrink(cache
);
1244 /*******************************************************************************
1246 * FUNCTION: acpi_os_delete_cache
1248 * PARAMETERS: Cache - Handle to cache object
1252 * DESCRIPTION: Free all objects within the requested cache and delete the
1255 ******************************************************************************/
1257 acpi_status
acpi_os_delete_cache(acpi_cache_t
* cache
)
1259 kmem_cache_destroy(cache
);
1263 /*******************************************************************************
1265 * FUNCTION: acpi_os_release_object
1267 * PARAMETERS: Cache - Handle to cache object
1268 * Object - The object to be released
1272 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1273 * the object is deleted.
1275 ******************************************************************************/
1277 acpi_status
acpi_os_release_object(acpi_cache_t
* cache
, void *object
)
1279 kmem_cache_free(cache
, object
);
1284 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1286 * Returns 0 on success
1288 int acpi_dmi_dump(void)
1294 printk(KERN_NOTICE PREFIX
"DMI System Vendor: %s\n",
1295 dmi_get_slot(DMI_SYS_VENDOR
));
1296 printk(KERN_NOTICE PREFIX
"DMI Product Name: %s\n",
1297 dmi_get_slot(DMI_PRODUCT_NAME
));
1298 printk(KERN_NOTICE PREFIX
"DMI Product Version: %s\n",
1299 dmi_get_slot(DMI_PRODUCT_VERSION
));
1300 printk(KERN_NOTICE PREFIX
"DMI Board Name: %s\n",
1301 dmi_get_slot(DMI_BOARD_NAME
));
1302 printk(KERN_NOTICE PREFIX
"DMI BIOS Vendor: %s\n",
1303 dmi_get_slot(DMI_BIOS_VENDOR
));
1304 printk(KERN_NOTICE PREFIX
"DMI BIOS Date: %s\n",
1305 dmi_get_slot(DMI_BIOS_DATE
));
1311 /******************************************************************************
1313 * FUNCTION: acpi_os_validate_interface
1315 * PARAMETERS: interface - Requested interface to be validated
1317 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1319 * DESCRIPTION: Match an interface string to the interfaces supported by the
1320 * host. Strings originate from an AML call to the _OSI method.
1322 *****************************************************************************/
1325 acpi_os_validate_interface (char *interface
)
1327 if (!strncmp(osi_additional_string
, interface
, OSI_STRING_LENGTH_MAX
))
1329 if (!strcmp("Linux", interface
)) {
1331 printk(KERN_NOTICE PREFIX
1332 "BIOS _OSI(Linux) query %s%s\n",
1333 osi_linux
.enable
? "honored" : "ignored",
1334 osi_linux
.cmdline
? " via cmdline" :
1335 osi_linux
.dmi
? " via DMI" : "");
1337 if (!osi_linux
.dmi
) {
1338 if (acpi_dmi_dump())
1339 printk(KERN_NOTICE PREFIX
1340 "[please extract dmidecode output]\n");
1341 printk(KERN_NOTICE PREFIX
1342 "Please send DMI info above to "
1343 "linux-acpi@vger.kernel.org\n");
1345 if (!osi_linux
.known
&& !osi_linux
.cmdline
) {
1346 printk(KERN_NOTICE PREFIX
1347 "If \"acpi_osi=%sLinux\" works better, "
1348 "please notify linux-acpi@vger.kernel.org\n",
1349 osi_linux
.enable
? "!" : "");
1352 if (osi_linux
.enable
)
1358 /******************************************************************************
1360 * FUNCTION: acpi_os_validate_address
1362 * PARAMETERS: space_id - ACPI space ID
1363 * address - Physical address
1364 * length - Address length
1366 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1367 * should return AE_AML_ILLEGAL_ADDRESS.
1369 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1370 * the addresses accessed by AML operation regions.
1372 *****************************************************************************/
1375 acpi_os_validate_address (
1377 acpi_physical_address address
,