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