[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 <xcu_driver.h> |
---|
| 14 | #include <tty_driver.h> |
---|
[294] | 15 | #include <nic_driver.h> |
---|
| 16 | #include <cma_driver.h> |
---|
[297] | 17 | #include <mmc_driver.h> |
---|
[294] | 18 | #include <bdv_driver.h> |
---|
[258] | 19 | #include <dma_driver.h> |
---|
[322] | 20 | #include <spi_driver.h> |
---|
[281] | 21 | #include <mapping_info.h> |
---|
[258] | 22 | #include <utils.h> |
---|
[459] | 23 | #include <tty0.h> |
---|
[258] | 24 | |
---|
| 25 | #if NB_TIM_CHANNELS |
---|
[440] | 26 | extern volatile unsigned char _user_timer_event[NB_TIM_CHANNELS] ; |
---|
[258] | 27 | #endif |
---|
| 28 | |
---|
[440] | 29 | // ISR_TYPE names for display |
---|
| 30 | char* _isr_type_name[] = { "DEFAULT", |
---|
| 31 | "TICK" , |
---|
| 32 | "TTY_RX" , |
---|
| 33 | "TTY_TX" , |
---|
| 34 | "BDV" , |
---|
| 35 | "TIMER" , |
---|
| 36 | "WAKUP" , |
---|
| 37 | "NIC_RX" , |
---|
| 38 | "NIC_TX" , |
---|
| 39 | "CMA" , |
---|
| 40 | "MMC" , |
---|
| 41 | "DMA" , |
---|
| 42 | "SPI" }; |
---|
| 43 | ///////////////// |
---|
[258] | 44 | void _irq_demux() |
---|
| 45 | { |
---|
[294] | 46 | unsigned int gpid = _get_procid(); |
---|
[428] | 47 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[294] | 48 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 49 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[428] | 50 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
[258] | 51 | unsigned int irq_id; |
---|
[294] | 52 | unsigned int irq_type; |
---|
[258] | 53 | |
---|
| 54 | // get the highest priority active IRQ index |
---|
[294] | 55 | unsigned int icu_out_index = lpid * IRQ_PER_PROCESSOR; |
---|
[258] | 56 | |
---|
[294] | 57 | _xcu_get_index( cluster_xy, icu_out_index, &irq_id, &irq_type ); |
---|
[258] | 58 | |
---|
| 59 | if (irq_id < 32) |
---|
| 60 | { |
---|
[294] | 61 | static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); |
---|
[346] | 62 | unsigned int entry = 0; |
---|
[294] | 63 | unsigned int isr_type; |
---|
| 64 | unsigned int channel; |
---|
[258] | 65 | |
---|
[294] | 66 | if (irq_type == IRQ_TYPE_HWI) entry = psched->hwi_vector[irq_id]; |
---|
| 67 | else if (irq_type == IRQ_TYPE_PTI) entry = psched->pti_vector[irq_id]; |
---|
| 68 | else if (irq_type == IRQ_TYPE_WTI) entry = psched->wti_vector[irq_id]; |
---|
| 69 | else |
---|
[258] | 70 | { |
---|
[294] | 71 | _printf("\n[GIET ERROR] illegal irq_type in irq_demux()\n"); |
---|
| 72 | _exit(); |
---|
[258] | 73 | } |
---|
[294] | 74 | |
---|
| 75 | isr_type = (entry ) & 0x0000FFFF; |
---|
| 76 | channel = (entry>>16) & 0x00007FFF; |
---|
| 77 | |
---|
| 78 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlocks |
---|
[310] | 79 | char* irq_type_str[] = { "HWI", "WTI", "PTI" }; |
---|
[294] | 80 | _puts("\n[IRQS DEBUG] Processor["); |
---|
| 81 | _putd(x); |
---|
| 82 | _puts(","); |
---|
| 83 | _putd(y); |
---|
| 84 | _puts(","); |
---|
| 85 | _putd(lpid); |
---|
| 86 | _puts("] enters _irq_demux() at cycle "); |
---|
| 87 | _putd(_get_proctime() ); |
---|
| 88 | _puts("\n "); |
---|
| 89 | _puts(irq_type_str[irq_type] ); |
---|
| 90 | _puts(" : irq_id = "); |
---|
| 91 | _putd(irq_id); |
---|
| 92 | _puts(" / isr_type = "); |
---|
| 93 | _putd(isr_type); |
---|
| 94 | _puts(" / channel = "); |
---|
| 95 | _putd(channel); |
---|
| 96 | _puts("\n"); |
---|
| 97 | #endif |
---|
| 98 | |
---|
| 99 | // ISR call |
---|
| 100 | if ( isr_type == ISR_TICK ) _isr_tick ( irq_type, irq_id, channel ); |
---|
| 101 | else if ( isr_type == ISR_WAKUP ) _isr_wakup ( irq_type, irq_id, channel ); |
---|
| 102 | else if ( isr_type == ISR_BDV ) _bdv_isr ( irq_type, irq_id, channel ); |
---|
| 103 | else if ( isr_type == ISR_CMA ) _cma_isr ( irq_type, irq_id, channel ); |
---|
| 104 | else if ( isr_type == ISR_TTY_RX ) _tty_rx_isr ( irq_type, irq_id, channel ); |
---|
| 105 | else if ( isr_type == ISR_TTY_TX ) _tty_tx_isr ( irq_type, irq_id, channel ); |
---|
| 106 | else if ( isr_type == ISR_NIC_RX ) _nic_rx_isr ( irq_type, irq_id, channel ); |
---|
| 107 | else if ( isr_type == ISR_NIC_TX ) _nic_tx_isr ( irq_type, irq_id, channel ); |
---|
| 108 | else if ( isr_type == ISR_TIMER ) _timer_isr ( irq_type, irq_id, channel ); |
---|
[297] | 109 | else if ( isr_type == ISR_MMC ) _mmc_isr ( irq_type, irq_id, channel ); |
---|
[322] | 110 | else if ( isr_type == ISR_DMA ) _dma_isr ( irq_type, irq_id, channel ); |
---|
| 111 | else if ( isr_type == ISR_SPI ) _spi_isr ( irq_type, irq_id, channel ); |
---|
[294] | 112 | else |
---|
[258] | 113 | { |
---|
[310] | 114 | _printf("\n[GIET ERROR] in _irq_demux() :" |
---|
| 115 | " illegal ISR type on processor[%d,%d,%d] at cycle %d\n" |
---|
| 116 | " - irq_type = %d\n" |
---|
| 117 | " - irq_id = %d\n" |
---|
| 118 | " - isr_type = %x\n", |
---|
| 119 | x, y, lpid, _get_proctime(), irq_type, irq_id, isr_type ); |
---|
[258] | 120 | } |
---|
| 121 | } |
---|
[294] | 122 | else // no interrupt active |
---|
| 123 | { |
---|
| 124 | _isr_default(); |
---|
| 125 | } |
---|
[258] | 126 | } |
---|
| 127 | |
---|
[440] | 128 | /////////////////// |
---|
[294] | 129 | void _isr_default() |
---|
[258] | 130 | { |
---|
[294] | 131 | unsigned int gpid = _get_procid(); |
---|
[428] | 132 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[294] | 133 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 134 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[428] | 135 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
[258] | 136 | |
---|
[322] | 137 | _printf("\n[GIET WARNING] IRQ handler called but no active IRQ " |
---|
| 138 | "on processor[%d,%d,%d] at cycle %d\n", |
---|
| 139 | x, y, lpid, _get_proctime() ); |
---|
[258] | 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
[440] | 143 | //////////////////////////////////////////////////////////// |
---|
[294] | 144 | void _isr_wakup( unsigned int irq_type, // HWI / WTI / PTI |
---|
| 145 | unsigned int irq_id, // index returned by ICU |
---|
| 146 | unsigned int channel ) // unused |
---|
[258] | 147 | { |
---|
[428] | 148 | unsigned int gpid = _get_procid(); |
---|
| 149 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[294] | 150 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 151 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[428] | 152 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
| 153 | |
---|
[294] | 154 | unsigned int task = _get_current_task_id(); |
---|
| 155 | unsigned int value; |
---|
[258] | 156 | |
---|
[294] | 157 | if ( irq_type != IRQ_TYPE_WTI ) |
---|
[258] | 158 | { |
---|
[294] | 159 | _puts("[GIET ERROR] _isr_wakup() not called by a WTI on processor["); |
---|
| 160 | _putd( x ); |
---|
| 161 | _puts(","); |
---|
| 162 | _putd( y ); |
---|
| 163 | _puts(","); |
---|
| 164 | _putd( lpid ); |
---|
| 165 | _puts("] at cycle "); |
---|
| 166 | _putd( _get_proctime() ); |
---|
| 167 | _puts("\n"); |
---|
| 168 | _exit(); |
---|
[258] | 169 | } |
---|
| 170 | |
---|
[294] | 171 | // get mailbox value and acknowledge WTI |
---|
| 172 | _xcu_get_wti_value( cluster_xy, irq_id, &value ); |
---|
| 173 | |
---|
| 174 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlocks |
---|
| 175 | _puts("\n[IRQS DEBUG] Processor["); |
---|
| 176 | _putd( x ); |
---|
| 177 | _puts(","); |
---|
| 178 | _putd( y ); |
---|
| 179 | _puts(","); |
---|
| 180 | _putd( lpid ); |
---|
| 181 | _puts("] enters _isr_wakup() at cycle "); |
---|
| 182 | _putd( _get_proctime() ); |
---|
| 183 | _puts("\n WTI / mailbox data = "); |
---|
| 184 | _putx( value ); |
---|
| 185 | _puts(" / current task index = "); |
---|
| 186 | _putd( task ); |
---|
| 187 | _puts("\n "); |
---|
[258] | 188 | #endif |
---|
| 189 | |
---|
[294] | 190 | // context swich if required |
---|
| 191 | if ( (task == IDLE_TASK_INDEX) || (value != 0) ) _ctx_switch(); |
---|
[440] | 192 | } // end _isr_wakup |
---|
[258] | 193 | |
---|
[440] | 194 | /////////////////////////////////////////////////////////// |
---|
[294] | 195 | void _isr_tick( unsigned int irq_type, // HWI / WTI / PTI |
---|
| 196 | unsigned int irq_id, // index returned by ICU |
---|
| 197 | unsigned int channel ) // channel index if HWI |
---|
[258] | 198 | { |
---|
[428] | 199 | unsigned int gpid = _get_procid(); |
---|
| 200 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[440] | 201 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 202 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
| 203 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
[258] | 204 | |
---|
[440] | 205 | if ( irq_type != IRQ_TYPE_PTI ) |
---|
| 206 | { |
---|
| 207 | _puts("[GIET ERROR] _isr_tick() not called by a PTI on processor["); |
---|
| 208 | _putd( x ); |
---|
| 209 | _puts(","); |
---|
| 210 | _putd( y ); |
---|
| 211 | _puts(","); |
---|
| 212 | _putd( lpid ); |
---|
| 213 | _puts("] at cycle "); |
---|
| 214 | _putd( _get_proctime() ); |
---|
| 215 | _puts("\n"); |
---|
| 216 | _exit(); |
---|
| 217 | } |
---|
[258] | 218 | |
---|
[440] | 219 | // acknowledge PTI |
---|
| 220 | _xcu_timer_reset_irq( cluster_xy, irq_id ); |
---|
| 221 | |
---|
| 222 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlock |
---|
[294] | 223 | _puts("\n[IRQS DEBUG] Processor["); |
---|
| 224 | _putd( x ); |
---|
| 225 | _puts(","); |
---|
| 226 | _putd( y ); |
---|
| 227 | _puts(","); |
---|
| 228 | _putd( lpid ); |
---|
| 229 | _puts("] enters _isr_tick() at cycle "); |
---|
| 230 | _putd( _get_proctime() ); |
---|
| 231 | _puts("\n "); |
---|
[258] | 232 | #endif |
---|
| 233 | |
---|
[294] | 234 | // context switch |
---|
[258] | 235 | _ctx_switch(); |
---|
[440] | 236 | } // end _isr_tick |
---|
[258] | 237 | |
---|
| 238 | |
---|
| 239 | // Local Variables: |
---|
| 240 | // tab-width: 4 |
---|
| 241 | // c-basic-offset: 4 |
---|
| 242 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 243 | // indent-tabs-mode: nil |
---|
| 244 | // End: |
---|
| 245 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 246 | |
---|