[OpenBIOS] [commit] r994 - trunk/openbios-devel/libopenbios

repository service svn at openbios.org
Thu Dec 30 14:56:21 CET 2010


Author: mcayland
Date: Thu Dec 30 14:56:20 2010
New Revision: 994
URL: http://tracker.coreboot.org/trac/openbios/changeset/994

Log:
Alter ofmem_posix_memalign() so that the resulting pointer is aligned for both physical and virtual addresses.

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>

Modified:
   trunk/openbios-devel/libopenbios/ofmem_common.c

Modified: trunk/openbios-devel/libopenbios/ofmem_common.c
==============================================================================
--- trunk/openbios-devel/libopenbios/ofmem_common.c	Thu Dec 30 14:56:17 2010	(r993)
+++ trunk/openbios-devel/libopenbios/ofmem_common.c	Thu Dec 30 14:56:20 2010	(r994)
@@ -33,9 +33,9 @@
     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 @@
 	alloc_desc_t *d, **pp;
 	void *ret;
 	ucell top;
+	phys_addr_t pa;
 
 	if( !size )
 		return ENOMEM;
@@ -117,7 +118,11 @@
 
 	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;



More information about the OpenBIOS mailing list