1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic MPC5200 BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | Partially based on the code references which are named below. | |
---|
5 | | Adaptions, modifications, enhancements and any recent parts of | |
---|
6 | | the code are: | |
---|
7 | | Copyright (c) 2005 | |
---|
8 | | Embedded Brains GmbH | |
---|
9 | | Obere Lagerstr. 30 | |
---|
10 | | D-82178 Puchheim | |
---|
11 | | Germany | |
---|
12 | | rtems@embedded-brains.de | |
---|
13 | +-----------------------------------------------------------------+ |
---|
14 | | The license and distribution terms for this file may be | |
---|
15 | | found in the file LICENSE in this distribution or at | |
---|
16 | | | |
---|
17 | | http://www.rtems.com/license/LICENSE. | |
---|
18 | | | |
---|
19 | +-----------------------------------------------------------------+ |
---|
20 | | this file contains the code to initialize the cpu | |
---|
21 | \*===============================================================*/ |
---|
22 | /***********************************************************************/ |
---|
23 | /* */ |
---|
24 | /* Module: cpuinit.c */ |
---|
25 | /* Date: 07/17/2003 */ |
---|
26 | /* Purpose: RTEMS MPC5x00 C level startup code */ |
---|
27 | /* */ |
---|
28 | /*---------------------------------------------------------------------*/ |
---|
29 | /* */ |
---|
30 | /* Description: This file contains additional functions for */ |
---|
31 | /* initializing the MPC5x00 CPU */ |
---|
32 | /* */ |
---|
33 | /*---------------------------------------------------------------------*/ |
---|
34 | /* */ |
---|
35 | /* Code */ |
---|
36 | /* References: MPC8260ads additional CPU initialization */ |
---|
37 | /* Module: cpuinit.c */ |
---|
38 | /* Project: RTEMS 4.6.0pre1 / MCF8260ads BSP */ |
---|
39 | /* Version 1.1 */ |
---|
40 | /* Date: 10/22/2002 */ |
---|
41 | /* */ |
---|
42 | /* Author(s) / Copyright(s): */ |
---|
43 | /* */ |
---|
44 | /* Written by Jay Monkman (jmonkman@frasca.com) */ |
---|
45 | /* */ |
---|
46 | /*---------------------------------------------------------------------*/ |
---|
47 | /* */ |
---|
48 | /* Partially based on the code references which are named above. */ |
---|
49 | /* Adaptions, modifications, enhancements and any recent parts of */ |
---|
50 | /* the code are under the right of */ |
---|
51 | /* */ |
---|
52 | /* IPR Engineering, Dachauer StraÃe 38, D-80335 MÃŒnchen */ |
---|
53 | /* Copyright(C) 2003 */ |
---|
54 | /* */ |
---|
55 | /*---------------------------------------------------------------------*/ |
---|
56 | /* */ |
---|
57 | /* IPR Engineering makes no representation or warranties with */ |
---|
58 | /* respect to the performance of this computer program, and */ |
---|
59 | /* specifically disclaims any responsibility for any damages, */ |
---|
60 | /* special or consequential, connected with the use of this program. */ |
---|
61 | /* */ |
---|
62 | /*---------------------------------------------------------------------*/ |
---|
63 | /* */ |
---|
64 | /* Version history: 1.0 */ |
---|
65 | /* */ |
---|
66 | /***********************************************************************/ |
---|
67 | |
---|
68 | #include <stdbool.h> |
---|
69 | #include <string.h> |
---|
70 | |
---|
71 | #include <libcpu/powerpc-utility.h> |
---|
72 | #include <libcpu/mmu.h> |
---|
73 | |
---|
74 | #include <bsp.h> |
---|
75 | #include <bsp/mpc5200.h> |
---|
76 | |
---|
77 | #define SET_DBAT( n, uv, lv) \ |
---|
78 | do { \ |
---|
79 | PPC_SET_SPECIAL_PURPOSE_REGISTER( DBAT##n##L, lv); \ |
---|
80 | PPC_SET_SPECIAL_PURPOSE_REGISTER( DBAT##n##U, uv); \ |
---|
81 | } while (0) |
---|
82 | |
---|
83 | static void calc_dbat_regvals( |
---|
84 | BAT *bat_ptr, |
---|
85 | uint32_t base_addr, |
---|
86 | uint32_t size, |
---|
87 | bool flg_w, |
---|
88 | bool flg_i, |
---|
89 | bool flg_m, |
---|
90 | bool flg_g, |
---|
91 | uint32_t flg_bpp |
---|
92 | ) |
---|
93 | { |
---|
94 | uint32_t block_mask = 0xffffffff; |
---|
95 | uint32_t end_addr = base_addr + size - 1; |
---|
96 | |
---|
97 | /* Determine block mask, that overlaps the whole block */ |
---|
98 | while ((end_addr & block_mask) != (base_addr & block_mask)) { |
---|
99 | block_mask <<= 1; |
---|
100 | } |
---|
101 | |
---|
102 | bat_ptr->batu.bepi = base_addr >> (32 - 15); |
---|
103 | bat_ptr->batu.bl = ~(block_mask >> (28 - 11)); |
---|
104 | bat_ptr->batu.vs = 1; |
---|
105 | bat_ptr->batu.vp = 1; |
---|
106 | |
---|
107 | bat_ptr->batl.brpn = base_addr >> (32 - 15); |
---|
108 | bat_ptr->batl.w = flg_w; |
---|
109 | bat_ptr->batl.i = flg_i; |
---|
110 | bat_ptr->batl.m = flg_m; |
---|
111 | bat_ptr->batl.g = flg_g; |
---|
112 | bat_ptr->batl.pp = flg_bpp; |
---|
113 | } |
---|
114 | |
---|
115 | #if defined (BRS5L) |
---|
116 | void cpu_init_bsp(void) |
---|
117 | { |
---|
118 | BAT dbat; |
---|
119 | |
---|
120 | calc_dbat_regvals(&dbat,RAM_START,RAM_SIZE,1,0,0,0,BPP_RW); |
---|
121 | SET_DBAT(0,dbat.batu,dbat.batl); |
---|
122 | |
---|
123 | calc_dbat_regvals(&dbat,ROM_START,ROM_SIZE,1,0,0,0,BPP_RX); |
---|
124 | SET_DBAT(1,dbat.batu,dbat.batl); |
---|
125 | |
---|
126 | calc_dbat_regvals(&dbat,MBAR,128*1024,1,1,1,1,BPP_RW); |
---|
127 | SET_DBAT(2,dbat.batu,dbat.batl); |
---|
128 | |
---|
129 | calc_dbat_regvals(&dbat,DPRAM_START,128*1024,1,1,1,1,BPP_RW); |
---|
130 | SET_DBAT(3,dbat.batu,dbat.batl); |
---|
131 | } |
---|
132 | #elif defined (HAS_UBOOT) |
---|
133 | void cpu_init_bsp(void) |
---|
134 | { |
---|
135 | BAT dbat; |
---|
136 | |
---|
137 | /* |
---|
138 | * Program BAT0 for RAM |
---|
139 | */ |
---|
140 | calc_dbat_regvals(&dbat, |
---|
141 | uboot_bdinfo_ptr->bi_memstart, |
---|
142 | uboot_bdinfo_ptr->bi_memsize, |
---|
143 | 1,0,0,0,BPP_RW); |
---|
144 | SET_DBAT(0,dbat.batu,dbat.batl); |
---|
145 | |
---|
146 | /* |
---|
147 | * Program BAT1 for Flash |
---|
148 | * |
---|
149 | * WARNING!! Some Freescale LITE5200B boards ship with a version of |
---|
150 | * U-Boot that lies about the starting address of Flash. This check |
---|
151 | * corrects that. |
---|
152 | */ |
---|
153 | if ( (uboot_bdinfo_ptr->bi_flashstart + uboot_bdinfo_ptr->bi_flashsize) < |
---|
154 | uboot_bdinfo_ptr->bi_flashstart ) { |
---|
155 | uint32_t start = 0 - uboot_bdinfo_ptr->bi_flashsize; |
---|
156 | calc_dbat_regvals(&dbat, |
---|
157 | start, uboot_bdinfo_ptr->bi_flashsize, 1,0,0,0,BPP_RX); |
---|
158 | } else { |
---|
159 | calc_dbat_regvals(&dbat, |
---|
160 | uboot_bdinfo_ptr->bi_flashstart, |
---|
161 | uboot_bdinfo_ptr->bi_flashsize, |
---|
162 | 1,0,0,0,BPP_RX); |
---|
163 | } |
---|
164 | SET_DBAT(1,dbat.batu,dbat.batl); |
---|
165 | |
---|
166 | /* |
---|
167 | * Program BAT2 for the MBAR |
---|
168 | */ |
---|
169 | calc_dbat_regvals(&dbat,MBAR,128*1024,1,1,1,1,BPP_RW); |
---|
170 | SET_DBAT(2,dbat.batu,dbat.batl); |
---|
171 | |
---|
172 | /* |
---|
173 | * If there is SRAM, program BAT3 for that memory |
---|
174 | */ |
---|
175 | if (uboot_bdinfo_ptr->bi_sramsize != 0) { |
---|
176 | calc_dbat_regvals(&dbat, |
---|
177 | uboot_bdinfo_ptr->bi_sramstart, |
---|
178 | uboot_bdinfo_ptr->bi_sramsize, |
---|
179 | 0,1,1,1,BPP_RW); |
---|
180 | SET_DBAT(3,dbat.batu,dbat.batl); |
---|
181 | } |
---|
182 | } |
---|
183 | #else |
---|
184 | #warning "Using BAT register values set by environment" |
---|
185 | #endif |
---|
186 | |
---|
187 | void cpu_init(void) |
---|
188 | { |
---|
189 | uint32_t msr; |
---|
190 | |
---|
191 | /* Enable instruction cache */ |
---|
192 | PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ICE); |
---|
193 | |
---|
194 | /* Set up DBAT registers in MMU */ |
---|
195 | cpu_init_bsp(); |
---|
196 | |
---|
197 | #if defined(SHOW_MORE_INIT_SETTINGS) |
---|
198 | { extern void ShowBATS(void); |
---|
199 | ShowBATS(); |
---|
200 | } |
---|
201 | #endif |
---|
202 | |
---|
203 | /* Read MSR */ |
---|
204 | msr = ppc_machine_state_register(); |
---|
205 | |
---|
206 | /* Enable data MMU in MSR */ |
---|
207 | msr |= MSR_DR; |
---|
208 | |
---|
209 | /* Update MSR */ |
---|
210 | ppc_set_machine_state_register( msr); |
---|
211 | |
---|
212 | /* |
---|
213 | * Enable data cache. |
---|
214 | * |
---|
215 | * NOTE: TRACE32 now supports data cache for MGT5x00. |
---|
216 | */ |
---|
217 | PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_DCE); |
---|
218 | } |
---|