1 | /* |
---|
2 | * COPYRIGHT (c) 1998 by Radstone Technology |
---|
3 | * |
---|
4 | * |
---|
5 | * THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY |
---|
6 | * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
---|
7 | * IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK |
---|
8 | * AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU. |
---|
9 | * |
---|
10 | * You are hereby granted permission to use, copy, modify, and distribute |
---|
11 | * this file, provided that this notice, plus the above copyright notice |
---|
12 | * and disclaimer, appears in all copies. Radstone Technology will provide |
---|
13 | * no support for this code. |
---|
14 | * |
---|
15 | */ |
---|
16 | /* bspstart.c |
---|
17 | * |
---|
18 | * This set of routines starts the application. It includes application, |
---|
19 | * board, and monitor specific initialization and configuration. |
---|
20 | * The generic CPU dependent initialization has been performed |
---|
21 | * before any of these are invoked. |
---|
22 | * |
---|
23 | * COPYRIGHT (c) 1989-1997. |
---|
24 | * On-Line Applications Research Corporation (OAR). |
---|
25 | * |
---|
26 | * The license and distribution terms for this file may in |
---|
27 | * the file LICENSE in this distribution or at |
---|
28 | * http://www.rtems.com/license/LICENSE. |
---|
29 | * |
---|
30 | * $Id: |
---|
31 | */ |
---|
32 | |
---|
33 | #include <string.h> |
---|
34 | |
---|
35 | #include <bsp.h> |
---|
36 | #include <rtems/libio.h> |
---|
37 | #include <rtems/libcsupport.h> |
---|
38 | #include <pci.h> |
---|
39 | |
---|
40 | unsigned char ucSystemType; |
---|
41 | unsigned char ucBoardRevMaj; |
---|
42 | unsigned char ucBoardRevMin; |
---|
43 | unsigned long ulMemorySize; |
---|
44 | unsigned long ulCpuBusClock; |
---|
45 | |
---|
46 | /* |
---|
47 | * The bus speed is expressed in MHz |
---|
48 | */ |
---|
49 | static unsigned long ulBusSpeed[] = { |
---|
50 | 56250000, |
---|
51 | 60000000, |
---|
52 | 64300000, |
---|
53 | 66666667, |
---|
54 | 75000000, |
---|
55 | 83333333, |
---|
56 | 100000000, |
---|
57 | 66666667 |
---|
58 | }; |
---|
59 | |
---|
60 | /* |
---|
61 | * The original table from the application and our copy of it with |
---|
62 | * some changes. |
---|
63 | */ |
---|
64 | |
---|
65 | extern rtems_configuration_table Configuration; |
---|
66 | rtems_configuration_table BSP_Configuration; |
---|
67 | |
---|
68 | rtems_cpu_table Cpu_table; |
---|
69 | uint32_t bsp_isr_level; |
---|
70 | |
---|
71 | static int stdin_fd, stdout_fd, stderr_fd; |
---|
72 | |
---|
73 | /* |
---|
74 | * End of RTEMs image imported from linker |
---|
75 | */ |
---|
76 | extern int end; |
---|
77 | |
---|
78 | /* |
---|
79 | * Use the shared implementations of the following routines |
---|
80 | */ |
---|
81 | |
---|
82 | void bsp_postdriver_hook(void); |
---|
83 | void bsp_libc_init( void *, uint32_t, int ); |
---|
84 | |
---|
85 | /* |
---|
86 | * bsp_pretasking_hook |
---|
87 | * |
---|
88 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
89 | * Used to setup libc and install any BSP extensions. |
---|
90 | */ |
---|
91 | |
---|
92 | void bsp_pretasking_hook(void) |
---|
93 | { |
---|
94 | uint32_t heap_start; |
---|
95 | uint32_t heap_size; |
---|
96 | |
---|
97 | heap_start = (uint32_t) &end; |
---|
98 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
99 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
100 | |
---|
101 | heap_size = BSP_Configuration.work_space_start - (void *)&end; |
---|
102 | heap_size &= 0xfffffff0; /* keep it as a multiple of 16 bytes */ |
---|
103 | |
---|
104 | bsp_libc_init((void *) heap_start, heap_size, 0); |
---|
105 | |
---|
106 | /* |
---|
107 | * Initialise RTC hooks based on system type |
---|
108 | */ |
---|
109 | InitializeRTC(); |
---|
110 | |
---|
111 | /* |
---|
112 | * Initialise NvRAM hooks based on system type |
---|
113 | */ |
---|
114 | InitializeNvRAM(); |
---|
115 | |
---|
116 | /* |
---|
117 | * Initialise the PCI bus(ses) |
---|
118 | */ |
---|
119 | InitializePCI(); |
---|
120 | |
---|
121 | /* |
---|
122 | * Initialize the Universe PCI-VME bridge |
---|
123 | */ |
---|
124 | InitializeUniverse(); |
---|
125 | |
---|
126 | |
---|
127 | #ifdef RTEMS_DEBUG |
---|
128 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
129 | #endif |
---|
130 | |
---|
131 | } |
---|
132 | |
---|
133 | /* |
---|
134 | * bsp_std_close |
---|
135 | * |
---|
136 | * Simple routine to close all standard IO streams. |
---|
137 | */ |
---|
138 | |
---|
139 | void bsp_std_close( void ) |
---|
140 | { |
---|
141 | close(stdin_fd); |
---|
142 | close(stdout_fd); |
---|
143 | close(stderr_fd); |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | /* |
---|
148 | * bsp_predriver_hook |
---|
149 | * |
---|
150 | * Before drivers are setup. |
---|
151 | */ |
---|
152 | void bsp_predriver_hook(void) |
---|
153 | { |
---|
154 | /* bsp_spurious_initialize; ??*/ |
---|
155 | initialize_external_exception_vector(); |
---|
156 | } |
---|
157 | |
---|
158 | /* |
---|
159 | * bsp_start |
---|
160 | * |
---|
161 | * This routine does the bulk of the system initialization. |
---|
162 | */ |
---|
163 | |
---|
164 | void bsp_start( void ) |
---|
165 | { |
---|
166 | unsigned char *work_space_start; |
---|
167 | unsigned char ucBoardRev, ucMothMemType, ucEquipPres1, ucEquipPres2; |
---|
168 | uint16_t usPVR=0; |
---|
169 | uint8_t ucTempl, ucTemph; |
---|
170 | uint8_t ucBanksPresent; |
---|
171 | uint8_t ucSimmPresent; |
---|
172 | uint32_t ulCurBank, ulTopBank; |
---|
173 | |
---|
174 | /* |
---|
175 | * Determine system type |
---|
176 | */ |
---|
177 | inport_byte(&((PPLANARREGISTERS)0)->MotherboardMemoryType, ucMothMemType); |
---|
178 | inport_byte(&((PPLANARREGISTERS)0)->SimmPresent, ucSimmPresent); |
---|
179 | |
---|
180 | inport_byte(&((PPLANARREGISTERS)0)->EquipmentPresent1, ucEquipPres1); |
---|
181 | inport_byte(&((PPLANARREGISTERS)0)->EquipmentPresent2, ucEquipPres2); |
---|
182 | ucSystemType=((ucMothMemType&0x03)<<1) | ((ucEquipPres1&0x80)>>7); |
---|
183 | ucSystemType^=7; |
---|
184 | |
---|
185 | /* |
---|
186 | * Determine board revision for use by rev. specific code |
---|
187 | */ |
---|
188 | inport_byte(&((PPLANARREGISTERS)0)->BoardRevision, ucBoardRev); |
---|
189 | ucBoardRevMaj=ucBoardRev>>5; |
---|
190 | ucBoardRevMin=ucBoardRev&0x1f; |
---|
191 | |
---|
192 | /* |
---|
193 | * Determine the memory size by reading the end address for top |
---|
194 | * assigned bank in the memory controller |
---|
195 | */ |
---|
196 | (void)PCIConfigRead8(0,0,0,0xa0, &ucBanksPresent); |
---|
197 | for(ulCurBank=0;ulCurBank<8;ulCurBank++) |
---|
198 | { |
---|
199 | if((ucBanksPresent>>ulCurBank)&0x01) |
---|
200 | { |
---|
201 | ulTopBank=ulCurBank; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | (void)PCIConfigRead8(0,0,0,0x90+ulTopBank, &ucTempl); |
---|
206 | (void)PCIConfigRead8(0,0,0,0x98+ulTopBank, &ucTemph); |
---|
207 | ulMemorySize=(ucTempl+(ucTemph<<8)+1)<<20; |
---|
208 | #if PPCN_60X_USE_DINK |
---|
209 | ulMemorySize=0x01fe0000; |
---|
210 | #endif |
---|
211 | |
---|
212 | /* |
---|
213 | * Determine processor bus clock |
---|
214 | */ |
---|
215 | asm volatile ("mfpvr %0" : "=r" ((usPVR)) : "0" ((usPVR))); |
---|
216 | |
---|
217 | /* |
---|
218 | * Determine processor internal clock |
---|
219 | */ |
---|
220 | if(ucSystemType==SYS_TYPE_PPC4) |
---|
221 | { |
---|
222 | if(((ucBoardRevMaj==1) && (ucBoardRevMin==0)) || |
---|
223 | ((ucSimmPresent&0x40)==0)) |
---|
224 | { |
---|
225 | /* |
---|
226 | * Rev. 1A is always 66MHz |
---|
227 | */ |
---|
228 | ulCpuBusClock=66666667; |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | ulCpuBusClock=83333333; |
---|
233 | } |
---|
234 | } |
---|
235 | else if((((usPVR>>16)==MPC603e) && (ucSystemType!=SYS_TYPE_PPC1)) || |
---|
236 | ((usPVR>>16)==MPC603ev) || |
---|
237 | ((usPVR>>16)==MPC604e)) |
---|
238 | { |
---|
239 | ulCpuBusClock=ulBusSpeed[(ucEquipPres2&0x1c)>>2]; |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | if(((ucSystemType>SYS_TYPE_PPC1) || (ucBoardRevMaj>=5)) && |
---|
244 | (ucEquipPres1&0x08)) |
---|
245 | { |
---|
246 | /* |
---|
247 | * 66 MHz bus clock for 005 if indicated |
---|
248 | */ |
---|
249 | ulCpuBusClock=66666667; |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | /* |
---|
254 | * 33 MHz bus clock for 004 always |
---|
255 | */ |
---|
256 | ulCpuBusClock=33333333; |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | |
---|
261 | /* |
---|
262 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
263 | * a variety of places: hard coded address, malloc'ed from outside |
---|
264 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
265 | * typically done by stock BSPs) by subtracting the required amount |
---|
266 | * of work space from the last physical address on the CPU board. |
---|
267 | */ |
---|
268 | |
---|
269 | work_space_start = |
---|
270 | (unsigned char *)ulMemorySize - BSP_Configuration.work_space_size; |
---|
271 | |
---|
272 | if ( work_space_start <= (unsigned char *)&end ) { |
---|
273 | DEBUG_puts( "bspstart: Not enough RAM!!!\n" ); |
---|
274 | bsp_cleanup(); |
---|
275 | } |
---|
276 | |
---|
277 | BSP_Configuration.work_space_start = work_space_start; |
---|
278 | |
---|
279 | /* |
---|
280 | * initialize the CPU table for this BSP |
---|
281 | */ |
---|
282 | |
---|
283 | Cpu_table.exceptions_in_RAM = TRUE; |
---|
284 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
285 | Cpu_table.predriver_hook = bsp_predriver_hook; |
---|
286 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
287 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
288 | Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY; |
---|
289 | Cpu_table.clicks_per_usec = ulCpuBusClock/4000000; |
---|
290 | |
---|
291 | |
---|
292 | } |
---|
293 | |
---|