Ignore:
File:
1 edited

Legend:

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

    r7de18418 r9d58539  
    4242#include <errno.h>
    4343#include <arch/cpu.h>
    44 #include <cpu.h>
    4544#include <arch.h>
    4645#include <align.h>
     
    5958int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    6059{
    61         size_t elements = ioaddr + size;
    62         if (elements > IO_PORTS)
     60        size_t bits = ioaddr + size;
     61        if (bits > IO_PORTS)
    6362                return ENOENT;
    6463       
    65         if (task->arch.iomap.elements < elements) {
     64        if (task->arch.iomap.bits < bits) {
    6665                /*
    6766                 * The I/O permission bitmap is too small and needs to be grown.
    6867                 */
    6968               
    70                 void *store = malloc(bitmap_size(elements, 0), FRAME_ATOMIC);
    71                 if (!store)
     69                uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
     70                if (!newmap)
    7271                        return ENOMEM;
    7372               
    7473                bitmap_t oldiomap;
    75                 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 0,
     74                bitmap_initialize(&oldiomap, task->arch.iomap.map,
    7675                    task->arch.iomap.bits);
    77                
    78                 bitmap_initialize(&task->arch.iomap, elements, 0, store);
     76                bitmap_initialize(&task->arch.iomap, newmap, bits);
    7977               
    8078                /*
    8179                 * Mark the new range inaccessible.
    8280                 */
    83                 bitmap_set_range(&task->arch.iomap, oldiomap.elements,
    84                     elements - oldiomap.elements);
     81                bitmap_set_range(&task->arch.iomap, oldiomap.bits,
     82                    bits - oldiomap.bits);
    8583               
    8684                /*
     
    9088                if (oldiomap.bits) {
    9189                        bitmap_copy(&task->arch.iomap, &oldiomap,
    92                             oldiomap.elements);
    93                        
    94                         free(oldiomap.bits);
     90                            oldiomap.bits);
     91                        free(oldiomap.map);
    9592                }
    9693        }
     
    9996         * Enable the range and we are done.
    10097         */
    101         bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, size);
     98        bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, (size_t) size);
    10299       
    103100        /*
     
    121118        /* First, copy the I/O Permission Bitmap. */
    122119        irq_spinlock_lock(&TASK->lock, false);
    123        
    124120        size_t ver = TASK->arch.iomapver;
    125         size_t elements = TASK->arch.iomap.elements;
    126        
    127         if (elements > 0) {
    128                 ASSERT(TASK->arch.iomap.bits);
     121        size_t bits = TASK->arch.iomap.bits;
     122        if (bits) {
     123                ASSERT(TASK->arch.iomap.map);
    129124               
    130125                bitmap_t iomap;
    131                 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 0,
    132                     CPU->arch.tss->iomap);
    133                 bitmap_copy(&iomap, &TASK->arch.iomap, elements);
     126                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
     127                    TSS_IOMAP_SIZE * 8);
     128                bitmap_copy(&iomap, &TASK->arch.iomap, bits);
    134129               
    135130                /*
     
    137132                 * I/O access.
    138133                 */
    139                 bitmap_set_range(&iomap, elements,
    140                     ALIGN_UP(elements, 8) - elements);
    141                
     134                bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
    142135                /*
    143136                 * It is safe to set the trailing eight bits because of the
    144137                 * extra convenience byte in TSS_IOMAP_SIZE.
    145138                 */
    146                 bitmap_set_range(&iomap, ALIGN_UP(elements, 8), 8);
     139                bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
    147140        }
    148        
    149141        irq_spinlock_unlock(&TASK->lock, false);
    150142       
    151143        /*
    152144         * Second, adjust TSS segment limit.
    153          * Take the extra ending byte with all bits set into account.
     145         * Take the extra ending byte will all bits set into account.
    154146         */
    155147        ptr_16_64_t cpugdtr;
     
    157149       
    158150        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    159         size_t size = bitmap_size(elements, 0);
    160         gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + size);
     151        gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
    161152        gdtr_load(&cpugdtr);
    162153       
Note: See TracChangeset for help on using the changeset viewer.