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