source: rtems/c/src/lib/libbsp/powerpc/gen83xx/startup/cpuinit.c @ ce7d6e62

4.104.115
Last change on this file since ce7d6e62 was ce7d6e62, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 03/19/09 at 10:49:55
  • start/start.S, include/hwreg_vals.h, startup/cpuinit.c: correct some init values for HSC_CM01 boards
  • Property mode set to 100644
File size: 9.7 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic MPC83xx 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 *  $Id$
25 */
26
27/***********************************************************************/
28/*                                                                     */
29/*   Module:       cpuinit.c                                           */
30/*   Date:         07/17/2003                                          */
31/*   Purpose:      RTEMS MPC5x00 C level startup code                  */
32/*                                                                     */
33/*---------------------------------------------------------------------*/
34/*                                                                     */
35/*   Description:  This file contains additional functions for         */
36/*                 initializing the MPC5x00 CPU                        */
37/*                                                                     */
38/*---------------------------------------------------------------------*/
39/*                                                                     */
40/*   Code                                                              */
41/*   References:   MPC8260ads additional CPU initialization            */
42/*   Module:       cpuinit.c                                           */
43/*   Project:      RTEMS 4.6.0pre1 / MCF8260ads BSP                    */
44/*   Version       1.1                                                 */
45/*   Date:         10/22/2002                                          */
46/*                                                                     */
47/*   Author(s) / Copyright(s):                                         */
48/*                                                                     */
49/*   Written by Jay Monkman (jmonkman@frasca.com)                      */
50/*                                                                     */
51/*---------------------------------------------------------------------*/
52/*                                                                     */
53/*   Partially based on the code references which are named above.     */
54/*   Adaptions, modifications, enhancements and any recent parts of    */
55/*   the code are under the right of                                   */
56/*                                                                     */
57/*         IPR Engineering, Dachauer Straße 38, D-80335 MÃŒnchen        */
58/*                        Copyright(C) 2003                            */
59/*                                                                     */
60/*---------------------------------------------------------------------*/
61/*                                                                     */
62/*   IPR Engineering makes no representation or warranties with        */
63/*   respect to the performance of this computer program, and          */
64/*   specifically disclaims any responsibility for any damages,        */
65/*   special or consequential, connected with the use of this program. */
66/*                                                                     */
67/*---------------------------------------------------------------------*/
68/*                                                                     */
69/*   Version history:  1.0                                             */
70/*                                                                     */
71/***********************************************************************/
72
73#include <stdbool.h>
74#include <string.h>
75
76#include <libcpu/powerpc-utility.h>
77#include <libcpu/mmu.h>
78
79#include <mpc83xx/mpc83xx.h>
80
81#include <bsp.h>
82
83#define SET_DBAT( n, uv, lv) \
84  do { \
85    PPC_SET_SPECIAL_PURPOSE_REGISTER( DBAT##n##L, lv); \
86    PPC_SET_SPECIAL_PURPOSE_REGISTER( DBAT##n##U, uv); \
87  } while (0)
88
89#define SET_IBAT( n, uv, lv) \
90  do { \
91    PPC_SET_SPECIAL_PURPOSE_REGISTER( IBAT##n##L, lv); \
92    PPC_SET_SPECIAL_PURPOSE_REGISTER( IBAT##n##U, uv); \
93  } while (0)
94
95static void calc_dbat_regvals(
96  BAT *bat_ptr,
97  uint32_t base_addr,
98  uint32_t size,
99  bool flg_w,
100  bool flg_i,
101  bool flg_m,
102  bool flg_g,
103  uint32_t flg_bpp
104)
105{
106  uint32_t block_mask = 0xffffffff;
107  uint32_t end_addr = base_addr + size - 1;
108
109  /* Determine block mask, that overlaps the whole block */
110  while ((end_addr & block_mask) != (base_addr & block_mask)) {
111    block_mask <<= 1;
112  }
113 
114  bat_ptr->batu.bepi = base_addr >> (32 - 15);
115  bat_ptr->batu.bl   = ~(block_mask >> (28 - 11));
116  bat_ptr->batu.vs   = 1;
117  bat_ptr->batu.vp   = 1;
118 
119  bat_ptr->batl.brpn = base_addr  >> (32 - 15);
120  bat_ptr->batl.w    = flg_w;
121  bat_ptr->batl.i    = flg_i;
122  bat_ptr->batl.m    = flg_m;
123  bat_ptr->batl.g    = flg_g;
124  bat_ptr->batl.pp   = flg_bpp;
125}
126
127static void clear_mmu_regs( void)
128{
129  uint32_t i;
130
131  /* Clear segment registers */
132  for (i = 0;i < 16;i++) {
133    asm volatile( "mtsrin %0, %1\n" : : "r" (i * 0x1000), "r" (i << (31 - 3)));
134  }
135 
136  /* Clear TLBs */
137  for (i = 0;i < 32;i++) {
138    asm volatile( "tlbie %0\n" : : "r" (i << (31 - 19)));
139  }
140}
141
142void cpu_init( void)
143{
144  BAT dbat, ibat;
145  uint32_t msr;
146
147  /* Clear MMU and segment registers */
148  clear_mmu_regs();
149
150  /* Clear caches */
151  PPC_CLEAR_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ILOCK | HID0_DLOCK);
152  PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ICFI | HID0_DCI);
153  PPC_CLEAR_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ICFI | HID0_DCI);
154 
155  /*
156   * Set up IBAT registers in MMU
157   */
158
159  memset(&ibat, 0, sizeof( ibat));
160  SET_IBAT( 2, ibat.batu, ibat.batl);
161  SET_IBAT( 3, ibat.batu, ibat.batl);
162  SET_IBAT( 4, ibat.batu, ibat.batl);
163  SET_IBAT( 5, ibat.batu, ibat.batl);
164  SET_IBAT( 6, ibat.batu, ibat.batl);
165  SET_IBAT( 7, ibat.batu, ibat.batl);
166
167  calc_dbat_regvals(
168    &ibat,
169    #ifdef HAS_UBOOT
170      bsp_uboot_board_info.bi_memstart,
171      bsp_uboot_board_info.bi_memsize,
172    #else /* HAS_UBOOT */
173      (uint32_t) bsp_ram_start,
174      (uint32_t) bsp_ram_size,
175    #endif /* HAS_UBOOT */
176    false,
177    false,
178    false,
179    false,
180    BPP_RX
181  );
182  SET_IBAT( 0, ibat.batu, ibat.batl);
183
184  calc_dbat_regvals(
185    &ibat,
186    #ifdef HAS_UBOOT
187      bsp_uboot_board_info.bi_flashstart,
188      bsp_uboot_board_info.bi_flashsize,
189    #else /* HAS_UBOOT */
190      (uint32_t) bsp_rom_start,
191      (uint32_t) bsp_rom_size,
192    #endif /* HAS_UBOOT */
193    false,
194    false,
195    false,
196    false,
197    BPP_RX
198  );
199  SET_IBAT( 1, ibat.batu, ibat.batl);
200
201  /*
202   * Set up DBAT registers in MMU
203   */
204
205  memset(&dbat, 0, sizeof( dbat));
206  SET_DBAT( 3, dbat.batu, dbat.batl);
207  SET_DBAT( 4, dbat.batu, dbat.batl);
208  SET_DBAT( 5, dbat.batu, dbat.batl);
209  SET_DBAT( 6, dbat.batu, dbat.batl);
210  SET_DBAT( 7, dbat.batu, dbat.batl);
211
212  calc_dbat_regvals(
213    &dbat,
214    #ifdef HAS_UBOOT
215      bsp_uboot_board_info.bi_memstart,
216      bsp_uboot_board_info.bi_memsize,
217    #else /* HAS_UBOOT */
218      (uint32_t) bsp_ram_start,
219      (uint32_t) bsp_ram_size,
220    #endif /* HAS_UBOOT */
221    false,
222    false,
223    false,
224    false,
225    BPP_RW
226  );
227  SET_DBAT( 0, dbat.batu, dbat.batl);
228
229  calc_dbat_regvals(
230    &dbat,
231    #ifdef HAS_UBOOT
232      bsp_uboot_board_info.bi_flashstart,
233      bsp_uboot_board_info.bi_flashsize,
234    #else /* HAS_UBOOT */
235      (uint32_t) bsp_rom_start,
236      (uint32_t) bsp_rom_size,
237    #endif /* HAS_UBOOT */
238    true,
239    false,
240    false,
241    false,
242    BPP_RX
243  );
244  SET_DBAT( 1, dbat.batu, dbat.batl);
245
246  calc_dbat_regvals(
247    &dbat,
248    #ifdef HAS_UBOOT
249      bsp_uboot_board_info.bi_immrbar,
250    #else /* HAS_UBOOT */
251      (uint32_t) IMMRBAR,
252    #endif /* HAS_UBOOT */
253    1024 * 1024,
254    false,
255    true,
256    false,
257    true,
258    BPP_RW
259  );
260  SET_DBAT( 2, dbat.batu, dbat.batl);
261
262#if defined(HSC_CM01)
263  calc_dbat_regvals(
264    &dbat,
265    FPGA_START,
266    FPGA_SIZE,
267    true,
268    true,
269    true,
270    false,
271    BPP_RW
272  );
273  SET_DBAT(3,dbat.batu,dbat.batl);
274#endif
275
276#ifdef MPC8313ERDB
277  /* Enhanced Local Bus Controller (eLBC) */
278  calc_dbat_regvals(
279    &dbat,
280    0xfa000000,
281    128 * 1024,
282    false,
283    true,
284    false,
285    true,
286    BPP_RW
287  );
288  SET_DBAT( 3, dbat.batu, dbat.batl);
289#endif /* MPC8313ERDB */
290
291  /* Read MSR */
292  msr = ppc_machine_state_register();
293
294  /* Enable data and instruction MMU in MSR */
295  msr |= MSR_DR | MSR_IR;
296
297  /* Enable FPU in MSR */
298  msr |= MSR_FP;
299
300  /* Update MSR */
301  ppc_set_machine_state_register( msr);
302
303  /*
304   * In HID0:
305   *  - Enable dynamic power management
306   *  - Enable machine check interrupts
307   */
308  PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_EMCP | HID0_DPM);
309
310  /* Enable timebase clock */
311  mpc83xx.syscon.spcr |= M83xx_SYSCON_SPCR_TBEN;
312}
Note: See TracBrowser for help on using the repository browser.