6 * Copyright (C) 1999-2004 Samuel Rydh (samuel@ibrium.se)
7 * Copyright (C) 2004 Stefan Reinauer
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation
16 #include "libopenbios/bindings.h"
17 #include "libc/string.h"
18 #include "libopenbios/ofmem.h"
22 #define OF_MALLOC_BASE ((char*)OFMEM + ALIGN_SIZE(sizeof(ofmem_t), 8))
24 /* Temporarily very small */
25 #define MEMSIZE (1 * 1024)
31 #define OFMEM (&s_ofmem_data.ofmem)
32 #define TOP_OF_RAM (s_ofmem_data.memory + MEMSIZE)
34 translation_t
**g_ofmem_translations
= &s_ofmem_data
.ofmem
.trans
;
36 extern uint32_t qemu_mem_size
;
38 static inline size_t ALIGN_SIZE(size_t x
, size_t a
)
40 return (x
+ a
- 1) & ~(a
-1);
43 static ucell
get_heap_top( void )
45 return (ucell
)TOP_OF_RAM
;
48 ofmem_t
* ofmem_arch_get_private(void)
53 void* ofmem_arch_get_malloc_base(void)
55 return OF_MALLOC_BASE
;
58 ucell
ofmem_arch_get_heap_top(void)
60 return get_heap_top();
63 ucell
ofmem_arch_get_virt_top(void)
65 return (ucell
)TOP_OF_RAM
;
68 phys_addr_t
ofmem_arch_get_phys_top(void)
70 ofmem_t
*ofmem
= ofmem_arch_get_private();
72 return (uintptr_t)ofmem
->ramsize
- 0x1000000;
75 retain_t
*ofmem_arch_get_retained(void)
81 int ofmem_arch_get_physaddr_cellsize(void)
86 int ofmem_arch_encode_physaddr(ucell
*p
, phys_addr_t value
)
96 int ofmem_arch_get_translation_entry_size(void)
98 /* Return size of a single MMU package translation property entry in cells */
102 void ofmem_arch_create_translation_entry(ucell
*transentry
, translation_t
*t
)
104 /* Generate translation property entry for SPARC. While there is no
105 formal documentation for this, both Linux kernel and OpenSolaris sources
106 expect a translation property entry to have the following layout:
113 transentry
[0] = t
->virt
;
114 transentry
[1] = t
->size
;
115 transentry
[2] = t
->mode
;
118 /************************************************************************/
120 /************************************************************************/
122 ucell
ofmem_arch_default_translation_mode( phys_addr_t phys
)
124 return SRMMU_REF
| SRMMU_CACHE
| SRMMU_PRIV
;
127 /************************************************************************/
129 /************************************************************************/
131 void ofmem_init( void )
133 memset(&s_ofmem_data
, 0, sizeof(s_ofmem_data
));
134 s_ofmem_data
.ofmem
.ramsize
= qemu_mem_size
;