2 * acpi_osl.c - OS-dependent functions ($Revision: 83 $)
4 * Copyright (C) 2000 Andrew Henroid
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * Copyright (c) 2008 Intel Corporation
8 * Author: Matthew Wilcox <willy@linux.intel.com>
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
34 #include <linux/pci.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 <linux/acpi.h>
41 #include <linux/efi.h>
42 #include <linux/ioport.h>
43 #include <linux/list.h>
44 #include <linux/jiffies.h>
45 #include <linux/semaphore.h>
48 #include <asm/uaccess.h>
50 #include <acpi/acpi.h>
51 #include <acpi/acpi_bus.h>
52 #include <acpi/processor.h>
54 #define _COMPONENT ACPI_OS_SERVICES
55 ACPI_MODULE_NAME("osl");
56 #define PREFIX "ACPI: "
58 acpi_osd_exec_callback function
;
60 struct work_struct work
;
63 #ifdef CONFIG_ACPI_CUSTOM_DSDT
64 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
67 #ifdef ENABLE_DEBUGGER
68 #include <linux/kdb.h>
70 /* stuff for debugger support */
72 EXPORT_SYMBOL(acpi_in_debugger
);
74 extern char line_buf
[80];
75 #endif /*ENABLE_DEBUGGER */
77 static unsigned int acpi_irq_irq
;
78 static acpi_osd_handler acpi_irq_handler
;
79 static void *acpi_irq_context
;
80 static struct workqueue_struct
*kacpid_wq
;
81 static struct workqueue_struct
*kacpi_notify_wq
;
83 struct acpi_res_list
{
84 resource_size_t start
;
86 acpi_adr_space_type resource_type
; /* IO port, System memory, ...*/
87 char name
[5]; /* only can have a length of 4 chars, make use of this
88 one instead of res->name, no need to kalloc then */
89 struct list_head resource_list
;
92 static LIST_HEAD(resource_list_head
);
93 static DEFINE_SPINLOCK(acpi_res_lock
);
95 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
96 static char osi_additional_string
[OSI_STRING_LENGTH_MAX
];
99 * The story of _OSI(Linux)
101 * From pre-history through Linux-2.6.22,
102 * Linux responded TRUE upon a BIOS OSI(Linux) query.
104 * Unfortunately, reference BIOS writers got wind of this
105 * and put OSI(Linux) in their example code, quickly exposing
106 * this string as ill-conceived and opening the door to
107 * an un-bounded number of BIOS incompatibilities.
109 * For example, OSI(Linux) was used on resume to re-POST a
110 * video card on one system, because Linux at that time
111 * could not do a speedy restore in its native driver.
112 * But then upon gaining quick native restore capability,
113 * Linux has no way to tell the BIOS to skip the time-consuming
114 * POST -- putting Linux at a permanent performance disadvantage.
115 * On another system, the BIOS writer used OSI(Linux)
116 * to infer native OS support for IPMI! On other systems,
117 * OSI(Linux) simply got in the way of Linux claiming to
118 * be compatible with other operating systems, exposing
119 * BIOS issues such as skipped device initialization.
121 * So "Linux" turned out to be a really poor chose of
122 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
124 * BIOS writers should NOT query _OSI(Linux) on future systems.
125 * Linux will complain on the console when it sees it, and return FALSE.
126 * To get Linux to return TRUE for your system will require
127 * a kernel source update to add a DMI entry,
128 * or boot with "acpi_osi=Linux"
131 static struct osi_linux
{
132 unsigned int enable
:1;
134 unsigned int cmdline
:1;
135 unsigned int known
:1;
136 } osi_linux
= { 0, 0, 0, 0};
138 static void __init
acpi_request_region (struct acpi_generic_address
*addr
,
139 unsigned int length
, char *desc
)
141 struct resource
*res
;
143 if (!addr
->address
|| !length
)
146 if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
147 res
= request_region(addr
->address
, length
, desc
);
148 else if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
149 res
= request_mem_region(addr
->address
, length
, desc
);
152 static int __init
acpi_reserve_resources(void)
154 acpi_request_region(&acpi_gbl_FADT
.xpm1a_event_block
, acpi_gbl_FADT
.pm1_event_length
,
155 "ACPI PM1a_EVT_BLK");
157 acpi_request_region(&acpi_gbl_FADT
.xpm1b_event_block
, acpi_gbl_FADT
.pm1_event_length
,
158 "ACPI PM1b_EVT_BLK");
160 acpi_request_region(&acpi_gbl_FADT
.xpm1a_control_block
, acpi_gbl_FADT
.pm1_control_length
,
161 "ACPI PM1a_CNT_BLK");
163 acpi_request_region(&acpi_gbl_FADT
.xpm1b_control_block
, acpi_gbl_FADT
.pm1_control_length
,
164 "ACPI PM1b_CNT_BLK");
166 if (acpi_gbl_FADT
.pm_timer_length
== 4)
167 acpi_request_region(&acpi_gbl_FADT
.xpm_timer_block
, 4, "ACPI PM_TMR");
169 acpi_request_region(&acpi_gbl_FADT
.xpm2_control_block
, acpi_gbl_FADT
.pm2_control_length
,
172 /* Length of GPE blocks must be a non-negative multiple of 2 */
174 if (!(acpi_gbl_FADT
.gpe0_block_length
& 0x1))
175 acpi_request_region(&acpi_gbl_FADT
.xgpe0_block
,
176 acpi_gbl_FADT
.gpe0_block_length
, "ACPI GPE0_BLK");
178 if (!(acpi_gbl_FADT
.gpe1_block_length
& 0x1))
179 acpi_request_region(&acpi_gbl_FADT
.xgpe1_block
,
180 acpi_gbl_FADT
.gpe1_block_length
, "ACPI GPE1_BLK");
184 device_initcall(acpi_reserve_resources
);
186 acpi_status __init
acpi_os_initialize(void)
191 acpi_status
acpi_os_initialize1(void)
193 kacpid_wq
= create_singlethread_workqueue("kacpid");
194 kacpi_notify_wq
= create_singlethread_workqueue("kacpi_notify");
196 BUG_ON(!kacpi_notify_wq
);
200 acpi_status
acpi_os_terminate(void)
202 if (acpi_irq_handler
) {
203 acpi_os_remove_interrupt_handler(acpi_irq_irq
,
207 destroy_workqueue(kacpid_wq
);
208 destroy_workqueue(kacpi_notify_wq
);
213 void acpi_os_printf(const char *fmt
, ...)
217 acpi_os_vprintf(fmt
, args
);
221 void acpi_os_vprintf(const char *fmt
, va_list args
)
223 static char buffer
[512];
225 vsprintf(buffer
, fmt
, args
);
227 #ifdef ENABLE_DEBUGGER
228 if (acpi_in_debugger
) {
229 kdb_printf("%s", buffer
);
231 printk(KERN_CONT
"%s", buffer
);
234 printk(KERN_CONT
"%s", buffer
);
238 acpi_physical_address __init
acpi_os_get_root_pointer(void)
241 if (efi
.acpi20
!= EFI_INVALID_TABLE_ADDR
)
243 else if (efi
.acpi
!= EFI_INVALID_TABLE_ADDR
)
246 printk(KERN_ERR PREFIX
247 "System description tables not found\n");
251 acpi_physical_address pa
= 0;
253 acpi_find_root_pointer(&pa
);
258 void __iomem
*__init_refok
259 acpi_os_map_memory(acpi_physical_address phys
, acpi_size size
)
261 if (phys
> ULONG_MAX
) {
262 printk(KERN_ERR PREFIX
"Cannot map memory that high\n");
265 if (acpi_gbl_permanent_mmap
)
267 * ioremap checks to ensure this is in reserved space
269 return ioremap((unsigned long)phys
, size
);
271 return __acpi_map_table((unsigned long)phys
, size
);
273 EXPORT_SYMBOL_GPL(acpi_os_map_memory
);
275 void __ref
acpi_os_unmap_memory(void __iomem
*virt
, acpi_size size
)
277 if (acpi_gbl_permanent_mmap
)
280 __acpi_unmap_table(virt
, size
);
282 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory
);
284 void __init
early_acpi_os_unmap_memory(void __iomem
*virt
, acpi_size size
)
286 if (!acpi_gbl_permanent_mmap
)
287 __acpi_unmap_table(virt
, size
);
290 #ifdef ACPI_FUTURE_USAGE
292 acpi_os_get_physical_address(void *virt
, acpi_physical_address
* phys
)
295 return AE_BAD_PARAMETER
;
297 *phys
= virt_to_phys(virt
);
303 #define ACPI_MAX_OVERRIDE_LEN 100
305 static char acpi_os_name
[ACPI_MAX_OVERRIDE_LEN
];
308 acpi_os_predefined_override(const struct acpi_predefined_names
*init_val
,
309 acpi_string
* new_val
)
311 if (!init_val
|| !new_val
)
312 return AE_BAD_PARAMETER
;
315 if (!memcmp(init_val
->name
, "_OS_", 4) && strlen(acpi_os_name
)) {
316 printk(KERN_INFO PREFIX
"Overriding _OS definition to '%s'\n",
318 *new_val
= acpi_os_name
;
325 acpi_os_table_override(struct acpi_table_header
* existing_table
,
326 struct acpi_table_header
** new_table
)
328 if (!existing_table
|| !new_table
)
329 return AE_BAD_PARAMETER
;
333 #ifdef CONFIG_ACPI_CUSTOM_DSDT
334 if (strncmp(existing_table
->signature
, "DSDT", 4) == 0)
335 *new_table
= (struct acpi_table_header
*)AmlCode
;
337 if (*new_table
!= NULL
) {
338 printk(KERN_WARNING PREFIX
"Override [%4.4s-%8.8s], "
339 "this is unsafe: tainting kernel\n",
340 existing_table
->signature
,
341 existing_table
->oem_table_id
);
342 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE
);
347 static irqreturn_t
acpi_irq(int irq
, void *dev_id
)
351 handled
= (*acpi_irq_handler
) (acpi_irq_context
);
361 acpi_os_install_interrupt_handler(u32 gsi
, acpi_osd_handler handler
,
366 acpi_irq_stats_init();
369 * Ignore the GSI from the core, and use the value in our copy of the
370 * FADT. It may not be the same if an interrupt source override exists
373 gsi
= acpi_gbl_FADT
.sci_interrupt
;
374 if (acpi_gsi_to_irq(gsi
, &irq
) < 0) {
375 printk(KERN_ERR PREFIX
"SCI (ACPI GSI %d) not registered\n",
380 acpi_irq_handler
= handler
;
381 acpi_irq_context
= context
;
382 if (request_irq(irq
, acpi_irq
, IRQF_SHARED
, "acpi", acpi_irq
)) {
383 printk(KERN_ERR PREFIX
"SCI (IRQ%d) allocation failed\n", irq
);
384 return AE_NOT_ACQUIRED
;
391 acpi_status
acpi_os_remove_interrupt_handler(u32 irq
, acpi_osd_handler handler
)
394 free_irq(irq
, acpi_irq
);
395 acpi_irq_handler
= NULL
;
403 * Running in interpreter thread context, safe to sleep
406 void acpi_os_sleep(acpi_integer ms
)
408 schedule_timeout_interruptible(msecs_to_jiffies(ms
));
411 void acpi_os_stall(u32 us
)
419 touch_nmi_watchdog();
425 * Support ACPI 3.0 AML Timer operand
426 * Returns 64-bit free-running, monotonically increasing timer
427 * with 100ns granularity
429 u64
acpi_os_get_timer(void)
434 /* TBD: use HPET if available */
437 #ifdef CONFIG_X86_PM_TIMER
438 /* TBD: default to PM timer if HPET was not available */
441 printk(KERN_ERR PREFIX
"acpi_os_get_timer() TBD\n");
446 acpi_status
acpi_os_read_port(acpi_io_address port
, u32
* value
, u32 width
)
455 *(u8
*) value
= inb(port
);
456 } else if (width
<= 16) {
457 *(u16
*) value
= inw(port
);
458 } else if (width
<= 32) {
459 *(u32
*) value
= inl(port
);
467 EXPORT_SYMBOL(acpi_os_read_port
);
469 acpi_status
acpi_os_write_port(acpi_io_address port
, u32 value
, u32 width
)
473 } else if (width
<= 16) {
475 } else if (width
<= 32) {
484 EXPORT_SYMBOL(acpi_os_write_port
);
487 acpi_os_read_memory(acpi_physical_address phys_addr
, u32
* value
, u32 width
)
490 void __iomem
*virt_addr
;
492 virt_addr
= ioremap(phys_addr
, width
);
498 *(u8
*) value
= readb(virt_addr
);
501 *(u16
*) value
= readw(virt_addr
);
504 *(u32
*) value
= readl(virt_addr
);
516 acpi_os_write_memory(acpi_physical_address phys_addr
, u32 value
, u32 width
)
518 void __iomem
*virt_addr
;
520 virt_addr
= ioremap(phys_addr
, width
);
524 writeb(value
, virt_addr
);
527 writew(value
, virt_addr
);
530 writel(value
, virt_addr
);
542 acpi_os_read_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
543 u32
*value
, u32 width
)
548 return AE_BAD_PARAMETER
;
564 result
= raw_pci_read(pci_id
->segment
, pci_id
->bus
,
565 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
568 return (result
? AE_ERROR
: AE_OK
);
572 acpi_os_write_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
573 acpi_integer value
, u32 width
)
591 result
= raw_pci_write(pci_id
->segment
, pci_id
->bus
,
592 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
595 return (result
? AE_ERROR
: AE_OK
);
598 /* TODO: Change code to take advantage of driver model more */
599 static void acpi_os_derive_pci_id_2(acpi_handle rhandle
, /* upper bound */
600 acpi_handle chandle
, /* current node */
601 struct acpi_pci_id
**id
,
602 int *is_bridge
, u8
* bus_number
)
605 struct acpi_pci_id
*pci_id
= *id
;
607 unsigned long long temp
;
608 acpi_object_type type
;
610 acpi_get_parent(chandle
, &handle
);
611 if (handle
!= rhandle
) {
612 acpi_os_derive_pci_id_2(rhandle
, handle
, &pci_id
, is_bridge
,
615 status
= acpi_get_type(handle
, &type
);
616 if ((ACPI_FAILURE(status
)) || (type
!= ACPI_TYPE_DEVICE
))
619 status
= acpi_evaluate_integer(handle
, METHOD_NAME__ADR
, NULL
,
621 if (ACPI_SUCCESS(status
)) {
623 pci_id
->device
= ACPI_HIWORD(ACPI_LODWORD(temp
));
624 pci_id
->function
= ACPI_LOWORD(ACPI_LODWORD(temp
));
627 pci_id
->bus
= *bus_number
;
629 /* any nicer way to get bus number of bridge ? */
631 acpi_os_read_pci_configuration(pci_id
, 0x0e, &val
,
633 if (ACPI_SUCCESS(status
)
634 && ((val
& 0x7f) == 1 || (val
& 0x7f) == 2)) {
636 acpi_os_read_pci_configuration(pci_id
, 0x18,
638 if (!ACPI_SUCCESS(status
)) {
639 /* Certainly broken... FIX ME */
645 acpi_os_read_pci_configuration(pci_id
, 0x19,
647 if (ACPI_SUCCESS(status
)) {
656 void acpi_os_derive_pci_id(acpi_handle rhandle
, /* upper bound */
657 acpi_handle chandle
, /* current node */
658 struct acpi_pci_id
**id
)
661 u8 bus_number
= (*id
)->bus
;
663 acpi_os_derive_pci_id_2(rhandle
, chandle
, id
, &is_bridge
, &bus_number
);
666 static void acpi_os_execute_deferred(struct work_struct
*work
)
668 struct acpi_os_dpc
*dpc
= container_of(work
, struct acpi_os_dpc
, work
);
670 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
674 dpc
->function(dpc
->context
);
680 static void acpi_os_execute_hp_deferred(struct work_struct
*work
)
682 struct acpi_os_dpc
*dpc
= container_of(work
, struct acpi_os_dpc
, work
);
684 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
688 acpi_os_wait_events_complete(NULL
);
690 dpc
->function(dpc
->context
);
696 /*******************************************************************************
698 * FUNCTION: acpi_os_execute
700 * PARAMETERS: Type - Type of the callback
701 * Function - Function to be executed
702 * Context - Function parameters
706 * DESCRIPTION: Depending on type, either queues function for deferred execution or
707 * immediately executes function on a separate thread.
709 ******************************************************************************/
711 static acpi_status
__acpi_os_execute(acpi_execute_type type
,
712 acpi_osd_exec_callback function
, void *context
, int hp
)
714 acpi_status status
= AE_OK
;
715 struct acpi_os_dpc
*dpc
;
716 struct workqueue_struct
*queue
;
718 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
719 "Scheduling function [%p(%p)] for deferred execution.\n",
723 return AE_BAD_PARAMETER
;
726 * Allocate/initialize DPC structure. Note that this memory will be
727 * freed by the callee. The kernel handles the work_struct list in a
728 * way that allows us to also free its memory inside the callee.
729 * Because we may want to schedule several tasks with different
730 * parameters we can't use the approach some kernel code uses of
731 * having a static work_struct.
734 dpc
= kmalloc(sizeof(struct acpi_os_dpc
), GFP_ATOMIC
);
738 dpc
->function
= function
;
739 dpc
->context
= context
;
742 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
743 queue
= (type
== OSL_NOTIFY_HANDLER
) ?
744 kacpi_notify_wq
: kacpid_wq
;
745 ret
= queue_work(queue
, &dpc
->work
);
747 INIT_WORK(&dpc
->work
, acpi_os_execute_hp_deferred
);
748 ret
= schedule_work(&dpc
->work
);
752 printk(KERN_ERR PREFIX
753 "Call to queue_work() failed.\n");
760 acpi_status
acpi_os_execute(acpi_execute_type type
,
761 acpi_osd_exec_callback function
, void *context
)
763 return __acpi_os_execute(type
, function
, context
, 0);
765 EXPORT_SYMBOL(acpi_os_execute
);
767 acpi_status
acpi_os_hotplug_execute(acpi_osd_exec_callback function
,
770 return __acpi_os_execute(0, function
, context
, 1);
773 void acpi_os_wait_events_complete(void *context
)
775 flush_workqueue(kacpid_wq
);
776 flush_workqueue(kacpi_notify_wq
);
779 EXPORT_SYMBOL(acpi_os_wait_events_complete
);
782 * Allocate the memory for a spinlock and initialize it.
784 acpi_status
acpi_os_create_lock(acpi_spinlock
* handle
)
786 spin_lock_init(*handle
);
792 * Deallocate the memory for a spinlock.
794 void acpi_os_delete_lock(acpi_spinlock handle
)
800 acpi_os_create_semaphore(u32 max_units
, u32 initial_units
, acpi_handle
* handle
)
802 struct semaphore
*sem
= NULL
;
804 sem
= acpi_os_allocate(sizeof(struct semaphore
));
807 memset(sem
, 0, sizeof(struct semaphore
));
809 sema_init(sem
, initial_units
);
811 *handle
= (acpi_handle
*) sem
;
813 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Creating semaphore[%p|%d].\n",
814 *handle
, initial_units
));
820 * TODO: A better way to delete semaphores? Linux doesn't have a
821 * 'delete_semaphore()' function -- may result in an invalid
822 * pointer dereference for non-synchronized consumers. Should
823 * we at least check for blocked threads and signal/cancel them?
826 acpi_status
acpi_os_delete_semaphore(acpi_handle handle
)
828 struct semaphore
*sem
= (struct semaphore
*)handle
;
831 return AE_BAD_PARAMETER
;
833 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Deleting semaphore[%p].\n", handle
));
835 BUG_ON(!list_empty(&sem
->wait_list
));
843 * TODO: Support for units > 1?
845 acpi_status
acpi_os_wait_semaphore(acpi_handle handle
, u32 units
, u16 timeout
)
847 acpi_status status
= AE_OK
;
848 struct semaphore
*sem
= (struct semaphore
*)handle
;
852 if (!sem
|| (units
< 1))
853 return AE_BAD_PARAMETER
;
858 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Waiting for semaphore[%p|%d|%d]\n",
859 handle
, units
, timeout
));
861 if (timeout
== ACPI_WAIT_FOREVER
)
862 jiffies
= MAX_SCHEDULE_TIMEOUT
;
864 jiffies
= msecs_to_jiffies(timeout
);
866 ret
= down_timeout(sem
, jiffies
);
870 if (ACPI_FAILURE(status
)) {
871 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
872 "Failed to acquire semaphore[%p|%d|%d], %s",
873 handle
, units
, timeout
,
874 acpi_format_exception(status
)));
876 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
877 "Acquired semaphore[%p|%d|%d]", handle
,
885 * TODO: Support for units > 1?
887 acpi_status
acpi_os_signal_semaphore(acpi_handle handle
, u32 units
)
889 struct semaphore
*sem
= (struct semaphore
*)handle
;
891 if (!sem
|| (units
< 1))
892 return AE_BAD_PARAMETER
;
897 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Signaling semaphore[%p|%d]\n", handle
,
905 #ifdef ACPI_FUTURE_USAGE
906 u32
acpi_os_get_line(char *buffer
)
909 #ifdef ENABLE_DEBUGGER
910 if (acpi_in_debugger
) {
913 kdb_read(buffer
, sizeof(line_buf
));
915 /* remove the CR kdb includes */
916 chars
= strlen(buffer
) - 1;
917 buffer
[chars
] = '\0';
923 #endif /* ACPI_FUTURE_USAGE */
925 acpi_status
acpi_os_signal(u32 function
, void *info
)
928 case ACPI_SIGNAL_FATAL
:
929 printk(KERN_ERR PREFIX
"Fatal opcode executed\n");
931 case ACPI_SIGNAL_BREAKPOINT
:
934 * ACPI spec. says to treat it as a NOP unless
935 * you are debugging. So if/when we integrate
936 * AML debugger into the kernel debugger its
937 * hook will go here. But until then it is
938 * not useful to print anything on breakpoints.
948 static int __init
acpi_os_name_setup(char *str
)
950 char *p
= acpi_os_name
;
951 int count
= ACPI_MAX_OVERRIDE_LEN
- 1;
956 for (; count
-- && str
&& *str
; str
++) {
957 if (isalnum(*str
) || *str
== ' ' || *str
== ':')
959 else if (*str
== '\'' || *str
== '"')
970 __setup("acpi_os_name=", acpi_os_name_setup
);
972 static void __init
set_osi_linux(unsigned int enable
)
974 if (osi_linux
.enable
!= enable
) {
975 osi_linux
.enable
= enable
;
976 printk(KERN_NOTICE PREFIX
"%sed _OSI(Linux)\n",
977 enable
? "Add": "Delet");
982 static void __init
acpi_cmdline_osi_linux(unsigned int enable
)
984 osi_linux
.cmdline
= 1; /* cmdline set the default */
985 set_osi_linux(enable
);
990 void __init
acpi_dmi_osi_linux(int enable
, const struct dmi_system_id
*d
)
992 osi_linux
.dmi
= 1; /* DMI knows that this box asks OSI(Linux) */
994 printk(KERN_NOTICE PREFIX
"DMI detected: %s\n", d
->ident
);
999 osi_linux
.known
= 1; /* DMI knows which OSI(Linux) default needed */
1001 set_osi_linux(enable
);
1007 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1009 * empty string disables _OSI
1010 * string starting with '!' disables that string
1011 * otherwise string is added to list, augmenting built-in strings
1013 int __init
acpi_osi_setup(char *str
)
1015 if (str
== NULL
|| *str
== '\0') {
1016 printk(KERN_INFO PREFIX
"_OSI method disabled\n");
1017 acpi_gbl_create_osi_method
= FALSE
;
1018 } else if (!strcmp("!Linux", str
)) {
1019 acpi_cmdline_osi_linux(0); /* !enable */
1020 } else if (*str
== '!') {
1021 if (acpi_osi_invalidate(++str
) == AE_OK
)
1022 printk(KERN_INFO PREFIX
"Deleted _OSI(%s)\n", str
);
1023 } else if (!strcmp("Linux", str
)) {
1024 acpi_cmdline_osi_linux(1); /* enable */
1025 } else if (*osi_additional_string
== '\0') {
1026 strncpy(osi_additional_string
, str
, OSI_STRING_LENGTH_MAX
);
1027 printk(KERN_INFO PREFIX
"Added _OSI(%s)\n", str
);
1033 __setup("acpi_osi=", acpi_osi_setup
);
1035 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1036 static int __init
acpi_serialize_setup(char *str
)
1038 printk(KERN_INFO PREFIX
"serialize enabled\n");
1040 acpi_gbl_all_methods_serialized
= TRUE
;
1045 __setup("acpi_serialize", acpi_serialize_setup
);
1048 * Wake and Run-Time GPES are expected to be separate.
1049 * We disable wake-GPEs at run-time to prevent spurious
1052 * However, if a system exists that shares Wake and
1053 * Run-time events on the same GPE this flag is available
1054 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1056 static int __init
acpi_wake_gpes_always_on_setup(char *str
)
1058 printk(KERN_INFO PREFIX
"wake GPEs not disabled\n");
1060 acpi_gbl_leave_wake_gpes_disabled
= FALSE
;
1065 __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup
);
1067 /* Check of resource interference between native drivers and ACPI
1068 * OperationRegions (SystemIO and System Memory only).
1069 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1070 * in arbitrary AML code and can interfere with legacy drivers.
1071 * acpi_enforce_resources= can be set to:
1074 * -> further driver trying to access the resources will not load
1075 * - lax (default) (1)
1076 * -> further driver trying to access the resources will load, but you
1077 * get a system message that something might go wrong...
1080 * -> ACPI Operation Region resources will not be registered
1083 #define ENFORCE_RESOURCES_STRICT 2
1084 #define ENFORCE_RESOURCES_LAX 1
1085 #define ENFORCE_RESOURCES_NO 0
1087 static unsigned int acpi_enforce_resources
= ENFORCE_RESOURCES_LAX
;
1089 static int __init
acpi_enforce_resources_setup(char *str
)
1091 if (str
== NULL
|| *str
== '\0')
1094 if (!strcmp("strict", str
))
1095 acpi_enforce_resources
= ENFORCE_RESOURCES_STRICT
;
1096 else if (!strcmp("lax", str
))
1097 acpi_enforce_resources
= ENFORCE_RESOURCES_LAX
;
1098 else if (!strcmp("no", str
))
1099 acpi_enforce_resources
= ENFORCE_RESOURCES_NO
;
1104 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup
);
1106 /* Check for resource conflicts between ACPI OperationRegions and native
1108 int acpi_check_resource_conflict(struct resource
*res
)
1110 struct acpi_res_list
*res_list_elem
;
1114 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1116 if (!(res
->flags
& IORESOURCE_IO
) && !(res
->flags
& IORESOURCE_MEM
))
1119 ioport
= res
->flags
& IORESOURCE_IO
;
1121 spin_lock(&acpi_res_lock
);
1122 list_for_each_entry(res_list_elem
, &resource_list_head
,
1124 if (ioport
&& (res_list_elem
->resource_type
1125 != ACPI_ADR_SPACE_SYSTEM_IO
))
1127 if (!ioport
&& (res_list_elem
->resource_type
1128 != ACPI_ADR_SPACE_SYSTEM_MEMORY
))
1131 if (res
->end
< res_list_elem
->start
1132 || res_list_elem
->end
< res
->start
)
1137 spin_unlock(&acpi_res_lock
);
1140 if (acpi_enforce_resources
!= ENFORCE_RESOURCES_NO
) {
1141 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
1142 " conflicts with ACPI region %s"
1143 " [0x%llx-0x%llx]\n",
1144 acpi_enforce_resources
== ENFORCE_RESOURCES_LAX
1145 ? KERN_WARNING
: KERN_ERR
,
1146 ioport
? "I/O" : "Memory", res
->name
,
1147 (long long) res
->start
, (long long) res
->end
,
1148 res_list_elem
->name
,
1149 (long long) res_list_elem
->start
,
1150 (long long) res_list_elem
->end
);
1151 printk(KERN_INFO
"ACPI: Device needs an ACPI driver\n");
1153 if (acpi_enforce_resources
== ENFORCE_RESOURCES_STRICT
)
1158 EXPORT_SYMBOL(acpi_check_resource_conflict
);
1160 int acpi_check_region(resource_size_t start
, resource_size_t n
,
1163 struct resource res
= {
1165 .end
= start
+ n
- 1,
1167 .flags
= IORESOURCE_IO
,
1170 return acpi_check_resource_conflict(&res
);
1172 EXPORT_SYMBOL(acpi_check_region
);
1174 int acpi_check_mem_region(resource_size_t start
, resource_size_t n
,
1177 struct resource res
= {
1179 .end
= start
+ n
- 1,
1181 .flags
= IORESOURCE_MEM
,
1184 return acpi_check_resource_conflict(&res
);
1187 EXPORT_SYMBOL(acpi_check_mem_region
);
1190 * Acquire a spinlock.
1192 * handle is a pointer to the spinlock_t.
1195 acpi_cpu_flags
acpi_os_acquire_lock(acpi_spinlock lockp
)
1197 acpi_cpu_flags flags
;
1198 spin_lock_irqsave(lockp
, flags
);
1203 * Release a spinlock. See above.
1206 void acpi_os_release_lock(acpi_spinlock lockp
, acpi_cpu_flags flags
)
1208 spin_unlock_irqrestore(lockp
, flags
);
1211 #ifndef ACPI_USE_LOCAL_CACHE
1213 /*******************************************************************************
1215 * FUNCTION: acpi_os_create_cache
1217 * PARAMETERS: name - Ascii name for the cache
1218 * size - Size of each cached object
1219 * depth - Maximum depth of the cache (in objects) <ignored>
1220 * cache - Where the new cache object is returned
1224 * DESCRIPTION: Create a cache object
1226 ******************************************************************************/
1229 acpi_os_create_cache(char *name
, u16 size
, u16 depth
, acpi_cache_t
** cache
)
1231 *cache
= kmem_cache_create(name
, size
, 0, 0, NULL
);
1238 /*******************************************************************************
1240 * FUNCTION: acpi_os_purge_cache
1242 * PARAMETERS: Cache - Handle to cache object
1246 * DESCRIPTION: Free all objects within the requested cache.
1248 ******************************************************************************/
1250 acpi_status
acpi_os_purge_cache(acpi_cache_t
* cache
)
1252 kmem_cache_shrink(cache
);
1256 /*******************************************************************************
1258 * FUNCTION: acpi_os_delete_cache
1260 * PARAMETERS: Cache - Handle to cache object
1264 * DESCRIPTION: Free all objects within the requested cache and delete the
1267 ******************************************************************************/
1269 acpi_status
acpi_os_delete_cache(acpi_cache_t
* cache
)
1271 kmem_cache_destroy(cache
);
1275 /*******************************************************************************
1277 * FUNCTION: acpi_os_release_object
1279 * PARAMETERS: Cache - Handle to cache object
1280 * Object - The object to be released
1284 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1285 * the object is deleted.
1287 ******************************************************************************/
1289 acpi_status
acpi_os_release_object(acpi_cache_t
* cache
, void *object
)
1291 kmem_cache_free(cache
, object
);
1295 /******************************************************************************
1297 * FUNCTION: acpi_os_validate_interface
1299 * PARAMETERS: interface - Requested interface to be validated
1301 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1303 * DESCRIPTION: Match an interface string to the interfaces supported by the
1304 * host. Strings originate from an AML call to the _OSI method.
1306 *****************************************************************************/
1309 acpi_os_validate_interface (char *interface
)
1311 if (!strncmp(osi_additional_string
, interface
, OSI_STRING_LENGTH_MAX
))
1313 if (!strcmp("Linux", interface
)) {
1315 printk(KERN_NOTICE PREFIX
1316 "BIOS _OSI(Linux) query %s%s\n",
1317 osi_linux
.enable
? "honored" : "ignored",
1318 osi_linux
.cmdline
? " via cmdline" :
1319 osi_linux
.dmi
? " via DMI" : "");
1321 if (osi_linux
.enable
)
1329 struct aml_port_desc
{
1336 static struct aml_port_desc aml_invalid_port_list
[] = {
1337 {0x20, 0x21, "PIC0", 0},
1338 {0xA0, 0xA1, "PIC1", 0},
1339 {0x4D0, 0x4D1, "ELCR", 0}
1343 * valid_aml_io_address()
1345 * if valid, return true
1346 * else invalid, warn once, return false
1348 static bool valid_aml_io_address(uint address
, uint length
)
1351 int entries
= sizeof(aml_invalid_port_list
) / sizeof(struct aml_port_desc
);
1353 for (i
= 0; i
< entries
; ++i
) {
1354 if ((address
>= aml_invalid_port_list
[i
].start
&&
1355 address
<= aml_invalid_port_list
[i
].end
) ||
1356 (address
+ length
>= aml_invalid_port_list
[i
].start
&&
1357 address
+ length
<= aml_invalid_port_list
[i
].end
))
1359 if (!aml_invalid_port_list
[i
].warned
)
1361 printk(KERN_ERR
"ACPI: Denied BIOS AML access"
1362 " to invalid port 0x%x+0x%x (%s)\n",
1364 aml_invalid_port_list
[i
].name
);
1365 aml_invalid_port_list
[i
].warned
= 1;
1367 return false; /* invalid */
1370 return true; /* valid */
1373 static inline bool valid_aml_io_address(uint address
, uint length
) { return true; }
1375 /******************************************************************************
1377 * FUNCTION: acpi_os_validate_address
1379 * PARAMETERS: space_id - ACPI space ID
1380 * address - Physical address
1381 * length - Address length
1383 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1384 * should return AE_AML_ILLEGAL_ADDRESS.
1386 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1387 * the addresses accessed by AML operation regions.
1389 *****************************************************************************/
1392 acpi_os_validate_address (
1394 acpi_physical_address address
,
1398 struct acpi_res_list
*res
;
1399 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1403 case ACPI_ADR_SPACE_SYSTEM_IO
:
1404 if (!valid_aml_io_address(address
, length
))
1405 return AE_AML_ILLEGAL_ADDRESS
;
1406 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
1407 /* Only interference checks against SystemIO and SytemMemory
1409 res
= kzalloc(sizeof(struct acpi_res_list
), GFP_KERNEL
);
1412 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1413 strlcpy(res
->name
, name
, 5);
1414 res
->start
= address
;
1415 res
->end
= address
+ length
- 1;
1416 res
->resource_type
= space_id
;
1417 spin_lock(&acpi_res_lock
);
1418 list_add(&res
->resource_list
, &resource_list_head
);
1419 spin_unlock(&acpi_res_lock
);
1420 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1421 "name: %s\n", (space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
1422 ? "SystemIO" : "System Memory",
1423 (unsigned long long)res
->start
,
1424 (unsigned long long)res
->end
,
1427 case ACPI_ADR_SPACE_PCI_CONFIG
:
1428 case ACPI_ADR_SPACE_EC
:
1429 case ACPI_ADR_SPACE_SMBUS
:
1430 case ACPI_ADR_SPACE_CMOS
:
1431 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
1432 case ACPI_ADR_SPACE_DATA_TABLE
:
1433 case ACPI_ADR_SPACE_FIXED_HARDWARE
: