OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [PCIe/] [sim/] [src/] [pcie_common_pkg.sv] - Blame information for rev 40

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 32 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
 
29
// --------------------------------------------------------------------
30
//
31
package pcie_common_pkg;
32
 
33
  typedef enum
34
  {
35
    MRd,      // Memory Read Request
36
    MRdLk,    // Memory Read Request-Locked
37
    MWr,      // Memory Write Request
38
    IORd,     // I/O Read Request
39
    IOWr,     // I/O Write Request
40
    CfgRd0,   // Configuration Read Type
41
    CfgWr0,   // Configuration Write Type
42
    CfgRd1,   // Configuration Read Type
43
    CfgWr1,   // Configuration Write Type
44
    TCfgRd,   // Deprecated TLP Type3
45
    TCfgWr,   // Deprecated TLP Type3
46
    Msg,      // Message Request
47
    MsgD,     // Message Request with data payload
48
    Cpl,      // Completion without Data
49
    CplD,     // Completion with Data
50
    CplLk,    // Completion for Locked Memory Read without Data
51
    CplDLk,   // Completion for Locked Memory Read
52
    FetchAdd, // Fetch and Add AtomicOp Request
53
    Swap,     // Unconditional Swap AtomicOp Request
54
    CAS,      // Compare and Swap AtomicOp Request
55
    LPrfx,    // Local TLP Prefix
56
    EPrfx,    // End-End TLP Prefix
57
    Reserved
58
  } tlp_type_t;
59
 
60
  typedef enum
61
  {
62 33 qaztronic
    DW_3_NO_DATA,
63
    DW_4_NO_DATA,
64
    DW_3_DATA,
65
    DW_4_DATA,
66
    TPL_PREFIX,
67
    RESERVED
68
  } tlp_fmt_t;
69
 
70
  typedef enum
71
  {
72 32 qaztronic
    ROUTING_UNKNOWN,
73
    ADDRESS,
74
    ID,
75
    IMPLICIT
76
  } tlp_routing_t;
77
 
78
  typedef enum
79
  {
80
    TRANSACTION_UNKNOWN,
81
    REQUESTER,
82
    COMPLETER
83
  } tlp_transaction_t;
84
 
85 33 qaztronic
  typedef byte tpl_packet_t[];
86 32 qaztronic
 
87 33 qaztronic
 
88 32 qaztronic
  // --------------------------------------------------------------------
89
  //
90
  class tlp_header_class;
91
 
92 33 qaztronic
    tlp_fmt_t   tlp_fmt;
93
    tlp_type_t  tlp_type;
94 32 qaztronic
    logic [7:0] fmt_type;
95
    logic [2:0] tc;
96
    logic       th;
97
    logic [2:0] attr;
98
    logic       td;
99
    logic       ep;
100
    logic [9:0] length;
101 33 qaztronic
    logic [63:0] address;
102
    logic [1:0] ph;
103
    byte header[];
104 32 qaztronic
 
105
 
106
    // --------------------------------------------------------------------
107
    //
108 33 qaztronic
    function bit is_3_dw;
109
      return(~this.fmt_type[5]);
110
    endfunction: is_3_dw
111
 
112
 
113
    // --------------------------------------------------------------------
114
    //
115
    function bit is_4_dw;
116
      return(this.fmt_type[5]);
117
    endfunction: is_4_dw
118
 
119
 
120
    // --------------------------------------------------------------------
121
    //
122
    function void set_tc(logic [2:0] tc);
123
      this.tc = tc;
124
      header[1][6:4] = tc;
125
    endfunction: set_tc
126
 
127
 
128
    // --------------------------------------------------------------------
129
    //
130
    function void set_th(logic th);
131
      this.th = th;
132
      header[1][0] = th;
133
    endfunction: set_th
134
 
135
 
136
    // --------------------------------------------------------------------
137
    //
138
    function void set_attr(logic [2:0] attr);
139
      this.attr = attr;
140
      {header[1][2], header[2][5:4]} = attr;
141
    endfunction: set_attr
142
 
143
 
144
    // --------------------------------------------------------------------
145
    //
146
    function void set_td(logic td);
147
      this.td = td;
148
      header[2][7] = td;
149
    endfunction: set_td
150
 
151
 
152
    // --------------------------------------------------------------------
153
    //
154
    function void set_ep(logic ep);
155
      this.ep = ep;
156
      header[2][6] = ep;
157
    endfunction: set_ep
158
 
159
 
160
    // --------------------------------------------------------------------
161
    //
