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