1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Physical Memory (arena) manager File: rm5200_arena.c
6 * This module describes the physical memory available to the
9 * Author: Mitch Lichtenberg (mpl@broadcom.com)
11 *********************************************************************
13 * Copyright 2000,2001,2002,2003
14 * Broadcom Corporation. All rights reserved.
16 * This software is furnished under license and may be used and
17 * copied only in accordance with the following terms and
18 * conditions. Subject to these conditions, you may download,
19 * copy, install, use, modify and distribute modified or unmodified
20 * copies of this software in source and/or binary form. No title
21 * or ownership is transferred hereby.
23 * 1) Any source code used, modified or distributed must reproduce
24 * and retain this copyright notice and list of conditions
25 * as they appear in the source file.
27 * 2) No right is granted to use any trade name, trademark, or
28 * logo of Broadcom Corporation. The "Broadcom Corporation"
29 * name may not be used to endorse or promote products derived
30 * from this software without the prior written permission of
31 * Broadcom Corporation.
33 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45 * THE POSSIBILITY OF SUCH DAMAGE.
46 ********************************************************************* */
50 #include "lib_types.h"
51 #include "lib_string.h"
52 #include "lib_queue.h"
53 #include "lib_malloc.h"
54 #include "lib_printf.h"
55 #include "lib_arena.h"
57 #include "cfe_error.h"
69 /* *********************************************************************
71 ********************************************************************* */
73 #define ARENA_RANGE(bottom,top,type) arena_markrange(&cfe_arena,(uint64_t)(bottom), \
74 (uint64_t)(top)-(uint64_t)bottom+1,(type),NULL)
76 #define MEG (1024*1024)
79 #define CFE_BOOTAREA_SIZE (256*KB)
80 #define CFE_BOOTAREA_ADDR 0x20000000
82 /* *********************************************************************
84 ********************************************************************* */
86 extern arena_t cfe_arena
;
88 unsigned int mem_bootarea_start
;
89 unsigned int mem_bootarea_size
;
91 void rm5200_arena_init(void);
92 void rm5200_pagetable_init(uint64_t *ptaddr
,unsigned int physaddr
);
95 /* *********************************************************************
98 * Create the initial map of physical memory
105 ********************************************************************* */
107 void rm5200_arena_init(void)
110 int64_t mem256
= (256*1024*1024); /* 256 MBytes */
113 arena_init(&cfe_arena
,0x0,0x100000000);
116 * Mark the ranges from the RM5200's memory map
119 ARENA_RANGE(0x0000000000,0x000FFFFFFF,MEMTYPE_DRAM_NOTINSTALLED
);
122 * Mark LDT and PCI regions
127 * Now, fix up the map with what is known about *this* system.
129 * Do each 256MB chunk.
132 memleft
= ((int64_t) mem_totalsize
) << 20;
134 memamt
= (memleft
> mem256
) ? mem256
: memleft
;
136 arena_markrange(&cfe_arena
,0x00000000,memamt
,MEMTYPE_DRAM_AVAILABLE
,NULL
);
139 * Note: we don't deal with RM5200 boards with >256MB memory. Big deal.
146 arena_markrange(&cfe_arena
,0x1FC00000,2*1024*1024,MEMTYPE_BOOTROM
,NULL
);
151 /* *********************************************************************
152 * RM5200_PAGETABLE_INIT(ptaddr,physaddr)
154 * This routine constructs the page table. 256KB is mapped
155 * starting at physical address 'physaddr' - the resulting
156 * table entries are placed at 'ptaddr'
159 * ptaddr - base of page table
160 * physaddr - starting physical addr of area to map
164 ********************************************************************* */
166 void rm5200_pagetable_init(uint64_t *ptaddr
,unsigned int physaddr
)
170 for (idx
= 0; idx
< (CFE_BOOTAREA_SIZE
/PAGESIZE
); idx
++) {
171 ptaddr
[idx
] = (physaddr
>> 6) |
172 V_TLBLO_CALG(K_CALG_NONCOHERENT
) |
175 physaddr
+= PAGESIZE
;