source: rtems/c/src/lib/libbsp/powerpc/gen5200/startup/cpuinit.c @ 82bd8d9d

4.104.114.95
Last change on this file since 82bd8d9d was 82bd8d9d, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 09/03/08 at 15:39:03

Converted to use shared

exception and interrupt code.

  • Property mode set to 100644
File size: 8.5 KB
Line 
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
83static 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)
116void cpu_init_bsp(void)
117{
118  BAT dbat;
119
120  calc_dbat_regvals(
121    &dbat,
122    (uint32_t) bsp_ram_start,
123    (uint32_t) bsp_ram_size,
124    true,
125    false,
126    false,
127    false,
128    BPP_RW
129  );
130  SET_DBAT(0,dbat.batu,dbat.batl);
131
132  calc_dbat_regvals(
133    &dbat,
134    (uint32_t) bsp_rom_start,
135    (uint32_t) bsp_rom_size,
136    true,
137    false,
138    false,
139    false,
140    BPP_RX
141  );
142  SET_DBAT(1,dbat.batu,dbat.batl);
143
144  calc_dbat_regvals(
145    &dbat,
146    (uint32_t) MBAR,
147    128 * 1024,
148    false,
149    true,
150    false,
151    true,
152    BPP_RW
153  );
154  SET_DBAT(2,dbat.batu,dbat.batl);
155
156  calc_dbat_regvals(
157    &dbat,
158    (uint32_t) bsp_dpram_start,
159    128 * 1024,
160    false,
161    true,
162    false,
163    true,
164    BPP_RW
165  );
166  SET_DBAT(3,dbat.batu,dbat.batl);
167}
168#elif defined (HAS_UBOOT)
169void cpu_init_bsp(void)
170{
171  BAT dbat;
172  uint32_t start = 0;
173 
174  /*
175   * Program BAT0 for RAM
176   */
177  calc_dbat_regvals(
178    &dbat,
179    uboot_bdinfo_ptr->bi_memstart,
180    uboot_bdinfo_ptr->bi_memsize,
181    true,
182    false,
183    false,
184    false,
185    BPP_RW
186  );
187  SET_DBAT(0,dbat.batu,dbat.batl);
188
189  /*
190   * Program BAT1 for Flash
191   *
192   * WARNING!! Some Freescale LITE5200B boards ship with a version of
193   * U-Boot that lies about the starting address of Flash.  This check
194   * corrects that.
195   */
196  if ((uboot_bdinfo_ptr->bi_flashstart + uboot_bdinfo_ptr->bi_flashsize)
197    < uboot_bdinfo_ptr->bi_flashstart) {
198    start = 0 - uboot_bdinfo_ptr->bi_flashsize;
199  } else {
200    start = uboot_bdinfo_ptr->bi_flashstart;
201  }
202  calc_dbat_regvals(
203    &dbat,
204    start,
205    uboot_bdinfo_ptr->bi_flashsize,
206    true,
207    false,
208    false,
209    false,
210    BPP_RX
211  );
212  SET_DBAT(1,dbat.batu,dbat.batl);
213
214  /*
215   * Program BAT2 for the MBAR
216   */
217  calc_dbat_regvals(
218    &dbat,
219    (uint32_t) MBAR,
220    128 * 1024,
221    false,
222    true,
223    false,
224    true,
225    BPP_RW
226  );
227  SET_DBAT(2,dbat.batu,dbat.batl);
228
229  /*
230   * If there is SRAM, program BAT3 for that memory
231   */
232  if (uboot_bdinfo_ptr->bi_sramsize != 0) {
233    calc_dbat_regvals(
234      &dbat,
235      uboot_bdinfo_ptr->bi_sramstart,
236      uboot_bdinfo_ptr->bi_sramsize,
237      false,
238      true,
239      true,
240      true,
241      BPP_RW
242    );
243    SET_DBAT(3,dbat.batu,dbat.batl);
244  }
245}
246#else
247#warning "Using BAT register values set by environment"
248#endif
249
250void cpu_init(void)
251{
252  uint32_t msr;
253
254  /* Enable instruction cache */
255  PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ICE);
256
257  /* Set up DBAT registers in MMU */
258  cpu_init_bsp();
259
260  #if defined(SHOW_MORE_INIT_SETTINGS)
261    { extern void ShowBATS(void);
262      ShowBATS();
263    }
264  #endif
265
266  /* Read MSR */
267  msr = ppc_machine_state_register();
268
269  /* Enable data MMU in MSR */
270  msr |= MSR_DR;
271
272  /* Update MSR */
273  ppc_set_machine_state_register( msr);
274
275  /*
276   * Enable data cache.
277   *
278   * NOTE: TRACE32 now supports data cache for MGT5x00.
279   */
280  PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_DCE);
281}
Note: See TracBrowser for help on using the repository browser.