xref: /XiangShan/src/main/scala/xiangshan/Bundle.scala (revision e25e4d90505c592524b410b127fe611ac49a3adf)
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 xiangshan
18
19import org.chipsalliance.cde.config.Parameters
20import chisel3._
21import chisel3.util.BitPat.bitPatToUInt
22import chisel3.util._
23import utility._
24import utils._
25import xiangshan.backend.decode.{ImmUnion, XDecode}
26import xiangshan.backend.fu.FuType
27import xiangshan.backend.rob.RobPtr
28import xiangshan.frontend._
29import xiangshan.mem.{LqPtr, SqPtr}
30import xiangshan.backend.Bundles.{DynInst, UopIdx}
31import xiangshan.backend.fu.vector.Bundles.VType
32import xiangshan.frontend.PreDecodeInfo
33import xiangshan.frontend.HasBPUParameter
34import xiangshan.frontend.{AllFoldedHistories, CircularGlobalHistory, GlobalHistory, ShiftingGlobalHistory}
35import xiangshan.frontend.RASEntry
36import xiangshan.frontend.BPUCtrl
37import xiangshan.frontend.FtqPtr
38import xiangshan.frontend.CGHPtr
39import xiangshan.frontend.FtqRead
40import xiangshan.frontend.FtqToCtrlIO
41import xiangshan.cache.HasDCacheParameters
42import utils._
43import utility._
44
45import scala.math.max
46import org.chipsalliance.cde.config.Parameters
47import chisel3.util.BitPat.bitPatToUInt
48import chisel3.util.experimental.decode.EspressoMinimizer
49import xiangshan.backend.CtrlToFtqIO
50import xiangshan.backend.fu.PMPEntry
51import xiangshan.frontend.Ftq_Redirect_SRAMEntry
52import xiangshan.frontend.AllFoldedHistories
53import xiangshan.frontend.AllAheadFoldedHistoryOldestBits
54import xiangshan.frontend.RASPtr
55
56class ValidUndirectioned[T <: Data](gen: T) extends Bundle {
57  val valid = Bool()
58  val bits = gen.cloneType.asInstanceOf[T]
59
60}
61
62object ValidUndirectioned {
63  def apply[T <: Data](gen: T) = {
64    new ValidUndirectioned[T](gen)
65  }
66}
67
68object RSFeedbackType {
69  val lrqFull         = 0.U(4.W)
70  val tlbMiss         = 1.U(4.W)
71  val mshrFull        = 2.U(4.W)
72  val dataInvalid     = 3.U(4.W)
73  val bankConflict    = 4.U(4.W)
74  val ldVioCheckRedo  = 5.U(4.W)
75  val feedbackInvalid = 7.U(4.W)
76  val issueSuccess    = 8.U(4.W)
77  val rfArbitFail     = 9.U(4.W)
78  val fuIdle          = 10.U(4.W)
79  val fuBusy          = 11.U(4.W)
80  val fuUncertain     = 12.U(4.W)
81
82  val allTypes = 16
83  def apply() = UInt(4.W)
84
85  def isStageSuccess(feedbackType: UInt) = {
86    feedbackType === issueSuccess
87  }
88
89  def isBlocked(feedbackType: UInt) = {
90    feedbackType === rfArbitFail || feedbackType === fuBusy || feedbackType >= lrqFull && feedbackType <= feedbackInvalid
91  }
92}
93
94class PredictorAnswer(implicit p: Parameters) extends XSBundle {
95  val hit    = if (!env.FPGAPlatform) Bool() else UInt(0.W)
96  val taken  = if (!env.FPGAPlatform) Bool() else UInt(0.W)
97  val target = if (!env.FPGAPlatform) UInt(VAddrBits.W) else UInt(0.W)
98}
99
100class CfiUpdateInfo(implicit p: Parameters) extends XSBundle with HasBPUParameter {
101  // from backend
102  val pc = UInt(VAddrBits.W)
103  // frontend -> backend -> frontend
104  val pd = new PreDecodeInfo
105  val ssp = UInt(log2Up(RasSize).W)
106  val sctr = UInt(log2Up(RasCtrSize).W)
107  val TOSW = new RASPtr
108  val TOSR = new RASPtr
109  val NOS = new RASPtr
110  val topAddr = UInt(VAddrBits.W)
111  // val hist = new ShiftingGlobalHistory
112  val folded_hist = new AllFoldedHistories(foldedGHistInfos)
113  val afhob = new AllAheadFoldedHistoryOldestBits(foldedGHistInfos)
114  val lastBrNumOH = UInt((numBr+1).W)
115  val ghr = UInt(UbtbGHRLength.W)
116  val histPtr = new CGHPtr
117  val specCnt = Vec(numBr, UInt(10.W))
118  // need pipeline update
119  val br_hit = Bool() // if in ftb entry
120  val jr_hit = Bool() // if in ftb entry
121  val sc_hit = Bool() // if used in ftb entry, invalid if !br_hit
122  val predTaken = Bool()
123  val target = UInt(VAddrBits.W)
124  val taken = Bool()
125  val isMisPred = Bool()
126  val shift = UInt((log2Ceil(numBr)+1).W)
127  val addIntoHist = Bool()
128
129  def fromFtqRedirectSram(entry: Ftq_Redirect_SRAMEntry) = {
130    // this.hist := entry.ghist
131    this.folded_hist := entry.folded_hist
132    this.lastBrNumOH := entry.lastBrNumOH
133    this.afhob := entry.afhob
134    this.histPtr := entry.histPtr
135    this.ssp := entry.ssp
136    this.sctr := entry.sctr
137    this.TOSW := entry.TOSW
138    this.TOSR := entry.TOSR
139    this.NOS := entry.NOS
140    this.topAddr := entry.topAddr
141    this
142  }
143}
144
145// Dequeue DecodeWidth insts from Ibuffer
146class CtrlFlow(implicit p: Parameters) extends XSBundle {
147  val instr = UInt(32.W)
148  val pc = UInt(VAddrBits.W)
149  // Todo: remove this
150  val gpaddr = UInt(GPAddrBits.W)
151  val foldpc = UInt(MemPredPCWidth.W)
152  val exceptionVec = ExceptionVec()
153  val trigger = new TriggerCf
154  val pd = new PreDecodeInfo
155  val pred_taken = Bool()
156  val crossPageIPFFix = Bool()
157  val storeSetHit = Bool() // inst has been allocated an store set
158  val waitForRobIdx = new RobPtr // store set predicted previous store robIdx
159  // Load wait is needed
160  // load inst will not be executed until former store (predicted by mdp) addr calcuated
161  val loadWaitBit = Bool()
162  // If (loadWaitBit && loadWaitStrict), strict load wait is needed
163  // load inst will not be executed until ALL former store addr calcuated
164  val loadWaitStrict = Bool()
165  val ssid = UInt(SSIDWidth.W)
166  val ftqPtr = new FtqPtr
167  val ftqOffset = UInt(log2Up(PredictWidth).W)
168}
169
170
171class FPUCtrlSignals(implicit p: Parameters) extends XSBundle {
172  val isAddSub = Bool() // swap23
173  val typeTagIn = UInt(1.W)
174  val typeTagOut = UInt(1.W)
175  val fromInt = Bool()
176  val wflags = Bool()
177  val fpWen = Bool()
178  val fmaCmd = UInt(2.W)
179  val div = Bool()
180  val sqrt = Bool()
181  val fcvt = Bool()
182  val typ = UInt(2.W)
183  val fmt = UInt(2.W)
184  val ren3 = Bool() //TODO: remove SrcType.fp
185  val rm = UInt(3.W)
186}
187
188// Decode DecodeWidth insts at Decode Stage
189class CtrlSignals(implicit p: Parameters) extends XSBundle {
190  val debug_globalID = UInt(XLEN.W)
191  val srcType = Vec(4, SrcType())
192  val lsrc = Vec(4, UInt(6.W))
193  val ldest = UInt(6.W)
194  val fuType = FuType()
195  val fuOpType = FuOpType()
196  val rfWen = Bool()
197  val fpWen = Bool()
198  val vecWen = Bool()
199  val isXSTrap = Bool()
200  val noSpecExec = Bool() // wait forward
201  val blockBackward = Bool() // block backward
202  val flushPipe = Bool() // This inst will flush all the pipe when commit, like exception but can commit
203  val uopSplitType = UopSplitType()
204  val selImm = SelImm()
205  val imm = UInt(ImmUnion.maxLen.W)
206  val commitType = CommitType()
207  val fpu = new FPUCtrlSignals
208  val uopIdx = UopIdx()
209  val isMove = Bool()
210  val vm = Bool()
211  val singleStep = Bool()
212  // This inst will flush all the pipe when it is the oldest inst in ROB,
213  // then replay from this inst itself
214  val replayInst = Bool()
215  val canRobCompress = Bool()
216
217  private def allSignals = srcType.take(3) ++ Seq(fuType, fuOpType, rfWen, fpWen, vecWen,
218    isXSTrap, noSpecExec, blockBackward, flushPipe, canRobCompress, uopSplitType, selImm)
219
220  def decode(inst: UInt, table: Iterable[(BitPat, List[BitPat])]): CtrlSignals = {
221    val decoder = freechips.rocketchip.rocket.DecodeLogic(inst, XDecode.decodeDefault, table, EspressoMinimizer)
222    allSignals zip decoder foreach { case (s, d) => s := d }
223    commitType := DontCare
224    this
225  }
226
227  def decode(bit: List[BitPat]): CtrlSignals = {
228    allSignals.zip(bit.map(bitPatToUInt(_))).foreach{ case (s, d) => s := d }
229    this
230  }
231
232  def isWFI: Bool = fuType === FuType.csr.U && fuOpType === CSROpType.wfi
233  def isSoftPrefetch: Bool = {
234    fuType === FuType.alu.U && fuOpType === ALUOpType.or && selImm === SelImm.IMM_I && ldest === 0.U
235  }
236  def needWriteRf: Bool = (rfWen && ldest =/= 0.U) || fpWen || vecWen
237  def isHyperInst: Bool = {
238    fuType === FuType.ldu.U && LSUOpType.isHlv(fuOpType) || fuType === FuType.stu.U && LSUOpType.isHsv(fuOpType)
239  }
240}
241
242class CfCtrl(implicit p: Parameters) extends XSBundle {
243  val cf = new CtrlFlow
244  val ctrl = new CtrlSignals
245}
246
247class PerfDebugInfo(implicit p: Parameters) extends XSBundle {
248  val eliminatedMove = Bool()
249  // val fetchTime = UInt(XLEN.W)
250  val renameTime = UInt(XLEN.W)
251  val dispatchTime = UInt(XLEN.W)
252  val enqRsTime = UInt(XLEN.W)
253  val selectTime = UInt(XLEN.W)
254  val issueTime = UInt(XLEN.W)
255  val writebackTime = UInt(XLEN.W)
256  // val commitTime = UInt(XLEN.W)
257  val runahead_checkpoint_id = UInt(XLEN.W)
258  val tlbFirstReqTime = UInt(XLEN.W)
259  val tlbRespTime = UInt(XLEN.W) // when getting hit result (including delay in L2TLB hit)
260}
261
262// Separate LSQ
263class LSIdx(implicit p: Parameters) extends XSBundle {
264  val lqIdx = new LqPtr
265  val sqIdx = new SqPtr
266}
267
268// CfCtrl -> MicroOp at Rename Stage
269class MicroOp(implicit p: Parameters) extends CfCtrl {
270  val srcState = Vec(4, SrcState())
271  val psrc = Vec(4, UInt(PhyRegIdxWidth.W))
272  val pdest = UInt(PhyRegIdxWidth.W)
273  val robIdx = new RobPtr
274  val instrSize = UInt(log2Ceil(RenameWidth + 1).W)
275  val lqIdx = new LqPtr
276  val sqIdx = new SqPtr
277  val eliminatedMove = Bool()
278  val snapshot = Bool()
279  val debugInfo = new PerfDebugInfo
280  def needRfRPort(index: Int, isFp: Boolean, ignoreState: Boolean = true) : Bool = {
281    val stateReady = srcState(index) === SrcState.rdy || ignoreState.B
282    val readReg = if (isFp) {
283      ctrl.srcType(index) === SrcType.fp
284    } else {
285      ctrl.srcType(index) === SrcType.reg && ctrl.lsrc(index) =/= 0.U
286    }
287    readReg && stateReady
288  }
289  def srcIsReady: Vec[Bool] = {
290    VecInit(ctrl.srcType.zip(srcState).map{ case (t, s) => SrcType.isPcOrImm(t) || s === SrcState.rdy })
291  }
292  def clearExceptions(
293    exceptionBits: Seq[Int] = Seq(),
294    flushPipe: Boolean = false,
295    replayInst: Boolean = false
296  ): MicroOp = {
297    cf.exceptionVec.zipWithIndex.filterNot(x => exceptionBits.contains(x._2)).foreach(_._1 := false.B)
298    if (!flushPipe) { ctrl.flushPipe := false.B }
299    if (!replayInst) { ctrl.replayInst := false.B }
300    this
301  }
302}
303
304class XSBundleWithMicroOp(implicit p: Parameters) extends XSBundle {
305  val uop = new DynInst
306}
307
308class MicroOpRbExt(implicit p: Parameters) extends XSBundleWithMicroOp {
309  val flag = UInt(1.W)
310}
311
312class Redirect(implicit p: Parameters) extends XSBundle {
313  val isRVC = Bool()
314  val robIdx = new RobPtr
315  val ftqIdx = new FtqPtr
316  val ftqOffset = UInt(log2Up(PredictWidth).W)
317  val level = RedirectLevel()
318  val interrupt = Bool()
319  val cfiUpdate = new CfiUpdateInfo
320
321  val stFtqIdx = new FtqPtr // for load violation predict
322  val stFtqOffset = UInt(log2Up(PredictWidth).W)
323
324  val debug_runahead_checkpoint_id = UInt(64.W)
325  val debugIsCtrl = Bool()
326  val debugIsMemVio = Bool()
327
328  def flushItself() = RedirectLevel.flushItself(level)
329}
330
331class ResetPregStateReq(implicit p: Parameters) extends XSBundle {
332  // NOTE: set isInt and isFp both to 'false' when invalid
333  val isInt = Bool()
334  val isFp = Bool()
335  val preg = UInt(PhyRegIdxWidth.W)
336}
337
338class DebugBundle(implicit p: Parameters) extends XSBundle {
339  val isMMIO = Bool()
340  val isPerfCnt = Bool()
341  val paddr = UInt(PAddrBits.W)
342  val vaddr = UInt(VAddrBits.W)
343  /* add L/S inst info in EXU */
344  // val L1toL2TlbLatency = UInt(XLEN.W)
345  // val levelTlbHit = UInt(2.W)
346}
347
348class ExternalInterruptIO(implicit p: Parameters) extends XSBundle {
349  val mtip = Input(Bool())
350  val msip = Input(Bool())
351  val meip = Input(Bool())
352  val seip = Input(Bool())
353  val debug = Input(Bool())
354}
355
356class CSRSpecialIO(implicit p: Parameters) extends XSBundle {
357  val exception = Flipped(ValidIO(new DynInst))
358  val isInterrupt = Input(Bool())
359  val memExceptionVAddr = Input(UInt(VAddrBits.W))
360  val trapTarget = Output(UInt(VAddrBits.W))
361  val externalInterrupt = new ExternalInterruptIO
362  val interrupt = Output(Bool())
363}
364
365class DiffCommitIO(implicit p: Parameters) extends XSBundle {
366  val isCommit = Bool()
367  val commitValid = Vec(CommitWidth * MaxUopSize, Bool())
368
369  val info = Vec(CommitWidth * MaxUopSize, new RabCommitInfo)
370}
371
372class RobCommitInfo(implicit p: Parameters) extends XSBundle {
373  val ldest = UInt(6.W)
374  val rfWen = Bool()
375  val fpWen = Bool() // for Rab only
376  def dirtyFs = fpWen // for Rob only
377  val vecWen = Bool()
378  def fpVecWen = fpWen || vecWen
379  val wflags = Bool()
380  val commitType = CommitType()
381  val pdest = UInt(PhyRegIdxWidth.W)
382  val ftqIdx = new FtqPtr
383  val ftqOffset = UInt(log2Up(PredictWidth).W)
384  val isMove = Bool()
385  val isRVC = Bool()
386  val isVset = Bool()
387  val isHls = Bool()
388  val vtype = new VType
389
390  // these should be optimized for synthesis verilog
391  val pc = UInt(VAddrBits.W)
392
393  val instrSize = UInt(log2Ceil(RenameWidth + 1).W)
394}
395
396class RobCommitIO(implicit p: Parameters) extends XSBundle {
397  val isCommit = Bool()
398  val commitValid = Vec(CommitWidth, Bool())
399
400  val isWalk = Bool()
401  // valid bits optimized for walk
402  val walkValid = Vec(CommitWidth, Bool())
403
404  val info = Vec(CommitWidth, new RobCommitInfo)
405  val robIdx = Vec(CommitWidth, new RobPtr)
406
407  def hasWalkInstr: Bool = isWalk && walkValid.asUInt.orR
408  def hasCommitInstr: Bool = isCommit && commitValid.asUInt.orR
409}
410
411class RabCommitInfo(implicit p: Parameters) extends XSBundle {
412  val ldest = UInt(6.W)
413  val pdest = UInt(PhyRegIdxWidth.W)
414  val rfWen = Bool()
415  val fpWen = Bool()
416  val vecWen = Bool()
417  val isMove = Bool()
418}
419
420class RabCommitIO(implicit p: Parameters) extends XSBundle {
421  val isCommit = Bool()
422  val commitValid = Vec(CommitWidth, Bool())
423
424  val isWalk = Bool()
425  // valid bits optimized for walk
426  val walkValid = Vec(CommitWidth, Bool())
427
428  val info = Vec(CommitWidth, new RabCommitInfo)
429  val robIdx = OptionWrapper(!env.FPGAPlatform, Vec(CommitWidth, new RobPtr))
430
431  def hasWalkInstr: Bool = isWalk && walkValid.asUInt.orR
432  def hasCommitInstr: Bool = isCommit && commitValid.asUInt.orR
433}
434
435class SnapshotPort(implicit p: Parameters) extends XSBundle {
436  val snptEnq = Bool()
437  val snptDeq = Bool()
438  val useSnpt = Bool()
439  val snptSelect = UInt(log2Ceil(RenameSnapshotNum).W)
440  val flushVec = Vec(RenameSnapshotNum, Bool())
441}
442
443class RSFeedback(implicit p: Parameters) extends XSBundle {
444  val robIdx = new RobPtr
445  val hit = Bool()
446  val flushState = Bool()
447  val sourceType = RSFeedbackType()
448  val dataInvalidSqIdx = new SqPtr
449}
450
451class MemRSFeedbackIO(implicit p: Parameters) extends XSBundle {
452  // Note: you need to update in implicit Parameters p before imp MemRSFeedbackIO
453  // for instance: MemRSFeedbackIO()(updateP)
454  val feedbackSlow = ValidIO(new RSFeedback()) // dcache miss queue full, dtlb miss
455  val feedbackFast = ValidIO(new RSFeedback()) // bank conflict
456}
457
458class LoadCancelIO(implicit p: Parameters) extends XSBundle {
459  val ld1Cancel = Bool()
460  val ld2Cancel = Bool()
461}
462
463class FrontendToCtrlIO(implicit p: Parameters) extends XSBundle {
464  // to backend end
465  val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow))
466  val stallReason = new StallReasonIO(DecodeWidth)
467  val fromFtq = new FtqToCtrlIO
468  // from backend
469  val toFtq = Flipped(new CtrlToFtqIO)
470  val canAccept = Input(Bool())
471}
472
473class SatpStruct(implicit p: Parameters) extends XSBundle {
474  val mode = UInt(4.W)
475  val asid = UInt(16.W)
476  val ppn  = UInt(44.W)
477}
478
479class TlbSatpBundle(implicit p: Parameters) extends SatpStruct {
480  val changed = Bool()
481
482  def apply(satp_value: UInt): Unit = {
483    require(satp_value.getWidth == XLEN)
484    val sa = satp_value.asTypeOf(new SatpStruct)
485    mode := sa.mode
486    asid := sa.asid
487    ppn := Cat(0.U((44-PAddrBits).W), sa.ppn(PAddrBits-1, 0)).asUInt
488    changed := DataChanged(sa.asid) // when ppn is changed, software need do the flush
489  }
490}
491
492class TlbCsrBundle(implicit p: Parameters) extends XSBundle {
493  val satp = new TlbSatpBundle()
494  val vsatp = new TlbSatpBundle()
495  val hgatp = new TlbSatpBundle()
496  val priv = new Bundle {
497    val mxr = Bool()
498    val sum = Bool()
499    val vmxr = Bool()
500    val vsum = Bool()
501    val virt = Bool()
502    val spvp = UInt(1.W)
503    val imode = UInt(2.W)
504    val dmode = UInt(2.W)
505  }
506
507  override def toPrintable: Printable = {
508    p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " +
509      p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}"
510  }
511}
512
513class SfenceBundle(implicit p: Parameters) extends XSBundle {
514  val valid = Bool()
515  val bits = new Bundle {
516    val rs1 = Bool()
517    val rs2 = Bool()
518    val addr = UInt(VAddrBits.W)
519    val id = UInt((AsidLength).W) // asid or vmid
520    val flushPipe = Bool()
521    val hv = Bool()
522    val hg = Bool()
523  }
524
525  override def toPrintable: Printable = {
526    p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}, flushPipe:${bits.flushPipe}"
527  }
528}
529
530// Bundle for load violation predictor updating
531class MemPredUpdateReq(implicit p: Parameters) extends XSBundle  {
532  val valid = Bool()
533
534  // wait table update
535  val waddr = UInt(MemPredPCWidth.W)
536  val wdata = Bool() // true.B by default
537
538  // store set update
539  // by default, ldpc/stpc should be xor folded
540  val ldpc = UInt(MemPredPCWidth.W)
541  val stpc = UInt(MemPredPCWidth.W)
542}
543
544class CustomCSRCtrlIO(implicit p: Parameters) extends XSBundle {
545  // Prefetcher
546  val l1I_pf_enable = Output(Bool())
547  val l2_pf_enable = Output(Bool())
548  val l1D_pf_enable = Output(Bool())
549  val l1D_pf_train_on_hit = Output(Bool())
550  val l1D_pf_enable_agt = Output(Bool())
551  val l1D_pf_enable_pht = Output(Bool())
552  val l1D_pf_active_threshold = Output(UInt(4.W))
553  val l1D_pf_active_stride = Output(UInt(6.W))
554  val l1D_pf_enable_stride = Output(Bool())
555  val l2_pf_store_only = Output(Bool())
556  // ICache
557  val icache_parity_enable = Output(Bool())
558  // Labeled XiangShan
559  val dsid = Output(UInt(8.W)) // TODO: DsidWidth as parameter
560  // Load violation predictor
561  val lvpred_disable = Output(Bool())
562  val no_spec_load = Output(Bool())
563  val storeset_wait_store = Output(Bool())
564  val storeset_no_fast_wakeup = Output(Bool())
565  val lvpred_timeout = Output(UInt(5.W))
566  // Branch predictor
567  val bp_ctrl = Output(new BPUCtrl)
568  // Memory Block
569  val sbuffer_threshold = Output(UInt(4.W))
570  val ldld_vio_check_enable = Output(Bool())
571  val soft_prefetch_enable = Output(Bool())
572  val cache_error_enable = Output(Bool())
573  val uncache_write_outstanding_enable = Output(Bool())
574  // Rename
575  val fusion_enable = Output(Bool())
576  val wfi_enable = Output(Bool())
577  // Decode
578  val svinval_enable = Output(Bool())
579
580  // distribute csr write signal
581  val distribute_csr = new DistributedCSRIO()
582  // TODO: move it to a new bundle, since single step is not a custom control signal
583  val singlestep = Output(Bool())
584  val frontend_trigger = new FrontendTdataDistributeIO()
585  val mem_trigger = new MemTdataDistributeIO()
586  // Virtualization Mode
587  val virtMode = Output(Bool())
588}
589
590class DistributedCSRIO(implicit p: Parameters) extends XSBundle {
591  // CSR has been written by csr inst, copies of csr should be updated
592  val w = ValidIO(new Bundle {
593    val addr = Output(UInt(12.W))
594    val data = Output(UInt(XLEN.W))
595  })
596}
597
598class DistributedCSRUpdateReq(implicit p: Parameters) extends XSBundle {
599  // Request csr to be updated
600  //
601  // Note that this request will ONLY update CSR Module it self,
602  // copies of csr will NOT be updated, use it with care!
603  //
604  // For each cycle, no more than 1 DistributedCSRUpdateReq is valid
605  val w = ValidIO(new Bundle {
606    val addr = Output(UInt(12.W))
607    val data = Output(UInt(XLEN.W))
608  })
609  def apply(valid: Bool, addr: UInt, data: UInt, src_description: String) = {
610    when(valid){
611      w.bits.addr := addr
612      w.bits.data := data
613    }
614    println("Distributed CSR update req registered for " + src_description)
615  }
616}
617
618class L1CacheErrorInfo(implicit p: Parameters) extends XSBundle {
619  // L1CacheErrorInfo is also used to encode customized CACHE_ERROR CSR
620  val source = Output(new Bundle() {
621    val tag = Bool() // l1 tag array
622    val data = Bool() // l1 data array
623    val l2 = Bool()
624  })
625  val opType = Output(new Bundle() {
626    val fetch = Bool()
627    val load = Bool()
628    val store = Bool()
629    val probe = Bool()
630    val release = Bool()
631    val atom = Bool()
632  })
633  val paddr = Output(UInt(PAddrBits.W))
634
635  // report error and paddr to beu
636  // bus error unit will receive error info iff ecc_error.valid
637  val report_to_beu = Output(Bool())
638
639  // there is an valid error
640  // l1 cache error will always be report to CACHE_ERROR csr
641  val valid = Output(Bool())
642
643  def toL1BusErrorUnitInfo(): L1BusErrorUnitInfo = {
644    val beu_info = Wire(new L1BusErrorUnitInfo)
645    beu_info.ecc_error.valid := report_to_beu
646    beu_info.ecc_error.bits := paddr
647    beu_info
648  }
649}
650
651class TriggerCf(implicit p: Parameters) extends XSBundle {
652  // frontend
653  val frontendHit       = Vec(TriggerNum, Bool()) // en && hit
654  val frontendCanFire   = Vec(TriggerNum, Bool())
655  // backend
656  val backendHit        = Vec(TriggerNum, Bool())
657  val backendCanFire    = Vec(TriggerNum, Bool())
658
659  // Two situations not allowed:
660  // 1. load data comparison
661  // 2. store chaining with store
662  def getFrontendCanFire = frontendCanFire.reduce(_ || _)
663  def getBackendCanFire = backendCanFire.reduce(_ || _)
664  def canFire = getFrontendCanFire || getBackendCanFire
665  def clear(): Unit = {
666    frontendHit.foreach(_ := false.B)
667    frontendCanFire.foreach(_ := false.B)
668    backendHit.foreach(_ := false.B)
669    backendCanFire.foreach(_ := false.B)
670  }
671}
672
673// these 3 bundles help distribute trigger control signals from CSR
674// to Frontend, Load and Store.
675class FrontendTdataDistributeIO(implicit p: Parameters) extends XSBundle {
676  val tUpdate = ValidIO(new Bundle {
677    val addr = Output(UInt(log2Up(TriggerNum).W))
678    val tdata = new MatchTriggerIO
679  })
680  val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool()))
681}
682
683class MemTdataDistributeIO(implicit p: Parameters) extends XSBundle {
684  val tUpdate = ValidIO(new Bundle {
685    val addr = Output(UInt(log2Up(TriggerNum).W))
686    val tdata = new MatchTriggerIO
687  })
688  val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool()))
689}
690
691class MatchTriggerIO(implicit p: Parameters) extends XSBundle {
692  val matchType = Output(UInt(2.W))
693  val select = Output(Bool())
694  val timing = Output(Bool())
695  val action = Output(Bool())
696  val chain = Output(Bool())
697  val execute = Output(Bool())
698  val store = Output(Bool())
699  val load = Output(Bool())
700  val tdata2 = Output(UInt(64.W))
701}
702
703class StallReasonIO(width: Int) extends Bundle {
704  val reason = Output(Vec(width, UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W)))
705  val backReason = Flipped(Valid(UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W)))
706}
707
708// custom l2 - l1 interface
709class L2ToL1Hint(implicit p: Parameters) extends XSBundle with HasDCacheParameters {
710  val sourceId = UInt(log2Up(cfg.nMissEntries).W)    // tilelink sourceID -> mshr id
711  val isKeyword = Bool()                             // miss entry keyword -> L1 load queue replay
712}
713
714