]>
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 | ||
28 | #include <linux/config.h> | |
29 | #include <linux/module.h> | |
30 | #include <linux/kernel.h> | |
31 | #include <linux/slab.h> | |
32 | #include <linux/mm.h> | |
33 | #include <linux/pci.h> | |
34 | #include <linux/smp_lock.h> | |
35 | #include <linux/interrupt.h> | |
36 | #include <linux/kmod.h> | |
37 | #include <linux/delay.h> | |
38 | #include <linux/workqueue.h> | |
39 | #include <linux/nmi.h> | |
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 |
4be44fcd | 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; | |
1da177e4 LT |
54 | }; |
55 | ||
56 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | |
57 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE | |
58 | #endif | |
59 | ||
60 | #ifdef ENABLE_DEBUGGER | |
61 | #include <linux/kdb.h> | |
62 | ||
63 | /* stuff for debugger support */ | |
64 | int acpi_in_debugger; | |
65 | EXPORT_SYMBOL(acpi_in_debugger); | |
66 | ||
67 | extern char line_buf[80]; | |
4be44fcd | 68 | #endif /*ENABLE_DEBUGGER */ |
1da177e4 | 69 | |
30e332f3 | 70 | int acpi_specific_hotkey_enabled = TRUE; |
fb9802fa LY |
71 | EXPORT_SYMBOL(acpi_specific_hotkey_enabled); |
72 | ||
1da177e4 LT |
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; | |
77 | ||
4be44fcd | 78 | acpi_status acpi_os_initialize(void) |
1da177e4 LT |
79 | { |
80 | return AE_OK; | |
81 | } | |
82 | ||
4be44fcd | 83 | acpi_status acpi_os_initialize1(void) |
1da177e4 LT |
84 | { |
85 | /* | |
86 | * Initialize PCI configuration space access, as we'll need to access | |
87 | * it while walking the namespace (bus 0 and root bridges w/ _BBNs). | |
88 | */ | |
1da177e4 | 89 | if (!raw_pci_ops) { |
4be44fcd LB |
90 | printk(KERN_ERR PREFIX |
91 | "Access to PCI configuration space unavailable\n"); | |
1da177e4 LT |
92 | return AE_NULL_ENTRY; |
93 | } | |
1da177e4 LT |
94 | kacpid_wq = create_singlethread_workqueue("kacpid"); |
95 | BUG_ON(!kacpid_wq); | |
96 | ||
97 | return AE_OK; | |
98 | } | |
99 | ||
4be44fcd | 100 | acpi_status acpi_os_terminate(void) |
1da177e4 LT |
101 | { |
102 | if (acpi_irq_handler) { | |
103 | acpi_os_remove_interrupt_handler(acpi_irq_irq, | |
104 | acpi_irq_handler); | |
105 | } | |
106 | ||
107 | destroy_workqueue(kacpid_wq); | |
108 | ||
109 | return AE_OK; | |
110 | } | |
111 | ||
4be44fcd | 112 | void acpi_os_printf(const char *fmt, ...) |
1da177e4 LT |
113 | { |
114 | va_list args; | |
115 | va_start(args, fmt); | |
116 | acpi_os_vprintf(fmt, args); | |
117 | va_end(args); | |
118 | } | |
4be44fcd | 119 | |
1da177e4 LT |
120 | EXPORT_SYMBOL(acpi_os_printf); |
121 | ||
4be44fcd | 122 | void acpi_os_vprintf(const char *fmt, va_list args) |
1da177e4 LT |
123 | { |
124 | static char buffer[512]; | |
4be44fcd | 125 | |
1da177e4 LT |
126 | vsprintf(buffer, fmt, args); |
127 | ||
128 | #ifdef ENABLE_DEBUGGER | |
129 | if (acpi_in_debugger) { | |
130 | kdb_printf("%s", buffer); | |
131 | } else { | |
132 | printk("%s", buffer); | |
133 | } | |
134 | #else | |
135 | printk("%s", buffer); | |
136 | #endif | |
137 | } | |
138 | ||
11e981f1 | 139 | extern int acpi_in_resume; |
4be44fcd | 140 | void *acpi_os_allocate(acpi_size size) |
1da177e4 | 141 | { |
11e981f1 DSL |
142 | if (acpi_in_resume) |
143 | return kmalloc(size, GFP_ATOMIC); | |
144 | else | |
145 | return kmalloc(size, GFP_KERNEL); | |
1da177e4 LT |
146 | } |
147 | ||
4be44fcd | 148 | void acpi_os_free(void *ptr) |
1da177e4 LT |
149 | { |
150 | kfree(ptr); | |
151 | } | |
4be44fcd | 152 | |
1da177e4 LT |
153 | EXPORT_SYMBOL(acpi_os_free); |
154 | ||
4be44fcd | 155 | acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr) |
1da177e4 LT |
156 | { |
157 | if (efi_enabled) { | |
158 | addr->pointer_type = ACPI_PHYSICAL_POINTER; | |
159 | if (efi.acpi20) | |
160 | addr->pointer.physical = | |
4be44fcd | 161 | (acpi_physical_address) virt_to_phys(efi.acpi20); |
1da177e4 LT |
162 | else if (efi.acpi) |
163 | addr->pointer.physical = | |
4be44fcd | 164 | (acpi_physical_address) virt_to_phys(efi.acpi); |
1da177e4 | 165 | else { |
4be44fcd LB |
166 | printk(KERN_ERR PREFIX |
167 | "System description tables not found\n"); | |
1da177e4 LT |
168 | return AE_NOT_FOUND; |
169 | } | |
170 | } else { | |
171 | if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) { | |
4be44fcd LB |
172 | printk(KERN_ERR PREFIX |
173 | "System description tables not found\n"); | |
1da177e4 LT |
174 | return AE_NOT_FOUND; |
175 | } | |
176 | } | |
177 | ||
178 | return AE_OK; | |
179 | } | |
180 | ||
181 | acpi_status | |
4be44fcd LB |
182 | acpi_os_map_memory(acpi_physical_address phys, acpi_size size, |
183 | void __iomem ** virt) | |
1da177e4 LT |
184 | { |
185 | if (efi_enabled) { | |
186 | if (EFI_MEMORY_WB & efi_mem_attributes(phys)) { | |
4be44fcd | 187 | *virt = (void __iomem *)phys_to_virt(phys); |
1da177e4 LT |
188 | } else { |
189 | *virt = ioremap(phys, size); | |
190 | } | |
191 | } else { | |
192 | if (phys > ULONG_MAX) { | |
193 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); | |
194 | return AE_BAD_PARAMETER; | |
195 | } | |
196 | /* | |
4be44fcd LB |
197 | * ioremap checks to ensure this is in reserved space |
198 | */ | |
199 | *virt = ioremap((unsigned long)phys, size); | |
1da177e4 LT |
200 | } |
201 | ||
202 | if (!*virt) | |
203 | return AE_NO_MEMORY; | |
204 | ||
205 | return AE_OK; | |
206 | } | |
55a82ab3 | 207 | EXPORT_SYMBOL_GPL(acpi_os_map_memory); |
1da177e4 | 208 | |
4be44fcd | 209 | void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) |
1da177e4 LT |
210 | { |
211 | iounmap(virt); | |
212 | } | |
55a82ab3 | 213 | EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); |
1da177e4 LT |
214 | |
215 | #ifdef ACPI_FUTURE_USAGE | |
216 | acpi_status | |
4be44fcd | 217 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
1da177e4 | 218 | { |
4be44fcd | 219 | if (!phys || !virt) |
1da177e4 LT |
220 | return AE_BAD_PARAMETER; |
221 | ||
222 | *phys = virt_to_phys(virt); | |
223 | ||
224 | return AE_OK; | |
225 | } | |
226 | #endif | |
227 | ||
228 | #define ACPI_MAX_OVERRIDE_LEN 100 | |
229 | ||
230 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; | |
231 | ||
232 | acpi_status | |
4be44fcd LB |
233 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
234 | acpi_string * new_val) | |
1da177e4 LT |
235 | { |
236 | if (!init_val || !new_val) | |
237 | return AE_BAD_PARAMETER; | |
238 | ||
239 | *new_val = NULL; | |
4be44fcd | 240 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
1da177e4 | 241 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
4be44fcd | 242 | acpi_os_name); |
1da177e4 LT |
243 | *new_val = acpi_os_name; |
244 | } | |
245 | ||
246 | return AE_OK; | |
247 | } | |
248 | ||
249 | acpi_status | |
4be44fcd LB |
250 | acpi_os_table_override(struct acpi_table_header * existing_table, |
251 | struct acpi_table_header ** new_table) | |
1da177e4 LT |
252 | { |
253 | if (!existing_table || !new_table) | |
254 | return AE_BAD_PARAMETER; | |
255 | ||
256 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | |
257 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) | |
4be44fcd | 258 | *new_table = (struct acpi_table_header *)AmlCode; |
1da177e4 LT |
259 | else |
260 | *new_table = NULL; | |
261 | #else | |
262 | *new_table = NULL; | |
263 | #endif | |
264 | return AE_OK; | |
265 | } | |
266 | ||
4be44fcd | 267 | static irqreturn_t acpi_irq(int irq, void *dev_id, struct pt_regs *regs) |
1da177e4 | 268 | { |
4be44fcd | 269 | return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE; |
1da177e4 LT |
270 | } |
271 | ||
272 | acpi_status | |
4be44fcd LB |
273 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
274 | void *context) | |
1da177e4 LT |
275 | { |
276 | unsigned int irq; | |
277 | ||
278 | /* | |
279 | * Ignore the GSI from the core, and use the value in our copy of the | |
280 | * FADT. It may not be the same if an interrupt source override exists | |
281 | * for the SCI. | |
282 | */ | |
283 | gsi = acpi_fadt.sci_int; | |
284 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { | |
285 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", | |
286 | gsi); | |
287 | return AE_OK; | |
288 | } | |
289 | ||
290 | acpi_irq_handler = handler; | |
291 | acpi_irq_context = context; | |
292 | if (request_irq(irq, acpi_irq, SA_SHIRQ, "acpi", acpi_irq)) { | |
293 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); | |
294 | return AE_NOT_ACQUIRED; | |
295 | } | |
296 | acpi_irq_irq = irq; | |
297 | ||
298 | return AE_OK; | |
299 | } | |
300 | ||
4be44fcd | 301 | acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) |
1da177e4 LT |
302 | { |
303 | if (irq) { | |
304 | free_irq(irq, acpi_irq); | |
305 | acpi_irq_handler = NULL; | |
306 | acpi_irq_irq = 0; | |
307 | } | |
308 | ||
309 | return AE_OK; | |
310 | } | |
311 | ||
312 | /* | |
313 | * Running in interpreter thread context, safe to sleep | |
314 | */ | |
315 | ||
4be44fcd | 316 | void acpi_os_sleep(acpi_integer ms) |
1da177e4 | 317 | { |
01a527ec | 318 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
1da177e4 | 319 | } |
4be44fcd | 320 | |
1da177e4 LT |
321 | EXPORT_SYMBOL(acpi_os_sleep); |
322 | ||
4be44fcd | 323 | void acpi_os_stall(u32 us) |
1da177e4 LT |
324 | { |
325 | while (us) { | |
326 | u32 delay = 1000; | |
327 | ||
328 | if (delay > us) | |
329 | delay = us; | |
330 | udelay(delay); | |
331 | touch_nmi_watchdog(); | |
332 | us -= delay; | |
333 | } | |
334 | } | |
4be44fcd | 335 | |
1da177e4 LT |
336 | EXPORT_SYMBOL(acpi_os_stall); |
337 | ||
338 | /* | |
339 | * Support ACPI 3.0 AML Timer operand | |
340 | * Returns 64-bit free-running, monotonically increasing timer | |
341 | * with 100ns granularity | |
342 | */ | |
4be44fcd | 343 | u64 acpi_os_get_timer(void) |
1da177e4 LT |
344 | { |
345 | static u64 t; | |
346 | ||
347 | #ifdef CONFIG_HPET | |
348 | /* TBD: use HPET if available */ | |
349 | #endif | |
350 | ||
351 | #ifdef CONFIG_X86_PM_TIMER | |
352 | /* TBD: default to PM timer if HPET was not available */ | |
353 | #endif | |
354 | if (!t) | |
355 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); | |
356 | ||
357 | return ++t; | |
358 | } | |
359 | ||
4be44fcd | 360 | acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width) |
1da177e4 LT |
361 | { |
362 | u32 dummy; | |
363 | ||
364 | if (!value) | |
365 | value = &dummy; | |
366 | ||
4be44fcd | 367 | switch (width) { |
1da177e4 | 368 | case 8: |
4be44fcd | 369 | *(u8 *) value = inb(port); |
1da177e4 LT |
370 | break; |
371 | case 16: | |
4be44fcd | 372 | *(u16 *) value = inw(port); |
1da177e4 LT |
373 | break; |
374 | case 32: | |
4be44fcd | 375 | *(u32 *) value = inl(port); |
1da177e4 LT |
376 | break; |
377 | default: | |
378 | BUG(); | |
379 | } | |
380 | ||
381 | return AE_OK; | |
382 | } | |
4be44fcd | 383 | |
1da177e4 LT |
384 | EXPORT_SYMBOL(acpi_os_read_port); |
385 | ||
4be44fcd | 386 | acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width) |
1da177e4 | 387 | { |
4be44fcd | 388 | switch (width) { |
1da177e4 LT |
389 | case 8: |
390 | outb(value, port); | |
391 | break; | |
392 | case 16: | |
393 | outw(value, port); | |
394 | break; | |
395 | case 32: | |
396 | outl(value, port); | |
397 | break; | |
398 | default: | |
399 | BUG(); | |
400 | } | |
401 | ||
402 | return AE_OK; | |
403 | } | |
4be44fcd | 404 | |
1da177e4 LT |
405 | EXPORT_SYMBOL(acpi_os_write_port); |
406 | ||
407 | acpi_status | |
4be44fcd | 408 | acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width) |
1da177e4 | 409 | { |
4be44fcd LB |
410 | u32 dummy; |
411 | void __iomem *virt_addr; | |
412 | int iomem = 0; | |
1da177e4 LT |
413 | |
414 | if (efi_enabled) { | |
415 | if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) { | |
416 | /* HACK ALERT! We can use readb/w/l on real memory too.. */ | |
4be44fcd | 417 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
1da177e4 LT |
418 | } else { |
419 | iomem = 1; | |
420 | virt_addr = ioremap(phys_addr, width); | |
421 | } | |
422 | } else | |
4be44fcd | 423 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
1da177e4 LT |
424 | if (!value) |
425 | value = &dummy; | |
426 | ||
427 | switch (width) { | |
428 | case 8: | |
4be44fcd | 429 | *(u8 *) value = readb(virt_addr); |
1da177e4 LT |
430 | break; |
431 | case 16: | |
4be44fcd | 432 | *(u16 *) value = readw(virt_addr); |
1da177e4 LT |
433 | break; |
434 | case 32: | |
4be44fcd | 435 | *(u32 *) value = readl(virt_addr); |
1da177e4 LT |
436 | break; |
437 | default: | |
438 | BUG(); | |
439 | } | |
440 | ||
441 | if (efi_enabled) { | |
442 | if (iomem) | |
443 | iounmap(virt_addr); | |
444 | } | |
445 | ||
446 | return AE_OK; | |
447 | } | |
448 | ||
449 | acpi_status | |
4be44fcd | 450 | acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width) |
1da177e4 | 451 | { |
4be44fcd LB |
452 | void __iomem *virt_addr; |
453 | int iomem = 0; | |
1da177e4 LT |
454 | |
455 | if (efi_enabled) { | |
456 | if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) { | |
457 | /* HACK ALERT! We can use writeb/w/l on real memory too */ | |
4be44fcd | 458 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
1da177e4 LT |
459 | } else { |
460 | iomem = 1; | |
461 | virt_addr = ioremap(phys_addr, width); | |
462 | } | |
463 | } else | |
4be44fcd | 464 | virt_addr = (void __iomem *)phys_to_virt(phys_addr); |
1da177e4 LT |
465 | |
466 | switch (width) { | |
467 | case 8: | |
468 | writeb(value, virt_addr); | |
469 | break; | |
470 | case 16: | |
471 | writew(value, virt_addr); | |
472 | break; | |
473 | case 32: | |
474 | writel(value, virt_addr); | |
475 | break; | |
476 | default: | |
477 | BUG(); | |
478 | } | |
479 | ||
480 | if (iomem) | |
481 | iounmap(virt_addr); | |
482 | ||
483 | return AE_OK; | |
484 | } | |
485 | ||
1da177e4 | 486 | acpi_status |
4be44fcd LB |
487 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
488 | void *value, u32 width) | |
1da177e4 LT |
489 | { |
490 | int result, size; | |
491 | ||
492 | if (!value) | |
493 | return AE_BAD_PARAMETER; | |
494 | ||
495 | switch (width) { | |
496 | case 8: | |
497 | size = 1; | |
498 | break; | |
499 | case 16: | |
500 | size = 2; | |
501 | break; | |
502 | case 32: | |
503 | size = 4; | |
504 | break; | |
505 | default: | |
506 | return AE_ERROR; | |
507 | } | |
508 | ||
509 | BUG_ON(!raw_pci_ops); | |
510 | ||
511 | result = raw_pci_ops->read(pci_id->segment, pci_id->bus, | |
4be44fcd LB |
512 | PCI_DEVFN(pci_id->device, pci_id->function), |
513 | reg, size, value); | |
1da177e4 LT |
514 | |
515 | return (result ? AE_ERROR : AE_OK); | |
516 | } | |
4be44fcd | 517 | |
1da177e4 LT |
518 | EXPORT_SYMBOL(acpi_os_read_pci_configuration); |
519 | ||
520 | acpi_status | |
4be44fcd LB |
521 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
522 | acpi_integer value, u32 width) | |
1da177e4 LT |
523 | { |
524 | int result, size; | |
525 | ||
526 | switch (width) { | |
527 | case 8: | |
528 | size = 1; | |
529 | break; | |
530 | case 16: | |
531 | size = 2; | |
532 | break; | |
533 | case 32: | |
534 | size = 4; | |
535 | break; | |
536 | default: | |
537 | return AE_ERROR; | |
538 | } | |
539 | ||
540 | BUG_ON(!raw_pci_ops); | |
541 | ||
542 | result = raw_pci_ops->write(pci_id->segment, pci_id->bus, | |
4be44fcd LB |
543 | PCI_DEVFN(pci_id->device, pci_id->function), |
544 | reg, size, value); | |
1da177e4 LT |
545 | |
546 | return (result ? AE_ERROR : AE_OK); | |
547 | } | |
548 | ||
549 | /* TODO: Change code to take advantage of driver model more */ | |
4be44fcd LB |
550 | static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */ |
551 | acpi_handle chandle, /* current node */ | |
552 | struct acpi_pci_id **id, | |
553 | int *is_bridge, u8 * bus_number) | |
1da177e4 | 554 | { |
4be44fcd LB |
555 | acpi_handle handle; |
556 | struct acpi_pci_id *pci_id = *id; | |
557 | acpi_status status; | |
558 | unsigned long temp; | |
559 | acpi_object_type type; | |
560 | u8 tu8; | |
1da177e4 LT |
561 | |
562 | acpi_get_parent(chandle, &handle); | |
563 | if (handle != rhandle) { | |
4be44fcd LB |
564 | acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge, |
565 | bus_number); | |
1da177e4 LT |
566 | |
567 | status = acpi_get_type(handle, &type); | |
4be44fcd | 568 | if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE)) |
1da177e4 LT |
569 | return; |
570 | ||
4be44fcd LB |
571 | status = |
572 | acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, | |
573 | &temp); | |
1da177e4 | 574 | if (ACPI_SUCCESS(status)) { |
4be44fcd LB |
575 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp)); |
576 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp)); | |
1da177e4 LT |
577 | |
578 | if (*is_bridge) | |
579 | pci_id->bus = *bus_number; | |
580 | ||
581 | /* any nicer way to get bus number of bridge ? */ | |
4be44fcd LB |
582 | status = |
583 | acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8, | |
584 | 8); | |
585 | if (ACPI_SUCCESS(status) | |
586 | && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) { | |
587 | status = | |
588 | acpi_os_read_pci_configuration(pci_id, 0x18, | |
589 | &tu8, 8); | |
1da177e4 LT |
590 | if (!ACPI_SUCCESS(status)) { |
591 | /* Certainly broken... FIX ME */ | |
592 | return; | |
593 | } | |
594 | *is_bridge = 1; | |
595 | pci_id->bus = tu8; | |
4be44fcd LB |
596 | status = |
597 | acpi_os_read_pci_configuration(pci_id, 0x19, | |
598 | &tu8, 8); | |
1da177e4 LT |
599 | if (ACPI_SUCCESS(status)) { |
600 | *bus_number = tu8; | |
601 | } | |
602 | } else | |
603 | *is_bridge = 0; | |
604 | } | |
605 | } | |
606 | } | |
607 | ||
4be44fcd LB |
608 | void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ |
609 | acpi_handle chandle, /* current node */ | |
610 | struct acpi_pci_id **id) | |
1da177e4 LT |
611 | { |
612 | int is_bridge = 1; | |
613 | u8 bus_number = (*id)->bus; | |
614 | ||
615 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); | |
616 | } | |
617 | ||
4be44fcd | 618 | static void acpi_os_execute_deferred(void *context) |
1da177e4 | 619 | { |
4be44fcd | 620 | struct acpi_os_dpc *dpc = NULL; |
1da177e4 | 621 | |
4be44fcd | 622 | ACPI_FUNCTION_TRACE("os_execute_deferred"); |
1da177e4 | 623 | |
4be44fcd | 624 | dpc = (struct acpi_os_dpc *)context; |
1da177e4 | 625 | if (!dpc) { |
4be44fcd | 626 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n")); |
1da177e4 LT |
627 | return_VOID; |
628 | } | |
629 | ||
630 | dpc->function(dpc->context); | |
631 | ||
632 | kfree(dpc); | |
633 | ||
634 | return_VOID; | |
635 | } | |
636 | ||
637 | acpi_status | |
4be44fcd LB |
638 | acpi_os_queue_for_execution(u32 priority, |
639 | acpi_osd_exec_callback function, void *context) | |
1da177e4 | 640 | { |
4be44fcd LB |
641 | acpi_status status = AE_OK; |
642 | struct acpi_os_dpc *dpc; | |
643 | struct work_struct *task; | |
1da177e4 | 644 | |
4be44fcd | 645 | ACPI_FUNCTION_TRACE("os_queue_for_execution"); |
1da177e4 | 646 | |
4be44fcd LB |
647 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
648 | "Scheduling function [%p(%p)] for deferred execution.\n", | |
649 | function, context)); | |
1da177e4 LT |
650 | |
651 | if (!function) | |
4be44fcd | 652 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
653 | |
654 | /* | |
655 | * Allocate/initialize DPC structure. Note that this memory will be | |
656 | * freed by the callee. The kernel handles the tq_struct list in a | |
657 | * way that allows us to also free its memory inside the callee. | |
658 | * Because we may want to schedule several tasks with different | |
659 | * parameters we can't use the approach some kernel code uses of | |
660 | * having a static tq_struct. | |
661 | * We can save time and code by allocating the DPC and tq_structs | |
662 | * from the same memory. | |
663 | */ | |
664 | ||
4be44fcd LB |
665 | dpc = |
666 | kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct), | |
667 | GFP_ATOMIC); | |
1da177e4 | 668 | if (!dpc) |
4be44fcd | 669 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
670 | |
671 | dpc->function = function; | |
672 | dpc->context = context; | |
673 | ||
4be44fcd LB |
674 | task = (void *)(dpc + 1); |
675 | INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc); | |
1da177e4 LT |
676 | |
677 | if (!queue_work(kacpid_wq, task)) { | |
4be44fcd LB |
678 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
679 | "Call to queue_work() failed.\n")); | |
1da177e4 LT |
680 | kfree(dpc); |
681 | status = AE_ERROR; | |
682 | } | |
683 | ||
4be44fcd | 684 | return_ACPI_STATUS(status); |
1da177e4 | 685 | } |
4be44fcd | 686 | |
1da177e4 LT |
687 | EXPORT_SYMBOL(acpi_os_queue_for_execution); |
688 | ||
4be44fcd | 689 | void acpi_os_wait_events_complete(void *context) |
1da177e4 LT |
690 | { |
691 | flush_workqueue(kacpid_wq); | |
692 | } | |
4be44fcd | 693 | |
1da177e4 LT |
694 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
695 | ||
696 | /* | |
697 | * Allocate the memory for a spinlock and initialize it. | |
698 | */ | |
4be44fcd | 699 | acpi_status acpi_os_create_lock(acpi_handle * out_handle) |
1da177e4 LT |
700 | { |
701 | spinlock_t *lock_ptr; | |
702 | ||
4be44fcd | 703 | ACPI_FUNCTION_TRACE("os_create_lock"); |
1da177e4 LT |
704 | |
705 | lock_ptr = acpi_os_allocate(sizeof(spinlock_t)); | |
706 | ||
707 | spin_lock_init(lock_ptr); | |
708 | ||
4be44fcd | 709 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr)); |
1da177e4 LT |
710 | |
711 | *out_handle = lock_ptr; | |
712 | ||
4be44fcd | 713 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
714 | } |
715 | ||
1da177e4 LT |
716 | /* |
717 | * Deallocate the memory for a spinlock. | |
718 | */ | |
4be44fcd | 719 | void acpi_os_delete_lock(acpi_handle handle) |
1da177e4 | 720 | { |
4be44fcd | 721 | ACPI_FUNCTION_TRACE("os_create_lock"); |
1da177e4 | 722 | |
4be44fcd | 723 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle)); |
1da177e4 LT |
724 | |
725 | acpi_os_free(handle); | |
726 | ||
727 | return_VOID; | |
728 | } | |
729 | ||
1da177e4 | 730 | acpi_status |
4be44fcd | 731 | acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) |
1da177e4 | 732 | { |
4be44fcd | 733 | struct semaphore *sem = NULL; |
1da177e4 | 734 | |
4be44fcd | 735 | ACPI_FUNCTION_TRACE("os_create_semaphore"); |
1da177e4 LT |
736 | |
737 | sem = acpi_os_allocate(sizeof(struct semaphore)); | |
738 | if (!sem) | |
4be44fcd | 739 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
740 | memset(sem, 0, sizeof(struct semaphore)); |
741 | ||
742 | sema_init(sem, initial_units); | |
743 | ||
4be44fcd | 744 | *handle = (acpi_handle *) sem; |
1da177e4 | 745 | |
4be44fcd LB |
746 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
747 | *handle, initial_units)); | |
1da177e4 | 748 | |
4be44fcd | 749 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 750 | } |
1da177e4 | 751 | |
4be44fcd | 752 | EXPORT_SYMBOL(acpi_os_create_semaphore); |
1da177e4 LT |
753 | |
754 | /* | |
755 | * TODO: A better way to delete semaphores? Linux doesn't have a | |
756 | * 'delete_semaphore()' function -- may result in an invalid | |
757 | * pointer dereference for non-synchronized consumers. Should | |
758 | * we at least check for blocked threads and signal/cancel them? | |
759 | */ | |
760 | ||
4be44fcd | 761 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
1da177e4 | 762 | { |
4be44fcd | 763 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 764 | |
4be44fcd | 765 | ACPI_FUNCTION_TRACE("os_delete_semaphore"); |
1da177e4 LT |
766 | |
767 | if (!sem) | |
4be44fcd | 768 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 | 769 | |
4be44fcd | 770 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
1da177e4 | 771 | |
4be44fcd LB |
772 | acpi_os_free(sem); |
773 | sem = NULL; | |
1da177e4 | 774 | |
4be44fcd | 775 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 776 | } |
1da177e4 | 777 | |
4be44fcd | 778 | EXPORT_SYMBOL(acpi_os_delete_semaphore); |
1da177e4 LT |
779 | |
780 | /* | |
781 | * TODO: The kernel doesn't have a 'down_timeout' function -- had to | |
782 | * improvise. The process is to sleep for one scheduler quantum | |
783 | * until the semaphore becomes available. Downside is that this | |
784 | * may result in starvation for timeout-based waits when there's | |
785 | * lots of semaphore activity. | |
786 | * | |
787 | * TODO: Support for units > 1? | |
788 | */ | |
4be44fcd | 789 | acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) |
1da177e4 | 790 | { |
4be44fcd LB |
791 | acpi_status status = AE_OK; |
792 | struct semaphore *sem = (struct semaphore *)handle; | |
793 | int ret = 0; | |
1da177e4 | 794 | |
4be44fcd | 795 | ACPI_FUNCTION_TRACE("os_wait_semaphore"); |
1da177e4 LT |
796 | |
797 | if (!sem || (units < 1)) | |
4be44fcd | 798 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
799 | |
800 | if (units > 1) | |
4be44fcd | 801 | return_ACPI_STATUS(AE_SUPPORT); |
1da177e4 | 802 | |
4be44fcd LB |
803 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
804 | handle, units, timeout)); | |
1da177e4 LT |
805 | |
806 | if (in_atomic()) | |
807 | timeout = 0; | |
808 | ||
4be44fcd | 809 | switch (timeout) { |
1da177e4 LT |
810 | /* |
811 | * No Wait: | |
812 | * -------- | |
813 | * A zero timeout value indicates that we shouldn't wait - just | |
814 | * acquire the semaphore if available otherwise return AE_TIME | |
815 | * (a.k.a. 'would block'). | |
816 | */ | |
4be44fcd LB |
817 | case 0: |
818 | if (down_trylock(sem)) | |
1da177e4 LT |
819 | status = AE_TIME; |
820 | break; | |
821 | ||
822 | /* | |
823 | * Wait Indefinitely: | |
824 | * ------------------ | |
825 | */ | |
4be44fcd | 826 | case ACPI_WAIT_FOREVER: |
1da177e4 LT |
827 | down(sem); |
828 | break; | |
829 | ||
830 | /* | |
831 | * Wait w/ Timeout: | |
832 | * ---------------- | |
833 | */ | |
4be44fcd | 834 | default: |
1da177e4 LT |
835 | // TODO: A better timeout algorithm? |
836 | { | |
837 | int i = 0; | |
4be44fcd | 838 | static const int quantum_ms = 1000 / HZ; |
1da177e4 LT |
839 | |
840 | ret = down_trylock(sem); | |
dacd9b80 | 841 | for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) { |
01a527ec | 842 | schedule_timeout_interruptible(1); |
1da177e4 LT |
843 | ret = down_trylock(sem); |
844 | } | |
4be44fcd | 845 | |
1da177e4 LT |
846 | if (ret != 0) |
847 | status = AE_TIME; | |
848 | } | |
849 | break; | |
850 | } | |
851 | ||
852 | if (ACPI_FAILURE(status)) { | |
4be44fcd LB |
853 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
854 | "Failed to acquire semaphore[%p|%d|%d], %s\n", | |
855 | handle, units, timeout, | |
856 | acpi_format_exception(status))); | |
857 | } else { | |
858 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | |
859 | "Acquired semaphore[%p|%d|%d]\n", handle, | |
860 | units, timeout)); | |
1da177e4 LT |
861 | } |
862 | ||
4be44fcd | 863 | return_ACPI_STATUS(status); |
1da177e4 | 864 | } |
1da177e4 | 865 | |
4be44fcd | 866 | EXPORT_SYMBOL(acpi_os_wait_semaphore); |
1da177e4 LT |
867 | |
868 | /* | |
869 | * TODO: Support for units > 1? | |
870 | */ | |
4be44fcd | 871 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
1da177e4 | 872 | { |
4be44fcd | 873 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 874 | |
4be44fcd | 875 | ACPI_FUNCTION_TRACE("os_signal_semaphore"); |
1da177e4 LT |
876 | |
877 | if (!sem || (units < 1)) | |
4be44fcd | 878 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
879 | |
880 | if (units > 1) | |
4be44fcd | 881 | return_ACPI_STATUS(AE_SUPPORT); |
1da177e4 | 882 | |
4be44fcd LB |
883 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
884 | units)); | |
1da177e4 LT |
885 | |
886 | up(sem); | |
887 | ||
4be44fcd | 888 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 889 | } |
4be44fcd | 890 | |
1da177e4 LT |
891 | EXPORT_SYMBOL(acpi_os_signal_semaphore); |
892 | ||
893 | #ifdef ACPI_FUTURE_USAGE | |
4be44fcd | 894 | u32 acpi_os_get_line(char *buffer) |
1da177e4 LT |
895 | { |
896 | ||
897 | #ifdef ENABLE_DEBUGGER | |
898 | if (acpi_in_debugger) { | |
899 | u32 chars; | |
900 | ||
901 | kdb_read(buffer, sizeof(line_buf)); | |
902 | ||
903 | /* remove the CR kdb includes */ | |
904 | chars = strlen(buffer) - 1; | |
905 | buffer[chars] = '\0'; | |
906 | } | |
907 | #endif | |
908 | ||
909 | return 0; | |
910 | } | |
4be44fcd | 911 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 LT |
912 | |
913 | /* Assumes no unreadable holes inbetween */ | |
4be44fcd | 914 | u8 acpi_os_readable(void *ptr, acpi_size len) |
1da177e4 | 915 | { |
4be44fcd | 916 | #if defined(__i386__) || defined(__x86_64__) |
1da177e4 | 917 | char tmp; |
4be44fcd LB |
918 | return !__get_user(tmp, (char __user *)ptr) |
919 | && !__get_user(tmp, (char __user *)ptr + len - 1); | |
1da177e4 LT |
920 | #endif |
921 | return 1; | |
922 | } | |
923 | ||
924 | #ifdef ACPI_FUTURE_USAGE | |
4be44fcd | 925 | u8 acpi_os_writable(void *ptr, acpi_size len) |
1da177e4 LT |
926 | { |
927 | /* could do dummy write (racy) or a kernel page table lookup. | |
928 | The later may be difficult at early boot when kmap doesn't work yet. */ | |
929 | return 1; | |
930 | } | |
931 | #endif | |
932 | ||
4be44fcd | 933 | u32 acpi_os_get_thread_id(void) |
1da177e4 LT |
934 | { |
935 | if (!in_atomic()) | |
936 | return current->pid; | |
937 | ||
938 | return 0; | |
939 | } | |
940 | ||
4be44fcd | 941 | acpi_status acpi_os_signal(u32 function, void *info) |
1da177e4 | 942 | { |
4be44fcd | 943 | switch (function) { |
1da177e4 LT |
944 | case ACPI_SIGNAL_FATAL: |
945 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); | |
946 | break; | |
947 | case ACPI_SIGNAL_BREAKPOINT: | |
948 | /* | |
949 | * AML Breakpoint | |
950 | * ACPI spec. says to treat it as a NOP unless | |
951 | * you are debugging. So if/when we integrate | |
952 | * AML debugger into the kernel debugger its | |
953 | * hook will go here. But until then it is | |
954 | * not useful to print anything on breakpoints. | |
955 | */ | |
956 | break; | |
957 | default: | |
958 | break; | |
959 | } | |
960 | ||
961 | return AE_OK; | |
962 | } | |
4be44fcd | 963 | |
1da177e4 LT |
964 | EXPORT_SYMBOL(acpi_os_signal); |
965 | ||
4be44fcd | 966 | static int __init acpi_os_name_setup(char *str) |
1da177e4 LT |
967 | { |
968 | char *p = acpi_os_name; | |
4be44fcd | 969 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
1da177e4 LT |
970 | |
971 | if (!str || !*str) | |
972 | return 0; | |
973 | ||
974 | for (; count-- && str && *str; str++) { | |
975 | if (isalnum(*str) || *str == ' ' || *str == ':') | |
976 | *p++ = *str; | |
977 | else if (*str == '\'' || *str == '"') | |
978 | continue; | |
979 | else | |
980 | break; | |
981 | } | |
982 | *p = 0; | |
983 | ||
984 | return 1; | |
4be44fcd | 985 | |
1da177e4 LT |
986 | } |
987 | ||
988 | __setup("acpi_os_name=", acpi_os_name_setup); | |
989 | ||
990 | /* | |
991 | * _OSI control | |
992 | * empty string disables _OSI | |
993 | * TBD additional string adds to _OSI | |
994 | */ | |
4be44fcd | 995 | static int __init acpi_osi_setup(char *str) |
1da177e4 LT |
996 | { |
997 | if (str == NULL || *str == '\0') { | |
998 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); | |
999 | acpi_gbl_create_osi_method = FALSE; | |
4be44fcd | 1000 | } else { |
1da177e4 | 1001 | /* TBD */ |
4be44fcd LB |
1002 | printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n", |
1003 | str); | |
1da177e4 LT |
1004 | } |
1005 | ||
1006 | return 1; | |
1007 | } | |
1008 | ||
1009 | __setup("acpi_osi=", acpi_osi_setup); | |
1010 | ||
1011 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ | |
4be44fcd | 1012 | static int __init acpi_serialize_setup(char *str) |
1da177e4 LT |
1013 | { |
1014 | printk(KERN_INFO PREFIX "serialize enabled\n"); | |
1015 | ||
1016 | acpi_gbl_all_methods_serialized = TRUE; | |
1017 | ||
1018 | return 1; | |
1019 | } | |
1020 | ||
1021 | __setup("acpi_serialize", acpi_serialize_setup); | |
1022 | ||
1023 | /* | |
1024 | * Wake and Run-Time GPES are expected to be separate. | |
1025 | * We disable wake-GPEs at run-time to prevent spurious | |
1026 | * interrupts. | |
1027 | * | |
1028 | * However, if a system exists that shares Wake and | |
1029 | * Run-time events on the same GPE this flag is available | |
1030 | * to tell Linux to keep the wake-time GPEs enabled at run-time. | |
1031 | */ | |
4be44fcd | 1032 | static int __init acpi_wake_gpes_always_on_setup(char *str) |
1da177e4 LT |
1033 | { |
1034 | printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); | |
1035 | ||
1036 | acpi_gbl_leave_wake_gpes_disabled = FALSE; | |
1037 | ||
1038 | return 1; | |
1039 | } | |
1040 | ||
1041 | __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); | |
1042 | ||
8713cbef | 1043 | static int __init acpi_hotkey_setup(char *str) |
fb9802fa | 1044 | { |
30e332f3 | 1045 | acpi_specific_hotkey_enabled = FALSE; |
fb9802fa LY |
1046 | return 1; |
1047 | } | |
1048 | ||
30e332f3 | 1049 | __setup("acpi_generic_hotkey", acpi_hotkey_setup); |
fb9802fa | 1050 | |
1da177e4 LT |
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 | ||
b8e4d893 | 1065 | acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle) |
73459f73 | 1066 | { |
b8e4d893 | 1067 | acpi_cpu_flags flags; |
4be44fcd | 1068 | spin_lock_irqsave((spinlock_t *) handle, flags); |
73459f73 RM |
1069 | return flags; |
1070 | } | |
1071 | ||
1072 | /* | |
1073 | * Release a spinlock. See above. | |
1074 | */ | |
1075 | ||
b8e4d893 | 1076 | void acpi_os_release_lock(acpi_handle handle, acpi_cpu_flags flags) |
73459f73 | 1077 | { |
b8e4d893 | 1078 | spin_unlock_irqrestore((spinlock_t *) handle, flags); |
73459f73 RM |
1079 | } |
1080 | ||
73459f73 RM |
1081 | #ifndef ACPI_USE_LOCAL_CACHE |
1082 | ||
1083 | /******************************************************************************* | |
1084 | * | |
1085 | * FUNCTION: acpi_os_create_cache | |
1086 | * | |
1087 | * PARAMETERS: CacheName - Ascii name for the cache | |
1088 | * ObjectSize - Size of each cached object | |
1089 | * MaxDepth - Maximum depth of the cache (in objects) | |
1090 | * ReturnCache - Where the new cache object is returned | |
1091 | * | |
1092 | * RETURN: Status | |
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); |
73459f73 RM |
1102 | return AE_OK; |
1103 | } | |
1104 | ||
1105 | /******************************************************************************* | |
1106 | * | |
1107 | * FUNCTION: acpi_os_purge_cache | |
1108 | * | |
1109 | * PARAMETERS: Cache - Handle to cache object | |
1110 | * | |
1111 | * RETURN: Status | |
1112 | * | |
1113 | * DESCRIPTION: Free all objects within the requested cache. | |
1114 | * | |
1115 | ******************************************************************************/ | |
1116 | ||
4be44fcd | 1117 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
73459f73 | 1118 | { |
4be44fcd LB |
1119 | (void)kmem_cache_shrink(cache); |
1120 | return (AE_OK); | |
73459f73 RM |
1121 | } |
1122 | ||
1123 | /******************************************************************************* | |
1124 | * | |
1125 | * FUNCTION: acpi_os_delete_cache | |
1126 | * | |
1127 | * PARAMETERS: Cache - Handle to cache object | |
1128 | * | |
1129 | * RETURN: Status | |
1130 | * | |
1131 | * DESCRIPTION: Free all objects within the requested cache and delete the | |
1132 | * cache object. | |
1133 | * | |
1134 | ******************************************************************************/ | |
1135 | ||
4be44fcd | 1136 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
73459f73 | 1137 | { |
4be44fcd LB |
1138 | (void)kmem_cache_destroy(cache); |
1139 | return (AE_OK); | |
73459f73 RM |
1140 | } |
1141 | ||
1142 | /******************************************************************************* | |
1143 | * | |
1144 | * FUNCTION: acpi_os_release_object | |
1145 | * | |
1146 | * PARAMETERS: Cache - Handle to cache object | |
1147 | * Object - The object to be released | |
1148 | * | |
1149 | * RETURN: None | |
1150 | * | |
1151 | * DESCRIPTION: Release an object to the specified cache. If cache is full, | |
1152 | * the object is deleted. | |
1153 | * | |
1154 | ******************************************************************************/ | |
1155 | ||
4be44fcd | 1156 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
73459f73 | 1157 | { |
4be44fcd LB |
1158 | kmem_cache_free(cache, object); |
1159 | return (AE_OK); | |
73459f73 RM |
1160 | } |
1161 | ||
1162 | /******************************************************************************* | |
1163 | * | |
1164 | * FUNCTION: acpi_os_acquire_object | |
1165 | * | |
1166 | * PARAMETERS: Cache - Handle to cache object | |
1167 | * ReturnObject - Where the object is returned | |
1168 | * | |
1169 | * RETURN: Status | |
1170 | * | |
1171 | * DESCRIPTION: Get an object from the specified cache. If cache is empty, | |
1172 | * the object is allocated. | |
1173 | * | |
1174 | ******************************************************************************/ | |
1175 | ||
4be44fcd | 1176 | void *acpi_os_acquire_object(acpi_cache_t * cache) |
73459f73 | 1177 | { |
4be44fcd LB |
1178 | void *object = kmem_cache_alloc(cache, GFP_KERNEL); |
1179 | WARN_ON(!object); | |
1180 | return object; | |
73459f73 RM |
1181 | } |
1182 | ||
1183 | #endif |