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