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>
47 #include <linux/ioport.h>
48 #include <linux/list.h>
50 #define _COMPONENT ACPI_OS_SERVICES
51 ACPI_MODULE_NAME("osl");
52 #define PREFIX "ACPI: "
54 acpi_osd_exec_callback function
;
56 struct work_struct work
;
59 #ifdef CONFIG_ACPI_CUSTOM_DSDT
60 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
63 #ifdef ENABLE_DEBUGGER
64 #include <linux/kdb.h>
66 /* stuff for debugger support */
68 EXPORT_SYMBOL(acpi_in_debugger
);
70 extern char line_buf
[80];
71 #endif /*ENABLE_DEBUGGER */
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
;
77 static struct workqueue_struct
*kacpi_notify_wq
;
79 struct acpi_res_list
{
80 resource_size_t start
;
82 acpi_adr_space_type resource_type
; /* IO port, System memory, ...*/
83 char name
[5]; /* only can have a length of 4 chars, make use of this
84 one instead of res->name, no need to kalloc then */
85 struct list_head resource_list
;
88 static LIST_HEAD(resource_list_head
);
89 static DEFINE_SPINLOCK(acpi_res_lock
);
91 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
92 static char osi_additional_string
[OSI_STRING_LENGTH_MAX
];
94 <<<<<<< HEAD
:drivers
/acpi
/osl
.c
95 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
96 static int acpi_no_initrd_override
;
100 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/osl
.c
102 * "Ode to _OSI(Linux)"
104 * osi_linux -- Control response to BIOS _OSI(Linux) query.
106 * As Linux evolves, the features that it supports change.
107 * So an OSI string such as "Linux" is not specific enough
108 * to be useful across multiple versions of Linux. It
109 * doesn't identify any particular feature, interface,
110 * or even any particular version of Linux...
112 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
113 * to a BIOS _OSI(Linux) query. When
114 * a reference mobile BIOS started using it, its use
115 * started to spread to many vendor platforms.
116 * As it is not supportable, we need to halt that spread.
118 * Today, most BIOS references to _OSI(Linux) are noise --
119 * they have no functional effect and are just dead code
120 * carried over from the reference BIOS.
122 * The next most common case is that _OSI(Linux) harms Linux,
123 * usually by causing the BIOS to follow paths that are
124 * not tested during Windows validation.
126 * Finally, there is a short list of platforms
127 * where OSI(Linux) benefits Linux.
129 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
130 * DMI is used to disable the dmesg warning about OSI(Linux)
131 * on platforms where it is known to have no effect.
132 * But a dmesg warning remains for systems where
133 * we do not know if OSI(Linux) is good or bad for the system.
134 * DMI is also used to enable OSI(Linux) for the machines
135 * that are known to need it.
137 * BIOS writers should NOT query _OSI(Linux) on future systems.
138 * It will be ignored by default, and to get Linux to
139 * not ignore it will require a kernel source update to
140 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
142 #define OSI_LINUX_ENABLE 0
144 static struct osi_linux
{
145 unsigned int enable
:1;
147 unsigned int cmdline
:1;
148 unsigned int known
:1;
149 } osi_linux
= { OSI_LINUX_ENABLE
, 0, 0, 0};
151 static void __init
acpi_request_region (struct acpi_generic_address
*addr
,
152 unsigned int length
, char *desc
)
154 struct resource
*res
;
156 if (!addr
->address
|| !length
)
159 if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
160 res
= request_region(addr
->address
, length
, desc
);
161 else if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
162 res
= request_mem_region(addr
->address
, length
, desc
);
165 static int __init
acpi_reserve_resources(void)
167 acpi_request_region(&acpi_gbl_FADT
.xpm1a_event_block
, acpi_gbl_FADT
.pm1_event_length
,
168 "ACPI PM1a_EVT_BLK");
170 acpi_request_region(&acpi_gbl_FADT
.xpm1b_event_block
, acpi_gbl_FADT
.pm1_event_length
,
171 "ACPI PM1b_EVT_BLK");
173 acpi_request_region(&acpi_gbl_FADT
.xpm1a_control_block
, acpi_gbl_FADT
.pm1_control_length
,
174 "ACPI PM1a_CNT_BLK");
176 acpi_request_region(&acpi_gbl_FADT
.xpm1b_control_block
, acpi_gbl_FADT
.pm1_control_length
,
177 "ACPI PM1b_CNT_BLK");
179 if (acpi_gbl_FADT
.pm_timer_length
== 4)
180 acpi_request_region(&acpi_gbl_FADT
.xpm_timer_block
, 4, "ACPI PM_TMR");
182 acpi_request_region(&acpi_gbl_FADT
.xpm2_control_block
, acpi_gbl_FADT
.pm2_control_length
,
185 /* Length of GPE blocks must be a non-negative multiple of 2 */
187 if (!(acpi_gbl_FADT
.gpe0_block_length
& 0x1))
188 acpi_request_region(&acpi_gbl_FADT
.xgpe0_block
,
189 acpi_gbl_FADT
.gpe0_block_length
, "ACPI GPE0_BLK");
191 if (!(acpi_gbl_FADT
.gpe1_block_length
& 0x1))
192 acpi_request_region(&acpi_gbl_FADT
.xgpe1_block
,
193 acpi_gbl_FADT
.gpe1_block_length
, "ACPI GPE1_BLK");
197 device_initcall(acpi_reserve_resources
);
199 acpi_status __init
acpi_os_initialize(void)
204 acpi_status
acpi_os_initialize1(void)
206 kacpid_wq
= create_singlethread_workqueue("kacpid");
207 kacpi_notify_wq
= create_singlethread_workqueue("kacpi_notify");
209 BUG_ON(!kacpi_notify_wq
);
213 acpi_status
acpi_os_terminate(void)
215 if (acpi_irq_handler
) {
216 acpi_os_remove_interrupt_handler(acpi_irq_irq
,
220 destroy_workqueue(kacpid_wq
);
221 destroy_workqueue(kacpi_notify_wq
);
226 void acpi_os_printf(const char *fmt
, ...)
230 acpi_os_vprintf(fmt
, args
);
234 void acpi_os_vprintf(const char *fmt
, va_list args
)
236 static char buffer
[512];
238 vsprintf(buffer
, fmt
, args
);
240 #ifdef ENABLE_DEBUGGER
241 if (acpi_in_debugger
) {
242 kdb_printf("%s", buffer
);
244 printk("%s", buffer
);
247 printk("%s", buffer
);
251 acpi_physical_address __init
acpi_os_get_root_pointer(void)
254 if (efi
.acpi20
!= EFI_INVALID_TABLE_ADDR
)
256 else if (efi
.acpi
!= EFI_INVALID_TABLE_ADDR
)
259 printk(KERN_ERR PREFIX
260 "System description tables not found\n");
264 acpi_physical_address pa
= 0;
266 acpi_find_root_pointer(&pa
);
271 void __iomem
*__init_refok
272 acpi_os_map_memory(acpi_physical_address phys
, acpi_size size
)
274 if (phys
> ULONG_MAX
) {
275 printk(KERN_ERR PREFIX
"Cannot map memory that high\n");
278 if (acpi_gbl_permanent_mmap
)
280 * ioremap checks to ensure this is in reserved space
282 return ioremap((unsigned long)phys
, size
);
284 return __acpi_map_table((unsigned long)phys
, size
);
286 EXPORT_SYMBOL_GPL(acpi_os_map_memory
);
288 void acpi_os_unmap_memory(void __iomem
* virt
, acpi_size size
)
290 if (acpi_gbl_permanent_mmap
) {
294 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory
);
296 #ifdef ACPI_FUTURE_USAGE
298 acpi_os_get_physical_address(void *virt
, acpi_physical_address
* phys
)
301 return AE_BAD_PARAMETER
;
303 *phys
= virt_to_phys(virt
);
309 #define ACPI_MAX_OVERRIDE_LEN 100
311 static char acpi_os_name
[ACPI_MAX_OVERRIDE_LEN
];
314 acpi_os_predefined_override(const struct acpi_predefined_names
*init_val
,
315 acpi_string
* new_val
)
317 if (!init_val
|| !new_val
)
318 return AE_BAD_PARAMETER
;
321 if (!memcmp(init_val
->name
, "_OS_", 4) && strlen(acpi_os_name
)) {
322 printk(KERN_INFO PREFIX
"Overriding _OS definition to '%s'\n",
324 *new_val
= acpi_os_name
;
330 <<<<<<< HEAD
:drivers
/acpi
/osl
.c
331 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
332 static struct acpi_table_header
*acpi_find_dsdt_initrd(void)
334 struct file
*firmware_file
;
336 unsigned long len
, len2
;
337 struct acpi_table_header
*dsdt_buffer
, *ret
= NULL
;
339 char *ramfs_dsdt_name
= "/DSDT.aml";
341 printk(KERN_INFO PREFIX
"Checking initramfs for custom DSDT\n");
344 * Never do this at home, only the user-space is allowed to open a file.
345 * The clean way would be to use the firmware loader.
346 * But this code must be run before there is any userspace available.
347 * A static/init firmware infrastructure doesn't exist yet...
349 if (vfs_stat(ramfs_dsdt_name
, &stat
) < 0)
353 /* check especially against empty files */
355 printk(KERN_ERR PREFIX
"Failed: DSDT only %lu bytes.\n", len
);
359 firmware_file
= filp_open(ramfs_dsdt_name
, O_RDONLY
, 0);
360 if (IS_ERR(firmware_file
)) {
361 printk(KERN_ERR PREFIX
"Failed to open %s.\n", ramfs_dsdt_name
);
365 dsdt_buffer
= kmalloc(len
, GFP_ATOMIC
);
367 printk(KERN_ERR PREFIX
"Failed to allocate %lu bytes.\n", len
);
373 len2
= vfs_read(firmware_file
, (char __user
*)dsdt_buffer
, len
,
374 &firmware_file
->f_pos
);
377 printk(KERN_ERR PREFIX
"Failed to read %lu bytes from %s.\n",
378 len
, ramfs_dsdt_name
);
379 ACPI_FREE(dsdt_buffer
);
383 printk(KERN_INFO PREFIX
"Found %lu byte DSDT in %s.\n",
384 len
, ramfs_dsdt_name
);
387 filp_close(firmware_file
, NULL
);
393 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/osl
.c
395 acpi_os_table_override(struct acpi_table_header
* existing_table
,
396 struct acpi_table_header
** new_table
)
398 if (!existing_table
|| !new_table
)
399 return AE_BAD_PARAMETER
;
403 #ifdef CONFIG_ACPI_CUSTOM_DSDT
404 if (strncmp(existing_table
->signature
, "DSDT", 4) == 0)
405 *new_table
= (struct acpi_table_header
*)AmlCode
;
407 <<<<<<< HEAD
:drivers
/acpi
/osl
.c
408 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
409 if ((strncmp(existing_table
->signature
, "DSDT", 4) == 0) &&
410 !acpi_no_initrd_override
) {
411 struct acpi_table_header
*initrd_table
;
413 initrd_table
= acpi_find_dsdt_initrd();
415 *new_table
= initrd_table
;
419 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/osl
.c
420 if (*new_table
!= NULL
) {
421 printk(KERN_WARNING PREFIX
"Override [%4.4s-%8.8s], "
422 "this is unsafe: tainting kernel\n",
423 existing_table
->signature
,
424 existing_table
->oem_table_id
);
425 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE
);
430 <<<<<<< HEAD
:drivers
/acpi
/osl
.c
431 #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
432 static int __init
acpi_no_initrd_override_setup(char *s
)
434 acpi_no_initrd_override
= 1;
437 __setup("acpi_no_initrd_override", acpi_no_initrd_override_setup
);
441 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/osl
.c
442 static irqreturn_t
acpi_irq(int irq
, void *dev_id
)
446 handled
= (*acpi_irq_handler
) (acpi_irq_context
);
456 acpi_os_install_interrupt_handler(u32 gsi
, acpi_osd_handler handler
,
461 acpi_irq_stats_init();
464 * Ignore the GSI from the core, and use the value in our copy of the
465 * FADT. It may not be the same if an interrupt source override exists
468 gsi
= acpi_gbl_FADT
.sci_interrupt
;
469 if (acpi_gsi_to_irq(gsi
, &irq
) < 0) {
470 printk(KERN_ERR PREFIX
"SCI (ACPI GSI %d) not registered\n",
475 acpi_irq_handler
= handler
;
476 acpi_irq_context
= context
;
477 if (request_irq(irq
, acpi_irq
, IRQF_SHARED
, "acpi", acpi_irq
)) {
478 printk(KERN_ERR PREFIX
"SCI (IRQ%d) allocation failed\n", irq
);
479 return AE_NOT_ACQUIRED
;
486 acpi_status
acpi_os_remove_interrupt_handler(u32 irq
, acpi_osd_handler handler
)
489 free_irq(irq
, acpi_irq
);
490 acpi_irq_handler
= NULL
;
498 * Running in interpreter thread context, safe to sleep
501 void acpi_os_sleep(acpi_integer ms
)
503 schedule_timeout_interruptible(msecs_to_jiffies(ms
));
506 void acpi_os_stall(u32 us
)
514 touch_nmi_watchdog();
520 * Support ACPI 3.0 AML Timer operand
521 * Returns 64-bit free-running, monotonically increasing timer
522 * with 100ns granularity
524 u64
acpi_os_get_timer(void)
529 /* TBD: use HPET if available */
532 #ifdef CONFIG_X86_PM_TIMER
533 /* TBD: default to PM timer if HPET was not available */
536 printk(KERN_ERR PREFIX
"acpi_os_get_timer() TBD\n");
541 acpi_status
acpi_os_read_port(acpi_io_address port
, u32
* value
, u32 width
)
550 *(u8
*) value
= inb(port
);
551 } else if (width
<= 16) {
552 *(u16
*) value
= inw(port
);
553 } else if (width
<= 32) {
554 *(u32
*) value
= inl(port
);
562 EXPORT_SYMBOL(acpi_os_read_port
);
564 acpi_status
acpi_os_write_port(acpi_io_address port
, u32 value
, u32 width
)
568 } else if (width
<= 16) {
570 } else if (width
<= 32) {
579 EXPORT_SYMBOL(acpi_os_write_port
);
582 acpi_os_read_memory(acpi_physical_address phys_addr
, u32
* value
, u32 width
)
585 void __iomem
*virt_addr
;
587 virt_addr
= ioremap(phys_addr
, width
);
593 *(u8
*) value
= readb(virt_addr
);
596 *(u16
*) value
= readw(virt_addr
);
599 *(u32
*) value
= readl(virt_addr
);
611 acpi_os_write_memory(acpi_physical_address phys_addr
, u32 value
, u32 width
)
613 void __iomem
*virt_addr
;
615 virt_addr
= ioremap(phys_addr
, width
);
619 writeb(value
, virt_addr
);
622 writew(value
, virt_addr
);
625 writel(value
, virt_addr
);
637 acpi_os_read_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
638 u32
*value
, u32 width
)
643 return AE_BAD_PARAMETER
;
659 result
= raw_pci_read(pci_id
->segment
, pci_id
->bus
,
660 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
663 return (result
? AE_ERROR
: AE_OK
);
667 acpi_os_write_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
668 acpi_integer value
, u32 width
)
686 result
= raw_pci_write(pci_id
->segment
, pci_id
->bus
,
687 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
690 return (result
? AE_ERROR
: AE_OK
);
693 /* TODO: Change code to take advantage of driver model more */
694 static void acpi_os_derive_pci_id_2(acpi_handle rhandle
, /* upper bound */
695 acpi_handle chandle
, /* current node */
696 struct acpi_pci_id
**id
,
697 int *is_bridge
, u8
* bus_number
)
700 struct acpi_pci_id
*pci_id
= *id
;
703 acpi_object_type type
;
705 acpi_get_parent(chandle
, &handle
);
706 if (handle
!= rhandle
) {
707 acpi_os_derive_pci_id_2(rhandle
, handle
, &pci_id
, is_bridge
,
710 status
= acpi_get_type(handle
, &type
);
711 if ((ACPI_FAILURE(status
)) || (type
!= ACPI_TYPE_DEVICE
))
715 acpi_evaluate_integer(handle
, METHOD_NAME__ADR
, NULL
,
717 if (ACPI_SUCCESS(status
)) {
719 pci_id
->device
= ACPI_HIWORD(ACPI_LODWORD(temp
));
720 pci_id
->function
= ACPI_LOWORD(ACPI_LODWORD(temp
));
723 pci_id
->bus
= *bus_number
;
725 /* any nicer way to get bus number of bridge ? */
727 acpi_os_read_pci_configuration(pci_id
, 0x0e, &val
,
729 if (ACPI_SUCCESS(status
)
730 && ((val
& 0x7f) == 1 || (val
& 0x7f) == 2)) {
732 acpi_os_read_pci_configuration(pci_id
, 0x18,
734 if (!ACPI_SUCCESS(status
)) {
735 /* Certainly broken... FIX ME */
741 acpi_os_read_pci_configuration(pci_id
, 0x19,
743 if (ACPI_SUCCESS(status
)) {
752 void acpi_os_derive_pci_id(acpi_handle rhandle
, /* upper bound */
753 acpi_handle chandle
, /* current node */
754 struct acpi_pci_id
**id
)
757 u8 bus_number
= (*id
)->bus
;
759 acpi_os_derive_pci_id_2(rhandle
, chandle
, id
, &is_bridge
, &bus_number
);
762 static void acpi_os_execute_deferred(struct work_struct
*work
)
764 struct acpi_os_dpc
*dpc
= container_of(work
, struct acpi_os_dpc
, work
);
766 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
770 dpc
->function(dpc
->context
);
776 /*******************************************************************************
778 * FUNCTION: acpi_os_execute
780 * PARAMETERS: Type - Type of the callback
781 * Function - Function to be executed
782 * Context - Function parameters
786 * DESCRIPTION: Depending on type, either queues function for deferred execution or
787 * immediately executes function on a separate thread.
789 ******************************************************************************/
791 acpi_status
acpi_os_execute(acpi_execute_type type
,
792 acpi_osd_exec_callback function
, void *context
)
794 acpi_status status
= AE_OK
;
795 struct acpi_os_dpc
*dpc
;
796 struct workqueue_struct
*queue
;
797 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
798 "Scheduling function [%p(%p)] for deferred execution.\n",
802 return AE_BAD_PARAMETER
;
805 * Allocate/initialize DPC structure. Note that this memory will be
806 * freed by the callee. The kernel handles the work_struct list in a
807 * way that allows us to also free its memory inside the callee.
808 * Because we may want to schedule several tasks with different
809 * parameters we can't use the approach some kernel code uses of
810 * having a static work_struct.
813 dpc
= kmalloc(sizeof(struct acpi_os_dpc
), GFP_ATOMIC
);
815 return_ACPI_STATUS(AE_NO_MEMORY
);
817 dpc
->function
= function
;
818 dpc
->context
= context
;
820 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
821 queue
= (type
== OSL_NOTIFY_HANDLER
) ? kacpi_notify_wq
: kacpid_wq
;
822 if (!queue_work(queue
, &dpc
->work
)) {
823 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
824 "Call to queue_work() failed.\n"));
828 return_ACPI_STATUS(status
);
831 EXPORT_SYMBOL(acpi_os_execute
);
833 void acpi_os_wait_events_complete(void *context
)
835 flush_workqueue(kacpid_wq
);
838 EXPORT_SYMBOL(acpi_os_wait_events_complete
);
841 * Allocate the memory for a spinlock and initialize it.
843 acpi_status
acpi_os_create_lock(acpi_spinlock
* handle
)
845 spin_lock_init(*handle
);
851 * Deallocate the memory for a spinlock.
853 void acpi_os_delete_lock(acpi_spinlock handle
)
859 acpi_os_create_semaphore(u32 max_units
, u32 initial_units
, acpi_handle
* handle
)
861 struct semaphore
*sem
= NULL
;
864 sem
= acpi_os_allocate(sizeof(struct semaphore
));
867 memset(sem
, 0, sizeof(struct semaphore
));
869 sema_init(sem
, initial_units
);
871 *handle
= (acpi_handle
*) sem
;
873 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Creating semaphore[%p|%d].\n",
874 *handle
, initial_units
));
880 * TODO: A better way to delete semaphores? Linux doesn't have a
881 * 'delete_semaphore()' function -- may result in an invalid
882 * pointer dereference for non-synchronized consumers. Should
883 * we at least check for blocked threads and signal/cancel them?
886 acpi_status
acpi_os_delete_semaphore(acpi_handle handle
)
888 struct semaphore
*sem
= (struct semaphore
*)handle
;
892 return AE_BAD_PARAMETER
;
894 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Deleting semaphore[%p].\n", handle
));
903 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
904 * improvise. The process is to sleep for one scheduler quantum
905 * until the semaphore becomes available. Downside is that this
906 * may result in starvation for timeout-based waits when there's
907 * lots of semaphore activity.
909 * TODO: Support for units > 1?
911 acpi_status
acpi_os_wait_semaphore(acpi_handle handle
, u32 units
, u16 timeout
)
913 acpi_status status
= AE_OK
;
914 struct semaphore
*sem
= (struct semaphore
*)handle
;
918 if (!sem
|| (units
< 1))
919 return AE_BAD_PARAMETER
;
924 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Waiting for semaphore[%p|%d|%d]\n",
925 handle
, units
, timeout
));
928 * This can be called during resume with interrupts off.
929 * Like boot-time, we should be single threaded and will
930 * always get the lock if we try -- timeout or not.
931 * If this doesn't succeed, then we will oops courtesy of
932 * might_sleep() in down().
934 if (!down_trylock(sem
))
941 * A zero timeout value indicates that we shouldn't wait - just
942 * acquire the semaphore if available otherwise return AE_TIME
943 * (a.k.a. 'would block').
946 if (down_trylock(sem
))
954 case ACPI_WAIT_FOREVER
:
963 // TODO: A better timeout algorithm?
966 static const int quantum_ms
= 1000 / HZ
;
968 ret
= down_trylock(sem
);
969 for (i
= timeout
; (i
> 0 && ret
!= 0); i
-= quantum_ms
) {
970 schedule_timeout_interruptible(1);
971 ret
= down_trylock(sem
);
980 if (ACPI_FAILURE(status
)) {
981 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
982 "Failed to acquire semaphore[%p|%d|%d], %s",
983 handle
, units
, timeout
,
984 acpi_format_exception(status
)));
986 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
987 "Acquired semaphore[%p|%d|%d]", handle
,
995 * TODO: Support for units > 1?
997 acpi_status
acpi_os_signal_semaphore(acpi_handle handle
, u32 units
)
999 struct semaphore
*sem
= (struct semaphore
*)handle
;
1002 if (!sem
|| (units
< 1))
1003 return AE_BAD_PARAMETER
;
1008 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Signaling semaphore[%p|%d]\n", handle
,
1016 #ifdef ACPI_FUTURE_USAGE
1017 u32
acpi_os_get_line(char *buffer
)
1020 #ifdef ENABLE_DEBUGGER
1021 if (acpi_in_debugger
) {
1024 kdb_read(buffer
, sizeof(line_buf
));
1026 /* remove the CR kdb includes */
1027 chars
= strlen(buffer
) - 1;
1028 buffer
[chars
] = '\0';
1034 #endif /* ACPI_FUTURE_USAGE */
1036 acpi_status
acpi_os_signal(u32 function
, void *info
)
1039 case ACPI_SIGNAL_FATAL
:
1040 printk(KERN_ERR PREFIX
"Fatal opcode executed\n");
1042 case ACPI_SIGNAL_BREAKPOINT
:
1045 * ACPI spec. says to treat it as a NOP unless
1046 * you are debugging. So if/when we integrate
1047 * AML debugger into the kernel debugger its
1048 * hook will go here. But until then it is
1049 * not useful to print anything on breakpoints.
1059 static int __init
acpi_os_name_setup(char *str
)
1061 char *p
= acpi_os_name
;
1062 int count
= ACPI_MAX_OVERRIDE_LEN
- 1;
1067 for (; count
-- && str
&& *str
; str
++) {
1068 if (isalnum(*str
) || *str
== ' ' || *str
== ':')
1070 else if (*str
== '\'' || *str
== '"')
1081 __setup("acpi_os_name=", acpi_os_name_setup
);
1083 static void __init
set_osi_linux(unsigned int enable
)
1085 if (osi_linux
.enable
!= enable
) {
1086 osi_linux
.enable
= enable
;
1087 printk(KERN_NOTICE PREFIX
"%sed _OSI(Linux)\n",
1088 enable
? "Add": "Delet");
1093 static void __init
acpi_cmdline_osi_linux(unsigned int enable
)
1095 osi_linux
.cmdline
= 1; /* cmdline set the default */
1096 set_osi_linux(enable
);
1101 void __init
acpi_dmi_osi_linux(int enable
, const struct dmi_system_id
*d
)
1103 osi_linux
.dmi
= 1; /* DMI knows that this box asks OSI(Linux) */
1105 printk(KERN_NOTICE PREFIX
"DMI detected: %s\n", d
->ident
);
1110 osi_linux
.known
= 1; /* DMI knows which OSI(Linux) default needed */
1112 set_osi_linux(enable
);
1118 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1120 * empty string disables _OSI
1121 * string starting with '!' disables that string
1122 * otherwise string is added to list, augmenting built-in strings
1124 int __init
acpi_osi_setup(char *str
)
1126 if (str
== NULL
|| *str
== '\0') {
1127 printk(KERN_INFO PREFIX
"_OSI method disabled\n");
1128 acpi_gbl_create_osi_method
= FALSE
;
1129 } else if (!strcmp("!Linux", str
)) {
1130 acpi_cmdline_osi_linux(0); /* !enable */
1131 } else if (*str
== '!') {
1132 if (acpi_osi_invalidate(++str
) == AE_OK
)
1133 printk(KERN_INFO PREFIX
"Deleted _OSI(%s)\n", str
);
1134 } else if (!strcmp("Linux", str
)) {
1135 acpi_cmdline_osi_linux(1); /* enable */
1136 } else if (*osi_additional_string
== '\0') {
1137 strncpy(osi_additional_string
, str
, OSI_STRING_LENGTH_MAX
);
1138 printk(KERN_INFO PREFIX
"Added _OSI(%s)\n", str
);
1144 __setup("acpi_osi=", acpi_osi_setup
);
1146 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1147 static int __init
acpi_serialize_setup(char *str
)
1149 printk(KERN_INFO PREFIX
"serialize enabled\n");
1151 acpi_gbl_all_methods_serialized
= TRUE
;
1156 __setup("acpi_serialize", acpi_serialize_setup
);
1159 * Wake and Run-Time GPES are expected to be separate.
1160 * We disable wake-GPEs at run-time to prevent spurious
1163 * However, if a system exists that shares Wake and
1164 * Run-time events on the same GPE this flag is available
1165 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1167 static int __init
acpi_wake_gpes_always_on_setup(char *str
)
1169 printk(KERN_INFO PREFIX
"wake GPEs not disabled\n");
1171 acpi_gbl_leave_wake_gpes_disabled
= FALSE
;
1176 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup
);
1178 /* Check of resource interference between native drivers and ACPI
1179 * OperationRegions (SystemIO and System Memory only).
1180 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1181 * in arbitrary AML code and can interfere with legacy drivers.
1182 * acpi_enforce_resources= can be set to:
1185 * -> further driver trying to access the resources will not load
1186 * - lax (default) (1)
1187 * -> further driver trying to access the resources will load, but you
1188 * get a system message that something might go wrong...
1191 * -> ACPI Operation Region resources will not be registered
1194 #define ENFORCE_RESOURCES_STRICT 2
1195 #define ENFORCE_RESOURCES_LAX 1
1196 #define ENFORCE_RESOURCES_NO 0
1198 static unsigned int acpi_enforce_resources
= ENFORCE_RESOURCES_LAX
;
1200 static int __init
acpi_enforce_resources_setup(char *str
)
1202 if (str
== NULL
|| *str
== '\0')
1205 if (!strcmp("strict", str
))
1206 acpi_enforce_resources
= ENFORCE_RESOURCES_STRICT
;
1207 else if (!strcmp("lax", str
))
1208 acpi_enforce_resources
= ENFORCE_RESOURCES_LAX
;
1209 else if (!strcmp("no", str
))
1210 acpi_enforce_resources
= ENFORCE_RESOURCES_NO
;
1215 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup
);
1217 /* Check for resource conflicts between ACPI OperationRegions and native
1219 int acpi_check_resource_conflict(struct resource
*res
)
1221 struct acpi_res_list
*res_list_elem
;
1225 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1227 if (!(res
->flags
& IORESOURCE_IO
) && !(res
->flags
& IORESOURCE_MEM
))
1230 ioport
= res
->flags
& IORESOURCE_IO
;
1232 spin_lock(&acpi_res_lock
);
1233 list_for_each_entry(res_list_elem
, &resource_list_head
,
1235 if (ioport
&& (res_list_elem
->resource_type
1236 != ACPI_ADR_SPACE_SYSTEM_IO
))
1238 if (!ioport
&& (res_list_elem
->resource_type
1239 != ACPI_ADR_SPACE_SYSTEM_MEMORY
))
1242 if (res
->end
< res_list_elem
->start
1243 || res_list_elem
->end
< res
->start
)
1248 spin_unlock(&acpi_res_lock
);
1251 if (acpi_enforce_resources
!= ENFORCE_RESOURCES_NO
) {
1252 <<<<<<< HEAD
:drivers
/acpi
/osl
.c
1253 printk(KERN_INFO
"%sACPI: %s resource %s [0x%llx-0x%llx]"
1255 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
1256 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/osl
.c
1257 " conflicts with ACPI region %s"
1258 " [0x%llx-0x%llx]\n",
1259 acpi_enforce_resources
== ENFORCE_RESOURCES_LAX
1260 ? KERN_WARNING
: KERN_ERR
,
1261 ioport
? "I/O" : "Memory", res
->name
,
1262 (long long) res
->start
, (long long) res
->end
,
1263 res_list_elem
->name
,
1264 (long long) res_list_elem
->start
,
1265 (long long) res_list_elem
->end
);
1266 printk(KERN_INFO
"ACPI: Device needs an ACPI driver\n");
1268 if (acpi_enforce_resources
== ENFORCE_RESOURCES_STRICT
)
1273 EXPORT_SYMBOL(acpi_check_resource_conflict
);
1275 int acpi_check_region(resource_size_t start
, resource_size_t n
,
1278 struct resource res
= {
1280 .end
= start
+ n
- 1,
1282 .flags
= IORESOURCE_IO
,
1285 return acpi_check_resource_conflict(&res
);
1287 EXPORT_SYMBOL(acpi_check_region
);
1289 int acpi_check_mem_region(resource_size_t start
, resource_size_t n
,
1292 struct resource res
= {
1294 .end
= start
+ n
- 1,
1296 .flags
= IORESOURCE_MEM
,
1299 return acpi_check_resource_conflict(&res
);
1302 EXPORT_SYMBOL(acpi_check_mem_region
);
1305 * Acquire a spinlock.
1307 * handle is a pointer to the spinlock_t.
1310 acpi_cpu_flags
acpi_os_acquire_lock(acpi_spinlock lockp
)
1312 acpi_cpu_flags flags
;
1313 spin_lock_irqsave(lockp
, flags
);
1318 * Release a spinlock. See above.
1321 void acpi_os_release_lock(acpi_spinlock lockp
, acpi_cpu_flags flags
)
1323 spin_unlock_irqrestore(lockp
, flags
);
1326 #ifndef ACPI_USE_LOCAL_CACHE
1328 /*******************************************************************************
1330 * FUNCTION: acpi_os_create_cache
1332 * PARAMETERS: name - Ascii name for the cache
1333 * size - Size of each cached object
1334 * depth - Maximum depth of the cache (in objects) <ignored>
1335 * cache - Where the new cache object is returned
1339 * DESCRIPTION: Create a cache object
1341 ******************************************************************************/
1344 acpi_os_create_cache(char *name
, u16 size
, u16 depth
, acpi_cache_t
** cache
)
1346 *cache
= kmem_cache_create(name
, size
, 0, 0, NULL
);
1353 /*******************************************************************************
1355 * FUNCTION: acpi_os_purge_cache
1357 * PARAMETERS: Cache - Handle to cache object
1361 * DESCRIPTION: Free all objects within the requested cache.
1363 ******************************************************************************/
1365 acpi_status
acpi_os_purge_cache(acpi_cache_t
* cache
)
1367 kmem_cache_shrink(cache
);
1371 /*******************************************************************************
1373 * FUNCTION: acpi_os_delete_cache
1375 * PARAMETERS: Cache - Handle to cache object
1379 * DESCRIPTION: Free all objects within the requested cache and delete the
1382 ******************************************************************************/
1384 acpi_status
acpi_os_delete_cache(acpi_cache_t
* cache
)
1386 kmem_cache_destroy(cache
);
1390 /*******************************************************************************
1392 * FUNCTION: acpi_os_release_object
1394 * PARAMETERS: Cache - Handle to cache object
1395 * Object - The object to be released
1399 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1400 * the object is deleted.
1402 ******************************************************************************/
1404 acpi_status
acpi_os_release_object(acpi_cache_t
* cache
, void *object
)
1406 kmem_cache_free(cache
, object
);
1411 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1413 * Returns 0 on success
1415 static int acpi_dmi_dump(void)
1421 printk(KERN_NOTICE PREFIX
"DMI System Vendor: %s\n",
1422 dmi_get_system_info(DMI_SYS_VENDOR
));
1423 printk(KERN_NOTICE PREFIX
"DMI Product Name: %s\n",
1424 dmi_get_system_info(DMI_PRODUCT_NAME
));
1425 printk(KERN_NOTICE PREFIX
"DMI Product Version: %s\n",
1426 dmi_get_system_info(DMI_PRODUCT_VERSION
));
1427 printk(KERN_NOTICE PREFIX
"DMI Board Name: %s\n",
1428 dmi_get_system_info(DMI_BOARD_NAME
));
1429 printk(KERN_NOTICE PREFIX
"DMI BIOS Vendor: %s\n",
1430 dmi_get_system_info(DMI_BIOS_VENDOR
));
1431 printk(KERN_NOTICE PREFIX
"DMI BIOS Date: %s\n",
1432 dmi_get_system_info(DMI_BIOS_DATE
));
1438 /******************************************************************************
1440 * FUNCTION: acpi_os_validate_interface
1442 * PARAMETERS: interface - Requested interface to be validated
1444 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1446 * DESCRIPTION: Match an interface string to the interfaces supported by the
1447 * host. Strings originate from an AML call to the _OSI method.
1449 *****************************************************************************/
1452 acpi_os_validate_interface (char *interface
)
1454 if (!strncmp(osi_additional_string
, interface
, OSI_STRING_LENGTH_MAX
))
1456 if (!strcmp("Linux", interface
)) {
1458 printk(KERN_NOTICE PREFIX
1459 "BIOS _OSI(Linux) query %s%s\n",
1460 osi_linux
.enable
? "honored" : "ignored",
1461 osi_linux
.cmdline
? " via cmdline" :
1462 osi_linux
.dmi
? " via DMI" : "");
1464 if (!osi_linux
.dmi
) {
1465 if (acpi_dmi_dump())
1466 printk(KERN_NOTICE PREFIX
1467 "[please extract dmidecode output]\n");
1468 printk(KERN_NOTICE PREFIX
1469 "Please send DMI info above to "
1470 "linux-acpi@vger.kernel.org\n");
1472 if (!osi_linux
.known
&& !osi_linux
.cmdline
) {
1473 printk(KERN_NOTICE PREFIX
1474 "If \"acpi_osi=%sLinux\" works better, "
1475 "please notify linux-acpi@vger.kernel.org\n",
1476 osi_linux
.enable
? "!" : "");
1479 if (osi_linux
.enable
)
1485 /******************************************************************************
1487 * FUNCTION: acpi_os_validate_address
1489 * PARAMETERS: space_id - ACPI space ID
1490 * address - Physical address
1491 * length - Address length
1493 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1494 * should return AE_AML_ILLEGAL_ADDRESS.
1496 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1497 * the addresses accessed by AML operation regions.
1499 *****************************************************************************/
1502 acpi_os_validate_address (
1504 acpi_physical_address address
,
1508 struct acpi_res_list
*res
;
1509 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1513 case ACPI_ADR_SPACE_SYSTEM_IO
:
1514 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
1515 /* Only interference checks against SystemIO and SytemMemory
1517 res
= kzalloc(sizeof(struct acpi_res_list
), GFP_KERNEL
);
1520 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1521 strlcpy(res
->name
, name
, 5);
1522 res
->start
= address
;
1523 res
->end
= address
+ length
- 1;
1524 res
->resource_type
= space_id
;
1525 spin_lock(&acpi_res_lock
);
1526 list_add(&res
->resource_list
, &resource_list_head
);
1527 spin_unlock(&acpi_res_lock
);
1528 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1529 "name: %s\n", (space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
1530 ? "SystemIO" : "System Memory",
1531 (unsigned long long)res
->start
,
1532 (unsigned long long)res
->end
,
1535 case ACPI_ADR_SPACE_PCI_CONFIG
:
1536 case ACPI_ADR_SPACE_EC
:
1537 case ACPI_ADR_SPACE_SMBUS
:
1538 case ACPI_ADR_SPACE_CMOS
:
1539 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
1540 case ACPI_ADR_SPACE_DATA_TABLE
:
1541 case ACPI_ADR_SPACE_FIXED_HARDWARE
: