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