xref: /XiangShan/src/main/scala/utils/TLDump.scala (revision 94aa21c6009c2f39c5c5dae9c87260c78887efcc)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3* Copyright (c) 2020-2021 Peng Cheng Laboratory
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15***************************************************************************************/
16
17package utils
18
19import org.chipsalliance.cde.config.Parameters
20import chisel3._
21import chisel3.util._
22import freechips.rocketchip.tilelink.TLMessages._
23import freechips.rocketchip.tilelink.TLPermissions._
24import freechips.rocketchip.tilelink.{TLBundle, TLBundleA, TLBundleB, TLBundleC, TLBundleD, TLBundleE, TLChannel}
25import utility.XSDebug
26
27trait HasTLDump {
28
29  implicit val p: Parameters
30
31  implicit class TLDump(channel: TLChannel) {
32    def dump(cond: Bool) = channel match {
33      case a: TLBundleA =>
34        printChannelA(a, cond)
35      case b: TLBundleB =>
36        printChannelB(b, cond)
37      case c: TLBundleC =>
38        printChannelC(c, cond)
39      case d: TLBundleD =>
40        printChannelD(d, cond)
41      case e: TLBundleE =>
42        printChannelE(e, cond)
43    }
44  }
45
46  def printChannelA(a: TLBundleA, cond: Bool): Unit = {
47    def APrintable(opStr: String, paramStr: String = ""): Printable = {
48      a.channelName + " " + opStr + " " +
49        (if (paramStr != "") paramStr else Printable.pack("param: %x", a.param)) +
50        Printable.pack(" size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
51          a.size, a.source, a.address, a.mask, a.data, a.corrupt)
52    }
53    def ACond(opCode: UInt, param: Option[UInt] = None): Bool = {
54      // skip param compare if not passed
55      val paramComp = if (param.isDefined) a.param === param.get else true.B
56      cond && a.opcode === opCode && paramComp
57    }
58
59    XSDebug(false, ACond(PutFullData), APrintable("PutFullData"))
60    XSDebug(false, ACond(PutPartialData), APrintable("PutPartialData"))
61    XSDebug(false, ACond(ArithmeticData), APrintable("ArithmeticData"))
62    XSDebug(false, ACond(LogicalData), APrintable("LogicalData"))
63    XSDebug(false, ACond(Get), APrintable("Get"))
64    XSDebug(false, ACond(Hint), APrintable("Intent"))
65
66    XSDebug(false, ACond(AcquireBlock, Some(NtoB)), APrintable("AcquireBlock", "NtoB"))
67    XSDebug(false, ACond(AcquireBlock, Some(NtoT)), APrintable("AcquireBlock", "NtoT"))
68    XSDebug(false, ACond(AcquireBlock, Some(BtoT)), APrintable("AcquireBlock", "BtoT"))
69
70    XSDebug(false, ACond(AcquirePerm, Some(NtoB)), APrintable("AcquirePerm", "NtoB"))
71    XSDebug(false, ACond(AcquirePerm, Some(NtoT)), APrintable("AcquirePerm", "NtoT"))
72    XSDebug(false, ACond(AcquirePerm, Some(BtoT)), APrintable("AcquirePerm", "BtoT"))
73  }
74
75  def printChannelB(b: TLBundleB, cond: Bool): Unit = {
76    def BPrintable(opStr: String, paramStr: String = ""): Printable = {
77      b.channelName + " " + opStr + " " +
78        (if (paramStr != "") paramStr else Printable.pack("param: %x", b.param)) +
79        Printable.pack(" size: %x source: %d address: %x mask: %x data: %x corrupt: %b\n",
80          b.size, b.source, b.address, b.mask, b.data, b.corrupt)
81    }
82    def BCond(opCode: UInt, param: Option[UInt] = None): Bool = {
83      // skip param compare if not passed
84      val paramComp = if (param.isDefined) b.param === param.get else true.B
85      cond && b.opcode === opCode && paramComp
86    }
87
88    XSDebug(false, BCond(PutFullData), BPrintable("PutFullData"))
89    XSDebug(false, BCond(PutPartialData), BPrintable("PutPartialData"))
90    XSDebug(false, BCond(ArithmeticData), BPrintable("ArithmeticData"))
91    XSDebug(false, BCond(LogicalData), BPrintable("LogicalData"))
92    XSDebug(false, BCond(Get), BPrintable("Get"))
93    XSDebug(false, BCond(Hint), BPrintable("Intent"))
94
95    XSDebug(false, BCond(Probe, Some(toN)), BPrintable("Probe", "toN"))
96    XSDebug(false, BCond(Probe, Some(toB)), BPrintable("Probe", "toB"))
97    XSDebug(false, BCond(Probe, Some(toT)), BPrintable("Probe", "toT"))
98  }
99
100  def printChannelC(c: TLBundleC, cond: Bool): Unit = {
101    def CPrintable(opStr: String, paramStr: String = ""): Printable = {
102      c.channelName + " " + opStr + " " +
103        (if (paramStr != "") paramStr else Printable.pack("param: %x", c.param)) +
104        Printable.pack(" size: %x source: %d address: %x data: %x corrupt: %b\n",
105          c.size, c.source, c.address, c.data, c.corrupt)
106    }
107    def CCond(opCode: UInt, param: Option[UInt] = None): Bool = {
108      // skip param compare if not passed
109      val paramComp = if (param.isDefined) c.param === param.get else true.B
110      cond && c.opcode === opCode && paramComp
111    }
112
113    XSDebug(false, CCond(AccessAck), CPrintable("AccessAck"))
114    XSDebug(false, CCond(AccessAckData), CPrintable("AccessAckData"))
115    XSDebug(false, CCond(HintAck), CPrintable("HintAck"))
116
117    XSDebug(false, CCond(ProbeAck, Some(TtoB)), CPrintable("ProbeAck", "TtoB"))
118    XSDebug(false, CCond(ProbeAck, Some(TtoN)), CPrintable("ProbeAck", "TtoN"))
119    XSDebug(false, CCond(ProbeAck, Some(BtoN)), CPrintable("ProbeAck", "BtoN"))
120    XSDebug(false, CCond(ProbeAck, Some(TtoT)), CPrintable("ProbeAck", "TtoT"))
121    XSDebug(false, CCond(ProbeAck, Some(BtoB)), CPrintable("ProbeAck", "BtoB"))
122    XSDebug(false, CCond(ProbeAck, Some(NtoN)), CPrintable("ProbeAck", "NtoN"))
123
124    XSDebug(false, CCond(ProbeAckData, Some(TtoB)), CPrintable("ProbeAckData", "TtoB"))
125    XSDebug(false, CCond(ProbeAckData, Some(TtoN)), CPrintable("ProbeAckData", "TtoN"))
126    XSDebug(false, CCond(ProbeAckData, Some(BtoN)), CPrintable("ProbeAckData", "BtoN"))
127    XSDebug(false, CCond(ProbeAckData, Some(TtoT)), CPrintable("ProbeAckData", "TtoT"))
128    XSDebug(false, CCond(ProbeAckData, Some(BtoB)), CPrintable("ProbeAckData", "BtoB"))
129    XSDebug(false, CCond(ProbeAckData, Some(NtoN)), CPrintable("ProbeAckData", "NtoN"))
130
131    XSDebug(false, CCond(Release, Some(TtoB)), CPrintable("Release", "TtoB"))
132    XSDebug(false, CCond(Release, Some(TtoN)), CPrintable("Release", "TtoN"))
133    XSDebug(false, CCond(Release, Some(BtoN)), CPrintable("Release", "BtoN"))
134    XSDebug(false, CCond(Release, Some(TtoT)), CPrintable("Release", "TtoT"))
135    XSDebug(false, CCond(Release, Some(BtoB)), CPrintable("Release", "BtoB"))
136    XSDebug(false, CCond(Release, Some(NtoN)), CPrintable("Release", "NtoN"))
137
138    XSDebug(false, CCond(ReleaseData, Some(TtoB)), CPrintable("ReleaseData", "TtoB"))
139    XSDebug(false, CCond(ReleaseData, Some(TtoN)), CPrintable("ReleaseData", "TtoN"))
140    XSDebug(false, CCond(ReleaseData, Some(BtoN)), CPrintable("ReleaseData", "BtoN"))
141    XSDebug(false, CCond(ReleaseData, Some(TtoT)), CPrintable("ReleaseData", "TtoT"))
142    XSDebug(false, CCond(ReleaseData, Some(BtoB)), CPrintable("ReleaseData", "BtoB"))
143    XSDebug(false, CCond(ReleaseData, Some(NtoN)), CPrintable("ReleaseData", "NtoN"))
144  }
145
146  def printChannelD(d: TLBundleD, cond: Bool): Unit = {
147    def DPrintable(opStr: String, paramStr: String = ""): Printable = {
148      d.channelName + " " + opStr + " " +
149        (if (paramStr != "") paramStr else Printable.pack("param: %x", d.param)) +
150        Printable.pack(" size: %x source: %d sink: %d denied: %b data: %x corrupt: %b\n",
151          d.size, d.source, d.sink, d.denied, d.data, d.corrupt)
152    }
153    def DCond(opCode: UInt, param: Option[UInt] = None): Bool = {
154      // skip param compare if not passed
155      val paramComp = if (param.isDefined) d.param === param.get else true.B
156      cond && d.opcode === opCode && paramComp
157    }
158
159    XSDebug(false, DCond(AccessAck), DPrintable("AccessAck"))
160    XSDebug(false, DCond(AccessAckData), DPrintable("AccessAckData"))
161    XSDebug(false, DCond(HintAck), DPrintable("HintAck"))
162
163    XSDebug(false, DCond(Grant, Some(toT)), DPrintable("Grant", "toT"))
164    XSDebug(false, DCond(Grant, Some(toB)), DPrintable("Grant", "toB"))
165    XSDebug(false, DCond(Grant, Some(toN)), DPrintable("Grant", "toN"))
166
167    XSDebug(false, DCond(GrantData, Some(toT)), DPrintable("GrantData", "toT"))
168    XSDebug(false, DCond(GrantData, Some(toB)), DPrintable("GrantData", "toB"))
169    XSDebug(false, DCond(GrantData, Some(toN)), DPrintable("GrantData", "toN"))
170
171    XSDebug(false, DCond(GrantData, Some(toT)), DPrintable("GrantData", "toT"))
172    XSDebug(false, DCond(GrantData, Some(toB)), DPrintable("GrantData", "toB"))
173    XSDebug(false, DCond(GrantData, Some(toN)), DPrintable("GrantData", "toN"))
174
175    XSDebug(false, DCond(ReleaseAck), DPrintable("ReleaseAck"))
176  }
177
178  def printChannelE(e: TLBundleE, cond: Bool): Unit = {
179    XSDebug(false, cond, e.channelName + "GrantAck sink: %d\n", e.sink)
180  }
181
182}
183