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

Last change on this file since 8ca372e was 8ca372e, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 26, 2016 at 9:11:48 AM

Use linker set for MPCI initialization

Update #2408.

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