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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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