Ignore:
File:
1 edited

Legend:

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

    ra35b458 r5a6cc679  
    7979{
    8080        mutex_lock(&parea_lock);
    81 
     81       
    8282        /*
    8383         * We don't check for overlaps here as the kernel is pretty sane.
    8484         */
    8585        btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);
    86 
     86       
    8787        mutex_unlock(&parea_lock);
    8888}
     
    108108{
    109109        assert(TASK);
    110 
     110       
    111111        if ((phys % FRAME_SIZE) != 0)
    112112                return EBADMEM;
    113 
     113       
    114114        /*
    115115         * Unprivileged tasks are only allowed to map pareas
     
    118118        bool priv =
    119119            ((perm_get(TASK) & PERM_MEM_MANAGER) == PERM_MEM_MANAGER);
    120 
     120       
    121121        mem_backend_data_t backend_data;
    122122        backend_data.base = phys;
    123123        backend_data.frames = pages;
    124124        backend_data.anonymous = false;
    125 
     125       
    126126        /*
    127127         * Check if the memory region is explicitly enabled
    128128         * for mapping by any parea structure.
    129129         */
    130 
     130       
    131131        mutex_lock(&parea_lock);
    132132        btree_node_t *nodep;
    133133        parea_t *parea = (parea_t *) btree_search(&parea_btree,
    134134            (btree_key_t) phys, &nodep);
    135 
     135       
    136136        if ((parea != NULL) && (parea->frames >= pages)) {
    137137                if ((!priv) && (!parea->unpriv)) {
     
    139139                        return EPERM;
    140140                }
    141 
     141               
    142142                goto map;
    143143        }
    144 
     144       
    145145        parea = NULL;
    146146        mutex_unlock(&parea_lock);
    147 
     147       
    148148        /*
    149149         * Check if the memory region is part of physical
    150150         * memory generally enabled for mapping.
    151151         */
    152 
     152       
    153153        irq_spinlock_lock(&zones.lock, true);
    154154        size_t znum = find_zone(ADDR2PFN(phys), pages, 0);
    155 
     155       
    156156        if (znum == (size_t) -1) {
    157157                /*
     
    161161                 */
    162162                irq_spinlock_unlock(&zones.lock, true);
    163 
     163               
    164164                if (!priv)
    165165                        return EPERM;
    166 
     166               
    167167                goto map;
    168168        }
    169 
     169       
    170170        if (zones.info[znum].flags & (ZONE_FIRMWARE | ZONE_RESERVED)) {
    171171                /*
     
    174174                 */
    175175                irq_spinlock_unlock(&zones.lock, true);
    176 
     176               
    177177                if (!priv)
    178178                        return EPERM;
    179 
     179               
    180180                goto map;
    181181        }
    182 
     182       
    183183        irq_spinlock_unlock(&zones.lock, true);
    184184        return ENOENT;
    185 
     185       
    186186map:
    187187        if (!as_area_create(TASK->as, flags, FRAMES2SIZE(pages),
     
    191191                 * We report it using ENOMEM.
    192192                 */
    193 
     193               
    194194                if (parea != NULL)
    195195                        mutex_unlock(&parea_lock);
    196 
     196               
    197197                return ENOMEM;
    198198        }
    199 
     199       
    200200        /*
    201201         * Mapping is created on-demand during page fault.
    202202         */
    203 
     203       
    204204        if (parea != NULL) {
    205205                parea->mapped = true;
    206206                mutex_unlock(&parea_lock);
    207207        }
    208 
     208       
    209209        return EOK;
    210210}
     
    235235        if (rc != EOK)
    236236                return rc;
    237 
     237       
    238238        rc = physmem_map(ALIGN_DOWN(phys, FRAME_SIZE), pages, flags, &virt,
    239239            bound);
    240240        if (rc != EOK)
    241241                return rc;
    242 
     242       
    243243        rc = copy_to_uspace(virt_ptr, &virt, sizeof(virt));
    244244        if (rc != EOK) {
     
    246246                return rc;
    247247        }
    248 
     248       
    249249        return EOK;
    250250}
     
    273273        if (!(perms & PERM_IO_MANAGER))
    274274                return EPERM;
    275 
     275       
    276276        irq_spinlock_lock(&tasks_lock, true);
    277 
     277       
    278278        task_t *task = task_find_by_id(id);
    279 
     279       
    280280        if ((!task) || (!container_check(CONTAINER, task->container))) {
    281281                /*
     
    287287                return ENOENT;
    288288        }
    289 
     289       
    290290        /* Lock the task and release the lock protecting tasks_btree. */
    291291        irq_spinlock_exchange(&tasks_lock, &task->lock);
     
    314314        if (!(perms & PERM_IO_MANAGER))
    315315                return EPERM;
    316 
     316       
    317317        irq_spinlock_lock(&tasks_lock, true);
    318 
     318       
    319319        task_t *task = task_find_by_id(id);
    320 
     320       
    321321        if ((!task) || (!container_check(CONTAINER, task->container))) {
    322322                /*
     
    328328                return ENOENT;
    329329        }
    330 
     330       
    331331        /* Lock the task and release the lock protecting tasks_btree. */
    332332        irq_spinlock_exchange(&tasks_lock, &task->lock);
    333333        errno_t rc = ddi_iospace_disable_arch(task, ioaddr, size);
    334334        irq_spinlock_unlock(&task->lock, true);
    335 
     335       
    336336        return rc;
    337337}
     
    350350        if (rc != EOK)
    351351                return (sys_errno_t) rc;
    352 
     352       
    353353        return (sys_errno_t) iospace_enable((task_id_t) arg.task_id,
    354354            (uintptr_t) arg.ioaddr, (size_t) arg.size);
     
    370370{
    371371        assert(TASK);
    372 
     372       
    373373        // TODO: implement locking of non-anonymous mapping
    374374        return page_find_mapping(virt, phys);
     
    380380{
    381381        assert(TASK);
    382 
     382       
    383383        size_t frames = SIZE2FRAMES(size);
    384384        if (frames == 0)
     
    388388        if (*phys == 0)
    389389                return ENOMEM;
    390 
     390       
    391391        mem_backend_data_t backend_data;
    392392        backend_data.base = *phys;
    393393        backend_data.frames = frames;
    394394        backend_data.anonymous = true;
    395 
     395       
    396396        if (!as_area_create(TASK->as, map_flags, size,
    397397            AS_AREA_ATTR_NONE, &phys_backend, &backend_data, virt, bound)) {
     
    399399                return ENOMEM;
    400400        }
    401 
     401       
    402402        return EOK;
    403403}
     
    421421                 * Non-anonymous DMA mapping
    422422                 */
    423 
     423               
    424424                uintptr_t phys;
    425425                errno_t rc = dmamem_map((uintptr_t) virt_ptr, size, map_flags,
    426426                    flags, &phys);
    427 
     427               
    428428                if (rc != EOK)
    429429                        return rc;
    430 
     430               
    431431                rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys));
    432432                if (rc != EOK) {
     
    438438                 * Anonymous DMA mapping
    439439                 */
    440 
     440               
    441441                uintptr_t constraint;
    442442                errno_t rc = copy_from_uspace(&constraint, phys_ptr,
     
    444444                if (rc != EOK)
    445445                        return rc;
    446 
     446               
    447447                uintptr_t virt;
    448448                rc = copy_from_uspace(&virt, virt_ptr, sizeof(virt));
    449449                if (rc != EOK)
    450450                        return rc;
    451 
     451               
    452452                uintptr_t phys;
    453453                rc = dmamem_map_anonymous(size, constraint, map_flags, flags,
     
    455455                if (rc != EOK)
    456456                        return rc;
    457 
     457               
    458458                rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys));
    459459                if (rc != EOK) {
     
    461461                        return rc;
    462462                }
    463 
     463               
    464464                rc = copy_to_uspace(virt_ptr, &virt, sizeof(virt));
    465465                if (rc != EOK) {
     
    468468                }
    469469        }
    470 
     470       
    471471        return EOK;
    472472}
Note: See TracChangeset for help on using the changeset viewer.