Hi!
This patch series moves OF memory manager code to separate module. New OFMEM module is used by sparc64 and all ppc configurations.
Since ppc briq/mol/pearpc are not buildable for years I used local build hack to verify this change does not make those even worse.
Boot-tested on sparc64 and ppc/qemu.
Signed-off-by: igor.v.kovalenko@gmail.com
extern void nvconf_init( void ); -extern void nvram_init( char *path ); +extern void nvram_init( const char *path ); extern void update_nvram( void );
#endif /* _H_NVRAM */ Index: openbios-devel/modules/nvram.c =================================================================== --- openbios-devel.orig/modules/nvram.c +++ openbios-devel/modules/nvram.c @@ -297,7 +297,7 @@ NODE_METHODS( nvram ) = {
void -nvram_init( char *path ) +nvram_init( const char *path ) { nvconf_init();
#define BIT(n) (1U<<(31-(n)))
+/* called from assembly */ +extern void dsi_exception( void ); +extern void isi_exception( void ); +extern void setup_mmu( ulong code_base ); + #define FREE_BASE 0x00004000 #define IO_BASE 0x80000000 #define OFMEM ((ofmem_t*)FREE_BASE) Index: openbios-devel/include/ofmem.h =================================================================== --- openbios-devel.orig/include/ofmem.h +++ openbios-devel/include/ofmem.h @@ -35,9 +35,6 @@ extern ucell ofmem_translate( ucell vir ulong get_ram_size( void ); ulong get_ram_top( void ); ulong get_ram_bottom( void ); -void dsi_exception( void ); -void isi_exception( void ); -void setup_mmu( ulong ramsize ); void ofmem_register( phandle_t ph ); #elif defined(CONFIG_SPARC32) #define PAGE_SHIFT 12 Index: openbios-devel/arch/ppc/ofmem.c =================================================================== --- openbios-devel.orig/arch/ppc/ofmem.c +++ openbios-devel/arch/ppc/ofmem.c @@ -35,9 +35,9 @@ #define BIT(n) (1U<<(31-(n)))
/* called from assembly */ -extern void dsi_exception( void ); -extern void isi_exception( void ); -extern void setup_mmu( ulong code_base, ulong code_size, ulong ramsize ); +extern void dsi_exception( void ); +extern void isi_exception( void ); +extern void setup_mmu( ulong code_base, ulong code_size, ulong ramsize );
/**************************************************************** * Memory usage (before of_quiesce is called)
On Sun, Aug 2, 2009 at 11:54 AM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
#define BIT(n) Â Â Â Â (1U<<(31-(n)))
+/* called from assembly */ +extern void dsi_exception( void ); +extern void isi_exception( void ); +extern void setup_mmu( ulong code_base );
#define FREE_BASE        0x00004000  #define IO_BASE             0x80000000  #define OFMEM          ((ofmem_t*)FREE_BASE) Index: openbios-devel/include/ofmem.h =================================================================== --- openbios-devel.orig/include/ofmem.h +++ openbios-devel/include/ofmem.h @@ -35,9 +35,6 @@ extern ucell  ofmem_translate( ucell vir  ulong get_ram_size( void );  ulong get_ram_top( void );  ulong get_ram_bottom( void ); -void dsi_exception( void ); -void isi_exception( void ); -void setup_mmu( ulong ramsize );  void ofmem_register( phandle_t ph );  #elif defined(CONFIG_SPARC32)  #define PAGE_SHIFT  12 Index: openbios-devel/arch/ppc/ofmem.c =================================================================== --- openbios-devel.orig/arch/ppc/ofmem.c +++ openbios-devel/arch/ppc/ofmem.c @@ -35,9 +35,9 @@  #define BIT(n)     (1U<<(31-(n)))
/* called from assembly */ -extern void   dsi_exception( void ); -extern void   isi_exception( void ); -extern void   setup_mmu( ulong code_base, ulong code_size, ulong ramsize ); +extern void dsi_exception( void ); +extern void isi_exception( void ); +extern void setup_mmu( ulong code_base, ulong code_size, ulong ramsize );
Can't you use the .h file touched by the first hunk so that these could be removed?
On Sun, Aug 2, 2009 at 1:32 PM, Blue Swirlblauwirbel@gmail.com wrote:
On Sun, Aug 2, 2009 at 11:54 AM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
#define BIT(n) Â Â Â Â (1U<<(31-(n)))
+/* called from assembly */ +extern void dsi_exception( void ); +extern void isi_exception( void ); +extern void setup_mmu( ulong code_base );
#define FREE_BASE        0x00004000  #define IO_BASE             0x80000000  #define OFMEM          ((ofmem_t*)FREE_BASE) Index: openbios-devel/include/ofmem.h =================================================================== --- openbios-devel.orig/include/ofmem.h +++ openbios-devel/include/ofmem.h @@ -35,9 +35,6 @@ extern ucell  ofmem_translate( ucell vir  ulong get_ram_size( void );  ulong get_ram_top( void );  ulong get_ram_bottom( void ); -void dsi_exception( void ); -void isi_exception( void ); -void setup_mmu( ulong ramsize );  void ofmem_register( phandle_t ph );  #elif defined(CONFIG_SPARC32)  #define PAGE_SHIFT  12 Index: openbios-devel/arch/ppc/ofmem.c =================================================================== --- openbios-devel.orig/arch/ppc/ofmem.c +++ openbios-devel/arch/ppc/ofmem.c @@ -35,9 +35,9 @@  #define BIT(n)     (1U<<(31-(n)))
/* called from assembly */ -extern void   dsi_exception( void ); -extern void   isi_exception( void ); -extern void   setup_mmu( ulong code_base, ulong code_size, ulong ramsize ); +extern void dsi_exception( void ); +extern void isi_exception( void ); +extern void setup_mmu( ulong code_base, ulong code_size, ulong ramsize );
Can't you use the .h file touched by the first hunk so that these could be removed?
These are ppc arch-private functions, so no. I cleaned up last hunk since that was whitespace only.
+#define FMT_cell "%d" +#define FMT_ucell "%u" +#define FMT_ucellx "%08x" +#define FMT_ucellX "%08X" + #define bitspercell (sizeof(cell)<<3) #define bitsperdcell (sizeof(dcell)<<3)
Index: openbios-devel/include/sparc64/types.h =================================================================== --- openbios-devel.orig/include/sparc64/types.h +++ openbios-devel/include/sparc64/types.h @@ -32,9 +32,10 @@ typedef long long int64_t; typedef int64_t cell; typedef uint64_t ucell;
-#define FMT_cell "%lld" +#define FMT_cell "%lld" #define FMT_ucell "%llu" #define FMT_ucellx "%016llx" +#define FMT_ucellX "%016llX"
#ifdef NEED_FAKE_INT128_T typedef struct {
while( s < size ) @@ -166,10 +166,10 @@ DECLARE_NODE( mmu_ciface, 0, 0, "+/openp static void mem_claim( void ) { - int align = POP(); - int size = POP(); - int phys = POP(); - int ret = ofmem_claim_phys( phys, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_phys( phys, size, align );
if( ret == -1 ) { printk("MEM: claim failure\n"); @@ -190,10 +190,10 @@ mem_release( void ) static void mmu_claim( void ) { - int align = POP(); - int size = POP(); - int phys = POP(); - int ret = ofmem_claim_virt( phys, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_virt( phys, size, align );
if( ret == -1 ) { printk("MMU: CLAIM failure\n"); @@ -214,11 +214,11 @@ mmu_release( void ) static void mmu_map( void ) { - int mode = POP(); - int size = POP(); - int virt = POP(); - int phys = POP(); - int ret; + ucell mode = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell phys = POP(); + ucell ret;
/* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */ ret = ofmem_map( phys, virt, size, mode ); @@ -258,10 +258,10 @@ mmu_translate( void ) static void ciface_claim( void ) { - int align = POP(); - int size = POP(); - int virt = POP(); - int ret = ofmem_claim( virt, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell ret = ofmem_claim( virt, size, align );
/* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ PUSH( ret ); Index: openbios-devel/arch/ppc/qemu/ofmem.c =================================================================== --- openbios-devel.orig/arch/ppc/qemu/ofmem.c +++ openbios-devel/arch/ppc/qemu/ofmem.c @@ -315,7 +315,7 @@ join_ranges( range_t **rr ) }
static void -fill_range( ulong ea, ucell size, range_t **rr ) +fill_range( ucell ea, ucell size, range_t **rr ) { add_entry_( ea, size, rr ); join_ranges( rr ); @@ -328,7 +328,7 @@ find_area( ucell align, ucell size, rang range_t *r2;
if( (align & (align-1)) ) { - printk("bad alignment %d\n", align); + printk("bad alignment " FMT_ucell "\n", align); align = 0x1000; } if( !align ) @@ -383,8 +383,8 @@ ofmem_claim_phys_( ucell phys, ucell siz return phys; } phys = find_area( align, size, ofmem->phys_range, min, max, reverse ); - if( phys == (ulong)-1 ) { - printk("ofmem->claim_phys - out of space\n"); + if( phys == (ucell)-1 ) { + printk("ofmem_claim_phys - out of space\n"); return -1; } add_entry( phys, size, &ofmem->phys_range ); @@ -413,7 +413,7 @@ ofmem_claim_virt_( ucell virt, ucell siz }
virt = find_area( align, size, ofmem->virt_range, min, max, reverse ); - if( virt == (ulong)-1 ) { + if( virt == (ucell)-1 ) { printk("ofmem_claim_virt - out of space\n"); return -1; } @@ -454,7 +454,7 @@ ofmem_claim( ucell addr, ucell size, uce align = 0x1000; phys = ofmem_claim_phys_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); virt = ofmem_claim_virt_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); - if( phys == (ulong)-1 || virt == (ulong)-1 ) { + if( phys == (ucell)-1 || virt == (ucell)-1 ) { printk("ofmem_claim failed\n"); return -1; } @@ -481,7 +481,7 @@ ofmem_claim( ucell addr, ucell size, uce /************************************************************************/
static void -split_trans( ulong virt ) +split_trans( ucell virt ) { ofmem_t *ofmem = OFMEM; translation_t *t, *t2; @@ -513,7 +513,7 @@ map_page_range( ucell virt, ucell phys, for( t=ofmem->trans; t; ) { if( virt == t->virt || (virt < t->virt && virt + size > t->virt )) { if( t->phys + virt - t->virt != phys ) { - printk("mapping altered (ea %08x)\n", t->virt ); + printk("mapping altered (ea " FMT_ucellx ")\n", t->virt ); } else if( t->mode != mode ){ printk("mapping mode altered\n"); }
typedef struct alloc_desc { struct alloc_desc *next; - int size; /* size (including) this struct */ + ucell size; /* size (including) this struct */ } alloc_desc_t;
typedef struct mem_range { struct mem_range *next; - ulong start; - ulong size; + ucell start; + ucell size; } range_t;
typedef struct trans { struct trans *next; - ulong virt; /* chain is sorted by virt */ - ulong size; - ulong phys; - int mode; + ucell virt; /* chain is sorted by virt */ + ucell size; + ucell phys; + ucell mode; } translation_t;
static struct { @@ -227,8 +227,8 @@ print_trans( void ) /* misc */ /************************************************************************/
-static inline int -def_memmode( ulong phys ) +static inline ucell +def_memmode( ucell phys ) { /* XXX: Guard bit not set as it should! */ if( phys < 0x80000000 || phys >= 0xffc00000 ) @@ -242,7 +242,7 @@ def_memmode( ulong phys ) /************************************************************************/
static int -is_free( ulong ea, ulong size, range_t *r ) +is_free( ucell ea, ucell size, range_t *r ) { if( size == 0 ) return 1; @@ -256,7 +256,7 @@ is_free( ulong ea, ulong size, range_t * }
static void -add_entry_( ulong ea, ulong size, range_t **r ) +add_entry_( ucell ea, ucell size, range_t **r ) { range_t *nr;
@@ -270,7 +270,7 @@ add_entry_( ulong ea, ulong size, range_ }
static int -add_entry( ulong ea, ulong size, range_t **r ) +add_entry( ucell ea, ucell size, range_t **r ) { if( !is_free( ea, size, *r ) ) { printk("add_entry: range not free!\n"); @@ -301,20 +301,20 @@ join_ranges( range_t **rr ) }
static void -fill_range( ulong ea, int size, range_t **rr ) +fill_range( ucell ea, ucell size, range_t **rr ) { add_entry_( ea, size, rr ); join_ranges( rr ); }
-static ulong -find_area( ulong align, ulong size, range_t *r, ulong min, ulong max, int reverse ) +static ucell +find_area( ucell align, ucell size, range_t *r, ucell min, ucell max, int reverse ) { - ulong base = min; + ucell base = min; range_t *r2;
if( (align & (align-1)) ) { - printk("bad alignment %ld\n", align); + printk("bad alignment " FMT_ucell "\n", align); align = 0x1000; } if( !align ) @@ -353,11 +353,11 @@ find_area( ulong align, ulong size, rang base = r2->start - size; } } - return (ulong)-1; + return (ucell)-1; }
-static ulong -ofmem_claim_phys_( ulong phys, ulong size, ulong align, int min, int max, int reverse ) +static ucell +ofmem_claim_phys_( ucell phys, ucell size, ucell align, ucell min, ucell max, int reverse ) { if( !align ) { if( !is_free( phys, size, ofmem.phys_range ) ) { @@ -368,7 +368,7 @@ ofmem_claim_phys_( ulong phys, ulong siz return phys; } phys = find_area( align, size, ofmem.phys_range, min, max, reverse ); - if( phys == (ulong)-1 ) { + if( phys == (ucell)-1 ) { printk("ofmem_claim_phys - out of space\n"); return -1; } @@ -377,15 +377,15 @@ ofmem_claim_phys_( ulong phys, ulong siz }
/* if align != 0, phys is ignored. Returns -1 on error */ -ulong -ofmem_claim_phys( ulong phys, ulong size, ulong align ) +ucell +ofmem_claim_phys( ucell phys, ucell size, ucell align ) { /* printk("+ ofmem_claim phys %08lx %lx %ld\n", phys, size, align ); */ return ofmem_claim_phys_( phys, size, align, 0, RAMSIZE, 0 ); }
-static ulong -ofmem_claim_virt_( ulong virt, ulong size, ulong align, int min, int max, int reverse ) +static ucell +ofmem_claim_virt_( ucell virt, ucell size, ucell align, ucell min, ucell max, int reverse ) { if( !align ) { if( !is_free( virt, size, ofmem.virt_range ) ) { @@ -397,7 +397,7 @@ ofmem_claim_virt_( ulong virt, ulong siz }
virt = find_area( align, size, ofmem.virt_range, min, max, reverse ); - if( virt == (ulong)-1 ) { + if( virt == (ucell)-1 ) { printk("ofmem_claim_virt - out of space\n"); return -1; } @@ -405,8 +405,8 @@ ofmem_claim_virt_( ulong virt, ulong siz return virt; }
-ulong -ofmem_claim_virt( ulong virt, ulong size, ulong align ) +ucell +ofmem_claim_virt( ucell virt, ucell size, ucell align ) { /* printk("+ ofmem_claim virt %08lx %lx %ld\n", virt, size, align ); */ return ofmem_claim_virt_( virt, size, align, RAMSIZE, 0x80000000, 0 ); @@ -414,11 +414,11 @@ ofmem_claim_virt( ulong virt, ulong size
/* allocate both physical and virtual space and add a translation */ -ulong -ofmem_claim( ulong addr, ulong size, ulong align ) +ucell +ofmem_claim( ucell addr, ucell size, ucell align ) { - ulong virt, phys; - ulong offs = addr & 0xfff; + ucell virt, phys; + ucell offs = addr & 0xfff;
/* printk("+ ofmem_claim %08lx %lx %ld\n", addr, size, align ); */ virt = phys = 0; @@ -436,7 +436,7 @@ ofmem_claim( ulong addr, ulong size, ulo align = 0x1000; phys = ofmem_claim_phys_( addr, size, align, 0, RAMSIZE, 1 /* reverse */ ); virt = ofmem_claim_virt_( addr, size, align, 0, RAMSIZE, 1 /* reverse */ ); - if( phys == (ulong)-1 || virt == (ulong)-1 ) { + if( phys == (ucell)-1 || virt == (ucell)-1 ) { printk("ofmem_claim failed\n"); return -1; } @@ -463,7 +463,7 @@ ofmem_claim( ulong addr, ulong size, ulo /************************************************************************/
static void -split_trans( ulong virt ) +split_trans( ucell virt ) { translation_t *t, *t2;
@@ -482,7 +482,7 @@ split_trans( ulong virt ) }
static int -map_page_range( ulong virt, ulong phys, ulong size, int mode ) +map_page_range( ucell virt, ucell phys, ucell size, ucell mode ) { translation_t *t, **tt;
@@ -493,7 +493,7 @@ map_page_range( ulong virt, ulong phys, for( t=ofmem.trans; t; ) { if( virt == t->virt || (virt < t->virt && virt + size > t->virt )) { if( t->phys + virt - t->virt != phys ) { - printk("mapping altered (ea %08lx)\n", t->virt ); + printk("mapping altered (ea " FMT_ucellx ")\n", t->virt ); } else if( t->mode != mode ){ printk("mapping mode altered\n"); } @@ -521,13 +521,15 @@ map_page_range( ulong virt, ulong phys, }
int -ofmem_map( ulong phys, ulong virt, ulong size, int mode ) +ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ) { /* printk("+ofmem_map: %08lX --> %08lX (size %08lX, mode 0x%02X)\n", virt, phys, size, mode ); */
if( (phys & 0xfff) || (virt & 0xfff) || (size & 0xfff) ) { - printk("ofmem_map: Bad parameters (%08lX %08lX %08lX)\n", phys, virt, size ); + printk("ofmem_map: Bad parameters (" FMT_ucellX " " FMT_ucellX " " + FMT_ucellX ")\n", + phys, virt, size ); phys &= ~0xfff; virt &= ~0xfff; size = (size + 0xfff) & ~0xfff; @@ -544,13 +546,13 @@ ofmem_map( ulong phys, ulong virt, ulong }
/* virtual -> physical. */ -ulong -ofmem_translate( ulong virt, ulong *mode ) +ucell +ofmem_translate( ucell virt, ucell *mode ) { translation_t *t;
for( t=ofmem.trans; t && t->virt <= virt ; t=t->next ) { - ulong offs; + ucell offs; if( t->virt + t->size - 1 < virt ) continue; offs = virt - t->virt; @@ -565,7 +567,7 @@ ofmem_translate( ulong virt, ulong *mode
/* release memory allocated by ofmem_claim */ void -ofmem_release( ulong virt, ulong size ) +ofmem_release( ucell virt, ucell size ) { /* printk("ofmem_release unimplemented (%08lx, %08lx)\n", virt, size ); */ } @@ -575,17 +577,17 @@ ofmem_release( ulong virt, ulong size ) /* page fault handler */ /************************************************************************/
-static ulong -ea_to_phys( ulong ea, int *mode ) +static ucell +ea_to_phys( ucell ea, ucell *mode ) { - ulong phys; + ucell phys;
/* hardcode our translation needs */ if( ea >= OF_CODE_START && ea < FREE_BASE_2 ) { *mode = def_memmode( ea ); return ea; } - if( (phys=ofmem_translate(ea, (ulong*)mode)) == (ulong)-1 ) { + if( (phys=ofmem_translate(ea, mode)) == (ucell)-1 ) { #ifdef I_WANT_MOLISMS if( ea != 0x80816c00 ) printk("ea_to_phys: no translation for %08lx, using 1-1\n", ea ); @@ -605,7 +607,7 @@ ea_to_phys( ulong ea, int *mode ) }
static void -hash_page( ulong ea, ulong phys, int mode ) +hash_page( ucell ea, ucell phys, ucell mode ) { static int next_grab_slot=0; ulong *upte, cmp, hash1; @@ -648,7 +650,7 @@ void dsi_exception( void ) { ulong dar, dsisr; - int mode; + ucell mode;
asm volatile("mfdar %0" : "=r" (dar) : ); asm volatile("mfdsisr %0" : "=r" (dsisr) : ); @@ -660,7 +662,7 @@ void isi_exception( void ) { ulong nip, srr1; - int mode; + ucell mode;
asm volatile("mfsrr0 %0" : "=r" (nip) : ); asm volatile("mfsrr1 %0" : "=r" (srr1) : );
- if( ret == -1 ) { + if( ret == (ucell)-1 ) { printk("MEM: claim failure\n"); throw( -13 ); return; @@ -211,10 +211,10 @@ mem_release( void ) static void mmu_claim( void ) { - int align = POP(); - int size = POP(); - int phys = POP(); - int ret = ofmem_claim_virt( phys, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_virt( phys, size, align );
if( ret == -1 ) { printk("MMU: CLAIM failure\n"); @@ -235,11 +235,11 @@ mmu_release( void ) static void mmu_map( void ) { - int mode = POP(); - int size = POP(); - int virt = POP(); - int phys = POP(); - int ret; + ucell mode = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell phys = POP(); + ucell ret;
/* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */ ret = ofmem_map( phys, virt, size, mode ); @@ -262,15 +262,15 @@ mmu_unmap( void ) static void mmu_translate( void ) { - ulong mode; - int virt = POP(); - int phys = ofmem_translate( virt, &mode ); + ucell mode; + ucell virt = POP(); + ucell phys = ofmem_translate( virt, &mode );
if( phys == -1 ) { PUSH( 0 ); } else { PUSH( phys ); - PUSH( (int)mode ); + PUSH( mode ); PUSH( -1 ); } } @@ -279,10 +279,10 @@ mmu_translate( void ) static void ciface_claim( void ) { - int align = POP(); - int size = POP(); - int virt = POP(); - int ret = ofmem_claim( virt, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell ret = ofmem_claim( virt, size, align );
/* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ PUSH( ret ); Index: openbios-devel/arch/ppc/briq/methods.c =================================================================== --- openbios-devel.orig/arch/ppc/briq/methods.c +++ openbios-devel/arch/ppc/briq/methods.c @@ -260,15 +260,15 @@ mmu_unmap( void ) static void mmu_translate( void ) { - ulong mode; - int virt = POP(); - int phys = ofmem_translate( virt, &mode ); + ucell mode; + ucell virt = POP(); + ucell phys = ofmem_translate( virt, &mode );
if( phys == -1 ) { PUSH( 0 ); } else { PUSH( phys ); - PUSH( (int)mode ); + PUSH( mode ); PUSH( -1 ); } } Index: openbios-devel/arch/ppc/mol/methods.c =================================================================== --- openbios-devel.orig/arch/ppc/mol/methods.c +++ openbios-devel/arch/ppc/mol/methods.c @@ -323,10 +323,10 @@ DECLARE_NODE( mmu_ciface, 0, 0, "/packag static void mem_claim( void ) { - int align = POP(); - int size = POP(); - int phys = POP(); - int ret = ofmem_claim_phys( phys, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_phys( phys, size, align );
if( ret == -1 ) { printk("MEM: claim failure\n"); @@ -347,10 +347,10 @@ mem_release( void ) static void mmu_claim( void ) { - int align = POP(); - int size = POP(); - int phys = POP(); - int ret = ofmem_claim_virt( phys, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_virt( phys, size, align );
if( ret == -1 ) { printk("MMU: CLAIM failure\n"); @@ -371,11 +371,11 @@ mmu_release( void ) static void mmu_map( void ) { - int mode = POP(); - int size = POP(); - int virt = POP(); - int phys = POP(); - int ret; + ucell mode = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell phys = POP(); + ucell ret;
/* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */ ret = ofmem_map( phys, virt, size, mode ); @@ -398,15 +398,15 @@ mmu_unmap( void ) static void mmu_translate( void ) { - ulong mode; - int virt = POP(); - int phys = ofmem_translate( virt, &mode ); + ucell mode; + ucell virt = POP(); + ucell phys = ofmem_translate( virt, &mode );
if( phys == -1 ) { PUSH( 0 ); } else { PUSH( phys ); - PUSH( (int)mode ); + PUSH( mode ); PUSH( -1 ); } } @@ -415,10 +415,10 @@ mmu_translate( void ) static void ciface_claim( void ) { - int align = POP(); - int size = POP(); - int virt = POP(); - int ret = ofmem_claim( virt, size, align ); + ucell align = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell ret = ofmem_claim( virt, size, align );
/* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ PUSH( ret );
-static struct { +typedef struct { char *next_malloc; alloc_desc_t *mfree; /* list of free malloc blocks */
@@ -96,8 +96,30 @@ static struct { range_t *virt_range;
translation_t *trans; /* this is really a translation_t */ -} ofmem; +} ofmem_t;
+static ofmem_t s_ofmem; + +#define IO_BASE 0x80000000 +#define OFMEM (&s_ofmem) + +static inline ulong +get_hash_base( void ) +{ + return HASH_BASE; +} + +static inline ulong +get_hash_size( void ) +{ + return HASH_SIZE; +} + +ulong +get_ram_size( void ) +{ + return RAMSIZE; +}
/************************************************************************/ /* OF private allocations */ @@ -106,21 +128,23 @@ static struct { void * malloc( int size ) { + ofmem_t *ofmem = OFMEM; alloc_desc_t *d, **pp; char *ret; + ulong top;
if( !size ) return NULL;
- if( !ofmem.next_malloc ) - ofmem.next_malloc = (char*)OF_MALLOC_BASE; + if( !ofmem->next_malloc ) + ofmem->next_malloc = (char*)OF_MALLOC_BASE;
if( size & 3 ) size += 4 - (size & 3); size += sizeof(alloc_desc_t);
/* look in the freelist */ - for( pp=&ofmem.mfree; *pp && (**pp).size < size; pp = &(**pp).next ) + for( pp=&ofmem->mfree; *pp && (**pp).size < size; pp = &(**pp).next ) ;
/* waste at most 4K by taking an entry from the freelist */ @@ -131,24 +155,28 @@ malloc( int size ) return ret; }
- if( (ulong)ofmem.next_malloc + size > HASH_BASE ) { + top = HASH_BASE; + if( (ulong)ofmem->next_malloc + size > top ) { printk("out of malloc memory (%x)!\n", size ); return NULL; } - d = (alloc_desc_t*) ofmem.next_malloc; - ofmem.next_malloc += size; + + d = (alloc_desc_t*) ofmem->next_malloc; + ofmem->next_malloc += size;
d->next = NULL; d->size = size;
ret = (char*)d + sizeof(alloc_desc_t); memset( ret, 0, size - sizeof(alloc_desc_t) ); + return ret; }
void free( void *ptr ) { + ofmem_t *ofmem = OFMEM; alloc_desc_t **pp, *d;
/* it is legal to free NULL pointers (size zero allocations) */ @@ -156,10 +184,10 @@ free( void *ptr ) return;
d = (alloc_desc_t*)((char *)ptr - sizeof(alloc_desc_t)); - d->next = ofmem.mfree; + d->next = ofmem->mfree;
/* insert in the (sorted) freelist */ - for( pp=&ofmem.mfree; *pp && (**pp).size < d->size ; pp = &(**pp).next ) + for( pp=&ofmem->mfree; *pp && (**pp).size < d->size ; pp = &(**pp).next ) ; d->next = *pp; *pp = d; @@ -231,7 +259,7 @@ static inline ucell def_memmode( ucell phys ) { /* XXX: Guard bit not set as it should! */ - if( phys < 0x80000000 || phys >= 0xffc00000 ) + if( phys < IO_BASE || phys >= 0xffc00000 ) return 0x02; /*0xa*/ /* wim GxPp */ return 0x6a; /* WIm GxPp, I/O */ } @@ -359,20 +387,21 @@ find_area( ucell align, ucell size, rang static ucell ofmem_claim_phys_( ucell phys, ucell size, ucell align, ucell min, ucell max, int reverse ) { + ofmem_t *ofmem = OFMEM; if( !align ) { - if( !is_free( phys, size, ofmem.phys_range ) ) { + if( !is_free( phys, size, ofmem->phys_range ) ) { printk("Non-free physical memory claimed!\n"); return -1; } - add_entry( phys, size, &ofmem.phys_range ); + add_entry( phys, size, &ofmem->phys_range ); return phys; } - phys = find_area( align, size, ofmem.phys_range, min, max, reverse ); + phys = find_area( align, size, ofmem->phys_range, min, max, reverse ); if( phys == (ucell)-1 ) { printk("ofmem_claim_phys - out of space\n"); return -1; } - add_entry( phys, size, &ofmem.phys_range ); + add_entry( phys, size, &ofmem->phys_range ); return phys; }
@@ -381,27 +410,28 @@ ucell ofmem_claim_phys( ucell phys, ucell size, ucell align ) { /* printk("+ ofmem_claim phys %08lx %lx %ld\n", phys, size, align ); */ - return ofmem_claim_phys_( phys, size, align, 0, RAMSIZE, 0 ); + return ofmem_claim_phys_( phys, size, align, 0, get_ram_size(), 0 ); }
static ucell ofmem_claim_virt_( ucell virt, ucell size, ucell align, ucell min, ucell max, int reverse ) { + ofmem_t *ofmem = OFMEM; if( !align ) { - if( !is_free( virt, size, ofmem.virt_range ) ) { + if( !is_free( virt, size, ofmem->virt_range ) ) { printk("Non-free physical memory claimed!\n"); return -1; } - add_entry( virt, size, &ofmem.virt_range ); + add_entry( virt, size, &ofmem->virt_range ); return virt; }
- virt = find_area( align, size, ofmem.virt_range, min, max, reverse ); + virt = find_area( align, size, ofmem->virt_range, min, max, reverse ); if( virt == (ucell)-1 ) { printk("ofmem_claim_virt - out of space\n"); return -1; } - add_entry( virt, size, &ofmem.virt_range ); + add_entry( virt, size, &ofmem->virt_range ); return virt; }
@@ -409,7 +439,7 @@ ucell ofmem_claim_virt( ucell virt, ucell size, ucell align ) { /* printk("+ ofmem_claim virt %08lx %lx %ld\n", virt, size, align ); */ - return ofmem_claim_virt_( virt, size, align, RAMSIZE, 0x80000000, 0 ); + return ofmem_claim_virt_( virt, size, align, get_ram_size() , IO_BASE, 0 ); }
@@ -417,13 +447,15 @@ ofmem_claim_virt( ucell virt, ucell size ucell ofmem_claim( ucell addr, ucell size, ucell align ) { + ofmem_t *ofmem = OFMEM; ucell virt, phys; ucell offs = addr & 0xfff;
/* printk("+ ofmem_claim %08lx %lx %ld\n", addr, size, align ); */ virt = phys = 0; if( !align ) { - if( is_free(addr, size, ofmem.virt_range) && is_free(addr, size, ofmem.phys_range) ) { + if( is_free(addr, size, ofmem->virt_range) && + is_free(addr, size, ofmem->phys_range) ) { ofmem_claim_phys_( addr, size, 0, 0, 0, 0 ); ofmem_claim_virt_( addr, size, 0, 0, 0, 0 ); virt = phys = addr; @@ -434,8 +466,8 @@ ofmem_claim( ucell addr, ucell size, uce } else { if( align < 0x1000 ) align = 0x1000; - phys = ofmem_claim_phys_( addr, size, align, 0, RAMSIZE, 1 /* reverse */ ); - virt = ofmem_claim_virt_( addr, size, align, 0, RAMSIZE, 1 /* reverse */ ); + phys = ofmem_claim_phys_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); + virt = ofmem_claim_virt_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); if( phys == (ucell)-1 || virt == (ucell)-1 ) { printk("ofmem_claim failed\n"); return -1; @@ -465,9 +497,10 @@ ofmem_claim( ucell addr, ucell size, uce static void split_trans( ucell virt ) { + ofmem_t *ofmem = OFMEM; translation_t *t, *t2;
- for( t=ofmem.trans; t; t=t->next ) { + for( t=ofmem->trans; t; t=t->next ) { if( virt > t->virt && virt < t->virt + t->size-1 ) { t2 = (translation_t*)malloc( sizeof(translation_t) ); t2->virt = virt; @@ -484,30 +517,31 @@ split_trans( ucell virt ) static int map_page_range( ucell virt, ucell phys, ucell size, ucell mode ) { + ofmem_t *ofmem = OFMEM; translation_t *t, **tt;
split_trans( virt ); split_trans( virt + size );
/* detect remappings */ - for( t=ofmem.trans; t; ) { + for( t=ofmem->trans; t; ) { if( virt == t->virt || (virt < t->virt && virt + size > t->virt )) { if( t->phys + virt - t->virt != phys ) { printk("mapping altered (ea " FMT_ucellx ")\n", t->virt ); } else if( t->mode != mode ){ printk("mapping mode altered\n"); } - for( tt=&ofmem.trans; *tt != t ; tt=&(**tt).next ) + for( tt=&ofmem->trans; *tt != t ; tt=&(**tt).next ) ; *tt = t->next; free((char*)t); - t=ofmem.trans; + t=ofmem->trans; continue; } t=t->next; } /* add mapping */ - for( tt=&ofmem.trans; *tt && (**tt).virt < virt ; tt=&(**tt).next ) + for( tt=&ofmem->trans; *tt && (**tt).virt < virt ; tt=&(**tt).next ) ; t = (translation_t*)malloc( sizeof(translation_t) ); t->virt = virt; @@ -523,6 +557,7 @@ map_page_range( ucell virt, ucell phys, int ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ) { + ofmem_t *ofmem = OFMEM; /* printk("+ofmem_map: %08lX --> %08lX (size %08lX, mode 0x%02X)\n", virt, phys, size, mode ); */
@@ -536,9 +571,9 @@ ofmem_map( ucell phys, ucell virt, ucell } #if 1 /* claim any unclaimed virtual memory in the range */ - fill_range( virt, size, &ofmem.virt_range ); + fill_range( virt, size, &ofmem->virt_range ); /* hmm... we better claim the physical range too */ - fill_range( phys, size, &ofmem.phys_range ); + fill_range( phys, size, &ofmem->phys_range ); #endif //printk("map_page_range %08lx -> %08lx %08lx\n", virt, phys, size ); map_page_range( virt, phys, size, (mode==-1)? def_memmode(phys) : mode ); @@ -549,9 +584,10 @@ ofmem_map( ucell phys, ucell virt, ucell ucell ofmem_translate( ucell virt, ucell *mode ) { + ofmem_t *ofmem = OFMEM; translation_t *t;
- for( t=ofmem.trans; t && t->virt <= virt ; t=t->next ) { + for( t=ofmem->trans; t && t->virt <= virt ; t=t->next ) { ucell offs; if( t->virt + t->size - 1 < virt ) continue; @@ -587,7 +623,9 @@ ea_to_phys( ucell ea, ucell *mode ) *mode = def_memmode( ea ); return ea; } - if( (phys=ofmem_translate(ea, mode)) == (ucell)-1 ) { + + phys = ofmem_translate(ea, mode); + if( phys == (ucell)-1 ) { #ifdef I_WANT_MOLISMS if( ea != 0x80816c00 ) printk("ea_to_phys: no translation for %08lx, using 1-1\n", ea ); @@ -619,9 +657,9 @@ hash_page( ucell ea, ucell phys, ucell m
hash1 = vsid; hash1 ^= (ea >> 12) & 0xffff; - hash1 &= (HASH_SIZE-1) >> 6; + hash1 &= (get_hash_size() - 1) >> 6;
- pp = (mPTE_t*)(HASH_BASE + (hash1 << 6)); + pp = (mPTE_t*)(get_hash_base() + (hash1 << 6)); upte = (ulong*)pp;
/* replace old translation */ @@ -651,11 +689,15 @@ dsi_exception( void ) { ulong dar, dsisr; ucell mode; + ucell phys;
asm volatile("mfdar %0" : "=r" (dar) : ); asm volatile("mfdsisr %0" : "=r" (dsisr) : ); + //printk("dsi-exception @ %08lx <%08lx>\n", dar, dsisr ); - hash_page( dar, ea_to_phys(dar, &mode), mode ); + + phys = ea_to_phys(dar, &mode); + hash_page( dar, phys, mode ); }
void @@ -663,12 +705,15 @@ isi_exception( void ) { ulong nip, srr1; ucell mode; + ucell phys;
asm volatile("mfsrr0 %0" : "=r" (nip) : ); asm volatile("mfsrr1 %0" : "=r" (srr1) : );
//printk("isi-exception @ %08lx <%08lx>\n", nip, srr1 ); - hash_page( nip, ea_to_phys(nip, &mode), mode ); + + phys = ea_to_phys(nip, &mode); + hash_page( nip, phys, mode ); }
@@ -697,8 +742,9 @@ setup_mmu( ulong code_base, ulong code_s void ofmem_init( void ) { + ofmem_t *ofmem = OFMEM; /* In case we can't rely on memory being zero initialized */ - memset(&ofmem, 0, sizeof(ofmem)); + memset(ofmem, 0, sizeof(ofmem));
ofmem_claim_phys( 0, FREE_BASE_1, 0 ); ofmem_claim_virt( 0, FREE_BASE_1, 0 ); Index: openbios-devel/arch/ppc/qemu/ofmem.c =================================================================== --- openbios-devel.orig/arch/ppc/qemu/ofmem.c +++ openbios-devel/arch/ppc/qemu/ofmem.c @@ -31,6 +31,7 @@ extern void isi_exception( void ); extern void setup_mmu( ulong code_base );
#define FREE_BASE 0x00004000 +#define OF_CODE_START 0xfff00000UL #define IO_BASE 0x80000000 #define OFMEM ((ofmem_t*)FREE_BASE) #define OF_MALLOC_BASE ((char*)OFMEM + ((sizeof(ofmem_t) + 3) & ~3)) @@ -446,7 +447,7 @@ ofmem_claim( ucell addr, ucell size, uce ofmem_claim_virt_( addr, size, 0, 0, 0, 0 ); virt = phys = addr; } else { - /* printk("**** ofmem_claim failure ***!\n"); */ + printk("**** ofmem_claim failure ***!\n"); return -1; } } else { @@ -550,8 +551,9 @@ ofmem_map( ucell phys, ucell virt, ucell virt, phys, size, mode ); */
if( (phys & 0xfff) || (virt & 0xfff) || (size & 0xfff) ) { - /* printk("ofmem_map: Bad parameters (%08lX %08lX %08lX)\n", - phys, virt, size ); */ + printk("ofmem_map: Bad parameters (" FMT_ucellX " " FMT_ucellX " " + FMT_ucellX ")\n", + phys, virt, size ); phys &= ~0xfff; virt &= ~0xfff; size = (size + 0xfff) & ~0xfff; @@ -585,7 +587,7 @@ ofmem_translate( ucell virt, ucell *mode
//printk("ofmem_translate: no translation defined (%08lx)\n", virt); //print_trans(); - return -1UL; + return -1; }
/* release memory allocated by ofmem_claim */ @@ -605,16 +607,16 @@ ea_to_phys( ucell ea, ucell *mode ) { ucell phys;
- if (ea >= 0xfff00000UL) { + if (ea >= OF_CODE_START) { /* ROM into RAM */ - ea -= 0xfff00000UL; + ea -= OF_CODE_START; phys = get_rom_base() + ea; *mode = 0x02; return phys; }
phys = ofmem_translate(ea, mode); - if( phys == -1UL ) { + if( phys == (ucell)-1 ) { phys = ea; *mode = def_memmode( phys );
#define RAMSIZE 0x02000000 /* XXXXXXXXXXXXXXXXXXX FIXME XXXXXXXXXXXXXXX */
-typedef struct alloc_desc { - struct alloc_desc *next; - ucell size; /* size (including) this struct */ -} alloc_desc_t; - -typedef struct mem_range { - struct mem_range *next; - ucell start; - ucell size; -} range_t; - -typedef struct trans { - struct trans *next; - ucell virt; /* chain is sorted by virt */ - ucell size; - ucell phys; - ucell mode; -} translation_t; - -typedef struct { - char *next_malloc; - 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_t; - static ofmem_t s_ofmem;
#define IO_BASE 0x80000000 @@ -115,497 +86,79 @@ get_hash_size( void ) return HASH_SIZE; }
-ulong -get_ram_size( void ) +static ucell get_heap_top( void ) { - return RAMSIZE; -} - -/************************************************************************/ -/* OF private allocations */ -/************************************************************************/ - -void * -malloc( int size ) -{ - ofmem_t *ofmem = OFMEM; - alloc_desc_t *d, **pp; - char *ret; - ulong top; - - if( !size ) - return NULL; - - if( !ofmem->next_malloc ) - ofmem->next_malloc = (char*)OF_MALLOC_BASE; - - if( size & 3 ) - size += 4 - (size & 3); - 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; - return ret; - } - - top = HASH_BASE; - if( (ulong)ofmem->next_malloc + size > top ) { - printk("out of malloc memory (%x)!\n", size ); - return NULL; - } - - d = (alloc_desc_t*) ofmem->next_malloc; - ofmem->next_malloc += size; - - d->next = NULL; - d->size = size; - - ret = (char*)d + sizeof(alloc_desc_t); - memset( ret, 0, size - sizeof(alloc_desc_t) ); - - return ret; + return HASH_BASE; }
-void -free( void *ptr ) +static inline size_t ALIGN_SIZE(size_t x, size_t a) { - ofmem_t *ofmem = OFMEM; - alloc_desc_t **pp, *d; - - /* it is legal to free NULL pointers (size zero allocations) */ - if( !ptr ) - return; - - d = (alloc_desc_t*)((char *)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 (x + a - 1) & ~(a-1); }
-void * -realloc( void *ptr, size_t size ) +ofmem_t* ofmem_arch_get_private(void) { - alloc_desc_t *d = (alloc_desc_t*)((char *)ptr - sizeof(alloc_desc_t)); - char *p; - - 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; + return OFMEM; }
- -/************************************************************************/ -/* debug */ -/************************************************************************/ - -#if 0 -static void -print_range( range_t *r, char *str ) +void* ofmem_arch_get_malloc_base(void) { - printk("--- Range %s ---\n", str ); - for( ; r; r=r->next ) - printk("%08lx - %08lx\n", r->start, r->start + r->size -1 ); - printk("\n"); + return OF_MALLOC_BASE; }
-static void -print_phys_range() +ucell ofmem_arch_get_heap_top(void) { - print_range( ofmem.phys_range, "phys" ); + return get_heap_top(); }
-static void -print_virt_range() +ucell ofmem_arch_get_virt_top(void) { - print_range( ofmem.virt_range, "virt" ); + return IO_BASE; }
-static void -print_trans( void ) +void ofmem_arch_unmap_pages(ucell virt, ucell size) { - translation_t *t = ofmem.trans; - - printk("--- Translations ---\n"); - for( ; t; t=t->next ) - printk("%08lx -> %08lx [size %lx]\n", t->virt, t->phys, t->size ); - printk("\n"); + /* kill page mappings in provided range */ } -#endif - - -/************************************************************************/ -/* misc */ -/************************************************************************/
-static inline ucell -def_memmode( ucell phys ) +void ofmem_arch_early_map_pages(ucell phys, ucell virt, ucell size, ucell mode) { - /* XXX: Guard bit not set as it should! */ - if( phys < IO_BASE || phys >= 0xffc00000 ) - return 0x02; /*0xa*/ /* wim GxPp */ - return 0x6a; /* WIm GxPp, I/O */ + /* none yet */ }
- /************************************************************************/ -/* client interface */ +/* OF private allocations */ /************************************************************************/
-static int -is_free( ucell ea, ucell size, range_t *r ) -{ - if( size == 0 ) - return 1; - for( ; r ; r=r->next ) { - if( r->start + r->size - 1 >= ea && r->start <= ea ) - return 0; - if( r->start >= ea && r->start <= ea + size - 1 ) - return 0; - } - return 1; -} - -static void -add_entry_( ucell ea, ucell size, range_t **r ) -{ - range_t *nr; - - for( ; *r && (**r).start < ea; r=&(**r).next ) - ; - nr = (range_t*)malloc( sizeof(range_t) ); - nr->next = *r; - nr->start = ea; - nr->size = size; - *r = nr; -} - -static int -add_entry( ucell ea, ucell size, range_t **r ) -{ - if( !is_free( ea, size, *r ) ) { - printk("add_entry: range not free!\n"); - return -1; - } - add_entry_( ea, size, r ); - return 0; -} - -static void -join_ranges( range_t **rr ) -{ - range_t *n, *r = *rr; - while( r ) { - if( !(n=r->next) ) - break; - - if( r->start + r->size - 1 >= n->start -1 ) { - int s = n->size + (n->start - r->start - r->size); - if( s > 0 ) - r->size += s; - r->next = n->next; - free( n ); - continue; - } - r=r->next; - } -} - -static void -fill_range( ucell ea, ucell size, range_t **rr ) -{ - add_entry_( ea, size, rr ); - join_ranges( rr ); -} - -static ucell -find_area( ucell align, ucell size, range_t *r, ucell min, ucell max, int reverse ) -{ - ucell base = min; - range_t *r2; - - if( (align & (align-1)) ) { - printk("bad alignment " FMT_ucell "\n", align); - align = 0x1000; - } - if( !align ) - align = 0x1000; - - base = reverse ? max - size : min; - r2 = reverse ? NULL : r; - - for( ;; ) { - if( !reverse ) { - base = (base + align - 1) & ~(align-1); - if( base < min ) - base = min; - if( base + size - 1 >= max -1 ) - break; - } else { - if( base > max - size ) - base = max - size; - base -= base & (align-1); - } - if( is_free( base, size, r ) ) - return base; - - if( !reverse ) { - if( !r2 ) - break; - base = r2->start + r2->size; - r2 = r2->next; - } else { - range_t *rp; - for( rp=r; rp && rp->next != r2 ; rp=rp->next ) - ; - r2 = rp; - if( !r2 ) - break; - base = r2->start - size; - } - } - return (ucell)-1; -} - -static ucell -ofmem_claim_phys_( ucell phys, ucell size, ucell align, ucell min, ucell max, int reverse ) -{ - ofmem_t *ofmem = OFMEM; - if( !align ) { - if( !is_free( phys, size, ofmem->phys_range ) ) { - printk("Non-free physical memory claimed!\n"); - return -1; - } - add_entry( phys, size, &ofmem->phys_range ); - return phys; - } - phys = find_area( align, size, ofmem->phys_range, min, max, reverse ); - if( phys == (ucell)-1 ) { - printk("ofmem_claim_phys - out of space\n"); - return -1; - } - add_entry( phys, size, &ofmem->phys_range ); - return phys; -} - -/* if align != 0, phys is ignored. Returns -1 on error */ -ucell -ofmem_claim_phys( ucell phys, ucell size, ucell align ) -{ - /* printk("+ ofmem_claim phys %08lx %lx %ld\n", phys, size, align ); */ - return ofmem_claim_phys_( phys, size, align, 0, get_ram_size(), 0 ); -} - -static ucell -ofmem_claim_virt_( ucell virt, ucell size, ucell align, ucell min, ucell max, int reverse ) +void * +malloc( int size ) { - ofmem_t *ofmem = OFMEM; - if( !align ) { - if( !is_free( virt, size, ofmem->virt_range ) ) { - printk("Non-free physical memory claimed!\n"); - return -1; - } - add_entry( virt, size, &ofmem->virt_range ); - return virt; - } - - virt = find_area( align, size, ofmem->virt_range, min, max, reverse ); - if( virt == (ucell)-1 ) { - printk("ofmem_claim_virt - out of space\n"); - return -1; - } - add_entry( virt, size, &ofmem->virt_range ); - return virt; + return ofmem_malloc(size); }
-ucell -ofmem_claim_virt( ucell virt, ucell size, ucell align ) +void +free( void *ptr ) { - /* printk("+ ofmem_claim virt %08lx %lx %ld\n", virt, size, align ); */ - return ofmem_claim_virt_( virt, size, align, get_ram_size() , IO_BASE, 0 ); + return ofmem_free(ptr); }
- -/* allocate both physical and virtual space and add a translation */ -ucell -ofmem_claim( ucell addr, ucell size, ucell align ) +void * +realloc( void *ptr, size_t size ) { - ofmem_t *ofmem = OFMEM; - ucell virt, phys; - ucell offs = addr & 0xfff; - - /* printk("+ ofmem_claim %08lx %lx %ld\n", addr, size, align ); */ - virt = phys = 0; - if( !align ) { - if( is_free(addr, size, ofmem->virt_range) && - is_free(addr, size, ofmem->phys_range) ) { - ofmem_claim_phys_( addr, size, 0, 0, 0, 0 ); - ofmem_claim_virt_( addr, size, 0, 0, 0, 0 ); - virt = phys = addr; - } else { - printk("**** ofmem_claim failure ***!\n"); - return -1; - } - } else { - if( align < 0x1000 ) - align = 0x1000; - phys = ofmem_claim_phys_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); - virt = ofmem_claim_virt_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); - if( phys == (ucell)-1 || virt == (ucell)-1 ) { - printk("ofmem_claim failed\n"); - return -1; - } - /* printk("...phys = %08lX, virt = %08lX, size = %08lX\n", phys, virt, size ); */ - } - - /* align */ - if( phys & 0xfff ) { - size += (phys & 0xfff); - virt -= (phys & 0xfff); - phys &= ~0xfff; - } - if( size & 0xfff ) - size = (size + 0xfff) & ~0xfff; - - /* printk("...free memory found... phys: %08lX, virt: %08lX, size %lX\n", phys, virt, size ); */ - ofmem_map( phys, virt, size, def_memmode(phys) ); - return virt + offs; + return ofmem_realloc(ptr, size); }
/************************************************************************/ -/* keep track of ea -> phys translations */ +/* misc */ /************************************************************************/
-static void -split_trans( ucell virt ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t, *t2; - - for( t=ofmem->trans; t; t=t->next ) { - if( virt > t->virt && virt < t->virt + t->size-1 ) { - t2 = (translation_t*)malloc( sizeof(translation_t) ); - t2->virt = virt; - t2->size = t->size - (virt - t->virt); - t->size = virt - t->virt; - t2->phys = t->phys + t->size; - t2->mode = t->mode; - t2->next = t->next; - t->next = t2; - } - } -} - -static int -map_page_range( ucell virt, ucell phys, ucell size, ucell mode ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t, **tt; - - split_trans( virt ); - split_trans( virt + size ); - - /* detect remappings */ - for( t=ofmem->trans; t; ) { - if( virt == t->virt || (virt < t->virt && virt + size > t->virt )) { - if( t->phys + virt - t->virt != phys ) { - printk("mapping altered (ea " FMT_ucellx ")\n", t->virt ); - } else if( t->mode != mode ){ - printk("mapping mode altered\n"); - } - for( tt=&ofmem->trans; *tt != t ; tt=&(**tt).next ) - ; - *tt = t->next; - free((char*)t); - t=ofmem->trans; - continue; - } - t=t->next; - } - /* add mapping */ - for( tt=&ofmem->trans; *tt && (**tt).virt < virt ; tt=&(**tt).next ) - ; - t = (translation_t*)malloc( sizeof(translation_t) ); - t->virt = virt; - t->phys = phys; - t->size = size; - t->mode = mode; - t->next = *tt; - *tt = t; - - return 0; -} - -int -ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ) -{ - ofmem_t *ofmem = OFMEM; - /* printk("+ofmem_map: %08lX --> %08lX (size %08lX, mode 0x%02X)\n", - virt, phys, size, mode ); */ - - if( (phys & 0xfff) || (virt & 0xfff) || (size & 0xfff) ) { - printk("ofmem_map: Bad parameters (" FMT_ucellX " " FMT_ucellX " " - FMT_ucellX ")\n", - phys, virt, size ); - phys &= ~0xfff; - virt &= ~0xfff; - size = (size + 0xfff) & ~0xfff; - } -#if 1 - /* claim any unclaimed virtual memory in the range */ - fill_range( virt, size, &ofmem->virt_range ); - /* hmm... we better claim the physical range too */ - fill_range( phys, size, &ofmem->phys_range ); -#endif - //printk("map_page_range %08lx -> %08lx %08lx\n", virt, phys, size ); - map_page_range( virt, phys, size, (mode==-1)? def_memmode(phys) : mode ); - return 0; -} - -/* virtual -> physical. */ -ucell -ofmem_translate( ucell virt, ucell *mode ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t; - - for( t=ofmem->trans; t && t->virt <= virt ; t=t->next ) { - ucell offs; - if( t->virt + t->size - 1 < virt ) - continue; - offs = virt - t->virt; - *mode = t->mode; - return t->phys + offs; - } - - //printk("ofmem_translate: no translation defined (%08lx)\n", virt); - //print_trans(); - return -1; -} - -/* release memory allocated by ofmem_claim */ -void -ofmem_release( ucell virt, ucell size ) +ucell ofmem_arch_default_translation_mode( ucell phys ) { - /* printk("ofmem_release unimplemented (%08lx, %08lx)\n", virt, size ); */ + /* XXX: Guard bit not set as it should! */ + if( phys < IO_BASE || phys >= 0xffc00000 ) + return 0x02; /*0xa*/ /* wim GxPp */ + return 0x6a; /* WIm GxPp, I/O */ }
@@ -620,7 +173,7 @@ ea_to_phys( ucell ea, ucell *mode )
/* hardcode our translation needs */ if( ea >= OF_CODE_START && ea < FREE_BASE_2 ) { - *mode = def_memmode( ea ); + *mode = ofmem_arch_default_translation_mode( ea ); return ea; }
@@ -631,7 +184,7 @@ ea_to_phys( ucell ea, ucell *mode ) printk("ea_to_phys: no translation for %08lx, using 1-1\n", ea ); #endif phys = ea; - *mode = def_memmode( phys ); + *mode = ofmem_arch_default_translation_mode( phys );
#ifdef I_WANT_MOLISMS forth_segv_handler( (char*)ea ); @@ -746,6 +299,8 @@ ofmem_init( void ) /* In case we can't rely on memory being zero initialized */ memset(ofmem, 0, sizeof(ofmem));
+ ofmem->ramsize = RAMSIZE; + ofmem_claim_phys( 0, FREE_BASE_1, 0 ); ofmem_claim_virt( 0, FREE_BASE_1, 0 ); ofmem_claim_phys( OF_CODE_START, FREE_BASE_2 - OF_CODE_START, 0 ); Index: openbios-devel/arch/ppc/qemu/ofmem.c =================================================================== --- openbios-devel.orig/arch/ppc/qemu/ofmem.c +++ openbios-devel/arch/ppc/qemu/ofmem.c @@ -34,6 +34,7 @@ extern void setup_mmu( ulong code_base ) #define OF_CODE_START 0xfff00000UL #define IO_BASE 0x80000000 #define OFMEM ((ofmem_t*)FREE_BASE) + #define OF_MALLOC_BASE ((char*)OFMEM + ((sizeof(ofmem_t) + 3) & ~3))
#define HASH_SIZE (2 << 15) @@ -41,36 +42,6 @@ extern void setup_mmu( ulong code_base ) #define SEGR_USER BIT(2) #define SEGR_BASE 0x0400
-typedef struct alloc_desc { - struct alloc_desc *next; - ucell size; /* size (including) this struct */ -} alloc_desc_t; - -typedef struct mem_range { - struct mem_range *next; - ucell start; - ucell size; -} range_t; - -typedef struct trans { - struct trans *next; - ucell virt; /* chain is sorted by virt */ - ucell size; - ucell phys; - ucell mode; -} translation_t; - -typedef struct { - ulong ramsize; - char *next_malloc; - 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_t; - static inline ulong get_hash_base( void ) { @@ -91,17 +62,11 @@ get_hash_size( void ) return ((sdr1 << 16) | 0x0000ffff) + 1; }
-ulong -get_ram_size( void ) -{ - ofmem_t *ofmem = OFMEM; - return ofmem->ramsize; -} - static inline ulong get_rom_base( void ) { - return get_ram_size() - 0x00100000; + ofmem_t *ofmem = ofmem_arch_get_private(); + return ofmem->ramsize - 0x00100000; }
ulong @@ -116,485 +81,81 @@ get_ram_bottom( void ) return (ulong)OF_MALLOC_BASE; }
-static phandle_t cpu_handle = 0; -static void -ofmem_update_translations( void ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t; - int ncells; - cell *props; - - if (cpu_handle == 0) - return; - - for( t = ofmem->trans, ncells = 0; t ; t=t->next, ncells++ ) - ; - - props = malloc(ncells * sizeof(cell) * 4); - if (props == NULL) - return; - - for( t = ofmem->trans, ncells = 0 ; t ; t=t->next ) { - props[ncells++] = t->virt; - props[ncells++] = t->size; - props[ncells++] = t->phys; - props[ncells++] = t->mode; - } - set_property(cpu_handle, "translations", - (char*)props, ncells * sizeof(cell)); - free(props); -} - -/************************************************************************/ -/* OF private allocations */ -/************************************************************************/ - -void * -malloc( int size ) -{ - ofmem_t *ofmem = OFMEM; - alloc_desc_t *d, **pp; - char *ret; - ulong top; - - if( !size ) - return NULL; - - if( !ofmem->next_malloc ) - ofmem->next_malloc = (char*)OF_MALLOC_BASE; - - if( size & 3 ) - size += 4 - (size & 3); - 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; - return ret; - } - - top = get_hash_base() - (32 + 64) * 1024; - if( (ulong)ofmem->next_malloc + size > top ) { - printk("out of malloc memory (%x)!\n", size ); - return NULL; - } - - d = (alloc_desc_t*) ofmem->next_malloc; - ofmem->next_malloc += size; - - d->next = NULL; - d->size = size; - - ret = (char*)d + sizeof(alloc_desc_t); - memset( ret, 0, size - sizeof(alloc_desc_t) ); - - return ret; -} - -void -free( void *ptr ) -{ - ofmem_t *ofmem = OFMEM; - alloc_desc_t **pp, *d; - - /* it is legal to free NULL pointers (size zero allocations) */ - if( !ptr ) - return; - - d = (alloc_desc_t*)((char *)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; -} - -void * -realloc( void *ptr, size_t size ) -{ - alloc_desc_t *d = (alloc_desc_t*)((char *)ptr - sizeof(alloc_desc_t)); - char *p; - - 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; -} - - -/************************************************************************/ -/* misc */ -/************************************************************************/ - -extern char _start[], _end[]; -static inline ucell -def_memmode( ucell phys ) -{ - /* XXX: Guard bit not set as it should! */ - if( phys < IO_BASE ) - return 0x02; /*0xa*/ /* wim GxPp */ - return 0x6a; /* WIm GxPp, I/O */ -} - - -/************************************************************************/ -/* client interface */ -/************************************************************************/ - -static int -is_free( ucell ea, ucell size, range_t *r ) -{ - if( size == 0 ) - return 1; - for( ; r ; r=r->next ) { - if( r->start + r->size - 1 >= ea && r->start <= ea ) - return 0; - if( r->start >= ea && r->start <= ea + size - 1 ) - return 0; - } - return 1; -} - -static void -add_entry_( ucell ea, ucell size, range_t **r ) -{ - range_t *nr; - - for( ; *r && (**r).start < ea; r=&(**r).next ) - ; - nr = (range_t*)malloc( sizeof(range_t) ); - nr->next = *r; - nr->start = ea; - nr->size = size; - *r = nr; -} - -static int -add_entry( ucell ea, ucell size, range_t **r ) +static ucell get_heap_top( void ) { - if( !is_free( ea, size, *r ) ) { - printk("add_entry: range not free!\n"); - return -1; - } - add_entry_( ea, size, r ); - return 0; + return get_hash_base() - (32 + 64) * 1024; }
-static void -join_ranges( range_t **rr ) +static inline size_t ALIGN_SIZE(size_t x, size_t a) { - range_t *n, *r = *rr; - while( r ) { - if( !(n=r->next) ) - break; - - if( r->start + r->size - 1 >= n->start -1 ) { - int s = n->size + (n->start - r->start - r->size); - if( s > 0 ) - r->size += s; - r->next = n->next; - free( n ); - continue; - } - r=r->next; - } + return (x + a - 1) & ~(a-1); }
-static void -fill_range( ucell ea, ucell size, range_t **rr ) -{ - add_entry_( ea, size, rr ); - join_ranges( rr ); -} - -static ucell -find_area( ucell align, ucell size, range_t *r, ucell min, ucell max, int reverse ) +ofmem_t* ofmem_arch_get_private(void) { - ucell base = min; - range_t *r2; - - if( (align & (align-1)) ) { - printk("bad alignment " FMT_ucell "\n", align); - align = 0x1000; - } - if( !align ) - align = 0x1000; - - base = reverse ? max - size : min; - r2 = reverse ? NULL : r; - - for( ;; ) { - if( !reverse ) { - base = (base + align - 1) & ~(align-1); - if( base < min ) - base = min; - if( base + size - 1 >= max -1 ) - break; - } else { - if( base > max - size ) - base = max - size; - base -= base & (align-1); - } - if( is_free( base, size, r ) ) - return base; - - if( !reverse ) { - if( !r2 ) - break; - base = r2->start + r2->size; - r2 = r2->next; - } else { - range_t *rp; - for( rp=r; rp && rp->next != r2 ; rp=rp->next ) - ; - r2 = rp; - if( !r2 ) - break; - base = r2->start - size; - } - } - return (ucell)-1; + return OFMEM; }
-static ucell -ofmem_claim_phys_( ucell phys, ucell size, ucell align, ucell min, ucell max, int reverse ) +void* ofmem_arch_get_malloc_base(void) { - ofmem_t *ofmem = OFMEM; - if( !align ) { - if( !is_free( phys, size, ofmem->phys_range ) ) { - printk("Non-free physical memory claimed!\n"); - return -1; - } - add_entry( phys, size, &ofmem->phys_range ); - return phys; - } - phys = find_area( align, size, ofmem->phys_range, min, max, reverse ); - if( phys == (ucell)-1 ) { - printk("ofmem_claim_phys - out of space\n"); - return -1; - } - add_entry( phys, size, &ofmem->phys_range ); - return phys; + return OF_MALLOC_BASE; }
-/* if align != 0, phys is ignored. Returns -1 on error */ -ucell -ofmem_claim_phys( ucell phys, ucell size, ucell align ) +ucell ofmem_arch_get_heap_top(void) { - /* printk("+ ofmem_claim phys %08lx %lx %ld\n", phys, size, align ); */ - return ofmem_claim_phys_( phys, size, align, 0, get_ram_size(), 0 ); + return get_heap_top(); }
-static ucell -ofmem_claim_virt_( ucell virt, ucell size, ucell align, ucell min, ucell max, int reverse ) +ucell ofmem_arch_get_virt_top(void) { - ofmem_t *ofmem = OFMEM; - if( !align ) { - if( !is_free( virt, size, ofmem->virt_range ) ) { - printk("Non-free physical memory claimed!\n"); - return -1; - } - add_entry( virt, size, &ofmem->virt_range ); - return virt; - } - - virt = find_area( align, size, ofmem->virt_range, min, max, reverse ); - if( virt == (ucell)-1 ) { - printk("ofmem_claim_virt - out of space\n"); - return -1; - } - add_entry( virt, size, &ofmem->virt_range ); - return virt; + return IO_BASE; }
-ucell -ofmem_claim_virt( ucell virt, ucell size, ucell align ) +void ofmem_arch_unmap_pages(ucell virt, ucell size) { - /* printk("+ ofmem_claim virt %08lx %lx %ld\n", virt, size, align ); */ - return ofmem_claim_virt_( virt, size, align, get_ram_size() , IO_BASE, 0 ); + /* kill page mappings in provided range */ }
- -/* allocate both physical and virtual space and add a translation */ -ucell -ofmem_claim( ucell addr, ucell size, ucell align ) +void ofmem_arch_early_map_pages(ucell phys, ucell virt, ucell size, ucell mode) { - ofmem_t *ofmem = OFMEM; - ucell virt, phys; - ucell offs = addr & 0xfff; - - /* printk("+ ofmem_claim %08lx %lx %ld\n", addr, size, align ); */ - virt = phys = 0; - if( !align ) { - if( is_free(addr, size, ofmem->virt_range) && - is_free(addr, size, ofmem->phys_range) ) { - ofmem_claim_phys_( addr, size, 0, 0, 0, 0 ); - ofmem_claim_virt_( addr, size, 0, 0, 0, 0 ); - virt = phys = addr; - } else { - printk("**** ofmem_claim failure ***!\n"); - return -1; - } - } else { - if( align < 0x1000 ) - align = 0x1000; - phys = ofmem_claim_phys_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); - virt = ofmem_claim_virt_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); - if( phys == (ucell)-1 || virt == (ucell)-1 ) { - printk("ofmem_claim failed\n"); - return -1; - } - /* printk("...phys = %08lX, virt = %08lX, size = %08lX\n", phys, virt, size ); */ - } - - /* align */ - if( phys & 0xfff ) { - size += (phys & 0xfff); - virt -= (phys & 0xfff); - phys &= ~0xfff; - } - if( size & 0xfff ) - size = (size + 0xfff) & ~0xfff; - - /* printk("...free memory found... phys: %08lX, virt: %08lX, size %lX\n", phys, virt, size ); */ - ofmem_map( phys, virt, size, def_memmode(phys) ); - return virt + offs; + /* none yet */ }
- /************************************************************************/ -/* keep track of ea -> phys translations */ +/* OF private allocations */ /************************************************************************/
-static void -split_trans( ucell virt ) +void * +malloc( int size ) { - ofmem_t *ofmem = OFMEM; - translation_t *t, *t2; - - for( t=ofmem->trans; t; t=t->next ) { - if( virt > t->virt && virt < t->virt + t->size-1 ) { - t2 = (translation_t*)malloc( sizeof(translation_t) ); - t2->virt = virt; - t2->size = t->size - (virt - t->virt); - t->size = virt - t->virt; - t2->phys = t->phys + t->size; - t2->mode = t->mode; - t2->next = t->next; - t->next = t2; - } - } + return ofmem_malloc(size); }
-static int -map_page_range( ucell virt, ucell phys, ucell size, ucell mode ) +void +free( void *ptr ) { - ofmem_t *ofmem = OFMEM; - translation_t *t, **tt; - - split_trans( virt ); - split_trans( virt + size ); - - /* detect remappings */ - for( t=ofmem->trans; t; ) { - if( virt == t->virt || (virt < t->virt && virt + size > t->virt )) { - if( t->phys + virt - t->virt != phys ) { - printk("mapping altered (ea " FMT_ucellx ")\n", t->virt ); - } else if( t->mode != mode ){ - printk("mapping mode altered\n"); - } - for( tt=&ofmem->trans; *tt != t ; tt=&(**tt).next ) - ; - *tt = t->next; - free((char*)t); - t=ofmem->trans; - continue; - } - t=t->next; - } - /* add mapping */ - for( tt=&ofmem->trans; *tt && (**tt).virt < virt ; tt=&(**tt).next ) - ; - t = (translation_t*)malloc( sizeof(translation_t) ); - t->virt = virt; - t->phys = phys; - t->size = size; - t->mode = mode; - t->next = *tt; - *tt = t; - - ofmem_update_translations(); - - return 0; + return ofmem_free(ptr); }
-int -ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ) +void * +realloc( void *ptr, size_t size ) { - ofmem_t *ofmem = OFMEM; - /* printk("+ofmem_map: %08lX --> %08lX (size %08lX, mode 0x%02X)\n", - virt, phys, size, mode ); */ - - if( (phys & 0xfff) || (virt & 0xfff) || (size & 0xfff) ) { - printk("ofmem_map: Bad parameters (" FMT_ucellX " " FMT_ucellX " " - FMT_ucellX ")\n", - phys, virt, size ); - phys &= ~0xfff; - virt &= ~0xfff; - size = (size + 0xfff) & ~0xfff; - } -#if 1 - /* claim any unclaimed virtual memory in the range */ - fill_range( virt, size, &ofmem->virt_range ); - /* hmm... we better claim the physical range too */ - fill_range( phys, size, &ofmem->phys_range ); -#endif - //printk("map_page_range %08lx -> %08lx %08lx\n", virt, phys, size ); - map_page_range( virt, phys, size, (mode==-1)? def_memmode(phys) : mode ); - return 0; + return ofmem_realloc(ptr, size); }
-/* virtual -> physical. */ -ucell -ofmem_translate( ucell virt, ucell *mode ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t;
- for( t=ofmem->trans; t && t->virt <= virt ; t=t->next ) { - ucell offs; - if( t->virt + t->size - 1 < virt ) - continue; - offs = virt - t->virt; - *mode = t->mode; - return t->phys + offs; - } +/************************************************************************/ +/* misc */ +/************************************************************************/
- //printk("ofmem_translate: no translation defined (%08lx)\n", virt); - //print_trans(); - return -1; -} +extern char _start[], _end[];
-/* release memory allocated by ofmem_claim */ -void -ofmem_release( ucell virt, ucell size ) +ucell ofmem_arch_default_translation_mode( ucell phys ) { - /* printk("ofmem_release unimplemented (%08lx, %08lx)\n", virt, size ); */ + /* XXX: Guard bit not set as it should! */ + if( phys < IO_BASE ) + return 0x02; /*0xa*/ /* wim GxPp */ + return 0x6a; /* WIm GxPp, I/O */ }
@@ -616,9 +177,9 @@ ea_to_phys( ucell ea, ucell *mode ) }
phys = ofmem_translate(ea, mode); - if( phys == (ucell)-1 ) { + if( phys == -1 ) { phys = ea; - *mode = def_memmode( phys ); + *mode = ofmem_arch_default_translation_mode( phys );
/* print_virt_range(); */ /* print_phys_range(); */ @@ -824,15 +385,10 @@ setup_mmu( ulong ramsize ) void ofmem_init( void ) { + ofmem_t *ofmem = ofmem_arch_get_private(); + ofmem_claim_phys( 0, get_ram_bottom(), 0 ); ofmem_claim_virt( 0, get_ram_bottom(), 0 ); - ofmem_claim_phys( get_ram_top(), get_ram_size() - get_ram_top(), 0); - ofmem_claim_virt( get_ram_top(), get_ram_size() - get_ram_top(), 0); -} - -void -ofmem_register( phandle_t ph ) -{ - cpu_handle = ph; - ofmem_update_translations(); + ofmem_claim_phys( get_ram_top(), ofmem->ramsize - get_ram_top(), 0); + ofmem_claim_virt( get_ram_top(), ofmem->ramsize - get_ram_top(), 0); } Index: openbios-devel/arch/sparc64/ofmem_sparc64.c =================================================================== --- openbios-devel.orig/arch/sparc64/ofmem_sparc64.c +++ openbios-devel/arch/sparc64/ofmem_sparc64.c @@ -18,11 +18,6 @@ #include "ofmem_sparc64.h" #include "spitfire.h"
-static inline uint64_t ALIGN_SIZE(uint64_t x, uint64_t a) -{ - return (x + a - 1) & ~(a-1); -} - #define OF_MALLOC_BASE ((char*)OFMEM + ALIGN_SIZE(sizeof(ofmem_t), 8))
#define MEMSIZE ((128 + 256 + 512) * 1024) @@ -36,199 +31,41 @@ static union {
translation_t **g_ofmem_translations = &s_ofmem_data.ofmem.trans;
-ulong get_ram_size( void ) +static ucell get_heap_top( void ) { - ofmem_t *ofmem = OFMEM; - return ofmem->ramsize; + return (ucell)TOP_OF_RAM; }
-static phandle_t s_phandle_memory = 0; -static phandle_t s_phandle_mmu = 0; - -static void ofmem_update_mmu_translations( void ) +static inline size_t ALIGN_SIZE(size_t x, size_t a) { - ofmem_t *ofmem = OFMEM; - translation_t *t; - int ncells; - ucell *props; - - if (s_phandle_mmu == 0) - return; - - for( t = ofmem->trans, ncells = 0; t ; t=t->next, ncells++ ) { - } - - props = malloc(ncells * sizeof(ucell) * 3); - - if (props == NULL) - return; - - for( t = ofmem->trans, ncells = 0 ; t ; t=t->next ) { - props[ncells++] = t->virt; - props[ncells++] = t->size; - props[ncells++] = t->mode; - } - - set_property(s_phandle_mmu, "translations", - (char*)props, ncells * sizeof(props[0])); - - free(props); + return (x + a - 1) & ~(a-1); }
-static void ofmem_update_memory_available( phandle_t ph, range_t *range, - u64 top_address ) +ofmem_t* ofmem_arch_get_private(void) { - range_t *r; - int ncells; - ucell *props; - - ucell start, size; - - if (s_phandle_memory == 0) - return; - - /* count phys_range list entries */ - for( r = range, ncells = 0; r ; r=r->next, ncells++ ) { - } - - /* inverse of phys_range list could take 2 more cells for the tail */ - props = malloc((ncells+1) * sizeof(ucell) * 2); - - if (props == NULL) { - /* out of memory! */ - return; - } - - start = 0; - ncells = 0; - - for (r = range; r; r=r->next) { - if (r->start >= top_address) { - break; - } - - size = r->start - start; - if (size) { - props[ncells++] = start; - props[ncells++] = size; - } - start = r->start + r->size; - } - - /* tail */ - if (start < top_address) { - props[ncells++] = start; - props[ncells++] = top_address - start; - } - - set_property(ph, "available", - (char*)props, ncells * sizeof(props[0])); - - free(props); + return OFMEM; }
-static void ofmem_update_translations( void ) +void* ofmem_arch_get_malloc_base(void) { - ofmem_t *ofmem = OFMEM; - - ofmem_update_memory_available(s_phandle_memory, - ofmem->phys_range, ofmem->ramsize); - ofmem_update_memory_available(s_phandle_mmu, - ofmem->virt_range, -1ULL); - ofmem_update_mmu_translations(); + return OF_MALLOC_BASE; }
-/************************************************************************/ -/* OF private allocations */ -/************************************************************************/ - -void* ofmem_malloc( size_t size ) +ucell ofmem_arch_get_heap_top(void) { - ofmem_t *ofmem = OFMEM; - alloc_desc_t *d, **pp; - char *ret; - - if( !size ) - return NULL; - - if( !ofmem->next_malloc ) - ofmem->next_malloc = (char*)OF_MALLOC_BASE; - - /* assuming sizeof(alloc_desc_t) is multiple of 8 */ - size = ALIGN_SIZE(size + sizeof(alloc_desc_t), 8); - - /* 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; - return ret; - } - - if( ofmem->next_malloc + size >= TOP_OF_RAM ) { - printk("out of malloc memory (%x)!\n", size ); - return NULL; - } - - d = (alloc_desc_t*) ofmem->next_malloc; - ofmem->next_malloc += size; - - d->next = NULL; - d->size = size; - - ret = (char*)d + sizeof(alloc_desc_t); - memset( ret, 0, size - sizeof(alloc_desc_t) ); - - return ret; + return get_heap_top(); }
-void ofmem_free( void *ptr ) +ucell ofmem_arch_get_virt_top(void) { - ofmem_t *ofmem = OFMEM; - alloc_desc_t **pp, *d; - - /* it is legal to free NULL pointers (size zero allocations) */ - if( !ptr ) - return; - - d = (alloc_desc_t*)((char *)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; -} - -void* ofmem_realloc( void *ptr, size_t size ) -{ - alloc_desc_t *d = (alloc_desc_t*)((char *)ptr - sizeof(alloc_desc_t)); - char *p; - - 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; + return (ucell)TOP_OF_RAM; }
- /************************************************************************/ /* misc */ /************************************************************************/
-static inline ucell def_memmode( ucell phys ) +ucell ofmem_arch_default_translation_mode( ucell phys ) { /* Writable, cacheable */ /* not privileged and not locked */ @@ -236,396 +73,6 @@ static inline ucell def_memmode( ucell p }
-/************************************************************************/ -/* client interface */ -/************************************************************************/ - -static int is_free( ucell ea, ucell size, range_t *r ) -{ - if( size == 0 ) - return 1; - for( ; r ; r=r->next ) { - if( r->start + r->size - 1 >= ea && r->start <= ea ) - return 0; - if( r->start >= ea && r->start <= ea + size - 1 ) - return 0; - } - return 1; -} - -static void add_entry_( ucell ea, ucell size, range_t **r ) -{ - range_t *nr; - - for( ; *r && (**r).start < ea; r=&(**r).next ) { - } - - nr = (range_t*)malloc( sizeof(range_t) ); - nr->next = *r; - nr->start = ea; - nr->size = size; - *r = nr; -} - -static int add_entry( ucell ea, ucell size, range_t **r ) -{ - if( !is_free( ea, size, *r ) ) { - printk("add_entry: range not free!\n"); - return -1; - } - add_entry_( ea, size, r ); - return 0; -} - -static ucell find_area( ucell align, ucell size, range_t *r, - ucell min, ucell max, int reverse ) -{ - ucell base = min; - range_t *r2; - - if( (align & (align-1)) ) { - printk("bad alignment " FMT_ucell "\n", align); - align = 0x1000; - } - if( !align ) - align = 0x1000; - - base = reverse ? max - size : min; - r2 = reverse ? NULL : r; - - for( ;; ) { - if( !reverse ) { - base = (base + align - 1) & ~(align-1); - if( base < min ) - base = min; - if( base + size - 1 >= max -1 ) - break; - } else { - if( base > max - size ) - base = max - size; - base -= base & (align-1); - } - if( is_free( base, size, r ) ) - return base; - - if( !reverse ) { - if( !r2 ) - break; - base = r2->start + r2->size; - r2 = r2->next; - } else { - range_t *rp; - - for( rp=r; rp && rp->next != r2 ; rp=rp->next ) { - } - - r2 = rp; - if( !r2 ) - break; - base = r2->start - size; - } - } - return (ucell)-1; -} - -static ucell ofmem_claim_phys_( ucell phys, ucell size, ucell align, - ucell min, ucell max, int reverse ) -{ - ofmem_t *ofmem = OFMEM; - if( !align ) { - if( !is_free( phys, size, ofmem->phys_range ) ) { - printk("Non-free physical memory claimed!\n"); - return -1; - } - add_entry( phys, size, &ofmem->phys_range ); - return phys; - } - phys = find_area( align, size, ofmem->phys_range, min, max, reverse ); - if( phys == (ucell)-1 ) { - printk("ofmem->claim_phys - out of space\n"); - return -1; - } - add_entry( phys, size, &ofmem->phys_range ); - - ofmem_update_translations(); - - return phys; -} - -/* if align != 0, phys is ignored. Returns -1 on error */ -ucell ofmem_claim_phys( ucell phys, ucell size, ucell align ) -{ - /* printk("+ ofmem_claim phys %08lx %lx %ld\n", phys, size, align ); */ - return ofmem_claim_phys_( phys, size, align, 0, get_ram_size(), 0 ); -} - -static ucell ofmem_claim_virt_( ucell virt, ucell size, ucell align, - ucell min, ucell max, int reverse ) -{ - ofmem_t *ofmem = OFMEM; - if( !align ) { - if( !is_free( virt, size, ofmem->virt_range ) ) { - printk("Non-free physical memory claimed!\n"); - return -1; - } - add_entry( virt, size, &ofmem->virt_range ); - return virt; - } - - virt = find_area( align, size, ofmem->virt_range, min, max, reverse ); - if( virt == -1UL ) { - printk("ofmem_claim_virt - out of space\n"); - return -1UL; - } - add_entry( virt, size, &ofmem->virt_range ); - return virt; -} - -ucell ofmem_claim_virt( ucell virt, ucell size, ucell align ) -{ - /* printk("+ ofmem_claim virt %08lx %lx %ld\n", virt, size, align ); */ - return ofmem_claim_virt_( virt, size, align, get_ram_size(), (ucell)TOP_OF_RAM, 0 ); -} - - -/* allocate both physical and virtual space and add a translation */ -ucell ofmem_claim( ucell addr, ucell size, ucell align ) -{ - ofmem_t *ofmem = OFMEM; - ucell virt, phys; - ucell offs = addr & 0xfff; - - /* printk("+ ofmem_claim %08lx %lx %ld\n", addr, size, align ); */ - virt = phys = 0; - if( !align ) { - if( is_free(addr, size, ofmem->virt_range) && - is_free(addr, size, ofmem->phys_range) ) { - ofmem_claim_phys_( addr, size, 0, 0, 0, 0 ); - ofmem_claim_virt_( addr, size, 0, 0, 0, 0 ); - virt = phys = addr; - } else { - /* printk("**** ofmem_claim failure ***!\n"); */ - return -1; - } - } else { - if( align < 0x1000 ) - align = 0x1000; - phys = ofmem_claim_phys_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); - virt = ofmem_claim_virt_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); - if( phys == (ucell)-1 || virt == (ucell)-1 ) { - printk("ofmem_claim failed\n"); - return -1; - } - /* printk("...phys = %08lX, virt = %08lX, size = %08lX\n", phys, virt, size ); */ - } - - /* align */ - if( phys & 0xfff ) { - size += (phys & 0xfff); - virt -= (phys & 0xfff); - phys &= ~0xfff; - } - if( size & 0xfff ) - size = (size + 0xfff) & ~0xfff; - - /* printk("...free memory found... phys: %08lX, virt: %08lX, size %lX\n", phys, virt, size ); */ - ofmem_map( phys, virt, size, -1 ); - return virt + offs; -} - - -/************************************************************************/ -/* keep track of ea -> phys translations */ -/************************************************************************/ - -static void split_trans( ucell virt ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t, *t2; - - for( t=ofmem->trans; t; t=t->next ) { - if( virt > t->virt && virt < t->virt + t->size-1 ) { - t2 = (translation_t*)malloc( sizeof(translation_t) ); - t2->virt = virt; - t2->size = t->size - (virt - t->virt); - t->size = virt - t->virt; - t2->phys = t->phys + t->size; - t2->mode = t->mode; - t2->next = t->next; - t->next = t2; - } - } -} - -static int map_page_range( ucell phys, ucell virt, ucell size, ucell mode ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t, **tt; - - OFMEM_TRACE("map_page_range " FMT_ucellx - " -> " FMT_ucellx " " FMT_ucellx " mode " FMT_ucellx "\n", - virt, phys, size, mode ); - - split_trans( virt ); - split_trans( virt + size ); - - /* detect remappings */ - for( t=ofmem->trans; t; ) { - if( virt == t->virt || (virt < t->virt && virt + size > t->virt )) { - if( t->phys + virt - t->virt != phys ) { - OFMEM_TRACE("mapping altered virt=" FMT_ucellx ")\n", t->virt ); - } else if( t->mode != mode ){ - OFMEM_TRACE("mapping mode altered virt=" FMT_ucellx - " old mode=" FMT_ucellx " new mode=" FMT_ucellx "\n", - t->virt, t->mode, mode); - } - - for( tt=&ofmem->trans; *tt != t ; tt=&(**tt).next ) { - } - - *tt = t->next; - - /* really unmap these pages */ - ofmem_unmap_pages(t->virt, t->size); - - free((char*)t); - - t=ofmem->trans; - continue; - } - t=t->next; - } - - /* add mapping */ - for( tt=&ofmem->trans; *tt && (**tt).virt < virt ; tt=&(**tt).next ) { - } - - t = (translation_t*)malloc( sizeof(translation_t) ); - t->virt = virt; - t->phys = phys; - t->size = size; - t->mode = mode; - t->next = *tt; - *tt = t; - - ofmem_update_translations(); - - return 0; -} - -static int unmap_page_range( ucell virt, ucell size ) -{ - ofmem_t *ofmem = OFMEM; - translation_t **plink; - - /* make sure there is exactly one matching translation entry */ - - split_trans( virt ); - split_trans( virt + size ); - - /* find and unlink entries in range */ - plink = &ofmem->trans; - - while (*plink && (*plink)->virt < virt+size) { - translation_t **plinkentry = plink; - translation_t *t = *plink; - - /* move ahead */ - plink = &t->next; - - if (t->virt >= virt && t->virt + t->size <= virt+size) { - - /* unlink entry */ - *plinkentry = t->next; - - printk("unmap_page_range found " FMT_ucellx - " -> " FMT_ucellx " " FMT_ucellx " mode " FMT_ucellx "\n", - t->virt, t->phys, t->size, t->mode ); - - // really map these pages - ofmem_unmap_pages(t->virt, t->size); - - free((char*)t); - } - } - - ofmem_update_translations(); - - return 0; -} - -int ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ) -{ - /* printk("+ofmem_map: %08lX --> %08lX (size %08lX, mode 0x%02X)\n", - virt, phys, size, mode ); */ - - if( (phys & 0xfff) || (virt & 0xfff) || (size & 0xfff) ) { - /* printk("ofmem_map: Bad parameters (%08lX %08lX %08lX)\n", - phys, virt, size ); */ - phys &= ~0xfff; - virt &= ~0xfff; - size = (size + 0xfff) & ~0xfff; - } - - if (mode==-1) { - mode = def_memmode(phys); - } - - // install translations - map_page_range(phys, virt, size, mode); - - if (mode & SPITFIRE_TTE_LOCKED) { - // install locked tlb entries now - ofmem_map_pages(phys, virt, size, mode); - } - - return 0; -} - -int ofmem_unmap( ucell virt, ucell size ) -{ - OFMEM_TRACE("ofmem_unmap " FMT_ucellx " " FMT_ucellx "\n", - virt, size ); - - if( (virt & 0xfff) || (size & 0xfff) ) { - /* printk("ofmem_unmap: Bad parameters (%08lX %08lX)\n", - virt, size ); */ - virt &= ~0xfff; - size = (size + 0xfff) & ~0xfff; - } - - /* remove translations and unmap pages */ - unmap_page_range(virt, size); - - return 0; -} - -/* virtual -> physical. */ -ucell ofmem_translate( ucell virt, ucell *mode ) -{ - ofmem_t *ofmem = OFMEM; - translation_t *t; - - for( t=ofmem->trans; t && t->virt <= virt ; t=t->next ) { - ucell offs; - if( t->virt + t->size - 1 < virt ) - continue; - offs = virt - t->virt; - *mode = t->mode; - return t->phys + offs; - } - - /*printk("ofmem_translate: no translation defined (%08lx)\n", virt);*/ - /*print_trans();*/ - return -1UL; -} - -/* release memory allocated by ofmem_claim */ -void ofmem_release( ucell virt, ucell size ) -{ - printk("ofmem_release unimplemented (" FMT_ucellx ", " FMT_ucellx ")\n", - virt, size ); -}
/************************************************************************/ @@ -636,12 +83,12 @@ extern uint64_t qemu_mem_size;
static int remap_page_range( ucell phys, ucell virt, ucell size, ucell mode ) { - map_page_range(phys, virt, size, mode); + ofmem_map_page_range(phys, virt, size, mode); if (!(mode & SPITFIRE_TTE_LOCKED)) { OFMEM_TRACE("remap_page_range clearing translation " FMT_ucellx " -> " FMT_ucellx " " FMT_ucellx " mode " FMT_ucellx "\n", virt, phys, size, mode ); - ofmem_unmap_pages(virt, size); + ofmem_arch_unmap_pages(virt, size); } return 0; } @@ -655,10 +102,3 @@ void ofmem_init( void ) ofmem_walk_boot_map(remap_page_range); }
-void ofmem_register( phandle_t ph_memory, phandle_t ph_mmu ) -{ - s_phandle_memory = ph_memory; - s_phandle_mmu = ph_mmu; - - ofmem_update_translations(); -} Index: openbios-devel/arch/sparc64/ofmem_sparc64.h =================================================================== --- openbios-devel.orig/arch/sparc64/ofmem_sparc64.h +++ openbios-devel/arch/sparc64/ofmem_sparc64.h @@ -16,54 +16,13 @@
#include "ofmem.h"
-extern void* ofmem_malloc( size_t size ); -extern void ofmem_free( void *ptr ); -extern void* ofmem_realloc( void *ptr, size_t size ); - -extern int ofmem_unmap(ucell virt, ucell size); - -ulong get_ram_size( void ); -ulong get_ram_top( void ); -ulong get_ram_bottom( void ); -extern void ofmem_register( phandle_t ph_memory, phandle_t ph_mmu ); extern void ofmem_map_pages(ucell phys, ucell virt, ucell size, ucell mode); -extern void ofmem_unmap_pages(ucell virt, ucell size);
typedef int (*translation_entry_cb)(ucell phys, ucell virt, ucell size, ucell mode);
extern void ofmem_walk_boot_map(translation_entry_cb cb);
-typedef struct alloc_desc { - struct alloc_desc *next; - ucell size; /* size (including) this struct */ -} alloc_desc_t; - -typedef struct mem_range { - struct mem_range *next; - ucell start; - ucell size; -} range_t; - -typedef struct trans { - struct trans *next; - ucell virt; /* chain is sorted by virt */ - ucell size; - ucell phys; - ucell mode; -} translation_t; - -typedef struct { - uint64_t ramsize; - char *next_malloc; - 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_t; - extern translation_t **g_ofmem_translations;
#endif /* _H_OFMEM_SPARC64 */ Index: openbios-devel/include/ofmem.h =================================================================== --- openbios-devel.orig/include/ofmem.h +++ openbios-devel/include/ofmem.h @@ -17,25 +17,88 @@ #ifndef _H_OFMEM #define _H_OFMEM
-extern void ofmem_cleanup( void ); -extern void ofmem_init( void ); +#include "openbios/stack.h" + +typedef struct alloc_desc { + struct alloc_desc *next; + ucell size; /* size (including) this struct */ +} alloc_desc_t; + +typedef struct mem_range { + struct mem_range *next; + ucell start; + ucell size; +} range_t; + +typedef struct trans { + struct trans *next; + ucell virt; /* chain is sorted by virt */ + ucell size; + ucell phys; + ucell mode; +} translation_t; + +/* ofmem private data */ +typedef struct { + ucell ramsize; + char *next_malloc; + 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_t; + +/* TODO: temporary migration interface */ +extern ofmem_t* ofmem_arch_get_private(void); +extern void* ofmem_arch_get_malloc_base(void); +extern ucell ofmem_arch_get_heap_top(void); +extern ucell ofmem_arch_get_virt_top(void); +extern ucell ofmem_arch_default_translation_mode( ucell phys ); +extern void ofmem_arch_early_map_pages(ucell phys, ucell virt, ucell size, + ucell mode); +extern void ofmem_arch_unmap_pages(ucell virt, ucell size); +/* sparc64 uses this method */ +extern int ofmem_map_page_range( ucell phys, ucell virt, ucell size, + ucell mode ); + +/* malloc interface */ +extern void* ofmem_malloc( size_t size ); +extern void ofmem_free( void *ptr ); +extern void* ofmem_realloc( void *ptr, size_t size );
-extern ucell ofmem_claim( ucell addr, ucell size, ucell align ); -extern ucell ofmem_claim_phys( ucell mphys, ucell size, ucell align ); -extern ucell ofmem_claim_virt( ucell mvirt, ucell size, ucell align ); +/* ofmem_common.c */
-extern int ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ); +extern void ofmem_cleanup( void ); +extern void ofmem_init( void );
-extern void ofmem_release( ucell virt, ucell size ); -extern ucell ofmem_translate( ucell virt, ucell *ret_mode ); +/* + * register /memory and /virtual-memory handles + * ofmem module will update "available" and "translations" properties + * using these handles + * + * to disable updating /memory properties pass zero memory handle + */ +extern void ofmem_register( phandle_t ph_memory, phandle_t ph_mmu ); + +extern ucell ofmem_claim( ucell addr, ucell size, ucell align ); +extern ucell ofmem_claim_phys( ucell mphys, ucell size, ucell align ); +extern ucell ofmem_claim_virt( ucell mvirt, ucell size, ucell align ); + +extern int ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ); +extern int ofmem_unmap( ucell virt, ucell size ); + +extern void ofmem_release_phys( ucell phys, ucell size ); +extern void ofmem_release_virt( ucell virt, ucell size ); +extern ucell ofmem_translate( ucell virt, ucell *ret_mode );
#ifdef CONFIG_PPC #define PAGE_SHIFT 12
-ulong get_ram_size( void ); ulong get_ram_top( void ); ulong get_ram_bottom( void ); -void ofmem_register( phandle_t ph ); + #elif defined(CONFIG_SPARC32) #define PAGE_SHIFT 12
Index: openbios-devel/modules/build.xml =================================================================== --- openbios-devel.orig/modules/build.xml +++ openbios-devel/modules/build.xml @@ -23,6 +23,7 @@ <object source="sun-parts.c" condition="SUN_PARTS"/> <object source="font_8x8.c" condition="FONT_8X8"/> <object source="font_8x16.c" condition="FONT_8X16"/> + <object source="ofmem_common.c" condition="OFMEM"/> </library>
<dictionary name="openbios" target="forth"> Index: openbios-devel/modules/ofmem_common.c =================================================================== --- /dev/null +++ openbios-devel/modules/ofmem_common.c @@ -0,0 +1,725 @@ +/* + * <ofmem_sparc64.c> + * + * OF Memory manager + * + * Copyright (C) 1999-2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "openbios/config.h" +#include "openbios/bindings.h" +#include "ofmem.h" + +/* + * define OFMEM_FILL_RANGE to claim any unclaimed virtual and + * physical memory in the range for ofmem_map + * + * TODO: remove this macro and wrapped code if not needed by implementations + */ +//#define OFMEM_FILL_RANGE + + +static inline size_t ALIGN_SIZE(size_t x, size_t a) +{ + return (x + a - 1) & ~(a-1); +} + +static ucell get_ram_size( void ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + return ofmem->ramsize; +} + +/************************************************************************/ +/* debug */ +/************************************************************************/ + +#if 0 +static void +print_range( range_t *r, char *str ) +{ + printk("--- Range %s ---\n", str ); + for( ; r; r=r->next ) + printk("%08lx - %08lx\n", r->start, r->start + r->size -1 ); + printk("\n"); +} + +static void +print_phys_range() +{ + print_range( ofmem.phys_range, "phys" ); +} + +static void +print_virt_range() +{ + print_range( ofmem.virt_range, "virt" ); +} + +static void +print_trans( void ) +{ + translation_t *t = ofmem.trans; + + printk("--- Translations ---\n"); + for( ; t; t=t->next ) + printk("%08lx -> %08lx [size %lx]\n", t->virt, t->phys, t->size ); + printk("\n"); +} +#endif + +/************************************************************************/ +/* OF private allocations */ +/************************************************************************/ + +void* ofmem_malloc( size_t size ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + alloc_desc_t *d, **pp; + char *ret; + ucell top; + + if( !size ) + return NULL; + + if( !ofmem->next_malloc ) + ofmem->next_malloc = (char*)ofmem_arch_get_malloc_base(); + + size = ALIGN_SIZE(size + sizeof(alloc_desc_t), CONFIG_OFMEM_MALLOC_ALIGN); + + /* 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; + return ret; + } + + top = ofmem_arch_get_heap_top(); + + if( (ucell)ofmem->next_malloc + size > top ) { + OFMEM_TRACE("out of malloc memory (%x)!\n", size ); + return NULL; + } + + d = (alloc_desc_t*) ofmem->next_malloc; + ofmem->next_malloc += size; + + d->next = NULL; + d->size = size; + + ret = (char*)d + sizeof(alloc_desc_t); + memset( ret, 0, size - sizeof(alloc_desc_t) ); + + return ret; +} + +void ofmem_free( void *ptr ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + alloc_desc_t **pp, *d; + + /* it is legal to free NULL pointers (size zero allocations) */ + if( !ptr ) + return; + + d = (alloc_desc_t*)((char *)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; +} + +void* ofmem_realloc( void *ptr, size_t size ) +{ + alloc_desc_t *d = (alloc_desc_t*)((char *)ptr - sizeof(alloc_desc_t)); + char *p; + + 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; +} + + +/************************************************************************/ +/* "translations" and "available" property tracking */ +/************************************************************************/ + +static phandle_t s_phandle_memory = 0; +static phandle_t s_phandle_mmu = 0; + +static void ofmem_update_mmu_translations( void ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + translation_t *t; + int ncells; + ucell *props; + + if (s_phandle_mmu == 0) + return; + + for( t = ofmem->trans, ncells = 0; t ; t=t->next, ncells++ ) { + } + + props = malloc(ncells * sizeof(ucell) * 3); + + if (props == NULL) + return; + + for( t = ofmem->trans, ncells = 0 ; t ; t=t->next ) { + props[ncells++] = t->virt; + props[ncells++] = t->size; + props[ncells++] = t->mode; + } + + set_property(s_phandle_mmu, "translations", + (char*)props, ncells * sizeof(props[0])); + + free(props); +} + +static void ofmem_update_memory_available( phandle_t ph, range_t *range, + u64 top_address ) +{ + range_t *r; + int ncells; + ucell *props; + + ucell start, size; + + if (s_phandle_memory == 0) + return; + + /* count phys_range list entries */ + for( r = range, ncells = 0; r ; r=r->next, ncells++ ) { + } + + /* inverse of phys_range list could take 2 more cells for the tail */ + props = malloc((ncells+1) * sizeof(ucell) * 2); + + if (props == NULL) { + /* out of memory! */ + return; + } + + start = 0; + ncells = 0; + + for (r = range; r; r=r->next) { + if (r->start >= top_address) { + break; + } + + size = r->start - start; + if (size) { + props[ncells++] = start; + props[ncells++] = size; + } + start = r->start + r->size; + } + + /* tail */ + if (start < top_address) { + props[ncells++] = start; + props[ncells++] = top_address - start; + } + + set_property(ph, "available", + (char*)props, ncells * sizeof(props[0])); + + free(props); +} + +static void ofmem_update_translations( void ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + + ofmem_update_memory_available(s_phandle_memory, + ofmem->phys_range, get_ram_size()); + ofmem_update_memory_available(s_phandle_mmu, + ofmem->virt_range, -1ULL); + ofmem_update_mmu_translations(); +} + + +/************************************************************************/ +/* client interface */ +/************************************************************************/ + +static int is_free( ucell ea, ucell size, range_t *r ) +{ + if( size == 0 ) + return 1; + for( ; r ; r=r->next ) { + if( r->start + r->size - 1 >= ea && r->start <= ea ) + return 0; + if( r->start >= ea && r->start <= ea + size - 1 ) + return 0; + } + return 1; +} + +static void add_entry_( ucell ea, ucell size, range_t **r ) +{ + range_t *nr; + + for( ; *r && (**r).start < ea; r=&(**r).next ) { + } + + nr = (range_t*)malloc( sizeof(range_t) ); + nr->next = *r; + nr->start = ea; + nr->size = size; + *r = nr; +} + +static int add_entry( ucell ea, ucell size, range_t **r ) +{ + if( !is_free( ea, size, *r ) ) { + OFMEM_TRACE("add_entry: range not free!\n"); + return -1; + } + add_entry_( ea, size, r ); + return 0; +} + +#if defined(OFMEM_FILL_RANGE) +static void join_ranges( range_t **rr ) +{ + range_t *n, *r = *rr; + while( r ) { + if( !(n=r->next) ) + break; + + if( r->start + r->size - 1 >= n->start -1 ) { + int s = n->size + (n->start - r->start - r->size); + if( s > 0 ) + r->size += s; + r->next = n->next; + free( n ); + continue; + } + r=r->next; + } +} + +static void fill_range( ucell ea, ucell size, range_t **rr ) +{ + add_entry_( ea, size, rr ); + join_ranges( rr ); +} +#endif + +static ucell find_area( ucell align, ucell size, range_t *r, + ucell min, ucell max, int reverse ) +{ + ucell base = min; + range_t *r2; + + if( (align & (align-1)) ) { + OFMEM_TRACE("bad alignment " FMT_ucell "\n", align); + align = 0x1000; + } + if( !align ) + align = 0x1000; + + base = reverse ? max - size : min; + r2 = reverse ? NULL : r; + + for( ;; ) { + if( !reverse ) { + base = (base + align - 1) & ~(align-1); + if( base < min ) + base = min; + if( base + size - 1 >= max -1 ) + break; + } else { + if( base > max - size ) + base = max - size; + base -= base & (align-1); + } + if( is_free( base, size, r ) ) + return base; + + if( !reverse ) { + if( !r2 ) + break; + base = r2->start + r2->size; + r2 = r2->next; + } else { + range_t *rp; + + for( rp=r; rp && rp->next != r2 ; rp=rp->next ) { + } + + r2 = rp; + if( !r2 ) + break; + base = r2->start - size; + } + } + return -1; +} + +static ucell ofmem_claim_phys_( ucell phys, ucell size, ucell align, + ucell min, ucell max, int reverse ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + if( !align ) { + if( !is_free( phys, size, ofmem->phys_range ) ) { + OFMEM_TRACE("Non-free physical memory claimed!\n"); + return -1; + } + add_entry( phys, size, &ofmem->phys_range ); + return phys; + } + phys = find_area( align, size, ofmem->phys_range, min, max, reverse ); + if( phys == -1 ) { + OFMEM_TRACE("ofmem_claim_phys - out of space\n"); + return -1; + } + add_entry( phys, size, &ofmem->phys_range ); + + ofmem_update_translations(); + + return phys; +} + +/* if align != 0, phys is ignored. Returns -1 on error */ +ucell ofmem_claim_phys( ucell phys, ucell size, ucell align ) +{ + OFMEM_TRACE("ofmem_claim phys=" FMT_ucellx " size=" FMT_ucellx + " align=" FMT_ucellx "\n", + phys, size, align); + + return ofmem_claim_phys_( phys, size, align, 0, get_ram_size(), 0 ); +} + +static ucell ofmem_claim_virt_( ucell virt, ucell size, ucell align, + ucell min, ucell max, int reverse ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + if( !align ) { + if( !is_free( virt, size, ofmem->virt_range ) ) { + OFMEM_TRACE("Non-free virtual memory claimed!\n"); + return -1; + } + add_entry( virt, size, &ofmem->virt_range ); + return virt; + } + + virt = find_area( align, size, ofmem->virt_range, min, max, reverse ); + if( virt == -1 ) { + OFMEM_TRACE("ofmem_claim_virt - out of space\n"); + return -1; + } + add_entry( virt, size, &ofmem->virt_range ); + return virt; +} + +ucell ofmem_claim_virt( ucell virt, ucell size, ucell align ) +{ + OFMEM_TRACE("ofmem_claim_virt virt=" FMT_ucellx " size=" FMT_ucellx + " align=" FMT_ucellx "\n", + virt, size, align); + + /* printk("+ ofmem_claim virt %08lx %lx %ld\n", virt, size, align ); */ + return ofmem_claim_virt_( virt, size, align, + get_ram_size(), ofmem_arch_get_virt_top(), 0 ); +} + + +/* allocate both physical and virtual space and add a translation */ +ucell ofmem_claim( ucell addr, ucell size, ucell align ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + ucell virt, phys; + ucell offs = addr & 0xfff; + + /* printk("+ ofmem_claim %08lx %lx %ld\n", addr, size, align ); */ + virt = phys = 0; + if( !align ) { + if( is_free(addr, size, ofmem->virt_range) && + is_free(addr, size, ofmem->phys_range) ) { + ofmem_claim_phys_( addr, size, 0, 0, 0, 0 ); + ofmem_claim_virt_( addr, size, 0, 0, 0, 0 ); + virt = phys = addr; + } else { + OFMEM_TRACE("**** ofmem_claim failure ***!\n"); + return -1; + } + } else { + if( align < 0x1000 ) + align = 0x1000; + phys = ofmem_claim_phys_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); + virt = ofmem_claim_virt_( addr, size, align, 0, get_ram_size(), 1 /* reverse */ ); + if( phys == -1 || virt == -1 ) { + OFMEM_TRACE("ofmem_claim failed\n"); + return -1; + } + /* printk("...phys = %08lX, virt = %08lX, size = %08lX\n", phys, virt, size ); */ + } + + /* align */ + if( phys & 0xfff ) { + size += (phys & 0xfff); + virt -= (phys & 0xfff); + phys &= ~0xfff; + } + if( size & 0xfff ) + size = (size + 0xfff) & ~0xfff; + + /* printk("...free memory found... phys: %08lX, virt: %08lX, size %lX\n", phys, virt, size ); */ + ofmem_map( phys, virt, size, -1 ); + return virt + offs; +} + + +/************************************************************************/ +/* keep track of ea -> phys translations */ +/************************************************************************/ + +static void split_trans( ucell virt ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + translation_t *t, *t2; + + for( t=ofmem->trans; t; t=t->next ) { + if( virt > t->virt && virt < t->virt + t->size-1 ) { + t2 = (translation_t*)malloc( sizeof(translation_t) ); + t2->virt = virt; + t2->size = t->size - (virt - t->virt); + t->size = virt - t->virt; + t2->phys = t->phys + t->size; + t2->mode = t->mode; + t2->next = t->next; + t->next = t2; + } + } +} + +int ofmem_map_page_range( ucell phys, ucell virt, ucell size, ucell mode ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + translation_t *t, **tt; + + OFMEM_TRACE("ofmem_map_page_range " FMT_ucellx + " -> " FMT_ucellx " " FMT_ucellx " mode " FMT_ucellx "\n", + virt, phys, size, mode ); + + split_trans( virt ); + split_trans( virt + size ); + + /* detect remappings */ + for( t=ofmem->trans; t; ) { + if( virt == t->virt || (virt < t->virt && virt + size > t->virt )) { + if( t->phys + virt - t->virt != phys ) { + OFMEM_TRACE("mapping altered virt=" FMT_ucellx ")\n", t->virt ); + } else if( t->mode != mode ){ + OFMEM_TRACE("mapping mode altered virt=" FMT_ucellx + " old mode=" FMT_ucellx " new mode=" FMT_ucellx "\n", + t->virt, t->mode, mode); + } + + for( tt=&ofmem->trans; *tt != t ; tt=&(**tt).next ) { + } + + *tt = t->next; + + /* really unmap these pages */ + ofmem_arch_unmap_pages(t->virt, t->size); + + free((char*)t); + + t=ofmem->trans; + continue; + } + t=t->next; + } + + /* add mapping */ + for( tt=&ofmem->trans; *tt && (**tt).virt < virt ; tt=&(**tt).next ) { + } + + t = (translation_t*)malloc( sizeof(translation_t) ); + t->virt = virt; + t->phys = phys; + t->size = size; + t->mode = mode; + t->next = *tt; + *tt = t; + + ofmem_update_translations(); + + return 0; +} + +static int unmap_page_range( ucell virt, ucell size ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + translation_t **plink; + + /* make sure there is exactly one matching translation entry */ + + split_trans( virt ); + split_trans( virt + size ); + + /* find and unlink entries in range */ + plink = &ofmem->trans; + + while (*plink && (*plink)->virt < virt+size) { + translation_t **plinkentry = plink; + translation_t *t = *plink; + + /* move ahead */ + plink = &t->next; + + if (t->virt >= virt && t->virt + t->size <= virt+size) { + + /* unlink entry */ + *plinkentry = t->next; + + OFMEM_TRACE("unmap_page_range found " + FMT_ucellx " -> " FMT_ucellx " " FMT_ucellx + " mode " FMT_ucellx "\n", + t->virt, t->phys, t->size, t->mode ); + + // really map these pages + ofmem_arch_unmap_pages(t->virt, t->size); + + free((char*)t); + } + } + + ofmem_update_translations(); + + return 0; +} + +int ofmem_map( ucell phys, ucell virt, ucell size, ucell mode ) +{ + /* printk("+ofmem_map: %08lX --> %08lX (size %08lX, mode 0x%02X)\n", + virt, phys, size, mode ); */ + + if( (phys & 0xfff) || (virt & 0xfff) || (size & 0xfff) ) { + + OFMEM_TRACE("ofmem_map: Bad parameters (" + FMT_ucellX " " FMT_ucellX " " FMT_ucellX ")\n", + phys, virt, size ); + + phys &= ~0xfff; + virt &= ~0xfff; + size = (size + 0xfff) & ~0xfff; + } + +#if defined(OFMEM_FILL_RANGE) + { + ofmem_t *ofmem = ofmem_arch_get_private(); + /* claim any unclaimed virtual memory in the range */ + fill_range( virt, size, &ofmem->virt_range ); + /* hmm... we better claim the physical range too */ + fill_range( phys, size, &ofmem->phys_range ); + } +#endif + + if (mode==-1) { + mode = ofmem_arch_default_translation_mode(phys); + } + + /* install translations */ + ofmem_map_page_range(phys, virt, size, mode); + + /* allow arch to install mappings early, e.g. for locked mappings */ + ofmem_arch_early_map_pages(phys, virt, size, mode); + + return 0; +} + +int ofmem_unmap( ucell virt, ucell size ) +{ + OFMEM_TRACE("ofmem_unmap " FMT_ucellx " " FMT_ucellx "\n", + virt, size ); + + if( (virt & 0xfff) || (size & 0xfff) ) { + /* printk("ofmem_unmap: Bad parameters (%08lX %08lX)\n", + virt, size ); */ + virt &= ~0xfff; + size = (size + 0xfff) & ~0xfff; + } + + /* remove translations and unmap pages */ + unmap_page_range(virt, size); + + return 0; +} + +/* virtual -> physical. */ +ucell ofmem_translate( ucell virt, ucell *mode ) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + translation_t *t; + + for( t=ofmem->trans; t && t->virt <= virt ; t=t->next ) { + ucell offs; + if( t->virt + t->size - 1 < virt ) + continue; + offs = virt - t->virt; + *mode = t->mode; + return t->phys + offs; + } + + /*printk("ofmem_translate: no translation defined (%08lx)\n", virt);*/ + /*print_trans();*/ + return -1; +} + +/* release memory allocated by ofmem_claim_phys */ +void ofmem_release_phys( ucell phys, ucell size ) +{ + OFMEM_TRACE("ofmem_release_phys addr=" FMT_ucellx " size=" FMT_ucellx "\n", + phys, size); + + OFMEM_TRACE("ofmem_release_phys not implemented"); +} + +/* release memory allocated by ofmem_claim_virt */ +void ofmem_release_virt( ucell virt, ucell size ) +{ + OFMEM_TRACE("ofmem_release_virt addr=" FMT_ucellx " size=" FMT_ucellx "\n", + virt, size); + + OFMEM_TRACE("ofmem_release_virt not implemented"); +} + +/************************************************************************/ +/* init / cleanup */ +/************************************************************************/ + +void ofmem_register( phandle_t ph_memory, phandle_t ph_mmu ) +{ + s_phandle_memory = ph_memory; + s_phandle_mmu = ph_mmu; + + ofmem_update_translations(); +} Index: openbios-devel/config/examples/cross-sparc64_config.xml =================================================================== --- openbios-devel.orig/config/examples/cross-sparc64_config.xml +++ openbios-devel/config/examples/cross-sparc64_config.xml @@ -38,6 +38,8 @@ <option name="CONFIG_DEBLOCKER" type="boolean" value="true"/> <option name="CONFIG_FONT_8X8" type="boolean" value="true"/> <option name="CONFIG_FONT_8X16" type="boolean" value="false"/> + <option name="CONFIG_OFMEM" type="boolean" value="true"/> + <option name="CONFIG_OFMEM_MALLOC_ALIGN" type="integer" value="8"/>
<!-- Filesystem Configuration --> <option name="CONFIG_DISK_LABEL" type="boolean" value="true"/> Index: openbios-devel/arch/sparc32/lib.c =================================================================== --- openbios-devel.orig/arch/sparc32/lib.c +++ openbios-devel/arch/sparc32/lib.c @@ -68,25 +68,6 @@ struct linux_mlist_v0 *ptphys; struct linux_mlist_v0 *ptmap; struct linux_mlist_v0 *ptavail;
-typedef struct alloc_desc { - struct alloc_desc *next; - int size; /* size (including) this struct */ -} alloc_desc_t; - -typedef struct mem_range { - struct mem_range *next; - ulong start; - ulong size; -} range_t; - -typedef struct trans { - struct trans *next; - ulong virt; /* chain is sorted by virt */ - ulong size; - ulong phys; - int mode; -} translation_t; - static struct { char *next_malloc; int left; Index: openbios-devel/config/examples/cross-ppc_config.xml =================================================================== --- openbios-devel.orig/config/examples/cross-ppc_config.xml +++ openbios-devel/config/examples/cross-ppc_config.xml @@ -35,6 +35,8 @@ <option name="CONFIG_DEBLOCKER" type="boolean" value="true"/> <option name="CONFIG_FONT_8X8" type="boolean" value="true"/> <option name="CONFIG_FONT_8X16" type="boolean" value="false"/> + <option name="CONFIG_OFMEM" type="boolean" value="true"/> + <option name="CONFIG_OFMEM_MALLOC_ALIGN" type="integer" value="4"/>
<!-- Filesystem Configuration --> <option name="CONFIG_DISK_LABEL" type="boolean" value="true"/> Index: openbios-devel/arch/sparc64/lib.c =================================================================== --- openbios-devel.orig/arch/sparc64/lib.c +++ openbios-devel/arch/sparc64/lib.c @@ -298,11 +298,19 @@ unmap_pages(ucell virt, ucell size) } }
-void ofmem_unmap_pages(ucell virt, ucell size) +void ofmem_arch_unmap_pages(ucell virt, ucell size) { unmap_pages(virt, size); }
+void ofmem_arch_early_map_pages(ucell phys, ucell virt, ucell size, ucell mode) +{ + if (mode & SPITFIRE_TTE_LOCKED) { + // install locked tlb entries now + ofmem_map_pages(phys, virt, size, mode); + } +} + /* 3.6.5 unmap ( virt size -- ) @@ -332,14 +340,8 @@ mmu_claim(void) virt = POP(); }
- printk("claim virt=" FMT_ucellx " size=" FMT_ucellx " align=" FMT_ucellx - "\n", - virt, size, align); - virt = ofmem_claim_virt(virt, size, align);
- printk("claimed virt=" FMT_ucellx "\n", virt); - PUSH(virt); }
@@ -354,9 +356,8 @@ mmu_release(void)
size = POP(); virt = POP(); - printk("release virt=" FMT_ucellx " size=" FMT_ucellx "\n", virt, size);
- ofmem_release(virt, size); + ofmem_release_virt(virt, size); }
/* ( phys size align --- base ) */ @@ -373,14 +374,8 @@ mem_claim( void ) phys |= POP(); }
- printk("mem_claim phys=" FMT_ucellx " size=" FMT_ucellx - " align=" FMT_ucellx "\n", - phys, size, align); - phys = ofmem_claim_phys(phys, size, align);
- printk("ofmem_claim_phys result phys=" FMT_ucellx "\n", phys); - ofmem_map(phys, phys, size, -1);
PUSH(phys >> 32); @@ -395,9 +390,8 @@ mem_release( void )
size = POP(); phys = POP(); - printk("release virt=" FMT_ucellx " size=" FMT_ucellx "\n", phys, size);
- ofmem_release(phys, size); + ofmem_release_phys(phys, size); }
DECLARE_NODE(memory, INSTALL_OPEN, 0, "/memory"); Index: openbios-devel/arch/ppc/qemu/init.c =================================================================== --- openbios-devel.orig/arch/ppc/qemu/init.c +++ openbios-devel/arch/ppc/qemu/init.c @@ -451,6 +451,8 @@ arch_of_init( void ) const char *stdin_path, *stdout_path; uint32_t temp = 0;
+ ofmem_t *ofmem = ofmem_arch_get_private(); + modules_init(); setup_timers(); #ifdef CONFIG_DRIVER_PCI @@ -472,7 +474,7 @@ arch_of_init( void )
printk("CPUs: %x\n", temp);
- ram_size = get_ram_size(); + ram_size = ofmem->ramsize;
printk("Memory: %lldM\n", ram_size / 1024 / 1024);
@@ -619,7 +621,7 @@ arch_of_init( void ) printk("CPU type %s\n", cpu->name);
snprintf(buf, sizeof(buf), "/cpus/%s", cpu->name); - ofmem_register(find_dev(buf)); + ofmem_register(0, find_dev(buf)); node_methods_init(buf);
#ifdef USE_RTAS
On Sun, Aug 2, 2009 at 11:54 AM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
Hi!
This patch series moves OF memory manager code to separate module. New OFMEM module is used by sparc64 and all ppc configurations.
Since ppc briq/mol/pearpc are not buildable for years I used local build hack to verify this change does not make those even worse.
Boot-tested on sparc64 and ppc/qemu.
The patches look OK, but for some reason some of the topmost lines are missing as well as 8/8: http://www.openfirmware.info/pipermail/openbios/2009-August/date.html
On Sun, Aug 2, 2009 at 1:30 PM, Blue Swirlblauwirbel@gmail.com wrote:
On Sun, Aug 2, 2009 at 11:54 AM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
Hi!
This patch series moves OF memory manager code to separate module. New OFMEM module is used by sparc64 and all ppc configurations.
Since ppc briq/mol/pearpc are not buildable for years I used local build hack to verify this change does not make those even worse.
Boot-tested on sparc64 and ppc/qemu.
The patches look OK, but for some reason some of the topmost lines are missing as well as 8/8:
8/8 awaits moderator approval due to message size limit. I can repost deeper split version which will pass instantly, should I?
On Sun, Aug 2, 2009 at 12:32 PM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
On Sun, Aug 2, 2009 at 1:30 PM, Blue Swirlblauwirbel@gmail.com wrote:
On Sun, Aug 2, 2009 at 11:54 AM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
Hi!
This patch series moves OF memory manager code to separate module. New OFMEM module is used by sparc64 and all ppc configurations.
Since ppc briq/mol/pearpc are not buildable for years I used local build hack to verify this change does not make those even worse.
Boot-tested on sparc64 and ppc/qemu.
The patches look OK, but for some reason some of the topmost lines are missing as well as 8/8:
8/8 awaits moderator approval due to message size limit. I can repost deeper split version which will pass instantly, should I?
Either that, or you could compress it.
On Sun, Aug 2, 2009 at 1:36 PM, Blue Swirlblauwirbel@gmail.com wrote:
On Sun, Aug 2, 2009 at 12:32 PM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
On Sun, Aug 2, 2009 at 1:30 PM, Blue Swirlblauwirbel@gmail.com wrote:
On Sun, Aug 2, 2009 at 11:54 AM, Igor Kovalenkoigor.v.kovalenko@gmail.com wrote:
Hi!
This patch series moves OF memory manager code to separate module. New OFMEM module is used by sparc64 and all ppc configurations.
Since ppc briq/mol/pearpc are not buildable for years I used local build hack to verify this change does not make those even worse.
Boot-tested on sparc64 and ppc/qemu.
The patches look OK, but for some reason some of the topmost lines are missing as well as 8/8:
8/8 awaits moderator approval due to message size limit. I can repost deeper split version which will pass instantly, should I?
Either that, or you could compress it.
I reposted v1 of series, can we please restart from scratch :)