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