| 1 | #ifndef UPDATE_TAB_H_ |
|---|
| 2 | #define UPDATE_TAB_H_ |
|---|
| 3 | |
|---|
| 4 | #include <inttypes.h> |
|---|
| 5 | #include <systemc> |
|---|
| 6 | #include <cassert> |
|---|
| 7 | #include "arithmetics.h" |
|---|
| 8 | |
|---|
| 9 | //////////////////////////////////////////////////////////////////////// |
|---|
| 10 | // An update tab entry |
|---|
| 11 | //////////////////////////////////////////////////////////////////////// |
|---|
| 12 | class UpdateTabEntry { |
|---|
| 13 | |
|---|
| 14 | typedef uint32_t size_t; |
|---|
| 15 | typedef sc_dt::sc_uint<40> addr_t; |
|---|
| 16 | |
|---|
| 17 | public: |
|---|
| 18 | |
|---|
| 19 | bool valid; // It is a valid pending transaction |
|---|
| 20 | bool update; // It is an update transaction |
|---|
| 21 | bool brdcast; // It is a broadcast invalidate |
|---|
| 22 | bool rsp; // Response to the initiator required |
|---|
| 23 | bool ack; // Acknowledge to the CONFIG FSM required |
|---|
| 24 | size_t srcid; // The srcid of the initiator which wrote the data |
|---|
| 25 | size_t trdid; // The trdid of the initiator which wrote the data |
|---|
| 26 | size_t pktid; // The pktid of the initiator which wrote the data |
|---|
| 27 | addr_t nline; // The identifier of the cache line |
|---|
| 28 | size_t count; // The number of acknowledge responses to receive |
|---|
| 29 | |
|---|
| 30 | UpdateTabEntry() |
|---|
| 31 | { |
|---|
| 32 | valid = false; |
|---|
| 33 | update = false; |
|---|
| 34 | brdcast = false; |
|---|
| 35 | rsp = false; |
|---|
| 36 | ack = false; |
|---|
| 37 | srcid = 0; |
|---|
| 38 | trdid = 0; |
|---|
| 39 | pktid = 0; |
|---|
| 40 | nline = 0; |
|---|
| 41 | count = 0; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | UpdateTabEntry(bool i_valid, |
|---|
| 45 | bool i_update, |
|---|
| 46 | bool i_brdcast, |
|---|
| 47 | bool i_rsp, |
|---|
| 48 | bool i_ack, |
|---|
| 49 | size_t i_srcid, |
|---|
| 50 | size_t i_trdid, |
|---|
| 51 | size_t i_pktid, |
|---|
| 52 | addr_t i_nline, |
|---|
| 53 | size_t i_count) |
|---|
| 54 | { |
|---|
| 55 | valid = i_valid; |
|---|
| 56 | update = i_update; |
|---|
| 57 | brdcast = i_brdcast; |
|---|
| 58 | rsp = i_rsp; |
|---|
| 59 | ack = i_ack; |
|---|
| 60 | srcid = i_srcid; |
|---|
| 61 | trdid = i_trdid; |
|---|
| 62 | pktid = i_pktid; |
|---|
| 63 | nline = i_nline; |
|---|
| 64 | count = i_count; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | UpdateTabEntry(const UpdateTabEntry &source) |
|---|
| 68 | { |
|---|
| 69 | valid = source.valid; |
|---|
| 70 | update = source.update; |
|---|
| 71 | brdcast = source.brdcast; |
|---|
| 72 | rsp = source.rsp; |
|---|
| 73 | ack = source.ack; |
|---|
| 74 | srcid = source.srcid; |
|---|
| 75 | trdid = source.trdid; |
|---|
| 76 | pktid = source.pktid; |
|---|
| 77 | nline = source.nline; |
|---|
| 78 | count = source.count; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | //////////////////////////////////////////////////// |
|---|
| 82 | // The init() function initializes the entry |
|---|
| 83 | /////////////////////////////////////////////////// |
|---|
| 84 | void init() |
|---|
| 85 | { |
|---|
| 86 | valid = false; |
|---|
| 87 | update = false; |
|---|
| 88 | brdcast = false; |
|---|
| 89 | rsp = false; |
|---|
| 90 | ack = false; |
|---|
| 91 | srcid = 0; |
|---|
| 92 | trdid = 0; |
|---|
| 93 | pktid = 0; |
|---|
| 94 | nline = 0; |
|---|
| 95 | count = 0; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | //////////////////////////////////////////////////////////////////// |
|---|
| 99 | // The copy() function copies an existing entry |
|---|
| 100 | // Its arguments are : |
|---|
| 101 | // - source : the update tab entry to copy |
|---|
| 102 | //////////////////////////////////////////////////////////////////// |
|---|
| 103 | void copy(const UpdateTabEntry &source) |
|---|
| 104 | { |
|---|
| 105 | valid = source.valid; |
|---|
| 106 | update = source.update; |
|---|
| 107 | brdcast = source.brdcast; |
|---|
| 108 | rsp = source.rsp; |
|---|
| 109 | ack = source.ack; |
|---|
| 110 | srcid = source.srcid; |
|---|
| 111 | trdid = source.trdid; |
|---|
| 112 | pktid = source.pktid; |
|---|
| 113 | nline = source.nline; |
|---|
| 114 | count = source.count; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | //////////////////////////////////////////////////////////////////// |
|---|
| 118 | // The print() function prints the entry |
|---|
| 119 | //////////////////////////////////////////////////////////////////// |
|---|
| 120 | void print() |
|---|
| 121 | { |
|---|
| 122 | std::cout << " val = " << std::dec << valid |
|---|
| 123 | << " / updt = " << update |
|---|
| 124 | << " / bc = " << brdcast |
|---|
| 125 | << " / rsp = " << rsp |
|---|
| 126 | << " / ack = " << ack |
|---|
| 127 | << " / count = " << count |
|---|
| 128 | << " / srcid = " << std::hex << srcid |
|---|
| 129 | << " / trdid = " << trdid |
|---|
| 130 | << " / pktid = " << pktid |
|---|
| 131 | << " / nline = " << nline << std::endl; |
|---|
| 132 | } |
|---|
| 133 | }; |
|---|
| 134 | |
|---|
| 135 | //////////////////////////////////////////////////////////////////////// |
|---|
| 136 | // The update tab |
|---|
| 137 | //////////////////////////////////////////////////////////////////////// |
|---|
| 138 | class UpdateTab{ |
|---|
| 139 | |
|---|
| 140 | typedef uint64_t addr_t; |
|---|
| 141 | |
|---|
| 142 | private: |
|---|
| 143 | size_t size_tab; |
|---|
| 144 | std::vector<UpdateTabEntry> tab; |
|---|
| 145 | |
|---|
| 146 | public: |
|---|
| 147 | |
|---|
| 148 | UpdateTab() |
|---|
| 149 | : tab(0) |
|---|
| 150 | { |
|---|
| 151 | size_tab = 0; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | UpdateTab(size_t size_tab_i) |
|---|
| 155 | : tab(size_tab_i) |
|---|
| 156 | { |
|---|
| 157 | size_tab = size_tab_i; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | //////////////////////////////////////////////////////////////////// |
|---|
| 161 | // The size() function returns the size of the tab |
|---|
| 162 | //////////////////////////////////////////////////////////////////// |
|---|
| 163 | const size_t size() |
|---|
| 164 | { |
|---|
| 165 | return size_tab; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | //////////////////////////////////////////////////////////////////// |
|---|
| 169 | // The print() function diplays the tab content |
|---|
| 170 | //////////////////////////////////////////////////////////////////// |
|---|
| 171 | void print() |
|---|
| 172 | { |
|---|
| 173 | std::cout << "UPDATE TABLE Content" << std::endl; |
|---|
| 174 | for (size_t i = 0; i < size_tab; i++) |
|---|
| 175 | { |
|---|
| 176 | std::cout << "[" << std::dec << i << "] "; |
|---|
| 177 | tab[i].print(); |
|---|
| 178 | } |
|---|
| 179 | return; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | ///////////////////////////////////////////////////////////////////// |
|---|
| 183 | // The init() function initializes the tab |
|---|
| 184 | ///////////////////////////////////////////////////////////////////// |
|---|
| 185 | void init() |
|---|
| 186 | { |
|---|
| 187 | for (size_t i = 0; i < size_tab; i++) |
|---|
| 188 | { |
|---|
| 189 | tab[i].init(); |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | ///////////////////////////////////////////////////////////////////// |
|---|
| 194 | // The reads() function reads an entry |
|---|
| 195 | // Arguments : |
|---|
| 196 | // - entry : the entry to read |
|---|
| 197 | // This function returns a copy of the entry. |
|---|
| 198 | ///////////////////////////////////////////////////////////////////// |
|---|
| 199 | UpdateTabEntry read(size_t entry) |
|---|
| 200 | { |
|---|
| 201 | assert(entry < size_tab && "Bad Update Tab Entry"); |
|---|
| 202 | return UpdateTabEntry(tab[entry]); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 206 | // The set() function writes an entry in the Update Table |
|---|
| 207 | // Arguments : |
|---|
| 208 | // - update : transaction type (bool) |
|---|
| 209 | // - srcid : srcid of the initiator |
|---|
| 210 | // - trdid : trdid of the initiator |
|---|
| 211 | // - pktid : pktid of the initiator |
|---|
| 212 | // - count : number of expected responses |
|---|
| 213 | // - index : (return argument) index of the selected entry |
|---|
| 214 | // This function returns true if the write successed (an entry was empty). |
|---|
| 215 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 216 | bool set(const bool update, |
|---|
| 217 | const bool brdcast, |
|---|
| 218 | const bool rsp, |
|---|
| 219 | const bool ack, |
|---|
| 220 | const size_t srcid, |
|---|
| 221 | const size_t trdid, |
|---|
| 222 | const size_t pktid, |
|---|
| 223 | const addr_t nline, |
|---|
| 224 | const size_t count, |
|---|
| 225 | size_t &index) |
|---|
| 226 | { |
|---|
| 227 | for (size_t i = 0; i < size_tab; i++) |
|---|
| 228 | { |
|---|
| 229 | if (!tab[i].valid) |
|---|
| 230 | { |
|---|
| 231 | tab[i].valid = true; |
|---|
| 232 | tab[i].update = update; |
|---|
| 233 | tab[i].brdcast = brdcast; |
|---|
| 234 | tab[i].rsp = rsp; |
|---|
| 235 | tab[i].ack = ack; |
|---|
| 236 | tab[i].srcid = (size_t) srcid; |
|---|
| 237 | tab[i].trdid = (size_t) trdid; |
|---|
| 238 | tab[i].pktid = (size_t) pktid; |
|---|
| 239 | tab[i].nline = (addr_t) nline; |
|---|
| 240 | tab[i].count = (size_t) count; |
|---|
| 241 | index = i; |
|---|
| 242 | return true; |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | return false; |
|---|
| 246 | } // end set() |
|---|
| 247 | |
|---|
| 248 | ///////////////////////////////////////////////////////////////////// |
|---|
| 249 | // The decrement() function decrements the counter for a given entry. |
|---|
| 250 | // Arguments : |
|---|
| 251 | // - index : the index of the entry |
|---|
| 252 | // - counter : (return argument) value of the counter after decrement |
|---|
| 253 | // This function returns true if the entry is valid. |
|---|
| 254 | ///////////////////////////////////////////////////////////////////// |
|---|
| 255 | bool decrement(const size_t index, |
|---|
| 256 | size_t &counter) |
|---|
| 257 | { |
|---|
| 258 | assert((index < size_tab) && "Bad Update Tab Entry"); |
|---|
| 259 | if (tab[index].valid) |
|---|
| 260 | { |
|---|
| 261 | tab[index].count--; |
|---|
| 262 | counter = tab[index].count; |
|---|
| 263 | return true; |
|---|
| 264 | } |
|---|
| 265 | else |
|---|
| 266 | { |
|---|
| 267 | return false; |
|---|
| 268 | } |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | ///////////////////////////////////////////////////////////////////// |
|---|
| 272 | // The is_full() function returns true if the table is full |
|---|
| 273 | ///////////////////////////////////////////////////////////////////// |
|---|
| 274 | bool is_full() |
|---|
| 275 | { |
|---|
| 276 | for (size_t i = 0; i < size_tab; i++) |
|---|
| 277 | { |
|---|
| 278 | if (!tab[i].valid) |
|---|
| 279 | { |
|---|
| 280 | return false; |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | return true; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | ///////////////////////////////////////////////////////////////////// |
|---|
| 287 | // The is_not_empty() function returns true if the table is not empty |
|---|
| 288 | ///////////////////////////////////////////////////////////////////// |
|---|
| 289 | bool is_not_empty() |
|---|
| 290 | { |
|---|
| 291 | for (size_t i = 0; i < size_tab; i++) |
|---|
| 292 | { |
|---|
| 293 | if (tab[i].valid) |
|---|
| 294 | { |
|---|
| 295 | return true; |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | return false; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | ///////////////////////////////////////////////////////////////////// |
|---|
| 302 | // The need_rsp() function returns the need of a response |
|---|
| 303 | // Arguments : |
|---|
| 304 | // - index : the index of the entry |
|---|
| 305 | ///////////////////////////////////////////////////////////////////// |
|---|
| 306 | bool need_rsp(const size_t index) |
|---|
| 307 | { |
|---|
| 308 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 309 | return tab[index].rsp; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | ///////////////////////////////////////////////////////////////////// |
|---|
| 313 | // The need_ack() function returns the need of an acknowledge |
|---|
| 314 | // Arguments : |
|---|
| 315 | // - index : the index of the entry |
|---|
| 316 | ///////////////////////////////////////////////////////////////////// |
|---|
| 317 | bool need_ack(const size_t index) |
|---|
| 318 | { |
|---|
| 319 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 320 | return tab[index].ack; |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | ///////////////////////////////////////////////////////////////////// |
|---|
| 324 | // The is_brdcast() function returns the transaction type |
|---|
| 325 | // Arguments : |
|---|
| 326 | // - index : the index of the entry |
|---|
| 327 | ///////////////////////////////////////////////////////////////////// |
|---|
| 328 | bool is_brdcast(const size_t index) |
|---|
| 329 | { |
|---|
| 330 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 331 | return tab[index].brdcast; |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | ///////////////////////////////////////////////////////////////////// |
|---|
| 335 | // The is_update() function returns the transaction type |
|---|
| 336 | // Arguments : |
|---|
| 337 | // - index : the index of the entry |
|---|
| 338 | ///////////////////////////////////////////////////////////////////// |
|---|
| 339 | bool is_update(const size_t index) |
|---|
| 340 | { |
|---|
| 341 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 342 | return tab[index].update; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | ///////////////////////////////////////////////////////////////////// |
|---|
| 346 | // The srcid() function returns the srcid value |
|---|
| 347 | // Arguments : |
|---|
| 348 | // - index : the index of the entry |
|---|
| 349 | ///////////////////////////////////////////////////////////////////// |
|---|
| 350 | size_t srcid(const size_t index) |
|---|
| 351 | { |
|---|
| 352 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 353 | return tab[index].srcid; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | ///////////////////////////////////////////////////////////////////// |
|---|
| 357 | // The trdid() function returns the trdid value |
|---|
| 358 | // Arguments : |
|---|
| 359 | // - index : the index of the entry |
|---|
| 360 | ///////////////////////////////////////////////////////////////////// |
|---|
| 361 | size_t trdid(const size_t index) |
|---|
| 362 | { |
|---|
| 363 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 364 | return tab[index].trdid; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | ///////////////////////////////////////////////////////////////////// |
|---|
| 368 | // The pktid() function returns the pktid value |
|---|
| 369 | // Arguments : |
|---|
| 370 | // - index : the index of the entry |
|---|
| 371 | ///////////////////////////////////////////////////////////////////// |
|---|
| 372 | size_t pktid(const size_t index) |
|---|
| 373 | { |
|---|
| 374 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 375 | return tab[index].pktid; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | ///////////////////////////////////////////////////////////////////// |
|---|
| 379 | // The nline() function returns the nline value |
|---|
| 380 | // Arguments : |
|---|
| 381 | // - index : the index of the entry |
|---|
| 382 | ///////////////////////////////////////////////////////////////////// |
|---|
| 383 | addr_t nline(const size_t index) |
|---|
| 384 | { |
|---|
| 385 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 386 | return tab[index].nline; |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | ///////////////////////////////////////////////////////////////////// |
|---|
| 390 | // The search_inval() function returns the index of the entry in UPT |
|---|
| 391 | // Arguments : |
|---|
| 392 | // - nline : the line number of the entry in the directory |
|---|
| 393 | ///////////////////////////////////////////////////////////////////// |
|---|
| 394 | bool search_inval(const addr_t nline, size_t &index) |
|---|
| 395 | { |
|---|
| 396 | size_t i; |
|---|
| 397 | |
|---|
| 398 | for (i = 0; i < size_tab; i++) |
|---|
| 399 | { |
|---|
| 400 | if ((tab[i].nline == nline) and tab[i].valid and not tab[i].update) |
|---|
| 401 | { |
|---|
| 402 | index = i; |
|---|
| 403 | return true; |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | return false; |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | ///////////////////////////////////////////////////////////////////// |
|---|
| 410 | // The read_nline() function returns the index of the entry in UPT |
|---|
| 411 | // Arguments : |
|---|
| 412 | // - nline : the line number of the entry in the directory |
|---|
| 413 | ///////////////////////////////////////////////////////////////////// |
|---|
| 414 | bool read_nline(const addr_t nline, size_t &index) |
|---|
| 415 | { |
|---|
| 416 | size_t i; |
|---|
| 417 | |
|---|
| 418 | for (i = 0; i < size_tab; i++) |
|---|
| 419 | { |
|---|
| 420 | if ((tab[i].nline == nline) and tab[i].valid) |
|---|
| 421 | { |
|---|
| 422 | index = i; |
|---|
| 423 | return true; |
|---|
| 424 | } |
|---|
| 425 | } |
|---|
| 426 | return false; |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | ///////////////////////////////////////////////////////////////////// |
|---|
| 430 | // The clear() function erases an entry of the tab |
|---|
| 431 | // Arguments : |
|---|
| 432 | // - index : the index of the entry |
|---|
| 433 | ///////////////////////////////////////////////////////////////////// |
|---|
| 434 | void clear(const size_t index) |
|---|
| 435 | { |
|---|
| 436 | assert(index < size_tab && "Bad Update Tab Entry"); |
|---|
| 437 | tab[index].valid = false; |
|---|
| 438 | return; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | }; |
|---|
| 442 | |
|---|
| 443 | #endif |
|---|
| 444 | |
|---|
| 445 | // Local Variables: |
|---|
| 446 | // tab-width: 4 |
|---|
| 447 | // c-basic-offset: 4 |
|---|
| 448 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 449 | // indent-tabs-mode: nil |
|---|
| 450 | // End: |
|---|
| 451 | |
|---|
| 452 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 453 | |
|---|