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