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