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 | // as well as the block size (bytes), and the burst size (bytes). |
---|
36 | // This component has a DMA capability, and is both a target and an initiator. |
---|
37 | // Both read and write transfers are supported. An IRQ is optionally |
---|
38 | // asserted when the transfer is completed. |
---|
39 | // |
---|
40 | // As a target this block device controler contains 8 memory mapped registers, |
---|
41 | // taking 32 bytes in the address space. |
---|
42 | // - BLOCK_DEVICE_BUFFER 0x00 (read/write) Memory buffer base address. |
---|
43 | // - BLOCK_DEVICE_COUNT 0x04 (read/write) Number of blocks to be transfered. |
---|
44 | // - BLOCK_DEVICE_LBA 0x08 (read/write) Index of first block in the file. |
---|
45 | // - BLOCK_DEVICE_OP 0x0C (write-only) Writing here starts the operation. |
---|
46 | // - BLOCK_DEVICE_STATUS 0x10 (read-only) Block Device status. |
---|
47 | // - BLOCK_DEVICE_IRQ_ENABLE 0x14 (read/write) IRQ enabled if non zero. |
---|
48 | // - BLOCK_DEVICE_SIZE 0x18 (read-only) Number of addressable blocks. |
---|
49 | // - BLOCK_DEVICE_BLOCK_SIZE 0x1C (read_only) Block size in bytes. |
---|
50 | // |
---|
51 | // The following operations codes are supported: |
---|
52 | // - BLOCK_DEVICE_NOOP No operation |
---|
53 | // - BLOCK_DEVICE_READ From block device to memory |
---|
54 | // - BLOCK_DEVICE_WRITE From memory to block device |
---|
55 | // |
---|
56 | // The BLOCK_DEVICE_STATUS is actually defined by the initiator FSM state. |
---|
57 | // The following values are defined for device status: |
---|
58 | // -BLOCK_DEVICE_IDLE 0 |
---|
59 | // -BLOCK_DEVICE_BUSY 1 |
---|
60 | // -BLOCK_DEVICE_READ_SUCCESS 2 |
---|
61 | // -BLOCK_DEVICE_WRITE_SUCCESS 3 |
---|
62 | // -BLOCK_DEVICE_READ_ERROR 4 |
---|
63 | // -BLOCK_DEVICE_WRITE_ERROR 5 |
---|
64 | // |
---|
65 | // In the 4 states READ_ERROR, READ_SUCCESS, WRITE_ERROR, WRITE_SUCCESS, |
---|
66 | // the IRQ is asserted (if it is enabled). |
---|
67 | // A read access to the BLOCK_DEVICE_STATUS in these 4 states reset |
---|
68 | // the initiator FSM state to IDLE, and acknowledge the IRQ. |
---|
69 | // Any write access to registers BUFFER, COUNT, LBA, OP is ignored |
---|
70 | // if the device is not IDLE. |
---|
71 | /////////////////////////////////////////////////////////////////////////// |
---|
72 | |
---|
73 | #ifndef SOCLIB_VCI_BLOCK_DEVICE_TSAR_V4_H |
---|
74 | #define SOCLIB_VCI_BLOCK_DEVICE_TSAR_V4_H |
---|
75 | |
---|
76 | #include <stdint.h> |
---|
77 | #include <systemc> |
---|
78 | #include "caba_base_module.h" |
---|
79 | #include "mapping_table.h" |
---|
80 | #include "vci_target.h" |
---|
81 | |
---|
82 | namespace soclib { |
---|
83 | namespace caba { |
---|
84 | |
---|
85 | using namespace sc_core; |
---|
86 | |
---|
87 | template<typename vci_param> |
---|
88 | class VciBlockDeviceTsarV4 |
---|
89 | : public caba::BaseModule |
---|
90 | { |
---|
91 | private: |
---|
92 | |
---|
93 | // Registers |
---|
94 | sc_signal<int> r_target_fsm; // target fsm state register |
---|
95 | sc_signal<int> r_initiator_fsm; // initiator fsm state register |
---|
96 | sc_signal<bool> r_irq_enable; // default value is true |
---|
97 | sc_signal<uint32_t> r_nblocks; // number of blocks to be transfered |
---|
98 | sc_signal<uint32_t> r_buf_address; // memory buffer address |
---|
99 | sc_signal<uint32_t> r_lba; // first block index |
---|
100 | sc_signal<bool> r_read; // requested operation |
---|
101 | sc_signal<uint32_t> r_flit_count; // flit counter (in a burst) |
---|
102 | sc_signal<uint32_t> r_burst_count; // burst counter (in a block) |
---|
103 | sc_signal<uint32_t> r_block_count; // block counter (in a transfer) |
---|
104 | sc_signal<uint32_t> r_latency_count; // latency access (for each block) |
---|
105 | sc_signal<bool> r_go; // transmit command from T_FSM to M_FSM |
---|
106 | sc_signal<sc_dt::sc_uint<vci_param::S> > r_srcid; // save srcid |
---|
107 | sc_signal<sc_dt::sc_uint<vci_param::T> > r_trdid; // save trdid |
---|
108 | sc_signal<sc_dt::sc_uint<vci_param::P> > r_pktid; // save pktid |
---|
109 | |
---|
110 | uint32_t* m_local_buffer; // capacity is one block (block_size bytes) |
---|
111 | |
---|
112 | // structural parameters |
---|
113 | soclib::common::Segment m_segment; // segment associated to target |
---|
114 | uint32_t m_srcid; // initiator index |
---|
115 | int m_fd; // File descriptor |
---|
116 | uint64_t m_device_size; // Total number of blocks |
---|
117 | const uint32_t m_flits_per_block; // number of flits in a block |
---|
118 | const uint32_t m_flits_per_burst; // number of flits in a burst |
---|
119 | const uint32_t m_bursts_per_block; // number of bursts in a block |
---|
120 | const uint32_t m_latency; // device latency |
---|
121 | |
---|
122 | // methods |
---|
123 | void transition(); |
---|
124 | void genMoore(); |
---|
125 | |
---|
126 | // Master FSM states |
---|
127 | enum { |
---|
128 | M_IDLE = 0, |
---|
129 | M_READ_BLOCK = 1, |
---|
130 | M_READ_CMD = 2, |
---|
131 | M_READ_RSP = 3, |
---|
132 | M_READ_TEST = 4, |
---|
133 | M_READ_SUCCESS = 5, |
---|
134 | M_READ_ERROR = 6, |
---|
135 | M_WRITE_BLOCK = 7, |
---|
136 | M_WRITE_CMD = 8, |
---|
137 | M_WRITE_RSP = 9, |
---|
138 | M_WRITE_TEST = 10, |
---|
139 | M_WRITE_SUCCESS = 11, |
---|
140 | M_WRITE_ERROR = 12, |
---|
141 | }; |
---|
142 | |
---|
143 | // Target FSM states |
---|
144 | enum { |
---|
145 | T_IDLE = 0, |
---|
146 | T_WRITE_BUFFER = 1, |
---|
147 | T_READ_BUFFER = 2, |
---|
148 | T_WRITE_COUNT = 3, |
---|
149 | T_READ_COUNT = 4, |
---|
150 | T_WRITE_LBA = 5, |
---|
151 | T_READ_LBA = 6, |
---|
152 | T_WRITE_OP = 7, |
---|
153 | T_READ_STATUS = 8, |
---|
154 | T_WRITE_IRQEN = 9, |
---|
155 | T_READ_IRQEN = 10, |
---|
156 | T_READ_SIZE = 11, |
---|
157 | T_READ_BLOCK = 12, |
---|
158 | T_READ_ERROR = 13, |
---|
159 | T_WRITE_ERROR = 14, |
---|
160 | }; |
---|
161 | |
---|
162 | // Error codes values |
---|
163 | enum { |
---|
164 | VCI_READ_OK = 0, |
---|
165 | VCI_READ_ERROR = 1, |
---|
166 | VCI_WRITE_OK = 2, |
---|
167 | VCI_WRITE_ERROR = 3, |
---|
168 | }; |
---|
169 | |
---|
170 | protected: |
---|
171 | |
---|
172 | SC_HAS_PROCESS(VciBlockDeviceTsarV4); |
---|
173 | |
---|
174 | public: |
---|
175 | |
---|
176 | // ports |
---|
177 | sc_in<bool> p_clk; |
---|
178 | sc_in<bool> p_resetn; |
---|
179 | soclib::caba::VciInitiator<vci_param> p_vci_initiator; |
---|
180 | soclib::caba::VciTarget<vci_param> p_vci_target; |
---|
181 | sc_out<bool> p_irq; |
---|
182 | |
---|
183 | void print_trace(); |
---|
184 | |
---|
185 | // Constructor |
---|
186 | VciBlockDeviceTsarV4( |
---|
187 | sc_module_name name, |
---|
188 | const soclib::common::MappingTable &mt, |
---|
189 | const soclib::common::IntTab &srcid, |
---|
190 | const soclib::common::IntTab &tgtid, |
---|
191 | const std::string &filename, |
---|
192 | const uint32_t block_size = 512, |
---|
193 | const uint32_t burst_size = 64, |
---|
194 | const uint32_t latency = 0); |
---|
195 | }; |
---|
196 | |
---|
197 | }} |
---|
198 | |
---|
199 | #endif /* SOCLIB_VCI_BLOCK_DEVICE_TSAR_V4_H */ |
---|
200 | |
---|
201 | // Local Variables: |
---|
202 | // tab-width: 4 |
---|
203 | // c-basic-offset: 4 |
---|
204 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
205 | // indent-tabs-mode: nil |
---|
206 | // End: |
---|
207 | |
---|
208 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
209 | |
---|