Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * acpi_osl.c - OS-dependent functions ($Revision: 83 $) |
| 3 | * |
| 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 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 25 | * |
| 26 | */ |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/mm.h> |
| 32 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/interrupt.h> |
| 34 | #include <linux/kmod.h> |
| 35 | #include <linux/delay.h> |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 36 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/workqueue.h> |
| 38 | #include <linux/nmi.h> |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 39 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <acpi/acpi.h> |
| 41 | #include <asm/io.h> |
| 42 | #include <acpi/acpi_bus.h> |
| 43 | #include <acpi/processor.h> |
| 44 | #include <asm/uaccess.h> |
| 45 | |
| 46 | #include <linux/efi.h> |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define _COMPONENT ACPI_OS_SERVICES |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 49 | ACPI_MODULE_NAME("osl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define PREFIX "ACPI: " |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | struct acpi_os_dpc { |
| 52 | acpi_osd_exec_callback function; |
| 53 | void *context; |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 54 | struct work_struct work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
| 58 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE |
| 59 | #endif |
| 60 | |
| 61 | #ifdef ENABLE_DEBUGGER |
| 62 | #include <linux/kdb.h> |
| 63 | |
| 64 | /* stuff for debugger support */ |
| 65 | int acpi_in_debugger; |
| 66 | EXPORT_SYMBOL(acpi_in_debugger); |
| 67 | |
| 68 | extern char line_buf[80]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | #endif /*ENABLE_DEBUGGER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | static unsigned int acpi_irq_irq; |
| 72 | static acpi_osd_handler acpi_irq_handler; |
| 73 | static void *acpi_irq_context; |
| 74 | static struct workqueue_struct *kacpid_wq; |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 75 | static struct workqueue_struct *kacpi_notify_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 77 | #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ |
| 78 | static char osi_additional_string[OSI_STRING_LENGTH_MAX]; |
| 79 | |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 80 | #define OSI_LINUX_ENABLED |
| 81 | #ifdef OSI_LINUX_ENABLED |
| 82 | int osi_linux = 1; /* enable _OSI(Linux) by default */ |
| 83 | #else |
| 84 | int osi_linux; /* disable _OSI(Linux) by default */ |
| 85 | #endif |
| 86 | |
| 87 | |
| 88 | #ifdef CONFIG_DMI |
Len Brown | dd272b5 | 2007-05-30 00:26:11 -0400 | [diff] [blame^] | 89 | static struct __initdata dmi_system_id acpi_osl_dmi_table[]; |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 90 | #endif |
| 91 | |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 92 | static void __init acpi_request_region (struct acpi_generic_address *addr, |
| 93 | unsigned int length, char *desc) |
| 94 | { |
| 95 | struct resource *res; |
| 96 | |
| 97 | if (!addr->address || !length) |
| 98 | return; |
| 99 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 100 | if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 101 | res = request_region(addr->address, length, desc); |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 102 | else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 103 | res = request_mem_region(addr->address, length, desc); |
| 104 | } |
| 105 | |
| 106 | static int __init acpi_reserve_resources(void) |
| 107 | { |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 108 | acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length, |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 109 | "ACPI PM1a_EVT_BLK"); |
| 110 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 111 | acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length, |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 112 | "ACPI PM1b_EVT_BLK"); |
| 113 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 114 | acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length, |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 115 | "ACPI PM1a_CNT_BLK"); |
| 116 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 117 | acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length, |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 118 | "ACPI PM1b_CNT_BLK"); |
| 119 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 120 | if (acpi_gbl_FADT.pm_timer_length == 4) |
| 121 | acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR"); |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 122 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 123 | acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length, |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 124 | "ACPI PM2_CNT_BLK"); |
| 125 | |
| 126 | /* Length of GPE blocks must be a non-negative multiple of 2 */ |
| 127 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 128 | if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) |
| 129 | acpi_request_region(&acpi_gbl_FADT.xgpe0_block, |
| 130 | acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK"); |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 131 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 132 | if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) |
| 133 | acpi_request_region(&acpi_gbl_FADT.xgpe1_block, |
| 134 | acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | device_initcall(acpi_reserve_resources); |
| 139 | |
Len Brown | dd272b5 | 2007-05-30 00:26:11 -0400 | [diff] [blame^] | 140 | acpi_status __init acpi_os_initialize(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 142 | dmi_check_system(acpi_osl_dmi_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return AE_OK; |
| 144 | } |
| 145 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 146 | acpi_status acpi_os_initialize1(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | /* |
| 149 | * Initialize PCI configuration space access, as we'll need to access |
| 150 | * it while walking the namespace (bus 0 and root bridges w/ _BBNs). |
| 151 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | if (!raw_pci_ops) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | printk(KERN_ERR PREFIX |
| 154 | "Access to PCI configuration space unavailable\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | return AE_NULL_ENTRY; |
| 156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | kacpid_wq = create_singlethread_workqueue("kacpid"); |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 158 | kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | BUG_ON(!kacpid_wq); |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 160 | BUG_ON(!kacpi_notify_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return AE_OK; |
| 162 | } |
| 163 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | acpi_status acpi_os_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
| 166 | if (acpi_irq_handler) { |
| 167 | acpi_os_remove_interrupt_handler(acpi_irq_irq, |
| 168 | acpi_irq_handler); |
| 169 | } |
| 170 | |
| 171 | destroy_workqueue(kacpid_wq); |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 172 | destroy_workqueue(kacpi_notify_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | return AE_OK; |
| 175 | } |
| 176 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | void acpi_os_printf(const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
| 179 | va_list args; |
| 180 | va_start(args, fmt); |
| 181 | acpi_os_vprintf(fmt, args); |
| 182 | va_end(args); |
| 183 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | EXPORT_SYMBOL(acpi_os_printf); |
| 186 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | void acpi_os_vprintf(const char *fmt, va_list args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
| 189 | static char buffer[512]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | vsprintf(buffer, fmt, args); |
| 192 | |
| 193 | #ifdef ENABLE_DEBUGGER |
| 194 | if (acpi_in_debugger) { |
| 195 | kdb_printf("%s", buffer); |
| 196 | } else { |
| 197 | printk("%s", buffer); |
| 198 | } |
| 199 | #else |
| 200 | printk("%s", buffer); |
| 201 | #endif |
| 202 | } |
| 203 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 204 | acpi_physical_address __init acpi_os_get_root_pointer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
| 206 | if (efi_enabled) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 207 | if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 208 | return efi.acpi20; |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 209 | else if (efi.acpi != EFI_INVALID_TABLE_ADDR) |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 210 | return efi.acpi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | printk(KERN_ERR PREFIX |
| 213 | "System description tables not found\n"); |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 214 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 216 | } else |
| 217 | return acpi_find_rsdp(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 220 | void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
Bjorn Helgaas | 9f4fd61 | 2006-03-26 01:37:10 -0800 | [diff] [blame] | 222 | if (phys > ULONG_MAX) { |
| 223 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); |
Randy Dunlap | 70c0846 | 2007-02-13 16:11:36 -0800 | [diff] [blame] | 224 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 226 | if (acpi_gbl_permanent_mmap) |
| 227 | /* |
| 228 | * ioremap checks to ensure this is in reserved space |
| 229 | */ |
| 230 | return ioremap((unsigned long)phys, size); |
| 231 | else |
| 232 | return __acpi_map_table((unsigned long)phys, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 234 | EXPORT_SYMBOL_GPL(acpi_os_map_memory); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 236 | void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 238 | if (acpi_gbl_permanent_mmap) { |
| 239 | iounmap(virt); |
| 240 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 242 | EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | #ifdef ACPI_FUTURE_USAGE |
| 245 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | if (!phys || !virt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return AE_BAD_PARAMETER; |
| 250 | |
| 251 | *phys = virt_to_phys(virt); |
| 252 | |
| 253 | return AE_OK; |
| 254 | } |
| 255 | #endif |
| 256 | |
| 257 | #define ACPI_MAX_OVERRIDE_LEN 100 |
| 258 | |
| 259 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; |
| 260 | |
| 261 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 262 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
| 263 | acpi_string * new_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | if (!init_val || !new_val) |
| 266 | return AE_BAD_PARAMETER; |
| 267 | |
| 268 | *new_val = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | acpi_os_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | *new_val = acpi_os_name; |
| 273 | } |
| 274 | |
| 275 | return AE_OK; |
| 276 | } |
| 277 | |
| 278 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | acpi_os_table_override(struct acpi_table_header * existing_table, |
| 280 | struct acpi_table_header ** new_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | if (!existing_table || !new_table) |
| 283 | return AE_BAD_PARAMETER; |
| 284 | |
| 285 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
| 286 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | *new_table = (struct acpi_table_header *)AmlCode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | else |
| 289 | *new_table = NULL; |
| 290 | #else |
| 291 | *new_table = NULL; |
| 292 | #endif |
| 293 | return AE_OK; |
| 294 | } |
| 295 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 296 | static irqreturn_t acpi_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
| 303 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
| 305 | unsigned int irq; |
| 306 | |
| 307 | /* |
| 308 | * Ignore the GSI from the core, and use the value in our copy of the |
| 309 | * FADT. It may not be the same if an interrupt source override exists |
| 310 | * for the SCI. |
| 311 | */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 312 | gsi = acpi_gbl_FADT.sci_interrupt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { |
| 314 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", |
| 315 | gsi); |
| 316 | return AE_OK; |
| 317 | } |
| 318 | |
| 319 | acpi_irq_handler = handler; |
| 320 | acpi_irq_context = context; |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 321 | if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); |
| 323 | return AE_NOT_ACQUIRED; |
| 324 | } |
| 325 | acpi_irq_irq = irq; |
| 326 | |
| 327 | return AE_OK; |
| 328 | } |
| 329 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | if (irq) { |
| 333 | free_irq(irq, acpi_irq); |
| 334 | acpi_irq_handler = NULL; |
| 335 | acpi_irq_irq = 0; |
| 336 | } |
| 337 | |
| 338 | return AE_OK; |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | * Running in interpreter thread context, safe to sleep |
| 343 | */ |
| 344 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | void acpi_os_sleep(acpi_integer ms) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Nishanth Aravamudan | 01a527e | 2005-11-07 01:01:14 -0800 | [diff] [blame] | 347 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | EXPORT_SYMBOL(acpi_os_sleep); |
| 351 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | void acpi_os_stall(u32 us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
| 354 | while (us) { |
| 355 | u32 delay = 1000; |
| 356 | |
| 357 | if (delay > us) |
| 358 | delay = us; |
| 359 | udelay(delay); |
| 360 | touch_nmi_watchdog(); |
| 361 | us -= delay; |
| 362 | } |
| 363 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | EXPORT_SYMBOL(acpi_os_stall); |
| 366 | |
| 367 | /* |
| 368 | * Support ACPI 3.0 AML Timer operand |
| 369 | * Returns 64-bit free-running, monotonically increasing timer |
| 370 | * with 100ns granularity |
| 371 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | u64 acpi_os_get_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
| 374 | static u64 t; |
| 375 | |
| 376 | #ifdef CONFIG_HPET |
| 377 | /* TBD: use HPET if available */ |
| 378 | #endif |
| 379 | |
| 380 | #ifdef CONFIG_X86_PM_TIMER |
| 381 | /* TBD: default to PM timer if HPET was not available */ |
| 382 | #endif |
| 383 | if (!t) |
| 384 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); |
| 385 | |
| 386 | return ++t; |
| 387 | } |
| 388 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
| 391 | u32 dummy; |
| 392 | |
| 393 | if (!value) |
| 394 | value = &dummy; |
| 395 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | switch (width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | case 8: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | *(u8 *) value = inb(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | break; |
| 400 | case 16: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | *(u16 *) value = inw(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | break; |
| 403 | case 32: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | *(u32 *) value = inl(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | break; |
| 406 | default: |
| 407 | BUG(); |
| 408 | } |
| 409 | |
| 410 | return AE_OK; |
| 411 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | EXPORT_SYMBOL(acpi_os_read_port); |
| 414 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | switch (width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | case 8: |
| 419 | outb(value, port); |
| 420 | break; |
| 421 | case 16: |
| 422 | outw(value, port); |
| 423 | break; |
| 424 | case 32: |
| 425 | outl(value, port); |
| 426 | break; |
| 427 | default: |
| 428 | BUG(); |
| 429 | } |
| 430 | |
| 431 | return AE_OK; |
| 432 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | EXPORT_SYMBOL(acpi_os_write_port); |
| 435 | |
| 436 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | u32 dummy; |
| 440 | void __iomem *virt_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Bjorn Helgaas | 9f4fd61 | 2006-03-26 01:37:10 -0800 | [diff] [blame] | 442 | virt_addr = ioremap(phys_addr, width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | if (!value) |
| 444 | value = &dummy; |
| 445 | |
| 446 | switch (width) { |
| 447 | case 8: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | *(u8 *) value = readb(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | break; |
| 450 | case 16: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 451 | *(u16 *) value = readw(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | break; |
| 453 | case 32: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | *(u32 *) value = readl(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | break; |
| 456 | default: |
| 457 | BUG(); |
| 458 | } |
| 459 | |
Bjorn Helgaas | 9f4fd61 | 2006-03-26 01:37:10 -0800 | [diff] [blame] | 460 | iounmap(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
| 462 | return AE_OK; |
| 463 | } |
| 464 | |
| 465 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 466 | acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | void __iomem *virt_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Bjorn Helgaas | 9f4fd61 | 2006-03-26 01:37:10 -0800 | [diff] [blame] | 470 | virt_addr = ioremap(phys_addr, width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | switch (width) { |
| 473 | case 8: |
| 474 | writeb(value, virt_addr); |
| 475 | break; |
| 476 | case 16: |
| 477 | writew(value, virt_addr); |
| 478 | break; |
| 479 | case 32: |
| 480 | writel(value, virt_addr); |
| 481 | break; |
| 482 | default: |
| 483 | BUG(); |
| 484 | } |
| 485 | |
Bjorn Helgaas | 9f4fd61 | 2006-03-26 01:37:10 -0800 | [diff] [blame] | 486 | iounmap(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
| 488 | return AE_OK; |
| 489 | } |
| 490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
| 493 | void *value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { |
| 495 | int result, size; |
| 496 | |
| 497 | if (!value) |
| 498 | return AE_BAD_PARAMETER; |
| 499 | |
| 500 | switch (width) { |
| 501 | case 8: |
| 502 | size = 1; |
| 503 | break; |
| 504 | case 16: |
| 505 | size = 2; |
| 506 | break; |
| 507 | case 32: |
| 508 | size = 4; |
| 509 | break; |
| 510 | default: |
| 511 | return AE_ERROR; |
| 512 | } |
| 513 | |
| 514 | BUG_ON(!raw_pci_ops); |
| 515 | |
| 516 | result = raw_pci_ops->read(pci_id->segment, pci_id->bus, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | PCI_DEVFN(pci_id->device, pci_id->function), |
| 518 | reg, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | return (result ? AE_ERROR : AE_OK); |
| 521 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | EXPORT_SYMBOL(acpi_os_read_pci_configuration); |
| 524 | |
| 525 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 526 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
| 527 | acpi_integer value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | int result, size; |
| 530 | |
| 531 | switch (width) { |
| 532 | case 8: |
| 533 | size = 1; |
| 534 | break; |
| 535 | case 16: |
| 536 | size = 2; |
| 537 | break; |
| 538 | case 32: |
| 539 | size = 4; |
| 540 | break; |
| 541 | default: |
| 542 | return AE_ERROR; |
| 543 | } |
| 544 | |
| 545 | BUG_ON(!raw_pci_ops); |
| 546 | |
| 547 | result = raw_pci_ops->write(pci_id->segment, pci_id->bus, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | PCI_DEVFN(pci_id->device, pci_id->function), |
| 549 | reg, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | return (result ? AE_ERROR : AE_OK); |
| 552 | } |
| 553 | |
| 554 | /* TODO: Change code to take advantage of driver model more */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 555 | static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */ |
| 556 | acpi_handle chandle, /* current node */ |
| 557 | struct acpi_pci_id **id, |
| 558 | int *is_bridge, u8 * bus_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 560 | acpi_handle handle; |
| 561 | struct acpi_pci_id *pci_id = *id; |
| 562 | acpi_status status; |
| 563 | unsigned long temp; |
| 564 | acpi_object_type type; |
| 565 | u8 tu8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
| 567 | acpi_get_parent(chandle, &handle); |
| 568 | if (handle != rhandle) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 569 | acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge, |
| 570 | bus_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | status = acpi_get_type(handle, &type); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | return; |
| 575 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 576 | status = |
| 577 | acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, |
| 578 | &temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | if (ACPI_SUCCESS(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 580 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp)); |
| 581 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | if (*is_bridge) |
| 584 | pci_id->bus = *bus_number; |
| 585 | |
| 586 | /* any nicer way to get bus number of bridge ? */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 587 | status = |
| 588 | acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8, |
| 589 | 8); |
| 590 | if (ACPI_SUCCESS(status) |
| 591 | && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) { |
| 592 | status = |
| 593 | acpi_os_read_pci_configuration(pci_id, 0x18, |
| 594 | &tu8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | if (!ACPI_SUCCESS(status)) { |
| 596 | /* Certainly broken... FIX ME */ |
| 597 | return; |
| 598 | } |
| 599 | *is_bridge = 1; |
| 600 | pci_id->bus = tu8; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 601 | status = |
| 602 | acpi_os_read_pci_configuration(pci_id, 0x19, |
| 603 | &tu8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | if (ACPI_SUCCESS(status)) { |
| 605 | *bus_number = tu8; |
| 606 | } |
| 607 | } else |
| 608 | *is_bridge = 0; |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 613 | void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ |
| 614 | acpi_handle chandle, /* current node */ |
| 615 | struct acpi_pci_id **id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
| 617 | int is_bridge = 1; |
| 618 | u8 bus_number = (*id)->bus; |
| 619 | |
| 620 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); |
| 621 | } |
| 622 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 623 | static void acpi_os_execute_deferred(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 625 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 626 | if (!dpc) { |
| 627 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | dpc->function(dpc->context); |
| 632 | kfree(dpc); |
| 633 | |
| 634 | /* Yield cpu to notify thread */ |
| 635 | cond_resched(); |
| 636 | |
| 637 | return; |
| 638 | } |
| 639 | |
| 640 | static void acpi_os_execute_notify(struct work_struct *work) |
| 641 | { |
| 642 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | if (!dpc) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 645 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 646 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | dpc->function(dpc->context); |
| 650 | |
| 651 | kfree(dpc); |
| 652 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 653 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 656 | /******************************************************************************* |
| 657 | * |
| 658 | * FUNCTION: acpi_os_execute |
| 659 | * |
| 660 | * PARAMETERS: Type - Type of the callback |
| 661 | * Function - Function to be executed |
| 662 | * Context - Function parameters |
| 663 | * |
| 664 | * RETURN: Status |
| 665 | * |
| 666 | * DESCRIPTION: Depending on type, either queues function for deferred execution or |
| 667 | * immediately executes function on a separate thread. |
| 668 | * |
| 669 | ******************************************************************************/ |
| 670 | |
| 671 | acpi_status acpi_os_execute(acpi_execute_type type, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 | acpi_osd_exec_callback function, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 674 | acpi_status status = AE_OK; |
| 675 | struct acpi_os_dpc *dpc; |
Len Brown | 72945b2 | 2006-07-12 22:46:42 -0400 | [diff] [blame] | 676 | |
Len Brown | 72945b2 | 2006-07-12 22:46:42 -0400 | [diff] [blame] | 677 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 678 | "Scheduling function [%p(%p)] for deferred execution.\n", |
| 679 | function, context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
| 681 | if (!function) |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 682 | return AE_BAD_PARAMETER; |
Len Brown | 72945b2 | 2006-07-12 22:46:42 -0400 | [diff] [blame] | 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | /* |
| 685 | * Allocate/initialize DPC structure. Note that this memory will be |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 686 | * freed by the callee. The kernel handles the work_struct list in a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | * way that allows us to also free its memory inside the callee. |
| 688 | * Because we may want to schedule several tasks with different |
| 689 | * parameters we can't use the approach some kernel code uses of |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 690 | * having a static work_struct. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | */ |
Len Brown | 72945b2 | 2006-07-12 22:46:42 -0400 | [diff] [blame] | 692 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 693 | dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (!dpc) |
Linus Torvalds | b976fe1 | 2006-11-17 19:31:09 -0800 | [diff] [blame] | 695 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | dpc->function = function; |
| 698 | dpc->context = context; |
Linus Torvalds | b976fe1 | 2006-11-17 19:31:09 -0800 | [diff] [blame] | 699 | |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 700 | if (type == OSL_NOTIFY_HANDLER) { |
| 701 | INIT_WORK(&dpc->work, acpi_os_execute_notify); |
| 702 | if (!queue_work(kacpi_notify_wq, &dpc->work)) { |
| 703 | status = AE_ERROR; |
| 704 | kfree(dpc); |
| 705 | } |
| 706 | } else { |
| 707 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); |
| 708 | if (!queue_work(kacpid_wq, &dpc->work)) { |
| 709 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Linus Torvalds | b976fe1 | 2006-11-17 19:31:09 -0800 | [diff] [blame] | 710 | "Call to queue_work() failed.\n")); |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 711 | status = AE_ERROR; |
| 712 | kfree(dpc); |
| 713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | } |
Linus Torvalds | b976fe1 | 2006-11-17 19:31:09 -0800 | [diff] [blame] | 715 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 717 | |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 718 | EXPORT_SYMBOL(acpi_os_execute); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 720 | void acpi_os_wait_events_complete(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
| 722 | flush_workqueue(kacpid_wq); |
| 723 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
| 726 | |
| 727 | /* |
| 728 | * Allocate the memory for a spinlock and initialize it. |
| 729 | */ |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 730 | acpi_status acpi_os_create_lock(acpi_spinlock * handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 732 | spin_lock_init(*handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 734 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | /* |
| 738 | * Deallocate the memory for a spinlock. |
| 739 | */ |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 740 | void acpi_os_delete_lock(acpi_spinlock handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 742 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 746 | acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 748 | struct semaphore *sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
| 751 | sem = acpi_os_allocate(sizeof(struct semaphore)); |
| 752 | if (!sem) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 753 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | memset(sem, 0, sizeof(struct semaphore)); |
| 755 | |
| 756 | sema_init(sem, initial_units); |
| 757 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 758 | *handle = (acpi_handle *) sem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 760 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
| 761 | *handle, initial_units)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 763 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 766 | EXPORT_SYMBOL(acpi_os_create_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
| 768 | /* |
| 769 | * TODO: A better way to delete semaphores? Linux doesn't have a |
| 770 | * 'delete_semaphore()' function -- may result in an invalid |
| 771 | * pointer dereference for non-synchronized consumers. Should |
| 772 | * we at least check for blocked threads and signal/cancel them? |
| 773 | */ |
| 774 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 775 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 777 | struct semaphore *sem = (struct semaphore *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
| 780 | if (!sem) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 781 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 783 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 785 | kfree(sem); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 786 | sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 788 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 791 | EXPORT_SYMBOL(acpi_os_delete_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
| 793 | /* |
| 794 | * TODO: The kernel doesn't have a 'down_timeout' function -- had to |
| 795 | * improvise. The process is to sleep for one scheduler quantum |
| 796 | * until the semaphore becomes available. Downside is that this |
| 797 | * may result in starvation for timeout-based waits when there's |
| 798 | * lots of semaphore activity. |
| 799 | * |
| 800 | * TODO: Support for units > 1? |
| 801 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 802 | acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 804 | acpi_status status = AE_OK; |
| 805 | struct semaphore *sem = (struct semaphore *)handle; |
| 806 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
| 809 | if (!sem || (units < 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 810 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
| 812 | if (units > 1) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 813 | return AE_SUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 815 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
| 816 | handle, units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Len Brown | d68909f | 2006-08-16 19:16:58 -0400 | [diff] [blame] | 818 | /* |
| 819 | * This can be called during resume with interrupts off. |
| 820 | * Like boot-time, we should be single threaded and will |
| 821 | * always get the lock if we try -- timeout or not. |
| 822 | * If this doesn't succeed, then we will oops courtesy of |
| 823 | * might_sleep() in down(). |
| 824 | */ |
| 825 | if (!down_trylock(sem)) |
| 826 | return AE_OK; |
| 827 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 828 | switch (timeout) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | /* |
| 830 | * No Wait: |
| 831 | * -------- |
| 832 | * A zero timeout value indicates that we shouldn't wait - just |
| 833 | * acquire the semaphore if available otherwise return AE_TIME |
| 834 | * (a.k.a. 'would block'). |
| 835 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 836 | case 0: |
| 837 | if (down_trylock(sem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | status = AE_TIME; |
| 839 | break; |
| 840 | |
| 841 | /* |
| 842 | * Wait Indefinitely: |
| 843 | * ------------------ |
| 844 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 845 | case ACPI_WAIT_FOREVER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | down(sem); |
| 847 | break; |
| 848 | |
| 849 | /* |
| 850 | * Wait w/ Timeout: |
| 851 | * ---------------- |
| 852 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 853 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | // TODO: A better timeout algorithm? |
| 855 | { |
| 856 | int i = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 857 | static const int quantum_ms = 1000 / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
| 859 | ret = down_trylock(sem); |
Yu Luming | dacd9b8 | 2005-12-31 01:45:00 -0500 | [diff] [blame] | 860 | for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) { |
Nishanth Aravamudan | 01a527e | 2005-11-07 01:01:14 -0800 | [diff] [blame] | 861 | schedule_timeout_interruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | ret = down_trylock(sem); |
| 863 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | if (ret != 0) |
| 866 | status = AE_TIME; |
| 867 | } |
| 868 | break; |
| 869 | } |
| 870 | |
| 871 | if (ACPI_FAILURE(status)) { |
Bjorn Helgaas | 9e7e2c0 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 872 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 873 | "Failed to acquire semaphore[%p|%d|%d], %s", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 874 | handle, units, timeout, |
| 875 | acpi_format_exception(status))); |
| 876 | } else { |
| 877 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 878 | "Acquired semaphore[%p|%d|%d]", handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 879 | units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 882 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 885 | EXPORT_SYMBOL(acpi_os_wait_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | /* |
| 888 | * TODO: Support for units > 1? |
| 889 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 890 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 892 | struct semaphore *sem = (struct semaphore *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | if (!sem || (units < 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 896 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
| 898 | if (units > 1) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 899 | return AE_SUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 901 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
| 902 | units)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | up(sem); |
| 905 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 906 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 908 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | EXPORT_SYMBOL(acpi_os_signal_semaphore); |
| 910 | |
| 911 | #ifdef ACPI_FUTURE_USAGE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 912 | u32 acpi_os_get_line(char *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | { |
| 914 | |
| 915 | #ifdef ENABLE_DEBUGGER |
| 916 | if (acpi_in_debugger) { |
| 917 | u32 chars; |
| 918 | |
| 919 | kdb_read(buffer, sizeof(line_buf)); |
| 920 | |
| 921 | /* remove the CR kdb includes */ |
| 922 | chars = strlen(buffer) - 1; |
| 923 | buffer[chars] = '\0'; |
| 924 | } |
| 925 | #endif |
| 926 | |
| 927 | return 0; |
| 928 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 929 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 931 | acpi_status acpi_os_signal(u32 function, void *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 933 | switch (function) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | case ACPI_SIGNAL_FATAL: |
| 935 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); |
| 936 | break; |
| 937 | case ACPI_SIGNAL_BREAKPOINT: |
| 938 | /* |
| 939 | * AML Breakpoint |
| 940 | * ACPI spec. says to treat it as a NOP unless |
| 941 | * you are debugging. So if/when we integrate |
| 942 | * AML debugger into the kernel debugger its |
| 943 | * hook will go here. But until then it is |
| 944 | * not useful to print anything on breakpoints. |
| 945 | */ |
| 946 | break; |
| 947 | default: |
| 948 | break; |
| 949 | } |
| 950 | |
| 951 | return AE_OK; |
| 952 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | EXPORT_SYMBOL(acpi_os_signal); |
| 955 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 956 | static int __init acpi_os_name_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | { |
| 958 | char *p = acpi_os_name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 959 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
| 961 | if (!str || !*str) |
| 962 | return 0; |
| 963 | |
| 964 | for (; count-- && str && *str; str++) { |
| 965 | if (isalnum(*str) || *str == ' ' || *str == ':') |
| 966 | *p++ = *str; |
| 967 | else if (*str == '\'' || *str == '"') |
| 968 | continue; |
| 969 | else |
| 970 | break; |
| 971 | } |
| 972 | *p = 0; |
| 973 | |
| 974 | return 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | __setup("acpi_os_name=", acpi_os_name_setup); |
| 979 | |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 980 | static void enable_osi_linux(int enable) { |
| 981 | |
| 982 | if (osi_linux != enable) |
| 983 | printk(KERN_INFO PREFIX "%sabled _OSI(Linux)\n", |
| 984 | enable ? "En": "Dis"); |
| 985 | |
| 986 | osi_linux = enable; |
| 987 | return; |
| 988 | } |
| 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | /* |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 991 | * Modify the list of "OS Interfaces" reported to BIOS via _OSI |
| 992 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | * empty string disables _OSI |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 994 | * string starting with '!' disables that string |
| 995 | * otherwise string is added to list, augmenting built-in strings |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 997 | static int __init acpi_osi_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | { |
| 999 | if (str == NULL || *str == '\0') { |
| 1000 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); |
| 1001 | acpi_gbl_create_osi_method = FALSE; |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 1002 | } else if (*str == '!') { |
| 1003 | if (acpi_osi_invalidate(++str) == AE_OK) |
| 1004 | printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 1005 | } else if (!strcmp("!Linux", str)) { |
| 1006 | enable_osi_linux(0); |
| 1007 | } else if (!strcmp("Linux", str)) { |
| 1008 | enable_osi_linux(1); |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 1009 | } else if (*osi_additional_string == '\0') { |
| 1010 | strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX); |
| 1011 | printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | return 1; |
| 1015 | } |
| 1016 | |
| 1017 | __setup("acpi_osi=", acpi_osi_setup); |
| 1018 | |
| 1019 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1020 | static int __init acpi_serialize_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | { |
| 1022 | printk(KERN_INFO PREFIX "serialize enabled\n"); |
| 1023 | |
| 1024 | acpi_gbl_all_methods_serialized = TRUE; |
| 1025 | |
| 1026 | return 1; |
| 1027 | } |
| 1028 | |
| 1029 | __setup("acpi_serialize", acpi_serialize_setup); |
| 1030 | |
| 1031 | /* |
| 1032 | * Wake and Run-Time GPES are expected to be separate. |
| 1033 | * We disable wake-GPEs at run-time to prevent spurious |
| 1034 | * interrupts. |
| 1035 | * |
| 1036 | * However, if a system exists that shares Wake and |
| 1037 | * Run-time events on the same GPE this flag is available |
| 1038 | * to tell Linux to keep the wake-time GPEs enabled at run-time. |
| 1039 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1040 | static int __init acpi_wake_gpes_always_on_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | { |
| 1042 | printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); |
| 1043 | |
| 1044 | acpi_gbl_leave_wake_gpes_disabled = FALSE; |
| 1045 | |
| 1046 | return 1; |
| 1047 | } |
| 1048 | |
| 1049 | __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); |
| 1050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | /* |
| 1052 | * max_cstate is defined in the base kernel so modules can |
| 1053 | * change it w/o depending on the state of the processor module. |
| 1054 | */ |
| 1055 | unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER; |
| 1056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | EXPORT_SYMBOL(max_cstate); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1058 | |
| 1059 | /* |
| 1060 | * Acquire a spinlock. |
| 1061 | * |
| 1062 | * handle is a pointer to the spinlock_t. |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1063 | */ |
| 1064 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1065 | acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1066 | { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1067 | acpi_cpu_flags flags; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1068 | spin_lock_irqsave(lockp, flags); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1069 | return flags; |
| 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * Release a spinlock. See above. |
| 1074 | */ |
| 1075 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1076 | void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1077 | { |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1078 | spin_unlock_irqrestore(lockp, flags); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1081 | #ifndef ACPI_USE_LOCAL_CACHE |
| 1082 | |
| 1083 | /******************************************************************************* |
| 1084 | * |
| 1085 | * FUNCTION: acpi_os_create_cache |
| 1086 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1087 | * PARAMETERS: name - Ascii name for the cache |
| 1088 | * size - Size of each cached object |
| 1089 | * depth - Maximum depth of the cache (in objects) <ignored> |
| 1090 | * cache - Where the new cache object is returned |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1091 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1092 | * RETURN: status |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1093 | * |
| 1094 | * DESCRIPTION: Create a cache object |
| 1095 | * |
| 1096 | ******************************************************************************/ |
| 1097 | |
| 1098 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1099 | acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1100 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1101 | *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL); |
Adrian Bunk | a6fdbf9 | 2006-12-19 12:56:13 -0800 | [diff] [blame] | 1102 | if (*cache == NULL) |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1103 | return AE_ERROR; |
| 1104 | else |
| 1105 | return AE_OK; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | /******************************************************************************* |
| 1109 | * |
| 1110 | * FUNCTION: acpi_os_purge_cache |
| 1111 | * |
| 1112 | * PARAMETERS: Cache - Handle to cache object |
| 1113 | * |
| 1114 | * RETURN: Status |
| 1115 | * |
| 1116 | * DESCRIPTION: Free all objects within the requested cache. |
| 1117 | * |
| 1118 | ******************************************************************************/ |
| 1119 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1120 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1121 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1122 | kmem_cache_shrink(cache); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1123 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /******************************************************************************* |
| 1127 | * |
| 1128 | * FUNCTION: acpi_os_delete_cache |
| 1129 | * |
| 1130 | * PARAMETERS: Cache - Handle to cache object |
| 1131 | * |
| 1132 | * RETURN: Status |
| 1133 | * |
| 1134 | * DESCRIPTION: Free all objects within the requested cache and delete the |
| 1135 | * cache object. |
| 1136 | * |
| 1137 | ******************************************************************************/ |
| 1138 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1139 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1140 | { |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 1141 | kmem_cache_destroy(cache); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1142 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /******************************************************************************* |
| 1146 | * |
| 1147 | * FUNCTION: acpi_os_release_object |
| 1148 | * |
| 1149 | * PARAMETERS: Cache - Handle to cache object |
| 1150 | * Object - The object to be released |
| 1151 | * |
| 1152 | * RETURN: None |
| 1153 | * |
| 1154 | * DESCRIPTION: Release an object to the specified cache. If cache is full, |
| 1155 | * the object is deleted. |
| 1156 | * |
| 1157 | ******************************************************************************/ |
| 1158 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1159 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1160 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1161 | kmem_cache_free(cache, object); |
| 1162 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1163 | } |
| 1164 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1165 | /****************************************************************************** |
| 1166 | * |
| 1167 | * FUNCTION: acpi_os_validate_interface |
| 1168 | * |
| 1169 | * PARAMETERS: interface - Requested interface to be validated |
| 1170 | * |
| 1171 | * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise |
| 1172 | * |
| 1173 | * DESCRIPTION: Match an interface string to the interfaces supported by the |
| 1174 | * host. Strings originate from an AML call to the _OSI method. |
| 1175 | * |
| 1176 | *****************************************************************************/ |
| 1177 | |
| 1178 | acpi_status |
| 1179 | acpi_os_validate_interface (char *interface) |
| 1180 | { |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 1181 | if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX)) |
| 1182 | return AE_OK; |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 1183 | if (!strcmp("Linux", interface)) { |
| 1184 | printk(KERN_WARNING PREFIX |
| 1185 | "System BIOS is requesting _OSI(Linux)\n"); |
| 1186 | #ifdef OSI_LINUX_ENABLED |
| 1187 | printk(KERN_WARNING PREFIX |
| 1188 | "Please test with \"acpi_osi=!Linux\"\n" |
| 1189 | "Please send dmidecode " |
| 1190 | "to linux-acpi@vger.kernel.org\n"); |
| 1191 | #else |
| 1192 | printk(KERN_WARNING PREFIX |
| 1193 | "If \"acpi_osi=Linux\" works better,\n" |
| 1194 | "Please send dmidecode " |
| 1195 | "to linux-acpi@vger.kernel.org\n"); |
| 1196 | #endif |
| 1197 | if(osi_linux) |
| 1198 | return AE_OK; |
| 1199 | } |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 1200 | return AE_SUPPORT; |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1203 | /****************************************************************************** |
| 1204 | * |
| 1205 | * FUNCTION: acpi_os_validate_address |
| 1206 | * |
| 1207 | * PARAMETERS: space_id - ACPI space ID |
| 1208 | * address - Physical address |
| 1209 | * length - Address length |
| 1210 | * |
| 1211 | * RETURN: AE_OK if address/length is valid for the space_id. Otherwise, |
| 1212 | * should return AE_AML_ILLEGAL_ADDRESS. |
| 1213 | * |
| 1214 | * DESCRIPTION: Validate a system address via the host OS. Used to validate |
| 1215 | * the addresses accessed by AML operation regions. |
| 1216 | * |
| 1217 | *****************************************************************************/ |
| 1218 | |
| 1219 | acpi_status |
| 1220 | acpi_os_validate_address ( |
| 1221 | u8 space_id, |
| 1222 | acpi_physical_address address, |
| 1223 | acpi_size length) |
| 1224 | { |
| 1225 | |
| 1226 | return AE_OK; |
| 1227 | } |
| 1228 | |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 1229 | #ifdef CONFIG_DMI |
| 1230 | #ifdef OSI_LINUX_ENABLED |
| 1231 | static int dmi_osi_not_linux(struct dmi_system_id *d) |
| 1232 | { |
| 1233 | printk(KERN_NOTICE "%s detected: requires not _OSI(Linux)\n", d->ident); |
| 1234 | enable_osi_linux(0); |
| 1235 | return 0; |
| 1236 | } |
| 1237 | #else |
| 1238 | static int dmi_osi_linux(struct dmi_system_id *d) |
| 1239 | { |
| 1240 | printk(KERN_NOTICE "%s detected: requires _OSI(Linux)\n", d->ident); |
| 1241 | enable_osi_linux(1); |
| 1242 | return 0; |
| 1243 | } |
| 1244 | #endif |
| 1245 | |
Len Brown | dd272b5 | 2007-05-30 00:26:11 -0400 | [diff] [blame^] | 1246 | static struct dmi_system_id acpi_osl_dmi_table[] __initdata = { |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 1247 | #ifdef OSI_LINUX_ENABLED |
| 1248 | /* |
| 1249 | * Boxes that need NOT _OSI(Linux) |
| 1250 | */ |
| 1251 | { |
| 1252 | .callback = dmi_osi_not_linux, |
| 1253 | .ident = "Toshiba Satellite P100", |
| 1254 | .matches = { |
| 1255 | DMI_MATCH(DMI_BOARD_VENDOR, "TOSHIBA"), |
| 1256 | DMI_MATCH(DMI_BOARD_NAME, "Satellite P100"), |
| 1257 | }, |
| 1258 | }, |
| 1259 | #else |
| 1260 | /* |
| 1261 | * Boxes that need _OSI(Linux) |
| 1262 | */ |
| 1263 | { |
| 1264 | .callback = dmi_osi_linux, |
| 1265 | .ident = "Intel Napa CRB", |
| 1266 | .matches = { |
| 1267 | DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), |
| 1268 | DMI_MATCH(DMI_BOARD_NAME, "MPAD-MSAE Customer Reference Boards"), |
| 1269 | }, |
| 1270 | }, |
| 1271 | #endif |
| 1272 | {} |
| 1273 | }; |
| 1274 | #endif /* CONFIG_DMI */ |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1275 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1276 | #endif |