2009-07-31 11:15:30 +00:00
|
|
|
/*
|
|
|
|
|
* <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
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-03-14 17:19:58 +00:00
|
|
|
#include "config.h"
|
2010-03-14 15:05:53 +00:00
|
|
|
#include "libopenbios/bindings.h"
|
2009-07-31 11:15:30 +00:00
|
|
|
#include "libc/string.h"
|
|
|
|
|
#include "ofmem_sparc64.h"
|
|
|
|
|
#include "spitfire.h"
|
|
|
|
|
|
|
|
|
|
#define OF_MALLOC_BASE ((char*)OFMEM + ALIGN_SIZE(sizeof(ofmem_t), 8))
|
|
|
|
|
|
2010-10-02 13:28:49 +00:00
|
|
|
#define MEMSIZE ((256 + 512 + 512) * 1024)
|
2009-07-31 11:15:30 +00:00
|
|
|
static union {
|
|
|
|
|
char memory[MEMSIZE];
|
|
|
|
|
ofmem_t ofmem;
|
|
|
|
|
} s_ofmem_data;
|
|
|
|
|
|
2010-05-02 19:26:29 +00:00
|
|
|
#define OFMEM (&s_ofmem_data.ofmem)
|
|
|
|
|
#define TOP_OF_RAM (s_ofmem_data.memory + MEMSIZE)
|
2009-07-31 11:15:30 +00:00
|
|
|
|
|
|
|
|
translation_t **g_ofmem_translations = &s_ofmem_data.ofmem.trans;
|
|
|
|
|
|
2010-05-03 11:29:38 +00:00
|
|
|
extern uint64_t qemu_mem_size;
|
|
|
|
|
|
2010-05-02 19:26:29 +00:00
|
|
|
static inline size_t ALIGN_SIZE(size_t x, size_t a)
|
2009-07-31 11:15:30 +00:00
|
|
|
{
|
2010-05-02 19:26:29 +00:00
|
|
|
return (x + a - 1) & ~(a-1);
|
2009-07-31 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-02 19:26:29 +00:00
|
|
|
static ucell get_heap_top( void )
|
2009-07-31 11:15:30 +00:00
|
|
|
{
|
2010-05-02 19:26:29 +00:00
|
|
|
return (ucell)(TOP_OF_RAM - ALIGN_SIZE(sizeof(retain_t), 8));
|
2009-07-31 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 11:08:01 +00:00
|
|
|
ofmem_t* ofmem_arch_get_private(void)
|
2009-07-31 11:15:30 +00:00
|
|
|
{
|
2009-08-02 11:08:01 +00:00
|
|
|
return OFMEM;
|
2009-07-31 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 11:08:01 +00:00
|
|
|
void* ofmem_arch_get_malloc_base(void)
|
2009-07-31 11:15:30 +00:00
|
|
|
{
|
2009-08-02 11:08:01 +00:00
|
|
|
return OF_MALLOC_BASE;
|
2009-07-31 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 11:08:01 +00:00
|
|
|
ucell ofmem_arch_get_heap_top(void)
|
2009-07-31 11:15:30 +00:00
|
|
|
{
|
2009-08-02 11:08:01 +00:00
|
|
|
return get_heap_top();
|
2009-07-31 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 11:08:01 +00:00
|
|
|
ucell ofmem_arch_get_virt_top(void)
|
2009-07-31 11:15:30 +00:00
|
|
|
{
|
2009-08-02 11:08:01 +00:00
|
|
|
return (ucell)TOP_OF_RAM;
|
2009-07-31 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-03 11:29:38 +00:00
|
|
|
retain_t *ofmem_arch_get_retained(void)
|
|
|
|
|
{
|
|
|
|
|
/* Retained area is at the top of physical RAM */
|
|
|
|
|
return (retain_t *)(qemu_mem_size - sizeof(retain_t));
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-21 11:07:53 +00:00
|
|
|
int ofmem_arch_get_translation_entry_size(void)
|
|
|
|
|
{
|
|
|
|
|
/* Return size of a single MMU package translation property entry in cells */
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t)
|
|
|
|
|
{
|
|
|
|
|
/* Generate translation property entry for SPARC. While there is no
|
|
|
|
|
formal documentation for this, both Linux kernel and OpenSolaris sources
|
|
|
|
|
expect a translation property entry to have the following layout:
|
|
|
|
|
|
|
|
|
|
virtual address
|
|
|
|
|
length
|
|
|
|
|
mode
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
transentry[0] = t->virt;
|
|
|
|
|
transentry[1] = t->size;
|
|
|
|
|
transentry[2] = t->mode;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-31 11:15:30 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
/* misc */
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
2009-08-02 11:08:01 +00:00
|
|
|
ucell ofmem_arch_default_translation_mode( ucell phys )
|
2009-07-31 11:15:30 +00:00
|
|
|
{
|
|
|
|
|
/* Writable, cacheable */
|
|
|
|
|
/* not privileged and not locked */
|
|
|
|
|
return SPITFIRE_TTE_CP | SPITFIRE_TTE_CV | SPITFIRE_TTE_WRITABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
/* init / cleanup */
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
|
|
static int remap_page_range( ucell phys, ucell virt, ucell size, ucell mode )
|
|
|
|
|
{
|
2009-12-29 17:36:05 +00:00
|
|
|
ofmem_claim_phys(phys, size, 0);
|
|
|
|
|
ofmem_claim_virt(virt, size, 0);
|
2009-08-02 11:08:01 +00:00
|
|
|
ofmem_map_page_range(phys, virt, size, mode);
|
2009-07-31 11:15:30 +00:00
|
|
|
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 );
|
2009-08-02 11:08:01 +00:00
|
|
|
ofmem_arch_unmap_pages(virt, size);
|
2009-07-31 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-02 19:26:29 +00:00
|
|
|
#define RETAIN_MAGIC 0x1100220033004400
|
|
|
|
|
|
2009-07-31 11:15:30 +00:00
|
|
|
void ofmem_init( void )
|
|
|
|
|
{
|
2010-05-03 11:29:38 +00:00
|
|
|
retain_t *retained = ofmem_arch_get_retained();
|
|
|
|
|
int i;
|
2010-05-02 19:26:29 +00:00
|
|
|
|
2010-05-03 11:29:38 +00:00
|
|
|
memset(&s_ofmem_data, 0, sizeof(s_ofmem_data));
|
|
|
|
|
s_ofmem_data.ofmem.ramsize = qemu_mem_size;
|
2009-07-31 11:15:30 +00:00
|
|
|
|
|
|
|
|
/* inherit translations set up by entry.S */
|
|
|
|
|
ofmem_walk_boot_map(remap_page_range);
|
2009-12-29 17:36:03 +00:00
|
|
|
|
|
|
|
|
/* Map the memory */
|
|
|
|
|
ofmem_map_page_range(0, 0, qemu_mem_size, 0x36);
|
2009-07-31 11:15:30 +00:00
|
|
|
|
2010-05-03 11:29:38 +00:00
|
|
|
if (!(retained->magic == RETAIN_MAGIC)) {
|
|
|
|
|
OFMEM_TRACE("ofmem_init: no retained magic found, creating\n");
|
|
|
|
|
retained->magic = RETAIN_MAGIC;
|
|
|
|
|
retained->numentries = 0;
|
|
|
|
|
} else {
|
|
|
|
|
OFMEM_TRACE("ofmem_init: retained magic found, total %lld mappings\n", retained->numentries);
|
|
|
|
|
|
|
|
|
|
/* Mark physical addresses as used so they are not reallocated */
|
|
|
|
|
for (i = 0; i < retained->numentries; i++) {
|
|
|
|
|
ofmem_claim_phys(retained->retain_phys_range[i].start,
|
|
|
|
|
retained->retain_phys_range[i].size, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Reset retained area for next reset */
|
|
|
|
|
retained->magic = RETAIN_MAGIC;
|
|
|
|
|
retained->numentries = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|