Changeset 153cc76a in mainline for uspace/lib/c/generic/ddi.c


Ignore:
Timestamp:
2011-12-23T16:42:22Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7e1b130
Parents:
4291215 (diff), 2f0dd2a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/ddi.c

    r4291215 r153cc76a  
    3333 */
    3434
     35#include <assert.h>
     36#include <unistd.h>
     37#include <errno.h>
    3538#include <sys/types.h>
    3639#include <abi/ddi/arg.h>
     
    4245#include <align.h>
    4346#include <libarch/config.h>
     47#include "private/libc.h"
    4448
    4549/** Return unique device number.
     
    5761 * Caller of this function must have the CAP_MEM_MANAGER capability.
    5862 *
    59  * @param pf    Physical address of the starting frame.
    60  * @param vp    Virtual address of the starting page.
     63 * @param phys  Physical address of the starting frame.
    6164 * @param pages Number of pages to map.
    6265 * @param flags Flags for the new address space area.
     66 * @param virt  Virtual address of the starting page.
    6367 *
    6468 * @return EOK on success
     
    6973 *
    7074 */
    71 int physmem_map(void *pf, void *vp, size_t pages, unsigned int flags)
     75int physmem_map(void *phys, size_t pages, unsigned int flags, void **virt)
    7276{
    73         return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp,
    74             pages, flags);
     77        return __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys,
     78            pages, flags, (sysarg_t) virt, (sysarg_t) __entry);
    7579}
    7680
    77 int dmamem_map(dmamem_t *dmamem, size_t pages, unsigned int map_flags,
    78     unsigned int dma_flags)
     81int dmamem_map(void *virt, size_t size, unsigned int map_flags,
     82    unsigned int flags, void **phys)
    7983{
    80         // FIXME TODO
    81         return -1;
     84        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
     85            (sysarg_t) map_flags, (sysarg_t) flags & ~DMAMEM_FLAGS_ANONYMOUS,
     86            (sysarg_t) phys, (sysarg_t) virt, 0);
    8287}
    8388
    84 int dmamem_unmap(dmamem_t *dmamem)
     89int dmamem_map_anonymous(size_t size, unsigned int map_flags,
     90    unsigned int flags, void **phys, void **virt)
    8591{
    86         // FIXME TODO
    87         return -1;
     92        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
     93            (sysarg_t) map_flags, (sysarg_t) flags | DMAMEM_FLAGS_ANONYMOUS,
     94            (sysarg_t) phys, (sysarg_t) virt, (sysarg_t) __entry);
    8895}
    8996
    90 int dmamem_lock(void *virt, void **phys, size_t pages)
     97int dmamem_unmap(void *virt, size_t size)
    9198{
    92         // FIXME TODO
    93         return -1;
     99        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 0);
    94100}
    95101
    96 int dmamem_unlock(void *virt, size_t pages)
     102int dmamem_unmap_anonymous(void *virt)
    97103{
    98         // FIXME TODO
    99         return -1;
     104        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0,
     105            DMAMEM_FLAGS_ANONYMOUS);
    100106}
    101107
     
    129135 * @param pio_addr I/O start address.
    130136 * @param size     Size of the I/O region.
    131  * @param use_addr Address where the final address for
    132  *                 application's PIO will be stored.
     137 * @param virt     Virtual address for application's
     138 *                 PIO operations.
    133139 *
    134  * @return Zero on success or negative error code.
     140 * @return EOK on success.
     141 * @return Negative error code on failure.
    135142 *
    136143 */
    137 int pio_enable(void *pio_addr, size_t size, void **use_addr)
     144int pio_enable(void *pio_addr, size_t size, void **virt)
    138145{
    139         void *phys;
    140         void *virt;
    141         size_t offset;
    142         unsigned int pages;
    143        
    144146#ifdef IO_SPACE_BOUNDARY
    145147        if (pio_addr < IO_SPACE_BOUNDARY) {
    146                 *use_addr = pio_addr;
     148                *virt = pio_addr;
    147149                return iospace_enable(task_get_id(), pio_addr, size);
    148150        }
    149151#endif
    150152       
    151         phys = (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
    152         offset = pio_addr - phys;
    153         pages = ALIGN_UP(offset + size, PAGE_SIZE) >> PAGE_WIDTH;
    154         virt = as_get_mappable_page(pages << PAGE_WIDTH);
    155         *use_addr = virt + offset;
    156         return physmem_map(phys, virt, pages, AS_AREA_READ | AS_AREA_WRITE);
     153        void *phys_frame =
     154            (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
     155        size_t offset = pio_addr - phys_frame;
     156        size_t pages = SIZE2PAGES(offset + size);
     157       
     158        void *virt_page;
     159        int rc = physmem_map(phys_frame, pages,
     160            AS_AREA_READ | AS_AREA_WRITE, &virt_page);
     161        if (rc != EOK)
     162                return rc;
     163       
     164        *virt = virt_page + offset;
     165        return EOK;
    157166}
    158167
     
    167176 *
    168177 */
    169 int register_irq(int inr, int devno, int method, irq_code_t *ucode)
     178int irq_register(int inr, int devno, int method, irq_code_t *ucode)
    170179{
    171         return __SYSCALL4(SYS_REGISTER_IRQ, inr, devno, method,
     180        return __SYSCALL4(SYS_IRQ_REGISTER, inr, devno, method,
    172181            (sysarg_t) ucode);
    173182}
     
    181190 *
    182191 */
    183 int unregister_irq(int inr, int devno)
     192int irq_unregister(int inr, int devno)
    184193{
    185         return __SYSCALL2(SYS_UNREGISTER_IRQ, inr, devno);
     194        return __SYSCALL2(SYS_IRQ_UNREGISTER, inr, devno);
    186195}
    187196
Note: See TracChangeset for help on using the changeset viewer.