
Author: mcayland Date: Sat Apr 28 15:34:48 2012 New Revision: 1051 URL: http://tracker.coreboot.org/trac/openbios/changeset/1051 Log: SPARC64: Refactor tte-data code in preparation for moving architecture-specific code to ofmem_sparc64.c. Note we also change pgmap@ so it explicitly searches for a TTE entry using architecture-specific code, plus add the code to detect whether a page is marked as locked or not into the main page mapping function. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Modified: trunk/openbios-devel/arch/sparc64/lib.c trunk/openbios-devel/arch/sparc64/ofmem_sparc64.c trunk/openbios-devel/include/libopenbios/ofmem.h Modified: trunk/openbios-devel/arch/sparc64/lib.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/lib.c Sat Apr 28 15:34:46 2012 (r1050) +++ trunk/openbios-devel/arch/sparc64/lib.c Sat Apr 28 15:34:48 2012 (r1051) @@ -16,8 +16,6 @@ #include "ofmem_sparc64.h" -static ucell *va2ttedata = 0; - /* Format a string and print it on the screen, just like the libc * function printf. */ @@ -165,35 +163,21 @@ static void pgmap_fetch(void) { - translation_t *t = *g_ofmem_translations; - unsigned long va, tte_data; - - va = POP(); - - /* Search the ofmem linked list for this virtual address */ - while (t != NULL) { - /* Find the correct range */ - if (va >= t->virt && va < (t->virt + t->size)) { + unsigned long va, tte_data; - /* valid tte, 8k size */ - tte_data = SPITFIRE_TTE_VALID; + va = POP(); - /* mix in phys address mode */ - tte_data |= t->mode; + tte_data = find_tte(va); + if (tte_data == -1) + goto error; - /* mix in page physical address = t->phys + offset */ - tte_data |= t->phys + (va - t->virt); - - /* return tte_data */ - PUSH(tte_data); - - return; - } - t = t->next; - } + /* return tte_data */ + PUSH(tte_data); + return; - /* If we get here, there was no entry */ - PUSH(0); +error: + /* If we get here, there was no entry */ + PUSH(0); } static void @@ -270,9 +254,7 @@ } } else { /* Search the ofmem linked list for this virtual address */ - PUSH(faultva); - pgmap_fetch(); - tte_data = POP(); + tte_data = find_tte(faultva); } if (tte_data) { @@ -359,9 +341,7 @@ } } else { /* Search the ofmem linked list for this virtual address */ - PUSH(faultva); - pgmap_fetch(); - tte_data = POP(); + tte_data = find_tte(faultva); } if (tte_data) { @@ -373,16 +353,14 @@ } } -static void -map_pages(phys_addr_t phys, unsigned long virt, - unsigned long size, unsigned long mode) +void ofmem_map_pages(phys_addr_t phys, ucell virt, ucell size, ucell mode) { - unsigned long tte_data, currsize; + unsigned long tte_data, currsize; - /* aligned to 8k page */ - size = (size + PAGE_MASK_8K) & ~PAGE_MASK_8K; + /* aligned to 8k page */ + size = (size + PAGE_MASK_8K) & ~PAGE_MASK_8K; - while (size > 0) { + while (size > 0) { currsize = size; if (currsize >= PAGE_SIZE_4M && (virt & PAGE_MASK_4M) == 0 && @@ -406,20 +384,18 @@ tte_data |= phys | mode | SPITFIRE_TTE_VALID; - itlb_load2(virt, tte_data); - dtlb_load2(virt, tte_data); - + if (mode & SPITFIRE_TTE_LOCKED) { + // install locked tlb entries now + itlb_load2(virt, tte_data); + dtlb_load2(virt, tte_data); + } + size -= currsize; phys += currsize; virt += currsize; } } -void ofmem_map_pages(phys_addr_t phys, ucell virt, ucell size, ucell mode) -{ - return map_pages(phys, virt, size, mode); -} - /* 3.6.5 map ( phys.lo ... phys.hi virt size mode -- ) @@ -457,7 +433,7 @@ static void unmap_pages(ucell virt, ucell size) { - ucell va; + ucell va; /* align address to 8k */ virt &= ~PAGE_MASK_8K; @@ -478,10 +454,7 @@ void ofmem_arch_map_pages(phys_addr_t phys, ucell virt, ucell size, ucell mode) { - if (mode & SPITFIRE_TTE_LOCKED) { - // install locked tlb entries now - ofmem_map_pages(phys, virt, size, mode); - } + ofmem_map_pages(phys, virt, size, mode); } /* Modified: trunk/openbios-devel/arch/sparc64/ofmem_sparc64.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/ofmem_sparc64.c Sat Apr 28 15:34:46 2012 (r1050) +++ trunk/openbios-devel/arch/sparc64/ofmem_sparc64.c Sat Apr 28 15:34:48 2012 (r1051) @@ -31,6 +31,7 @@ translation_t **g_ofmem_translations = &s_ofmem_data.ofmem.trans; +ucell *va2ttedata = 0; extern uint64_t qemu_mem_size; static inline size_t ALIGN_SIZE(size_t x, size_t a) @@ -162,6 +163,37 @@ return SPITFIRE_TTE_CV | SPITFIRE_TTE_WRITABLE; } +/* Architecture-specific helpers */ +unsigned long +find_tte(unsigned long va) +{ + translation_t *t = *g_ofmem_translations; + unsigned long tte_data; + + /* Search the ofmem linked list for this virtual address */ + while (t != NULL) { + /* Find the correct range */ + if (va >= t->virt && va < (t->virt + t->size)) { + + /* valid tte, 8k size */ + tte_data = SPITFIRE_TTE_VALID; + + /* mix in phys address mode */ + tte_data |= t->mode; + + /* mix in page physical address = t->phys + offset */ + tte_data |= t->phys + (va - t->virt); + + /* return tte_data */ + return tte_data; + } + t = t->next; + } + + /* Couldn't find tte */ + return -1; +} + /************************************************************************/ /* init / cleanup */ /************************************************************************/ Modified: trunk/openbios-devel/include/libopenbios/ofmem.h ============================================================================== --- trunk/openbios-devel/include/libopenbios/ofmem.h Sat Apr 28 15:34:46 2012 (r1050) +++ trunk/openbios-devel/include/libopenbios/ofmem.h Sat Apr 28 15:34:48 2012 (r1051) @@ -144,6 +144,12 @@ void mem_init(struct mem *t, char *begin, char *limit); void *mem_alloc(struct mem *t, int size, int align); + +#elif defined(CONFIG_SPARC64) + +extern ucell *va2ttedata; +extern unsigned long find_tte(unsigned long va); + #endif #ifdef PAGE_SHIFT