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