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

Last change on this file since 434 was 434, checked in by alain, 11 years ago

Introducing a preliminary configuration interface in vci_mem_cache.

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