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

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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