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