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