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