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