source: trunk/modules/vci_mem_cache_v2/caba/source/include/xram_transaction_v2.h @ 2

Last change on this file since 2 was 2, checked in by nipo, 14 years ago

Import TSAR modules in TSAR's own svn

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