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

Last change on this file since 203 was 203, checked in by alain, 12 years ago

Introducing support for XICU

File size: 8.6 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
21///////////////////////////////////////////////////////////////////////////////////
[189]22//      _irq_demux()
23// This function uses the ICU or XICU component (Interrupt Controler Unit)
24// to get the interrupt vector entry. There is one ICU or XICU component per
25// cluster, and this component can support up to NB_PROCS_MAX output IRQs.
26// It returns the highest priority active interrupt index (smaller
27// indexes have the highest priority).
28// Any value larger than 31 means "no active interrupt", and no ISR is executed.
[158]29//
[189]30// There is one interrupt vector per processor (stored in the scheduler associated
31// to the processor. Each interrupt vector entry contains two 16 bits fields:
32// - isr_id : defines the type of ISR to be executed.
33// - channel_id : defines the specific channel for multi-channels peripherals.
[158]34//
[189]35// If the peripheral is replicated in clusters (TIMER or DMA), the channel_id is
36// a global index : channel_id = cluster_id * NB_CHANNELS_MAX + loc_id   
[158]37///////////////////////////////////////////////////////////////////////////////////
[189]38void _irq_demux()
[158]39{
[189]40    unsigned int    pid = _procid();
41    unsigned int        irq_id;
[158]42
[189]43    // get the highest priority active IRQ index
[203]44    if ( _icu_get_index( pid / NB_PROCS_MAX,
45                         pid % NB_PROCS_MAX,
46                         &irq_id ) )
[158]47    {
[203]48        _get_lock(&_tty_put_lock);
49        _puts("\n[GIET ERROR] Strange... Wrong _icu_read in _irq_demux()\n");
50        _release_lock(&_tty_put_lock);
[189]51    }
[158]52
[189]53    if ( irq_id < 32 )  // do nothing if no interrupt active
[165]54    {
[189]55        unsigned int entry      = _get_interrupt_vector_entry(irq_id);
56        unsigned int isr_id     = entry & 0x000000FF;
57        unsigned int channel_id = (entry>>16) & 0x0000FFFF;
58        if      ( isr_id == ISR_SWITCH  ) _isr_switch();
59        else if ( isr_id == ISR_IOC     ) _isr_ioc();
60        else if ( isr_id == ISR_DMA     ) _isr_dma( channel_id );
61        else if ( isr_id == ISR_TTY     ) _isr_tty( channel_id );
62        else if ( isr_id == ISR_TIMER   ) _isr_timer( channel_id );
63        else                              _isr_default();
[165]64    }
[158]65}
66///////////////////////////////////////////////////////////////////////////////////
67//      _isr_default()
68// The default ISR is called when no specific ISR has been installed in the
[203]69// interrupt vector. It simply displays an error message on kernel TTY[0].
[158]70///////////////////////////////////////////////////////////////////////////////////
71void _isr_default()
72{
[203]73    _get_lock(&_tty_put_lock);
74    _puts("\n[GIET ERROR] Strange... Default ISR activated for processor ");
75    _putd( _procid() );
76    _puts("\n");
77    _release_lock(&_tty_put_lock);
[158]78}
[165]79
[158]80///////////////////////////////////////////////////////////////////////////////////
81//      _isr_dma()
[189]82// This ISR handles all IRQs generated by the multi-channels DMA controlers.
83// The multi_dma components can be distributed in the clusters.
84// The channel_id argument is the global DMA channel index.
85//     channel_id = cluster_id*NB_DMAS_MAX + loc_id
86// - The ISR saves the transfert status in _dma_status[channel_id].
87// - It acknowledges the interrupt to reinitialize the DMA controler.
88// - it resets the synchronisation variable _dma_busy[channel_id].
[158]89///////////////////////////////////////////////////////////////////////////////////
[189]90void _isr_dma( unsigned int channel_id )
[158]91{
[189]92    // compute cluster_id and loc_id
93    unsigned int cluster_id = channel_id / NB_DMAS_MAX;
94    unsigned int loc_id     = channel_id % NB_DMAS_MAX;
[158]95
[169]96    // compute DMA channel address
[189]97    unsigned int*       dma_address = (unsigned int*)&seg_dma_base + 
98                                  (loc_id * DMA_SPAN) +
99                                  (cluster_id * CLUSTER_SPAN);
[158]100
[169]101    // save DMA channel status 
[189]102    _dma_status[channel_id] = dma_address[DMA_LEN];
[169]103
104    // reset DMA channel
[189]105    dma_address[DMA_RESET] = 0;                 
[165]106
[169]107    // release DMA channel
[189]108    _dma_done[channel_id] = 1; 
[158]109}
[165]110
[158]111///////////////////////////////////////////////////////////////////////////////////
112//      _isr_ioc()
[189]113// There is only one IOC controler shared by all tasks.
114// - The ISR save the status and acknowledge the IRQ.
115// - It sets the _ioc_done variable to signal completion.
[158]116///////////////////////////////////////////////////////////////////////////////////
117void _isr_ioc()
118{
[189]119    unsigned int* ioc_address = (unsigned int*)&seg_ioc_base;
[158]120
[203]121    _ioc_status = ioc_address[BLOCK_DEVICE_STATUS]; // save status & reset IRQ
122    _ioc_done   = 1;                                // signals completion
[158]123}
[165]124
[158]125///////////////////////////////////////////////////////////////////////////////////
[189]126//         _isr_timer()
[203]127// This ISR handles the IRQs generated by the "user" timers (the IRQs generated
128// by the "system" timers should be handled by the _isr_switch().
[189]129// These timers are distributed in all clusters, and can be implemented
130// in a vci_multi_timer component, or in a vci_xicu component.
[203]131// The timer_id argument is a global index:
132//     timer_id = cluster_id*(NB_TIMERS_MAX+NB_PROCS_MAX) + local_id
[189]133// The user timer local index is (loc_id - NB_PROCS_MAX).
134//
135// The ISR acknowledges the IRQ and registers the event in the proper entry
[203]136// of the _timer_event[] array, and a log message is displayed on kernel terminal.
[158]137///////////////////////////////////////////////////////////////////////////////////
[203]138void _isr_timer(unsigned int timer_id)
[158]139{
140
[203]141    unsigned int cluster_id = timer_id / (NB_TIMERS_MAX + NB_PROCS_MAX);
142    unsigned int local_id   = timer_id % (NB_TIMERS_MAX + NB_PROCS_MAX); 
[158]143
[203]144    // checking timer type
145    if (local_id < NB_PROCS_MAX )
[189]146    {
[203]147        _get_lock(&_tty_put_lock);
148        _puts("[GIET ERROR] Strange... User timer ISR for a system timer\n");
149        _release_lock(&_tty_put_lock);
[189]150    }
[158]151
[203]152    // aknowledge IRQ
153    _timer_reset_irq( cluster_id, local_id );
[189]154
155#if NB_TIMERS_MAX
156    // register the event
157    _timer_event[(cluster_id*NB_TIMERS_MAX) + (loc_id - NB_PROCS_MAX)] = 1;
158#endif
159
160    // display a message on TTY 0
[203]161    _get_lock(&_tty_put_lock);
162    _puts("[GIET] User Timer IRQ at cycle ");
163    _putd( _proctime() );
164    _puts(" / index = ");
165    _putd(timer_id);
[189]166    _puts("\n");
[203]167    _release_lock(&_tty_put_lock);
[158]168}
169
170///////////////////////////////////////////////////////////////////////////////////
[189]171//  _isr_tty()
172// This ISR handles the IRQs generated by the multi_tty controler,
173// signaling that a character is available.
174// There is one single multi_tty component controling all TTYs, and the tty_id
175// argument is the global TTY index.
176// There is one communication buffer _tty_buf[tty_id] per terminal.
177// The sychronisation variable _tty_full[tty_id], is set by the ISR,
[158]178// and reset by the OS.
179// A character is lost if the buffer is full when the ISR is executed.
180///////////////////////////////////////////////////////////////////////////////////
[189]181void _isr_tty(unsigned int tty_id)
[158]182{
[189]183    // compute terminal base address
184    unsigned int *tty_address = (unsigned int*)&seg_tty_base + (tty_id * TTY_SPAN);
[158]185
[189]186    // save character and reset IRQ
[158]187    _tty_get_buf[tty_id] = (unsigned char)tty_address[TTY_READ];
188
[189]189    // signals character available
[158]190    _tty_get_full[tty_id] = 1;
191}
192
193/////////////////////////////////////////////////////////////////////////////////////
194// _isr_switch
[189]195// This ISR is in charge of context switch, and handle the IRQs generated by
196// the "system" timers.
197// The IRQs can be generated by the MULTI_TIMER component or by the XICU component,
198// that are distributed in all clusters.
199// The ISR acknowledges the IRQ and calls the _ctx_switch() function.
[158]200/////////////////////////////////////////////////////////////////////////////////////
201void _isr_switch()
202{
[189]203    // get cluster index and proc local index
204    unsigned int pid        = _procid();
[203]205    unsigned int local_id   = pid % NB_PROCS_MAX;
[189]206    unsigned int cluster_id = pid / NB_PROCS_MAX;
[158]207
[203]208    // acknowledge IRQ
209    _timer_reset_irq( cluster_id, local_id ); 
[158]210
[189]211    // performs the context switch
[158]212    _ctx_switch();
213}
214
Note: See TracBrowser for help on using the repository browser.