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