Ignore:
File:
1 edited

Legend:

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

    r5a5269d r597fa24  
    5454#include <align.h>
    5555#include <errno.h>
    56 #include <mem.h>
     56#include <memw.h>
    5757#include <trace.h>
    5858#include <bitops.h>
     
    6060
    6161/** This lock protects the @c pareas ordered dictionary. */
    62 static mutex_t pareas_lock;
     62static MUTEX_INITIALIZE(pareas_lock, MUTEX_PASSIVE);
    6363
    6464/** Ordered dictionary of enabled physical memory areas by base address. */
     
    7474{
    7575        odict_initialize(&pareas, pareas_getkey, pareas_cmp);
    76         mutex_initialize(&pareas_lock, MUTEX_PASSIVE);
    7776}
    7877
     
    105104
    106105        mutex_unlock(&pareas_lock);
     106}
     107
     108/** Norify physical area has been unmapped.
     109 *
     110 * @param parea Physical area
     111 */
     112void ddi_parea_unmap_notify(parea_t *parea)
     113{
     114        parea->mapped = false;
     115        if (parea->mapped_changed != NULL)
     116                parea->mapped_changed(parea->arg);
    107117}
    108118
     
    204214
    205215map:
     216        backend_data.parea = parea;
     217
    206218        if (!as_area_create(TASK->as, flags, FRAMES2SIZE(pages),
    207219            AS_AREA_ATTR_NONE, &phys_backend, &backend_data, virt, bound)) {
     
    323335                return EPERM;
    324336
    325         irq_spinlock_lock(&tasks_lock, true);
    326 
    327337        task_t *task = task_find_by_id(id);
    328338
    329         if ((!task) || (!container_check(CONTAINER, task->container))) {
    330                 /*
    331                  * There is no task with the specified ID
    332                  * or the task belongs to a different security
    333                  * context.
    334                  */
    335                 irq_spinlock_unlock(&tasks_lock, true);
     339        if (!task)
    336340                return ENOENT;
    337         }
    338 
    339         /* Lock the task and release the lock protecting tasks dictionary. */
    340         irq_spinlock_exchange(&tasks_lock, &task->lock);
    341         errno_t rc = ddi_iospace_enable_arch(task, ioaddr, size);
     341
     342        errno_t rc = ENOENT;
     343
     344        irq_spinlock_lock(&task->lock, true);
     345
     346        /* Check that the task belongs to the correct security context. */
     347        if (container_check(CONTAINER, task->container))
     348                rc = ddi_iospace_enable_arch(task, ioaddr, size);
     349
    342350        irq_spinlock_unlock(&task->lock, true);
    343 
     351        task_release(task);
    344352        return rc;
    345353}
     
    364372                return EPERM;
    365373
    366         irq_spinlock_lock(&tasks_lock, true);
    367 
    368374        task_t *task = task_find_by_id(id);
    369375
    370         if ((!task) || (!container_check(CONTAINER, task->container))) {
    371                 /*
    372                  * There is no task with the specified ID
    373                  * or the task belongs to a different security
    374                  * context.
    375                  */
    376                 irq_spinlock_unlock(&tasks_lock, true);
     376        if (!task)
    377377                return ENOENT;
    378         }
    379 
    380         /* Lock the task and release the lock protecting tasks dictionary. */
    381         irq_spinlock_exchange(&tasks_lock, &task->lock);
    382         errno_t rc = ddi_iospace_disable_arch(task, ioaddr, size);
     378
     379        errno_t rc = ENOENT;
     380
     381        irq_spinlock_lock(&task->lock, true);
     382
     383        /* Check that the task belongs to the correct security context. */
     384        if (container_check(CONTAINER, task->container))
     385                rc = ddi_iospace_disable_arch(task, ioaddr, size);
     386
    383387        irq_spinlock_unlock(&task->lock, true);
    384 
     388        task_release(task);
    385389        return rc;
    386390}
     
    443447        backend_data.frames = frames;
    444448        backend_data.anonymous = true;
     449        backend_data.parea = NULL;
    445450
    446451        if (!as_area_create(TASK->as, map_flags, size,
Note: See TracChangeset for help on using the changeset viewer.