[OpenBIOS] [PATCH 15/16] Switch remaining SPARC32 code over to OFMEM.

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Thu Dec 30 19:07:18 CET 2010


This patch removes the SPARC32-specific map_pages() function from the IOMMU driver, plus switches obp_dumb_memalloc()
over to use OFMEM. OFMEM property generation is enabled for the /memory and /virtual-memory nodes, and any remaining
traces of the old memory variables are removed.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>
---
 openbios-devel/arch/sparc32/lib.c          |   69 +++++++++------------------
 openbios-devel/drivers/iommu.c             |    2 +-
 openbios-devel/include/libopenbios/ofmem.h |    1 -
 3 files changed, 24 insertions(+), 48 deletions(-)

diff --git a/openbios-devel/arch/sparc32/lib.c b/openbios-devel/arch/sparc32/lib.c
index 74ac5e7..6b51f1c 100644
--- a/openbios-devel/arch/sparc32/lib.c
+++ b/openbios-devel/arch/sparc32/lib.c
@@ -53,8 +53,6 @@ struct mem {
     char *curp;
 };
 
-static struct mem cmem;         /* Current memory, virtual */
-static struct mem cio;          /* Current I/O space */
 struct mem cdvmem;              /* Current device virtual memory space */
 
 unsigned int va_shift;
@@ -190,7 +188,7 @@ find_pte(unsigned long va, int alloc)
     return pa2va(pa);
 }
 
-void
+static void
 map_pages(phys_addr_t phys, unsigned long virt,
 		  unsigned long size, unsigned long mode)
 {
@@ -353,29 +351,19 @@ void ofmem_arch_early_map_pages(phys_addr_t phys, ucell virt, ucell size, ucell
 
 char *obp_dumb_memalloc(char *va, unsigned int size)
 {
-    size = (size + 7) & ~7;
-    // XXX should use normal memory alloc
-    totavail[0].num_bytes -= size;
-    DPRINTF("obp_dumb_memalloc va 0x%p size %x at 0x%x\n", va, size,
-            totavail[0].num_bytes);
-
-    // If va is null, the allocator is supposed to pick a "suitable" address.
-    // (See OpenSolaric prom_alloc.c)  There's not any real guidance as
-    // to what might be "suitable".  So we mimic the behavior of a Sun boot
-    // ROM.
-
-    if (va == NULL) {
-        va = (char *)(totmap[0].start_adr - size);
-        totmap[0].start_adr -= size;
-        totmap[0].num_bytes += size;
-        DPRINTF("obp_dumb_memalloc req null -> 0x%p\n", va);
-    }
+    phys_addr_t phys;
+    ucell virt;
+ 
+    /* Claim physical memory */
+    phys = ofmem_claim_phys(-1, size, CONFIG_OFMEM_MALLOC_ALIGN);
+ 
+    /* Claim virtual memory */
+    virt = ofmem_claim_virt(pointer2cell(va), size, 0);
 
-    map_pages(totavail[0].num_bytes, (unsigned long)va, size, ofmem_arch_default_translation_mode(totavail[0].num_bytes));
+    /* Map the memory */
+    ofmem_map(phys, virt, size, ofmem_arch_default_translation_mode(phys));
 
-    update_memory_properties();
-
-    return va;
+    return cell2pointer(virt);
 }
 
 void obp_dumb_memfree(__attribute__((unused))char *va,
@@ -387,6 +375,9 @@ void obp_dumb_memfree(__attribute__((unused))char *va,
 void
 ob_init_mmu(void)
 {
+    ucell *reg;
+    ofmem_t *ofmem;
+
     init_romvec_mem();
 
     /* Find the phandles for the /memory and /virtual-memory nodes */
@@ -400,30 +391,19 @@ ob_init_mmu(void)
     POP();
     s_phandle_mmu = POP();
 
-    /* Setup /memory:reg (totphys) property */
-    push_str("/memory");
-    fword("find-device");
-    PUSH(pointer2cell(mem_reg));
-    PUSH(3 * sizeof(ucell));
-    push_str("reg");
-    PUSH_ph(s_phandle_memory);
-    fword("encode-property");
+    ofmem_register(s_phandle_memory, s_phandle_mmu);
 
-    /* Setup /virtual-memory:avail (totmap) property */
-    push_str("/virtual-memory");
-    fword("find-device");
-    PUSH(pointer2cell(virt_avail));
-    PUSH(3 * sizeof(ucell));
-    push_str("available");
-    PUSH_ph(s_phandle_mmu);
-    fword("encode-property");
+    /* Setup /memory:reg (totphys) property */
+    ofmem = ofmem_arch_get_private();
+    reg = malloc(3 * sizeof(ucell));
+    ofmem_arch_encode_physaddr(reg, 0); /* physical base */
+    reg[2] = (ucell)ofmem_arch_get_phys_top(); /* size */
 
-    /* Setup /memory:avail (totavail) property */
     push_str("/memory");
     fword("find-device");
-    PUSH(pointer2cell(mem_avail));
+    PUSH(pointer2cell(reg));
     PUSH(3 * sizeof(ucell));
-    push_str("available");
+    push_str("reg");
     PUSH_ph(s_phandle_memory);
     fword("encode-property");
 
@@ -443,9 +423,6 @@ init_mmu_swift(void)
     unsigned int addr, i;
     unsigned long pa, va;
     int size;
-    
-    mem_init(&cmem, (char *) &_vmem, (char *)&_evmem);
-    mem_init(&cio, (char *)&_end, (char *)&_iomem);
 
     ofmem_posix_memalign((void *)&context_table, NCTX_SWIFT * sizeof(int),
                    NCTX_SWIFT * sizeof(int));
diff --git a/openbios-devel/drivers/iommu.c b/openbios-devel/drivers/iommu.c
index 7d34f81..28f3b57 100644
--- a/openbios-devel/drivers/iommu.c
+++ b/openbios-devel/drivers/iommu.c
@@ -68,7 +68,7 @@ dvma_alloc(int size, unsigned int *pphys)
      */
     mva = (unsigned int) va;
     mpa = (unsigned int) pa;
-    map_pages(mpa, mva, npages * PAGE_SIZE, ofmem_arch_io_translation_mode(mpa));
+    ofmem_arch_early_map_pages(mpa, mva, npages * PAGE_SIZE, ofmem_arch_io_translation_mode(mpa));
 
     /*
      * Map into IOMMU page table.
diff --git a/openbios-devel/include/libopenbios/ofmem.h b/openbios-devel/include/libopenbios/ofmem.h
index 4588a5e..5d7bfeb 100644
--- a/openbios-devel/include/libopenbios/ofmem.h
+++ b/openbios-devel/include/libopenbios/ofmem.h
@@ -135,7 +135,6 @@ extern struct mem cdvmem;
 
 void mem_init(struct mem *t, char *begin, char *limit);
 void *mem_alloc(struct mem *t, int size, int align);
-void map_pages(phys_addr_t phys, unsigned long virt, unsigned long size, unsigned long mode);
 #endif
 
 #ifdef PAGE_SHIFT
-- 
1.7.2.3




More information about the OpenBIOS mailing list