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