blob: 5b9a785e21550e9bb61ef7df6af95b1a5d54bce7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Wilcoxf1241c82008-03-14 13:43:13 -04007 * Copyright (c) 2008 Intel Corporation
8 * Author: Matthew Wilcox <willy@linux.intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
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 Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/slab.h>
33#include <linux/mm.h>
Myron Stoweba242d52012-01-20 19:13:30 -070034#include <linux/highmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/interrupt.h>
37#include <linux/kmod.h>
38#include <linux/delay.h>
39#include <linux/workqueue.h>
40#include <linux/nmi.h>
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030041#include <linux/acpi.h>
Rafael J. Wysocki2d6d9fd2011-01-19 22:27:14 +010042#include <linux/acpi_io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/efi.h>
Thomas Renningerdf92e692008-02-04 23:31:22 -080044#include <linux/ioport.h>
45#include <linux/list.h>
Matthew Wilcoxf1241c82008-03-14 13:43:13 -040046#include <linux/jiffies.h>
47#include <linux/semaphore.h>
48
49#include <asm/io.h>
50#include <asm/uaccess.h>
51
52#include <acpi/acpi.h>
53#include <acpi/acpi_bus.h>
54#include <acpi/processor.h>
Lv Zheng1129c922013-07-23 16:11:55 +080055#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define _COMPONENT ACPI_OS_SERVICES
Len Brownf52fd662007-02-12 22:42:12 -050058ACPI_MODULE_NAME("osl");
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040060struct acpi_os_dpc {
61 acpi_osd_exec_callback function;
62 void *context;
David Howells65f27f32006-11-22 14:55:48 +000063 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
66#ifdef CONFIG_ACPI_CUSTOM_DSDT
67#include CONFIG_ACPI_CUSTOM_DSDT_FILE
68#endif
69
70#ifdef ENABLE_DEBUGGER
71#include <linux/kdb.h>
72
73/* stuff for debugger support */
74int acpi_in_debugger;
75EXPORT_SYMBOL(acpi_in_debugger);
76
77extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040078#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Tang Liang09f98a82011-12-09 10:05:54 +080080static int (*__acpi_os_prepare_sleep)(u8 sleep_state, u32 pm1a_ctrl,
81 u32 pm1b_ctrl);
Ben Guthrod6b47b12013-07-30 08:24:52 -040082static int (*__acpi_os_prepare_extended_sleep)(u8 sleep_state, u32 val_a,
83 u32 val_b);
Tang Liang09f98a82011-12-09 10:05:54 +080084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static acpi_osd_handler acpi_irq_handler;
86static void *acpi_irq_context;
87static struct workqueue_struct *kacpid_wq;
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -040088static struct workqueue_struct *kacpi_notify_wq;
Yinghai Lu92d8aff2013-01-21 13:20:47 -080089static struct workqueue_struct *kacpi_hotplug_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Myron Stowe620242a2010-10-21 14:23:53 -060091/*
92 * This list of permanent mappings is for memory that may be accessed from
93 * interrupt context, where we can't do the ioremap().
94 */
95struct acpi_ioremap {
96 struct list_head list;
97 void __iomem *virt;
98 acpi_physical_address phys;
99 acpi_size size;
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100100 unsigned long refcount;
Myron Stowe620242a2010-10-21 14:23:53 -0600101};
102
103static LIST_HEAD(acpi_ioremaps);
Rafael J. Wysocki7bbb8902011-02-08 23:37:42 +0100104static DEFINE_MUTEX(acpi_ioremap_lock);
Myron Stowe620242a2010-10-21 14:23:53 -0600105
Lin Mingb0ed7a92010-08-06 09:35:51 +0800106static void __init acpi_osi_setup_late(void);
Len Brownae00d812007-05-29 18:43:33 -0400107
Len Brownd4b7dc42008-01-23 20:50:56 -0500108/*
Len Browna6e08872008-11-08 01:21:10 -0500109 * The story of _OSI(Linux)
Len Brownd4b7dc42008-01-23 20:50:56 -0500110 *
Len Browna6e08872008-11-08 01:21:10 -0500111 * From pre-history through Linux-2.6.22,
112 * Linux responded TRUE upon a BIOS OSI(Linux) query.
Len Brownd4b7dc42008-01-23 20:50:56 -0500113 *
Len Browna6e08872008-11-08 01:21:10 -0500114 * Unfortunately, reference BIOS writers got wind of this
115 * and put OSI(Linux) in their example code, quickly exposing
116 * this string as ill-conceived and opening the door to
117 * an un-bounded number of BIOS incompatibilities.
Len Brownd4b7dc42008-01-23 20:50:56 -0500118 *
Len Browna6e08872008-11-08 01:21:10 -0500119 * For example, OSI(Linux) was used on resume to re-POST a
120 * video card on one system, because Linux at that time
121 * could not do a speedy restore in its native driver.
122 * But then upon gaining quick native restore capability,
123 * Linux has no way to tell the BIOS to skip the time-consuming
124 * POST -- putting Linux at a permanent performance disadvantage.
125 * On another system, the BIOS writer used OSI(Linux)
126 * to infer native OS support for IPMI! On other systems,
127 * OSI(Linux) simply got in the way of Linux claiming to
128 * be compatible with other operating systems, exposing
129 * BIOS issues such as skipped device initialization.
Len Brownd4b7dc42008-01-23 20:50:56 -0500130 *
Len Browna6e08872008-11-08 01:21:10 -0500131 * So "Linux" turned out to be a really poor chose of
132 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
Len Brownd4b7dc42008-01-23 20:50:56 -0500133 *
134 * BIOS writers should NOT query _OSI(Linux) on future systems.
Len Browna6e08872008-11-08 01:21:10 -0500135 * Linux will complain on the console when it sees it, and return FALSE.
136 * To get Linux to return TRUE for your system will require
137 * a kernel source update to add a DMI entry,
138 * or boot with "acpi_osi=Linux"
Len Brownd4b7dc42008-01-23 20:50:56 -0500139 */
Len Brownd4b7dc42008-01-23 20:50:56 -0500140
Adrian Bunk1d15d842008-01-29 00:10:15 +0200141static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500142 unsigned int enable:1;
143 unsigned int dmi:1;
144 unsigned int cmdline:1;
Lv Zheng5dc17982013-07-22 16:08:25 +0800145 unsigned int default_disabling:1;
146} osi_linux = {0, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400147
Lin Mingb0ed7a92010-08-06 09:35:51 +0800148static u32 acpi_osi_handler(acpi_string interface, u32 supported)
149{
150 if (!strcmp("Linux", interface)) {
151
Len Brown89976212011-08-02 00:45:48 -0400152 printk_once(KERN_NOTICE FW_BUG PREFIX
Lin Mingb0ed7a92010-08-06 09:35:51 +0800153 "BIOS _OSI(Linux) query %s%s\n",
154 osi_linux.enable ? "honored" : "ignored",
155 osi_linux.cmdline ? " via cmdline" :
156 osi_linux.dmi ? " via DMI" : "");
157 }
158
159 return supported;
160}
161
Myron Stowebc9ffce2011-11-07 16:23:27 -0700162static void __init acpi_request_region (struct acpi_generic_address *gas,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700163 unsigned int length, char *desc)
164{
Myron Stowebc9ffce2011-11-07 16:23:27 -0700165 u64 addr;
166
167 /* Handle possible alignment issues */
168 memcpy(&addr, &gas->address, sizeof(addr));
169 if (!addr || !length)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700170 return;
171
Andi Kleencfa806f2010-07-20 15:18:36 -0700172 /* Resources are never freed */
Myron Stowebc9ffce2011-11-07 16:23:27 -0700173 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
174 request_region(addr, length, desc);
175 else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
176 request_mem_region(addr, length, desc);
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700177}
178
179static int __init acpi_reserve_resources(void)
180{
Len Browneee3c852007-02-03 01:38:16 -0500181 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700182 "ACPI PM1a_EVT_BLK");
183
Len Browneee3c852007-02-03 01:38:16 -0500184 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700185 "ACPI PM1b_EVT_BLK");
186
Len Browneee3c852007-02-03 01:38:16 -0500187 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700188 "ACPI PM1a_CNT_BLK");
189
Len Browneee3c852007-02-03 01:38:16 -0500190 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700191 "ACPI PM1b_CNT_BLK");
192
Len Browneee3c852007-02-03 01:38:16 -0500193 if (acpi_gbl_FADT.pm_timer_length == 4)
194 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700195
Len Browneee3c852007-02-03 01:38:16 -0500196 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700197 "ACPI PM2_CNT_BLK");
198
199 /* Length of GPE blocks must be a non-negative multiple of 2 */
200
Len Browneee3c852007-02-03 01:38:16 -0500201 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
202 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
203 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700204
Len Browneee3c852007-02-03 01:38:16 -0500205 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
206 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
207 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700208
209 return 0;
210}
211device_initcall(acpi_reserve_resources);
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 va_list args;
216 va_start(args, fmt);
217 acpi_os_vprintf(fmt, args);
218 va_end(args);
219}
Len Brown4be44fc2005-08-05 00:44:28 -0400220
Len Brown4be44fc2005-08-05 00:44:28 -0400221void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 vsprintf(buffer, fmt, args);
226
227#ifdef ENABLE_DEBUGGER
228 if (acpi_in_debugger) {
229 kdb_printf("%s", buffer);
230 } else {
Frank Seidel4d939152009-02-04 17:03:07 +0100231 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233#else
Frank Seidel4d939152009-02-04 17:03:07 +0100234 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#endif
236}
237
Takao Indoh4996c022011-07-14 18:05:21 -0400238#ifdef CONFIG_KEXEC
239static unsigned long acpi_rsdp;
240static int __init setup_acpi_rsdp(char *arg)
241{
242 acpi_rsdp = simple_strtoul(arg, NULL, 16);
243 return 0;
244}
245early_param("acpi_rsdp", setup_acpi_rsdp);
246#endif
247
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300248acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Takao Indoh4996c022011-07-14 18:05:21 -0400250#ifdef CONFIG_KEXEC
251 if (acpi_rsdp)
252 return acpi_rsdp;
253#endif
254
Matt Fleming83e68182012-11-14 09:42:35 +0000255 if (efi_enabled(EFI_CONFIG_TABLES)) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800256 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300257 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800258 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300259 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400261 printk(KERN_ERR PREFIX
262 "System description tables not found\n");
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300263 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
Len Brown239665a2007-11-23 20:08:02 -0500265 } else {
266 acpi_physical_address pa = 0;
267
268 acpi_find_root_pointer(&pa);
269 return pa;
270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
Myron Stowe78cdb3e2010-10-21 14:24:09 -0600273/* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
Myron Stowe4a3cba52010-10-21 14:24:14 -0600274static struct acpi_ioremap *
275acpi_map_lookup(acpi_physical_address phys, acpi_size size)
Myron Stowe620242a2010-10-21 14:23:53 -0600276{
277 struct acpi_ioremap *map;
278
Myron Stowe78cdb3e2010-10-21 14:24:09 -0600279 list_for_each_entry_rcu(map, &acpi_ioremaps, list)
Myron Stowe620242a2010-10-21 14:23:53 -0600280 if (map->phys <= phys &&
281 phys + size <= map->phys + map->size)
Myron Stowe4a3cba52010-10-21 14:24:14 -0600282 return map;
283
284 return NULL;
285}
286
287/* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
288static void __iomem *
289acpi_map_vaddr_lookup(acpi_physical_address phys, unsigned int size)
290{
291 struct acpi_ioremap *map;
292
293 map = acpi_map_lookup(phys, size);
294 if (map)
295 return map->virt + (phys - map->phys);
Myron Stowe620242a2010-10-21 14:23:53 -0600296
297 return NULL;
298}
299
Rafael J. Wysocki13606a22011-02-08 23:38:25 +0100300void __iomem *acpi_os_get_iomem(acpi_physical_address phys, unsigned int size)
301{
302 struct acpi_ioremap *map;
303 void __iomem *virt = NULL;
304
305 mutex_lock(&acpi_ioremap_lock);
306 map = acpi_map_lookup(phys, size);
307 if (map) {
308 virt = map->virt + (phys - map->phys);
309 map->refcount++;
310 }
311 mutex_unlock(&acpi_ioremap_lock);
312 return virt;
313}
314EXPORT_SYMBOL_GPL(acpi_os_get_iomem);
315
Myron Stowe78cdb3e2010-10-21 14:24:09 -0600316/* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
Myron Stowe620242a2010-10-21 14:23:53 -0600317static struct acpi_ioremap *
318acpi_map_lookup_virt(void __iomem *virt, acpi_size size)
319{
320 struct acpi_ioremap *map;
321
Myron Stowe78cdb3e2010-10-21 14:24:09 -0600322 list_for_each_entry_rcu(map, &acpi_ioremaps, list)
Myron Stowe4a3cba52010-10-21 14:24:14 -0600323 if (map->virt <= virt &&
324 virt + size <= map->virt + map->size)
Myron Stowe620242a2010-10-21 14:23:53 -0600325 return map;
326
327 return NULL;
328}
329
Myron Stoweba242d52012-01-20 19:13:30 -0700330#ifndef CONFIG_IA64
331#define should_use_kmap(pfn) page_is_ram(pfn)
332#else
333/* ioremap will take care of cache attributes */
334#define should_use_kmap(pfn) 0
335#endif
336
337static void __iomem *acpi_map(acpi_physical_address pg_off, unsigned long pg_sz)
338{
339 unsigned long pfn;
340
341 pfn = pg_off >> PAGE_SHIFT;
342 if (should_use_kmap(pfn)) {
343 if (pg_sz > PAGE_SIZE)
344 return NULL;
345 return (void __iomem __force *)kmap(pfn_to_page(pfn));
346 } else
347 return acpi_os_ioremap(pg_off, pg_sz);
348}
349
350static void acpi_unmap(acpi_physical_address pg_off, void __iomem *vaddr)
351{
352 unsigned long pfn;
353
354 pfn = pg_off >> PAGE_SHIFT;
Jan Beuliche2526752012-02-24 11:41:53 +0000355 if (should_use_kmap(pfn))
Myron Stoweba242d52012-01-20 19:13:30 -0700356 kunmap(pfn_to_page(pfn));
357 else
358 iounmap(vaddr);
359}
360
Jan Beulich2fdf0742007-12-13 08:33:59 +0000361void __iomem *__init_refok
362acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Rafael J. Wysocki7ffd0442011-02-08 23:38:05 +0100364 struct acpi_ioremap *map;
Myron Stowe620242a2010-10-21 14:23:53 -0600365 void __iomem *virt;
Rafael J. Wysocki2d6d9fd2011-01-19 22:27:14 +0100366 acpi_physical_address pg_off;
367 acpi_size pg_sz;
Myron Stowe620242a2010-10-21 14:23:53 -0600368
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800369 if (phys > ULONG_MAX) {
370 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800371 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
Myron Stowe620242a2010-10-21 14:23:53 -0600373
374 if (!acpi_gbl_permanent_mmap)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300375 return __acpi_map_table((unsigned long)phys, size);
Myron Stowe620242a2010-10-21 14:23:53 -0600376
Rafael J. Wysocki7ffd0442011-02-08 23:38:05 +0100377 mutex_lock(&acpi_ioremap_lock);
378 /* Check if there's a suitable mapping already. */
379 map = acpi_map_lookup(phys, size);
380 if (map) {
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100381 map->refcount++;
Rafael J. Wysocki7ffd0442011-02-08 23:38:05 +0100382 goto out;
383 }
384
Myron Stowe620242a2010-10-21 14:23:53 -0600385 map = kzalloc(sizeof(*map), GFP_KERNEL);
Rafael J. Wysocki7ffd0442011-02-08 23:38:05 +0100386 if (!map) {
387 mutex_unlock(&acpi_ioremap_lock);
Myron Stowe620242a2010-10-21 14:23:53 -0600388 return NULL;
Rafael J. Wysocki7ffd0442011-02-08 23:38:05 +0100389 }
Myron Stowe620242a2010-10-21 14:23:53 -0600390
Myron Stowe4a3cba52010-10-21 14:24:14 -0600391 pg_off = round_down(phys, PAGE_SIZE);
392 pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off;
Myron Stoweba242d52012-01-20 19:13:30 -0700393 virt = acpi_map(pg_off, pg_sz);
Myron Stowe620242a2010-10-21 14:23:53 -0600394 if (!virt) {
Rafael J. Wysocki7ffd0442011-02-08 23:38:05 +0100395 mutex_unlock(&acpi_ioremap_lock);
Myron Stowe620242a2010-10-21 14:23:53 -0600396 kfree(map);
397 return NULL;
398 }
399
400 INIT_LIST_HEAD(&map->list);
401 map->virt = virt;
Myron Stowe4a3cba52010-10-21 14:24:14 -0600402 map->phys = pg_off;
403 map->size = pg_sz;
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100404 map->refcount = 1;
Myron Stowe620242a2010-10-21 14:23:53 -0600405
Myron Stowe78cdb3e2010-10-21 14:24:09 -0600406 list_add_tail_rcu(&map->list, &acpi_ioremaps);
Myron Stowe620242a2010-10-21 14:23:53 -0600407
Rafael J. Wysocki7ffd0442011-02-08 23:38:05 +0100408 out:
409 mutex_unlock(&acpi_ioremap_lock);
Myron Stowe4a3cba52010-10-21 14:24:14 -0600410 return map->virt + (phys - map->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800412EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100414static void acpi_os_drop_map_ref(struct acpi_ioremap *map)
Myron Stowe4a3cba52010-10-21 14:24:14 -0600415{
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100416 if (!--map->refcount)
417 list_del_rcu(&map->list);
Myron Stowe4a3cba52010-10-21 14:24:14 -0600418}
Myron Stowe4a3cba52010-10-21 14:24:14 -0600419
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100420static void acpi_os_map_cleanup(struct acpi_ioremap *map)
Rafael J. Wysocki7fe135d2011-02-08 23:37:53 +0100421{
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100422 if (!map->refcount) {
423 synchronize_rcu();
Myron Stoweba242d52012-01-20 19:13:30 -0700424 acpi_unmap(map->phys, map->virt);
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100425 kfree(map);
426 }
Myron Stowe4a3cba52010-10-21 14:24:14 -0600427}
428
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800429void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Myron Stowe620242a2010-10-21 14:23:53 -0600431 struct acpi_ioremap *map;
Myron Stowe620242a2010-10-21 14:23:53 -0600432
433 if (!acpi_gbl_permanent_mmap) {
Yinghai Lu7d972772009-02-07 15:39:41 -0800434 __acpi_unmap_table(virt, size);
Myron Stowe620242a2010-10-21 14:23:53 -0600435 return;
436 }
437
Rafael J. Wysocki7bbb8902011-02-08 23:37:42 +0100438 mutex_lock(&acpi_ioremap_lock);
Myron Stowe620242a2010-10-21 14:23:53 -0600439 map = acpi_map_lookup_virt(virt, size);
440 if (!map) {
Rafael J. Wysocki7bbb8902011-02-08 23:37:42 +0100441 mutex_unlock(&acpi_ioremap_lock);
Rafael J. Wysocki7fe135d2011-02-08 23:37:53 +0100442 WARN(true, PREFIX "%s: bad address %p\n", __func__, virt);
Myron Stowe620242a2010-10-21 14:23:53 -0600443 return;
444 }
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100445 acpi_os_drop_map_ref(map);
Rafael J. Wysocki7bbb8902011-02-08 23:37:42 +0100446 mutex_unlock(&acpi_ioremap_lock);
Myron Stowe620242a2010-10-21 14:23:53 -0600447
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100448 acpi_os_map_cleanup(map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800450EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800452void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800453{
454 if (!acpi_gbl_permanent_mmap)
455 __acpi_unmap_table(virt, size);
456}
457
Myron Stowe6f68c912011-11-07 16:23:34 -0700458int acpi_os_map_generic_address(struct acpi_generic_address *gas)
Myron Stowe29718522010-10-21 14:23:59 -0600459{
Myron Stowebc9ffce2011-11-07 16:23:27 -0700460 u64 addr;
Myron Stowe29718522010-10-21 14:23:59 -0600461 void __iomem *virt;
462
Myron Stowebc9ffce2011-11-07 16:23:27 -0700463 if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
Myron Stowe29718522010-10-21 14:23:59 -0600464 return 0;
465
Myron Stowebc9ffce2011-11-07 16:23:27 -0700466 /* Handle possible alignment issues */
467 memcpy(&addr, &gas->address, sizeof(addr));
468 if (!addr || !gas->bit_width)
Myron Stowe29718522010-10-21 14:23:59 -0600469 return -EINVAL;
470
Myron Stowebc9ffce2011-11-07 16:23:27 -0700471 virt = acpi_os_map_memory(addr, gas->bit_width / 8);
Myron Stowe29718522010-10-21 14:23:59 -0600472 if (!virt)
473 return -EIO;
474
475 return 0;
476}
Myron Stowe6f68c912011-11-07 16:23:34 -0700477EXPORT_SYMBOL(acpi_os_map_generic_address);
Myron Stowe29718522010-10-21 14:23:59 -0600478
Myron Stowe6f68c912011-11-07 16:23:34 -0700479void acpi_os_unmap_generic_address(struct acpi_generic_address *gas)
Myron Stowe29718522010-10-21 14:23:59 -0600480{
Myron Stowebc9ffce2011-11-07 16:23:27 -0700481 u64 addr;
Rafael J. Wysocki7fe135d2011-02-08 23:37:53 +0100482 struct acpi_ioremap *map;
Myron Stowe29718522010-10-21 14:23:59 -0600483
Myron Stowebc9ffce2011-11-07 16:23:27 -0700484 if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
Myron Stowe29718522010-10-21 14:23:59 -0600485 return;
486
Myron Stowebc9ffce2011-11-07 16:23:27 -0700487 /* Handle possible alignment issues */
488 memcpy(&addr, &gas->address, sizeof(addr));
489 if (!addr || !gas->bit_width)
Myron Stowe29718522010-10-21 14:23:59 -0600490 return;
491
Rafael J. Wysocki7bbb8902011-02-08 23:37:42 +0100492 mutex_lock(&acpi_ioremap_lock);
Myron Stowebc9ffce2011-11-07 16:23:27 -0700493 map = acpi_map_lookup(addr, gas->bit_width / 8);
Rafael J. Wysocki7fe135d2011-02-08 23:37:53 +0100494 if (!map) {
495 mutex_unlock(&acpi_ioremap_lock);
496 return;
497 }
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100498 acpi_os_drop_map_ref(map);
Rafael J. Wysocki7bbb8902011-02-08 23:37:42 +0100499 mutex_unlock(&acpi_ioremap_lock);
Myron Stowe29718522010-10-21 14:23:59 -0600500
Rafael J. Wysockib7c1fad2011-02-08 23:38:15 +0100501 acpi_os_map_cleanup(map);
Myron Stowe29718522010-10-21 14:23:59 -0600502}
Myron Stowe6f68c912011-11-07 16:23:34 -0700503EXPORT_SYMBOL(acpi_os_unmap_generic_address);
Myron Stowe29718522010-10-21 14:23:59 -0600504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#ifdef ACPI_FUTURE_USAGE
506acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400507acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Len Brown4be44fc2005-08-05 00:44:28 -0400509 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 return AE_BAD_PARAMETER;
511
512 *phys = virt_to_phys(virt);
513
514 return AE_OK;
515}
516#endif
517
518#define ACPI_MAX_OVERRIDE_LEN 100
519
520static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
521
522acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400523acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
524 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
526 if (!init_val || !new_val)
527 return AE_BAD_PARAMETER;
528
529 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400530 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400532 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 *new_val = acpi_os_name;
534 }
535
536 return AE_OK;
537}
538
Thomas Renninger53aac442012-10-01 00:23:54 +0200539#ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
540#include <linux/earlycpio.h>
541#include <linux/memblock.h>
542
543static u64 acpi_tables_addr;
544static int all_tables_size;
545
546/* Copied from acpica/tbutils.c:acpi_tb_checksum() */
547u8 __init acpi_table_checksum(u8 *buffer, u32 length)
548{
549 u8 sum = 0;
550 u8 *end = buffer + length;
551
552 while (buffer < end)
553 sum = (u8) (sum + *(buffer++));
554 return sum;
555}
556
557/* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
558static const char * const table_sigs[] = {
559 ACPI_SIG_BERT, ACPI_SIG_CPEP, ACPI_SIG_ECDT, ACPI_SIG_EINJ,
560 ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT, ACPI_SIG_MSCT,
561 ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT, ACPI_SIG_ASF,
562 ACPI_SIG_BOOT, ACPI_SIG_DBGP, ACPI_SIG_DMAR, ACPI_SIG_HPET,
563 ACPI_SIG_IBFT, ACPI_SIG_IVRS, ACPI_SIG_MCFG, ACPI_SIG_MCHI,
564 ACPI_SIG_SLIC, ACPI_SIG_SPCR, ACPI_SIG_SPMI, ACPI_SIG_TCPA,
565 ACPI_SIG_UEFI, ACPI_SIG_WAET, ACPI_SIG_WDAT, ACPI_SIG_WDDT,
566 ACPI_SIG_WDRT, ACPI_SIG_DSDT, ACPI_SIG_FADT, ACPI_SIG_PSDT,
567 ACPI_SIG_RSDT, ACPI_SIG_XSDT, ACPI_SIG_SSDT, NULL };
568
Thomas Renninger53aac442012-10-01 00:23:54 +0200569#define ACPI_HEADER_SIZE sizeof(struct acpi_table_header)
570
Yinghai Lubee7f9c2013-09-06 19:08:00 -0700571#define ACPI_OVERRIDE_TABLES 64
572static struct cpio_data __initdata acpi_initrd_files[ACPI_OVERRIDE_TABLES];
573
574#define MAP_CHUNK_SIZE (NR_FIX_BTMAPS << PAGE_SHIFT)
Thomas Renninger53aac442012-10-01 00:23:54 +0200575
576void __init acpi_initrd_override(void *data, size_t size)
577{
578 int sig, no, table_nr = 0, total_offset = 0;
579 long offset = 0;
580 struct acpi_table_header *table;
581 char cpio_path[32] = "kernel/firmware/acpi/";
582 struct cpio_data file;
Thomas Renninger53aac442012-10-01 00:23:54 +0200583
584 if (data == NULL || size == 0)
585 return;
586
587 for (no = 0; no < ACPI_OVERRIDE_TABLES; no++) {
588 file = find_cpio_data(cpio_path, data, size, &offset);
589 if (!file.data)
590 break;
591
592 data += offset;
593 size -= offset;
594
Tang Chen7702ae02013-08-14 17:37:08 +0800595 if (file.size < sizeof(struct acpi_table_header)) {
596 pr_err("ACPI OVERRIDE: Table smaller than ACPI header [%s%s]\n",
597 cpio_path, file.name);
598 continue;
599 }
Thomas Renninger53aac442012-10-01 00:23:54 +0200600
601 table = file.data;
602
603 for (sig = 0; table_sigs[sig]; sig++)
604 if (!memcmp(table->signature, table_sigs[sig], 4))
605 break;
606
Tang Chen7702ae02013-08-14 17:37:08 +0800607 if (!table_sigs[sig]) {
608 pr_err("ACPI OVERRIDE: Unknown signature [%s%s]\n",
609 cpio_path, file.name);
610 continue;
611 }
612 if (file.size != table->length) {
613 pr_err("ACPI OVERRIDE: File length does not match table length [%s%s]\n",
614 cpio_path, file.name);
615 continue;
616 }
617 if (acpi_table_checksum(file.data, table->length)) {
618 pr_err("ACPI OVERRIDE: Bad table checksum [%s%s]\n",
619 cpio_path, file.name);
620 continue;
621 }
Thomas Renninger53aac442012-10-01 00:23:54 +0200622
623 pr_info("%4.4s ACPI table found in initrd [%s%s][0x%x]\n",
624 table->signature, cpio_path, file.name, table->length);
625
626 all_tables_size += table->length;
Yinghai Lubee7f9c2013-09-06 19:08:00 -0700627 acpi_initrd_files[table_nr].data = file.data;
628 acpi_initrd_files[table_nr].size = file.size;
Thomas Renninger53aac442012-10-01 00:23:54 +0200629 table_nr++;
630 }
631 if (table_nr == 0)
632 return;
633
634 acpi_tables_addr =
635 memblock_find_in_range(0, max_low_pfn_mapped << PAGE_SHIFT,
636 all_tables_size, PAGE_SIZE);
637 if (!acpi_tables_addr) {
638 WARN_ON(1);
639 return;
640 }
641 /*
642 * Only calling e820_add_reserve does not work and the
643 * tables are invalid (memory got used) later.
644 * memblock_reserve works as expected and the tables won't get modified.
645 * But it's not enough on X86 because ioremap will
646 * complain later (used by acpi_os_map_memory) that the pages
647 * that should get mapped are not marked "reserved".
648 * Both memblock_reserve and e820_add_region (via arch_reserve_mem_area)
649 * works fine.
650 */
Wang YanQinga6432de2013-04-23 01:19:19 +0200651 memblock_reserve(acpi_tables_addr, all_tables_size);
Thomas Renninger53aac442012-10-01 00:23:54 +0200652 arch_reserve_mem_area(acpi_tables_addr, all_tables_size);
653
Yinghai Lubee7f9c2013-09-06 19:08:00 -0700654 /*
655 * early_ioremap only can remap 256k one time. If we map all
656 * tables one time, we will hit the limit. Need to map chunks
657 * one by one during copying the same as that in relocate_initrd().
658 */
Thomas Renninger53aac442012-10-01 00:23:54 +0200659 for (no = 0; no < table_nr; no++) {
Yinghai Lubee7f9c2013-09-06 19:08:00 -0700660 unsigned char *src_p = acpi_initrd_files[no].data;
661 phys_addr_t size = acpi_initrd_files[no].size;
662 phys_addr_t dest_addr = acpi_tables_addr + total_offset;
663 phys_addr_t slop, clen;
664 char *dest_p;
665
666 total_offset += size;
667
668 while (size) {
669 slop = dest_addr & ~PAGE_MASK;
670 clen = size;
671 if (clen > MAP_CHUNK_SIZE - slop)
672 clen = MAP_CHUNK_SIZE - slop;
673 dest_p = early_ioremap(dest_addr & PAGE_MASK,
674 clen + slop);
675 memcpy(dest_p + slop, src_p, clen);
676 early_iounmap(dest_p, clen + slop);
677 src_p += clen;
678 dest_addr += clen;
679 size -= clen;
680 }
Thomas Renninger53aac442012-10-01 00:23:54 +0200681 }
Thomas Renninger53aac442012-10-01 00:23:54 +0200682}
683#endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */
684
Thomas Renninger325a8d362012-10-01 00:23:56 +0200685static void acpi_table_taint(struct acpi_table_header *table)
686{
687 pr_warn(PREFIX
688 "Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n",
689 table->signature, table->oem_table_id);
Rusty Russell373d4d02013-01-21 17:17:39 +1030690 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
Thomas Renninger325a8d362012-10-01 00:23:56 +0200691}
692
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400695acpi_os_table_override(struct acpi_table_header * existing_table,
696 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
698 if (!existing_table || !new_table)
699 return AE_BAD_PARAMETER;
700
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100701 *new_table = NULL;
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703#ifdef CONFIG_ACPI_CUSTOM_DSDT
704 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400705 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#endif
Thomas Renninger325a8d362012-10-01 00:23:56 +0200707 if (*new_table != NULL)
708 acpi_table_taint(existing_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 return AE_OK;
710}
711
Bob Mooref7b004a2012-02-14 18:31:56 +0800712acpi_status
713acpi_os_physical_table_override(struct acpi_table_header *existing_table,
Thomas Renningerb2a35002012-10-01 00:23:55 +0200714 acpi_physical_address *address,
715 u32 *table_length)
Bob Mooref7b004a2012-02-14 18:31:56 +0800716{
Thomas Renningerb2a35002012-10-01 00:23:55 +0200717#ifndef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
718 *table_length = 0;
719 *address = 0;
720 return AE_OK;
721#else
722 int table_offset = 0;
723 struct acpi_table_header *table;
Bob Mooref7b004a2012-02-14 18:31:56 +0800724
Thomas Renningerb2a35002012-10-01 00:23:55 +0200725 *table_length = 0;
726 *address = 0;
727
728 if (!acpi_tables_addr)
729 return AE_OK;
730
731 do {
732 if (table_offset + ACPI_HEADER_SIZE > all_tables_size) {
733 WARN_ON(1);
734 return AE_OK;
735 }
736
737 table = acpi_os_map_memory(acpi_tables_addr + table_offset,
738 ACPI_HEADER_SIZE);
739
740 if (table_offset + table->length > all_tables_size) {
741 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
742 WARN_ON(1);
743 return AE_OK;
744 }
745
746 table_offset += table->length;
747
748 if (memcmp(existing_table->signature, table->signature, 4)) {
749 acpi_os_unmap_memory(table,
750 ACPI_HEADER_SIZE);
751 continue;
752 }
753
754 /* Only override tables with matching oem id */
755 if (memcmp(table->oem_table_id, existing_table->oem_table_id,
756 ACPI_OEM_TABLE_ID_SIZE)) {
757 acpi_os_unmap_memory(table,
758 ACPI_HEADER_SIZE);
759 continue;
760 }
761
762 table_offset -= table->length;
763 *table_length = table->length;
764 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
765 *address = acpi_tables_addr + table_offset;
766 break;
767 } while (table_offset + ACPI_HEADER_SIZE < all_tables_size);
768
Thomas Renninger325a8d362012-10-01 00:23:56 +0200769 if (*address != 0)
770 acpi_table_taint(existing_table);
Thomas Renningerb2a35002012-10-01 00:23:55 +0200771 return AE_OK;
772#endif
773}
Bob Mooref7b004a2012-02-14 18:31:56 +0800774
David Howells7d12e782006-10-05 14:55:46 +0100775static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
Len Brown5229e872008-02-06 01:26:55 -0500777 u32 handled;
778
779 handled = (*acpi_irq_handler) (acpi_irq_context);
780
781 if (handled) {
782 acpi_irq_handled++;
783 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400784 } else {
785 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500786 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788}
789
790acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400791acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
792 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
794 unsigned int irq;
795
Len Brown5229e872008-02-06 01:26:55 -0500796 acpi_irq_stats_init();
797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /*
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100799 * ACPI interrupts different from the SCI in our copy of the FADT are
800 * not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 */
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100802 if (gsi != acpi_gbl_FADT.sci_interrupt)
803 return AE_BAD_PARAMETER;
804
805 if (acpi_irq_handler)
806 return AE_ALREADY_ACQUIRED;
807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
809 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
810 gsi);
811 return AE_OK;
812 }
813
814 acpi_irq_handler = handler;
815 acpi_irq_context = context;
Zhang Rui89a22da2013-02-04 07:10:10 +0000816 if (request_irq(irq, acpi_irq, IRQF_SHARED | IRQF_NO_SUSPEND, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100818 acpi_irq_handler = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 return AE_NOT_ACQUIRED;
820 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 return AE_OK;
823}
824
Len Brown4be44fc2005-08-05 00:44:28 -0400825acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100827 if (irq != acpi_gbl_FADT.sci_interrupt)
828 return AE_BAD_PARAMETER;
829
830 free_irq(irq, acpi_irq);
831 acpi_irq_handler = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 return AE_OK;
834}
835
836/*
837 * Running in interpreter thread context, safe to sleep
838 */
839
Lin Ming439913f2010-01-28 10:53:19 +0800840void acpi_os_sleep(u64 ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Liu Chuansheng30282292013-09-12 01:42:57 +0800842 msleep(ms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
Len Brown4be44fc2005-08-05 00:44:28 -0400844
Len Brown4be44fc2005-08-05 00:44:28 -0400845void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
847 while (us) {
848 u32 delay = 1000;
849
850 if (delay > us)
851 delay = us;
852 udelay(delay);
853 touch_nmi_watchdog();
854 us -= delay;
855 }
856}
Len Brown4be44fc2005-08-05 00:44:28 -0400857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858/*
859 * Support ACPI 3.0 AML Timer operand
860 * Returns 64-bit free-running, monotonically increasing timer
861 * with 100ns granularity
862 */
Len Brown4be44fc2005-08-05 00:44:28 -0400863u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Mika Westerberg10619062013-05-23 10:27:46 +0300865 u64 time_ns = ktime_to_ns(ktime_get());
866 do_div(time_ns, 100);
867 return time_ns;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
Len Brown4be44fc2005-08-05 00:44:28 -0400870acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871{
872 u32 dummy;
873
874 if (!value)
875 value = &dummy;
876
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800877 *value = 0;
878 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400879 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800880 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400881 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800882 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400883 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800884 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 BUG();
886 }
887
888 return AE_OK;
889}
Len Brown4be44fc2005-08-05 00:44:28 -0400890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891EXPORT_SYMBOL(acpi_os_read_port);
892
Len Brown4be44fc2005-08-05 00:44:28 -0400893acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800895 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800897 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800899 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800901 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 BUG();
903 }
904
905 return AE_OK;
906}
Len Brown4be44fc2005-08-05 00:44:28 -0400907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908EXPORT_SYMBOL(acpi_os_write_port);
909
Myron Stowee615bf52012-01-20 19:13:24 -0700910#ifdef readq
911static inline u64 read64(const volatile void __iomem *addr)
912{
913 return readq(addr);
914}
915#else
916static inline u64 read64(const volatile void __iomem *addr)
917{
918 u64 l, h;
919 l = readl(addr);
920 h = readl(addr+4);
921 return l | (h << 32);
922}
923#endif
924
925acpi_status
Bob Moore653f4b52012-02-14 18:29:55 +0800926acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
Myron Stowee615bf52012-01-20 19:13:24 -0700927{
928 void __iomem *virt_addr;
929 unsigned int size = width / 8;
930 bool unmap = false;
931 u64 dummy;
932
933 rcu_read_lock();
934 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
935 if (!virt_addr) {
936 rcu_read_unlock();
937 virt_addr = acpi_os_ioremap(phys_addr, size);
938 if (!virt_addr)
939 return AE_BAD_ADDRESS;
940 unmap = true;
941 }
942
943 if (!value)
944 value = &dummy;
945
946 switch (width) {
947 case 8:
948 *(u8 *) value = readb(virt_addr);
949 break;
950 case 16:
951 *(u16 *) value = readw(virt_addr);
952 break;
953 case 32:
954 *(u32 *) value = readl(virt_addr);
955 break;
956 case 64:
957 *(u64 *) value = read64(virt_addr);
958 break;
959 default:
960 BUG();
961 }
962
963 if (unmap)
964 iounmap(virt_addr);
965 else
966 rcu_read_unlock();
967
968 return AE_OK;
969}
970
Myron Stowee615bf52012-01-20 19:13:24 -0700971#ifdef writeq
972static inline void write64(u64 val, volatile void __iomem *addr)
973{
974 writeq(val, addr);
975}
976#else
977static inline void write64(u64 val, volatile void __iomem *addr)
978{
979 writel(val, addr);
980 writel(val>>32, addr+4);
981}
982#endif
983
984acpi_status
Bob Moore653f4b52012-02-14 18:29:55 +0800985acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
Myron Stowee615bf52012-01-20 19:13:24 -0700986{
987 void __iomem *virt_addr;
988 unsigned int size = width / 8;
989 bool unmap = false;
990
991 rcu_read_lock();
992 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
993 if (!virt_addr) {
994 rcu_read_unlock();
995 virt_addr = acpi_os_ioremap(phys_addr, size);
996 if (!virt_addr)
997 return AE_BAD_ADDRESS;
998 unmap = true;
999 }
1000
1001 switch (width) {
1002 case 8:
1003 writeb(value, virt_addr);
1004 break;
1005 case 16:
1006 writew(value, virt_addr);
1007 break;
1008 case 32:
1009 writel(value, virt_addr);
1010 break;
1011 case 64:
1012 write64(value, virt_addr);
1013 break;
1014 default:
1015 BUG();
1016 }
1017
1018 if (unmap)
1019 iounmap(virt_addr);
1020 else
1021 rcu_read_unlock();
1022
1023 return AE_OK;
1024}
1025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001027acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Bob Moorec5f02312010-08-06 08:57:53 +08001028 u64 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029{
1030 int result, size;
Bob Moorec5f02312010-08-06 08:57:53 +08001031 u32 value32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033 if (!value)
1034 return AE_BAD_PARAMETER;
1035
1036 switch (width) {
1037 case 8:
1038 size = 1;
1039 break;
1040 case 16:
1041 size = 2;
1042 break;
1043 case 32:
1044 size = 4;
1045 break;
1046 default:
1047 return AE_ERROR;
1048 }
1049
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -05001050 result = raw_pci_read(pci_id->segment, pci_id->bus,
1051 PCI_DEVFN(pci_id->device, pci_id->function),
Bob Moorec5f02312010-08-06 08:57:53 +08001052 reg, size, &value32);
1053 *value = value32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 return (result ? AE_ERROR : AE_OK);
1056}
Len Brown4be44fc2005-08-05 00:44:28 -04001057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001059acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Lin Ming439913f2010-01-28 10:53:19 +08001060 u64 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 int result, size;
1063
1064 switch (width) {
1065 case 8:
1066 size = 1;
1067 break;
1068 case 16:
1069 size = 2;
1070 break;
1071 case 32:
1072 size = 4;
1073 break;
1074 default:
1075 return AE_ERROR;
1076 }
1077
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -05001078 result = raw_pci_write(pci_id->segment, pci_id->bus,
1079 PCI_DEVFN(pci_id->device, pci_id->function),
1080 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 return (result ? AE_ERROR : AE_OK);
1083}
1084
David Howells65f27f32006-11-22 14:55:48 +00001085static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
David Howells65f27f32006-11-22 14:55:48 +00001087 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -04001088
Zhang Rui19cd8472008-08-28 10:05:06 +08001089 dpc->function(dpc->context);
1090 kfree(dpc);
Zhang Rui19cd8472008-08-28 10:05:06 +08001091}
1092
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -04001093/*******************************************************************************
1094 *
1095 * FUNCTION: acpi_os_execute
1096 *
1097 * PARAMETERS: Type - Type of the callback
1098 * Function - Function to be executed
1099 * Context - Function parameters
1100 *
1101 * RETURN: Status
1102 *
1103 * DESCRIPTION: Depending on type, either queues function for deferred execution or
1104 * immediately executes function on a separate thread.
1105 *
1106 ******************************************************************************/
1107
Rafael J. Wysocki7b981182013-11-07 01:45:40 +01001108acpi_status acpi_os_execute(acpi_execute_type type,
1109 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Len Brown4be44fc2005-08-05 00:44:28 -04001111 acpi_status status = AE_OK;
1112 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +03001113 struct workqueue_struct *queue;
Zhang Rui19cd8472008-08-28 10:05:06 +08001114 int ret;
Len Brown72945b22006-07-12 22:46:42 -04001115 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
1116 "Scheduling function [%p(%p)] for deferred execution.\n",
1117 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 /*
1120 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +00001121 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 * way that allows us to also free its memory inside the callee.
1123 * Because we may want to schedule several tasks with different
1124 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +00001125 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 */
Len Brown72945b22006-07-12 22:46:42 -04001127
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001128 dpc = kzalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +08001130 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -08001131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 dpc->function = function;
1133 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -08001134
Zhang Ruic02256b2009-06-23 10:20:29 +08001135 /*
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001136 * To prevent lockdep from complaining unnecessarily, make sure that
1137 * there is a different static lockdep key for each workqueue by using
1138 * INIT_WORK() for each of them separately.
Zhang Ruic02256b2009-06-23 10:20:29 +08001139 */
Rafael J. Wysocki7b981182013-11-07 01:45:40 +01001140 if (type == OSL_NOTIFY_HANDLER) {
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001141 queue = kacpi_notify_wq;
Zhang Ruibc736752010-03-22 15:48:54 +08001142 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001143 } else {
1144 queue = kacpid_wq;
Zhang Ruibc736752010-03-22 15:48:54 +08001145 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001146 }
Zhang Ruibc736752010-03-22 15:48:54 +08001147
Tejun Heo8fec62b2010-06-29 10:07:09 +02001148 /*
1149 * On some machines, a software-initiated SMI causes corruption unless
1150 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
1151 * typically it's done in GPE-related methods that are run via
1152 * workqueues, so we can avoid the known corruption cases by always
1153 * queueing on CPU 0.
1154 */
1155 ret = queue_work_on(0, queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +08001156
1157 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001158 printk(KERN_ERR PREFIX
1159 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +03001160 status = AE_ERROR;
1161 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 }
Lin Ming889c78b2008-12-31 09:23:57 +08001163 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -04001165EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Lin Mingbd6f10a2012-05-22 16:43:49 +08001167void acpi_os_wait_events_complete(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
1169 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -04001170 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
Len Brown4be44fc2005-08-05 00:44:28 -04001172
Rafael J. Wysocki7b981182013-11-07 01:45:40 +01001173struct acpi_hp_work {
1174 struct work_struct work;
1175 acpi_hp_callback func;
1176 void *data;
1177 u32 src;
1178};
1179
1180static void acpi_hotplug_work_fn(struct work_struct *work)
1181{
1182 struct acpi_hp_work *hpw = container_of(work, struct acpi_hp_work, work);
1183
1184 acpi_os_wait_events_complete();
1185 hpw->func(hpw->data, hpw->src);
1186 kfree(hpw);
1187}
1188
1189acpi_status acpi_hotplug_execute(acpi_hp_callback func, void *data, u32 src)
1190{
1191 struct acpi_hp_work *hpw;
1192
1193 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
1194 "Scheduling function [%p(%p, %u)] for deferred execution.\n",
1195 func, data, src));
1196
1197 hpw = kmalloc(sizeof(*hpw), GFP_KERNEL);
1198 if (!hpw)
1199 return AE_NO_MEMORY;
1200
1201 INIT_WORK(&hpw->work, acpi_hotplug_work_fn);
1202 hpw->func = func;
1203 hpw->data = data;
1204 hpw->src = src;
1205 /*
1206 * We can't run hotplug code in kacpid_wq/kacpid_notify_wq etc., because
1207 * the hotplug code may call driver .remove() functions, which may
1208 * invoke flush_scheduled_work()/acpi_os_wait_events_complete() to flush
1209 * these workqueues.
1210 */
1211 if (!queue_work(kacpi_hotplug_wq, &hpw->work)) {
1212 kfree(hpw);
1213 return AE_ERROR;
1214 }
1215 return AE_OK;
1216}
1217
Rafael J. Wysockid7831562013-11-22 21:52:12 +01001218bool acpi_queue_hotplug_work(struct work_struct *work)
1219{
1220 return queue_work(kacpi_hotplug_wq, work);
1221}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001224acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225{
Len Brown4be44fc2005-08-05 00:44:28 -04001226 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 sem = acpi_os_allocate(sizeof(struct semaphore));
1229 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -04001230 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 memset(sem, 0, sizeof(struct semaphore));
1232
1233 sema_init(sem, initial_units);
1234
Len Brown4be44fc2005-08-05 00:44:28 -04001235 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Len Brown4be44fc2005-08-05 00:44:28 -04001237 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
1238 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Patrick Mocheld550d982006-06-27 00:41:40 -04001240 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243/*
1244 * TODO: A better way to delete semaphores? Linux doesn't have a
1245 * 'delete_semaphore()' function -- may result in an invalid
1246 * pointer dereference for non-synchronized consumers. Should
1247 * we at least check for blocked threads and signal/cancel them?
1248 */
1249
Len Brown4be44fc2005-08-05 00:44:28 -04001250acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Len Brown4be44fc2005-08-05 00:44:28 -04001252 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -04001255 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Len Brown4be44fc2005-08-05 00:44:28 -04001257 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Matthew Wilcoxf1241c82008-03-14 13:43:13 -04001259 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -04001260 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -04001261 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Patrick Mocheld550d982006-06-27 00:41:40 -04001263 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 * TODO: Support for units > 1?
1268 */
Len Brown4be44fc2005-08-05 00:44:28 -04001269acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Len Brown4be44fc2005-08-05 00:44:28 -04001271 acpi_status status = AE_OK;
1272 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -04001273 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -04001274 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001277 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
1279 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -04001280 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Len Brown4be44fc2005-08-05 00:44:28 -04001282 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
1283 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Matthew Wilcoxf1241c82008-03-14 13:43:13 -04001285 if (timeout == ACPI_WAIT_FOREVER)
1286 jiffies = MAX_SCHEDULE_TIMEOUT;
1287 else
1288 jiffies = msecs_to_jiffies(timeout);
1289
1290 ret = down_timeout(sem, jiffies);
1291 if (ret)
1292 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -04001295 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -04001296 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -04001297 handle, units, timeout,
1298 acpi_format_exception(status)));
1299 } else {
1300 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -04001301 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001302 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 }
1304
Patrick Mocheld550d982006-06-27 00:41:40 -04001305 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308/*
1309 * TODO: Support for units > 1?
1310 */
Len Brown4be44fc2005-08-05 00:44:28 -04001311acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
Len Brown4be44fc2005-08-05 00:44:28 -04001313 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001316 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -04001319 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Len Brown4be44fc2005-08-05 00:44:28 -04001321 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
1322 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 up(sem);
1325
Patrick Mocheld550d982006-06-27 00:41:40 -04001326 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
Len Brown4be44fc2005-08-05 00:44:28 -04001328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -04001330u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331{
1332
1333#ifdef ENABLE_DEBUGGER
1334 if (acpi_in_debugger) {
1335 u32 chars;
1336
1337 kdb_read(buffer, sizeof(line_buf));
1338
1339 /* remove the CR kdb includes */
1340 chars = strlen(buffer) - 1;
1341 buffer[chars] = '\0';
1342 }
1343#endif
1344
1345 return 0;
1346}
Len Brown4be44fc2005-08-05 00:44:28 -04001347#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Len Brown4be44fc2005-08-05 00:44:28 -04001349acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Len Brown4be44fc2005-08-05 00:44:28 -04001351 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 case ACPI_SIGNAL_FATAL:
1353 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
1354 break;
1355 case ACPI_SIGNAL_BREAKPOINT:
1356 /*
1357 * AML Breakpoint
1358 * ACPI spec. says to treat it as a NOP unless
1359 * you are debugging. So if/when we integrate
1360 * AML debugger into the kernel debugger its
1361 * hook will go here. But until then it is
1362 * not useful to print anything on breakpoints.
1363 */
1364 break;
1365 default:
1366 break;
1367 }
1368
1369 return AE_OK;
1370}
Len Brown4be44fc2005-08-05 00:44:28 -04001371
Len Brown4be44fc2005-08-05 00:44:28 -04001372static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
1374 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -04001375 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
1377 if (!str || !*str)
1378 return 0;
1379
Dan Carpenter5e2be4e2013-10-18 12:01:43 +03001380 for (; count-- && *str; str++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (isalnum(*str) || *str == ' ' || *str == ':')
1382 *p++ = *str;
1383 else if (*str == '\'' || *str == '"')
1384 continue;
1385 else
1386 break;
1387 }
1388 *p = 0;
1389
1390 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001391
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392}
1393
1394__setup("acpi_os_name=", acpi_os_name_setup);
1395
Lin Ming12d32062010-12-09 16:51:06 +08001396#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
1397#define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */
1398
1399struct osi_setup_entry {
1400 char string[OSI_STRING_LENGTH_MAX];
1401 bool enable;
1402};
1403
Hanjun Guoe73d3132013-08-13 18:31:15 +08001404static struct osi_setup_entry
1405 osi_setup_entries[OSI_STRING_ENTRIES_MAX] __initdata = {
Shaohua Liaa165972011-07-28 13:48:43 -07001406 {"Module Device", true},
1407 {"Processor Device", true},
1408 {"3.0 _SCP Extensions", true},
1409 {"Processor Aggregator Device", true},
1410};
Lin Ming12d32062010-12-09 16:51:06 +08001411
Lin Mingd90aa922010-12-09 16:50:52 +08001412void __init acpi_osi_setup(char *str)
1413{
Lin Ming12d32062010-12-09 16:51:06 +08001414 struct osi_setup_entry *osi;
1415 bool enable = true;
1416 int i;
1417
Lin Mingd90aa922010-12-09 16:50:52 +08001418 if (!acpi_gbl_create_osi_method)
1419 return;
1420
1421 if (str == NULL || *str == '\0') {
1422 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1423 acpi_gbl_create_osi_method = FALSE;
Lin Ming12d32062010-12-09 16:51:06 +08001424 return;
1425 }
1426
1427 if (*str == '!') {
1428 str++;
Lv Zheng5dc17982013-07-22 16:08:25 +08001429 if (*str == '\0') {
1430 osi_linux.default_disabling = 1;
1431 return;
Lv Zheng741d8122013-07-22 16:08:36 +08001432 } else if (*str == '*') {
1433 acpi_update_interfaces(ACPI_DISABLE_ALL_STRINGS);
1434 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1435 osi = &osi_setup_entries[i];
1436 osi->enable = false;
1437 }
1438 return;
Lv Zheng5dc17982013-07-22 16:08:25 +08001439 }
Lin Ming12d32062010-12-09 16:51:06 +08001440 enable = false;
1441 }
1442
1443 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1444 osi = &osi_setup_entries[i];
1445 if (!strcmp(osi->string, str)) {
1446 osi->enable = enable;
1447 break;
1448 } else if (osi->string[0] == '\0') {
1449 osi->enable = enable;
1450 strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
1451 break;
1452 }
1453 }
Lin Mingd90aa922010-12-09 16:50:52 +08001454}
1455
Len Brownd4b7dc42008-01-23 20:50:56 -05001456static void __init set_osi_linux(unsigned int enable)
1457{
Lin Mingd90aa922010-12-09 16:50:52 +08001458 if (osi_linux.enable != enable)
Len Brownd4b7dc42008-01-23 20:50:56 -05001459 osi_linux.enable = enable;
Lin Mingb0ed7a92010-08-06 09:35:51 +08001460
1461 if (osi_linux.enable)
1462 acpi_osi_setup("Linux");
1463 else
1464 acpi_osi_setup("!Linux");
1465
Len Brownd4b7dc42008-01-23 20:50:56 -05001466 return;
1467}
Len Brownf5076542007-05-30 00:10:38 -04001468
Len Brownd4b7dc42008-01-23 20:50:56 -05001469static void __init acpi_cmdline_osi_linux(unsigned int enable)
1470{
Lin Mingd90aa922010-12-09 16:50:52 +08001471 osi_linux.cmdline = 1; /* cmdline set the default and override DMI */
1472 osi_linux.dmi = 0;
Len Brownd4b7dc42008-01-23 20:50:56 -05001473 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -04001474
Len Brownd4b7dc42008-01-23 20:50:56 -05001475 return;
1476}
1477
1478void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1479{
Len Brownd4b7dc42008-01-23 20:50:56 -05001480 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1481
1482 if (enable == -1)
1483 return;
1484
Lin Mingd90aa922010-12-09 16:50:52 +08001485 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
Len Brownd4b7dc42008-01-23 20:50:56 -05001486 set_osi_linux(enable);
1487
Len Brownf5076542007-05-30 00:10:38 -04001488 return;
1489}
1490
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491/*
Len Brownae00d812007-05-29 18:43:33 -04001492 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1493 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001495 * string starting with '!' disables that string
1496 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 */
Lin Mingb0ed7a92010-08-06 09:35:51 +08001498static void __init acpi_osi_setup_late(void)
1499{
Lin Ming12d32062010-12-09 16:51:06 +08001500 struct osi_setup_entry *osi;
1501 char *str;
1502 int i;
Lin Mingd90aa922010-12-09 16:50:52 +08001503 acpi_status status;
Lin Mingb0ed7a92010-08-06 09:35:51 +08001504
Lv Zheng5dc17982013-07-22 16:08:25 +08001505 if (osi_linux.default_disabling) {
1506 status = acpi_update_interfaces(ACPI_DISABLE_ALL_VENDOR_STRINGS);
1507
1508 if (ACPI_SUCCESS(status))
1509 printk(KERN_INFO PREFIX "Disabled all _OSI OS vendors\n");
1510 }
1511
Lin Ming12d32062010-12-09 16:51:06 +08001512 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1513 osi = &osi_setup_entries[i];
1514 str = osi->string;
Lin Mingb0ed7a92010-08-06 09:35:51 +08001515
Lin Ming12d32062010-12-09 16:51:06 +08001516 if (*str == '\0')
1517 break;
1518 if (osi->enable) {
1519 status = acpi_install_interface(str);
Lin Mingd90aa922010-12-09 16:50:52 +08001520
Lin Ming12d32062010-12-09 16:51:06 +08001521 if (ACPI_SUCCESS(status))
1522 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1523 } else {
1524 status = acpi_remove_interface(str);
Lin Mingd90aa922010-12-09 16:50:52 +08001525
Lin Ming12d32062010-12-09 16:51:06 +08001526 if (ACPI_SUCCESS(status))
1527 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1528 }
Lin Mingb0ed7a92010-08-06 09:35:51 +08001529 }
1530}
1531
Lin Mingd90aa922010-12-09 16:50:52 +08001532static int __init osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Lin Mingd90aa922010-12-09 16:50:52 +08001534 if (str && !strcmp("Linux", str))
1535 acpi_cmdline_osi_linux(1);
1536 else if (str && !strcmp("!Linux", str))
1537 acpi_cmdline_osi_linux(0);
1538 else
1539 acpi_osi_setup(str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 return 1;
1542}
1543
Lin Mingd90aa922010-12-09 16:50:52 +08001544__setup("acpi_osi=", osi_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
1546/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001547static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
1549 printk(KERN_INFO PREFIX "serialize enabled\n");
1550
1551 acpi_gbl_all_methods_serialized = TRUE;
1552
1553 return 1;
1554}
1555
1556__setup("acpi_serialize", acpi_serialize_setup);
1557
Thomas Renningerdf92e692008-02-04 23:31:22 -08001558/* Check of resource interference between native drivers and ACPI
1559 * OperationRegions (SystemIO and System Memory only).
1560 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1561 * in arbitrary AML code and can interfere with legacy drivers.
1562 * acpi_enforce_resources= can be set to:
1563 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001564 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001565 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001566 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001567 * -> further driver trying to access the resources will load, but you
1568 * get a system message that something might go wrong...
1569 *
1570 * - no (0)
1571 * -> ACPI Operation Region resources will not be registered
1572 *
1573 */
1574#define ENFORCE_RESOURCES_STRICT 2
1575#define ENFORCE_RESOURCES_LAX 1
1576#define ENFORCE_RESOURCES_NO 0
1577
Luca Tettamanti7e905602009-03-30 00:01:27 +02001578static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001579
1580static int __init acpi_enforce_resources_setup(char *str)
1581{
1582 if (str == NULL || *str == '\0')
1583 return 0;
1584
1585 if (!strcmp("strict", str))
1586 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1587 else if (!strcmp("lax", str))
1588 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1589 else if (!strcmp("no", str))
1590 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1591
1592 return 1;
1593}
1594
1595__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1596
1597/* Check for resource conflicts between ACPI OperationRegions and native
1598 * drivers */
Jean Delvare876fba42009-11-11 15:22:15 +01001599int acpi_check_resource_conflict(const struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001600{
Lin Mingf654c0f2012-01-12 13:10:32 +08001601 acpi_adr_space_type space_id;
1602 acpi_size length;
1603 u8 warn = 0;
1604 int clash = 0;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001605
1606 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1607 return 0;
1608 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1609 return 0;
1610
Lin Mingf654c0f2012-01-12 13:10:32 +08001611 if (res->flags & IORESOURCE_IO)
1612 space_id = ACPI_ADR_SPACE_SYSTEM_IO;
1613 else
1614 space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001615
Alexandru Gheorghiue4f52242013-03-12 08:53:02 +00001616 length = resource_size(res);
Lin Mingf654c0f2012-01-12 13:10:32 +08001617 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO)
1618 warn = 1;
1619 clash = acpi_check_address_range(space_id, res->start, length, warn);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001620
1621 if (clash) {
1622 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Jean Delvare14f03342009-09-08 15:31:46 +02001623 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1624 printk(KERN_NOTICE "ACPI: This conflict may"
1625 " cause random problems and system"
1626 " instability\n");
1627 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1628 " for this device, you should use it instead of"
1629 " the native driver\n");
Thomas Renningerdf92e692008-02-04 23:31:22 -08001630 }
1631 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1632 return -EBUSY;
1633 }
1634 return 0;
1635}
Thomas Renninger443dea72008-02-04 23:31:23 -08001636EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001637
1638int acpi_check_region(resource_size_t start, resource_size_t n,
1639 const char *name)
1640{
1641 struct resource res = {
1642 .start = start,
1643 .end = start + n - 1,
1644 .name = name,
1645 .flags = IORESOURCE_IO,
1646 };
1647
1648 return acpi_check_resource_conflict(&res);
1649}
1650EXPORT_SYMBOL(acpi_check_region);
1651
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652/*
Jean Delvare70dd6be2010-05-27 19:58:37 +02001653 * Let drivers know whether the resource checks are effective
1654 */
1655int acpi_resources_are_enforced(void)
1656{
1657 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1658}
1659EXPORT_SYMBOL(acpi_resources_are_enforced);
1660
1661/*
Lin Ming9f63b882011-03-23 17:26:34 +08001662 * Deallocate the memory for a spinlock.
1663 */
1664void acpi_os_delete_lock(acpi_spinlock handle)
1665{
1666 ACPI_FREE(handle);
1667}
1668
1669/*
Robert Moore73459f72005-06-24 00:00:00 -04001670 * Acquire a spinlock.
1671 *
1672 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001673 */
1674
Bob Moore967440e32006-06-23 17:04:00 -04001675acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001676{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001677 acpi_cpu_flags flags;
Bob Moore967440e32006-06-23 17:04:00 -04001678 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001679 return flags;
1680}
1681
1682/*
1683 * Release a spinlock. See above.
1684 */
1685
Bob Moore967440e32006-06-23 17:04:00 -04001686void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001687{
Bob Moore967440e32006-06-23 17:04:00 -04001688 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001689}
1690
Robert Moore73459f72005-06-24 00:00:00 -04001691#ifndef ACPI_USE_LOCAL_CACHE
1692
1693/*******************************************************************************
1694 *
1695 * FUNCTION: acpi_os_create_cache
1696 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001697 * PARAMETERS: name - Ascii name for the cache
1698 * size - Size of each cached object
1699 * depth - Maximum depth of the cache (in objects) <ignored>
1700 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001701 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001702 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001703 *
1704 * DESCRIPTION: Create a cache object
1705 *
1706 ******************************************************************************/
1707
1708acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001709acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001710{
Paul Mundt20c2df82007-07-20 10:11:58 +09001711 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001712 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001713 return AE_ERROR;
1714 else
1715 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001716}
1717
1718/*******************************************************************************
1719 *
1720 * FUNCTION: acpi_os_purge_cache
1721 *
1722 * PARAMETERS: Cache - Handle to cache object
1723 *
1724 * RETURN: Status
1725 *
1726 * DESCRIPTION: Free all objects within the requested cache.
1727 *
1728 ******************************************************************************/
1729
Len Brown4be44fc2005-08-05 00:44:28 -04001730acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001731{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001732 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001733 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001734}
1735
1736/*******************************************************************************
1737 *
1738 * FUNCTION: acpi_os_delete_cache
1739 *
1740 * PARAMETERS: Cache - Handle to cache object
1741 *
1742 * RETURN: Status
1743 *
1744 * DESCRIPTION: Free all objects within the requested cache and delete the
1745 * cache object.
1746 *
1747 ******************************************************************************/
1748
Len Brown4be44fc2005-08-05 00:44:28 -04001749acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001750{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001751 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001752 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001753}
1754
1755/*******************************************************************************
1756 *
1757 * FUNCTION: acpi_os_release_object
1758 *
1759 * PARAMETERS: Cache - Handle to cache object
1760 * Object - The object to be released
1761 *
1762 * RETURN: None
1763 *
1764 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1765 * the object is deleted.
1766 *
1767 ******************************************************************************/
1768
Len Brown4be44fc2005-08-05 00:44:28 -04001769acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001770{
Len Brown4be44fc2005-08-05 00:44:28 -04001771 kmem_cache_free(cache, object);
1772 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001773}
Robert Moore73459f72005-06-24 00:00:00 -04001774#endif
Myron Stowed362eda2010-10-21 14:24:04 -06001775
Lv Zhengb75dd292013-06-08 00:58:48 +00001776static int __init acpi_no_auto_ssdt_setup(char *s)
1777{
1778 printk(KERN_NOTICE PREFIX "SSDT auto-load disabled\n");
1779
1780 acpi_gbl_disable_ssdt_table_load = TRUE;
1781
1782 return 1;
1783}
1784
1785__setup("acpi_no_auto_ssdt", acpi_no_auto_ssdt_setup);
1786
Myron Stowed362eda2010-10-21 14:24:04 -06001787acpi_status __init acpi_os_initialize(void)
1788{
1789 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
1790 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
1791 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
1792 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
1793
1794 return AE_OK;
1795}
1796
Zhang Rui32d47ee2010-12-08 10:40:36 +08001797acpi_status __init acpi_os_initialize1(void)
Myron Stowed362eda2010-10-21 14:24:04 -06001798{
Tejun Heo44d25882011-02-01 11:42:42 +01001799 kacpid_wq = alloc_workqueue("kacpid", 0, 1);
1800 kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
Rafael J. Wysockid7831562013-11-22 21:52:12 +01001801 kacpi_hotplug_wq = alloc_ordered_workqueue("kacpi_hotplug", 0);
Myron Stowed362eda2010-10-21 14:24:04 -06001802 BUG_ON(!kacpid_wq);
1803 BUG_ON(!kacpi_notify_wq);
1804 BUG_ON(!kacpi_hotplug_wq);
Len Brown1bd64d42010-10-26 14:50:56 -04001805 acpi_install_interface_handler(acpi_osi_handler);
1806 acpi_osi_setup_late();
Myron Stowed362eda2010-10-21 14:24:04 -06001807 return AE_OK;
1808}
1809
1810acpi_status acpi_os_terminate(void)
1811{
1812 if (acpi_irq_handler) {
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +01001813 acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt,
Myron Stowed362eda2010-10-21 14:24:04 -06001814 acpi_irq_handler);
1815 }
1816
1817 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
1818 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
1819 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
1820 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
1821
1822 destroy_workqueue(kacpid_wq);
1823 destroy_workqueue(kacpi_notify_wq);
1824 destroy_workqueue(kacpi_hotplug_wq);
1825
1826 return AE_OK;
1827}
Tang Liang09f98a82011-12-09 10:05:54 +08001828
1829acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control,
1830 u32 pm1b_control)
1831{
1832 int rc = 0;
1833 if (__acpi_os_prepare_sleep)
1834 rc = __acpi_os_prepare_sleep(sleep_state,
1835 pm1a_control, pm1b_control);
1836 if (rc < 0)
1837 return AE_ERROR;
1838 else if (rc > 0)
1839 return AE_CTRL_SKIP;
1840
1841 return AE_OK;
1842}
1843
1844void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state,
1845 u32 pm1a_ctrl, u32 pm1b_ctrl))
1846{
1847 __acpi_os_prepare_sleep = func;
1848}
Yinghai Lu92d8aff2013-01-21 13:20:47 -08001849
Ben Guthrod6b47b12013-07-30 08:24:52 -04001850acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, u32 val_a,
1851 u32 val_b)
1852{
1853 int rc = 0;
1854 if (__acpi_os_prepare_extended_sleep)
1855 rc = __acpi_os_prepare_extended_sleep(sleep_state,
1856 val_a, val_b);
1857 if (rc < 0)
1858 return AE_ERROR;
1859 else if (rc > 0)
1860 return AE_CTRL_SKIP;
1861
1862 return AE_OK;
1863}
1864
1865void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
1866 u32 val_a, u32 val_b))
1867{
1868 __acpi_os_prepare_extended_sleep = func;
1869}