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

Last change on this file since 361 was 361, checked in by cfuguet, 11 years ago

Bugfix in vci_mem_cache_v4:

In function "copy()" of the xram_transaction table the LL key was not
copied into register. Hence, the key coming from the XRAM_RSP to the
TGT_RSP FSM was never correct.

In TGT_RSP FSM, in case of LL response, the two response flits were
inverted. We must send first the key and then the data.

Add:

Add the COMPARE_HIT_COMPARE state in the CAS FSM to optimize timing.
(This modification has been already done in the vci_mem_cache v5).

Add output ports for debug. This ports are used only if the
MONITOR_MEMCACHE_FSM compilation directive is gave.

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