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