- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / os.c
blob7bf86171bb2cad7ccb0ed1dc530680b7f8e3e48e
1 /*
2 * os.c - OS-dependent functions
4 * Copyright (C) 2000 Andrew Henroid
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/slab.h>
24 #include <linux/mm.h>
25 #include <linux/pci.h>
26 #include <linux/acpi.h>
27 #include <asm/io.h>
28 #include <asm/delay.h>
29 #include "acpi.h"
30 #include "driver.h"
32 #define _COMPONENT OS_DEPENDENT
33 MODULE_NAME ("os")
35 static int acpi_irq_irq = 0;
36 static OSD_HANDLER acpi_irq_handler = NULL;
37 static void *acpi_irq_context = NULL;
39 #ifdef ENABLE_DEBUGGER
41 #include <linux/kdb.h>
43 /* stuff for debugger support */
44 int acpi_in_debugger = 0;
45 extern NATIVE_CHAR line_buf[80];
47 #endif
50 ACPI_STATUS
51 acpi_os_initialize(void)
53 return AE_OK;
56 ACPI_STATUS
57 acpi_os_terminate(void)
59 if (acpi_irq_handler) {
60 acpi_os_remove_interrupt_handler(acpi_irq_irq,
61 acpi_irq_handler);
63 return AE_OK;
66 s32
67 acpi_os_printf(const NATIVE_CHAR *fmt,...)
69 s32 size;
70 va_list args;
71 va_start(args, fmt);
72 size = acpi_os_vprintf(fmt, args);
73 va_end(args);
74 return size;
77 s32
78 acpi_os_vprintf(const NATIVE_CHAR *fmt, va_list args)
80 static char buffer[512];
81 int size = vsprintf(buffer, fmt, args);
83 #ifdef ENABLE_DEBUGGER
84 if (acpi_in_debugger) {
85 kdb_printf("%s", buffer);
86 } else {
87 printk("%s", buffer);
89 #else
90 printk("%s", buffer);
91 #endif
93 return size;
96 void *
97 acpi_os_allocate(u32 size)
99 return kmalloc(size, GFP_KERNEL);
102 void *
103 acpi_os_callocate(u32 size)
105 void *ptr = acpi_os_allocate(size);
106 if (ptr)
107 memset(ptr, 0, size);
108 return ptr;
111 void
112 acpi_os_free(void *ptr)
114 kfree(ptr);
117 ACPI_STATUS
118 acpi_os_map_memory(ACPI_PHYSICAL_ADDRESS phys, u32 size, void **virt)
120 if (phys > ULONG_MAX) {
121 printk(KERN_ERR "ACPI: Cannot map memory that high\n");
122 return AE_ERROR;
125 if ((unsigned long) phys < virt_to_phys(high_memory)) {
126 *virt = phys_to_virt((unsigned long) phys);
127 return AE_OK;
130 *virt = ioremap((unsigned long) phys, size);
131 if (!*virt)
132 return AE_ERROR;
134 return AE_OK;
137 void
138 acpi_os_unmap_memory(void *virt, u32 size)
140 if (virt >= high_memory)
141 iounmap(virt);
144 static void
145 acpi_irq(int irq, void *dev_id, struct pt_regs *regs)
147 (*acpi_irq_handler)(acpi_irq_context);
150 ACPI_STATUS
151 acpi_os_install_interrupt_handler(u32 irq, OSD_HANDLER handler, void *context)
153 acpi_irq_irq = irq;
154 acpi_irq_handler = handler;
155 acpi_irq_context = context;
156 if (request_irq(irq,
157 acpi_irq,
158 SA_SHIRQ,
159 "acpi",
160 acpi_irq)) {
161 printk(KERN_ERR "ACPI: SCI (IRQ%d) allocation failed\n", irq);
162 return AE_ERROR;
164 return AE_OK;
167 ACPI_STATUS
168 acpi_os_remove_interrupt_handler(u32 irq, OSD_HANDLER handler)
170 if (acpi_irq_handler) {
171 free_irq(irq, acpi_irq);
172 acpi_irq_handler = NULL;
174 return AE_OK;
178 * Running in interpreter thread context, safe to sleep
181 void
182 acpi_os_sleep(u32 sec, u32 ms)
184 current->state = TASK_INTERRUPTIBLE;
185 schedule_timeout(HZ * sec + (ms * HZ) / 1000);
188 void
189 acpi_os_sleep_usec(u32 us)
191 udelay(us);
195 acpi_os_in8(ACPI_IO_ADDRESS port)
197 return inb(port);
201 acpi_os_in16(ACPI_IO_ADDRESS port)
203 return inw(port);
207 acpi_os_in32(ACPI_IO_ADDRESS port)
209 return inl(port);
212 void
213 acpi_os_out8(ACPI_IO_ADDRESS port, u8 val)
215 outb(val, port);
218 void
219 acpi_os_out16(ACPI_IO_ADDRESS port, u16 val)
221 outw(val, port);
224 void
225 acpi_os_out32(ACPI_IO_ADDRESS port, u32 val)
227 outl(val, port);
230 UINT8
231 acpi_os_mem_in8 (ACPI_PHYSICAL_ADDRESS phys_addr)
233 return (*(u8*) (u32) phys_addr);
236 UINT16
237 acpi_os_mem_in16 (ACPI_PHYSICAL_ADDRESS phys_addr)
239 return (*(u16*) (u32) phys_addr);
242 UINT32
243 acpi_os_mem_in32 (ACPI_PHYSICAL_ADDRESS phys_addr)
245 return (*(u32*) (u32) phys_addr);
248 void
249 acpi_os_mem_out8 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT8 value)
251 *(u8*) (u32) phys_addr = value;
254 void
255 acpi_os_mem_out16 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT16 value)
257 *(u16*) (u32) phys_addr = value;
260 void
261 acpi_os_mem_out32 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT32 value)
263 *(u32*) (u32) phys_addr = value;
266 ACPI_STATUS
267 acpi_os_read_pci_cfg_byte(
268 u32 bus,
269 u32 func,
270 u32 addr,
271 u8 * val)
273 int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
274 struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
275 if (!val || !dev || pci_read_config_byte(dev, addr, val))
276 return AE_ERROR;
277 return AE_OK;
280 ACPI_STATUS
281 acpi_os_read_pci_cfg_word(
282 u32 bus,
283 u32 func,
284 u32 addr,
285 u16 * val)
287 int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
288 struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
289 if (!val || !dev || pci_read_config_word(dev, addr, val))
290 return AE_ERROR;
291 return AE_OK;
294 ACPI_STATUS
295 acpi_os_read_pci_cfg_dword(
296 u32 bus,
297 u32 func,
298 u32 addr,
299 u32 * val)
301 int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
302 struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
303 if (!val || !dev || pci_read_config_dword(dev, addr, val))
304 return AE_ERROR;
305 return AE_OK;
308 ACPI_STATUS
309 acpi_os_write_pci_cfg_byte(
310 u32 bus,
311 u32 func,
312 u32 addr,
313 u8 val)
315 int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
316 struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
317 if (!dev || pci_write_config_byte(dev, addr, val))
318 return AE_ERROR;
319 return AE_OK;
322 ACPI_STATUS
323 acpi_os_write_pci_cfg_word(
324 u32 bus,
325 u32 func,
326 u32 addr,
327 u16 val)
329 int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
330 struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
331 if (!dev || pci_write_config_word(dev, addr, val))
332 return AE_ERROR;
333 return AE_OK;
336 ACPI_STATUS
337 acpi_os_write_pci_cfg_dword(
338 u32 bus,
339 u32 func,
340 u32 addr,
341 u32 val)
343 int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
344 struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
345 if (!dev || pci_write_config_dword(dev, addr, val))
346 return AE_ERROR;
347 return AE_OK;
351 * Queue for interpreter thread
354 ACPI_STATUS
355 acpi_os_queue_for_execution(
356 u32 priority,
357 OSD_EXECUTION_CALLBACK callback,
358 void *context)
360 if (acpi_run(callback, context))
361 return AE_ERROR;
362 return AE_OK;
366 * Semaphores are unused, interpreter access is single threaded
369 ACPI_STATUS
370 acpi_os_create_semaphore(u32 max_units, u32 init, ACPI_HANDLE * handle)
372 /* a hack to fake out sems until we implement them */
373 *handle = (ACPI_HANDLE) handle;
374 return AE_OK;
377 ACPI_STATUS
378 acpi_os_delete_semaphore(ACPI_HANDLE handle)
380 return AE_OK;
383 ACPI_STATUS
384 acpi_os_wait_semaphore(ACPI_HANDLE handle, u32 units, u32 timeout)
386 return AE_OK;
389 ACPI_STATUS
390 acpi_os_signal_semaphore(ACPI_HANDLE handle, u32 units)
392 return AE_OK;
395 ACPI_STATUS
396 acpi_os_breakpoint(NATIVE_CHAR *msg)
398 acpi_os_printf("breakpoint: %s", msg);
399 return AE_OK;
402 void
403 acpi_os_dbg_trap(char *msg)
405 acpi_os_printf("trap: %s", msg);
408 void
409 acpi_os_dbg_assert(void *failure, void *file, u32 line, NATIVE_CHAR *msg)
411 acpi_os_printf("assert: %s", msg);
415 acpi_os_get_line(NATIVE_CHAR *buffer)
418 #ifdef ENABLE_DEBUGGER
419 if (acpi_in_debugger) {
420 u32 chars;
422 kdb_read(buffer, sizeof(line_buf));
424 /* remove the CR kdb includes */
425 chars = strlen(buffer) - 1;
426 buffer[chars] = '\0';
428 #endif
430 return 0;
434 * We just have to assume we're dealing with valid memory
437 BOOLEAN
438 acpi_os_readable(void *ptr, u32 len)
440 return 1;
443 BOOLEAN
444 acpi_os_writable(void *ptr, u32 len)
446 return 1;