source: trunk/modules/vci_mem_cache_v4/caba/source/include/xram_transaction_v4.h @ 253

Last change on this file since 253 was 253, checked in by meunier, 12 years ago

Added the display of the name of the component in the vci_cc_vcache_v4 and
the vci_mem_cache_v4 in the debug traces.

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