00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <ddi.h>
00036 #include <libarch/ddi.h>
00037 #include <libc.h>
00038 #include <task.h>
00039 #include <as.h>
00040 #include <align.h>
00041 #include <libarch/config.h>
00042 #include <kernel/ddi/ddi_arg.h>
00043
00049 int device_assign_devno(void)
00050 {
00051 return __SYSCALL0(SYS_DEVICE_ASSIGN_DEVNO);
00052 }
00053
00068 int physmem_map(void *pf, void *vp, unsigned long pages, int flags)
00069 {
00070 return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, pages,
00071 flags);
00072 }
00073
00087 int iospace_enable(task_id_t id, void *ioaddr, unsigned long size)
00088 {
00089 ddi_ioarg_t arg;
00090
00091 arg.task_id = id;
00092 arg.ioaddr = ioaddr;
00093 arg.size = size;
00094
00095 return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
00096 }
00097
00107 int pio_enable(void *pio_addr, size_t size, void **use_addr)
00108 {
00109 void *phys;
00110 void *virt;
00111 size_t offset;
00112 unsigned int pages;
00113
00114 #ifdef IO_SPACE_BOUNDARY
00115 if (pio_addr < IO_SPACE_BOUNDARY) {
00116 *use_addr = pio_addr;
00117 return iospace_enable(task_get_id(), pio_addr, size);
00118 }
00119 #endif
00120
00121 phys = (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
00122 offset = pio_addr - phys;
00123 pages = ALIGN_UP(offset + size, PAGE_SIZE) >> PAGE_WIDTH;
00124 virt = as_get_mappable_page(pages << PAGE_WIDTH);
00125 *use_addr = virt + offset;
00126 return physmem_map(phys, virt, pages, AS_AREA_READ | AS_AREA_WRITE);
00127 }
00128
00139 int register_irq(int inr, int devno, int method, irq_code_t *ucode)
00140 {
00141 return __SYSCALL4(SYS_REGISTER_IRQ, inr, devno, method,
00142 (sysarg_t) ucode);
00143 }
00144
00153 int unregister_irq(int inr, int devno)
00154 {
00155 return __SYSCALL2(SYS_UNREGISTER_IRQ, inr, devno);
00156 }
00157