source: rtems/bsps/powerpc/gen83xx/start/cpuinit.c @ 65f868c

5
Last change on this file since 65f868c was 9964895, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 08:35:35

bsps: Move startup files to bsps

Adjust build support files to new directory layout.

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 10.1 KB
RevLine 
[f610e83f]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|                                                                 |
[c499856]17| http://www.rtems.org/license/LICENSE.                           |
[f610e83f]18|                                                                 |
19+-----------------------------------------------------------------+
20| this file contains the code to initialize the cpu               |
21\*===============================================================*/
[dfef80e8]22
23
[f610e83f]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
[d79a27be]70#include <stdbool.h>
71#include <string.h>
[f610e83f]72
[d79a27be]73#include <libcpu/powerpc-utility.h>
[f610e83f]74#include <libcpu/mmu.h>
75
[d79a27be]76#include <mpc83xx/mpc83xx.h>
77
78#include <bsp.h>
[ce0922e]79#include <bsp/u-boot.h>
[d79a27be]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)
[f610e83f]103{
[d79a27be]104  uint32_t block_mask = 0xffffffff;
105  uint32_t end_addr = base_addr + size - 1;
[f610e83f]106
[d79a27be]107  /* Determine block mask, that overlaps the whole block */
[f610e83f]108  while ((end_addr & block_mask) != (base_addr & block_mask)) {
109    block_mask <<= 1;
110  }
[ac7af4a]111
112  bat_ptr->batu.bepi = base_addr >> (32 - 15);
[d79a27be]113  bat_ptr->batu.bl   = ~(block_mask >> (28 - 11));
114  bat_ptr->batu.vs   = 1;
115  bat_ptr->batu.vp   = 1;
[ac7af4a]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;
[f610e83f]123}
124
[d79a27be]125static void clear_mmu_regs( void)
[f610e83f]126{
127  uint32_t i;
[d79a27be]128
129  /* Clear segment registers */
[f610e83f]130  for (i = 0;i < 16;i++) {
[0d01467b]131    __asm__ volatile( "mtsrin %0, %1\n" : : "r" (i * 0x1000), "r" (i << (31 - 3)));
[f610e83f]132  }
[ac7af4a]133
[d79a27be]134  /* Clear TLBs */
[f610e83f]135  for (i = 0;i < 32;i++) {
[0d01467b]136    __asm__ volatile( "tlbie %0\n" : : "r" (i << (31 - 19)));
[f610e83f]137  }
138}
139
[d79a27be]140void cpu_init( void)
[f610e83f]141{
[d79a27be]142  BAT dbat, ibat;
143  uint32_t msr;
[bfde536e]144  uint32_t hid0;
[f610e83f]145
[d79a27be]146  /* Clear MMU and segment registers */
[f610e83f]147  clear_mmu_regs();
[d79a27be]148
149  /* Clear caches */
[bfde536e]150  hid0 = PPC_SPECIAL_PURPOSE_REGISTER(HID0);
151  if ((hid0 & (HID0_ICE | HID0_DCE)) == 0) {
152    hid0 &= ~(HID0_ILOCK | HID0_DLOCK | HID0_ICE | HID0_DCE);
153    PPC_SET_SPECIAL_PURPOSE_REGISTER(HID0, hid0);
154    hid0 |= HID0_ICFI | HID0_DCI;
155    PPC_SET_SPECIAL_PURPOSE_REGISTER(HID0, hid0);
156    hid0 &= ~(HID0_ICFI | HID0_DCI);
157    PPC_SET_SPECIAL_PURPOSE_REGISTER(HID0, hid0);
158  }
[ac7af4a]159
[f610e83f]160  /*
[d79a27be]161   * Set up IBAT registers in MMU
[f610e83f]162   */
163
[d79a27be]164  memset(&ibat, 0, sizeof( ibat));
165  SET_IBAT( 2, ibat.batu, ibat.batl);
166  SET_IBAT( 3, ibat.batu, ibat.batl);
167  SET_IBAT( 4, ibat.batu, ibat.batl);
168  SET_IBAT( 5, ibat.batu, ibat.batl);
169  SET_IBAT( 6, ibat.batu, ibat.batl);
170  SET_IBAT( 7, ibat.batu, ibat.batl);
171
172  calc_dbat_regvals(
173    &ibat,
174    #ifdef HAS_UBOOT
[f044f9c]175      bsp_uboot_board_info.bi_memstart,
176      bsp_uboot_board_info.bi_memsize,
[d79a27be]177    #else /* HAS_UBOOT */
178      (uint32_t) bsp_ram_start,
179      (uint32_t) bsp_ram_size,
180    #endif /* HAS_UBOOT */
181    false,
182    false,
183    false,
184    false,
185    BPP_RX
186  );
187  SET_IBAT( 0, ibat.batu, ibat.batl);
[f610e83f]188
[d79a27be]189  calc_dbat_regvals(
190    &ibat,
191    #ifdef HAS_UBOOT
[f044f9c]192      bsp_uboot_board_info.bi_flashstart,
193      bsp_uboot_board_info.bi_flashsize,
[d79a27be]194    #else /* HAS_UBOOT */
195      (uint32_t) bsp_rom_start,
196      (uint32_t) bsp_rom_size,
197    #endif /* HAS_UBOOT */
198    false,
199    false,
200    false,
201    false,
202    BPP_RX
203  );
204  SET_IBAT( 1, ibat.batu, ibat.batl);
[574fb67]205
[d79a27be]206  /*
207   * Set up DBAT registers in MMU
208   */
[f610e83f]209
[d79a27be]210  memset(&dbat, 0, sizeof( dbat));
211  SET_DBAT( 3, dbat.batu, dbat.batl);
212  SET_DBAT( 4, dbat.batu, dbat.batl);
213  SET_DBAT( 5, dbat.batu, dbat.batl);
214  SET_DBAT( 6, dbat.batu, dbat.batl);
215  SET_DBAT( 7, dbat.batu, dbat.batl);
[574fb67]216
[d79a27be]217  calc_dbat_regvals(
218    &dbat,
219    #ifdef HAS_UBOOT
[f044f9c]220      bsp_uboot_board_info.bi_memstart,
221      bsp_uboot_board_info.bi_memsize,
[d79a27be]222    #else /* HAS_UBOOT */
223      (uint32_t) bsp_ram_start,
224      (uint32_t) bsp_ram_size,
225    #endif /* HAS_UBOOT */
226    false,
227    false,
228    false,
229    false,
230    BPP_RW
231  );
232  SET_DBAT( 0, dbat.batu, dbat.batl);
[f610e83f]233
[d79a27be]234  calc_dbat_regvals(
235    &dbat,
236    #ifdef HAS_UBOOT
[f044f9c]237      bsp_uboot_board_info.bi_flashstart,
238      bsp_uboot_board_info.bi_flashsize,
[d79a27be]239    #else /* HAS_UBOOT */
240      (uint32_t) bsp_rom_start,
241      (uint32_t) bsp_rom_size,
242    #endif /* HAS_UBOOT */
[907b07d9]243    #ifdef MPC83XX_HAS_NAND_LP_FLASH_ON_CS0
244      false,
245      true,
246      false,
247      true,
248      BPP_RW
249    #else
250      true,
251      false,
252      false,
253      false,
254      BPP_RX
255    #endif
[d79a27be]256  );
257  SET_DBAT( 1, dbat.batu, dbat.batl);
[574fb67]258
[d79a27be]259  calc_dbat_regvals(
260    &dbat,
261    #ifdef HAS_UBOOT
[f044f9c]262      bsp_uboot_board_info.bi_immrbar,
[d79a27be]263    #else /* HAS_UBOOT */
264      (uint32_t) IMMRBAR,
265    #endif /* HAS_UBOOT */
[a3db5ff4]266    #if MPC83XX_CHIP_TYPE / 10 == 830
267      2 * 1024 * 1024,
268    #else
269      1024 * 1024,
270    #endif
[d79a27be]271    false,
272    true,
273    false,
274    true,
275    BPP_RW
276  );
277  SET_DBAT( 2, dbat.batu, dbat.batl);
[f610e83f]278
[7a752161]279#if defined(MPC83XX_BOARD_HSC_CM01)
[4b23c94]280  calc_dbat_regvals(
281    &dbat,
282    FPGA_START,
283    FPGA_SIZE,
284    true,
285    true,
286    true,
287    false,
288    BPP_RW
289  );
290  SET_DBAT(3,dbat.batu,dbat.batl);
291#endif
292
[7a752161]293#ifdef MPC83XX_BOARD_MPC8313ERDB
[541c9e84]294  /* Enhanced Local Bus Controller (eLBC) */
[d79a27be]295  calc_dbat_regvals(
296    &dbat,
297    0xfa000000,
298    128 * 1024,
299    false,
300    true,
301    false,
302    true,
303    BPP_RW
304  );
[541c9e84]305  SET_DBAT( 3, dbat.batu, dbat.batl);
[7a752161]306#endif /* MPC83XX_BOARD_MPC8313ERDB */
[541c9e84]307
[d79a27be]308  /* Read MSR */
309  msr = ppc_machine_state_register();
[f610e83f]310
[d79a27be]311  /* Enable data and instruction MMU in MSR */
312  msr |= MSR_DR | MSR_IR;
[f610e83f]313
[d79a27be]314  /* Enable FPU in MSR */
315  msr |= MSR_FP;
316
317  /* Update MSR */
318  ppc_set_machine_state_register( msr);
[f610e83f]319
320  /*
[ac7af4a]321   * In HID0:
[d79a27be]322   *  - Enable dynamic power management
323   *  - Enable machine check interrupts
[f610e83f]324   */
[d79a27be]325  PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( HID0, HID0_EMCP | HID0_DPM);
326
327  /* Enable timebase clock */
[f610e83f]328  mpc83xx.syscon.spcr |= M83xx_SYSCON_SPCR_TBEN;
329}
Note: See TracBrowser for help on using the repository browser.