Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ddi/ddi.c

    r5df1963 r2c0b348  
    314314
    315315NO_TRACE static int dmamem_map(uintptr_t virt, size_t size, unsigned int map_flags,
    316     unsigned int flags, uintptr_t *phys)
     316    unsigned int flags, void **phys)
    317317{
    318318        ASSERT(TASK);
     
    322322}
    323323
    324 NO_TRACE static int dmamem_map_anonymous(size_t size, uintptr_t constraint,
    325     unsigned int map_flags, unsigned int flags, uintptr_t *phys,
    326     uintptr_t *virt, uintptr_t bound)
     324NO_TRACE static int dmamem_map_anonymous(size_t size, unsigned int map_flags,
     325    unsigned int flags, void **phys, uintptr_t *virt, uintptr_t bound)
    327326{
    328327        ASSERT(TASK);
    329328       
    330         size_t frames = SIZE2FRAMES(size);
    331         *phys = frame_alloc_noreserve(frames, 0, constraint);
    332         if (*phys == 0)
     329        size_t pages = SIZE2FRAMES(size);
     330        uint8_t order;
     331       
     332        /* We need the 2^order >= pages */
     333        if (pages == 1)
     334                order = 0;
     335        else
     336                order = fnzb(pages - 1) + 1;
     337       
     338        *phys = frame_alloc_noreserve(order, FRAME_DMA);
     339        if (*phys == NULL)
    333340                return ENOMEM;
    334341       
    335342        mem_backend_data_t backend_data;
    336         backend_data.base = *phys;
    337         backend_data.frames = frames;
     343        backend_data.base = (uintptr_t) *phys;
     344        backend_data.frames = pages;
    338345       
    339346        if (!as_area_create(TASK->as, map_flags, size,
    340347            AS_AREA_ATTR_NONE, &phys_backend, &backend_data, virt, bound)) {
    341                 frame_free_noreserve(*phys, frames);
     348                frame_free_noreserve((uintptr_t) *phys);
    342349                return ENOMEM;
    343350        }
     
    354361NO_TRACE static int dmamem_unmap_anonymous(uintptr_t virt)
    355362{
    356         // TODO: implement unlocking & unmap
    357         return EOK;
     363        // TODO: This is an ugly hack
     364        as_t *as = TASK->as;
     365
     366        mutex_lock(&as->lock);
     367        as_area_t *area = find_locked_area(as, virt);
     368        if (!area) {
     369                mutex_unlock(&as->lock);
     370                return ENOENT;
     371        }
     372        frame_free_noreserve(area->backend_data.base);
     373        area->backend_data.base = 0;
     374        area->backend_data.frames = 0;
     375        mutex_unlock(&area->lock);
     376        mutex_unlock(&as->lock);
     377
     378        return as_area_destroy(as, virt);
    358379}
    359380
     
    366387                 */
    367388               
    368                 uintptr_t phys;
     389                void *phys;
    369390                int rc = dmamem_map((uintptr_t) virt_ptr, size, map_flags,
    370391                    flags, &phys);
     
    383404                 */
    384405               
    385                 uintptr_t constraint;
    386                 int rc = copy_from_uspace(&constraint, phys_ptr,
    387                     sizeof(constraint));
    388                 if (rc != EOK)
    389                         return rc;
    390                
    391                 uintptr_t phys;
     406                void *phys;
    392407                uintptr_t virt = (uintptr_t) -1;
    393                 rc = dmamem_map_anonymous(size, constraint, map_flags, flags,
     408                int rc = dmamem_map_anonymous(size, map_flags, flags,
    394409                    &phys, &virt, bound);
    395410                if (rc != EOK)
Note: See TracChangeset for help on using the changeset viewer.