Changes in / [bf31e3f:3d4750f] in mainline
- Location:
- kernel
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/acpi/acpi.c
rbf31e3f r3d4750f 102 102 103 103 /* Start with mapping the header only. */ 104 vhdr = (struct acpi_sdt_header *) km_map _structure((uintptr_t) psdt,104 vhdr = (struct acpi_sdt_header *) km_map((uintptr_t) psdt, 105 105 sizeof(struct acpi_sdt_header), PAGE_READ | PAGE_NOT_CACHEABLE); 106 106 107 107 /* Now we can map the entire structure. */ 108 vsdt = (struct acpi_sdt_header *) km_map _structure((uintptr_t) psdt,108 vsdt = (struct acpi_sdt_header *) km_map((uintptr_t) psdt, 109 109 vhdr->length, PAGE_WRITE | PAGE_NOT_CACHEABLE); 110 110 -
kernel/generic/include/mm/km.h
rbf31e3f r3d4750f 50 50 51 51 extern uintptr_t km_map(uintptr_t, size_t, unsigned int); 52 extern uintptr_t km_map_structure(uintptr_t, size_t, unsigned int);52 extern void km_unmap(uintptr_t, size_t); 53 53 54 54 extern uintptr_t km_temporary_page_get(uintptr_t *, frame_flags_t); -
kernel/generic/src/mm/km.c
rbf31e3f r3d4750f 124 124 } 125 125 126 uintptr_t km_map(uintptr_t paddr, size_t size, unsigned int flags) 126 static uintptr_t 127 km_map_aligned(uintptr_t paddr, size_t size, unsigned int flags) 127 128 { 128 129 uintptr_t vaddr; 129 size_t asize;130 130 size_t align; 131 131 uintptr_t offs; 132 132 133 asize = ALIGN_UP(size, PAGE_SIZE); 133 ASSERT(ALIGN_DOWN(paddr, FRAME_SIZE) == paddr); 134 ASSERT(ALIGN_UP(size, FRAME_SIZE) == size); 135 134 136 align = ispwr2(size) ? size : (1U << (fnzb(size) + 1)); 135 vaddr = km_page_alloc( asize, max(PAGE_SIZE, align));137 vaddr = km_page_alloc(size, max(PAGE_SIZE, align)); 136 138 137 139 page_table_lock(AS_KERNEL, true); 138 for (offs = 0; offs < asize; offs += PAGE_SIZE) {140 for (offs = 0; offs < size; offs += PAGE_SIZE) { 139 141 page_mapping_insert(AS_KERNEL, vaddr + offs, paddr + offs, 140 142 flags); … … 145 147 } 146 148 147 uintptr_t km_map_structure(uintptr_t paddr, size_t size, unsigned int flags) 148 { 149 size_t offs = paddr - ALIGN_DOWN(paddr, FRAME_SIZE); 149 static void km_unmap_aligned(uintptr_t vaddr, size_t size) 150 { 151 uintptr_t offs; 152 ipl_t ipl; 153 154 ASSERT(ALIGN_DOWN(vaddr, PAGE_SIZE) == vaddr); 155 ASSERT(ALIGN_UP(size, PAGE_SIZE) == size); 156 157 page_table_lock(AS_KERNEL, true); 158 159 ipl = tlb_shootdown_start(TLB_INVL_ASID, ASID_KERNEL, 0, 0); 160 161 for (offs = 0; offs < size; offs += PAGE_SIZE) 162 page_mapping_remove(AS_KERNEL, vaddr + offs); 163 164 tlb_invalidate_asid(ASID_KERNEL); 165 166 as_invalidate_translation_cache(AS_KERNEL, 0, -1); 167 tlb_shootdown_finalize(ipl); 168 page_table_unlock(AS_KERNEL, true); 169 170 km_page_free(vaddr, size); 171 } 172 173 /** Map a piece of physical address space into the virtual address space. 174 * 175 * @param paddr Physical address to be mapped. May be unaligned. 176 * @param size Size of area starting at paddr to be mapped. 177 * @param flags Protection flags to be used for the mapping. 178 * 179 * @return New virtual address mapped to paddr. 180 */ 181 uintptr_t km_map(uintptr_t paddr, size_t size, unsigned int flags) 182 { 150 183 uintptr_t page; 151 152 page = km_map(ALIGN_DOWN(paddr, FRAME_SIZE), size + offs, flags); 184 size_t offs; 185 186 offs = paddr - ALIGN_DOWN(paddr, FRAME_SIZE); 187 page = km_map_aligned(ALIGN_DOWN(paddr, FRAME_SIZE), 188 ALIGN_UP(size + offs, FRAME_SIZE), flags); 189 153 190 return page + offs; 154 191 } 155 192 156 /** Unmap kernen non-identity page. 193 /** Unmap a piece of virtual address space. 194 * 195 * @param vaddr Virtual address to be unmapped. May be unaligned, but 196 * it must a value previously returned by km_map(). 197 * @param size Size of area starting at vaddr to be unmapped. 198 */ 199 void km_unmap(uintptr_t vaddr, size_t size) 200 { 201 size_t offs; 202 203 offs = vaddr - ALIGN_DOWN(vaddr, PAGE_SIZE); 204 km_unmap_aligned(ALIGN_DOWN(vaddr, PAGE_SIZE), 205 ALIGN_UP(size + offs, PAGE_SIZE)); 206 } 207 208 /** Unmap kernel non-identity page. 157 209 * 158 210 * @param[in] page Non-identity page to be unmapped. -
kernel/test/mm/mapping1.c
rbf31e3f r3d4750f 66 66 v = *((uint32_t *) page1); 67 67 68 if (v != TEST_MAGIC) 68 if (v != TEST_MAGIC) { 69 km_unmap(page0, PAGE_SIZE); 70 km_unmap(page1, PAGE_SIZE); 71 frame_free(frame); 69 72 return "Criss-cross read does not match the value written."; 73 } 70 74 71 75 TPRINTF("Writing zero using the second virtual address.\n"); … … 77 81 v = *((uint32_t *) page0); 78 82 79 if (v != 0) 83 if (v != 0) { 84 km_unmap(page0, PAGE_SIZE); 85 km_unmap(page1, PAGE_SIZE); 86 frame_free(frame); 80 87 return "Criss-cross read does not match the value written."; 88 } 81 89 } 82 90 83 // FIXME: do not leak frame, page0 and page1 91 km_unmap(page0, PAGE_SIZE); 92 km_unmap(page1, PAGE_SIZE); 93 frame_free(frame); 84 94 85 95 return NULL; -
kernel/test/mm/mapping1.def
rbf31e3f r3d4750f 3 3 "Mapping test", 4 4 &test_mapping1, 5 false5 true 6 6 },
Note:
See TracChangeset
for help on using the changeset viewer.