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