Changeset 89c57b6 in mainline for kernel/generic/src/ddi/ddi.c


Ignore:
Timestamp:
2011-04-13T14:45:41Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
88634420
Parents:
cefb126 (diff), 17279ead (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
  • kernel/generic/src/ddi/ddi.c

    rcefb126 r89c57b6  
    5252#include <align.h>
    5353#include <errno.h>
     54#include <trace.h>
    5455
    5556/** This lock protects the parea_btree. */
     
    99100 *
    100101 */
    101 static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, size_t pages,
     102NO_TRACE static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, size_t pages,
    102103    unsigned int flags)
    103104{
    104105        ASSERT(TASK);
    105         ASSERT((pf % FRAME_SIZE) == 0);
    106         ASSERT((vp % PAGE_SIZE) == 0);
    107        
    108         /*
    109          * Make sure the caller is authorised to make this syscall.
    110          */
    111         cap_t caps = cap_get(TASK);
    112         if (!(caps & CAP_MEM_MANAGER))
    113                 return EPERM;
     106       
     107        if ((pf % FRAME_SIZE) != 0)
     108                return EBADMEM;
     109       
     110        if ((vp % PAGE_SIZE) != 0)
     111                return EBADMEM;
     112       
     113        /*
     114         * Unprivileged tasks are only allowed to map pareas
     115         * which are explicitly marked as such.
     116         */
     117        bool priv =
     118            ((cap_get(TASK) & CAP_MEM_MANAGER) == CAP_MEM_MANAGER);
    114119       
    115120        mem_backend_data_t backend_data;
     
    122127       
    123128        if (znum == (size_t) -1) {
    124                 /* Frames not found in any zones
    125                  * -> assume it is hardware device and allow mapping
     129                /*
     130                 * Frames not found in any zone
     131                 * -> assume it is a hardware device and allow mapping
     132                 *    for privileged tasks.
    126133                 */
    127134                irq_spinlock_unlock(&zones.lock, true);
     135               
     136                if (!priv)
     137                        return EPERM;
     138               
    128139                goto map;
    129140        }
    130141       
    131142        if (zones.info[znum].flags & ZONE_FIRMWARE) {
    132                 /* Frames are part of firmware */
     143                /*
     144                 * Frames are part of firmware
     145                 * -> allow mapping for privileged tasks.
     146                 */
    133147                irq_spinlock_unlock(&zones.lock, true);
     148               
     149                if (!priv)
     150                        return EPERM;
     151               
    134152                goto map;
    135153        }
     
    137155        if (zone_flags_available(zones.info[znum].flags)) {
    138156                /*
    139                  * Frames are part of physical memory, check if the memory
    140                  * region is enabled for mapping.
     157                 * Frames are part of physical memory, check
     158                 * if the memory region is enabled for mapping.
    141159                 */
    142160                irq_spinlock_unlock(&zones.lock, true);
     
    149167                if ((!parea) || (parea->frames < pages)) {
    150168                        mutex_unlock(&parea_lock);
    151                         goto err;
     169                        return ENOENT;
     170                }
     171               
     172                if (!priv) {
     173                        if (!parea->unpriv) {
     174                                mutex_unlock(&parea_lock);
     175                                return EPERM;
     176                        }
    152177                }
    153178               
     
    157182       
    158183        irq_spinlock_unlock(&zones.lock, true);
    159        
    160 err:
    161184        return ENOENT;
    162185       
     
    187210 *
    188211 */
    189 static int ddi_iospace_enable(task_id_t id, uintptr_t ioaddr, size_t size)
     212NO_TRACE static int ddi_iospace_enable(task_id_t id, uintptr_t ioaddr,
     213    size_t size)
    190214{
    191215        /*
     
    230254 *
    231255 */
    232 unative_t sys_physmem_map(unative_t phys_base, unative_t virt_base,
    233     unative_t pages, unative_t flags)
    234 {
    235         return (unative_t) ddi_physmem_map(ALIGN_DOWN((uintptr_t) phys_base,
     256sysarg_t sys_physmem_map(sysarg_t phys_base, sysarg_t virt_base,
     257    sysarg_t pages, sysarg_t flags)
     258{
     259        return (sysarg_t) ddi_physmem_map(ALIGN_DOWN((uintptr_t) phys_base,
    236260            FRAME_SIZE), ALIGN_DOWN((uintptr_t) virt_base, PAGE_SIZE),
    237261            (size_t) pages, (int) flags);
     
    245269 *
    246270 */
    247 unative_t sys_iospace_enable(ddi_ioarg_t *uspace_io_arg)
     271sysarg_t sys_iospace_enable(ddi_ioarg_t *uspace_io_arg)
    248272{
    249273        ddi_ioarg_t arg;
    250274        int rc = copy_from_uspace(&arg, uspace_io_arg, sizeof(ddi_ioarg_t));
    251275        if (rc != 0)
    252                 return (unative_t) rc;
    253        
    254         return (unative_t) ddi_iospace_enable((task_id_t) arg.task_id,
     276                return (sysarg_t) rc;
     277       
     278        return (sysarg_t) ddi_iospace_enable((task_id_t) arg.task_id,
    255279            (uintptr_t) arg.ioaddr, (size_t) arg.size);
    256280}
    257281
    258 /** Disable or enable preemption.
    259  *
    260  * @param enable If non-zero, the preemption counter will be decremented,
    261  *               leading to potential enabling of preemption. Otherwise
    262  *               the preemption counter will be incremented, preventing
    263  *               preemption from occurring.
    264  *
    265  * @return Zero on success or EPERM if callers capabilities are not sufficient.
    266  *
    267  */
    268 unative_t sys_preempt_control(int enable)
    269 {
    270         if (!(cap_get(TASK) & CAP_PREEMPT_CONTROL))
    271                 return EPERM;
    272        
    273         if (enable)
    274                 preemption_enable();
    275         else
    276                 preemption_disable();
    277        
    278         return 0;
    279 }
    280 
    281282/** @}
    282283 */
Note: See TracChangeset for help on using the changeset viewer.