source: soft/giet_vm/sys/irq_handler.c @ 215

Last change on this file since 215 was 215, checked in by karaoui, 12 years ago

New components are now mandotory in the XML description:

The files giet_vsegs.ld and hard_config.h are now autogenerated by the xml2bin tool.

File size: 9.4 KB
RevLine 
[158]1///////////////////////////////////////////////////////////////////////////////////
2// File     : irq_handler.c
3// Date     : 01/04/2012
[189]4// Author   : alain greiner
[158]5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
[189]7// The irq_handler.c and irq_handler.h files are part of the GIET-VM nano-kernel.
8// They contain the code of the _irq_demux() function that access the XICU or
9// ICU component (Interupt Controler Unit), and the various ISRs (Interrupt
10// Service Routine) associated to the peripherals.
[158]11///////////////////////////////////////////////////////////////////////////////////
12
13#include <giet_config.h>
14#include <irq_handler.h>
15#include <sys_handler.h>
16#include <drivers.h>
17#include <common.h>
18#include <ctx_handler.h>
19#include <hwr_mapping.h>
20
[215]21#if NB_TIMERS_MAX
22extern volatile unsigned char _user_timer_event[NB_CLUSTERS*NB_TIMERS_MAX] ;
23#endif
24
[158]25///////////////////////////////////////////////////////////////////////////////////
[189]26//      _irq_demux()
27// This function uses the ICU or XICU component (Interrupt Controler Unit)
28// to get the interrupt vector entry. There is one ICU or XICU component per
29// cluster, and this component can support up to NB_PROCS_MAX output IRQs.
30// It returns the highest priority active interrupt index (smaller
31// indexes have the highest priority).
32// Any value larger than 31 means "no active interrupt", and no ISR is executed.
[158]33//
[189]34// There is one interrupt vector per processor (stored in the scheduler associated
35// to the processor. Each interrupt vector entry contains two 16 bits fields:
36// - isr_id : defines the type of ISR to be executed.
37// - channel_id : defines the specific channel for multi-channels peripherals.
[158]38//
[189]39// If the peripheral is replicated in clusters (TIMER or DMA), the channel_id is
40// a global index : channel_id = cluster_id * NB_CHANNELS_MAX + loc_id   
[158]41///////////////////////////////////////////////////////////////////////////////////
[189]42void _irq_demux()
[158]43{
[189]44    unsigned int    pid = _procid();
45    unsigned int        irq_id;
[158]46
[189]47    // get the highest priority active IRQ index
[203]48    if ( _icu_get_index( pid / NB_PROCS_MAX,
49                         pid % NB_PROCS_MAX,
50                         &irq_id ) )
[158]51    {
[203]52        _get_lock(&_tty_put_lock);
53        _puts("\n[GIET ERROR] Strange... Wrong _icu_read in _irq_demux()\n");
54        _release_lock(&_tty_put_lock);
[189]55    }
[158]56
[189]57    if ( irq_id < 32 )  // do nothing if no interrupt active
[165]58    {
[189]59        unsigned int entry      = _get_interrupt_vector_entry(irq_id);
60        unsigned int isr_id     = entry & 0x000000FF;
61        unsigned int channel_id = (entry>>16) & 0x0000FFFF;
62        if      ( isr_id == ISR_SWITCH  ) _isr_switch();
63        else if ( isr_id == ISR_IOC     ) _isr_ioc();
64        else if ( isr_id == ISR_DMA     ) _isr_dma( channel_id );
65        else if ( isr_id == ISR_TTY     ) _isr_tty( channel_id );
66        else if ( isr_id == ISR_TIMER   ) _isr_timer( channel_id );
67        else                              _isr_default();
[165]68    }
[158]69}
70///////////////////////////////////////////////////////////////////////////////////
71//      _isr_default()
72// The default ISR is called when no specific ISR has been installed in the
[203]73// interrupt vector. It simply displays an error message on kernel TTY[0].
[158]74///////////////////////////////////////////////////////////////////////////////////
75void _isr_default()
76{
[203]77    _get_lock(&_tty_put_lock);
78    _puts("\n[GIET ERROR] Strange... Default ISR activated for processor ");
79    _putd( _procid() );
80    _puts("\n");
81    _release_lock(&_tty_put_lock);
[158]82}
[165]83
[158]84///////////////////////////////////////////////////////////////////////////////////
85//      _isr_dma()
[189]86// This ISR handles all IRQs generated by the multi-channels DMA controlers.
87// The multi_dma components can be distributed in the clusters.
[207]88// The channel_id argument is the local DMA channel index.
89//     dma_global_id = cluster_id*NB_DMAS_MAX + channel_id
90// - The ISR saves the transfert status in _dma_status[dma_global_id].
[189]91// - It acknowledges the interrupt to reinitialize the DMA controler.
[207]92// - it resets the synchronisation variable _dma_busy[dma_global_id].
[158]93///////////////////////////////////////////////////////////////////////////////////
[189]94void _isr_dma( unsigned int channel_id )
[158]95{
[213]96#if NB_DMAS_MAX > 0
[207]97    // compute cluster_id
98    unsigned int cluster_id = _procid()/NB_PROCS_MAX;
[158]99
[207]100    // compute dma_global_id
101    unsigned int dma_global_id = cluster_id*NB_DMAS_MAX + channel_id;
102
[169]103    // save DMA channel status 
[207]104    if ( _dma_get_status(cluster_id, 
105                         channel_id, 
106                         (unsigned int*)&_dma_status[dma_global_id] ) )
[204]107    {
108        _get_lock(&_tty_put_lock);
109        _puts("[GIET ERROR] illegal DMA channel detected by _isr_dma\n");
110        _release_lock(&_tty_put_lock);
111        return;
112    }
[169]113
[204]114    // reset DMA channel irq
[207]115    if ( _dma_reset_irq( cluster_id, 
116                         channel_id) )
[204]117    {
118        _get_lock(&_tty_put_lock);
119        _puts("[GIET ERROR] illegal DMA channel detected by _isr_dma\n");
120        _release_lock(&_tty_put_lock);
121        return;
122    }
[165]123
[169]124    // release DMA channel
[207]125    _dma_done[dma_global_id] = 1; 
[213]126#else
127    _puts("[GIET ERROR] NB_DMAS_MAX is set to zero\n");
128
129#endif
[158]130}
[165]131
[158]132///////////////////////////////////////////////////////////////////////////////////
133//      _isr_ioc()
[189]134// There is only one IOC controler shared by all tasks.
135// - The ISR save the status and acknowledge the IRQ.
136// - It sets the _ioc_done variable to signal completion.
[158]137///////////////////////////////////////////////////////////////////////////////////
138void _isr_ioc()
139{
[204]140     // save status & reset IRQ
[207]141    if ( _ioc_get_status( (unsigned int*)&_ioc_status ) )
[204]142    {
143        _get_lock(&_tty_put_lock);
144        _puts("[GIET ERROR] bad access to IOC status detected by _isr_ioc\n");
145        _release_lock(&_tty_put_lock);
146        return;
147    }
[158]148
[204]149    // signals completion
150    _ioc_done   = 1; 
[158]151}
[165]152
[158]153///////////////////////////////////////////////////////////////////////////////////
[189]154//         _isr_timer()
[203]155// This ISR handles the IRQs generated by the "user" timers (the IRQs generated
156// by the "system" timers should be handled by the _isr_switch().
[189]157// These timers are distributed in all clusters, and can be implemented
158// in a vci_multi_timer component, or in a vci_xicu component.
[207]159// The timer_id argument is the user timer local index.
160//     timer_globa_id = cluster_id*(NB_TIMERS_MAX) + timer_id
[189]161// The ISR acknowledges the IRQ and registers the event in the proper entry
[203]162// of the _timer_event[] array, and a log message is displayed on kernel terminal.
[158]163///////////////////////////////////////////////////////////////////////////////////
[203]164void _isr_timer(unsigned int timer_id)
[158]165{
[207]166    // compute cluster_id
167    unsigned int cluster_id = _procid()/NB_PROCS_MAX;
[158]168
[203]169    // aknowledge IRQ
[207]170    if ( _timer_reset_irq( cluster_id, 
171                           NB_PROCS_MAX + timer_id ) )
[204]172    {
173        _get_lock(&_tty_put_lock);
174        _puts("[GIET ERROR] illegal timer index detected by _isr_timer\n");
175        _release_lock(&_tty_put_lock);
176        return;
177    }
[189]178
179#if NB_TIMERS_MAX
180    // register the event
[207]181    unsigned int timer_global_id = cluster_id*NB_TIMERS_MAX + timer_id;
182    _user_timer_event[timer_global_id] = 1;
[189]183#endif
184
185    // display a message on TTY 0
[203]186    _get_lock(&_tty_put_lock);
[207]187    _puts("\n[GIET] User Timer IRQ at cycle ");
[203]188    _putd( _proctime() );
[207]189    _puts("\n - cluster_id = ");
190    _putd( cluster_id );
191    _puts("\n - timer_id   = ");
192    _putd( timer_id );
[189]193    _puts("\n");
[203]194    _release_lock(&_tty_put_lock);
[158]195}
196
197///////////////////////////////////////////////////////////////////////////////////
[189]198//  _isr_tty()
199// This ISR handles the IRQs generated by the multi_tty controler,
200// signaling that a character is available.
[204]201// There is one single multi_tty component controling all TTYs,
[207]202// and the tty_id argument is the global TTY index.
[189]203// There is one communication buffer _tty_buf[tty_id] per terminal.
204// The sychronisation variable _tty_full[tty_id], is set by the ISR,
[158]205// and reset by the OS.
206// A character is lost if the buffer is full when the ISR is executed.
207///////////////////////////////////////////////////////////////////////////////////
[189]208void _isr_tty(unsigned int tty_id)
[158]209{
[189]210    // save character and reset IRQ
[207]211    if ( _tty_get_char( tty_id, 
212                        (unsigned char*)&_tty_get_buf[tty_id] ) )
[204]213    {
214        _get_lock(&_tty_put_lock);
215        _puts("[GIET ERROR] illegal tty index detected by _isr_tty\n");
216        _release_lock(&_tty_put_lock);
217        return;
218    }
[158]219
[189]220    // signals character available
[158]221    _tty_get_full[tty_id] = 1;
222}
223
224/////////////////////////////////////////////////////////////////////////////////////
225// _isr_switch
[189]226// This ISR is in charge of context switch, and handle the IRQs generated by
227// the "system" timers.
228// The IRQs can be generated by the MULTI_TIMER component or by the XICU component,
229// that are distributed in all clusters.
230// The ISR acknowledges the IRQ and calls the _ctx_switch() function.
[158]231/////////////////////////////////////////////////////////////////////////////////////
232void _isr_switch()
233{
[189]234    // get cluster index and proc local index
235    unsigned int pid        = _procid();
[203]236    unsigned int local_id   = pid % NB_PROCS_MAX;
[189]237    unsigned int cluster_id = pid / NB_PROCS_MAX;
[158]238
[203]239    // acknowledge IRQ
[204]240    if ( _timer_reset_irq( cluster_id, local_id ) ) 
241    {
242        _get_lock(&_tty_put_lock);
243        _puts("[GIET ERROR] illegal proc index detected by _isr_switch\n");
244        _release_lock(&_tty_put_lock);
245        return;
246    }
[158]247
[189]248    // performs the context switch
[158]249    _ctx_switch();
250}
251
Note: See TracBrowser for help on using the repository browser.