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