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

4.104.114.84.95
Last change on this file since 3a3e0b0e was 3a3e0b0e, checked in by Joel Sherrill <joel.sherrill@…>, on 06/13/03 at 17:39:46

2003-06-13 Greg Menke <gregory.menke@…>

PR 405/bsps

  • bootloader/pci.c: Added support for configuring devices for pci busses > 0
  • pci/pci.c, pci/pci.h: Added FixupPCI() to store vectors in the INTERRUPT_LINE register of pci devices any # of hops away from the host processor.
  • motorola/motorola.c, motorola/motorola.h: Added interrupt routing tables in support of FixupPCI. This is board-specific, each board will have to supply information for FixupPCI() to do anything for it.
  • startup/bspstart.c: Extended bat2 to cover entire PCI address space.
  • irq/irq.c, irq/irq.h: Added support for shared interrupts. Existing single hander vectors are undisturbed, a new function added to allow adding/removing handlers from a vector.
  • Property mode set to 100644
File size: 11.9 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-1998.
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.OARcorp.com/rtems/license.html.
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 <rtems/libio.h>
23#include <rtems/libcsupport.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 <bsp/VME.h>
31#include <bsp.h>
32#include <libcpu/bat.h>
33#include <libcpu/pte121.h>
34#include <libcpu/cpuIdent.h>
35#include <bsp/vectors.h>
36#include <bsp/motorola.h>
37
38extern void _return_to_ppcbug();
39extern unsigned long __rtems_end[];
40extern void L1_caches_enables();
41extern unsigned get_L2CR();
42extern void set_L2CR(unsigned);
43extern void bsp_cleanup(void);
44extern Triv121PgTbl BSP_pgtbl_setup();
45extern void                     BSP_pgtbl_activate();
46extern void                     BSP_vme_config();
47
48SPR_RW(SPR0)
49SPR_RW(SPR1)
50
51/*
52 * Copy of residuals passed by firmware
53 */
54RESIDUAL residualCopy;
55/*
56 * Copy Additional boot param passed by boot loader
57 */
58#define MAX_LOADER_ADD_PARM 80
59char loaderParam[MAX_LOADER_ADD_PARM];
60/*
61 * Vital Board data Start using DATA RESIDUAL
62 */
63/*
64 * Total memory using RESIDUAL DATA
65 */
66unsigned int BSP_mem_size;
67/*
68 * PCI Bus Frequency
69 */
70unsigned int BSP_bus_frequency;
71/*
72 * processor clock frequency
73 */
74unsigned int BSP_processor_frequency;
75/*
76 * Time base divisior (how many tick for 1 second).
77 */
78unsigned int BSP_time_base_divisor;
79/*
80 * system init stack and soft ir stack size
81 */
82#define INIT_STACK_SIZE 0x1000
83#define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY
84
85void BSP_panic(char *s)
86{
87  printk("%s PANIC %s\n",_RTEMS_version, s);
88  __asm__ __volatile ("sc");
89}
90
91void _BSP_Fatal_error(unsigned int v)
92{
93  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
94  __asm__ __volatile ("sc");
95}
96 
97/*
98 *  The original table from the application and our copy of it with
99 *  some changes.
100 */
101
102extern rtems_configuration_table Configuration;
103
104rtems_configuration_table  BSP_Configuration;
105
106rtems_cpu_table Cpu_table;
107
108char *rtems_progname;
109
110/*
111 *  Use the shared implementations of the following routines
112 */
113 
114void bsp_postdriver_hook(void);
115void bsp_libc_init( void *, unsigned32, int );
116
117/*
118 *  Function:   bsp_pretasking_hook
119 *  Created:    95/03/10
120 *
121 *  Description:
122 *      BSP pretasking hook.  Called just before drivers are initialized.
123 *      Used to setup libc and install any BSP extensions.
124 *
125 *  NOTES:
126 *      Must not use libc (to do io) from here, since drivers are
127 *      not yet initialized.
128 *
129 */
130 
131void bsp_pretasking_hook(void)
132{
133    rtems_unsigned32        heap_start;   
134    rtems_unsigned32        heap_size;
135
136    heap_start = ((rtems_unsigned32) __rtems_end) +INIT_STACK_SIZE + INTR_STACK_SIZE;
137    if (heap_start & (CPU_ALIGNMENT-1))
138        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
139
140    heap_size = (BSP_mem_size - heap_start) - BSP_Configuration.work_space_size;
141
142#ifdef SHOW_MORE_INIT_SETTINGS
143    printk(" HEAP start %x  size %x\n", heap_start, heap_size);
144#endif   
145    bsp_libc_init((void *) heap_start, heap_size, 0);
146
147#ifdef RTEMS_DEBUG
148    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
149#endif
150}
151
152void zero_bss()
153{
154  /* prevent these from being accessed in the short data areas */
155  extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[];
156  extern unsigned long __SBSS2_START__[], __SBSS2_END__[];
157  memset(__SBSS_START__, 0, ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__));
158  memset(__SBSS2_START__, 0, ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__));
159  memset(__bss_start, 0, ((unsigned) __rtems_end) - ((unsigned)__bss_start));
160}
161
162void save_boot_params(RESIDUAL* r3, void *r4, void* r5, char *additional_boot_options)
163{
164 
165  residualCopy = *r3;
166  strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM);
167  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
168}
169
170/*
171 *  bsp_start
172 *
173 *  This routine does the bulk of the system initialization.
174 */
175
176void bsp_start( void )
177{
178  int err;
179  unsigned char *stack;
180  unsigned l2cr;
181  register unsigned char* intrStack;
182  register unsigned int intrNestingLevel = 0;
183  unsigned char *work_space_start;
184  ppc_cpu_id_t myCpu;
185  ppc_cpu_revision_t myCpuRevision;
186  prep_t boardManufacturer;
187  motorolaBoard myBoard;
188  Triv121PgTbl  pt=0;
189  /*
190   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
191   * store the result in global variables so that it can be used latter...
192   */
193  myCpu         = get_ppc_cpu_type();
194  myCpuRevision = get_ppc_cpu_revision();
195  /*
196   * enables L1 Cache. Note that the L1_caches_enables() codes checks for
197   * relevant CPU type so that the reason why there is no use of myCpu...
198   */
199  L1_caches_enables();
200  /*
201   * Enable L2 Cache. Note that the set_L2CR(L2CR) codes checks for
202   * relevant CPU type (mpc750)...
203   */
204  l2cr = get_L2CR();
205#ifdef SHOW_LCR2_REGISTER
206  printk("Initial L2CR value = %x\n", l2cr);
207#endif 
208  if ( (! (l2cr & 0x80000000)) && ((int) l2cr == -1))
209    set_L2CR(0xb9A14000);
210  /*
211   * the initial stack  has aready been set to this value in start.S
212   * so there is no need to set it in r1 again... It is just for info
213   * so that It can be printed without accessing R1.
214   */
215  stack = ((unsigned char*) __rtems_end) + INIT_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
216
217 /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
218  *((unsigned32 *)stack) = 0;
219
220  /*
221   * Initialize the interrupt related settings
222   * SPRG0 = interrupt nesting level count
223   * SPRG1 = software managed IRQ stack
224   *
225   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
226   * some settings below...
227   */
228  intrStack = ((unsigned char*) __rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
229
230  /* make sure it's properly aligned */
231  (unsigned32)intrStack &= ~(CPU_STACK_ALIGNMENT-1);
232
233  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
234  *((unsigned32 *)intrStack) = 0;
235
236  _write_SPR1((unsigned int)intrStack);
237  _write_SPR0(intrNestingLevel);
238  /*
239   * Initialize default raw exception hanlders. See vectors/vectors_init.c
240   */
241  initialize_exceptions();
242  /*
243   * Init MMU block address translation to enable hardware
244   * access
245   */
246  /*
247   * PC legacy IO space used for inb/outb and all PC
248   * compatible hardware
249   */
250  setdbat(1, _IO_BASE, _IO_BASE, 0x10000000, IO_PAGE);
251  /*
252   * PCI devices memory area. Needed to access OPENPIC features
253   * provided by the RAVEN
254   */
255  /* T. Straumann: give more PCI address space */
256  setdbat(2, PCI_MEM_BASE, PCI_MEM_BASE, 0x30000000, IO_PAGE);
257  /*
258   * Must have acces to open pic PCI ACK registers
259   * provided by the RAVEN
260   *
261   */
262  setdbat(3, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
263
264  select_console(CONSOLE_LOG);
265
266  /* We check that the keyboard is present and immediately
267   * select the serial console if not.
268   */
269  err = kbdreset();
270  if (err) select_console(CONSOLE_SERIAL);
271
272  boardManufacturer   =  checkPrepBoardType(&residualCopy);
273  if (boardManufacturer != PREP_Motorola) {
274    printk("Unsupported hardware vendor\n");
275    while (1);
276  }
277  myBoard = getMotorolaBoard();
278 
279  printk("-----------------------------------------\n");
280  printk("Welcome to %s on %s\n", _RTEMS_version, motorolaBoardToString(myBoard));
281  printk("-----------------------------------------\n");
282#ifdef SHOW_MORE_INIT_SETTINGS 
283  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
284  printk("Additionnal boot options are %s\n", loaderParam);
285  printk("Initial system stack at %x\n",stack);
286  printk("Software IRQ stack at %x\n",intrStack);
287  printk("-----------------------------------------\n");
288#endif
289
290#ifdef TEST_RETURN_TO_PPCBUG 
291  printk("Hit <Enter> to return to PPCBUG monitor\n");
292  printk("When Finished hit GO. It should print <Back from monitor>\n");
293  debug_getc();
294  _return_to_ppcbug();
295  printk("Back from monitor\n");
296  _return_to_ppcbug();
297#endif /* TEST_RETURN_TO_PPCBUG  */
298
299#ifdef SHOW_MORE_INIT_SETTINGS
300  printk("Going to start PCI buses scanning and initialization\n");
301#endif 
302  InitializePCI();
303
304 {
305    struct _int_map     *bspmap   = motorolaIntMap(currentBoard);
306    if( bspmap )
307    {
308       printk("pci : Configuring interrupt routing for '%s'\n", motorolaBoardToString(currentBoard));
309       FixupPCI(bspmap, motorolaIntSwizzle(currentBoard) );
310    }
311    else
312       printk("pci : Interrupt routing not available for this bsp\n");
313
314 }
315
316
317
318#ifdef SHOW_MORE_INIT_SETTINGS
319  printk("Number of PCI buses found is : %d\n", BusCountPCI());
320#endif
321#ifdef TEST_RAW_EXCEPTION_CODE 
322  printk("Testing exception handling Part 1\n");
323  /*
324   * Cause a software exception
325   */
326  __asm__ __volatile ("sc");
327  /*
328   * Check we can still catch exceptions and returned coorectly.
329   */
330  printk("Testing exception handling Part 2\n");
331  __asm__ __volatile ("sc");
332#endif 
333
334
335  BSP_mem_size                          = residualCopy.TotalMemory;
336  BSP_bus_frequency                     = residualCopy.VitalProductData.ProcessorBusHz;
337  BSP_processor_frequency               = residualCopy.VitalProductData.ProcessorHz;
338  BSP_time_base_divisor                 = (residualCopy.VitalProductData.TimeBaseDivisor?
339                                           residualCopy.VitalProductData.TimeBaseDivisor : 4000);
340
341  /* clear hostbridge errors and enable MCP */
342  _BSP_clear_hostbridge_errors(1/*enableMCP*/, 0/*quiet*/);
343
344  /* Allocate and set up the page table mappings
345   * This is only available on >604 CPUs.
346   *
347   * NOTE: This setup routine may modify the available memory
348   *       size. It is essential to call it before
349   *       calculating the workspace etc.
350   */
351  pt = BSP_pgtbl_setup(&BSP_mem_size);
352
353  if (!pt ||
354          TRIV121_MAP_SUCCESS != triv121PgTblMap(
355                                                                                pt,
356                                                                                TRIV121_121_VSID,
357                                                                                0xfeff0000,
358                                                                                1,
359                                                                                TRIV121_ATTR_IO_PAGE,
360                                                                                TRIV121_PP_RW_PAGE
361                                                                                )) {
362        printk("WARNING: unable to setup page tables VME bridge must share PCI space\n");
363  }
364 
365  /*
366   * Set up our hooks
367   * Make sure libc_init is done before drivers initialized so that
368   * they can use atexit()
369   */
370
371  Cpu_table.pretasking_hook      = bsp_pretasking_hook;    /* init libc, etc. */
372  Cpu_table.postdriver_hook      = bsp_postdriver_hook;
373  Cpu_table.do_zero_of_workspace = TRUE;
374  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
375  Cpu_table.clicks_per_usec      = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
376  Cpu_table.exceptions_in_RAM    = TRUE;
377
378#ifdef SHOW_MORE_INIT_SETTINGS
379  printk("BSP_Configuration.work_space_size = %x\n", BSP_Configuration.work_space_size);
380#endif 
381  work_space_start =
382    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
383
384  if ( work_space_start <= ((unsigned char *)__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
385    printk( "bspstart: Not enough RAM!!!\n" );
386    bsp_cleanup();
387  }
388
389  BSP_Configuration.work_space_start = work_space_start;
390
391  /*
392   * Initalize RTEMS IRQ system
393   */
394  BSP_rtems_irq_mng_init(0);
395
396 
397  /* Activate the page table mappings only after
398   * initializing interrupts because the irq_mng_init()
399   * routine needs to modify the text
400   */           
401  if (pt) {
402#ifdef  SHOW_MORE_INIT_SETTINGS
403    printk("Page table setup finished; will activate it NOW...\n");
404#endif
405    BSP_pgtbl_activate(pt);
406        /* finally, switch off DBAT3 */
407        setdbat(3, 0, 0, 0, 0);
408  }
409
410  /*
411   * Initialize VME bridge - needs working PCI
412   * and IRQ subsystems...
413   */
414#ifdef SHOW_MORE_INIT_SETTINGS
415  printk("Going to initialize VME bridge\n");
416#endif
417  /* VME initialization is in a separate file so apps which don't use
418   * VME or want a different configuration may link against a customized
419   * routine.
420   */
421  BSP_vme_config();
422
423#ifdef SHOW_MORE_INIT_SETTINGS
424  printk("Exit from bspstart\n");
425#endif 
426}
Note: See TracBrowser for help on using the repository browser.