source: rtems/c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c @ 4130d8e2

4.104.114.95
Last change on this file since 4130d8e2 was 4130d8e2, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 15:50:25

2007-12-11 Joel Sherrill <joel.sherrill@…>

  • include/bsp.h, startup/bspstart.c: Eliminate copies of the Configuration Table. Use the RTEMS provided accessor macros to obtain configuration fields.
  • Property mode set to 100644
File size: 12.4 KB
Line 
1/*
2 *  This routine starts the application.  It includes application,
3 *  board, and monitor specific initialization and configuration.
4 *  The generic CPU dependent initialization has been performed
5 *  before this routine is invoked.
6 *
7 *  COPYRIGHT (c) 1989-2007.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *  Modified to support the MCP750.
15 *  Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
16 *
17 *  Modified to support the Synergy VGM & Motorola PowerPC boards
18 *  (C) by Till Straumann, <strauman@slac.stanford.edu>, 2002, 2004, 2005
19 *
20 *  Modified to support the MVME5500 board.
21 *  Also, the settings of L1, L2, and L3 caches is not necessary here.
22 *  (C) by Brookhaven National Lab., S. Kate Feng <feng1@bnl.gov>, 2003-2007
23 * 
24 *  $Id$
25 */
26
27#include <string.h>
28#include <stdlib.h>
29#include <ctype.h>
30
31#include <rtems/system.h>
32#include <rtems/libio.h>
33#include <rtems/libcsupport.h>
34#include <rtems/powerpc/powerpc.h>
35
36#include <libcpu/spr.h>   /* registers.h is included here */
37#include <bsp.h>
38#include <bsp/uart.h>
39#include <bsp/pci.h>
40#include <libcpu/bat.h>
41#include <libcpu/pte121.h>
42#include <libcpu/cpuIdent.h>
43#include <bsp/vectors.h>
44#include <bsp/bspException.h>
45
46#include <rtems/bspIo.h>
47#include <rtems/sptables.h>
48
49#ifdef __RTEMS_APPLICATION__
50#undef __RTEMS_APPLICATION__
51#endif
52
53/*
54#define SHOW_MORE_INIT_SETTINGS
55#define SHOW_LCR1_REGISTER
56#define SHOW_LCR2_REGISTER
57#define SHOW_LCR3_REGISTER
58#define CONF_VPD
59*/
60
61/* there is no public Workspace_Free() variant :-( */
62#include <rtems/score/wkspace.h>
63
64BSP_output_char_function_type BSP_output_char = BSP_output_char_via_serial;
65
66extern void _return_to_ppcbug();
67extern unsigned long __rtems_end[];
68extern unsigned get_L1CR(), get_L2CR(), get_L3CR();
69extern void bsp_cleanup(void);
70extern Triv121PgTbl BSP_pgtbl_setup();
71extern void BSP_pgtbl_activate();
72extern int I2Cread_eeprom();
73extern void BSP_vme_config(void);
74
75uint32_t bsp_clicks_per_usec;
76
77SPR_RW(SPRG0)
78SPR_RW(SPRG1)
79
80typedef struct CmdLineRec_ {
81    unsigned long  size;
82    char           buf[0];
83} CmdLineRec, *CmdLine;
84
85
86#define mtspr(reg, val)  \
87  __asm __volatile("mtspr %0,%1" : : "K"(reg), "r"(val))
88
89
90#define mfspr(reg) \
91  ( { unsigned val; \
92    __asm __volatile("mfspr %0,%1" : "=r"(val) : "K"(reg)); \
93    val; } )
94
95/*
96 * Copy Additional boot param passed by boot loader
97 */
98#define MAX_LOADER_ADD_PARM 80
99char loaderParam[MAX_LOADER_ADD_PARM];
100
101/*
102 * Total memory using RESIDUAL DATA
103 */
104unsigned int BSP_mem_size;
105/*
106 * PCI Bus Frequency
107 */
108/*
109 * Start of the heap
110 */
111unsigned int BSP_heap_start;
112
113unsigned int BSP_bus_frequency;
114/*
115 * processor clock frequency
116 */
117unsigned int BSP_processor_frequency;
118/*
119 * Time base divisior (how many tick for 1 second).
120 */
121unsigned int BSP_time_base_divisor;
122unsigned char ConfVPD_buff[200];
123
124#define CMDLINE_BUF_SIZE  2048
125
126static char cmdline_buf[CMDLINE_BUF_SIZE];
127char *BSP_commandline_string = cmdline_buf;
128
129/*
130 * system init stack
131 */
132#define INIT_STACK_SIZE 0x1000
133
134void BSP_panic(char *s)
135{
136  printk("%s PANIC %s\n",_RTEMS_version, s);
137  __asm__ __volatile ("sc");
138}
139
140void _BSP_Fatal_error(unsigned int v)
141{
142  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
143  __asm__ __volatile ("sc");
144}
145 
146/*
147 *  Use the shared implementations of the following routines
148 */
149 
150extern void bsp_postdriver_hook(void); /* see c/src/lib/libbsp/shared/bsppost.c */
151
152extern void bsp_libc_init( void *, uint32_t, int );
153
154extern void bsp_pretasking_hook(void);
155
156void zero_bss()
157{
158  /* prevent these from being accessed in the short data areas */
159  extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[];
160  extern unsigned long __SBSS2_START__[], __SBSS2_END__[];
161
162  memset(
163    __SBSS_START__,
164    0,
165    ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__)
166  );
167  memset(
168    __SBSS2_START__,
169    0,
170    ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__)
171  );
172  memset(
173    __bss_start,
174    0,
175    ((unsigned) __rtems_end) - ((unsigned)__bss_start)
176  );
177}
178
179/* NOTE: we cannot simply malloc the commandline string;
180 * save_boot_params() is called during a very early stage when
181 * libc/malloc etc. are not yet initialized!
182 *
183 * Here's what we do:
184 *
185 * initial layout setup by the loader (preload.S):
186 *
187 * 0..RTEMS...__rtems_end | cmdline ....... TOP
188 *
189 * After the save_boot_params() routine returns, the stack area will be
190 * set up (start.S):
191 *
192 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ..... TOP
193 *
194 * initialize_executive_early() [called from boot_card()]
195 * will initialize the workspace:
196 *
197 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ...... | workspace | TOP
198 *
199 * and later calls our pretasking_hook() which ends up initializing
200 * libc which in turn initializes the heap
201 *
202 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | heap | workspace | TOP
203 *
204 * The idea here is to first move the commandline to the future 'heap' area
205 * from where it will be picked up by our pretasking_hook().
206 * pretasking_hook() then moves it either to INIT_STACK or the workspace
207 * area using proper allocation, initializes libc and finally moves
208 * the data to the environment / malloced areas...
209 */
210
211/* this routine is called early at shared/start/start.S
212 * and must be safe with a not properly aligned stack
213 */
214void
215save_boot_params(
216  void *r3,
217  void *r4,
218  void* r5,
219  char *cmdline_start,
220  char *cmdline_end
221)
222{
223  int i=cmdline_end-cmdline_start;
224
225  if ( i >= CMDLINE_BUF_SIZE )
226    i = CMDLINE_BUF_SIZE-1;
227  else if ( i < 0 )
228    i = 0;
229
230  memmove(cmdline_buf, cmdline_start, i);
231  cmdline_buf[i]=0;
232}
233
234/*
235 *  bsp_start
236 *
237 *  This routine does the bulk of the system initialization.
238 */
239
240void bsp_start( void )
241{
242#ifdef CONF_VPD
243  int i;
244#endif
245  unsigned char *stack;
246  unsigned long   *r1sp;
247#ifdef SHOW_LCR1_REGISTER
248  unsigned l1cr;
249#endif
250#ifdef SHOW_LCR2_REGISTER
251  unsigned l2cr;
252#endif
253#ifdef SHOW_LCR3_REGISTER
254  unsigned l3cr;
255#endif
256  register uint32_t  intrStack;
257  register uint32_t *intrStackPtr;
258  unsigned char *work_space_start;
259  ppc_cpu_id_t myCpu;
260  ppc_cpu_revision_t myCpuRevision;
261  Triv121PgTbl  pt=0;
262
263  /* Till Straumann: 4/2005
264   * Need to map the system registers early, so we can printk...
265   * (otherwise we silently die)
266   */
267  /*
268   * Kate Feng : PCI 0 domain memory space, want to leave room for the VME window
269   */
270  setdbat(2, PCI0_MEM_BASE, PCI0_MEM_BASE, 0x10000000, IO_PAGE);
271
272  /* Till Straumann: 2004
273   * map the PCI 0, 1 Domain I/O space, GT64260B registers
274   * and the reserved area so that the size is the power of 2.
275   *
276   */
277  setdbat(3,PCI0_IO_BASE, PCI0_IO_BASE, 0x2000000, IO_PAGE);
278
279
280  /*
281   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
282   * store the result in global variables so that it can be used latter...
283   */
284  myCpu   = get_ppc_cpu_type();
285  myCpuRevision = get_ppc_cpu_revision();
286
287#ifdef SHOW_LCR1_REGISTER
288  l1cr = get_L1CR();
289  printk("Initial L1CR value = %x\n", l1cr);
290#endif
291
292  /*
293   * the initial stack  has aready been set to this value in start.S
294   * so there is no need to set it in r1 again... It is just for info
295   * so that it can be printed without accessing R1.
296   */
297  stack = ((unsigned char*) __rtems_end) +
298          INIT_STACK_SIZE - PPC_MINIMUM_STACK_FRAME_SIZE;
299
300  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
301  *((uint32_t *)stack) = 0;
302
303  /* fill stack with pattern for debugging */
304  __asm__ __volatile__("mr %0, %%r1":"=r"(r1sp));
305  while (--r1sp >= (unsigned long*)__rtems_end)
306    *r1sp=0xeeeeeeee;
307
308  /*
309   * Initialize the interrupt related settings
310   * SPRG0 = interrupt nesting level count
311   * SPRG1 = software managed IRQ stack
312   *
313   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
314   * some settings below...
315   */
316  BSP_heap_start = ((uint32_t) __rtems_end) + INIT_STACK_SIZE +
317    rtems_configuration_get_interrupt_stack_size();
318  intrStack = BSP_heap_start - PPC_MINIMUM_STACK_FRAME_SIZE;
319
320  /* make sure it's properly aligned */
321  intrStack &= ~(CPU_STACK_ALIGNMENT-1);
322
323  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
324  intrStackPtr = (uint32_t*) intrStack;
325  *intrStackPtr = 0;
326
327  _write_SPRG1(intrStack);
328
329  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
330
331  /*
332   * Initialize default raw exception hanlders. See vectors/vectors_init.c
333   */
334  initialize_exceptions();
335
336  /*
337   * Init MMU block address translation to enable hardware
338   * access
339   * More PCI1 memory mapping to be done after BSP_pgtbl_activate.
340   */
341  printk("-----------------------------------------\n");
342  printk("Welcome to %s on MVME5500-0163\n", _RTEMS_version );
343  printk("-----------------------------------------\n");
344
345#ifdef TEST_RETURN_TO_PPCBUG 
346  printk("Hit <Enter> to return to PPCBUG monitor\n");
347  printk("When Finished hit GO. It should print <Back from monitor>\n");
348  debug_getc();
349  _return_to_ppcbug();
350  printk("Back from monitor\n");
351  _return_to_ppcbug();
352#endif /* TEST_RETURN_TO_PPCBUG  */
353
354#ifdef TEST_RAW_EXCEPTION_CODE 
355  printk("Testing exception handling Part 1\n");
356  /*
357   * Cause a software exception
358   */
359  __asm__ __volatile ("sc");
360  /*
361   * Check we can still catch exceptions and returned coorectly.
362   */
363  printk("Testing exception handling Part 2\n");
364  __asm__ __volatile ("sc");
365#endif 
366
367  BSP_mem_size         =  _512M;
368  /* TODO: calculate the BSP_bus_frequency using the REF_CLK bit
369   *       of System Status  register
370   */
371  /* rtems_bsp_delay_in_bus_cycles are defined in registers.h */
372  BSP_bus_frequency      = 133333333;
373  BSP_processor_frequency    = 1000000000;
374  /* P94 : 7455 clocks the TB/DECR at 1/4 of the system bus clock frequency */
375  BSP_time_base_divisor      = 4000;
376
377
378  /* Maybe not setup yet becuase of the warning message */
379  /* Allocate and set up the page table mappings
380   * This is only available on >604 CPUs.
381   *
382   * NOTE: This setup routine may modify the available memory
383   *       size. It is essential to call it before
384   *       calculating the workspace etc.
385   */
386  pt = BSP_pgtbl_setup(&BSP_mem_size);
387  if (!pt)
388     printk("WARNING: unable to setup page tables.\n");
389
390  printk("Now BSP_mem_size = 0x%x\n",BSP_mem_size);
391
392  /* P94 : 7455 TB/DECR is clocked by the system bus clock frequency */
393
394  bsp_clicks_per_usec    = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
395
396  printk(
397    "rtems_configuration_get_work_space_size() = %x\n",
398     rtems_configuration_get_work_space_size()
399  );
400
401  work_space_start =
402    (unsigned char *)BSP_mem_size - rtems_configuration_get_work_space_size();
403
404  if ( work_space_start <= ((unsigned char *)__rtems_end) + INIT_STACK_SIZE +
405        rtems_configuration_get_interrupt_stack_size()) {
406    printk( "bspstart: Not enough RAM!!!\n" );
407    bsp_cleanup();
408  }
409
410  Configuration.work_space_start = work_space_start;
411
412  /*
413   * Initalize RTEMS IRQ system
414   */
415   BSP_rtems_irq_mng_init(0);
416
417#ifdef SHOW_LCR2_REGISTER
418  l2cr = get_L2CR();
419  printk("Initial L2CR value = %x\n", l2cr);
420#endif 
421
422#ifdef SHOW_LCR3_REGISTER
423  /* L3CR needs DEC int. handler installed for bsp_delay()*/
424  l3cr = get_L3CR();
425  printk("Initial L3CR value = %x\n", l3cr);
426#endif 
427
428
429  /* Activate the page table mappings only after
430   * initializing interrupts because the irq_mng_init()
431   * routine needs to modify the text
432   */           
433  if (pt) {
434#ifdef SHOW_MORE_INIT_SETTINGS
435    printk("Page table setup finished; will activate it NOW...\n");
436#endif
437    BSP_pgtbl_activate(pt);
438  }
439
440  /*
441   * PCI 1 domain memory space
442   */
443  setdbat(1, PCI1_MEM_BASE, PCI1_MEM_BASE, 0x10000000, IO_PAGE);
444 
445
446#ifdef SHOW_MORE_INIT_SETTINGS
447  printk("Going to start PCI buses scanning and initialization\n");
448#endif 
449  pci_initialize();
450#ifdef SHOW_MORE_INIT_SETTINGS
451  printk("Number of PCI buses found is : %d\n", pci_bus_count());
452#endif
453
454  /* Install our own exception handler (needs PCI) */
455  globalExceptHdl = BSP_exceptionHandler;
456
457  /* clear hostbridge errors. MCP signal is not used on the MVME5500
458   * PCI config space scanning code will trip otherwise :-(
459   */
460  _BSP_clear_hostbridge_errors(0, 1 /*quiet*/);
461
462  /* Read Configuration Vital Product Data (VPD) */
463  if ( I2Cread_eeprom(0xa8, 4,2, &ConfVPD_buff[0], 150))
464     printk("I2Cread_eeprom() error \n");
465  else {
466#ifdef CONF_VPD
467    printk("\n");
468    for (i=0; i<150; i++) {
469      printk("%2x ", ConfVPD_buff[i]); 
470      if ((i % 20)==0 ) printk("\n");
471    }
472    printk("\n");
473#endif
474  }
475
476#ifdef SHOW_MORE_INIT_SETTINGS
477  printk("MSR %x \n", _read_MSR());
478  printk("Exit from bspstart\n");
479#endif
480
481}
Note: See TracBrowser for help on using the repository browser.