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

4.104.115
Last change on this file since c603479 was cc981e1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 08/20/08 at 05:47:08

Add missing prototypes.

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