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