source: trunk/modules/vci_io_bridge/caba/source/src/vci_io_bridge.cpp @ 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: 78.8 KB
Line 
1/* -*- c++ -*-
2 * File : vci_io_bridge.cpp
3 * Copyright (c) UPMC, Lip6, SoC
4 * Authors: Cassio Fraga, Alain Greiner
5 *
6 * SOCLIB_LGPL_HEADER_BEGIN
7 *
8 * This file is part of SoCLib, GNU LGPLv2.1.
9 *
10 * SoCLib is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published
12 * by the Free Software Foundation; version 2.1 of the License.
13 *
14 * SoCLib is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with SoCLib; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 * SOCLIB_LGPL_HEADER_END
25 */
26
27#include <cassert>
28#include "arithmetics.h"
29#include "alloc_elems.h"
30#include "../include/vci_io_bridge.h"
31
32
33//////   debug services   ///////////////////////////////////////////////////////
34// All debug messages are conditionned by two variables:
35// - compile time : DEBUG_*** : defined below
36// - execution time : m_debug_***  : defined by constructor arguments
37//    m_debug_activated = (m_debug_ok) and (m_cpt_cycle > m_debug_start_cycle)
38/////////////////////////////////////////////////////////////////////////////////
39
40#define DEBUG_DMA_CMD           1
41#define DEBUG_DMA_RSP           1
42#define DEBUG_TLB_MISS          1
43#define DEBUG_CONFIG_CMD                1
44#define DEBUG_CONFIG_RSP                1
45#define DEBUG_MISS_WTI                  1
46
47namespace soclib { 
48namespace caba {
49
50namespace {
51
52const char *dma_cmd_fsm_state_str[] = 
53    {
54        "DMA_CMD_IDLE",
55        "DMA_CMD_FIFO_PUT_CMD",
56        "DMA_CMD_FIFO_PUT_RSP",
57        "DMA_CMD_MISS_WAIT",
58        "DMA_CMD_WAIT_EOP",
59    };
60
61const char *dma_rsp_fsm_state_str[] = 
62    {
63        "DMA_RSP_IDLE",
64        "DMA_RSP_FIFO_PUT",
65    };
66
67const char *tlb_fsm_state_str[] = 
68    {
69        "TLB_IDLE",
70        "TLB_MISS",
71        "TLB_PTE1_GET",
72        "TLB_PTE1_SELECT",
73        "TLB_PTE1_UPDT",
74        "TLB_PTE2_GET",                                                 
75        "TLB_PTE2_SELECT",
76        "TLB_PTE2_UPDT",
77        "TLB_WAIT",
78        "TLB_RETURN",
79        "TLB_INVAL_CHECK",
80    };
81
82const char *config_cmd_fsm_state_str[] = 
83    {
84        "CONFIG_CMD_IDLE",
85        "CONFIG_CMD_FIFO_PUT_CMD",
86        "CONFIG_CMD_FIFO_PUT_RSP",
87    };
88
89const char *config_rsp_fsm_state_str[] = 
90    {
91        "CONFIG_RSP_IDLE",
92        "CONFIG_RSP_FIFO_PUT", 
93    };
94
95const char *miss_wti_fsm_state_str[] = { 
96        "MISS_WTI_IDLE_MISS",
97        "MISS_WTI_IDLE_WTI",
98        "MISS_WTI_CMD_WTI",
99        "MISS_WTI_RSP_WTI",
100        "MISS_WTI_CMD_MISS",
101        "MISS_WTI_RSP_MISS",
102    };
103}
104
105#define tmpl(...)  template<typename vci_param_int,typename vci_param_ext> __VA_ARGS__ VciIoBridge<vci_param_int,vci_param_ext>
106
107////////////////////////
108tmpl(/**/)::VciIoBridge(
109    sc_module_name                                  name,
110    const soclib::common::MappingTable  &mt_ext,
111    const soclib::common::MappingTable  &mt_int,
112    const soclib::common::MappingTable  &mt_iox,
113    const soclib::common::IntTab            &int_tgtid,     // INT network TGTID
114    const soclib::common::IntTab            &int_srcid,     // INT network SRCID
115    const soclib::common::IntTab            &iox_tgtid,     // IOX network TGTID
116    const bool                          has_irqs,
117    const size_t                        dcache_words,
118    const size_t                                        iotlb_ways,
119    const size_t                                        iotlb_sets,
120    const uint32_t                                      debug_start_cycle,
121    const bool                                      debug_ok)
122    : soclib::caba::BaseModule(name),
123
124      p_clk("p_clk"),
125      p_resetn("p_resetn"),
126      p_vci_ini_ram("p_vci_ini_ram"),
127      p_vci_tgt_iox("p_vci_tgt_iox"),
128      p_vci_ini_iox("p_vci_ini_iox"),
129      p_vci_tgt_int("p_vci_tgt_int"),
130      p_vci_ini_int("p_vci_ini_int"),
131
132      m_words( dcache_words ),
133      m_has_irqs( has_irqs ),
134
135      // INT & IOX Network
136      m_int_seglist( mt_int.getSegmentList( int_tgtid )),
137      m_int_srcid( mt_int.indexForId( int_srcid )), 
138      m_iox_seglist( mt_iox.getSegmentList( iox_tgtid )),
139
140      m_iotlb_ways(iotlb_ways),
141      m_iotlb_sets(iotlb_sets),
142
143      m_debug_start_cycle(debug_start_cycle),
144      m_debug_ok(debug_ok),
145
146      // addressable registers
147      r_iommu_ptpr("r_iommu_ptpr"),
148      r_iommu_active("r_iommu_active"),
149      r_iommu_bvar("r_iommu_bvar"),
150      r_iommu_etr("r_iommu_etr"),
151      r_iommu_bad_id("r_iommu_bad_id"),
152      r_iommu_wti_paddr("r_iommu_wti_paddr"),
153      r_iommu_peri_wti(alloc_elems<sc_signal<vci_addr_t> >("r_peri_wti_paddr", 32)),
154
155      // DMA_CMD FSM registers
156      r_dma_cmd_fsm("r_dma_cmd_fsm"),
157      r_dma_cmd_vaddr("r_dma_cmd_vaddr"),
158      r_dma_cmd_paddr("r_dma_cmd_paddr"),
159
160      //DMA_RSP FSM registers
161      r_dma_rsp_fsm("r_dma_rsp_fsm"),
162
163      // CONFIG_CMD FSM registers
164      r_config_cmd_fsm("r_config_cmd_fsm"),
165      r_config_cmd_rdata("r_config_cmd_rdata"),
166      r_config_cmd_error("r_config_cmd_error"),
167      r_config_cmd_inval_vaddr("r_config_cmd_inval_vaddr"),
168
169      // CONFIG_RSP FSM registers 
170      r_config_rsp_fsm("r_config_rsp_fsm"),
171
172      // TLB FSM registers
173      r_tlb_fsm("r_tlb_fsm"),
174      r_waiting_transaction("r_waiting_transaction"),
175      r_tlb_miss_type("r_tlb_miss_type"),
176      r_tlb_miss_error("r_tlb_miss_error"),
177      r_tlb_paddr("r_tlb_paddr"),               
178      r_tlb_pte_flags("r_tlb_pte_flags"),
179      r_tlb_pte_ppn("r_tlb_pte_ppn"),
180      r_tlb_way("r_tlb_way"),
181      r_tlb_set("r_tlb_set"),   
182      r_tlb_buf_valid("r_tlb_buf_valid"),
183      r_tlb_buf_tag("r_tlb_buf_tag"),
184      r_tlb_buf_vaddr("r_tlb_buf_vaddr"),
185      r_tlb_buf_big_page("r_tlb_buf_big_page"),
186
187      // MISS_WTI_CMD FSM registers
188      r_miss_wti_cmd_fsm("r_miss_wti_cmd_fsm"), 
189      r_miss_wti_cmd_index("r_miss_wti_cmd_index"),
190
191      // MISS_WTI_CMD FSM registers
192      r_miss_wti_rsp_fsm("r_miss_wti_rsp_fsm"), 
193      r_miss_wti_rsp_error("r_miss_wti_rsp_error"),
194
195      // allocator for CONFIG_RSP & DMA_RSP fifos
196      r_alloc_fifo_config_rsp_local("r_alloc_fifo_config_rsp_local"), 
197      r_alloc_fifo_dma_rsp_local("r_alloc_fifo_dma_rsp_local"), 
198
199      // IRQs registers
200      r_irq_pending(alloc_elems<sc_signal<bool> >("r_irq_pending", 32)),
201      r_irq_request(alloc_elems<sc_signal<bool> >("r_irq_request", 32)),
202     
203      // TLB for IOMMU
204      r_iotlb("iotlb", 0, iotlb_ways, iotlb_sets, vci_param_int::N),
205     
206      // Inter-FSM communications
207      r_dma_tlb_req("r_dma_tlb_req"),
208      r_config_tlb_req("r_config_tlb_req"),
209      r_tlb_miss_req("r_tlb_miss_req"),
210     
211      // DMA_CMD FIFOs
212      m_dma_cmd_addr_fifo("m_dma_cmd_addr_fifo",2),
213      m_dma_cmd_srcid_fifo("m_dma_cmd_srcid_fifo",2), 
214      m_dma_cmd_trdid_fifo("m_dma_cmd_trdid_fifo",2), 
215      m_dma_cmd_pktid_fifo("m_dma_cmd_pktid_fifo",2), 
216      m_dma_cmd_be_fifo("m_dma_cmd_be_fifo",2), 
217      m_dma_cmd_cmd_fifo("m_dma_cmd_cmd_fifo",2), 
218      m_dma_cmd_contig_fifo("m_dma_cmd_contig_fifo",2), 
219      m_dma_cmd_data_fifo("m_dma_cmd_data_fifo",2), 
220      m_dma_cmd_eop_fifo("m_dma_cmd_eop_fifo",2),
221      m_dma_cmd_cons_fifo("m_dma_cmd_cons_fifo",2), 
222      m_dma_cmd_plen_fifo("m_dma_cmd_plen_fifo",2), 
223      m_dma_cmd_wrap_fifo("m_dma_cmd_wrap_fifo",2), 
224      m_dma_cmd_cfixed_fifo("m_dma_cmd_cfixed_fifo",2),
225      m_dma_cmd_clen_fifo("m_dma_cmd_clen_fifo",2), 
226
227      // DMA_RSP FIFOs
228      m_dma_rsp_data_fifo("m_dma_rsp_data_fifo",2),
229      m_dma_rsp_rsrcid_fifo("m_dma_rsp_rsrcid_fifo",2),
230      m_dma_rsp_rtrdid_fifo("m_dma_rsp_rtrdid_fifo",2),
231      m_dma_rsp_rpktid_fifo("m_dma_rsp_rpktid_fifo",2),
232      m_dma_rsp_reop_fifo("m_dma_rsp_reop_fifo",2),
233      m_dma_rsp_rerror_fifo("m_dma_rsp_rerror_fifo",2),
234 
235      // CONFIG_CMD FIFOs
236      m_config_cmd_addr_fifo("m_config_cmd_addr_fifo",2),
237      m_config_cmd_srcid_fifo("m_config_cmd_srcid_fifo",2),
238      m_config_cmd_trdid_fifo("m_config_cmd_trdid_fifo",2),
239      m_config_cmd_pktid_fifo("m_config_cmd_pktid_fifo",2),
240      m_config_cmd_be_fifo("m_config_cmd_be_fifo",2),
241      m_config_cmd_cmd_fifo("m_config_cmd_cmd_fifo",2),
242      m_config_cmd_contig_fifo("m_config_cmd_contig_fifo",2),
243      m_config_cmd_data_fifo("m_config_cmd_data_fifo",2),
244      m_config_cmd_eop_fifo("m_config_cmd_eop_fifo",2),
245      m_config_cmd_cons_fifo("m_config_cmd_cons_fifo",2),
246      m_config_cmd_plen_fifo("m_config_cmd_plen_fifo",2),
247      m_config_cmd_wrap_fifo("m_config_cmd_wrap_fifo",2),
248      m_config_cmd_cfixed_fifo("m_config_cmd_cfixed_fifo",2),
249      m_config_cmd_clen_fifo("m_config_cmd_clen_fifo",2),
250
251      // CONFIG_RSP FIFOs
252      m_config_rsp_data_fifo("m_config_rsp_data_fifo",2),     
253      m_config_rsp_rsrcid_fifo("m_config_rsp_rsrcid_fifo",2),
254      m_config_rsp_rtrdid_fifo("m_config_rsp_rtrdid_fifo",2),
255      m_config_rsp_rpktid_fifo("m_config_rsp_rpktid_fifo",2),
256      m_config_rsp_reop_fifo("m_config_rsp_reop_fifo",2),
257      m_config_rsp_rerror_fifo("m_config_rsp_rerror_fifo",2)
258{
259    std::cout << "  - Building VciIoBridge : " << name << std::endl;
260
261    // checking segments on INT network
262    assert ( ( not m_int_seglist.empty() ) and
263    "VCI_IO_BRIDGE ERROR : no segment allocated on INT network");
264
265    std::list<soclib::common::Segment>::iterator int_seg;
266    for ( int_seg = m_int_seglist.begin() ; int_seg != m_int_seglist.end() ; int_seg++ )
267    {
268        std::cout << "    => segment " << int_seg->name()
269                  << " / base = " << std::hex << int_seg->baseAddress()
270                  << " / size = " << int_seg->size() << std::endl; 
271    }
272
273    // checking segments on IOX network
274    assert ( ( not m_iox_seglist.empty() ) and
275    "VCI_IO_BRIDGE ERROR : no segment allocated on IOX network");
276
277    std::list<soclib::common::Segment>::iterator iox_seg;
278    for ( iox_seg = m_iox_seglist.begin() ; iox_seg != m_iox_seglist.end() ; iox_seg++ )
279    {
280        std::cout << "    => segment " << iox_seg->name()
281                  << " / base = " << std::hex << iox_seg->baseAddress()
282                  << " / size = " << iox_seg->size() << std::endl; 
283    }
284
285    assert( (vci_param_int::N == vci_param_ext::N) and
286    "VCI_IO_BRIDGE ERROR: VCI ADDRESS widths must be equal on the 3 networks");
287
288    assert( (vci_param_int::N <=  64) and
289    "VCI_IO_BRIDGE ERROR: VCI ADDRESS width cannot be bigger than 64 bits");
290
291    assert( ((vci_param_int::B == 4) or (vci_param_int::B == 8)) and
292    "VCI_IO_BRIDGE ERROR: VCI DATA width must be 32 or 64 bits on internal network");   
293
294    assert( ((vci_param_ext::B == 4) or (vci_param_ext::B == 8)) and
295    "VCI_IO_BRIDGE ERROR: VCI DATA width must be 32 or 64 bits on external network");   
296
297    assert( (vci_param_int::S == vci_param_ext::S) and
298            "VCI_IO_BRIDGE ERROR: SRCID widths must be equal on the 3 networks");
299
300    // contruct 32 IRQ ports if required
301    if ( has_irqs )
302    {
303        for ( size_t n=0 ; n<32 ; n++ ) p_irq[n] = new sc_core::sc_in<bool>;
304    }
305   
306    // Cache line buffer
307    r_tlb_buf_data = new uint32_t[dcache_words];
308
309    SC_METHOD(transition);
310    dont_initialize();
311    sensitive << p_clk.pos();
312 
313    SC_METHOD(genMoore);
314    dont_initialize();
315    sensitive << p_clk.neg();
316
317 }
318
319/////////////////////////////////////
320tmpl(/**/)::~VciIoBridge()
321/////////////////////////////////////
322{
323    delete [] r_iommu_peri_wti;
324    delete [] r_tlb_buf_data;
325    soclib::common::dealloc_elems(p_irq, 32);
326    soclib::common::dealloc_elems(r_irq_request, 32);
327    soclib::common::dealloc_elems(r_irq_pending, 32);
328}
329
330////////////////////////////////////
331tmpl(void)::print_trace(size_t mode)
332////////////////////////////////////
333{
334    // b0 : IOtlb trace
335
336    std::cout << std::dec << "IO_BRIDGE " << name() << std::endl;
337
338    std::cout << "  "  << dma_cmd_fsm_state_str[r_dma_cmd_fsm.read()]
339              << " | " << dma_rsp_fsm_state_str[r_dma_rsp_fsm.read()]
340              << " | " << tlb_fsm_state_str[r_tlb_fsm.read()]
341              << " | " << config_cmd_fsm_state_str[r_config_cmd_fsm.read()]
342              << " | " << config_rsp_fsm_state_str[r_config_rsp_fsm.read()]
343              << " | " << miss_wti_fsm_state_str[r_miss_wti_cmd_fsm.read()]
344              << std::endl;
345
346    if(mode & 0x01)
347    {
348        std::cout << "  IOTLB" << std::endl;
349        r_iotlb.printTrace();
350    }
351    if(mode & 0x02)
352    {
353       
354    }
355}
356
357////////////////////////
358tmpl(void)::print_stats()
359////////////////////////
360{
361    std::cout << name() << std::endl
362        << "- IOTLB MISS RATE      = " << (float)m_cpt_iotlb_miss/m_cpt_iotlb_read << std::endl
363        << "- IOTLB MISS COST         = " << (float)m_cost_iotlb_miss/m_cpt_iotlb_miss << std::endl
364        << "- IOTLB MISS TRANSACTION COST  = " << (float)m_cost_iotlbmiss_transaction/m_cpt_iotlbmiss_transaction << std::endl
365        << "- IOTLB MISS TRANSACTION RATE (OVER ALL MISSES)  = " << (float)m_cpt_iotlbmiss_transaction/m_cpt_iotlb_miss << std::endl;
366}
367
368////////////////////////
369tmpl(void)::clear_stats()
370////////////////////////
371{
372    m_cpt_iotlb_read                = 0;             
373    m_cpt_iotlb_miss                = 0;             
374    m_cost_iotlb_miss               = 0;
375    m_cpt_iotlbmiss_transaction     = 0;   
376    m_cost_iotlbmiss_transaction    = 0;   
377}
378
379/////////////////////////
380tmpl(void)::transition()
381/////////////////////////
382{
383    if ( not p_resetn.read() ) 
384    {
385        r_dma_cmd_fsm      = DMA_CMD_IDLE;
386        r_dma_rsp_fsm      = DMA_RSP_IDLE;
387        r_tlb_fsm              = TLB_IDLE;
388        r_config_cmd_fsm   = CONFIG_CMD_IDLE;
389        r_config_rsp_fsm   = CONFIG_RSP_IDLE;
390        r_miss_wti_cmd_fsm = MISS_WTI_CMD_IDLE;
391        r_miss_wti_rsp_fsm = MISS_WTI_RSP_IDLE;
392
393        r_alloc_fifo_config_rsp_local = true;
394        r_alloc_fifo_dma_rsp_local    = true;
395
396        r_tlb_buf_valid    = false; 
397                r_iommu_active     = false;
398                r_iommu_wti_enable = false;
399       
400        // initializing FIFOs
401        m_dma_cmd_addr_fifo.init();
402        m_dma_cmd_srcid_fifo.init();
403        m_dma_cmd_trdid_fifo.init();
404        m_dma_cmd_pktid_fifo.init();
405        m_dma_cmd_be_fifo.init();
406        m_dma_cmd_cmd_fifo.init();
407        m_dma_cmd_contig_fifo.init();
408        m_dma_cmd_data_fifo.init();
409        m_dma_cmd_eop_fifo.init();
410        m_dma_cmd_cons_fifo.init();
411        m_dma_cmd_plen_fifo.init();
412        m_dma_cmd_wrap_fifo.init();
413        m_dma_cmd_cfixed_fifo.init();
414        m_dma_cmd_clen_fifo.init();
415       
416        m_dma_rsp_rsrcid_fifo.init();
417        m_dma_rsp_rtrdid_fifo.init();
418        m_dma_rsp_rpktid_fifo.init();
419        m_dma_rsp_data_fifo.init();
420        m_dma_rsp_rerror_fifo.init();
421        m_dma_rsp_reop_fifo.init();
422       
423        m_config_cmd_addr_fifo.init();
424        m_config_cmd_srcid_fifo.init();
425        m_config_cmd_trdid_fifo.init();
426        m_config_cmd_pktid_fifo.init();
427        m_config_cmd_be_fifo.init();
428        m_config_cmd_cmd_fifo.init();
429        m_config_cmd_contig_fifo.init();
430        m_config_cmd_data_fifo.init();
431        m_config_cmd_eop_fifo.init();
432        m_config_cmd_cons_fifo.init();
433        m_config_cmd_plen_fifo.init();
434        m_config_cmd_wrap_fifo.init();
435        m_config_cmd_cfixed_fifo.init();
436        m_config_cmd_clen_fifo.init();
437       
438        m_config_rsp_rsrcid_fifo.init();
439        m_config_rsp_rtrdid_fifo.init();
440        m_config_rsp_rpktid_fifo.init();
441        m_config_rsp_data_fifo.init();
442        m_config_rsp_rerror_fifo.init();
443        m_config_rsp_reop_fifo.init();
444       
445        // SET/RESET Communication flip-flops
446        r_dma_tlb_req                   = false;
447        r_config_tlb_req                    = false;
448        r_tlb_miss_req              = false;
449
450        // Debug variable
451                m_debug_activated               = false;
452       
453        for ( size_t n=0 ; n<32 ; n++ )
454        {
455            r_irq_pending[n]        = false;
456            r_irq_request[n]        = false;
457        }
458         
459            // activity counters
460            m_cpt_total_cycles            = 0;
461        m_cpt_iotlb_read              = 0;             
462        m_cpt_iotlb_miss              = 0;             
463        m_cpt_iotlbmiss_transaction   = 0;   
464        m_cost_iotlbmiss_transaction  = 0;   
465       
466        m_cpt_trt_dma_full            = 0;
467        m_cpt_trt_dma_full_cost       = 0;
468        m_cpt_trt_config_full         = 0;
469        m_cpt_trt_config_full_cost    = 0;
470
471        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_dma_cmd            [i]   = 0;
472        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_dma_rsp            [i]   = 0;
473        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_tlb                [i]   = 0;
474        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_config_cmd         [i]   = 0;
475        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_config_rsp         [i]   = 0;
476        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_miss_wti_cmd       [i]   = 0;
477        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_miss_wti_rsp       [i]   = 0;
478
479        return;
480    }
481
482    // default values for FIFOs
483    bool        dma_cmd_fifo_put      = false;
484    bool        dma_cmd_fifo_get      = false;
485
486    bool        dma_rsp_fifo_put      = false; 
487    bool        dma_rsp_fifo_get      = false; 
488   
489    bool        config_cmd_fifo_put   = false;
490    bool        config_cmd_fifo_get   = false;
491
492    bool        config_rsp_fifo_put   = false;
493    bool        config_rsp_fifo_get   = false;
494
495#ifdef INSTRUMENTATION
496    m_cpt_fsm_dma_cmd           [r_dma_cmd_fsm.read()] ++;
497    m_cpt_fsm_dma_rsp           [r_dma_rsp_fsm.read() ] ++;
498    m_cpt_fsm_tlb                   [r_tlb_fsm.read() ] ++;
499    m_cpt_fsm_config_cmd            [r_config_cmd_fsm.read() ] ++;
500    m_cpt_fsm_config_rsp            [r_config_rsp_fsm.read() ] ++;
501    m_cpt_fsm_miss_wti_cmd      [r_miss_wti_cmd_fsm.read() ] ++;
502    m_cpt_fsm_miss_wti_rsp      [r_miss_wti_rsp_fsm.read() ] ++;
503#endif
504
505    m_cpt_total_cycles++;
506
507    m_debug_activated  = (m_cpt_total_cycles > m_debug_start_cycle) and m_debug_ok;
508
509    //////////////////////////////////////////////////////////////////////////////
510    // The DMA_CMD_FSM handles DMA transactions requested by peripherals
511    // It makes the address translation if IOMMU is activated.
512    ///////////////////////////////////////////////////////////////////////////////
513
514    switch( r_dma_cmd_fsm.read() ) 
515    {
516    //////////////////
517    case DMA_CMD_IDLE:  // waiting DMA VCI transaction
518    {
519        if ( p_vci_tgt_iox.cmdval.read() ) // compute physical address
520        { 
521            if ( not r_iommu_active.read() )    // tlb not activated
522            {
523#if DEBUG_DMA_CMD
524if( m_debug_activated )
525std::cout << "  <IOB DMA_CMD_IDLE> IOMMU not activated" << std::endl;
526#endif
527                // put DMA transaction into DMA_CMD fifo
528                r_dma_cmd_paddr = p_vci_tgt_iox.address.read();
529                r_dma_cmd_fsm   = DMA_CMD_FIFO_PUT_CMD;
530            }
531            else if (r_tlb_fsm.read() == TLB_IDLE ||
532                     r_tlb_fsm.read() == TLB_WAIT )       // tlb access possible
533            {
534                vci_addr_t      iotlb_paddr;
535                pte_info_t  iotlb_flags; 
536                size_t      iotlb_way; 
537                size_t      iotlb_set;
538                vci_addr_t  iotlb_nline;
539                bool            iotlb_hit; 
540
541#ifdef INSTRUMENTATION
542m_cpt_iotlb_read++;
543#endif
544                iotlb_hit = r_iotlb.translate(p_vci_tgt_iox.address.read(),
545                                              &iotlb_paddr,
546                                              &iotlb_flags,
547                                              &iotlb_nline,  // unused
548                                              &iotlb_way,        // unused
549                                              &iotlb_set );  // unused
550           
551                if ( iotlb_hit )                                     // tlb hit
552                { 
553                    if ( not iotlb_flags.w and    // access right violation
554                        (p_vci_tgt_iox.cmd.read() == vci_param_ext::CMD_WRITE) ) 
555                    {
556                        // put DMA response error into DMA_RSP fifo
557                        r_iommu_etr      = MMU_WRITE_ACCES_VIOLATION; 
558                        r_iommu_bvar     = p_vci_tgt_iox.address.read();
559                        r_iommu_bad_id   = p_vci_tgt_iox.srcid.read();
560                        r_dma_cmd_fsm    = DMA_CMD_FIFO_PUT_RSP;
561#if DEBUG_DMA_CMD
562if( m_debug_activated )
563std::cout << "  <IOB DMA_CMD_IDLE> TLB HIT but writable violation" << std::endl;
564#endif
565                    }
566                    else                         // no access rights violation
567                    {
568#if DEBUG_DMA_CMD
569if( m_debug_activated )
570std::cout << "  <IOB DMA_CMD_IDLE> TLB HIT" << std::endl;
571#endif
572                    // put DMA transaction into DMA_CMD fifo
573                    r_dma_cmd_paddr   = iotlb_paddr;                   
574                    r_dma_cmd_fsm     = DMA_CMD_FIFO_PUT_CMD;
575                    }
576                }
577                else                                             // TLB miss
578                {
579
580#ifdef INSTRUMENTATION
581m_cpt_iotlb_miss++;
582#endif
583                        // register virtual address, and send request to TLB FSM
584                                r_dma_cmd_vaddr = p_vci_tgt_iox.address.read();
585                        r_dma_tlb_req   = true;
586                        r_dma_cmd_fsm   = DMA_CMD_MISS_WAIT;
587#if DEBUG_DMA_CMD
588if( m_debug_activated )
589std::cout << "  <IOB DMA_CMD_IDLE> TLB MISS" << std::endl;
590#endif
591                } // end !hit
592            } // end if tlb_activated
593        } // end if cmdval
594        break;
595    }
596    //////////////////////////
597    case DMA_CMD_FIFO_PUT_CMD:    // put a DMA transaction in DMA_CMD fifo       
598                                  // if contig, VCI address must be incremented
599    {
600        if ( p_vci_tgt_iox.cmdval && m_dma_cmd_addr_fifo.wok() ) 
601        {
602            dma_cmd_fifo_put = true;
603           
604            if ( p_vci_tgt_iox.contig.read() ) r_dma_cmd_paddr = r_dma_cmd_paddr.read() + 
605                                                          vci_param_ext::B;
606
607            if ( p_vci_tgt_iox.eop.read() )    r_dma_cmd_fsm   = DMA_CMD_IDLE;
608           
609#if DEBUG_DMA_CMD
610if( m_debug_activated ) 
611std::cout << "  <IOB DMA_CMD_FIFO_PUT_CMD> Push into DMA_CMD fifo:" 
612          << " address = " << std::hex << r_dma_cmd_paddr.read()
613          << " srcid = " << p_vci_tgt_iox.srcid.read()
614          << " trdid = " << p_vci_tgt_iox.trdid.read()
615          << " wdata = " << p_vci_tgt_iox.wdata.read()
616          << " be = " << p_vci_tgt_iox.be.read()
617          << " contig = " << p_vci_tgt_iox.contig.read()
618          << " eop = " << std::dec << p_vci_tgt_iox.eop.read() 
619          << " plen = " << std::dec << p_vci_tgt_iox.plen.read() << std::endl;
620#endif
621        }
622        break;
623    }
624    //////////////////////
625    case DMA_CMD_WAIT_EOP:       // An error has been detected on the VCI DMA command
626                             // consume the VCI packet before sending the error response
627    {
628        if ( p_vci_tgt_iox.eop.read() )    r_dma_cmd_fsm   = DMA_CMD_FIFO_PUT_RSP;
629        break;
630    }
631    //////////////////////////
632    case DMA_CMD_FIFO_PUT_RSP:   // try to put a response error in DMA_RSP fifo
633                                 // The FIFO is shared with DMA_RSP FSM
634                                 // and we must we wait for allocation...
635    {
636        if ( r_alloc_fifo_dma_rsp_local.read() ) 
637        {
638            dma_rsp_fifo_put = true;
639
640            if( m_dma_rsp_data_fifo.wok() )
641            {
642
643#if DEBUG_DMA_CMD
644if( m_debug_activated ) 
645std::cout << "  <IOB DMA_CMD_FIFO_PUT_RSP> Put a response error to a DMA transaction." 
646          << std::endl;
647#endif
648                r_dma_cmd_fsm = DMA_CMD_IDLE;
649            }
650        }
651        break;
652    }
653    ///////////////////////
654    case DMA_CMD_MISS_WAIT:  // waiting completion of a TLB miss
655                             // we must test a possible page fault error...   
656    {
657        if ( not r_dma_tlb_req.read() ) // TLB miss completed
658        {
659            if ( r_tlb_miss_error.read() )   // Error reported by TLB FSM
660            {
661                r_iommu_etr     = MMU_READ_PT2_UNMAPPED; 
662                r_iommu_bvar    = r_dma_cmd_vaddr.read();
663                r_iommu_bad_id  = p_vci_tgt_iox.srcid.read();
664                r_dma_cmd_fsm   = DMA_CMD_FIFO_PUT_RSP;
665            }
666            else                            // No error
667            {
668                r_dma_cmd_fsm   = DMA_CMD_IDLE;
669            }
670        }
671        break;
672    }
673    } // end switch DMA_CMD FSM
674
675    //////////////////////////////////////////////////////////////////////////////
676    // The DMA_RSP_FSM handles the RAM responses to peripherals DMA transactions.
677    //////////////////////////////////////////////////////////////////////////////
678
679    switch( r_dma_rsp_fsm.read() ) 
680    {
681    //////////////////
682    case DMA_RSP_IDLE:  // waiting a response from RAM betwork
683    {           
684        if ( p_vci_ini_ram.rspval.read() ) 
685                {
686                        r_dma_rsp_fsm = DMA_RSP_FIFO_PUT;
687                }
688                break;
689    }
690    //////////////////////
691    case DMA_RSP_FIFO_PUT:
692    {
693        if(p_vci_ini_ram.rspval.read() and not r_alloc_fifo_dma_rsp_local.read() )
694        {
695            dma_rsp_fifo_put = true;
696
697            if(p_vci_ini_ram.reop.read())   r_dma_rsp_fsm = DMA_RSP_IDLE;       
698
699#if DEBUG_DMA_RSP
700if( m_debug_activated ) 
701std::cout << "  <IOB DMA_RSP_FIFO_PUT> Push response into DMA_RSP fifo:" 
702          << " / rsrcid = " << std::hex << p_vci_ini_ram.rsrcid.read()
703          << " / rtrdid = " << p_vci_ini_ram.rtrdid.read()
704          << " / rdata = " << std::hex << p_vci_ini_ram.rdata.read()
705          << " / rerror = " << p_vci_ini_ram.rerror.read()
706          << " / reop = " << p_vci_ini_ram.reop.read() << std::endl;
707#endif
708        }
709        break;
710    }
711    } // end switch DMA_RSP_FSM
712
713    //////////////////////////////////////////////////////////////////////////////////
714    // The TLB FSM handles TLB miss request (from DMA_CMD FSM),
715    // and the PTE inval request (from CONFIG_CMD FSM).
716    // PTE inval request have highest priority. In case of TLB miss,
717    // this fsm searchs the requested PTE on the prefetch buffer.
718    // In case of buffer miss,  it request the MISS_WTI FSM to access the memory.
719    // It bypass the first level page table access if possible.
720    // It reset the r_dma_tlb_req flip-flop to signal TLB miss completion.
721    // An unexpected, but possible page fault is signaled in r_tlb_miss_error flip_flop.
722    ////////////////////////////////////////////////////////////////////////////////////
723
724    switch (r_tlb_fsm.read())
725    {
726    //////////////
727    case TLB_IDLE:   // In case of TLB miss request, chek the prefetch buffer first
728                     // PTE inval request are handled as unmaskable interrupts
729    {
730        if ( r_config_tlb_req ) // Request from CONFIG FSM for a PTE invalidation
731        {
732            r_config_tlb_req      = false;
733            r_waiting_transaction = false;
734            r_tlb_fsm = TLB_INVAL_CHECK;
735        }
736
737        else if ( r_dma_tlb_req.read() )   // request from DMA_CMD for a TLB Miss
738        {
739            // Checking prefetch buffer
740            if( not r_tlb_buf_big_page )     // small page => PTE2
741            {
742                if( r_tlb_buf_valid &&         // Hit on prefetch buffer
743                    (r_tlb_buf_vaddr.read() == 
744                    (r_dma_cmd_vaddr.read()& ~PTE2_LINE_OFFSET & ~K_PAGE_OFFSET_MASK)))
745                {
746                    size_t   pte_offset = (r_dma_cmd_vaddr.read()& PTE2_LINE_OFFSET)>>12; 
747                    uint32_t pte_flags  = r_tlb_buf_data[2*pte_offset];
748                    uint32_t pte_ppn    = r_tlb_buf_data[2*pte_offset+1]; 
749               
750                    // Bit valid checking
751                    if ( not ( pte_flags & PTE_V_MASK) )        // unmapped
752                    {
753                        std::cout << "VCI_IO_BRIDGE ERROR : " << name() 
754                                  << " Page Table entry unmapped" << std::endl;
755                       
756                        r_tlb_miss_error = true;
757                        r_dma_tlb_req    = false;
758#if DEBUG_TLB_MISS
759if ( m_debug_activated )
760std::cout << "  <IOB TLB_IDLE> PTE2 Unmapped" << std::hex
761          << " / paddr = " << r_tlb_paddr.read()
762          << " / PTE_FLAGS = " << pte_flags
763          << " / PTE_PPN = " << pte_ppn << std::endl;
764#endif
765                        break; 
766                    }
767
768                    // valid PTE2 : we must update the TLB
769                    r_tlb_pte_flags = pte_flags; 
770                    r_tlb_pte_ppn   = pte_ppn;
771                    r_tlb_fsm       = TLB_PTE2_SELECT;
772#if DEBUG_TLB_MISS
773if ( m_debug_activated )
774std::cout << "  <IOB TLB_IDLE> Hit on prefetch buffer: PTE2" << std::hex
775          << " / PTE_FLAGS = " << pte_flags
776          << " / PTE_PPN = " << pte_ppn << std::endl;
777#endif
778                    break;   
779                }
780            }
781            else                             // big page => PTE1
782            {
783                if( r_tlb_buf_valid &&         // Hit on prefetch buffer
784                    (r_tlb_buf_vaddr.read() == 
785                    (r_dma_cmd_vaddr.read()& ~PTE1_LINE_OFFSET & ~M_PAGE_OFFSET_MASK ))) 
786                {
787                    size_t   pte_offset = (r_dma_cmd_vaddr.read()& PTE1_LINE_OFFSET)>>21; 
788                    uint32_t pte_flags  = r_tlb_buf_data[pte_offset];
789                           
790                    // Bit valid checking
791                    if ( not ( pte_flags & PTE_V_MASK) )        // unmapped
792                    {
793                        std::cout << "VCI_IO_BRIDGE ERROR : " << name() 
794                                  << " Page Table entry unmapped" << std::endl;
795                       
796                        r_tlb_miss_error = true;
797                        r_dma_tlb_req    = false;
798#if DEBUG_TLB_MISS
799if ( m_debug_activated )
800std::cout << "  <IOB TLB_IDLE> PTE1 Unmapped" << std::hex
801          << " / paddr = " << r_tlb_paddr.read()
802          << " / PTE = " << pte_flags << std::endl;
803#endif
804                        break; 
805                    }
806
807                    // valid PTE1 : we must update the TLB
808                    r_tlb_pte_flags = pte_flags;
809                    r_tlb_fsm       = TLB_PTE1_SELECT;
810#if DEBUG_TLB_MISS
811if ( m_debug_activated )
812std::cout << "  <IOB TLB_PTE1_GET> Hit on prefetch buffer: PTE1" << std::hex
813          << " / paddr = " << r_tlb_paddr.read()
814          << std::hex << " / PTE1 = " << pte_flags << std::endl;
815#endif
816                    break;
817                }
818            }
819       
820            // prefetch buffer miss
821            r_tlb_fsm = TLB_MISS; 
822
823#if DEBUG_TLB_MISS
824if ( m_debug_activated )
825std::cout << "  <IOB TLB_IDLE> Miss on prefetch buffer"
826          << std::hex << " / vaddr = " << r_dma_cmd_vaddr.read() << std::endl;
827#endif
828        }
829        break;
830    }
831    //////////////
832    case TLB_MISS: // handling tlb miss
833    {
834        uint32_t        ptba = 0; 
835        bool            bypass;
836        vci_addr_t      pte_paddr;
837
838#ifdef INSTRUMENTATION
839m_cpt_iotlbmiss_transaction++;
840#endif
841        // evaluate bypass in order to skip first level page table access
842        bypass = r_iotlb.get_bypass(r_dma_cmd_vaddr.read(), &ptba);
843       
844        // Request MISS_WTI_FSM a transaction on INT Network
845        if ( not bypass )     // Read PTE1/PTD1 in XRAM
846        {
847
848#if DEBUG_TLB_MISS
849if ( m_debug_activated )
850std::cout << "  <IOB TLB_MISS> Read PTE1/PTD1 in memory" << std::endl;
851#endif
852            pte_paddr = (vci_addr_t)((r_iommu_ptpr.read()) << (INDEX1_NBITS+2)) |
853                        (vci_addr_t)((r_dma_cmd_vaddr.read() >> PAGE_M_NBITS) << 2);
854            r_tlb_paddr = pte_paddr;
855           
856            r_tlb_miss_req     = true;
857            r_tlb_miss_type    = PTE1_MISS;
858            r_tlb_fsm          = TLB_WAIT;
859        }
860        else                  // Read PTE2 in XRAM
861        {
862
863#if DEBUG_TLB_MISS
864if ( m_debug_activated )
865std::cout << "  <IOB TLB_MISS> Read PTE2 in memory" << std::endl;
866#endif
867            //&PTE2 = PTBA + IX2 * 8
868            pte_paddr = (vci_addr_t)ptba << PAGE_K_NBITS |
869                        (vci_addr_t)(r_dma_cmd_vaddr.read()&PTD_ID2_MASK)>>(PAGE_K_NBITS-3);
870           
871            r_tlb_paddr = pte_paddr;
872           
873            r_tlb_miss_req     = true;
874            r_tlb_miss_type    = PTE2_MISS;
875            r_tlb_fsm          = TLB_WAIT;
876        }
877
878        break;
879    }
880    ////////////////// 
881    case TLB_PTE1_GET:  // Try to read a PT1 entry in the miss buffer
882    {
883       
884        uint32_t  entry;
885       
886        vci_addr_t line_number  = (vci_addr_t)((r_tlb_paddr.read())&(CACHE_LINE_MASK));
887        size_t word_position = (size_t)( ((r_tlb_paddr.read())&(~CACHE_LINE_MASK))>>2 );
888
889        // Hit test. Just to verify.
890        // Hit must happen, since we've just finished its' miss transaction
891        bool hit = (r_tlb_buf_valid && (r_tlb_buf_tag.read()== line_number) ); 
892        assert(hit and "Error: No hit on prefetch buffer after Miss Transaction"); 
893       
894        entry = r_tlb_buf_data[word_position];
895           
896        // Bit valid checking
897        if ( not ( entry & PTE_V_MASK) )        // unmapped
898        {
899            //must not occur!
900            std::cout << "IOMMU ERROR " << name() << "TLB_IDLE state" << std::endl
901                      << "The Page Table entry ins't valid (unmapped)" << std::endl;
902                       
903            r_tlb_miss_error       = true;
904            r_dma_tlb_req         = false;
905            r_tlb_fsm             = TLB_IDLE;           
906
907#if DEBUG_TLB_MISS
908if ( m_debug_activated )
909{
910    std::cout << "  <IOB DMA_PTE1_GET> First level entry Unmapped"
911              << std::hex << " / paddr = " << r_tlb_paddr.read()
912              << std::hex << " / PTE = " << entry << std::endl;
913}
914#endif
915                    break; 
916        }
917   
918        if( entry & PTE_T_MASK )        //  PTD : me must access PT2
919        {
920            // register bypass
921            r_iotlb.set_bypass( r_dma_cmd_vaddr.read(),
922                                entry & ((1 << (vci_param_int::N-PAGE_K_NBITS)) - 1), 
923                                0); //nline, unused
924
925            //&PTE2 = PTBA + IX2 * 8
926            // ps: PAGE_K_NBITS corresponds also to the size of a second level page table
927            r_tlb_paddr = (vci_addr_t)(entry & ((1<<(vci_param_int::N-PAGE_K_NBITS))-1)) << PAGE_K_NBITS |
928                                (vci_addr_t)(((r_dma_cmd_vaddr.read() & PTD_ID2_MASK) >> PAGE_K_NBITS) << 3);
929            r_tlb_miss_req     = true;
930            r_tlb_miss_type    = PTE2_MISS;
931            r_tlb_fsm          = TLB_WAIT;
932
933#ifdef INSTRUMENTATION
934m_cpt_iotlbmiss_transaction++;
935#endif
936
937#if DEBUG_TLB_MISS
938if ( m_debug_activated )
939std::cout << "  <IOB TLB_PTE1_GET> Success. Search PTE2" << std::hex
940          << " / PADDR = " << r_tlb_paddr.read()
941          << " / PTD = " << entry << std::endl;
942#endif
943        }
944        else                    //  PTE1 :  we must update the IOTLB
945                        //  Should not occur if working only with small pages
946        {
947            r_tlb_pte_flags   = entry;
948            r_tlb_fsm  = TLB_PTE1_SELECT;
949
950#if DEBUG_TLB_MISS
951if ( m_debug_activated )
952std::cout << "  <IOB TLB_PTE1_GET> Success. Big page"
953          << std::hex << " / paddr = " << r_tlb_paddr.read()
954          << std::hex << " / PTE1 = " << entry << std::endl;
955#endif
956        }
957        break;
958    }
959    /////////////////////
960    case TLB_PTE1_SELECT:       // select a slot for PTE1
961    {
962        size_t  way;
963        size_t  set;
964       
965        r_iotlb.select(  r_dma_cmd_vaddr.read(),
966                        true,  // PTE1
967                        &way,
968                        &set );
969#ifdef INSTRUMENTATION
970m_cpt_iotlb_read++;
971#endif
972
973#if DEBUG_TLB_MISS
974if ( m_debug_activated )
975std::cout << "  <IOB TLB_PTE1_SELECT> Select a slot in TLB"
976          << " / way = " << std::dec << way
977          << " / set = " << set << std::endl;
978#endif
979        r_tlb_way = way;
980        r_tlb_set = set;
981        r_tlb_fsm     = TLB_PTE1_UPDT;
982        break;
983    }
984    ///////////////////
985    case TLB_PTE1_UPDT:     // write a new PTE1 in tlb
986                            // not necessary to treat the L/R bit
987    {
988        uint32_t  pte   = r_tlb_pte_flags.read();
989       
990        r_tlb_paddr = (vci_addr_t)( ((r_tlb_pte_flags.read() & PPN1_MASK) << 21)
991                        | (r_dma_cmd_vaddr.read()& M_PAGE_OFFSET_MASK) );
992       
993        // update TLB
994        r_iotlb.write( true,            // 2M page
995                      pte,
996                      0,                // argument unused for a PTE1
997                      r_dma_cmd_vaddr.read(),   
998                      r_tlb_way.read(), 
999                      r_tlb_set.read(),
1000                      0 );      //we set nline = 0
1001#ifdef INSTRUMENTATION
1002m_cpt_iotlb_write++;
1003#endif
1004
1005#if DEBUG_TLB_MISS
1006if ( m_debug_activated )
1007{
1008std::cout << "  <IOB TLB_PTE1_UPDT> write PTE1 in TLB"
1009          << " / set = " << std::dec << r_tlb_set.read()
1010          << " / way = " << r_tlb_way.read() << std::endl;
1011r_iotlb.printTrace();
1012}
1013#endif
1014        // next state
1015        r_tlb_fsm = TLB_RETURN; // exit sub-fsm
1016        break;
1017    }
1018    //////////////////
1019    case TLB_PTE2_GET:  // Try to read a PTE2 (64 bits) in the miss buffer
1020    {   
1021        uint32_t        pte_flags;
1022        uint32_t        pte_ppn;
1023       
1024        vci_addr_t line_number  = (vci_addr_t)((r_tlb_paddr.read())&(CACHE_LINE_MASK));
1025        size_t word_position = (size_t)( ((r_tlb_paddr.read())&(~CACHE_LINE_MASK))>>2 );
1026       
1027       
1028        // Hit test. Just to verify.
1029        bool hit = (r_tlb_buf_valid && (r_tlb_buf_tag.read()== line_number) ); 
1030        assert(hit and "Error: No hit on prefetch buffer after Miss Transaction"); 
1031        pte_flags= r_tlb_buf_data[word_position];
1032        pte_ppn= r_tlb_buf_data[word_position+1]; //because PTE2 is 2 words long
1033        // Bit valid checking
1034        if ( not ( pte_flags & PTE_V_MASK) )    // unmapped
1035        {
1036            //must not occur!
1037            std::cout << "IOMMU ERROR " << name() << "TLB_IDLE state" << std::endl
1038                      << "The Page Table entry ins't valid (unmapped)" << std::endl;
1039                       
1040            r_tlb_miss_error       = true;
1041            r_dma_tlb_req         = false;
1042            r_tlb_fsm             = TLB_IDLE;           
1043
1044#if DEBUG_TLB_MISS
1045if ( m_debug_activated )
1046std::cout << "  <IOB TLB_PTE2_GET> PTE2 Unmapped" << std::hex
1047          << " / PADDR = " << r_tlb_paddr.read()
1048          << " / PTE = " << pte_flags << std::endl;
1049#endif
1050            break; 
1051        }
1052           
1053        r_tlb_pte_flags       = pte_flags; 
1054        r_tlb_pte_ppn         = pte_ppn;
1055        r_tlb_fsm           = TLB_PTE2_SELECT;
1056               
1057#if DEBUG_TLB_MISS
1058if ( m_debug_activated )
1059std::cout << "  <IOB TLB_PTE2_GET> Mapped" << std::hex
1060          << " / PTE_FLAGS = " << pte_flags
1061          << " / PTE_PPN = " << pte_ppn << std::endl;
1062#endif
1063        break;
1064    }
1065    ////////////////////////////
1066    case TLB_PTE2_SELECT:    // select a slot for PTE2
1067    {
1068        size_t way;
1069        size_t set;
1070
1071        r_iotlb.select( r_dma_cmd_vaddr.read(),
1072                        false,  // PTE2
1073                        &way,
1074                        &set );
1075#ifdef INSTRUMENTATION
1076m_cpt_iotlb_read++;
1077#endif
1078
1079#if DEBUG_TLB_MISS
1080if ( m_debug_activated )
1081{
1082        std::cout << "  <IOB TLB_PTE2_SELECT> Select a slot in IOTLB:";
1083        std::cout << " way = " << std::dec << way
1084                  << " / set = " << set << std::endl;
1085}
1086#endif
1087        r_tlb_way = way;
1088        r_tlb_set = set;
1089        r_tlb_fsm     = TLB_PTE2_UPDT;
1090        break;
1091    }
1092    ///////////////////
1093    case TLB_PTE2_UPDT:         // write a new PTE2 in tlb
1094                                // not necessary to treat the L/R bit
1095    {
1096        uint32_t        pte_flags = r_tlb_pte_flags.read();
1097        uint32_t        pte_ppn   = r_tlb_pte_ppn.read();
1098       
1099        r_tlb_paddr = (vci_addr_t)( ((r_tlb_pte_ppn.read() & PPN2_MASK) << 12)
1100                        | (r_dma_cmd_vaddr.read()& K_PAGE_OFFSET_MASK) );
1101       
1102        // update TLB for a PTE2
1103        r_iotlb.write( false,   // 4K page
1104                       pte_flags,
1105                       pte_ppn,
1106                       r_dma_cmd_vaddr.read(),   
1107                       r_tlb_way.read(), 
1108                       r_tlb_set.read(),
1109                       0 );     // nline = 0
1110#ifdef INSTRUMENTATION
1111m_cpt_iotlb_write++;
1112#endif
1113
1114#if DEBUG_TLB_MISS
1115if ( m_debug_activated )
1116{
1117        std::cout << "  <IOB TLB_PTE2_UPDT> write PTE2 in IOTLB";
1118        std::cout << " / set = " << std::dec << r_tlb_set.read()
1119                  << " / way = " << r_tlb_way.read() << std::endl;
1120        r_iotlb.printTrace();
1121}
1122#endif
1123        // next state
1124        r_tlb_fsm = TLB_RETURN; 
1125        break;
1126    }
1127    //////////////
1128    case TLB_WAIT:   // waiting completion of a miss transaction from MISS_WTI FSM
1129                     // PTE inval request are handled as unmaskable interrupts
1130    {
1131        if ( r_config_tlb_req ) // Request from CONFIG FSM for a PTE invalidation
1132        {
1133            r_config_tlb_req = false;
1134            r_waiting_transaction = true;
1135            r_tlb_fsm = TLB_INVAL_CHECK;
1136        }
1137
1138#ifdef INSTRUMENTATION
1139m_cost_iotlbmiss_transaction++;
1140#endif
1141        if ( not r_tlb_miss_req )       //  Miss transaction is done
1142        { 
1143                if ( r_miss_wti_rsp_error.read() ) // bus error
1144                {
1145                r_miss_wti_rsp_error = false;
1146                r_tlb_miss_error     = true;
1147                r_dma_tlb_req        = false;
1148                r_tlb_fsm            = TLB_IDLE;
1149            }
1150            else if(r_tlb_miss_type == PTE1_MISS)
1151            {
1152                r_tlb_fsm = TLB_PTE1_GET; 
1153            }
1154            else
1155            {
1156                r_tlb_fsm = TLB_PTE2_GET;
1157            }
1158        }
1159        break;
1160    }
1161    ////////////////
1162    case TLB_RETURN:            // reset r_dma_tlb_req flip-flop to signal TLB miss completion
1163                            // possible errors are signaled through r_tlb_miss_error
1164    {
1165#if DEBUG_TLB_MISS
1166if ( m_debug_activated )
1167std::cout << "  <IOB TLB_RETURN> IOTLB MISS completed" << std::endl;
1168#endif
1169        r_dma_tlb_req  = false;
1170        r_tlb_fsm = TLB_IDLE;
1171        break;
1172    }
1173    /////////////////////
1174    case TLB_INVAL_CHECK:   // request from CONFIG_FSM to invalidate all PTE in a given line
1175                            // checks the necessity to invalidate prefetch buffer
1176    {
1177        // If a transaction is pending, no need to invalidate the prefetch
1178        // We can ignore it, since we'll replace the line.
1179        // The new line is necessarily up-to-date
1180        if(!r_waiting_transaction.read() && r_tlb_buf_valid)
1181        {
1182            if(!r_tlb_buf_big_page)
1183            {
1184               if( r_tlb_buf_vaddr.read() == 
1185                   (r_config_cmd_inval_vaddr.read()& ~PTE2_LINE_OFFSET) ) 
1186                // The virtual address corresponds to one entry on the buffer line
1187                {
1188                    r_tlb_buf_valid = false;   //change here for individual invalidation
1189                }
1190            }
1191            else    // First level entries on buffer. Unused if only small pages
1192            {
1193               if( r_tlb_buf_vaddr.read() == 
1194                   (r_config_cmd_inval_vaddr.read()& ~PTE1_LINE_OFFSET) ) 
1195                // The virtual address corresponds to one entry on the buffer line
1196                {
1197                    r_tlb_buf_valid = false;   //change here for individual invalidation
1198                }
1199            }
1200        }
1201       
1202        // Invalidation on IOTLB
1203        bool    ok;
1204        ok = r_iotlb.inval(r_config_cmd_inval_vaddr.read());
1205         
1206        if(r_waiting_transaction.read()) r_tlb_fsm =TLB_WAIT; 
1207        else r_tlb_fsm = TLB_IDLE;
1208        break; 
1209    }
1210    } //end switch r_tlb_fsm
1211   
1212    ////////////////////////////////////////////////////////////////////////////////
1213    // The CONFIG_CMD_FSM handles the VCI commands from the INT network.
1214    // This FSM is mainly intended to handle single flit config transactions,
1215    // but it can also handle software driven, multi-flits data transactions.
1216    // - The configuration requests can be local (IO_BRIDGE config registers)
1217    //   or remote (config registers of peripherals on IOX network).
1218    // - The data requests are always remote.
1219    // In case of local config, this FSM put a VCI response in CONFIG_RSP fifo.
1220    // In case of remote transaction, it put the VCI command in CONFIG_CMD fifo.
1221    ///////////////////////////////////////////////////////////////////////////////
1222
1223    switch( r_config_cmd_fsm.read() ) 
1224    {
1225    /////////////////////
1226    case CONFIG_CMD_IDLE:   // waiting VCI command
1227    {
1228        if ( p_vci_tgt_int.cmdval.read() ) 
1229        {
1230
1231#if DEBUG_CONFIG_CMD
1232if( m_debug_activated )
1233std::cout << "  <IOB CONFIG_CMD_IDLE> Command received" 
1234          << " / address = " << std::hex << p_vci_tgt_int.address.read()
1235          << " / srcid = " << std::dec << p_vci_tgt_int.srcid.read()
1236          << " / trdid = " << p_vci_tgt_int.trdid.read()
1237          << " / wdata = " << std::hex << p_vci_tgt_int.wdata.read()
1238          << " / be = " << p_vci_tgt_int.be.read()
1239          << " / plen = " << std::dec << p_vci_tgt_int.plen.read()
1240          << " / eop = " << p_vci_tgt_int.eop.read() << std::endl;
1241#endif
1242            vci_addr_t paddr = p_vci_tgt_int.address.read();
1243            bool       read  = (p_vci_tgt_int.cmd.read() == vci_param_int::CMD_READ);
1244            uint32_t   cell  = (uint32_t)((paddr & 0x1FF)>>2); 
1245 
1246            // The "local" segment must be the first in the seglist
1247            soclib::common::Segment seg = m_int_seglist.front(); 
1248           
1249            if ( seg.contains(paddr) )  // IO_BRIDGE itself
1250            {
1251                uint32_t      rdata  = 0;
1252                bool          rerror = false;
1253
1254                if ( not read && (cell == IOB_IOMMU_PTPR) )       // WRITE PTPR
1255                {
1256                    r_iommu_ptpr = (uint32_t)p_vci_tgt_int.wdata.read();
1257                }
1258                else if ( read && (cell == IOB_IOMMU_PTPR) )      // READ PTPR
1259                {
1260                    rdata = r_iommu_ptpr.read();
1261                }
1262                else if( not read && (cell == IOB_WTI_ENABLE))  // WRITE WTI_ENABLE
1263                {
1264                    r_iommu_wti_enable = p_vci_tgt_int.wdata.read();
1265                }
1266                else if( read && (cell == IOB_WTI_ENABLE))       // READ WTI ENABLE
1267                {
1268                    rdata = r_iommu_wti_enable.read();
1269                }
1270                else if( read && (cell == IOB_IOMMU_BVAR))        // READ BVAR
1271                {
1272                    rdata = r_iommu_bvar.read();
1273                }
1274                else if( read && (cell == IOB_IOMMU_ETR))          // READ ETR
1275                {
1276                    rdata = r_iommu_etr.read();
1277                }
1278                else if( read && (cell == IOB_IOMMU_BAD_ID))      // READ BAD_ID
1279                {
1280                    rdata = r_iommu_bad_id.read();
1281                }
1282                else if( not read && (cell == IOB_INVAL_PTE))     // WRITE INVAL_PTE
1283                {
1284                    r_config_tlb_req         = true;
1285                    r_config_cmd_inval_vaddr = (uint32_t)p_vci_tgt_int.wdata.read();
1286                }
1287                else if( not read && (cell == IOB_WTI_ADDR_LO)) // WRITE WTI_PADDR_LO
1288                {
1289                    r_iommu_wti_paddr = (vci_addr_t)p_vci_tgt_int.wdata.read();
1290                }
1291                else if( read && (cell == IOB_WTI_ADDR_LO))    // READ WTI_PADDR_LO
1292                {
1293                    rdata = (uint32_t)r_iommu_wti_paddr.read();
1294                }
1295                else if( not read && (cell == IOB_WTI_ADDR_HI)) // WRITE WTI_PADDR_HI
1296                {
1297                    r_iommu_wti_paddr = (r_iommu_wti_paddr.read() & 0x00000000FFFFFFFFLL) |
1298                                        ((vci_addr_t)p_vci_tgt_int.wdata.read())<<32;
1299                }
1300                else if( read && (cell == IOB_WTI_ADDR_HI))    // READ WTI_PADDR_HI
1301                {
1302                    rdata = (uint32_t)(r_iommu_wti_paddr.read()>>32);
1303                }
1304                else if( not read && ((cell >= IOB_PERI_WTI_BEGIN)  // WRITE PERI WTI
1305                          && (cell< (IOB_PERI_WTI_BEGIN + 64))) )
1306                {
1307                    size_t  index = (cell - IOB_PERI_WTI_BEGIN)/2;
1308                    bool    high  = (cell - IOB_PERI_WTI_BEGIN)%2;
1309                    if ( high ) r_iommu_peri_wti[index] =          // set 32 MSB bits
1310                        (r_iommu_peri_wti[index].read() & 0x00000000FFFFFFFFLL) |
1311                        ((vci_addr_t)p_vci_tgt_int.wdata.read())<<32;
1312                    else        r_iommu_peri_wti[index] =          // set 32 LSB bits
1313                         (vci_addr_t)p_vci_tgt_int.wdata.read();
1314                } 
1315                else if( read && ((cell >= IOB_PERI_WTI_BEGIN)      // READ PERI WTI   
1316                         && (cell< (IOB_PERI_WTI_BEGIN + 64))) ) 
1317                {
1318                    size_t  index = (cell - IOB_PERI_WTI_BEGIN)/2;
1319                    bool    high  = (cell - IOB_PERI_WTI_BEGIN)%2;
1320                    if ( high ) rdata = (uint32_t)(r_iommu_peri_wti[index].read()>>32);
1321                    else        rdata = (uint32_t)(r_iommu_peri_wti[index].read());
1322                }
1323                else   // Error: Wrong address, or invalid operation.
1324                {
1325                    rerror = true;
1326                }
1327                r_config_cmd_rdata  = rdata;
1328                r_config_cmd_error = rerror;
1329                r_config_cmd_fsm    = CONFIG_CMD_FIFO_PUT_RSP;
1330            }
1331            else                                        // remote peripheral
1332            {
1333                r_config_cmd_fsm  = CONFIG_CMD_FIFO_PUT_CMD;
1334            }
1335        } // end if cmdval
1336        break;
1337    }
1338    /////////////////////////////
1339    case CONFIG_CMD_FIFO_PUT_CMD:       // transmit VCI command from the INT network
1340                                    // to the CONFIG_CMD fifo to IOX network
1341    {
1342        config_cmd_fifo_put = true;
1343
1344        if ( p_vci_tgt_int.cmdval.read()  and m_config_cmd_addr_fifo.wok() )
1345        {
1346
1347#if DEBUG_CONFIG_CMD
1348if( m_debug_activated ) 
1349std::cout << "  <IOB CONFIG_CMD_FIFO_PUT_CMD> Transmit VCI command to IOX network"
1350          << " : address = " << std::hex << p_vci_tgt_int.address.read()
1351          << " / srcid = " << p_vci_tgt_int.srcid.read()
1352          << std::endl;
1353#endif
1354            if(  p_vci_tgt_int.eop.read() ) r_config_cmd_fsm = CONFIG_CMD_IDLE;
1355        }
1356        break;
1357    }
1358    /////////////////////////////
1359    case CONFIG_CMD_FIFO_PUT_RSP:   // Try to put a response in CONFIG_RSP fifo,
1360                                    // for a local configuration transaction.
1361                                    // The FIFO is shared with CONFIG_RSP FSM
1362                                    // and must we wait for allocation...
1363    {
1364        if ( p_vci_tgt_int.cmdval.read() and r_alloc_fifo_config_rsp_local.read() )
1365        {
1366            config_rsp_fifo_put = true;
1367
1368            if ( m_config_rsp_data_fifo.wok() ) 
1369            {
1370
1371#if DEBUG_CONFIG_CMD
1372if( m_debug_activated ) 
1373std::cout << "  <IOB CONFIG_CMD_FIFO_PUT_RSP> Response to a local configuration request" 
1374          << std::endl;
1375#endif
1376                if(  p_vci_tgt_int.eop.read() ) r_config_cmd_fsm = CONFIG_CMD_IDLE;
1377            }
1378        }
1379        break;
1380    }
1381    } // end switch CONFIG_CMD FSM
1382
1383    //////////////////////////////////////////////////////////////////////////////
1384    // The CONFIG_RSP_FSM handles the VCI responses from the periherals
1385    // on the IOX network and  writes the responses in the CONFIG_RSP fifo.
1386    // The VCI response flit is only consumed in the FIFO_PUT state.
1387    // This FSM is mainly intended to handle single flit config transactions,
1388    // but it can also handle software driven, multi-flits data transactions.
1389    //////////////////////////////////////////////////////////////////////////////
1390
1391    switch( r_config_rsp_fsm.read() ) 
1392    {
1393    /////////////////////
1394    case CONFIG_RSP_IDLE:  // waiting a VCI response from IOX network
1395    {           
1396        if ( p_vci_ini_iox.rspval.read() ) 
1397                {
1398            r_config_rsp_fsm = CONFIG_RSP_FIFO_PUT;
1399                }
1400                break;
1401    }
1402    /////////////////////////
1403    case CONFIG_RSP_FIFO_PUT:  // try to write into CONFIG_RSP fifo
1404                               // as soon as it is allocated
1405    {
1406        if ( p_vci_ini_iox.rspval.read() and not r_alloc_fifo_config_rsp_local.read() )
1407        {
1408            config_rsp_fifo_put = true;
1409
1410            if ( m_config_rsp_data_fifo.wok() ) 
1411            {
1412                if ( p_vci_ini_iox.reop.read() ) r_config_rsp_fsm = CONFIG_RSP_IDLE;   
1413
1414#if DEBUG_CONFIG_RSP
1415if( m_debug_activated ) 
1416std::cout << "  <IOB CONFIG_RSP_FIFO_PUT> Push response into CONFIG_RSP fifo:" 
1417          << " / rsrcid = " << std::hex << p_vci_ini_iox.rsrcid.read()
1418          << " / rtrdid = " << p_vci_ini_iox.rtrdid.read()
1419          << " / rdata = " << p_vci_ini_iox.rdata.read()
1420          << " / reop  = " << p_vci_ini_iox.reop.read()
1421          << " / rerror = " << p_vci_ini_iox.rerror.read() << std::endl;
1422#endif
1423            }
1424                       
1425        }
1426        break;
1427    }
1428    } // end switch CONFIG_RSP FSM
1429
1430    /////////////////////////////////////////////////////////////////////////////////
1431    // If the IOB component has IRQ ports, the IRQ FSM detects all changes
1432    // on the 32 p_irq[i] ports and request a VCI write transaction to the
1433    // MISS_INIT FSM, using the 64 r_irq_request[i] and r_irq_pending[i] flip-flops.
1434    /////////////////////////////////////////////////////////////////////////////////
1435
1436    if ( m_has_irqs )
1437    {
1438        for ( size_t i = 0; i<32; ++i )
1439        {
1440            r_irq_request[i] = ( p_irq[i]->read() == not r_irq_pending[i].read() );
1441            r_irq_pending[i] = p_irq[i]->read();
1442        }
1443    }
1444       
1445    ///////////////////////////////////////////////////////////////////////////////////
1446    // The MISS_WTI_CMD FSM send VCI commands on the Internal Network.
1447    // It handles PTE MISS requests from TLB_MISS FSM and software IRQs.
1448    // It supports several simultaneous VCI transactions.
1449    ////////////////////////////////////////////////////////////////////////////////////
1450 
1451    switch ( r_miss_wti_cmd_fsm.read() ) 
1452    {
1453        ///////////////////////
1454        case MISS_WTI_CMD_IDLE:   // TLB MISS have highest priority
1455        {
1456            if ( r_tlb_miss_req.read() )
1457            {
1458                r_miss_wti_cmd_fsm = MISS_WTI_CMD_MISS;
1459            }
1460            else if ( r_iommu_wti_enable.read() )
1461            {
1462                // checking if there is a new pending interrupt
1463                bool found = false;
1464                size_t n;
1465                for ( n = 0 ; (n < 32) and not found ; n++ )
1466                {
1467                    if ( r_irq_request[n] ) found = true;
1468                }
1469                if ( found )
1470                {
1471                    r_miss_wti_cmd_index = n;
1472                    r_miss_wti_cmd_fsm   = MISS_WTI_CMD_WTI;
1473                }
1474            }
1475                        break;
1476        }
1477        //////////////////////     
1478        case MISS_WTI_CMD_WTI:   // send a single flit IRQ WRITE on INT Network
1479                                 // address is defined by IRQ_VECTOR[r_miss_wti_index]
1480                                 // data is defined by r_irq_pending[r_miss_wti_index]
1481        {
1482            if ( p_vci_ini_int.cmdack ) 
1483            {
1484                // reset the request
1485                r_irq_request[r_miss_wti_cmd_index.read()] = false;
1486                r_miss_wti_cmd_fsm = MISS_WTI_RSP_WTI;         
1487
1488#if DEBUG_MISS_WTI
1489if( m_debug_activated )
1490std::cout << "  <IOB MISS_WTI_CMD_WTI> Send WTI write command on Internal Network"
1491          << " / IRQID = " << std::dec << r_miss_wti_cmd_index.read() << std::endl;
1492#endif
1493            }
1494            break;
1495        }
1496        ///////////////////////
1497        case MISS_WTI_CMD_MISS:   // send a TLB MISS request on INT Network
1498        {
1499            if ( p_vci_ini_int.cmdack ) 
1500            {
1501                r_tlb_buf_tag     = ( (r_tlb_paddr.read()) & CACHE_LINE_MASK ); 
1502                r_tlb_buf_valid   = true;
1503           
1504                if( r_tlb_miss_type.read() == PTE1_MISS )
1505                    r_tlb_buf_vaddr = (r_dma_cmd_vaddr.read() & 
1506                                        ~M_PAGE_OFFSET_MASK & ~PTE1_LINE_OFFSET);
1507                else
1508                    r_tlb_buf_vaddr = (r_dma_cmd_vaddr.read() & 
1509                                        ~K_PAGE_OFFSET_MASK & ~PTE2_LINE_OFFSET);
1510               
1511                r_miss_wti_cmd_fsm = MISS_WTI_RSP_MISS;         
1512
1513#if DEBUG_MISS_WTI
1514if( m_debug_activated )
1515std::cout << "  <IOB MISS_WTI_CMD_MISS> Send TLB MISS command on Internal Network" << std::hex
1516          << " / address = " <<(vci_addr_t)((r_tlb_paddr.read())& CACHE_LINE_MASK) << std::endl;
1517#endif
1518            }
1519            break;
1520        }
1521    } // end switch r_miss_wti_cmd_fsm
1522
1523    ///////////////////////////////////////////////////////////////////////////////////
1524    // The MISS_WTI_RSP FSM handles VCI responses on the Internal Network.
1525    // it can be response to TLB MISS (read transaction) or WTI (write transaction).
1526    // It supports several simultaneous VCI transactions.
1527    ////////////////////////////////////////////////////////////////////////////////////
1528 
1529    switch ( r_miss_wti_rsp_fsm.read() ) 
1530    {
1531        case MISS_WTI_RSP_IDLE:   // waiting a VCI response
1532        {
1533            if ( p_vci_ini_int.rspval.read() ) 
1534            {
1535                if ( p_vci_ini_int.rpktid.read() == PKTID_READ )  // it's a TLB MISS response
1536                {
1537                    r_miss_wti_rsp_fsm   = MISS_WTI_RSP_MISS;
1538                    r_miss_wti_rsp_count = 0;
1539                }
1540                else                                       // it's a WTI WRITE response
1541                {
1542                    r_miss_wti_rsp_fsm   = MISS_WTI_RSP_WTI;
1543
1544                }
1545            }
1546            break;
1547        }
1548        //////////////////////
1549        case MISS_WTI_RSP_WTI:   // Handling response to a WTI transaction
1550        {
1551            assert( p_vci_ini_int.reop.read() and
1552            "VCI_IO_BRIDGE ERROR: IRQ Write response should have one single flit" ); 
1553
1554            assert( ( (p_vci_ini_int.rerror.read()&0x1) == 0 ) and
1555            "VCI_IO_BRIDGE ERROR: IRQ Write response error !!!" ); 
1556             // TODO traiter error using the IOMMU IRQ
1557
1558#if DEBUG_MISS_WTI
1559if( m_debug_activated )
1560std::cout << "  <IOB MISS_WTI_RSP_WTI> Response to WTI write" << std::endl;
1561#endif
1562            r_miss_wti_rsp_fsm = MISS_WTI_RSP_IDLE;
1563            break;
1564        }
1565        ///////////////////////
1566        case MISS_WTI_RSP_MISS:   // Handling response to a TLB MISS transaction
1567        {
1568            if ( p_vci_ini_int.rspval.read() ) 
1569            {
1570                if ( (p_vci_ini_int.rerror.read()&0x1) != 0 )  // error reported
1571                {
1572                    r_miss_wti_rsp_error = true;
1573                    if ( p_vci_ini_int.reop.read() ) 
1574                    {   
1575                        r_miss_wti_cmd_fsm = MISS_WTI_RSP_IDLE;
1576                        r_tlb_miss_req = false; 
1577                    }
1578#if DEBUG_MISS_WTI
1579if( m_debug_activated ) 
1580std::cout << " <IOB MISS_WTI_RSP_MISS> ERROR " << std::endl; 
1581#endif
1582                }
1583                else                                           // no error
1584                { 
1585                    bool   eop          = p_vci_ini_int.reop.read();
1586
1587#if DEBUG_MISS_WTI
1588if( m_debug_activated ) 
1589std::cout << "  <IOB MISS_WTI_RSP_MISS> Response to a tlb miss transaction"
1590          << " / Count = " << r_miss_wti_rsp_count.read()
1591          << " / Data = " << std::hex << p_vci_ini_int.rdata.read() << std::endl; 
1592#endif
1593                    assert(((eop == (r_miss_wti_rsp_count.read() == (m_words-1)))) and
1594                    "VCI_IO_BRIDGE ERROR: invalid length for a TLB MISS response");
1595
1596                    r_tlb_buf_data[r_miss_wti_rsp_count.read()] = p_vci_ini_int.rdata.read();
1597                    r_miss_wti_rsp_count = r_miss_wti_rsp_count.read() + 1;
1598                   
1599                    if ( eop ) 
1600                    {
1601                        r_tlb_miss_req = false;     //reset the request flip-flop
1602                        r_miss_wti_cmd_fsm = MISS_WTI_RSP_IDLE;         
1603                    }
1604                }
1605            }
1606            break;
1607        }
1608    } // end  switch r_miss_wti_rsp_fsm
1609
1610    /////////////////////////////////////////////////////////////////////////
1611    // This flip-flop allocates the access to the CONFIG_RSP fifo
1612    // with a round robin priority between 2 clients FSMs :
1613    // - CONFIG_CMD : to put a response to a local config command.
1614    // - CONFIG_RSP : to put a response to a peripheral config command.
1615    // The ressource is always allocated.
1616    // A new allocation occurs when the owner FSM is not using it,
1617    // and the other FSM is requiring it.
1618    /////////////////////////////////////////////////////////////////////////
1619   
1620    if ( r_alloc_fifo_config_rsp_local.read() )
1621    {
1622        if ( (r_config_rsp_fsm.read() == CONFIG_RSP_FIFO_PUT) and
1623             (r_config_cmd_fsm.read() != CONFIG_CMD_FIFO_PUT_RSP) )
1624        r_alloc_fifo_config_rsp_local = false;
1625    }
1626    else 
1627    {
1628        if ( (r_config_cmd_fsm.read() == CONFIG_CMD_FIFO_PUT_RSP) and
1629             (r_config_rsp_fsm.read() != CONFIG_RSP_FIFO_PUT) )
1630        r_alloc_fifo_config_rsp_local = true;
1631    }
1632
1633    /////////////////////////////////////////////////////////////////////////
1634    // This flip-flop allocates the access to the DMA_RSP fifo
1635    // with a round robin priority between 2 clients FSMs :
1636    // - DMA_CMD : to put a error response in case of bad address translation
1637    // - DMA_RSP : to put a normal response to a DMA transaction.
1638    // The ressource is always allocated.
1639    // A new allocation occurs when the owner FSM is not using it,
1640    // and the other FSM is requiring it.
1641    /////////////////////////////////////////////////////////////////////////
1642   
1643    if ( r_alloc_fifo_dma_rsp_local.read() )
1644    {
1645        if ( (r_dma_rsp_fsm.read() == DMA_RSP_FIFO_PUT) and
1646             (r_dma_cmd_fsm.read() != DMA_CMD_FIFO_PUT_RSP) )
1647        r_alloc_fifo_dma_rsp_local = false;
1648    }
1649    else 
1650    {
1651        if ( (r_dma_cmd_fsm.read() == DMA_CMD_FIFO_PUT_RSP) and
1652             (r_dma_rsp_fsm.read() != DMA_RSP_FIFO_PUT) )
1653        r_alloc_fifo_dma_rsp_local = true;
1654    }
1655
1656    // Define GET signals for all output FIFOs
1657    dma_cmd_fifo_get    = p_vci_ini_ram.cmdack.read();
1658    dma_rsp_fifo_get    = p_vci_tgt_iox.rspack.read();
1659    config_cmd_fifo_get = p_vci_ini_iox.cmdack.read();
1660    config_rsp_fifo_get = p_vci_tgt_int.rspack.read();
1661
1662    ///////////////////////////////////////////////////////////
1663    // DMA_CMD fifo update
1664    // One writer : DMA_CMD FSM
1665    ///////////////////////////////////////////////////////////
1666
1667    m_dma_cmd_addr_fifo.update(   dma_cmd_fifo_get,
1668                                  dma_cmd_fifo_put,
1669                                  r_dma_cmd_paddr.read() );   // address translation
1670    m_dma_cmd_cmd_fifo.update(    dma_cmd_fifo_get,
1671                                  dma_cmd_fifo_put,
1672                                  p_vci_tgt_iox.cmd.read() );
1673    m_dma_cmd_contig_fifo.update( dma_cmd_fifo_get,
1674                                  dma_cmd_fifo_put,
1675                                  p_vci_tgt_iox.contig.read() );
1676    m_dma_cmd_cons_fifo.update(   dma_cmd_fifo_get,
1677                                  dma_cmd_fifo_put,
1678                                  p_vci_tgt_iox.cons.read() );
1679    m_dma_cmd_plen_fifo.update(   dma_cmd_fifo_get,
1680                                  dma_cmd_fifo_put,
1681                                  p_vci_tgt_iox.plen.read() );
1682    m_dma_cmd_wrap_fifo.update(   dma_cmd_fifo_get,
1683                                  dma_cmd_fifo_put,
1684                                  p_vci_tgt_iox.wrap.read() );
1685    m_dma_cmd_cfixed_fifo.update( dma_cmd_fifo_get,
1686                                  dma_cmd_fifo_put,
1687                                  p_vci_tgt_iox.cfixed.read() );
1688    m_dma_cmd_clen_fifo.update(   dma_cmd_fifo_get,
1689                                  dma_cmd_fifo_put,
1690                                  p_vci_tgt_iox.clen.read() );
1691    m_dma_cmd_srcid_fifo.update(  dma_cmd_fifo_get,
1692                                  dma_cmd_fifo_put,
1693                                  p_vci_tgt_iox.srcid.read() );
1694    m_dma_cmd_trdid_fifo.update(  dma_cmd_fifo_get,
1695                                  dma_cmd_fifo_put,
1696                                  p_vci_tgt_iox.trdid.read() );
1697    m_dma_cmd_pktid_fifo.update(  dma_cmd_fifo_get,
1698                                  dma_cmd_fifo_put,
1699                                  p_vci_tgt_iox.pktid.read() );
1700    m_dma_cmd_data_fifo.update(   dma_cmd_fifo_get,
1701                                  dma_cmd_fifo_put,
1702                                  p_vci_tgt_iox.wdata.read() ); 
1703    m_dma_cmd_be_fifo.update(     dma_cmd_fifo_get,
1704                                  dma_cmd_fifo_put,
1705                                  p_vci_tgt_iox.be.read() ); 
1706    m_dma_cmd_eop_fifo.update(    dma_cmd_fifo_get,
1707                                  dma_cmd_fifo_put,
1708                                  p_vci_tgt_iox.eop.read() );
1709
1710    //////////////////////////////////////////////////////////////
1711    // DMA_RSP fifo update
1712    // Two writers : DMA_CMD FSM & DMA_RSP FSM
1713    //////////////////////////////////////////////////////////////
1714
1715    if (r_alloc_fifo_dma_rsp_local.read() )  // owner is DMA_CMD FSM
1716                                             // local response for a translation error
1717    {
1718        m_dma_rsp_data_fifo.update(   dma_rsp_fifo_get,
1719                                      dma_rsp_fifo_put,
1720                                      0 );                      // no data if error
1721        m_dma_rsp_rsrcid_fifo.update( dma_rsp_fifo_get,
1722                                      dma_rsp_fifo_put,
1723                                      p_vci_tgt_iox.rsrcid.read() ); 
1724        m_dma_rsp_rtrdid_fifo.update( dma_rsp_fifo_get,
1725                                      dma_rsp_fifo_put,
1726                                      p_vci_tgt_iox.rtrdid.read() ); 
1727        m_dma_rsp_rpktid_fifo.update( dma_rsp_fifo_get,
1728                                      dma_rsp_fifo_put,
1729                                      p_vci_tgt_iox.rpktid.read() ); 
1730        m_dma_rsp_reop_fifo.update(   dma_rsp_fifo_get,
1731                                      dma_rsp_fifo_put,
1732                                      true );                    // single flit response
1733        m_dma_rsp_rerror_fifo.update( dma_rsp_fifo_get,
1734                                      dma_rsp_fifo_put,
1735                                      1 );                        // error
1736    }
1737    else                                   // owner is DMA_RSP FSM
1738                                           // normal response to a DMA transaction
1739    {
1740        m_dma_rsp_data_fifo.update(   dma_rsp_fifo_get,
1741                                      dma_rsp_fifo_put,
1742                                      p_vci_ini_ram.rdata.read() );
1743        m_dma_rsp_rsrcid_fifo.update( dma_rsp_fifo_get,
1744                                      dma_rsp_fifo_put,
1745                                      p_vci_ini_ram.rsrcid.read() );
1746        m_dma_rsp_rtrdid_fifo.update( dma_rsp_fifo_get,
1747                                      dma_rsp_fifo_put,
1748                                      p_vci_ini_ram.rtrdid.read() );
1749        m_dma_rsp_rpktid_fifo.update( dma_rsp_fifo_get,
1750                                      dma_rsp_fifo_put,
1751                                      p_vci_ini_ram.rpktid.read() );
1752        m_dma_rsp_reop_fifo.update(   dma_rsp_fifo_get,
1753                                      dma_rsp_fifo_put,
1754                                      p_vci_ini_ram.reop.read() );
1755        m_dma_rsp_rerror_fifo.update( dma_rsp_fifo_get,
1756                                      dma_rsp_fifo_put,
1757                                      p_vci_ini_ram.rerror.read() );
1758    }
1759
1760    ////////////////////////////////////////////////////////////////
1761    // CONFIG_CMD fifo update
1762    // One writer : CONFIG_CMD FSM
1763    ////////////////////////////////////////////////////////////////
1764
1765    m_config_cmd_addr_fifo.update(   config_cmd_fifo_get,
1766                                     config_cmd_fifo_put,
1767                                     p_vci_tgt_int.address.read() ); 
1768    m_config_cmd_cmd_fifo.update(    config_cmd_fifo_get,
1769                                     config_cmd_fifo_put,
1770                                     p_vci_tgt_int.cmd.read() );
1771    m_config_cmd_contig_fifo.update( config_cmd_fifo_get,
1772                                     config_cmd_fifo_put,
1773                                     p_vci_tgt_int.contig.read() );
1774    m_config_cmd_cons_fifo.update(   config_cmd_fifo_get,
1775                                     config_cmd_fifo_put,
1776                                     p_vci_tgt_int.cons.read() );
1777    m_config_cmd_plen_fifo.update(   config_cmd_fifo_get,
1778                                     config_cmd_fifo_put,
1779                                     p_vci_tgt_int.plen.read() );
1780    m_config_cmd_wrap_fifo.update(   config_cmd_fifo_get,
1781                                     config_cmd_fifo_put,
1782                                     p_vci_tgt_int.wrap.read() );
1783    m_config_cmd_cfixed_fifo.update( config_cmd_fifo_get,
1784                                     config_cmd_fifo_put,
1785                                     p_vci_tgt_int.cfixed.read() );
1786    m_config_cmd_clen_fifo.update(   config_cmd_fifo_get,
1787                                     config_cmd_fifo_put,
1788                                     p_vci_tgt_int.clen.read() );
1789    m_config_cmd_srcid_fifo.update(  config_cmd_fifo_get,
1790                                     config_cmd_fifo_put,
1791                                     p_vci_tgt_int.srcid.read() );
1792    m_config_cmd_trdid_fifo.update(  config_cmd_fifo_get,
1793                                     config_cmd_fifo_put,
1794                                     p_vci_tgt_int.trdid.read() ); 
1795    m_config_cmd_pktid_fifo.update(  config_cmd_fifo_get,
1796                                     config_cmd_fifo_put,
1797                                     p_vci_tgt_int.pktid.read() );
1798    m_config_cmd_data_fifo.update(   config_cmd_fifo_get,
1799                                     config_cmd_fifo_put,
1800                                     (ext_data_t)p_vci_tgt_int.wdata.read() );
1801    m_config_cmd_be_fifo.update(     config_cmd_fifo_get,
1802                                     config_cmd_fifo_put,
1803                                     p_vci_tgt_int.be.read() );
1804    m_config_cmd_eop_fifo.update(    config_cmd_fifo_get,
1805                                     config_cmd_fifo_put,
1806                                     p_vci_tgt_int.eop.read() );
1807   
1808    //////////////////////////////////////////////////////////////////////////
1809    // CONFIG_RSP fifo update
1810    // There is two writers : CONFIG_CMD FSM & CONFIG_RSP FSM
1811    //////////////////////////////////////////////////////////////////////////
1812
1813    if ( r_alloc_fifo_config_rsp_local.read() )  // owner is CONFIG_CMD FSM
1814                                                 // response for a local config transaction
1815    {
1816        m_config_rsp_data_fifo.update(   config_rsp_fifo_get,
1817                                         config_rsp_fifo_put,
1818                                         (int_data_t)r_config_cmd_rdata.read() ); 
1819        m_config_rsp_rsrcid_fifo.update( config_rsp_fifo_get,
1820                                         config_rsp_fifo_put,
1821                                         p_vci_tgt_int.srcid.read() );
1822        m_config_rsp_rtrdid_fifo.update( config_rsp_fifo_get,
1823                                         config_rsp_fifo_put,
1824                                         p_vci_tgt_int.trdid.read() );
1825        m_config_rsp_rpktid_fifo.update( config_rsp_fifo_get,
1826                                         config_rsp_fifo_put,
1827                                         p_vci_tgt_int.pktid.read() );
1828        m_config_rsp_reop_fifo.update(   config_rsp_fifo_get,
1829                                         config_rsp_fifo_put,
1830                                         true );                // local config are one flit
1831        m_config_rsp_rerror_fifo.update( config_rsp_fifo_get,
1832                                         config_rsp_fifo_put,
1833                                         r_config_cmd_error.read() );
1834    }
1835    else                                         // owner is CONFIG_RSP FSM
1836                                                 // response for a remote transaction
1837    {
1838        m_config_rsp_data_fifo.update(   config_rsp_fifo_get,
1839                                         config_rsp_fifo_put,
1840                                         (int_data_t)p_vci_ini_iox.rdata.read() );
1841        m_config_rsp_rsrcid_fifo.update( config_rsp_fifo_get,
1842                                         config_rsp_fifo_put,
1843                                         p_vci_ini_iox.rsrcid.read() );
1844        m_config_rsp_rtrdid_fifo.update( config_rsp_fifo_get,
1845                                         config_rsp_fifo_put,
1846                                         p_vci_ini_iox.rtrdid.read() );
1847        m_config_rsp_rpktid_fifo.update( config_rsp_fifo_get,
1848                                         config_rsp_fifo_put,
1849                                         p_vci_ini_iox.rpktid.read() );
1850        m_config_rsp_reop_fifo.update(   config_rsp_fifo_get,
1851                                         config_rsp_fifo_put,
1852                                         p_vci_ini_iox.reop.read() );
1853        m_config_rsp_rerror_fifo.update( config_rsp_fifo_get,
1854                                         config_rsp_fifo_put,
1855                                         p_vci_ini_iox.rerror.read() );
1856    }
1857   
1858} // end transition()
1859
1860///////////////////////
1861tmpl(void)::genMoore()
1862///////////////////////
1863{
1864    // VCI initiator command on RAM network
1865    // directly the content of the dma_cmd FIFO
1866
1867    p_vci_ini_ram.cmdval  = m_dma_cmd_addr_fifo.rok(); 
1868    p_vci_ini_ram.address = m_dma_cmd_addr_fifo.read();
1869    p_vci_ini_ram.be      = m_dma_cmd_be_fifo.read();
1870    p_vci_ini_ram.cmd     = m_dma_cmd_cmd_fifo.read();
1871    p_vci_ini_ram.contig  = m_dma_cmd_contig_fifo.read();
1872    p_vci_ini_ram.wdata   = m_dma_cmd_data_fifo.read(); 
1873    p_vci_ini_ram.eop     = m_dma_cmd_eop_fifo.read();
1874    p_vci_ini_ram.cons    = m_dma_cmd_cons_fifo.read();
1875    p_vci_ini_ram.plen    = m_dma_cmd_plen_fifo.read();
1876    p_vci_ini_ram.wrap    = m_dma_cmd_wrap_fifo.read();
1877    p_vci_ini_ram.cfixed  = m_dma_cmd_cfixed_fifo.read();
1878    p_vci_ini_ram.clen    = m_dma_cmd_clen_fifo.read();
1879    p_vci_ini_ram.trdid   = m_dma_cmd_trdid_fifo.read();
1880    p_vci_ini_ram.pktid   = m_dma_cmd_pktid_fifo.read();
1881    p_vci_ini_ram.srcid   = m_dma_cmd_srcid_fifo.read();
1882   
1883    // VCI target command ack on IOX network
1884    // depends on the DMA_CMD FSM state
1885
1886    switch ( r_dma_cmd_fsm.read() ) 
1887    {
1888    case DMA_CMD_IDLE:
1889    case DMA_CMD_MISS_WAIT:
1890        p_vci_tgt_iox.cmdack  = false;
1891        break;
1892    case DMA_CMD_WAIT_EOP:
1893        p_vci_tgt_iox.cmdack  = true;
1894        break;
1895    case DMA_CMD_FIFO_PUT_CMD:
1896        p_vci_tgt_iox.cmdack  = m_dma_cmd_addr_fifo.wok();
1897        break;
1898    case DMA_CMD_FIFO_PUT_RSP:
1899        p_vci_tgt_iox.cmdack  = m_dma_rsp_data_fifo.wok();
1900        break; 
1901    }// end switch r_dma_cmd_fsm
1902
1903    // VCI target response on IOX network
1904    // directly the content of the DMA_RSP FIFO
1905
1906    p_vci_tgt_iox.rspval  = m_dma_rsp_data_fifo.rok();
1907    p_vci_tgt_iox.rsrcid  = m_dma_rsp_rsrcid_fifo.read();
1908    p_vci_tgt_iox.rtrdid  = m_dma_rsp_rtrdid_fifo.read();
1909    p_vci_tgt_iox.rpktid  = m_dma_rsp_rpktid_fifo.read();
1910    p_vci_tgt_iox.rdata   = m_dma_rsp_data_fifo.read(); 
1911    p_vci_tgt_iox.rerror  = m_dma_rsp_rerror_fifo.read();
1912    p_vci_tgt_iox.reop    = m_dma_rsp_reop_fifo.read();
1913
1914    // VCI initiator response on the RAM Network
1915    // depends on the DMA_RSP FSM state
1916
1917        p_vci_ini_ram.rspack = m_dma_rsp_data_fifo.wok() and
1918                           (r_dma_rsp_fsm.read() == DMA_RSP_FIFO_PUT) and
1919                           not r_alloc_fifo_dma_rsp_local.read();
1920
1921    // VCI initiator command on IOX network
1922    // directly the content of the CONFIG_CMD FIFO
1923
1924    p_vci_ini_iox.cmdval  = m_config_cmd_addr_fifo.rok();
1925    p_vci_ini_iox.address = m_config_cmd_addr_fifo.read();
1926    p_vci_ini_iox.be      = m_config_cmd_be_fifo.read();
1927    p_vci_ini_iox.cmd     = m_config_cmd_cmd_fifo.read();
1928    p_vci_ini_iox.contig  = m_config_cmd_contig_fifo.read();
1929    p_vci_ini_iox.wdata   = (ext_data_t)m_config_cmd_data_fifo.read(); 
1930    p_vci_ini_iox.eop     = m_config_cmd_eop_fifo.read();
1931    p_vci_ini_iox.cons    = m_config_cmd_cons_fifo.read();
1932    p_vci_ini_iox.plen    = m_config_cmd_plen_fifo.read();
1933    p_vci_ini_iox.wrap    = m_config_cmd_wrap_fifo.read();
1934    p_vci_ini_iox.cfixed  = m_config_cmd_cfixed_fifo.read();
1935    p_vci_ini_iox.clen    = m_config_cmd_clen_fifo.read();
1936    p_vci_ini_iox.trdid   = m_config_cmd_trdid_fifo.read();
1937    p_vci_ini_iox.pktid   = m_config_cmd_pktid_fifo.read();
1938    p_vci_ini_iox.srcid   = m_config_cmd_srcid_fifo.read();
1939   
1940    // VCI target command ack on INT network
1941    // it depends on the CONFIG_CMD FSM state
1942
1943    switch ( r_config_cmd_fsm.read() ) 
1944    {
1945    case CONFIG_CMD_IDLE:
1946        p_vci_tgt_int.cmdack  = false;
1947        break;
1948    case CONFIG_CMD_FIFO_PUT_CMD:         
1949        p_vci_tgt_int.cmdack  = m_config_cmd_addr_fifo.wok();
1950        break;
1951    case CONFIG_CMD_FIFO_PUT_RSP:         
1952        p_vci_tgt_int.cmdack  = m_config_rsp_data_fifo.wok() and
1953                                r_alloc_fifo_config_rsp_local.read();
1954        break;
1955    }// end switch r_config_cmd_fsm
1956
1957    // VCI target response on INT network
1958    // directly the content of the CONFIG_RSP FIFO
1959
1960    p_vci_tgt_int.rspval  = m_config_rsp_data_fifo.rok();
1961        p_vci_tgt_int.rsrcid  = m_config_rsp_rsrcid_fifo.read();
1962    p_vci_tgt_int.rtrdid  = m_config_rsp_rtrdid_fifo.read();
1963    p_vci_tgt_int.rpktid  = m_config_rsp_rpktid_fifo.read();
1964    p_vci_tgt_int.rdata   = m_config_rsp_data_fifo.read();
1965    p_vci_tgt_int.rerror  = m_config_rsp_rerror_fifo.read();
1966    p_vci_tgt_int.reop    = m_config_rsp_reop_fifo.read();
1967   
1968    // VCI initiator response on IOX Network
1969    // it depends on the CONFIG_RSP FSM state
1970
1971        p_vci_ini_iox.rspack = m_config_rsp_data_fifo.wok() and
1972                           (r_config_rsp_fsm.read() == CONFIG_RSP_FIFO_PUT) and
1973                           not r_alloc_fifo_config_rsp_local.read();
1974
1975    // VCI initiator command  on INT network
1976    // it depends on the MISS_WTI_CMD FSM state
1977
1978    // default values
1979    p_vci_ini_int.srcid   = m_int_srcid;
1980    p_vci_ini_int.trdid   = 0;
1981    p_vci_ini_int.cfixed  = false;
1982    p_vci_ini_int.eop     = true;
1983    p_vci_ini_int.wrap    = false;
1984    p_vci_ini_int.clen    = 0;
1985    p_vci_ini_int.contig  = false;
1986    p_vci_ini_int.cons    = true;
1987    p_vci_ini_int.be      = 0xFF;
1988   
1989    switch ( r_miss_wti_cmd_fsm.read() ) 
1990    {   
1991    case MISS_WTI_CMD_IDLE:
1992                p_vci_ini_int.cmdval  = false;
1993        p_vci_ini_int.address = 0;
1994        p_vci_ini_int.cmd     = vci_param_int::CMD_NOP;
1995        p_vci_ini_int.pktid   = PKTID_READ;
1996        p_vci_ini_int.wdata   = 0;
1997        p_vci_ini_int.plen    = 0;
1998        break;
1999   
2000    case MISS_WTI_CMD_WTI:
2001        p_vci_ini_int.cmdval  = true;
2002        p_vci_ini_int.address = r_iommu_peri_wti[r_miss_wti_cmd_index.read()].read(); 
2003        p_vci_ini_int.cmd     = vci_param_int::CMD_WRITE;
2004        p_vci_ini_int.pktid   = PKTID_WRITE;
2005        p_vci_ini_int.wdata   = (int_data_t)r_irq_pending[r_miss_wti_cmd_index.read()].read();
2006        p_vci_ini_int.plen    = vci_param_int::B;
2007        break;
2008   
2009    case MISS_WTI_CMD_MISS:
2010        p_vci_ini_int.cmdval  = true;
2011        p_vci_ini_int.address = r_tlb_paddr.read() & CACHE_LINE_MASK;
2012        p_vci_ini_int.cmd     = vci_param_int::CMD_READ;
2013        p_vci_ini_int.pktid   = PKTID_READ;
2014        p_vci_ini_int.wdata   = 0;
2015        p_vci_ini_int.plen    = m_words*(vci_param_int::B);
2016        break;
2017    }
2018
2019    // VCI initiator response on INT network
2020    // It depends on the MISS_WTI_RSP FSM state
2021
2022    if ( r_miss_wti_rsp_fsm.read() == MISS_WTI_RSP_IDLE ) p_vci_ini_int.rspack  = false;
2023    else                                                  p_vci_ini_int.rspack  = true;
2024
2025} // end genMoore
2026
2027}}
2028
2029// Local Variables:
2030// tab-width: 4
2031// c-basic-offset: 4
2032// c-file-offsets:((innamespace . 0)(inline-open . 0))
2033// indent-tabs-mode: nil
2034// End:
2035
2036// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.