ddi.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 

Generated on Thu Jun 2 07:45:45 2011 for HelenOS/USB by  doxygen 1.4.7