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
;
64 #ifdef CONFIG_ACPI_CUSTOM_DSDT
65 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
68 #ifdef ENABLE_DEBUGGER
69 #include <linux/kdb.h>
71 /* stuff for debugger support */
73 EXPORT_SYMBOL(acpi_in_debugger
);
75 extern char line_buf
[80];
76 #endif /*ENABLE_DEBUGGER */
78 static unsigned int acpi_irq_irq
;
79 static acpi_osd_handler acpi_irq_handler
;
80 static void *acpi_irq_context
;
81 static struct workqueue_struct
*kacpid_wq
;
82 static struct workqueue_struct
*kacpi_notify_wq
;
83 static struct workqueue_struct
*kacpi_hotplug_wq
;
85 struct acpi_res_list
{
86 resource_size_t start
;
88 acpi_adr_space_type resource_type
; /* IO port, System memory, ...*/
89 char name
[5]; /* only can have a length of 4 chars, make use of this
90 one instead of res->name, no need to kalloc then */
91 struct list_head resource_list
;
95 static LIST_HEAD(resource_list_head
);
96 static DEFINE_SPINLOCK(acpi_res_lock
);
98 #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
99 static char osi_additional_string
[OSI_STRING_LENGTH_MAX
];
102 * The story of _OSI(Linux)
104 * From pre-history through Linux-2.6.22,
105 * Linux responded TRUE upon a BIOS OSI(Linux) query.
107 * Unfortunately, reference BIOS writers got wind of this
108 * and put OSI(Linux) in their example code, quickly exposing
109 * this string as ill-conceived and opening the door to
110 * an un-bounded number of BIOS incompatibilities.
112 * For example, OSI(Linux) was used on resume to re-POST a
113 * video card on one system, because Linux at that time
114 * could not do a speedy restore in its native driver.
115 * But then upon gaining quick native restore capability,
116 * Linux has no way to tell the BIOS to skip the time-consuming
117 * POST -- putting Linux at a permanent performance disadvantage.
118 * On another system, the BIOS writer used OSI(Linux)
119 * to infer native OS support for IPMI! On other systems,
120 * OSI(Linux) simply got in the way of Linux claiming to
121 * be compatible with other operating systems, exposing
122 * BIOS issues such as skipped device initialization.
124 * So "Linux" turned out to be a really poor chose of
125 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
127 * BIOS writers should NOT query _OSI(Linux) on future systems.
128 * Linux will complain on the console when it sees it, and return FALSE.
129 * To get Linux to return TRUE for your system will require
130 * a kernel source update to add a DMI entry,
131 * or boot with "acpi_osi=Linux"
134 static struct osi_linux
{
135 unsigned int enable
:1;
137 unsigned int cmdline
:1;
138 unsigned int known
:1;
139 } osi_linux
= { 0, 0, 0, 0};
141 static void __init
acpi_request_region (struct acpi_generic_address
*addr
,
142 unsigned int length
, char *desc
)
144 if (!addr
->address
|| !length
)
147 /* Resources are never freed */
148 if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
149 request_region(addr
->address
, length
, desc
);
150 else if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
151 request_mem_region(addr
->address
, length
, desc
);
154 static int __init
acpi_reserve_resources(void)
156 acpi_request_region(&acpi_gbl_FADT
.xpm1a_event_block
, acpi_gbl_FADT
.pm1_event_length
,
157 "ACPI PM1a_EVT_BLK");
159 acpi_request_region(&acpi_gbl_FADT
.xpm1b_event_block
, acpi_gbl_FADT
.pm1_event_length
,
160 "ACPI PM1b_EVT_BLK");
162 acpi_request_region(&acpi_gbl_FADT
.xpm1a_control_block
, acpi_gbl_FADT
.pm1_control_length
,
163 "ACPI PM1a_CNT_BLK");
165 acpi_request_region(&acpi_gbl_FADT
.xpm1b_control_block
, acpi_gbl_FADT
.pm1_control_length
,
166 "ACPI PM1b_CNT_BLK");
168 if (acpi_gbl_FADT
.pm_timer_length
== 4)
169 acpi_request_region(&acpi_gbl_FADT
.xpm_timer_block
, 4, "ACPI PM_TMR");
171 acpi_request_region(&acpi_gbl_FADT
.xpm2_control_block
, acpi_gbl_FADT
.pm2_control_length
,
174 /* Length of GPE blocks must be a non-negative multiple of 2 */
176 if (!(acpi_gbl_FADT
.gpe0_block_length
& 0x1))
177 acpi_request_region(&acpi_gbl_FADT
.xgpe0_block
,
178 acpi_gbl_FADT
.gpe0_block_length
, "ACPI GPE0_BLK");
180 if (!(acpi_gbl_FADT
.gpe1_block_length
& 0x1))
181 acpi_request_region(&acpi_gbl_FADT
.xgpe1_block
,
182 acpi_gbl_FADT
.gpe1_block_length
, "ACPI GPE1_BLK");
186 device_initcall(acpi_reserve_resources
);
188 acpi_status __init
acpi_os_initialize(void)
193 acpi_status
acpi_os_initialize1(void)
195 kacpid_wq
= create_workqueue("kacpid");
196 kacpi_notify_wq
= create_workqueue("kacpi_notify");
197 kacpi_hotplug_wq
= create_workqueue("kacpi_hotplug");
199 BUG_ON(!kacpi_notify_wq
);
200 BUG_ON(!kacpi_hotplug_wq
);
204 acpi_status
acpi_os_terminate(void)
206 if (acpi_irq_handler
) {
207 acpi_os_remove_interrupt_handler(acpi_irq_irq
,
211 destroy_workqueue(kacpid_wq
);
212 destroy_workqueue(kacpi_notify_wq
);
213 destroy_workqueue(kacpi_hotplug_wq
);
218 void acpi_os_printf(const char *fmt
, ...)
222 acpi_os_vprintf(fmt
, args
);
226 void acpi_os_vprintf(const char *fmt
, va_list args
)
228 static char buffer
[512];
230 vsprintf(buffer
, fmt
, args
);
232 #ifdef ENABLE_DEBUGGER
233 if (acpi_in_debugger
) {
234 kdb_printf("%s", buffer
);
236 printk(KERN_CONT
"%s", buffer
);
239 printk(KERN_CONT
"%s", buffer
);
243 acpi_physical_address __init
acpi_os_get_root_pointer(void)
246 if (efi
.acpi20
!= EFI_INVALID_TABLE_ADDR
)
248 else if (efi
.acpi
!= EFI_INVALID_TABLE_ADDR
)
251 printk(KERN_ERR PREFIX
252 "System description tables not found\n");
256 acpi_physical_address pa
= 0;
258 acpi_find_root_pointer(&pa
);
263 void __iomem
*__init_refok
264 acpi_os_map_memory(acpi_physical_address phys
, acpi_size size
)
266 if (phys
> ULONG_MAX
) {
267 printk(KERN_ERR PREFIX
"Cannot map memory that high\n");
270 if (acpi_gbl_permanent_mmap
)
272 * ioremap checks to ensure this is in reserved space
274 return ioremap((unsigned long)phys
, size
);
276 return __acpi_map_table((unsigned long)phys
, size
);
278 EXPORT_SYMBOL_GPL(acpi_os_map_memory
);
280 void __ref
acpi_os_unmap_memory(void __iomem
*virt
, acpi_size size
)
282 if (acpi_gbl_permanent_mmap
)
285 __acpi_unmap_table(virt
, size
);
287 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory
);
289 void __init
early_acpi_os_unmap_memory(void __iomem
*virt
, acpi_size size
)
291 if (!acpi_gbl_permanent_mmap
)
292 __acpi_unmap_table(virt
, size
);
295 #ifdef ACPI_FUTURE_USAGE
297 acpi_os_get_physical_address(void *virt
, acpi_physical_address
* phys
)
300 return AE_BAD_PARAMETER
;
302 *phys
= virt_to_phys(virt
);
308 #define ACPI_MAX_OVERRIDE_LEN 100
310 static char acpi_os_name
[ACPI_MAX_OVERRIDE_LEN
];
313 acpi_os_predefined_override(const struct acpi_predefined_names
*init_val
,
314 acpi_string
* new_val
)
316 if (!init_val
|| !new_val
)
317 return AE_BAD_PARAMETER
;
320 if (!memcmp(init_val
->name
, "_OS_", 4) && strlen(acpi_os_name
)) {
321 printk(KERN_INFO PREFIX
"Overriding _OS definition to '%s'\n",
323 *new_val
= acpi_os_name
;
330 acpi_os_table_override(struct acpi_table_header
* existing_table
,
331 struct acpi_table_header
** new_table
)
333 if (!existing_table
|| !new_table
)
334 return AE_BAD_PARAMETER
;
338 #ifdef CONFIG_ACPI_CUSTOM_DSDT
339 if (strncmp(existing_table
->signature
, "DSDT", 4) == 0)
340 *new_table
= (struct acpi_table_header
*)AmlCode
;
342 if (*new_table
!= NULL
) {
343 printk(KERN_WARNING PREFIX
"Override [%4.4s-%8.8s], "
344 "this is unsafe: tainting kernel\n",
345 existing_table
->signature
,
346 existing_table
->oem_table_id
);
347 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE
);
352 static irqreturn_t
acpi_irq(int irq
, void *dev_id
)
356 handled
= (*acpi_irq_handler
) (acpi_irq_context
);
362 acpi_irq_not_handled
++;
368 acpi_os_install_interrupt_handler(u32 gsi
, acpi_osd_handler handler
,
373 acpi_irq_stats_init();
376 * Ignore the GSI from the core, and use the value in our copy of the
377 * FADT. It may not be the same if an interrupt source override exists
380 gsi
= acpi_gbl_FADT
.sci_interrupt
;
381 if (acpi_gsi_to_irq(gsi
, &irq
) < 0) {
382 printk(KERN_ERR PREFIX
"SCI (ACPI GSI %d) not registered\n",
387 acpi_irq_handler
= handler
;
388 acpi_irq_context
= context
;
389 if (request_irq(irq
, acpi_irq
, IRQF_SHARED
, "acpi", acpi_irq
)) {
390 printk(KERN_ERR PREFIX
"SCI (IRQ%d) allocation failed\n", irq
);
391 return AE_NOT_ACQUIRED
;
398 acpi_status
acpi_os_remove_interrupt_handler(u32 irq
, acpi_osd_handler handler
)
401 free_irq(irq
, acpi_irq
);
402 acpi_irq_handler
= NULL
;
410 * Running in interpreter thread context, safe to sleep
413 void acpi_os_sleep(u64 ms
)
415 schedule_timeout_interruptible(msecs_to_jiffies(ms
));
418 void acpi_os_stall(u32 us
)
426 touch_nmi_watchdog();
432 * Support ACPI 3.0 AML Timer operand
433 * Returns 64-bit free-running, monotonically increasing timer
434 * with 100ns granularity
436 u64
acpi_os_get_timer(void)
441 /* TBD: use HPET if available */
444 #ifdef CONFIG_X86_PM_TIMER
445 /* TBD: default to PM timer if HPET was not available */
448 printk(KERN_ERR PREFIX
"acpi_os_get_timer() TBD\n");
453 acpi_status
acpi_os_read_port(acpi_io_address port
, u32
* value
, u32 width
)
462 *(u8
*) value
= inb(port
);
463 } else if (width
<= 16) {
464 *(u16
*) value
= inw(port
);
465 } else if (width
<= 32) {
466 *(u32
*) value
= inl(port
);
474 EXPORT_SYMBOL(acpi_os_read_port
);
476 acpi_status
acpi_os_write_port(acpi_io_address port
, u32 value
, u32 width
)
480 } else if (width
<= 16) {
482 } else if (width
<= 32) {
491 EXPORT_SYMBOL(acpi_os_write_port
);
494 acpi_os_read_memory(acpi_physical_address phys_addr
, u32
* value
, u32 width
)
497 void __iomem
*virt_addr
;
499 virt_addr
= ioremap(phys_addr
, width
);
505 *(u8
*) value
= readb(virt_addr
);
508 *(u16
*) value
= readw(virt_addr
);
511 *(u32
*) value
= readl(virt_addr
);
523 acpi_os_write_memory(acpi_physical_address phys_addr
, u32 value
, u32 width
)
525 void __iomem
*virt_addr
;
527 virt_addr
= ioremap(phys_addr
, width
);
531 writeb(value
, virt_addr
);
534 writew(value
, virt_addr
);
537 writel(value
, virt_addr
);
549 acpi_os_read_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
550 u32
*value
, u32 width
)
555 return AE_BAD_PARAMETER
;
571 result
= raw_pci_read(pci_id
->segment
, pci_id
->bus
,
572 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
575 return (result
? AE_ERROR
: AE_OK
);
579 acpi_os_write_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
580 u64 value
, u32 width
)
598 result
= raw_pci_write(pci_id
->segment
, pci_id
->bus
,
599 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
602 return (result
? AE_ERROR
: AE_OK
);
605 /* TODO: Change code to take advantage of driver model more */
606 static void acpi_os_derive_pci_id_2(acpi_handle rhandle
, /* upper bound */
607 acpi_handle chandle
, /* current node */
608 struct acpi_pci_id
**id
,
609 int *is_bridge
, u8
* bus_number
)
612 struct acpi_pci_id
*pci_id
= *id
;
614 unsigned long long temp
;
615 acpi_object_type type
;
617 acpi_get_parent(chandle
, &handle
);
618 if (handle
!= rhandle
) {
619 acpi_os_derive_pci_id_2(rhandle
, handle
, &pci_id
, is_bridge
,
622 status
= acpi_get_type(handle
, &type
);
623 if ((ACPI_FAILURE(status
)) || (type
!= ACPI_TYPE_DEVICE
))
626 status
= acpi_evaluate_integer(handle
, METHOD_NAME__ADR
, NULL
,
628 if (ACPI_SUCCESS(status
)) {
630 pci_id
->device
= ACPI_HIWORD(ACPI_LODWORD(temp
));
631 pci_id
->function
= ACPI_LOWORD(ACPI_LODWORD(temp
));
634 pci_id
->bus
= *bus_number
;
636 /* any nicer way to get bus number of bridge ? */
638 acpi_os_read_pci_configuration(pci_id
, 0x0e, &val
,
640 if (ACPI_SUCCESS(status
)
641 && ((val
& 0x7f) == 1 || (val
& 0x7f) == 2)) {
643 acpi_os_read_pci_configuration(pci_id
, 0x18,
645 if (!ACPI_SUCCESS(status
)) {
646 /* Certainly broken... FIX ME */
652 acpi_os_read_pci_configuration(pci_id
, 0x19,
654 if (ACPI_SUCCESS(status
)) {
663 void acpi_os_derive_pci_id(acpi_handle rhandle
, /* upper bound */
664 acpi_handle chandle
, /* current node */
665 struct acpi_pci_id
**id
)
668 u8 bus_number
= (*id
)->bus
;
670 acpi_os_derive_pci_id_2(rhandle
, chandle
, id
, &is_bridge
, &bus_number
);
673 static void acpi_os_execute_deferred(struct work_struct
*work
)
675 struct acpi_os_dpc
*dpc
= container_of(work
, struct acpi_os_dpc
, work
);
678 acpi_os_wait_events_complete(NULL
);
680 dpc
->function(dpc
->context
);
684 /*******************************************************************************
686 * FUNCTION: acpi_os_execute
688 * PARAMETERS: Type - Type of the callback
689 * Function - Function to be executed
690 * Context - Function parameters
694 * DESCRIPTION: Depending on type, either queues function for deferred execution or
695 * immediately executes function on a separate thread.
697 ******************************************************************************/
699 static acpi_status
__acpi_os_execute(acpi_execute_type type
,
700 acpi_osd_exec_callback function
, void *context
, int hp
)
702 acpi_status status
= AE_OK
;
703 struct acpi_os_dpc
*dpc
;
704 struct workqueue_struct
*queue
;
706 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
707 "Scheduling function [%p(%p)] for deferred execution.\n",
711 * Allocate/initialize DPC structure. Note that this memory will be
712 * freed by the callee. The kernel handles the work_struct list in a
713 * way that allows us to also free its memory inside the callee.
714 * Because we may want to schedule several tasks with different
715 * parameters we can't use the approach some kernel code uses of
716 * having a static work_struct.
719 dpc
= kmalloc(sizeof(struct acpi_os_dpc
), GFP_ATOMIC
);
723 dpc
->function
= function
;
724 dpc
->context
= context
;
727 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
728 * because the hotplug code may call driver .remove() functions,
729 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
730 * to flush these workqueues.
732 queue
= hp
? kacpi_hotplug_wq
:
733 (type
== OSL_NOTIFY_HANDLER
? kacpi_notify_wq
: kacpid_wq
);
734 dpc
->wait
= hp
? 1 : 0;
736 if (queue
== kacpi_hotplug_wq
)
737 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
738 else if (queue
== kacpi_notify_wq
)
739 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
741 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
744 * On some machines, a software-initiated SMI causes corruption unless
745 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
746 * typically it's done in GPE-related methods that are run via
747 * workqueues, so we can avoid the known corruption cases by always
750 ret
= queue_work_on(0, queue
, &dpc
->work
);
753 printk(KERN_ERR PREFIX
754 "Call to queue_work() failed.\n");
761 acpi_status
acpi_os_execute(acpi_execute_type type
,
762 acpi_osd_exec_callback function
, void *context
)
764 return __acpi_os_execute(type
, function
, context
, 0);
766 EXPORT_SYMBOL(acpi_os_execute
);
768 acpi_status
acpi_os_hotplug_execute(acpi_osd_exec_callback function
,
771 return __acpi_os_execute(0, function
, context
, 1);
774 void acpi_os_wait_events_complete(void *context
)
776 flush_workqueue(kacpid_wq
);
777 flush_workqueue(kacpi_notify_wq
);
780 EXPORT_SYMBOL(acpi_os_wait_events_complete
);
783 * Allocate the memory for a spinlock and initialize it.
785 acpi_status
acpi_os_create_lock(acpi_spinlock
* handle
)
787 spin_lock_init(*handle
);
793 * Deallocate the memory for a spinlock.
795 void acpi_os_delete_lock(acpi_spinlock handle
)
801 acpi_os_create_semaphore(u32 max_units
, u32 initial_units
, acpi_handle
* handle
)
803 struct semaphore
*sem
= NULL
;
805 sem
= acpi_os_allocate(sizeof(struct semaphore
));
808 memset(sem
, 0, sizeof(struct semaphore
));
810 sema_init(sem
, initial_units
);
812 *handle
= (acpi_handle
*) sem
;
814 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Creating semaphore[%p|%d].\n",
815 *handle
, initial_units
));
821 * TODO: A better way to delete semaphores? Linux doesn't have a
822 * 'delete_semaphore()' function -- may result in an invalid
823 * pointer dereference for non-synchronized consumers. Should
824 * we at least check for blocked threads and signal/cancel them?
827 acpi_status
acpi_os_delete_semaphore(acpi_handle handle
)
829 struct semaphore
*sem
= (struct semaphore
*)handle
;
832 return AE_BAD_PARAMETER
;
834 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Deleting semaphore[%p].\n", handle
));
836 BUG_ON(!list_empty(&sem
->wait_list
));
844 * TODO: Support for units > 1?
846 acpi_status
acpi_os_wait_semaphore(acpi_handle handle
, u32 units
, u16 timeout
)
848 acpi_status status
= AE_OK
;
849 struct semaphore
*sem
= (struct semaphore
*)handle
;
853 if (!sem
|| (units
< 1))
854 return AE_BAD_PARAMETER
;
859 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Waiting for semaphore[%p|%d|%d]\n",
860 handle
, units
, timeout
));
862 if (timeout
== ACPI_WAIT_FOREVER
)
863 jiffies
= MAX_SCHEDULE_TIMEOUT
;
865 jiffies
= msecs_to_jiffies(timeout
);
867 ret
= down_timeout(sem
, jiffies
);
871 if (ACPI_FAILURE(status
)) {
872 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
873 "Failed to acquire semaphore[%p|%d|%d], %s",
874 handle
, units
, timeout
,
875 acpi_format_exception(status
)));
877 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
878 "Acquired semaphore[%p|%d|%d]", handle
,
886 * TODO: Support for units > 1?
888 acpi_status
acpi_os_signal_semaphore(acpi_handle handle
, u32 units
)
890 struct semaphore
*sem
= (struct semaphore
*)handle
;
892 if (!sem
|| (units
< 1))
893 return AE_BAD_PARAMETER
;
898 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Signaling semaphore[%p|%d]\n", handle
,
906 #ifdef ACPI_FUTURE_USAGE
907 u32
acpi_os_get_line(char *buffer
)
910 #ifdef ENABLE_DEBUGGER
911 if (acpi_in_debugger
) {
914 kdb_read(buffer
, sizeof(line_buf
));
916 /* remove the CR kdb includes */
917 chars
= strlen(buffer
) - 1;
918 buffer
[chars
] = '\0';
924 #endif /* ACPI_FUTURE_USAGE */
926 acpi_status
acpi_os_signal(u32 function
, void *info
)
929 case ACPI_SIGNAL_FATAL
:
930 printk(KERN_ERR PREFIX
"Fatal opcode executed\n");
932 case ACPI_SIGNAL_BREAKPOINT
:
935 * ACPI spec. says to treat it as a NOP unless
936 * you are debugging. So if/when we integrate
937 * AML debugger into the kernel debugger its
938 * hook will go here. But until then it is
939 * not useful to print anything on breakpoints.
949 static int __init
acpi_os_name_setup(char *str
)
951 char *p
= acpi_os_name
;
952 int count
= ACPI_MAX_OVERRIDE_LEN
- 1;
957 for (; count
-- && str
&& *str
; str
++) {
958 if (isalnum(*str
) || *str
== ' ' || *str
== ':')
960 else if (*str
== '\'' || *str
== '"')
971 __setup("acpi_os_name=", acpi_os_name_setup
);
973 static void __init
set_osi_linux(unsigned int enable
)
975 if (osi_linux
.enable
!= enable
) {
976 osi_linux
.enable
= enable
;
977 printk(KERN_NOTICE PREFIX
"%sed _OSI(Linux)\n",
978 enable
? "Add": "Delet");
983 static void __init
acpi_cmdline_osi_linux(unsigned int enable
)
985 osi_linux
.cmdline
= 1; /* cmdline set the default */
986 set_osi_linux(enable
);
991 void __init
acpi_dmi_osi_linux(int enable
, const struct dmi_system_id
*d
)
993 osi_linux
.dmi
= 1; /* DMI knows that this box asks OSI(Linux) */
995 printk(KERN_NOTICE PREFIX
"DMI detected: %s\n", d
->ident
);
1000 osi_linux
.known
= 1; /* DMI knows which OSI(Linux) default needed */
1002 set_osi_linux(enable
);
1008 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1010 * empty string disables _OSI
1011 * string starting with '!' disables that string
1012 * otherwise string is added to list, augmenting built-in strings
1014 int __init
acpi_osi_setup(char *str
)
1016 if (str
== NULL
|| *str
== '\0') {
1017 printk(KERN_INFO PREFIX
"_OSI method disabled\n");
1018 acpi_gbl_create_osi_method
= FALSE
;
1019 } else if (!strcmp("!Linux", str
)) {
1020 acpi_cmdline_osi_linux(0); /* !enable */
1021 } else if (*str
== '!') {
1022 if (acpi_osi_invalidate(++str
) == AE_OK
)
1023 printk(KERN_INFO PREFIX
"Deleted _OSI(%s)\n", str
);
1024 } else if (!strcmp("Linux", str
)) {
1025 acpi_cmdline_osi_linux(1); /* enable */
1026 } else if (*osi_additional_string
== '\0') {
1027 strncpy(osi_additional_string
, str
, OSI_STRING_LENGTH_MAX
);
1028 printk(KERN_INFO PREFIX
"Added _OSI(%s)\n", str
);
1034 __setup("acpi_osi=", acpi_osi_setup
);
1036 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1037 static int __init
acpi_serialize_setup(char *str
)
1039 printk(KERN_INFO PREFIX
"serialize enabled\n");
1041 acpi_gbl_all_methods_serialized
= TRUE
;
1046 __setup("acpi_serialize", acpi_serialize_setup
);
1048 /* Check of resource interference between native drivers and ACPI
1049 * OperationRegions (SystemIO and System Memory only).
1050 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1051 * in arbitrary AML code and can interfere with legacy drivers.
1052 * acpi_enforce_resources= can be set to:
1054 * - strict (default) (2)
1055 * -> further driver trying to access the resources will not load
1057 * -> further driver trying to access the resources will load, but you
1058 * get a system message that something might go wrong...
1061 * -> ACPI Operation Region resources will not be registered
1064 #define ENFORCE_RESOURCES_STRICT 2
1065 #define ENFORCE_RESOURCES_LAX 1
1066 #define ENFORCE_RESOURCES_NO 0
1068 static unsigned int acpi_enforce_resources
= ENFORCE_RESOURCES_STRICT
;
1070 static int __init
acpi_enforce_resources_setup(char *str
)
1072 if (str
== NULL
|| *str
== '\0')
1075 if (!strcmp("strict", str
))
1076 acpi_enforce_resources
= ENFORCE_RESOURCES_STRICT
;
1077 else if (!strcmp("lax", str
))
1078 acpi_enforce_resources
= ENFORCE_RESOURCES_LAX
;
1079 else if (!strcmp("no", str
))
1080 acpi_enforce_resources
= ENFORCE_RESOURCES_NO
;
1085 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup
);
1087 /* Check for resource conflicts between ACPI OperationRegions and native
1089 int acpi_check_resource_conflict(const struct resource
*res
)
1091 struct acpi_res_list
*res_list_elem
;
1095 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1097 if (!(res
->flags
& IORESOURCE_IO
) && !(res
->flags
& IORESOURCE_MEM
))
1100 ioport
= res
->flags
& IORESOURCE_IO
;
1102 spin_lock(&acpi_res_lock
);
1103 list_for_each_entry(res_list_elem
, &resource_list_head
,
1105 if (ioport
&& (res_list_elem
->resource_type
1106 != ACPI_ADR_SPACE_SYSTEM_IO
))
1108 if (!ioport
&& (res_list_elem
->resource_type
1109 != ACPI_ADR_SPACE_SYSTEM_MEMORY
))
1112 if (res
->end
< res_list_elem
->start
1113 || res_list_elem
->end
< res
->start
)
1118 spin_unlock(&acpi_res_lock
);
1121 if (acpi_enforce_resources
!= ENFORCE_RESOURCES_NO
) {
1122 printk(KERN_WARNING
"ACPI: resource %s %pR"
1123 " conflicts with ACPI region %s %pR\n",
1124 res
->name
, res
, res_list_elem
->name
,
1126 if (acpi_enforce_resources
== ENFORCE_RESOURCES_LAX
)
1127 printk(KERN_NOTICE
"ACPI: This conflict may"
1128 " cause random problems and system"
1130 printk(KERN_INFO
"ACPI: If an ACPI driver is available"
1131 " for this device, you should use it instead of"
1132 " the native driver\n");
1134 if (acpi_enforce_resources
== ENFORCE_RESOURCES_STRICT
)
1139 EXPORT_SYMBOL(acpi_check_resource_conflict
);
1141 int acpi_check_region(resource_size_t start
, resource_size_t n
,
1144 struct resource res
= {
1146 .end
= start
+ n
- 1,
1148 .flags
= IORESOURCE_IO
,
1151 return acpi_check_resource_conflict(&res
);
1153 EXPORT_SYMBOL(acpi_check_region
);
1155 int acpi_check_mem_region(resource_size_t start
, resource_size_t n
,
1158 struct resource res
= {
1160 .end
= start
+ n
- 1,
1162 .flags
= IORESOURCE_MEM
,
1165 return acpi_check_resource_conflict(&res
);
1168 EXPORT_SYMBOL(acpi_check_mem_region
);
1171 * Let drivers know whether the resource checks are effective
1173 int acpi_resources_are_enforced(void)
1175 return acpi_enforce_resources
== ENFORCE_RESOURCES_STRICT
;
1177 EXPORT_SYMBOL(acpi_resources_are_enforced
);
1180 * Acquire a spinlock.
1182 * handle is a pointer to the spinlock_t.
1185 acpi_cpu_flags
acpi_os_acquire_lock(acpi_spinlock lockp
)
1187 acpi_cpu_flags flags
;
1188 spin_lock_irqsave(lockp
, flags
);
1193 * Release a spinlock. See above.
1196 void acpi_os_release_lock(acpi_spinlock lockp
, acpi_cpu_flags flags
)
1198 spin_unlock_irqrestore(lockp
, flags
);
1201 #ifndef ACPI_USE_LOCAL_CACHE
1203 /*******************************************************************************
1205 * FUNCTION: acpi_os_create_cache
1207 * PARAMETERS: name - Ascii name for the cache
1208 * size - Size of each cached object
1209 * depth - Maximum depth of the cache (in objects) <ignored>
1210 * cache - Where the new cache object is returned
1214 * DESCRIPTION: Create a cache object
1216 ******************************************************************************/
1219 acpi_os_create_cache(char *name
, u16 size
, u16 depth
, acpi_cache_t
** cache
)
1221 *cache
= kmem_cache_create(name
, size
, 0, 0, NULL
);
1228 /*******************************************************************************
1230 * FUNCTION: acpi_os_purge_cache
1232 * PARAMETERS: Cache - Handle to cache object
1236 * DESCRIPTION: Free all objects within the requested cache.
1238 ******************************************************************************/
1240 acpi_status
acpi_os_purge_cache(acpi_cache_t
* cache
)
1242 kmem_cache_shrink(cache
);
1246 /*******************************************************************************
1248 * FUNCTION: acpi_os_delete_cache
1250 * PARAMETERS: Cache - Handle to cache object
1254 * DESCRIPTION: Free all objects within the requested cache and delete the
1257 ******************************************************************************/
1259 acpi_status
acpi_os_delete_cache(acpi_cache_t
* cache
)
1261 kmem_cache_destroy(cache
);
1265 /*******************************************************************************
1267 * FUNCTION: acpi_os_release_object
1269 * PARAMETERS: Cache - Handle to cache object
1270 * Object - The object to be released
1274 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1275 * the object is deleted.
1277 ******************************************************************************/
1279 acpi_status
acpi_os_release_object(acpi_cache_t
* cache
, void *object
)
1281 kmem_cache_free(cache
, object
);
1285 /******************************************************************************
1287 * FUNCTION: acpi_os_validate_interface
1289 * PARAMETERS: interface - Requested interface to be validated
1291 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1293 * DESCRIPTION: Match an interface string to the interfaces supported by the
1294 * host. Strings originate from an AML call to the _OSI method.
1296 *****************************************************************************/
1299 acpi_os_validate_interface (char *interface
)
1301 if (!strncmp(osi_additional_string
, interface
, OSI_STRING_LENGTH_MAX
))
1303 if (!strcmp("Linux", interface
)) {
1305 printk(KERN_NOTICE PREFIX
1306 "BIOS _OSI(Linux) query %s%s\n",
1307 osi_linux
.enable
? "honored" : "ignored",
1308 osi_linux
.cmdline
? " via cmdline" :
1309 osi_linux
.dmi
? " via DMI" : "");
1311 if (osi_linux
.enable
)
1317 static inline int acpi_res_list_add(struct acpi_res_list
*res
)
1319 struct acpi_res_list
*res_list_elem
;
1321 list_for_each_entry(res_list_elem
, &resource_list_head
,
1324 if (res
->resource_type
== res_list_elem
->resource_type
&&
1325 res
->start
== res_list_elem
->start
&&
1326 res
->end
== res_list_elem
->end
) {
1329 * The Region(addr,len) already exist in the list,
1330 * just increase the count
1333 res_list_elem
->count
++;
1339 list_add(&res
->resource_list
, &resource_list_head
);
1343 static inline void acpi_res_list_del(struct acpi_res_list
*res
)
1345 struct acpi_res_list
*res_list_elem
;
1347 list_for_each_entry(res_list_elem
, &resource_list_head
,
1350 if (res
->resource_type
== res_list_elem
->resource_type
&&
1351 res
->start
== res_list_elem
->start
&&
1352 res
->end
== res_list_elem
->end
) {
1355 * If the res count is decreased to 0,
1356 * remove and free it
1359 if (--res_list_elem
->count
== 0) {
1360 list_del(&res_list_elem
->resource_list
);
1361 kfree(res_list_elem
);
1369 acpi_os_invalidate_address(
1371 acpi_physical_address address
,
1374 struct acpi_res_list res
;
1377 case ACPI_ADR_SPACE_SYSTEM_IO
:
1378 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
1379 /* Only interference checks against SystemIO and SystemMemory
1381 res
.start
= address
;
1382 res
.end
= address
+ length
- 1;
1383 res
.resource_type
= space_id
;
1384 spin_lock(&acpi_res_lock
);
1385 acpi_res_list_del(&res
);
1386 spin_unlock(&acpi_res_lock
);
1388 case ACPI_ADR_SPACE_PCI_CONFIG
:
1389 case ACPI_ADR_SPACE_EC
:
1390 case ACPI_ADR_SPACE_SMBUS
:
1391 case ACPI_ADR_SPACE_CMOS
:
1392 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
1393 case ACPI_ADR_SPACE_DATA_TABLE
:
1394 case ACPI_ADR_SPACE_FIXED_HARDWARE
:
1400 /******************************************************************************
1402 * FUNCTION: acpi_os_validate_address
1404 * PARAMETERS: space_id - ACPI space ID
1405 * address - Physical address
1406 * length - Address length
1408 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1409 * should return AE_AML_ILLEGAL_ADDRESS.
1411 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1412 * the addresses accessed by AML operation regions.
1414 *****************************************************************************/
1417 acpi_os_validate_address (
1419 acpi_physical_address address
,
1423 struct acpi_res_list
*res
;
1425 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1429 case ACPI_ADR_SPACE_SYSTEM_IO
:
1430 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
1431 /* Only interference checks against SystemIO and SystemMemory
1433 res
= kzalloc(sizeof(struct acpi_res_list
), GFP_KERNEL
);
1436 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1437 strlcpy(res
->name
, name
, 5);
1438 res
->start
= address
;
1439 res
->end
= address
+ length
- 1;
1440 res
->resource_type
= space_id
;
1441 spin_lock(&acpi_res_lock
);
1442 added
= acpi_res_list_add(res
);
1443 spin_unlock(&acpi_res_lock
);
1444 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1445 "name: %s\n", added
? "Added" : "Already exist",
1446 (space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
1447 ? "SystemIO" : "System Memory",
1448 (unsigned long long)res
->start
,
1449 (unsigned long long)res
->end
,
1454 case ACPI_ADR_SPACE_PCI_CONFIG
:
1455 case ACPI_ADR_SPACE_EC
:
1456 case ACPI_ADR_SPACE_SMBUS
:
1457 case ACPI_ADR_SPACE_CMOS
:
1458 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
1459 case ACPI_ADR_SPACE_DATA_TABLE
:
1460 case ACPI_ADR_SPACE_FIXED_HARDWARE
: