source: rtems/c/src/lib/libbsp/powerpc/shared/startup/bspstart.c @ 00b5917

4.104.115
Last change on this file since 00b5917 was 00b5917, checked in by Joel Sherrill <joel.sherrill@…>, on 04/28/10 at 18:51:58

2010-04-28 Joel Sherrill <joel.sherrilL@…>

  • shared/bootloader/em86.c, shared/bootloader/mm.c, shared/console/polled_io.c, shared/irq/irq_init.c, shared/startup/bspstart.c: Remove warnings.
  • Property mode set to 100644
File size: 9.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 *  $Id$
18 */
19
20#include <string.h>
21
22#include <bsp.h>
23#include <rtems/bspIo.h>
24#include <bsp/consoleIo.h>
25#include <libcpu/spr.h>
26#include <bsp/residual.h>
27#include <bsp/pci.h>
28#include <bsp/openpic.h>
29#include <bsp/irq.h>
30#include <libcpu/bat.h>
31#include <libcpu/pte121.h>
32#include <libcpu/cpuIdent.h>
33#include <bsp/vectors.h>
34#include <bsp/motorola.h>
35#include <rtems/powerpc/powerpc.h>
36
37extern void _return_to_ppcbug(void);
38extern unsigned long __rtems_end[];
39extern void L1_caches_enables(void);
40extern unsigned get_L2CR(void);
41extern void set_L2CR(unsigned);
42extern Triv121PgTbl BSP_pgtbl_setup(unsigned int *);
43extern void                     BSP_pgtbl_activate(Triv121PgTbl);
44extern void                     BSP_vme_config(void);
45
46SPR_RW(SPRG1)
47
48#if defined(DEBUG_BATS)
49extern void ShowBATS(void);
50#endif
51
52/*
53 *  Driver configuration parameters
54 */
55uint32_t   bsp_clicks_per_usec;
56
57/*
58 * Copy of residuals passed by firmware
59 */
60RESIDUAL residualCopy;
61/*
62 * Copy Additional boot param passed by boot loader
63 */
64#define MAX_LOADER_ADD_PARM 80
65char loaderParam[MAX_LOADER_ADD_PARM];
66
67char *BSP_commandline_string = loaderParam;
68/*
69 * Vital Board data Start using DATA RESIDUAL
70 */
71/*
72 * Total memory using RESIDUAL DATA
73 */
74unsigned int BSP_mem_size;
75
76/*
77 * PCI Bus Frequency
78 */
79unsigned int BSP_bus_frequency;
80/*
81 * processor clock frequency
82 */
83unsigned int BSP_processor_frequency;
84/*
85 * Time base divisior (how many tick for 1 second).
86 */
87unsigned int BSP_time_base_divisor;
88
89void BSP_panic(char *s)
90{
91  printk("%s PANIC %s\n",_RTEMS_version, s);
92  __asm__ __volatile ("sc");
93}
94
95void _BSP_Fatal_error(unsigned int v)
96{
97  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
98  __asm__ __volatile ("sc");
99}
100
101/*
102 *  Use the shared implementations of the following routines
103 */
104
105char * save_boot_params(
106  RESIDUAL *r3,
107  void     *r4,
108  void     *r5,
109  char     *additional_boot_options
110)
111{
112
113  residualCopy = *r3;
114  strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM);
115  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
116  return loaderParam;
117}
118
119#if defined(mvme2100)
120unsigned int EUMBBAR;
121
122/*
123 * Return the current value of the Embedded Utilities Memory Block Base Address
124 * Register (EUMBBAR) as read from the processor configuration register using
125 * Processor Address Map B (CHRP).
126 */
127unsigned int get_eumbbar(void) {
128  out_le32( (volatile unsigned *)0xfec00000, 0x80000078 );
129  return in_le32( (volatile unsigned *)0xfee00000 );
130}
131#endif
132
133/*
134 *  bsp_start
135 *
136 *  This routine does the bulk of the system initialization.
137 */
138
139void bsp_start( void )
140{
141  rtems_status_code sc = RTEMS_SUCCESSFUL;
142#if !defined(mvme2100)
143  unsigned l2cr;
144#endif
145  uintptr_t intrStackStart;
146  uintptr_t intrStackSize;
147  ppc_cpu_id_t myCpu;
148  ppc_cpu_revision_t myCpuRevision;
149  prep_t boardManufacturer;
150  motorolaBoard myBoard;
151  Triv121PgTbl  pt=0;
152
153  /*
154   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
155   * function store the result in global variables so that it can be used
156   * later...
157   */
158  myCpu         = get_ppc_cpu_type();
159  myCpuRevision = get_ppc_cpu_revision();
160
161  /*
162   * Init MMU block address translation to enable hardware access
163   */
164
165#if !defined(mvme2100)
166  /*
167   * PC legacy IO space used for inb/outb and all PC compatible hardware
168   */
169  setdbat(1, _IO_BASE, _IO_BASE, 0x10000000, IO_PAGE);
170#endif
171
172  /*
173   * PCI devices memory area. Needed to access OpenPIC features
174   * provided by the Raven
175   *
176   * T. Straumann: give more PCI address space
177   */
178  setdbat(2, PCI_MEM_BASE+PCI_MEM_WIN0, PCI_MEM_BASE+PCI_MEM_WIN0, 0x10000000, IO_PAGE);
179
180  /*
181   * Must have acces to open pic PCI ACK registers provided by the RAVEN
182   */
183  setdbat(3, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
184
185#if defined(mvme2100)
186  /* Need 0xfec00000 mapped for this */
187  EUMBBAR = get_eumbbar();
188#endif
189
190  /*
191   * enables L1 Cache. Note that the L1_caches_enables() codes checks for
192   * relevant CPU type so that the reason why there is no use of myCpu...
193   */
194  L1_caches_enables();
195
196#if !defined(mvme2100)
197  /*
198   * Enable L2 Cache. Note that the set_L2CR(L2CR) codes checks for
199   * relevant CPU type (mpc750)...
200   */
201  l2cr = get_L2CR();
202#ifdef SHOW_LCR2_REGISTER
203  printk("Initial L2CR value = %x\n", l2cr);
204#endif
205  if ( (! (l2cr & 0x80000000)) && ((int) l2cr == -1))
206    set_L2CR(0xb9A14000);
207#endif
208
209  /*
210   * Initialize the interrupt related settings.
211   */
212  intrStackStart = (uintptr_t) __rtems_end;
213  intrStackSize = rtems_configuration_get_interrupt_stack_size();
214
215  /*
216   * Initialize default raw exception handlers.
217   */
218  sc = ppc_exc_initialize(
219    PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
220    intrStackStart,
221    intrStackSize
222  );
223  if (sc != RTEMS_SUCCESSFUL) {
224    BSP_panic("cannot initialize exceptions");
225  }
226
227  select_console(CONSOLE_LOG);
228
229  /*
230   * We check that the keyboard is present and immediately
231   * select the serial console if not.
232   */
233#if defined(BSP_KBD_IOBASE)
234  { int err;
235    err = kbdreset();
236    if (err) select_console(CONSOLE_SERIAL);
237  }
238#else
239  select_console(CONSOLE_SERIAL);
240#endif
241
242  boardManufacturer   =  checkPrepBoardType(&residualCopy);
243  if (boardManufacturer != PREP_Motorola) {
244    printk("Unsupported hardware vendor\n");
245    while (1);
246  }
247  myBoard = getMotorolaBoard();
248
249  printk("-----------------------------------------\n");
250  printk("Welcome to %s on %s\n", _RTEMS_version,
251                                    motorolaBoardToString(myBoard));
252  printk("-----------------------------------------\n");
253#ifdef SHOW_MORE_INIT_SETTINGS
254  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
255  printk("Additionnal boot options are %s\n", loaderParam);
256  printk("Initial system stack at %x\n",stack);
257  printk("Software IRQ stack starts at %x with size %u\n", intrStackStart, intrStackSize);
258  printk("-----------------------------------------\n");
259#endif
260
261#ifdef TEST_RETURN_TO_PPCBUG
262  printk("Hit <Enter> to return to PPCBUG monitor\n");
263  printk("When Finished hit GO. It should print <Back from monitor>\n");
264  debug_getc();
265  _return_to_ppcbug();
266  printk("Back from monitor\n");
267  _return_to_ppcbug();
268#endif /* TEST_RETURN_TO_PPCBUG  */
269
270#ifdef SHOW_MORE_INIT_SETTINGS
271  printk("Going to start PCI buses scanning and initialization\n");
272#endif
273
274  pci_initialize();
275  {
276    const struct _int_map *bspmap  = motorolaIntMap(currentBoard);
277    if( bspmap ) {
278       printk("pci : Configuring interrupt routing for '%s'\n",
279          motorolaBoardToString(currentBoard));
280       FixupPCI(bspmap, motorolaIntSwizzle(currentBoard));
281    }
282    else
283       printk("pci : Interrupt routing not available for this bsp\n");
284 }
285
286#ifdef SHOW_MORE_INIT_SETTINGS
287  printk("Number of PCI buses found is : %d\n", pci_bus_count());
288#endif
289#ifdef TEST_RAW_EXCEPTION_CODE
290  printk("Testing exception handling Part 1\n");
291  /*
292   * Cause a software exception
293   */
294  __asm__ __volatile ("sc");
295  /*
296   * Check we can still catch exceptions and return coorectly.
297   */
298  printk("Testing exception handling Part 2\n");
299  __asm__ __volatile ("sc");
300
301  /*
302   * Somehow doing the above seems to clobber SPRG0 on the mvme2100.  The
303   * interrupt disable mask is stored in SPRG0. Is this a problem?
304   */
305  ppc_interrupt_set_disable_mask( PPC_INTERRUPT_DISABLE_MASK_DEFAULT);
306
307#endif
308
309/* See above */
310
311  BSP_mem_size            = residualCopy.TotalMemory;
312  BSP_bus_frequency       = residualCopy.VitalProductData.ProcessorBusHz;
313  BSP_processor_frequency = residualCopy.VitalProductData.ProcessorHz;
314  BSP_time_base_divisor   = (residualCopy.VitalProductData.TimeBaseDivisor?
315                    residualCopy.VitalProductData.TimeBaseDivisor : 4000);
316
317  /* clear hostbridge errors but leave MCP disabled -
318   * PCI config space scanning code will trip otherwise :-(
319   */
320  _BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
321
322  /* Allocate and set up the page table mappings
323   * This is only available on >604 CPUs.
324   *
325   * NOTE: This setup routine may modify the available memory
326   *       size. It is essential to call it before
327   *       calculating the workspace etc.
328   */
329  pt = BSP_pgtbl_setup(&BSP_mem_size);
330
331  if (!pt || TRIV121_MAP_SUCCESS != triv121PgTblMap(
332            pt, TRIV121_121_VSID, 0xfeff0000, 1,
333            TRIV121_ATTR_IO_PAGE, TRIV121_PP_RW_PAGE)) {
334        printk("WARNING: unable to setup page tables VME "
335               "bridge must share PCI space\n");
336  }
337
338  /*
339   *  initialize the device driver parameters
340   */
341  bsp_clicks_per_usec    = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
342
343  /*
344   * Initalize RTEMS IRQ system
345   */
346  BSP_rtems_irq_mng_init(0);
347
348  /* Activate the page table mappings only after
349   * initializing interrupts because the irq_mng_init()
350   * routine needs to modify the text
351   */
352  if (pt) {
353#ifdef  SHOW_MORE_INIT_SETTINGS
354    printk("Page table setup finished; will activate it NOW...\n");
355#endif
356    BSP_pgtbl_activate(pt);
357    /* finally, switch off DBAT3 */
358    setdbat(3, 0, 0, 0, 0);
359  }
360
361#if defined(DEBUG_BATS)
362  ShowBATS();
363#endif
364
365#ifdef SHOW_MORE_INIT_SETTINGS
366  printk("Exit from bspstart\n");
367#endif
368}
Note: See TracBrowser for help on using the repository browser.