source: branches/v4/platforms/almos-tsarv3-platforms/common/vci_mem_cache_v3/caba/source/include/xram_transaction_v3.h

Last change on this file was 259, checked in by almaless, 12 years ago

Introduce ALMOS used platforms for TSAR.
See the package's README file for more information.

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