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>
25 #include <linux/pci.h>
26 #include <linux/acpi.h>
28 #include <asm/delay.h>
32 #define _COMPONENT OS_DEPENDENT
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];
51 acpi_os_initialize(void)
57 acpi_os_terminate(void)
59 if (acpi_irq_handler
) {
60 acpi_os_remove_interrupt_handler(acpi_irq_irq
,
67 acpi_os_printf(const NATIVE_CHAR
*fmt
,...)
72 size
= acpi_os_vprintf(fmt
, args
);
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
);
97 acpi_os_allocate(u32 size
)
99 return kmalloc(size
, GFP_KERNEL
);
103 acpi_os_callocate(u32 size
)
105 void *ptr
= acpi_os_allocate(size
);
107 memset(ptr
, 0, size
);
112 acpi_os_free(void *ptr
)
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");
125 if ((unsigned long) phys
< virt_to_phys(high_memory
)) {
126 *virt
= phys_to_virt((unsigned long) phys
);
130 *virt
= ioremap((unsigned long) phys
, size
);
138 acpi_os_unmap_memory(void *virt
, u32 size
)
140 if (virt
>= high_memory
)
145 acpi_irq(int irq
, void *dev_id
, struct pt_regs
*regs
)
147 (*acpi_irq_handler
)(acpi_irq_context
);
151 acpi_os_install_interrupt_handler(u32 irq
, OSD_HANDLER handler
, void *context
)
154 acpi_irq_handler
= handler
;
155 acpi_irq_context
= context
;
161 printk(KERN_ERR
"ACPI: SCI (IRQ%d) allocation failed\n", irq
);
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
;
178 * Running in interpreter thread context, safe to sleep
182 acpi_os_sleep(u32 sec
, u32 ms
)
184 current
->state
= TASK_INTERRUPTIBLE
;
185 schedule_timeout(HZ
* sec
+ (ms
* HZ
) / 1000);
189 acpi_os_sleep_usec(u32 us
)
195 acpi_os_in8(ACPI_IO_ADDRESS port
)
201 acpi_os_in16(ACPI_IO_ADDRESS port
)
207 acpi_os_in32(ACPI_IO_ADDRESS port
)
213 acpi_os_out8(ACPI_IO_ADDRESS port
, u8 val
)
219 acpi_os_out16(ACPI_IO_ADDRESS port
, u16 val
)
225 acpi_os_out32(ACPI_IO_ADDRESS port
, u32 val
)
231 acpi_os_mem_in8 (ACPI_PHYSICAL_ADDRESS phys_addr
)
233 return (*(u8
*) (u32
) phys_addr
);
237 acpi_os_mem_in16 (ACPI_PHYSICAL_ADDRESS phys_addr
)
239 return (*(u16
*) (u32
) phys_addr
);
243 acpi_os_mem_in32 (ACPI_PHYSICAL_ADDRESS phys_addr
)
245 return (*(u32
*) (u32
) phys_addr
);
249 acpi_os_mem_out8 (ACPI_PHYSICAL_ADDRESS phys_addr
, UINT8 value
)
251 *(u8
*) (u32
) phys_addr
= value
;
255 acpi_os_mem_out16 (ACPI_PHYSICAL_ADDRESS phys_addr
, UINT16 value
)
257 *(u16
*) (u32
) phys_addr
= value
;
261 acpi_os_mem_out32 (ACPI_PHYSICAL_ADDRESS phys_addr
, UINT32 value
)
263 *(u32
*) (u32
) phys_addr
= value
;
267 acpi_os_read_pci_cfg_byte(
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
))
281 acpi_os_read_pci_cfg_word(
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
))
295 acpi_os_read_pci_cfg_dword(
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
))
309 acpi_os_write_pci_cfg_byte(
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
))
323 acpi_os_write_pci_cfg_word(
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
))
337 acpi_os_write_pci_cfg_dword(
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
))
351 * Queue for interpreter thread
355 acpi_os_queue_for_execution(
357 OSD_EXECUTION_CALLBACK callback
,
360 if (acpi_run(callback
, context
))
366 * Semaphores are unused, interpreter access is single threaded
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
;
378 acpi_os_delete_semaphore(ACPI_HANDLE handle
)
384 acpi_os_wait_semaphore(ACPI_HANDLE handle
, u32 units
, u32 timeout
)
390 acpi_os_signal_semaphore(ACPI_HANDLE handle
, u32 units
)
396 acpi_os_breakpoint(NATIVE_CHAR
*msg
)
398 acpi_os_printf("breakpoint: %s", msg
);
403 acpi_os_dbg_trap(char *msg
)
405 acpi_os_printf("trap: %s", msg
);
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
) {
422 kdb_read(buffer
, sizeof(line_buf
));
424 /* remove the CR kdb includes */
425 chars
= strlen(buffer
) - 1;
426 buffer
[chars
] = '\0';
434 * We just have to assume we're dealing with valid memory
438 acpi_os_readable(void *ptr
, u32 len
)
444 acpi_os_writable(void *ptr
, u32 len
)