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 val canAccept = Input(Bool()) 465} 466 467class SatpStruct(implicit p: Parameters) extends XSBundle { 468 val mode = UInt(4.W) 469 val asid = UInt(16.W) 470 val ppn = UInt(44.W) 471} 472 473class TlbSatpBundle(implicit p: Parameters) extends SatpStruct { 474 val changed = Bool() 475 476 def apply(satp_value: UInt): Unit = { 477 require(satp_value.getWidth == XLEN) 478 val sa = satp_value.asTypeOf(new SatpStruct) 479 mode := sa.mode 480 asid := sa.asid 481 ppn := Cat(0.U((44-PAddrBits).W), sa.ppn(PAddrBits-1, 0)).asUInt 482 changed := DataChanged(sa.asid) // when ppn is changed, software need do the flush 483 } 484} 485 486class TlbCsrBundle(implicit p: Parameters) extends XSBundle { 487 val satp = new TlbSatpBundle() 488 val priv = new Bundle { 489 val mxr = Bool() 490 val sum = Bool() 491 val imode = UInt(2.W) 492 val dmode = UInt(2.W) 493 } 494 495 override def toPrintable: Printable = { 496 p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " + 497 p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}" 498 } 499} 500 501class SfenceBundle(implicit p: Parameters) extends XSBundle { 502 val valid = Bool() 503 val bits = new Bundle { 504 val rs1 = Bool() 505 val rs2 = Bool() 506 val addr = UInt(VAddrBits.W) 507 val asid = UInt(AsidLength.W) 508 val flushPipe = Bool() 509 } 510 511 override def toPrintable: Printable = { 512 p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}, flushPipe:${bits.flushPipe}" 513 } 514} 515 516// Bundle for load violation predictor updating 517class MemPredUpdateReq(implicit p: Parameters) extends XSBundle { 518 val valid = Bool() 519 520 // wait table update 521 val waddr = UInt(MemPredPCWidth.W) 522 val wdata = Bool() // true.B by default 523 524 // store set update 525 // by default, ldpc/stpc should be xor folded 526 val ldpc = UInt(MemPredPCWidth.W) 527 val stpc = UInt(MemPredPCWidth.W) 528} 529 530class CustomCSRCtrlIO(implicit p: Parameters) extends XSBundle { 531 // Prefetcher 532 val l1I_pf_enable = Output(Bool()) 533 val l2_pf_enable = Output(Bool()) 534 val l1D_pf_enable = Output(Bool()) 535 val l1D_pf_train_on_hit = Output(Bool()) 536 val l1D_pf_enable_agt = Output(Bool()) 537 val l1D_pf_enable_pht = Output(Bool()) 538 val l1D_pf_active_threshold = Output(UInt(4.W)) 539 val l1D_pf_active_stride = Output(UInt(6.W)) 540 val l1D_pf_enable_stride = Output(Bool()) 541 val l2_pf_store_only = Output(Bool()) 542 // ICache 543 val icache_parity_enable = Output(Bool()) 544 // Labeled XiangShan 545 val dsid = Output(UInt(8.W)) // TODO: DsidWidth as parameter 546 // Load violation predictor 547 val lvpred_disable = Output(Bool()) 548 val no_spec_load = Output(Bool()) 549 val storeset_wait_store = Output(Bool()) 550 val storeset_no_fast_wakeup = Output(Bool()) 551 val lvpred_timeout = Output(UInt(5.W)) 552 // Branch predictor 553 val bp_ctrl = Output(new BPUCtrl) 554 // Memory Block 555 val sbuffer_threshold = Output(UInt(4.W)) 556 val ldld_vio_check_enable = Output(Bool()) 557 val soft_prefetch_enable = Output(Bool()) 558 val cache_error_enable = Output(Bool()) 559 val uncache_write_outstanding_enable = Output(Bool()) 560 // Rename 561 val fusion_enable = Output(Bool()) 562 val wfi_enable = Output(Bool()) 563 // Decode 564 val svinval_enable = Output(Bool()) 565 566 // distribute csr write signal 567 val distribute_csr = new DistributedCSRIO() 568 569 val singlestep = Output(Bool()) 570 val frontend_trigger = new FrontendTdataDistributeIO() 571 val mem_trigger = new MemTdataDistributeIO() 572} 573 574class DistributedCSRIO(implicit p: Parameters) extends XSBundle { 575 // CSR has been written by csr inst, copies of csr should be updated 576 val w = ValidIO(new Bundle { 577 val addr = Output(UInt(12.W)) 578 val data = Output(UInt(XLEN.W)) 579 }) 580} 581 582class DistributedCSRUpdateReq(implicit p: Parameters) extends XSBundle { 583 // Request csr to be updated 584 // 585 // Note that this request will ONLY update CSR Module it self, 586 // copies of csr will NOT be updated, use it with care! 587 // 588 // For each cycle, no more than 1 DistributedCSRUpdateReq is valid 589 val w = ValidIO(new Bundle { 590 val addr = Output(UInt(12.W)) 591 val data = Output(UInt(XLEN.W)) 592 }) 593 def apply(valid: Bool, addr: UInt, data: UInt, src_description: String) = { 594 when(valid){ 595 w.bits.addr := addr 596 w.bits.data := data 597 } 598 println("Distributed CSR update req registered for " + src_description) 599 } 600} 601 602class L1CacheErrorInfo(implicit p: Parameters) extends XSBundle { 603 // L1CacheErrorInfo is also used to encode customized CACHE_ERROR CSR 604 val source = Output(new Bundle() { 605 val tag = Bool() // l1 tag array 606 val data = Bool() // l1 data array 607 val l2 = Bool() 608 }) 609 val opType = Output(new Bundle() { 610 val fetch = Bool() 611 val load = Bool() 612 val store = Bool() 613 val probe = Bool() 614 val release = Bool() 615 val atom = Bool() 616 }) 617 val paddr = Output(UInt(PAddrBits.W)) 618 619 // report error and paddr to beu 620 // bus error unit will receive error info iff ecc_error.valid 621 val report_to_beu = Output(Bool()) 622 623 // there is an valid error 624 // l1 cache error will always be report to CACHE_ERROR csr 625 val valid = Output(Bool()) 626 627 def toL1BusErrorUnitInfo(): L1BusErrorUnitInfo = { 628 val beu_info = Wire(new L1BusErrorUnitInfo) 629 beu_info.ecc_error.valid := report_to_beu 630 beu_info.ecc_error.bits := paddr 631 beu_info 632 } 633} 634 635class TriggerCf(implicit p: Parameters) extends XSBundle { 636 // frontend 637 val frontendHit = Vec(TriggerNum, Bool()) // en && hit 638 val frontendCanFire = Vec(TriggerNum, Bool()) 639 // backend 640 val backendHit = Vec(TriggerNum, Bool()) 641 val backendCanFire = Vec(TriggerNum, Bool()) 642 643 // Two situations not allowed: 644 // 1. load data comparison 645 // 2. store chaining with store 646 def getFrontendCanFire = frontendCanFire.reduce(_ || _) 647 def getBackendCanFire = backendCanFire.reduce(_ || _) 648 def canFire = getFrontendCanFire || getBackendCanFire 649 def clear(): Unit = { 650 frontendHit.foreach(_ := false.B) 651 frontendCanFire.foreach(_ := false.B) 652 backendHit.foreach(_ := false.B) 653 backendCanFire.foreach(_ := false.B) 654 } 655} 656 657// these 3 bundles help distribute trigger control signals from CSR 658// to Frontend, Load and Store. 659class FrontendTdataDistributeIO(implicit p: Parameters) extends XSBundle { 660 val tUpdate = ValidIO(new Bundle { 661 val addr = Output(UInt(log2Up(TriggerNum).W)) 662 val tdata = new MatchTriggerIO 663 }) 664 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 665} 666 667class MemTdataDistributeIO(implicit p: Parameters) extends XSBundle { 668 val tUpdate = ValidIO(new Bundle { 669 val addr = Output(UInt(log2Up(TriggerNum).W)) 670 val tdata = new MatchTriggerIO 671 }) 672 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 673} 674 675class MatchTriggerIO(implicit p: Parameters) extends XSBundle { 676 val matchType = Output(UInt(2.W)) 677 val select = Output(Bool()) 678 val timing = Output(Bool()) 679 val action = Output(Bool()) 680 val chain = Output(Bool()) 681 val execute = Output(Bool()) 682 val store = Output(Bool()) 683 val load = Output(Bool()) 684 val tdata2 = Output(UInt(64.W)) 685} 686 687class StallReasonIO(width: Int) extends Bundle { 688 val reason = Output(Vec(width, UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 689 val backReason = Flipped(Valid(UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 690} 691 692// custom l2 - l1 interface 693class L2ToL1Hint(implicit p: Parameters) extends XSBundle with HasDCacheParameters { 694 val sourceId = UInt(log2Up(cfg.nMissEntries).W) // tilelink sourceID -> mshr id 695 val isKeyword = Bool() // miss entry keyword -> L1 load queue replay 696} 697 698