Author: mcayland Date: Sun Jan 2 01:06:40 2011 New Revision: 1004 URL: http://tracker.coreboot.org/trac/openbios/changeset/1004
Log: Switch SPARC32 over to use OFMEM's malloc()/free() internally rather than using it's own implementation.
Also juggle the memory to take into account that the allocations are coming from OFMEM, and remove posix_memalign2() since it is no longer required.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk Tested-by: Blue Swirl blauwirbel@gmail.com Reviewed-by: Blue Swirl blauwirbel@gmail.com
Modified: trunk/openbios-devel/arch/sparc32/ldscript trunk/openbios-devel/arch/sparc32/lib.c trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c
Modified: trunk/openbios-devel/arch/sparc32/ldscript ============================================================================== --- trunk/openbios-devel/arch/sparc32/ldscript Sun Jan 2 01:06:34 2011 (r1003) +++ trunk/openbios-devel/arch/sparc32/ldscript Sun Jan 2 01:06:40 2011 (r1004) @@ -12,8 +12,7 @@
/* 16KB stack */ STACK_SIZE = 16384; -/* 256k general alloc + 256k Forth dictionary + 16k Forth memory */ -VMEM_SIZE = (256 + 256 + 16) * 1024; +VMEM_SIZE = 128 * 1024; IOMEM_SIZE = 256 * 1024 + 768 * 1024;
SECTIONS
Modified: trunk/openbios-devel/arch/sparc32/lib.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/lib.c Sun Jan 2 01:06:34 2011 (r1003) +++ trunk/openbios-devel/arch/sparc32/lib.c Sun Jan 2 01:06:40 2011 (r1004) @@ -75,18 +75,6 @@ struct linux_mlist_v0 *ptmap; struct linux_mlist_v0 *ptavail;
-static struct { - char *next_malloc; - int left; - alloc_desc_t *mfree; /* list of free malloc blocks */ - - range_t *phys_range; - range_t *virt_range; - - translation_t *trans; /* this is really a translation_t */ -} ofmem; -#define ALLOC_BLOCK (64 * 1024) - /* Private functions for mapping between physical/virtual addresses */ phys_addr_t va2pa(unsigned long va) @@ -108,112 +96,22 @@ return pa; }
-// XXX should be posix_memalign -static int -posix_memalign2(void **memptr, size_t alignment, size_t size) -{ - alloc_desc_t *d, **pp; - char *ret; - - if( !size ) - return -1; - - size = (size + (alignment - 1)) & ~(alignment - 1); - size += sizeof(alloc_desc_t); - - /* look in the freelist */ - for( pp=&ofmem.mfree; *pp && (**pp).size < size; pp = &(**pp).next ) - ; - - /* waste at most 4K by taking an entry from the freelist */ - if( *pp && (**pp).size < size + 0x1000 ) { - ret = (char*)*pp + sizeof(alloc_desc_t); - memset( ret, 0, (**pp).size - sizeof(alloc_desc_t) ); - *pp = (**pp).next; - *memptr = ret; - return 0; - } - - if( !ofmem.next_malloc || ofmem.left < size) { - unsigned long alloc_size = ALLOC_BLOCK; - if (size > ALLOC_BLOCK) - alloc_size = size; - // Recover possible leftover - if ((size_t)ofmem.left > sizeof(alloc_desc_t) + 4) { - alloc_desc_t *d_leftover; - - d_leftover = (alloc_desc_t*)ofmem.next_malloc; - d_leftover->size = ofmem.left - sizeof(alloc_desc_t); - free((void *)((unsigned long)d_leftover + - sizeof(alloc_desc_t))); - } - - ofmem.next_malloc = mem_alloc(&cmem, alloc_size, 8); - ofmem.left = alloc_size; - } - - if( ofmem.left < size) { - printk("out of malloc memory (%x)!\n", size ); - return -1; - } - d = (alloc_desc_t*) ofmem.next_malloc; - ofmem.next_malloc += size; - ofmem.left -= size; - - d->next = NULL; - d->size = size; - - ret = (char*)d + sizeof(alloc_desc_t); - memset( ret, 0, size - sizeof(alloc_desc_t) ); - *memptr = ret; - return 0; -} - -void *malloc(int size) -{ - int ret; - void *mem; - - ret = posix_memalign2(&mem, 8, size); - if (ret != 0) - return NULL; - return mem; -} - -void free(void *ptr) +void * +malloc(int size) { - alloc_desc_t **pp, *d; - - /* it is legal to free NULL pointers (size zero allocations) */ - if( !ptr ) - return; - - d = (alloc_desc_t*)((unsigned long)ptr - sizeof(alloc_desc_t)); - d->next = ofmem.mfree; - - /* insert in the (sorted) freelist */ - for( pp=&ofmem.mfree; *pp && (**pp).size < d->size ; pp = &(**pp).next ) - ; - d->next = *pp; - *pp = d; + return ofmem_malloc(size); }
void * realloc( void *ptr, size_t size ) { - alloc_desc_t *d = (alloc_desc_t*)((unsigned long)ptr - sizeof(alloc_desc_t)); - char *p; + return ofmem_realloc(ptr, size); +}
- if( !ptr ) - return malloc( size ); - if( !size ) { - free( ptr ); - return NULL; - } - p = malloc( size ); - memcpy( p, ptr, MIN(d->size - sizeof(alloc_desc_t),size) ); - free( ptr ); - return p; +void +free(void *ptr) +{ + ofmem_free(ptr); }
/*
Modified: trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c Sun Jan 2 01:06:34 2011 (r1003) +++ trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c Sun Jan 2 01:06:40 2011 (r1004) @@ -21,7 +21,7 @@
#define OF_MALLOC_BASE ((char*)OFMEM + ALIGN_SIZE(sizeof(ofmem_t), 8))
-#define MEMSIZE (256 * 1024) +#define MEMSIZE (512 * 1024) static union { char memory[MEMSIZE]; ofmem_t ofmem;