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