Changeset 0c2d9bb in mainline for uspace/lib/c/generic/ddi.c


Ignore:
Timestamp:
2013-12-25T22:54:29Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b51cf2c
Parents:
f7a33de (diff), ac36aed (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

    rf7a33de r0c2d9bb  
    4242#include <ddi.h>
    4343#include <libarch/ddi.h>
     44#include <device/hw_res.h>
     45#include <device/hw_res_parsed.h>
     46#include <device/pio_window.h>
    4447#include <libc.h>
    4548#include <task.h>
     
    7679 *
    7780 */
    78 int physmem_map(void *phys, size_t pages, unsigned int flags, void **virt)
     81int physmem_map(uintptr_t phys, size_t pages, unsigned int flags, void **virt)
    7982{
    8083        return __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys,
     
    8386
    8487int dmamem_map(void *virt, size_t size, unsigned int map_flags,
    85     unsigned int flags, void **phys)
     88    unsigned int flags, uintptr_t *phys)
    8689{
    8790        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
     
    9093}
    9194
    92 int dmamem_map_anonymous(size_t size, unsigned int map_flags,
    93     unsigned int flags, void **phys, void **virt)
    94 {
     95int dmamem_map_anonymous(size_t size, uintptr_t constraint,
     96    unsigned int map_flags, unsigned int flags, uintptr_t *phys, void **virt)
     97{
     98        *phys = constraint;
     99       
    95100        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
    96101            (sysarg_t) map_flags, (sysarg_t) flags | DMAMEM_FLAGS_ANONYMOUS,
     
    132137       
    133138        return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
     139}
     140
     141/** Enable PIO for specified address range.
     142 *
     143 * @param range I/O range to be enable.
     144 * @param virt  Virtual address for application's PIO operations.
     145 */
     146int pio_enable_range(addr_range_t *range, void **virt)
     147{
     148        return pio_enable(RNGABSPTR(*range), RNGSZ(*range), virt);
     149}
     150
     151/** Enable PIO for specified HW resource wrt. to the PIO window.
     152 *
     153 * @param win      PIO window. May be NULL if the resources are known to be
     154 *                 absolute.
     155 * @param res      Resources specifying the I/O range wrt. to the PIO window.
     156 * @param virt     Virtual address for application's PIO operations.
     157 *
     158 * @return EOK on success.
     159 * @return Negative error code on failure.
     160 *
     161 */
     162int pio_enable_resource(pio_window_t *win, hw_resource_t *res, void **virt)
     163{
     164        uintptr_t addr;
     165        size_t size;
     166
     167        switch (res->type) {
     168        case IO_RANGE:
     169                addr = res->res.io_range.address;
     170                if (res->res.io_range.relative) {
     171                        if (!win)
     172                                return EINVAL;
     173                        addr += win->io.base;
     174                }
     175                size = res->res.io_range.size;
     176                break;
     177        case MEM_RANGE:
     178                addr = res->res.mem_range.address;
     179                if (res->res.mem_range.relative) {
     180                        if (!win)
     181                                return EINVAL;
     182                        addr += win->mem.base;
     183                }
     184                size = res->res.mem_range.size;
     185                break;
     186        default:
     187                return EINVAL;
     188        }
     189
     190        return pio_enable((void *) addr, size, virt);   
    134191}
    135192
     
    158215        if (!virt)
    159216                return EINVAL;
    160 
    161         void *phys_frame =
    162             (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
    163         size_t offset = pio_addr - phys_frame;
     217       
     218        uintptr_t phys_frame =
     219            ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
     220        size_t offset = (uintptr_t) pio_addr - phys_frame;
    164221        size_t pages = SIZE2PAGES(offset + size);
    165222       
Note: See TracChangeset for help on using the changeset viewer.