blob: a498a6cc68fec1d463786fba1d3b6c84a6e6b68f [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>
34#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/interrupt.h>
36#include <linux/kmod.h>
37#include <linux/delay.h>
Len Brownf5076542007-05-30 00:10:38 -040038#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/workqueue.h>
40#include <linux/nmi.h>
Alexey Starikovskiyad718602007-02-02 19:48:19 +030041#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/efi.h>
Thomas Renningerdf92e692008-02-04 23:31:22 -080043#include <linux/ioport.h>
44#include <linux/list.h>
Matthew Wilcoxf1241c82008-03-14 13:43:13 -040045#include <linux/jiffies.h>
46#include <linux/semaphore.h>
47
48#include <asm/io.h>
49#include <asm/uaccess.h>
50
51#include <acpi/acpi.h>
52#include <acpi/acpi_bus.h>
53#include <acpi/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#define _COMPONENT ACPI_OS_SERVICES
Len Brownf52fd662007-02-12 22:42:12 -050056ACPI_MODULE_NAME("osl");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040058struct acpi_os_dpc {
59 acpi_osd_exec_callback function;
60 void *context;
David Howells65f27f32006-11-22 14:55:48 +000061 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64#ifdef CONFIG_ACPI_CUSTOM_DSDT
65#include CONFIG_ACPI_CUSTOM_DSDT_FILE
66#endif
67
68#ifdef ENABLE_DEBUGGER
69#include <linux/kdb.h>
70
71/* stuff for debugger support */
72int acpi_in_debugger;
73EXPORT_SYMBOL(acpi_in_debugger);
74
75extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040076#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78static unsigned int acpi_irq_irq;
79static acpi_osd_handler acpi_irq_handler;
80static void *acpi_irq_context;
81static struct workqueue_struct *kacpid_wq;
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -040082static struct workqueue_struct *kacpi_notify_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Thomas Renningerdf92e692008-02-04 23:31:22 -080084struct acpi_res_list {
85 resource_size_t start;
86 resource_size_t end;
87 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
88 char name[5]; /* only can have a length of 4 chars, make use of this
89 one instead of res->name, no need to kalloc then */
90 struct list_head resource_list;
91};
92
93static LIST_HEAD(resource_list_head);
94static DEFINE_SPINLOCK(acpi_res_lock);
95
Len Brownae00d812007-05-29 18:43:33 -040096#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
97static char osi_additional_string[OSI_STRING_LENGTH_MAX];
98
Len Brownd4b7dc42008-01-23 20:50:56 -050099/*
100 * "Ode to _OSI(Linux)"
101 *
102 * osi_linux -- Control response to BIOS _OSI(Linux) query.
103 *
104 * As Linux evolves, the features that it supports change.
105 * So an OSI string such as "Linux" is not specific enough
106 * to be useful across multiple versions of Linux. It
107 * doesn't identify any particular feature, interface,
108 * or even any particular version of Linux...
109 *
110 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
111 * to a BIOS _OSI(Linux) query. When
112 * a reference mobile BIOS started using it, its use
113 * started to spread to many vendor platforms.
114 * As it is not supportable, we need to halt that spread.
115 *
116 * Today, most BIOS references to _OSI(Linux) are noise --
117 * they have no functional effect and are just dead code
118 * carried over from the reference BIOS.
119 *
120 * The next most common case is that _OSI(Linux) harms Linux,
121 * usually by causing the BIOS to follow paths that are
122 * not tested during Windows validation.
123 *
124 * Finally, there is a short list of platforms
125 * where OSI(Linux) benefits Linux.
126 *
127 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
128 * DMI is used to disable the dmesg warning about OSI(Linux)
129 * on platforms where it is known to have no effect.
130 * But a dmesg warning remains for systems where
131 * we do not know if OSI(Linux) is good or bad for the system.
132 * DMI is also used to enable OSI(Linux) for the machines
133 * that are known to need it.
134 *
135 * BIOS writers should NOT query _OSI(Linux) on future systems.
136 * It will be ignored by default, and to get Linux to
137 * not ignore it will require a kernel source update to
138 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
139 */
140#define OSI_LINUX_ENABLE 0
141
Adrian Bunk1d15d842008-01-29 00:10:15 +0200142static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500143 unsigned int enable:1;
144 unsigned int dmi:1;
145 unsigned int cmdline:1;
146 unsigned int known:1;
147} osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400148
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700149static void __init acpi_request_region (struct acpi_generic_address *addr,
150 unsigned int length, char *desc)
151{
152 struct resource *res;
153
154 if (!addr->address || !length)
155 return;
156
Len Browneee3c852007-02-03 01:38:16 -0500157 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700158 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500159 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700160 res = request_mem_region(addr->address, length, desc);
161}
162
163static int __init acpi_reserve_resources(void)
164{
Len Browneee3c852007-02-03 01:38:16 -0500165 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700166 "ACPI PM1a_EVT_BLK");
167
Len Browneee3c852007-02-03 01:38:16 -0500168 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700169 "ACPI PM1b_EVT_BLK");
170
Len Browneee3c852007-02-03 01:38:16 -0500171 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700172 "ACPI PM1a_CNT_BLK");
173
Len Browneee3c852007-02-03 01:38:16 -0500174 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700175 "ACPI PM1b_CNT_BLK");
176
Len Browneee3c852007-02-03 01:38:16 -0500177 if (acpi_gbl_FADT.pm_timer_length == 4)
178 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700179
Len Browneee3c852007-02-03 01:38:16 -0500180 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700181 "ACPI PM2_CNT_BLK");
182
183 /* Length of GPE blocks must be a non-negative multiple of 2 */
184
Len Browneee3c852007-02-03 01:38:16 -0500185 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
186 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
187 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700188
Len Browneee3c852007-02-03 01:38:16 -0500189 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
190 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
191 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700192
193 return 0;
194}
195device_initcall(acpi_reserve_resources);
196
Len Browndd272b52007-05-30 00:26:11 -0400197acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
199 return AE_OK;
200}
201
Len Brown4be44fc2005-08-05 00:44:28 -0400202acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 kacpid_wq = create_singlethread_workqueue("kacpid");
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400205 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400207 BUG_ON(!kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return AE_OK;
209}
210
Len Brown4be44fc2005-08-05 00:44:28 -0400211acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 if (acpi_irq_handler) {
214 acpi_os_remove_interrupt_handler(acpi_irq_irq,
215 acpi_irq_handler);
216 }
217
218 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400219 destroy_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 return AE_OK;
222}
223
Len Brown4be44fc2005-08-05 00:44:28 -0400224void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
226 va_list args;
227 va_start(args, fmt);
228 acpi_os_vprintf(fmt, args);
229 va_end(args);
230}
Len Brown4be44fc2005-08-05 00:44:28 -0400231
Len Brown4be44fc2005-08-05 00:44:28 -0400232void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
234 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 vsprintf(buffer, fmt, args);
237
238#ifdef ENABLE_DEBUGGER
239 if (acpi_in_debugger) {
240 kdb_printf("%s", buffer);
241 } else {
242 printk("%s", buffer);
243 }
244#else
245 printk("%s", buffer);
246#endif
247}
248
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300249acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
251 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800252 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300253 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800254 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300255 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400257 printk(KERN_ERR PREFIX
258 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300259 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
Len Brown239665a2007-11-23 20:08:02 -0500261 } else {
262 acpi_physical_address pa = 0;
263
264 acpi_find_root_pointer(&pa);
265 return pa;
266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Jan Beulich2fdf0742007-12-13 08:33:59 +0000269void __iomem *__init_refok
270acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800272 if (phys > ULONG_MAX) {
273 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800274 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300276 if (acpi_gbl_permanent_mmap)
277 /*
278 * ioremap checks to ensure this is in reserved space
279 */
280 return ioremap((unsigned long)phys, size);
281 else
282 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800284EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Len Brown4be44fc2005-08-05 00:44:28 -0400286void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300288 if (acpi_gbl_permanent_mmap) {
289 iounmap(virt);
290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800292EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294#ifdef ACPI_FUTURE_USAGE
295acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400296acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Len Brown4be44fc2005-08-05 00:44:28 -0400298 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 return AE_BAD_PARAMETER;
300
301 *phys = virt_to_phys(virt);
302
303 return AE_OK;
304}
305#endif
306
307#define ACPI_MAX_OVERRIDE_LEN 100
308
309static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
310
311acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400312acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
313 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
315 if (!init_val || !new_val)
316 return AE_BAD_PARAMETER;
317
318 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400319 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400321 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 *new_val = acpi_os_name;
323 }
324
325 return AE_OK;
326}
327
328acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400329acpi_os_table_override(struct acpi_table_header * existing_table,
330 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 if (!existing_table || !new_table)
333 return AE_BAD_PARAMETER;
334
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100335 *new_table = NULL;
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337#ifdef CONFIG_ACPI_CUSTOM_DSDT
338 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400339 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100341 if (*new_table != NULL) {
342 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
343 "this is unsafe: tainting kernel\n",
344 existing_table->signature,
345 existing_table->oem_table_id);
346 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return AE_OK;
349}
350
David Howells7d12e782006-10-05 14:55:46 +0100351static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Len Brown5229e872008-02-06 01:26:55 -0500353 u32 handled;
354
355 handled = (*acpi_irq_handler) (acpi_irq_context);
356
357 if (handled) {
358 acpi_irq_handled++;
359 return IRQ_HANDLED;
360 } else
361 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400365acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
366 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 unsigned int irq;
369
Len Brown5229e872008-02-06 01:26:55 -0500370 acpi_irq_stats_init();
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 /*
373 * Ignore the GSI from the core, and use the value in our copy of the
374 * FADT. It may not be the same if an interrupt source override exists
375 * for the SCI.
376 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300377 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
379 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
380 gsi);
381 return AE_OK;
382 }
383
384 acpi_irq_handler = handler;
385 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700386 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
388 return AE_NOT_ACQUIRED;
389 }
390 acpi_irq_irq = irq;
391
392 return AE_OK;
393}
394
Len Brown4be44fc2005-08-05 00:44:28 -0400395acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
397 if (irq) {
398 free_irq(irq, acpi_irq);
399 acpi_irq_handler = NULL;
400 acpi_irq_irq = 0;
401 }
402
403 return AE_OK;
404}
405
406/*
407 * Running in interpreter thread context, safe to sleep
408 */
409
Len Brown4be44fc2005-08-05 00:44:28 -0400410void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800412 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
Len Brown4be44fc2005-08-05 00:44:28 -0400414
Len Brown4be44fc2005-08-05 00:44:28 -0400415void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
417 while (us) {
418 u32 delay = 1000;
419
420 if (delay > us)
421 delay = us;
422 udelay(delay);
423 touch_nmi_watchdog();
424 us -= delay;
425 }
426}
Len Brown4be44fc2005-08-05 00:44:28 -0400427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/*
429 * Support ACPI 3.0 AML Timer operand
430 * Returns 64-bit free-running, monotonically increasing timer
431 * with 100ns granularity
432 */
Len Brown4be44fc2005-08-05 00:44:28 -0400433u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
435 static u64 t;
436
437#ifdef CONFIG_HPET
438 /* TBD: use HPET if available */
439#endif
440
441#ifdef CONFIG_X86_PM_TIMER
442 /* TBD: default to PM timer if HPET was not available */
443#endif
444 if (!t)
445 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
446
447 return ++t;
448}
449
Len Brown4be44fc2005-08-05 00:44:28 -0400450acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 u32 dummy;
453
454 if (!value)
455 value = &dummy;
456
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800457 *value = 0;
458 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400459 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800460 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400461 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800462 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400463 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800464 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 BUG();
466 }
467
468 return AE_OK;
469}
Len Brown4be44fc2005-08-05 00:44:28 -0400470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471EXPORT_SYMBOL(acpi_os_read_port);
472
Len Brown4be44fc2005-08-05 00:44:28 -0400473acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800475 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800477 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800479 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800481 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 BUG();
483 }
484
485 return AE_OK;
486}
Len Brown4be44fc2005-08-05 00:44:28 -0400487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488EXPORT_SYMBOL(acpi_os_write_port);
489
490acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400491acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Len Brown4be44fc2005-08-05 00:44:28 -0400493 u32 dummy;
494 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800496 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (!value)
498 value = &dummy;
499
500 switch (width) {
501 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400502 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 break;
504 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400505 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 break;
507 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400508 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 break;
510 default:
511 BUG();
512 }
513
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800514 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 return AE_OK;
517}
518
519acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400520acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Len Brown4be44fc2005-08-05 00:44:28 -0400522 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800524 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 switch (width) {
527 case 8:
528 writeb(value, virt_addr);
529 break;
530 case 16:
531 writew(value, virt_addr);
532 break;
533 case 32:
534 writel(value, virt_addr);
535 break;
536 default:
537 BUG();
538 }
539
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800540 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 return AE_OK;
543}
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400546acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Linus Torvalds10270d42008-02-13 09:56:14 -0800547 u32 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
549 int result, size;
550
551 if (!value)
552 return AE_BAD_PARAMETER;
553
554 switch (width) {
555 case 8:
556 size = 1;
557 break;
558 case 16:
559 size = 2;
560 break;
561 case 32:
562 size = 4;
563 break;
564 default:
565 return AE_ERROR;
566 }
567
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500568 result = raw_pci_read(pci_id->segment, pci_id->bus,
569 PCI_DEVFN(pci_id->device, pci_id->function),
570 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 return (result ? AE_ERROR : AE_OK);
573}
Len Brown4be44fc2005-08-05 00:44:28 -0400574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400576acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
577 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 int result, size;
580
581 switch (width) {
582 case 8:
583 size = 1;
584 break;
585 case 16:
586 size = 2;
587 break;
588 case 32:
589 size = 4;
590 break;
591 default:
592 return AE_ERROR;
593 }
594
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500595 result = raw_pci_write(pci_id->segment, pci_id->bus,
596 PCI_DEVFN(pci_id->device, pci_id->function),
597 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 return (result ? AE_ERROR : AE_OK);
600}
601
602/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400603static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
604 acpi_handle chandle, /* current node */
605 struct acpi_pci_id **id,
606 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Len Brown4be44fc2005-08-05 00:44:28 -0400608 acpi_handle handle;
609 struct acpi_pci_id *pci_id = *id;
610 acpi_status status;
611 unsigned long temp;
612 acpi_object_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 acpi_get_parent(chandle, &handle);
615 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400616 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
617 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400620 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 return;
622
Len Brown4be44fc2005-08-05 00:44:28 -0400623 status =
624 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
625 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800627 u32 val;
Len Brown4be44fc2005-08-05 00:44:28 -0400628 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
629 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 if (*is_bridge)
632 pci_id->bus = *bus_number;
633
634 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400635 status =
Linus Torvalds10270d42008-02-13 09:56:14 -0800636 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
Len Brown4be44fc2005-08-05 00:44:28 -0400637 8);
638 if (ACPI_SUCCESS(status)
Linus Torvalds10270d42008-02-13 09:56:14 -0800639 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400640 status =
641 acpi_os_read_pci_configuration(pci_id, 0x18,
Linus Torvalds10270d42008-02-13 09:56:14 -0800642 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 if (!ACPI_SUCCESS(status)) {
644 /* Certainly broken... FIX ME */
645 return;
646 }
647 *is_bridge = 1;
Linus Torvalds10270d42008-02-13 09:56:14 -0800648 pci_id->bus = val;
Len Brown4be44fc2005-08-05 00:44:28 -0400649 status =
650 acpi_os_read_pci_configuration(pci_id, 0x19,
Linus Torvalds10270d42008-02-13 09:56:14 -0800651 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800653 *bus_number = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655 } else
656 *is_bridge = 0;
657 }
658 }
659}
660
Len Brown4be44fc2005-08-05 00:44:28 -0400661void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
662 acpi_handle chandle, /* current node */
663 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
665 int is_bridge = 1;
666 u8 bus_number = (*id)->bus;
667
668 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
669}
670
David Howells65f27f32006-11-22 14:55:48 +0000671static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
David Howells65f27f32006-11-22 14:55:48 +0000673 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400674 if (!dpc) {
675 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
676 return;
677 }
678
679 dpc->function(dpc->context);
680 kfree(dpc);
681
Patrick Mocheld550d982006-06-27 00:41:40 -0400682 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400685/*******************************************************************************
686 *
687 * FUNCTION: acpi_os_execute
688 *
689 * PARAMETERS: Type - Type of the callback
690 * Function - Function to be executed
691 * Context - Function parameters
692 *
693 * RETURN: Status
694 *
695 * DESCRIPTION: Depending on type, either queues function for deferred execution or
696 * immediately executes function on a separate thread.
697 *
698 ******************************************************************************/
699
700acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400701 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Len Brown4be44fc2005-08-05 00:44:28 -0400703 acpi_status status = AE_OK;
704 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300705 struct workqueue_struct *queue;
Len Brown72945b22006-07-12 22:46:42 -0400706 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
707 "Scheduling function [%p(%p)] for deferred execution.\n",
708 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 if (!function)
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400711 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400712
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 /*
714 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000715 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 * way that allows us to also free its memory inside the callee.
717 * Because we may want to schedule several tasks with different
718 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000719 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 */
Len Brown72945b22006-07-12 22:46:42 -0400721
David Howells65f27f32006-11-22 14:55:48 +0000722 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (!dpc)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800724 return_ACPI_STATUS(AE_NO_MEMORY);
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 dpc->function = function;
727 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800728
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300729 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
730 queue = (type == OSL_NOTIFY_HANDLER) ? kacpi_notify_wq : kacpid_wq;
731 if (!queue_work(queue, &dpc->work)) {
732 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
733 "Call to queue_work() failed.\n"));
734 status = AE_ERROR;
735 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800737 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
Len Brown4be44fc2005-08-05 00:44:28 -0400739
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400740EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Len Brown4be44fc2005-08-05 00:44:28 -0400742void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
744 flush_workqueue(kacpid_wq);
745}
Len Brown4be44fc2005-08-05 00:44:28 -0400746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747EXPORT_SYMBOL(acpi_os_wait_events_complete);
748
749/*
750 * Allocate the memory for a spinlock and initialize it.
751 */
Bob Moore967440e2006-06-23 17:04:00 -0400752acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753{
Bob Moore967440e2006-06-23 17:04:00 -0400754 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Patrick Mocheld550d982006-06-27 00:41:40 -0400756 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759/*
760 * Deallocate the memory for a spinlock.
761 */
Bob Moore967440e2006-06-23 17:04:00 -0400762void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763{
Patrick Mocheld550d982006-06-27 00:41:40 -0400764 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765}
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400768acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
Len Brown4be44fc2005-08-05 00:44:28 -0400770 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 sem = acpi_os_allocate(sizeof(struct semaphore));
773 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 memset(sem, 0, sizeof(struct semaphore));
776
777 sema_init(sem, initial_units);
778
Len Brown4be44fc2005-08-05 00:44:28 -0400779 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Len Brown4be44fc2005-08-05 00:44:28 -0400781 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
782 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Patrick Mocheld550d982006-06-27 00:41:40 -0400784 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787/*
788 * TODO: A better way to delete semaphores? Linux doesn't have a
789 * 'delete_semaphore()' function -- may result in an invalid
790 * pointer dereference for non-synchronized consumers. Should
791 * we at least check for blocked threads and signal/cancel them?
792 */
793
Len Brown4be44fc2005-08-05 00:44:28 -0400794acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
Len Brown4be44fc2005-08-05 00:44:28 -0400796 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400799 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Len Brown4be44fc2005-08-05 00:44:28 -0400801 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400803 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -0400804 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400805 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Patrick Mocheld550d982006-06-27 00:41:40 -0400807 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 * TODO: Support for units > 1?
812 */
Len Brown4be44fc2005-08-05 00:44:28 -0400813acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Len Brown4be44fc2005-08-05 00:44:28 -0400815 acpi_status status = AE_OK;
816 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400817 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -0400818 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400821 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400824 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Len Brown4be44fc2005-08-05 00:44:28 -0400826 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
827 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400829 if (timeout == ACPI_WAIT_FOREVER)
830 jiffies = MAX_SCHEDULE_TIMEOUT;
831 else
832 jiffies = msecs_to_jiffies(timeout);
833
834 ret = down_timeout(sem, jiffies);
835 if (ret)
836 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400839 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400840 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400841 handle, units, timeout,
842 acpi_format_exception(status)));
843 } else {
844 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400845 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400846 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848
Patrick Mocheld550d982006-06-27 00:41:40 -0400849 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852/*
853 * TODO: Support for units > 1?
854 */
Len Brown4be44fc2005-08-05 00:44:28 -0400855acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
Len Brown4be44fc2005-08-05 00:44:28 -0400857 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400860 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400863 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Len Brown4be44fc2005-08-05 00:44:28 -0400865 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
866 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 up(sem);
869
Patrick Mocheld550d982006-06-27 00:41:40 -0400870 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
Len Brown4be44fc2005-08-05 00:44:28 -0400872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400874u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876
877#ifdef ENABLE_DEBUGGER
878 if (acpi_in_debugger) {
879 u32 chars;
880
881 kdb_read(buffer, sizeof(line_buf));
882
883 /* remove the CR kdb includes */
884 chars = strlen(buffer) - 1;
885 buffer[chars] = '\0';
886 }
887#endif
888
889 return 0;
890}
Len Brown4be44fc2005-08-05 00:44:28 -0400891#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Len Brown4be44fc2005-08-05 00:44:28 -0400893acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Len Brown4be44fc2005-08-05 00:44:28 -0400895 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 case ACPI_SIGNAL_FATAL:
897 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
898 break;
899 case ACPI_SIGNAL_BREAKPOINT:
900 /*
901 * AML Breakpoint
902 * ACPI spec. says to treat it as a NOP unless
903 * you are debugging. So if/when we integrate
904 * AML debugger into the kernel debugger its
905 * hook will go here. But until then it is
906 * not useful to print anything on breakpoints.
907 */
908 break;
909 default:
910 break;
911 }
912
913 return AE_OK;
914}
Len Brown4be44fc2005-08-05 00:44:28 -0400915
Len Brown4be44fc2005-08-05 00:44:28 -0400916static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
918 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400919 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 if (!str || !*str)
922 return 0;
923
924 for (; count-- && str && *str; str++) {
925 if (isalnum(*str) || *str == ' ' || *str == ':')
926 *p++ = *str;
927 else if (*str == '\'' || *str == '"')
928 continue;
929 else
930 break;
931 }
932 *p = 0;
933
934 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938__setup("acpi_os_name=", acpi_os_name_setup);
939
Len Brownd4b7dc42008-01-23 20:50:56 -0500940static void __init set_osi_linux(unsigned int enable)
941{
942 if (osi_linux.enable != enable) {
943 osi_linux.enable = enable;
944 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
945 enable ? "Add": "Delet");
946 }
947 return;
948}
Len Brownf5076542007-05-30 00:10:38 -0400949
Len Brownd4b7dc42008-01-23 20:50:56 -0500950static void __init acpi_cmdline_osi_linux(unsigned int enable)
951{
952 osi_linux.cmdline = 1; /* cmdline set the default */
953 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -0400954
Len Brownd4b7dc42008-01-23 20:50:56 -0500955 return;
956}
957
958void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
959{
960 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
961
962 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
963
964 if (enable == -1)
965 return;
966
967 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
968
969 set_osi_linux(enable);
970
Len Brownf5076542007-05-30 00:10:38 -0400971 return;
972}
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974/*
Len Brownae00d812007-05-29 18:43:33 -0400975 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
976 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -0400978 * string starting with '!' disables that string
979 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 */
Len Brown46c1fbd2008-02-13 23:13:25 -0500981int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982{
983 if (str == NULL || *str == '\0') {
984 printk(KERN_INFO PREFIX "_OSI method disabled\n");
985 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -0400986 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -0500987 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -0400988 } else if (*str == '!') {
989 if (acpi_osi_invalidate(++str) == AE_OK)
990 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -0400991 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -0500992 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -0400993 } else if (*osi_additional_string == '\0') {
994 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
995 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
997
998 return 1;
999}
1000
1001__setup("acpi_osi=", acpi_osi_setup);
1002
1003/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001004static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
1006 printk(KERN_INFO PREFIX "serialize enabled\n");
1007
1008 acpi_gbl_all_methods_serialized = TRUE;
1009
1010 return 1;
1011}
1012
1013__setup("acpi_serialize", acpi_serialize_setup);
1014
1015/*
1016 * Wake and Run-Time GPES are expected to be separate.
1017 * We disable wake-GPEs at run-time to prevent spurious
1018 * interrupts.
1019 *
1020 * However, if a system exists that shares Wake and
1021 * Run-time events on the same GPE this flag is available
1022 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1023 */
Len Brown4be44fc2005-08-05 00:44:28 -04001024static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
1026 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1027
1028 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1029
1030 return 1;
1031}
1032
1033__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1034
Thomas Renningerdf92e692008-02-04 23:31:22 -08001035/* Check of resource interference between native drivers and ACPI
1036 * OperationRegions (SystemIO and System Memory only).
1037 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1038 * in arbitrary AML code and can interfere with legacy drivers.
1039 * acpi_enforce_resources= can be set to:
1040 *
1041 * - strict (2)
1042 * -> further driver trying to access the resources will not load
1043 * - lax (default) (1)
1044 * -> further driver trying to access the resources will load, but you
1045 * get a system message that something might go wrong...
1046 *
1047 * - no (0)
1048 * -> ACPI Operation Region resources will not be registered
1049 *
1050 */
1051#define ENFORCE_RESOURCES_STRICT 2
1052#define ENFORCE_RESOURCES_LAX 1
1053#define ENFORCE_RESOURCES_NO 0
1054
1055static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1056
1057static int __init acpi_enforce_resources_setup(char *str)
1058{
1059 if (str == NULL || *str == '\0')
1060 return 0;
1061
1062 if (!strcmp("strict", str))
1063 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1064 else if (!strcmp("lax", str))
1065 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1066 else if (!strcmp("no", str))
1067 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1068
1069 return 1;
1070}
1071
1072__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1073
1074/* Check for resource conflicts between ACPI OperationRegions and native
1075 * drivers */
Thomas Renninger443dea72008-02-04 23:31:23 -08001076int acpi_check_resource_conflict(struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001077{
1078 struct acpi_res_list *res_list_elem;
1079 int ioport;
1080 int clash = 0;
1081
1082 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1083 return 0;
1084 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1085 return 0;
1086
1087 ioport = res->flags & IORESOURCE_IO;
1088
1089 spin_lock(&acpi_res_lock);
1090 list_for_each_entry(res_list_elem, &resource_list_head,
1091 resource_list) {
1092 if (ioport && (res_list_elem->resource_type
1093 != ACPI_ADR_SPACE_SYSTEM_IO))
1094 continue;
1095 if (!ioport && (res_list_elem->resource_type
1096 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1097 continue;
1098
1099 if (res->end < res_list_elem->start
1100 || res_list_elem->end < res->start)
1101 continue;
1102 clash = 1;
1103 break;
1104 }
1105 spin_unlock(&acpi_res_lock);
1106
1107 if (clash) {
1108 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Jean Delvarebd129352008-02-27 20:56:01 +01001109 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
Thomas Renningerdf92e692008-02-04 23:31:22 -08001110 " conflicts with ACPI region %s"
1111 " [0x%llx-0x%llx]\n",
1112 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1113 ? KERN_WARNING : KERN_ERR,
1114 ioport ? "I/O" : "Memory", res->name,
1115 (long long) res->start, (long long) res->end,
1116 res_list_elem->name,
1117 (long long) res_list_elem->start,
1118 (long long) res_list_elem->end);
1119 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1120 }
1121 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1122 return -EBUSY;
1123 }
1124 return 0;
1125}
Thomas Renninger443dea72008-02-04 23:31:23 -08001126EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001127
1128int acpi_check_region(resource_size_t start, resource_size_t n,
1129 const char *name)
1130{
1131 struct resource res = {
1132 .start = start,
1133 .end = start + n - 1,
1134 .name = name,
1135 .flags = IORESOURCE_IO,
1136 };
1137
1138 return acpi_check_resource_conflict(&res);
1139}
1140EXPORT_SYMBOL(acpi_check_region);
1141
1142int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1143 const char *name)
1144{
1145 struct resource res = {
1146 .start = start,
1147 .end = start + n - 1,
1148 .name = name,
1149 .flags = IORESOURCE_MEM,
1150 };
1151
1152 return acpi_check_resource_conflict(&res);
1153
1154}
1155EXPORT_SYMBOL(acpi_check_mem_region);
1156
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157/*
Robert Moore73459f72005-06-24 00:00:00 -04001158 * Acquire a spinlock.
1159 *
1160 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001161 */
1162
Bob Moore967440e2006-06-23 17:04:00 -04001163acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001164{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001165 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001166 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001167 return flags;
1168}
1169
1170/*
1171 * Release a spinlock. See above.
1172 */
1173
Bob Moore967440e2006-06-23 17:04:00 -04001174void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001175{
Bob Moore967440e2006-06-23 17:04:00 -04001176 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001177}
1178
Robert Moore73459f72005-06-24 00:00:00 -04001179#ifndef ACPI_USE_LOCAL_CACHE
1180
1181/*******************************************************************************
1182 *
1183 * FUNCTION: acpi_os_create_cache
1184 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001185 * PARAMETERS: name - Ascii name for the cache
1186 * size - Size of each cached object
1187 * depth - Maximum depth of the cache (in objects) <ignored>
1188 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001189 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001190 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001191 *
1192 * DESCRIPTION: Create a cache object
1193 *
1194 ******************************************************************************/
1195
1196acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001197acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001198{
Paul Mundt20c2df82007-07-20 10:11:58 +09001199 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001200 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001201 return AE_ERROR;
1202 else
1203 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001204}
1205
1206/*******************************************************************************
1207 *
1208 * FUNCTION: acpi_os_purge_cache
1209 *
1210 * PARAMETERS: Cache - Handle to cache object
1211 *
1212 * RETURN: Status
1213 *
1214 * DESCRIPTION: Free all objects within the requested cache.
1215 *
1216 ******************************************************************************/
1217
Len Brown4be44fc2005-08-05 00:44:28 -04001218acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001219{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001220 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001221 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001222}
1223
1224/*******************************************************************************
1225 *
1226 * FUNCTION: acpi_os_delete_cache
1227 *
1228 * PARAMETERS: Cache - Handle to cache object
1229 *
1230 * RETURN: Status
1231 *
1232 * DESCRIPTION: Free all objects within the requested cache and delete the
1233 * cache object.
1234 *
1235 ******************************************************************************/
1236
Len Brown4be44fc2005-08-05 00:44:28 -04001237acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001238{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001239 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001240 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001241}
1242
1243/*******************************************************************************
1244 *
1245 * FUNCTION: acpi_os_release_object
1246 *
1247 * PARAMETERS: Cache - Handle to cache object
1248 * Object - The object to be released
1249 *
1250 * RETURN: None
1251 *
1252 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1253 * the object is deleted.
1254 *
1255 ******************************************************************************/
1256
Len Brown4be44fc2005-08-05 00:44:28 -04001257acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001258{
Len Brown4be44fc2005-08-05 00:44:28 -04001259 kmem_cache_free(cache, object);
1260 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001261}
1262
Len Brown5a4e1432008-01-23 20:01:22 -05001263/**
1264 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1265 *
1266 * Returns 0 on success
1267 */
Adrian Bunk12d39312008-01-29 00:10:12 +02001268static int acpi_dmi_dump(void)
Len Brown5a4e1432008-01-23 20:01:22 -05001269{
1270
1271 if (!dmi_available)
1272 return -1;
1273
1274 printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001275 dmi_get_system_info(DMI_SYS_VENDOR));
Len Brown5a4e1432008-01-23 20:01:22 -05001276 printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001277 dmi_get_system_info(DMI_PRODUCT_NAME));
Len Brown5a4e1432008-01-23 20:01:22 -05001278 printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001279 dmi_get_system_info(DMI_PRODUCT_VERSION));
Len Brown5a4e1432008-01-23 20:01:22 -05001280 printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001281 dmi_get_system_info(DMI_BOARD_NAME));
Len Brown5a4e1432008-01-23 20:01:22 -05001282 printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001283 dmi_get_system_info(DMI_BIOS_VENDOR));
Len Brown5a4e1432008-01-23 20:01:22 -05001284 printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001285 dmi_get_system_info(DMI_BIOS_DATE));
Len Brown5a4e1432008-01-23 20:01:22 -05001286
1287 return 0;
1288}
1289
1290
Bob Mooreb229cf92006-04-21 17:15:00 -04001291/******************************************************************************
1292 *
1293 * FUNCTION: acpi_os_validate_interface
1294 *
1295 * PARAMETERS: interface - Requested interface to be validated
1296 *
1297 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1298 *
1299 * DESCRIPTION: Match an interface string to the interfaces supported by the
1300 * host. Strings originate from an AML call to the _OSI method.
1301 *
1302 *****************************************************************************/
1303
1304acpi_status
1305acpi_os_validate_interface (char *interface)
1306{
Len Brownae00d812007-05-29 18:43:33 -04001307 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1308 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001309 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001310
1311 printk(KERN_NOTICE PREFIX
1312 "BIOS _OSI(Linux) query %s%s\n",
1313 osi_linux.enable ? "honored" : "ignored",
1314 osi_linux.cmdline ? " via cmdline" :
1315 osi_linux.dmi ? " via DMI" : "");
1316
1317 if (!osi_linux.dmi) {
1318 if (acpi_dmi_dump())
1319 printk(KERN_NOTICE PREFIX
1320 "[please extract dmidecode output]\n");
Len Brownf40cd6f2008-01-23 20:04:28 -05001321 printk(KERN_NOTICE PREFIX
Len Brownd4b7dc42008-01-23 20:50:56 -05001322 "Please send DMI info above to "
1323 "linux-acpi@vger.kernel.org\n");
1324 }
1325 if (!osi_linux.known && !osi_linux.cmdline) {
1326 printk(KERN_NOTICE PREFIX
1327 "If \"acpi_osi=%sLinux\" works better, "
1328 "please notify linux-acpi@vger.kernel.org\n",
1329 osi_linux.enable ? "!" : "");
1330 }
1331
1332 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001333 return AE_OK;
1334 }
Len Brownae00d812007-05-29 18:43:33 -04001335 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001336}
1337
Bob Mooreb229cf92006-04-21 17:15:00 -04001338/******************************************************************************
1339 *
1340 * FUNCTION: acpi_os_validate_address
1341 *
1342 * PARAMETERS: space_id - ACPI space ID
1343 * address - Physical address
1344 * length - Address length
1345 *
1346 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1347 * should return AE_AML_ILLEGAL_ADDRESS.
1348 *
1349 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1350 * the addresses accessed by AML operation regions.
1351 *
1352 *****************************************************************************/
1353
1354acpi_status
1355acpi_os_validate_address (
1356 u8 space_id,
1357 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001358 acpi_size length,
1359 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001360{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001361 struct acpi_res_list *res;
1362 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1363 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001364
Thomas Renningerdf92e692008-02-04 23:31:22 -08001365 switch (space_id) {
1366 case ACPI_ADR_SPACE_SYSTEM_IO:
1367 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1368 /* Only interference checks against SystemIO and SytemMemory
1369 are needed */
1370 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1371 if (!res)
1372 return AE_OK;
1373 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1374 strlcpy(res->name, name, 5);
1375 res->start = address;
1376 res->end = address + length - 1;
1377 res->resource_type = space_id;
1378 spin_lock(&acpi_res_lock);
1379 list_add(&res->resource_list, &resource_list_head);
1380 spin_unlock(&acpi_res_lock);
1381 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1382 "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1383 ? "SystemIO" : "System Memory",
1384 (unsigned long long)res->start,
1385 (unsigned long long)res->end,
1386 res->name);
1387 break;
1388 case ACPI_ADR_SPACE_PCI_CONFIG:
1389 case ACPI_ADR_SPACE_EC:
1390 case ACPI_ADR_SPACE_SMBUS:
1391 case ACPI_ADR_SPACE_CMOS:
1392 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1393 case ACPI_ADR_SPACE_DATA_TABLE:
1394 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1395 break;
1396 }
1397 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001398}
1399
Robert Moore73459f72005-06-24 00:00:00 -04001400#endif