source: rtems/bsps/powerpc/mvme5500/start/bspstart.c @ 54d87f2

5
Last change on this file since 54d87f2 was 54d87f2, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 4, 2018 at 4:28:57 PM

bsps/powerpc: Simplify ppc_exc_initialize()

Remove parameters from ppc_exc_initialize() since all BSPs passed the
same values.

Update #3459.

  • Property mode set to 100644
File size: 8.9 KB
Line 
1/*
2 *  This routine does the bulk of the system initialization.
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2007.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 *
13 *  Modified to support the MCP750.
14 *  Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
15 *
16 *  Modified to support the Synergy VGM & Motorola PowerPC boards
17 *  (C) by Till Straumann, <strauman@slac.stanford.edu>, 2002, 2004, 2005
18 *
19 *  Modified to support the MVME5500 board.
20 *  Also, the settings of L1, L2, and L3 caches is not necessary here.
21 *  (C) by Brookhaven National Lab., S. Kate Feng <feng1@bnl.gov>, 2003-2009
22 */
23
24#include <string.h>
25#include <stdlib.h>
26#include <ctype.h>
27
28#include <rtems/sysinit.h>
29#include <rtems/system.h>
30#include <rtems/powerpc/powerpc.h>
31
32#include <libcpu/spr.h>   /* registers.h is included here */
33#include <bsp.h>
34#include <bsp/bootcard.h>
35#include <bsp/uart.h>
36#include <bsp/pci.h>
37#include <libcpu/bat.h>
38#include <libcpu/pte121.h>
39#include <libcpu/cpuIdent.h>
40#include <bsp/vectors.h>
41#include <bsp/VME.h>
42#include <bsp/bspException.h>
43
44#include <rtems/bspIo.h>
45#include <rtems/counter.h>
46
47/*
48#define SHOW_MORE_INIT_SETTINGS
49#define SHOW_LCR1_REGISTER
50#define SHOW_LCR2_REGISTER
51#define SHOW_LCR3_REGISTER
52#define CONF_VPD
53*/
54
55extern uint32_t probeMemoryEnd(void); /* from shared/startup/probeMemoryEnd.c */
56
57BSP_output_char_function_type     BSP_output_char = BSP_output_char_via_serial;
58BSP_polling_getchar_function_type BSP_poll_char = NULL;
59
60extern void _return_to_ppcbug(void);
61extern unsigned long __rtems_end[];
62extern unsigned get_L1CR(void), get_L2CR(void), get_L3CR(void);
63extern Triv121PgTbl BSP_pgtbl_setup(unsigned int *);
64extern void BSP_pgtbl_activate(Triv121PgTbl);
65extern int I2Cread_eeprom(unsigned char I2cBusAddr, uint32_t devA2A1A0, uint32_t AddrBytes, unsigned char *pBuff, uint32_t numBytes);
66extern void BSP_vme_config(void);
67
68extern unsigned char ReadConfVPD_buff(int offset);
69
70uint32_t bsp_clicks_per_usec;
71
72typedef struct CmdLineRec_ {
73    unsigned long  size;
74    char           buf[0];
75} CmdLineRec, *CmdLine;
76
77
78#define mtspr(reg, val)  \
79  __asm __volatile("mtspr %0,%1" : : "K"(reg), "r"(val))
80
81
82#define mfspr(reg) \
83  ( { unsigned val; \
84    __asm __volatile("mfspr %0,%1" : "=r"(val) : "K"(reg)); \
85    val; } )
86
87/*
88 * Copy Additional boot param passed by boot loader
89 */
90#define MAX_LOADER_ADD_PARM 80
91char loaderParam[MAX_LOADER_ADD_PARM];
92
93/*
94 * Total memory using RESIDUAL DATA
95 */
96unsigned int BSP_mem_size;
97/*
98 * PCI Bus Frequency
99 */
100unsigned int BSP_bus_frequency;
101/*
102 * processor clock frequency
103 */
104unsigned int BSP_processor_frequency;
105/*
106 * Time base divisior (how many tick for 1 second).
107 */
108unsigned int BSP_time_base_divisor;
109static unsigned char ConfVPD_buff[200];
110
111#define CMDLINE_BUF_SIZE  2048
112
113static char cmdline_buf[CMDLINE_BUF_SIZE];
114char *BSP_commandline_string = cmdline_buf;
115
116/* NOTE: we cannot simply malloc the commandline string;
117 * save_boot_params() is called during a very early stage when
118 * libc/malloc etc. are not yet initialized!
119 *
120 * Here's what we do:
121 *
122 * initial layout setup by the loader (preload.S):
123 *
124 * 0..RTEMS...__rtems_end | cmdline ....... TOP
125 *
126 * After the save_boot_params() routine returns, the stack area will be
127 * set up (start.S):
128 *
129 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ..... TOP
130 *
131 * initialize_executive_early() [called from boot_card()]
132 * will initialize the workspace:
133 *
134 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ...... | workspace | TOP
135 *
136 * and later calls our bsp_predriver_hook() which ends up initializing
137 * libc which in turn initializes the heap
138 *
139 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | heap | workspace | TOP
140 *
141 * The idea here is to first move the commandline to the future 'heap' area
142 * from where it will be picked up by our bsp_predriver_hook().
143 * bsp_predriver_hook() then moves it either to INIT_STACK or the workspace
144 * area using proper allocation, initializes libc and finally moves
145 * the data to the environment / malloced areas...
146 */
147
148/* this routine is called early at shared/start/start.S
149 * and must be safe with a not properly aligned stack
150 */
151char *
152save_boot_params(
153  void *r3,
154  void *r4,
155  void* r5,
156  char *cmdline_start,
157  char *cmdline_end
158)
159{
160  int i=cmdline_end-cmdline_start;
161
162  if ( i >= CMDLINE_BUF_SIZE )
163    i = CMDLINE_BUF_SIZE-1;
164  else if ( i < 0 )
165    i = 0;
166
167  memmove(cmdline_buf, cmdline_start, i);
168  cmdline_buf[i]=0;
169  return cmdline_buf;
170}
171
172uint32_t _CPU_Counter_frequency(void)
173{
174  return BSP_bus_frequency / (BSP_time_base_divisor / 1000);
175}
176
177void bsp_start( void )
178{
179#ifdef CONF_VPD
180  int i;
181#endif
182#ifdef SHOW_LCR1_REGISTER
183  unsigned l1cr;
184#endif
185#ifdef SHOW_LCR2_REGISTER
186  unsigned l2cr;
187#endif
188#ifdef SHOW_LCR3_REGISTER
189  unsigned l3cr;
190#endif
191  Triv121PgTbl  pt=0;
192
193  /* Till Straumann: 4/2005
194   * Need to map the system registers early, so we can printk...
195   * (otherwise we silently die)
196   */
197  /*
198   * Kate Feng : PCI 0 domain memory space, want to leave room for the VME window
199   */
200  setdbat(2, PCI0_MEM_BASE, PCI0_MEM_BASE, 0x10000000, IO_PAGE);
201
202  /* Till Straumann: 2004
203   * map the PCI 0, 1 Domain I/O space, GT64260B registers
204   * and the reserved area so that the size is the power of 2.
205   * 2009 : map the entire 256 M space
206   *
207   */
208  setdbat(3,PCI0_IO_BASE, PCI0_IO_BASE, 0x10000000, IO_PAGE);
209
210
211  /*
212   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
213   * function store the result in global variables so that it can be used later.
214   */
215  get_ppc_cpu_type();
216  get_ppc_cpu_revision();
217
218#ifdef SHOW_LCR1_REGISTER
219  l1cr = get_L1CR();
220  printk("Initial L1CR value = %x\n", l1cr);
221#endif
222
223  ppc_exc_initialize();
224
225  /*
226   * Init MMU block address translation to enable hardware
227   * access
228   * More PCI1 memory mapping to be done after BSP_pgtbl_activate.
229   */
230  printk("-----------------------------------------\n");
231  printk("Welcome to %s on MVME5500-0163\n", _RTEMS_version );
232  printk("-----------------------------------------\n");
233
234  BSP_mem_size         =  probeMemoryEnd();
235
236  /* TODO: calculate the BSP_bus_frequency using the REF_CLK bit
237   *       of System Status  register
238   */
239  /* rtems_bsp_delay_in_bus_cycles are defined in registers.h */
240  BSP_bus_frequency      = 133333333;
241  BSP_processor_frequency    = 1000000000;
242  /* P94 : 7455 clocks the TB/DECR at 1/4 of the system bus clock frequency */
243  BSP_time_base_divisor      = 4000;
244
245  /* Maybe not setup yet becuase of the warning message */
246  /* Allocate and set up the page table mappings
247   * This is only available on >604 CPUs.
248   *
249   * NOTE: This setup routine may modify the available memory
250   *       size. It is essential to call it before
251   *       calculating the workspace etc.
252   */
253  pt = BSP_pgtbl_setup(&BSP_mem_size);
254  if (!pt)
255     printk("WARNING: unable to setup page tables.\n");
256
257  printk("Now BSP_mem_size = 0x%x\n",BSP_mem_size);
258
259  /* P94 : 7455 TB/DECR is clocked by the system bus clock frequency */
260
261  bsp_clicks_per_usec    = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
262
263  /*
264   * Initalize RTEMS IRQ system
265   */
266   BSP_rtems_irq_mng_init(0);
267
268#ifdef SHOW_LCR2_REGISTER
269  l2cr = get_L2CR();
270  printk("Initial L2CR value = %x\n", l2cr);
271#endif
272
273#ifdef SHOW_LCR3_REGISTER
274  /* L3CR needs DEC int. handler installed for bsp_delay()*/
275  l3cr = get_L3CR();
276  printk("Initial L3CR value = %x\n", l3cr);
277#endif
278
279
280  /* Activate the page table mappings only after
281   * initializing interrupts because the irq_mng_init()
282   * routine needs to modify the text
283   */
284  if (pt) {
285#ifdef SHOW_MORE_INIT_SETTINGS
286    printk("Page table setup finished; will activate it NOW...\n");
287#endif
288    BSP_pgtbl_activate(pt);
289  }
290  /* Read Configuration Vital Product Data (VPD) */
291  if ( I2Cread_eeprom(0xa8, 4,2, &ConfVPD_buff[0], 150))
292     printk("I2Cread_eeprom() error \n");
293  else {
294#ifdef CONF_VPD
295    printk("\n");
296    for (i=0; i<150; i++) {
297      printk("%2x ", ConfVPD_buff[i]);
298      if ((i % 20)==0 ) printk("\n");
299    }
300    printk("\n");
301#endif
302  }
303
304  /*
305   * PCI 1 domain memory space
306   */
307  setdbat(1, PCI1_MEM_BASE, PCI1_MEM_BASE, 0x10000000, IO_PAGE);
308
309
310#ifdef SHOW_MORE_INIT_SETTINGS
311  printk("Going to start PCI buses scanning and initialization\n");
312#endif
313  pci_initialize();
314#ifdef SHOW_MORE_INIT_SETTINGS
315  printk("Number of PCI buses found is : %d\n", pci_bus_count());
316#endif
317
318  /* Install our own exception handler (needs PCI) */
319  globalExceptHdl = BSP_exceptionHandler;
320
321  /* clear hostbridge errors. MCP signal is not used on the MVME5500
322   * PCI config space scanning code will trip otherwise :-(
323   */
324  _BSP_clear_hostbridge_errors(0, 1 /*quiet*/);
325
326#ifdef SHOW_MORE_INIT_SETTINGS
327  printk("MSR %x \n", _read_MSR());
328  printk("Exit from bspstart\n");
329#endif
330
331}
332
333unsigned char ReadConfVPD_buff(int offset)
334{
335  return(ConfVPD_buff[offset]);
336}
337
338RTEMS_SYSINIT_ITEM(
339  BSP_vme_config,
340  RTEMS_SYSINIT_BSP_PRE_DRIVERS,
341  RTEMS_SYSINIT_ORDER_MIDDLE
342);
Note: See TracBrowser for help on using the repository browser.