blob: cfc3e260a68849c67602d887b3228b29f6a6450e [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
571/* Must not increase 10 or needs code modification below */
572#define ACPI_OVERRIDE_TABLES 10
573
574void __init acpi_initrd_override(void *data, size_t size)
575{
576 int sig, no, table_nr = 0, total_offset = 0;
577 long offset = 0;
578 struct acpi_table_header *table;
579 char cpio_path[32] = "kernel/firmware/acpi/";
580 struct cpio_data file;
581 struct cpio_data early_initrd_files[ACPI_OVERRIDE_TABLES];
582 char *p;
583
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;
627 early_initrd_files[table_nr].data = file.data;
628 early_initrd_files[table_nr].size = file.size;
629 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
654 p = early_ioremap(acpi_tables_addr, all_tables_size);
655
656 for (no = 0; no < table_nr; no++) {
657 memcpy(p + total_offset, early_initrd_files[no].data,
658 early_initrd_files[no].size);
659 total_offset += early_initrd_files[no].size;
660 }
661 early_iounmap(p, all_tables_size);
662}
663#endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */
664
Thomas Renninger325a8d362012-10-01 00:23:56 +0200665static void acpi_table_taint(struct acpi_table_header *table)
666{
667 pr_warn(PREFIX
668 "Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n",
669 table->signature, table->oem_table_id);
Rusty Russell373d4d02013-01-21 17:17:39 +1030670 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
Thomas Renninger325a8d362012-10-01 00:23:56 +0200671}
672
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400675acpi_os_table_override(struct acpi_table_header * existing_table,
676 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
678 if (!existing_table || !new_table)
679 return AE_BAD_PARAMETER;
680
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100681 *new_table = NULL;
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#ifdef CONFIG_ACPI_CUSTOM_DSDT
684 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400685 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#endif
Thomas Renninger325a8d362012-10-01 00:23:56 +0200687 if (*new_table != NULL)
688 acpi_table_taint(existing_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 return AE_OK;
690}
691
Bob Mooref7b004a2012-02-14 18:31:56 +0800692acpi_status
693acpi_os_physical_table_override(struct acpi_table_header *existing_table,
Thomas Renningerb2a35002012-10-01 00:23:55 +0200694 acpi_physical_address *address,
695 u32 *table_length)
Bob Mooref7b004a2012-02-14 18:31:56 +0800696{
Thomas Renningerb2a35002012-10-01 00:23:55 +0200697#ifndef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
698 *table_length = 0;
699 *address = 0;
700 return AE_OK;
701#else
702 int table_offset = 0;
703 struct acpi_table_header *table;
Bob Mooref7b004a2012-02-14 18:31:56 +0800704
Thomas Renningerb2a35002012-10-01 00:23:55 +0200705 *table_length = 0;
706 *address = 0;
707
708 if (!acpi_tables_addr)
709 return AE_OK;
710
711 do {
712 if (table_offset + ACPI_HEADER_SIZE > all_tables_size) {
713 WARN_ON(1);
714 return AE_OK;
715 }
716
717 table = acpi_os_map_memory(acpi_tables_addr + table_offset,
718 ACPI_HEADER_SIZE);
719
720 if (table_offset + table->length > all_tables_size) {
721 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
722 WARN_ON(1);
723 return AE_OK;
724 }
725
726 table_offset += table->length;
727
728 if (memcmp(existing_table->signature, table->signature, 4)) {
729 acpi_os_unmap_memory(table,
730 ACPI_HEADER_SIZE);
731 continue;
732 }
733
734 /* Only override tables with matching oem id */
735 if (memcmp(table->oem_table_id, existing_table->oem_table_id,
736 ACPI_OEM_TABLE_ID_SIZE)) {
737 acpi_os_unmap_memory(table,
738 ACPI_HEADER_SIZE);
739 continue;
740 }
741
742 table_offset -= table->length;
743 *table_length = table->length;
744 acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
745 *address = acpi_tables_addr + table_offset;
746 break;
747 } while (table_offset + ACPI_HEADER_SIZE < all_tables_size);
748
Thomas Renninger325a8d362012-10-01 00:23:56 +0200749 if (*address != 0)
750 acpi_table_taint(existing_table);
Thomas Renningerb2a35002012-10-01 00:23:55 +0200751 return AE_OK;
752#endif
753}
Bob Mooref7b004a2012-02-14 18:31:56 +0800754
David Howells7d12e782006-10-05 14:55:46 +0100755static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
Len Brown5229e872008-02-06 01:26:55 -0500757 u32 handled;
758
759 handled = (*acpi_irq_handler) (acpi_irq_context);
760
761 if (handled) {
762 acpi_irq_handled++;
763 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400764 } else {
765 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500766 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
769
770acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400771acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
772 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
774 unsigned int irq;
775
Len Brown5229e872008-02-06 01:26:55 -0500776 acpi_irq_stats_init();
777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 /*
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100779 * ACPI interrupts different from the SCI in our copy of the FADT are
780 * not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 */
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100782 if (gsi != acpi_gbl_FADT.sci_interrupt)
783 return AE_BAD_PARAMETER;
784
785 if (acpi_irq_handler)
786 return AE_ALREADY_ACQUIRED;
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
789 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
790 gsi);
791 return AE_OK;
792 }
793
794 acpi_irq_handler = handler;
795 acpi_irq_context = context;
Zhang Rui89a22da2013-02-04 07:10:10 +0000796 if (request_irq(irq, acpi_irq, IRQF_SHARED | IRQF_NO_SUSPEND, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100798 acpi_irq_handler = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 return AE_NOT_ACQUIRED;
800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 return AE_OK;
803}
804
Len Brown4be44fc2005-08-05 00:44:28 -0400805acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +0100807 if (irq != acpi_gbl_FADT.sci_interrupt)
808 return AE_BAD_PARAMETER;
809
810 free_irq(irq, acpi_irq);
811 acpi_irq_handler = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 return AE_OK;
814}
815
816/*
817 * Running in interpreter thread context, safe to sleep
818 */
819
Lin Ming439913f2010-01-28 10:53:19 +0800820void acpi_os_sleep(u64 ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800822 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
Len Brown4be44fc2005-08-05 00:44:28 -0400824
Len Brown4be44fc2005-08-05 00:44:28 -0400825void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
827 while (us) {
828 u32 delay = 1000;
829
830 if (delay > us)
831 delay = us;
832 udelay(delay);
833 touch_nmi_watchdog();
834 us -= delay;
835 }
836}
Len Brown4be44fc2005-08-05 00:44:28 -0400837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838/*
839 * Support ACPI 3.0 AML Timer operand
840 * Returns 64-bit free-running, monotonically increasing timer
841 * with 100ns granularity
842 */
Len Brown4be44fc2005-08-05 00:44:28 -0400843u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Mika Westerberg10619062013-05-23 10:27:46 +0300845 u64 time_ns = ktime_to_ns(ktime_get());
846 do_div(time_ns, 100);
847 return time_ns;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848}
849
Len Brown4be44fc2005-08-05 00:44:28 -0400850acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
852 u32 dummy;
853
854 if (!value)
855 value = &dummy;
856
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800857 *value = 0;
858 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400859 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800860 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400861 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800862 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400863 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800864 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 BUG();
866 }
867
868 return AE_OK;
869}
Len Brown4be44fc2005-08-05 00:44:28 -0400870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871EXPORT_SYMBOL(acpi_os_read_port);
872
Len Brown4be44fc2005-08-05 00:44:28 -0400873acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800875 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800877 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800879 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800881 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 BUG();
883 }
884
885 return AE_OK;
886}
Len Brown4be44fc2005-08-05 00:44:28 -0400887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888EXPORT_SYMBOL(acpi_os_write_port);
889
Myron Stowee615bf52012-01-20 19:13:24 -0700890#ifdef readq
891static inline u64 read64(const volatile void __iomem *addr)
892{
893 return readq(addr);
894}
895#else
896static inline u64 read64(const volatile void __iomem *addr)
897{
898 u64 l, h;
899 l = readl(addr);
900 h = readl(addr+4);
901 return l | (h << 32);
902}
903#endif
904
905acpi_status
Bob Moore653f4b52012-02-14 18:29:55 +0800906acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
Myron Stowee615bf52012-01-20 19:13:24 -0700907{
908 void __iomem *virt_addr;
909 unsigned int size = width / 8;
910 bool unmap = false;
911 u64 dummy;
912
913 rcu_read_lock();
914 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
915 if (!virt_addr) {
916 rcu_read_unlock();
917 virt_addr = acpi_os_ioremap(phys_addr, size);
918 if (!virt_addr)
919 return AE_BAD_ADDRESS;
920 unmap = true;
921 }
922
923 if (!value)
924 value = &dummy;
925
926 switch (width) {
927 case 8:
928 *(u8 *) value = readb(virt_addr);
929 break;
930 case 16:
931 *(u16 *) value = readw(virt_addr);
932 break;
933 case 32:
934 *(u32 *) value = readl(virt_addr);
935 break;
936 case 64:
937 *(u64 *) value = read64(virt_addr);
938 break;
939 default:
940 BUG();
941 }
942
943 if (unmap)
944 iounmap(virt_addr);
945 else
946 rcu_read_unlock();
947
948 return AE_OK;
949}
950
Myron Stowee615bf52012-01-20 19:13:24 -0700951#ifdef writeq
952static inline void write64(u64 val, volatile void __iomem *addr)
953{
954 writeq(val, addr);
955}
956#else
957static inline void write64(u64 val, volatile void __iomem *addr)
958{
959 writel(val, addr);
960 writel(val>>32, addr+4);
961}
962#endif
963
964acpi_status
Bob Moore653f4b52012-02-14 18:29:55 +0800965acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
Myron Stowee615bf52012-01-20 19:13:24 -0700966{
967 void __iomem *virt_addr;
968 unsigned int size = width / 8;
969 bool unmap = false;
970
971 rcu_read_lock();
972 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
973 if (!virt_addr) {
974 rcu_read_unlock();
975 virt_addr = acpi_os_ioremap(phys_addr, size);
976 if (!virt_addr)
977 return AE_BAD_ADDRESS;
978 unmap = true;
979 }
980
981 switch (width) {
982 case 8:
983 writeb(value, virt_addr);
984 break;
985 case 16:
986 writew(value, virt_addr);
987 break;
988 case 32:
989 writel(value, virt_addr);
990 break;
991 case 64:
992 write64(value, virt_addr);
993 break;
994 default:
995 BUG();
996 }
997
998 if (unmap)
999 iounmap(virt_addr);
1000 else
1001 rcu_read_unlock();
1002
1003 return AE_OK;
1004}
1005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001007acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Bob Moorec5f02312010-08-06 08:57:53 +08001008 u64 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
1010 int result, size;
Bob Moorec5f02312010-08-06 08:57:53 +08001011 u32 value32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
1013 if (!value)
1014 return AE_BAD_PARAMETER;
1015
1016 switch (width) {
1017 case 8:
1018 size = 1;
1019 break;
1020 case 16:
1021 size = 2;
1022 break;
1023 case 32:
1024 size = 4;
1025 break;
1026 default:
1027 return AE_ERROR;
1028 }
1029
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -05001030 result = raw_pci_read(pci_id->segment, pci_id->bus,
1031 PCI_DEVFN(pci_id->device, pci_id->function),
Bob Moorec5f02312010-08-06 08:57:53 +08001032 reg, size, &value32);
1033 *value = value32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
1035 return (result ? AE_ERROR : AE_OK);
1036}
Len Brown4be44fc2005-08-05 00:44:28 -04001037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001039acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Lin Ming439913f2010-01-28 10:53:19 +08001040 u64 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 int result, size;
1043
1044 switch (width) {
1045 case 8:
1046 size = 1;
1047 break;
1048 case 16:
1049 size = 2;
1050 break;
1051 case 32:
1052 size = 4;
1053 break;
1054 default:
1055 return AE_ERROR;
1056 }
1057
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -05001058 result = raw_pci_write(pci_id->segment, pci_id->bus,
1059 PCI_DEVFN(pci_id->device, pci_id->function),
1060 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 return (result ? AE_ERROR : AE_OK);
1063}
1064
David Howells65f27f32006-11-22 14:55:48 +00001065static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
David Howells65f27f32006-11-22 14:55:48 +00001067 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -04001068
Zhang Rui19cd8472008-08-28 10:05:06 +08001069 dpc->function(dpc->context);
1070 kfree(dpc);
Zhang Rui19cd8472008-08-28 10:05:06 +08001071}
1072
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -04001073/*******************************************************************************
1074 *
1075 * FUNCTION: acpi_os_execute
1076 *
1077 * PARAMETERS: Type - Type of the callback
1078 * Function - Function to be executed
1079 * Context - Function parameters
1080 *
1081 * RETURN: Status
1082 *
1083 * DESCRIPTION: Depending on type, either queues function for deferred execution or
1084 * immediately executes function on a separate thread.
1085 *
1086 ******************************************************************************/
1087
Rafael J. Wysocki7b981182013-11-07 01:45:40 +01001088acpi_status acpi_os_execute(acpi_execute_type type,
1089 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Len Brown4be44fc2005-08-05 00:44:28 -04001091 acpi_status status = AE_OK;
1092 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +03001093 struct workqueue_struct *queue;
Zhang Rui19cd8472008-08-28 10:05:06 +08001094 int ret;
Len Brown72945b22006-07-12 22:46:42 -04001095 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
1096 "Scheduling function [%p(%p)] for deferred execution.\n",
1097 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 /*
1100 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +00001101 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 * way that allows us to also free its memory inside the callee.
1103 * Because we may want to schedule several tasks with different
1104 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +00001105 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 */
Len Brown72945b22006-07-12 22:46:42 -04001107
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001108 dpc = kzalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +08001110 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -08001111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 dpc->function = function;
1113 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -08001114
Zhang Ruic02256b2009-06-23 10:20:29 +08001115 /*
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001116 * To prevent lockdep from complaining unnecessarily, make sure that
1117 * there is a different static lockdep key for each workqueue by using
1118 * INIT_WORK() for each of them separately.
Zhang Ruic02256b2009-06-23 10:20:29 +08001119 */
Rafael J. Wysocki7b981182013-11-07 01:45:40 +01001120 if (type == OSL_NOTIFY_HANDLER) {
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001121 queue = kacpi_notify_wq;
Zhang Ruibc736752010-03-22 15:48:54 +08001122 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001123 } else {
1124 queue = kacpid_wq;
Zhang Ruibc736752010-03-22 15:48:54 +08001125 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
Rafael J. Wysocki3ae45a22012-11-02 13:09:08 +01001126 }
Zhang Ruibc736752010-03-22 15:48:54 +08001127
Tejun Heo8fec62b2010-06-29 10:07:09 +02001128 /*
1129 * On some machines, a software-initiated SMI causes corruption unless
1130 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
1131 * typically it's done in GPE-related methods that are run via
1132 * workqueues, so we can avoid the known corruption cases by always
1133 * queueing on CPU 0.
1134 */
1135 ret = queue_work_on(0, queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +08001136
1137 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001138 printk(KERN_ERR PREFIX
1139 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +03001140 status = AE_ERROR;
1141 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
Lin Ming889c78b2008-12-31 09:23:57 +08001143 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -04001145EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Lin Mingbd6f10a2012-05-22 16:43:49 +08001147void acpi_os_wait_events_complete(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
1149 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -04001150 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
Len Brown4be44fc2005-08-05 00:44:28 -04001152
Rafael J. Wysocki7b981182013-11-07 01:45:40 +01001153struct acpi_hp_work {
1154 struct work_struct work;
1155 acpi_hp_callback func;
1156 void *data;
1157 u32 src;
1158};
1159
1160static void acpi_hotplug_work_fn(struct work_struct *work)
1161{
1162 struct acpi_hp_work *hpw = container_of(work, struct acpi_hp_work, work);
1163
1164 acpi_os_wait_events_complete();
1165 hpw->func(hpw->data, hpw->src);
1166 kfree(hpw);
1167}
1168
1169acpi_status acpi_hotplug_execute(acpi_hp_callback func, void *data, u32 src)
1170{
1171 struct acpi_hp_work *hpw;
1172
1173 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
1174 "Scheduling function [%p(%p, %u)] for deferred execution.\n",
1175 func, data, src));
1176
1177 hpw = kmalloc(sizeof(*hpw), GFP_KERNEL);
1178 if (!hpw)
1179 return AE_NO_MEMORY;
1180
1181 INIT_WORK(&hpw->work, acpi_hotplug_work_fn);
1182 hpw->func = func;
1183 hpw->data = data;
1184 hpw->src = src;
1185 /*
1186 * We can't run hotplug code in kacpid_wq/kacpid_notify_wq etc., because
1187 * the hotplug code may call driver .remove() functions, which may
1188 * invoke flush_scheduled_work()/acpi_os_wait_events_complete() to flush
1189 * these workqueues.
1190 */
1191 if (!queue_work(kacpi_hotplug_wq, &hpw->work)) {
1192 kfree(hpw);
1193 return AE_ERROR;
1194 }
1195 return AE_OK;
1196}
1197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001200acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
Len Brown4be44fc2005-08-05 00:44:28 -04001202 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 sem = acpi_os_allocate(sizeof(struct semaphore));
1205 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -04001206 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 memset(sem, 0, sizeof(struct semaphore));
1208
1209 sema_init(sem, initial_units);
1210
Len Brown4be44fc2005-08-05 00:44:28 -04001211 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Len Brown4be44fc2005-08-05 00:44:28 -04001213 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
1214 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Patrick Mocheld550d982006-06-27 00:41:40 -04001216 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219/*
1220 * TODO: A better way to delete semaphores? Linux doesn't have a
1221 * 'delete_semaphore()' function -- may result in an invalid
1222 * pointer dereference for non-synchronized consumers. Should
1223 * we at least check for blocked threads and signal/cancel them?
1224 */
1225
Len Brown4be44fc2005-08-05 00:44:28 -04001226acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
Len Brown4be44fc2005-08-05 00:44:28 -04001228 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -04001231 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Len Brown4be44fc2005-08-05 00:44:28 -04001233 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Matthew Wilcoxf1241c82008-03-14 13:43:13 -04001235 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -04001236 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -04001237 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Patrick Mocheld550d982006-06-27 00:41:40 -04001239 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 * TODO: Support for units > 1?
1244 */
Len Brown4be44fc2005-08-05 00:44:28 -04001245acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
Len Brown4be44fc2005-08-05 00:44:28 -04001247 acpi_status status = AE_OK;
1248 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -04001249 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -04001250 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001253 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -04001256 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Len Brown4be44fc2005-08-05 00:44:28 -04001258 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
1259 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Matthew Wilcoxf1241c82008-03-14 13:43:13 -04001261 if (timeout == ACPI_WAIT_FOREVER)
1262 jiffies = MAX_SCHEDULE_TIMEOUT;
1263 else
1264 jiffies = msecs_to_jiffies(timeout);
1265
1266 ret = down_timeout(sem, jiffies);
1267 if (ret)
1268 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
1270 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -04001271 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -04001272 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -04001273 handle, units, timeout,
1274 acpi_format_exception(status)));
1275 } else {
1276 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -04001277 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001278 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 }
1280
Patrick Mocheld550d982006-06-27 00:41:40 -04001281 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284/*
1285 * TODO: Support for units > 1?
1286 */
Len Brown4be44fc2005-08-05 00:44:28 -04001287acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288{
Len Brown4be44fc2005-08-05 00:44:28 -04001289 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001292 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -04001295 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Len Brown4be44fc2005-08-05 00:44:28 -04001297 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
1298 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 up(sem);
1301
Patrick Mocheld550d982006-06-27 00:41:40 -04001302 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303}
Len Brown4be44fc2005-08-05 00:44:28 -04001304
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -04001306u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307{
1308
1309#ifdef ENABLE_DEBUGGER
1310 if (acpi_in_debugger) {
1311 u32 chars;
1312
1313 kdb_read(buffer, sizeof(line_buf));
1314
1315 /* remove the CR kdb includes */
1316 chars = strlen(buffer) - 1;
1317 buffer[chars] = '\0';
1318 }
1319#endif
1320
1321 return 0;
1322}
Len Brown4be44fc2005-08-05 00:44:28 -04001323#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Len Brown4be44fc2005-08-05 00:44:28 -04001325acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Len Brown4be44fc2005-08-05 00:44:28 -04001327 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 case ACPI_SIGNAL_FATAL:
1329 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
1330 break;
1331 case ACPI_SIGNAL_BREAKPOINT:
1332 /*
1333 * AML Breakpoint
1334 * ACPI spec. says to treat it as a NOP unless
1335 * you are debugging. So if/when we integrate
1336 * AML debugger into the kernel debugger its
1337 * hook will go here. But until then it is
1338 * not useful to print anything on breakpoints.
1339 */
1340 break;
1341 default:
1342 break;
1343 }
1344
1345 return AE_OK;
1346}
Len Brown4be44fc2005-08-05 00:44:28 -04001347
Len Brown4be44fc2005-08-05 00:44:28 -04001348static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
1350 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -04001351 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 if (!str || !*str)
1354 return 0;
1355
1356 for (; count-- && str && *str; str++) {
1357 if (isalnum(*str) || *str == ' ' || *str == ':')
1358 *p++ = *str;
1359 else if (*str == '\'' || *str == '"')
1360 continue;
1361 else
1362 break;
1363 }
1364 *p = 0;
1365
1366 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
1370__setup("acpi_os_name=", acpi_os_name_setup);
1371
Lin Ming12d32062010-12-09 16:51:06 +08001372#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
1373#define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */
1374
1375struct osi_setup_entry {
1376 char string[OSI_STRING_LENGTH_MAX];
1377 bool enable;
1378};
1379
Hanjun Guoe73d3132013-08-13 18:31:15 +08001380static struct osi_setup_entry
1381 osi_setup_entries[OSI_STRING_ENTRIES_MAX] __initdata = {
Shaohua Liaa165972011-07-28 13:48:43 -07001382 {"Module Device", true},
1383 {"Processor Device", true},
1384 {"3.0 _SCP Extensions", true},
1385 {"Processor Aggregator Device", true},
1386};
Lin Ming12d32062010-12-09 16:51:06 +08001387
Lin Mingd90aa922010-12-09 16:50:52 +08001388void __init acpi_osi_setup(char *str)
1389{
Lin Ming12d32062010-12-09 16:51:06 +08001390 struct osi_setup_entry *osi;
1391 bool enable = true;
1392 int i;
1393
Lin Mingd90aa922010-12-09 16:50:52 +08001394 if (!acpi_gbl_create_osi_method)
1395 return;
1396
1397 if (str == NULL || *str == '\0') {
1398 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1399 acpi_gbl_create_osi_method = FALSE;
Lin Ming12d32062010-12-09 16:51:06 +08001400 return;
1401 }
1402
1403 if (*str == '!') {
1404 str++;
Lv Zheng5dc17982013-07-22 16:08:25 +08001405 if (*str == '\0') {
1406 osi_linux.default_disabling = 1;
1407 return;
Lv Zheng741d8122013-07-22 16:08:36 +08001408 } else if (*str == '*') {
1409 acpi_update_interfaces(ACPI_DISABLE_ALL_STRINGS);
1410 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1411 osi = &osi_setup_entries[i];
1412 osi->enable = false;
1413 }
1414 return;
Lv Zheng5dc17982013-07-22 16:08:25 +08001415 }
Lin Ming12d32062010-12-09 16:51:06 +08001416 enable = false;
1417 }
1418
1419 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1420 osi = &osi_setup_entries[i];
1421 if (!strcmp(osi->string, str)) {
1422 osi->enable = enable;
1423 break;
1424 } else if (osi->string[0] == '\0') {
1425 osi->enable = enable;
1426 strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
1427 break;
1428 }
1429 }
Lin Mingd90aa922010-12-09 16:50:52 +08001430}
1431
Len Brownd4b7dc42008-01-23 20:50:56 -05001432static void __init set_osi_linux(unsigned int enable)
1433{
Lin Mingd90aa922010-12-09 16:50:52 +08001434 if (osi_linux.enable != enable)
Len Brownd4b7dc42008-01-23 20:50:56 -05001435 osi_linux.enable = enable;
Lin Mingb0ed7a92010-08-06 09:35:51 +08001436
1437 if (osi_linux.enable)
1438 acpi_osi_setup("Linux");
1439 else
1440 acpi_osi_setup("!Linux");
1441
Len Brownd4b7dc42008-01-23 20:50:56 -05001442 return;
1443}
Len Brownf5076542007-05-30 00:10:38 -04001444
Len Brownd4b7dc42008-01-23 20:50:56 -05001445static void __init acpi_cmdline_osi_linux(unsigned int enable)
1446{
Lin Mingd90aa922010-12-09 16:50:52 +08001447 osi_linux.cmdline = 1; /* cmdline set the default and override DMI */
1448 osi_linux.dmi = 0;
Len Brownd4b7dc42008-01-23 20:50:56 -05001449 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -04001450
Len Brownd4b7dc42008-01-23 20:50:56 -05001451 return;
1452}
1453
1454void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1455{
Len Brownd4b7dc42008-01-23 20:50:56 -05001456 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1457
1458 if (enable == -1)
1459 return;
1460
Lin Mingd90aa922010-12-09 16:50:52 +08001461 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
Len Brownd4b7dc42008-01-23 20:50:56 -05001462 set_osi_linux(enable);
1463
Len Brownf5076542007-05-30 00:10:38 -04001464 return;
1465}
1466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467/*
Len Brownae00d812007-05-29 18:43:33 -04001468 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1469 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001471 * string starting with '!' disables that string
1472 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 */
Lin Mingb0ed7a92010-08-06 09:35:51 +08001474static void __init acpi_osi_setup_late(void)
1475{
Lin Ming12d32062010-12-09 16:51:06 +08001476 struct osi_setup_entry *osi;
1477 char *str;
1478 int i;
Lin Mingd90aa922010-12-09 16:50:52 +08001479 acpi_status status;
Lin Mingb0ed7a92010-08-06 09:35:51 +08001480
Lv Zheng5dc17982013-07-22 16:08:25 +08001481 if (osi_linux.default_disabling) {
1482 status = acpi_update_interfaces(ACPI_DISABLE_ALL_VENDOR_STRINGS);
1483
1484 if (ACPI_SUCCESS(status))
1485 printk(KERN_INFO PREFIX "Disabled all _OSI OS vendors\n");
1486 }
1487
Lin Ming12d32062010-12-09 16:51:06 +08001488 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1489 osi = &osi_setup_entries[i];
1490 str = osi->string;
Lin Mingb0ed7a92010-08-06 09:35:51 +08001491
Lin Ming12d32062010-12-09 16:51:06 +08001492 if (*str == '\0')
1493 break;
1494 if (osi->enable) {
1495 status = acpi_install_interface(str);
Lin Mingd90aa922010-12-09 16:50:52 +08001496
Lin Ming12d32062010-12-09 16:51:06 +08001497 if (ACPI_SUCCESS(status))
1498 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1499 } else {
1500 status = acpi_remove_interface(str);
Lin Mingd90aa922010-12-09 16:50:52 +08001501
Lin Ming12d32062010-12-09 16:51:06 +08001502 if (ACPI_SUCCESS(status))
1503 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1504 }
Lin Mingb0ed7a92010-08-06 09:35:51 +08001505 }
1506}
1507
Lin Mingd90aa922010-12-09 16:50:52 +08001508static int __init osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Lin Mingd90aa922010-12-09 16:50:52 +08001510 if (str && !strcmp("Linux", str))
1511 acpi_cmdline_osi_linux(1);
1512 else if (str && !strcmp("!Linux", str))
1513 acpi_cmdline_osi_linux(0);
1514 else
1515 acpi_osi_setup(str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
1517 return 1;
1518}
1519
Lin Mingd90aa922010-12-09 16:50:52 +08001520__setup("acpi_osi=", osi_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001523static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
1525 printk(KERN_INFO PREFIX "serialize enabled\n");
1526
1527 acpi_gbl_all_methods_serialized = TRUE;
1528
1529 return 1;
1530}
1531
1532__setup("acpi_serialize", acpi_serialize_setup);
1533
Thomas Renningerdf92e692008-02-04 23:31:22 -08001534/* Check of resource interference between native drivers and ACPI
1535 * OperationRegions (SystemIO and System Memory only).
1536 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1537 * in arbitrary AML code and can interfere with legacy drivers.
1538 * acpi_enforce_resources= can be set to:
1539 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001540 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001541 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001542 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001543 * -> further driver trying to access the resources will load, but you
1544 * get a system message that something might go wrong...
1545 *
1546 * - no (0)
1547 * -> ACPI Operation Region resources will not be registered
1548 *
1549 */
1550#define ENFORCE_RESOURCES_STRICT 2
1551#define ENFORCE_RESOURCES_LAX 1
1552#define ENFORCE_RESOURCES_NO 0
1553
Luca Tettamanti7e905602009-03-30 00:01:27 +02001554static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001555
1556static int __init acpi_enforce_resources_setup(char *str)
1557{
1558 if (str == NULL || *str == '\0')
1559 return 0;
1560
1561 if (!strcmp("strict", str))
1562 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1563 else if (!strcmp("lax", str))
1564 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1565 else if (!strcmp("no", str))
1566 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1567
1568 return 1;
1569}
1570
1571__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1572
1573/* Check for resource conflicts between ACPI OperationRegions and native
1574 * drivers */
Jean Delvare876fba42009-11-11 15:22:15 +01001575int acpi_check_resource_conflict(const struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001576{
Lin Mingf654c0f2012-01-12 13:10:32 +08001577 acpi_adr_space_type space_id;
1578 acpi_size length;
1579 u8 warn = 0;
1580 int clash = 0;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001581
1582 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1583 return 0;
1584 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1585 return 0;
1586
Lin Mingf654c0f2012-01-12 13:10:32 +08001587 if (res->flags & IORESOURCE_IO)
1588 space_id = ACPI_ADR_SPACE_SYSTEM_IO;
1589 else
1590 space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001591
Alexandru Gheorghiue4f52242013-03-12 08:53:02 +00001592 length = resource_size(res);
Lin Mingf654c0f2012-01-12 13:10:32 +08001593 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO)
1594 warn = 1;
1595 clash = acpi_check_address_range(space_id, res->start, length, warn);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001596
1597 if (clash) {
1598 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Jean Delvare14f03342009-09-08 15:31:46 +02001599 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1600 printk(KERN_NOTICE "ACPI: This conflict may"
1601 " cause random problems and system"
1602 " instability\n");
1603 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1604 " for this device, you should use it instead of"
1605 " the native driver\n");
Thomas Renningerdf92e692008-02-04 23:31:22 -08001606 }
1607 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1608 return -EBUSY;
1609 }
1610 return 0;
1611}
Thomas Renninger443dea72008-02-04 23:31:23 -08001612EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001613
1614int acpi_check_region(resource_size_t start, resource_size_t n,
1615 const char *name)
1616{
1617 struct resource res = {
1618 .start = start,
1619 .end = start + n - 1,
1620 .name = name,
1621 .flags = IORESOURCE_IO,
1622 };
1623
1624 return acpi_check_resource_conflict(&res);
1625}
1626EXPORT_SYMBOL(acpi_check_region);
1627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628/*
Jean Delvare70dd6be2010-05-27 19:58:37 +02001629 * Let drivers know whether the resource checks are effective
1630 */
1631int acpi_resources_are_enforced(void)
1632{
1633 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1634}
1635EXPORT_SYMBOL(acpi_resources_are_enforced);
1636
1637/*
Lin Ming9f63b882011-03-23 17:26:34 +08001638 * Deallocate the memory for a spinlock.
1639 */
1640void acpi_os_delete_lock(acpi_spinlock handle)
1641{
1642 ACPI_FREE(handle);
1643}
1644
1645/*
Robert Moore73459f72005-06-24 00:00:00 -04001646 * Acquire a spinlock.
1647 *
1648 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001649 */
1650
Bob Moore967440e32006-06-23 17:04:00 -04001651acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001652{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001653 acpi_cpu_flags flags;
Bob Moore967440e32006-06-23 17:04:00 -04001654 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001655 return flags;
1656}
1657
1658/*
1659 * Release a spinlock. See above.
1660 */
1661
Bob Moore967440e32006-06-23 17:04:00 -04001662void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001663{
Bob Moore967440e32006-06-23 17:04:00 -04001664 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001665}
1666
Robert Moore73459f72005-06-24 00:00:00 -04001667#ifndef ACPI_USE_LOCAL_CACHE
1668
1669/*******************************************************************************
1670 *
1671 * FUNCTION: acpi_os_create_cache
1672 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001673 * PARAMETERS: name - Ascii name for the cache
1674 * size - Size of each cached object
1675 * depth - Maximum depth of the cache (in objects) <ignored>
1676 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001677 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001678 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001679 *
1680 * DESCRIPTION: Create a cache object
1681 *
1682 ******************************************************************************/
1683
1684acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001685acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001686{
Paul Mundt20c2df82007-07-20 10:11:58 +09001687 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001688 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001689 return AE_ERROR;
1690 else
1691 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001692}
1693
1694/*******************************************************************************
1695 *
1696 * FUNCTION: acpi_os_purge_cache
1697 *
1698 * PARAMETERS: Cache - Handle to cache object
1699 *
1700 * RETURN: Status
1701 *
1702 * DESCRIPTION: Free all objects within the requested cache.
1703 *
1704 ******************************************************************************/
1705
Len Brown4be44fc2005-08-05 00:44:28 -04001706acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001707{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001708 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001709 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001710}
1711
1712/*******************************************************************************
1713 *
1714 * FUNCTION: acpi_os_delete_cache
1715 *
1716 * PARAMETERS: Cache - Handle to cache object
1717 *
1718 * RETURN: Status
1719 *
1720 * DESCRIPTION: Free all objects within the requested cache and delete the
1721 * cache object.
1722 *
1723 ******************************************************************************/
1724
Len Brown4be44fc2005-08-05 00:44:28 -04001725acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001726{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001727 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001728 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001729}
1730
1731/*******************************************************************************
1732 *
1733 * FUNCTION: acpi_os_release_object
1734 *
1735 * PARAMETERS: Cache - Handle to cache object
1736 * Object - The object to be released
1737 *
1738 * RETURN: None
1739 *
1740 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1741 * the object is deleted.
1742 *
1743 ******************************************************************************/
1744
Len Brown4be44fc2005-08-05 00:44:28 -04001745acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001746{
Len Brown4be44fc2005-08-05 00:44:28 -04001747 kmem_cache_free(cache, object);
1748 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001749}
Robert Moore73459f72005-06-24 00:00:00 -04001750#endif
Myron Stowed362eda2010-10-21 14:24:04 -06001751
Lv Zhengb75dd292013-06-08 00:58:48 +00001752static int __init acpi_no_auto_ssdt_setup(char *s)
1753{
1754 printk(KERN_NOTICE PREFIX "SSDT auto-load disabled\n");
1755
1756 acpi_gbl_disable_ssdt_table_load = TRUE;
1757
1758 return 1;
1759}
1760
1761__setup("acpi_no_auto_ssdt", acpi_no_auto_ssdt_setup);
1762
Myron Stowed362eda2010-10-21 14:24:04 -06001763acpi_status __init acpi_os_initialize(void)
1764{
1765 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
1766 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
1767 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
1768 acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
1769
1770 return AE_OK;
1771}
1772
Zhang Rui32d47ee2010-12-08 10:40:36 +08001773acpi_status __init acpi_os_initialize1(void)
Myron Stowed362eda2010-10-21 14:24:04 -06001774{
Tejun Heo44d25882011-02-01 11:42:42 +01001775 kacpid_wq = alloc_workqueue("kacpid", 0, 1);
1776 kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
1777 kacpi_hotplug_wq = alloc_workqueue("kacpi_hotplug", 0, 1);
Myron Stowed362eda2010-10-21 14:24:04 -06001778 BUG_ON(!kacpid_wq);
1779 BUG_ON(!kacpi_notify_wq);
1780 BUG_ON(!kacpi_hotplug_wq);
Len Brown1bd64d42010-10-26 14:50:56 -04001781 acpi_install_interface_handler(acpi_osi_handler);
1782 acpi_osi_setup_late();
Myron Stowed362eda2010-10-21 14:24:04 -06001783 return AE_OK;
1784}
1785
1786acpi_status acpi_os_terminate(void)
1787{
1788 if (acpi_irq_handler) {
Rafael J. Wysocki23fe3632011-02-08 23:48:16 +01001789 acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt,
Myron Stowed362eda2010-10-21 14:24:04 -06001790 acpi_irq_handler);
1791 }
1792
1793 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
1794 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
1795 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
1796 acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
1797
1798 destroy_workqueue(kacpid_wq);
1799 destroy_workqueue(kacpi_notify_wq);
1800 destroy_workqueue(kacpi_hotplug_wq);
1801
1802 return AE_OK;
1803}
Tang Liang09f98a82011-12-09 10:05:54 +08001804
1805acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control,
1806 u32 pm1b_control)
1807{
1808 int rc = 0;
1809 if (__acpi_os_prepare_sleep)
1810 rc = __acpi_os_prepare_sleep(sleep_state,
1811 pm1a_control, pm1b_control);
1812 if (rc < 0)
1813 return AE_ERROR;
1814 else if (rc > 0)
1815 return AE_CTRL_SKIP;
1816
1817 return AE_OK;
1818}
1819
1820void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state,
1821 u32 pm1a_ctrl, u32 pm1b_ctrl))
1822{
1823 __acpi_os_prepare_sleep = func;
1824}
Yinghai Lu92d8aff2013-01-21 13:20:47 -08001825
Ben Guthrod6b47b12013-07-30 08:24:52 -04001826acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, u32 val_a,
1827 u32 val_b)
1828{
1829 int rc = 0;
1830 if (__acpi_os_prepare_extended_sleep)
1831 rc = __acpi_os_prepare_extended_sleep(sleep_state,
1832 val_a, val_b);
1833 if (rc < 0)
1834 return AE_ERROR;
1835 else if (rc > 0)
1836 return AE_CTRL_SKIP;
1837
1838 return AE_OK;
1839}
1840
1841void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
1842 u32 val_a, u32 val_b))
1843{
1844 __acpi_os_prepare_extended_sleep = func;
1845}