162
    function void set_address(logic [63:0] address);
163
      this.address = address;
164
      if(is_3_dw)
165
      begin
166
        header[8] = this.address[31:24];
167
        header[9] = this.address[23:16];
168
        header[10] = this.address[15:8];
169
        header[11][7:2] = this.address[7:2];
170
      end
171
      else
172
      begin
173
        header[8] = this.address[63:56];
174
        header[9] = this.address[55:48];
175
        header[10] = this.address[47:40];
176
        header[11] = this.address[39:32];
177
        header[12] = this.address[31:24];
178
        header[13] = this.address[23:16];
179
        header[14] = this.address[15:8];
180
        header[15][7:2] = this.address[7:2];
181
      end
182
    endfunction: set_address
183
 
184
 
185
    // --------------------------------------------------------------------
186
    //
187
    function void set_ph(logic [1:0] ph);
188
      this.ph = ph;
189
      if(is_3_dw)
190
        header[11][1:0] = ph;
191
      else
192
        header[15][1:0] = ph;
193
    endfunction: set_ph
194
 
195
 
196
    // --------------------------------------------------------------------
197
    //
198 32 qaztronic
    function logic [7:0] get_fmt_type;
199 33 qaztronic
      casez({tlp_fmt, tlp_type})
200
        {DW_3_NO_DATA, MRd}:    get_fmt_type = 8'b000_00000;
201
        {DW_4_NO_DATA, MRd}:    get_fmt_type = 8'b001_00000;
202
        {DW_3_NO_DATA, MRdLk}:  get_fmt_type = 8'b000_00001;
203
        {DW_4_NO_DATA, MRdLk}:  get_fmt_type = 8'b001_00001;
204
        {DW_3_DATA, MWr}:       get_fmt_type = 8'b010_00000;
205
        {DW_4_DATA, MWr}:       get_fmt_type = 8'b011_00000;
206
        {DW_3_NO_DATA, IORd}:   get_fmt_type = 8'b000_00010;
207
        {DW_3_DATA, IOWr}:      get_fmt_type = 8'b010_00010;
208
        {DW_3_NO_DATA, CfgRd0}: get_fmt_type = 8'b000_00100;
209
        {DW_3_DATA, CfgWr0}:    get_fmt_type = 8'b010_00100;
210
        {DW_3_NO_DATA, CfgRd1}: get_fmt_type = 8'b000_00101;
211
        {DW_3_DATA, CfgWr1}:    get_fmt_type = 8'b010_00101;
212
        {DW_3_NO_DATA, TCfgRd}: get_fmt_type = 8'b000_11011;
213
        {DW_3_DATA, TCfgWr}:    get_fmt_type = 8'b010_11011;
214
        {DW_4_NO_DATA, Msg}:    get_fmt_type = 8'b001_10xxx;
215
        {DW_4_DATA, MsgD}:      get_fmt_type = 8'b011_10xxx;
216
        {DW_3_NO_DATA, Cpl}:    get_fmt_type = 8'b000_01010;
217
        {DW_3_DATA, CplD}:      get_fmt_type = 8'b010_01010;
218
        {DW_3_NO_DATA, CplLk}:  get_fmt_type = 8'b000_01011;
219
        {DW_3_DATA, CplDLk}:    get_fmt_type = 8'b010_01011;
220
        {DW_3_DATA, FetchAdd}:  get_fmt_type = 8'b010_01100;
221
        {DW_4_DATA, FetchAdd}:  get_fmt_type = 8'b011_01100;
222
        {DW_3_DATA, Swap}:      get_fmt_type = 8'b010_01101;
223
        {DW_4_DATA, Swap}:      get_fmt_type = 8'b011_01101;
224
        {DW_3_DATA, CAS}:       get_fmt_type = 8'b010_01110;
225
        {DW_4_DATA, CAS}:       get_fmt_type = 8'b011_01110;
226
        {TPL_PREFIX, LPrfx}:    get_fmt_type = 8'b100_0xxxx;
227
        {TPL_PREFIX, EPrfx}:    get_fmt_type = 8'b100_1xxxx;
228
        default:                get_fmt_type = Reserved;
229 32 qaztronic
      endcase
230
    endfunction: get_fmt_type
231
 
232
 
233
    // --------------------------------------------------------------------
234
    //
235 33 qaztronic
    function tlp_type_t get_tlp_type;
236 32 qaztronic
      casez(fmt_type)
237
        8'b000_00000: get_tlp_type = MRd;
238
        8'b001_00000: get_tlp_type = MRd;
