Changeset 7aaed09 in mainline for uspace/lib/c/generic/ddi.c


Ignore:
Timestamp:
2011-12-18T14:02:30Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c868e2d
Parents:
3b71e84d (diff), 1761268 (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:

Merge mainline changes.

File:
1 edited

Legend:

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

    r3b71e84d r7aaed09  
    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>
     
    5356}
    5457
    55 /** Map piece of physical memory to task.
     58/** Map a piece of physical memory to task.
    5659 *
    5760 * Caller of this function must have the CAP_MEM_MANAGER capability.
    5861 *
    59  * @param pf            Physical address of the starting frame.
    60  * @param vp            Virtual address of the starting page.
    61  * @param pages         Number of pages to map.
    62  * @param flags         Flags for the new address space area.
     62 * @param phys  Physical address of the starting frame.
     63 * @param virt  Virtual address of the starting page.
     64 * @param pages Number of pages to map.
     65 * @param flags Flags for the new address space area.
    6366 *
    64  * @return              0 on success, EPERM if the caller lacks the
    65  *                      CAP_MEM_MANAGER capability, ENOENT if there is no task
    66  *                      with specified ID and ENOMEM if there was some problem
    67  *                      in creating address space area.
     67 * @return EOK on success
     68 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability
     69 * @return ENOENT if there is no task with specified ID
     70 * @return ENOMEM if there was some problem in creating
     71 *         the address space area.
     72 *
    6873 */
    69 int physmem_map(void *pf, void *vp, unsigned long pages, int flags)
     74int physmem_map(void *phys, void *virt, size_t pages, unsigned int flags)
    7075{
    71         return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, pages,
    72             flags);
     76        return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) phys,
     77            (sysarg_t) virt, pages, flags);
     78}
     79
     80int dmamem_map(void *virt, size_t size, unsigned int map_flags,
     81    unsigned int flags, void **phys)
     82{
     83        return (int) __SYSCALL5(SYS_DMAMEM_MAP, (sysarg_t) virt,
     84            (sysarg_t) size, (sysarg_t) map_flags, (sysarg_t) flags,
     85            (sysarg_t) phys);
     86}
     87
     88int dmamem_map_anonymous(size_t size, unsigned int map_flags,
     89    unsigned int flags, void **phys, void **virt)
     90{
     91        *virt = as_get_mappable_page(size);
     92        if (*virt == NULL)
     93                return ENOMEM;
     94       
     95        return dmamem_map(*virt, size, map_flags,
     96            flags | DMAMEM_FLAGS_ANONYMOUS, phys);
     97}
     98
     99int dmamem_unmap(void *virt, size_t size, unsigned int flags)
     100{
     101        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size,
     102            (sysarg_t) flags);
     103}
     104
     105int dmamem_unmap_anonymous(void *virt)
     106{
     107        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0,
     108            DMAMEM_FLAGS_ANONYMOUS);
    73109}
    74110
     
    77113 * Caller of this function must have the IO_MEM_MANAGER capability.
    78114 *
    79  * @param id            Task ID.
    80  * @param ioaddr        Starting address of the I/O range.
    81  * @param size          Size of the range.
     115 * @param id     Task ID.
     116 * @param ioaddr Starting address of the I/O range.
     117 * @param size   Size of the range.
    82118 *
    83  * @return              0 on success, EPERM if the caller lacks the
    84  *                      CAP_IO_MANAGER capability, ENOENT if there is no task
    85  *                      with specified ID and ENOMEM if there was some problem
    86  *                      in allocating memory.
     119 * @return EOK on success
     120 * @return EPERM if the caller lacks the CAP_IO_MANAGER capability
     121 * @return ENOENT if there is no task with specified ID
     122 * @return ENOMEM if there was some problem in allocating memory.
     123 *
    87124 */
    88125int iospace_enable(task_id_t id, void *ioaddr, unsigned long size)
    89126{
    90127        ddi_ioarg_t arg;
    91 
     128       
    92129        arg.task_id = id;
    93130        arg.ioaddr = ioaddr;
    94131        arg.size = size;
    95 
     132       
    96133        return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
    97134}
     
    99136/** Enable PIO for specified I/O range.
    100137 *
    101  * @param pio_addr      I/O start address.
    102  * @param size          Size of the I/O region.
    103  * @param use_addr      Address where the final address for application's PIO
    104  *                      will be stored.
     138 * @param pio_addr I/O start address.
     139 * @param size     Size of the I/O region.
     140 * @param use_addr Address where the final address for
     141 *                 application's PIO will be stored.
    105142 *
    106  * @return              Zero on success or negative error code.
     143 * @return Zero on success or negative error code.
     144 *
    107145 */
    108146int pio_enable(void *pio_addr, size_t size, void **use_addr)
     
    112150        size_t offset;
    113151        unsigned int pages;
    114 
     152       
    115153#ifdef IO_SPACE_BOUNDARY
    116154        if (pio_addr < IO_SPACE_BOUNDARY) {
     
    119157        }
    120158#endif
    121 
     159       
    122160        phys = (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
    123161        offset = pio_addr - phys;
Note: See TracChangeset for help on using the changeset viewer.