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 |
|
|
ROUTING_UNKNOWN,
|
63 |
|
|
ADDRESS,
|
64 |
|
|
ID,
|
65 |
|
|
IMPLICIT
|
66 |
|
|
} tlp_routing_t;
|
67 |
|
|
|
68 |
|
|
typedef enum
|
69 |
|
|
{
|
70 |
|
|
TRANSACTION_UNKNOWN,
|
71 |
|
|
REQUESTER,
|
72 |
|
|
COMPLETER
|
73 |
|
|
} tlp_transaction_t;
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
// --------------------------------------------------------------------
|
77 |
|
|
//
|
78 |
|
|
class tlp_header_class;
|
79 |
|
|
|
80 |
|
|
tlp_type_t header_type;
|
81 |
|
|
logic [7:0] fmt_type;
|
82 |
|
|
logic [2:0] tc;
|
83 |
|
|
logic th;
|
84 |
|
|
logic [2:0] attr;
|
85 |
|
|
logic td;
|
86 |
|
|
logic ep;
|
87 |
|
|
logic [9:0] length;
|
88 |
|
|
logic [7:0] header[16];
|
89 |
|
|
logic header_is_4_dw;
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
// --------------------------------------------------------------------
|
93 |
|
|
//
|
94 |
|
|
// function logic [7:0] get_fmt_type(tlp_type_t header_type);
|
95 |
|
|
function logic [7:0] get_fmt_type;
|
96 |
|
|
casez(header_type)
|
97 |
|
|
MRd: get_fmt_type = 8'b000_00000;
|
98 |
|
|
MRd: get_fmt_type = 8'b001_00000;
|
99 |
|
|
MRdLk: get_fmt_type = 8'b000_00001;
|
100 |
|
|
MRdLk: get_fmt_type = 8'b001_00001;
|
101 |
|
|
MWr: get_fmt_type = 8'b010_00000;
|
102 |
|
|
MWr: get_fmt_type = 8'b011_00000;
|
103 |
|
|
IORd: get_fmt_type = 8'b000_00010;
|
104 |
|
|
IOWr: get_fmt_type = 8'b010_00010;
|
105 |
|
|
CfgRd0: get_fmt_type = 8'b000_00100;
|
106 |
|
|
CfgWr0: get_fmt_type = 8'b010_00100;
|
107 |
|
|
CfgRd1: get_fmt_type = 8'b000_00101;
|
108 |
|
|
CfgWr1: get_fmt_type = 8'b010_00101;
|
109 |
|
|
TCfgRd: get_fmt_type = 8'b000_11011;
|
110 |
|
|
TCfgWr: get_fmt_type = 8'b010_11011;
|
111 |
|
|
Msg: get_fmt_type = 8'b001_10xxx;
|
112 |
|
|
MsgD: get_fmt_type = 8'b011_10xxx;
|
113 |
|
|
Cpl: get_fmt_type = 8'b000_01010;
|
114 |
|
|
CplD: get_fmt_type = 8'b010_01010;
|
115 |
|
|
CplLk: get_fmt_type = 8'b000_01011;
|
116 |
|
|
CplDLk: get_fmt_type = 8'b010_01011;
|
117 |
|
|
FetchAdd: get_fmt_type = 8'b010_01100;
|
118 |
|
|
FetchAdd: get_fmt_type = 8'b011_01100;
|
119 |
|
|
Swap: get_fmt_type = 8'b010_01101;
|
120 |
|
|
Swap: get_fmt_type = 8'b011_01101;
|
121 |
|
|
CAS: get_fmt_type = 8'b010_01110;
|
122 |
|
|
CAS: get_fmt_type = 8'b011_01110;
|
123 |
|
|
LPrfx: get_fmt_type = 8'b100_0xxxx;
|
124 |
|
|
EPrfx: get_fmt_type = 8'b100_1xxxx;
|
125 |
|
|
default: get_fmt_type = Reserved;
|
126 |
|
|
endcase
|
127 |
|
|
endfunction: get_fmt_type
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
// --------------------------------------------------------------------
|
131 |
|
|
//
|
132 |
|
|
function tlp_type_t get_tlp_type(logic [7:0] fmt_type);
|
133 |
|
|
casez(fmt_type)
|
134 |
|
|
8'b000_00000: get_tlp_type = MRd;
|
135 |
|
|
8'b001_00000: get_tlp_type = MRd;
|
136 |
|
|
8'b000_00001: get_tlp_type = MRdLk;
|
137 |
|
|
8'b001_00001: get_tlp_type = MRdLk;
|
138 |
|
|
8'b010_00000: get_tlp_type = MWr;
|
139 |
|
|
8'b011_00000: get_tlp_type = MWr;
|
140 |
|
|
8'b000_00010: get_tlp_type = IORd;
|
141 |
|
|
8'b010_00010: get_tlp_type = IOWr;
|
142 |
|
|
8'b000_00100: get_tlp_type = CfgRd0;
|
143 |
|
|
8'b010_00100: get_tlp_type = CfgWr0;
|
144 |
|
|
8'b000_00101: get_tlp_type = CfgRd1;
|
145 |
|
|
8'b010_00101: get_tlp_type = CfgWr1;
|
146 |
|
|
8'b000_11011: get_tlp_type = TCfgRd;
|
147 |
|
|
8'b010_11011: get_tlp_type = TCfgWr;
|
148 |
|
|
8'b001_10???: get_tlp_type = Msg;
|
149 |
|
|
8'b011_10???: get_tlp_type = MsgD;
|
150 |
|
|
8'b000_01010: get_tlp_type = Cpl;
|
151 |
|
|
8'b010_01010: get_tlp_type = CplD;
|
152 |
|
|
8'b000_01011: get_tlp_type = CplLk;
|
153 |
|
|
8'b010_01011: get_tlp_type = CplDLk;
|
154 |
|
|
8'b010_01100: get_tlp_type = FetchAdd;
|
155 |
|
|
8'b011_01100: get_tlp_type = FetchAdd;
|
156 |
|
|
8'b010_01101: get_tlp_type = Swap;
|
157 |
|
|
8'b011_01101: get_tlp_type = Swap;
|
158 |
|
|
8'b010_01110: get_tlp_type = CAS;
|
159 |
|
|
8'b011_01110: get_tlp_type = CAS;
|
160 |
|
|
8'b100_0????: get_tlp_type = LPrfx;
|
161 |
|
|
8'b100_1????: get_tlp_type = EPrfx;
|
162 |
|
|
default: get_tlp_type = Reserved;
|
163 |
|
|
endcase
|
164 |
|
|
endfunction: get_tlp_type
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
// --------------------------------------------------------------------
|
168 |
|
|
//
|
169 |
|
|
// function tlp_routing_t get_tlp_routing(tlp_type_t header_type);
|
170 |
|
|
function tlp_routing_t get_tlp_routing;
|
171 |
|
|
|
172 |
|
|
case(header_type)
|
173 |
|
|
MRd: get_tlp_routing = ADDRESS;
|
174 |
|
|
MRdLk: get_tlp_routing = ADDRESS;
|
175 |
|
|
MWr: get_tlp_routing = ADDRESS;
|
176 |
|
|
IORd: get_tlp_routing = ADDRESS;
|
177 |
|
|
IOWr: get_tlp_routing = ADDRESS;
|
178 |
|
|
CfgRd0: get_tlp_routing = ID;
|
179 |
|
|
CfgWr0: get_tlp_routing = ID;
|
180 |
|
|
CfgRd1: get_tlp_routing = ID;
|
181 |
|
|
CfgWr1: get_tlp_routing = ID;
|
182 |
|
|
TCfgRd: get_tlp_routing = ID;
|
183 |
|
|
TCfgWr: get_tlp_routing = ID;
|
184 |
|
|
Msg: get_tlp_routing = ROUTING_UNKNOWN;
|
185 |
|
|
MsgD: get_tlp_routing = ROUTING_UNKNOWN;
|
186 |
|
|
Cpl: get_tlp_routing = ID;
|
187 |
|
|
CplD: get_tlp_routing = ID;
|
188 |
|
|
CplLk: get_tlp_routing = ID;
|
189 |
|
|
CplDLk: get_tlp_routing = ID;
|
190 |
|
|
FetchAdd: get_tlp_routing = ROUTING_UNKNOWN;
|
191 |
|
|
Swap: get_tlp_routing = ROUTING_UNKNOWN;
|
192 |
|
|
CAS: get_tlp_routing = ROUTING_UNKNOWN;
|
193 |
|
|
LPrfx: get_tlp_routing = ROUTING_UNKNOWN;
|
194 |
|
|
EPrfx: get_tlp_routing = ROUTING_UNKNOWN;
|
195 |
|
|
default: get_tlp_routing = ROUTING_UNKNOWN;
|
196 |
|
|
endcase
|
197 |
|
|
|
198 |
|
|
endfunction: get_tlp_routing
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
// --------------------------------------------------------------------
|
202 |
|
|
//
|
203 |
|
|
// function tlp_transaction_t get_tlp_transaction(tlp_type_t header_type);
|
204 |
|
|
function tlp_transaction_t get_tlp_transaction;
|
205 |
|
|
|
206 |
|
|
case(header_type)
|
207 |
|
|
MRd: get_tlp_transaction = REQUESTER;
|
208 |
|
|
MRdLk: get_tlp_transaction = REQUESTER;
|
209 |
|
|
MWr: get_tlp_transaction = REQUESTER;
|
210 |
|
|
IORd: get_tlp_transaction = REQUESTER;
|
211 |
|
|
IOWr: get_tlp_transaction = REQUESTER;
|
212 |
|
|
CfgRd0: get_tlp_transaction = REQUESTER;
|
213 |
|
|
CfgWr0: get_tlp_transaction = REQUESTER;
|
214 |
|
|
CfgRd1: get_tlp_transaction = REQUESTER;
|
215 |
|
|
CfgWr1: get_tlp_transaction = REQUESTER;
|
216 |
|
|
TCfgRd: get_tlp_transaction = REQUESTER;
|
217 |
|
|
TCfgWr: get_tlp_transaction = REQUESTER;
|
218 |
|
|
Msg: get_tlp_transaction = REQUESTER;
|
219 |
|
|
MsgD: get_tlp_transaction = REQUESTER;
|
220 |
|
|
Cpl: get_tlp_transaction = COMPLETER;
|
221 |
|
|
CplD: get_tlp_transaction = COMPLETER;
|
222 |
|
|
CplLk: get_tlp_transaction = COMPLETER;
|
223 |
|
|
CplDLk: get_tlp_transaction = COMPLETER;
|
224 |
|
|
FetchAdd: get_tlp_transaction = TRANSACTION_UNKNOWN;
|
225 |
|
|
Swap: get_tlp_transaction = TRANSACTION_UNKNOWN;
|
226 |
|
|
CAS: get_tlp_transaction = TRANSACTION_UNKNOWN;
|
227 |
|
|
LPrfx: get_tlp_transaction = TRANSACTION_UNKNOWN;
|
228 |
|
|
EPrfx: get_tlp_transaction = TRANSACTION_UNKNOWN;
|
229 |
|
|
default: get_tlp_transaction = TRANSACTION_UNKNOWN;
|
230 |
|
|
endcase
|
231 |
|
|
|
232 |
|
|
endfunction: get_tlp_transaction
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
// --------------------------------------------------------------------
|
236 |
|
|
//
|
237 |
|
|
function void display_header(string str);
|
238 |
|
|
tlp_routing_t routing_type = get_tlp_routing;
|
239 |
|
|
tlp_transaction_t transaction_type = get_tlp_transaction;
|
240 |
|
|
|
241 |
|
|
$display("??? %16.t | .....................", $time);
|
242 |
|
|
$display("??? %16.t | %s | TLP type | %s", $time, str, header_type.name);
|
243 |
|
|
// $display("??? %16.t | fmt = %b | type = %b", $time, fmt_type[7:5], fmt_type[4:0]);
|
244 |
|
|
$display("??? %16.t | length = %d", $time, length);
|
245 |
|
|
$display("??? %16.t | tc = %b | th = %b | attr = %b | td = %b | ep = %b",
|
246 |
|
|
$time, tc, th, attr, td, ep);
|
247 |
|
|
|
248 |
|
|
if(routing_type == ADDRESS)
|
249 |
|
|
if(header_is_4_dw)
|
250 |
|
|
$display("??? %16.t | address[63:0] = 0x%16.x", $time,
|
251 |
|
|
{ header[8], header[9], header[10], header[11],
|
252 |
|
|
header[12], header[13], header[14], header[15][7:2], 2'b00});
|
253 |
|
|
else
|
254 |
|
|
$display("??? %16.t | address[31:0] = 0x%8.x", $time,
|
255 |
|
|
{ header[8], header[9], header[10], header[11][7:2], 2'b00});
|
256 |
|
|
else if(routing_type == ID)
|
257 |
|
|
$display("??? %16.t | bus = 0x%2.x | device = 0x%x | function = 0x%x", $time,
|
258 |
|
|
header[8], header[9][7:3], header[9][2:0]);
|
259 |
|
|
|
260 |
|
|
if(transaction_type == COMPLETER)
|
261 |
|
|
begin
|
262 |
|
|
$display("??? %16.t | Completer ID = %b", $time, {header[4], header[5]});
|
263 |
|
|
$display("??? %16.t | requester ID = %b", $time, {header[8], header[9]});
|
264 |
|
|
$display("??? %16.t | tag = %b", $time, header[10]);
|
265 |
|
|
end
|
266 |
|
|
else
|
267 |
|
|
begin
|
268 |
|
|
$display("??? %16.t | requester ID = %b", $time, {header[4], header[5]});
|
269 |
|
|
$display("??? %16.t | tag = %b", $time, header[6]);
|
270 |
|
|
$display("??? %16.t | last DW BE = %b | first DW BE = %b",
|
271 |
|
|
$time, header[7][7:4], header[7][3:0]);
|
272 |
|
|
end
|
273 |
|
|
|
274 |
|
|
// display_tlp_type(header_type);
|
275 |
|
|
|
276 |
|
|
$display("??? %16.t | ---------------------", $time);
|
277 |
|
|
|
278 |
|
|
endfunction: display_header
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
//--------------------------------------------------------------------
|
282 |
|
|
//
|
283 |
|
|
function new(tlp_type_t header_type, logic [9:0] length);
|
284 |
|
|
this.header_type = header_type;
|
285 |
|
|
this.fmt_type = get_fmt_type;
|
286 |
|
|
this.length = length;
|
287 |
|
|
this.header_is_4_dw = fmt_type[5];
|
288 |
|
|
this.header[0] = fmt_type;
|
289 |
|
|
this.header[3] = length[7:0];
|
290 |
|
|
this.header[2][1:0] = length[9:8];
|
291 |
|
|
endfunction: new
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
// --------------------------------------------------------------------
|
295 |
|
|
//
|
296 |
|
|
endclass: tlp_header_class
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
// --------------------------------------------------------------------
|
300 |
|
|
//
|
301 |
|
|
endpackage: pcie_common_pkg
|
302 |
|
|
|
303 |
|
|
|