Changeset 7b3b571 in mainline
- Timestamp:
- 2012-01-28T14:40:18Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dc9a3ba
- Parents:
- 9970a5a (diff), 20de14d (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. - Location:
- kernel
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/arm32/src/ras.c
r9970a5a r7b3b571 38 38 #include <mm/frame.h> 39 39 #include <mm/page.h> 40 #include <mm/km.h> 40 41 #include <mm/tlb.h> 41 42 #include <mm/asid.h> … … 50 51 void ras_init(void) 51 52 { 52 ras_page = frame_alloc(ONE_FRAME, FRAME_KA); 53 memsetb(ras_page, FRAME_SIZE, 0); 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); 54 63 ras_page[RAS_START] = 0; 55 64 ras_page[RAS_END] = 0xffffffff; 56 /*57 * Userspace needs to be able to write to this page. The page is58 * cached in TLB as PAGE_KERNEL. Purge it from TLB and map it59 * 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);66 65 } 67 66 -
kernel/genarch/src/acpi/acpi.c
r9970a5a r7b3b571 39 39 #include <genarch/acpi/madt.h> 40 40 #include <arch/bios/bios.h> 41 #include <mm/as.h>42 41 #include <mm/page.h> 42 #include <mm/km.h> 43 43 #include <print.h> 44 44 … … 96 96 } 97 97 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); 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; 105 114 } 106 115 … … 118 127 (struct acpi_sdt_header *) (sysarg_t) acpi_rsdt->entry[i]; 119 128 120 map_sdt(hdr);121 if (CMP_SIGNATURE( hdr->signature, signature_map[j].signature)) {122 if (!acpi_sdt_check((uint8_t *) hdr))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)) 123 132 break; 124 133 125 *signature_map[j].sdt_ptr = hdr;134 *signature_map[j].sdt_ptr = vhdr; 126 135 LOG("%p: ACPI %s", *signature_map[j].sdt_ptr, 127 136 signature_map[j].description); … … 144 153 (struct acpi_sdt_header *) ((uintptr_t) acpi_xsdt->entry[i]); 145 154 146 map_sdt(hdr);147 if (CMP_SIGNATURE( hdr->signature, signature_map[j].signature)) {148 if (!acpi_sdt_check((uint8_t *) hdr))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)) 149 158 break; 150 159 151 *signature_map[j].sdt_ptr = hdr;160 *signature_map[j].sdt_ptr = vhdr; 152 161 LOG("%p: ACPI %s", *signature_map[j].sdt_ptr, 153 162 signature_map[j].description); … … 187 196 LOG("%p: ACPI Root System Description Pointer", acpi_rsdp); 188 197 189 acpi_rsdt = (struct acpi_rsdt *) ((uintptr_t) acpi_rsdp->rsdt_address); 198 uintptr_t acpi_rsdt_p = (uintptr_t) acpi_rsdp->rsdt_address; 199 uintptr_t acpi_xsdt_p = 0; 200 190 201 if (acpi_rsdp->revision) 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); 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); 198 211 199 212 if ((acpi_rsdt) && (!acpi_sdt_check((uint8_t *) acpi_rsdt))) { -
kernel/generic/include/mm/km.h
r9970a5a r7b3b571 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 53 53 54 extern uintptr_t km_temporary_page_get(uintptr_t *, frame_flags_t); -
kernel/generic/include/mm/page.h
r9970a5a r7b3b571 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);67 66 68 67 extern int page_find_mapping(uintptr_t, void **); -
kernel/generic/src/mm/km.c
r9970a5a r7b3b571 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 } 147 155 148 156 /** Unmap kernen non-identity page. -
kernel/generic/src/mm/page.c
r9970a5a r7b3b571 84 84 } 85 85 86 /** Map memory structure87 *88 * Identity-map memory structure89 * considering possible crossings90 * 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 110 86 /** Insert mapping of page to frame. 111 87 * -
kernel/test/mm/mapping1.c
r9970a5a r7b3b571 31 31 #include <mm/page.h> 32 32 #include <mm/frame.h> 33 #include <mm/as.h>34 33 #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 PAGE0 0x10000000 40 #define PAGE1 (PAGE0 + PAGE_SIZE) 41 42 #define VALUE0 UINT32_C(0x01234567) 43 #define VALUE1 UINT32_C(0x89abcdef) 39 #define TEST_MAGIC UINT32_C(0x01234567) 44 40 45 41 const char *test_mapping1(void) 46 42 { 47 uintptr_t frame0, frame1; 48 uint32_t v0, v1; 43 uintptr_t page0, page1; 44 uintptr_t frame; 45 uint32_t v; 46 int i; 49 47 50 frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 51 frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 48 frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_NONE); 49 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); 52 58 53 TPRINTF("Writing %#" PRIx32 " to physical address %p.\n", 54 (uint32_t) VALUE0, (void *) KA2PA(frame0)); 55 *((uint32_t *) frame0) = VALUE0; 59 for (i = 0; i < 2; i++) { 60 TPRINTF("Writing magic using the first virtual address.\n"); 61 62 *((uint32_t *) page0) = TEST_MAGIC; 63 64 TPRINTF("Reading magic using the second virtual address.\n"); 65 66 v = *((uint32_t *) page1); 56 67 57 TPRINTF("Writing %#" PRIx32 " to physical address %p.\n", 58 (uint32_t) VALUE1, (void *) KA2PA(frame1)); 59 *((uint32_t *) frame1) = VALUE1; 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"); 60 72 61 page_table_lock(AS, true);73 *((uint32_t *) page1) = 0; 62 74 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); 75 TPRINTF("Reading zero using the first virtual address.\n"); 66 76 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); 77 v = *((uint32_t *) page0); 78 79 if (v != 0) 80 return "Criss-cross read does not match the value written."; 81 } 70 82 71 page_table_unlock(AS, true); 72 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); 79 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"; 84 85 TPRINTF("Writing %#" PRIx32 " to virtual address %p.\n", 86 (uint32_t) 0, (void *) PAGE0); 87 *((uint32_t *) PAGE0) = 0; 88 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"; 83 // FIXME: do not leak frame, page0 and page1 105 84 106 85 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.