Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * acpi_osl.c - OS-dependent functions ($Revision: 83 $) | |
3 | * | |
4 | * Copyright (C) 2000 Andrew Henroid | |
5 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | |
6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
7 | * | |
8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 | * | |
24 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
25 | * | |
26 | */ | |
27 | ||
1da177e4 LT |
28 | #include <linux/module.h> |
29 | #include <linux/kernel.h> | |
30 | #include <linux/slab.h> | |
31 | #include <linux/mm.h> | |
32 | #include <linux/pci.h> | |
1da177e4 LT |
33 | #include <linux/interrupt.h> |
34 | #include <linux/kmod.h> | |
35 | #include <linux/delay.h> | |
f507654d | 36 | #include <linux/dmi.h> |
1da177e4 LT |
37 | #include <linux/workqueue.h> |
38 | #include <linux/nmi.h> | |
ad71860a | 39 | #include <linux/acpi.h> |
1da177e4 LT |
40 | #include <acpi/acpi.h> |
41 | #include <asm/io.h> | |
42 | #include <acpi/acpi_bus.h> | |
43 | #include <acpi/processor.h> | |
44 | #include <asm/uaccess.h> | |
45 | ||
46 | #include <linux/efi.h> | |
df92e695 TR |
47 | #include <linux/ioport.h> |
48 | #include <linux/list.h> | |
1da177e4 | 49 | |
1da177e4 | 50 | #define _COMPONENT ACPI_OS_SERVICES |
f52fd66d | 51 | ACPI_MODULE_NAME("osl"); |
1da177e4 | 52 | #define PREFIX "ACPI: " |
4be44fcd LB |
53 | struct acpi_os_dpc { |
54 | acpi_osd_exec_callback function; | |
55 | void *context; | |
65f27f38 | 56 | struct work_struct work; |
1da177e4 LT |
57 | }; |
58 | ||
59 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | |
60 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE | |
61 | #endif | |
62 | ||
63 | #ifdef ENABLE_DEBUGGER | |
64 | #include <linux/kdb.h> | |
65 | ||
66 | /* stuff for debugger support */ | |
67 | int acpi_in_debugger; | |
68 | EXPORT_SYMBOL(acpi_in_debugger); | |
69 | ||
70 | extern char line_buf[80]; | |
4be44fcd | 71 | #endif /*ENABLE_DEBUGGER */ |
1da177e4 LT |
72 | |
73 | static unsigned int acpi_irq_irq; | |
74 | static acpi_osd_handler acpi_irq_handler; | |
75 | static void *acpi_irq_context; | |
76 | static struct workqueue_struct *kacpid_wq; | |
88db5e14 | 77 | static struct workqueue_struct *kacpi_notify_wq; |
1da177e4 | 78 | |
df92e695 TR |
79 | struct acpi_res_list { |
80 | resource_size_t start; | |
81 | resource_size_t end; | |
82 | acpi_adr_space_type resource_type; /* IO port, System memory, ...*/ | |
83 | char name[5]; /* only can have a length of 4 chars, make use of this | |
84 | one instead of res->name, no need to kalloc then */ | |
85 | struct list_head resource_list; | |
86 | }; | |
87 | ||
88 | static LIST_HEAD(resource_list_head); | |
89 | static DEFINE_SPINLOCK(acpi_res_lock); | |
90 | ||
ae00d812 LB |
91 | #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ |
92 | static char osi_additional_string[OSI_STRING_LENGTH_MAX]; | |
93 | ||
9cbc7960 ÉP |
94 | #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD |
95 | static int acpi_no_initrd_override; | |
96 | #endif | |
97 | ||
d4b7dc49 LB |
98 | /* |
99 | * "Ode to _OSI(Linux)" | |
100 | * | |
101 | * osi_linux -- Control response to BIOS _OSI(Linux) query. | |
102 | * | |
103 | * As Linux evolves, the features that it supports change. | |
104 | * So an OSI string such as "Linux" is not specific enough | |
105 | * to be useful across multiple versions of Linux. It | |
106 | * doesn't identify any particular feature, interface, | |
107 | * or even any particular version of Linux... | |
108 | * | |
109 | * Unfortunately, Linux-2.6.22 and earlier responded "yes" | |
110 | * to a BIOS _OSI(Linux) query. When | |
111 | * a reference mobile BIOS started using it, its use | |
112 | * started to spread to many vendor platforms. | |
113 | * As it is not supportable, we need to halt that spread. | |
114 | * | |
115 | * Today, most BIOS references to _OSI(Linux) are noise -- | |
116 | * they have no functional effect and are just dead code | |
117 | * carried over from the reference BIOS. | |
118 | * | |
119 | * The next most common case is that _OSI(Linux) harms Linux, | |
120 | * usually by causing the BIOS to follow paths that are | |
121 | * not tested during Windows validation. | |
122 | * | |
123 | * Finally, there is a short list of platforms | |
124 | * where OSI(Linux) benefits Linux. | |
125 | * | |
126 | * In Linux-2.6.23, OSI(Linux) is first disabled by default. | |
127 | * DMI is used to disable the dmesg warning about OSI(Linux) | |
128 | * on platforms where it is known to have no effect. | |
129 | * But a dmesg warning remains for systems where | |
130 | * we do not know if OSI(Linux) is good or bad for the system. | |
131 | * DMI is also used to enable OSI(Linux) for the machines | |
132 | * that are known to need it. | |
133 | * | |
134 | * BIOS writers should NOT query _OSI(Linux) on future systems. | |
135 | * It will be ignored by default, and to get Linux to | |
136 | * not ignore it will require a kernel source update to | |
137 | * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation. | |
138 | */ | |
139 | #define OSI_LINUX_ENABLE 0 | |
140 | ||
1d15d84e | 141 | static struct osi_linux { |
d4b7dc49 LB |
142 | unsigned int enable:1; |
143 | unsigned int dmi:1; | |
144 | unsigned int cmdline:1; | |
145 | unsigned int known:1; | |
146 | } osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0}; | |
f507654d | 147 | |
9a47cdb1 BH |
148 | static void __init acpi_request_region (struct acpi_generic_address *addr, |
149 | unsigned int length, char *desc) | |
150 | { | |
151 | struct resource *res; | |
152 | ||
153 | if (!addr->address || !length) | |
154 | return; | |
155 | ||
eee3c859 | 156 | if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
9a47cdb1 | 157 | res = request_region(addr->address, length, desc); |
eee3c859 | 158 | else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
9a47cdb1 BH |
159 | res = request_mem_region(addr->address, length, desc); |
160 | } | |
161 | ||
162 | static int __init acpi_reserve_resources(void) | |
163 | { | |
eee3c859 | 164 | acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
165 | "ACPI PM1a_EVT_BLK"); |
166 | ||
eee3c859 | 167 | acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
168 | "ACPI PM1b_EVT_BLK"); |
169 | ||
eee3c859 | 170 | acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
171 | "ACPI PM1a_CNT_BLK"); |
172 | ||
eee3c859 | 173 | acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
174 | "ACPI PM1b_CNT_BLK"); |
175 | ||
eee3c859 LB |
176 | if (acpi_gbl_FADT.pm_timer_length == 4) |
177 | acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR"); | |
9a47cdb1 | 178 | |
eee3c859 | 179 | acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length, |
9a47cdb1 BH |
180 | "ACPI PM2_CNT_BLK"); |
181 | ||
182 | /* Length of GPE blocks must be a non-negative multiple of 2 */ | |
183 | ||
eee3c859 LB |
184 | if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) |
185 | acpi_request_region(&acpi_gbl_FADT.xgpe0_block, | |
186 | acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK"); | |
9a47cdb1 | 187 | |
eee3c859 LB |
188 | if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) |
189 | acpi_request_region(&acpi_gbl_FADT.xgpe1_block, | |
190 | acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); | |
9a47cdb1 BH |
191 | |
192 | return 0; | |
193 | } | |
194 | device_initcall(acpi_reserve_resources); | |
195 | ||
dd272b57 | 196 | acpi_status __init acpi_os_initialize(void) |
1da177e4 LT |
197 | { |
198 | return AE_OK; | |
199 | } | |
200 | ||
4be44fcd | 201 | acpi_status acpi_os_initialize1(void) |
1da177e4 LT |
202 | { |
203 | /* | |
204 | * Initialize PCI configuration space access, as we'll need to access | |
205 | * it while walking the namespace (bus 0 and root bridges w/ _BBNs). | |
206 | */ | |
1da177e4 | 207 | if (!raw_pci_ops) { |
4be44fcd LB |
208 | printk(KERN_ERR PREFIX |
209 | "Access to PCI configuration space unavailable\n"); | |
1da177e4 LT |
210 | return AE_NULL_ENTRY; |
211 | } | |
1da177e4 | 212 | kacpid_wq = create_singlethread_workqueue("kacpid"); |
88db5e14 | 213 | kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify"); |
1da177e4 | 214 | BUG_ON(!kacpid_wq); |
88db5e14 | 215 | BUG_ON(!kacpi_notify_wq); |
1da177e4 LT |
216 | return AE_OK; |
217 | } | |
218 | ||
4be44fcd | 219 | acpi_status acpi_os_terminate(void) |
1da177e4 LT |
220 | { |
221 | if (acpi_irq_handler) { | |
222 | acpi_os_remove_interrupt_handler(acpi_irq_irq, | |
223 | acpi_irq_handler); | |
224 | } | |
225 | ||
226 | destroy_workqueue(kacpid_wq); | |
88db5e14 | 227 | destroy_workqueue(kacpi_notify_wq); |
1da177e4 LT |
228 | |
229 | return AE_OK; | |
230 | } | |
231 | ||
4be44fcd | 232 | void acpi_os_printf(const char *fmt, ...) |
1da177e4 LT |
233 | { |
234 | va_list args; | |
235 | va_start(args, fmt); | |
236 | acpi_os_vprintf(fmt, args); | |
237 | va_end(args); | |
238 | } | |
4be44fcd | 239 | |
4be44fcd | 240 | void acpi_os_vprintf(const char *fmt, va_list args) |
1da177e4 LT |
241 | { |
242 | static char buffer[512]; | |
4be44fcd | 243 | |
1da177e4 LT |
244 | vsprintf(buffer, fmt, args); |
245 | ||
246 | #ifdef ENABLE_DEBUGGER | |
247 | if (acpi_in_debugger) { | |
248 | kdb_printf("%s", buffer); | |
249 | } else { | |
250 | printk("%s", buffer); | |
251 | } | |
252 | #else | |
253 | printk("%s", buffer); | |
254 | #endif | |
255 | } | |
256 | ||
ad71860a | 257 | acpi_physical_address __init acpi_os_get_root_pointer(void) |
1da177e4 LT |
258 | { |
259 | if (efi_enabled) { | |
b2c99e3c | 260 | if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) |
ad71860a | 261 | return efi.acpi20; |
b2c99e3c | 262 | else if (efi.acpi != EFI_INVALID_TABLE_ADDR) |
ad71860a | 263 | return efi.acpi; |
1da177e4 | 264 | else { |
4be44fcd LB |
265 | printk(KERN_ERR PREFIX |
266 | "System description tables not found\n"); | |
ad71860a | 267 | return 0; |
1da177e4 | 268 | } |
239665a3 LB |
269 | } else { |
270 | acpi_physical_address pa = 0; | |
271 | ||
272 | acpi_find_root_pointer(&pa); | |
273 | return pa; | |
274 | } | |
1da177e4 LT |
275 | } |
276 | ||
2fdf0741 JB |
277 | void __iomem *__init_refok |
278 | acpi_os_map_memory(acpi_physical_address phys, acpi_size size) | |
1da177e4 | 279 | { |
9f4fd61f BH |
280 | if (phys > ULONG_MAX) { |
281 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); | |
70c0846e | 282 | return NULL; |
1da177e4 | 283 | } |
ad71860a AS |
284 | if (acpi_gbl_permanent_mmap) |
285 | /* | |
286 | * ioremap checks to ensure this is in reserved space | |
287 | */ | |
288 | return ioremap((unsigned long)phys, size); | |
289 | else | |
290 | return __acpi_map_table((unsigned long)phys, size); | |
1da177e4 | 291 | } |
55a82ab3 | 292 | EXPORT_SYMBOL_GPL(acpi_os_map_memory); |
1da177e4 | 293 | |
4be44fcd | 294 | void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) |
1da177e4 | 295 | { |
ad71860a AS |
296 | if (acpi_gbl_permanent_mmap) { |
297 | iounmap(virt); | |
298 | } | |
1da177e4 | 299 | } |
55a82ab3 | 300 | EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); |
1da177e4 LT |
301 | |
302 | #ifdef ACPI_FUTURE_USAGE | |
303 | acpi_status | |
4be44fcd | 304 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
1da177e4 | 305 | { |
4be44fcd | 306 | if (!phys || !virt) |
1da177e4 LT |
307 | return AE_BAD_PARAMETER; |
308 | ||
309 | *phys = virt_to_phys(virt); | |
310 | ||
311 | return AE_OK; | |
312 | } | |
313 | #endif | |
314 | ||
315 | #define ACPI_MAX_OVERRIDE_LEN 100 | |
316 | ||
317 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; | |
318 | ||
319 | acpi_status | |
4be44fcd LB |
320 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
321 | acpi_string * new_val) | |
1da177e4 LT |
322 | { |
323 | if (!init_val || !new_val) | |
324 | return AE_BAD_PARAMETER; | |
325 | ||
326 | *new_val = NULL; | |
4be44fcd | 327 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
1da177e4 | 328 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
4be44fcd | 329 | acpi_os_name); |
1da177e4 LT |
330 | *new_val = acpi_os_name; |
331 | } | |
332 | ||
333 | return AE_OK; | |
334 | } | |
335 | ||
71fc47a9 MG |
336 | #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD |
337 | struct acpi_table_header *acpi_find_dsdt_initrd(void) | |
338 | { | |
339 | struct file *firmware_file; | |
340 | mm_segment_t oldfs; | |
341 | unsigned long len, len2; | |
342 | struct acpi_table_header *dsdt_buffer, *ret = NULL; | |
343 | struct kstat stat; | |
344 | char *ramfs_dsdt_name = "/DSDT.aml"; | |
345 | ||
b0b23e0a | 346 | printk(KERN_INFO PREFIX "Checking initramfs for custom DSDT\n"); |
71fc47a9 MG |
347 | |
348 | /* | |
349 | * Never do this at home, only the user-space is allowed to open a file. | |
04d94886 LB |
350 | * The clean way would be to use the firmware loader. |
351 | * But this code must be run before there is any userspace available. | |
352 | * A static/init firmware infrastructure doesn't exist yet... | |
71fc47a9 | 353 | */ |
04d94886 | 354 | if (vfs_stat(ramfs_dsdt_name, &stat) < 0) |
71fc47a9 | 355 | return ret; |
71fc47a9 MG |
356 | |
357 | len = stat.size; | |
358 | /* check especially against empty files */ | |
359 | if (len <= 4) { | |
04d94886 | 360 | printk(KERN_ERR PREFIX "Failed: DSDT only %lu bytes.\n", len); |
71fc47a9 MG |
361 | return ret; |
362 | } | |
363 | ||
364 | firmware_file = filp_open(ramfs_dsdt_name, O_RDONLY, 0); | |
365 | if (IS_ERR(firmware_file)) { | |
04d94886 | 366 | printk(KERN_ERR PREFIX "Failed to open %s.\n", ramfs_dsdt_name); |
71fc47a9 MG |
367 | return ret; |
368 | } | |
369 | ||
04d94886 | 370 | dsdt_buffer = kmalloc(len, GFP_ATOMIC); |
71fc47a9 | 371 | if (!dsdt_buffer) { |
04d94886 | 372 | printk(KERN_ERR PREFIX "Failed to allocate %lu bytes.\n", len); |
71fc47a9 MG |
373 | goto err; |
374 | } | |
375 | ||
376 | oldfs = get_fs(); | |
377 | set_fs(KERNEL_DS); | |
04d94886 LB |
378 | len2 = vfs_read(firmware_file, (char __user *)dsdt_buffer, len, |
379 | &firmware_file->f_pos); | |
71fc47a9 MG |
380 | set_fs(oldfs); |
381 | if (len2 < len) { | |
04d94886 LB |
382 | printk(KERN_ERR PREFIX "Failed to read %lu bytes from %s.\n", |
383 | len, ramfs_dsdt_name); | |
71fc47a9 MG |
384 | ACPI_FREE(dsdt_buffer); |
385 | goto err; | |
386 | } | |
387 | ||
04d94886 LB |
388 | printk(KERN_INFO PREFIX "Found %lu byte DSDT in %s.\n", |
389 | len, ramfs_dsdt_name); | |
71fc47a9 MG |
390 | ret = dsdt_buffer; |
391 | err: | |
392 | filp_close(firmware_file, NULL); | |
393 | return ret; | |
394 | } | |
395 | #endif | |
396 | ||
1da177e4 | 397 | acpi_status |
4be44fcd LB |
398 | acpi_os_table_override(struct acpi_table_header * existing_table, |
399 | struct acpi_table_header ** new_table) | |
1da177e4 LT |
400 | { |
401 | if (!existing_table || !new_table) | |
402 | return AE_BAD_PARAMETER; | |
403 | ||
71fc47a9 MG |
404 | *new_table = NULL; |
405 | ||
1da177e4 LT |
406 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
407 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) | |
4be44fcd | 408 | *new_table = (struct acpi_table_header *)AmlCode; |
1da177e4 | 409 | #endif |
71fc47a9 | 410 | #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD |
9cbc7960 ÉP |
411 | if ((strncmp(existing_table->signature, "DSDT", 4) == 0) && |
412 | !acpi_no_initrd_override) { | |
04d94886 LB |
413 | struct acpi_table_header *initrd_table; |
414 | ||
415 | initrd_table = acpi_find_dsdt_initrd(); | |
71fc47a9 MG |
416 | if (initrd_table) |
417 | *new_table = initrd_table; | |
418 | } | |
1da177e4 | 419 | #endif |
6ed31e92 ÉP |
420 | if (*new_table != NULL) { |
421 | printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], " | |
422 | "this is unsafe: tainting kernel\n", | |
423 | existing_table->signature, | |
424 | existing_table->oem_table_id); | |
425 | add_taint(TAINT_OVERRIDDEN_ACPI_TABLE); | |
426 | } | |
1da177e4 LT |
427 | return AE_OK; |
428 | } | |
429 | ||
9cbc7960 ÉP |
430 | #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD |
431 | int __init acpi_no_initrd_override_setup(char *s) | |
432 | { | |
433 | acpi_no_initrd_override = 1; | |
434 | return 1; | |
435 | } | |
436 | __setup("acpi_no_initrd_override", acpi_no_initrd_override_setup); | |
437 | #endif | |
438 | ||
7d12e780 | 439 | static irqreturn_t acpi_irq(int irq, void *dev_id) |
1da177e4 | 440 | { |
5229e87d LB |
441 | u32 handled; |
442 | ||
443 | handled = (*acpi_irq_handler) (acpi_irq_context); | |
444 | ||
445 | if (handled) { | |
446 | acpi_irq_handled++; | |
447 | return IRQ_HANDLED; | |
448 | } else | |
449 | return IRQ_NONE; | |
1da177e4 LT |
450 | } |
451 | ||
452 | acpi_status | |
4be44fcd LB |
453 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
454 | void *context) | |
1da177e4 LT |
455 | { |
456 | unsigned int irq; | |
457 | ||
5229e87d LB |
458 | acpi_irq_stats_init(); |
459 | ||
1da177e4 LT |
460 | /* |
461 | * Ignore the GSI from the core, and use the value in our copy of the | |
462 | * FADT. It may not be the same if an interrupt source override exists | |
463 | * for the SCI. | |
464 | */ | |
cee324b1 | 465 | gsi = acpi_gbl_FADT.sci_interrupt; |
1da177e4 LT |
466 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { |
467 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", | |
468 | gsi); | |
469 | return AE_OK; | |
470 | } | |
471 | ||
472 | acpi_irq_handler = handler; | |
473 | acpi_irq_context = context; | |
dace1453 | 474 | if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) { |
1da177e4 LT |
475 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); |
476 | return AE_NOT_ACQUIRED; | |
477 | } | |
478 | acpi_irq_irq = irq; | |
479 | ||
480 | return AE_OK; | |
481 | } | |
482 | ||
4be44fcd | 483 | acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) |
1da177e4 LT |
484 | { |
485 | if (irq) { | |
486 | free_irq(irq, acpi_irq); | |
487 | acpi_irq_handler = NULL; | |
488 | acpi_irq_irq = 0; | |
489 | } | |
490 | ||
491 | return AE_OK; | |
492 | } | |
493 | ||
494 | /* | |
495 | * Running in interpreter thread context, safe to sleep | |
496 | */ | |
497 | ||
4be44fcd | 498 | void acpi_os_sleep(acpi_integer ms) |
1da177e4 | 499 | { |
01a527ec | 500 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
1da177e4 | 501 | } |
4be44fcd | 502 | |
4be44fcd | 503 | void acpi_os_stall(u32 us) |
1da177e4 LT |
504 | { |
505 | while (us) { | |
506 | u32 delay = 1000; | |
507 | ||
508 | if (delay > us) | |
509 | delay = us; | |
510 | udelay(delay); | |
511 | touch_nmi_watchdog(); | |
512 | us -= delay; | |
513 | } | |
514 | } | |
4be44fcd | 515 | |
1da177e4 LT |
516 | /* |
517 | * Support ACPI 3.0 AML Timer operand | |
518 | * Returns 64-bit free-running, monotonically increasing timer | |
519 | * with 100ns granularity | |
520 | */ | |
4be44fcd | 521 | u64 acpi_os_get_timer(void) |
1da177e4 LT |
522 | { |
523 | static u64 t; | |
524 | ||
525 | #ifdef CONFIG_HPET | |
526 | /* TBD: use HPET if available */ | |
527 | #endif | |
528 | ||
529 | #ifdef CONFIG_X86_PM_TIMER | |
530 | /* TBD: default to PM timer if HPET was not available */ | |
531 | #endif | |
532 | if (!t) | |
533 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); | |
534 | ||
535 | return ++t; | |
536 | } | |
537 | ||
4be44fcd | 538 | acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width) |
1da177e4 LT |
539 | { |
540 | u32 dummy; | |
541 | ||
542 | if (!value) | |
543 | value = &dummy; | |
544 | ||
49fbabf5 ZY |
545 | *value = 0; |
546 | if (width <= 8) { | |
4be44fcd | 547 | *(u8 *) value = inb(port); |
49fbabf5 | 548 | } else if (width <= 16) { |
4be44fcd | 549 | *(u16 *) value = inw(port); |
49fbabf5 | 550 | } else if (width <= 32) { |
4be44fcd | 551 | *(u32 *) value = inl(port); |
49fbabf5 | 552 | } else { |
1da177e4 LT |
553 | BUG(); |
554 | } | |
555 | ||
556 | return AE_OK; | |
557 | } | |
4be44fcd | 558 | |
1da177e4 LT |
559 | EXPORT_SYMBOL(acpi_os_read_port); |
560 | ||
4be44fcd | 561 | acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width) |
1da177e4 | 562 | { |
49fbabf5 | 563 | if (width <= 8) { |
1da177e4 | 564 | outb(value, port); |
49fbabf5 | 565 | } else if (width <= 16) { |
1da177e4 | 566 | outw(value, port); |
49fbabf5 | 567 | } else if (width <= 32) { |
1da177e4 | 568 | outl(value, port); |
49fbabf5 | 569 | } else { |
1da177e4 LT |
570 | BUG(); |
571 | } | |
572 | ||
573 | return AE_OK; | |
574 | } | |
4be44fcd | 575 | |
1da177e4 LT |
576 | EXPORT_SYMBOL(acpi_os_write_port); |
577 | ||
578 | acpi_status | |
4be44fcd | 579 | acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width) |
1da177e4 | 580 | { |
4be44fcd LB |
581 | u32 dummy; |
582 | void __iomem *virt_addr; | |
1da177e4 | 583 | |
9f4fd61f | 584 | virt_addr = ioremap(phys_addr, width); |
1da177e4 LT |
585 | if (!value) |
586 | value = &dummy; | |
587 | ||
588 | switch (width) { | |
589 | case 8: | |
4be44fcd | 590 | *(u8 *) value = readb(virt_addr); |
1da177e4 LT |
591 | break; |
592 | case 16: | |
4be44fcd | 593 | *(u16 *) value = readw(virt_addr); |
1da177e4 LT |
594 | break; |
595 | case 32: | |
4be44fcd | 596 | *(u32 *) value = readl(virt_addr); |
1da177e4 LT |
597 | break; |
598 | default: | |
599 | BUG(); | |
600 | } | |
601 | ||
9f4fd61f | 602 | iounmap(virt_addr); |
1da177e4 LT |
603 | |
604 | return AE_OK; | |
605 | } | |
606 | ||
607 | acpi_status | |
4be44fcd | 608 | acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width) |
1da177e4 | 609 | { |
4be44fcd | 610 | void __iomem *virt_addr; |
1da177e4 | 611 | |
9f4fd61f | 612 | virt_addr = ioremap(phys_addr, width); |
1da177e4 LT |
613 | |
614 | switch (width) { | |
615 | case 8: | |
616 | writeb(value, virt_addr); | |
617 | break; | |
618 | case 16: | |
619 | writew(value, virt_addr); | |
620 | break; | |
621 | case 32: | |
622 | writel(value, virt_addr); | |
623 | break; | |
624 | default: | |
625 | BUG(); | |
626 | } | |
627 | ||
9f4fd61f | 628 | iounmap(virt_addr); |
1da177e4 LT |
629 | |
630 | return AE_OK; | |
631 | } | |
632 | ||
1da177e4 | 633 | acpi_status |
4be44fcd LB |
634 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
635 | void *value, u32 width) | |
1da177e4 LT |
636 | { |
637 | int result, size; | |
638 | ||
639 | if (!value) | |
640 | return AE_BAD_PARAMETER; | |
641 | ||
642 | switch (width) { | |
643 | case 8: | |
644 | size = 1; | |
645 | break; | |
646 | case 16: | |
647 | size = 2; | |
648 | break; | |
649 | case 32: | |
650 | size = 4; | |
651 | break; | |
652 | default: | |
653 | return AE_ERROR; | |
654 | } | |
655 | ||
656 | BUG_ON(!raw_pci_ops); | |
657 | ||
658 | result = raw_pci_ops->read(pci_id->segment, pci_id->bus, | |
4be44fcd LB |
659 | PCI_DEVFN(pci_id->device, pci_id->function), |
660 | reg, size, value); | |
1da177e4 LT |
661 | |
662 | return (result ? AE_ERROR : AE_OK); | |
663 | } | |
4be44fcd | 664 | |
1da177e4 | 665 | acpi_status |
4be44fcd LB |
666 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
667 | acpi_integer value, u32 width) | |
1da177e4 LT |
668 | { |
669 | int result, size; | |
670 | ||
671 | switch (width) { | |
672 | case 8: | |
673 | size = 1; | |
674 | break; | |
675 | case 16: | |
676 | size = 2; | |
677 | break; | |
678 | case 32: | |
679 | size = 4; | |
680 | break; | |
681 | default: | |
682 | return AE_ERROR; | |
683 | } | |
684 | ||
685 | BUG_ON(!raw_pci_ops); | |
686 | ||
687 | result = raw_pci_ops->write(pci_id->segment, pci_id->bus, | |
4be44fcd LB |
688 | PCI_DEVFN(pci_id->device, pci_id->function), |
689 | reg, size, value); | |
1da177e4 LT |
690 | |
691 | return (result ? AE_ERROR : AE_OK); | |
692 | } | |
693 | ||
694 | /* TODO: Change code to take advantage of driver model more */ | |
4be44fcd LB |
695 | static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */ |
696 | acpi_handle chandle, /* current node */ | |
697 | struct acpi_pci_id **id, | |
698 | int *is_bridge, u8 * bus_number) | |
1da177e4 | 699 | { |
4be44fcd LB |
700 | acpi_handle handle; |
701 | struct acpi_pci_id *pci_id = *id; | |
702 | acpi_status status; | |
703 | unsigned long temp; | |
704 | acpi_object_type type; | |
705 | u8 tu8; | |
1da177e4 LT |
706 | |
707 | acpi_get_parent(chandle, &handle); | |
708 | if (handle != rhandle) { | |
4be44fcd LB |
709 | acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge, |
710 | bus_number); | |
1da177e4 LT |
711 | |
712 | status = acpi_get_type(handle, &type); | |
4be44fcd | 713 | if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE)) |
1da177e4 LT |
714 | return; |
715 | ||
4be44fcd LB |
716 | status = |
717 | acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, | |
718 | &temp); | |
1da177e4 | 719 | if (ACPI_SUCCESS(status)) { |
4be44fcd LB |
720 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp)); |
721 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp)); | |
1da177e4 LT |
722 | |
723 | if (*is_bridge) | |
724 | pci_id->bus = *bus_number; | |
725 | ||
726 | /* any nicer way to get bus number of bridge ? */ | |
4be44fcd LB |
727 | status = |
728 | acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8, | |
729 | 8); | |
730 | if (ACPI_SUCCESS(status) | |
731 | && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) { | |
732 | status = | |
733 | acpi_os_read_pci_configuration(pci_id, 0x18, | |
734 | &tu8, 8); | |
1da177e4 LT |
735 | if (!ACPI_SUCCESS(status)) { |
736 | /* Certainly broken... FIX ME */ | |
737 | return; | |
738 | } | |
739 | *is_bridge = 1; | |
740 | pci_id->bus = tu8; | |
4be44fcd LB |
741 | status = |
742 | acpi_os_read_pci_configuration(pci_id, 0x19, | |
743 | &tu8, 8); | |
1da177e4 LT |
744 | if (ACPI_SUCCESS(status)) { |
745 | *bus_number = tu8; | |
746 | } | |
747 | } else | |
748 | *is_bridge = 0; | |
749 | } | |
750 | } | |
751 | } | |
752 | ||
4be44fcd LB |
753 | void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ |
754 | acpi_handle chandle, /* current node */ | |
755 | struct acpi_pci_id **id) | |
1da177e4 LT |
756 | { |
757 | int is_bridge = 1; | |
758 | u8 bus_number = (*id)->bus; | |
759 | ||
760 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); | |
761 | } | |
762 | ||
65f27f38 | 763 | static void acpi_os_execute_deferred(struct work_struct *work) |
88db5e14 AS |
764 | { |
765 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); | |
766 | if (!dpc) { | |
767 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); | |
768 | return; | |
769 | } | |
770 | ||
771 | dpc->function(dpc->context); | |
772 | kfree(dpc); | |
773 | ||
d550d98d | 774 | return; |
1da177e4 LT |
775 | } |
776 | ||
b8d35192 AS |
777 | /******************************************************************************* |
778 | * | |
779 | * FUNCTION: acpi_os_execute | |
780 | * | |
781 | * PARAMETERS: Type - Type of the callback | |
782 | * Function - Function to be executed | |
783 | * Context - Function parameters | |
784 | * | |
785 | * RETURN: Status | |
786 | * | |
787 | * DESCRIPTION: Depending on type, either queues function for deferred execution or | |
788 | * immediately executes function on a separate thread. | |
789 | * | |
790 | ******************************************************************************/ | |
791 | ||
792 | acpi_status acpi_os_execute(acpi_execute_type type, | |
4be44fcd | 793 | acpi_osd_exec_callback function, void *context) |
1da177e4 | 794 | { |
4be44fcd LB |
795 | acpi_status status = AE_OK; |
796 | struct acpi_os_dpc *dpc; | |
17bc54ee | 797 | struct workqueue_struct *queue; |
72945b2b LB |
798 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
799 | "Scheduling function [%p(%p)] for deferred execution.\n", | |
800 | function, context)); | |
1da177e4 LT |
801 | |
802 | if (!function) | |
88db5e14 | 803 | return AE_BAD_PARAMETER; |
72945b2b | 804 | |
1da177e4 LT |
805 | /* |
806 | * Allocate/initialize DPC structure. Note that this memory will be | |
65f27f38 | 807 | * freed by the callee. The kernel handles the work_struct list in a |
1da177e4 LT |
808 | * way that allows us to also free its memory inside the callee. |
809 | * Because we may want to schedule several tasks with different | |
810 | * parameters we can't use the approach some kernel code uses of | |
65f27f38 | 811 | * having a static work_struct. |
1da177e4 | 812 | */ |
72945b2b | 813 | |
65f27f38 | 814 | dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC); |
1da177e4 | 815 | if (!dpc) |
b976fe19 LT |
816 | return_ACPI_STATUS(AE_NO_MEMORY); |
817 | ||
1da177e4 LT |
818 | dpc->function = function; |
819 | dpc->context = context; | |
b976fe19 | 820 | |
17bc54ee AS |
821 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); |
822 | queue = (type == OSL_NOTIFY_HANDLER) ? kacpi_notify_wq : kacpid_wq; | |
823 | if (!queue_work(queue, &dpc->work)) { | |
824 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
825 | "Call to queue_work() failed.\n")); | |
826 | status = AE_ERROR; | |
827 | kfree(dpc); | |
1da177e4 | 828 | } |
b976fe19 | 829 | return_ACPI_STATUS(status); |
1da177e4 | 830 | } |
4be44fcd | 831 | |
b8d35192 | 832 | EXPORT_SYMBOL(acpi_os_execute); |
1da177e4 | 833 | |
4be44fcd | 834 | void acpi_os_wait_events_complete(void *context) |
1da177e4 LT |
835 | { |
836 | flush_workqueue(kacpid_wq); | |
837 | } | |
4be44fcd | 838 | |
1da177e4 LT |
839 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
840 | ||
841 | /* | |
842 | * Allocate the memory for a spinlock and initialize it. | |
843 | */ | |
967440e3 | 844 | acpi_status acpi_os_create_lock(acpi_spinlock * handle) |
1da177e4 | 845 | { |
967440e3 | 846 | spin_lock_init(*handle); |
1da177e4 | 847 | |
d550d98d | 848 | return AE_OK; |
1da177e4 LT |
849 | } |
850 | ||
1da177e4 LT |
851 | /* |
852 | * Deallocate the memory for a spinlock. | |
853 | */ | |
967440e3 | 854 | void acpi_os_delete_lock(acpi_spinlock handle) |
1da177e4 | 855 | { |
d550d98d | 856 | return; |
1da177e4 LT |
857 | } |
858 | ||
1da177e4 | 859 | acpi_status |
4be44fcd | 860 | acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) |
1da177e4 | 861 | { |
4be44fcd | 862 | struct semaphore *sem = NULL; |
1da177e4 | 863 | |
1da177e4 LT |
864 | |
865 | sem = acpi_os_allocate(sizeof(struct semaphore)); | |
866 | if (!sem) | |
d550d98d | 867 | return AE_NO_MEMORY; |
1da177e4 LT |
868 | memset(sem, 0, sizeof(struct semaphore)); |
869 | ||
870 | sema_init(sem, initial_units); | |
871 | ||
4be44fcd | 872 | *handle = (acpi_handle *) sem; |
1da177e4 | 873 | |
4be44fcd LB |
874 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
875 | *handle, initial_units)); | |
1da177e4 | 876 | |
d550d98d | 877 | return AE_OK; |
1da177e4 | 878 | } |
1da177e4 | 879 | |
1da177e4 LT |
880 | /* |
881 | * TODO: A better way to delete semaphores? Linux doesn't have a | |
882 | * 'delete_semaphore()' function -- may result in an invalid | |
883 | * pointer dereference for non-synchronized consumers. Should | |
884 | * we at least check for blocked threads and signal/cancel them? | |
885 | */ | |
886 | ||
4be44fcd | 887 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
1da177e4 | 888 | { |
4be44fcd | 889 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 890 | |
1da177e4 LT |
891 | |
892 | if (!sem) | |
d550d98d | 893 | return AE_BAD_PARAMETER; |
1da177e4 | 894 | |
4be44fcd | 895 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
1da177e4 | 896 | |
02438d87 | 897 | kfree(sem); |
4be44fcd | 898 | sem = NULL; |
1da177e4 | 899 | |
d550d98d | 900 | return AE_OK; |
1da177e4 | 901 | } |
1da177e4 | 902 | |
1da177e4 LT |
903 | /* |
904 | * TODO: The kernel doesn't have a 'down_timeout' function -- had to | |
905 | * improvise. The process is to sleep for one scheduler quantum | |
906 | * until the semaphore becomes available. Downside is that this | |
907 | * may result in starvation for timeout-based waits when there's | |
908 | * lots of semaphore activity. | |
909 | * | |
910 | * TODO: Support for units > 1? | |
911 | */ | |
4be44fcd | 912 | acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) |
1da177e4 | 913 | { |
4be44fcd LB |
914 | acpi_status status = AE_OK; |
915 | struct semaphore *sem = (struct semaphore *)handle; | |
916 | int ret = 0; | |
1da177e4 | 917 | |
1da177e4 LT |
918 | |
919 | if (!sem || (units < 1)) | |
d550d98d | 920 | return AE_BAD_PARAMETER; |
1da177e4 LT |
921 | |
922 | if (units > 1) | |
d550d98d | 923 | return AE_SUPPORT; |
1da177e4 | 924 | |
4be44fcd LB |
925 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
926 | handle, units, timeout)); | |
1da177e4 | 927 | |
d68909f4 LB |
928 | /* |
929 | * This can be called during resume with interrupts off. | |
930 | * Like boot-time, we should be single threaded and will | |
931 | * always get the lock if we try -- timeout or not. | |
932 | * If this doesn't succeed, then we will oops courtesy of | |
933 | * might_sleep() in down(). | |
934 | */ | |
935 | if (!down_trylock(sem)) | |
936 | return AE_OK; | |
937 | ||
4be44fcd | 938 | switch (timeout) { |
1da177e4 LT |
939 | /* |
940 | * No Wait: | |
941 | * -------- | |
942 | * A zero timeout value indicates that we shouldn't wait - just | |
943 | * acquire the semaphore if available otherwise return AE_TIME | |
944 | * (a.k.a. 'would block'). | |
945 | */ | |
4be44fcd LB |
946 | case 0: |
947 | if (down_trylock(sem)) | |
1da177e4 LT |
948 | status = AE_TIME; |
949 | break; | |
950 | ||
951 | /* | |
952 | * Wait Indefinitely: | |
953 | * ------------------ | |
954 | */ | |
4be44fcd | 955 | case ACPI_WAIT_FOREVER: |
1da177e4 LT |
956 | down(sem); |
957 | break; | |
958 | ||
959 | /* | |
960 | * Wait w/ Timeout: | |
961 | * ---------------- | |
962 | */ | |
4be44fcd | 963 | default: |
1da177e4 LT |
964 | // TODO: A better timeout algorithm? |
965 | { | |
966 | int i = 0; | |
4be44fcd | 967 | static const int quantum_ms = 1000 / HZ; |
1da177e4 LT |
968 | |
969 | ret = down_trylock(sem); | |
dacd9b80 | 970 | for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) { |
01a527ec | 971 | schedule_timeout_interruptible(1); |
1da177e4 LT |
972 | ret = down_trylock(sem); |
973 | } | |
4be44fcd | 974 | |
1da177e4 LT |
975 | if (ret != 0) |
976 | status = AE_TIME; | |
977 | } | |
978 | break; | |
979 | } | |
980 | ||
981 | if (ACPI_FAILURE(status)) { | |
9e7e2c04 | 982 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
a6fc6720 | 983 | "Failed to acquire semaphore[%p|%d|%d], %s", |
4be44fcd LB |
984 | handle, units, timeout, |
985 | acpi_format_exception(status))); | |
986 | } else { | |
987 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | |
a6fc6720 | 988 | "Acquired semaphore[%p|%d|%d]", handle, |
4be44fcd | 989 | units, timeout)); |
1da177e4 LT |
990 | } |
991 | ||
d550d98d | 992 | return status; |
1da177e4 | 993 | } |
1da177e4 | 994 | |
1da177e4 LT |
995 | /* |
996 | * TODO: Support for units > 1? | |
997 | */ | |
4be44fcd | 998 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
1da177e4 | 999 | { |
4be44fcd | 1000 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 1001 | |
1da177e4 LT |
1002 | |
1003 | if (!sem || (units < 1)) | |
d550d98d | 1004 | return AE_BAD_PARAMETER; |
1da177e4 LT |
1005 | |
1006 | if (units > 1) | |
d550d98d | 1007 | return AE_SUPPORT; |
1da177e4 | 1008 | |
4be44fcd LB |
1009 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
1010 | units)); | |
1da177e4 LT |
1011 | |
1012 | up(sem); | |
1013 | ||
d550d98d | 1014 | return AE_OK; |
1da177e4 | 1015 | } |
4be44fcd | 1016 | |
1da177e4 | 1017 | #ifdef ACPI_FUTURE_USAGE |
4be44fcd | 1018 | u32 acpi_os_get_line(char *buffer) |
1da177e4 LT |
1019 | { |
1020 | ||
1021 | #ifdef ENABLE_DEBUGGER | |
1022 | if (acpi_in_debugger) { | |
1023 | u32 chars; | |
1024 | ||
1025 | kdb_read(buffer, sizeof(line_buf)); | |
1026 | ||
1027 | /* remove the CR kdb includes */ | |
1028 | chars = strlen(buffer) - 1; | |
1029 | buffer[chars] = '\0'; | |
1030 | } | |
1031 | #endif | |
1032 | ||
1033 | return 0; | |
1034 | } | |
4be44fcd | 1035 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 | 1036 | |
4be44fcd | 1037 | acpi_status acpi_os_signal(u32 function, void *info) |
1da177e4 | 1038 | { |
4be44fcd | 1039 | switch (function) { |
1da177e4 LT |
1040 | case ACPI_SIGNAL_FATAL: |
1041 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); | |
1042 | break; | |
1043 | case ACPI_SIGNAL_BREAKPOINT: | |
1044 | /* | |
1045 | * AML Breakpoint | |
1046 | * ACPI spec. says to treat it as a NOP unless | |
1047 | * you are debugging. So if/when we integrate | |
1048 | * AML debugger into the kernel debugger its | |
1049 | * hook will go here. But until then it is | |
1050 | * not useful to print anything on breakpoints. | |
1051 | */ | |
1052 | break; | |
1053 | default: | |
1054 | break; | |
1055 | } | |
1056 | ||
1057 | return AE_OK; | |
1058 | } | |
4be44fcd | 1059 | |
4be44fcd | 1060 | static int __init acpi_os_name_setup(char *str) |
1da177e4 LT |
1061 | { |
1062 | char *p = acpi_os_name; | |
4be44fcd | 1063 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
1da177e4 LT |
1064 | |
1065 | if (!str || !*str) | |
1066 | return 0; | |
1067 | ||
1068 | for (; count-- && str && *str; str++) { | |
1069 | if (isalnum(*str) || *str == ' ' || *str == ':') | |
1070 | *p++ = *str; | |
1071 | else if (*str == '\'' || *str == '"') | |
1072 | continue; | |
1073 | else | |
1074 | break; | |
1075 | } | |
1076 | *p = 0; | |
1077 | ||
1078 | return 1; | |
4be44fcd | 1079 | |
1da177e4 LT |
1080 | } |
1081 | ||
1082 | __setup("acpi_os_name=", acpi_os_name_setup); | |
1083 | ||
d4b7dc49 LB |
1084 | static void __init set_osi_linux(unsigned int enable) |
1085 | { | |
1086 | if (osi_linux.enable != enable) { | |
1087 | osi_linux.enable = enable; | |
1088 | printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n", | |
1089 | enable ? "Add": "Delet"); | |
1090 | } | |
1091 | return; | |
1092 | } | |
1093 | ||
1094 | static void __init acpi_cmdline_osi_linux(unsigned int enable) | |
1095 | { | |
1096 | osi_linux.cmdline = 1; /* cmdline set the default */ | |
1097 | set_osi_linux(enable); | |
1098 | ||
1099 | return; | |
1100 | } | |
1101 | ||
1102 | void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d) | |
1103 | { | |
1104 | osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */ | |
1105 | ||
1106 | printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident); | |
1107 | ||
1108 | if (enable == -1) | |
1109 | return; | |
1110 | ||
1111 | osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */ | |
f507654d | 1112 | |
d4b7dc49 | 1113 | set_osi_linux(enable); |
f507654d | 1114 | |
f507654d LB |
1115 | return; |
1116 | } | |
1117 | ||
1da177e4 | 1118 | /* |
ae00d812 LB |
1119 | * Modify the list of "OS Interfaces" reported to BIOS via _OSI |
1120 | * | |
1da177e4 | 1121 | * empty string disables _OSI |
ae00d812 LB |
1122 | * string starting with '!' disables that string |
1123 | * otherwise string is added to list, augmenting built-in strings | |
1da177e4 | 1124 | */ |
4be44fcd | 1125 | static int __init acpi_osi_setup(char *str) |
1da177e4 LT |
1126 | { |
1127 | if (str == NULL || *str == '\0') { | |
1128 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); | |
1129 | acpi_gbl_create_osi_method = FALSE; | |
aa2e09da | 1130 | } else if (!strcmp("!Linux", str)) { |
d4b7dc49 | 1131 | acpi_cmdline_osi_linux(0); /* !enable */ |
ae00d812 LB |
1132 | } else if (*str == '!') { |
1133 | if (acpi_osi_invalidate(++str) == AE_OK) | |
1134 | printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); | |
f507654d | 1135 | } else if (!strcmp("Linux", str)) { |
d4b7dc49 | 1136 | acpi_cmdline_osi_linux(1); /* enable */ |
ae00d812 LB |
1137 | } else if (*osi_additional_string == '\0') { |
1138 | strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX); | |
1139 | printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str); | |
1da177e4 LT |
1140 | } |
1141 | ||
1142 | return 1; | |
1143 | } | |
1144 | ||
1145 | __setup("acpi_osi=", acpi_osi_setup); | |
1146 | ||
1147 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ | |
4be44fcd | 1148 | static int __init acpi_serialize_setup(char *str) |
1da177e4 LT |
1149 | { |
1150 | printk(KERN_INFO PREFIX "serialize enabled\n"); | |
1151 | ||
1152 | acpi_gbl_all_methods_serialized = TRUE; | |
1153 | ||
1154 | return 1; | |
1155 | } | |
1156 | ||
1157 | __setup("acpi_serialize", acpi_serialize_setup); | |
1158 | ||
1159 | /* | |
1160 | * Wake and Run-Time GPES are expected to be separate. | |
1161 | * We disable wake-GPEs at run-time to prevent spurious | |
1162 | * interrupts. | |
1163 | * | |
1164 | * However, if a system exists that shares Wake and | |
1165 | * Run-time events on the same GPE this flag is available | |
1166 | * to tell Linux to keep the wake-time GPEs enabled at run-time. | |
1167 | */ | |
4be44fcd | 1168 | static int __init acpi_wake_gpes_always_on_setup(char *str) |
1da177e4 LT |
1169 | { |
1170 | printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); | |
1171 | ||
1172 | acpi_gbl_leave_wake_gpes_disabled = FALSE; | |
1173 | ||
1174 | return 1; | |
1175 | } | |
1176 | ||
1177 | __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); | |
1178 | ||
df92e695 TR |
1179 | /* Check of resource interference between native drivers and ACPI |
1180 | * OperationRegions (SystemIO and System Memory only). | |
1181 | * IO ports and memory declared in ACPI might be used by the ACPI subsystem | |
1182 | * in arbitrary AML code and can interfere with legacy drivers. | |
1183 | * acpi_enforce_resources= can be set to: | |
1184 | * | |
1185 | * - strict (2) | |
1186 | * -> further driver trying to access the resources will not load | |
1187 | * - lax (default) (1) | |
1188 | * -> further driver trying to access the resources will load, but you | |
1189 | * get a system message that something might go wrong... | |
1190 | * | |
1191 | * - no (0) | |
1192 | * -> ACPI Operation Region resources will not be registered | |
1193 | * | |
1194 | */ | |
1195 | #define ENFORCE_RESOURCES_STRICT 2 | |
1196 | #define ENFORCE_RESOURCES_LAX 1 | |
1197 | #define ENFORCE_RESOURCES_NO 0 | |
1198 | ||
1199 | static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX; | |
1200 | ||
1201 | static int __init acpi_enforce_resources_setup(char *str) | |
1202 | { | |
1203 | if (str == NULL || *str == '\0') | |
1204 | return 0; | |
1205 | ||
1206 | if (!strcmp("strict", str)) | |
1207 | acpi_enforce_resources = ENFORCE_RESOURCES_STRICT; | |
1208 | else if (!strcmp("lax", str)) | |
1209 | acpi_enforce_resources = ENFORCE_RESOURCES_LAX; | |
1210 | else if (!strcmp("no", str)) | |
1211 | acpi_enforce_resources = ENFORCE_RESOURCES_NO; | |
1212 | ||
1213 | return 1; | |
1214 | } | |
1215 | ||
1216 | __setup("acpi_enforce_resources=", acpi_enforce_resources_setup); | |
1217 | ||
1218 | /* Check for resource conflicts between ACPI OperationRegions and native | |
1219 | * drivers */ | |
443dea72 | 1220 | int acpi_check_resource_conflict(struct resource *res) |
df92e695 TR |
1221 | { |
1222 | struct acpi_res_list *res_list_elem; | |
1223 | int ioport; | |
1224 | int clash = 0; | |
1225 | ||
1226 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) | |
1227 | return 0; | |
1228 | if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM)) | |
1229 | return 0; | |
1230 | ||
1231 | ioport = res->flags & IORESOURCE_IO; | |
1232 | ||
1233 | spin_lock(&acpi_res_lock); | |
1234 | list_for_each_entry(res_list_elem, &resource_list_head, | |
1235 | resource_list) { | |
1236 | if (ioport && (res_list_elem->resource_type | |
1237 | != ACPI_ADR_SPACE_SYSTEM_IO)) | |
1238 | continue; | |
1239 | if (!ioport && (res_list_elem->resource_type | |
1240 | != ACPI_ADR_SPACE_SYSTEM_MEMORY)) | |
1241 | continue; | |
1242 | ||
1243 | if (res->end < res_list_elem->start | |
1244 | || res_list_elem->end < res->start) | |
1245 | continue; | |
1246 | clash = 1; | |
1247 | break; | |
1248 | } | |
1249 | spin_unlock(&acpi_res_lock); | |
1250 | ||
1251 | if (clash) { | |
1252 | if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) { | |
1253 | printk(KERN_INFO "%sACPI: %s resource %s [0x%llx-0x%llx]" | |
1254 | " conflicts with ACPI region %s" | |
1255 | " [0x%llx-0x%llx]\n", | |
1256 | acpi_enforce_resources == ENFORCE_RESOURCES_LAX | |
1257 | ? KERN_WARNING : KERN_ERR, | |
1258 | ioport ? "I/O" : "Memory", res->name, | |
1259 | (long long) res->start, (long long) res->end, | |
1260 | res_list_elem->name, | |
1261 | (long long) res_list_elem->start, | |
1262 | (long long) res_list_elem->end); | |
1263 | printk(KERN_INFO "ACPI: Device needs an ACPI driver\n"); | |
1264 | } | |
1265 | if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT) | |
1266 | return -EBUSY; | |
1267 | } | |
1268 | return 0; | |
1269 | } | |
443dea72 | 1270 | EXPORT_SYMBOL(acpi_check_resource_conflict); |
df92e695 TR |
1271 | |
1272 | int acpi_check_region(resource_size_t start, resource_size_t n, | |
1273 | const char *name) | |
1274 | { | |
1275 | struct resource res = { | |
1276 | .start = start, | |
1277 | .end = start + n - 1, | |
1278 | .name = name, | |
1279 | .flags = IORESOURCE_IO, | |
1280 | }; | |
1281 | ||
1282 | return acpi_check_resource_conflict(&res); | |
1283 | } | |
1284 | EXPORT_SYMBOL(acpi_check_region); | |
1285 | ||
1286 | int acpi_check_mem_region(resource_size_t start, resource_size_t n, | |
1287 | const char *name) | |
1288 | { | |
1289 | struct resource res = { | |
1290 | .start = start, | |
1291 | .end = start + n - 1, | |
1292 | .name = name, | |
1293 | .flags = IORESOURCE_MEM, | |
1294 | }; | |
1295 | ||
1296 | return acpi_check_resource_conflict(&res); | |
1297 | ||
1298 | } | |
1299 | EXPORT_SYMBOL(acpi_check_mem_region); | |
1300 | ||
73459f73 RM |
1301 | /* |
1302 | * Acquire a spinlock. | |
1303 | * | |
1304 | * handle is a pointer to the spinlock_t. | |
73459f73 RM |
1305 | */ |
1306 | ||
967440e3 | 1307 | acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp) |
73459f73 | 1308 | { |
b8e4d893 | 1309 | acpi_cpu_flags flags; |
967440e3 | 1310 | spin_lock_irqsave(lockp, flags); |
73459f73 RM |
1311 | return flags; |
1312 | } | |
1313 | ||
1314 | /* | |
1315 | * Release a spinlock. See above. | |
1316 | */ | |
1317 | ||
967440e3 | 1318 | void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags) |
73459f73 | 1319 | { |
967440e3 | 1320 | spin_unlock_irqrestore(lockp, flags); |
73459f73 RM |
1321 | } |
1322 | ||
73459f73 RM |
1323 | #ifndef ACPI_USE_LOCAL_CACHE |
1324 | ||
1325 | /******************************************************************************* | |
1326 | * | |
1327 | * FUNCTION: acpi_os_create_cache | |
1328 | * | |
b229cf92 BM |
1329 | * PARAMETERS: name - Ascii name for the cache |
1330 | * size - Size of each cached object | |
1331 | * depth - Maximum depth of the cache (in objects) <ignored> | |
1332 | * cache - Where the new cache object is returned | |
73459f73 | 1333 | * |
b229cf92 | 1334 | * RETURN: status |
73459f73 RM |
1335 | * |
1336 | * DESCRIPTION: Create a cache object | |
1337 | * | |
1338 | ******************************************************************************/ | |
1339 | ||
1340 | acpi_status | |
4be44fcd | 1341 | acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) |
73459f73 | 1342 | { |
20c2df83 | 1343 | *cache = kmem_cache_create(name, size, 0, 0, NULL); |
a6fdbf90 | 1344 | if (*cache == NULL) |
b229cf92 BM |
1345 | return AE_ERROR; |
1346 | else | |
1347 | return AE_OK; | |
73459f73 RM |
1348 | } |
1349 | ||
1350 | /******************************************************************************* | |
1351 | * | |
1352 | * FUNCTION: acpi_os_purge_cache | |
1353 | * | |
1354 | * PARAMETERS: Cache - Handle to cache object | |
1355 | * | |
1356 | * RETURN: Status | |
1357 | * | |
1358 | * DESCRIPTION: Free all objects within the requested cache. | |
1359 | * | |
1360 | ******************************************************************************/ | |
1361 | ||
4be44fcd | 1362 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
73459f73 | 1363 | { |
50dd0969 | 1364 | kmem_cache_shrink(cache); |
4be44fcd | 1365 | return (AE_OK); |
73459f73 RM |
1366 | } |
1367 | ||
1368 | /******************************************************************************* | |
1369 | * | |
1370 | * FUNCTION: acpi_os_delete_cache | |
1371 | * | |
1372 | * PARAMETERS: Cache - Handle to cache object | |
1373 | * | |
1374 | * RETURN: Status | |
1375 | * | |
1376 | * DESCRIPTION: Free all objects within the requested cache and delete the | |
1377 | * cache object. | |
1378 | * | |
1379 | ******************************************************************************/ | |
1380 | ||
4be44fcd | 1381 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
73459f73 | 1382 | { |
1a1d92c1 | 1383 | kmem_cache_destroy(cache); |
4be44fcd | 1384 | return (AE_OK); |
73459f73 RM |
1385 | } |
1386 | ||
1387 | /******************************************************************************* | |
1388 | * | |
1389 | * FUNCTION: acpi_os_release_object | |
1390 | * | |
1391 | * PARAMETERS: Cache - Handle to cache object | |
1392 | * Object - The object to be released | |
1393 | * | |
1394 | * RETURN: None | |
1395 | * | |
1396 | * DESCRIPTION: Release an object to the specified cache. If cache is full, | |
1397 | * the object is deleted. | |
1398 | * | |
1399 | ******************************************************************************/ | |
1400 | ||
4be44fcd | 1401 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
73459f73 | 1402 | { |
4be44fcd LB |
1403 | kmem_cache_free(cache, object); |
1404 | return (AE_OK); | |
73459f73 RM |
1405 | } |
1406 | ||
5a4e1432 LB |
1407 | /** |
1408 | * acpi_dmi_dump - dump DMI slots needed for blacklist entry | |
1409 | * | |
1410 | * Returns 0 on success | |
1411 | */ | |
12d3931c | 1412 | static int acpi_dmi_dump(void) |
5a4e1432 LB |
1413 | { |
1414 | ||
1415 | if (!dmi_available) | |
1416 | return -1; | |
1417 | ||
1418 | printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n", | |
e6298c6d | 1419 | dmi_get_system_info(DMI_SYS_VENDOR)); |
5a4e1432 | 1420 | printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n", |
e6298c6d | 1421 | dmi_get_system_info(DMI_PRODUCT_NAME)); |
5a4e1432 | 1422 | printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n", |
e6298c6d | 1423 | dmi_get_system_info(DMI_PRODUCT_VERSION)); |
5a4e1432 | 1424 | printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n", |
e6298c6d | 1425 | dmi_get_system_info(DMI_BOARD_NAME)); |
5a4e1432 | 1426 | printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n", |
e6298c6d | 1427 | dmi_get_system_info(DMI_BIOS_VENDOR)); |
5a4e1432 | 1428 | printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n", |
e6298c6d | 1429 | dmi_get_system_info(DMI_BIOS_DATE)); |
5a4e1432 LB |
1430 | |
1431 | return 0; | |
1432 | } | |
1433 | ||
1434 | ||
b229cf92 BM |
1435 | /****************************************************************************** |
1436 | * | |
1437 | * FUNCTION: acpi_os_validate_interface | |
1438 | * | |
1439 | * PARAMETERS: interface - Requested interface to be validated | |
1440 | * | |
1441 | * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise | |
1442 | * | |
1443 | * DESCRIPTION: Match an interface string to the interfaces supported by the | |
1444 | * host. Strings originate from an AML call to the _OSI method. | |
1445 | * | |
1446 | *****************************************************************************/ | |
1447 | ||
1448 | acpi_status | |
1449 | acpi_os_validate_interface (char *interface) | |
1450 | { | |
ae00d812 LB |
1451 | if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX)) |
1452 | return AE_OK; | |
f507654d | 1453 | if (!strcmp("Linux", interface)) { |
d4b7dc49 | 1454 | |
f40cd6fd | 1455 | printk(KERN_NOTICE PREFIX |
d4b7dc49 LB |
1456 | "BIOS _OSI(Linux) query %s%s\n", |
1457 | osi_linux.enable ? "honored" : "ignored", | |
1458 | osi_linux.cmdline ? " via cmdline" : | |
1459 | osi_linux.dmi ? " via DMI" : ""); | |
1460 | ||
1461 | if (!osi_linux.dmi) { | |
1462 | if (acpi_dmi_dump()) | |
1463 | printk(KERN_NOTICE PREFIX | |
1464 | "[please extract dmidecode output]\n"); | |
1465 | printk(KERN_NOTICE PREFIX | |
1466 | "Please send DMI info above to " | |
1467 | "linux-acpi@vger.kernel.org\n"); | |
1468 | } | |
1469 | if (!osi_linux.known && !osi_linux.cmdline) { | |
1470 | printk(KERN_NOTICE PREFIX | |
1471 | "If \"acpi_osi=%sLinux\" works better, " | |
1472 | "please notify linux-acpi@vger.kernel.org\n", | |
1473 | osi_linux.enable ? "!" : ""); | |
1474 | } | |
1475 | ||
1476 | if (osi_linux.enable) | |
f507654d LB |
1477 | return AE_OK; |
1478 | } | |
ae00d812 | 1479 | return AE_SUPPORT; |
b229cf92 BM |
1480 | } |
1481 | ||
b229cf92 BM |
1482 | /****************************************************************************** |
1483 | * | |
1484 | * FUNCTION: acpi_os_validate_address | |
1485 | * | |
1486 | * PARAMETERS: space_id - ACPI space ID | |
1487 | * address - Physical address | |
1488 | * length - Address length | |
1489 | * | |
1490 | * RETURN: AE_OK if address/length is valid for the space_id. Otherwise, | |
1491 | * should return AE_AML_ILLEGAL_ADDRESS. | |
1492 | * | |
1493 | * DESCRIPTION: Validate a system address via the host OS. Used to validate | |
1494 | * the addresses accessed by AML operation regions. | |
1495 | * | |
1496 | *****************************************************************************/ | |
1497 | ||
1498 | acpi_status | |
1499 | acpi_os_validate_address ( | |
1500 | u8 space_id, | |
1501 | acpi_physical_address address, | |
df92e695 TR |
1502 | acpi_size length, |
1503 | char *name) | |
b229cf92 | 1504 | { |
df92e695 TR |
1505 | struct acpi_res_list *res; |
1506 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) | |
1507 | return AE_OK; | |
b229cf92 | 1508 | |
df92e695 TR |
1509 | switch (space_id) { |
1510 | case ACPI_ADR_SPACE_SYSTEM_IO: | |
1511 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | |
1512 | /* Only interference checks against SystemIO and SytemMemory | |
1513 | are needed */ | |
1514 | res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL); | |
1515 | if (!res) | |
1516 | return AE_OK; | |
1517 | /* ACPI names are fixed to 4 bytes, still better use strlcpy */ | |
1518 | strlcpy(res->name, name, 5); | |
1519 | res->start = address; | |
1520 | res->end = address + length - 1; | |
1521 | res->resource_type = space_id; | |
1522 | spin_lock(&acpi_res_lock); | |
1523 | list_add(&res->resource_list, &resource_list_head); | |
1524 | spin_unlock(&acpi_res_lock); | |
1525 | pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, " | |
1526 | "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO) | |
1527 | ? "SystemIO" : "System Memory", | |
1528 | (unsigned long long)res->start, | |
1529 | (unsigned long long)res->end, | |
1530 | res->name); | |
1531 | break; | |
1532 | case ACPI_ADR_SPACE_PCI_CONFIG: | |
1533 | case ACPI_ADR_SPACE_EC: | |
1534 | case ACPI_ADR_SPACE_SMBUS: | |
1535 | case ACPI_ADR_SPACE_CMOS: | |
1536 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: | |
1537 | case ACPI_ADR_SPACE_DATA_TABLE: | |
1538 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | |
1539 | break; | |
1540 | } | |
1541 | return AE_OK; | |
b229cf92 BM |
1542 | } |
1543 | ||
73459f73 | 1544 | #endif |