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