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