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_setup_string
[OSI_STRING_LENGTH_MAX
];
101 static void __init
acpi_osi_setup_late(void);
104 * The story of _OSI(Linux)
106 * From pre-history through Linux-2.6.22,
107 * Linux responded TRUE upon a BIOS OSI(Linux) query.
109 * Unfortunately, reference BIOS writers got wind of this
110 * and put OSI(Linux) in their example code, quickly exposing
111 * this string as ill-conceived and opening the door to
112 * an un-bounded number of BIOS incompatibilities.
114 * For example, OSI(Linux) was used on resume to re-POST a
115 * video card on one system, because Linux at that time
116 * could not do a speedy restore in its native driver.
117 * But then upon gaining quick native restore capability,
118 * Linux has no way to tell the BIOS to skip the time-consuming
119 * POST -- putting Linux at a permanent performance disadvantage.
120 * On another system, the BIOS writer used OSI(Linux)
121 * to infer native OS support for IPMI! On other systems,
122 * OSI(Linux) simply got in the way of Linux claiming to
123 * be compatible with other operating systems, exposing
124 * BIOS issues such as skipped device initialization.
126 * So "Linux" turned out to be a really poor chose of
127 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
129 * BIOS writers should NOT query _OSI(Linux) on future systems.
130 * Linux will complain on the console when it sees it, and return FALSE.
131 * To get Linux to return TRUE for your system will require
132 * a kernel source update to add a DMI entry,
133 * or boot with "acpi_osi=Linux"
136 static struct osi_linux
{
137 unsigned int enable
:1;
139 unsigned int cmdline
:1;
140 unsigned int known
:1;
141 } osi_linux
= { 0, 0, 0, 0};
143 static u32
acpi_osi_handler(acpi_string interface
, u32 supported
)
145 if (!strcmp("Linux", interface
)) {
147 printk(KERN_NOTICE PREFIX
148 "BIOS _OSI(Linux) query %s%s\n",
149 osi_linux
.enable
? "honored" : "ignored",
150 osi_linux
.cmdline
? " via cmdline" :
151 osi_linux
.dmi
? " via DMI" : "");
157 static void __init
acpi_request_region (struct acpi_generic_address
*addr
,
158 unsigned int length
, char *desc
)
160 if (!addr
->address
|| !length
)
163 /* Resources are never freed */
164 if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
165 request_region(addr
->address
, length
, desc
);
166 else if (addr
->space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
167 request_mem_region(addr
->address
, length
, desc
);
170 static int __init
acpi_reserve_resources(void)
172 acpi_request_region(&acpi_gbl_FADT
.xpm1a_event_block
, acpi_gbl_FADT
.pm1_event_length
,
173 "ACPI PM1a_EVT_BLK");
175 acpi_request_region(&acpi_gbl_FADT
.xpm1b_event_block
, acpi_gbl_FADT
.pm1_event_length
,
176 "ACPI PM1b_EVT_BLK");
178 acpi_request_region(&acpi_gbl_FADT
.xpm1a_control_block
, acpi_gbl_FADT
.pm1_control_length
,
179 "ACPI PM1a_CNT_BLK");
181 acpi_request_region(&acpi_gbl_FADT
.xpm1b_control_block
, acpi_gbl_FADT
.pm1_control_length
,
182 "ACPI PM1b_CNT_BLK");
184 if (acpi_gbl_FADT
.pm_timer_length
== 4)
185 acpi_request_region(&acpi_gbl_FADT
.xpm_timer_block
, 4, "ACPI PM_TMR");
187 acpi_request_region(&acpi_gbl_FADT
.xpm2_control_block
, acpi_gbl_FADT
.pm2_control_length
,
190 /* Length of GPE blocks must be a non-negative multiple of 2 */
192 if (!(acpi_gbl_FADT
.gpe0_block_length
& 0x1))
193 acpi_request_region(&acpi_gbl_FADT
.xgpe0_block
,
194 acpi_gbl_FADT
.gpe0_block_length
, "ACPI GPE0_BLK");
196 if (!(acpi_gbl_FADT
.gpe1_block_length
& 0x1))
197 acpi_request_region(&acpi_gbl_FADT
.xgpe1_block
,
198 acpi_gbl_FADT
.gpe1_block_length
, "ACPI GPE1_BLK");
202 device_initcall(acpi_reserve_resources
);
204 acpi_status __init
acpi_os_initialize(void)
209 acpi_status
acpi_os_initialize1(void)
211 kacpid_wq
= create_workqueue("kacpid");
212 kacpi_notify_wq
= create_workqueue("kacpi_notify");
213 kacpi_hotplug_wq
= create_workqueue("kacpi_hotplug");
215 BUG_ON(!kacpi_notify_wq
);
216 BUG_ON(!kacpi_hotplug_wq
);
217 acpi_install_interface_handler(acpi_osi_handler
);
218 acpi_osi_setup_late();
222 acpi_status
acpi_os_terminate(void)
224 if (acpi_irq_handler
) {
225 acpi_os_remove_interrupt_handler(acpi_irq_irq
,
229 destroy_workqueue(kacpid_wq
);
230 destroy_workqueue(kacpi_notify_wq
);
231 destroy_workqueue(kacpi_hotplug_wq
);
236 void acpi_os_printf(const char *fmt
, ...)
240 acpi_os_vprintf(fmt
, args
);
244 void acpi_os_vprintf(const char *fmt
, va_list args
)
246 static char buffer
[512];
248 vsprintf(buffer
, fmt
, args
);
250 #ifdef ENABLE_DEBUGGER
251 if (acpi_in_debugger
) {
252 kdb_printf("%s", buffer
);
254 printk(KERN_CONT
"%s", buffer
);
257 printk(KERN_CONT
"%s", buffer
);
261 acpi_physical_address __init
acpi_os_get_root_pointer(void)
264 if (efi
.acpi20
!= EFI_INVALID_TABLE_ADDR
)
266 else if (efi
.acpi
!= EFI_INVALID_TABLE_ADDR
)
269 printk(KERN_ERR PREFIX
270 "System description tables not found\n");
274 acpi_physical_address pa
= 0;
276 acpi_find_root_pointer(&pa
);
281 void __iomem
*__init_refok
282 acpi_os_map_memory(acpi_physical_address phys
, acpi_size size
)
284 if (phys
> ULONG_MAX
) {
285 printk(KERN_ERR PREFIX
"Cannot map memory that high\n");
288 if (acpi_gbl_permanent_mmap
)
290 * ioremap checks to ensure this is in reserved space
292 return ioremap((unsigned long)phys
, size
);
294 return __acpi_map_table((unsigned long)phys
, size
);
296 EXPORT_SYMBOL_GPL(acpi_os_map_memory
);
298 void __ref
acpi_os_unmap_memory(void __iomem
*virt
, acpi_size size
)
300 if (acpi_gbl_permanent_mmap
)
303 __acpi_unmap_table(virt
, size
);
305 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory
);
307 void __init
early_acpi_os_unmap_memory(void __iomem
*virt
, acpi_size size
)
309 if (!acpi_gbl_permanent_mmap
)
310 __acpi_unmap_table(virt
, size
);
313 #ifdef ACPI_FUTURE_USAGE
315 acpi_os_get_physical_address(void *virt
, acpi_physical_address
* phys
)
318 return AE_BAD_PARAMETER
;
320 *phys
= virt_to_phys(virt
);
326 #define ACPI_MAX_OVERRIDE_LEN 100
328 static char acpi_os_name
[ACPI_MAX_OVERRIDE_LEN
];
331 acpi_os_predefined_override(const struct acpi_predefined_names
*init_val
,
332 acpi_string
* new_val
)
334 if (!init_val
|| !new_val
)
335 return AE_BAD_PARAMETER
;
338 if (!memcmp(init_val
->name
, "_OS_", 4) && strlen(acpi_os_name
)) {
339 printk(KERN_INFO PREFIX
"Overriding _OS definition to '%s'\n",
341 *new_val
= acpi_os_name
;
348 acpi_os_table_override(struct acpi_table_header
* existing_table
,
349 struct acpi_table_header
** new_table
)
351 if (!existing_table
|| !new_table
)
352 return AE_BAD_PARAMETER
;
356 #ifdef CONFIG_ACPI_CUSTOM_DSDT
357 if (strncmp(existing_table
->signature
, "DSDT", 4) == 0)
358 *new_table
= (struct acpi_table_header
*)AmlCode
;
360 if (*new_table
!= NULL
) {
361 printk(KERN_WARNING PREFIX
"Override [%4.4s-%8.8s], "
362 "this is unsafe: tainting kernel\n",
363 existing_table
->signature
,
364 existing_table
->oem_table_id
);
365 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE
);
370 static irqreturn_t
acpi_irq(int irq
, void *dev_id
)
374 handled
= (*acpi_irq_handler
) (acpi_irq_context
);
380 acpi_irq_not_handled
++;
386 acpi_os_install_interrupt_handler(u32 gsi
, acpi_osd_handler handler
,
391 acpi_irq_stats_init();
394 * Ignore the GSI from the core, and use the value in our copy of the
395 * FADT. It may not be the same if an interrupt source override exists
398 gsi
= acpi_gbl_FADT
.sci_interrupt
;
399 if (acpi_gsi_to_irq(gsi
, &irq
) < 0) {
400 printk(KERN_ERR PREFIX
"SCI (ACPI GSI %d) not registered\n",
405 acpi_irq_handler
= handler
;
406 acpi_irq_context
= context
;
407 if (request_irq(irq
, acpi_irq
, IRQF_SHARED
, "acpi", acpi_irq
)) {
408 printk(KERN_ERR PREFIX
"SCI (IRQ%d) allocation failed\n", irq
);
409 return AE_NOT_ACQUIRED
;
416 acpi_status
acpi_os_remove_interrupt_handler(u32 irq
, acpi_osd_handler handler
)
419 free_irq(irq
, acpi_irq
);
420 acpi_irq_handler
= NULL
;
428 * Running in interpreter thread context, safe to sleep
431 void acpi_os_sleep(u64 ms
)
433 schedule_timeout_interruptible(msecs_to_jiffies(ms
));
436 void acpi_os_stall(u32 us
)
444 touch_nmi_watchdog();
450 * Support ACPI 3.0 AML Timer operand
451 * Returns 64-bit free-running, monotonically increasing timer
452 * with 100ns granularity
454 u64
acpi_os_get_timer(void)
459 /* TBD: use HPET if available */
462 #ifdef CONFIG_X86_PM_TIMER
463 /* TBD: default to PM timer if HPET was not available */
466 printk(KERN_ERR PREFIX
"acpi_os_get_timer() TBD\n");
471 acpi_status
acpi_os_read_port(acpi_io_address port
, u32
* value
, u32 width
)
480 *(u8
*) value
= inb(port
);
481 } else if (width
<= 16) {
482 *(u16
*) value
= inw(port
);
483 } else if (width
<= 32) {
484 *(u32
*) value
= inl(port
);
492 EXPORT_SYMBOL(acpi_os_read_port
);
494 acpi_status
acpi_os_write_port(acpi_io_address port
, u32 value
, u32 width
)
498 } else if (width
<= 16) {
500 } else if (width
<= 32) {
509 EXPORT_SYMBOL(acpi_os_write_port
);
512 acpi_os_read_memory(acpi_physical_address phys_addr
, u32
* value
, u32 width
)
515 void __iomem
*virt_addr
;
517 virt_addr
= ioremap(phys_addr
, width
);
523 *(u8
*) value
= readb(virt_addr
);
526 *(u16
*) value
= readw(virt_addr
);
529 *(u32
*) value
= readl(virt_addr
);
541 acpi_os_write_memory(acpi_physical_address phys_addr
, u32 value
, u32 width
)
543 void __iomem
*virt_addr
;
545 virt_addr
= ioremap(phys_addr
, width
);
549 writeb(value
, virt_addr
);
552 writew(value
, virt_addr
);
555 writel(value
, virt_addr
);
567 acpi_os_read_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
568 u64
*value
, u32 width
)
574 return AE_BAD_PARAMETER
;
590 result
= raw_pci_read(pci_id
->segment
, pci_id
->bus
,
591 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
592 reg
, size
, &value32
);
595 return (result
? AE_ERROR
: AE_OK
);
599 acpi_os_write_pci_configuration(struct acpi_pci_id
* pci_id
, u32 reg
,
600 u64 value
, u32 width
)
618 result
= raw_pci_write(pci_id
->segment
, pci_id
->bus
,
619 PCI_DEVFN(pci_id
->device
, pci_id
->function
),
622 return (result
? AE_ERROR
: AE_OK
);
625 static void acpi_os_execute_deferred(struct work_struct
*work
)
627 struct acpi_os_dpc
*dpc
= container_of(work
, struct acpi_os_dpc
, work
);
630 acpi_os_wait_events_complete(NULL
);
632 dpc
->function(dpc
->context
);
636 /*******************************************************************************
638 * FUNCTION: acpi_os_execute
640 * PARAMETERS: Type - Type of the callback
641 * Function - Function to be executed
642 * Context - Function parameters
646 * DESCRIPTION: Depending on type, either queues function for deferred execution or
647 * immediately executes function on a separate thread.
649 ******************************************************************************/
651 static acpi_status
__acpi_os_execute(acpi_execute_type type
,
652 acpi_osd_exec_callback function
, void *context
, int hp
)
654 acpi_status status
= AE_OK
;
655 struct acpi_os_dpc
*dpc
;
656 struct workqueue_struct
*queue
;
658 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
659 "Scheduling function [%p(%p)] for deferred execution.\n",
663 * Allocate/initialize DPC structure. Note that this memory will be
664 * freed by the callee. The kernel handles the work_struct list in a
665 * way that allows us to also free its memory inside the callee.
666 * Because we may want to schedule several tasks with different
667 * parameters we can't use the approach some kernel code uses of
668 * having a static work_struct.
671 dpc
= kmalloc(sizeof(struct acpi_os_dpc
), GFP_ATOMIC
);
675 dpc
->function
= function
;
676 dpc
->context
= context
;
679 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
680 * because the hotplug code may call driver .remove() functions,
681 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
682 * to flush these workqueues.
684 queue
= hp
? kacpi_hotplug_wq
:
685 (type
== OSL_NOTIFY_HANDLER
? kacpi_notify_wq
: kacpid_wq
);
686 dpc
->wait
= hp
? 1 : 0;
688 if (queue
== kacpi_hotplug_wq
)
689 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
690 else if (queue
== kacpi_notify_wq
)
691 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
693 INIT_WORK(&dpc
->work
, acpi_os_execute_deferred
);
696 * On some machines, a software-initiated SMI causes corruption unless
697 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
698 * typically it's done in GPE-related methods that are run via
699 * workqueues, so we can avoid the known corruption cases by always
702 ret
= queue_work_on(0, queue
, &dpc
->work
);
705 printk(KERN_ERR PREFIX
706 "Call to queue_work() failed.\n");
713 acpi_status
acpi_os_execute(acpi_execute_type type
,
714 acpi_osd_exec_callback function
, void *context
)
716 return __acpi_os_execute(type
, function
, context
, 0);
718 EXPORT_SYMBOL(acpi_os_execute
);
720 acpi_status
acpi_os_hotplug_execute(acpi_osd_exec_callback function
,
723 return __acpi_os_execute(0, function
, context
, 1);
726 void acpi_os_wait_events_complete(void *context
)
728 flush_workqueue(kacpid_wq
);
729 flush_workqueue(kacpi_notify_wq
);
732 EXPORT_SYMBOL(acpi_os_wait_events_complete
);
735 * Allocate the memory for a spinlock and initialize it.
737 acpi_status
acpi_os_create_lock(acpi_spinlock
* handle
)
739 spin_lock_init(*handle
);
745 * Deallocate the memory for a spinlock.
747 void acpi_os_delete_lock(acpi_spinlock handle
)
753 acpi_os_create_semaphore(u32 max_units
, u32 initial_units
, acpi_handle
* handle
)
755 struct semaphore
*sem
= NULL
;
757 sem
= acpi_os_allocate(sizeof(struct semaphore
));
760 memset(sem
, 0, sizeof(struct semaphore
));
762 sema_init(sem
, initial_units
);
764 *handle
= (acpi_handle
*) sem
;
766 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Creating semaphore[%p|%d].\n",
767 *handle
, initial_units
));
773 * TODO: A better way to delete semaphores? Linux doesn't have a
774 * 'delete_semaphore()' function -- may result in an invalid
775 * pointer dereference for non-synchronized consumers. Should
776 * we at least check for blocked threads and signal/cancel them?
779 acpi_status
acpi_os_delete_semaphore(acpi_handle handle
)
781 struct semaphore
*sem
= (struct semaphore
*)handle
;
784 return AE_BAD_PARAMETER
;
786 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Deleting semaphore[%p].\n", handle
));
788 BUG_ON(!list_empty(&sem
->wait_list
));
796 * TODO: Support for units > 1?
798 acpi_status
acpi_os_wait_semaphore(acpi_handle handle
, u32 units
, u16 timeout
)
800 acpi_status status
= AE_OK
;
801 struct semaphore
*sem
= (struct semaphore
*)handle
;
805 if (!sem
|| (units
< 1))
806 return AE_BAD_PARAMETER
;
811 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Waiting for semaphore[%p|%d|%d]\n",
812 handle
, units
, timeout
));
814 if (timeout
== ACPI_WAIT_FOREVER
)
815 jiffies
= MAX_SCHEDULE_TIMEOUT
;
817 jiffies
= msecs_to_jiffies(timeout
);
819 ret
= down_timeout(sem
, jiffies
);
823 if (ACPI_FAILURE(status
)) {
824 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
825 "Failed to acquire semaphore[%p|%d|%d], %s",
826 handle
, units
, timeout
,
827 acpi_format_exception(status
)));
829 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
,
830 "Acquired semaphore[%p|%d|%d]", handle
,
838 * TODO: Support for units > 1?
840 acpi_status
acpi_os_signal_semaphore(acpi_handle handle
, u32 units
)
842 struct semaphore
*sem
= (struct semaphore
*)handle
;
844 if (!sem
|| (units
< 1))
845 return AE_BAD_PARAMETER
;
850 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX
, "Signaling semaphore[%p|%d]\n", handle
,
858 #ifdef ACPI_FUTURE_USAGE
859 u32
acpi_os_get_line(char *buffer
)
862 #ifdef ENABLE_DEBUGGER
863 if (acpi_in_debugger
) {
866 kdb_read(buffer
, sizeof(line_buf
));
868 /* remove the CR kdb includes */
869 chars
= strlen(buffer
) - 1;
870 buffer
[chars
] = '\0';
876 #endif /* ACPI_FUTURE_USAGE */
878 acpi_status
acpi_os_signal(u32 function
, void *info
)
881 case ACPI_SIGNAL_FATAL
:
882 printk(KERN_ERR PREFIX
"Fatal opcode executed\n");
884 case ACPI_SIGNAL_BREAKPOINT
:
887 * ACPI spec. says to treat it as a NOP unless
888 * you are debugging. So if/when we integrate
889 * AML debugger into the kernel debugger its
890 * hook will go here. But until then it is
891 * not useful to print anything on breakpoints.
901 static int __init
acpi_os_name_setup(char *str
)
903 char *p
= acpi_os_name
;
904 int count
= ACPI_MAX_OVERRIDE_LEN
- 1;
909 for (; count
-- && str
&& *str
; str
++) {
910 if (isalnum(*str
) || *str
== ' ' || *str
== ':')
912 else if (*str
== '\'' || *str
== '"')
923 __setup("acpi_os_name=", acpi_os_name_setup
);
925 static void __init
set_osi_linux(unsigned int enable
)
927 if (osi_linux
.enable
!= enable
) {
928 osi_linux
.enable
= enable
;
929 printk(KERN_NOTICE PREFIX
"%sed _OSI(Linux)\n",
930 enable
? "Add": "Delet");
933 if (osi_linux
.enable
)
934 acpi_osi_setup("Linux");
936 acpi_osi_setup("!Linux");
941 static void __init
acpi_cmdline_osi_linux(unsigned int enable
)
943 osi_linux
.cmdline
= 1; /* cmdline set the default */
944 set_osi_linux(enable
);
949 void __init
acpi_dmi_osi_linux(int enable
, const struct dmi_system_id
*d
)
951 osi_linux
.dmi
= 1; /* DMI knows that this box asks OSI(Linux) */
953 printk(KERN_NOTICE PREFIX
"DMI detected: %s\n", d
->ident
);
958 osi_linux
.known
= 1; /* DMI knows which OSI(Linux) default needed */
960 set_osi_linux(enable
);
966 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
968 * empty string disables _OSI
969 * string starting with '!' disables that string
970 * otherwise string is added to list, augmenting built-in strings
972 static void __init
acpi_osi_setup_late(void)
974 char *str
= osi_setup_string
;
979 if (!strcmp("!Linux", str
)) {
980 acpi_cmdline_osi_linux(0); /* !enable */
981 } else if (*str
== '!') {
982 if (acpi_remove_interface(++str
) == AE_OK
)
983 printk(KERN_INFO PREFIX
"Deleted _OSI(%s)\n", str
);
984 } else if (!strcmp("Linux", str
)) {
985 acpi_cmdline_osi_linux(1); /* enable */
987 if (acpi_install_interface(str
) == AE_OK
)
988 printk(KERN_INFO PREFIX
"Added _OSI(%s)\n", str
);
992 int __init
acpi_osi_setup(char *str
)
994 if (str
== NULL
|| *str
== '\0') {
995 printk(KERN_INFO PREFIX
"_OSI method disabled\n");
996 acpi_gbl_create_osi_method
= FALSE
;
998 strncpy(osi_setup_string
, str
, OSI_STRING_LENGTH_MAX
);
1004 __setup("acpi_osi=", acpi_osi_setup
);
1006 /* enable serialization to combat AE_ALREADY_EXISTS errors */
1007 static int __init
acpi_serialize_setup(char *str
)
1009 printk(KERN_INFO PREFIX
"serialize enabled\n");
1011 acpi_gbl_all_methods_serialized
= TRUE
;
1016 __setup("acpi_serialize", acpi_serialize_setup
);
1018 /* Check of resource interference between native drivers and ACPI
1019 * OperationRegions (SystemIO and System Memory only).
1020 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1021 * in arbitrary AML code and can interfere with legacy drivers.
1022 * acpi_enforce_resources= can be set to:
1024 * - strict (default) (2)
1025 * -> further driver trying to access the resources will not load
1027 * -> further driver trying to access the resources will load, but you
1028 * get a system message that something might go wrong...
1031 * -> ACPI Operation Region resources will not be registered
1034 #define ENFORCE_RESOURCES_STRICT 2
1035 #define ENFORCE_RESOURCES_LAX 1
1036 #define ENFORCE_RESOURCES_NO 0
1038 static unsigned int acpi_enforce_resources
= ENFORCE_RESOURCES_STRICT
;
1040 static int __init
acpi_enforce_resources_setup(char *str
)
1042 if (str
== NULL
|| *str
== '\0')
1045 if (!strcmp("strict", str
))
1046 acpi_enforce_resources
= ENFORCE_RESOURCES_STRICT
;
1047 else if (!strcmp("lax", str
))
1048 acpi_enforce_resources
= ENFORCE_RESOURCES_LAX
;
1049 else if (!strcmp("no", str
))
1050 acpi_enforce_resources
= ENFORCE_RESOURCES_NO
;
1055 __setup("acpi_enforce_resources=", acpi_enforce_resources_setup
);
1057 /* Check for resource conflicts between ACPI OperationRegions and native
1059 int acpi_check_resource_conflict(const struct resource
*res
)
1061 struct acpi_res_list
*res_list_elem
;
1065 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1067 if (!(res
->flags
& IORESOURCE_IO
) && !(res
->flags
& IORESOURCE_MEM
))
1070 ioport
= res
->flags
& IORESOURCE_IO
;
1072 spin_lock(&acpi_res_lock
);
1073 list_for_each_entry(res_list_elem
, &resource_list_head
,
1075 if (ioport
&& (res_list_elem
->resource_type
1076 != ACPI_ADR_SPACE_SYSTEM_IO
))
1078 if (!ioport
&& (res_list_elem
->resource_type
1079 != ACPI_ADR_SPACE_SYSTEM_MEMORY
))
1082 if (res
->end
< res_list_elem
->start
1083 || res_list_elem
->end
< res
->start
)
1088 spin_unlock(&acpi_res_lock
);
1091 if (acpi_enforce_resources
!= ENFORCE_RESOURCES_NO
) {
1092 printk(KERN_WARNING
"ACPI: resource %s %pR"
1093 " conflicts with ACPI region %s %pR\n",
1094 res
->name
, res
, res_list_elem
->name
,
1096 if (acpi_enforce_resources
== ENFORCE_RESOURCES_LAX
)
1097 printk(KERN_NOTICE
"ACPI: This conflict may"
1098 " cause random problems and system"
1100 printk(KERN_INFO
"ACPI: If an ACPI driver is available"
1101 " for this device, you should use it instead of"
1102 " the native driver\n");
1104 if (acpi_enforce_resources
== ENFORCE_RESOURCES_STRICT
)
1109 EXPORT_SYMBOL(acpi_check_resource_conflict
);
1111 int acpi_check_region(resource_size_t start
, resource_size_t n
,
1114 struct resource res
= {
1116 .end
= start
+ n
- 1,
1118 .flags
= IORESOURCE_IO
,
1121 return acpi_check_resource_conflict(&res
);
1123 EXPORT_SYMBOL(acpi_check_region
);
1125 int acpi_check_mem_region(resource_size_t start
, resource_size_t n
,
1128 struct resource res
= {
1130 .end
= start
+ n
- 1,
1132 .flags
= IORESOURCE_MEM
,
1135 return acpi_check_resource_conflict(&res
);
1138 EXPORT_SYMBOL(acpi_check_mem_region
);
1141 * Let drivers know whether the resource checks are effective
1143 int acpi_resources_are_enforced(void)
1145 return acpi_enforce_resources
== ENFORCE_RESOURCES_STRICT
;
1147 EXPORT_SYMBOL(acpi_resources_are_enforced
);
1150 * Acquire a spinlock.
1152 * handle is a pointer to the spinlock_t.
1155 acpi_cpu_flags
acpi_os_acquire_lock(acpi_spinlock lockp
)
1157 acpi_cpu_flags flags
;
1158 spin_lock_irqsave(lockp
, flags
);
1163 * Release a spinlock. See above.
1166 void acpi_os_release_lock(acpi_spinlock lockp
, acpi_cpu_flags flags
)
1168 spin_unlock_irqrestore(lockp
, flags
);
1171 #ifndef ACPI_USE_LOCAL_CACHE
1173 /*******************************************************************************
1175 * FUNCTION: acpi_os_create_cache
1177 * PARAMETERS: name - Ascii name for the cache
1178 * size - Size of each cached object
1179 * depth - Maximum depth of the cache (in objects) <ignored>
1180 * cache - Where the new cache object is returned
1184 * DESCRIPTION: Create a cache object
1186 ******************************************************************************/
1189 acpi_os_create_cache(char *name
, u16 size
, u16 depth
, acpi_cache_t
** cache
)
1191 *cache
= kmem_cache_create(name
, size
, 0, 0, NULL
);
1198 /*******************************************************************************
1200 * FUNCTION: acpi_os_purge_cache
1202 * PARAMETERS: Cache - Handle to cache object
1206 * DESCRIPTION: Free all objects within the requested cache.
1208 ******************************************************************************/
1210 acpi_status
acpi_os_purge_cache(acpi_cache_t
* cache
)
1212 kmem_cache_shrink(cache
);
1216 /*******************************************************************************
1218 * FUNCTION: acpi_os_delete_cache
1220 * PARAMETERS: Cache - Handle to cache object
1224 * DESCRIPTION: Free all objects within the requested cache and delete the
1227 ******************************************************************************/
1229 acpi_status
acpi_os_delete_cache(acpi_cache_t
* cache
)
1231 kmem_cache_destroy(cache
);
1235 /*******************************************************************************
1237 * FUNCTION: acpi_os_release_object
1239 * PARAMETERS: Cache - Handle to cache object
1240 * Object - The object to be released
1244 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1245 * the object is deleted.
1247 ******************************************************************************/
1249 acpi_status
acpi_os_release_object(acpi_cache_t
* cache
, void *object
)
1251 kmem_cache_free(cache
, object
);
1255 static inline int acpi_res_list_add(struct acpi_res_list
*res
)
1257 struct acpi_res_list
*res_list_elem
;
1259 list_for_each_entry(res_list_elem
, &resource_list_head
,
1262 if (res
->resource_type
== res_list_elem
->resource_type
&&
1263 res
->start
== res_list_elem
->start
&&
1264 res
->end
== res_list_elem
->end
) {
1267 * The Region(addr,len) already exist in the list,
1268 * just increase the count
1271 res_list_elem
->count
++;
1277 list_add(&res
->resource_list
, &resource_list_head
);
1281 static inline void acpi_res_list_del(struct acpi_res_list
*res
)
1283 struct acpi_res_list
*res_list_elem
;
1285 list_for_each_entry(res_list_elem
, &resource_list_head
,
1288 if (res
->resource_type
== res_list_elem
->resource_type
&&
1289 res
->start
== res_list_elem
->start
&&
1290 res
->end
== res_list_elem
->end
) {
1293 * If the res count is decreased to 0,
1294 * remove and free it
1297 if (--res_list_elem
->count
== 0) {
1298 list_del(&res_list_elem
->resource_list
);
1299 kfree(res_list_elem
);
1307 acpi_os_invalidate_address(
1309 acpi_physical_address address
,
1312 struct acpi_res_list res
;
1315 case ACPI_ADR_SPACE_SYSTEM_IO
:
1316 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
1317 /* Only interference checks against SystemIO and SystemMemory
1319 res
.start
= address
;
1320 res
.end
= address
+ length
- 1;
1321 res
.resource_type
= space_id
;
1322 spin_lock(&acpi_res_lock
);
1323 acpi_res_list_del(&res
);
1324 spin_unlock(&acpi_res_lock
);
1326 case ACPI_ADR_SPACE_PCI_CONFIG
:
1327 case ACPI_ADR_SPACE_EC
:
1328 case ACPI_ADR_SPACE_SMBUS
:
1329 case ACPI_ADR_SPACE_CMOS
:
1330 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
1331 case ACPI_ADR_SPACE_DATA_TABLE
:
1332 case ACPI_ADR_SPACE_FIXED_HARDWARE
:
1338 /******************************************************************************
1340 * FUNCTION: acpi_os_validate_address
1342 * PARAMETERS: space_id - ACPI space ID
1343 * address - Physical address
1344 * length - Address length
1346 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1347 * should return AE_AML_ILLEGAL_ADDRESS.
1349 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1350 * the addresses accessed by AML operation regions.
1352 *****************************************************************************/
1355 acpi_os_validate_address (
1357 acpi_physical_address address
,
1361 struct acpi_res_list
*res
;
1363 if (acpi_enforce_resources
== ENFORCE_RESOURCES_NO
)
1367 case ACPI_ADR_SPACE_SYSTEM_IO
:
1368 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
1369 /* Only interference checks against SystemIO and SystemMemory
1371 res
= kzalloc(sizeof(struct acpi_res_list
), GFP_KERNEL
);
1374 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1375 strlcpy(res
->name
, name
, 5);
1376 res
->start
= address
;
1377 res
->end
= address
+ length
- 1;
1378 res
->resource_type
= space_id
;
1379 spin_lock(&acpi_res_lock
);
1380 added
= acpi_res_list_add(res
);
1381 spin_unlock(&acpi_res_lock
);
1382 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1383 "name: %s\n", added
? "Added" : "Already exist",
1384 (space_id
== ACPI_ADR_SPACE_SYSTEM_IO
)
1385 ? "SystemIO" : "System Memory",
1386 (unsigned long long)res
->start
,
1387 (unsigned long long)res
->end
,
1392 case ACPI_ADR_SPACE_PCI_CONFIG
:
1393 case ACPI_ADR_SPACE_EC
:
1394 case ACPI_ADR_SPACE_SMBUS
:
1395 case ACPI_ADR_SPACE_CMOS
:
1396 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
1397 case ACPI_ADR_SPACE_DATA_TABLE
:
1398 case ACPI_ADR_SPACE_FIXED_HARDWARE
: