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 | |
| 28 | #include <linux/config.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/mm.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/smp_lock.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 <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 | 4be44fc | 2005-08-05 00:44:28 -0400 | [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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
| 57 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE |
| 58 | #endif |
| 59 | |
| 60 | #ifdef ENABLE_DEBUGGER |
| 61 | #include <linux/kdb.h> |
| 62 | |
| 63 | /* stuff for debugger support */ |
| 64 | int acpi_in_debugger; |
| 65 | EXPORT_SYMBOL(acpi_in_debugger); |
| 66 | |
| 67 | extern char line_buf[80]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | #endif /*ENABLE_DEBUGGER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Luming Yu | 30e332f | 2005-08-12 00:31:00 -0400 | [diff] [blame] | 70 | int acpi_specific_hotkey_enabled = TRUE; |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 71 | EXPORT_SYMBOL(acpi_specific_hotkey_enabled); |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static unsigned int acpi_irq_irq; |
| 74 | static acpi_osd_handler acpi_irq_handler; |
| 75 | static void *acpi_irq_context; |
| 76 | static struct workqueue_struct *kacpid_wq; |
| 77 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | acpi_status acpi_os_initialize(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | return AE_OK; |
| 81 | } |
| 82 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | acpi_status acpi_os_initialize1(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
| 85 | /* |
| 86 | * Initialize PCI configuration space access, as we'll need to access |
| 87 | * it while walking the namespace (bus 0 and root bridges w/ _BBNs). |
| 88 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | if (!raw_pci_ops) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | printk(KERN_ERR PREFIX |
| 91 | "Access to PCI configuration space unavailable\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return AE_NULL_ENTRY; |
| 93 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | kacpid_wq = create_singlethread_workqueue("kacpid"); |
| 95 | BUG_ON(!kacpid_wq); |
| 96 | |
| 97 | return AE_OK; |
| 98 | } |
| 99 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 100 | acpi_status acpi_os_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | if (acpi_irq_handler) { |
| 103 | acpi_os_remove_interrupt_handler(acpi_irq_irq, |
| 104 | acpi_irq_handler); |
| 105 | } |
| 106 | |
| 107 | destroy_workqueue(kacpid_wq); |
| 108 | |
| 109 | return AE_OK; |
| 110 | } |
| 111 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | void acpi_os_printf(const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
| 114 | va_list args; |
| 115 | va_start(args, fmt); |
| 116 | acpi_os_vprintf(fmt, args); |
| 117 | va_end(args); |
| 118 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | EXPORT_SYMBOL(acpi_os_printf); |
| 121 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | void acpi_os_vprintf(const char *fmt, va_list args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | static char buffer[512]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | vsprintf(buffer, fmt, args); |
| 127 | |
| 128 | #ifdef ENABLE_DEBUGGER |
| 129 | if (acpi_in_debugger) { |
| 130 | kdb_printf("%s", buffer); |
| 131 | } else { |
| 132 | printk("%s", buffer); |
| 133 | } |
| 134 | #else |
| 135 | printk("%s", buffer); |
| 136 | #endif |
| 137 | } |
| 138 | |
David Shaohua Li | 11e981f | 2005-08-03 23:46:33 -0400 | [diff] [blame] | 139 | extern int acpi_in_resume; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | void *acpi_os_allocate(acpi_size size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
David Shaohua Li | 11e981f | 2005-08-03 23:46:33 -0400 | [diff] [blame] | 142 | if (acpi_in_resume) |
| 143 | return kmalloc(size, GFP_ATOMIC); |
| 144 | else |
| 145 | return kmalloc(size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | void acpi_os_free(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
| 150 | kfree(ptr); |
| 151 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | EXPORT_SYMBOL(acpi_os_free); |
| 154 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
| 157 | if (efi_enabled) { |
| 158 | addr->pointer_type = ACPI_PHYSICAL_POINTER; |
| 159 | if (efi.acpi20) |
| 160 | addr->pointer.physical = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | (acpi_physical_address) virt_to_phys(efi.acpi20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | else if (efi.acpi) |
| 163 | addr->pointer.physical = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | (acpi_physical_address) virt_to_phys(efi.acpi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | printk(KERN_ERR PREFIX |
| 167 | "System description tables not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return AE_NOT_FOUND; |
| 169 | } |
| 170 | } else { |
| 171 | if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | printk(KERN_ERR PREFIX |
| 173 | "System description tables not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return AE_NOT_FOUND; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | return AE_OK; |
| 179 | } |
| 180 | |
| 181 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | acpi_os_map_memory(acpi_physical_address phys, acpi_size size, |
| 183 | void __iomem ** virt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | if (efi_enabled) { |
| 186 | if (EFI_MEMORY_WB & efi_mem_attributes(phys)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | *virt = (void __iomem *)phys_to_virt(phys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } else { |
| 189 | *virt = ioremap(phys, size); |
| 190 | } |
| 191 | } else { |
| 192 | if (phys > ULONG_MAX) { |
| 193 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); |
| 194 | return AE_BAD_PARAMETER; |
| 195 | } |
| 196 | /* |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | * ioremap checks to ensure this is in reserved space |
| 198 | */ |
| 199 | *virt = ioremap((unsigned long)phys, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | if (!*virt) |
| 203 | return AE_NO_MEMORY; |
| 204 | |
| 205 | return AE_OK; |
| 206 | } |
| 207 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
| 210 | iounmap(virt); |
| 211 | } |
| 212 | |
| 213 | #ifdef ACPI_FUTURE_USAGE |
| 214 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | if (!phys || !virt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return AE_BAD_PARAMETER; |
| 219 | |
| 220 | *phys = virt_to_phys(virt); |
| 221 | |
| 222 | return AE_OK; |
| 223 | } |
| 224 | #endif |
| 225 | |
| 226 | #define ACPI_MAX_OVERRIDE_LEN 100 |
| 227 | |
| 228 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; |
| 229 | |
| 230 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
| 232 | acpi_string * new_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
| 234 | if (!init_val || !new_val) |
| 235 | return AE_BAD_PARAMETER; |
| 236 | |
| 237 | *new_val = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | acpi_os_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | *new_val = acpi_os_name; |
| 242 | } |
| 243 | |
| 244 | return AE_OK; |
| 245 | } |
| 246 | |
| 247 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | acpi_os_table_override(struct acpi_table_header * existing_table, |
| 249 | struct acpi_table_header ** new_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
| 251 | if (!existing_table || !new_table) |
| 252 | return AE_BAD_PARAMETER; |
| 253 | |
| 254 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
| 255 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | *new_table = (struct acpi_table_header *)AmlCode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | else |
| 258 | *new_table = NULL; |
| 259 | #else |
| 260 | *new_table = NULL; |
| 261 | #endif |
| 262 | return AE_OK; |
| 263 | } |
| 264 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | static irqreturn_t acpi_irq(int irq, void *dev_id, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
| 272 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
| 274 | unsigned int irq; |
| 275 | |
| 276 | /* |
| 277 | * Ignore the GSI from the core, and use the value in our copy of the |
| 278 | * FADT. It may not be the same if an interrupt source override exists |
| 279 | * for the SCI. |
| 280 | */ |
| 281 | gsi = acpi_fadt.sci_int; |
| 282 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { |
| 283 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", |
| 284 | gsi); |
| 285 | return AE_OK; |
| 286 | } |
| 287 | |
| 288 | acpi_irq_handler = handler; |
| 289 | acpi_irq_context = context; |
| 290 | if (request_irq(irq, acpi_irq, SA_SHIRQ, "acpi", acpi_irq)) { |
| 291 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); |
| 292 | return AE_NOT_ACQUIRED; |
| 293 | } |
| 294 | acpi_irq_irq = irq; |
| 295 | |
| 296 | return AE_OK; |
| 297 | } |
| 298 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | 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] | 300 | { |
| 301 | if (irq) { |
| 302 | free_irq(irq, acpi_irq); |
| 303 | acpi_irq_handler = NULL; |
| 304 | acpi_irq_irq = 0; |
| 305 | } |
| 306 | |
| 307 | return AE_OK; |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Running in interpreter thread context, safe to sleep |
| 312 | */ |
| 313 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | void acpi_os_sleep(acpi_integer ms) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
| 316 | current->state = TASK_INTERRUPTIBLE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | schedule_timeout(((signed long)ms * HZ) / 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | EXPORT_SYMBOL(acpi_os_sleep); |
| 321 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | void acpi_os_stall(u32 us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
| 324 | while (us) { |
| 325 | u32 delay = 1000; |
| 326 | |
| 327 | if (delay > us) |
| 328 | delay = us; |
| 329 | udelay(delay); |
| 330 | touch_nmi_watchdog(); |
| 331 | us -= delay; |
| 332 | } |
| 333 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | EXPORT_SYMBOL(acpi_os_stall); |
| 336 | |
| 337 | /* |
| 338 | * Support ACPI 3.0 AML Timer operand |
| 339 | * Returns 64-bit free-running, monotonically increasing timer |
| 340 | * with 100ns granularity |
| 341 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | u64 acpi_os_get_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
| 344 | static u64 t; |
| 345 | |
| 346 | #ifdef CONFIG_HPET |
| 347 | /* TBD: use HPET if available */ |
| 348 | #endif |
| 349 | |
| 350 | #ifdef CONFIG_X86_PM_TIMER |
| 351 | /* TBD: default to PM timer if HPET was not available */ |
| 352 | #endif |
| 353 | if (!t) |
| 354 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); |
| 355 | |
| 356 | return ++t; |
| 357 | } |
| 358 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 359 | 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] | 360 | { |
| 361 | u32 dummy; |
| 362 | |
| 363 | if (!value) |
| 364 | value = &dummy; |
| 365 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | switch (width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | case 8: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | *(u8 *) value = inb(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | break; |
| 370 | case 16: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | *(u16 *) value = inw(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | break; |
| 373 | case 32: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | *(u32 *) value = inl(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | break; |
| 376 | default: |
| 377 | BUG(); |
| 378 | } |
| 379 | |
| 380 | return AE_OK; |
| 381 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | EXPORT_SYMBOL(acpi_os_read_port); |
| 384 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 385 | 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] | 386 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 387 | switch (width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | case 8: |
| 389 | outb(value, port); |
| 390 | break; |
| 391 | case 16: |
| 392 | outw(value, port); |
| 393 | break; |
| 394 | case 32: |
| 395 | outl(value, port); |
| 396 | break; |
| 397 | default: |
| 398 | BUG(); |
| 399 | } |
| 400 | |
| 401 | return AE_OK; |
| 402 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | EXPORT_SYMBOL(acpi_os_write_port); |
| 405 | |
| 406 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | 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] | 408 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | u32 dummy; |
| 410 | void __iomem *virt_addr; |
| 411 | int iomem = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | if (efi_enabled) { |
| 414 | if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) { |
| 415 | /* HACK ALERT! We can use readb/w/l on real memory too.. */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } else { |
| 418 | iomem = 1; |
| 419 | virt_addr = ioremap(phys_addr, width); |
| 420 | } |
| 421 | } else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (!value) |
| 424 | value = &dummy; |
| 425 | |
| 426 | switch (width) { |
| 427 | case 8: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | *(u8 *) value = readb(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | break; |
| 430 | case 16: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 431 | *(u16 *) value = readw(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | break; |
| 433 | case 32: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 434 | *(u32 *) value = readl(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | break; |
| 436 | default: |
| 437 | BUG(); |
| 438 | } |
| 439 | |
| 440 | if (efi_enabled) { |
| 441 | if (iomem) |
| 442 | iounmap(virt_addr); |
| 443 | } |
| 444 | |
| 445 | return AE_OK; |
| 446 | } |
| 447 | |
| 448 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 449 | 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] | 450 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 451 | void __iomem *virt_addr; |
| 452 | int iomem = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
| 454 | if (efi_enabled) { |
| 455 | if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) { |
| 456 | /* HACK ALERT! We can use writeb/w/l on real memory too */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } else { |
| 459 | iomem = 1; |
| 460 | virt_addr = ioremap(phys_addr, width); |
| 461 | } |
| 462 | } else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | switch (width) { |
| 466 | case 8: |
| 467 | writeb(value, virt_addr); |
| 468 | break; |
| 469 | case 16: |
| 470 | writew(value, virt_addr); |
| 471 | break; |
| 472 | case 32: |
| 473 | writel(value, virt_addr); |
| 474 | break; |
| 475 | default: |
| 476 | BUG(); |
| 477 | } |
| 478 | |
| 479 | if (iomem) |
| 480 | iounmap(virt_addr); |
| 481 | |
| 482 | return AE_OK; |
| 483 | } |
| 484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
| 487 | void *value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
| 489 | int result, size; |
| 490 | |
| 491 | if (!value) |
| 492 | return AE_BAD_PARAMETER; |
| 493 | |
| 494 | switch (width) { |
| 495 | case 8: |
| 496 | size = 1; |
| 497 | break; |
| 498 | case 16: |
| 499 | size = 2; |
| 500 | break; |
| 501 | case 32: |
| 502 | size = 4; |
| 503 | break; |
| 504 | default: |
| 505 | return AE_ERROR; |
| 506 | } |
| 507 | |
| 508 | BUG_ON(!raw_pci_ops); |
| 509 | |
| 510 | result = raw_pci_ops->read(pci_id->segment, pci_id->bus, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 511 | PCI_DEVFN(pci_id->device, pci_id->function), |
| 512 | reg, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | return (result ? AE_ERROR : AE_OK); |
| 515 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | EXPORT_SYMBOL(acpi_os_read_pci_configuration); |
| 518 | |
| 519 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 520 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
| 521 | acpi_integer value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
| 523 | int result, size; |
| 524 | |
| 525 | switch (width) { |
| 526 | case 8: |
| 527 | size = 1; |
| 528 | break; |
| 529 | case 16: |
| 530 | size = 2; |
| 531 | break; |
| 532 | case 32: |
| 533 | size = 4; |
| 534 | break; |
| 535 | default: |
| 536 | return AE_ERROR; |
| 537 | } |
| 538 | |
| 539 | BUG_ON(!raw_pci_ops); |
| 540 | |
| 541 | result = raw_pci_ops->write(pci_id->segment, pci_id->bus, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 542 | PCI_DEVFN(pci_id->device, pci_id->function), |
| 543 | reg, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | return (result ? AE_ERROR : AE_OK); |
| 546 | } |
| 547 | |
| 548 | /* TODO: Change code to take advantage of driver model more */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 549 | static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */ |
| 550 | acpi_handle chandle, /* current node */ |
| 551 | struct acpi_pci_id **id, |
| 552 | int *is_bridge, u8 * bus_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 554 | acpi_handle handle; |
| 555 | struct acpi_pci_id *pci_id = *id; |
| 556 | acpi_status status; |
| 557 | unsigned long temp; |
| 558 | acpi_object_type type; |
| 559 | u8 tu8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | acpi_get_parent(chandle, &handle); |
| 562 | if (handle != rhandle) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 563 | acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge, |
| 564 | bus_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
| 566 | status = acpi_get_type(handle, &type); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | return; |
| 569 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 570 | status = |
| 571 | acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, |
| 572 | &temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (ACPI_SUCCESS(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 574 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp)); |
| 575 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | if (*is_bridge) |
| 578 | pci_id->bus = *bus_number; |
| 579 | |
| 580 | /* any nicer way to get bus number of bridge ? */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | status = |
| 582 | acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8, |
| 583 | 8); |
| 584 | if (ACPI_SUCCESS(status) |
| 585 | && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) { |
| 586 | status = |
| 587 | acpi_os_read_pci_configuration(pci_id, 0x18, |
| 588 | &tu8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (!ACPI_SUCCESS(status)) { |
| 590 | /* Certainly broken... FIX ME */ |
| 591 | return; |
| 592 | } |
| 593 | *is_bridge = 1; |
| 594 | pci_id->bus = tu8; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 595 | status = |
| 596 | acpi_os_read_pci_configuration(pci_id, 0x19, |
| 597 | &tu8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (ACPI_SUCCESS(status)) { |
| 599 | *bus_number = tu8; |
| 600 | } |
| 601 | } else |
| 602 | *is_bridge = 0; |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ |
| 608 | acpi_handle chandle, /* current node */ |
| 609 | struct acpi_pci_id **id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
| 611 | int is_bridge = 1; |
| 612 | u8 bus_number = (*id)->bus; |
| 613 | |
| 614 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); |
| 615 | } |
| 616 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 617 | static void acpi_os_execute_deferred(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 619 | struct acpi_os_dpc *dpc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | ACPI_FUNCTION_TRACE("os_execute_deferred"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 623 | dpc = (struct acpi_os_dpc *)context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | if (!dpc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 625 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return_VOID; |
| 627 | } |
| 628 | |
| 629 | dpc->function(dpc->context); |
| 630 | |
| 631 | kfree(dpc); |
| 632 | |
| 633 | return_VOID; |
| 634 | } |
| 635 | |
| 636 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 637 | acpi_os_queue_for_execution(u32 priority, |
| 638 | acpi_osd_exec_callback function, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | acpi_status status = AE_OK; |
| 641 | struct acpi_os_dpc *dpc; |
| 642 | struct work_struct *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 644 | ACPI_FUNCTION_TRACE("os_queue_for_execution"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 646 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 647 | "Scheduling function [%p(%p)] for deferred execution.\n", |
| 648 | function, context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | if (!function) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 651 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * Allocate/initialize DPC structure. Note that this memory will be |
| 655 | * freed by the callee. The kernel handles the tq_struct list in a |
| 656 | * way that allows us to also free its memory inside the callee. |
| 657 | * Because we may want to schedule several tasks with different |
| 658 | * parameters we can't use the approach some kernel code uses of |
| 659 | * having a static tq_struct. |
| 660 | * We can save time and code by allocating the DPC and tq_structs |
| 661 | * from the same memory. |
| 662 | */ |
| 663 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 664 | dpc = |
| 665 | kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct), |
| 666 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | if (!dpc) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 668 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
| 670 | dpc->function = function; |
| 671 | dpc->context = context; |
| 672 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 673 | task = (void *)(dpc + 1); |
| 674 | INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
| 676 | if (!queue_work(kacpid_wq, task)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 677 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 678 | "Call to queue_work() failed.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | kfree(dpc); |
| 680 | status = AE_ERROR; |
| 681 | } |
| 682 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 683 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | EXPORT_SYMBOL(acpi_os_queue_for_execution); |
| 687 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 688 | void acpi_os_wait_events_complete(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
| 690 | flush_workqueue(kacpid_wq); |
| 691 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
| 694 | |
| 695 | /* |
| 696 | * Allocate the memory for a spinlock and initialize it. |
| 697 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | acpi_status acpi_os_create_lock(acpi_handle * out_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
| 700 | spinlock_t *lock_ptr; |
| 701 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 702 | ACPI_FUNCTION_TRACE("os_create_lock"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | lock_ptr = acpi_os_allocate(sizeof(spinlock_t)); |
| 705 | |
| 706 | spin_lock_init(lock_ptr); |
| 707 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 708 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
| 710 | *out_handle = lock_ptr; |
| 711 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 712 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | /* |
| 716 | * Deallocate the memory for a spinlock. |
| 717 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 718 | void acpi_os_delete_lock(acpi_handle handle) |
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 | ACPI_FUNCTION_TRACE("os_create_lock"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 722 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | acpi_os_free(handle); |
| 725 | |
| 726 | return_VOID; |
| 727 | } |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 730 | 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] | 731 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | struct semaphore *sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 734 | ACPI_FUNCTION_TRACE("os_create_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
| 736 | sem = acpi_os_allocate(sizeof(struct semaphore)); |
| 737 | if (!sem) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 738 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | memset(sem, 0, sizeof(struct semaphore)); |
| 740 | |
| 741 | sema_init(sem, initial_units); |
| 742 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 743 | *handle = (acpi_handle *) sem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 745 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
| 746 | *handle, initial_units)); |
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 | return_ACPI_STATUS(AE_OK); |
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 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 751 | EXPORT_SYMBOL(acpi_os_create_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | /* |
| 754 | * TODO: A better way to delete semaphores? Linux doesn't have a |
| 755 | * 'delete_semaphore()' function -- may result in an invalid |
| 756 | * pointer dereference for non-synchronized consumers. Should |
| 757 | * we at least check for blocked threads and signal/cancel them? |
| 758 | */ |
| 759 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 760 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 762 | struct semaphore *sem = (struct semaphore *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 764 | ACPI_FUNCTION_TRACE("os_delete_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
| 766 | if (!sem) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 767 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 769 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 771 | acpi_os_free(sem); |
| 772 | sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 774 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
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 | EXPORT_SYMBOL(acpi_os_delete_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | /* |
| 780 | * TODO: The kernel doesn't have a 'down_timeout' function -- had to |
| 781 | * improvise. The process is to sleep for one scheduler quantum |
| 782 | * until the semaphore becomes available. Downside is that this |
| 783 | * may result in starvation for timeout-based waits when there's |
| 784 | * lots of semaphore activity. |
| 785 | * |
| 786 | * TODO: Support for units > 1? |
| 787 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 788 | 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] | 789 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 790 | acpi_status status = AE_OK; |
| 791 | struct semaphore *sem = (struct semaphore *)handle; |
| 792 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 794 | ACPI_FUNCTION_TRACE("os_wait_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | if (!sem || (units < 1)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 797 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | if (units > 1) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 800 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 802 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
| 803 | handle, units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
| 805 | if (in_atomic()) |
| 806 | timeout = 0; |
| 807 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 808 | switch (timeout) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | /* |
| 810 | * No Wait: |
| 811 | * -------- |
| 812 | * A zero timeout value indicates that we shouldn't wait - just |
| 813 | * acquire the semaphore if available otherwise return AE_TIME |
| 814 | * (a.k.a. 'would block'). |
| 815 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 816 | case 0: |
| 817 | if (down_trylock(sem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | status = AE_TIME; |
| 819 | break; |
| 820 | |
| 821 | /* |
| 822 | * Wait Indefinitely: |
| 823 | * ------------------ |
| 824 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 825 | case ACPI_WAIT_FOREVER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | down(sem); |
| 827 | break; |
| 828 | |
| 829 | /* |
| 830 | * Wait w/ Timeout: |
| 831 | * ---------------- |
| 832 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 833 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | // TODO: A better timeout algorithm? |
| 835 | { |
| 836 | int i = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 837 | static const int quantum_ms = 1000 / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | ret = down_trylock(sem); |
| 840 | for (i = timeout; (i > 0 && ret < 0); i -= quantum_ms) { |
| 841 | current->state = TASK_INTERRUPTIBLE; |
| 842 | schedule_timeout(1); |
| 843 | ret = down_trylock(sem); |
| 844 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | if (ret != 0) |
| 847 | status = AE_TIME; |
| 848 | } |
| 849 | break; |
| 850 | } |
| 851 | |
| 852 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 853 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 854 | "Failed to acquire semaphore[%p|%d|%d], %s\n", |
| 855 | handle, units, timeout, |
| 856 | acpi_format_exception(status))); |
| 857 | } else { |
| 858 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
| 859 | "Acquired semaphore[%p|%d|%d]\n", handle, |
| 860 | units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 863 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 866 | EXPORT_SYMBOL(acpi_os_wait_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
| 868 | /* |
| 869 | * TODO: Support for units > 1? |
| 870 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 871 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 873 | struct semaphore *sem = (struct semaphore *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 875 | ACPI_FUNCTION_TRACE("os_signal_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
| 877 | if (!sem || (units < 1)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 878 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
| 880 | if (units > 1) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 883 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
| 884 | units)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
| 886 | up(sem); |
| 887 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 888 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | EXPORT_SYMBOL(acpi_os_signal_semaphore); |
| 892 | |
| 893 | #ifdef ACPI_FUTURE_USAGE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 894 | u32 acpi_os_get_line(char *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | { |
| 896 | |
| 897 | #ifdef ENABLE_DEBUGGER |
| 898 | if (acpi_in_debugger) { |
| 899 | u32 chars; |
| 900 | |
| 901 | kdb_read(buffer, sizeof(line_buf)); |
| 902 | |
| 903 | /* remove the CR kdb includes */ |
| 904 | chars = strlen(buffer) - 1; |
| 905 | buffer[chars] = '\0'; |
| 906 | } |
| 907 | #endif |
| 908 | |
| 909 | return 0; |
| 910 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 911 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | /* Assumes no unreadable holes inbetween */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 914 | u8 acpi_os_readable(void *ptr, acpi_size len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 916 | #if defined(__i386__) || defined(__x86_64__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | char tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 918 | return !__get_user(tmp, (char __user *)ptr) |
| 919 | && !__get_user(tmp, (char __user *)ptr + len - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | #endif |
| 921 | return 1; |
| 922 | } |
| 923 | |
| 924 | #ifdef ACPI_FUTURE_USAGE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 925 | u8 acpi_os_writable(void *ptr, acpi_size len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | { |
| 927 | /* could do dummy write (racy) or a kernel page table lookup. |
| 928 | The later may be difficult at early boot when kmap doesn't work yet. */ |
| 929 | return 1; |
| 930 | } |
| 931 | #endif |
| 932 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 933 | u32 acpi_os_get_thread_id(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { |
| 935 | if (!in_atomic()) |
| 936 | return current->pid; |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 941 | acpi_status acpi_os_signal(u32 function, void *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 943 | switch (function) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | case ACPI_SIGNAL_FATAL: |
| 945 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); |
| 946 | break; |
| 947 | case ACPI_SIGNAL_BREAKPOINT: |
| 948 | /* |
| 949 | * AML Breakpoint |
| 950 | * ACPI spec. says to treat it as a NOP unless |
| 951 | * you are debugging. So if/when we integrate |
| 952 | * AML debugger into the kernel debugger its |
| 953 | * hook will go here. But until then it is |
| 954 | * not useful to print anything on breakpoints. |
| 955 | */ |
| 956 | break; |
| 957 | default: |
| 958 | break; |
| 959 | } |
| 960 | |
| 961 | return AE_OK; |
| 962 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | EXPORT_SYMBOL(acpi_os_signal); |
| 965 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 966 | static int __init acpi_os_name_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | { |
| 968 | char *p = acpi_os_name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 969 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | if (!str || !*str) |
| 972 | return 0; |
| 973 | |
| 974 | for (; count-- && str && *str; str++) { |
| 975 | if (isalnum(*str) || *str == ' ' || *str == ':') |
| 976 | *p++ = *str; |
| 977 | else if (*str == '\'' || *str == '"') |
| 978 | continue; |
| 979 | else |
| 980 | break; |
| 981 | } |
| 982 | *p = 0; |
| 983 | |
| 984 | return 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | __setup("acpi_os_name=", acpi_os_name_setup); |
| 989 | |
| 990 | /* |
| 991 | * _OSI control |
| 992 | * empty string disables _OSI |
| 993 | * TBD additional string adds to _OSI |
| 994 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 995 | static int __init acpi_osi_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | { |
| 997 | if (str == NULL || *str == '\0') { |
| 998 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); |
| 999 | acpi_gbl_create_osi_method = FALSE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1000 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | /* TBD */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1002 | printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n", |
| 1003 | str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | return 1; |
| 1007 | } |
| 1008 | |
| 1009 | __setup("acpi_osi=", acpi_osi_setup); |
| 1010 | |
| 1011 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1012 | static int __init acpi_serialize_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | { |
| 1014 | printk(KERN_INFO PREFIX "serialize enabled\n"); |
| 1015 | |
| 1016 | acpi_gbl_all_methods_serialized = TRUE; |
| 1017 | |
| 1018 | return 1; |
| 1019 | } |
| 1020 | |
| 1021 | __setup("acpi_serialize", acpi_serialize_setup); |
| 1022 | |
| 1023 | /* |
| 1024 | * Wake and Run-Time GPES are expected to be separate. |
| 1025 | * We disable wake-GPEs at run-time to prevent spurious |
| 1026 | * interrupts. |
| 1027 | * |
| 1028 | * However, if a system exists that shares Wake and |
| 1029 | * Run-time events on the same GPE this flag is available |
| 1030 | * to tell Linux to keep the wake-time GPEs enabled at run-time. |
| 1031 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1032 | static int __init acpi_wake_gpes_always_on_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | { |
| 1034 | printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); |
| 1035 | |
| 1036 | acpi_gbl_leave_wake_gpes_disabled = FALSE; |
| 1037 | |
| 1038 | return 1; |
| 1039 | } |
| 1040 | |
| 1041 | __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); |
| 1042 | |
Adrian Bunk | 8713cbe | 2005-09-02 17:16:48 -0400 | [diff] [blame] | 1043 | static int __init acpi_hotkey_setup(char *str) |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 1044 | { |
Luming Yu | 30e332f | 2005-08-12 00:31:00 -0400 | [diff] [blame] | 1045 | acpi_specific_hotkey_enabled = FALSE; |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 1046 | return 1; |
| 1047 | } |
| 1048 | |
Luming Yu | 30e332f | 2005-08-12 00:31:00 -0400 | [diff] [blame] | 1049 | __setup("acpi_generic_hotkey", acpi_hotkey_setup); |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 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. |
| 1063 | * flags is *not* the result of save_flags - it is an ACPI-specific flag variable |
| 1064 | * that indicates whether we are at interrupt level. |
| 1065 | */ |
| 1066 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1067 | unsigned long acpi_os_acquire_lock(acpi_handle handle) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1068 | { |
| 1069 | unsigned long flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1070 | spin_lock_irqsave((spinlock_t *) handle, flags); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1071 | return flags; |
| 1072 | } |
| 1073 | |
| 1074 | /* |
| 1075 | * Release a spinlock. See above. |
| 1076 | */ |
| 1077 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1078 | void acpi_os_release_lock(acpi_handle handle, unsigned long flags) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1079 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1080 | spin_unlock_irqrestore((spinlock_t *) handle, flags); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1081 | } |
| 1082 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1083 | #ifndef ACPI_USE_LOCAL_CACHE |
| 1084 | |
| 1085 | /******************************************************************************* |
| 1086 | * |
| 1087 | * FUNCTION: acpi_os_create_cache |
| 1088 | * |
| 1089 | * PARAMETERS: CacheName - Ascii name for the cache |
| 1090 | * ObjectSize - Size of each cached object |
| 1091 | * MaxDepth - Maximum depth of the cache (in objects) |
| 1092 | * ReturnCache - Where the new cache object is returned |
| 1093 | * |
| 1094 | * RETURN: Status |
| 1095 | * |
| 1096 | * DESCRIPTION: Create a cache object |
| 1097 | * |
| 1098 | ******************************************************************************/ |
| 1099 | |
| 1100 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1101 | 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] | 1102 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1103 | *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1104 | return AE_OK; |
| 1105 | } |
| 1106 | |
| 1107 | /******************************************************************************* |
| 1108 | * |
| 1109 | * FUNCTION: acpi_os_purge_cache |
| 1110 | * |
| 1111 | * PARAMETERS: Cache - Handle to cache object |
| 1112 | * |
| 1113 | * RETURN: Status |
| 1114 | * |
| 1115 | * DESCRIPTION: Free all objects within the requested cache. |
| 1116 | * |
| 1117 | ******************************************************************************/ |
| 1118 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1119 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1120 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1121 | (void)kmem_cache_shrink(cache); |
| 1122 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | /******************************************************************************* |
| 1126 | * |
| 1127 | * FUNCTION: acpi_os_delete_cache |
| 1128 | * |
| 1129 | * PARAMETERS: Cache - Handle to cache object |
| 1130 | * |
| 1131 | * RETURN: Status |
| 1132 | * |
| 1133 | * DESCRIPTION: Free all objects within the requested cache and delete the |
| 1134 | * cache object. |
| 1135 | * |
| 1136 | ******************************************************************************/ |
| 1137 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1138 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1139 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1140 | (void)kmem_cache_destroy(cache); |
| 1141 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | /******************************************************************************* |
| 1145 | * |
| 1146 | * FUNCTION: acpi_os_release_object |
| 1147 | * |
| 1148 | * PARAMETERS: Cache - Handle to cache object |
| 1149 | * Object - The object to be released |
| 1150 | * |
| 1151 | * RETURN: None |
| 1152 | * |
| 1153 | * DESCRIPTION: Release an object to the specified cache. If cache is full, |
| 1154 | * the object is deleted. |
| 1155 | * |
| 1156 | ******************************************************************************/ |
| 1157 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1158 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1159 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1160 | kmem_cache_free(cache, object); |
| 1161 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | /******************************************************************************* |
| 1165 | * |
| 1166 | * FUNCTION: acpi_os_acquire_object |
| 1167 | * |
| 1168 | * PARAMETERS: Cache - Handle to cache object |
| 1169 | * ReturnObject - Where the object is returned |
| 1170 | * |
| 1171 | * RETURN: Status |
| 1172 | * |
| 1173 | * DESCRIPTION: Get an object from the specified cache. If cache is empty, |
| 1174 | * the object is allocated. |
| 1175 | * |
| 1176 | ******************************************************************************/ |
| 1177 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1178 | void *acpi_os_acquire_object(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1179 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1180 | void *object = kmem_cache_alloc(cache, GFP_KERNEL); |
| 1181 | WARN_ON(!object); |
| 1182 | return object; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | #endif |