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