source: trunk/modules/vci_block_device_tsar/caba/source/include/vci_block_device_tsar.h @ 391

Last change on this file since 391 was 391, checked in by lambert, 11 years ago

Bug fix in Vci_mem_cache :

  • When line evicion in write fsm to IXR_CMD, second word should be shifted for 64 bits support
  • Fixing assert message for vci_param_ext, only support for cell_size = 8

Adding include in Vci_block_device_tsar to fix compiling problem

File size: 8.5 KB
Line 
1
2/* -*- c++ -*-
3 *
4 * SOCLIB_LGPL_HEADER_BEGIN
5 *
6 * This file is part of SoCLib, GNU LGPLv2.1.
7 *
8 * SoCLib is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; version 2.1 of the License.
11 *
12 * SoCLib is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with SoCLib; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 * SOCLIB_LGPL_HEADER_END
23 *
24 * Copyright (c) UPMC, Lip6, Asim
25 *         alain.greiner@lip6.fr april 2011
26 *
27 * Maintainers: alain
28 */
29
30//////////////////////////////////////////////////////////////////////////////////////
31// This component is a simplified disk controller with a VCI interface.
32// This component can perform data transfers between one single file belonging
33// to the host system and a buffer in the memory of the virtual prototype.
34// The file name is an argument of the constructor.
35// This component has a DMA capability, and is both a target and an initiator.
36// The block size (bytes), and the burst size (bytes) must be power of 2.
37// The burst size is typically a cache line.
38// If the memory buffer is not constrained to be aligned on a burst boundary.
39// Both read and write transfers are supported. An IRQ is optionally
40// asserted when the transfer is completed.
41//
42// As a target this block device controler contains 8 memory mapped registers,
43// taking 32 bytes in the address space.
44// - BLOCK_DEVICE_BUFFER        0x00 (read/write)    Memory buffer base address.
45// - BLOCK_DEVICE_COUNT         0x04 (read/write)    Number of blocks to be transfered.
46// - BLOCK_DEVICE_LBA           0x08 (read/write)    Index of first block in the file.
47// - BLOCK_DEVICE_OP            0x0C (write-only)    Writing here starts the operation.
48// - BLOCK_DEVICE_STATUS        0x10 (read-only)     Block Device status.
49// - BLOCK_DEVICE_IRQ_ENABLE    0x14 (read/write)    IRQ enabled if non zero.
50// - BLOCK_DEVICE_SIZE          0x18 (read-only)     Number of addressable blocks.
51// - BLOCK_DEVICE_BLOCK_SIZE    0x1C (read_only)     Block size in bytes.
52//
53// The following operations codes are supported:
54// - BLOCK_DEVICE_NOOP          No operation
55// - BLOCK_DEVICE_READ          From block device to memory
56// - BLOCK_DEVICE_WRITE         From memory to block device
57//
58// The BLOCK_DEVICE_STATUS is actually defined by the initiator FSM state.
59// The following values are defined for device status:
60// -BLOCK_DEVICE_IDLE           0
61// -BLOCK_DEVICE_BUSY           1
62// -BLOCK_DEVICE_READ_SUCCESS   2
63// -BLOCK_DEVICE_WRITE_SUCCESS  3
64// -BLOCK_DEVICE_READ_ERROR     4
65// -BLOCK_DEVICE_WRITE_ERROR    5
66//
67// In the 4 states READ_ERROR, READ_SUCCESS, WRITE_ERROR, WRITE_SUCCESS,
68// the IRQ is asserted (if it is enabled).
69// A read access to the BLOCK_DEVICE_STATUS in these 4 states reset
70// the initiator FSM state to IDLE, and acknowledge the IRQ.
71// Any write access to registers BUFFER, COUNT, LBA, OP is ignored
72// if the device is not IDLE.
73///////////////////////////////////////////////////////////////////////////
74
75#ifndef SOCLIB_VCI_BLOCK_DEVICE_TSAR_H
76#define SOCLIB_VCI_BLOCK_DEVICE_TSAR_H
77
78#include <stdint.h>
79#include <systemc>
80#include <unistd.h>
81#include "caba_base_module.h"
82#include "mapping_table.h"
83#include "vci_initiator.h"
84#include "vci_target.h"
85
86namespace soclib {
87namespace caba {
88
89using namespace sc_core;
90
91template<typename vci_param>
92class VciBlockDeviceTsar
93        : public caba::BaseModule
94{
95private:
96
97    // Registers
98    sc_signal<int>               r_target_fsm;           // target fsm state register
99    sc_signal<int>               r_initiator_fsm;    // initiator fsm state register
100    sc_signal<bool>              r_irq_enable;           // default value is true
101    sc_signal<uint32_t>          r_nblocks;              // number of blocks in transfer
102    sc_signal<uint32_t>          r_buf_address;          // memory buffer address
103    sc_signal<uint32_t>          r_lba;                  // first block index
104    sc_signal<bool>              r_read;                 // requested operation
105    sc_signal<uint32_t>          r_index;                // flit index in local buffer
106    sc_signal<uint32_t>          r_latency_count;    // latency counter
107    sc_signal<uint32_t>          r_flit_count;           // flit counter (in a burst)
108    sc_signal<uint32_t>          r_burst_count;          // burst counter (in a block)
109    sc_signal<uint32_t>          r_block_count;          // block counter (in a transfer)
110    sc_signal<uint32_t>          r_burst_offset;     // number of non aligned flits
111    sc_signal<uint32_t>          r_burst_nflits;     // number of flits in a burst
112    sc_signal<bool>              r_go;                   // command from T_FSM to M_FSM
113
114    sc_signal<sc_dt::sc_uint<vci_param::S> >    r_srcid;                // save srcid
115    sc_signal<sc_dt::sc_uint<vci_param::T> >    r_trdid;                // save trdid
116    sc_signal<sc_dt::sc_uint<vci_param::P> >    r_pktid;                // save pktid
117
118    uint32_t*                    r_local_buffer;         // capacity is one block
119
120    // structural parameters
121    soclib::common::Segment      m_segment;              // segment associated to target
122    uint32_t                     m_srcid;                // initiator index
123    int                          m_fd;                   // File descriptor
124    uint64_t                     m_device_size;          // Total number of blocks
125    const uint32_t               m_flits_per_block;      // number of flits in a block
126    const uint32_t               m_flits_per_burst;      // number of flits in a burst
127    const uint32_t               m_bursts_per_block; // number of bursts in a block
128    const uint32_t               m_latency;              // device latency
129
130    // methods
131    void transition();
132    void genMoore();
133
134    //  Master FSM states
135    enum {
136    M_IDLE              = 0,
137
138    M_READ_BLOCK        = 1,
139    M_READ_BURST        = 2,
140    M_READ_CMD          = 3,
141    M_READ_RSP          = 4,
142    M_READ_SUCCESS      = 5,
143    M_READ_ERROR        = 6,
144
145    M_WRITE_BURST       = 7,
146    M_WRITE_CMD         = 8,
147    M_WRITE_RSP         = 9,
148    M_WRITE_BLOCK       = 10,
149    M_WRITE_SUCCESS     = 11,
150    M_WRITE_ERROR       = 12,
151    };
152
153    // Target FSM states
154    enum {
155    T_IDLE              = 0,
156    T_WRITE_BUFFER      = 1,
157    T_READ_BUFFER       = 2,
158    T_WRITE_COUNT       = 3,
159    T_READ_COUNT        = 4,
160    T_WRITE_LBA         = 5,
161    T_READ_LBA          = 6,
162    T_WRITE_OP          = 7,
163    T_READ_STATUS       = 8,
164    T_WRITE_IRQEN       = 9,
165    T_READ_IRQEN        = 10,
166    T_READ_SIZE         = 11,
167    T_READ_BLOCK        = 12,
168    T_READ_ERROR        = 13,
169    T_WRITE_ERROR       = 14,
170    };
171
172    // Error codes values
173    enum {
174    VCI_READ_OK         = 0,
175    VCI_READ_ERROR      = 1,
176    VCI_WRITE_OK        = 2,
177    VCI_WRITE_ERROR     = 3,
178    };
179
180    /* transaction type, pktid field */
181    enum transaction_type_e
182    {
183      // b3 unused
184      // b2 READ / NOT READ
185      // Si READ
186      //  b1 DATA / INS
187      //  b0 UNC / MISS
188      // Si NOT READ
189      //  b1 accÚs table llsc type SW / other
190      //  b2 WRITE/CAS/LL/SC
191      TYPE_READ_DATA_UNC          = 0x0,
192      TYPE_READ_DATA_MISS         = 0x1,
193      TYPE_READ_INS_UNC           = 0x2,
194      TYPE_READ_INS_MISS          = 0x3,
195      TYPE_WRITE                  = 0x4,
196      TYPE_CAS                    = 0x5,
197      TYPE_LL                     = 0x6,
198      TYPE_SC                     = 0x7
199    };
200
201protected:
202
203    SC_HAS_PROCESS(VciBlockDeviceTsar);
204
205public:
206
207    // ports
208    sc_in<bool>                                               p_clk;
209    sc_in<bool>                                               p_resetn;
210    soclib::caba::VciInitiator<vci_param> p_vci_initiator;
211    soclib::caba::VciTarget<vci_param>    p_vci_target;
212    sc_out<bool>                                              p_irq;
213
214    void print_trace();
215
216    // Constructor   
217    VciBlockDeviceTsar(
218                sc_module_name                      name,
219                const soclib::common::MappingTable      &mt,
220                const soclib::common::IntTab            &srcid,
221                const soclib::common::IntTab            &tgtid,
222        const std::string                   &filename,
223        const uint32_t                      block_size = 512,
224        const uint32_t                      burst_size = 64,
225        const uint32_t                      latency = 0);
226};
227
228}}
229
230#endif /* SOCLIB_VCI_BLOCK_DEVICE_TSAR_H */
231
232// Local Variables:
233// tab-width: 4
234// c-basic-offset: 4
235// c-file-offsets:((innamespace . 0)(inline-open . 0))
236// indent-tabs-mode: nil
237// End:
238
239// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
240
Note: See TracBrowser for help on using the repository browser.