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 | { |
Nishanth Aravamudan | 01a527e | 2005-11-07 01:01:14 -0800 | [diff] [blame] | 316 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | EXPORT_SYMBOL(acpi_os_sleep); |
| 320 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | void acpi_os_stall(u32 us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | while (us) { |
| 324 | u32 delay = 1000; |
| 325 | |
| 326 | if (delay > us) |
| 327 | delay = us; |
| 328 | udelay(delay); |
| 329 | touch_nmi_watchdog(); |
| 330 | us -= delay; |
| 331 | } |
| 332 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | EXPORT_SYMBOL(acpi_os_stall); |
| 335 | |
| 336 | /* |
| 337 | * Support ACPI 3.0 AML Timer operand |
| 338 | * Returns 64-bit free-running, monotonically increasing timer |
| 339 | * with 100ns granularity |
| 340 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | u64 acpi_os_get_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | { |
| 343 | static u64 t; |
| 344 | |
| 345 | #ifdef CONFIG_HPET |
| 346 | /* TBD: use HPET if available */ |
| 347 | #endif |
| 348 | |
| 349 | #ifdef CONFIG_X86_PM_TIMER |
| 350 | /* TBD: default to PM timer if HPET was not available */ |
| 351 | #endif |
| 352 | if (!t) |
| 353 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); |
| 354 | |
| 355 | return ++t; |
| 356 | } |
| 357 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | 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] | 359 | { |
| 360 | u32 dummy; |
| 361 | |
| 362 | if (!value) |
| 363 | value = &dummy; |
| 364 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | switch (width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | case 8: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 367 | *(u8 *) value = inb(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | break; |
| 369 | case 16: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 370 | *(u16 *) value = inw(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | break; |
| 372 | case 32: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | *(u32 *) value = inl(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | break; |
| 375 | default: |
| 376 | BUG(); |
| 377 | } |
| 378 | |
| 379 | return AE_OK; |
| 380 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | EXPORT_SYMBOL(acpi_os_read_port); |
| 383 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | 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] | 385 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | switch (width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | case 8: |
| 388 | outb(value, port); |
| 389 | break; |
| 390 | case 16: |
| 391 | outw(value, port); |
| 392 | break; |
| 393 | case 32: |
| 394 | outl(value, port); |
| 395 | break; |
| 396 | default: |
| 397 | BUG(); |
| 398 | } |
| 399 | |
| 400 | return AE_OK; |
| 401 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | EXPORT_SYMBOL(acpi_os_write_port); |
| 404 | |
| 405 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | 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] | 407 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | u32 dummy; |
| 409 | void __iomem *virt_addr; |
| 410 | int iomem = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | if (efi_enabled) { |
| 413 | if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) { |
| 414 | /* HACK ALERT! We can use readb/w/l on real memory too.. */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } else { |
| 417 | iomem = 1; |
| 418 | virt_addr = ioremap(phys_addr, width); |
| 419 | } |
| 420 | } else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 421 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | if (!value) |
| 423 | value = &dummy; |
| 424 | |
| 425 | switch (width) { |
| 426 | case 8: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 427 | *(u8 *) value = readb(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | break; |
| 429 | case 16: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | *(u16 *) value = readw(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | break; |
| 432 | case 32: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | *(u32 *) value = readl(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | break; |
| 435 | default: |
| 436 | BUG(); |
| 437 | } |
| 438 | |
| 439 | if (efi_enabled) { |
| 440 | if (iomem) |
| 441 | iounmap(virt_addr); |
| 442 | } |
| 443 | |
| 444 | return AE_OK; |
| 445 | } |
| 446 | |
| 447 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | 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] | 449 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | void __iomem *virt_addr; |
| 451 | int iomem = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | if (efi_enabled) { |
| 454 | if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) { |
| 455 | /* HACK ALERT! We can use writeb/w/l on real memory too */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } else { |
| 458 | iomem = 1; |
| 459 | virt_addr = ioremap(phys_addr, width); |
| 460 | } |
| 461 | } else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 462 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | switch (width) { |
| 465 | case 8: |
| 466 | writeb(value, virt_addr); |
| 467 | break; |
| 468 | case 16: |
| 469 | writew(value, virt_addr); |
| 470 | break; |
| 471 | case 32: |
| 472 | writel(value, virt_addr); |
| 473 | break; |
| 474 | default: |
| 475 | BUG(); |
| 476 | } |
| 477 | |
| 478 | if (iomem) |
| 479 | iounmap(virt_addr); |
| 480 | |
| 481 | return AE_OK; |
| 482 | } |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
| 486 | void *value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
| 488 | int result, size; |
| 489 | |
| 490 | if (!value) |
| 491 | return AE_BAD_PARAMETER; |
| 492 | |
| 493 | switch (width) { |
| 494 | case 8: |
| 495 | size = 1; |
| 496 | break; |
| 497 | case 16: |
| 498 | size = 2; |
| 499 | break; |
| 500 | case 32: |
| 501 | size = 4; |
| 502 | break; |
| 503 | default: |
| 504 | return AE_ERROR; |
| 505 | } |
| 506 | |
| 507 | BUG_ON(!raw_pci_ops); |
| 508 | |
| 509 | result = raw_pci_ops->read(pci_id->segment, pci_id->bus, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 510 | PCI_DEVFN(pci_id->device, pci_id->function), |
| 511 | reg, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | return (result ? AE_ERROR : AE_OK); |
| 514 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | EXPORT_SYMBOL(acpi_os_read_pci_configuration); |
| 517 | |
| 518 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 519 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
| 520 | acpi_integer value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
| 522 | int result, size; |
| 523 | |
| 524 | switch (width) { |
| 525 | case 8: |
| 526 | size = 1; |
| 527 | break; |
| 528 | case 16: |
| 529 | size = 2; |
| 530 | break; |
| 531 | case 32: |
| 532 | size = 4; |
| 533 | break; |
| 534 | default: |
| 535 | return AE_ERROR; |
| 536 | } |
| 537 | |
| 538 | BUG_ON(!raw_pci_ops); |
| 539 | |
| 540 | result = raw_pci_ops->write(pci_id->segment, pci_id->bus, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 541 | PCI_DEVFN(pci_id->device, pci_id->function), |
| 542 | reg, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
| 544 | return (result ? AE_ERROR : AE_OK); |
| 545 | } |
| 546 | |
| 547 | /* TODO: Change code to take advantage of driver model more */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */ |
| 549 | acpi_handle chandle, /* current node */ |
| 550 | struct acpi_pci_id **id, |
| 551 | int *is_bridge, u8 * bus_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 553 | acpi_handle handle; |
| 554 | struct acpi_pci_id *pci_id = *id; |
| 555 | acpi_status status; |
| 556 | unsigned long temp; |
| 557 | acpi_object_type type; |
| 558 | u8 tu8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
| 560 | acpi_get_parent(chandle, &handle); |
| 561 | if (handle != rhandle) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 562 | acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge, |
| 563 | bus_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
| 565 | status = acpi_get_type(handle, &type); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 566 | if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | return; |
| 568 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 569 | status = |
| 570 | acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, |
| 571 | &temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | if (ACPI_SUCCESS(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp)); |
| 574 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | if (*is_bridge) |
| 577 | pci_id->bus = *bus_number; |
| 578 | |
| 579 | /* any nicer way to get bus number of bridge ? */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 580 | status = |
| 581 | acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8, |
| 582 | 8); |
| 583 | if (ACPI_SUCCESS(status) |
| 584 | && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) { |
| 585 | status = |
| 586 | acpi_os_read_pci_configuration(pci_id, 0x18, |
| 587 | &tu8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | if (!ACPI_SUCCESS(status)) { |
| 589 | /* Certainly broken... FIX ME */ |
| 590 | return; |
| 591 | } |
| 592 | *is_bridge = 1; |
| 593 | pci_id->bus = tu8; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | status = |
| 595 | acpi_os_read_pci_configuration(pci_id, 0x19, |
| 596 | &tu8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | if (ACPI_SUCCESS(status)) { |
| 598 | *bus_number = tu8; |
| 599 | } |
| 600 | } else |
| 601 | *is_bridge = 0; |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 606 | void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ |
| 607 | acpi_handle chandle, /* current node */ |
| 608 | struct acpi_pci_id **id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { |
| 610 | int is_bridge = 1; |
| 611 | u8 bus_number = (*id)->bus; |
| 612 | |
| 613 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); |
| 614 | } |
| 615 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | static void acpi_os_execute_deferred(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 618 | struct acpi_os_dpc *dpc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 620 | ACPI_FUNCTION_TRACE("os_execute_deferred"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | dpc = (struct acpi_os_dpc *)context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | if (!dpc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 624 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return_VOID; |
| 626 | } |
| 627 | |
| 628 | dpc->function(dpc->context); |
| 629 | |
| 630 | kfree(dpc); |
| 631 | |
| 632 | return_VOID; |
| 633 | } |
| 634 | |
| 635 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 636 | acpi_os_queue_for_execution(u32 priority, |
| 637 | acpi_osd_exec_callback function, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | acpi_status status = AE_OK; |
| 640 | struct acpi_os_dpc *dpc; |
| 641 | struct work_struct *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 643 | ACPI_FUNCTION_TRACE("os_queue_for_execution"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 645 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 646 | "Scheduling function [%p(%p)] for deferred execution.\n", |
| 647 | function, context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
| 649 | if (!function) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 650 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | /* |
| 653 | * Allocate/initialize DPC structure. Note that this memory will be |
| 654 | * freed by the callee. The kernel handles the tq_struct list in a |
| 655 | * way that allows us to also free its memory inside the callee. |
| 656 | * Because we may want to schedule several tasks with different |
| 657 | * parameters we can't use the approach some kernel code uses of |
| 658 | * having a static tq_struct. |
| 659 | * We can save time and code by allocating the DPC and tq_structs |
| 660 | * from the same memory. |
| 661 | */ |
| 662 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 663 | dpc = |
| 664 | kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct), |
| 665 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | if (!dpc) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 667 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | dpc->function = function; |
| 670 | dpc->context = context; |
| 671 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 | task = (void *)(dpc + 1); |
| 673 | INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | if (!queue_work(kacpid_wq, task)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 676 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 677 | "Call to queue_work() failed.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | kfree(dpc); |
| 679 | status = AE_ERROR; |
| 680 | } |
| 681 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 682 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | EXPORT_SYMBOL(acpi_os_queue_for_execution); |
| 686 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 687 | void acpi_os_wait_events_complete(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
| 689 | flush_workqueue(kacpid_wq); |
| 690 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
| 693 | |
| 694 | /* |
| 695 | * Allocate the memory for a spinlock and initialize it. |
| 696 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 697 | acpi_status acpi_os_create_lock(acpi_handle * out_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | { |
| 699 | spinlock_t *lock_ptr; |
| 700 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | ACPI_FUNCTION_TRACE("os_create_lock"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
| 703 | lock_ptr = acpi_os_allocate(sizeof(spinlock_t)); |
| 704 | |
| 705 | spin_lock_init(lock_ptr); |
| 706 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 707 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
| 709 | *out_handle = lock_ptr; |
| 710 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | /* |
| 715 | * Deallocate the memory for a spinlock. |
| 716 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 717 | void acpi_os_delete_lock(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 719 | ACPI_FUNCTION_TRACE("os_create_lock"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 721 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | acpi_os_free(handle); |
| 724 | |
| 725 | return_VOID; |
| 726 | } |
| 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 729 | 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] | 730 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 731 | struct semaphore *sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 733 | ACPI_FUNCTION_TRACE("os_create_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | sem = acpi_os_allocate(sizeof(struct semaphore)); |
| 736 | if (!sem) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 737 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | memset(sem, 0, sizeof(struct semaphore)); |
| 739 | |
| 740 | sema_init(sem, initial_units); |
| 741 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 742 | *handle = (acpi_handle *) sem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 744 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
| 745 | *handle, initial_units)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 747 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 750 | EXPORT_SYMBOL(acpi_os_create_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
| 752 | /* |
| 753 | * TODO: A better way to delete semaphores? Linux doesn't have a |
| 754 | * 'delete_semaphore()' function -- may result in an invalid |
| 755 | * pointer dereference for non-synchronized consumers. Should |
| 756 | * we at least check for blocked threads and signal/cancel them? |
| 757 | */ |
| 758 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 759 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 761 | struct semaphore *sem = (struct semaphore *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 763 | ACPI_FUNCTION_TRACE("os_delete_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | if (!sem) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 766 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 768 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 770 | acpi_os_free(sem); |
| 771 | sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 773 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 776 | EXPORT_SYMBOL(acpi_os_delete_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | /* |
| 779 | * TODO: The kernel doesn't have a 'down_timeout' function -- had to |
| 780 | * improvise. The process is to sleep for one scheduler quantum |
| 781 | * until the semaphore becomes available. Downside is that this |
| 782 | * may result in starvation for timeout-based waits when there's |
| 783 | * lots of semaphore activity. |
| 784 | * |
| 785 | * TODO: Support for units > 1? |
| 786 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 787 | 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] | 788 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 789 | acpi_status status = AE_OK; |
| 790 | struct semaphore *sem = (struct semaphore *)handle; |
| 791 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 793 | ACPI_FUNCTION_TRACE("os_wait_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | if (!sem || (units < 1)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 796 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
| 798 | if (units > 1) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 799 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 801 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
| 802 | handle, units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | if (in_atomic()) |
| 805 | timeout = 0; |
| 806 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 807 | switch (timeout) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | /* |
| 809 | * No Wait: |
| 810 | * -------- |
| 811 | * A zero timeout value indicates that we shouldn't wait - just |
| 812 | * acquire the semaphore if available otherwise return AE_TIME |
| 813 | * (a.k.a. 'would block'). |
| 814 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 815 | case 0: |
| 816 | if (down_trylock(sem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | status = AE_TIME; |
| 818 | break; |
| 819 | |
| 820 | /* |
| 821 | * Wait Indefinitely: |
| 822 | * ------------------ |
| 823 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 824 | case ACPI_WAIT_FOREVER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | down(sem); |
| 826 | break; |
| 827 | |
| 828 | /* |
| 829 | * Wait w/ Timeout: |
| 830 | * ---------------- |
| 831 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 832 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | // TODO: A better timeout algorithm? |
| 834 | { |
| 835 | int i = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 836 | static const int quantum_ms = 1000 / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | ret = down_trylock(sem); |
| 839 | for (i = timeout; (i > 0 && ret < 0); i -= quantum_ms) { |
Nishanth Aravamudan | 01a527e | 2005-11-07 01:01:14 -0800 | [diff] [blame] | 840 | schedule_timeout_interruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | ret = down_trylock(sem); |
| 842 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | if (ret != 0) |
| 845 | status = AE_TIME; |
| 846 | } |
| 847 | break; |
| 848 | } |
| 849 | |
| 850 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 851 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 852 | "Failed to acquire semaphore[%p|%d|%d], %s\n", |
| 853 | handle, units, timeout, |
| 854 | acpi_format_exception(status))); |
| 855 | } else { |
| 856 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
| 857 | "Acquired semaphore[%p|%d|%d]\n", handle, |
| 858 | units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 861 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 864 | EXPORT_SYMBOL(acpi_os_wait_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | /* |
| 867 | * TODO: Support for units > 1? |
| 868 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 869 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 871 | struct semaphore *sem = (struct semaphore *)handle; |
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 | ACPI_FUNCTION_TRACE("os_signal_semaphore"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | if (!sem || (units < 1)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 876 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | if (units > 1) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 879 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
| 882 | units)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| 884 | up(sem); |
| 885 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 886 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | EXPORT_SYMBOL(acpi_os_signal_semaphore); |
| 890 | |
| 891 | #ifdef ACPI_FUTURE_USAGE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 892 | u32 acpi_os_get_line(char *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | { |
| 894 | |
| 895 | #ifdef ENABLE_DEBUGGER |
| 896 | if (acpi_in_debugger) { |
| 897 | u32 chars; |
| 898 | |
| 899 | kdb_read(buffer, sizeof(line_buf)); |
| 900 | |
| 901 | /* remove the CR kdb includes */ |
| 902 | chars = strlen(buffer) - 1; |
| 903 | buffer[chars] = '\0'; |
| 904 | } |
| 905 | #endif |
| 906 | |
| 907 | return 0; |
| 908 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 909 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | /* Assumes no unreadable holes inbetween */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 912 | u8 acpi_os_readable(void *ptr, acpi_size len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 914 | #if defined(__i386__) || defined(__x86_64__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | char tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 916 | return !__get_user(tmp, (char __user *)ptr) |
| 917 | && !__get_user(tmp, (char __user *)ptr + len - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | #endif |
| 919 | return 1; |
| 920 | } |
| 921 | |
| 922 | #ifdef ACPI_FUTURE_USAGE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 923 | u8 acpi_os_writable(void *ptr, acpi_size len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
| 925 | /* could do dummy write (racy) or a kernel page table lookup. |
| 926 | The later may be difficult at early boot when kmap doesn't work yet. */ |
| 927 | return 1; |
| 928 | } |
| 929 | #endif |
| 930 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 931 | u32 acpi_os_get_thread_id(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | { |
| 933 | if (!in_atomic()) |
| 934 | return current->pid; |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 939 | acpi_status acpi_os_signal(u32 function, void *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 941 | switch (function) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | case ACPI_SIGNAL_FATAL: |
| 943 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); |
| 944 | break; |
| 945 | case ACPI_SIGNAL_BREAKPOINT: |
| 946 | /* |
| 947 | * AML Breakpoint |
| 948 | * ACPI spec. says to treat it as a NOP unless |
| 949 | * you are debugging. So if/when we integrate |
| 950 | * AML debugger into the kernel debugger its |
| 951 | * hook will go here. But until then it is |
| 952 | * not useful to print anything on breakpoints. |
| 953 | */ |
| 954 | break; |
| 955 | default: |
| 956 | break; |
| 957 | } |
| 958 | |
| 959 | return AE_OK; |
| 960 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | EXPORT_SYMBOL(acpi_os_signal); |
| 963 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 964 | static int __init acpi_os_name_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | { |
| 966 | char *p = acpi_os_name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 967 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
| 969 | if (!str || !*str) |
| 970 | return 0; |
| 971 | |
| 972 | for (; count-- && str && *str; str++) { |
| 973 | if (isalnum(*str) || *str == ' ' || *str == ':') |
| 974 | *p++ = *str; |
| 975 | else if (*str == '\'' || *str == '"') |
| 976 | continue; |
| 977 | else |
| 978 | break; |
| 979 | } |
| 980 | *p = 0; |
| 981 | |
| 982 | return 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | __setup("acpi_os_name=", acpi_os_name_setup); |
| 987 | |
| 988 | /* |
| 989 | * _OSI control |
| 990 | * empty string disables _OSI |
| 991 | * TBD additional string adds to _OSI |
| 992 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 993 | static int __init acpi_osi_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | { |
| 995 | if (str == NULL || *str == '\0') { |
| 996 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); |
| 997 | acpi_gbl_create_osi_method = FALSE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 998 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | /* TBD */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1000 | printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n", |
| 1001 | str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | return 1; |
| 1005 | } |
| 1006 | |
| 1007 | __setup("acpi_osi=", acpi_osi_setup); |
| 1008 | |
| 1009 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1010 | static int __init acpi_serialize_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
| 1012 | printk(KERN_INFO PREFIX "serialize enabled\n"); |
| 1013 | |
| 1014 | acpi_gbl_all_methods_serialized = TRUE; |
| 1015 | |
| 1016 | return 1; |
| 1017 | } |
| 1018 | |
| 1019 | __setup("acpi_serialize", acpi_serialize_setup); |
| 1020 | |
| 1021 | /* |
| 1022 | * Wake and Run-Time GPES are expected to be separate. |
| 1023 | * We disable wake-GPEs at run-time to prevent spurious |
| 1024 | * interrupts. |
| 1025 | * |
| 1026 | * However, if a system exists that shares Wake and |
| 1027 | * Run-time events on the same GPE this flag is available |
| 1028 | * to tell Linux to keep the wake-time GPEs enabled at run-time. |
| 1029 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1030 | static int __init acpi_wake_gpes_always_on_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | { |
| 1032 | printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); |
| 1033 | |
| 1034 | acpi_gbl_leave_wake_gpes_disabled = FALSE; |
| 1035 | |
| 1036 | return 1; |
| 1037 | } |
| 1038 | |
| 1039 | __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); |
| 1040 | |
Adrian Bunk | 8713cbe | 2005-09-02 17:16:48 -0400 | [diff] [blame] | 1041 | static int __init acpi_hotkey_setup(char *str) |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 1042 | { |
Luming Yu | 30e332f | 2005-08-12 00:31:00 -0400 | [diff] [blame] | 1043 | acpi_specific_hotkey_enabled = FALSE; |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 1044 | return 1; |
| 1045 | } |
| 1046 | |
Luming Yu | 30e332f | 2005-08-12 00:31:00 -0400 | [diff] [blame] | 1047 | __setup("acpi_generic_hotkey", acpi_hotkey_setup); |
Luming Yu | fb9802f | 2005-03-18 18:03:45 -0500 | [diff] [blame] | 1048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | /* |
| 1050 | * max_cstate is defined in the base kernel so modules can |
| 1051 | * change it w/o depending on the state of the processor module. |
| 1052 | */ |
| 1053 | unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER; |
| 1054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | EXPORT_SYMBOL(max_cstate); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1056 | |
| 1057 | /* |
| 1058 | * Acquire a spinlock. |
| 1059 | * |
| 1060 | * handle is a pointer to the spinlock_t. |
| 1061 | * flags is *not* the result of save_flags - it is an ACPI-specific flag variable |
| 1062 | * that indicates whether we are at interrupt level. |
| 1063 | */ |
| 1064 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1065 | unsigned long acpi_os_acquire_lock(acpi_handle handle) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1066 | { |
| 1067 | unsigned long flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1068 | spin_lock_irqsave((spinlock_t *) handle, 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 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1076 | void acpi_os_release_lock(acpi_handle handle, unsigned long flags) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1077 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1078 | spin_unlock_irqrestore((spinlock_t *) handle, 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 | * |
| 1087 | * PARAMETERS: CacheName - Ascii name for the cache |
| 1088 | * ObjectSize - Size of each cached object |
| 1089 | * MaxDepth - Maximum depth of the cache (in objects) |
| 1090 | * ReturnCache - Where the new cache object is returned |
| 1091 | * |
| 1092 | * RETURN: Status |
| 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); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1102 | return AE_OK; |
| 1103 | } |
| 1104 | |
| 1105 | /******************************************************************************* |
| 1106 | * |
| 1107 | * FUNCTION: acpi_os_purge_cache |
| 1108 | * |
| 1109 | * PARAMETERS: Cache - Handle to cache object |
| 1110 | * |
| 1111 | * RETURN: Status |
| 1112 | * |
| 1113 | * DESCRIPTION: Free all objects within the requested cache. |
| 1114 | * |
| 1115 | ******************************************************************************/ |
| 1116 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1117 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1118 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1119 | (void)kmem_cache_shrink(cache); |
| 1120 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /******************************************************************************* |
| 1124 | * |
| 1125 | * FUNCTION: acpi_os_delete_cache |
| 1126 | * |
| 1127 | * PARAMETERS: Cache - Handle to cache object |
| 1128 | * |
| 1129 | * RETURN: Status |
| 1130 | * |
| 1131 | * DESCRIPTION: Free all objects within the requested cache and delete the |
| 1132 | * cache object. |
| 1133 | * |
| 1134 | ******************************************************************************/ |
| 1135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1136 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1137 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1138 | (void)kmem_cache_destroy(cache); |
| 1139 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | /******************************************************************************* |
| 1143 | * |
| 1144 | * FUNCTION: acpi_os_release_object |
| 1145 | * |
| 1146 | * PARAMETERS: Cache - Handle to cache object |
| 1147 | * Object - The object to be released |
| 1148 | * |
| 1149 | * RETURN: None |
| 1150 | * |
| 1151 | * DESCRIPTION: Release an object to the specified cache. If cache is full, |
| 1152 | * the object is deleted. |
| 1153 | * |
| 1154 | ******************************************************************************/ |
| 1155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1156 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1157 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1158 | kmem_cache_free(cache, object); |
| 1159 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /******************************************************************************* |
| 1163 | * |
| 1164 | * FUNCTION: acpi_os_acquire_object |
| 1165 | * |
| 1166 | * PARAMETERS: Cache - Handle to cache object |
| 1167 | * ReturnObject - Where the object is returned |
| 1168 | * |
| 1169 | * RETURN: Status |
| 1170 | * |
| 1171 | * DESCRIPTION: Get an object from the specified cache. If cache is empty, |
| 1172 | * the object is allocated. |
| 1173 | * |
| 1174 | ******************************************************************************/ |
| 1175 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1176 | void *acpi_os_acquire_object(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1177 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1178 | void *object = kmem_cache_alloc(cache, GFP_KERNEL); |
| 1179 | WARN_ON(!object); |
| 1180 | return object; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | #endif |