Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/ddi/ddi.c

    r98000fb re9e5b9ab  
    3636#include <arch/ddi/ddi.h>
    3737#include <proc/task.h>
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <adt/bitmap.h>
    4040#include <mm/slab.h>
     
    4949 * Interrupts are disabled and task is locked.
    5050 *
    51  * @param task Task.
     51 * @param task   Task.
    5252 * @param ioaddr Startign I/O space address.
    53  * @param size Size of the enabled I/O range.
     53 * @param size   Size of the enabled I/O range.
    5454 *
    5555 * @return 0 on success or an error code from errno.h.
     56 *
    5657 */
    5758int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    5859{
    59         size_t bits;
    60        
    61         bits = ioaddr + size;
     60        size_t bits = ioaddr + size;
    6261        if (bits > IO_PORTS)
    6362                return ENOENT;
    6463       
    6564        if (task->arch.iomap.bits < bits) {
    66                 bitmap_t oldiomap;
    67                 uint8_t *newmap;
    68                
    6965                /*
    7066                 * The I/O permission bitmap is too small and needs to be grown.
    7167                 */
    7268               
    73                 newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
     69                uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
    7470                if (!newmap)
    7571                        return ENOMEM;
    7672               
     73                bitmap_t oldiomap;
    7774                bitmap_initialize(&oldiomap, task->arch.iomap.map,
    7875                    task->arch.iomap.bits);
     
    115112 *
    116113 * Interrupts must be disabled prior this call.
     114 *
    117115 */
    118116void io_perm_bitmap_install(void)
    119117{
    120         size_t bits;
    121         ptr_16_64_t cpugdtr;
    122         descriptor_t *gdt_p;
    123         tss_descriptor_t *tss_desc;
    124         size_t ver;
    125        
    126118        /* First, copy the I/O Permission Bitmap. */
    127         spinlock_lock(&TASK->lock);
    128         ver = TASK->arch.iomapver;
    129         if ((bits = TASK->arch.iomap.bits)) {
     119        irq_spinlock_lock(&TASK->lock, false);
     120        size_t ver = TASK->arch.iomapver;
     121        size_t bits = TASK->arch.iomap.bits;
     122        if (bits) {
     123                ASSERT(TASK->arch.iomap.map);
     124               
    130125                bitmap_t iomap;
    131        
    132                 ASSERT(TASK->arch.iomap.map);
    133126                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    134127                    TSS_IOMAP_SIZE * 8);
    135                 bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
     128                bitmap_copy(&iomap, &TASK->arch.iomap, bits);
     129               
     130                /*
     131                 * Set the trailing bits in the last byte of the map to disable
     132                 * I/O access.
     133                 */
     134                bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
    136135                /*
    137136                 * It is safe to set the trailing eight bits because of the
    138137                 * extra convenience byte in TSS_IOMAP_SIZE.
    139138                 */
    140                 bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
     139                bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
    141140        }
    142         spinlock_unlock(&TASK->lock);
     141        irq_spinlock_unlock(&TASK->lock, false);
    143142       
    144143        /*
     
    146145         * Take the extra ending byte will all bits set into account.
    147146         */
     147        ptr_16_64_t cpugdtr;
    148148        gdtr_store(&cpugdtr);
    149         gdt_p = (descriptor_t *) cpugdtr.base;
     149       
     150        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    150151        gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
    151152        gdtr_load(&cpugdtr);
     
    155156         * type must be changed to describe inactive TSS.
    156157         */
    157         tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
     158        tss_descriptor_t *tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
    158159        tss_desc->type = AR_TSS;
    159         tr_load(gdtselector(TSS_DES));
     160        tr_load(GDT_SELECTOR(TSS_DES));
    160161       
    161162        /*
Note: See TracChangeset for help on using the changeset viewer.