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> | |
47 | ||
1da177e4 | 48 | #define _COMPONENT ACPI_OS_SERVICES |
f52fd66d | 49 | ACPI_MODULE_NAME("osl"); |
1da177e4 | 50 | #define PREFIX "ACPI: " |
4be44fcd LB |
51 | struct acpi_os_dpc { |
52 | acpi_osd_exec_callback function; | |
53 | void *context; | |
65f27f38 | 54 | struct work_struct work; |
1da177e4 LT |
55 | }; |
56 | ||
57 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | |
58 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE | |
59 | #endif | |
60 | ||
61 | #ifdef ENABLE_DEBUGGER | |
62 | #include <linux/kdb.h> | |
63 | ||
64 | /* stuff for debugger support */ | |
65 | int acpi_in_debugger; | |
66 | EXPORT_SYMBOL(acpi_in_debugger); | |
67 | ||
68 | extern char line_buf[80]; | |
4be44fcd | 69 | #endif /*ENABLE_DEBUGGER */ |
1da177e4 LT |
70 | |
71 | static unsigned int acpi_irq_irq; | |
72 | static acpi_osd_handler acpi_irq_handler; | |
73 | static void *acpi_irq_context; | |
74 | static struct workqueue_struct *kacpid_wq; | |
88db5e14 | 75 | static struct workqueue_struct *kacpi_notify_wq; |
1da177e4 | 76 | |
ae00d812 LB |
77 | #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ |
78 | static char osi_additional_string[OSI_STRING_LENGTH_MAX]; | |
79 | ||
f507654d LB |
80 | #define OSI_LINUX_ENABLED |
81 | #ifdef OSI_LINUX_ENABLED | |
82 | int osi_linux = 1; /* enable _OSI(Linux) by default */ | |
83 | #else | |
84 | int osi_linux; /* disable _OSI(Linux) by default */ | |
85 | #endif | |
86 | ||
87 | ||
88 | #ifdef CONFIG_DMI | |
dd272b57 | 89 | static struct __initdata dmi_system_id acpi_osl_dmi_table[]; |
f507654d LB |
90 | #endif |
91 | ||
9a47cdb1 BH |
92 | static void __init acpi_request_region (struct acpi_generic_address *addr, |
93 | unsigned int length, char *desc) | |
94 | { | |
95 | struct resource *res; | |
96 | ||
97 | if (!addr->address || !length) | |
98 | return; | |
99 | ||
eee3c859 | 100 | if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
9a47cdb1 | 101 | res = request_region(addr->address, length, desc); |
eee3c859 | 102 | else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
9a47cdb1 BH |
103 | res = request_mem_region(addr->address, length, desc); |
104 | } | |
105 | ||
106 | static int __init acpi_reserve_resources(void) | |
107 | { | |
eee3c859 | 108 | acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
109 | "ACPI PM1a_EVT_BLK"); |
110 | ||
eee3c859 | 111 | acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
112 | "ACPI PM1b_EVT_BLK"); |
113 | ||
eee3c859 | 114 | acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
115 | "ACPI PM1a_CNT_BLK"); |
116 | ||
eee3c859 | 117 | acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
118 | "ACPI PM1b_CNT_BLK"); |
119 | ||
eee3c859 LB |
120 | if (acpi_gbl_FADT.pm_timer_length == 4) |
121 | acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR"); | |
9a47cdb1 | 122 | |
eee3c859 | 123 | acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length, |
9a47cdb1 BH |
124 | "ACPI PM2_CNT_BLK"); |
125 | ||
126 | /* Length of GPE blocks must be a non-negative multiple of 2 */ | |
127 | ||
eee3c859 LB |
128 | if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) |
129 | acpi_request_region(&acpi_gbl_FADT.xgpe0_block, | |
130 | acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK"); | |
9a47cdb1 | 131 | |
eee3c859 LB |
132 | if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) |
133 | acpi_request_region(&acpi_gbl_FADT.xgpe1_block, | |
134 | acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); | |
9a47cdb1 BH |
135 | |
136 | return 0; | |
137 | } | |
138 | device_initcall(acpi_reserve_resources); | |
139 | ||
dd272b57 | 140 | acpi_status __init acpi_os_initialize(void) |
1da177e4 | 141 | { |
f507654d | 142 | dmi_check_system(acpi_osl_dmi_table); |
1da177e4 LT |
143 | return AE_OK; |
144 | } | |
145 | ||
4be44fcd | 146 | acpi_status acpi_os_initialize1(void) |
1da177e4 LT |
147 | { |
148 | /* | |
149 | * Initialize PCI configuration space access, as we'll need to access | |
150 | * it while walking the namespace (bus 0 and root bridges w/ _BBNs). | |
151 | */ | |
1da177e4 | 152 | if (!raw_pci_ops) { |
4be44fcd LB |
153 | printk(KERN_ERR PREFIX |
154 | "Access to PCI configuration space unavailable\n"); | |
1da177e4 LT |
155 | return AE_NULL_ENTRY; |
156 | } | |
1da177e4 | 157 | kacpid_wq = create_singlethread_workqueue("kacpid"); |
88db5e14 | 158 | kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify"); |
1da177e4 | 159 | BUG_ON(!kacpid_wq); |
88db5e14 | 160 | BUG_ON(!kacpi_notify_wq); |
1da177e4 LT |
161 | return AE_OK; |
162 | } | |
163 | ||
4be44fcd | 164 | acpi_status acpi_os_terminate(void) |
1da177e4 LT |
165 | { |
166 | if (acpi_irq_handler) { | |
167 | acpi_os_remove_interrupt_handler(acpi_irq_irq, | |
168 | acpi_irq_handler); | |
169 | } | |
170 | ||
171 | destroy_workqueue(kacpid_wq); | |
88db5e14 | 172 | destroy_workqueue(kacpi_notify_wq); |
1da177e4 LT |
173 | |
174 | return AE_OK; | |
175 | } | |
176 | ||
4be44fcd | 177 | void acpi_os_printf(const char *fmt, ...) |
1da177e4 LT |
178 | { |
179 | va_list args; | |
180 | va_start(args, fmt); | |
181 | acpi_os_vprintf(fmt, args); | |
182 | va_end(args); | |
183 | } | |
4be44fcd | 184 | |
1da177e4 LT |
185 | EXPORT_SYMBOL(acpi_os_printf); |
186 | ||
4be44fcd | 187 | void acpi_os_vprintf(const char *fmt, va_list args) |
1da177e4 LT |
188 | { |
189 | static char buffer[512]; | |
4be44fcd | 190 | |
1da177e4 LT |
191 | vsprintf(buffer, fmt, args); |
192 | ||
193 | #ifdef ENABLE_DEBUGGER | |
194 | if (acpi_in_debugger) { | |
195 | kdb_printf("%s", buffer); | |
196 | } else { | |
197 | printk("%s", buffer); | |
198 | } | |
199 | #else | |
200 | printk("%s", buffer); | |
201 | #endif | |
202 | } | |
203 | ||
ad71860a | 204 | acpi_physical_address __init acpi_os_get_root_pointer(void) |
1da177e4 LT |
205 | { |
206 | if (efi_enabled) { | |
b2c99e3c | 207 | if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) |
ad71860a | 208 | return efi.acpi20; |
b2c99e3c | 209 | else if (efi.acpi != EFI_INVALID_TABLE_ADDR) |
ad71860a | 210 | return efi.acpi; |
1da177e4 | 211 | else { |
4be44fcd LB |
212 | printk(KERN_ERR PREFIX |
213 | "System description tables not found\n"); | |
ad71860a | 214 | return 0; |
1da177e4 | 215 | } |
ad71860a AS |
216 | } else |
217 | return acpi_find_rsdp(); | |
1da177e4 LT |
218 | } |
219 | ||
ad71860a | 220 | void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size) |
1da177e4 | 221 | { |
9f4fd61f BH |
222 | if (phys > ULONG_MAX) { |
223 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); | |
70c0846e | 224 | return NULL; |
1da177e4 | 225 | } |
ad71860a AS |
226 | if (acpi_gbl_permanent_mmap) |
227 | /* | |
228 | * ioremap checks to ensure this is in reserved space | |
229 | */ | |
230 | return ioremap((unsigned long)phys, size); | |
231 | else | |
232 | return __acpi_map_table((unsigned long)phys, size); | |
1da177e4 | 233 | } |
55a82ab3 | 234 | EXPORT_SYMBOL_GPL(acpi_os_map_memory); |
1da177e4 | 235 | |
4be44fcd | 236 | void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) |
1da177e4 | 237 | { |
ad71860a AS |
238 | if (acpi_gbl_permanent_mmap) { |
239 | iounmap(virt); | |
240 | } | |
1da177e4 | 241 | } |
55a82ab3 | 242 | EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); |
1da177e4 LT |
243 | |
244 | #ifdef ACPI_FUTURE_USAGE | |
245 | acpi_status | |
4be44fcd | 246 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
1da177e4 | 247 | { |
4be44fcd | 248 | if (!phys || !virt) |
1da177e4 LT |
249 | return AE_BAD_PARAMETER; |
250 | ||
251 | *phys = virt_to_phys(virt); | |
252 | ||
253 | return AE_OK; | |
254 | } | |
255 | #endif | |
256 | ||
257 | #define ACPI_MAX_OVERRIDE_LEN 100 | |
258 | ||
259 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; | |
260 | ||
261 | acpi_status | |
4be44fcd LB |
262 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
263 | acpi_string * new_val) | |
1da177e4 LT |
264 | { |
265 | if (!init_val || !new_val) | |
266 | return AE_BAD_PARAMETER; | |
267 | ||
268 | *new_val = NULL; | |
4be44fcd | 269 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
1da177e4 | 270 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
4be44fcd | 271 | acpi_os_name); |
1da177e4 LT |
272 | *new_val = acpi_os_name; |
273 | } | |
274 | ||
275 | return AE_OK; | |
276 | } | |
277 | ||
278 | acpi_status | |
4be44fcd LB |
279 | acpi_os_table_override(struct acpi_table_header * existing_table, |
280 | struct acpi_table_header ** new_table) | |
1da177e4 LT |
281 | { |
282 | if (!existing_table || !new_table) | |
283 | return AE_BAD_PARAMETER; | |
284 | ||
285 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | |
286 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) | |
4be44fcd | 287 | *new_table = (struct acpi_table_header *)AmlCode; |
1da177e4 LT |
288 | else |
289 | *new_table = NULL; | |
290 | #else | |
291 | *new_table = NULL; | |
292 | #endif | |
293 | return AE_OK; | |
294 | } | |
295 | ||
7d12e780 | 296 | static irqreturn_t acpi_irq(int irq, void *dev_id) |
1da177e4 | 297 | { |
4be44fcd | 298 | return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE; |
1da177e4 LT |
299 | } |
300 | ||
301 | acpi_status | |
4be44fcd LB |
302 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
303 | void *context) | |
1da177e4 LT |
304 | { |
305 | unsigned int irq; | |
306 | ||
307 | /* | |
308 | * Ignore the GSI from the core, and use the value in our copy of the | |
309 | * FADT. It may not be the same if an interrupt source override exists | |
310 | * for the SCI. | |
311 | */ | |
cee324b1 | 312 | gsi = acpi_gbl_FADT.sci_interrupt; |
1da177e4 LT |
313 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { |
314 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", | |
315 | gsi); | |
316 | return AE_OK; | |
317 | } | |
318 | ||
319 | acpi_irq_handler = handler; | |
320 | acpi_irq_context = context; | |
dace1453 | 321 | if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) { |
1da177e4 LT |
322 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); |
323 | return AE_NOT_ACQUIRED; | |
324 | } | |
325 | acpi_irq_irq = irq; | |
326 | ||
327 | return AE_OK; | |
328 | } | |
329 | ||
4be44fcd | 330 | acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) |
1da177e4 LT |
331 | { |
332 | if (irq) { | |
333 | free_irq(irq, acpi_irq); | |
334 | acpi_irq_handler = NULL; | |
335 | acpi_irq_irq = 0; | |
336 | } | |
337 | ||
338 | return AE_OK; | |
339 | } | |
340 | ||
341 | /* | |
342 | * Running in interpreter thread context, safe to sleep | |
343 | */ | |
344 | ||
4be44fcd | 345 | void acpi_os_sleep(acpi_integer ms) |
1da177e4 | 346 | { |
01a527ec | 347 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
1da177e4 | 348 | } |
4be44fcd | 349 | |
1da177e4 LT |
350 | EXPORT_SYMBOL(acpi_os_sleep); |
351 | ||
4be44fcd | 352 | void acpi_os_stall(u32 us) |
1da177e4 LT |
353 | { |
354 | while (us) { | |
355 | u32 delay = 1000; | |
356 | ||
357 | if (delay > us) | |
358 | delay = us; | |
359 | udelay(delay); | |
360 | touch_nmi_watchdog(); | |
361 | us -= delay; | |
362 | } | |
363 | } | |
4be44fcd | 364 | |
1da177e4 LT |
365 | EXPORT_SYMBOL(acpi_os_stall); |
366 | ||
367 | /* | |
368 | * Support ACPI 3.0 AML Timer operand | |
369 | * Returns 64-bit free-running, monotonically increasing timer | |
370 | * with 100ns granularity | |
371 | */ | |
4be44fcd | 372 | u64 acpi_os_get_timer(void) |
1da177e4 LT |
373 | { |
374 | static u64 t; | |
375 | ||
376 | #ifdef CONFIG_HPET | |
377 | /* TBD: use HPET if available */ | |
378 | #endif | |
379 | ||
380 | #ifdef CONFIG_X86_PM_TIMER | |
381 | /* TBD: default to PM timer if HPET was not available */ | |
382 | #endif | |
383 | if (!t) | |
384 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); | |
385 | ||
386 | return ++t; | |
387 | } | |
388 | ||
4be44fcd | 389 | acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width) |
1da177e4 LT |
390 | { |
391 | u32 dummy; | |
392 | ||
393 | if (!value) | |
394 | value = &dummy; | |
395 | ||
4be44fcd | 396 | switch (width) { |
1da177e4 | 397 | case 8: |
4be44fcd | 398 | *(u8 *) value = inb(port); |
1da177e4 LT |
399 | break; |
400 | case 16: | |
4be44fcd | 401 | *(u16 *) value = inw(port); |
1da177e4 LT |
402 | break; |
403 | case 32: | |
4be44fcd | 404 | *(u32 *) value = inl(port); |
1da177e4 LT |
405 | break; |
406 | default: | |
407 | BUG(); | |
408 | } | |
409 | ||
410 | return AE_OK; | |
411 | } | |
4be44fcd | 412 | |
1da177e4 LT |
413 | EXPORT_SYMBOL(acpi_os_read_port); |
414 | ||
4be44fcd | 415 | acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width) |
1da177e4 | 416 | { |
4be44fcd | 417 | switch (width) { |
1da177e4 LT |
418 | case 8: |
419 | outb(value, port); | |
420 | break; | |
421 | case 16: | |
422 | outw(value, port); | |
423 | break; | |
424 | case 32: | |
425 | outl(value, port); | |
426 | break; | |
427 | default: | |
428 | BUG(); | |
429 | } | |
430 | ||
431 | return AE_OK; | |
432 | } | |
4be44fcd | 433 | |
1da177e4 LT |
434 | EXPORT_SYMBOL(acpi_os_write_port); |
435 | ||
436 | acpi_status | |
4be44fcd | 437 | acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width) |
1da177e4 | 438 | { |
4be44fcd LB |
439 | u32 dummy; |
440 | void __iomem *virt_addr; | |
1da177e4 | 441 | |
9f4fd61f | 442 | virt_addr = ioremap(phys_addr, width); |
1da177e4 LT |
443 | if (!value) |
444 | value = &dummy; | |
445 | ||
446 | switch (width) { | |
447 | case 8: | |
4be44fcd | 448 | *(u8 *) value = readb(virt_addr); |
1da177e4 LT |
449 | break; |
450 | case 16: | |
4be44fcd | 451 | *(u16 *) value = readw(virt_addr); |
1da177e4 LT |
452 | break; |
453 | case 32: | |
4be44fcd | 454 | *(u32 *) value = readl(virt_addr); |
1da177e4 LT |
455 | break; |
456 | default: | |
457 | BUG(); | |
458 | } | |
459 | ||
9f4fd61f | 460 | iounmap(virt_addr); |
1da177e4 LT |
461 | |
462 | return AE_OK; | |
463 | } | |
464 | ||
465 | acpi_status | |
4be44fcd | 466 | acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width) |
1da177e4 | 467 | { |
4be44fcd | 468 | void __iomem *virt_addr; |
1da177e4 | 469 | |
9f4fd61f | 470 | virt_addr = ioremap(phys_addr, width); |
1da177e4 LT |
471 | |
472 | switch (width) { | |
473 | case 8: | |
474 | writeb(value, virt_addr); | |
475 | break; | |
476 | case 16: | |
477 | writew(value, virt_addr); | |
478 | break; | |
479 | case 32: | |
480 | writel(value, virt_addr); | |
481 | break; | |
482 | default: | |
483 | BUG(); | |
484 | } | |
485 | ||
9f4fd61f | 486 | iounmap(virt_addr); |
1da177e4 LT |
487 | |
488 | return AE_OK; | |
489 | } | |
490 | ||
1da177e4 | 491 | acpi_status |
4be44fcd LB |
492 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
493 | void *value, u32 width) | |
1da177e4 LT |
494 | { |
495 | int result, size; | |
496 | ||
497 | if (!value) | |
498 | return AE_BAD_PARAMETER; | |
499 | ||
500 | switch (width) { | |
501 | case 8: | |
502 | size = 1; | |
503 | break; | |
504 | case 16: | |
505 | size = 2; | |
506 | break; | |
507 | case 32: | |
508 | size = 4; | |
509 | break; | |
510 | default: | |
511 | return AE_ERROR; | |
512 | } | |
513 | ||
514 | BUG_ON(!raw_pci_ops); | |
515 | ||
516 | result = raw_pci_ops->read(pci_id->segment, pci_id->bus, | |
4be44fcd LB |
517 | PCI_DEVFN(pci_id->device, pci_id->function), |
518 | reg, size, value); | |
1da177e4 LT |
519 | |
520 | return (result ? AE_ERROR : AE_OK); | |
521 | } | |
4be44fcd | 522 | |
1da177e4 LT |
523 | EXPORT_SYMBOL(acpi_os_read_pci_configuration); |
524 | ||
525 | acpi_status | |
4be44fcd LB |
526 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
527 | acpi_integer value, u32 width) | |
1da177e4 LT |
528 | { |
529 | int result, size; | |
530 | ||
531 | switch (width) { | |
532 | case 8: | |
533 | size = 1; | |
534 | break; | |
535 | case 16: | |
536 | size = 2; | |
537 | break; | |
538 | case 32: | |
539 | size = 4; | |
540 | break; | |
541 | default: | |
542 | return AE_ERROR; | |
543 | } | |
544 | ||
545 | BUG_ON(!raw_pci_ops); | |
546 | ||
547 | result = raw_pci_ops->write(pci_id->segment, pci_id->bus, | |
4be44fcd LB |
548 | PCI_DEVFN(pci_id->device, pci_id->function), |
549 | reg, size, value); | |
1da177e4 LT |
550 | |
551 | return (result ? AE_ERROR : AE_OK); | |
552 | } | |
553 | ||
554 | /* TODO: Change code to take advantage of driver model more */ | |
4be44fcd LB |
555 | static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */ |
556 | acpi_handle chandle, /* current node */ | |
557 | struct acpi_pci_id **id, | |
558 | int *is_bridge, u8 * bus_number) | |
1da177e4 | 559 | { |
4be44fcd LB |
560 | acpi_handle handle; |
561 | struct acpi_pci_id *pci_id = *id; | |
562 | acpi_status status; | |
563 | unsigned long temp; | |
564 | acpi_object_type type; | |
565 | u8 tu8; | |
1da177e4 LT |
566 | |
567 | acpi_get_parent(chandle, &handle); | |
568 | if (handle != rhandle) { | |
4be44fcd LB |
569 | acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge, |
570 | bus_number); | |
1da177e4 LT |
571 | |
572 | status = acpi_get_type(handle, &type); | |
4be44fcd | 573 | if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE)) |
1da177e4 LT |
574 | return; |
575 | ||
4be44fcd LB |
576 | status = |
577 | acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, | |
578 | &temp); | |
1da177e4 | 579 | if (ACPI_SUCCESS(status)) { |
4be44fcd LB |
580 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp)); |
581 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp)); | |
1da177e4 LT |
582 | |
583 | if (*is_bridge) | |
584 | pci_id->bus = *bus_number; | |
585 | ||
586 | /* any nicer way to get bus number of bridge ? */ | |
4be44fcd LB |
587 | status = |
588 | acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8, | |
589 | 8); | |
590 | if (ACPI_SUCCESS(status) | |
591 | && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) { | |
592 | status = | |
593 | acpi_os_read_pci_configuration(pci_id, 0x18, | |
594 | &tu8, 8); | |
1da177e4 LT |
595 | if (!ACPI_SUCCESS(status)) { |
596 | /* Certainly broken... FIX ME */ | |
597 | return; | |
598 | } | |
599 | *is_bridge = 1; | |
600 | pci_id->bus = tu8; | |
4be44fcd LB |
601 | status = |
602 | acpi_os_read_pci_configuration(pci_id, 0x19, | |
603 | &tu8, 8); | |
1da177e4 LT |
604 | if (ACPI_SUCCESS(status)) { |
605 | *bus_number = tu8; | |
606 | } | |
607 | } else | |
608 | *is_bridge = 0; | |
609 | } | |
610 | } | |
611 | } | |
612 | ||
4be44fcd LB |
613 | void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ |
614 | acpi_handle chandle, /* current node */ | |
615 | struct acpi_pci_id **id) | |
1da177e4 LT |
616 | { |
617 | int is_bridge = 1; | |
618 | u8 bus_number = (*id)->bus; | |
619 | ||
620 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); | |
621 | } | |
622 | ||
65f27f38 | 623 | static void acpi_os_execute_deferred(struct work_struct *work) |
88db5e14 AS |
624 | { |
625 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); | |
626 | if (!dpc) { | |
627 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); | |
628 | return; | |
629 | } | |
630 | ||
631 | dpc->function(dpc->context); | |
632 | kfree(dpc); | |
633 | ||
634 | /* Yield cpu to notify thread */ | |
635 | cond_resched(); | |
636 | ||
637 | return; | |
638 | } | |
639 | ||
640 | static void acpi_os_execute_notify(struct work_struct *work) | |
1da177e4 | 641 | { |
65f27f38 | 642 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); |
1da177e4 | 643 | |
1da177e4 | 644 | if (!dpc) { |
6468463a | 645 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); |
d550d98d | 646 | return; |
1da177e4 LT |
647 | } |
648 | ||
649 | dpc->function(dpc->context); | |
650 | ||
651 | kfree(dpc); | |
652 | ||
d550d98d | 653 | return; |
1da177e4 LT |
654 | } |
655 | ||
b8d35192 AS |
656 | /******************************************************************************* |
657 | * | |
658 | * FUNCTION: acpi_os_execute | |
659 | * | |
660 | * PARAMETERS: Type - Type of the callback | |
661 | * Function - Function to be executed | |
662 | * Context - Function parameters | |
663 | * | |
664 | * RETURN: Status | |
665 | * | |
666 | * DESCRIPTION: Depending on type, either queues function for deferred execution or | |
667 | * immediately executes function on a separate thread. | |
668 | * | |
669 | ******************************************************************************/ | |
670 | ||
671 | acpi_status acpi_os_execute(acpi_execute_type type, | |
4be44fcd | 672 | acpi_osd_exec_callback function, void *context) |
1da177e4 | 673 | { |
4be44fcd LB |
674 | acpi_status status = AE_OK; |
675 | struct acpi_os_dpc *dpc; | |
72945b2b | 676 | |
72945b2b LB |
677 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
678 | "Scheduling function [%p(%p)] for deferred execution.\n", | |
679 | function, context)); | |
1da177e4 LT |
680 | |
681 | if (!function) | |
88db5e14 | 682 | return AE_BAD_PARAMETER; |
72945b2b | 683 | |
1da177e4 LT |
684 | /* |
685 | * Allocate/initialize DPC structure. Note that this memory will be | |
65f27f38 | 686 | * freed by the callee. The kernel handles the work_struct list in a |
1da177e4 LT |
687 | * way that allows us to also free its memory inside the callee. |
688 | * Because we may want to schedule several tasks with different | |
689 | * parameters we can't use the approach some kernel code uses of | |
65f27f38 | 690 | * having a static work_struct. |
1da177e4 | 691 | */ |
72945b2b | 692 | |
65f27f38 | 693 | dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC); |
1da177e4 | 694 | if (!dpc) |
b976fe19 LT |
695 | return_ACPI_STATUS(AE_NO_MEMORY); |
696 | ||
1da177e4 LT |
697 | dpc->function = function; |
698 | dpc->context = context; | |
b976fe19 | 699 | |
88db5e14 AS |
700 | if (type == OSL_NOTIFY_HANDLER) { |
701 | INIT_WORK(&dpc->work, acpi_os_execute_notify); | |
702 | if (!queue_work(kacpi_notify_wq, &dpc->work)) { | |
703 | status = AE_ERROR; | |
704 | kfree(dpc); | |
705 | } | |
706 | } else { | |
707 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); | |
708 | if (!queue_work(kacpid_wq, &dpc->work)) { | |
709 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
b976fe19 | 710 | "Call to queue_work() failed.\n")); |
88db5e14 AS |
711 | status = AE_ERROR; |
712 | kfree(dpc); | |
713 | } | |
1da177e4 | 714 | } |
b976fe19 | 715 | return_ACPI_STATUS(status); |
1da177e4 | 716 | } |
4be44fcd | 717 | |
b8d35192 | 718 | EXPORT_SYMBOL(acpi_os_execute); |
1da177e4 | 719 | |
4be44fcd | 720 | void acpi_os_wait_events_complete(void *context) |
1da177e4 LT |
721 | { |
722 | flush_workqueue(kacpid_wq); | |
723 | } | |
4be44fcd | 724 | |
1da177e4 LT |
725 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
726 | ||
727 | /* | |
728 | * Allocate the memory for a spinlock and initialize it. | |
729 | */ | |
967440e3 | 730 | acpi_status acpi_os_create_lock(acpi_spinlock * handle) |
1da177e4 | 731 | { |
967440e3 | 732 | spin_lock_init(*handle); |
1da177e4 | 733 | |
d550d98d | 734 | return AE_OK; |
1da177e4 LT |
735 | } |
736 | ||
1da177e4 LT |
737 | /* |
738 | * Deallocate the memory for a spinlock. | |
739 | */ | |
967440e3 | 740 | void acpi_os_delete_lock(acpi_spinlock handle) |
1da177e4 | 741 | { |
d550d98d | 742 | return; |
1da177e4 LT |
743 | } |
744 | ||
1da177e4 | 745 | acpi_status |
4be44fcd | 746 | acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) |
1da177e4 | 747 | { |
4be44fcd | 748 | struct semaphore *sem = NULL; |
1da177e4 | 749 | |
1da177e4 LT |
750 | |
751 | sem = acpi_os_allocate(sizeof(struct semaphore)); | |
752 | if (!sem) | |
d550d98d | 753 | return AE_NO_MEMORY; |
1da177e4 LT |
754 | memset(sem, 0, sizeof(struct semaphore)); |
755 | ||
756 | sema_init(sem, initial_units); | |
757 | ||
4be44fcd | 758 | *handle = (acpi_handle *) sem; |
1da177e4 | 759 | |
4be44fcd LB |
760 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
761 | *handle, initial_units)); | |
1da177e4 | 762 | |
d550d98d | 763 | return AE_OK; |
1da177e4 | 764 | } |
1da177e4 | 765 | |
4be44fcd | 766 | EXPORT_SYMBOL(acpi_os_create_semaphore); |
1da177e4 LT |
767 | |
768 | /* | |
769 | * TODO: A better way to delete semaphores? Linux doesn't have a | |
770 | * 'delete_semaphore()' function -- may result in an invalid | |
771 | * pointer dereference for non-synchronized consumers. Should | |
772 | * we at least check for blocked threads and signal/cancel them? | |
773 | */ | |
774 | ||
4be44fcd | 775 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
1da177e4 | 776 | { |
4be44fcd | 777 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 778 | |
1da177e4 LT |
779 | |
780 | if (!sem) | |
d550d98d | 781 | return AE_BAD_PARAMETER; |
1da177e4 | 782 | |
4be44fcd | 783 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
1da177e4 | 784 | |
02438d87 | 785 | kfree(sem); |
4be44fcd | 786 | sem = NULL; |
1da177e4 | 787 | |
d550d98d | 788 | return AE_OK; |
1da177e4 | 789 | } |
1da177e4 | 790 | |
4be44fcd | 791 | EXPORT_SYMBOL(acpi_os_delete_semaphore); |
1da177e4 LT |
792 | |
793 | /* | |
794 | * TODO: The kernel doesn't have a 'down_timeout' function -- had to | |
795 | * improvise. The process is to sleep for one scheduler quantum | |
796 | * until the semaphore becomes available. Downside is that this | |
797 | * may result in starvation for timeout-based waits when there's | |
798 | * lots of semaphore activity. | |
799 | * | |
800 | * TODO: Support for units > 1? | |
801 | */ | |
4be44fcd | 802 | acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) |
1da177e4 | 803 | { |
4be44fcd LB |
804 | acpi_status status = AE_OK; |
805 | struct semaphore *sem = (struct semaphore *)handle; | |
806 | int ret = 0; | |
1da177e4 | 807 | |
1da177e4 LT |
808 | |
809 | if (!sem || (units < 1)) | |
d550d98d | 810 | return AE_BAD_PARAMETER; |
1da177e4 LT |
811 | |
812 | if (units > 1) | |
d550d98d | 813 | return AE_SUPPORT; |
1da177e4 | 814 | |
4be44fcd LB |
815 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
816 | handle, units, timeout)); | |
1da177e4 | 817 | |
d68909f4 LB |
818 | /* |
819 | * This can be called during resume with interrupts off. | |
820 | * Like boot-time, we should be single threaded and will | |
821 | * always get the lock if we try -- timeout or not. | |
822 | * If this doesn't succeed, then we will oops courtesy of | |
823 | * might_sleep() in down(). | |
824 | */ | |
825 | if (!down_trylock(sem)) | |
826 | return AE_OK; | |
827 | ||
4be44fcd | 828 | switch (timeout) { |
1da177e4 LT |
829 | /* |
830 | * No Wait: | |
831 | * -------- | |
832 | * A zero timeout value indicates that we shouldn't wait - just | |
833 | * acquire the semaphore if available otherwise return AE_TIME | |
834 | * (a.k.a. 'would block'). | |
835 | */ | |
4be44fcd LB |
836 | case 0: |
837 | if (down_trylock(sem)) | |
1da177e4 LT |
838 | status = AE_TIME; |
839 | break; | |
840 | ||
841 | /* | |
842 | * Wait Indefinitely: | |
843 | * ------------------ | |
844 | */ | |
4be44fcd | 845 | case ACPI_WAIT_FOREVER: |
1da177e4 LT |
846 | down(sem); |
847 | break; | |
848 | ||
849 | /* | |
850 | * Wait w/ Timeout: | |
851 | * ---------------- | |
852 | */ | |
4be44fcd | 853 | default: |
1da177e4 LT |
854 | // TODO: A better timeout algorithm? |
855 | { | |
856 | int i = 0; | |
4be44fcd | 857 | static const int quantum_ms = 1000 / HZ; |
1da177e4 LT |
858 | |
859 | ret = down_trylock(sem); | |
dacd9b80 | 860 | for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) { |
01a527ec | 861 | schedule_timeout_interruptible(1); |
1da177e4 LT |
862 | ret = down_trylock(sem); |
863 | } | |
4be44fcd | 864 | |
1da177e4 LT |
865 | if (ret != 0) |
866 | status = AE_TIME; | |
867 | } | |
868 | break; | |
869 | } | |
870 | ||
871 | if (ACPI_FAILURE(status)) { | |
9e7e2c04 | 872 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
a6fc6720 | 873 | "Failed to acquire semaphore[%p|%d|%d], %s", |
4be44fcd LB |
874 | handle, units, timeout, |
875 | acpi_format_exception(status))); | |
876 | } else { | |
877 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | |
a6fc6720 | 878 | "Acquired semaphore[%p|%d|%d]", handle, |
4be44fcd | 879 | units, timeout)); |
1da177e4 LT |
880 | } |
881 | ||
d550d98d | 882 | return status; |
1da177e4 | 883 | } |
1da177e4 | 884 | |
4be44fcd | 885 | EXPORT_SYMBOL(acpi_os_wait_semaphore); |
1da177e4 LT |
886 | |
887 | /* | |
888 | * TODO: Support for units > 1? | |
889 | */ | |
4be44fcd | 890 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
1da177e4 | 891 | { |
4be44fcd | 892 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 893 | |
1da177e4 LT |
894 | |
895 | if (!sem || (units < 1)) | |
d550d98d | 896 | return AE_BAD_PARAMETER; |
1da177e4 LT |
897 | |
898 | if (units > 1) | |
d550d98d | 899 | return AE_SUPPORT; |
1da177e4 | 900 | |
4be44fcd LB |
901 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
902 | units)); | |
1da177e4 LT |
903 | |
904 | up(sem); | |
905 | ||
d550d98d | 906 | return AE_OK; |
1da177e4 | 907 | } |
4be44fcd | 908 | |
1da177e4 LT |
909 | EXPORT_SYMBOL(acpi_os_signal_semaphore); |
910 | ||
911 | #ifdef ACPI_FUTURE_USAGE | |
4be44fcd | 912 | u32 acpi_os_get_line(char *buffer) |
1da177e4 LT |
913 | { |
914 | ||
915 | #ifdef ENABLE_DEBUGGER | |
916 | if (acpi_in_debugger) { | |
917 | u32 chars; | |
918 | ||
919 | kdb_read(buffer, sizeof(line_buf)); | |
920 | ||
921 | /* remove the CR kdb includes */ | |
922 | chars = strlen(buffer) - 1; | |
923 | buffer[chars] = '\0'; | |
924 | } | |
925 | #endif | |
926 | ||
927 | return 0; | |
928 | } | |
4be44fcd | 929 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 | 930 | |
4be44fcd | 931 | acpi_status acpi_os_signal(u32 function, void *info) |
1da177e4 | 932 | { |
4be44fcd | 933 | switch (function) { |
1da177e4 LT |
934 | case ACPI_SIGNAL_FATAL: |
935 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); | |
936 | break; | |
937 | case ACPI_SIGNAL_BREAKPOINT: | |
938 | /* | |
939 | * AML Breakpoint | |
940 | * ACPI spec. says to treat it as a NOP unless | |
941 | * you are debugging. So if/when we integrate | |
942 | * AML debugger into the kernel debugger its | |
943 | * hook will go here. But until then it is | |
944 | * not useful to print anything on breakpoints. | |
945 | */ | |
946 | break; | |
947 | default: | |
948 | break; | |
949 | } | |
950 | ||
951 | return AE_OK; | |
952 | } | |
4be44fcd | 953 | |
1da177e4 LT |
954 | EXPORT_SYMBOL(acpi_os_signal); |
955 | ||
4be44fcd | 956 | static int __init acpi_os_name_setup(char *str) |
1da177e4 LT |
957 | { |
958 | char *p = acpi_os_name; | |
4be44fcd | 959 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
1da177e4 LT |
960 | |
961 | if (!str || !*str) | |
962 | return 0; | |
963 | ||
964 | for (; count-- && str && *str; str++) { | |
965 | if (isalnum(*str) || *str == ' ' || *str == ':') | |
966 | *p++ = *str; | |
967 | else if (*str == '\'' || *str == '"') | |
968 | continue; | |
969 | else | |
970 | break; | |
971 | } | |
972 | *p = 0; | |
973 | ||
974 | return 1; | |
4be44fcd | 975 | |
1da177e4 LT |
976 | } |
977 | ||
978 | __setup("acpi_os_name=", acpi_os_name_setup); | |
979 | ||
f507654d LB |
980 | static void enable_osi_linux(int enable) { |
981 | ||
982 | if (osi_linux != enable) | |
983 | printk(KERN_INFO PREFIX "%sabled _OSI(Linux)\n", | |
984 | enable ? "En": "Dis"); | |
985 | ||
986 | osi_linux = enable; | |
987 | return; | |
988 | } | |
989 | ||
1da177e4 | 990 | /* |
ae00d812 LB |
991 | * Modify the list of "OS Interfaces" reported to BIOS via _OSI |
992 | * | |
1da177e4 | 993 | * empty string disables _OSI |
ae00d812 LB |
994 | * string starting with '!' disables that string |
995 | * otherwise string is added to list, augmenting built-in strings | |
1da177e4 | 996 | */ |
4be44fcd | 997 | static int __init acpi_osi_setup(char *str) |
1da177e4 LT |
998 | { |
999 | if (str == NULL || *str == '\0') { | |
1000 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); | |
1001 | acpi_gbl_create_osi_method = FALSE; | |
aa2e09da LB |
1002 | } else if (!strcmp("!Linux", str)) { |
1003 | enable_osi_linux(0); | |
ae00d812 LB |
1004 | } else if (*str == '!') { |
1005 | if (acpi_osi_invalidate(++str) == AE_OK) | |
1006 | printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); | |
f507654d LB |
1007 | } else if (!strcmp("Linux", str)) { |
1008 | enable_osi_linux(1); | |
ae00d812 LB |
1009 | } else if (*osi_additional_string == '\0') { |
1010 | strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX); | |
1011 | printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str); | |
1da177e4 LT |
1012 | } |
1013 | ||
1014 | return 1; | |
1015 | } | |
1016 | ||
1017 | __setup("acpi_osi=", acpi_osi_setup); | |
1018 | ||
1019 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ | |
4be44fcd | 1020 | static int __init acpi_serialize_setup(char *str) |
1da177e4 LT |
1021 | { |
1022 | printk(KERN_INFO PREFIX "serialize enabled\n"); | |
1023 | ||
1024 | acpi_gbl_all_methods_serialized = TRUE; | |
1025 | ||
1026 | return 1; | |
1027 | } | |
1028 | ||
1029 | __setup("acpi_serialize", acpi_serialize_setup); | |
1030 | ||
1031 | /* | |
1032 | * Wake and Run-Time GPES are expected to be separate. | |
1033 | * We disable wake-GPEs at run-time to prevent spurious | |
1034 | * interrupts. | |
1035 | * | |
1036 | * However, if a system exists that shares Wake and | |
1037 | * Run-time events on the same GPE this flag is available | |
1038 | * to tell Linux to keep the wake-time GPEs enabled at run-time. | |
1039 | */ | |
4be44fcd | 1040 | static int __init acpi_wake_gpes_always_on_setup(char *str) |
1da177e4 LT |
1041 | { |
1042 | printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); | |
1043 | ||
1044 | acpi_gbl_leave_wake_gpes_disabled = FALSE; | |
1045 | ||
1046 | return 1; | |
1047 | } | |
1048 | ||
1049 | __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); | |
1050 | ||
1051 | /* | |
1052 | * max_cstate is defined in the base kernel so modules can | |
1053 | * change it w/o depending on the state of the processor module. | |
1054 | */ | |
1055 | unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER; | |
1056 | ||
1da177e4 | 1057 | EXPORT_SYMBOL(max_cstate); |
73459f73 RM |
1058 | |
1059 | /* | |
1060 | * Acquire a spinlock. | |
1061 | * | |
1062 | * handle is a pointer to the spinlock_t. | |
73459f73 RM |
1063 | */ |
1064 | ||
967440e3 | 1065 | acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp) |
73459f73 | 1066 | { |
b8e4d893 | 1067 | acpi_cpu_flags flags; |
967440e3 | 1068 | spin_lock_irqsave(lockp, flags); |
73459f73 RM |
1069 | return flags; |
1070 | } | |
1071 | ||
1072 | /* | |
1073 | * Release a spinlock. See above. | |
1074 | */ | |
1075 | ||
967440e3 | 1076 | void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags) |
73459f73 | 1077 | { |
967440e3 | 1078 | spin_unlock_irqrestore(lockp, flags); |
73459f73 RM |
1079 | } |
1080 | ||
73459f73 RM |
1081 | #ifndef ACPI_USE_LOCAL_CACHE |
1082 | ||
1083 | /******************************************************************************* | |
1084 | * | |
1085 | * FUNCTION: acpi_os_create_cache | |
1086 | * | |
b229cf92 BM |
1087 | * PARAMETERS: name - Ascii name for the cache |
1088 | * size - Size of each cached object | |
1089 | * depth - Maximum depth of the cache (in objects) <ignored> | |
1090 | * cache - Where the new cache object is returned | |
73459f73 | 1091 | * |
b229cf92 | 1092 | * RETURN: status |
73459f73 RM |
1093 | * |
1094 | * DESCRIPTION: Create a cache object | |
1095 | * | |
1096 | ******************************************************************************/ | |
1097 | ||
1098 | acpi_status | |
4be44fcd | 1099 | acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) |
73459f73 | 1100 | { |
4be44fcd | 1101 | *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL); |
a6fdbf90 | 1102 | if (*cache == NULL) |
b229cf92 BM |
1103 | return AE_ERROR; |
1104 | else | |
1105 | return AE_OK; | |
73459f73 RM |
1106 | } |
1107 | ||
1108 | /******************************************************************************* | |
1109 | * | |
1110 | * FUNCTION: acpi_os_purge_cache | |
1111 | * | |
1112 | * PARAMETERS: Cache - Handle to cache object | |
1113 | * | |
1114 | * RETURN: Status | |
1115 | * | |
1116 | * DESCRIPTION: Free all objects within the requested cache. | |
1117 | * | |
1118 | ******************************************************************************/ | |
1119 | ||
4be44fcd | 1120 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
73459f73 | 1121 | { |
50dd0969 | 1122 | kmem_cache_shrink(cache); |
4be44fcd | 1123 | return (AE_OK); |
73459f73 RM |
1124 | } |
1125 | ||
1126 | /******************************************************************************* | |
1127 | * | |
1128 | * FUNCTION: acpi_os_delete_cache | |
1129 | * | |
1130 | * PARAMETERS: Cache - Handle to cache object | |
1131 | * | |
1132 | * RETURN: Status | |
1133 | * | |
1134 | * DESCRIPTION: Free all objects within the requested cache and delete the | |
1135 | * cache object. | |
1136 | * | |
1137 | ******************************************************************************/ | |
1138 | ||
4be44fcd | 1139 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
73459f73 | 1140 | { |
1a1d92c1 | 1141 | kmem_cache_destroy(cache); |
4be44fcd | 1142 | return (AE_OK); |
73459f73 RM |
1143 | } |
1144 | ||
1145 | /******************************************************************************* | |
1146 | * | |
1147 | * FUNCTION: acpi_os_release_object | |
1148 | * | |
1149 | * PARAMETERS: Cache - Handle to cache object | |
1150 | * Object - The object to be released | |
1151 | * | |
1152 | * RETURN: None | |
1153 | * | |
1154 | * DESCRIPTION: Release an object to the specified cache. If cache is full, | |
1155 | * the object is deleted. | |
1156 | * | |
1157 | ******************************************************************************/ | |
1158 | ||
4be44fcd | 1159 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
73459f73 | 1160 | { |
4be44fcd LB |
1161 | kmem_cache_free(cache, object); |
1162 | return (AE_OK); | |
73459f73 RM |
1163 | } |
1164 | ||
b229cf92 BM |
1165 | /****************************************************************************** |
1166 | * | |
1167 | * FUNCTION: acpi_os_validate_interface | |
1168 | * | |
1169 | * PARAMETERS: interface - Requested interface to be validated | |
1170 | * | |
1171 | * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise | |
1172 | * | |
1173 | * DESCRIPTION: Match an interface string to the interfaces supported by the | |
1174 | * host. Strings originate from an AML call to the _OSI method. | |
1175 | * | |
1176 | *****************************************************************************/ | |
1177 | ||
1178 | acpi_status | |
1179 | acpi_os_validate_interface (char *interface) | |
1180 | { | |
ae00d812 LB |
1181 | if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX)) |
1182 | return AE_OK; | |
f507654d LB |
1183 | if (!strcmp("Linux", interface)) { |
1184 | printk(KERN_WARNING PREFIX | |
1185 | "System BIOS is requesting _OSI(Linux)\n"); | |
1186 | #ifdef OSI_LINUX_ENABLED | |
1187 | printk(KERN_WARNING PREFIX | |
1188 | "Please test with \"acpi_osi=!Linux\"\n" | |
1189 | "Please send dmidecode " | |
1190 | "to linux-acpi@vger.kernel.org\n"); | |
1191 | #else | |
1192 | printk(KERN_WARNING PREFIX | |
1193 | "If \"acpi_osi=Linux\" works better,\n" | |
1194 | "Please send dmidecode " | |
1195 | "to linux-acpi@vger.kernel.org\n"); | |
1196 | #endif | |
1197 | if(osi_linux) | |
1198 | return AE_OK; | |
1199 | } | |
ae00d812 | 1200 | return AE_SUPPORT; |
b229cf92 BM |
1201 | } |
1202 | ||
b229cf92 BM |
1203 | /****************************************************************************** |
1204 | * | |
1205 | * FUNCTION: acpi_os_validate_address | |
1206 | * | |
1207 | * PARAMETERS: space_id - ACPI space ID | |
1208 | * address - Physical address | |
1209 | * length - Address length | |
1210 | * | |
1211 | * RETURN: AE_OK if address/length is valid for the space_id. Otherwise, | |
1212 | * should return AE_AML_ILLEGAL_ADDRESS. | |
1213 | * | |
1214 | * DESCRIPTION: Validate a system address via the host OS. Used to validate | |
1215 | * the addresses accessed by AML operation regions. | |
1216 | * | |
1217 | *****************************************************************************/ | |
1218 | ||
1219 | acpi_status | |
1220 | acpi_os_validate_address ( | |
1221 | u8 space_id, | |
1222 | acpi_physical_address address, | |
1223 | acpi_size length) | |
1224 | { | |
1225 | ||
1226 | return AE_OK; | |
1227 | } | |
1228 | ||
f507654d LB |
1229 | #ifdef CONFIG_DMI |
1230 | #ifdef OSI_LINUX_ENABLED | |
1231 | static int dmi_osi_not_linux(struct dmi_system_id *d) | |
1232 | { | |
1233 | printk(KERN_NOTICE "%s detected: requires not _OSI(Linux)\n", d->ident); | |
1234 | enable_osi_linux(0); | |
1235 | return 0; | |
1236 | } | |
1237 | #else | |
1238 | static int dmi_osi_linux(struct dmi_system_id *d) | |
1239 | { | |
1240 | printk(KERN_NOTICE "%s detected: requires _OSI(Linux)\n", d->ident); | |
1241 | enable_osi_linux(1); | |
1242 | return 0; | |
1243 | } | |
1244 | #endif | |
1245 | ||
dd272b57 | 1246 | static struct dmi_system_id acpi_osl_dmi_table[] __initdata = { |
f507654d LB |
1247 | #ifdef OSI_LINUX_ENABLED |
1248 | /* | |
1249 | * Boxes that need NOT _OSI(Linux) | |
1250 | */ | |
1251 | { | |
1252 | .callback = dmi_osi_not_linux, | |
1253 | .ident = "Toshiba Satellite P100", | |
1254 | .matches = { | |
1255 | DMI_MATCH(DMI_BOARD_VENDOR, "TOSHIBA"), | |
1256 | DMI_MATCH(DMI_BOARD_NAME, "Satellite P100"), | |
1257 | }, | |
1258 | }, | |
1259 | #else | |
1260 | /* | |
1261 | * Boxes that need _OSI(Linux) | |
1262 | */ | |
1263 | { | |
1264 | .callback = dmi_osi_linux, | |
1265 | .ident = "Intel Napa CRB", | |
1266 | .matches = { | |
1267 | DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), | |
1268 | DMI_MATCH(DMI_BOARD_NAME, "MPAD-MSAE Customer Reference Boards"), | |
1269 | }, | |
1270 | }, | |
1271 | #endif | |
1272 | {} | |
1273 | }; | |
1274 | #endif /* CONFIG_DMI */ | |
b229cf92 | 1275 | |
73459f73 | 1276 | #endif |