239
        8'b000_00001: get_tlp_type = MRdLk;
240
        8'b001_00001: get_tlp_type = MRdLk;
241
        8'b010_00000: get_tlp_type = MWr;
242
        8'b011_00000: get_tlp_type = MWr;
243
        8'b000_00010: get_tlp_type = IORd;
244
        8'b010_00010: get_tlp_type = IOWr;
245
        8'b000_00100: get_tlp_type = CfgRd0;
246
        8'b010_00100: get_tlp_type = CfgWr0;
247
        8'b000_00101: get_tlp_type = CfgRd1;
248
        8'b010_00101: get_tlp_type = CfgWr1;
249
        8'b000_11011: get_tlp_type = TCfgRd;
250
        8'b010_11011: get_tlp_type = TCfgWr;
251
        8'b001_10???: get_tlp_type = Msg;
252
        8'b011_10???: get_tlp_type = MsgD;
253
        8'b000_01010: get_tlp_type = Cpl;
254
        8'b010_01010: get_tlp_type = CplD;
255
        8'b000_01011: get_tlp_type = CplLk;
256
        8'b010_01011: get_tlp_type = CplDLk;
257
        8'b010_01100: get_tlp_type = FetchAdd;
258
        8'b011_01100: get_tlp_type = FetchAdd;
259
        8'b010_01101: get_tlp_type = Swap;
260
        8'b011_01101: get_tlp_type = Swap;
261
        8'b010_01110: get_tlp_type = CAS;
262
        8'b011_01110: get_tlp_type = CAS;
263
        8'b100_0????: get_tlp_type = LPrfx;
264
        8'b100_1????: get_tlp_type = EPrfx;
265
        default:      get_tlp_type = Reserved;
266
      endcase
267
    endfunction: get_tlp_type
268
 
269
 
270
    // --------------------------------------------------------------------
271
    //
272
    function tlp_routing_t get_tlp_routing;
273
 
274 33 qaztronic
      case(tlp_type)
275 32 qaztronic
        MRd:      get_tlp_routing = ADDRESS;
276
        MRdLk:    get_tlp_routing = ADDRESS;
277
        MWr:      get_tlp_routing = ADDRESS;
278
        IORd:     get_tlp_routing = ADDRESS;
279
        IOWr:     get_tlp_routing = ADDRESS;
280
        CfgRd0:   get_tlp_routing = ID;
281
        CfgWr0:   get_tlp_routing = ID;
282
        CfgRd1:   get_tlp_routing = ID;
283
        CfgWr1:   get_tlp_routing = ID;
284
        TCfgRd:   get_tlp_routing = ID;
285
        TCfgWr:   get_tlp_routing = ID;
286
        Msg:      get_tlp_routing = ROUTING_UNKNOWN;
287
        MsgD:     get_tlp_routing = ROUTING_UNKNOWN;
288
        Cpl:      get_tlp_routing = ID;
289
        CplD:     get_tlp_routing = ID;
290
        CplLk:    get_tlp_routing = ID;
291
        CplDLk:   get_tlp_routing = ID;
292
        FetchAdd: get_tlp_routing = ROUTING_UNKNOWN;
293
        Swap:     get_tlp_routing = ROUTING_UNKNOWN;
294
        CAS:      get_tlp_routing = ROUTING_UNKNOWN;
295
        LPrfx:    get_tlp_routing = ROUTING_UNKNOWN;
296
        EPrfx:    get_tlp_routing = ROUTING_UNKNOWN;
297
        default:  get_tlp_routing = ROUTING_UNKNOWN;
298
      endcase
299
 
300
    endfunction: get_tlp_routing
301
 
302
 
303
    // --------------------------------------------------------------------
304
    //
305
    function tlp_transaction_t get_tlp_transaction;
306
 
307 33 qaztronic
      case(tlp_type)
308 32 qaztronic
        MRd:      get_tlp_transaction = REQUESTER;
309
        MRdLk:    get_tlp_transaction = REQUESTER;
310
        MWr:      get_tlp_transaction = REQUESTER;
311
        IORd:     get_tlp_transaction = REQUESTER;
312
        IOWr:     get_tlp_transaction = REQUESTER;
313
        CfgRd0:   get_tlp_transaction = REQUESTER;
314
        CfgWr0:   get_tlp_transaction = REQUESTER;
315
        CfgRd1:   get_tlp_transaction = REQUESTER;
316
        CfgWr1:   get_tlp_transaction = REQUESTER;
317
        TCfgRd:   get_tlp_transaction = REQUESTER;
