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} 450 451class LoadCancelIO(implicit p: Parameters) extends XSBundle { 452 val ld1Cancel = Bool() 453 val ld2Cancel = Bool() 454} 455 456class FrontendToCtrlIO(implicit p: Parameters) extends XSBundle { 457 // to backend end 458 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 459 val stallReason = new StallReasonIO(DecodeWidth) 460 val fromFtq = new FtqToCtrlIO 461 // from backend 462 val toFtq = Flipped(new CtrlToFtqIO) 463} 464 465class SatpStruct(implicit p: Parameters) extends XSBundle { 466 val mode = UInt(4.W) 467 val asid = UInt(16.W) 468 val ppn = UInt(44.W) 469} 470 471class TlbSatpBundle(implicit p: Parameters) extends SatpStruct { 472 val changed = Bool() 473 474 def apply(satp_value: UInt): Unit = { 475 require(satp_value.getWidth == XLEN) 476 val sa = satp_value.asTypeOf(new SatpStruct) 477 mode := sa.mode 478 asid := sa.asid 479 ppn := Cat(0.U((44-PAddrBits).W), sa.ppn(PAddrBits-1, 0)).asUInt 480 changed := DataChanged(sa.asid) // when ppn is changed, software need do the flush 481 } 482} 483 484class TlbCsrBundle(implicit p: Parameters) extends XSBundle { 485 val satp = new TlbSatpBundle() 486 val priv = new Bundle { 487 val mxr = Bool() 488 val sum = Bool() 489 val imode = UInt(2.W) 490 val dmode = UInt(2.W) 491 } 492 493 override def toPrintable: Printable = { 494 p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " + 495 p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}" 496 } 497} 498 499class SfenceBundle(implicit p: Parameters) extends XSBundle { 500 val valid = Bool() 501 val bits = new Bundle { 502 val rs1 = Bool() 503 val rs2 = Bool() 504 val addr = UInt(VAddrBits.W) 505 val asid = UInt(AsidLength.W) 506 val flushPipe = Bool() 507 } 508 509 override def toPrintable: Printable = { 510 p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}, flushPipe:${bits.flushPipe}" 511 } 512} 513 514// Bundle for load violation predictor updating 515class MemPredUpdateReq(implicit p: Parameters) extends XSBundle { 516 val valid = Bool() 517 518 // wait table update 519 val waddr = UInt(MemPredPCWidth.W) 520 val wdata = Bool() // true.B by default 521 522 // store set update 523 // by default, ldpc/stpc should be xor folded 524 val ldpc = UInt(MemPredPCWidth.W) 525 val stpc = UInt(MemPredPCWidth.W) 526} 527 528class CustomCSRCtrlIO(implicit p: Parameters) extends XSBundle { 529 // Prefetcher 530 val l1I_pf_enable = Output(Bool()) 531 val l2_pf_enable = Output(Bool()) 532 val l1D_pf_enable = Output(Bool()) 533 val l1D_pf_train_on_hit = Output(Bool()) 534 val l1D_pf_enable_agt = Output(Bool()) 535 val l1D_pf_enable_pht = Output(Bool()) 536 val l1D_pf_active_threshold = Output(UInt(4.W)) 537 val l1D_pf_active_stride = Output(UInt(6.W)) 538 val l1D_pf_enable_stride = Output(Bool()) 539 val l2_pf_store_only = Output(Bool()) 540 // ICache 541 val icache_parity_enable = Output(Bool()) 542 // Labeled XiangShan 543 val dsid = Output(UInt(8.W)) // TODO: DsidWidth as parameter 544 // Load violation predictor 545 val lvpred_disable = Output(Bool()) 546 val no_spec_load = Output(Bool()) 547 val storeset_wait_store = Output(Bool()) 548 val storeset_no_fast_wakeup = Output(Bool()) 549 val lvpred_timeout = Output(UInt(5.W)) 550 // Branch predictor 551 val bp_ctrl = Output(new BPUCtrl) 552 // Memory Block 553 val sbuffer_threshold = Output(UInt(4.W)) 554 val ldld_vio_check_enable = Output(Bool()) 555 val soft_prefetch_enable = Output(Bool()) 556 val cache_error_enable = Output(Bool()) 557 val uncache_write_outstanding_enable = Output(Bool()) 558 // Rename 559 val fusion_enable = Output(Bool()) 560 val wfi_enable = Output(Bool()) 561 // Decode 562 val svinval_enable = Output(Bool()) 563 564 // distribute csr write signal 565 val distribute_csr = new DistributedCSRIO() 566 567 val singlestep = Output(Bool()) 568 val frontend_trigger = new FrontendTdataDistributeIO() 569 val mem_trigger = new MemTdataDistributeIO() 570} 571 572class DistributedCSRIO(implicit p: Parameters) extends XSBundle { 573 // CSR has been written by csr inst, copies of csr should be updated 574 val w = ValidIO(new Bundle { 575 val addr = Output(UInt(12.W)) 576 val data = Output(UInt(XLEN.W)) 577 }) 578} 579 580class DistributedCSRUpdateReq(implicit p: Parameters) extends XSBundle { 581 // Request csr to be updated 582 // 583 // Note that this request will ONLY update CSR Module it self, 584 // copies of csr will NOT be updated, use it with care! 585 // 586 // For each cycle, no more than 1 DistributedCSRUpdateReq is valid 587 val w = ValidIO(new Bundle { 588 val addr = Output(UInt(12.W)) 589 val data = Output(UInt(XLEN.W)) 590 }) 591 def apply(valid: Bool, addr: UInt, data: UInt, src_description: String) = { 592 when(valid){ 593 w.bits.addr := addr 594 w.bits.data := data 595 } 596 println("Distributed CSR update req registered for " + src_description) 597 } 598} 599 600class L1CacheErrorInfo(implicit p: Parameters) extends XSBundle { 601 // L1CacheErrorInfo is also used to encode customized CACHE_ERROR CSR 602 val source = Output(new Bundle() { 603 val tag = Bool() // l1 tag array 604 val data = Bool() // l1 data array 605 val l2 = Bool() 606 }) 607 val opType = Output(new Bundle() { 608 val fetch = Bool() 609 val load = Bool() 610 val store = Bool() 611 val probe = Bool() 612 val release = Bool() 613 val atom = Bool() 614 }) 615 val paddr = Output(UInt(PAddrBits.W)) 616 617 // report error and paddr to beu 618 // bus error unit will receive error info iff ecc_error.valid 619 val report_to_beu = Output(Bool()) 620 621 // there is an valid error 622 // l1 cache error will always be report to CACHE_ERROR csr 623 val valid = Output(Bool()) 624 625 def toL1BusErrorUnitInfo(): L1BusErrorUnitInfo = { 626 val beu_info = Wire(new L1BusErrorUnitInfo) 627 beu_info.ecc_error.valid := report_to_beu 628 beu_info.ecc_error.bits := paddr 629 beu_info 630 } 631} 632 633/* TODO how to trigger on next inst? 6341. If hit is determined at frontend, then set a "next instr" trap at dispatch like singlestep 6352. If it is determined at Load(meaning it must be "hit after", then it must not be a jump. So we can let it commit and set 636xret csr to pc + 4/ + 2 6372.5 The problem is to let it commit. This is the real TODO 6383. If it is load and hit before just treat it as regular load exception 639 */ 640 641// This bundle carries trigger hit info along the pipeline 642// Now there are 10 triggers divided into 5 groups of 2 643// These groups are 644// (if if) (store store) (load loid) (if store) (if load) 645 646// Triggers in the same group can chain, meaning that they only 647// fire is both triggers in the group matches (the triggerHitVec bit is asserted) 648// Chaining of trigger No. (2i) and (2i+1) is indicated by triggerChainVec(i) 649// Timing of 0 means trap at current inst, 1 means trap at next inst 650// Chaining and timing and the validness of a trigger is controlled by csr 651// In two chained triggers, if they have different timing, both won't fire 652//class TriggerCf (implicit p: Parameters) extends XSBundle { 653// val triggerHitVec = Vec(10, Bool()) 654// val triggerTiming = Vec(10, Bool()) 655// val triggerChainVec = Vec(5, Bool()) 656//} 657 658class TriggerCf(implicit p: Parameters) extends XSBundle { 659 // frontend 660 val frontendHit = Vec(TriggerNum, Bool()) // en && hit 661 val frontendTiming = Vec(TriggerNum, Bool()) // en && timing 662 val frontendChain = Vec(TriggerNum, Bool()) // en && chain 663 val frontendCanFire = Vec(TriggerNum, Bool()) 664 // backend 665 val backendHit = Vec(TriggerNum, Bool()) 666 val backendCanFire = Vec(TriggerNum, Bool()) 667 668 // Two situations not allowed: 669 // 1. load data comparison 670 // 2. store chaining with store 671 def getFrontendCanFire = frontendCanFire.reduce(_ || _) 672 def getBackendCanFire = backendCanFire.reduce(_ || _) 673 def canFire = getFrontendCanFire || getBackendCanFire 674 def clear(): Unit = { 675 frontendHit.foreach(_ := false.B) 676 frontendCanFire.foreach(_ := false.B) 677 backendHit.foreach(_ := false.B) 678 backendCanFire.foreach(_ := false.B) 679 frontendTiming.foreach(_ := false.B) 680 frontendChain.foreach(_ := false.B) 681 } 682} 683 684// these 3 bundles help distribute trigger control signals from CSR 685// to Frontend, Load and Store. 686class FrontendTdataDistributeIO(implicit p: Parameters) extends XSBundle { 687 val tUpdate = ValidIO(new Bundle { 688 val addr = Output(UInt(log2Up(TriggerNum).W)) 689 val tdata = new MatchTriggerIO 690 }) 691 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 692} 693 694class MemTdataDistributeIO(implicit p: Parameters) extends XSBundle { 695 val tUpdate = ValidIO(new Bundle { 696 val addr = Output(UInt(log2Up(TriggerNum).W)) 697 val tdata = new MatchTriggerIO 698 }) 699 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 700} 701 702class MatchTriggerIO(implicit p: Parameters) extends XSBundle { 703 val matchType = Output(UInt(2.W)) 704 val select = Output(Bool()) 705 val timing = Output(Bool()) 706 val action = Output(Bool()) 707 val chain = Output(Bool()) 708 val execute = Output(Bool()) 709 val store = Output(Bool()) 710 val load = Output(Bool()) 711 val tdata2 = Output(UInt(64.W)) 712} 713 714class StallReasonIO(width: Int) extends Bundle { 715 val reason = Output(Vec(width, UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 716 val backReason = Flipped(Valid(UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 717} 718 719// custom l2 - l1 interface 720class L2ToL1Hint(implicit p: Parameters) extends XSBundle with HasDCacheParameters { 721 val sourceId = UInt(log2Up(cfg.nMissEntries).W) // tilelink sourceID -> mshr id 722} 723 724