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.org/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 | static inline void enable_bat_4_to_7(void) |
---|
116 | { |
---|
117 | PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS(HID2, BSP_BBIT32(13)); |
---|
118 | } |
---|
119 | |
---|
120 | static void cpu_init_bsp(void) |
---|
121 | { |
---|
122 | BAT dbat; |
---|
123 | |
---|
124 | #if defined(MPC5200_BOARD_BRS5L) || defined(MPC5200_BOARD_BRS6L) |
---|
125 | calc_dbat_regvals( |
---|
126 | &dbat, |
---|
127 | (uint32_t) bsp_ram_start, |
---|
128 | (uint32_t) bsp_ram_size, |
---|
129 | false, |
---|
130 | false, |
---|
131 | false, |
---|
132 | false, |
---|
133 | BPP_RW |
---|
134 | ); |
---|
135 | SET_DBAT(0,dbat.batu,dbat.batl); |
---|
136 | |
---|
137 | calc_dbat_regvals( |
---|
138 | &dbat, |
---|
139 | (uint32_t) bsp_rom_start, |
---|
140 | (uint32_t) bsp_rom_size, |
---|
141 | false, |
---|
142 | false, |
---|
143 | false, |
---|
144 | false, |
---|
145 | BPP_RX |
---|
146 | ); |
---|
147 | SET_DBAT(1,dbat.batu,dbat.batl); |
---|
148 | |
---|
149 | calc_dbat_regvals( |
---|
150 | &dbat, |
---|
151 | (uint32_t) MBAR, |
---|
152 | 128 * 1024, |
---|
153 | false, |
---|
154 | true, |
---|
155 | false, |
---|
156 | true, |
---|
157 | BPP_RW |
---|
158 | ); |
---|
159 | SET_DBAT(2,dbat.batu,dbat.batl); |
---|
160 | #elif defined (HAS_UBOOT) |
---|
161 | uint32_t start = 0; |
---|
162 | |
---|
163 | /* |
---|
164 | * Accesses (also speculative accesses) outside of the RAM area are a |
---|
165 | * disaster especially in combination with the BestComm. For safety reasons |
---|
166 | * we make the available RAM a little bit smaller to have an unused area at |
---|
167 | * the end. |
---|
168 | */ |
---|
169 | bsp_uboot_board_info.bi_memsize -= 4 * 1024; |
---|
170 | |
---|
171 | /* |
---|
172 | * Program BAT0 for RAM |
---|
173 | */ |
---|
174 | calc_dbat_regvals( |
---|
175 | &dbat, |
---|
176 | bsp_uboot_board_info.bi_memstart, |
---|
177 | bsp_uboot_board_info.bi_memsize, |
---|
178 | false, |
---|
179 | false, |
---|
180 | false, |
---|
181 | false, |
---|
182 | BPP_RW |
---|
183 | ); |
---|
184 | SET_DBAT(0,dbat.batu,dbat.batl); |
---|
185 | |
---|
186 | /* |
---|
187 | * Program BAT1 for Flash |
---|
188 | * |
---|
189 | * WARNING!! Some Freescale LITE5200B boards ship with a version of |
---|
190 | * U-Boot that lies about the starting address of Flash. This check |
---|
191 | * corrects that. |
---|
192 | */ |
---|
193 | if ((bsp_uboot_board_info.bi_flashstart + bsp_uboot_board_info.bi_flashsize) |
---|
194 | < bsp_uboot_board_info.bi_flashstart) { |
---|
195 | start = 0 - bsp_uboot_board_info.bi_flashsize; |
---|
196 | } else { |
---|
197 | start = bsp_uboot_board_info.bi_flashstart; |
---|
198 | } |
---|
199 | calc_dbat_regvals( |
---|
200 | &dbat, |
---|
201 | start, |
---|
202 | bsp_uboot_board_info.bi_flashsize, |
---|
203 | false, |
---|
204 | false, |
---|
205 | false, |
---|
206 | false, |
---|
207 | BPP_RX |
---|
208 | ); |
---|
209 | SET_DBAT(1,dbat.batu,dbat.batl); |
---|
210 | |
---|
211 | /* |
---|
212 | * Program BAT2 for the MBAR |
---|
213 | */ |
---|
214 | calc_dbat_regvals( |
---|
215 | &dbat, |
---|
216 | (uint32_t) MBAR, |
---|
217 | 128 * 1024, |
---|
218 | false, |
---|
219 | true, |
---|
220 | false, |
---|
221 | true, |
---|
222 | BPP_RW |
---|
223 | ); |
---|
224 | SET_DBAT(2,dbat.batu,dbat.batl); |
---|
225 | |
---|
226 | /* |
---|
227 | * If there is SRAM, program BAT3 for that memory |
---|
228 | */ |
---|
229 | if (bsp_uboot_board_info.bi_sramsize != 0) { |
---|
230 | calc_dbat_regvals( |
---|
231 | &dbat, |
---|
232 | bsp_uboot_board_info.bi_sramstart, |
---|
233 | bsp_uboot_board_info.bi_sramsize, |
---|
234 | false, |
---|
235 | true, |
---|
236 | true, |
---|
237 | true, |
---|
238 | BPP_RW |
---|
239 | ); |
---|
240 | SET_DBAT(3,dbat.batu,dbat.batl); |
---|
241 | } |
---|
242 | #else |
---|
243 | #warning "Using BAT register values set by environment" |
---|
244 | #endif |
---|
245 | |
---|
246 | #if defined(MPC5200_BOARD_DP2) |
---|
247 | enable_bat_4_to_7(); |
---|
248 | |
---|
249 | /* FPGA */ |
---|
250 | calc_dbat_regvals( |
---|
251 | &dbat, |
---|
252 | 0xf0020000, |
---|
253 | 128 * 1024, |
---|
254 | false, |
---|
255 | true, |
---|
256 | false, |
---|
257 | true, |
---|
258 | BPP_RW |
---|
259 | ); |
---|
260 | SET_DBAT(4, dbat.batu, dbat.batl); |
---|
261 | #elif defined(MPC5200_BOARD_PM520_ZE30) |
---|
262 | enable_bat_4_to_7(); |
---|
263 | |
---|
264 | /* External CC770 CAN controller available in version 2 */ |
---|
265 | calc_dbat_regvals( |
---|
266 | &dbat, |
---|
267 | 0xf2000000, |
---|
268 | 128 * 1024, |
---|
269 | false, |
---|
270 | true, |
---|
271 | false, |
---|
272 | true, |
---|
273 | BPP_RW |
---|
274 | ); |
---|
275 | SET_DBAT(4, dbat.batu, dbat.batl); |
---|
276 | #elif defined(MPC5200_BOARD_BRS5L) |
---|
277 | calc_dbat_regvals( |
---|
278 | &dbat, |
---|
279 | (uint32_t) bsp_dpram_start, |
---|
280 | 128 * 1024, |
---|
281 | false, |
---|
282 | true, |
---|
283 | false, |
---|
284 | true, |
---|
285 | BPP_RW |
---|
286 | ); |
---|
287 | SET_DBAT(3,dbat.batu,dbat.batl); |
---|
288 | #elif defined(MPC5200_BOARD_BRS6L) |
---|
289 | enable_bat_4_to_7(); |
---|
290 | |
---|
291 | /* FPGA */ |
---|
292 | calc_dbat_regvals( |
---|
293 | &dbat, |
---|
294 | MPC5200_BRS6L_FPGA_BEGIN, |
---|
295 | MPC5200_BRS6L_FPGA_SIZE, |
---|
296 | false, |
---|
297 | true, |
---|
298 | false, |
---|
299 | true, |
---|
300 | BPP_RW |
---|
301 | ); |
---|
302 | SET_DBAT(3,dbat.batu,dbat.batl); |
---|
303 | |
---|
304 | /* MRAM */ |
---|
305 | calc_dbat_regvals( |
---|
306 | &dbat, |
---|
307 | MPC5200_BRS6L_MRAM_BEGIN, |
---|
308 | MPC5200_BRS6L_MRAM_SIZE, |
---|
309 | true, |
---|
310 | false, |
---|
311 | false, |
---|
312 | false, |
---|
313 | BPP_RW |
---|
314 | ); |
---|
315 | SET_DBAT(4,dbat.batu,dbat.batl); |
---|
316 | #endif |
---|
317 | } |
---|
318 | |
---|
319 | void cpu_init(void) |
---|
320 | { |
---|
321 | uint32_t msr; |
---|
322 | |
---|
323 | #if BSP_INSTRUCTION_CACHE_ENABLED |
---|
324 | rtems_cache_enable_instruction(); |
---|
325 | #endif |
---|
326 | |
---|
327 | /* Set up DBAT registers in MMU */ |
---|
328 | cpu_init_bsp(); |
---|
329 | |
---|
330 | #if defined(SHOW_MORE_INIT_SETTINGS) |
---|
331 | { extern void ShowBATS(void); |
---|
332 | ShowBATS(); |
---|
333 | } |
---|
334 | #endif |
---|
335 | |
---|
336 | /* Read MSR */ |
---|
337 | msr = ppc_machine_state_register(); |
---|
338 | |
---|
339 | /* Enable data MMU in MSR */ |
---|
340 | msr |= MSR_DR; |
---|
341 | |
---|
342 | /* Update MSR */ |
---|
343 | ppc_set_machine_state_register( msr); |
---|
344 | |
---|
345 | #if BSP_DATA_CACHE_ENABLED |
---|
346 | rtems_cache_enable_data(); |
---|
347 | #endif |
---|
348 | } |
---|