xref: /XiangShan/src/main/scala/utils/TLDump.scala (revision c6d439803a044ea209139672b25e35fe8d7f4aa0)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3*
4* XiangShan is licensed under Mulan PSL v2.
5* You can use this software according to the terms and conditions of the Mulan PSL v2.
6* You may obtain a copy of Mulan PSL v2 at:
7*          http://license.coscl.org.cn/MulanPSL2
8*
9* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
12*
13* See the Mulan PSL v2 for more details.
14***************************************************************************************/
15
16package utils
17
18import chipsalliance.rocketchip.config.Parameters
19import chisel3._
20import chisel3.util._
21import freechips.rocketchip.tilelink.TLMessages._
22import freechips.rocketchip.tilelink.TLPermissions._
23import freechips.rocketchip.tilelink.{TLBundle, TLBundleA, TLBundleB, TLBundleC, TLBundleD, TLBundleE, TLChannel}
24
25trait HasTLDump {
26
27  implicit val p: Parameters
28
29  implicit class TLDump(channel: TLChannel) {
30    def dump = channel match {
31      case a: TLBundleA =>
32        printChannelA(a)
33      case b: TLBundleB =>
34        printChannelB(b)
35      case c: TLBundleC =>
36        printChannelC(c)
37      case d: TLBundleD =>
38        printChannelD(d)
39      case e: TLBundleE =>
40        printChannelE(e)
41    }
42  }
43
44  def printChannelA(a: TLBundleA): Unit = {
45    switch(a.opcode) {
46      is(PutFullData) {
47        XSDebug(false, true.B,
48          a.channelName + " PutFullData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
49          a.param, a.size, a.source, a.address, a.mask, a.data, a.corrupt
50        )
51      }
52
53      is(PutPartialData) {
54        XSDebug(false, true.B,
55          a.channelName + " PutPartialData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
56          a.param, a.size, a.source, a.address, a.mask, a.data, a.corrupt
57        )
58      }
59
60      is(ArithmeticData) {
61        XSDebug(false, true.B,
62          a.channelName + " ArithmeticData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
63          a.param, a.size, a.source, a.address, a.mask, a.data, a.corrupt
64        )
65      }
66
67      is(LogicalData) {
68        XSDebug(false, true.B,
69          a.channelName + " LogicalData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
70          a.param, a.size, a.source, a.address, a.mask, a.data, a.corrupt
71        )
72      }
73
74      is(Get) {
75        XSDebug(false, true.B,
76          a.channelName + " Get param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
77          a.param, a.size, a.source, a.address, a.mask, a.data, a.corrupt
78        )
79      }
80
81      is(Hint) {
82        XSDebug(false, true.B,
83          a.channelName + " Intent param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
84          a.param, a.size, a.source, a.address, a.mask, a.data, a.corrupt
85        )
86      }
87
88      is(AcquireBlock) {
89        switch(a.param) {
90          is(NtoB) {
91            XSDebug(false, true.B,
92              a.channelName + " AcquireBlock NtoB size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
93              a.size, a.source, a.address, a.mask, a.data, a.corrupt
94            )
95          }
96          is(NtoT) {
97            XSDebug(false, true.B,
98              a.channelName + " AcquireBlock NtoT size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
99              a.size, a.source, a.address, a.mask, a.data, a.corrupt
100            )
101          }
102          is(BtoT) {
103            XSDebug(false, true.B,
104              a.channelName + " AcquireBlock BtoT size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
105              a.size, a.source, a.address, a.mask, a.data, a.corrupt
106            )
107          }
108        }
109      }
110
111      is(AcquirePerm) {
112        switch(a.param) {
113          is(NtoB) {
114            XSDebug(false, true.B,
115              a.channelName + " AcquirePerm NtoB size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
116              a.size, a.source, a.address, a.mask, a.data, a.corrupt
117            )
118          }
119          is(NtoT) {
120            XSDebug(false, true.B,
121              a.channelName + " AcquirePerm NtoT size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
122              a.size, a.source, a.address, a.mask, a.data, a.corrupt
123            )
124          }
125          is(BtoT) {
126            XSDebug(false, true.B,
127              a.channelName + " AcquirePerm BtoT size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
128              a.size, a.source, a.address, a.mask, a.data, a.corrupt
129            )
130          }
131        }
132      }
133
134    }
135  }
136
137  def printChannelB(b: TLBundleB): Unit = {
138    switch(b.opcode) {
139      is(PutFullData) {
140        XSDebug(false, true.B,
141          b.channelName + " PutFullData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
142          b.param, b.size, b.source, b.address, b.mask, b.data, b.corrupt
143        )
144      }
145
146      is(PutPartialData) {
147        XSDebug(false, true.B,
148          b.channelName + " PutPartialData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
149          b.param, b.size, b.source, b.address, b.mask, b.data, b.corrupt
150        )
151      }
152
153      is(ArithmeticData) {
154        XSDebug(false, true.B,
155          b.channelName + " ArithmeticData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
156          b.param, b.size, b.source, b.address, b.mask, b.data, b.corrupt
157        )
158      }
159
160      is(LogicalData) {
161        XSDebug(false, true.B,
162          b.channelName + " LogicalData param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
163          b.param, b.size, b.source, b.address, b.mask, b.data, b.corrupt
164        )
165      }
166
167      is(Get) {
168        XSDebug(false, true.B,
169          b.channelName + " Get param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
170          b.param, b.size, b.source, b.address, b.mask, b.data, b.corrupt
171        )
172      }
173
174      is(Hint) {
175        XSDebug(false, true.B,
176          b.channelName + " Intent param: %x size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
177          b.param, b.size, b.source, b.address, b.mask, b.data, b.corrupt
178        )
179      }
180
181      is(Probe) {
182        switch(b.param) {
183          is(toN) {
184            XSDebug(false, true.B,
185              b.channelName + " Probe toN size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
186              b.size, b.source, b.address, b.mask, b.data, b.corrupt
187            )
188          }
189          is(toB) {
190            XSDebug(false, true.B,
191              b.channelName + " Probe toB size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
192              b.size, b.source, b.address, b.mask, b.data, b.corrupt
193            )
194          }
195          is(toT) {
196            XSDebug(false, true.B,
197              b.channelName + " Probe toT size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
198              b.size, b.source, b.address, b.mask, b.data, b.corrupt
199            )
200          }
201        }
202      }
203
204    }
205  }
206
207  def printChannelC(c: TLBundleC): Unit = {
208    switch(c.opcode) {
209      is(AccessAck) {
210        XSDebug(false, true.B,
211          c.channelName + " AccessAck param: %x size: %x source: %d address: %x data: %x corrupt: %b\n",
212          c.param, c.size, c.source, c.address, c.data, c.corrupt
213        )
214      }
215
216      is(AccessAckData) {
217        XSDebug(false, true.B,
218          c.channelName + " AccessAckData param: %x size: %x source: %d address: %x data: %x corrupt: %b\n",
219          c.param, c.size, c.source, c.address, c.data, c.corrupt
220        )
221      }
222
223      is(HintAck) {
224        XSDebug(false, true.B,
225          c.channelName + " HintAck param: %x size: %x source: %d address: %x data: %x corrupt: %b\n",
226          c.param, c.size, c.source, c.address, c.data, c.corrupt
227        )
228      }
229
230      is(ProbeAck) {
231        switch(c.param) {
232          is(TtoB) {
233            XSDebug(false, true.B,
234              c.channelName + " ProbeAck TtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
235              c.size, c.source, c.address, c.data, c.corrupt
236            )
237          }
238          is(TtoN) {
239            XSDebug(false, true.B,
240              c.channelName + " ProbeAck TtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
241              c.size, c.source, c.address, c.data, c.corrupt
242            )
243          }
244          is(BtoN) {
245            XSDebug(false, true.B,
246              c.channelName + " ProbeAck BtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
247              c.size, c.source, c.address, c.data, c.corrupt
248            )
249          }
250          is(TtoT) {
251            XSDebug(false, true.B,
252              c.channelName + " ProbeAck TtoT size: %x source: %d address: %x data: %x corrupt: %b\n",
253              c.size, c.source, c.address, c.data, c.corrupt
254            )
255          }
256          is(BtoB) {
257            XSDebug(false, true.B,
258              c.channelName + " ProbeAck BtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
259              c.size, c.source, c.address, c.data, c.corrupt
260            )
261          }
262          is(NtoN) {
263            XSDebug(false, true.B,
264              c.channelName + " ProbeAck NtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
265              c.size, c.source, c.address, c.data, c.corrupt
266            )
267          }
268        }
269      }
270
271      is(ProbeAckData) {
272        switch(c.param) {
273          is(TtoB) {
274            XSDebug(false, true.B,
275              c.channelName + " ProbeAckData TtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
276              c.size, c.source, c.address, c.data, c.corrupt
277            )
278          }
279          is(TtoN) {
280            XSDebug(false, true.B,
281              c.channelName + " ProbeAckData TtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
282              c.size, c.source, c.address, c.data, c.corrupt
283            )
284          }
285          is(BtoN) {
286            XSDebug(false, true.B,
287              c.channelName + " ProbeAckData BtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
288              c.size, c.source, c.address, c.data, c.corrupt
289            )
290          }
291          is(TtoT) {
292            XSDebug(false, true.B,
293              c.channelName + " ProbeAckData TtoT size: %x source: %d address: %x data: %x corrupt: %b\n",
294              c.size, c.source, c.address, c.data, c.corrupt
295            )
296          }
297          is(BtoB) {
298            XSDebug(false, true.B,
299              c.channelName + " ProbeAckData BtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
300              c.size, c.source, c.address, c.data, c.corrupt
301            )
302          }
303          is(NtoN) {
304            XSDebug(false, true.B,
305              c.channelName + " ProbeAckData NtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
306              c.size, c.source, c.address, c.data, c.corrupt
307            )
308          }
309        }
310      }
311
312      is(Release) {
313        switch(c.param) {
314          is(TtoB) {
315            XSDebug(false, true.B,
316              c.channelName + " Release TtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
317              c.size, c.source, c.address, c.data, c.corrupt
318            )
319          }
320          is(TtoN) {
321            XSDebug(false, true.B,
322              c.channelName + " Release TtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
323              c.size, c.source, c.address, c.data, c.corrupt
324            )
325          }
326          is(BtoN) {
327            XSDebug(false, true.B,
328              c.channelName + " Release BtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
329              c.size, c.source, c.address, c.data, c.corrupt
330            )
331          }
332          is(TtoT) {
333            XSDebug(false, true.B,
334              c.channelName + " Release TtoT size: %x source: %d address: %x data: %x corrupt: %b\n",
335              c.size, c.source, c.address, c.data, c.corrupt
336            )
337          }
338          is(BtoB) {
339            XSDebug(false, true.B,
340              c.channelName + " Release BtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
341              c.size, c.source, c.address, c.data, c.corrupt
342            )
343          }
344          is(NtoN) {
345            XSDebug(false, true.B,
346              c.channelName + " Release NtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
347              c.size, c.source, c.address, c.data, c.corrupt
348            )
349          }
350        }
351      }
352
353      is(ReleaseData) {
354        switch(c.param) {
355          is(TtoB) {
356            XSDebug(false, true.B,
357              c.channelName + " ReleaseData TtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
358              c.size, c.source, c.address, c.data, c.corrupt
359            )
360          }
361          is(TtoN) {
362            XSDebug(false, true.B,
363              c.channelName + " ReleaseData TtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
364              c.size, c.source, c.address, c.data, c.corrupt
365            )
366          }
367          is(BtoN) {
368            XSDebug(false, true.B,
369              c.channelName + " ReleaseData BtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
370              c.size, c.source, c.address, c.data, c.corrupt
371            )
372          }
373          is(TtoT) {
374            XSDebug(false, true.B,
375              c.channelName + " ReleaseData TtoT size: %x source: %d address: %x data: %x corrupt: %b\n",
376              c.size, c.source, c.address, c.data, c.corrupt
377            )
378          }
379          is(BtoB) {
380            XSDebug(false, true.B,
381              c.channelName + " ReleaseData BtoB size: %x source: %d address: %x data: %x corrupt: %b\n",
382              c.size, c.source, c.address, c.data, c.corrupt
383            )
384          }
385          is(NtoN) {
386            XSDebug(false, true.B,
387              c.channelName + " ReleaseData NtoN size: %x source: %d address: %x data: %x corrupt: %b\n",
388              c.size, c.source, c.address, c.data, c.corrupt
389            )
390          }
391        }
392      }
393
394    }
395  }
396
397  def printChannelD(d: TLBundleD): Unit = {
398    switch(d.opcode) {
399      is(AccessAck) {
400        XSDebug(false, true.B,
401          d.channelName + " AccessAck param: %x size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
402          d.param, d.size, d.source, d.sink, d.denied, d.data, d.corrupt
403        )
404      }
405
406      is(AccessAckData) {
407        XSDebug(false, true.B,
408          d.channelName + " AccessAckData param: %x size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
409          d.param, d.size, d.source, d.sink, d.denied, d.data, d.corrupt
410        )
411      }
412
413      is(HintAck) {
414        XSDebug(false, true.B,
415          d.channelName + " HintAck param: %x size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
416          d.param, d.size, d.source, d.sink, d.denied, d.data, d.corrupt
417        )
418      }
419
420      is(Grant) {
421        switch(d.param) {
422          is(toT) {
423            XSDebug(false, true.B,
424              d.channelName + " Grant toT size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
425              d.size, d.source, d.sink, d.denied, d.data, d.corrupt
426            )
427          }
428          is(toB) {
429            XSDebug(false, true.B,
430              d.channelName + " Grant toB size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
431              d.size, d.source, d.sink, d.denied, d.data, d.corrupt
432            )
433          }
434          is(toN) {
435            XSDebug(false, true.B,
436              d.channelName + " Grant toN size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
437              d.size, d.source, d.sink, d.denied, d.data, d.corrupt
438            )
439          }
440        }
441      }
442
443      is(GrantData) {
444        switch(d.param) {
445          is(toT) {
446            XSDebug(false, true.B,
447              d.channelName + " GrantData toT size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
448              d.size, d.source, d.sink, d.denied, d.data, d.corrupt
449            )
450          }
451          is(toB) {
452            XSDebug(false, true.B,
453              d.channelName + " GrantData toB size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
454              d.size, d.source, d.sink, d.denied, d.data, d.corrupt
455            )
456          }
457          is(toN) {
458            XSDebug(false, true.B,
459              d.channelName + " GrantData toN size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
460              d.size, d.source, d.sink, d.denied, d.data, d.corrupt
461            )
462          }
463        }
464      }
465
466      is(ReleaseAck) {
467        XSDebug(false, true.B,
468          d.channelName + " ReleaseAck param: %x size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
469          d.param, d.size, d.source, d.sink, d.denied, d.data, d.corrupt
470        )
471      }
472
473    }
474  }
475
476  def printChannelE(e: TLBundleE): Unit = {
477    XSDebug(false, true.B, e.channelName + "GrantAck sink: %d\n", e.sink)
478  }
479
480}
481