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