[OpenBIOS] [PATCH 1/6] Delegate construction of memory "available" property to each architecture.

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Sun Jan 9 18:56:30 CET 2011


This is required because some architectures do not strictly follow the convention
of using physical addresses sizes in the /memory node and virtual addresses in
the /virtual-memory node.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>
---
 openbios-devel/arch/ppc/qemu/ofmem.c        |   24 ++++++++++++++++++++++++
 openbios-devel/arch/sparc32/lib.c           |    2 --
 openbios-devel/arch/sparc32/ofmem_sparc32.c |   24 ++++++++++++++++++++++++
 openbios-devel/arch/sparc64/ofmem_sparc64.c |   24 ++++++++++++++++++++++++
 openbios-devel/include/libopenbios/ofmem.h  |    6 ++++++
 openbios-devel/libopenbios/ofmem_common.c   |   27 +++++++--------------------
 6 files changed, 85 insertions(+), 22 deletions(-)

diff --git a/openbios-devel/arch/ppc/qemu/ofmem.c b/openbios-devel/arch/ppc/qemu/ofmem.c
index 4c6825e..f654d0f 100644
--- a/openbios-devel/arch/ppc/qemu/ofmem.c
+++ b/openbios-devel/arch/ppc/qemu/ofmem.c
@@ -195,6 +195,30 @@ void ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t)
     transentry[i++] = t->mode;
 }
 
+/* Return the size of a memory available entry given the phandle in cells */
+int ofmem_arch_get_available_entry_size(phandle_t ph)
+{
+    if (ph == s_phandle_memory) {
+        return 1 + ofmem_arch_get_physaddr_cellsize();
+    } else {
+        return 1 + 1;
+    }
+}
+
+/* Generate memory available property entry for PPC */
+void ofmem_arch_create_available_entry(phandle_t ph, ucell *availentry, phys_addr_t start, ucell size)
+{
+    int i = 0;
+
+    if (ph == s_phandle_memory) {
+        i += ofmem_arch_encode_physaddr(availentry, start);
+    } else {
+	availentry[i++] = start;
+    }
+    
+    availentry[i] = size;
+}
+
 /************************************************************************/
 /*	OF private allocations						*/
 /************************************************************************/
diff --git a/openbios-devel/arch/sparc32/lib.c b/openbios-devel/arch/sparc32/lib.c
index 72d3a87..90a070b 100644
--- a/openbios-devel/arch/sparc32/lib.c
+++ b/openbios-devel/arch/sparc32/lib.c
@@ -59,8 +59,6 @@ unsigned int va_shift;
 static unsigned long *context_table;
 static unsigned long *l1;
 
-static phandle_t s_phandle_memory = 0;
-static phandle_t s_phandle_mmu = 0;
 static ucell *mem_reg = 0;
 static ucell *mem_avail = 0;
 static ucell *virt_avail = 0;
diff --git a/openbios-devel/arch/sparc32/ofmem_sparc32.c b/openbios-devel/arch/sparc32/ofmem_sparc32.c
index 6815349..ba47913 100644
--- a/openbios-devel/arch/sparc32/ofmem_sparc32.c
+++ b/openbios-devel/arch/sparc32/ofmem_sparc32.c
@@ -124,6 +124,30 @@ void ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t)
 	transentry[2] = t->mode;
 }
 
+/* Return the size of a memory available entry given the phandle in cells */
+int ofmem_arch_get_available_entry_size(phandle_t ph)
+{
+	if (ph == s_phandle_memory) {
+		return 1 + ofmem_arch_get_physaddr_cellsize();
+	} else {
+		return 1 + 1;
+	}
+}
+
+/* Generate memory available property entry for Sparc32 */
+void ofmem_arch_create_available_entry(phandle_t ph, ucell *availentry, phys_addr_t start, ucell size)
+{
+	int i = 0;
+
+	if (ph == s_phandle_memory) {
+		i += ofmem_arch_encode_physaddr(availentry, start);
+	} else {
+		availentry[i++] = start;
+	}
+
+	availentry[i] = size;
+}
+
 /************************************************************************/
 /* misc                                                                 */
 /************************************************************************/
diff --git a/openbios-devel/arch/sparc64/ofmem_sparc64.c b/openbios-devel/arch/sparc64/ofmem_sparc64.c
index 1655978..d4caddc 100644
--- a/openbios-devel/arch/sparc64/ofmem_sparc64.c
+++ b/openbios-devel/arch/sparc64/ofmem_sparc64.c
@@ -110,6 +110,30 @@ void ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t)
 	transentry[2] = t->mode;
 }
 
