Changes in / [7b3b571:9970a5a] in mainline
- Location:
- kernel
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/arm32/src/ras.c
r7b3b571 r9970a5a 38 38 #include <mm/frame.h> 39 39 #include <mm/page.h> 40 #include <mm/km.h>41 40 #include <mm/tlb.h> 42 41 #include <mm/asid.h> … … 51 50 void ras_init(void) 52 51 { 53 uintptr_t frame; 54 55 frame = (uintptr_t) frame_alloc(ONE_FRAME, 56 FRAME_ATOMIC | FRAME_HIGHMEM); 57 if (!frame) 58 frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_LOWMEM); 59 ras_page = (uintptr_t *) km_map(frame, 60 PAGE_SIZE, PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE); 61 62 memsetb(ras_page, PAGE_SIZE, 0); 52 ras_page = frame_alloc(ONE_FRAME, FRAME_KA); 53 memsetb(ras_page, FRAME_SIZE, 0); 63 54 ras_page[RAS_START] = 0; 64 55 ras_page[RAS_END] = 0xffffffff; 56 /* 57 * Userspace needs to be able to write to this page. The page is 58 * cached in TLB as PAGE_KERNEL. Purge it from TLB and map it 59 * read/write PAGE_USER. 60 */ 61 tlb_invalidate_pages(ASID_KERNEL, (uintptr_t)ras_page, 1); 62 page_table_lock(AS, true); 63 page_mapping_insert(AS, (uintptr_t)ras_page, (uintptr_t)KA2PA(ras_page), 64 PAGE_READ | PAGE_WRITE | PAGE_USER); 65 page_table_unlock(AS, true); 65 66 } 66 67 -
kernel/genarch/src/acpi/acpi.c
r7b3b571 r9970a5a 39 39 #include <genarch/acpi/madt.h> 40 40 #include <arch/bios/bios.h> 41 #include <mm/as.h> 41 42 #include <mm/page.h> 42 #include <mm/km.h>43 43 #include <print.h> 44 44 … … 96 96 } 97 97 98 static struct acpi_sdt_header *map_sdt(struct acpi_sdt_header *psdt) 99 { 100 struct acpi_sdt_header *vhdr; 101 struct acpi_sdt_header *vsdt; 102 103 /* Start with mapping the header only. */ 104 vhdr = (struct acpi_sdt_header *) km_map_structure((uintptr_t) psdt, 105 sizeof(struct acpi_sdt_header), PAGE_READ | PAGE_NOT_CACHEABLE); 106 107 /* Now we can map the entire structure. */ 108 vsdt = (struct acpi_sdt_header *) km_map_structure((uintptr_t) psdt, 109 vhdr->length, PAGE_WRITE | PAGE_NOT_CACHEABLE); 110 111 // TODO: do not leak vtmp 112 113 return vsdt; 98 static void map_sdt(struct acpi_sdt_header *sdt) 99 { 100 page_table_lock(AS_KERNEL, true); 101 page_mapping_insert(AS_KERNEL, (uintptr_t) sdt, (uintptr_t) sdt, 102 PAGE_NOT_CACHEABLE | PAGE_WRITE); 103 map_structure((uintptr_t) sdt, sdt->length); 104 page_table_unlock(AS_KERNEL, true); 114 105 } 115 106 … … 127 118 (struct acpi_sdt_header *) (sysarg_t) acpi_rsdt->entry[i]; 128 119 129 struct acpi_sdt_header *vhdr =map_sdt(hdr);130 if (CMP_SIGNATURE( vhdr->signature, signature_map[j].signature)) {131 if (!acpi_sdt_check((uint8_t *) vhdr))120 map_sdt(hdr); 121 if (CMP_SIGNATURE(hdr->signature, signature_map[j].signature)) { 122 if (!acpi_sdt_check((uint8_t *) hdr)) 132 123 break; 133 124 134 *signature_map[j].sdt_ptr = vhdr;125 *signature_map[j].sdt_ptr = hdr; 135 126 LOG("%p: ACPI %s", *signature_map[j].sdt_ptr, 136 127 signature_map[j].description); … … 153 144 (struct acpi_sdt_header *) ((uintptr_t) acpi_xsdt->entry[i]); 154 145 155 struct acpi_sdt_header *vhdr =map_sdt(hdr);156 if (CMP_SIGNATURE( vhdr->signature, signature_map[j].signature)) {157 if (!acpi_sdt_check((uint8_t *) vhdr))146 map_sdt(hdr); 147 if (CMP_SIGNATURE(hdr->signature, signature_map[j].signature)) { 148 if (!acpi_sdt_check((uint8_t *) hdr)) 158 149 break; 159 150 160 *signature_map[j].sdt_ptr = vhdr;151 *signature_map[j].sdt_ptr = hdr; 161 152 LOG("%p: ACPI %s", *signature_map[j].sdt_ptr, 162 153 signature_map[j].description); … … 196 187 LOG("%p: ACPI Root System Description Pointer", acpi_rsdp); 197 188 198 uintptr_t acpi_rsdt_p = (uintptr_t) acpi_rsdp->rsdt_address; 199 uintptr_t acpi_xsdt_p = 0; 200 189 acpi_rsdt = (struct acpi_rsdt *) ((uintptr_t) acpi_rsdp->rsdt_address); 201 190 if (acpi_rsdp->revision) 202 acpi_xsdt_p = (uintptr_t) acpi_rsdp->xsdt_address; 203 204 if (acpi_rsdt_p) 205 acpi_rsdt = (struct acpi_rsdt *) map_sdt( 206 (struct acpi_sdt_header *) acpi_rsdt_p); 207 208 if (acpi_xsdt_p) 209 acpi_xsdt = (struct acpi_xsdt *) map_sdt( 210 (struct acpi_sdt_header *) acpi_xsdt_p); 191 acpi_xsdt = (struct acpi_xsdt *) ((uintptr_t) acpi_rsdp->xsdt_address); 192 193 if (acpi_rsdt) 194 map_sdt((struct acpi_sdt_header *) acpi_rsdt); 195 196 if (acpi_xsdt) 197 map_sdt((struct acpi_sdt_header *) acpi_xsdt); 211 198 212 199 if ((acpi_rsdt) && (!acpi_sdt_check((uint8_t *) acpi_rsdt))) { -
kernel/generic/include/mm/km.h
r7b3b571 r9970a5a 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);53 52 54 53 extern uintptr_t km_temporary_page_get(uintptr_t *, frame_flags_t); -
kernel/generic/include/mm/page.h
r7b3b571 r9970a5a 64 64 extern pte_t *page_table_create(unsigned int); 65 65 extern void page_table_destroy(pte_t *); 66 extern void map_structure(uintptr_t, size_t); 66 67 67 68 extern int page_find_mapping(uintptr_t, void **); -
kernel/generic/src/mm/km.c
r7b3b571 r9970a5a 145 145 } 146 146 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);150 uintptr_t page;151 152 page = km_map(ALIGN_DOWN(paddr, FRAME_SIZE), size + offs, flags);153 return page + offs;154 }155 147 156 148 /** Unmap kernen non-identity page. -
kernel/generic/src/mm/page.c
r7b3b571 r9970a5a 84 84 } 85 85 86 /** Map memory structure 87 * 88 * Identity-map memory structure 89 * considering possible crossings 90 * of page boundaries. 91 * 92 * @param addr Address of the structure. 93 * @param size Size of the structure. 94 * 95 */ 96 void map_structure(uintptr_t addr, size_t size) 97 { 98 size_t length = size + (addr - (addr & ~(PAGE_SIZE - 1))); 99 size_t cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0); 100 101 size_t i; 102 for (i = 0; i < cnt; i++) 103 page_mapping_insert(AS_KERNEL, addr + i * PAGE_SIZE, 104 addr + i * PAGE_SIZE, PAGE_NOT_CACHEABLE | PAGE_WRITE); 105 106 /* Repel prefetched accesses to the old mapping. */ 107 memory_barrier(); 108 } 109 86 110 /** Insert mapping of page to frame. 87 111 * -
kernel/test/mm/mapping1.c
r7b3b571 r9970a5a 31 31 #include <mm/page.h> 32 32 #include <mm/frame.h> 33 #include <mm/as.h> 33 34 #include <arch/mm/page.h> 34 #include <mm/km.h>35 35 #include <typedefs.h> 36 36 #include <debug.h> 37 37 #include <arch.h> 38 38 39 #define TEST_MAGIC UINT32_C(0x01234567) 39 #define PAGE0 0x10000000 40 #define PAGE1 (PAGE0 + PAGE_SIZE) 41 42 #define VALUE0 UINT32_C(0x01234567) 43 #define VALUE1 UINT32_C(0x89abcdef) 40 44 41 45 const char *test_mapping1(void) 42 46 { 43 uintptr_t page0, page1; 44 uintptr_t frame; 45 uint32_t v; 46 int i; 47 uintptr_t frame0, frame1; 48 uint32_t v0, v1; 47 49 48 frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_NONE); 50 frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 51 frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 52 53 TPRINTF("Writing %#" PRIx32 " to physical address %p.\n", 54 (uint32_t) VALUE0, (void *) KA2PA(frame0)); 55 *((uint32_t *) frame0) = VALUE0; 56 57 TPRINTF("Writing %#" PRIx32 " to physical address %p.\n", 58 (uint32_t) VALUE1, (void *) KA2PA(frame1)); 59 *((uint32_t *) frame1) = VALUE1; 60 61 page_table_lock(AS, true); 49 62 50 page0 = km_map(frame, FRAME_SIZE, 51 PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE); 52 TPRINTF("Virtual address %p mapped to physical address %p.\n", 53 (void *) page0, (void *) frame); 54 page1 = km_map(frame, FRAME_SIZE, 55 PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE); 56 TPRINTF("Virtual address %p mapped to physical address %p.\n", 57 (void *) page1, (void *) frame); 63 TPRINTF("Mapping virtual address %p to physical address %p.\n", 64 (void *) PAGE0, (void *) KA2PA(frame0)); 65 page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); 58 66 59 for (i = 0; i < 2; i++) { 60 TPRINTF("Writing magic using the first virtual address.\n"); 67 TPRINTF("Mapping virtual address %p to physical address %p.\n", 68 (void *) PAGE1, (void *) KA2PA(frame1)); 69 page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); 61 70 62 *((uint32_t *) page0) = TEST_MAGIC; 63 64 TPRINTF("Reading magic using the second virtual address.\n"); 65 66 v = *((uint32_t *) page1); 71 page_table_unlock(AS, true); 67 72 68 if (v != TEST_MAGIC) 69 return "Criss-cross read does not match the value written."; 70 71 TPRINTF("Writing zero using the second virtual address.\n"); 73 v0 = *((uint32_t *) PAGE0); 74 v1 = *((uint32_t *) PAGE1); 75 TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n", 76 (void *) PAGE0, v0); 77 TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n", 78 (void *) PAGE1, v1); 72 79 73 *((uint32_t *) page1) = 0; 74 75 TPRINTF("Reading zero using the first virtual address.\n"); 80 if (v0 != VALUE0) 81 return "Value at v0 not equal to VALUE0"; 82 if (v1 != VALUE1) 83 return "Value at v1 not equal to VALUE1"; 76 84 77 v = *((uint32_t *) page0); 85 TPRINTF("Writing %#" PRIx32 " to virtual address %p.\n", 86 (uint32_t) 0, (void *) PAGE0); 87 *((uint32_t *) PAGE0) = 0; 78 88 79 if (v != 0) 80 return "Criss-cross read does not match the value written."; 81 } 82 83 // FIXME: do not leak frame, page0 and page1 89 TPRINTF("Writing %#" PRIx32 " to virtual address %p.\n", 90 (uint32_t) 0, (void *) PAGE1); 91 *((uint32_t *) PAGE1) = 0; 92 93 v0 = *((uint32_t *) PAGE0); 94 v1 = *((uint32_t *) PAGE1); 95 96 TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n", 97 (void *) PAGE0, *((uint32_t *) PAGE0)); 98 TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n", 99 (void *) PAGE1, *((uint32_t *) PAGE1)); 100 101 if (v0 != 0) 102 return "Value at v0 not equal to 0"; 103 if (v1 != 0) 104 return "Value at v1 not equal to 0"; 84 105 85 106 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.