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

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

Introducing support for physical addresses larger than 32 bits.
A new addressable register has been defined: BLOCK_DEVICE_BUFFER_EXT

File size: 8.8 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 9 memory mapped registers,
43// taking 36 bytes in the address space.
44// - BLOCK_DEVICE_BUFFER        0x00 (read/write)    Memory buffer base address (32 LSB bits)
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// - BLOCK_DEVICE_BUFFER_EXT    0x20 (read_only)     Memory buffer base address (32 MSB bits)
53//
54// The following operations codes are supported:
55// - BLOCK_DEVICE_NOOP          No operation
56// - BLOCK_DEVICE_READ          From block device to memory
57// - BLOCK_DEVICE_WRITE         From memory to block device
58//
59// The BLOCK_DEVICE_STATUS is actually defined by the initiator FSM state.
60// The following values are defined for device status:
61// -BLOCK_DEVICE_IDLE           0
62// -BLOCK_DEVICE_BUSY           1
63// -BLOCK_DEVICE_READ_SUCCESS   2
64// -BLOCK_DEVICE_WRITE_SUCCESS  3
65// -BLOCK_DEVICE_READ_ERROR     4
66// -BLOCK_DEVICE_WRITE_ERROR    5
67//
68// In the 4 states READ_ERROR, READ_SUCCESS, WRITE_ERROR, WRITE_SUCCESS,
69// the IRQ is asserted (if it is enabled).
70// A read access to the BLOCK_DEVICE_STATUS in these 4 states reset
71// the initiator FSM state to IDLE, and acknowledge the IRQ.
72// Any write access to registers BUFFER, COUNT, LBA, OP is ignored
73// if the device is not IDLE.
74///////////////////////////////////////////////////////////////////////////
75
76#ifndef SOCLIB_VCI_BLOCK_DEVICE_TSAR_H
77#define SOCLIB_VCI_BLOCK_DEVICE_TSAR_H
78
79#include <stdint.h>
80#include <systemc>
81#include <unistd.h>
82#include "caba_base_module.h"
83#include "mapping_table.h"
84#include "vci_initiator.h"
85#include "vci_target.h"
86
87namespace soclib {
88namespace caba {
89
90using namespace sc_core;
91
92template<typename vci_param>
93class VciBlockDeviceTsar
94        : public caba::BaseModule
95{
96private:
97
98    // Registers
99    sc_signal<int>                    r_target_fsm;       // target fsm state register
100    sc_signal<int>                    r_initiator_fsm;    // initiator fsm state register
101    sc_signal<bool>                   r_irq_enable;       // default value is true
102    sc_signal<uint32_t>               r_nblocks;          // number of blocks in transfer
103    sc_signal<uint64_t>               r_buf_address;      // memory buffer address
104    sc_signal<uint32_t>               r_lba;              // first block index
105    sc_signal<bool>                   r_read;             // requested operation
106    sc_signal<uint32_t>               r_index;            // flit index in local buffer
107    sc_signal<uint32_t>               r_latency_count;    // latency counter
108    sc_signal<uint32_t>               r_flit_count;       // flit counter (in a burst)
109    sc_signal<uint32_t>               r_burst_count;      // burst counter (in a block)
110    sc_signal<uint32_t>               r_block_count;      // block counter (in a transfer)
111    sc_signal<uint32_t>               r_burst_offset;     // number of non aligned flits
112    sc_signal<uint32_t>               r_burst_nflits;     // number of flits in a burst
113    sc_signal<bool>                   r_go;               // command from T_FSM to M_FSM
114
115    sc_signal<sc_dt::sc_uint<vci_param::S> >    r_srcid;  // save srcid
116    sc_signal<sc_dt::sc_uint<vci_param::T> >    r_trdid;  // save trdid
117    sc_signal<sc_dt::sc_uint<vci_param::P> >    r_pktid;  // save pktid
118
119    uint32_t*                         r_local_buffer;     // capacity is one block
120
121    // structural parameters
122    soclib::common::Segment           m_segment;          // segment associated to target
123    uint32_t                          m_srcid;            // initiator index
124    int                               m_fd;               // File descriptor
125    uint64_t                          m_device_size;      // Total number of blocks
126    const uint32_t                    m_flits_per_block;  // number of flits in a block
127    const uint32_t                    m_flits_per_burst;  // number of flits in a burst
128    const uint32_t                    m_bursts_per_block; // number of bursts in a block
129    const uint32_t                    m_latency;          // device latency
130
131    // methods
132    void transition();
133    void genMoore();
134
135    //  Master FSM states
136    enum {
137    M_IDLE              = 0,
138
139    M_READ_BLOCK        = 1,
140    M_READ_BURST        = 2,
141    M_READ_CMD          = 3,
142    M_READ_RSP          = 4,
143    M_READ_SUCCESS      = 5,
144    M_READ_ERROR        = 6,
145
146    M_WRITE_BURST       = 7,
147    M_WRITE_CMD         = 8,
148    M_WRITE_RSP         = 9,
149    M_WRITE_BLOCK       = 10,
150    M_WRITE_SUCCESS     = 11,
151    M_WRITE_ERROR       = 12,
152    };
153
154    // Target FSM states
155    enum {
156    T_IDLE              = 0,
157    T_WRITE_BUFFER      = 1,
158    T_READ_BUFFER       = 2,
159    T_WRITE_BUFFER_EXT  = 3,
160    T_READ_BUFFER_EXT   = 4,
161    T_WRITE_COUNT       = 5,
162    T_READ_COUNT        = 6,
163    T_WRITE_LBA         = 7,
164    T_READ_LBA          = 8,
165    T_WRITE_OP          = 9,
166    T_READ_STATUS       = 10,
167    T_WRITE_IRQEN       = 11,
168    T_READ_IRQEN        = 12,
169    T_READ_SIZE         = 13,
170    T_READ_BLOCK        = 14,
171    T_READ_ERROR        = 15,
172    T_WRITE_ERROR       = 16,
173    };
174
175    // Error codes values
176    enum {
177    VCI_READ_OK         = 0,
178    VCI_READ_ERROR      = 1,
179    VCI_WRITE_OK        = 2,
180    VCI_WRITE_ERROR     = 3,
181    };
182
183    /* transaction type, pktid field */
184    enum transaction_type_e
185    {
186      // b3 unused
187      // b2 READ / NOT READ
188      // Si READ
189      //  b1 DATA / INS
190      //  b0 UNC / MISS
191      // Si NOT READ
192      //  b1 accÚs table llsc type SW / other
193      //  b2 WRITE/CAS/LL/SC
194      TYPE_READ_DATA_UNC          = 0x0,
195      TYPE_READ_DATA_MISS         = 0x1,
196      TYPE_READ_INS_UNC           = 0x2,
197      TYPE_READ_INS_MISS          = 0x3,
198      TYPE_WRITE                  = 0x4,
199      TYPE_CAS                    = 0x5,
200      TYPE_LL                     = 0x6,
201      TYPE_SC                     = 0x7
202    };
203
204protected:
205
206    SC_HAS_PROCESS(VciBlockDeviceTsar);
207
208public:
209
210    // ports
211    sc_in<bool>                                               p_clk;
212    sc_in<bool>                                               p_resetn;
213    soclib::caba::VciInitiator<vci_param> p_vci_initiator;
214    soclib::caba::VciTarget<vci_param>    p_vci_target;
215    sc_out<bool>                                              p_irq;
216
217    void print_trace();
218
219    // Constructor   
220    VciBlockDeviceTsar(
221                sc_module_name                      name,
222                const soclib::common::MappingTable      &mt,
223                const soclib::common::IntTab            &srcid,
224                const soclib::common::IntTab            &tgtid,
225        const std::string                   &filename,
226        const uint32_t                      block_size = 512,
227        const uint32_t                      burst_size = 64,
228        const uint32_t                      latency = 0);
229};
230
231}}
232
233#endif /* SOCLIB_VCI_BLOCK_DEVICE_TSAR_H */
234
235// Local Variables:
236// tab-width: 4
237// c-basic-offset: 4
238// c-file-offsets:((innamespace . 0)(inline-open . 0))
239// indent-tabs-mode: nil
240// End:
241
242// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
243
Note: See TracBrowser for help on using the repository browser.