1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS TQM8xx BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | This file has been adapted to MPC8xx by | |
---|
5 | | Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> | |
---|
6 | | Copyright (c) 2008 | |
---|
7 | | Embedded Brains GmbH | |
---|
8 | | Obere Lagerstr. 30 | |
---|
9 | | D-82178 Puchheim | |
---|
10 | | Germany | |
---|
11 | | rtems@embedded-brains.de | |
---|
12 | | | |
---|
13 | | See the other copyright notice below for the original parts. | |
---|
14 | +-----------------------------------------------------------------+ |
---|
15 | | The license and distribution terms for this file may be | |
---|
16 | | found in the file LICENSE in this distribution or at | |
---|
17 | | | |
---|
18 | | http://www.rtems.org/license/LICENSE. | |
---|
19 | | | |
---|
20 | +-----------------------------------------------------------------+ |
---|
21 | | this file contains the console driver | |
---|
22 | \*===============================================================*/ |
---|
23 | /* derived from: generic MPC83xx BSP */ |
---|
24 | |
---|
25 | #include <rtems.h> |
---|
26 | #include <mpc8xx.h> |
---|
27 | |
---|
28 | #include <libcpu/powerpc-utility.h> |
---|
29 | #include <bsp/vectors.h> |
---|
30 | |
---|
31 | #include <bsp.h> |
---|
32 | #include <bsp/irq.h> |
---|
33 | #include <bsp/irq-generic.h> |
---|
34 | /* |
---|
35 | * functions to enable/disable a source at the SIU/CPM irq controller |
---|
36 | */ |
---|
37 | |
---|
38 | static rtems_status_code bsp_irq_disable_at_SIU(rtems_vector_number irqnum) |
---|
39 | { |
---|
40 | rtems_vector_number vecnum = irqnum - BSP_SIU_IRQ_LOWEST_OFFSET; |
---|
41 | m8xx.simask &= ~(1 << (31 - vecnum)); |
---|
42 | return RTEMS_SUCCESSFUL; |
---|
43 | } |
---|
44 | |
---|
45 | static rtems_status_code bsp_irq_enable_at_SIU(rtems_vector_number irqnum) |
---|
46 | { |
---|
47 | rtems_vector_number vecnum = irqnum - BSP_SIU_IRQ_LOWEST_OFFSET; |
---|
48 | m8xx.simask |= (1 << (31 - vecnum)); |
---|
49 | return RTEMS_SUCCESSFUL; |
---|
50 | } |
---|
51 | |
---|
52 | static rtems_status_code bsp_irq_disable_at_CPM(rtems_vector_number irqnum) |
---|
53 | { |
---|
54 | rtems_vector_number vecnum = irqnum - BSP_CPM_IRQ_LOWEST_OFFSET; |
---|
55 | m8xx.cimr &= ~(1 << (vecnum)); |
---|
56 | return RTEMS_SUCCESSFUL; |
---|
57 | } |
---|
58 | |
---|
59 | static rtems_status_code bsp_irq_enable_at_CPM(rtems_vector_number irqnum) |
---|
60 | { |
---|
61 | rtems_vector_number vecnum = irqnum - BSP_CPM_IRQ_LOWEST_OFFSET; |
---|
62 | m8xx.cimr |= (1 << (vecnum)); |
---|
63 | return RTEMS_SUCCESSFUL; |
---|
64 | } |
---|
65 | |
---|
66 | rtems_status_code bsp_interrupt_get_attributes( |
---|
67 | rtems_vector_number vector, |
---|
68 | rtems_interrupt_attributes *attributes |
---|
69 | ) |
---|
70 | { |
---|
71 | return RTEMS_SUCCESSFUL; |
---|
72 | } |
---|
73 | |
---|
74 | rtems_status_code bsp_interrupt_is_pending( |
---|
75 | rtems_vector_number vector, |
---|
76 | bool *pending |
---|
77 | ) |
---|
78 | { |
---|
79 | bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); |
---|
80 | bsp_interrupt_assert(pending != NULL); |
---|
81 | *pending = false; |
---|
82 | return RTEMS_UNSATISFIED; |
---|
83 | } |
---|
84 | |
---|
85 | rtems_status_code bsp_interrupt_raise(rtems_vector_number vector) |
---|
86 | { |
---|
87 | bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); |
---|
88 | return RTEMS_UNSATISFIED; |
---|
89 | } |
---|
90 | |
---|
91 | rtems_status_code bsp_interrupt_clear(rtems_vector_number vector) |
---|
92 | { |
---|
93 | bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); |
---|
94 | return RTEMS_UNSATISFIED; |
---|
95 | } |
---|
96 | |
---|
97 | rtems_status_code bsp_interrupt_vector_is_enabled( |
---|
98 | rtems_vector_number vector, |
---|
99 | bool *enabled |
---|
100 | ) |
---|
101 | { |
---|
102 | bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); |
---|
103 | bsp_interrupt_assert(enabled != NULL); |
---|
104 | *enabled = false; |
---|
105 | return RTEMS_UNSATISFIED; |
---|
106 | } |
---|
107 | |
---|
108 | rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector) |
---|
109 | { |
---|
110 | bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); |
---|
111 | |
---|
112 | if (BSP_IS_CPM_IRQ(vector)) { |
---|
113 | bsp_irq_enable_at_CPM(vector); |
---|
114 | } else if (BSP_IS_SIU_IRQ(vector)) { |
---|
115 | bsp_irq_enable_at_SIU(vector); |
---|
116 | } |
---|
117 | |
---|
118 | return RTEMS_SUCCESSFUL; |
---|
119 | } |
---|
120 | |
---|
121 | rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector) |
---|
122 | { |
---|
123 | bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); |
---|
124 | |
---|
125 | if (BSP_IS_CPM_IRQ(vector)) { |
---|
126 | bsp_irq_disable_at_CPM(vector); |
---|
127 | } else if (BSP_IS_SIU_IRQ(vector)) { |
---|
128 | bsp_irq_disable_at_SIU(vector); |
---|
129 | } |
---|
130 | |
---|
131 | return RTEMS_SUCCESSFUL; |
---|
132 | } |
---|
133 | |
---|
134 | /* |
---|
135 | * IRQ Handler: this is called from the primary exception dispatcher |
---|
136 | */ |
---|
137 | static int BSP_irq_handle_at_cpm(void) |
---|
138 | { |
---|
139 | int32_t cpvecnum; |
---|
140 | uint32_t msr; |
---|
141 | |
---|
142 | /* Get vector number: write IACK=1, then read vectir */ |
---|
143 | m8xx.civr = 1; |
---|
144 | cpvecnum = (m8xx.civr >> 11) + BSP_CPM_IRQ_LOWEST_OFFSET; |
---|
145 | |
---|
146 | /* |
---|
147 | * Check the vector number, |
---|
148 | * enable exceptions and dispatch the handler. |
---|
149 | * NOTE: lower-prio interrupts are automatically masked in CPIC |
---|
150 | */ |
---|
151 | if (BSP_IS_CPM_IRQ(cpvecnum)) { |
---|
152 | /* Enable all interrupts */ |
---|
153 | msr = ppc_external_exceptions_enable(); |
---|
154 | /* Dispatch interrupt handlers */ |
---|
155 | bsp_interrupt_handler_dispatch(cpvecnum); |
---|
156 | /* Restore machine state */ |
---|
157 | ppc_external_exceptions_disable(msr); |
---|
158 | } |
---|
159 | else { |
---|
160 | /* not valid vector */ |
---|
161 | bsp_interrupt_handler_default(cpvecnum); |
---|
162 | } |
---|
163 | /* |
---|
164 | * clear "in-service" bit |
---|
165 | */ |
---|
166 | m8xx.cisr = 1 << (cpvecnum - BSP_CPM_IRQ_LOWEST_OFFSET); |
---|
167 | |
---|
168 | return 0; |
---|
169 | } |
---|
170 | |
---|
171 | static int BSP_irq_handle_at_siu( unsigned excNum) |
---|
172 | { |
---|
173 | int32_t sivecnum; |
---|
174 | uint32_t msr; |
---|
175 | bool is_cpm_irq; |
---|
176 | uint32_t simask_save; |
---|
177 | /* |
---|
178 | * check, if interrupt is pending |
---|
179 | * and repeat as long as valid interrupts are pending |
---|
180 | */ |
---|
181 | while (0 != (m8xx.simask & m8xx.sipend)) { |
---|
182 | /* Get vector number */ |
---|
183 | sivecnum = (m8xx.sivec >> 26); |
---|
184 | is_cpm_irq = (sivecnum == BSP_CPM_INTERRUPT); |
---|
185 | /* |
---|
186 | * Check the vector number, mask lower priority interrupts, enable |
---|
187 | * exceptions and dispatch the handler. |
---|
188 | */ |
---|
189 | if (BSP_IS_SIU_IRQ(sivecnum)) { |
---|
190 | simask_save = m8xx.simask; |
---|
191 | /* |
---|
192 | * if this is the CPM interrupt, mask lower prio interrupts at SIU |
---|
193 | * else mask lower and same priority interrupts |
---|
194 | */ |
---|
195 | m8xx.simask &= ~0 << (32 |
---|
196 | - sivecnum |
---|
197 | - ((is_cpm_irq) ? 1 : 0)); |
---|
198 | |
---|
199 | if (is_cpm_irq) { |
---|
200 | BSP_irq_handle_at_cpm(); |
---|
201 | } |
---|
202 | else { |
---|
203 | /* Enable all interrupts */ |
---|
204 | msr = ppc_external_exceptions_enable(); |
---|
205 | /* Dispatch interrupt handlers */ |
---|
206 | bsp_interrupt_handler_dispatch(sivecnum + BSP_SIU_IRQ_LOWEST_OFFSET); |
---|
207 | /* Restore machine state */ |
---|
208 | ppc_external_exceptions_disable(msr); |
---|
209 | /* |
---|
210 | * clear pending bit, if edge triggered interrupt input |
---|
211 | */ |
---|
212 | m8xx.sipend = 1 << (31 - sivecnum); |
---|
213 | } |
---|
214 | |
---|
215 | |
---|
216 | /* Restore initial masks */ |
---|
217 | m8xx.simask = simask_save; |
---|
218 | } else { |
---|
219 | /* not valid vector */ |
---|
220 | bsp_interrupt_handler_default(sivecnum); |
---|
221 | } |
---|
222 | } |
---|
223 | return 0; |
---|
224 | } |
---|
225 | |
---|
226 | /* |
---|
227 | * Activate the CPIC |
---|
228 | */ |
---|
229 | static rtems_status_code mpc8xx_cpic_initialize( void) |
---|
230 | { |
---|
231 | /* |
---|
232 | * mask off all interrupts |
---|
233 | */ |
---|
234 | m8xx.cimr = 0; |
---|
235 | /* |
---|
236 | * make sure CPIC request proper level at SIU interrupt controller |
---|
237 | */ |
---|
238 | m8xx.cicr = (0x00e41f80 | |
---|
239 | ((BSP_CPM_INTERRUPT/2) << 13)); |
---|
240 | /* |
---|
241 | * enable CPIC interrupt in SIU interrupt controller |
---|
242 | */ |
---|
243 | return bsp_irq_enable_at_SIU(BSP_CPM_INTERRUPT); |
---|
244 | } |
---|
245 | |
---|
246 | /* |
---|
247 | * Activate the SIU interrupt controller |
---|
248 | */ |
---|
249 | static rtems_status_code mpc8xx_siu_int_initialize( void) |
---|
250 | { |
---|
251 | /* |
---|
252 | * mask off all interrupts |
---|
253 | */ |
---|
254 | m8xx.simask = 0; |
---|
255 | |
---|
256 | return RTEMS_SUCCESSFUL; |
---|
257 | } |
---|
258 | |
---|
259 | static int mpc8xx_exception_handler(BSP_Exception_frame *frame, |
---|
260 | unsigned exception_number) |
---|
261 | { |
---|
262 | return BSP_irq_handle_at_siu(exception_number); |
---|
263 | } |
---|
264 | |
---|
265 | rtems_status_code bsp_interrupt_facility_initialize() |
---|
266 | { |
---|
267 | /* Install exception handler */ |
---|
268 | if (ppc_exc_set_handler(ASM_EXT_VECTOR, mpc8xx_exception_handler)) { |
---|
269 | return RTEMS_IO_ERROR; |
---|
270 | } |
---|
271 | /* Initialize the SIU interrupt controller */ |
---|
272 | if (mpc8xx_siu_int_initialize()) { |
---|
273 | return RTEMS_IO_ERROR; |
---|
274 | } |
---|
275 | /* Initialize the CPIC interrupt controller */ |
---|
276 | return mpc8xx_cpic_initialize(); |
---|
277 | } |
---|