Changeset da1bafb in mainline for kernel/arch/ia32/src/ddi/ddi.c


Ignore:
Timestamp:
2010-05-24T18:57:31Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

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

    r666f492 rda1bafb  
    5050 * Interrupts are disabled and task is locked.
    5151 *
    52  * @param task Task.
     52 * @param task   Task.
    5353 * @param ioaddr Startign I/O space address.
    54  * @param size Size of the enabled I/O range.
     54 * @param size   Size of the enabled I/O range.
    5555 *
    5656 * @return 0 on success or an error code from errno.h.
     57 *
    5758 */
    5859int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    5960{
    60         size_t bits;
    61 
    62         bits = ioaddr + size;
     61        size_t bits = ioaddr + size;
    6362        if (bits > IO_PORTS)
    6463                return ENOENT;
    65 
     64       
    6665        if (task->arch.iomap.bits < bits) {
    67                 bitmap_t oldiomap;
    68                 uint8_t *newmap;
    69        
    7066                /*
    7167                 * The I/O permission bitmap is too small and needs to be grown.
    7268                 */
    7369               
    74                 newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
     70                uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
    7571                if (!newmap)
    7672                        return ENOMEM;
    7773               
     74                bitmap_t oldiomap;
    7875                bitmap_initialize(&oldiomap, task->arch.iomap.map,
    7976                    task->arch.iomap.bits);
    8077                bitmap_initialize(&task->arch.iomap, newmap, bits);
    81 
     78               
    8279                /*
    8380                 * Mark the new range inaccessible.
     
    8582                bitmap_set_range(&task->arch.iomap, oldiomap.bits,
    8683                    bits - oldiomap.bits);
    87 
     84               
    8885                /*
    8986                 * In case there really existed smaller iomap,
    9087                 * copy its contents and deallocate it.
    91                  */             
     88                 */
    9289                if (oldiomap.bits) {
    9390                        bitmap_copy(&task->arch.iomap, &oldiomap,
     
    9693                }
    9794        }
    98 
     95       
    9996        /*
    10097         * Enable the range and we are done.
    10198         */
    10299        bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, (size_t) size);
    103 
     100       
    104101        /*
    105102         * Increment I/O Permission bitmap generation counter.
    106103         */
    107104        task->arch.iomapver++;
    108 
     105       
    109106        return 0;
    110107}
     
    116113 *
    117114 * Interrupts must be disabled prior this call.
     115 *
    118116 */
    119117void io_perm_bitmap_install(void)
    120118{
    121         size_t bits;
    122         ptr_16_32_t cpugdtr;
    123         descriptor_t *gdt_p;
    124         size_t ver;
    125 
    126119        /* First, copy the I/O Permission Bitmap. */
    127         spinlock_lock(&TASK->lock);
    128         ver = TASK->arch.iomapver;
    129         if ((bits = TASK->arch.iomap.bits)) {
     120        irq_spinlock_lock(&TASK->lock, false);
     121        size_t ver = TASK->arch.iomapver;
     122        size_t bits = TASK->arch.iomap.bits;
     123        if (bits) {
     124                ASSERT(TASK->arch.iomap.map);
     125               
    130126                bitmap_t iomap;
    131                 task_t *task = TASK;
    132        
    133                 ASSERT(TASK->arch.iomap.map);
    134127                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    135128                    TSS_IOMAP_SIZE * 8);
    136                 bitmap_copy(&iomap, &task->arch.iomap, task->arch.iomap.bits);
     129                bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
     130               
    137131                /*
    138132                 * It is safe to set the trailing eight bits because of the
     
    141135                bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
    142136        }
    143         spinlock_unlock(&TASK->lock);
    144 
     137        irq_spinlock_unlock(&TASK->lock, false);
     138       
    145139        /*
    146140         * Second, adjust TSS segment limit.
    147141         * Take the extra ending byte with all bits set into account.
    148142         */
     143        ptr_16_32_t cpugdtr;
    149144        gdtr_store(&cpugdtr);
    150         gdt_p = (descriptor_t *) cpugdtr.base;
     145       
     146        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    151147        gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
    152148        gdtr_load(&cpugdtr);
    153 
     149       
    154150        /*
    155151         * Before we load new TSS limit, the current TSS descriptor
Note: See TracChangeset for help on using the changeset viewer.