Changeset 99c2c69e in mainline for kernel/arch/amd64/src/ddi/ddi.c
- Timestamp:
- 2013-09-13T00:36:30Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 67fbd5e
- Parents:
- 7f84430 (diff), 11d41be5 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/ddi/ddi.c
r7f84430 r99c2c69e 42 42 #include <errno.h> 43 43 #include <arch/cpu.h> 44 #include <cpu.h> 44 45 #include <arch.h> 45 46 #include <align.h> … … 58 59 int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size) 59 60 { 60 size_t bits = ioaddr + size;61 if ( bits > IO_PORTS)61 size_t elements = ioaddr + size; 62 if (elements > IO_PORTS) 62 63 return ENOENT; 63 64 64 if (task->arch.iomap. bits < bits) {65 if (task->arch.iomap.elements < elements) { 65 66 /* 66 67 * The I/O permission bitmap is too small and needs to be grown. 67 68 */ 68 69 69 uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);70 if (! newmap)70 void *store = malloc(bitmap_size(elements), FRAME_ATOMIC); 71 if (!store) 71 72 return ENOMEM; 72 73 73 74 bitmap_t oldiomap; 74 bitmap_initialize(&oldiomap, task->arch.iomap. map,75 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 75 76 task->arch.iomap.bits); 76 bitmap_initialize(&task->arch.iomap, newmap, bits); 77 78 bitmap_initialize(&task->arch.iomap, elements, store); 77 79 78 80 /* 79 81 * Mark the new range inaccessible. 80 82 */ 81 bitmap_set_range(&task->arch.iomap, oldiomap. bits,82 bits - oldiomap.bits);83 bitmap_set_range(&task->arch.iomap, oldiomap.elements, 84 elements - oldiomap.elements); 83 85 84 86 /* … … 88 90 if (oldiomap.bits) { 89 91 bitmap_copy(&task->arch.iomap, &oldiomap, 90 oldiomap.bits); 91 free(oldiomap.map); 92 oldiomap.elements); 93 94 free(oldiomap.bits); 92 95 } 93 96 } … … 96 99 * Enable the range and we are done. 97 100 */ 98 bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, (size_t)size);101 bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, size); 99 102 100 103 /* … … 118 121 /* First, copy the I/O Permission Bitmap. */ 119 122 irq_spinlock_lock(&TASK->lock, false); 123 120 124 size_t ver = TASK->arch.iomapver; 121 size_t bits = TASK->arch.iomap.bits; 122 if (bits) { 123 ASSERT(TASK->arch.iomap.map); 125 size_t elements = TASK->arch.iomap.elements; 126 127 if (elements > 0) { 128 ASSERT(TASK->arch.iomap.bits); 124 129 125 130 bitmap_t iomap; 126 bitmap_initialize(&iomap, CPU->arch.tss->iomap,127 TSS_IOMAP_SIZE * 8);128 bitmap_copy(&iomap, &TASK->arch.iomap, bits);131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 132 CPU->arch.tss->iomap); 133 bitmap_copy(&iomap, &TASK->arch.iomap, elements); 129 134 130 135 /* … … 132 137 * I/O access. 133 138 */ 134 bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits); 139 bitmap_set_range(&iomap, elements, 140 ALIGN_UP(elements, 8) - elements); 141 135 142 /* 136 143 * It is safe to set the trailing eight bits because of the 137 144 * extra convenience byte in TSS_IOMAP_SIZE. 138 145 */ 139 bitmap_set_range(&iomap, ALIGN_UP( bits, 8), 8);146 bitmap_set_range(&iomap, ALIGN_UP(elements, 8), 8); 140 147 } 148 141 149 irq_spinlock_unlock(&TASK->lock, false); 142 150 143 151 /* 144 152 * Second, adjust TSS segment limit. 145 * Take the extra ending byte wi ll all bits set into account.153 * Take the extra ending byte with all bits set into account. 146 154 */ 147 155 ptr_16_64_t cpugdtr; … … 149 157 150 158 descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base; 151 gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits)); 159 size_t size = bitmap_size(elements); 160 gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + size); 152 161 gdtr_load(&cpugdtr); 153 162
Note:
See TracChangeset
for help on using the changeset viewer.