source: trunk/modules/vci_io_bridge/caba/source/include/vci_io_bridge.h @ 585

Last change on this file since 585 was 585, checked in by alain, 10 years ago

debug...

File size: 18.8 KB
Line 
1/* -*- c++ -*-
2 * File : vci_io_bridge.h
3 * Copyright (c) UPMC, Lip6, SoC
4 * Date : 16/04/2012
5 * Authors: Cassio Fraga, Alain Greiner
6 *
7 * SOCLIB_LGPL_HEADER_BEGIN
8 *
9 * This file is part of SoCLib, GNU LGPLv2.1.
10 *
11 * SoCLib is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published
13 * by the Free Software Foundation; version 2.1 of the License.
14 *
15 * SoCLib is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with SoCLib; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * 02110-1301 USA
24 *
25 * SOCLIB_LGPL_HEADER_END
26 */
27/////////////////////////////////////////////////////////////////////////////////
28// This TSAR component is a bridge to access external peripherals
29// connected to an external I/O bus (such as Hypertransport or PCIe).
30// It connects three VCI networks:
31//
32// - INT network : to receive both configuration requests from processors
33//                 or software driven data access to peripherals.
34// - RAM network : to send DMA transactions initiated by peripherals
35//                 directly to the RAM (or L3 caches).
36// - IOX network : to receive DMA transactions from peripherals, or to send
37//                 configuration or data transactions to peripherals.
38//
39// Regarding DMA transactions initiated by external peripherals, it provides
40// an - optional - IOMMU service : the 32 bits virtual address is translated
41// to a (up to) 40 bits physical address by a standard SoCLib generic TLB.
42// In case of TLB MISS, the DMA transaction is stalled until the TLB is updated.
43// In case of page fault (illegal access), a VCI error is returned to the
44// faulty peripheral.
45/////////////////////////////////////////////////////////////////////////////////
46//   General Constraints:
47//
48// - All VCI fields have the same widths on the RAM and IOX networks,
49//   and the VCI DATA field is 64 bits.
50// - Only the VCI DATA field differ between INT and IOX/RAM networks,
51//   as the VCI DATA field is 32 bits.
52// - The common VCI ADDRESS width cannot be larger than 64 bits.
53// - All VCI transactions must be included in a single cache line.
54// - Page Tables must have the format required by the SoCLib generic_tlb.
55// - IO's segments must be the same in INT and IOX networks
56// - Write operations on IOMMU configuration registers (PTPR, ACTIVE) are
57//   delayed until DMA_TLB FSM is IDLE. It should, preferably, be done before
58//   starting any transfers. Pseudo register INVAL may be modified any time.
59////////////////////////////////////////////////////////////////////////////////
60
61 
62///////TODO List///////////////////////////////////////////////////////////////
63// - Ne pas garder tous les champs WRITE CMD dans les FIFO a chaque flit
64//   (seulement 'data' et 'be')
65// - Traiter complêtement les codes d'erreur en réponse à une transaction
66//   WTI write
67///////////////////////////////////////////////////////////////////////////////
68
69#ifndef SOCLIB_CABA_VCI_IO_BRIDGE_H
70#define SOCLIB_CABA_VCI_IO_BRIDGE_H
71
72#include <inttypes.h>
73#include <systemc>
74#include "caba_base_module.h"
75#include "generic_fifo.h"
76#include "generic_tlb.h"
77#include "mapping_table.h"
78#include "address_decoding_table.h"
79#include "static_assert.h"
80#include "vci_initiator.h"
81#include "vci_target.h"
82#include "../../../include/soclib/io_bridge.h"
83
84namespace soclib {
85namespace caba {
86
87using namespace soclib::common;
88
89///////////////////////////////////////////////////////////////////////////////////
90template<typename vci_param_int,
91         typename vci_param_ext>
92class VciIoBridge
93///////////////////////////////////////////////////////////////////////////////////
94    : public soclib::caba::BaseModule
95{
96    // Data and be fields have different widths on INT and EXT networks
97    typedef typename vci_param_ext::data_t          ext_data_t;
98    typedef typename vci_param_int::data_t          int_data_t;
99    typedef typename vci_param_ext::be_t            ext_be_t;
100    typedef typename vci_param_int::be_t            ext_in_t;
101
102    // Other fields must be equal   
103    typedef typename vci_param_int::fast_addr_t     vci_addr_t; 
104    typedef typename vci_param_int::srcid_t         vci_srcid_t; 
105    typedef typename vci_param_int::trdid_t         vci_trdid_t;
106    typedef typename vci_param_int::pktid_t         vci_pktid_t;
107    typedef typename vci_param_int::plen_t          vci_plen_t;
108    typedef typename vci_param_int::cmd_t           vci_cmd_t;
109    typedef typename vci_param_int::contig_t        vci_contig_t;
110    typedef typename vci_param_int::eop_t           vci_eop_t;
111    typedef typename vci_param_int::const_t         vci_cons_t;
112    typedef typename vci_param_int::wrap_t          vci_wrap_t;
113    typedef typename vci_param_int::clen_t          vci_clen_t;
114    typedef typename vci_param_int::cfixed_t        vci_cfixed_t;
115    typedef typename vci_param_int::rerror_t        vci_rerror_t;
116
117    enum 
118    {
119        CACHE_LINE_MASK    = 0xFFFFFFFFC0LL, 
120        PPN1_MASK          = 0x0007FFFF, 
121        PPN2_MASK          = 0x0FFFFFFF, 
122        K_PAGE_OFFSET_MASK = 0x00000FFF, 
123        M_PAGE_OFFSET_MASK = 0x001FFFFF,
124        PTE2_LINE_OFFSET   = 0x00007000, // bits 12,13,14.
125        PTE1_LINE_OFFSET   = 0x01E00000, // bits 21,22,23,24
126    };
127 
128    // States for DMA_CMD FSM (from IOX to RAM)
129    enum dma_cmd_fsm_state
130    { 
131        DMA_CMD_IDLE,
132        DMA_CMD_FIFO_PUT_CMD,
133        DMA_CMD_FIFO_PUT_RSP,
134        DMA_CMD_MISS_WAIT,
135        DMA_CMD_WAIT_EOP,
136    };
137   
138    // States for DMA_RSP FSM (from RAM to IOX)
139    enum dma_rsp_fsm_state
140    { 
141        DMA_RSP_IDLE,
142        DMA_RSP_FIFO_PUT, 
143    };
144   
145    // States for TLB_MISS FSM
146    enum dma_tlb_fsm_state
147    {   
148        TLB_IDLE,
149        TLB_MISS,
150        TLB_PTE1_GET,
151        TLB_PTE1_SELECT,
152        TLB_PTE1_UPDT,
153        TLB_PTE2_GET,                                                 
154        TLB_PTE2_SELECT,
155        TLB_PTE2_UPDT,
156        TLB_WAIT,
157        TLB_RETURN,
158        TLB_INVAL_CHECK,
159        };
160   
161    // States for CONFIG_CMD FSM (from INT to IOX)
162    enum config_cmd_fsm_state
163    { 
164        CONFIG_CMD_IDLE,
165        CONFIG_CMD_NEXT,
166        CONFIG_CMD_PUT,
167        CONFIG_CMD_RSP,
168        };
169   
170    // states for CONFIG_RSP FSM (from IOX to INT)
171    enum config_rsp_fsm_state
172    { 
173        CONFIG_RSP_IDLE,
174        CONFIG_RSP_PUT_LO,
175        CONFIG_RSP_PUT_HI,
176        CONFIG_RSP_PUT_UNC,
177    };
178   
179    // States for MISS_WTI_CMD FSM (to INT network)
180    enum miss_wti_cmd_state
181    { 
182        MISS_WTI_CMD_IDLE,
183        MISS_WTI_CMD_WTI,
184        MISS_WTI_CMD_MISS,
185        };
186   
187    // States for MISS_WTI_RSP FSM (from INT network)
188    enum miss_wti_rsp_state
189    { 
190        MISS_WTI_RSP_IDLE,
191        MISS_WTI_RSP_WTI,
192        MISS_WTI_RSP_MISS,
193        };
194
195    // PKTID values for TLB MISS and WTI transactions
196    enum pktid_values_e
197    {
198        PKTID_READ  = 0x0,  // TSAR code for read data uncached
199        PKTID_WRITE = 0x4,  // TSAR code for write
200    };
201   
202    // Miss types for iotlb
203    enum tlb_miss_type_e
204    {
205        PTE1_MISS, 
206        PTE2_MISS,
207        };
208   
209public:
210    sc_in<bool>                               p_clk;
211    sc_in<bool>                               p_resetn;
212    sc_in<bool>*                              p_irq[32];     // not always constructed
213   
214    soclib::caba::VciInitiator<vci_param_ext> p_vci_ini_ram; 
215
216    soclib::caba::VciTarget<vci_param_ext>    p_vci_tgt_iox;
217    soclib::caba::VciInitiator<vci_param_ext> p_vci_ini_iox;
218
219    soclib::caba::VciTarget<vci_param_int>    p_vci_tgt_int;
220    soclib::caba::VciInitiator<vci_param_int> p_vci_ini_int;
221
222private:
223    const size_t                                  m_words;
224    const bool                                m_has_irqs;
225
226    // INT & IOX Networks
227    std::list<soclib::common::Segment>        m_int_seglist;
228    const vci_srcid_t                             m_int_srcid;  // local SRCID on INT network
229    std::list<soclib::common::Segment>        m_iox_seglist;
230
231    // TLB parameters
232    const size_t                                                  m_iotlb_ways;
233    const size_t                                                  m_iotlb_sets;
234
235    // debug variables
236    uint32_t                                  m_debug_start_cycle;
237    bool                                      m_debug_ok;
238    bool                                      m_debug_activated;
239
240    ///////////////////////////////
241    // MEMORY MAPPED REGISTERS
242    ///////////////////////////////
243    sc_signal<uint32_t>         r_iommu_ptpr;           // page table pointer register
244    sc_signal<bool>             r_iommu_active;         // iotlb mode
245    sc_signal<uint32_t>         r_iommu_bvar;           // iommu bad virtual address
246    sc_signal<uint32_t>         r_iommu_etr;            // iommu error type
247    sc_signal<uint32_t>         r_iommu_bad_id;         // SRCID of faulty peripheral
248    sc_signal<uint32_t>         r_iommu_wti_enable;     // enable WTI transactions 
249    sc_signal<vci_addr_t>       r_iommu_wti_paddr;      // address of IOMMU WTI
250    sc_signal<vci_addr_t>*      r_iommu_peri_wti;       // array[32] WTI for peripherals
251 
252        ///////////////////////////////////
253    // DMA_CMD FSM REGISTERS
254    ///////////////////////////////////
255    sc_signal<int>              r_dma_cmd_fsm;         
256    sc_signal<uint32_t>         r_dma_cmd_vaddr;        // input virtual address
257    sc_signal<vci_addr_t>       r_dma_cmd_paddr;        // output physical address
258
259    ///////////////////////////////////
260    // DMA_RSP FSM REGISTERS
261    ///////////////////////////////////
262    sc_signal<int>              r_dma_rsp_fsm;
263   
264    ///////////////////////////////////
265    // CONFIG_CMD FSM REGISTERS
266    ///////////////////////////////////
267    sc_signal<int>              r_config_cmd_fsm;
268    sc_signal<uint32_t>         r_config_cmd_rdata;
269    sc_signal<bool>             r_config_cmd_error;
270    sc_signal<uint32_t>         r_config_cmd_inval_vaddr;
271
272    sc_signal<ext_data_t>       r_config_cmd_wdata;
273    sc_signal<ext_be_t>         r_config_cmd_be;
274    sc_signal<vci_plen_t>       r_config_cmd_cmd;
275    sc_signal<vci_addr_t>       r_config_cmd_address;
276    sc_signal<vci_srcid_t>      r_config_cmd_srcid;
277    sc_signal<vci_pktid_t>      r_config_cmd_pktid;
278    sc_signal<vci_trdid_t>      r_config_cmd_trdid;
279    sc_signal<vci_plen_t>       r_config_cmd_plen;
280    sc_signal<vci_clen_t>       r_config_cmd_clen;
281    sc_signal<vci_cons_t>       r_config_cmd_cons;
282    sc_signal<vci_contig_t>     r_config_cmd_contig;
283    sc_signal<vci_cfixed_t>     r_config_cmd_cfixed;
284    sc_signal<vci_wrap_t>       r_config_cmd_wrap;
285    sc_signal<vci_eop_t>        r_config_cmd_eop;
286
287    ///////////////////////////////////
288    // CONFIG_RSP FSM REGISTERS
289    ///////////////////////////////////
290    sc_signal<int>              r_config_rsp_fsm;
291
292    ///////////////////////////////////
293    // TLB FSM REGISTERS
294    ///////////////////////////////////
295    sc_signal<int>              r_tlb_fsm;                      // state register
296    sc_signal<bool>             r_waiting_transaction;  // Flag for returning from
297    sc_signal<int>              r_tlb_miss_type;
298        sc_signal<bool>             r_tlb_miss_error; 
299
300    sc_signal<vci_addr_t>       r_tlb_paddr;                // physical address of pte
301    sc_signal<uint32_t>         r_tlb_pte_flags;            // pte1 or first word of pte2
302    sc_signal<uint32_t>         r_tlb_pte_ppn;          // second word of pte2
303    sc_signal<size_t>           r_tlb_way;                      // selected way in tlb   
304    sc_signal<size_t>           r_tlb_set;                      // selected set in tlb   
305
306    uint32_t*                   r_tlb_buf_data;         // prefetch buffer for PTEs
307    sc_signal<bool>             r_tlb_buf_valid;        // one valit flag for all PTEs
308    sc_signal<vci_addr_t>       r_tlb_buf_tag;          // cache line number 
309    sc_signal<vci_addr_t>       r_tlb_buf_vaddr;        // virtual address first PTE 
310    sc_signal<bool>             r_tlb_buf_big_page;     // ???
311
312    ///////////////////////////////////
313    // MISS_WTI_CMD FSM REGISTERS
314    ///////////////////////////////////
315    sc_signal<int>              r_miss_wti_cmd_fsm;
316    sc_signal<size_t>           r_miss_wti_cmd_index;
317
318    ///////////////////////////////////
319    // MISS_WTI_RSP FSM REGISTERS
320    ///////////////////////////////////
321    sc_signal<int>              r_miss_wti_rsp_fsm;
322    sc_signal<bool>             r_miss_wti_rsp_error; 
323    sc_signal<size_t>           r_miss_wti_rsp_count; 
324   
325    /////////////////////////////////////////////////////
326    //  ALLOCATORS for CONFIG_RSP fifo & DMA_RSP fifo
327    /////////////////////////////////////////////////////
328    sc_signal<bool>             r_alloc_fifo_config_rsp_local; 
329    sc_signal<bool>             r_alloc_fifo_dma_rsp_local; 
330
331    //////////////////////////////////
332    // IRQ FSM registers
333    //////////////////////////////////
334        sc_signal<bool>*            r_irq_pending;  // array[32]
335        sc_signal<bool>*            r_irq_request;  // array[32]
336   
337    //////////////////////////////////////////////////////////////////
338    // IOTLB 
339    //////////////////////////////////////////////////////////////////
340    GenericTlb<vci_addr_t>      r_iotlb;
341       
342    //////////////////////////////////////////////////////////////////
343    // Inter-FSM communications
344    //////////////////////////////////////////////////////////////////
345   
346    // between DMA_CMD and TLB FSM
347    sc_signal<bool>             r_dma_tlb_req;
348
349    // between CONFIG_CMD FSM and TLB FSM
350    sc_signal<bool>             r_config_tlb_req;
351   
352    // between TLB FSM and MISS_WTI FSM
353    sc_signal<bool>             r_tlb_miss_req;
354   
355    /////////////////////////
356    // FIFOs
357    /////////////////////////
358
359    // ouput FIFO to VCI INI port on RAM network (VCI command)
360    GenericFifo<vci_addr_t>     m_dma_cmd_addr_fifo;
361    GenericFifo<vci_srcid_t>    m_dma_cmd_srcid_fifo;
362    GenericFifo<vci_trdid_t>    m_dma_cmd_trdid_fifo;
363    GenericFifo<vci_pktid_t>    m_dma_cmd_pktid_fifo;
364    GenericFifo<ext_be_t>       m_dma_cmd_be_fifo;
365    GenericFifo<vci_cmd_t>      m_dma_cmd_cmd_fifo;
366    GenericFifo<vci_contig_t>   m_dma_cmd_contig_fifo;
367    GenericFifo<ext_data_t>     m_dma_cmd_data_fifo;
368    GenericFifo<vci_eop_t>      m_dma_cmd_eop_fifo;
369    GenericFifo<vci_cons_t>     m_dma_cmd_cons_fifo;
370    GenericFifo<vci_plen_t>     m_dma_cmd_plen_fifo;
371    GenericFifo<vci_wrap_t>     m_dma_cmd_wrap_fifo;
372    GenericFifo<vci_cfixed_t>   m_dma_cmd_cfixed_fifo;
373    GenericFifo<vci_clen_t>     m_dma_cmd_clen_fifo;
374
375    // output FIFO to VCI TGT port on IOX network (VCI response)
376    GenericFifo<ext_data_t>     m_dma_rsp_data_fifo;
377    GenericFifo<vci_srcid_t>    m_dma_rsp_rsrcid_fifo;
378    GenericFifo<vci_trdid_t>    m_dma_rsp_rtrdid_fifo;
379    GenericFifo<vci_pktid_t>    m_dma_rsp_rpktid_fifo;
380    GenericFifo<vci_eop_t>      m_dma_rsp_reop_fifo;
381    GenericFifo<vci_rerror_t>   m_dma_rsp_rerror_fifo;
382       
383    // output FIFO to VCI INI port on IOX network (VCI command)
384    GenericFifo<vci_addr_t>     m_config_cmd_addr_fifo;
385    GenericFifo<vci_srcid_t>    m_config_cmd_srcid_fifo;
386    GenericFifo<vci_trdid_t>    m_config_cmd_trdid_fifo;
387    GenericFifo<vci_pktid_t>    m_config_cmd_pktid_fifo;
388    GenericFifo<ext_be_t>       m_config_cmd_be_fifo;
389    GenericFifo<vci_cmd_t>      m_config_cmd_cmd_fifo;
390    GenericFifo<vci_contig_t>   m_config_cmd_contig_fifo;
391    GenericFifo<ext_data_t>     m_config_cmd_data_fifo;
392    GenericFifo<vci_eop_t>      m_config_cmd_eop_fifo;
393    GenericFifo<vci_cons_t>     m_config_cmd_cons_fifo;
394    GenericFifo<vci_plen_t>     m_config_cmd_plen_fifo;
395    GenericFifo<vci_wrap_t>     m_config_cmd_wrap_fifo;
396    GenericFifo<vci_cfixed_t>   m_config_cmd_cfixed_fifo;
397    GenericFifo<vci_clen_t>     m_config_cmd_clen_fifo;
398   
399    // output FIFO to VCI TGT port on INT network (VCI response) 
400    GenericFifo<int_data_t>     m_config_rsp_data_fifo;
401    GenericFifo<vci_srcid_t>    m_config_rsp_rsrcid_fifo;
402    GenericFifo<vci_trdid_t>    m_config_rsp_rtrdid_fifo;
403    GenericFifo<vci_pktid_t>    m_config_rsp_rpktid_fifo;
404    GenericFifo<vci_eop_t>      m_config_rsp_reop_fifo;
405    GenericFifo<vci_rerror_t>   m_config_rsp_rerror_fifo;
406       
407   
408    ////////////////////////////////
409    // Activity counters
410    ////////////////////////////////
411   
412    uint32_t m_cpt_total_cycles;            // total number of cycles
413   
414    // TLB activity counters
415    uint32_t m_cpt_iotlb_read;              // number of iotlb read
416    uint32_t m_cpt_iotlb_miss;              // number of iotlb miss
417    uint32_t m_cost_iotlb_miss;             // number of wait cycles (not treatment itself)
418    uint32_t m_cpt_iotlbmiss_transaction;   // number of tlb miss transactions
419    uint32_t m_cost_iotlbmiss_transaction;  // cumulated duration tlb miss transactions
420
421    //Transaction Tabs (TRTs) activity counters
422    uint32_t m_cpt_trt_dma_full;            // DMA TRT full when a new command arrives
423    uint32_t m_cpt_trt_dma_full_cost;       // total number of cycles blocked
424    uint32_t m_cpt_trt_config_full;         // Config TRT full when a new command arrives
425    uint32_t m_cpt_trt_config_full_cost;    // total number of cycles blocked
426
427    // FSM activity counters
428    // unused on print_stats
429    uint32_t m_cpt_fsm_dma_cmd          [32]; 
430    uint32_t m_cpt_fsm_dma_rsp          [32]; 
431    uint32_t m_cpt_fsm_tlb              [32]; 
432    uint32_t m_cpt_fsm_config_cmd       [32]; 
433    uint32_t m_cpt_fsm_config_rsp       [32]; 
434    uint32_t m_cpt_fsm_miss_wti_cmd     [32]; 
435    uint32_t m_cpt_fsm_miss_wti_rsp     [32];
436 
437protected:
438    SC_HAS_PROCESS(VciIoBridge);
439
440public:
441    VciIoBridge(
442        sc_module_name insname,
443        const    soclib::common::MappingTable  &mt_ext,      // external network
444        const    soclib::common::MappingTable  &mt_int,      // internal network
445        const    soclib::common::MappingTable  &mt_iox,      // iox network
446        const    soclib::common::IntTab        &int_tgtid,   // INT network TGTID
447        const    soclib::common::IntTab        &int_srcid,   // INT network SRCID
448        const    soclib::common::IntTab        &iox_tgtid,   // IOX network TGTID
449        const    bool                          has_irqs,     // component has irq ports
450        const    size_t                        dcache_words,
451        const    size_t                        iotlb_ways,
452        const    size_t                        iotlb_sets,
453        const    uint32_t                      debug_start_cycle,
454        const    bool                          debug_ok );
455
456    ~VciIoBridge();
457
458    void print_stats();
459    void clear_stats();
460    void print_trace(size_t mode = 0);
461   
462
463private:
464    void transition();
465    void genMoore();
466};
467
468}}
469
470#endif /* SOCLIB_CABA_VCI_CC_VCACHE_WRAPPER_V4_H */
471
472// Local Variables:
473// tab-width: 4
474// c-basic-offset: 4
475// c-file-offsets:((innamespace . 0)(inline-open . 0))
476// indent-tabs-mode: nil
477// End:
478
479// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
480
481
482
483
Note: See TracBrowser for help on using the repository browser.