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