30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
35 #include <linux/pci.h>
45 #include <linux/list.h>
50 #include <asm/uaccess.h>
56 #define _COMPONENT ACPI_OS_SERVICES
58 #define PREFIX "ACPI: "
60 acpi_osd_exec_callback
function;
66 #ifdef CONFIG_ACPI_CUSTOM_DSDT
67 #include CONFIG_ACPI_CUSTOM_DSDT_FILE
70 #ifdef ENABLE_DEBUGGER
77 extern char line_buf[80];
80 static int (*__acpi_os_prepare_sleep)(
u8 sleep_state,
u32 pm1a_ctrl,
83 static acpi_osd_handler acpi_irq_handler;
84 static void *acpi_irq_context;
97 acpi_physical_address
phys;
105 static void __init acpi_osi_setup_late(
void);
140 static struct osi_linux {
144 } osi_linux = {0, 0, 0};
148 if (!
strcmp(
"Linux", interface)) {
151 "BIOS _OSI(Linux) query %s%s\n",
152 osi_linux.enable ?
"honored" :
"ignored",
153 osi_linux.cmdline ?
" via cmdline" :
154 osi_linux.dmi ?
" via DMI" :
"");
167 if (!addr || !length)
177 static int __init acpi_reserve_resources(
void)
180 "ACPI PM1a_EVT_BLK");
183 "ACPI PM1b_EVT_BLK");
186 "ACPI PM1a_CNT_BLK");
189 "ACPI PM1b_CNT_BLK");
192 acpi_request_region(&
acpi_gbl_FADT.xpm_timer_block, 4,
"ACPI PM_TMR");
225 #ifdef ENABLE_DEBUGGER
226 if (acpi_in_debugger) {
237 static unsigned long acpi_rsdp;
238 static int __init setup_acpi_rsdp(
char *
arg)
260 "System description tables not found\n");
264 acpi_physical_address pa = 0;
273 acpi_map_lookup(acpi_physical_address
phys, acpi_size
size)
277 list_for_each_entry_rcu(map, &acpi_ioremaps,
list)
278 if (map->phys <= phys &&
279 phys + size <= map->phys + map->size)
287 acpi_map_vaddr_lookup(acpi_physical_address phys,
unsigned int size)
291 map = acpi_map_lookup(phys, size);
293 return map->
virt + (phys - map->
phys);
304 map = acpi_map_lookup(phys, size);
306 virt = map->
virt + (phys - map->
phys);
316 acpi_map_lookup_virt(
void __iomem *
virt, acpi_size size)
320 list_for_each_entry_rcu(map, &acpi_ioremaps,
list)
321 if (map->virt <= virt &&
322 virt + size <= map->virt + map->size)
329 #define should_use_kmap(pfn) page_is_ram(pfn)
332 #define should_use_kmap(pfn) 0
335 static void __iomem *acpi_map(acpi_physical_address pg_off,
unsigned long pg_sz)
345 return acpi_os_ioremap(pg_off, pg_sz);
348 static void acpi_unmap(acpi_physical_address pg_off,
void __iomem *
vaddr)
364 acpi_physical_address pg_off;
377 map = acpi_map_lookup(phys, size);
391 virt = acpi_map(pg_off, pg_sz);
398 INIT_LIST_HEAD(&map->
list);
404 list_add_tail_rcu(&map->
list, &acpi_ioremaps);
408 return map->
virt + (phys - map->
phys);
412 static void acpi_os_drop_map_ref(
struct acpi_ioremap *map)
415 list_del_rcu(&map->
list);
418 static void acpi_os_map_cleanup(
struct acpi_ioremap *map)
437 map = acpi_map_lookup_virt(virt, size);
440 WARN(
true,
PREFIX "%s: bad address %p\n", __func__, virt);
443 acpi_os_drop_map_ref(map);
446 acpi_os_map_cleanup(map);
491 map = acpi_map_lookup(addr, gas->
bit_width / 8);
496 acpi_os_drop_map_ref(map);
499 acpi_os_map_cleanup(map);
503 #ifdef ACPI_FUTURE_USAGE
505 acpi_os_get_physical_address(
void *virt, acpi_physical_address * phys)
516 #define ACPI_MAX_OVERRIDE_LEN 100
524 if (!init_val || !new_val)
531 *new_val = acpi_os_name;
541 if (!existing_table || !new_table)
546 #ifdef CONFIG_ACPI_CUSTOM_DSDT
550 if (*new_table != NULL) {
552 "this is unsafe: tainting kernel\n",
562 acpi_physical_address * new_address,
563 u32 *new_table_length)
573 handled = (*acpi_irq_handler) (acpi_irq_context);
599 if (acpi_irq_handler)
608 acpi_irq_handler = handler;
612 acpi_irq_handler =
NULL;
625 acpi_irq_handler =
NULL;
665 #ifdef CONFIG_X86_PM_TIMER
683 *(
u8 *) value =
inb(port);
684 }
else if (width <= 16) {
685 *(
u16 *) value =
inw(port);
686 }
else if (width <= 32) {
687 *(
u32 *) value =
inl(port);
701 }
else if (width <= 16) {
703 }
else if (width <= 32) {
715 static inline u64 read64(
const volatile void __iomem *addr)
720 static inline u64 read64(
const volatile void __iomem *addr)
725 return l | (h << 32);
733 unsigned int size = width / 8;
738 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
741 virt_addr = acpi_os_ioremap(phys_addr, size);
752 *(
u8 *) value =
readb(virt_addr);
761 *(
u64 *) value = read64(virt_addr);
776 static inline void write64(
u64 val,
volatile void __iomem *addr)
781 static inline void write64(
u64 val,
volatile void __iomem *addr)
792 unsigned int size = width / 8;
796 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
799 virt_addr = acpi_os_ioremap(phys_addr, size);
816 write64(value, virt_addr);
856 reg, size, &value32);
916 acpi_osd_exec_callback
function,
void *
context,
int hp)
923 "Scheduling function [%p(%p)] for deferred execution.\n",
948 queue = hp ? kacpi_hotplug_wq :
950 dpc->
wait = hp ? 1 : 0;
952 if (queue == kacpi_hotplug_wq)
954 else if (queue == kacpi_notify_wq)
970 "Call to queue_work() failed.\n");
978 acpi_osd_exec_callback
function,
void *context)
980 return __acpi_os_execute(type,
function, context, 0);
987 return __acpi_os_execute(0,
function, context, 1);
1008 sema_init(sem, initial_units);
1013 *handle, initial_units));
1051 if (!sem || (units < 1))
1058 handle, units, timeout));
1071 "Failed to acquire semaphore[%p|%d|%d], %s",
1072 handle, units, timeout,
1076 "Acquired semaphore[%p|%d|%d]", handle,
1090 if (!sem || (units < 1))
1104 #ifdef ACPI_FUTURE_USAGE
1108 #ifdef ENABLE_DEBUGGER
1109 if (acpi_in_debugger) {
1112 kdb_read(buffer,
sizeof(line_buf));
1115 chars =
strlen(buffer) - 1;
1116 buffer[chars] =
'\0';
1147 static int __init acpi_os_name_setup(
char *
str)
1149 char *
p = acpi_os_name;
1155 for (; count-- && str && *
str; str++) {
1156 if (
isalnum(*str) || *str ==
' ' || *str ==
':')
1158 else if (*str ==
'\'' || *str ==
'"')
1169 __setup(
"acpi_os_name=", acpi_os_name_setup);
1171 #define OSI_STRING_LENGTH_MAX 64
1172 #define OSI_STRING_ENTRIES_MAX 16
1181 {
"Module Device",
true},
1182 {
"Processor Device",
true},
1183 {
"3.0 _SCP Extensions",
true},
1184 {
"Processor Aggregator Device",
true},
1196 if (str == NULL || *str ==
'\0') {
1208 osi = &osi_setup_entries[
i];
1212 }
else if (osi->
string[0] ==
'\0') {
1222 if (osi_linux.enable != enable)
1223 osi_linux.enable =
enable;
1225 if (osi_linux.enable)
1233 static void __init acpi_cmdline_osi_linux(
unsigned int enable)
1235 osi_linux.cmdline = 1;
1237 set_osi_linux(enable);
1250 set_osi_linux(enable);
1262 static void __init acpi_osi_setup_late(
void)
1270 osi = &osi_setup_entries[
i];
1289 static int __init osi_setup(
char *str)
1291 if (str && !
strcmp(
"Linux", str))
1292 acpi_cmdline_osi_linux(1);
1293 else if (str && !
strcmp(
"!Linux", str))
1294 acpi_cmdline_osi_linux(0);
1301 __setup(
"acpi_osi=", osi_setup);
1304 static int __init acpi_serialize_setup(
char *str)
1313 __setup(
"acpi_serialize", acpi_serialize_setup);
1331 #define ENFORCE_RESOURCES_STRICT 2
1332 #define ENFORCE_RESOURCES_LAX 1
1333 #define ENFORCE_RESOURCES_NO 0
1337 static int __init acpi_enforce_resources_setup(
char *str)
1339 if (str == NULL || *str ==
'\0')
1342 if (!
strcmp(
"strict", str))
1344 else if (!
strcmp(
"lax", str))
1346 else if (!
strcmp(
"no", str))
1352 __setup(
"acpi_enforce_resources=", acpi_enforce_resources_setup);
1373 length = res->
end - res->
start + 1;
1382 " cause random problems and system"
1385 " for this device, you should use it instead of"
1386 " the native driver\n");
1400 .end = start + n - 1,
1445 spin_unlock_irqrestore(lockp, flags);
1448 #ifndef ACPI_USE_LOCAL_CACHE
1549 BUG_ON(!kacpi_notify_wq);
1550 BUG_ON(!kacpi_hotplug_wq);
1552 acpi_osi_setup_late();
1558 if (acpi_irq_handler) {
1579 if (__acpi_os_prepare_sleep)
1580 rc = __acpi_os_prepare_sleep(sleep_state,
1581 pm1a_control, pm1b_control);
1591 u32 pm1a_ctrl,
u32 pm1b_ctrl))
1593 __acpi_os_prepare_sleep =
func;