[OpenBIOS] [PATCH 01/16] Alter ofmem_posix_memalign() so that the resulting pointer is aligned for both physical and virtual addresses.

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


From: mcayland <mcayland at f158a5a8-5612-0410-a976-696ce0be7e32>

Some uses of ofmem_posix_memalign() need to ensure that the alignment requirement is for physical as well as virtual addresses,
e.g. for MMU page tables.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>

git-svn-id: svn://openbios.org/openbios/trunk@994 f158a5a8-5612-0410-a976-696ce0be7e32
---
 openbios-devel/libopenbios/ofmem_common.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/openbios-devel/libopenbios/ofmem_common.c b/openbios-devel/libopenbios/ofmem_common.c
index 8a24a7f..48b0b17 100644
--- a/openbios-devel/libopenbios/ofmem_common.c
+++ b/openbios-devel/libopenbios/ofmem_common.c
@@ -33,9 +33,9 @@ static inline size_t align_size(size_t x, size_t a)
     return (x + a - 1) & ~(a - 1);
 }
 
-static inline void * align_ptr(uintptr_t x, size_t a)
+static inline phys_addr_t align_ptr(uintptr_t x, size_t a)
 {
-    return (void *)((x + a - 1) & ~(a - 1));
+    return (x + a - 1) & ~(a - 1);
 }
 
 static ucell get_ram_size( void )
@@ -92,6 +92,7 @@ int ofmem_posix_memalign( void **memptr, size_t alignment, size_t size )
 	alloc_desc_t *d, **pp;
 	void *ret;
 	ucell top;
+	phys_addr_t pa;
 
 	if( !size )
 		return ENOMEM;
@@ -117,7 +118,11 @@ int ofmem_posix_memalign( void **memptr, size_t alignment, size_t size )
 
 	top = ofmem_arch_get_heap_top();
 
-	ret = align_ptr((uintptr_t)ofmem->next_malloc + sizeof(alloc_desc_t), alignment);
+	/* Alignment should be on physical not virtual address */
+	pa = va2pa((uintptr_t)ofmem->next_malloc + sizeof(alloc_desc_t));
+	pa = align_ptr(pa, alignment);
+	ret = (void *)pa2va(pa);
+
 	if( pointer2cell(ret) + size > top ) {
 		printk("out of malloc memory (%x)!\n", size );
 		return ENOMEM;
-- 
1.7.2.3




More information about the OpenBIOS mailing list