-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathTestTop.scala
More file actions
353 lines (299 loc) · 10.9 KB
/
TestTop.scala
File metadata and controls
353 lines (299 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package coupledL2
import chisel3._
import circt.stage.ChiselStage
import chisel3.util._
import org.chipsalliance.cde.config._
import chisel3.stage.ChiselGeneratorAnnotation
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.tilelink._
import freechips.rocketchip.tile.MaxHartIdBits
import huancun._
import coupledL2.prefetch._
import coupledL2.tl2chi._
import utility._
import utility.chiron._
import scala.collection.mutable.ArrayBuffer
class TestTop_CHIL2(numCores: Int = 1, numULAgents: Int = 0, banks: Int = 1, extTime: Boolean = false, vTime: Boolean = false)(implicit p: Parameters) extends LazyModule
with HasCHIMsgParameters {
/* L1D(L1I)* L1D(L1I)* ... L1D(L1I)*
* \ | /
* L2 L2 ... L2
* \ | /
* \ | /
* NoC or VIP
*/
override lazy val desiredName: String = "TestTop"
val delayFactor = 0.5
val cacheParams = p(L2ParamKey)
val clogId = "l2top"
println(s"CLog.b shared handle Id: ${clogId}")
println(s"eTime: ${extTime}")
println(s"vTime: ${vTime}")
def createClientNode(name: String, sources: Int) = {
val masterNode = TLClientNode(Seq(
TLMasterPortParameters.v2(
masters = Seq(
TLMasterParameters.v1(
name = name,
sourceId = IdRange(0, sources),
supportsProbe = TransferSizes(cacheParams.blockBytes)
)
),
channelBytes = TLChannelBeatBytes(cacheParams.blockBytes),
minLatency = 1,
echoFields = Nil,
requestFields = Seq(AliasField(2), VaddrField(36), PrefetchField()),
responseKeys = cacheParams.respKey
)
))
masterNode
}
val l1d_nodes = (0 until numCores).map(i => createClientNode(s"l1d$i", 64))
val l1i_nodes = (0 until numCores).map {i =>
(0 until numULAgents).map { j =>
TLClientNode(Seq(
TLMasterPortParameters.v1(
clients = Seq(TLMasterParameters.v1(
name = s"l1i${i}_${j}",
sourceId = IdRange(0, 64)
))
)
))
}
}
// val l2 = LazyModule(new TL2CHICoupledL2())
val l2_nodes = (0 until numCores).map(i => LazyModule(new TL2CHICoupledL2()(new Config((site, here, up) => {
case L2ParamKey => cacheParams.copy(
name = s"L2_$i",
hartId = i,
)
case CHIIssue => p(CHIIssue)
case EnableCHI => p(EnableCHI)
case BankBitsKey => log2Ceil(banks)
case MaxHartIdBits => log2Up(numCores)
case LogUtilsOptionsKey => LogUtilsOptions(
false,
here(L2ParamKey).enablePerf,
here(L2ParamKey).FPGAPlatform
)
case PerfCounterOptionsKey => PerfCounterOptions(
here(L2ParamKey).enablePerf && !here(L2ParamKey).FPGAPlatform,
here(L2ParamKey).enableRollingDB && !here(L2ParamKey).FPGAPlatform,
XSPerfLevel.withName("VERBOSE"),
i
)
}))))
val bankBinders = (0 until numCores).map(_ => BankBinder(banks, 64))
val mmio_nodes = l1d_nodes.zip(l2_nodes).zipWithIndex.map { case ((l1d, l2), i) =>
val l1xbar = TLXbar()
l1xbar :=
TLBuffer() :=
TLLogger(s"L2_L1[${i}].C[0]", !cacheParams.FPGAPlatform && cacheParams.enableTLLog) :=
l1d
l1i_nodes(i).zipWithIndex.foreach { case (l1i, j) =>
l1xbar :=
TLBuffer() :=
TLLogger(s"L2_L1[${i}].UL[${j}]", !cacheParams.FPGAPlatform && cacheParams.enableTLLog) :=
l1i
}
l2.managerNode :=
TLXbar() :=*
bankBinders(i) :*=
l2.node :*=
l1xbar
val mmioClientNode = TLClientNode(Seq(
TLMasterPortParameters.v1(
clients = Seq(TLMasterParameters.v1(
name = "uncache",
sourceId = IdRange(0, 16)
))
)
))
l2.mmioBridge.mmioNode := mmioClientNode
mmioClientNode
}
lazy val module = new LazyModuleImp(this){
val time_sim = if (extTime) {
IO(Input(UInt(64.W)))
} else {
WireDefault(0.U(64.W))
}
val timer = WireDefault(0.U(64.W))
val logEnable = WireDefault(false.B)
val clean = WireDefault(false.B)
val dump = WireDefault(false.B)
dontTouch(timer)
dontTouch(logEnable)
dontTouch(clean)
dontTouch(dump)
l1d_nodes.zipWithIndex.foreach{
case (node, i) =>
node.makeIOs()(ValName(s"master_port_$i"))
}
if (numULAgents != 0) {
l1i_nodes.zipWithIndex.foreach { case (core, i) =>
core.zipWithIndex.foreach { case (node, j) =>
node.makeIOs()(ValName(s"master_ul_port_${i}_${j}"))
}
}
}
mmio_nodes.zipWithIndex.foreach {
case (node, i) =>
node.makeIOs()(ValName(s"mmio_port_$i"))
}
val io = IO(Vec(numCores, new Bundle() {
val chi = new PortIO
val nodeId = Input(UInt(NODEID_WIDTH.W))
}))
val io_powerdown = IO(Vec(numCores, new Bundle {
val flushAll = Input(Bool())
val flushAllDone = Output(Bool())
val cpuHalt = Input(Bool())
}))
val io_linkdown = IO(Vec(numCores, Output(Bool())))
val io_resetsep = IO(Vec(numCores, Input(Bool())))
l2_nodes.zipWithIndex.foreach { case (l2, i) =>
if (!cacheParams.FPGAPlatform && cacheParams.enableCHILog) {
CLogB.logFlitsRNOfRNF(
id = clogId,
vTime = vTime,
clock = l2.module.clock,
reset = l2.module.reset,
rnId = l2.module.io_nodeID,
txreqflit = l2.module.io_chi.tx.req.flit, txreqflitv = l2.module.io_chi.tx.req.flitv,
rxrspflit = l2.module.io_chi.rx.rsp.flit, rxrspflitv = l2.module.io_chi.rx.rsp.flitv,
rxdatflit = l2.module.io_chi.rx.dat.flit, rxdatflitv = l2.module.io_chi.rx.dat.flitv,
rxsnpflit = l2.module.io_chi.rx.snp.flit, rxsnpflitv = l2.module.io_chi.rx.snp.flitv,
txrspflit = l2.module.io_chi.tx.rsp.flit, txrspflitv = l2.module.io_chi.tx.rsp.flitv,
txdatflit = l2.module.io_chi.tx.dat.flit, txdatflitv = l2.module.io_chi.tx.dat.flitv,
time = time_sim, timev = extTime.B
)
}
l2.module.io_chi <> io(i).chi
dontTouch(l2.module.io)
l2.module.io.hartId := i.U
l2.module.io.pfCtrlFromCore := DontCare
l2.module.io_nodeID := io(i).nodeId
l2.module.io.debugTopDown := DontCare
l2.module.io.l2_tlb_req <> DontCare
l2.module.io.l2Flush.foreach(_ := io_powerdown(i).flushAll)
io_powerdown(i).flushAllDone := l2.module.io.l2FlushDone.getOrElse(false.B)
l2.module.io_cpu_halt.foreach(_ := io_powerdown(i).cpuHalt)
l2.module.reset := io_resetsep(i) || reset.asBool
io_linkdown(i) := !l2.module.io_chi.syscoreq && !l2.module.io_chi.syscoack &&
!l2.module.io_chi.tx.linkactivereq && !l2.module.io_chi.tx.linkactiveack &&
!l2.module.io_chi.rx.linkactivereq && !l2.module.io_chi.rx.linkactiveack
}
}
}
object TestTopCHIHelper {
def gen(fTop: Parameters => TestTop_CHIL2,
issue: String,
onFPGAPlatform: Boolean,
enableChiselDB: Boolean,
enableTLLog: Boolean,
enableCHILog: Boolean)(args: Array[String]) = {
val config = new Config((_, _, _) => {
case L2ParamKey => L2Param(
ways = 4,
sets = 128,
clientCaches = Seq(L1Param(aliasBitsOpt = Some(2), vaddrBitsOpt = Some(36))),
// echoField = Seq(DirtyField),
enablePerf = false,
enableRollingDB = !onFPGAPlatform && enableChiselDB,
enableMonitor = !onFPGAPlatform && enableChiselDB,
enableTLLog = !onFPGAPlatform && enableChiselDB && enableTLLog,
enableCHILog = !onFPGAPlatform && enableCHILog,
elaboratedTopDown = false,
FPGAPlatform = onFPGAPlatform,
// prefetch
prefetch = Seq(BOPParameters()),
// data check
dataCheck = Some("oddparity"),
enablePoison = true,
// internal ECC
tagECC = Some("secded"),
dataECC = Some("secded"),
enableTagECC = true,
enableDataECC = true,
// using external RN-F SAM
sam = Seq(AddressSet.everything -> 0),
// L2 flush all
enableL2Flush = true
)
case CHIIssue => issue
case EnableCHI => true
})
CLogB.init(true)
ChiselDB.init(enableChiselDB)
Constantin.init(false)
val top = DisableMonitors(p => LazyModule(fTop(p)))(config)
(new ChiselStage).execute(args,
ChiselGeneratorAnnotation(() => top.module) +: TestTopFirtoolOptions()
)
ChiselDB.addToFileRegisters
FileRegisters.write("./build")
}
}
object TestTop_CHIL2 extends App {
val usage = """
Usage: TestTop_CHIL2 [<--option> <values>]
--issue <chi_issue> specify AMBA CHI Issue of downstream, B by default
--core <core_count> specify core count, 2 by default
--tl-ul <tl_ul_count> specify TileLink-UL upstream count, 0 by default
--bank <bank_count> specify bank (slice) count, 4 by default
--fpga <1> generate for FPGA platform
--chiseldb <1> enable ChisleDB
--tllog <1> enable TLLogger under ChiselDB
--chilog <1> enable CHILogger under ChiselDB
--etime <1> enable external world time for CHI logging
--vtime <1> enable verilog world time for CHI logging
"""
if (args.contains("--help"))
{
println(usage)
System.exit(-1)
}
var varArgs = ArrayBuffer(args.toIndexedSeq:_*)
var varArgsDropped = 0
var numCores: Int = 2
var numULAgents: Int = 0
var numBanks: Int = 4
var issue: String = "B"
var onFPGAPlatform: Boolean = false
var enableChiselDB: Boolean = false
var enableTLLog: Boolean = false
var enableCHILog: Boolean = false
var eTime: Boolean = false
var vTime: Boolean = false
val varArgsToDrop = args.sliding(2, 1).zipWithIndex.collect {
case (Array("--issue", value), i) => (issue = value, i)
case (Array("--core", value), i) => (numCores = value.toInt, i)
case (Array("--tl-ul", value), i) => (numULAgents = value.toInt, i)
case (Array("--bank", value), i) => (numBanks = value.toInt, i)
case (Array("--fpga", value), i) => (onFPGAPlatform = value.toInt != 0, i)
case (Array("--chiseldb", value), i) => (enableChiselDB = value.toInt != 0, i)
case (Array("--tllog", value), i) => (enableTLLog = value.toInt != 0, i)
case (Array("--chilog", value), i) => (enableCHILog = value.toInt != 0, i)
case (Array("--etime", value), i) => (eTime = value.toInt != 0, i)
case (Array("--vtime", value), i) => (vTime = value.toInt != 0, i)
}
varArgsToDrop.map(_._2).foreach(i => {
varArgs.remove(i - varArgsDropped, 2)
varArgsDropped = varArgsDropped + 2
})
varArgs.trimToSize()
TestTopCHIHelper.gen(
p => new TestTop_CHIL2(
numCores,
numULAgents,
numBanks,
eTime,
vTime)(p),
issue,
onFPGAPlatform,
enableChiselDB,
enableTLLog,
enableCHILog
)(varArgs.toArray)
}