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