source: rtems/c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c @ 72510eb2

4.104.115
Last change on this file since 72510eb2 was 72510eb2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/08/09 at 18:12:31

2009-05-08 Kate Feng <feng1@…>

  • include/bsp.h, start/start.S, startup/bspstart.c: added CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK in bsp.h. removed BSP_INIT_STACK_SIZE in bsp.h -- it uses stack defined by the linker script (shared/startup/linkcmds) for the initial stack. replaced rtems_end+4096 with stack in start.S Removed legacy code in bspstart.c (inherited from old mvme2307 BSP but not relevant to this one) that tested trapping into PPCBug. Changed ConfVPD_buff[] to be static and added ReadConfVPD_buf() in bspstart.c
  • Property mode set to 100644
File size: 10.1 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-2009
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/powerpc/powerpc.h>
33
34#include <libcpu/spr.h>   /* registers.h is included here */
35#include <bsp.h>
36#include <bsp/uart.h>
37#include <bsp/pci.h>
38#include <libcpu/bat.h>
39#include <libcpu/pte121.h>
40#include <libcpu/cpuIdent.h>
41#include <bsp/vectors.h>
42#include <bsp/bspException.h>
43
44#include <rtems/bspIo.h>
45#include <rtems/sptables.h>
46
47#ifdef __RTEMS_APPLICATION__
48#undef __RTEMS_APPLICATION__
49#endif
50
51/*
52#define SHOW_MORE_INIT_SETTINGS
53#define SHOW_LCR1_REGISTER
54#define SHOW_LCR2_REGISTER
55#define SHOW_LCR3_REGISTER
56#define CONF_VPD
57*/
58
59/* there is no public Workspace_Free() variant :-( */
60#include <rtems/score/wkspace.h>
61
62BSP_output_char_function_type BSP_output_char = BSP_output_char_via_serial;
63
64extern void _return_to_ppcbug(void);
65extern unsigned long __rtems_end[];
66extern unsigned get_L1CR(void), get_L2CR(void), get_L3CR(void);
67extern Triv121PgTbl BSP_pgtbl_setup(unsigned long);
68extern void BSP_pgtbl_activate(Triv121PgTbl);
69extern int I2Cread_eeprom(unsigned char I2cBusAddr, uint32_t devA2A1A0, uint32_t AddrBytes, unsigned char *pBuff, uint32_t numBytes);
70extern void BSP_vme_config(void);
71
72uint32_t bsp_clicks_per_usec;
73
74SPR_RW(SPRG1)
75
76typedef struct CmdLineRec_ {
77    unsigned long  size;
78    char           buf[0];
79} CmdLineRec, *CmdLine;
80
81
82#define mtspr(reg, val)  \
83  __asm __volatile("mtspr %0,%1" : : "K"(reg), "r"(val))
84
85
86#define mfspr(reg) \
87  ( { unsigned val; \
88    __asm __volatile("mfspr %0,%1" : "=r"(val) : "K"(reg)); \
89    val; } )
90
91/*
92 * Copy Additional boot param passed by boot loader
93 */
94#define MAX_LOADER_ADD_PARM 80
95char loaderParam[MAX_LOADER_ADD_PARM];
96
97/*
98 * Total memory using RESIDUAL DATA
99 */
100unsigned int BSP_mem_size;
101/*
102 * PCI Bus Frequency
103 */
104unsigned int BSP_bus_frequency;
105/*
106 * processor clock frequency
107 */
108unsigned int BSP_processor_frequency;
109/*
110 * Time base divisior (how many tick for 1 second).
111 */
112unsigned int BSP_time_base_divisor;
113static unsigned char ConfVPD_buff[200];
114
115#define CMDLINE_BUF_SIZE  2048
116
117static char cmdline_buf[CMDLINE_BUF_SIZE];
118char *BSP_commandline_string = cmdline_buf;
119
120void BSP_panic(char *s)
121{
122  printk("%s PANIC %s\n",_RTEMS_version, s);
123  __asm__ __volatile ("sc");
124}
125
126void _BSP_Fatal_error(unsigned int v)
127{
128  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
129  __asm__ __volatile ("sc");
130}
131 
132void zero_bss()
133{
134  /* prevent these from being accessed in the short data areas */
135  extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[];
136  extern unsigned long __SBSS2_START__[], __SBSS2_END__[];
137
138  memset(
139    __SBSS_START__,
140    0,
141    ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__)
142  );
143  memset(
144    __SBSS2_START__,
145    0,
146    ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__)
147  );
148  memset(
149    __bss_start,
150    0,
151    ((unsigned) __rtems_end) - ((unsigned)__bss_start)
152  );
153}
154
155/* NOTE: we cannot simply malloc the commandline string;
156 * save_boot_params() is called during a very early stage when
157 * libc/malloc etc. are not yet initialized!
158 *
159 * Here's what we do:
160 *
161 * initial layout setup by the loader (preload.S):
162 *
163 * 0..RTEMS...__rtems_end | cmdline ....... TOP
164 *
165 * After the save_boot_params() routine returns, the stack area will be
166 * set up (start.S):
167 *
168 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ..... TOP
169 *
170 * initialize_executive_early() [called from boot_card()]
171 * will initialize the workspace:
172 *
173 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ...... | workspace | TOP
174 *
175 * and later calls our pretasking_hook() which ends up initializing
176 * libc which in turn initializes the heap
177 *
178 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | heap | workspace | TOP
179 *
180 * The idea here is to first move the commandline to the future 'heap' area
181 * from where it will be picked up by our pretasking_hook().
182 * pretasking_hook() then moves it either to INIT_STACK or the workspace
183 * area using proper allocation, initializes libc and finally moves
184 * the data to the environment / malloced areas...
185 */
186
187/* this routine is called early at shared/start/start.S
188 * and must be safe with a not properly aligned stack
189 */
190void
191save_boot_params(
192  void *r3,
193  void *r4,
194  void* r5,
195  char *cmdline_start,
196  char *cmdline_end
197)
198{
199  int i=cmdline_end-cmdline_start;
200
201  if ( i >= CMDLINE_BUF_SIZE )
202    i = CMDLINE_BUF_SIZE-1;
203  else if ( i < 0 )
204    i = 0;
205
206  memmove(cmdline_buf, cmdline_start, i);
207  cmdline_buf[i]=0;
208}
209
210/*
211 *  bsp_start
212 *
213 *  This routine does the bulk of the system initialization.
214 */
215
216void bsp_start( void )
217{
218#ifdef CONF_VPD
219  int i;
220#endif
221  unsigned char *stack;
222  unsigned long   *r1sp;
223#ifdef SHOW_LCR1_REGISTER
224  unsigned l1cr;
225#endif
226#ifdef SHOW_LCR2_REGISTER
227  unsigned l2cr;
228#endif
229#ifdef SHOW_LCR3_REGISTER
230  unsigned l3cr;
231#endif
232  uint32_t intrStackStart;
233  uint32_t intrStackSize;
234  ppc_cpu_id_t myCpu;
235  ppc_cpu_revision_t myCpuRevision;
236  Triv121PgTbl  pt=0;
237
238  /* Till Straumann: 4/2005
239   * Need to map the system registers early, so we can printk...
240   * (otherwise we silently die)
241   */
242  /*
243   * Kate Feng : PCI 0 domain memory space, want to leave room for the VME window
244   */
245  setdbat(2, PCI0_MEM_BASE, PCI0_MEM_BASE, 0x10000000, IO_PAGE);
246
247  /* Till Straumann: 2004
248   * map the PCI 0, 1 Domain I/O space, GT64260B registers
249   * and the reserved area so that the size is the power of 2.
250   * 2009 : map the entire 256 M space
251   *
252   */
253  setdbat(3,PCI0_IO_BASE, PCI0_IO_BASE, 0x10000000, IO_PAGE);
254
255
256  /*
257   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
258   * store the result in global variables so that it can be used latter...
259   */
260  myCpu   = get_ppc_cpu_type();
261  myCpuRevision = get_ppc_cpu_revision();
262
263#ifdef SHOW_LCR1_REGISTER
264  l1cr = get_L1CR();
265  printk("Initial L1CR value = %x\n", l1cr);
266#endif
267
268  /*
269   * Initialize the interrupt related settings.
270   */
271  intrStackStart = (uint32_t) __rtems_end;
272  intrStackSize = rtems_configuration_get_interrupt_stack_size();
273
274  /*
275   * Initialize default raw exception handlers.
276   */
277  ppc_exc_initialize(
278    PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
279    intrStackStart,
280    intrStackSize
281  );
282
283  /*
284   * Init MMU block address translation to enable hardware
285   * access
286   * More PCI1 memory mapping to be done after BSP_pgtbl_activate.
287   */
288  printk("-----------------------------------------\n");
289  printk("Welcome to %s on MVME5500-0163\n", _RTEMS_version );
290  printk("-----------------------------------------\n");
291
292  BSP_mem_size         =  probeMemoryEnd();
293  /* TODO: calculate the BSP_bus_frequency using the REF_CLK bit
294   *       of System Status  register
295   */
296  /* rtems_bsp_delay_in_bus_cycles are defined in registers.h */
297  BSP_bus_frequency      = 133333333;
298  BSP_processor_frequency    = 1000000000;
299  /* P94 : 7455 clocks the TB/DECR at 1/4 of the system bus clock frequency */
300  BSP_time_base_divisor      = 4000;
301
302
303  /* Maybe not setup yet becuase of the warning message */
304  /* Allocate and set up the page table mappings
305   * This is only available on >604 CPUs.
306   *
307   * NOTE: This setup routine may modify the available memory
308   *       size. It is essential to call it before
309   *       calculating the workspace etc.
310   */
311  pt = BSP_pgtbl_setup(&BSP_mem_size);
312  if (!pt)
313     printk("WARNING: unable to setup page tables.\n");
314
315  printk("Now BSP_mem_size = 0x%x\n",BSP_mem_size);
316
317  /* P94 : 7455 TB/DECR is clocked by the system bus clock frequency */
318
319  bsp_clicks_per_usec    = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
320
321  /*
322   * Initalize RTEMS IRQ system
323   */
324   BSP_rtems_irq_mng_init(0);
325
326#ifdef SHOW_LCR2_REGISTER
327  l2cr = get_L2CR();
328  printk("Initial L2CR value = %x\n", l2cr);
329#endif 
330
331#ifdef SHOW_LCR3_REGISTER
332  /* L3CR needs DEC int. handler installed for bsp_delay()*/
333  l3cr = get_L3CR();
334  printk("Initial L3CR value = %x\n", l3cr);
335#endif 
336
337
338  /* Activate the page table mappings only after
339   * initializing interrupts because the irq_mng_init()
340   * routine needs to modify the text
341   */           
342  if (pt) {
343#ifdef SHOW_MORE_INIT_SETTINGS
344    printk("Page table setup finished; will activate it NOW...\n");
345#endif
346    BSP_pgtbl_activate(pt);
347  }
348  /* Read Configuration Vital Product Data (VPD) */
349  if ( I2Cread_eeprom(0xa8, 4,2, &ConfVPD_buff[0], 150))
350     printk("I2Cread_eeprom() error \n");
351  else {
352#ifdef CONF_VPD
353    printk("\n");
354    for (i=0; i<150; i++) {
355      printk("%2x ", ConfVPD_buff[i]); 
356      if ((i % 20)==0 ) printk("\n");
357    }
358    printk("\n");
359#endif
360  }
361
362  /*
363   * PCI 1 domain memory space
364   */
365  setdbat(1, PCI1_MEM_BASE, PCI1_MEM_BASE, 0x10000000, IO_PAGE);
366 
367
368#ifdef SHOW_MORE_INIT_SETTINGS
369  printk("Going to start PCI buses scanning and initialization\n");
370#endif 
371  pci_initialize();
372#ifdef SHOW_MORE_INIT_SETTINGS
373  printk("Number of PCI buses found is : %d\n", pci_bus_count());
374#endif
375
376  /* Install our own exception handler (needs PCI) */
377  globalExceptHdl = BSP_exceptionHandler;
378
379  /* clear hostbridge errors. MCP signal is not used on the MVME5500
380   * PCI config space scanning code will trip otherwise :-(
381   */
382  _BSP_clear_hostbridge_errors(0, 1 /*quiet*/);
383
384#ifdef SHOW_MORE_INIT_SETTINGS
385  printk("MSR %x \n", _read_MSR());
386  printk("Exit from bspstart\n");
387#endif
388
389}
390
391unsigned char ReadConfVPD_buff(int offset)
392{
393  return(ConfVPD_buff[offset]);
394}
Note: See TracBrowser for help on using the repository browser.