Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset f93ba6d in mainline


Ignore:
Timestamp:
2014-08-31T19:01:29Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
c62a8275
Parents:
af0a2c7 (diff), 6eeb4a3 (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 from lp:~jakub/helenos/piodisable.

Files:
1 added
5 deleted
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    raf0a2c7 rf93ba6d  
    346346! [PLATFORM=amd64] CONFIG_FENCES_P4 (y)
    347347
     348% IOMAP bitmap support
     349! [PLATFORM=ia32|PLATFORM=amd64] CONFIG_IOMAP_BITMAP (y)
     350
     351% IOMAP dummy support
     352! [PLATFORM=abs32le|PLATFORM=arm32|PLATFORM=mips32|PLATFORM=ppc32|PLATFORM=sparc32|PLATFORM=sparc64] CONFIG_IOMAP_DUMMY (y)
     353
    348354% ACPI support
    349355! [PLATFORM=ia32|PLATFORM=amd64] CONFIG_ACPI (y)
  • kernel/arch/abs32le/Makefile.inc

    raf0a2c7 rf93ba6d  
    5050        arch/$(KARCH)/src/userspace.c \
    5151        arch/$(KARCH)/src/cpu/cpu.c \
    52         arch/$(KARCH)/src/ddi/ddi.c \
    5352        arch/$(KARCH)/src/smp/smp.c \
    5453        arch/$(KARCH)/src/smp/ipi.c \
  • kernel/arch/amd64/src/ddi/ddi.c

    raf0a2c7 rf93ba6d  
    4545#include <arch.h>
    4646#include <align.h>
    47 
    48 /** Enable I/O space range for task.
    49  *
    50  * Interrupts are disabled and task is locked.
    51  *
    52  * @param task   Task.
    53  * @param ioaddr Startign I/O space address.
    54  * @param size   Size of the enabled I/O range.
    55  *
    56  * @return 0 on success or an error code from errno.h.
    57  *
    58  */
    59 int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    60 {
    61         size_t elements = ioaddr + size;
    62         if (elements > IO_PORTS)
    63                 return ENOENT;
    64        
    65         if (task->arch.iomap.elements < elements) {
    66                 /*
    67                  * The I/O permission bitmap is too small and needs to be grown.
    68                  */
    69                
    70                 void *store = malloc(bitmap_size(elements), FRAME_ATOMIC);
    71                 if (!store)
    72                         return ENOMEM;
    73                
    74                 bitmap_t oldiomap;
    75                 bitmap_initialize(&oldiomap, task->arch.iomap.elements,
    76                     task->arch.iomap.bits);
    77                
    78                 bitmap_initialize(&task->arch.iomap, elements, store);
    79                
    80                 /*
    81                  * Mark the new range inaccessible.
    82                  */
    83                 bitmap_set_range(&task->arch.iomap, oldiomap.elements,
    84                     elements - oldiomap.elements);
    85                
    86                 /*
    87                  * In case there really existed smaller iomap,
    88                  * copy its contents and deallocate it.
    89                  */
    90                 if (oldiomap.bits) {
    91                         bitmap_copy(&task->arch.iomap, &oldiomap,
    92                             oldiomap.elements);
    93                        
    94                         free(oldiomap.bits);
    95                 }
    96         }
    97        
    98         /*
    99          * Enable the range and we are done.
    100          */
    101         bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, size);
    102        
    103         /*
    104          * Increment I/O Permission bitmap generation counter.
    105          */
    106         task->arch.iomapver++;
    107        
    108         return 0;
    109 }
    11047
    11148/** Install I/O Permission bitmap.
  • kernel/arch/arm32/Makefile.inc

    raf0a2c7 rf93ba6d  
    5454        arch/$(KARCH)/src/dummy.S \
    5555        arch/$(KARCH)/src/cpu/cpu.c \
    56         arch/$(KARCH)/src/ddi/ddi.c \
    5756        arch/$(KARCH)/src/interrupt.c \
    5857        arch/$(KARCH)/src/exception.c \
  • kernel/arch/ia32/src/ddi/ddi.c

    raf0a2c7 rf93ba6d  
    4545#include <arch.h>
    4646#include <align.h>
    47 
    48 /** Enable I/O space range for task.
    49  *
    50  * Interrupts are disabled and task is locked.
    51  *
    52  * @param task   Task.
    53  * @param ioaddr Startign I/O space address.
    54  * @param size   Size of the enabled I/O range.
    55  *
    56  * @return 0 on success or an error code from errno.h.
    57  *
    58  */
    59 int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    60 {
    61         size_t elements = ioaddr + size;
    62         if (elements > IO_PORTS)
    63                 return ENOENT;
    64        
    65         if (task->arch.iomap.elements < elements) {
    66                 /*
    67                  * The I/O permission bitmap is too small and needs to be grown.
    68                  */
    69                
    70                 void *store = malloc(bitmap_size(elements), FRAME_ATOMIC);
    71                 if (!store)
    72                         return ENOMEM;
    73                
    74                 bitmap_t oldiomap;
    75                 bitmap_initialize(&oldiomap, task->arch.iomap.elements,
    76                     task->arch.iomap.bits);
    77                
    78                 bitmap_initialize(&task->arch.iomap, elements, store);
    79                
    80                 /*
    81                  * Mark the new range inaccessible.
    82                  */
    83                 bitmap_set_range(&task->arch.iomap, oldiomap.elements,
    84                     elements - oldiomap.elements);
    85                
    86                 /*
    87                  * In case there really existed smaller iomap,
    88                  * copy its contents and deallocate it.
    89                  */
    90                 if (oldiomap.bits) {
    91                         bitmap_copy(&task->arch.iomap, &oldiomap,
    92                             oldiomap.elements);
    93                        
    94                         free(oldiomap.bits);
    95                 }
    96         }
    97        
    98         /*
    99          * Enable the range and we are done.
    100          */
    101         bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, size);
    102        
    103         /*
    104          * Increment I/O Permission bitmap generation counter.
    105          */
    106         task->arch.iomapver++;
    107        
    108         return 0;
    109 }
    11047
    11148/** Install I/O Permission bitmap.
  • kernel/arch/ia64/src/ddi/ddi.c

    raf0a2c7 rf93ba6d  
    4747 * Interrupts are disabled and task is locked.
    4848 *
    49  * @param task          Task.
    50  * @param ioaddr        Starting I/O space address.
    51  * @param size          Size of the enabled I/O range.
     49 * @param task   Task.
     50 * @param ioaddr Starting I/O space address.
     51 * @param size   Size of the enabled I/O range.
    5252 *
    53  * @return 0 on success or an error code from errno.h.
     53 * @return EOK on success or an error code from errno.h.
    5454 */
    5555int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
     
    7272        bitmap_set_range(task->arch.iomap, iopage, size / 4);
    7373       
    74         return 0;
     74        return EOK;
     75}
     76
     77/** Disable I/O space range for task.
     78 *
     79 * Interrupts are disabled and task is locked.
     80 *
     81 * @param task   Task.
     82 * @param ioaddr Starting I/O space address.
     83 * @param size   Size of the disabled I/O range.
     84 *
     85 * @return EOK on success or an error code from errno.h.
     86 */
     87int ddi_iospace_disable_arch(task_t *task, uintptr_t ioaddr, size_t size)
     88{
     89        if (!task->arch.iomap)
     90                return EINVAL;
     91
     92        uintptr_t iopage = ioaddr / PORTS_PER_PAGE;
     93        size = ALIGN_UP(size + ioaddr - 4 * iopage, PORTS_PER_PAGE);
     94        bitmap_clear_range(task->arch.iomap, iopage, size / 4);
     95       
     96        return EOK;
    7597}
    7698
  • kernel/arch/mips32/Makefile.inc

    raf0a2c7 rf93ba6d  
    7070        arch/$(KARCH)/src/mm/as.c \
    7171        arch/$(KARCH)/src/fpu_context.c \
    72         arch/$(KARCH)/src/ddi/ddi.c \
    7372        arch/$(KARCH)/src/smp/smp.c \
    7473        arch/$(KARCH)/src/machine_func.c
  • kernel/arch/ppc32/Makefile.inc

    raf0a2c7 rf93ba6d  
    5151        arch/$(KARCH)/src/cpu/cpu.c \
    5252        arch/$(KARCH)/src/proc/scheduler.c \
    53         arch/$(KARCH)/src/ddi/ddi.c \
    5453        arch/$(KARCH)/src/mm/km.c \
    5554        arch/$(KARCH)/src/mm/as.c \
  • kernel/arch/sparc32/Makefile.inc

    raf0a2c7 rf93ba6d  
    4545        arch/$(KARCH)/src/exception.c \
    4646        arch/$(KARCH)/src/cpu/cpu.c \
    47         arch/$(KARCH)/src/ddi/ddi.c \
    4847        arch/$(KARCH)/src/smp/smp.c \
    4948        arch/$(KARCH)/src/smp/ipi.c \
  • kernel/arch/sparc64/Makefile.inc

    raf0a2c7 rf93ba6d  
    8181        arch/$(KARCH)/src/trap/exception.c \
    8282        arch/$(KARCH)/src/trap/interrupt.c \
    83         arch/$(KARCH)/src/ddi/ddi.c \
    8483        arch/$(KARCH)/src/drivers/tick.c \
    8584        arch/$(KARCH)/src/drivers/kbd.c \
  • kernel/genarch/Makefile.inc

    raf0a2c7 rf93ba6d  
    181181                genarch/src/drivers/ega/ega.c
    182182endif
     183
     184ifeq ($(CONFIG_IOMAP_BITMAP), y)
     185        GENARCH_SOURCES += \
     186                genarch/src/ddi/ddi-bitmap.c
     187endif
     188
     189ifeq ($(CONFIG_IOMAP_DUMMY), y)
     190        GENARCH_SOURCES += \
     191                genarch/src/ddi/ddi-dummy.c
     192endif
     193
  • kernel/genarch/src/ddi/ddi-dummy.c

    raf0a2c7 rf93ba6d  
    2727 */
    2828
    29 /** @addtogroup sparc64ddi
     29/** @addtogroup genarch
    3030 * @{
    3131 */
    3232/** @file
     33 *  @brief DDI.
    3334 */
    3435
     
    4142 * Interrupts are disabled and task is locked.
    4243 *
    43  * @param task Task.
     44 * @param task   Task.
    4445 * @param ioaddr Starting I/O space address.
    45  * @param size Size of the enabled I/O range.
     46 * @param size   Size of the enabled I/O range.
    4647 *
    47  * @return 0 on success or an error code from errno.h.
     48 * @return EOK on success or an error code from errno.h.
    4849 */
    4950int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
     
    5253}
    5354
     55/** Disable I/O space range for task.
     56 *
     57 * Interrupts are disabled and task is locked.
     58 *
     59 * @param task   Task.
     60 * @param ioaddr Starting I/O space address.
     61 * @param size   Size of the disabled I/O range.
     62 *
     63 * @return EOK on success or an error code from errno.h.
     64 */
     65int ddi_iospace_disable_arch(task_t *task, uintptr_t ioaddr, size_t size)
     66{
     67        return 0;
     68}
     69
    5470/** @}
    5571 */
  • kernel/generic/include/ddi/ddi.h

    raf0a2c7 rf93ba6d  
    7070 */
    7171extern int ddi_iospace_enable_arch(task_t *, uintptr_t, size_t);
     72extern int ddi_iospace_disable_arch(task_t *, uintptr_t, size_t);
    7273
    7374#endif
  • kernel/generic/src/ddi/ddi.c

    raf0a2c7 rf93ba6d  
    211211NO_TRACE static int physmem_unmap(uintptr_t virt)
    212212{
    213         // TODO: implement unmap
    214         return EOK;
     213        ASSERT(TASK);
     214
     215        return as_area_destroy(TASK->as, virt);
    215216}
    216217
     
    255256/** Enable range of I/O space for task.
    256257 *
    257  * @param id Task ID of the destination task.
     258 * @param id     Task ID of the destination task.
    258259 * @param ioaddr Starting I/O address.
    259  * @param size Size of the enabled I/O space..
     260 * @param size   Size of the enabled I/O space.
    260261 *
    261262 * @return 0 on success, EPERM if the caller lacks capabilities to use this
     
    290291        int rc = ddi_iospace_enable_arch(task, ioaddr, size);
    291292        irq_spinlock_unlock(&task->lock, true);
     293
     294        return rc;
     295}
     296
     297/** Disable range of I/O space for task.
     298 *
     299 * @param id     Task ID of the destination task.
     300 * @param ioaddr Starting I/O address.
     301 * @param size   Size of the enabled I/O space.
     302 *
     303 * @return 0 on success, EPERM if the caller lacks capabilities to use this
     304 *           syscall, ENOENT if there is no task matching the specified ID.
     305 *
     306 */
     307NO_TRACE static int iospace_disable(task_id_t id, uintptr_t ioaddr, size_t size)
     308{
     309        /*
     310         * Make sure the caller is authorised to make this syscall.
     311         */
     312        cap_t caps = cap_get(TASK);
     313        if (!(caps & CAP_IO_MANAGER))
     314                return EPERM;
     315       
     316        irq_spinlock_lock(&tasks_lock, true);
     317       
     318        task_t *task = task_find_by_id(id);
     319       
     320        if ((!task) || (!container_check(CONTAINER, task->container))) {
     321                /*
     322                 * There is no task with the specified ID
     323                 * or the task belongs to a different security
     324                 * context.
     325                 */
     326                irq_spinlock_unlock(&tasks_lock, true);
     327                return ENOENT;
     328        }
     329       
     330        /* Lock the task and release the lock protecting tasks_btree. */
     331        irq_spinlock_exchange(&tasks_lock, &task->lock);
     332        int rc = ddi_iospace_disable_arch(task, ioaddr, size);
     333        irq_spinlock_unlock(&task->lock, true);
    292334       
    293335        return rc;
     
    314356sysarg_t sys_iospace_disable(ddi_ioarg_t *uspace_io_arg)
    315357{
    316         // TODO: implement
    317         return ENOTSUP;
     358        ddi_ioarg_t arg;
     359        int rc = copy_from_uspace(&arg, uspace_io_arg, sizeof(ddi_ioarg_t));
     360        if (rc != 0)
     361                return (sysarg_t) rc;
     362
     363        return (sysarg_t) iospace_disable((task_id_t) arg.task_id,
     364            (uintptr_t) arg.ioaddr, (size_t) arg.size);
    318365}
    319366
  • uspace/lib/c/generic/ddi.c

    raf0a2c7 rf93ba6d  
    8787}
    8888
     89/** Unmap a piece of physical memory to task.
     90 *
     91 * Caller of this function must have the CAP_MEM_MANAGER capability.
     92 *
     93 * @param virt Virtual address from the phys-mapped region.
     94 *
     95 * @return EOK on success.
     96 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability.
     97 *
     98 */
     99int physmem_unmap(void *virt)
     100{
     101        return __SYSCALL1(SYS_PHYSMEM_UNMAP, (sysarg_t) virt);
     102}
     103
    89104/** Lock a piece physical memory for DMA transfers.
    90105 *
     
    179194       
    180195        return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
     196}
     197
     198/** Disable I/O space range to task.
     199 *
     200 * Caller of this function must have the IO_MEM_MANAGER capability.
     201 *
     202 * @param id     Task ID.
     203 * @param ioaddr Starting address of the I/O range.
     204 * @param size   Size of the range.
     205 *
     206 * @return EOK on success
     207 * @return EPERM if the caller lacks the CAP_IO_MANAGER capability
     208 * @return ENOENT if there is no task with specified ID
     209 *
     210 */
     211static int iospace_disable(task_id_t id, void *ioaddr, size_t size)
     212{
     213        const ddi_ioarg_t arg = {
     214                .task_id = id,
     215                .ioaddr = ioaddr,
     216                .size = size
     217        };
     218       
     219        return __SYSCALL1(SYS_IOSPACE_DISABLE, (sysarg_t) &arg);
    181220}
    182221
     
    273312}
    274313
     314/** Disable PIO for specified I/O range.
     315 *
     316 * @param virt     I/O start address.
     317 * @param size     Size of the I/O region.
     318 *
     319 * @return EOK on success.
     320 * @return Negative error code on failure.
     321 *
     322 */
     323int pio_disable(void *virt, size_t size)
     324{
     325#ifdef IO_SPACE_BOUNDARY
     326        if (virt < IO_SPACE_BOUNDARY)
     327                return iospace_disable(task_get_id(), virt, size);
     328#else
     329        (void) iospace_disable;
     330#endif
     331        return physmem_unmap(virt);
     332}
     333
    275334void pio_write_8(ioport8_t *reg, uint8_t val)
    276335{
  • uspace/lib/c/include/ddi.h

    raf0a2c7 rf93ba6d  
    5151
    5252extern int physmem_map(uintptr_t, size_t, unsigned int, void **);
     53extern int physmem_unmap(void *);
    5354
    5455extern int dmamem_map(void *, size_t, unsigned int, unsigned int, uintptr_t *);
     
    6162extern int pio_enable_resource(pio_window_t *, hw_resource_t *, void **);
    6263extern int pio_enable(void *, size_t, void **);
     64extern int pio_disable(void *, size_t);
    6365
    6466typedef void (*trace_fnc)(const volatile void *place, uint32_t val,
Note: See TracChangeset for help on using the changeset viewer.