318
        TCfgWr:   get_tlp_transaction = REQUESTER;
319
        Msg:      get_tlp_transaction = REQUESTER;
320
        MsgD:     get_tlp_transaction = REQUESTER;
321
        Cpl:      get_tlp_transaction = COMPLETER;
322
        CplD:     get_tlp_transaction = COMPLETER;
323
        CplLk:    get_tlp_transaction = COMPLETER;
324
        CplDLk:   get_tlp_transaction = COMPLETER;
325
        FetchAdd: get_tlp_transaction = TRANSACTION_UNKNOWN;
326
        Swap:     get_tlp_transaction = TRANSACTION_UNKNOWN;
327
        CAS:      get_tlp_transaction = TRANSACTION_UNKNOWN;
328
        LPrfx:    get_tlp_transaction = TRANSACTION_UNKNOWN;
329
        EPrfx:    get_tlp_transaction = TRANSACTION_UNKNOWN;
330
        default:  get_tlp_transaction = TRANSACTION_UNKNOWN;
331
      endcase
332
 
333
    endfunction: get_tlp_transaction
334
 
335
 
336
    // --------------------------------------------------------------------
337
    //
338 33 qaztronic
    function void display_header(string str = "");
339
      tlp_routing_t routing_type = get_tlp_routing();
340 32 qaztronic
      tlp_transaction_t transaction_type = get_tlp_transaction;
341
 
342
      $display("??? %16.t | .....................", $time);
343 33 qaztronic
      $display("??? %16.t | %s | TLP type | %s", $time, str, tlp_type.name);
344 32 qaztronic
      // $display("??? %16.t | fmt           = %b | type = %b", $time, fmt_type[7:5], fmt_type[4:0]);
345
      $display("??? %16.t | length = %d", $time, length);
346
      $display("??? %16.t | tc = %b | th = %b | attr = %b | td = %b | ep = %b",
347
                $time, tc, th, attr, td, ep);
348
 
349
      if(routing_type == ADDRESS)
350 33 qaztronic
        if(is_4_dw)
351 32 qaztronic
          $display("??? %16.t | address[63:0] = 0x%16.x", $time,
352
                    { header[8],  header[9],  header[10], header[11],
353
                      header[12], header[13], header[14], header[15][7:2], 2'b00});
354
        else
355
          $display("??? %16.t | address[31:0] = 0x%8.x", $time,
356
                    { header[8],  header[9],  header[10], header[11][7:2], 2'b00});
357
      else if(routing_type == ID)
358
          $display("??? %16.t | bus = 0x%2.x | device = 0x%x | function = 0x%x", $time,
359
                    header[8],  header[9][7:3],  header[9][2:0]);
360
 
361
      if(transaction_type == COMPLETER)
362
      begin
363
        $display("??? %16.t | Completer ID  = %b", $time, {header[4], header[5]});
364
        $display("??? %16.t | requester ID  = %b", $time, {header[8], header[9]});
365
        $display("??? %16.t | tag           = %b", $time, header[10]);
366
      end
367
      else
368
      begin
369
        $display("??? %16.t | requester ID  = %b", $time, {header[4], header[5]});
370
        $display("??? %16.t | tag           = %b", $time, header[6]);
371
        $display("??? %16.t | last DW BE = %b | first DW BE = %b",
372
                  $time, header[7][7:4], header[7][3:0]);
373
      end
374
 
375 33 qaztronic
      // display_tlp_type(tlp_type);
376 32 qaztronic
 
377
      $display("??? %16.t | ---------------------", $time);
378
 
379
    endfunction: display_header
380
 
381
 
382
    //--------------------------------------------------------------------
383
    //
384 33 qaztronic
    function new(tlp_fmt_t tlp_fmt, tlp_type_t tlp_type, logic [9:0] length);
385
      this.tlp_fmt = tlp_fmt;
386
      this.tlp_type = tlp_type;
387
      this.fmt_type = get_fmt_type();
388 32 qaztronic
      this.length = length;
389 33 qaztronic
      if(is_3_dw)
390
        this.header = new[12];
391
      else
392
        this.header =  new[16];
393 32 qaztronic
      this.header[0] = fmt_type;
394
      this.header[3] = length[7:0];
395
      this.header[2][1:0] = length[9:8];
396
    endfunction: new
397
 
398
 
399
  // --------------------------------------------------------------------
400
  //
401
  endclass: tlp_header_class
402
 
403
 
404
// --------------------------------------------------------------------
405
//
406
endpackage: pcie_common_pkg
407
 
408
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.