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 | |
---|
15 | #warning The interrupt disable mask is now stored in SPRG0, please verify that this is compatible to this BSP (see also bootcard.c). |
---|
16 | |
---|
17 | #include <bsp/consoleIo.h> |
---|
18 | #include <libcpu/spr.h> |
---|
19 | #include <bsp/residual.h> |
---|
20 | #include <bsp/pci.h> |
---|
21 | #include <bsp/openpic.h> |
---|
22 | #include <bsp/irq.h> |
---|
23 | #include <bsp/VME.h> |
---|
24 | #include <bsp.h> |
---|
25 | #include <libcpu/bat.h> |
---|
26 | #include <libcpu/pte121.h> |
---|
27 | #include <libcpu/cpuIdent.h> |
---|
28 | #include <bsp/vectors.h> |
---|
29 | #include <rtems/powerpc/powerpc.h> |
---|
30 | |
---|
31 | extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[]; |
---|
32 | extern unsigned long __SBSS2_START__[], __SBSS2_END__[]; |
---|
33 | |
---|
34 | extern unsigned long __rtems_end[]; |
---|
35 | extern void L1_caches_enables(void); |
---|
36 | extern unsigned get_L2CR(void); |
---|
37 | extern void set_L2CR(unsigned); |
---|
38 | extern Triv121PgTbl BSP_pgtbl_setup(void); |
---|
39 | extern void BSP_pgtbl_activate(Triv121PgTbl); |
---|
40 | extern void BSP_vme_config(void); |
---|
41 | extern void ShowBATS(void); |
---|
42 | unsigned int rsPMCQ1Init(void); |
---|
43 | |
---|
44 | uint32_t bsp_clicks_per_usec; |
---|
45 | |
---|
46 | SPR_RW(SPRG1) |
---|
47 | |
---|
48 | uint8_t LightIdx = 0; |
---|
49 | |
---|
50 | extern int RAM_END; |
---|
51 | unsigned int BSP_mem_size = (unsigned int)&RAM_END; |
---|
52 | |
---|
53 | void BSP_Increment_Light(void){ |
---|
54 | uint8_t data; |
---|
55 | data = *GENERAL_REGISTER1; |
---|
56 | data &= 0xf0; |
---|
57 | data |= LightIdx++; |
---|
58 | *GENERAL_REGISTER1 = data; |
---|
59 | } |
---|
60 | |
---|
61 | void BSP_Fatal_Fault_Light(void) { |
---|
62 | uint8_t data; |
---|
63 | data = *GENERAL_REGISTER1; |
---|
64 | data &= 0xf0; |
---|
65 | data |= 0x7; |
---|
66 | while(1) |
---|
67 | *GENERAL_REGISTER1 = data; |
---|
68 | } |
---|
69 | |
---|
70 | void write_to_Q2ram(int offset, unsigned int data ) |
---|
71 | { |
---|
72 | printk("0x%x ==> %d\n", offset, data ); |
---|
73 | #if 0 |
---|
74 | unsigned int *ptr = 0x82000000; |
---|
75 | ptr += offset; |
---|
76 | *ptr = data; |
---|
77 | #endif |
---|
78 | } |
---|
79 | |
---|
80 | /* |
---|
81 | * Vital Board data Start using DATA RESIDUAL |
---|
82 | */ |
---|
83 | |
---|
84 | uint32_t VME_Slot1 = FALSE; |
---|
85 | |
---|
86 | /* |
---|
87 | * PCI Bus Frequency |
---|
88 | */ |
---|
89 | unsigned int BSP_bus_frequency; |
---|
90 | |
---|
91 | /* |
---|
92 | * processor clock frequency |
---|
93 | */ |
---|
94 | unsigned int BSP_processor_frequency; |
---|
95 | |
---|
96 | /* |
---|
97 | * Time base divisior (how many tick for 1 second). |
---|
98 | */ |
---|
99 | unsigned int BSP_time_base_divisor = 1000; /* XXX - Just a guess */ |
---|
100 | |
---|
101 | void BSP_panic(char *s) |
---|
102 | { |
---|
103 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
104 | __asm__ __volatile ("sc"); |
---|
105 | } |
---|
106 | |
---|
107 | void _BSP_Fatal_error(unsigned int v) |
---|
108 | { |
---|
109 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
110 | __asm__ __volatile ("sc"); |
---|
111 | } |
---|
112 | |
---|
113 | int BSP_FLASH_Disable_writes( |
---|
114 | uint32_t area |
---|
115 | ) |
---|
116 | { |
---|
117 | unsigned char data; |
---|
118 | |
---|
119 | data = *GENERAL_REGISTER1; |
---|
120 | data |= DISABLE_USER_FLASH; |
---|
121 | *GENERAL_REGISTER1 = data; |
---|
122 | |
---|
123 | return RTEMS_SUCCESSFUL; |
---|
124 | } |
---|
125 | |
---|
126 | int BSP_FLASH_Enable_writes( |
---|
127 | uint32_t area /* IN */ |
---|
128 | ) |
---|
129 | { |
---|
130 | unsigned char data; |
---|
131 | |
---|
132 | data = *GENERAL_REGISTER1; |
---|
133 | data &= (~DISABLE_USER_FLASH); |
---|
134 | *GENERAL_REGISTER1 = data; |
---|
135 | |
---|
136 | return RTEMS_SUCCESSFUL; |
---|
137 | } |
---|
138 | |
---|
139 | void BSP_FLASH_set_page( |
---|
140 | uint8_t page |
---|
141 | ) |
---|
142 | { |
---|
143 | unsigned char data; |
---|
144 | |
---|
145 | /* Set the flash page register. */ |
---|
146 | data = *GENERAL_REGISTER2; |
---|
147 | data &= ~(BSP_FLASH_PAGE_MASK); |
---|
148 | data |= 0x80 | (page << BSP_FLASH_PAGE_SHIFT); |
---|
149 | *GENERAL_REGISTER2 = data; |
---|
150 | } |
---|
151 | |
---|
152 | /* |
---|
153 | * bsp_pretasking_hook |
---|
154 | * |
---|
155 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
156 | */ |
---|
157 | void bsp_pretasking_hook(void) |
---|
158 | { |
---|
159 | rsPMCQ1Init(); |
---|
160 | } |
---|
161 | |
---|
162 | void zero_bss(void) |
---|
163 | { |
---|
164 | memset(__SBSS_START__, 0, ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__)); |
---|
165 | memset(__SBSS2_START__, 0, ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__)); |
---|
166 | memset(__bss_start, 0, ((unsigned) __rtems_end) - ((unsigned)__bss_start)); |
---|
167 | } |
---|
168 | |
---|
169 | char * save_boot_params(RESIDUAL* r3, void *r4, void* r5, char *additional_boot_options) |
---|
170 | { |
---|
171 | #if 0 |
---|
172 | residualCopy = *r3; |
---|
173 | strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM); |
---|
174 | loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0'; |
---|
175 | return loaderParam; |
---|
176 | #endif |
---|
177 | return 0; |
---|
178 | } |
---|
179 | |
---|
180 | unsigned int EUMBBAR; |
---|
181 | |
---|
182 | unsigned int get_eumbbar(void) { |
---|
183 | register int a, e; |
---|
184 | |
---|
185 | __asm__ volatile( "lis %0,0xfec0; ori %0,%0,0x0000": "=r" (a) ); |
---|
186 | __asm__ volatile("sync"); |
---|
187 | |
---|
188 | __asm__ volatile("lis %0,0x8000; ori %0,%0,0x0078": "=r"(e) ); |
---|
189 | __asm__ volatile("stwbrx %0,0x0,%1": "=r"(e): "r"(a)); |
---|
190 | __asm__ volatile("sync"); |
---|
191 | |
---|
192 | __asm__ volatile("lis %0,0xfee0; ori %0,%0,0x0000": "=r" (a) ); |
---|
193 | __asm__ volatile("sync"); |
---|
194 | |
---|
195 | __asm__ volatile("lwbrx %0,0x0,%1": "=r" (e): "r" (a)); |
---|
196 | __asm__ volatile("isync"); |
---|
197 | return e; |
---|
198 | } |
---|
199 | |
---|
200 | void Read_ep1a_config_registers( ppc_cpu_id_t myCpu ) { |
---|
201 | unsigned char value; |
---|
202 | |
---|
203 | /* |
---|
204 | * Print out the board and revision. |
---|
205 | */ |
---|
206 | |
---|
207 | printk("Board: "); |
---|
208 | printk( get_ppc_cpu_type_name(myCpu) ); |
---|
209 | |
---|
210 | value = *BOARD_REVISION_REGISTER2 & HARDWARE_ID_MASK; |
---|
211 | if ( value == HARDWARE_ID_PPC5_EP1A ) |
---|
212 | printk(" EP1A "); |
---|
213 | else if ( value == HARDWARE_ID_EP1B ) |
---|
214 | printk(" EP1B "); |
---|
215 | else |
---|
216 | printk(" Unknown "); |
---|
217 | |
---|
218 | value = *BOARD_REVISION_REGISTER2&0x1; |
---|
219 | printk("Board ID %08x", value); |
---|
220 | if(value == 0x0){ |
---|
221 | VME_Slot1 = TRUE; |
---|
222 | printk("VME Slot 1\n"); |
---|
223 | } |
---|
224 | else{ |
---|
225 | VME_Slot1 = FALSE; |
---|
226 | printk("\n"); |
---|
227 | } |
---|
228 | |
---|
229 | printk("Revision: "); |
---|
230 | value = *BOARD_REVISION_REGISTER1; |
---|
231 | printk("%d%c\n\n", value>>4, 'A'+(value&BUILD_REVISION_MASK) ); |
---|
232 | |
---|
233 | /* |
---|
234 | * Get the CPU, XXX frequency |
---|
235 | */ |
---|
236 | value = *EQUIPMENT_PRESENT_REGISTER2 & PLL_CFG_MASK; |
---|
237 | switch( value ) { |
---|
238 | case MHZ_33_66_200: /* PCI, MEM, & CPU Frequency */ |
---|
239 | BSP_processor_frequency = 200000000; |
---|
240 | BSP_bus_frequency = 33000000; |
---|
241 | break; |
---|
242 | case MHZ_33_100_200: /* PCI, MEM, & CPU Frequency */ |
---|
243 | BSP_processor_frequency = 200000000; |
---|
244 | BSP_bus_frequency = 33000000; |
---|
245 | break; |
---|
246 | case MHZ_33_66_266: /* PCI, MEM, & CPU Frequency */ |
---|
247 | BSP_processor_frequency = 266000000; |
---|
248 | BSP_bus_frequency = 33000000; |
---|
249 | break; |
---|
250 | case MHZ_33_66_333: /* PCI, MEM, & CPU Frequency */ |
---|
251 | BSP_processor_frequency = 333000000; |
---|
252 | BSP_bus_frequency = 33000000; |
---|
253 | break; |
---|
254 | case MHZ_33_100_333: /* PCI, MEM, & CPU Frequency */ |
---|
255 | BSP_processor_frequency = 333000000; |
---|
256 | BSP_bus_frequency = 33000000; |
---|
257 | break; |
---|
258 | case MHZ_33_100_350: /* PCI, MEM, & CPU Frequency */ |
---|
259 | BSP_processor_frequency = 350000000; |
---|
260 | BSP_bus_frequency = 33000000; |
---|
261 | break; |
---|
262 | default: |
---|
263 | printk("ERROR: Unknown Processor frequency 0x%02x please fill in bspstart.c\n",value); |
---|
264 | BSP_processor_frequency = 350000000; |
---|
265 | BSP_bus_frequency = 33000000; |
---|
266 | break; |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | /* |
---|
271 | * bsp_start |
---|
272 | * |
---|
273 | * This routine does the bulk of the system initialization. |
---|
274 | */ |
---|
275 | |
---|
276 | void bsp_start( void ) |
---|
277 | { |
---|
278 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
279 | uintptr_t intrStackStart; |
---|
280 | uintptr_t intrStackSize; |
---|
281 | ppc_cpu_id_t myCpu; |
---|
282 | ppc_cpu_revision_t myCpuRevision; |
---|
283 | Triv121PgTbl pt=0; /* R = e; */ |
---|
284 | |
---|
285 | /* |
---|
286 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
287 | * function store the result in global variables so that it can be used |
---|
288 | * latter... |
---|
289 | */ |
---|
290 | BSP_Increment_Light(); |
---|
291 | myCpu = get_ppc_cpu_type(); |
---|
292 | myCpuRevision = get_ppc_cpu_revision(); |
---|
293 | |
---|
294 | EUMBBAR = get_eumbbar(); |
---|
295 | printk("EUMBBAR 0x%08x\n", EUMBBAR ); |
---|
296 | |
---|
297 | /* |
---|
298 | * Note this sets BSP_processor_frequency based upon register settings. |
---|
299 | * It must be done prior to setting up hooks. |
---|
300 | */ |
---|
301 | Read_ep1a_config_registers( myCpu ); |
---|
302 | |
---|
303 | bsp_clicks_per_usec = BSP_processor_frequency/(BSP_time_base_divisor * 1000); |
---|
304 | |
---|
305 | ShowBATS(); |
---|
306 | #if 0 /* XXX - Add back in cache enable when we get this up and running!! */ |
---|
307 | /* |
---|
308 | * enables L1 Cache. Note that the L1_caches_enables() codes checks for |
---|
309 | * relevant CPU type so that the reason why there is no use of myCpu... |
---|
310 | */ |
---|
311 | L1_caches_enables(); |
---|
312 | #endif |
---|
313 | |
---|
314 | /* |
---|
315 | * Initialize the interrupt related settings. |
---|
316 | */ |
---|
317 | intrStackStart = (uintptr_t) __rtems_end; |
---|
318 | intrStackSize = rtems_configuration_get_interrupt_stack_size(); |
---|
319 | |
---|
320 | /* |
---|
321 | * Initialize default raw exception hanlders. |
---|
322 | */ |
---|
323 | sc = ppc_exc_initialize( |
---|
324 | PPC_INTERRUPT_DISABLE_MASK_DEFAULT, |
---|
325 | intrStackStart, |
---|
326 | intrStackSize |
---|
327 | ); |
---|
328 | if (sc != RTEMS_SUCCESSFUL) { |
---|
329 | BSP_panic("cannot initialize exceptions"); |
---|
330 | } |
---|
331 | |
---|
332 | /* |
---|
333 | * Init MMU block address translation to enable hardware |
---|
334 | * access |
---|
335 | */ |
---|
336 | setdbat(1, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE); |
---|
337 | setdbat(3, 0x90000000, 0x90000000, 0x10000000, IO_PAGE); |
---|
338 | |
---|
339 | |
---|
340 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
341 | printk("Going to start PCI buses scanning and initialization\n"); |
---|
342 | #endif |
---|
343 | pci_initialize(); |
---|
344 | |
---|
345 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
346 | printk("Number of PCI buses found is : %d\n", pci_bus_count()); |
---|
347 | #endif |
---|
348 | #ifdef TEST_RAW_EXCEPTION_CODE |
---|
349 | printk("Testing exception handling Part 1\n"); |
---|
350 | |
---|
351 | /* |
---|
352 | * Cause a software exception |
---|
353 | */ |
---|
354 | __asm__ __volatile ("sc"); |
---|
355 | |
---|
356 | /* |
---|
357 | * Check we can still catch exceptions and returned coorectly. |
---|
358 | */ |
---|
359 | printk("Testing exception handling Part 2\n"); |
---|
360 | __asm__ __volatile ("sc"); |
---|
361 | #endif |
---|
362 | |
---|
363 | /* |
---|
364 | * Initalize RTEMS IRQ system |
---|
365 | */ |
---|
366 | BSP_rtems_irq_mng_init(0); |
---|
367 | |
---|
368 | /* Activate the page table mappings only after |
---|
369 | * initializing interrupts because the irq_mng_init() |
---|
370 | * routine needs to modify the text |
---|
371 | */ |
---|
372 | if (pt) { |
---|
373 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
374 | printk("Page table setup finished; will activate it NOW...\n"); |
---|
375 | #endif |
---|
376 | BSP_pgtbl_activate(pt); |
---|
377 | } |
---|
378 | |
---|
379 | /* |
---|
380 | * Initialize VME bridge - needs working PCI |
---|
381 | * and IRQ subsystems... |
---|
382 | */ |
---|
383 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
384 | printk("Going to initialize VME bridge\n"); |
---|
385 | #endif |
---|
386 | /* VME initialization is in a separate file so apps which don't use |
---|
387 | * VME or want a different configuration may link against a customized |
---|
388 | * routine. |
---|
389 | */ |
---|
390 | BSP_vme_config(); |
---|
391 | |
---|
392 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
393 | ShowBATS(); |
---|
394 | printk("Exit from bspstart\n"); |
---|
395 | #endif |
---|
396 | } |
---|