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