Change the SPARC32 build system so that OFMEM is now included within SPARC32 builds.
[openbios.git] / arch / sparc32 / ofmem_sparc32.c
blobfffd32ac4070dfadd540113c21b9834be419f952
1 /*
2 * <ofmem_sparc32.c>
4 * OF Memory manager
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
15 #include "config.h"
16 #include "libopenbios/bindings.h"
17 #include "libc/string.h"
18 #include "libopenbios/ofmem.h"
19 #include "asm/asi.h"
20 #include "pgtsrmmu.h"
22 #define OF_MALLOC_BASE ((char*)OFMEM + ALIGN_SIZE(sizeof(ofmem_t), 8))
24 /* Temporarily very small */
25 #define MEMSIZE (1 * 1024)
26 static union {
27 char memory[MEMSIZE];
28 ofmem_t ofmem;
29 } s_ofmem_data;
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)
50 return OFMEM;
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)
77 /* Not used */
78 return 0;
81 int ofmem_arch_get_physaddr_cellsize(void)
83 return 2;
86 int ofmem_arch_encode_physaddr(ucell *p, phys_addr_t value)
88 int n = 0;
90 p[n++] = value >> 32;
91 p[n++] = value;
93 return n;
96 int ofmem_arch_get_translation_entry_size(void)
98 /* Return size of a single MMU package translation property entry in cells */
99 return 3;
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:
108 virtual address
109 length
110 mode
113 transentry[0] = t->virt;
114 transentry[1] = t->size;
115 transentry[2] = t->mode;
118 /************************************************************************/
119 /* misc */
120 /************************************************************************/
122 ucell ofmem_arch_default_translation_mode( phys_addr_t phys )
124 return SRMMU_REF | SRMMU_CACHE | SRMMU_PRIV;
127 /************************************************************************/
128 /* init / cleanup */
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;