1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Physical Memory (arena) manager		File: rm7000_arena.c
5    *
6    *  This module describes the physical memory available to the
7    *  firmware.
8    *
9    *  Author:  Mitch Lichtenberg (mpl@broadcom.com)
10    *
11    *********************************************************************
12    *
13    *  Copyright 2000,2001,2002,2003
14    *  Broadcom Corporation. All rights reserved.
15    *
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.
22    *
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.
26    *
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.
32    *
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    ********************************************************************* */
47
48#include "sbmips.h"
49
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"
56
57#include "cfe_error.h"
58
59#include "cfe.h"
60#include "cfe_mem.h"
61
62#include "initdata.h"
63
64#define _NOPROTOS_
65#include "cfe_boot.h"
66#undef _NOPROTOS_
67
68
69/*  *********************************************************************
70    *  Macros
71    ********************************************************************* */
72
73#define ARENA_RANGE(bottom,top,type) arena_markrange(&cfe_arena,(uint64_t)(bottom), \
74                                     (uint64_t)(top)-(uint64_t)bottom+1,(type),NULL)
75
76#define MEG	(1024*1024)
77#define KB      1024
78#define PAGESIZE 4096
79#define CFE_BOOTAREA_SIZE (256*KB)
80#define CFE_BOOTAREA_ADDR 0x20000000
81
82/*  *********************************************************************
83    *  Globals
84    ********************************************************************* */
85
86extern arena_t cfe_arena;
87
88unsigned int mem_bootarea_start;
89unsigned int mem_bootarea_size;
90
91void rm7000_arena_init(void);
92void rm7000_pagetable_init(uint64_t *ptaddr,unsigned int physaddr);
93
94
95/*  *********************************************************************
96    *  rm7000_arena_init()
97    *
98    *  Create the initial map of physical memory
99    *
100    *  Input parameters:
101    *  	   nothing
102    *
103    *  Return value:
104    *  	   nothing
105    ********************************************************************* */
106
107void rm7000_arena_init(void)
108{
109    int64_t memleft;
110    int64_t mem256 = (256*1024*1024);		/* 256 MBytes */
111    int64_t memamt;
112
113    arena_init(&cfe_arena,0x0,0x100000000);
114
115    /*
116     * Mark the ranges from the RM7000's memory map
117     */
118
119    ARENA_RANGE(0x0000000000,0x000FFFFFFF,MEMTYPE_DRAM_NOTINSTALLED);
120
121    /*
122     * Mark LDT and PCI regions
123     */
124
125
126    /*
127     * Now, fix up the map with what is known about *this* system.
128     *
129     * Do each 256MB chunk.
130     */
131
132    memleft = ((int64_t) mem_totalsize) << 20;
133
134    memamt = (memleft > mem256) ? mem256 : memleft;
135
136    arena_markrange(&cfe_arena,0x00000000,memamt,MEMTYPE_DRAM_AVAILABLE,NULL);
137
138    /*
139     * Note: we don't deal with RM7000 boards with >256MB memory.  Big deal.
140     */
141
142    /*
143     * Do the boot ROM
144     */
145
146    arena_markrange(&cfe_arena,0x1FC00000,2*1024*1024,MEMTYPE_BOOTROM,NULL);
147
148}
149
150
151/*  *********************************************************************
152    *  RM7000_PAGETABLE_INIT(ptaddr,physaddr)
153    *
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'
157    *
158    *  Input parameters:
159    *  	   ptaddr - base of page table
160    *  	   physaddr - starting physical addr of area to map
161    *
162    *  Return value:
163    *  	   nothing
164    ********************************************************************* */
165
166void rm7000_pagetable_init(uint64_t *ptaddr,unsigned int physaddr)
167{
168    int idx;
169
170    for (idx = 0; idx < (CFE_BOOTAREA_SIZE/PAGESIZE); idx++) {
171	ptaddr[idx] = (physaddr >> 6) |
172	    V_TLBLO_CALG(K_CALG_NONCOHERENT) |
173	    M_TLBLO_V |
174	    M_TLBLO_D;
175	physaddr += PAGESIZE;
176	}
177
178}
179
180