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> |
Matthew Wilcox | f1241c8 | 2008-03-14 13:43:13 -0400 | [diff] [blame] | 7 | * Copyright (c) 2008 Intel Corporation |
| 8 | * Author: Matthew Wilcox <willy@linux.intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 | * |
| 28 | */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/mm.h> |
| 34 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/interrupt.h> |
| 36 | #include <linux/kmod.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/workqueue.h> |
| 39 | #include <linux/nmi.h> |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 40 | #include <linux/acpi.h> |
Rafael J. Wysocki | 2d6d9fd | 2011-01-19 22:27:14 +0100 | [diff] [blame] | 41 | #include <linux/acpi_io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/efi.h> |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 43 | #include <linux/ioport.h> |
| 44 | #include <linux/list.h> |
Matthew Wilcox | f1241c8 | 2008-03-14 13:43:13 -0400 | [diff] [blame] | 45 | #include <linux/jiffies.h> |
| 46 | #include <linux/semaphore.h> |
| 47 | |
| 48 | #include <asm/io.h> |
| 49 | #include <asm/uaccess.h> |
| 50 | |
| 51 | #include <acpi/acpi.h> |
| 52 | #include <acpi/acpi_bus.h> |
| 53 | #include <acpi/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define _COMPONENT ACPI_OS_SERVICES |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 56 | ACPI_MODULE_NAME("osl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define PREFIX "ACPI: " |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 58 | struct acpi_os_dpc { |
| 59 | acpi_osd_exec_callback function; |
| 60 | void *context; |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 61 | struct work_struct work; |
Bjorn Helgaas | 9ac61856 | 2009-08-31 22:32:10 +0000 | [diff] [blame] | 62 | int wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
| 66 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE |
| 67 | #endif |
| 68 | |
| 69 | #ifdef ENABLE_DEBUGGER |
| 70 | #include <linux/kdb.h> |
| 71 | |
| 72 | /* stuff for debugger support */ |
| 73 | int acpi_in_debugger; |
| 74 | EXPORT_SYMBOL(acpi_in_debugger); |
| 75 | |
| 76 | extern char line_buf[80]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | #endif /*ENABLE_DEBUGGER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | static unsigned int acpi_irq_irq; |
| 80 | static acpi_osd_handler acpi_irq_handler; |
| 81 | static void *acpi_irq_context; |
| 82 | static struct workqueue_struct *kacpid_wq; |
Alexey Starikovskiy | 88db5e1 | 2007-05-09 23:31:03 -0400 | [diff] [blame] | 83 | static struct workqueue_struct *kacpi_notify_wq; |
Zhang Rui | c02256b | 2009-06-23 10:20:29 +0800 | [diff] [blame] | 84 | static struct workqueue_struct *kacpi_hotplug_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 86 | struct acpi_res_list { |
| 87 | resource_size_t start; |
| 88 | resource_size_t end; |
| 89 | acpi_adr_space_type resource_type; /* IO port, System memory, ...*/ |
| 90 | char name[5]; /* only can have a length of 4 chars, make use of this |
| 91 | one instead of res->name, no need to kalloc then */ |
| 92 | struct list_head resource_list; |
Lin Ming | a5fe1a0 | 2009-08-13 10:43:27 +0800 | [diff] [blame] | 93 | int count; |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | static LIST_HEAD(resource_list_head); |
| 97 | static DEFINE_SPINLOCK(acpi_res_lock); |
| 98 | |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 99 | /* |
| 100 | * This list of permanent mappings is for memory that may be accessed from |
| 101 | * interrupt context, where we can't do the ioremap(). |
| 102 | */ |
| 103 | struct acpi_ioremap { |
| 104 | struct list_head list; |
| 105 | void __iomem *virt; |
| 106 | acpi_physical_address phys; |
| 107 | acpi_size size; |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 108 | struct kref ref; |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | static LIST_HEAD(acpi_ioremaps); |
| 112 | static DEFINE_SPINLOCK(acpi_ioremap_lock); |
| 113 | |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 114 | static void __init acpi_osi_setup_late(void); |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 115 | |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 116 | /* |
Len Brown | a6e0887 | 2008-11-08 01:21:10 -0500 | [diff] [blame] | 117 | * The story of _OSI(Linux) |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 118 | * |
Len Brown | a6e0887 | 2008-11-08 01:21:10 -0500 | [diff] [blame] | 119 | * From pre-history through Linux-2.6.22, |
| 120 | * Linux responded TRUE upon a BIOS OSI(Linux) query. |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 121 | * |
Len Brown | a6e0887 | 2008-11-08 01:21:10 -0500 | [diff] [blame] | 122 | * Unfortunately, reference BIOS writers got wind of this |
| 123 | * and put OSI(Linux) in their example code, quickly exposing |
| 124 | * this string as ill-conceived and opening the door to |
| 125 | * an un-bounded number of BIOS incompatibilities. |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 126 | * |
Len Brown | a6e0887 | 2008-11-08 01:21:10 -0500 | [diff] [blame] | 127 | * For example, OSI(Linux) was used on resume to re-POST a |
| 128 | * video card on one system, because Linux at that time |
| 129 | * could not do a speedy restore in its native driver. |
| 130 | * But then upon gaining quick native restore capability, |
| 131 | * Linux has no way to tell the BIOS to skip the time-consuming |
| 132 | * POST -- putting Linux at a permanent performance disadvantage. |
| 133 | * On another system, the BIOS writer used OSI(Linux) |
| 134 | * to infer native OS support for IPMI! On other systems, |
| 135 | * OSI(Linux) simply got in the way of Linux claiming to |
| 136 | * be compatible with other operating systems, exposing |
| 137 | * BIOS issues such as skipped device initialization. |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 138 | * |
Len Brown | a6e0887 | 2008-11-08 01:21:10 -0500 | [diff] [blame] | 139 | * So "Linux" turned out to be a really poor chose of |
| 140 | * OSI string, and from Linux-2.6.23 onward we respond FALSE. |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 141 | * |
| 142 | * BIOS writers should NOT query _OSI(Linux) on future systems. |
Len Brown | a6e0887 | 2008-11-08 01:21:10 -0500 | [diff] [blame] | 143 | * Linux will complain on the console when it sees it, and return FALSE. |
| 144 | * To get Linux to return TRUE for your system will require |
| 145 | * a kernel source update to add a DMI entry, |
| 146 | * or boot with "acpi_osi=Linux" |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 147 | */ |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 148 | |
Adrian Bunk | 1d15d84 | 2008-01-29 00:10:15 +0200 | [diff] [blame] | 149 | static struct osi_linux { |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 150 | unsigned int enable:1; |
| 151 | unsigned int dmi:1; |
| 152 | unsigned int cmdline:1; |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 153 | } osi_linux = {0, 0, 0}; |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 154 | |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 155 | static u32 acpi_osi_handler(acpi_string interface, u32 supported) |
| 156 | { |
| 157 | if (!strcmp("Linux", interface)) { |
| 158 | |
Len Brown | 3af283e | 2010-10-15 21:38:57 -0400 | [diff] [blame] | 159 | printk(KERN_NOTICE FW_BUG PREFIX |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 160 | "BIOS _OSI(Linux) query %s%s\n", |
| 161 | osi_linux.enable ? "honored" : "ignored", |
| 162 | osi_linux.cmdline ? " via cmdline" : |
| 163 | osi_linux.dmi ? " via DMI" : ""); |
| 164 | } |
| 165 | |
| 166 | return supported; |
| 167 | } |
| 168 | |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 169 | static void __init acpi_request_region (struct acpi_generic_address *addr, |
| 170 | unsigned int length, char *desc) |
| 171 | { |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 172 | if (!addr->address || !length) |
| 173 | return; |
| 174 | |
Andi Kleen | cfa806f | 2010-07-20 15:18:36 -0700 | [diff] [blame] | 175 | /* Resources are never freed */ |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 176 | if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
Andi Kleen | cfa806f | 2010-07-20 15:18:36 -0700 | [diff] [blame] | 177 | request_region(addr->address, length, desc); |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 178 | else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
Andi Kleen | cfa806f | 2010-07-20 15:18:36 -0700 | [diff] [blame] | 179 | request_mem_region(addr->address, length, desc); |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static int __init acpi_reserve_resources(void) |
| 183 | { |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 184 | 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] | 185 | "ACPI PM1a_EVT_BLK"); |
| 186 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 187 | 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] | 188 | "ACPI PM1b_EVT_BLK"); |
| 189 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 190 | 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] | 191 | "ACPI PM1a_CNT_BLK"); |
| 192 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 193 | 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] | 194 | "ACPI PM1b_CNT_BLK"); |
| 195 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 196 | if (acpi_gbl_FADT.pm_timer_length == 4) |
| 197 | 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] | 198 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 199 | 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] | 200 | "ACPI PM2_CNT_BLK"); |
| 201 | |
| 202 | /* Length of GPE blocks must be a non-negative multiple of 2 */ |
| 203 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 204 | if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) |
| 205 | acpi_request_region(&acpi_gbl_FADT.xgpe0_block, |
| 206 | acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK"); |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 207 | |
Len Brown | eee3c85 | 2007-02-03 01:38:16 -0500 | [diff] [blame] | 208 | if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) |
| 209 | acpi_request_region(&acpi_gbl_FADT.xgpe1_block, |
| 210 | acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); |
Bjorn Helgaas | 9a47cdb | 2007-01-18 16:42:55 -0700 | [diff] [blame] | 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | device_initcall(acpi_reserve_resources); |
| 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | void acpi_os_printf(const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
| 218 | va_list args; |
| 219 | va_start(args, fmt); |
| 220 | acpi_os_vprintf(fmt, args); |
| 221 | va_end(args); |
| 222 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | void acpi_os_vprintf(const char *fmt, va_list args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | static char buffer[512]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | vsprintf(buffer, fmt, args); |
| 229 | |
| 230 | #ifdef ENABLE_DEBUGGER |
| 231 | if (acpi_in_debugger) { |
| 232 | kdb_printf("%s", buffer); |
| 233 | } else { |
Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 234 | printk(KERN_CONT "%s", buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | #else |
Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 237 | printk(KERN_CONT "%s", buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | #endif |
| 239 | } |
| 240 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 241 | acpi_physical_address __init acpi_os_get_root_pointer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | if (efi_enabled) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 244 | if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 245 | return efi.acpi20; |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 246 | else if (efi.acpi != EFI_INVALID_TABLE_ADDR) |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 247 | return efi.acpi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | printk(KERN_ERR PREFIX |
| 250 | "System description tables not found\n"); |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 251 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
Len Brown | 239665a | 2007-11-23 20:08:02 -0500 | [diff] [blame] | 253 | } else { |
| 254 | acpi_physical_address pa = 0; |
| 255 | |
| 256 | acpi_find_root_pointer(&pa); |
| 257 | return pa; |
| 258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 261 | /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */ |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 262 | static struct acpi_ioremap * |
| 263 | acpi_map_lookup(acpi_physical_address phys, acpi_size size) |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 264 | { |
| 265 | struct acpi_ioremap *map; |
| 266 | |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 267 | list_for_each_entry_rcu(map, &acpi_ioremaps, list) |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 268 | if (map->phys <= phys && |
| 269 | phys + size <= map->phys + map->size) |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 270 | return map; |
| 271 | |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */ |
| 276 | static void __iomem * |
| 277 | acpi_map_vaddr_lookup(acpi_physical_address phys, unsigned int size) |
| 278 | { |
| 279 | struct acpi_ioremap *map; |
| 280 | |
| 281 | map = acpi_map_lookup(phys, size); |
| 282 | if (map) |
| 283 | return map->virt + (phys - map->phys); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 284 | |
| 285 | return NULL; |
| 286 | } |
| 287 | |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 288 | /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */ |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 289 | static struct acpi_ioremap * |
| 290 | acpi_map_lookup_virt(void __iomem *virt, acpi_size size) |
| 291 | { |
| 292 | struct acpi_ioremap *map; |
| 293 | |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 294 | list_for_each_entry_rcu(map, &acpi_ioremaps, list) |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 295 | if (map->virt <= virt && |
| 296 | virt + size <= map->virt + map->size) |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 297 | return map; |
| 298 | |
| 299 | return NULL; |
| 300 | } |
| 301 | |
Jan Beulich | 2fdf074 | 2007-12-13 08:33:59 +0000 | [diff] [blame] | 302 | void __iomem *__init_refok |
| 303 | acpi_os_map_memory(acpi_physical_address phys, acpi_size size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 305 | struct acpi_ioremap *map, *tmp_map; |
Rafael J. Wysocki | 2d6d9fd | 2011-01-19 22:27:14 +0100 | [diff] [blame] | 306 | unsigned long flags; |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 307 | void __iomem *virt; |
Rafael J. Wysocki | 2d6d9fd | 2011-01-19 22:27:14 +0100 | [diff] [blame] | 308 | acpi_physical_address pg_off; |
| 309 | acpi_size pg_sz; |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 310 | |
Bjorn Helgaas | 9f4fd61 | 2006-03-26 01:37:10 -0800 | [diff] [blame] | 311 | if (phys > ULONG_MAX) { |
| 312 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); |
Randy Dunlap | 70c0846 | 2007-02-13 16:11:36 -0800 | [diff] [blame] | 313 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 315 | |
| 316 | if (!acpi_gbl_permanent_mmap) |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 317 | return __acpi_map_table((unsigned long)phys, size); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 318 | |
| 319 | map = kzalloc(sizeof(*map), GFP_KERNEL); |
| 320 | if (!map) |
| 321 | return NULL; |
| 322 | |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 323 | pg_off = round_down(phys, PAGE_SIZE); |
| 324 | pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off; |
Rafael J. Wysocki | 2d6d9fd | 2011-01-19 22:27:14 +0100 | [diff] [blame] | 325 | virt = acpi_os_ioremap(pg_off, pg_sz); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 326 | if (!virt) { |
| 327 | kfree(map); |
| 328 | return NULL; |
| 329 | } |
| 330 | |
| 331 | INIT_LIST_HEAD(&map->list); |
| 332 | map->virt = virt; |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 333 | map->phys = pg_off; |
| 334 | map->size = pg_sz; |
| 335 | kref_init(&map->ref); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 336 | |
| 337 | spin_lock_irqsave(&acpi_ioremap_lock, flags); |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 338 | /* Check if page has already been mapped. */ |
| 339 | tmp_map = acpi_map_lookup(phys, size); |
| 340 | if (tmp_map) { |
| 341 | kref_get(&tmp_map->ref); |
| 342 | spin_unlock_irqrestore(&acpi_ioremap_lock, flags); |
| 343 | iounmap(map->virt); |
| 344 | kfree(map); |
| 345 | return tmp_map->virt + (phys - tmp_map->phys); |
| 346 | } |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 347 | list_add_tail_rcu(&map->list, &acpi_ioremaps); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 348 | spin_unlock_irqrestore(&acpi_ioremap_lock, flags); |
| 349 | |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 350 | return map->virt + (phys - map->phys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 352 | EXPORT_SYMBOL_GPL(acpi_os_map_memory); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 354 | static void acpi_kref_del_iomap(struct kref *ref) |
| 355 | { |
| 356 | struct acpi_ioremap *map; |
| 357 | |
| 358 | map = container_of(ref, struct acpi_ioremap, ref); |
| 359 | list_del_rcu(&map->list); |
| 360 | } |
| 361 | |
Jeremy Fitzhardinge | 0d3a9cf | 2009-02-22 14:58:56 -0800 | [diff] [blame] | 362 | void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 364 | struct acpi_ioremap *map; |
| 365 | unsigned long flags; |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 366 | int del; |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 367 | |
| 368 | if (!acpi_gbl_permanent_mmap) { |
Yinghai Lu | 7d97277 | 2009-02-07 15:39:41 -0800 | [diff] [blame] | 369 | __acpi_unmap_table(virt, size); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 370 | return; |
| 371 | } |
| 372 | |
| 373 | spin_lock_irqsave(&acpi_ioremap_lock, flags); |
| 374 | map = acpi_map_lookup_virt(virt, size); |
| 375 | if (!map) { |
| 376 | spin_unlock_irqrestore(&acpi_ioremap_lock, flags); |
| 377 | printk(KERN_ERR PREFIX "%s: bad address %p\n", __func__, virt); |
| 378 | dump_stack(); |
| 379 | return; |
| 380 | } |
| 381 | |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 382 | del = kref_put(&map->ref, acpi_kref_del_iomap); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 383 | spin_unlock_irqrestore(&acpi_ioremap_lock, flags); |
| 384 | |
Myron Stowe | 4a3cba5 | 2010-10-21 14:24:14 -0600 | [diff] [blame] | 385 | if (!del) |
| 386 | return; |
| 387 | |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 388 | synchronize_rcu(); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 389 | iounmap(map->virt); |
| 390 | kfree(map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 392 | EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Jeremy Fitzhardinge | 0d3a9cf | 2009-02-22 14:58:56 -0800 | [diff] [blame] | 394 | void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size) |
Yinghai Lu | 7d97277 | 2009-02-07 15:39:41 -0800 | [diff] [blame] | 395 | { |
| 396 | if (!acpi_gbl_permanent_mmap) |
| 397 | __acpi_unmap_table(virt, size); |
| 398 | } |
| 399 | |
Rafael J. Wysocki | 073b496 | 2011-02-08 23:37:31 +0100 | [diff] [blame^] | 400 | static int acpi_os_map_generic_address(struct acpi_generic_address *addr) |
Myron Stowe | 2971852 | 2010-10-21 14:23:59 -0600 | [diff] [blame] | 401 | { |
| 402 | void __iomem *virt; |
| 403 | |
| 404 | if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) |
| 405 | return 0; |
| 406 | |
| 407 | if (!addr->address || !addr->bit_width) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | virt = acpi_os_map_memory(addr->address, addr->bit_width / 8); |
| 411 | if (!virt) |
| 412 | return -EIO; |
| 413 | |
| 414 | return 0; |
| 415 | } |
Myron Stowe | 2971852 | 2010-10-21 14:23:59 -0600 | [diff] [blame] | 416 | |
Rafael J. Wysocki | 073b496 | 2011-02-08 23:37:31 +0100 | [diff] [blame^] | 417 | static void acpi_os_unmap_generic_address(struct acpi_generic_address *addr) |
Myron Stowe | 2971852 | 2010-10-21 14:23:59 -0600 | [diff] [blame] | 418 | { |
| 419 | void __iomem *virt; |
| 420 | unsigned long flags; |
| 421 | acpi_size size = addr->bit_width / 8; |
| 422 | |
| 423 | if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) |
| 424 | return; |
| 425 | |
| 426 | if (!addr->address || !addr->bit_width) |
| 427 | return; |
| 428 | |
| 429 | spin_lock_irqsave(&acpi_ioremap_lock, flags); |
| 430 | virt = acpi_map_vaddr_lookup(addr->address, size); |
| 431 | spin_unlock_irqrestore(&acpi_ioremap_lock, flags); |
| 432 | |
| 433 | acpi_os_unmap_memory(virt, size); |
| 434 | } |
Myron Stowe | 2971852 | 2010-10-21 14:23:59 -0600 | [diff] [blame] | 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | #ifdef ACPI_FUTURE_USAGE |
| 437 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 438 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | if (!phys || !virt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return AE_BAD_PARAMETER; |
| 442 | |
| 443 | *phys = virt_to_phys(virt); |
| 444 | |
| 445 | return AE_OK; |
| 446 | } |
| 447 | #endif |
| 448 | |
| 449 | #define ACPI_MAX_OVERRIDE_LEN 100 |
| 450 | |
| 451 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; |
| 452 | |
| 453 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
| 455 | acpi_string * new_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { |
| 457 | if (!init_val || !new_val) |
| 458 | return AE_BAD_PARAMETER; |
| 459 | |
| 460 | *new_val = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | acpi_os_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | *new_val = acpi_os_name; |
| 465 | } |
| 466 | |
| 467 | return AE_OK; |
| 468 | } |
| 469 | |
| 470 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 471 | acpi_os_table_override(struct acpi_table_header * existing_table, |
| 472 | struct acpi_table_header ** new_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | { |
| 474 | if (!existing_table || !new_table) |
| 475 | return AE_BAD_PARAMETER; |
| 476 | |
Markus Gaugusch | 71fc47a | 2008-02-05 00:04:06 +0100 | [diff] [blame] | 477 | *new_table = NULL; |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
| 480 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | *new_table = (struct acpi_table_header *)AmlCode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | #endif |
Éric Piel | 6ed31e9 | 2008-02-05 00:04:50 +0100 | [diff] [blame] | 483 | if (*new_table != NULL) { |
| 484 | printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], " |
| 485 | "this is unsafe: tainting kernel\n", |
| 486 | existing_table->signature, |
| 487 | existing_table->oem_table_id); |
| 488 | add_taint(TAINT_OVERRIDDEN_ACPI_TABLE); |
| 489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | return AE_OK; |
| 491 | } |
| 492 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 493 | static irqreturn_t acpi_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 495 | u32 handled; |
| 496 | |
| 497 | handled = (*acpi_irq_handler) (acpi_irq_context); |
| 498 | |
| 499 | if (handled) { |
| 500 | acpi_irq_handled++; |
| 501 | return IRQ_HANDLED; |
Len Brown | 88bea18 | 2009-04-21 00:35:47 -0400 | [diff] [blame] | 502 | } else { |
| 503 | acpi_irq_not_handled++; |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 504 | return IRQ_NONE; |
Len Brown | 88bea18 | 2009-04-21 00:35:47 -0400 | [diff] [blame] | 505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 509 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
| 510 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
| 512 | unsigned int irq; |
| 513 | |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 514 | acpi_irq_stats_init(); |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | /* |
| 517 | * Ignore the GSI from the core, and use the value in our copy of the |
| 518 | * FADT. It may not be the same if an interrupt source override exists |
| 519 | * for the SCI. |
| 520 | */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 521 | gsi = acpi_gbl_FADT.sci_interrupt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { |
| 523 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", |
| 524 | gsi); |
| 525 | return AE_OK; |
| 526 | } |
| 527 | |
| 528 | acpi_irq_handler = handler; |
| 529 | acpi_irq_context = context; |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 530 | if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); |
| 532 | return AE_NOT_ACQUIRED; |
| 533 | } |
| 534 | acpi_irq_irq = irq; |
| 535 | |
| 536 | return AE_OK; |
| 537 | } |
| 538 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 539 | 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] | 540 | { |
| 541 | if (irq) { |
| 542 | free_irq(irq, acpi_irq); |
| 543 | acpi_irq_handler = NULL; |
| 544 | acpi_irq_irq = 0; |
| 545 | } |
| 546 | |
| 547 | return AE_OK; |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * Running in interpreter thread context, safe to sleep |
| 552 | */ |
| 553 | |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 554 | void acpi_os_sleep(u64 ms) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
Nishanth Aravamudan | 01a527e | 2005-11-07 01:01:14 -0800 | [diff] [blame] | 556 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 558 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 559 | void acpi_os_stall(u32 us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
| 561 | while (us) { |
| 562 | u32 delay = 1000; |
| 563 | |
| 564 | if (delay > us) |
| 565 | delay = us; |
| 566 | udelay(delay); |
| 567 | touch_nmi_watchdog(); |
| 568 | us -= delay; |
| 569 | } |
| 570 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | /* |
| 573 | * Support ACPI 3.0 AML Timer operand |
| 574 | * Returns 64-bit free-running, monotonically increasing timer |
| 575 | * with 100ns granularity |
| 576 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | u64 acpi_os_get_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
| 579 | static u64 t; |
| 580 | |
| 581 | #ifdef CONFIG_HPET |
| 582 | /* TBD: use HPET if available */ |
| 583 | #endif |
| 584 | |
| 585 | #ifdef CONFIG_X86_PM_TIMER |
| 586 | /* TBD: default to PM timer if HPET was not available */ |
| 587 | #endif |
| 588 | if (!t) |
| 589 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); |
| 590 | |
| 591 | return ++t; |
| 592 | } |
| 593 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | 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] | 595 | { |
| 596 | u32 dummy; |
| 597 | |
| 598 | if (!value) |
| 599 | value = &dummy; |
| 600 | |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 601 | *value = 0; |
| 602 | if (width <= 8) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 603 | *(u8 *) value = inb(port); |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 604 | } else if (width <= 16) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 605 | *(u16 *) value = inw(port); |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 606 | } else if (width <= 32) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | *(u32 *) value = inl(port); |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 608 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | BUG(); |
| 610 | } |
| 611 | |
| 612 | return AE_OK; |
| 613 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | EXPORT_SYMBOL(acpi_os_read_port); |
| 616 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 617 | 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] | 618 | { |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 619 | if (width <= 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | outb(value, port); |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 621 | } else if (width <= 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | outw(value, port); |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 623 | } else if (width <= 32) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | outl(value, port); |
Zhao Yakui | 49fbabf | 2007-11-15 17:01:06 +0800 | [diff] [blame] | 625 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | BUG(); |
| 627 | } |
| 628 | |
| 629 | return AE_OK; |
| 630 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | EXPORT_SYMBOL(acpi_os_write_port); |
| 633 | |
| 634 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 635 | 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] | 636 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 637 | void __iomem *virt_addr; |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 638 | unsigned int size = width / 8; |
| 639 | bool unmap = false; |
| 640 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 642 | rcu_read_lock(); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 643 | virt_addr = acpi_map_vaddr_lookup(phys_addr, size); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 644 | if (!virt_addr) { |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 645 | rcu_read_unlock(); |
Rafael J. Wysocki | 2d6d9fd | 2011-01-19 22:27:14 +0100 | [diff] [blame] | 646 | virt_addr = acpi_os_ioremap(phys_addr, size); |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 647 | if (!virt_addr) |
| 648 | return AE_BAD_ADDRESS; |
| 649 | unmap = true; |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 650 | } |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | if (!value) |
| 653 | value = &dummy; |
| 654 | |
| 655 | switch (width) { |
| 656 | case 8: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 657 | *(u8 *) value = readb(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | break; |
| 659 | case 16: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 660 | *(u16 *) value = readw(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | break; |
| 662 | case 32: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 663 | *(u32 *) value = readl(virt_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | break; |
| 665 | default: |
| 666 | BUG(); |
| 667 | } |
| 668 | |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 669 | if (unmap) |
| 670 | iounmap(virt_addr); |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 671 | else |
| 672 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | return AE_OK; |
| 675 | } |
| 676 | |
| 677 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | 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] | 679 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 | void __iomem *virt_addr; |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 681 | unsigned int size = width / 8; |
| 682 | bool unmap = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
Myron Stowe | 78cdb3e | 2010-10-21 14:24:09 -0600 | [diff] [blame] | 684 | rcu_read_lock(); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 685 | virt_addr = acpi_map_vaddr_lookup(phys_addr, size); |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 686 | if (!virt_addr) { |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 687 | rcu_read_unlock(); |
Rafael J. Wysocki | 2d6d9fd | 2011-01-19 22:27:14 +0100 | [diff] [blame] | 688 | virt_addr = acpi_os_ioremap(phys_addr, size); |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 689 | if (!virt_addr) |
| 690 | return AE_BAD_ADDRESS; |
| 691 | unmap = true; |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | switch (width) { |
| 695 | case 8: |
| 696 | writeb(value, virt_addr); |
| 697 | break; |
| 698 | case 16: |
| 699 | writew(value, virt_addr); |
| 700 | break; |
| 701 | case 32: |
| 702 | writel(value, virt_addr); |
| 703 | break; |
| 704 | default: |
| 705 | BUG(); |
| 706 | } |
| 707 | |
Myron Stowe | 620242a | 2010-10-21 14:23:53 -0600 | [diff] [blame] | 708 | if (unmap) |
| 709 | iounmap(virt_addr); |
Rafael J. Wysocki | 884b821 | 2011-02-08 23:37:16 +0100 | [diff] [blame] | 710 | else |
| 711 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | return AE_OK; |
| 714 | } |
| 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 717 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
Bob Moore | c5f0231 | 2010-08-06 08:57:53 +0800 | [diff] [blame] | 718 | u64 *value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
| 720 | int result, size; |
Bob Moore | c5f0231 | 2010-08-06 08:57:53 +0800 | [diff] [blame] | 721 | u32 value32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | if (!value) |
| 724 | return AE_BAD_PARAMETER; |
| 725 | |
| 726 | switch (width) { |
| 727 | case 8: |
| 728 | size = 1; |
| 729 | break; |
| 730 | case 16: |
| 731 | size = 2; |
| 732 | break; |
| 733 | case 32: |
| 734 | size = 4; |
| 735 | break; |
| 736 | default: |
| 737 | return AE_ERROR; |
| 738 | } |
| 739 | |
Matthew Wilcox | b6ce068 | 2008-02-10 09:45:28 -0500 | [diff] [blame] | 740 | result = raw_pci_read(pci_id->segment, pci_id->bus, |
| 741 | PCI_DEVFN(pci_id->device, pci_id->function), |
Bob Moore | c5f0231 | 2010-08-06 08:57:53 +0800 | [diff] [blame] | 742 | reg, size, &value32); |
| 743 | *value = value32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
| 745 | return (result ? AE_ERROR : AE_OK); |
| 746 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 749 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 750 | u64 value, u32 width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
| 752 | int result, size; |
| 753 | |
| 754 | switch (width) { |
| 755 | case 8: |
| 756 | size = 1; |
| 757 | break; |
| 758 | case 16: |
| 759 | size = 2; |
| 760 | break; |
| 761 | case 32: |
| 762 | size = 4; |
| 763 | break; |
| 764 | default: |
| 765 | return AE_ERROR; |
| 766 | } |
| 767 | |
Matthew Wilcox | b6ce068 | 2008-02-10 09:45:28 -0500 | [diff] [blame] | 768 | result = raw_pci_write(pci_id->segment, pci_id->bus, |
| 769 | PCI_DEVFN(pci_id->device, pci_id->function), |
| 770 | reg, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
| 772 | return (result ? AE_ERROR : AE_OK); |
| 773 | } |
| 774 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 775 | static void acpi_os_execute_deferred(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 777 | 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] | 778 | |
Bjorn Helgaas | 9ac61856 | 2009-08-31 22:32:10 +0000 | [diff] [blame] | 779 | if (dpc->wait) |
| 780 | acpi_os_wait_events_complete(NULL); |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 781 | |
| 782 | dpc->function(dpc->context); |
| 783 | kfree(dpc); |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 784 | } |
| 785 | |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 786 | /******************************************************************************* |
| 787 | * |
| 788 | * FUNCTION: acpi_os_execute |
| 789 | * |
| 790 | * PARAMETERS: Type - Type of the callback |
| 791 | * Function - Function to be executed |
| 792 | * Context - Function parameters |
| 793 | * |
| 794 | * RETURN: Status |
| 795 | * |
| 796 | * DESCRIPTION: Depending on type, either queues function for deferred execution or |
| 797 | * immediately executes function on a separate thread. |
| 798 | * |
| 799 | ******************************************************************************/ |
| 800 | |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 801 | static acpi_status __acpi_os_execute(acpi_execute_type type, |
| 802 | acpi_osd_exec_callback function, void *context, int hp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 804 | acpi_status status = AE_OK; |
| 805 | struct acpi_os_dpc *dpc; |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 806 | struct workqueue_struct *queue; |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 807 | int ret; |
Len Brown | 72945b2 | 2006-07-12 22:46:42 -0400 | [diff] [blame] | 808 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 809 | "Scheduling function [%p(%p)] for deferred execution.\n", |
| 810 | function, context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | /* |
| 813 | * Allocate/initialize DPC structure. Note that this memory will be |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 814 | * 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] | 815 | * way that allows us to also free its memory inside the callee. |
| 816 | * Because we may want to schedule several tasks with different |
| 817 | * parameters we can't use the approach some kernel code uses of |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 818 | * having a static work_struct. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | */ |
Len Brown | 72945b2 | 2006-07-12 22:46:42 -0400 | [diff] [blame] | 820 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 821 | dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | if (!dpc) |
Lin Ming | 889c78b | 2008-12-31 09:23:57 +0800 | [diff] [blame] | 823 | return AE_NO_MEMORY; |
Linus Torvalds | b976fe1 | 2006-11-17 19:31:09 -0800 | [diff] [blame] | 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | dpc->function = function; |
| 826 | dpc->context = context; |
Linus Torvalds | b976fe1 | 2006-11-17 19:31:09 -0800 | [diff] [blame] | 827 | |
Zhang Rui | c02256b | 2009-06-23 10:20:29 +0800 | [diff] [blame] | 828 | /* |
| 829 | * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq |
| 830 | * because the hotplug code may call driver .remove() functions, |
| 831 | * which invoke flush_scheduled_work/acpi_os_wait_events_complete |
| 832 | * to flush these workqueues. |
| 833 | */ |
| 834 | queue = hp ? kacpi_hotplug_wq : |
| 835 | (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq); |
Bjorn Helgaas | 9ac61856 | 2009-08-31 22:32:10 +0000 | [diff] [blame] | 836 | dpc->wait = hp ? 1 : 0; |
Zhang Rui | bc73675 | 2010-03-22 15:48:54 +0800 | [diff] [blame] | 837 | |
| 838 | if (queue == kacpi_hotplug_wq) |
| 839 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); |
| 840 | else if (queue == kacpi_notify_wq) |
| 841 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); |
| 842 | else |
| 843 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); |
| 844 | |
Tejun Heo | 8fec62b | 2010-06-29 10:07:09 +0200 | [diff] [blame] | 845 | /* |
| 846 | * On some machines, a software-initiated SMI causes corruption unless |
| 847 | * the SMI runs on CPU 0. An SMI can be initiated by any AML, but |
| 848 | * typically it's done in GPE-related methods that are run via |
| 849 | * workqueues, so we can avoid the known corruption cases by always |
| 850 | * queueing on CPU 0. |
| 851 | */ |
| 852 | ret = queue_work_on(0, queue, &dpc->work); |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 853 | |
| 854 | if (!ret) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 855 | printk(KERN_ERR PREFIX |
| 856 | "Call to queue_work() failed.\n"); |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 857 | status = AE_ERROR; |
| 858 | kfree(dpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
Lin Ming | 889c78b | 2008-12-31 09:23:57 +0800 | [diff] [blame] | 860 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 862 | |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 863 | acpi_status acpi_os_execute(acpi_execute_type type, |
| 864 | acpi_osd_exec_callback function, void *context) |
| 865 | { |
| 866 | return __acpi_os_execute(type, function, context, 0); |
| 867 | } |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 868 | EXPORT_SYMBOL(acpi_os_execute); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 870 | acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function, |
| 871 | void *context) |
| 872 | { |
| 873 | return __acpi_os_execute(0, function, context, 1); |
| 874 | } |
| 875 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 876 | void acpi_os_wait_events_complete(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | { |
| 878 | flush_workqueue(kacpid_wq); |
Zhang Rui | 2f67a06 | 2008-04-29 02:34:42 -0400 | [diff] [blame] | 879 | flush_workqueue(kacpi_notify_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
| 883 | |
| 884 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | * Deallocate the memory for a spinlock. |
| 886 | */ |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 887 | void acpi_os_delete_lock(acpi_spinlock handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 889 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 893 | 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] | 894 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | struct semaphore *sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | sem = acpi_os_allocate(sizeof(struct semaphore)); |
| 898 | if (!sem) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 899 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | memset(sem, 0, sizeof(struct semaphore)); |
| 901 | |
| 902 | sema_init(sem, initial_units); |
| 903 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 904 | *handle = (acpi_handle *) sem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 906 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
| 907 | *handle, initial_units)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 909 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | /* |
| 913 | * TODO: A better way to delete semaphores? Linux doesn't have a |
| 914 | * 'delete_semaphore()' function -- may result in an invalid |
| 915 | * pointer dereference for non-synchronized consumers. Should |
| 916 | * we at least check for blocked threads and signal/cancel them? |
| 917 | */ |
| 918 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 919 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
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 | struct semaphore *sem = (struct semaphore *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | if (!sem) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 924 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 926 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
Matthew Wilcox | f1241c8 | 2008-03-14 13:43:13 -0400 | [diff] [blame] | 928 | BUG_ON(!list_empty(&sem->wait_list)); |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 929 | kfree(sem); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 930 | sem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 932 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | * TODO: Support for units > 1? |
| 937 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 938 | 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] | 939 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 940 | acpi_status status = AE_OK; |
| 941 | struct semaphore *sem = (struct semaphore *)handle; |
Matthew Wilcox | f1241c8 | 2008-03-14 13:43:13 -0400 | [diff] [blame] | 942 | long jiffies; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 943 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | if (!sem || (units < 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 946 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
| 948 | if (units > 1) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 949 | return AE_SUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 951 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
| 952 | handle, units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Matthew Wilcox | f1241c8 | 2008-03-14 13:43:13 -0400 | [diff] [blame] | 954 | if (timeout == ACPI_WAIT_FOREVER) |
| 955 | jiffies = MAX_SCHEDULE_TIMEOUT; |
| 956 | else |
| 957 | jiffies = msecs_to_jiffies(timeout); |
| 958 | |
| 959 | ret = down_timeout(sem, jiffies); |
| 960 | if (ret) |
| 961 | status = AE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | |
| 963 | if (ACPI_FAILURE(status)) { |
Bjorn Helgaas | 9e7e2c0 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 964 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 965 | "Failed to acquire semaphore[%p|%d|%d], %s", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 966 | handle, units, timeout, |
| 967 | acpi_format_exception(status))); |
| 968 | } else { |
| 969 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 970 | "Acquired semaphore[%p|%d|%d]", handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 971 | units, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 974 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | /* |
| 978 | * TODO: Support for units > 1? |
| 979 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 980 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 982 | struct semaphore *sem = (struct semaphore *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | if (!sem || (units < 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 985 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
| 987 | if (units > 1) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 988 | return AE_SUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 990 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
| 991 | units)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
| 993 | up(sem); |
| 994 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 995 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | #ifdef ACPI_FUTURE_USAGE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 999 | u32 acpi_os_get_line(char *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | { |
| 1001 | |
| 1002 | #ifdef ENABLE_DEBUGGER |
| 1003 | if (acpi_in_debugger) { |
| 1004 | u32 chars; |
| 1005 | |
| 1006 | kdb_read(buffer, sizeof(line_buf)); |
| 1007 | |
| 1008 | /* remove the CR kdb includes */ |
| 1009 | chars = strlen(buffer) - 1; |
| 1010 | buffer[chars] = '\0'; |
| 1011 | } |
| 1012 | #endif |
| 1013 | |
| 1014 | return 0; |
| 1015 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1016 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1018 | acpi_status acpi_os_signal(u32 function, void *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1020 | switch (function) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | case ACPI_SIGNAL_FATAL: |
| 1022 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); |
| 1023 | break; |
| 1024 | case ACPI_SIGNAL_BREAKPOINT: |
| 1025 | /* |
| 1026 | * AML Breakpoint |
| 1027 | * ACPI spec. says to treat it as a NOP unless |
| 1028 | * you are debugging. So if/when we integrate |
| 1029 | * AML debugger into the kernel debugger its |
| 1030 | * hook will go here. But until then it is |
| 1031 | * not useful to print anything on breakpoints. |
| 1032 | */ |
| 1033 | break; |
| 1034 | default: |
| 1035 | break; |
| 1036 | } |
| 1037 | |
| 1038 | return AE_OK; |
| 1039 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1040 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1041 | static int __init acpi_os_name_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { |
| 1043 | char *p = acpi_os_name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1044 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | |
| 1046 | if (!str || !*str) |
| 1047 | return 0; |
| 1048 | |
| 1049 | for (; count-- && str && *str; str++) { |
| 1050 | if (isalnum(*str) || *str == ' ' || *str == ':') |
| 1051 | *p++ = *str; |
| 1052 | else if (*str == '\'' || *str == '"') |
| 1053 | continue; |
| 1054 | else |
| 1055 | break; |
| 1056 | } |
| 1057 | *p = 0; |
| 1058 | |
| 1059 | return 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | __setup("acpi_os_name=", acpi_os_name_setup); |
| 1064 | |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1065 | #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ |
| 1066 | #define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */ |
| 1067 | |
| 1068 | struct osi_setup_entry { |
| 1069 | char string[OSI_STRING_LENGTH_MAX]; |
| 1070 | bool enable; |
| 1071 | }; |
| 1072 | |
| 1073 | static struct osi_setup_entry __initdata osi_setup_entries[OSI_STRING_ENTRIES_MAX]; |
| 1074 | |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1075 | void __init acpi_osi_setup(char *str) |
| 1076 | { |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1077 | struct osi_setup_entry *osi; |
| 1078 | bool enable = true; |
| 1079 | int i; |
| 1080 | |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1081 | if (!acpi_gbl_create_osi_method) |
| 1082 | return; |
| 1083 | |
| 1084 | if (str == NULL || *str == '\0') { |
| 1085 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); |
| 1086 | acpi_gbl_create_osi_method = FALSE; |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1087 | return; |
| 1088 | } |
| 1089 | |
| 1090 | if (*str == '!') { |
| 1091 | str++; |
| 1092 | enable = false; |
| 1093 | } |
| 1094 | |
| 1095 | for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) { |
| 1096 | osi = &osi_setup_entries[i]; |
| 1097 | if (!strcmp(osi->string, str)) { |
| 1098 | osi->enable = enable; |
| 1099 | break; |
| 1100 | } else if (osi->string[0] == '\0') { |
| 1101 | osi->enable = enable; |
| 1102 | strncpy(osi->string, str, OSI_STRING_LENGTH_MAX); |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1106 | } |
| 1107 | |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1108 | static void __init set_osi_linux(unsigned int enable) |
| 1109 | { |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1110 | if (osi_linux.enable != enable) |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1111 | osi_linux.enable = enable; |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 1112 | |
| 1113 | if (osi_linux.enable) |
| 1114 | acpi_osi_setup("Linux"); |
| 1115 | else |
| 1116 | acpi_osi_setup("!Linux"); |
| 1117 | |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1118 | return; |
| 1119 | } |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 1120 | |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1121 | static void __init acpi_cmdline_osi_linux(unsigned int enable) |
| 1122 | { |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1123 | osi_linux.cmdline = 1; /* cmdline set the default and override DMI */ |
| 1124 | osi_linux.dmi = 0; |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1125 | set_osi_linux(enable); |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 1126 | |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1127 | return; |
| 1128 | } |
| 1129 | |
| 1130 | void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d) |
| 1131 | { |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1132 | printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident); |
| 1133 | |
| 1134 | if (enable == -1) |
| 1135 | return; |
| 1136 | |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1137 | osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */ |
Len Brown | d4b7dc4 | 2008-01-23 20:50:56 -0500 | [diff] [blame] | 1138 | set_osi_linux(enable); |
| 1139 | |
Len Brown | f507654 | 2007-05-30 00:10:38 -0400 | [diff] [blame] | 1140 | return; |
| 1141 | } |
| 1142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | /* |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 1144 | * Modify the list of "OS Interfaces" reported to BIOS via _OSI |
| 1145 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | * empty string disables _OSI |
Len Brown | ae00d81 | 2007-05-29 18:43:33 -0400 | [diff] [blame] | 1147 | * string starting with '!' disables that string |
| 1148 | * otherwise string is added to list, augmenting built-in strings |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | */ |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 1150 | static void __init acpi_osi_setup_late(void) |
| 1151 | { |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1152 | struct osi_setup_entry *osi; |
| 1153 | char *str; |
| 1154 | int i; |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1155 | acpi_status status; |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 1156 | |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1157 | for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) { |
| 1158 | osi = &osi_setup_entries[i]; |
| 1159 | str = osi->string; |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 1160 | |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1161 | if (*str == '\0') |
| 1162 | break; |
| 1163 | if (osi->enable) { |
| 1164 | status = acpi_install_interface(str); |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1165 | |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1166 | if (ACPI_SUCCESS(status)) |
| 1167 | printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str); |
| 1168 | } else { |
| 1169 | status = acpi_remove_interface(str); |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1170 | |
Lin Ming | 12d3206 | 2010-12-09 16:51:06 +0800 | [diff] [blame] | 1171 | if (ACPI_SUCCESS(status)) |
| 1172 | printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); |
| 1173 | } |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1177 | static int __init osi_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | { |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1179 | if (str && !strcmp("Linux", str)) |
| 1180 | acpi_cmdline_osi_linux(1); |
| 1181 | else if (str && !strcmp("!Linux", str)) |
| 1182 | acpi_cmdline_osi_linux(0); |
| 1183 | else |
| 1184 | acpi_osi_setup(str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
| 1186 | return 1; |
| 1187 | } |
| 1188 | |
Lin Ming | d90aa92 | 2010-12-09 16:50:52 +0800 | [diff] [blame] | 1189 | __setup("acpi_osi=", osi_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
| 1191 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1192 | static int __init acpi_serialize_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | { |
| 1194 | printk(KERN_INFO PREFIX "serialize enabled\n"); |
| 1195 | |
| 1196 | acpi_gbl_all_methods_serialized = TRUE; |
| 1197 | |
| 1198 | return 1; |
| 1199 | } |
| 1200 | |
| 1201 | __setup("acpi_serialize", acpi_serialize_setup); |
| 1202 | |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1203 | /* Check of resource interference between native drivers and ACPI |
| 1204 | * OperationRegions (SystemIO and System Memory only). |
| 1205 | * IO ports and memory declared in ACPI might be used by the ACPI subsystem |
| 1206 | * in arbitrary AML code and can interfere with legacy drivers. |
| 1207 | * acpi_enforce_resources= can be set to: |
| 1208 | * |
Luca Tettamanti | 7e90560 | 2009-03-30 00:01:27 +0200 | [diff] [blame] | 1209 | * - strict (default) (2) |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1210 | * -> further driver trying to access the resources will not load |
Luca Tettamanti | 7e90560 | 2009-03-30 00:01:27 +0200 | [diff] [blame] | 1211 | * - lax (1) |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1212 | * -> further driver trying to access the resources will load, but you |
| 1213 | * get a system message that something might go wrong... |
| 1214 | * |
| 1215 | * - no (0) |
| 1216 | * -> ACPI Operation Region resources will not be registered |
| 1217 | * |
| 1218 | */ |
| 1219 | #define ENFORCE_RESOURCES_STRICT 2 |
| 1220 | #define ENFORCE_RESOURCES_LAX 1 |
| 1221 | #define ENFORCE_RESOURCES_NO 0 |
| 1222 | |
Luca Tettamanti | 7e90560 | 2009-03-30 00:01:27 +0200 | [diff] [blame] | 1223 | static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT; |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1224 | |
| 1225 | static int __init acpi_enforce_resources_setup(char *str) |
| 1226 | { |
| 1227 | if (str == NULL || *str == '\0') |
| 1228 | return 0; |
| 1229 | |
| 1230 | if (!strcmp("strict", str)) |
| 1231 | acpi_enforce_resources = ENFORCE_RESOURCES_STRICT; |
| 1232 | else if (!strcmp("lax", str)) |
| 1233 | acpi_enforce_resources = ENFORCE_RESOURCES_LAX; |
| 1234 | else if (!strcmp("no", str)) |
| 1235 | acpi_enforce_resources = ENFORCE_RESOURCES_NO; |
| 1236 | |
| 1237 | return 1; |
| 1238 | } |
| 1239 | |
| 1240 | __setup("acpi_enforce_resources=", acpi_enforce_resources_setup); |
| 1241 | |
| 1242 | /* Check for resource conflicts between ACPI OperationRegions and native |
| 1243 | * drivers */ |
Jean Delvare | 876fba4 | 2009-11-11 15:22:15 +0100 | [diff] [blame] | 1244 | int acpi_check_resource_conflict(const struct resource *res) |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1245 | { |
| 1246 | struct acpi_res_list *res_list_elem; |
Thomas Renninger | 106d1a0 | 2010-12-20 12:11:45 +0100 | [diff] [blame] | 1247 | int ioport = 0, clash = 0; |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1248 | |
| 1249 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) |
| 1250 | return 0; |
| 1251 | if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM)) |
| 1252 | return 0; |
| 1253 | |
| 1254 | ioport = res->flags & IORESOURCE_IO; |
| 1255 | |
| 1256 | spin_lock(&acpi_res_lock); |
| 1257 | list_for_each_entry(res_list_elem, &resource_list_head, |
| 1258 | resource_list) { |
| 1259 | if (ioport && (res_list_elem->resource_type |
| 1260 | != ACPI_ADR_SPACE_SYSTEM_IO)) |
| 1261 | continue; |
| 1262 | if (!ioport && (res_list_elem->resource_type |
| 1263 | != ACPI_ADR_SPACE_SYSTEM_MEMORY)) |
| 1264 | continue; |
| 1265 | |
| 1266 | if (res->end < res_list_elem->start |
| 1267 | || res_list_elem->end < res->start) |
| 1268 | continue; |
| 1269 | clash = 1; |
| 1270 | break; |
| 1271 | } |
| 1272 | spin_unlock(&acpi_res_lock); |
| 1273 | |
| 1274 | if (clash) { |
| 1275 | if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) { |
Chase Douglas | 1638bca | 2010-03-22 15:08:09 -0400 | [diff] [blame] | 1276 | printk(KERN_WARNING "ACPI: resource %s %pR" |
Thomas Renninger | 106d1a0 | 2010-12-20 12:11:45 +0100 | [diff] [blame] | 1277 | " conflicts with ACPI region %s " |
| 1278 | "[%s 0x%zx-0x%zx]\n", |
Chase Douglas | 1638bca | 2010-03-22 15:08:09 -0400 | [diff] [blame] | 1279 | res->name, res, res_list_elem->name, |
Thomas Renninger | 106d1a0 | 2010-12-20 12:11:45 +0100 | [diff] [blame] | 1280 | (res_list_elem->resource_type == |
| 1281 | ACPI_ADR_SPACE_SYSTEM_IO) ? "io" : "mem", |
| 1282 | (size_t) res_list_elem->start, |
| 1283 | (size_t) res_list_elem->end); |
Jean Delvare | 14f0334 | 2009-09-08 15:31:46 +0200 | [diff] [blame] | 1284 | if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX) |
| 1285 | printk(KERN_NOTICE "ACPI: This conflict may" |
| 1286 | " cause random problems and system" |
| 1287 | " instability\n"); |
| 1288 | printk(KERN_INFO "ACPI: If an ACPI driver is available" |
| 1289 | " for this device, you should use it instead of" |
| 1290 | " the native driver\n"); |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1291 | } |
| 1292 | if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT) |
| 1293 | return -EBUSY; |
| 1294 | } |
| 1295 | return 0; |
| 1296 | } |
Thomas Renninger | 443dea7 | 2008-02-04 23:31:23 -0800 | [diff] [blame] | 1297 | EXPORT_SYMBOL(acpi_check_resource_conflict); |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1298 | |
| 1299 | int acpi_check_region(resource_size_t start, resource_size_t n, |
| 1300 | const char *name) |
| 1301 | { |
| 1302 | struct resource res = { |
| 1303 | .start = start, |
| 1304 | .end = start + n - 1, |
| 1305 | .name = name, |
| 1306 | .flags = IORESOURCE_IO, |
| 1307 | }; |
| 1308 | |
| 1309 | return acpi_check_resource_conflict(&res); |
| 1310 | } |
| 1311 | EXPORT_SYMBOL(acpi_check_region); |
| 1312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | /* |
Jean Delvare | 70dd6be | 2010-05-27 19:58:37 +0200 | [diff] [blame] | 1314 | * Let drivers know whether the resource checks are effective |
| 1315 | */ |
| 1316 | int acpi_resources_are_enforced(void) |
| 1317 | { |
| 1318 | return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT; |
| 1319 | } |
| 1320 | EXPORT_SYMBOL(acpi_resources_are_enforced); |
| 1321 | |
| 1322 | /* |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1323 | * Acquire a spinlock. |
| 1324 | * |
| 1325 | * handle is a pointer to the spinlock_t. |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1326 | */ |
| 1327 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1328 | acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1329 | { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1330 | acpi_cpu_flags flags; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1331 | spin_lock_irqsave(lockp, flags); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1332 | return flags; |
| 1333 | } |
| 1334 | |
| 1335 | /* |
| 1336 | * Release a spinlock. See above. |
| 1337 | */ |
| 1338 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1339 | void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1340 | { |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 1341 | spin_unlock_irqrestore(lockp, flags); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1344 | #ifndef ACPI_USE_LOCAL_CACHE |
| 1345 | |
| 1346 | /******************************************************************************* |
| 1347 | * |
| 1348 | * FUNCTION: acpi_os_create_cache |
| 1349 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1350 | * PARAMETERS: name - Ascii name for the cache |
| 1351 | * size - Size of each cached object |
| 1352 | * depth - Maximum depth of the cache (in objects) <ignored> |
| 1353 | * cache - Where the new cache object is returned |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1354 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1355 | * RETURN: status |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1356 | * |
| 1357 | * DESCRIPTION: Create a cache object |
| 1358 | * |
| 1359 | ******************************************************************************/ |
| 1360 | |
| 1361 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1362 | 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] | 1363 | { |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1364 | *cache = kmem_cache_create(name, size, 0, 0, NULL); |
Adrian Bunk | a6fdbf9 | 2006-12-19 12:56:13 -0800 | [diff] [blame] | 1365 | if (*cache == NULL) |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1366 | return AE_ERROR; |
| 1367 | else |
| 1368 | return AE_OK; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /******************************************************************************* |
| 1372 | * |
| 1373 | * FUNCTION: acpi_os_purge_cache |
| 1374 | * |
| 1375 | * PARAMETERS: Cache - Handle to cache object |
| 1376 | * |
| 1377 | * RETURN: Status |
| 1378 | * |
| 1379 | * DESCRIPTION: Free all objects within the requested cache. |
| 1380 | * |
| 1381 | ******************************************************************************/ |
| 1382 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1383 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1384 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1385 | kmem_cache_shrink(cache); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1386 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /******************************************************************************* |
| 1390 | * |
| 1391 | * FUNCTION: acpi_os_delete_cache |
| 1392 | * |
| 1393 | * PARAMETERS: Cache - Handle to cache object |
| 1394 | * |
| 1395 | * RETURN: Status |
| 1396 | * |
| 1397 | * DESCRIPTION: Free all objects within the requested cache and delete the |
| 1398 | * cache object. |
| 1399 | * |
| 1400 | ******************************************************************************/ |
| 1401 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1402 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1403 | { |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 1404 | kmem_cache_destroy(cache); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1405 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | /******************************************************************************* |
| 1409 | * |
| 1410 | * FUNCTION: acpi_os_release_object |
| 1411 | * |
| 1412 | * PARAMETERS: Cache - Handle to cache object |
| 1413 | * Object - The object to be released |
| 1414 | * |
| 1415 | * RETURN: None |
| 1416 | * |
| 1417 | * DESCRIPTION: Release an object to the specified cache. If cache is full, |
| 1418 | * the object is deleted. |
| 1419 | * |
| 1420 | ******************************************************************************/ |
| 1421 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1422 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1423 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1424 | kmem_cache_free(cache, object); |
| 1425 | return (AE_OK); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
Lin Ming | a5fe1a0 | 2009-08-13 10:43:27 +0800 | [diff] [blame] | 1428 | static inline int acpi_res_list_add(struct acpi_res_list *res) |
| 1429 | { |
| 1430 | struct acpi_res_list *res_list_elem; |
| 1431 | |
| 1432 | list_for_each_entry(res_list_elem, &resource_list_head, |
| 1433 | resource_list) { |
| 1434 | |
| 1435 | if (res->resource_type == res_list_elem->resource_type && |
| 1436 | res->start == res_list_elem->start && |
| 1437 | res->end == res_list_elem->end) { |
| 1438 | |
| 1439 | /* |
| 1440 | * The Region(addr,len) already exist in the list, |
| 1441 | * just increase the count |
| 1442 | */ |
| 1443 | |
| 1444 | res_list_elem->count++; |
| 1445 | return 0; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | res->count = 1; |
| 1450 | list_add(&res->resource_list, &resource_list_head); |
| 1451 | return 1; |
| 1452 | } |
| 1453 | |
| 1454 | static inline void acpi_res_list_del(struct acpi_res_list *res) |
| 1455 | { |
| 1456 | struct acpi_res_list *res_list_elem; |
| 1457 | |
| 1458 | list_for_each_entry(res_list_elem, &resource_list_head, |
| 1459 | resource_list) { |
| 1460 | |
| 1461 | if (res->resource_type == res_list_elem->resource_type && |
| 1462 | res->start == res_list_elem->start && |
| 1463 | res->end == res_list_elem->end) { |
| 1464 | |
| 1465 | /* |
| 1466 | * If the res count is decreased to 0, |
| 1467 | * remove and free it |
| 1468 | */ |
| 1469 | |
| 1470 | if (--res_list_elem->count == 0) { |
| 1471 | list_del(&res_list_elem->resource_list); |
| 1472 | kfree(res_list_elem); |
| 1473 | } |
| 1474 | return; |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | acpi_status |
| 1480 | acpi_os_invalidate_address( |
| 1481 | u8 space_id, |
| 1482 | acpi_physical_address address, |
| 1483 | acpi_size length) |
| 1484 | { |
| 1485 | struct acpi_res_list res; |
| 1486 | |
| 1487 | switch (space_id) { |
| 1488 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 1489 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
Thomas Weber | 8839316 | 2010-03-16 11:47:56 +0100 | [diff] [blame] | 1490 | /* Only interference checks against SystemIO and SystemMemory |
Lin Ming | a5fe1a0 | 2009-08-13 10:43:27 +0800 | [diff] [blame] | 1491 | are needed */ |
| 1492 | res.start = address; |
| 1493 | res.end = address + length - 1; |
| 1494 | res.resource_type = space_id; |
| 1495 | spin_lock(&acpi_res_lock); |
| 1496 | acpi_res_list_del(&res); |
| 1497 | spin_unlock(&acpi_res_lock); |
| 1498 | break; |
| 1499 | case ACPI_ADR_SPACE_PCI_CONFIG: |
| 1500 | case ACPI_ADR_SPACE_EC: |
| 1501 | case ACPI_ADR_SPACE_SMBUS: |
| 1502 | case ACPI_ADR_SPACE_CMOS: |
| 1503 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: |
| 1504 | case ACPI_ADR_SPACE_DATA_TABLE: |
| 1505 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
| 1506 | break; |
| 1507 | } |
| 1508 | return AE_OK; |
| 1509 | } |
| 1510 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1511 | /****************************************************************************** |
| 1512 | * |
| 1513 | * FUNCTION: acpi_os_validate_address |
| 1514 | * |
| 1515 | * PARAMETERS: space_id - ACPI space ID |
| 1516 | * address - Physical address |
| 1517 | * length - Address length |
| 1518 | * |
| 1519 | * RETURN: AE_OK if address/length is valid for the space_id. Otherwise, |
| 1520 | * should return AE_AML_ILLEGAL_ADDRESS. |
| 1521 | * |
| 1522 | * DESCRIPTION: Validate a system address via the host OS. Used to validate |
| 1523 | * the addresses accessed by AML operation regions. |
| 1524 | * |
| 1525 | *****************************************************************************/ |
| 1526 | |
| 1527 | acpi_status |
| 1528 | acpi_os_validate_address ( |
| 1529 | u8 space_id, |
| 1530 | acpi_physical_address address, |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1531 | acpi_size length, |
| 1532 | char *name) |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1533 | { |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1534 | struct acpi_res_list *res; |
Lin Ming | a5fe1a0 | 2009-08-13 10:43:27 +0800 | [diff] [blame] | 1535 | int added; |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1536 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) |
| 1537 | return AE_OK; |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1538 | |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1539 | switch (space_id) { |
| 1540 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 1541 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
Thomas Weber | 8839316 | 2010-03-16 11:47:56 +0100 | [diff] [blame] | 1542 | /* Only interference checks against SystemIO and SystemMemory |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1543 | are needed */ |
| 1544 | res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL); |
| 1545 | if (!res) |
| 1546 | return AE_OK; |
| 1547 | /* ACPI names are fixed to 4 bytes, still better use strlcpy */ |
| 1548 | strlcpy(res->name, name, 5); |
| 1549 | res->start = address; |
| 1550 | res->end = address + length - 1; |
| 1551 | res->resource_type = space_id; |
| 1552 | spin_lock(&acpi_res_lock); |
Lin Ming | a5fe1a0 | 2009-08-13 10:43:27 +0800 | [diff] [blame] | 1553 | added = acpi_res_list_add(res); |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1554 | spin_unlock(&acpi_res_lock); |
Lin Ming | a5fe1a0 | 2009-08-13 10:43:27 +0800 | [diff] [blame] | 1555 | pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, " |
| 1556 | "name: %s\n", added ? "Added" : "Already exist", |
| 1557 | (space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1558 | ? "SystemIO" : "System Memory", |
| 1559 | (unsigned long long)res->start, |
| 1560 | (unsigned long long)res->end, |
| 1561 | res->name); |
Lin Ming | a5fe1a0 | 2009-08-13 10:43:27 +0800 | [diff] [blame] | 1562 | if (!added) |
| 1563 | kfree(res); |
Thomas Renninger | df92e69 | 2008-02-04 23:31:22 -0800 | [diff] [blame] | 1564 | break; |
| 1565 | case ACPI_ADR_SPACE_PCI_CONFIG: |
| 1566 | case ACPI_ADR_SPACE_EC: |
| 1567 | case ACPI_ADR_SPACE_SMBUS: |
| 1568 | case ACPI_ADR_SPACE_CMOS: |
| 1569 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: |
| 1570 | case ACPI_ADR_SPACE_DATA_TABLE: |
| 1571 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
| 1572 | break; |
| 1573 | } |
| 1574 | return AE_OK; |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1575 | } |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1576 | #endif |
Myron Stowe | d362eda | 2010-10-21 14:24:04 -0600 | [diff] [blame] | 1577 | |
| 1578 | acpi_status __init acpi_os_initialize(void) |
| 1579 | { |
| 1580 | acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block); |
| 1581 | acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block); |
| 1582 | acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block); |
| 1583 | acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block); |
| 1584 | |
| 1585 | return AE_OK; |
| 1586 | } |
| 1587 | |
Zhang Rui | 32d47ee | 2010-12-08 10:40:36 +0800 | [diff] [blame] | 1588 | acpi_status __init acpi_os_initialize1(void) |
Myron Stowe | d362eda | 2010-10-21 14:24:04 -0600 | [diff] [blame] | 1589 | { |
| 1590 | kacpid_wq = create_workqueue("kacpid"); |
| 1591 | kacpi_notify_wq = create_workqueue("kacpi_notify"); |
| 1592 | kacpi_hotplug_wq = create_workqueue("kacpi_hotplug"); |
| 1593 | BUG_ON(!kacpid_wq); |
| 1594 | BUG_ON(!kacpi_notify_wq); |
| 1595 | BUG_ON(!kacpi_hotplug_wq); |
Len Brown | 1bd64d4 | 2010-10-26 14:50:56 -0400 | [diff] [blame] | 1596 | acpi_install_interface_handler(acpi_osi_handler); |
| 1597 | acpi_osi_setup_late(); |
Myron Stowe | d362eda | 2010-10-21 14:24:04 -0600 | [diff] [blame] | 1598 | return AE_OK; |
| 1599 | } |
| 1600 | |
| 1601 | acpi_status acpi_os_terminate(void) |
| 1602 | { |
| 1603 | if (acpi_irq_handler) { |
| 1604 | acpi_os_remove_interrupt_handler(acpi_irq_irq, |
| 1605 | acpi_irq_handler); |
| 1606 | } |
| 1607 | |
| 1608 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block); |
| 1609 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block); |
| 1610 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block); |
| 1611 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block); |
| 1612 | |
| 1613 | destroy_workqueue(kacpid_wq); |
| 1614 | destroy_workqueue(kacpi_notify_wq); |
| 1615 | destroy_workqueue(kacpi_hotplug_wq); |
| 1616 | |
| 1617 | return AE_OK; |
| 1618 | } |