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