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

4.115
Last change on this file since a3db5ff4 was a3db5ff4, checked in by Sebastian Huber <sebastian.huber@…>, on 04/02/12 at 09:05:29

bsp/gen83xx: Support for MPC830X

  • 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 *  $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#include <bsp/u-boot.h>
83
84#define SET_DBAT( n, uv, lv) \
85  do { \
86    PPC_SET_SPECIAL_PURPOSE_REGISTER( DBAT##n##L, lv); \
87    PPC_SET_SPECIAL_PURPOSE_REGISTER( DBAT##n##U, uv); \
88  } while (0)
89
90#define SET_IBAT( n, uv, lv) \
91  do { \
92    PPC_SET_SPECIAL_PURPOSE_REGISTER( IBAT##n##L, lv); \
93    PPC_SET_SPECIAL_PURPOSE_REGISTER( IBAT##n##U, uv); \
94  } while (0)
95
96static void calc_dbat_regvals(
97  BAT *bat_ptr,
98  uint32_t base_addr,
99  uint32_t size,
100  bool flg_w,
101  bool flg_i,
102  bool flg_m,
103  bool flg_g,
104  uint32_t flg_bpp
105)
106{
107  uint32_t block_mask = 0xffffffff;
108  uint32_t end_addr = base_addr + size - 1;
109
110  /* Determine block mask, that overlaps the whole block */
111  while ((end_addr & block_mask) != (base_addr & block_mask)) {
112    block_mask <<= 1;
113  }
114
115  bat_ptr->batu.bepi = base_addr >> (32 - 15);
116  bat_ptr->batu.bl   = ~(block_mask >> (28 - 11));
117  bat_ptr->batu.vs   = 1;
118  bat_ptr->batu.vp   = 1;
119
120  bat_ptr->batl.brpn = base_addr  >> (32 - 15);
121  bat_ptr->batl.w    = flg_w;
122  bat_ptr->batl.i    = flg_i;
123  bat_ptr->batl.m    = flg_m;
124  bat_ptr->batl.g    = flg_g;
125  bat_ptr->batl.pp   = flg_bpp;
126}
127
128static void clear_mmu_regs( void)
129{
130  uint32_t i;
131
132  /* Clear segment registers */
133  for (i = 0;i < 16;i++) {
134    __asm__ volatile( "mtsrin %0, %1\n" : : "r" (i * 0x1000), "r" (i << (31 - 3)));
135  }
136
137  /* Clear TLBs */
138  for (i = 0;i < 32;i++) {
139    __asm__ volatile( "tlbie %0\n" : : "r" (i << (31 - 19)));
140  }
141}
142
143void cpu_init( void)
144{
145  BAT dbat, ibat;
146  uint32_t msr;
147
148  /* Clear MMU and segment registers */
149  clear_mmu_regs();
150
151  /* Clear caches */
152  PPC_CLEAR_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ILOCK | HID0_DLOCK);
153  PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ICFI | HID0_DCI);
154  PPC_CLEAR_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_ICFI | HID0_DCI);
155
156  /*
157   * Set up IBAT registers in MMU
158   */
159
160  memset(&ibat, 0, sizeof( ibat));
161  SET_IBAT( 2, ibat.batu, ibat.batl);
162  SET_IBAT( 3, ibat.batu, ibat.batl);
163  SET_IBAT( 4, ibat.batu, ibat.batl);
164  SET_IBAT( 5, ibat.batu, ibat.batl);
165  SET_IBAT( 6, ibat.batu, ibat.batl);
166  SET_IBAT( 7, ibat.batu, ibat.batl);
167
168  calc_dbat_regvals(
169    &ibat,
170    #ifdef HAS_UBOOT
171      bsp_uboot_board_info.bi_memstart,
172      bsp_uboot_board_info.bi_memsize,
173    #else /* HAS_UBOOT */
174      (uint32_t) bsp_ram_start,
175      (uint32_t) bsp_ram_size,
176    #endif /* HAS_UBOOT */
177    false,
178    false,
179    false,
180    false,
181    BPP_RX
182  );
183  SET_IBAT( 0, ibat.batu, ibat.batl);
184
185  calc_dbat_regvals(
186    &ibat,
187    #ifdef HAS_UBOOT
188      bsp_uboot_board_info.bi_flashstart,
189      bsp_uboot_board_info.bi_flashsize,
190    #else /* HAS_UBOOT */
191      (uint32_t) bsp_rom_start,
192      (uint32_t) bsp_rom_size,
193    #endif /* HAS_UBOOT */
194    false,
195    false,
196    false,
197    false,
198    BPP_RX
199  );
200  SET_IBAT( 1, ibat.batu, ibat.batl);
201
202  /*
203   * Set up DBAT registers in MMU
204   */
205
206  memset(&dbat, 0, sizeof( dbat));
207  SET_DBAT( 3, dbat.batu, dbat.batl);
208  SET_DBAT( 4, dbat.batu, dbat.batl);
209  SET_DBAT( 5, dbat.batu, dbat.batl);
210  SET_DBAT( 6, dbat.batu, dbat.batl);
211  SET_DBAT( 7, dbat.batu, dbat.batl);
212
213  calc_dbat_regvals(
214    &dbat,
215    #ifdef HAS_UBOOT
216      bsp_uboot_board_info.bi_memstart,
217      bsp_uboot_board_info.bi_memsize,
218    #else /* HAS_UBOOT */
219      (uint32_t) bsp_ram_start,
220      (uint32_t) bsp_ram_size,
221    #endif /* HAS_UBOOT */
222    false,
223    false,
224    false,
225    false,
226    BPP_RW
227  );
228  SET_DBAT( 0, dbat.batu, dbat.batl);
229
230  calc_dbat_regvals(
231    &dbat,
232    #ifdef HAS_UBOOT
233      bsp_uboot_board_info.bi_flashstart,
234      bsp_uboot_board_info.bi_flashsize,
235    #else /* HAS_UBOOT */
236      (uint32_t) bsp_rom_start,
237      (uint32_t) bsp_rom_size,
238    #endif /* HAS_UBOOT */
239    true,
240    false,
241    false,
242    false,
243    BPP_RX
244  );
245  SET_DBAT( 1, dbat.batu, dbat.batl);
246
247  calc_dbat_regvals(
248    &dbat,
249    #ifdef HAS_UBOOT
250      bsp_uboot_board_info.bi_immrbar,
251    #else /* HAS_UBOOT */
252      (uint32_t) IMMRBAR,
253    #endif /* HAS_UBOOT */
254    #if MPC83XX_CHIP_TYPE / 10 == 830
255      2 * 1024 * 1024,
256    #else
257      1024 * 1024,
258    #endif
259    false,
260    true,
261    false,
262    true,
263    BPP_RW
264  );
265  SET_DBAT( 2, dbat.batu, dbat.batl);
266
267#if defined(MPC83XX_BOARD_HSC_CM01)
268  calc_dbat_regvals(
269    &dbat,
270    FPGA_START,
271    FPGA_SIZE,
272    true,
273    true,
274    true,
275    false,
276    BPP_RW
277  );
278  SET_DBAT(3,dbat.batu,dbat.batl);
279#endif
280
281#ifdef MPC83XX_BOARD_MPC8313ERDB
282  /* Enhanced Local Bus Controller (eLBC) */
283  calc_dbat_regvals(
284    &dbat,
285    0xfa000000,
286    128 * 1024,
287    false,
288    true,
289    false,
290    true,
291    BPP_RW
292  );
293  SET_DBAT( 3, dbat.batu, dbat.batl);
294#endif /* MPC83XX_BOARD_MPC8313ERDB */
295
296  /* Read MSR */
297  msr = ppc_machine_state_register();
298
299  /* Enable data and instruction MMU in MSR */
300  msr |= MSR_DR | MSR_IR;
301
302  /* Enable FPU in MSR */
303  msr |= MSR_FP;
304
305  /* Update MSR */
306  ppc_set_machine_state_register( msr);
307
308  /*
309   * In HID0:
310   *  - Enable dynamic power management
311   *  - Enable machine check interrupts
312   */
313  PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_EMCP | HID0_DPM);
314
315  /* Enable timebase clock */
316  mpc83xx.syscon.spcr |= M83xx_SYSCON_SPCR_TBEN;
317}
Note: See TracBrowser for help on using the repository browser.