aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/acpica/acconfig.h226
-rw-r--r--drivers/acpi/atomicio.c365
2 files changed, 591 insertions, 0 deletions
diff --git a/drivers/acpi/acpica/acconfig.h b/drivers/acpi/acpica/acconfig.h
new file mode 100644
index 00000000000..f895a244ca7
--- /dev/null
+++ b/drivers/acpi/acpica/acconfig.h
@@ -0,0 +1,226 @@
1/******************************************************************************
2 *
3 * Name: acconfig.h - Global configuration constants
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#ifndef _ACCONFIG_H
45#define _ACCONFIG_H
46
47/******************************************************************************
48 *
49 * Configuration options
50 *
51 *****************************************************************************/
52
53/*
54 * ACPI_DEBUG_OUTPUT - This switch enables all the debug facilities of the
55 * ACPI subsystem. This includes the DEBUG_PRINT output
56 * statements. When disabled, all DEBUG_PRINT
57 * statements are compiled out.
58 *
59 * ACPI_APPLICATION - Use this switch if the subsystem is going to be run
60 * at the application level.
61 *
62 */
63
64/*
65 * OS name, used for the _OS object. The _OS object is essentially obsolete,
66 * but there is a large base of ASL/AML code in existing machines that check
67 * for the string below. The use of this string usually guarantees that
68 * the ASL will execute down the most tested code path. Also, there is some
69 * code that will not execute the _OSI method unless _OS matches the string
70 * below. Therefore, change this string at your own risk.
71 */
72#define ACPI_OS_NAME "Microsoft Windows NT"
73
74/* Maximum objects in the various object caches */
75
76#define ACPI_MAX_STATE_CACHE_DEPTH 96 /* State objects */
77#define ACPI_MAX_PARSE_CACHE_DEPTH 96 /* Parse tree objects */
78#define ACPI_MAX_EXTPARSE_CACHE_DEPTH 96 /* Parse tree objects */
79#define ACPI_MAX_OBJECT_CACHE_DEPTH 96 /* Interpreter operand objects */
80#define ACPI_MAX_NAMESPACE_CACHE_DEPTH 96 /* Namespace objects */
81
82/*
83 * Should the subsystem abort the loading of an ACPI table if the
84 * table checksum is incorrect?
85 */
86#define ACPI_CHECKSUM_ABORT FALSE
87
88/******************************************************************************
89 *
90 * Subsystem Constants
91 *
92 *****************************************************************************/
93
94/* Version of ACPI supported */
95
96#define ACPI_CA_SUPPORT_LEVEL 3
97
98/* Maximum count for a semaphore object */
99
100#define ACPI_MAX_SEMAPHORE_COUNT 256
101
102/* Maximum object reference count (detects object deletion issues) */
103
104#define ACPI_MAX_REFERENCE_COUNT 0x1000
105
106/* Default page size for use in mapping memory for operation regions */
107
108#define ACPI_DEFAULT_PAGE_SIZE 4096 /* Must be power of 2 */
109
110/* owner_id tracking. 8 entries allows for 255 owner_ids */
111
112#define ACPI_NUM_OWNERID_MASKS 8
113
114/* Size of the root table array is increased by this increment */
115
116#define ACPI_ROOT_TABLE_SIZE_INCREMENT 4
117
118/* Maximum number of While() loop iterations before forced abort */
119
120#define ACPI_MAX_LOOP_ITERATIONS 0xFFFF
121
122/* Maximum sleep allowed via Sleep() operator */
123
124#define ACPI_MAX_SLEEP 2000 /* Two seconds */
125
126/******************************************************************************
127 *
128 * ACPI Specification constants (Do not change unless the specification changes)
129 *
130 *****************************************************************************/
131
132/* Number of distinct GPE register blocks and register width */
133
134#define ACPI_MAX_GPE_BLOCKS 2
135#define ACPI_GPE_REGISTER_WIDTH 8
136
137/* Method info (in WALK_STATE), containing local variables and argumetns */
138
139#define ACPI_METHOD_NUM_LOCALS 8
140#define ACPI_METHOD_MAX_LOCAL 7
141
142#define ACPI_METHOD_NUM_ARGS 7
143#define ACPI_METHOD_MAX_ARG 6
144
145/* Length of _HID, _UID, _CID, and UUID values */
146
147#define ACPI_DEVICE_ID_LENGTH 0x09
148#define ACPI_MAX_CID_LENGTH 48
149#define ACPI_UUID_LENGTH 16
150
151/*
152 * Operand Stack (in WALK_STATE), Must be large enough to contain METHOD_MAX_ARG
153 */
154#define ACPI_OBJ_NUM_OPERANDS 8
155#define ACPI_OBJ_MAX_OPERAND 7
156
157/* Number of elements in the Result Stack frame, can be an arbitrary value */
158
159#define ACPI_RESULTS_FRAME_OBJ_NUM 8
160
161/*
162 * Maximal number of elements the Result Stack can contain,
163 * it may be an arbitray value not exceeding the types of
164 * result_size and result_count (now u8).
165 */
166#define ACPI_RESULTS_OBJ_NUM_MAX 255
167
168/* Names within the namespace are 4 bytes long */
169
170#define ACPI_NAME_SIZE 4
171#define ACPI_PATH_SEGMENT_LENGTH 5 /* 4 chars for name + 1 char for separator */
172#define ACPI_PATH_SEPARATOR '.'
173
174/* Sizes for ACPI table headers */
175
176#define ACPI_OEM_ID_SIZE 6
177#define ACPI_OEM_TABLE_ID_SIZE 8
178
179/* Constants used in searching for the RSDP in low memory */
180
181#define ACPI_EBDA_PTR_LOCATION 0x0000040E /* Physical Address */
182#define ACPI_EBDA_PTR_LENGTH 2
183#define ACPI_EBDA_WINDOW_SIZE 1024
184#define ACPI_HI_RSDP_WINDOW_BASE 0x000E0000 /* Physical Address */
185#define ACPI_HI_RSDP_WINDOW_SIZE 0x00020000
186#define ACPI_RSDP_SCAN_STEP 16
187
188/* Operation regions */
189
190#define ACPI_USER_REGION_BEGIN 0x80
191
192/* Maximum space_ids for Operation Regions */
193
194#define ACPI_MAX_ADDRESS_SPACE 255
195
196/* Array sizes. Used for range checking also */
197
198#define ACPI_MAX_MATCH_OPCODE 5
199
200/* RSDP checksums */
201
202#define ACPI_RSDP_CHECKSUM_LENGTH 20
203#define ACPI_RSDP_XCHECKSUM_LENGTH 36
204
205/* SMBus and IPMI bidirectional buffer size */
206
207#define ACPI_SMBUS_BUFFER_SIZE 34
208#define ACPI_IPMI_BUFFER_SIZE 66
209
210/* _sx_d and _sx_w control methods */
211
212#define ACPI_NUM_sx_d_METHODS 4
213#define ACPI_NUM_sx_w_METHODS 5
214
215/******************************************************************************
216 *
217 * ACPI AML Debugger
218 *
219 *****************************************************************************/
220
221#define ACPI_DEBUGGER_MAX_ARGS 8 /* Must be max method args + 1 */
222
223#define ACPI_DEBUGGER_COMMAND_PROMPT '-'
224#define ACPI_DEBUGGER_EXECUTE_PROMPT '%'
225
226#endif /* _ACCONFIG_H */
diff --git a/drivers/acpi/atomicio.c b/drivers/acpi/atomicio.c
new file mode 100644
index 00000000000..f151afe61aa
--- /dev/null
+++ b/drivers/acpi/atomicio.c
@@ -0,0 +1,365 @@
1/*
2 * atomicio.c - ACPI IO memory pre-mapping/post-unmapping, then
3 * accessing in atomic context.
4 *
5 * This is used for NMI handler to access IO memory area, because
6 * ioremap/iounmap can not be used in NMI handler. The IO memory area
7 * is pre-mapped in process context and accessed in NMI handler.
8 *
9 * Copyright (C) 2009-2010, Intel Corp.
10 * Author: Huang Ying <ying.huang@intel.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License version
14 * 2 as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/acpi.h>
30#include <linux/io.h>
31#include <linux/kref.h>
32#include <linux/rculist.h>
33#include <linux/interrupt.h>
34#include <linux/slab.h>
35#include <acpi/atomicio.h>
36
37#define ACPI_PFX "ACPI: "
38
39static LIST_HEAD(acpi_iomaps);
40/*
41 * Used for mutual exclusion between writers of acpi_iomaps list, for
42 * synchronization between readers and writer, RCU is used.
43 */
44static DEFINE_SPINLOCK(acpi_iomaps_lock);
45
46struct acpi_iomap {
47 struct list_head list;
48 void __iomem *vaddr;
49 unsigned long size;
50 phys_addr_t paddr;
51 struct kref ref;
52};
53
54/* acpi_iomaps_lock or RCU read lock must be held before calling */
55static struct acpi_iomap *__acpi_find_iomap(phys_addr_t paddr,
56 unsigned long size)
57{
58 struct acpi_iomap *map;
59
60 list_for_each_entry_rcu(map, &acpi_iomaps, list) {
61 if (map->paddr + map->size >= paddr + size &&
62 map->paddr <= paddr)
63 return map;
64 }
65 return NULL;
66}
67
68/*
69 * Atomic "ioremap" used by NMI handler, if the specified IO memory
70 * area is not pre-mapped, NULL will be returned.
71 *
72 * acpi_iomaps_lock or RCU read lock must be held before calling
73 */
74static void __iomem *__acpi_ioremap_fast(phys_addr_t paddr,
75 unsigned long size)
76{
77 struct acpi_iomap *map;
78
79 map = __acpi_find_iomap(paddr, size/8);
80 if (map)
81 return map->vaddr + (paddr - map->paddr);
82 else
83 return NULL;
84}
85
86/* acpi_iomaps_lock must be held before calling */
87static void __iomem *__acpi_try_ioremap(phys_addr_t paddr,
88 unsigned long size)
89{
90 struct acpi_iomap *map;
91
92 map = __acpi_find_iomap(paddr, size);
93 if (map) {
94 kref_get(&map->ref);
95 return map->vaddr + (paddr - map->paddr);
96 } else
97 return NULL;
98}
99
100/*
101 * Used to pre-map the specified IO memory area. First try to find
102 * whether the area is already pre-mapped, if it is, increase the
103 * reference count (in __acpi_try_ioremap) and return; otherwise, do
104 * the real ioremap, and add the mapping into acpi_iomaps list.
105 */
106static void __iomem *acpi_pre_map(phys_addr_t paddr,
107 unsigned long size)
108{
109 void __iomem *vaddr;
110 struct acpi_iomap *map;
111 unsigned long pg_sz, flags;
112 phys_addr_t pg_off;
113
114 spin_lock_irqsave(&acpi_iomaps_lock, flags);
115 vaddr = __acpi_try_ioremap(paddr, size);
116 spin_unlock_irqrestore(&acpi_iomaps_lock, flags);
117 if (vaddr)
118 return vaddr;
119
120 pg_off = paddr & PAGE_MASK;
121 pg_sz = ((paddr + size + PAGE_SIZE - 1) & PAGE_MASK) - pg_off;
122 vaddr = ioremap(pg_off, pg_sz);
123 if (!vaddr)
124 return NULL;
125 map = kmalloc(sizeof(*map), GFP_KERNEL);
126 if (!map)
127 goto err_unmap;
128 INIT_LIST_HEAD(&map->list);
129 map->paddr = pg_off;
130 map->size = pg_sz;
131 map->vaddr = vaddr;
132 kref_init(&map->ref);
133
134 spin_lock_irqsave(&acpi_iomaps_lock, flags);
135 vaddr = __acpi_try_ioremap(paddr, size);
136 if (vaddr) {
137 spin_unlock_irqrestore(&acpi_iomaps_lock, flags);
138 iounmap(map->vaddr);
139 kfree(map);
140 return vaddr;
141 }
142 list_add_tail_rcu(&map->list, &acpi_iomaps);
143 spin_unlock_irqrestore(&acpi_iomaps_lock, flags);
144
145 return map->vaddr + (paddr - map->paddr);
146err_unmap:
147 iounmap(vaddr);
148 return NULL;
149}
150
151/* acpi_iomaps_lock must be held before calling */
152static void __acpi_kref_del_iomap(struct kref *ref)
153{
154 struct acpi_iomap *map;
155
156 map = container_of(ref, struct acpi_iomap, ref);
157 list_del_rcu(&map->list);
158}
159
160/*
161 * Used to post-unmap the specified IO memory area. The iounmap is
162 * done only if the reference count goes zero.
163 */
164static void acpi_post_unmap(phys_addr_t paddr, unsigned long size)
165{
166 struct acpi_iomap *map;
167 unsigned long flags;
168 int del;
169
170 spin_lock_irqsave(&acpi_iomaps_lock, flags);
171 map = __acpi_find_iomap(paddr, size);
172 BUG_ON(!map);
173 del = kref_put(&map->ref, __acpi_kref_del_iomap);
174 spin_unlock_irqrestore(&acpi_iomaps_lock, flags);
175
176 if (!del)
177 return;
178
179 synchronize_rcu();
180 iounmap(map->vaddr);
181 kfree(map);
182}
183
184/* In NMI handler, should set silent = 1 */
185static int acpi_check_gar(struct acpi_generic_address *reg,
186 u64 *paddr, int silent)
187{
188 u32 width, space_id;
189
190 width = reg->bit_width;
191 space_id = reg->space_id;
192 /* Handle possible alignment issues */
193 memcpy(paddr, &reg->address, sizeof(*paddr));
194 if (!*paddr) {
195 if (!silent)
196 pr_warning(FW_BUG ACPI_PFX
197 "Invalid physical address in GAR [0x%llx/%u/%u]\n",
198 *paddr, width, space_id);
199 return -EINVAL;
200 }
201
202 if ((width != 8) && (width != 16) && (width != 32) && (width != 64)) {
203 if (!silent)
204 pr_warning(FW_BUG ACPI_PFX
205 "Invalid bit width in GAR [0x%llx/%u/%u]\n",
206 *paddr, width, space_id);
207 return -EINVAL;
208 }
209
210 if (space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY &&
211 space_id != ACPI_ADR_SPACE_SYSTEM_IO) {
212 if (!silent)
213 pr_warning(FW_BUG ACPI_PFX
214 "Invalid address space type in GAR [0x%llx/%u/%u]\n",
215 *paddr, width, space_id);
216 return -EINVAL;
217 }
218
219 return 0;
220}
221
222/* Pre-map, working on GAR */
223int acpi_pre_map_gar(struct acpi_generic_address *reg)
224{
225 u64 paddr;
226 void __iomem *vaddr;
227 int rc;
228
229 if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
230 return 0;
231
232 rc = acpi_check_gar(reg, &paddr, 0);
233 if (rc)
234 return rc;
235
236 vaddr = acpi_pre_map(paddr, reg->bit_width / 8);
237 if (!vaddr)
238 return -EIO;
239
240 return 0;
241}
242EXPORT_SYMBOL_GPL(acpi_pre_map_gar);
243
244/* Post-unmap, working on GAR */
245int acpi_post_unmap_gar(struct acpi_generic_address *reg)
246{
247 u64 paddr;
248 int rc;
249
250 if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
251 return 0;
252
253 rc = acpi_check_gar(reg, &paddr, 0);
254 if (rc)
255 return rc;
256
257 acpi_post_unmap(paddr, reg->bit_width / 8);
258
259 return 0;
260}
261EXPORT_SYMBOL_GPL(acpi_post_unmap_gar);
262
263/*
264 * Can be used in atomic (including NMI) or process context. RCU read
265 * lock can only be released after the IO memory area accessing.
266 */
267static int acpi_atomic_read_mem(u64 paddr, u64 *val, u32 width)
268{
269 void __iomem *addr;
270
271 rcu_read_lock();
272 addr = __acpi_ioremap_fast(paddr, width);
273 switch (width) {
274 case 8:
275 *val = readb(addr);
276 break;
277 case 16:
278 *val = readw(addr);
279 break;
280 case 32:
281 *val = readl(addr);
282 break;
283#ifdef readq
284 case 64:
285 *val = readq(addr);
286 break;
287#endif
288 default:
289 return -EINVAL;
290 }
291 rcu_read_unlock();
292
293 return 0;
294}
295
296static int acpi_atomic_write_mem(u64 paddr, u64 val, u32 width)
297{
298 void __iomem *addr;
299
300 rcu_read_lock();
301 addr = __acpi_ioremap_fast(paddr, width);
302 switch (width) {
303 case 8:
304 writeb(val, addr);
305 break;
306 case 16:
307 writew(val, addr);
308 break;
309 case 32:
310 writel(val, addr);
311 break;
312#ifdef writeq
313 case 64:
314 writeq(val, addr);
315 break;
316#endif
317 default:
318 return -EINVAL;
319 }
320 rcu_read_unlock();
321
322 return 0;
323}
324
325/* GAR accessing in atomic (including NMI) or process context */
326int acpi_atomic_read(u64 *val, struct acpi_generic_address *reg)
327{
328 u64 paddr;
329 int rc;
330
331 rc = acpi_check_gar(reg, &paddr, 1);
332 if (rc)
333 return rc;
334
335 *val = 0;
336 switch (reg->space_id) {
337 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
338 return acpi_atomic_read_mem(paddr, val, reg->bit_width);
339 case ACPI_ADR_SPACE_SYSTEM_IO:
340 return acpi_os_read_port(paddr, (u32 *)val, reg->bit_width);
341 default:
342 return -EINVAL;
343 }
344}
345EXPORT_SYMBOL_GPL(acpi_atomic_read);
346
347int acpi_atomic_write(u64 val, struct acpi_generic_address *reg)
348{
349 u64 paddr;
350 int rc;
351
352 rc = acpi_check_gar(reg, &paddr, 1);
353 if (rc)
354 return rc;
355
356 switch (reg->space_id) {
357 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
358 return acpi_atomic_write_mem(paddr, val, reg->bit_width);
359 case ACPI_ADR_SPACE_SYSTEM_IO:
360 return acpi_os_write_port(paddr, val, reg->bit_width);
361 default:
362 return -EINVAL;
363 }
364}
365EXPORT_SYMBOL_GPL(acpi_atomic_write);