RTEMS
bspstart.c
1 /*
2  * This set of routines 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 any of these are invoked.
6  *
7  * COPYRIGHT (c) 2011
8  * Aeroflex Gaisler
9  *
10  * COPYRIGHT (c) 1989-2013.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * Modified for LEON3 BSP.
14  * COPYRIGHT (c) 2004.
15  * Gaisler Research.
16  *
17  * The license and distribution terms for this file may be
18  * found in the file LICENSE in this distribution or at
19  * http://www.rtems.org/license/LICENSE.
20  */
21 
22 #include <bsp.h>
23 #include <leon.h>
24 #include <bsp/bootcard.h>
25 #include <rtems/sysinit.h>
26 
27 #if defined(RTEMS_SMP) || defined(RTEMS_MULTIPROCESSING)
28 /* Irq used by shared memory driver and for inter-processor interrupts.
29  * Can be overridden by being defined in the application.
30  */
31 const unsigned char LEON3_mp_irq __attribute__((weak)) = 14;
32 #endif
33 
34 /*
35  * Tells us if data cache snooping is available
36  */
37 int CPU_SPARC_HAS_SNOOPING;
38 
39 /* Index of CPU, in an AMP system CPU-index may be non-zero */
40 uint32_t LEON3_Cpu_Index = 0;
41 
42 #if defined(RTEMS_SMP)
43 /* Index of the boot CPU. Set by the first CPU at boot to its CPU ID. */
44 int LEON3_Boot_Cpu = -1;
45 #endif
46 
47 /*
48  * set_snooping
49  *
50  * Read the cache control register to determine if
51  * bus snooping is available and enabled. This is needed for some
52  * drivers so that they can select the most efficient copy routines.
53  *
54  */
55 
56 static inline int set_snooping(void)
57 {
58  return (leon3_get_cache_control_register() >> 23) & 1;
59 }
60 
61 /*
62  * bsp_start
63  *
64  * This routine does the bulk of the system initialization.
65  */
66 void bsp_start( void )
67 {
68  CPU_SPARC_HAS_SNOOPING = set_snooping();
69 }
70 
71 static void leon3_cpu_index_init(void)
72 {
73  /* Get the LEON3 CPU index, normally 0, but for MP systems we do
74  * _not_ assume that this is CPU0. One may run another OS on CPU0
75  * and RTEMS on this CPU, and AMP system with mixed operating
76  * systems
77  */
78  LEON3_Cpu_Index = _LEON3_Get_current_processor();
79 }
80 
81 RTEMS_SYSINIT_ITEM(
82  leon3_cpu_index_init,
83  RTEMS_SYSINIT_BSP_START,
84  RTEMS_SYSINIT_ORDER_FIRST
85 );
86 
87 static void leon3_interrupt_common_init( void )
88 {
89  /* Initialize shared interrupt handling, must be done after IRQ
90  * controller has been found and initialized.
91  */
92  BSP_shared_interrupt_init();
93 }
94 
95 /*
96  * Called just before drivers are initialized. Is used to initialize shared
97  * interrupt handling.
98  */
99 static void leon3_pre_driver_hook( void )
100 {
101  bsp_spurious_initialize();
102 
103 #ifndef RTEMS_DRVMGR_STARTUP
104  leon3_interrupt_common_init();
105 #endif
106 }
107 
108 RTEMS_SYSINIT_ITEM(
109  leon3_pre_driver_hook,
110  RTEMS_SYSINIT_BSP_PRE_DRIVERS,
111  RTEMS_SYSINIT_ORDER_MIDDLE
112 );
113 
114 #ifdef RTEMS_DRVMGR_STARTUP
115 /*
116  * Initialize shared interrupt handling, must be done after IRQ controller has
117  * been found and initialized.
118  */
119 RTEMS_SYSINIT_ITEM(
120  leon3_interrupt_common_init,
121  RTEMS_SYSINIT_DRVMGR_LEVEL_1,
122  RTEMS_SYSINIT_ORDER_LAST_BUT_5
123 );
124 #endif
LEON3 BSP data types and macros.