+/* Return the size of a memory available entry given the phandle in cells */
+int ofmem_arch_get_available_entry_size(phandle_t ph)
+{
+	if (ph == s_phandle_memory) {
+		return 1 + ofmem_arch_get_physaddr_cellsize();
+	} else {
+		return 1 + 1;
+	}
+}
+
+/* Generate memory available property entry for Sparc64 */
+void ofmem_arch_create_available_entry(phandle_t ph, ucell *availentry, phys_addr_t start, ucell size)
+{
+	int i = 0;
+
+	if (ph == s_phandle_memory) {
+		i += ofmem_arch_encode_physaddr(availentry, start);
+	} else {
+		availentry[i++] = start;
+	}
+    
+	availentry[i] = size;
+}
+
 /************************************************************************/
 /* misc                                                                 */
 /************************************************************************/
diff --git a/openbios-devel/include/libopenbios/ofmem.h b/openbios-devel/include/libopenbios/ofmem.h
index 2269fd7..30f20d8 100644
--- a/openbios-devel/include/libopenbios/ofmem.h
+++ b/openbios-devel/include/libopenbios/ofmem.h
@@ -69,6 +69,8 @@ extern ucell		ofmem_arch_get_iomem_top(void);
 extern retain_t*	ofmem_arch_get_retained(void);
 extern int			ofmem_arch_get_physaddr_cellsize(void);
 extern int			ofmem_arch_encode_physaddr(ucell *p, phys_addr_t value);
+extern int		ofmem_arch_get_available_entry_size(phandle_t ph);
+extern void 		ofmem_arch_create_available_entry(phandle_t ph, ucell *availentry, phys_addr_t start, ucell size);
 extern int 		ofmem_arch_get_translation_entry_size(void);
 extern void 		ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t);
 extern ucell    	ofmem_arch_default_translation_mode( phys_addr_t phys );
@@ -120,6 +122,10 @@ extern void  ofmem_release_phys( phys_addr_t phys, ucell size );
 extern void  ofmem_release_virt( ucell virt, ucell size );
 extern phys_addr_t ofmem_translate( ucell virt, ucell *ret_mode );
 
+/* memory and virtual-memory nodes */
+extern phandle_t s_phandle_memory;
+extern phandle_t s_phandle_mmu;
+
 /* Currently the same for all architectures */
 #define PAGE_SHIFT   12
 
diff --git a/openbios-devel/libopenbios/ofmem_common.c b/openbios-devel/libopenbios/ofmem_common.c
index 7f6223b..6d0f417 100644
--- a/openbios-devel/libopenbios/ofmem_common.c
+++ b/openbios-devel/libopenbios/ofmem_common.c
@@ -222,8 +222,8 @@ ofmem_set_property( phandle_t ph, const char *name, const char *buf, int len )
 	fword("encode-property");
 }
 
-static phandle_t s_phandle_memory = 0;
-static phandle_t s_phandle_mmu = 0;
+phandle_t s_phandle_memory = 0;
+phandle_t s_phandle_mmu = 0;
 
 static void ofmem_update_mmu_translations( void )
 {
@@ -290,8 +290,7 @@ static void ofmem_update_memory_available( phandle_t ph, range_t *range,
 
 	/* inverse of phys_range list could take 2 or more additional cells for the tail
 	   For /memory, physical addresses may be wider than one ucell. */
-	prop_used = (ncells + 1) * sizeof(ucell) *
-		(((ph == s_phandle_memory) ? ofmem_arch_get_physaddr_cellsize() : 1) + 1);
+	prop_used = (ncells + 1) * sizeof(ucell) * ofmem_arch_get_available_entry_size(ph) + 1;
 
 	if (prop_used > *mem_prop_size) {
 
@@ -325,28 +324,16 @@ static void ofmem_update_memory_available( phandle_t ph, range_t *range,
 
 		size = r->start - start;
 		if (size) {
-			if (ph == s_phandle_memory) {
-				/* physical address for /memory */
-				ncells += ofmem_arch_encode_physaddr(&prop[ncells], start);
-			} else {
-				/* virtual address for MMU */
-				prop[ncells++] = start;
-			}
-			prop[ncells++] = size;
+			ofmem_arch_create_available_entry(ph, &prop[ncells], start, size);
+			ncells += ofmem_arch_get_available_entry_size(ph);
 		}
 		start = r->start + r->size;
 	}
 
 	/* tail */
 	if (start < top_address) {
-		if (ph == s_phandle_memory) {
-			/* physical address for /memory */
-			ncells += ofmem_arch_encode_physaddr(&prop[ncells], start);
-		} else {
-			/* virtual address for MMU */
-			prop[ncells++] = start;
-		}
-		prop[ncells++] = top_address - start;
+		ofmem_arch_create_available_entry(ph, &prop[ncells], start, top_address - start);
+		ncells += ofmem_arch_get_available_entry_size(ph);
 	}
 
 	ofmem_set_property(ph, "available",
-- 
1.7.2.3




More information about the OpenBIOS mailing list