[307] | 1 | #ifndef XRAM_TRANSACTION_H_ |
---|
| 2 | #define XRAM_TRANSACTION_H_ |
---|
| 3 | |
---|
| 4 | #include <inttypes.h> |
---|
| 5 | #include <systemc> |
---|
| 6 | #include <cassert> |
---|
| 7 | #include "arithmetics.h" |
---|
| 8 | |
---|
| 9 | #define DEBUG_XRAM_TRANSACTION 0 |
---|
| 10 | |
---|
| 11 | //////////////////////////////////////////////////////////////////////// |
---|
| 12 | // A transaction tab entry |
---|
| 13 | //////////////////////////////////////////////////////////////////////// |
---|
| 14 | |
---|
| 15 | class TransactionTabEntry { |
---|
| 16 | typedef uint32_t size_t; |
---|
| 17 | typedef uint32_t data_t; |
---|
| 18 | typedef sc_dt::sc_uint<40> addr_t; |
---|
| 19 | typedef uint32_t be_t; |
---|
| 20 | |
---|
| 21 | public: |
---|
| 22 | bool valid; // entry valid |
---|
| 23 | bool xram_read; // read request to XRAM |
---|
| 24 | addr_t nline; // index (zy) of the requested line |
---|
| 25 | size_t srcid; // processor requesting the transaction |
---|
| 26 | size_t trdid; // processor requesting the transaction |
---|
| 27 | size_t pktid; // processor requesting the transaction |
---|
| 28 | bool proc_read; // read request from processor |
---|
| 29 | size_t read_length; // length of the read (for the response) |
---|
| 30 | size_t word_index; // index of the first read word (for the response) |
---|
| 31 | std::vector<data_t> wdata; // write buffer (one cache line) |
---|
| 32 | std::vector<be_t> wdata_be; // be for each data in the write buffer |
---|
| 33 | bool rerror; // error returned by xram |
---|
| 34 | data_t ll_key; // LL key returned by the llsc_global_table |
---|
| 35 | |
---|
| 36 | ///////////////////////////////////////////////////////////////////// |
---|
| 37 | // The init() function initializes the entry |
---|
| 38 | ///////////////////////////////////////////////////////////////////// |
---|
| 39 | void init() |
---|
| 40 | { |
---|
| 41 | valid = false; |
---|
| 42 | rerror = false; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | ///////////////////////////////////////////////////////////////////// |
---|
| 46 | // The alloc() function initializes the vectors of an entry |
---|
| 47 | // Its arguments are : |
---|
| 48 | // - n_words : number of words per line in the cache |
---|
| 49 | ///////////////////////////////////////////////////////////////////// |
---|
| 50 | void alloc(size_t n_words) |
---|
| 51 | { |
---|
| 52 | wdata_be.reserve( (int)n_words ); |
---|
| 53 | wdata.reserve( (int)n_words ); |
---|
| 54 | for(size_t i=0; i<n_words; i++) |
---|
| 55 | { |
---|
| 56 | wdata_be.push_back(0); |
---|
| 57 | wdata.push_back(0); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | //////////////////////////////////////////////////////////////////// |
---|
| 62 | // The copy() function copies an existing entry |
---|
| 63 | // Its arguments are : |
---|
| 64 | // - source : the transaction tab entry to copy |
---|
| 65 | //////////////////////////////////////////////////////////////////// |
---|
| 66 | void copy(const TransactionTabEntry &source) |
---|
| 67 | { |
---|
| 68 | valid = source.valid; |
---|
| 69 | xram_read = source.xram_read; |
---|
| 70 | nline = source.nline; |
---|
| 71 | srcid = source.srcid; |
---|
| 72 | trdid = source.trdid; |
---|
| 73 | pktid = source.pktid; |
---|
| 74 | proc_read = source.proc_read; |
---|
| 75 | read_length = source.read_length; |
---|
| 76 | word_index = source.word_index; |
---|
| 77 | wdata_be.assign(source.wdata_be.begin(),source.wdata_be.end()); |
---|
| 78 | wdata.assign(source.wdata.begin(),source.wdata.end()); |
---|
| 79 | rerror = source.rerror; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | //////////////////////////////////////////////////////////////////// |
---|
| 83 | // The print() function prints the entry |
---|
| 84 | //////////////////////////////////////////////////////////////////// |
---|
| 85 | void print(){ |
---|
| 86 | std::cout << "valid = " << valid << std::endl; |
---|
| 87 | std::cout << "xram_read = " << xram_read << std::endl; |
---|
| 88 | std::cout << "nline = " << std::hex << nline << std::endl; |
---|
| 89 | std::cout << "srcid = " << srcid << std::endl; |
---|
| 90 | std::cout << "trdid = " << trdid << std::endl; |
---|
| 91 | std::cout << "pktid = " << pktid << std::endl; |
---|
| 92 | std::cout << "proc_read = " << proc_read << std::endl; |
---|
| 93 | std::cout << "read_length = " << read_length << std::endl; |
---|
| 94 | std::cout << "word_index = " << word_index << std::endl; |
---|
| 95 | for(size_t i=0; i<wdata_be.size() ; i++){ |
---|
| 96 | std::cout << "wdata_be [" << i <<"] = " << wdata_be[i] << std::endl; |
---|
| 97 | } |
---|
| 98 | for(size_t i=0; i<wdata.size() ; i++){ |
---|
| 99 | std::cout << "wdata [" << i <<"] = " << wdata[i] << std::endl; |
---|
| 100 | } |
---|
| 101 | std::cout << std::endl; |
---|
| 102 | std::cout << "rerror = " << rerror << std::endl; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | ///////////////////////////////////////////////////////////////////// |
---|
| 106 | // Constructors |
---|
| 107 | ///////////////////////////////////////////////////////////////////// |
---|
| 108 | |
---|
| 109 | TransactionTabEntry() |
---|
| 110 | { |
---|
| 111 | wdata_be.clear(); |
---|
| 112 | wdata.clear(); |
---|
| 113 | valid=false; |
---|
| 114 | rerror=false; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | TransactionTabEntry(const TransactionTabEntry &source){ |
---|
| 118 | valid = source.valid; |
---|
| 119 | xram_read = source.xram_read; |
---|
| 120 | nline = source.nline; |
---|
| 121 | srcid = source.srcid; |
---|
| 122 | trdid = source.trdid; |
---|
| 123 | pktid = source.pktid; |
---|
| 124 | proc_read = source.proc_read; |
---|
| 125 | read_length = source.read_length; |
---|
| 126 | word_index = source.word_index; |
---|
| 127 | wdata_be.assign(source.wdata_be.begin(),source.wdata_be.end()); |
---|
| 128 | wdata.assign(source.wdata.begin(),source.wdata.end()); |
---|
| 129 | rerror = source.rerror; |
---|
| 130 | ll_key = source.ll_key; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | }; // end class TransactionTabEntry |
---|
| 134 | |
---|
| 135 | //////////////////////////////////////////////////////////////////////// |
---|
| 136 | // The transaction tab |
---|
| 137 | //////////////////////////////////////////////////////////////////////// |
---|
| 138 | class TransactionTab{ |
---|
| 139 | typedef uint32_t size_t; |
---|
| 140 | typedef uint32_t data_t; |
---|
| 141 | typedef sc_dt::sc_uint<40> addr_t; |
---|
| 142 | typedef uint32_t be_t; |
---|
| 143 | |
---|
| 144 | private: |
---|
| 145 | size_t size_tab; // The size of the tab |
---|
| 146 | |
---|
| 147 | data_t be_to_mask(be_t be) |
---|
| 148 | { |
---|
| 149 | data_t ret = 0; |
---|
| 150 | if ( be&0x1 ) { |
---|
| 151 | ret = ret | 0x000000FF; |
---|
| 152 | } |
---|
| 153 | if ( be&0x2 ) { |
---|
| 154 | ret = ret | 0x0000FF00; |
---|
| 155 | } |
---|
| 156 | if ( be&0x4 ) { |
---|
| 157 | ret = ret | 0x00FF0000; |
---|
| 158 | } |
---|
| 159 | if ( be&0x8 ) { |
---|
| 160 | ret = ret | 0xFF000000; |
---|
| 161 | } |
---|
| 162 | return ret; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | public: |
---|
| 166 | TransactionTabEntry *tab; // The transaction tab |
---|
| 167 | |
---|
| 168 | //////////////////////////////////////////////////////////////////// |
---|
| 169 | // Constructors |
---|
| 170 | //////////////////////////////////////////////////////////////////// |
---|
| 171 | TransactionTab() |
---|
| 172 | { |
---|
| 173 | size_tab=0; |
---|
| 174 | tab=NULL; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | TransactionTab(size_t n_entries, size_t n_words) |
---|
| 178 | { |
---|
| 179 | size_tab = n_entries; |
---|
| 180 | tab = new TransactionTabEntry[size_tab]; |
---|
| 181 | for ( size_t i=0; i<size_tab; i++) { |
---|
| 182 | tab[i].alloc(n_words); |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | ~TransactionTab() |
---|
| 187 | { |
---|
| 188 | delete [] tab; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | ///////////////////////////////////////////////////////////////////// |
---|
| 192 | // The size() function returns the size of the tab |
---|
| 193 | ///////////////////////////////////////////////////////////////////// |
---|
| 194 | size_t size() |
---|
| 195 | { |
---|
| 196 | return size_tab; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | ///////////////////////////////////////////////////////////////////// |
---|
| 200 | // The init() function initializes the transaction tab entries |
---|
| 201 | ///////////////////////////////////////////////////////////////////// |
---|
| 202 | void init() |
---|
| 203 | { |
---|
| 204 | for ( size_t i=0; i<size_tab; i++) { |
---|
| 205 | tab[i].init(); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | ///////////////////////////////////////////////////////////////////// |
---|
| 210 | // The print() function prints a transaction tab entry |
---|
| 211 | // Arguments : |
---|
| 212 | // - index : the index of the entry to print |
---|
| 213 | ///////////////////////////////////////////////////////////////////// |
---|
| 214 | void print(const size_t index) |
---|
| 215 | { |
---|
| 216 | assert( (index < size_tab) |
---|
| 217 | && "Invalid Transaction Tab Entry"); |
---|
| 218 | tab[index].print(); |
---|
| 219 | return; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | ///////////////////////////////////////////////////////////////////// |
---|
| 223 | // The read() function returns a transaction tab entry. |
---|
| 224 | // Arguments : |
---|
| 225 | // - index : the index of the entry to read |
---|
| 226 | ///////////////////////////////////////////////////////////////////// |
---|
| 227 | TransactionTabEntry read(const size_t index) |
---|
| 228 | { |
---|
| 229 | assert( (index < size_tab) |
---|
| 230 | && "Invalid Transaction Tab Entry"); |
---|
| 231 | return tab[index]; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | ///////////////////////////////////////////////////////////////////// |
---|
| 235 | // The full() function returns the state of the transaction tab |
---|
| 236 | // Arguments : |
---|
| 237 | // - index : (return argument) the index of an empty entry |
---|
| 238 | // The function returns true if the transaction tab is full |
---|
| 239 | ///////////////////////////////////////////////////////////////////// |
---|
| 240 | bool full(size_t &index) |
---|
| 241 | { |
---|
| 242 | for(size_t i=0; i<size_tab; i++){ |
---|
| 243 | if(!tab[i].valid){ |
---|
| 244 | index=i; |
---|
| 245 | return false; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | return true; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | ///////////////////////////////////////////////////////////////////// |
---|
| 252 | // The hit_read() function checks if an XRAM read transaction exists |
---|
| 253 | // for a given cache line. |
---|
| 254 | // Arguments : |
---|
| 255 | // - index : (return argument) the index of the hit entry, if there is |
---|
| 256 | // - nline : the index (zy) of the requested line |
---|
| 257 | // The function returns true if a read request has already been sent |
---|
| 258 | ////////////////////////////////////////////////////////////////////// |
---|
| 259 | bool hit_read(const addr_t nline,size_t &index) |
---|
| 260 | { |
---|
| 261 | for(size_t i=0; i<size_tab; i++){ |
---|
| 262 | if((tab[i].valid && (nline==tab[i].nline)) && (tab[i].xram_read)) { |
---|
| 263 | index=i; |
---|
| 264 | return true; |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | return false; |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | /////////////////////////////////////////////////////////////////////// |
---|
| 271 | // The hit_write() function looks if an XRAM write transaction exists |
---|
| 272 | // for a given line. |
---|
| 273 | // Arguments : |
---|
| 274 | // - nline : the index (zy) of the requested line |
---|
| 275 | // The function returns true if a write request has already been sent |
---|
| 276 | /////////////////////////////////////////////////////////////////////// |
---|
| 277 | bool hit_write(const addr_t nline) |
---|
| 278 | { |
---|
| 279 | for(size_t i=0; i<size_tab; i++){ |
---|
| 280 | if(tab[i].valid && (nline==tab[i].nline) && !(tab[i].xram_read)) { |
---|
| 281 | return true; |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | return false; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | ///////////////////////////////////////////////////////////////////// |
---|
| 288 | // The write_data_mask() function writes a vector of data (a line). |
---|
| 289 | // The data is written only if the corresponding bits are set |
---|
| 290 | // in the be vector. |
---|
| 291 | // Arguments : |
---|
| 292 | // - index : the index of the request in the transaction tab |
---|
| 293 | // - be : vector of be |
---|
| 294 | // - data : vector of data |
---|
| 295 | ///////////////////////////////////////////////////////////////////// |
---|
| 296 | void write_data_mask(const size_t index, |
---|
| 297 | const std::vector<be_t> &be, |
---|
| 298 | const std::vector<data_t> &data) |
---|
| 299 | { |
---|
| 300 | assert( (index < size_tab) |
---|
| 301 | && "Invalid Transaction Tab Entry"); |
---|
| 302 | assert(be.size()==tab[index].wdata_be.size() |
---|
| 303 | && "Bad data mask in write_data_mask in TransactionTab"); |
---|
| 304 | assert(data.size()==tab[index].wdata.size() |
---|
| 305 | && "Bad data in write_data_mask in TransactionTab"); |
---|
| 306 | |
---|
| 307 | for(size_t i=0; i<tab[index].wdata_be.size() ; i++) { |
---|
| 308 | tab[index].wdata_be[i] = tab[index].wdata_be[i] | be[i]; |
---|
| 309 | data_t mask = be_to_mask(be[i]); |
---|
| 310 | tab[index].wdata[i] = (tab[index].wdata[i] & ~mask) | (data[i] & mask); |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | ///////////////////////////////////////////////////////////////////// |
---|
| 315 | // The set() function registers a transaction (read or write) |
---|
| 316 | // to the XRAM in the transaction tab. |
---|
| 317 | // Arguments : |
---|
| 318 | // - index : index in the transaction tab |
---|
| 319 | // - xram_read : transaction type (read or write a cache line) |
---|
| 320 | // - nline : the index (zy) of the cache line |
---|
| 321 | // - srcid : srcid of the initiator that caused the transaction |
---|
| 322 | // - trdid : trdid of the initiator that caused the transaction |
---|
| 323 | // - pktid : pktid of the initiator that caused the transaction |
---|
| 324 | // - proc_read : does the initiator want a copy |
---|
| 325 | // - read_length : length of read (in case of processor read) |
---|
| 326 | // - word_index : index in the line (in case of single word read) |
---|
| 327 | // - data : the data to write (in case of write) |
---|
| 328 | // - data_be : the mask of the data to write (in case of write) |
---|
| 329 | // - ll_key : the ll key (if any) returned by the llsc_global_table |
---|
| 330 | ///////////////////////////////////////////////////////////////////// |
---|
| 331 | void set(const size_t index, |
---|
| 332 | const bool xram_read, |
---|
| 333 | const addr_t nline, |
---|
| 334 | const size_t srcid, |
---|
| 335 | const size_t trdid, |
---|
| 336 | const size_t pktid, |
---|
| 337 | const bool proc_read, |
---|
| 338 | const size_t read_length, |
---|
| 339 | const size_t word_index, |
---|
| 340 | const std::vector<be_t> &data_be, |
---|
| 341 | const std::vector<data_t> &data, |
---|
| 342 | const data_t ll_key = 0) |
---|
| 343 | { |
---|
| 344 | assert( (index < size_tab) |
---|
| 345 | && "The selected entry is out of range in set() Transaction Tab"); |
---|
| 346 | assert(data_be.size()==tab[index].wdata_be.size() |
---|
| 347 | && "Bad data_be argument in set() TransactionTab"); |
---|
| 348 | assert(data.size()==tab[index].wdata.size() |
---|
| 349 | && "Bad data argument in set() TransactionTab"); |
---|
| 350 | |
---|
| 351 | tab[index].valid = true; |
---|
| 352 | tab[index].xram_read = xram_read; |
---|
| 353 | tab[index].nline = nline; |
---|
| 354 | tab[index].srcid = srcid; |
---|
| 355 | tab[index].trdid = trdid; |
---|
| 356 | tab[index].pktid = pktid; |
---|
| 357 | tab[index].proc_read = proc_read; |
---|
| 358 | tab[index].read_length = read_length; |
---|
| 359 | tab[index].word_index = word_index; |
---|
| 360 | tab[index].ll_key = ll_key; |
---|
| 361 | for(size_t i=0; i<tab[index].wdata.size(); i++) |
---|
| 362 | { |
---|
| 363 | tab[index].wdata_be[i] = data_be[i]; |
---|
| 364 | tab[index].wdata[i] = data[i]; |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | ///////////////////////////////////////////////////////////////////// |
---|
| 369 | // The write_rsp() function writes a word of the response to an |
---|
| 370 | // XRAM read transaction. |
---|
| 371 | // The BE field in TRT is taken into account. |
---|
| 372 | // Arguments : |
---|
| 373 | // - index : the index of the transaction in the transaction tab |
---|
| 374 | // - word_index : the index of the data in the line |
---|
| 375 | // - data : the data to write |
---|
| 376 | // - error : invalid data |
---|
| 377 | ///////////////////////////////////////////////////////////////////// |
---|
| 378 | void write_rsp(const size_t index, |
---|
| 379 | const size_t word, |
---|
| 380 | const data_t data, |
---|
| 381 | const bool rerror) |
---|
| 382 | { |
---|
| 383 | assert( (index < size_tab) |
---|
| 384 | && "Selected entry out of range in write_rsp() Transaction Tab"); |
---|
| 385 | assert( (word <= tab[index].wdata_be.size()) |
---|
| 386 | && "Bad word_index in write_rsp() in TransactionTab"); |
---|
| 387 | assert( tab[index].valid |
---|
| 388 | && "Transaction Tab Entry invalid in write_rsp()"); |
---|
| 389 | assert( tab[index].xram_read |
---|
| 390 | && "Selected entry is not an XRAM read transaction in write_rsp()"); |
---|
| 391 | |
---|
| 392 | data_t mask = be_to_mask(tab[index].wdata_be[word]); |
---|
| 393 | tab[index].wdata[word] = (tab[index].wdata[word] & mask) | (data & ~mask); |
---|
| 394 | tab[index].rerror |= rerror; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | ///////////////////////////////////////////////////////////////////// |
---|
| 398 | // The erase() function erases an entry in the transaction tab. |
---|
| 399 | // Arguments : |
---|
| 400 | // - index : the index of the request in the transaction tab |
---|
| 401 | ///////////////////////////////////////////////////////////////////// |
---|
| 402 | void erase(const size_t index) |
---|
| 403 | { |
---|
| 404 | assert( (index < size_tab) |
---|
| 405 | && "The selected entry is out of range in erase() Transaction Tab"); |
---|
| 406 | tab[index].valid = false; |
---|
| 407 | tab[index].rerror = false; |
---|
| 408 | } |
---|
| 409 | }; // end class TransactionTab |
---|
| 410 | |
---|
| 411 | #endif |
---|
| 412 | |
---|
| 413 | // Local Variables: |
---|
| 414 | // tab-width: 4 |
---|
| 415 | // c-basic-offset: 4 |
---|
| 416 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 417 | // indent-tabs-mode: nil |
---|
| 418 | // End: |
---|
| 419 | |
---|
| 420 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 421 | |
---|