1 | /* bspstart.c |
---|
2 | * |
---|
3 | * This set of routines starts the application. It includes application, |
---|
4 | * board, and monitor specific initialization and configuration. |
---|
5 | * The generic CPU dependent initialization has been performed |
---|
6 | * before any of these are invoked. |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1989-2010. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.org/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #include <string.h> |
---|
17 | |
---|
18 | #include <bsp.h> |
---|
19 | #include <rtems/libio.h> |
---|
20 | #include <rtems/libcsupport.h> |
---|
21 | #include <rtems/bspIo.h> |
---|
22 | #include <rtems/counter.h> |
---|
23 | #include <libcpu/cpuIdent.h> |
---|
24 | #include <bsp/irq.h> |
---|
25 | |
---|
26 | #define DEBUG 0 |
---|
27 | |
---|
28 | /* |
---|
29 | * Where the heap starts; is used by bsp_pretasking_hook; |
---|
30 | */ |
---|
31 | unsigned int BSP_heap_start; |
---|
32 | |
---|
33 | /* |
---|
34 | * PCI Bus Frequency |
---|
35 | */ |
---|
36 | unsigned int BSP_bus_frequency; |
---|
37 | |
---|
38 | /* |
---|
39 | * processor clock frequency |
---|
40 | */ |
---|
41 | unsigned int BSP_processor_frequency; |
---|
42 | |
---|
43 | /* |
---|
44 | * Time base divisior (how many tick for 1 second). |
---|
45 | * Note: Calibrated with an application using a 20ms timer and |
---|
46 | * a scope. |
---|
47 | */ |
---|
48 | unsigned int BSP_time_base_divisor = 3960; |
---|
49 | |
---|
50 | /* |
---|
51 | * Driver configuration parameters |
---|
52 | */ |
---|
53 | uint32_t bsp_clicks_per_usec; |
---|
54 | |
---|
55 | /* |
---|
56 | * Memory on this board. |
---|
57 | */ |
---|
58 | extern char RamSize[]; |
---|
59 | uint32_t BSP_mem_size; |
---|
60 | |
---|
61 | extern unsigned long __rtems_end[]; |
---|
62 | |
---|
63 | void BSP_panic(char *s) |
---|
64 | { |
---|
65 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
66 | __asm__ __volatile ("sc"); |
---|
67 | } |
---|
68 | |
---|
69 | void _BSP_Fatal_error(unsigned int v) |
---|
70 | { |
---|
71 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
72 | __asm__ __volatile ("sc"); |
---|
73 | } |
---|
74 | |
---|
75 | /*PAGE |
---|
76 | * |
---|
77 | * bsp_predriver_hook |
---|
78 | * |
---|
79 | * Before drivers are setup initialize interupt vectors. |
---|
80 | */ |
---|
81 | |
---|
82 | void init_RTC(void); |
---|
83 | void initialize_PMC(void); |
---|
84 | |
---|
85 | void bsp_predriver_hook(void) |
---|
86 | { |
---|
87 | init_PCI(); |
---|
88 | initialize_universe(); |
---|
89 | |
---|
90 | #if DEBUG |
---|
91 | printk("bsp_predriver_hook: initialize_PCI_bridge\n"); |
---|
92 | #endif |
---|
93 | initialize_PCI_bridge (); |
---|
94 | |
---|
95 | #if (HAS_PMC_PSC8) |
---|
96 | #if DEBUG |
---|
97 | printk("bsp_predriver_hook: initialize_PMC\n"); |
---|
98 | #endif |
---|
99 | initialize_PMC(); |
---|
100 | #endif |
---|
101 | |
---|
102 | #if DEBUG |
---|
103 | printk("bsp_predriver_hook: End of routine\n"); |
---|
104 | #endif |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | /*PAGE |
---|
109 | * |
---|
110 | * initialize_PMC |
---|
111 | */ |
---|
112 | |
---|
113 | void initialize_PMC(void) { |
---|
114 | volatile uint32_t *PMC_addr; |
---|
115 | uint32_t data; |
---|
116 | |
---|
117 | /* |
---|
118 | * Clear status, enable SERR and memory space only. |
---|
119 | */ |
---|
120 | PMC_addr = BSP_PCI_DEVICE_ADDRESS( 0x4 ); |
---|
121 | *PMC_addr = 0x020080cc; |
---|
122 | #if DEBUG |
---|
123 | printk("initialize_PMC: 0x%x = 0x%x\n", PMC_addr, 0x020080cc); |
---|
124 | #endif |
---|
125 | |
---|
126 | /* |
---|
127 | * set PMC base address. |
---|
128 | */ |
---|
129 | PMC_addr = BSP_PCI_DEVICE_ADDRESS( 0x14 ); |
---|
130 | *PMC_addr = (BSP_PCI_REGISTER_BASE >> 24) & 0x3f; |
---|
131 | #if DEBUG |
---|
132 | printk("initialize_PMC: 0x%x = 0x%x\n", PMC_addr, ((BSP_PCI_REGISTER_BASE >> 24) & 0x3f)); |
---|
133 | #endif |
---|
134 | |
---|
135 | PMC_addr = (volatile uint32_t*) |
---|
136 | BSP_PMC_SERIAL_ADDRESS( 0x100000 ); |
---|
137 | data = *PMC_addr; |
---|
138 | #if DEBUG |
---|
139 | printk("initialize_PMC: Read 0x%x (0x%x)\n", PMC_addr, data ); |
---|
140 | printk("initialize_PMC: Read 0x%x (0x%x)\n", PMC_addr, data & 0xfc ); |
---|
141 | #endif |
---|
142 | *PMC_addr = data & 0xfc; |
---|
143 | } |
---|
144 | |
---|
145 | /*PAGE |
---|
146 | * |
---|
147 | * bsp_start |
---|
148 | * |
---|
149 | * This routine does the bulk of the system initialization. |
---|
150 | */ |
---|
151 | |
---|
152 | void bsp_start( void ) |
---|
153 | { |
---|
154 | unsigned int msr_value = 0x0000; |
---|
155 | uintptr_t intrStackStart; |
---|
156 | uintptr_t intrStackSize; |
---|
157 | ppc_cpu_id_t myCpu; |
---|
158 | ppc_cpu_revision_t myCpuRevision; |
---|
159 | |
---|
160 | rtems_bsp_delay( 1000 ); |
---|
161 | |
---|
162 | /* |
---|
163 | * Zero out lots of memory |
---|
164 | */ |
---|
165 | #if DEBUG |
---|
166 | printk("bsp_start: Zero out lots of memory\n"); |
---|
167 | #endif |
---|
168 | |
---|
169 | BSP_processor_frequency = 266000000; |
---|
170 | BSP_bus_frequency = 66000000; |
---|
171 | |
---|
172 | /* |
---|
173 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
174 | * function store the result in global variables so that it can be used |
---|
175 | * later... |
---|
176 | */ |
---|
177 | myCpu = get_ppc_cpu_type(); |
---|
178 | myCpuRevision = get_ppc_cpu_revision(); |
---|
179 | printk("Cpu: 0x%x Revision: %d\n", myCpu, myCpuRevision); |
---|
180 | printk("Cpu %s\n", get_ppc_cpu_type_name(myCpu) ); |
---|
181 | |
---|
182 | /* |
---|
183 | * Initialize the interrupt related settings. |
---|
184 | */ |
---|
185 | intrStackStart = (uintptr_t) __rtems_end; |
---|
186 | intrStackSize = rtems_configuration_get_interrupt_stack_size(); |
---|
187 | printk("Interrupt Stack Start: 0x%x Size: 0x%x Heap Start: 0x%x\n", |
---|
188 | intrStackStart, intrStackSize, BSP_heap_start |
---|
189 | ); |
---|
190 | |
---|
191 | BSP_mem_size = (uint32_t) RamSize; |
---|
192 | printk("BSP_mem_size: %p\n", RamSize ); |
---|
193 | |
---|
194 | /* |
---|
195 | * Initialize default raw exception handlers. |
---|
196 | */ |
---|
197 | ppc_exc_initialize(intrStackStart, intrStackSize); |
---|
198 | |
---|
199 | msr_value = 0x2030; |
---|
200 | _CPU_MSR_SET( msr_value ); |
---|
201 | __asm__ volatile("sync; isync"); |
---|
202 | |
---|
203 | /* |
---|
204 | * initialize the device driver parameters |
---|
205 | */ |
---|
206 | #if DEBUG |
---|
207 | printk("bsp_start: set clicks poer usec\n"); |
---|
208 | #endif |
---|
209 | bsp_clicks_per_usec = 66 / 4; |
---|
210 | rtems_counter_initialize_converter(bsp_clicks_per_usec * 1000000); |
---|
211 | |
---|
212 | #if BSP_DATA_CACHE_ENABLED |
---|
213 | #if DEBUG |
---|
214 | printk("bsp_start: cache_enable\n"); |
---|
215 | #endif |
---|
216 | instruction_cache_enable (); |
---|
217 | data_cache_enable (); |
---|
218 | #if DEBUG |
---|
219 | printk("bsp_start: END BSP_DATA_CACHE_ENABLED\n"); |
---|
220 | #endif |
---|
221 | #endif |
---|
222 | |
---|
223 | /* |
---|
224 | * Initalize RTEMS IRQ system |
---|
225 | */ |
---|
226 | #if DEBUG |
---|
227 | printk("bspstart: Call BSP_rtems_irq_mng_init\n"); |
---|
228 | #endif |
---|
229 | BSP_rtems_irq_mng_init(0); |
---|
230 | |
---|
231 | #if DEBUG |
---|
232 | printk("bsp_start: end BSPSTART\n"); |
---|
233 | ShowBATS(); |
---|
234 | #endif |
---|
235 | } |
---|