1 | /* -*- c++ -*- |
---|
2 | * |
---|
3 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
4 | * |
---|
5 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
6 | * |
---|
7 | * SoCLib is free software; you can redistribute it and/or modify it |
---|
8 | * under the terms of the GNU Lesser General Public License as published |
---|
9 | * by the Free Software Foundation; version 2.1 of the License. |
---|
10 | * |
---|
11 | * SoCLib is distributed in the hope that it will be useful, but |
---|
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Lesser General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Lesser General Public |
---|
17 | * License along with SoCLib; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
19 | * 02110-1301 USA |
---|
20 | * |
---|
21 | * SOCLIB_LGPL_HEADER_END |
---|
22 | * |
---|
23 | * Copyright (c) UPMC, Lip6, Asim |
---|
24 | * alain.greiner@lip6.fr april 2011 |
---|
25 | * |
---|
26 | * Maintainers: alain |
---|
27 | */ |
---|
28 | |
---|
29 | #include <stdint.h> |
---|
30 | #include <iostream> |
---|
31 | #include <fcntl.h> |
---|
32 | #include "vci_block_device_tsar_v4.h" |
---|
33 | |
---|
34 | namespace soclib { namespace caba { |
---|
35 | |
---|
36 | #define tmpl(t) template<typename vci_param> t VciBlockDeviceTsarV4<vci_param> |
---|
37 | |
---|
38 | using namespace soclib::caba; |
---|
39 | using namespace soclib::common; |
---|
40 | |
---|
41 | //////////////////////// |
---|
42 | tmpl(void)::transition() |
---|
43 | { |
---|
44 | if(p_resetn.read() == false) |
---|
45 | { |
---|
46 | r_initiator_fsm = M_IDLE; |
---|
47 | r_target_fsm = T_IDLE; |
---|
48 | r_irq_enable = true; |
---|
49 | r_go = false; |
---|
50 | return; |
---|
51 | } |
---|
52 | |
---|
53 | ////////////////////////////////////////////////////////////////////////////// |
---|
54 | // The Target FSM controls the following registers: |
---|
55 | // r_target_fsm, r_irq_enable, r_nblocks, r_buf adress, r_lba, r_go, r_read |
---|
56 | ////////////////////////////////////////////////////////////////////////////// |
---|
57 | |
---|
58 | switch(r_target_fsm) { |
---|
59 | case T_IDLE: |
---|
60 | { |
---|
61 | if ( p_vci_target.cmdval.read() ) |
---|
62 | { |
---|
63 | r_srcid = p_vci_target.srcid.read(); |
---|
64 | r_trdid = p_vci_target.trdid.read(); |
---|
65 | r_pktid = p_vci_target.pktid.read(); |
---|
66 | sc_dt::sc_uint<vci_param::N> address = p_vci_target.address.read(); |
---|
67 | bool read = (p_vci_target.cmd.read() == vci_param::CMD_READ); |
---|
68 | uint32_t cell = (uint32_t)((address & 0x1F)>>2); |
---|
69 | |
---|
70 | if ( !read && !m_segment.contains(address) ) r_target_fsm = T_WRITE_ERROR; |
---|
71 | else if( read && !m_segment.contains(address) ) r_target_fsm = T_READ_ERROR; |
---|
72 | else if( !read && !p_vci_target.eop.read() ) r_target_fsm = T_WRITE_ERROR; |
---|
73 | else if( read && !p_vci_target.eop.read() ) r_target_fsm = T_READ_ERROR; |
---|
74 | else if( !read && (cell == BLOCK_DEVICE_BUFFER) ) r_target_fsm = T_WRITE_BUFFER; |
---|
75 | else if( read && (cell == BLOCK_DEVICE_BUFFER) ) r_target_fsm = T_READ_BUFFER; |
---|
76 | else if( !read && (cell == BLOCK_DEVICE_COUNT) ) r_target_fsm = T_WRITE_COUNT; |
---|
77 | else if( read && (cell == BLOCK_DEVICE_COUNT) ) r_target_fsm = T_READ_COUNT; |
---|
78 | else if( !read && (cell == BLOCK_DEVICE_LBA) ) r_target_fsm = T_WRITE_LBA; |
---|
79 | else if( read && (cell == BLOCK_DEVICE_LBA) ) r_target_fsm = T_READ_LBA; |
---|
80 | else if( !read && (cell == BLOCK_DEVICE_OP) ) r_target_fsm = T_WRITE_OP; |
---|
81 | else if( read && (cell == BLOCK_DEVICE_STATUS) ) r_target_fsm = T_READ_STATUS; |
---|
82 | else if( !read && (cell == BLOCK_DEVICE_IRQ_ENABLE) ) r_target_fsm = T_WRITE_IRQEN; |
---|
83 | else if( read && (cell == BLOCK_DEVICE_IRQ_ENABLE) ) r_target_fsm = T_READ_IRQEN; |
---|
84 | else if( read && (cell == BLOCK_DEVICE_SIZE) ) r_target_fsm = T_READ_SIZE; |
---|
85 | else if( read && (cell == BLOCK_DEVICE_BLOCK_SIZE) ) r_target_fsm = T_READ_BLOCK; |
---|
86 | } |
---|
87 | break; |
---|
88 | } |
---|
89 | case T_WRITE_BUFFER: |
---|
90 | { |
---|
91 | if ( r_initiator_fsm == M_IDLE ) r_buf_address = (uint32_t)p_vci_target.wdata.read(); |
---|
92 | if ( p_vci_target.rspack.read() ) r_target_fsm = T_IDLE; |
---|
93 | break; |
---|
94 | } |
---|
95 | case T_WRITE_COUNT: |
---|
96 | { |
---|
97 | if ( r_initiator_fsm == M_IDLE ) r_nblocks = (uint32_t)p_vci_target.wdata.read(); |
---|
98 | if ( p_vci_target.rspack.read() ) r_target_fsm = T_IDLE; |
---|
99 | break; |
---|
100 | } |
---|
101 | case T_WRITE_LBA: |
---|
102 | { |
---|
103 | if ( r_initiator_fsm == M_IDLE ) r_lba = (uint32_t)p_vci_target.wdata.read(); |
---|
104 | if ( p_vci_target.rspack.read() ) r_target_fsm = T_IDLE; |
---|
105 | break; |
---|
106 | } |
---|
107 | case T_WRITE_OP: |
---|
108 | { |
---|
109 | if ( r_initiator_fsm == M_IDLE ) |
---|
110 | { |
---|
111 | if ( (uint32_t)p_vci_target.wdata.read() == BLOCK_DEVICE_READ ) |
---|
112 | { |
---|
113 | r_read = true; |
---|
114 | r_go = true; |
---|
115 | } |
---|
116 | else if ( (uint32_t)p_vci_target.wdata.read() == BLOCK_DEVICE_WRITE) |
---|
117 | { |
---|
118 | r_read = false; |
---|
119 | r_go = true; |
---|
120 | } |
---|
121 | } |
---|
122 | if ( p_vci_target.rspack.read() ) r_target_fsm = T_IDLE; |
---|
123 | break; |
---|
124 | } |
---|
125 | case T_WRITE_IRQEN: |
---|
126 | { |
---|
127 | r_irq_enable = (p_vci_target.wdata.read() != 0); |
---|
128 | if ( p_vci_target.rspack.read() ) r_target_fsm = T_IDLE; |
---|
129 | break; |
---|
130 | } |
---|
131 | case T_READ_BUFFER: |
---|
132 | case T_READ_COUNT: |
---|
133 | case T_READ_LBA: |
---|
134 | case T_READ_IRQEN: |
---|
135 | case T_READ_SIZE: |
---|
136 | case T_READ_BLOCK: |
---|
137 | case T_READ_ERROR: |
---|
138 | case T_WRITE_ERROR: |
---|
139 | { |
---|
140 | if ( p_vci_target.rspack.read() ) r_target_fsm = T_IDLE; |
---|
141 | break; |
---|
142 | } |
---|
143 | case T_READ_STATUS: |
---|
144 | { |
---|
145 | if ( p_vci_target.rspack.read() ) |
---|
146 | { |
---|
147 | r_target_fsm = T_IDLE; |
---|
148 | if( (r_initiator_fsm == M_READ_SUCCESS ) || |
---|
149 | (r_initiator_fsm == M_READ_ERROR ) || |
---|
150 | (r_initiator_fsm == M_WRITE_SUCCESS) || |
---|
151 | (r_initiator_fsm == M_WRITE_ERROR ) ) r_go = false; |
---|
152 | } |
---|
153 | break; |
---|
154 | } |
---|
155 | } // end switch target fsm |
---|
156 | |
---|
157 | ///////////////////////////////////////////////////////////////////////// |
---|
158 | // The initiator FSM controls the following registers : |
---|
159 | // r_initiator_fsm, r_flit_count, r_block_count, m_local_buffer |
---|
160 | ///////////////////////////////////////////////////////////////////////// |
---|
161 | switch(r_initiator_fsm) { |
---|
162 | case M_IDLE : // waiting for activation |
---|
163 | { |
---|
164 | if ( r_go ) |
---|
165 | { |
---|
166 | r_block_count = 0; |
---|
167 | r_burst_count = 0; |
---|
168 | r_flit_count = 0; |
---|
169 | r_latency_count = m_latency; |
---|
170 | |
---|
171 | if ( r_read ) r_initiator_fsm = M_READ_BLOCK; |
---|
172 | else r_initiator_fsm = M_WRITE_CMD; |
---|
173 | } |
---|
174 | break; |
---|
175 | } |
---|
176 | case M_READ_BLOCK: // read one block from disk after waiting m_latency cycles |
---|
177 | { |
---|
178 | if ( r_latency_count == 0 ) |
---|
179 | { |
---|
180 | r_latency_count = m_latency; |
---|
181 | ::lseek(m_fd, (r_lba + r_block_count)*m_flits_per_block*vci_param::B, SEEK_SET); |
---|
182 | if( ::read(m_fd, m_local_buffer, m_flits_per_block*vci_param::B) < 0 ) |
---|
183 | { |
---|
184 | r_initiator_fsm = M_READ_ERROR; |
---|
185 | } |
---|
186 | else |
---|
187 | { |
---|
188 | r_initiator_fsm = M_READ_CMD; |
---|
189 | } |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | r_latency_count = r_latency_count - 1; |
---|
194 | } |
---|
195 | break; |
---|
196 | } |
---|
197 | case M_READ_CMD: // This is actually a multi-flits VCI WRITE command |
---|
198 | { |
---|
199 | if ( p_vci_initiator.cmdack.read() ) |
---|
200 | { |
---|
201 | if ( r_flit_count == (m_flits_per_burst - 1) ) |
---|
202 | { |
---|
203 | r_initiator_fsm = M_READ_RSP; |
---|
204 | r_flit_count = 0; |
---|
205 | } |
---|
206 | else |
---|
207 | { |
---|
208 | r_flit_count = r_flit_count + 1; |
---|
209 | } |
---|
210 | } |
---|
211 | break; |
---|
212 | } |
---|
213 | case M_READ_RSP: // This is actually a single flit VCI WRITE response |
---|
214 | { |
---|
215 | if ( p_vci_initiator.rspval.read() ) |
---|
216 | { |
---|
217 | if ( (p_vci_initiator.rerror.read()&0x1) == 0 ) r_initiator_fsm = M_READ_TEST; |
---|
218 | else r_initiator_fsm = M_READ_ERROR; |
---|
219 | } |
---|
220 | break; |
---|
221 | } |
---|
222 | case M_READ_TEST: |
---|
223 | { |
---|
224 | if ( r_burst_count.read() == (m_bursts_per_block - 1) ) |
---|
225 | { |
---|
226 | if ( r_block_count.read() == (r_nblocks.read() - 1) ) // last burst of the last block |
---|
227 | { |
---|
228 | r_burst_count = 0; |
---|
229 | r_block_count = 0; |
---|
230 | r_initiator_fsm = M_READ_SUCCESS; |
---|
231 | } |
---|
232 | else // last burst but not last block |
---|
233 | { |
---|
234 | r_burst_count = 0; |
---|
235 | r_block_count = r_block_count.read() + 1; |
---|
236 | r_initiator_fsm = M_READ_BLOCK; |
---|
237 | } |
---|
238 | } |
---|
239 | else // not the last burst of the block |
---|
240 | { |
---|
241 | r_burst_count = r_burst_count.read() + 1; |
---|
242 | r_initiator_fsm = M_READ_CMD; |
---|
243 | } |
---|
244 | break; |
---|
245 | } |
---|
246 | case M_READ_SUCCESS: |
---|
247 | { |
---|
248 | if( !r_go ) r_initiator_fsm = M_IDLE; |
---|
249 | break; |
---|
250 | } |
---|
251 | case M_READ_ERROR: |
---|
252 | { |
---|
253 | if( !r_go ) r_initiator_fsm = M_IDLE; |
---|
254 | break; |
---|
255 | } |
---|
256 | case M_WRITE_CMD: // This is actually a single flit VCI READ command |
---|
257 | { |
---|
258 | if ( p_vci_initiator.cmdack.read() ) r_initiator_fsm = M_WRITE_RSP; |
---|
259 | break; |
---|
260 | } |
---|
261 | case M_WRITE_RSP: // This is actually a multi-flits VCI READ response |
---|
262 | { |
---|
263 | if ( p_vci_initiator.rspval.read() ) |
---|
264 | { |
---|
265 | uint32_t index = (r_burst_count.read()*m_flits_per_burst) + r_flit_count.read(); |
---|
266 | m_local_buffer[index] = (uint32_t)p_vci_initiator.rdata.read(); |
---|
267 | if ( p_vci_initiator.reop.read() ) |
---|
268 | { |
---|
269 | r_flit_count = 0; |
---|
270 | if( (p_vci_initiator.rerror.read()&0x1) == 0 ) r_initiator_fsm = M_WRITE_TEST; |
---|
271 | else r_initiator_fsm = M_WRITE_ERROR; |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | r_flit_count = r_flit_count.read() + 1; |
---|
276 | } |
---|
277 | } |
---|
278 | break; |
---|
279 | } |
---|
280 | case M_WRITE_TEST: |
---|
281 | { |
---|
282 | if ( r_burst_count.read() == (m_bursts_per_block - 1) ) // last burst of the block |
---|
283 | { |
---|
284 | r_burst_count = 0; |
---|
285 | r_block_count = r_block_count.read() + 1; |
---|
286 | r_initiator_fsm = M_WRITE_BLOCK; |
---|
287 | } |
---|
288 | else // not the last burst |
---|
289 | { |
---|
290 | r_burst_count = r_burst_count.read() + 1; |
---|
291 | r_initiator_fsm = M_WRITE_CMD; |
---|
292 | } |
---|
293 | break; |
---|
294 | } |
---|
295 | case M_WRITE_BLOCK: // write a block to disk after waiting m_latency cycles |
---|
296 | { |
---|
297 | if ( r_latency_count == 0 ) |
---|
298 | { |
---|
299 | r_latency_count = m_latency; |
---|
300 | ::lseek(m_fd, (r_lba + r_block_count)*m_flits_per_block*vci_param::B, SEEK_SET); |
---|
301 | if( ::write(m_fd, m_local_buffer, m_flits_per_block*vci_param::B) < 0 ) |
---|
302 | { |
---|
303 | r_initiator_fsm = M_WRITE_ERROR; |
---|
304 | } |
---|
305 | else if ( r_block_count.read() == r_nblocks.read() ) |
---|
306 | { |
---|
307 | r_initiator_fsm = M_WRITE_SUCCESS; |
---|
308 | } |
---|
309 | else |
---|
310 | { |
---|
311 | r_initiator_fsm = M_WRITE_CMD; |
---|
312 | } |
---|
313 | } |
---|
314 | else |
---|
315 | { |
---|
316 | r_latency_count = r_latency_count - 1; |
---|
317 | } |
---|
318 | break; |
---|
319 | } |
---|
320 | case M_WRITE_SUCCESS: |
---|
321 | { |
---|
322 | if( !r_go ) r_initiator_fsm = M_IDLE; |
---|
323 | break; |
---|
324 | } |
---|
325 | case M_WRITE_ERROR: |
---|
326 | { |
---|
327 | if( !r_go ) r_initiator_fsm = M_IDLE; |
---|
328 | break; |
---|
329 | } |
---|
330 | } // end switch r_initiator_fsm |
---|
331 | } // end transition |
---|
332 | |
---|
333 | ////////////////////// |
---|
334 | tmpl(void)::genMoore() |
---|
335 | { |
---|
336 | sc_dt::sc_uint<vci_param::N> offset; |
---|
337 | uint32_t index; |
---|
338 | |
---|
339 | // p_vci_target port |
---|
340 | p_vci_target.rsrcid = (sc_dt::sc_uint<vci_param::S>)r_srcid.read(); |
---|
341 | p_vci_target.rtrdid = (sc_dt::sc_uint<vci_param::T>)r_trdid.read(); |
---|
342 | p_vci_target.rpktid = (sc_dt::sc_uint<vci_param::P>)r_pktid.read(); |
---|
343 | p_vci_target.reop = true; |
---|
344 | |
---|
345 | switch(r_target_fsm) { |
---|
346 | case T_IDLE: |
---|
347 | p_vci_target.cmdack = true; |
---|
348 | p_vci_target.rspval = false; |
---|
349 | break; |
---|
350 | case T_READ_STATUS: |
---|
351 | p_vci_target.cmdack = false; |
---|
352 | p_vci_target.rspval = true; |
---|
353 | if (r_initiator_fsm == M_IDLE) p_vci_target.rdata = BLOCK_DEVICE_IDLE; |
---|
354 | else if(r_initiator_fsm == M_READ_SUCCESS) p_vci_target.rdata = BLOCK_DEVICE_READ_SUCCESS; |
---|
355 | else if(r_initiator_fsm == M_WRITE_SUCCESS) p_vci_target.rdata = BLOCK_DEVICE_WRITE_SUCCESS; |
---|
356 | else if(r_initiator_fsm == M_READ_ERROR) p_vci_target.rdata = BLOCK_DEVICE_READ_ERROR; |
---|
357 | else if(r_initiator_fsm == M_WRITE_ERROR) p_vci_target.rdata = BLOCK_DEVICE_WRITE_ERROR; |
---|
358 | else p_vci_target.rdata = BLOCK_DEVICE_BUSY; |
---|
359 | p_vci_target.rerror = VCI_READ_OK; |
---|
360 | break; |
---|
361 | case T_READ_BUFFER: |
---|
362 | p_vci_target.cmdack = false; |
---|
363 | p_vci_target.rspval = true; |
---|
364 | p_vci_target.rdata = (uint32_t)r_buf_address; |
---|
365 | p_vci_target.rerror = VCI_READ_OK; |
---|
366 | break; |
---|
367 | case T_READ_COUNT: |
---|
368 | p_vci_target.cmdack = false; |
---|
369 | p_vci_target.rspval = true; |
---|
370 | p_vci_target.rdata = (uint32_t)r_nblocks; |
---|
371 | p_vci_target.rerror = VCI_READ_OK; |
---|
372 | break; |
---|
373 | case T_READ_LBA: |
---|
374 | p_vci_target.cmdack = false; |
---|
375 | p_vci_target.rspval = true; |
---|
376 | p_vci_target.rdata = (uint32_t)r_lba; |
---|
377 | p_vci_target.rerror = VCI_READ_OK; |
---|
378 | break; |
---|
379 | case T_READ_IRQEN: |
---|
380 | p_vci_target.cmdack = false; |
---|
381 | p_vci_target.rspval = true; |
---|
382 | p_vci_target.rdata = (uint32_t)r_irq_enable; |
---|
383 | p_vci_target.rerror = VCI_READ_OK; |
---|
384 | break; |
---|
385 | case T_READ_SIZE: |
---|
386 | p_vci_target.cmdack = false; |
---|
387 | p_vci_target.rspval = true; |
---|
388 | p_vci_target.rdata = (uint32_t)m_device_size; |
---|
389 | p_vci_target.rerror = VCI_READ_OK; |
---|
390 | break; |
---|
391 | case T_READ_BLOCK: |
---|
392 | p_vci_target.cmdack = false; |
---|
393 | p_vci_target.rspval = true; |
---|
394 | p_vci_target.rdata = (uint32_t)m_flits_per_block*vci_param::B; |
---|
395 | p_vci_target.rerror = VCI_READ_OK; |
---|
396 | break; |
---|
397 | case T_READ_ERROR: |
---|
398 | p_vci_target.cmdack = false; |
---|
399 | p_vci_target.rspval = true; |
---|
400 | p_vci_target.rdata = 0; |
---|
401 | p_vci_target.rerror = VCI_READ_ERROR; |
---|
402 | break; |
---|
403 | case T_WRITE_ERROR: |
---|
404 | p_vci_target.cmdack = false; |
---|
405 | p_vci_target.rspval = true; |
---|
406 | p_vci_target.rdata = 0; |
---|
407 | p_vci_target.rerror = VCI_WRITE_ERROR; |
---|
408 | break; |
---|
409 | default: |
---|
410 | p_vci_target.cmdack = false; |
---|
411 | p_vci_target.rspval = true; |
---|
412 | p_vci_target.rdata = 0; |
---|
413 | p_vci_target.rerror = VCI_WRITE_OK; |
---|
414 | break; |
---|
415 | } // end switch target fsm |
---|
416 | |
---|
417 | // p_vci_initiator port |
---|
418 | p_vci_initiator.srcid = (sc_dt::sc_uint<vci_param::S>)m_srcid; |
---|
419 | p_vci_initiator.trdid = 0; |
---|
420 | p_vci_initiator.pktid = 0; |
---|
421 | p_vci_initiator.contig = true; |
---|
422 | p_vci_initiator.cons = false; |
---|
423 | p_vci_initiator.wrap = false; |
---|
424 | p_vci_initiator.cfixed = false; |
---|
425 | p_vci_initiator.clen = 0; |
---|
426 | |
---|
427 | switch (r_initiator_fsm) { |
---|
428 | case M_WRITE_CMD: // It is actually a single flit VCI read command |
---|
429 | offset = (r_block_count.read()*m_flits_per_block + |
---|
430 | r_burst_count.read()*m_flits_per_burst) * vci_param::B; |
---|
431 | p_vci_initiator.rspack = false; |
---|
432 | p_vci_initiator.cmdval = true; |
---|
433 | p_vci_initiator.address = (sc_dt::sc_uint<vci_param::N>)r_buf_address.read() + offset; |
---|
434 | p_vci_initiator.cmd = vci_param::CMD_READ; |
---|
435 | p_vci_initiator.wdata = 0; |
---|
436 | p_vci_initiator.be = (uint32_t)0xF; |
---|
437 | p_vci_initiator.plen = (sc_dt::sc_uint<vci_param::K>)m_flits_per_burst*vci_param::B; |
---|
438 | p_vci_initiator.eop = true; |
---|
439 | break; |
---|
440 | case M_READ_CMD: // It is actually a multi-flits VCI WRITE command |
---|
441 | offset = ( r_block_count.read()*m_flits_per_block + |
---|
442 | r_burst_count.read()*m_flits_per_burst + |
---|
443 | r_flit_count.read() ) * vci_param::B; |
---|
444 | index = (r_burst_count.read()*m_flits_per_burst) + r_flit_count.read(); |
---|
445 | p_vci_initiator.rspack = false; |
---|
446 | p_vci_initiator.cmdval = true; |
---|
447 | p_vci_initiator.address = (sc_dt::sc_uint<vci_param::N>)r_buf_address.read() + offset; |
---|
448 | p_vci_initiator.cmd = vci_param::CMD_WRITE; |
---|
449 | p_vci_initiator.wdata = (uint32_t)m_local_buffer[index]; |
---|
450 | p_vci_initiator.be = 0xF; |
---|
451 | p_vci_initiator.plen = (sc_dt::sc_uint<vci_param::K>)m_flits_per_burst*vci_param::B; |
---|
452 | p_vci_initiator.eop = ( r_flit_count.read() == (m_flits_per_burst - 1) ); |
---|
453 | break; |
---|
454 | case M_READ_RSP: |
---|
455 | case M_WRITE_RSP: |
---|
456 | p_vci_initiator.rspack = true; |
---|
457 | p_vci_initiator.cmdval = false; |
---|
458 | break; |
---|
459 | default: |
---|
460 | p_vci_initiator.rspack = false; |
---|
461 | p_vci_initiator.cmdval = false; |
---|
462 | break; |
---|
463 | } |
---|
464 | |
---|
465 | // IRQ signal |
---|
466 | if(((r_initiator_fsm == M_READ_SUCCESS) || |
---|
467 | (r_initiator_fsm == M_WRITE_SUCCESS) || |
---|
468 | (r_initiator_fsm == M_READ_ERROR) || |
---|
469 | (r_initiator_fsm == M_WRITE_ERROR) ) && r_irq_enable) p_irq = true; |
---|
470 | else p_irq = false; |
---|
471 | } // end GenMoore() |
---|
472 | |
---|
473 | ////////////////////////////////////////////////////////////////////////////// |
---|
474 | tmpl(/**/)::VciBlockDeviceTsarV4( sc_core::sc_module_name name, |
---|
475 | const soclib::common::MappingTable &mt, |
---|
476 | const soclib::common::IntTab &srcid, |
---|
477 | const soclib::common::IntTab &tgtid, |
---|
478 | const std::string &filename, |
---|
479 | const uint32_t block_size, |
---|
480 | const uint32_t burst_size, |
---|
481 | const uint32_t latency) |
---|
482 | |
---|
483 | : caba::BaseModule(name), |
---|
484 | m_segment(mt.getSegment(tgtid)), |
---|
485 | m_srcid(mt.indexForId(srcid)), |
---|
486 | m_flits_per_block(block_size/vci_param::B), |
---|
487 | m_flits_per_burst(burst_size/vci_param::B), |
---|
488 | m_bursts_per_block(block_size/burst_size), |
---|
489 | m_latency(latency), |
---|
490 | p_clk("p_clk"), |
---|
491 | p_resetn("p_resetn"), |
---|
492 | p_vci_initiator("p_vci_initiator"), |
---|
493 | p_vci_target("p_vci_target"), |
---|
494 | p_irq("p_irq") |
---|
495 | { |
---|
496 | SC_METHOD(transition); |
---|
497 | sensitive_pos << p_clk; |
---|
498 | |
---|
499 | SC_METHOD(genMoore); |
---|
500 | sensitive_neg << p_clk; |
---|
501 | |
---|
502 | if( (block_size != 64 ) && |
---|
503 | (block_size != 128) && |
---|
504 | (block_size != 256) && |
---|
505 | (block_size != 512) && |
---|
506 | (block_size != 1024) && |
---|
507 | (block_size != 2048) && |
---|
508 | (block_size != 4096) ) |
---|
509 | { |
---|
510 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
---|
511 | std::cout << "The block size must be 128, 256, 512, 1024, 2048 or 4096 bytes" << std::endl; |
---|
512 | exit(1); |
---|
513 | } |
---|
514 | if ( m_segment.size() < 32 ) |
---|
515 | { |
---|
516 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
---|
517 | std::cout << "The size of the segment cannot be smaller than 32 bytes" << std::endl; |
---|
518 | exit(1); |
---|
519 | } |
---|
520 | if ( (m_segment.baseAddress() & 0x0000001F) != 0 ) |
---|
521 | { |
---|
522 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
---|
523 | std::cout << "The base address of the segment must be multiple of 32 bytes" << std::endl; |
---|
524 | exit(1); |
---|
525 | } |
---|
526 | if ( block_size%burst_size != 0 ) |
---|
527 | { |
---|
528 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
---|
529 | std::cout << "The block_size parameter must be a multiple of the burst_size" << std::endl; |
---|
530 | exit(1); |
---|
531 | } |
---|
532 | if ( vci_param::B != 4 ) |
---|
533 | { |
---|
534 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
---|
535 | std::cout << "The VCI data fields must have 32 bits" << std::endl; |
---|
536 | exit(1); |
---|
537 | } |
---|
538 | m_fd = ::open(filename.c_str(), O_RDWR); |
---|
539 | if ( m_fd < 0 ) |
---|
540 | { |
---|
541 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
---|
542 | std::cout << "Unable to open file " << filename << std::endl; |
---|
543 | exit(1); |
---|
544 | } |
---|
545 | m_device_size = lseek(m_fd, 0, SEEK_END) / block_size; |
---|
546 | if ( m_device_size > ((uint64_t)1<<32) ) |
---|
547 | { |
---|
548 | std::cout << "Warning: block device " << name << std::endl; |
---|
549 | std::cout << "The file " << filename << std::endl; |
---|
550 | std::cout << "has more blocks than addressable with the 32 bits PIBUS address" << std::endl; |
---|
551 | m_device_size = ((uint64_t)1<<32); |
---|
552 | } |
---|
553 | |
---|
554 | m_local_buffer = new uint32_t[m_flits_per_block]; |
---|
555 | /* |
---|
556 | std::cout << std::endl << "Instanciation of VciBlockDeviceTsarV4 : " << name << std::endl; |
---|
557 | std::cout << " file_name = " << filename << std::endl; |
---|
558 | std::cout << " burst_size = " << std::dec << m_flits_per_burst*vci_param::B << std::endl; |
---|
559 | std::cout << " block_size = " << std::dec << m_flits_per_block*vci_param::B << std::endl; |
---|
560 | std::cout << " latency = " << std::dec << m_latency << std::endl; |
---|
561 | std::cout << " segment " << m_segment.name() |
---|
562 | << " | base = 0x" << std::hex << m_segment.baseAddress() |
---|
563 | << " | size = " << std::dec << m_segment.size() << std::endl; |
---|
564 | */ |
---|
565 | } // end constructor |
---|
566 | |
---|
567 | ////////////////////////// |
---|
568 | tmpl(void)::print_trace() |
---|
569 | { |
---|
570 | const char* initiator_str[] = { |
---|
571 | "IDLE ", |
---|
572 | "READ_BLOCK ", |
---|
573 | "READ_CMD ", |
---|
574 | "READ_RSP ", |
---|
575 | "READ_TEST ", |
---|
576 | "READ_SUCCESS ", |
---|
577 | "READ_ERROR ", |
---|
578 | "WRITE_BLOCK ", |
---|
579 | "WRITE_CMD ", |
---|
580 | "WRITE_RSP ", |
---|
581 | "WRITE_TEST ", |
---|
582 | "WRITE_SUCCESS", |
---|
583 | "WRITE_ERROR ", |
---|
584 | }; |
---|
585 | const char* target_str[] = { |
---|
586 | "IDLE ", |
---|
587 | "WRITE_BUFFER", |
---|
588 | "READ_BUFFER ", |
---|
589 | "WRITE_COUNT ", |
---|
590 | "READ_COUNT ", |
---|
591 | "WRITE_LBA ", |
---|
592 | "READ_LBA ", |
---|
593 | "WRITE_OP ", |
---|
594 | "READ_STATUS ", |
---|
595 | "WRITE_IRQEN ", |
---|
596 | "READ_IRQEN ", |
---|
597 | "READ_SIZE ", |
---|
598 | "READ_BLOCK ", |
---|
599 | "READ_ERROR ", |
---|
600 | "WRITE_ERROR ", |
---|
601 | }; |
---|
602 | |
---|
603 | std::cout << "BDEV_TGT : " << target_str[r_target_fsm.read()] |
---|
604 | << " BDEV_INI : " << initiator_str[r_initiator_fsm.read()] |
---|
605 | << " block = " << r_block_count.read() |
---|
606 | << " burst = " << r_burst_count.read() |
---|
607 | << " flit = " << r_flit_count.read() <<std::endl; |
---|
608 | } |
---|
609 | |
---|
610 | |
---|
611 | }} // end namespace |
---|
612 | |
---|
613 | // Local Variables: |
---|
614 | // tab-width: 4 |
---|
615 | // c-basic-offset: 4 |
---|
616 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
617 | // indent-tabs-mode: nil |
---|
618 | // End: |
---|
619 | |
---|
620 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
621 | |
---|