1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : irq_handler.c |
---|
3 | // Date : 01/04/2012 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
7 | |
---|
8 | #include <giet_config.h> |
---|
9 | #include <irq_handler.h> |
---|
10 | #include <sys_handler.h> |
---|
11 | #include <ctx_handler.h> |
---|
12 | #include <tim_driver.h> |
---|
13 | #include <icu_driver.h> |
---|
14 | #include <xcu_driver.h> |
---|
15 | #include <tty_driver.h> |
---|
16 | #include <nic_driver.h> |
---|
17 | #include <cma_driver.h> |
---|
18 | #include <mmc_driver.h> |
---|
19 | #include <bdv_driver.h> |
---|
20 | #include <dma_driver.h> |
---|
21 | #include <mapping_info.h> |
---|
22 | #include <utils.h> |
---|
23 | |
---|
24 | #if !defined( USE_XICU ) |
---|
25 | # error: You must define USE_XICU in the hard_config.h file |
---|
26 | #endif |
---|
27 | |
---|
28 | #if NB_TIM_CHANNELS |
---|
29 | extern volatile unsigned char _user_timer_event[X_SIZE*Y_SIZE*NB_TIM_CHANNELS] ; |
---|
30 | #endif |
---|
31 | |
---|
32 | /////////////////////////////////////////////////////////////////////////////////// |
---|
33 | // This function uses the ICU or XICU component (Interrupt Controler Unit) |
---|
34 | // to get the interrupt vector entry. There is one ICU or XICU component per |
---|
35 | // cluster, and this component can support up to NB_PROCS_MAX output IRQs. |
---|
36 | // It returns the highest priority active interrupt index (smaller |
---|
37 | // indexes have the highest priority). |
---|
38 | // Any value larger than 31 means "no active interrupt", and no ISR is executed. |
---|
39 | // |
---|
40 | // There is three interrupt vectors per processor (stored in the processor's |
---|
41 | // scheduler) for the three HWI, PTI, and WTI interrupts types. |
---|
42 | // Each interrupt vector entry contains three bits fields: |
---|
43 | // - isr_id bits[15:0] : defines the type of ISR to be executed. |
---|
44 | // - channel_id bits[30:16] : defines the channel for multi-channels peripherals. |
---|
45 | // - valid bit 31 : valid interrupt vector entry |
---|
46 | // If the peripheral is replicated in clusters, the channel_id is |
---|
47 | // a global index : channel_id = cluster_id * NB_CHANNELS_MAX + loc_id |
---|
48 | /////////////////////////////////////////////////////////////////////////////////// |
---|
49 | void _irq_demux() |
---|
50 | { |
---|
51 | unsigned int gpid = _get_procid(); |
---|
52 | unsigned int cluster_xy = gpid / NB_PROCS_MAX; |
---|
53 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
54 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
55 | unsigned int lpid = gpid % NB_PROCS_MAX; |
---|
56 | unsigned int irq_id; |
---|
57 | unsigned int irq_type; |
---|
58 | char* irq_type_str[] = { "HWI", "WTI", "PTI" }; |
---|
59 | |
---|
60 | // get the highest priority active IRQ index |
---|
61 | unsigned int icu_out_index = lpid * IRQ_PER_PROCESSOR; |
---|
62 | |
---|
63 | #if USE_XICU |
---|
64 | _xcu_get_index( cluster_xy, icu_out_index, &irq_id, &irq_type ); |
---|
65 | #else |
---|
66 | irq_type = IRQ_TYPE_HWI; |
---|
67 | _icu_get_index( cluster_xy, icu_out_index, &irq_id ); |
---|
68 | #endif |
---|
69 | |
---|
70 | if (irq_id < 32) |
---|
71 | { |
---|
72 | static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); |
---|
73 | unsigned int entry; |
---|
74 | unsigned int isr_type; |
---|
75 | unsigned int channel; |
---|
76 | |
---|
77 | if (irq_type == IRQ_TYPE_HWI) entry = psched->hwi_vector[irq_id]; |
---|
78 | else if (irq_type == IRQ_TYPE_PTI) entry = psched->pti_vector[irq_id]; |
---|
79 | else if (irq_type == IRQ_TYPE_WTI) entry = psched->wti_vector[irq_id]; |
---|
80 | else |
---|
81 | { |
---|
82 | _printf("\n[GIET ERROR] illegal irq_type in irq_demux()\n"); |
---|
83 | _exit(); |
---|
84 | } |
---|
85 | |
---|
86 | isr_type = (entry ) & 0x0000FFFF; |
---|
87 | channel = (entry>>16) & 0x00007FFF; |
---|
88 | |
---|
89 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlocks |
---|
90 | _puts("\n[IRQS DEBUG] Processor["); |
---|
91 | _putd(x); |
---|
92 | _puts(","); |
---|
93 | _putd(y); |
---|
94 | _puts(","); |
---|
95 | _putd(lpid); |
---|
96 | _puts("] enters _irq_demux() at cycle "); |
---|
97 | _putd(_get_proctime() ); |
---|
98 | _puts("\n "); |
---|
99 | _puts(irq_type_str[irq_type] ); |
---|
100 | _puts(" : irq_id = "); |
---|
101 | _putd(irq_id); |
---|
102 | _puts(" / isr_type = "); |
---|
103 | _putd(isr_type); |
---|
104 | _puts(" / channel = "); |
---|
105 | _putd(channel); |
---|
106 | _puts("\n"); |
---|
107 | #endif |
---|
108 | |
---|
109 | // ISR call |
---|
110 | if ( isr_type == ISR_TICK ) _isr_tick ( irq_type, irq_id, channel ); |
---|
111 | else if ( isr_type == ISR_WAKUP ) _isr_wakup ( irq_type, irq_id, channel ); |
---|
112 | else if ( isr_type == ISR_BDV ) _bdv_isr ( irq_type, irq_id, channel ); |
---|
113 | else if ( isr_type == ISR_CMA ) _cma_isr ( irq_type, irq_id, channel ); |
---|
114 | else if ( isr_type == ISR_TTY_RX ) _tty_rx_isr ( irq_type, irq_id, channel ); |
---|
115 | else if ( isr_type == ISR_TTY_TX ) _tty_tx_isr ( irq_type, irq_id, channel ); |
---|
116 | else if ( isr_type == ISR_NIC_RX ) _nic_rx_isr ( irq_type, irq_id, channel ); |
---|
117 | else if ( isr_type == ISR_NIC_TX ) _nic_tx_isr ( irq_type, irq_id, channel ); |
---|
118 | else if ( isr_type == ISR_TIMER ) _timer_isr ( irq_type, irq_id, channel ); |
---|
119 | else if ( isr_type == ISR_MMC ) _mmc_isr ( irq_type, irq_id, channel ); |
---|
120 | else |
---|
121 | { |
---|
122 | // we don't take the TTY lock to avoid deadlock |
---|
123 | _puts("\n[GIET ERROR] in _irq_demux() illegal ISR type on processor["); |
---|
124 | _putd(x); |
---|
125 | _puts(","); |
---|
126 | _putd(y); |
---|
127 | _puts(","); |
---|
128 | _putd(lpid); |
---|
129 | _puts("] at cycle "); |
---|
130 | _putd(_get_proctime() ); |
---|
131 | _puts("\n "); |
---|
132 | _puts(irq_type_str[irq_type] ); |
---|
133 | _puts(" : irq_id = "); |
---|
134 | _putd(irq_id); |
---|
135 | _puts(" / isr_type = "); |
---|
136 | _putd(isr_type); |
---|
137 | _puts(" / channel = "); |
---|
138 | _putd(channel); |
---|
139 | _puts("\n"); |
---|
140 | _exit(); |
---|
141 | } |
---|
142 | } |
---|
143 | else // no interrupt active |
---|
144 | { |
---|
145 | _isr_default(); |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | /////////////////////////////////////////////////////////////////////////////////// |
---|
150 | // The default ISR is called when there is no active IRQ when the interrupt |
---|
151 | // handler is called. It simply displays a warning message on TTY[0]. |
---|
152 | /////////////////////////////////////////////////////////////////////////////////// |
---|
153 | void _isr_default() |
---|
154 | { |
---|
155 | unsigned int gpid = _get_procid(); |
---|
156 | unsigned int cluster_xy = gpid / NB_PROCS_MAX; |
---|
157 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
158 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
159 | unsigned int lpid = gpid % NB_PROCS_MAX; |
---|
160 | |
---|
161 | // We don't take TTY lock to avoid deadlock |
---|
162 | _puts("\n[GIET WARNING] IRQ handler called but no active IRQ on processor["); |
---|
163 | _putd( x ); |
---|
164 | _puts(","); |
---|
165 | _putd( y ); |
---|
166 | _puts(","); |
---|
167 | _putd( lpid ); |
---|
168 | _puts("] at cycle "); |
---|
169 | _putd( _get_proctime() ); |
---|
170 | _puts("\n "); |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | /////////////////////////////////////////////////////////////////////////////////// |
---|
175 | // This ISR can only be executed after a WTI (IPI) to force a context switch |
---|
176 | // on a remote processor. The context switch is only executed if the current task |
---|
177 | // is the IDLE_TASK, or if the value written in the mailbox is non zero. |
---|
178 | /////////////////////////////////////////////////////////////////////////////////// |
---|
179 | void _isr_wakup( unsigned int irq_type, // HWI / WTI / PTI |
---|
180 | unsigned int irq_id, // index returned by ICU |
---|
181 | unsigned int channel ) // unused |
---|
182 | { |
---|
183 | unsigned int procid = _get_procid(); |
---|
184 | unsigned int cluster_xy = procid / NB_PROCS_MAX; |
---|
185 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
186 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
187 | unsigned int lpid = procid % NB_PROCS_MAX; |
---|
188 | unsigned int task = _get_current_task_id(); |
---|
189 | unsigned int value; |
---|
190 | |
---|
191 | if ( irq_type != IRQ_TYPE_WTI ) |
---|
192 | { |
---|
193 | // we don't take the TTY lock to avoid deadlocks |
---|
194 | _puts("[GIET ERROR] _isr_wakup() not called by a WTI on processor["); |
---|
195 | _putd( x ); |
---|
196 | _puts(","); |
---|
197 | _putd( y ); |
---|
198 | _puts(","); |
---|
199 | _putd( lpid ); |
---|
200 | _puts("] at cycle "); |
---|
201 | _putd( _get_proctime() ); |
---|
202 | _puts("\n"); |
---|
203 | _exit(); |
---|
204 | } |
---|
205 | |
---|
206 | // get mailbox value and acknowledge WTI |
---|
207 | _xcu_get_wti_value( cluster_xy, irq_id, &value ); |
---|
208 | |
---|
209 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlocks |
---|
210 | _puts("\n[IRQS DEBUG] Processor["); |
---|
211 | _putd( x ); |
---|
212 | _puts(","); |
---|
213 | _putd( y ); |
---|
214 | _puts(","); |
---|
215 | _putd( lpid ); |
---|
216 | _puts("] enters _isr_wakup() at cycle "); |
---|
217 | _putd( _get_proctime() ); |
---|
218 | _puts("\n WTI / mailbox data = "); |
---|
219 | _putx( value ); |
---|
220 | _puts(" / current task index = "); |
---|
221 | _putd( task ); |
---|
222 | _puts("\n "); |
---|
223 | #endif |
---|
224 | |
---|
225 | // context swich if required |
---|
226 | if ( (task == IDLE_TASK_INDEX) || (value != 0) ) _ctx_switch(); |
---|
227 | } |
---|
228 | |
---|
229 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
230 | // This ISR is in charge of context switch, and handles the IRQs generated by |
---|
231 | // the "system" timers contained in the MULTI_TIMER or in the XICU component. |
---|
232 | // The ISR acknowledges the IRQ, and calls the _ctx_switch() function. |
---|
233 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
234 | void _isr_tick( unsigned int irq_type, // HWI / WTI / PTI |
---|
235 | unsigned int irq_id, // index returned by ICU |
---|
236 | unsigned int channel ) // channel index if HWI |
---|
237 | { |
---|
238 | unsigned int procid = _get_procid(); |
---|
239 | unsigned int cluster_xy = procid / NB_PROCS_MAX; |
---|
240 | |
---|
241 | // acknowledge HWI or PTI |
---|
242 | if ( irq_type == IRQ_TYPE_HWI ) _timer_reset_irq( cluster_xy, channel ); |
---|
243 | else _xcu_timer_reset_irq( cluster_xy, irq_id ); |
---|
244 | |
---|
245 | #if GIET_DEBUG_IRQS // we don't take the lock to avoid deadlock |
---|
246 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
247 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
248 | unsigned int lpid = procid % NB_PROCS_MAX; |
---|
249 | _puts("\n[IRQS DEBUG] Processor["); |
---|
250 | _putd( x ); |
---|
251 | _puts(","); |
---|
252 | _putd( y ); |
---|
253 | _puts(","); |
---|
254 | _putd( lpid ); |
---|
255 | _puts("] enters _isr_tick() at cycle "); |
---|
256 | _putd( _get_proctime() ); |
---|
257 | _puts("\n "); |
---|
258 | #endif |
---|
259 | |
---|
260 | // context switch |
---|
261 | _ctx_switch(); |
---|
262 | } |
---|
263 | |
---|
264 | |
---|
265 | // Local Variables: |
---|
266 | // tab-width: 4 |
---|
267 | // c-basic-offset: 4 |
---|
268 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
269 | // indent-tabs-mode: nil |
---|
270 | // End: |
---|
271 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
272 | |
---|