| 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 "vci_block_device_tsar_v4.h" |
|---|
| 30 | #include <stdint.h> |
|---|
| 31 | #include <iostream> |
|---|
| 32 | #include <fcntl.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_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 block 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*4, SEEK_SET); |
|---|
| 182 | if( ::read(m_fd, m_local_buffer, m_flits_per_block*4) < 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_BLOCK; |
|---|
| 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 | } // not the last burst |
|---|
| 288 | else |
|---|
| 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*4, SEEK_SET); |
|---|
| 301 | if( ::write(m_fd, m_local_buffer, m_flits_per_block*4) < 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 | |
|---|
| 332 | } // end transition |
|---|
| 333 | |
|---|
| 334 | ////////////////////// |
|---|
| 335 | tmpl(void)::genMoore() |
|---|
| 336 | { |
|---|
| 337 | sc_uint<vci_param::N> offset; |
|---|
| 338 | uint32_t index; |
|---|
| 339 | |
|---|
| 340 | // p_vci_target port |
|---|
| 341 | p_vci_target.rsrcid = (sc_uint<vci_param::S>)r_srcid.read(); |
|---|
| 342 | p_vci_target.rtrdid = (sc_uint<vci_param::T>)r_trdid.read(); |
|---|
| 343 | p_vci_target.rpktid = (sc_uint<vci_param::P>)r_pktid.read(); |
|---|
| 344 | p_vci_target.reop = true; |
|---|
| 345 | |
|---|
| 346 | switch(r_target_fsm) { |
|---|
| 347 | case T_IDLE: |
|---|
| 348 | p_vci_target.cmdack = true; |
|---|
| 349 | p_vci_target.rspval = false; |
|---|
| 350 | break; |
|---|
| 351 | case T_READ_STATUS: |
|---|
| 352 | p_vci_target.cmdack = false; |
|---|
| 353 | p_vci_target.rspval = true; |
|---|
| 354 | if (r_initiator_fsm == M_IDLE) p_vci_target.rdata = BLOCK_DEVICE_IDLE; |
|---|
| 355 | else if(r_initiator_fsm == M_READ_SUCCESS) p_vci_target.rdata = BLOCK_DEVICE_READ_SUCCESS; |
|---|
| 356 | else if(r_initiator_fsm == M_WRITE_SUCCESS) p_vci_target.rdata = BLOCK_DEVICE_WRITE_SUCCESS; |
|---|
| 357 | else if(r_initiator_fsm == M_READ_ERROR) p_vci_target.rdata = BLOCK_DEVICE_READ_ERROR; |
|---|
| 358 | else if(r_initiator_fsm == M_WRITE_ERROR) p_vci_target.rdata = BLOCK_DEVICE_WRITE_ERROR; |
|---|
| 359 | else p_vci_target.rdata = BLOCK_DEVICE_BUSY; |
|---|
| 360 | p_vci_target.rerror = VCI_READ_OK; |
|---|
| 361 | break; |
|---|
| 362 | case T_READ_BUFFER: |
|---|
| 363 | p_vci_target.cmdack = false; |
|---|
| 364 | p_vci_target.rspval = true; |
|---|
| 365 | p_vci_target.rdata = (uint32_t)r_buf_address; |
|---|
| 366 | p_vci_target.rerror = VCI_READ_OK; |
|---|
| 367 | break; |
|---|
| 368 | case T_READ_COUNT: |
|---|
| 369 | p_vci_target.cmdack = false; |
|---|
| 370 | p_vci_target.rspval = true; |
|---|
| 371 | p_vci_target.rdata = (uint32_t)r_nblocks; |
|---|
| 372 | p_vci_target.rerror = VCI_READ_OK; |
|---|
| 373 | break; |
|---|
| 374 | case T_READ_LBA: |
|---|
| 375 | p_vci_target.cmdack = false; |
|---|
| 376 | p_vci_target.rspval = true; |
|---|
| 377 | p_vci_target.rdata = (uint32_t)r_lba; |
|---|
| 378 | p_vci_target.rerror = VCI_READ_OK; |
|---|
| 379 | break; |
|---|
| 380 | case T_READ_IRQEN: |
|---|
| 381 | p_vci_target.cmdack = false; |
|---|
| 382 | p_vci_target.rspval = true; |
|---|
| 383 | p_vci_target.rdata = (uint32_t)r_irq_enable; |
|---|
| 384 | p_vci_target.rerror = VCI_READ_OK; |
|---|
| 385 | break; |
|---|
| 386 | case T_READ_SIZE: |
|---|
| 387 | p_vci_target.cmdack = false; |
|---|
| 388 | p_vci_target.rspval = true; |
|---|
| 389 | p_vci_target.rdata = (uint32_t)m_device_size; |
|---|
| 390 | p_vci_target.rerror = VCI_READ_OK; |
|---|
| 391 | break; |
|---|
| 392 | case T_READ_BLOCK: |
|---|
| 393 | p_vci_target.cmdack = false; |
|---|
| 394 | p_vci_target.rspval = true; |
|---|
| 395 | p_vci_target.rdata = (uint32_t)m_flits_per_block; |
|---|
| 396 | p_vci_target.rerror = VCI_READ_OK; |
|---|
| 397 | break; |
|---|
| 398 | case T_READ_ERROR: |
|---|
| 399 | p_vci_target.cmdack = false; |
|---|
| 400 | p_vci_target.rspval = true; |
|---|
| 401 | p_vci_target.rdata = 0; |
|---|
| 402 | p_vci_target.rerror = VCI_READ_ERROR; |
|---|
| 403 | break; |
|---|
| 404 | case T_WRITE_ERROR: |
|---|
| 405 | p_vci_target.cmdack = false; |
|---|
| 406 | p_vci_target.rspval = true; |
|---|
| 407 | p_vci_target.rdata = 0; |
|---|
| 408 | p_vci_target.rerror = VCI_WRITE_ERROR; |
|---|
| 409 | break; |
|---|
| 410 | default: |
|---|
| 411 | p_vci_target.cmdack = false; |
|---|
| 412 | p_vci_target.rspval = true; |
|---|
| 413 | p_vci_target.rdata = 0; |
|---|
| 414 | p_vci_target.rerror = VCI_WRITE_OK; |
|---|
| 415 | break; |
|---|
| 416 | } // end switch target fsm |
|---|
| 417 | |
|---|
| 418 | // p_vci_initiator port |
|---|
| 419 | p_vci_initiator.srcid = (sc_uint<vci_param::S>)m_srcid; |
|---|
| 420 | p_vci_initiator.trdid = 0; |
|---|
| 421 | p_vci_initiator.pktid = 0; |
|---|
| 422 | p_vci_initiator.contig = true; |
|---|
| 423 | p_vci_initiator.cons = false; |
|---|
| 424 | p_vci_initiator.wrap = false; |
|---|
| 425 | p_vci_initiator.cfixed = false; |
|---|
| 426 | p_vci_initiator.clen = 0; |
|---|
| 427 | |
|---|
| 428 | switch (r_initiator_fsm) { |
|---|
| 429 | case M_WRITE_CMD: // It is actually a single flit VCI read command |
|---|
| 430 | offset = (r_block_count.read()*m_flits_per_block + |
|---|
| 431 | r_burst_count.read()*m_flits_per_burst) * vci_param::B; |
|---|
| 432 | p_vci_initiator.rspack = false; |
|---|
| 433 | p_vci_initiator.cmdval = true; |
|---|
| 434 | p_vci_initiator.address = (sc_uint<vci_param::N>)r_buf_address.read() + offset; |
|---|
| 435 | p_vci_initiator.cmd = vci_param::CMD_READ; |
|---|
| 436 | p_vci_initiator.wdata = 0; |
|---|
| 437 | p_vci_initiator.be = (uint32_t)0xF; |
|---|
| 438 | p_vci_initiator.plen = (sc_uint<vci_param::K>)m_flits_per_burst*vci_param::B; |
|---|
| 439 | p_vci_initiator.eop = true; |
|---|
| 440 | break; |
|---|
| 441 | case M_READ_CMD: // It is actually a multi-flits VCI WRITE command |
|---|
| 442 | offset = ( r_block_count.read()*m_flits_per_block + |
|---|
| 443 | r_burst_count.read()*m_flits_per_burst + |
|---|
| 444 | r_flit_count.read() ) * vci_param::B; |
|---|
| 445 | index = (r_burst_count.read()*m_flits_per_burst) + r_flit_count.read(); |
|---|
| 446 | p_vci_initiator.rspack = false; |
|---|
| 447 | p_vci_initiator.cmdval = true; |
|---|
| 448 | p_vci_initiator.address = (sc_uint<vci_param::N>)r_buf_address.read() + offset; |
|---|
| 449 | p_vci_initiator.cmd = vci_param::CMD_WRITE; |
|---|
| 450 | p_vci_initiator.wdata = (uint32_t)m_local_buffer[index]; |
|---|
| 451 | p_vci_initiator.be = 0xF; |
|---|
| 452 | p_vci_initiator.plen = (sc_uint<vci_param::K>)m_flits_per_burst*vci_param::B; |
|---|
| 453 | p_vci_initiator.eop = ( r_flit_count.read() == (m_flits_per_burst - 1) ); |
|---|
| 454 | break; |
|---|
| 455 | case M_READ_RSP: |
|---|
| 456 | case M_WRITE_RSP: |
|---|
| 457 | p_vci_initiator.rspack = true; |
|---|
| 458 | p_vci_initiator.cmdval = false; |
|---|
| 459 | break; |
|---|
| 460 | default: |
|---|
| 461 | p_vci_initiator.rspack = false; |
|---|
| 462 | p_vci_initiator.cmdval = false; |
|---|
| 463 | break; |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | // IRQ signal |
|---|
| 467 | if(((r_initiator_fsm == M_READ_SUCCESS) || |
|---|
| 468 | (r_initiator_fsm == M_WRITE_SUCCESS) || |
|---|
| 469 | (r_initiator_fsm == M_READ_ERROR) || |
|---|
| 470 | (r_initiator_fsm == M_WRITE_ERROR) ) && r_irq_enable) p_irq = true; |
|---|
| 471 | else p_irq = false; |
|---|
| 472 | } // end GenMoore() |
|---|
| 473 | |
|---|
| 474 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 475 | tmpl(/**/)::VciBlockDeviceTsarV4( sc_core::sc_module_name name, |
|---|
| 476 | const soclib::common::MappingTable &mt, |
|---|
| 477 | const soclib::common::IntTab &srcid, |
|---|
| 478 | const soclib::common::IntTab &tgtid, |
|---|
| 479 | const std::string &filename, |
|---|
| 480 | const uint32_t block_size, |
|---|
| 481 | const uint32_t burst_size, |
|---|
| 482 | const uint32_t latency) |
|---|
| 483 | |
|---|
| 484 | : caba::BaseModule(name), |
|---|
| 485 | m_segment(mt.getSegment(tgtid)), |
|---|
| 486 | m_srcid(mt.indexForId(srcid)), |
|---|
| 487 | m_flits_per_block(block_size/vci_param::B), |
|---|
| 488 | m_flits_per_burst(burst_size/vci_param::B), |
|---|
| 489 | m_bursts_per_block(block_size/burst_size), |
|---|
| 490 | m_latency(latency), |
|---|
| 491 | p_clk("p_clk"), |
|---|
| 492 | p_resetn("p_resetn"), |
|---|
| 493 | p_vci_initiator("p_vci_initiator"), |
|---|
| 494 | p_vci_target("p_vci_target"), |
|---|
| 495 | p_irq("p_irq") |
|---|
| 496 | { |
|---|
| 497 | SC_METHOD(transition); |
|---|
| 498 | sensitive_pos << p_clk; |
|---|
| 499 | |
|---|
| 500 | SC_METHOD(genMoore); |
|---|
| 501 | sensitive_neg << p_clk; |
|---|
| 502 | |
|---|
| 503 | if( (block_size != 64 ) && |
|---|
| 504 | (block_size != 128) && |
|---|
| 505 | (block_size != 256) && |
|---|
| 506 | (block_size != 512) && |
|---|
| 507 | (block_size != 1024) ) |
|---|
| 508 | { |
|---|
| 509 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
|---|
| 510 | std::cout << "The block size must be 128, 256, 512 or 1024 bytes" << std::endl; |
|---|
| 511 | exit(1); |
|---|
| 512 | } |
|---|
| 513 | if ( m_segment.size() < 32 ) |
|---|
| 514 | { |
|---|
| 515 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
|---|
| 516 | std::cout << "The size of the segment cannot be smaller than 32 bytes" << std::endl; |
|---|
| 517 | exit(1); |
|---|
| 518 | } |
|---|
| 519 | if ( (m_segment.baseAddress() & 0x0000001F) != 0 ) |
|---|
| 520 | { |
|---|
| 521 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
|---|
| 522 | std::cout << "The base address of the segment must be multiple of 32 bytes" << std::endl; |
|---|
| 523 | exit(1); |
|---|
| 524 | } |
|---|
| 525 | if ( block_size%burst_size != 0 ) |
|---|
| 526 | { |
|---|
| 527 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
|---|
| 528 | std::cout << "The block_size parameter must be a multiple of the burst_size" << std::endl; |
|---|
| 529 | exit(1); |
|---|
| 530 | } |
|---|
| 531 | if ( vci_param::B != 4 ) |
|---|
| 532 | { |
|---|
| 533 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
|---|
| 534 | std::cout << "The VCI data fields must have 32 bits" << std::endl; |
|---|
| 535 | exit(1); |
|---|
| 536 | } |
|---|
| 537 | m_fd = ::open(filename.c_str(), O_RDWR); |
|---|
| 538 | if ( m_fd < 0 ) |
|---|
| 539 | { |
|---|
| 540 | std::cout << "Error in component VciBlockDeviceTsarV4 : " << name << std::endl; |
|---|
| 541 | std::cout << "Unable to open file " << filename << std::endl; |
|---|
| 542 | exit(1); |
|---|
| 543 | } |
|---|
| 544 | m_device_size = lseek(m_fd, 0, SEEK_END) / block_size; |
|---|
| 545 | if ( m_device_size > ((uint64_t)1<<32) ) |
|---|
| 546 | { |
|---|
| 547 | std::cout << "Warning: block device " << name << std::endl; |
|---|
| 548 | std::cout << "The file " << filename << std::endl; |
|---|
| 549 | std::cout << "has more blocks than addressable with the 32 bits PIBUS address" << std::endl; |
|---|
| 550 | m_device_size = ((uint64_t)1<<32); |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | m_local_buffer = new uint32_t[m_flits_per_block]; |
|---|
| 554 | |
|---|
| 555 | std::cout << std::endl << "Instanciation of VciBlockDeviceTsarV4 : " << name << std::endl; |
|---|
| 556 | std::cout << " file_name = " << filename << std::endl; |
|---|
| 557 | std::cout << " burst_size = " << std::dec << m_flits_per_burst*vci_param::B << std::endl; |
|---|
| 558 | std::cout << " block_size = " << std::dec << m_flits_per_block*vci_param::B << std::endl; |
|---|
| 559 | std::cout << " latency = " << std::dec << m_latency << std::endl; |
|---|
| 560 | std::cout << " segment " << m_segment.name() |
|---|
| 561 | << " | base = 0x" << std::hex << m_segment.baseAddress() |
|---|
| 562 | << " | size = " << std::dec << m_segment.size() << std::endl; |
|---|
| 563 | |
|---|
| 564 | } // end constructor |
|---|
| 565 | |
|---|
| 566 | ////////////////////////// |
|---|
| 567 | tmpl(void)::print_trace() |
|---|
| 568 | { |
|---|
| 569 | const char* initiator_str[] = { |
|---|
| 570 | "IDLE ", |
|---|
| 571 | "READ_BLOCK ", |
|---|
| 572 | "READ_CMD ", |
|---|
| 573 | "READ_RSP ", |
|---|
| 574 | "READ_TEST ", |
|---|
| 575 | "READ_SUCCESS ", |
|---|
| 576 | "READ_ERROR ", |
|---|
| 577 | "WRITE_BLOCK ", |
|---|
| 578 | "WRITE_CMD ", |
|---|
| 579 | "WRITE_RSP ", |
|---|
| 580 | "WRITE_TEST ", |
|---|
| 581 | "WRITE_SUCCESS", |
|---|
| 582 | "WRITE_ERROR ", |
|---|
| 583 | }; |
|---|
| 584 | const char* target_str[] = { |
|---|
| 585 | "IDLE ", |
|---|
| 586 | "WRITE_BUFFER", |
|---|
| 587 | "READ_BUFFER ", |
|---|
| 588 | "WRITE_COUNT ", |
|---|
| 589 | "READ_COUNT ", |
|---|
| 590 | "WRITE_LBA ", |
|---|
| 591 | "READ_LBA ", |
|---|
| 592 | "WRITE_OP ", |
|---|
| 593 | "READ_STATUS ", |
|---|
| 594 | "WRITE_IRQEN ", |
|---|
| 595 | "READ_IRQEN ", |
|---|
| 596 | "READ_SIZE ", |
|---|
| 597 | "READ_BLOCK ", |
|---|
| 598 | "READ_ERROR ", |
|---|
| 599 | "WRITE_ERROR ", |
|---|
| 600 | }; |
|---|
| 601 | |
|---|
| 602 | std::cout << "BDEV_TGT : " << target_str[r_target_fsm.read()] |
|---|
| 603 | << " BDEV_INI : " << initiator_str[r_initiator_fsm.read()] |
|---|
| 604 | << " block = " << r_block_count.read() |
|---|
| 605 | << " burst = " << r_burst_count.read() |
|---|
| 606 | << " flit = " << r_flit_count.read() <<std::endl; |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | }} // end namespace |
|---|
| 611 | |
|---|
| 612 | // Local Variables: |
|---|
| 613 | // tab-width: 4 |
|---|
| 614 | // c-basic-offset: 4 |
|---|
| 615 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 616 | // indent-tabs-mode: nil |
|---|
| 617 | // End: |
|---|
| 618 | |
|---|
| 619 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 620 | |
|---|