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 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 = UInt(5.W) 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 RabCommitInfo(implicit p: Parameters) extends XSBundle { 361 val ldest = UInt(6.W) 362 val pdest = UInt(PhyRegIdxWidth.W) 363 val old_pdest = UInt(PhyRegIdxWidth.W) 364 val rfWen = Bool() 365 val fpWen = Bool() 366 val vecWen = Bool() 367 val isMove = Bool() 368} 369 370class RabCommitIO(implicit p: Parameters) extends XSBundle { 371 val isCommit = Bool() 372 val commitValid = Vec(CommitWidth, Bool()) 373 val isWalk = Bool() 374 val walkValid = Vec(CommitWidth, Bool()) 375 val info = Vec(CommitWidth, new RabCommitInfo) 376} 377 378class DiffCommitIO(implicit p: Parameters) extends XSBundle { 379 val isCommit = Bool() 380 val commitValid = Vec(CommitWidth * MaxUopSize, Bool()) 381 382 val info = Vec(CommitWidth * MaxUopSize, new RobCommitInfo) 383} 384 385class RobCommitInfo(implicit p: Parameters) extends XSBundle { 386 val ldest = UInt(6.W) 387 val rfWen = Bool() 388 val fpWen = Bool() // for Rab only 389 def dirtyFs = fpWen // for Rob only 390 val vecWen = Bool() 391 def fpVecWen = fpWen || vecWen 392 val wflags = Bool() 393 val commitType = CommitType() 394 val pdest = UInt(PhyRegIdxWidth.W) 395 val ftqIdx = new FtqPtr 396 val ftqOffset = UInt(log2Up(PredictWidth).W) 397 val isMove = Bool() 398 val isRVC = Bool() 399 val isVset = Bool() 400 val vtype = new VType 401 402 // these should be optimized for synthesis verilog 403 val pc = UInt(VAddrBits.W) 404 405 val instrSize = UInt(log2Ceil(RenameWidth + 1).W) 406} 407 408class RobCommitIO(implicit p: Parameters) extends XSBundle { 409 val isCommit = Bool() 410 val commitValid = Vec(CommitWidth, Bool()) 411 412 val isWalk = Bool() 413 // valid bits optimized for walk 414 val walkValid = Vec(CommitWidth, Bool()) 415 416 val info = Vec(CommitWidth, new RobCommitInfo) 417 val robIdx = Vec(CommitWidth, new RobPtr) 418 419 def hasWalkInstr: Bool = isWalk && walkValid.asUInt.orR 420 def hasCommitInstr: Bool = isCommit && commitValid.asUInt.orR 421} 422 423class SnapshotPort(implicit p: Parameters) extends XSBundle { 424 val snptEnq = Bool() 425 val snptDeq = Bool() 426 val useSnpt = Bool() 427 val snptSelect = UInt(log2Ceil(RenameSnapshotNum).W) 428 val flushVec = Vec(RenameSnapshotNum, Bool()) 429} 430 431class RSFeedback(implicit p: Parameters) extends XSBundle { 432 val robIdx = new RobPtr 433 val hit = Bool() 434 val flushState = Bool() 435 val sourceType = RSFeedbackType() 436 val dataInvalidSqIdx = new SqPtr 437} 438 439class MemRSFeedbackIO(implicit p: Parameters) extends XSBundle { 440 // Note: you need to update in implicit Parameters p before imp MemRSFeedbackIO 441 // for instance: MemRSFeedbackIO()(updateP) 442 val feedbackSlow = ValidIO(new RSFeedback()) // dcache miss queue full, dtlb miss 443 val feedbackFast = ValidIO(new RSFeedback()) // bank conflict 444} 445 446class LoadCancelIO(implicit p: Parameters) extends XSBundle { 447 val ld1Cancel = ValidIO(UInt(log2Ceil(LoadPipelineWidth).W)) 448 val ld2Cancel = ValidIO(UInt(log2Ceil(LoadPipelineWidth).W)) 449} 450 451class FrontendToCtrlIO(implicit p: Parameters) extends XSBundle { 452 // to backend end 453 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 454 val stallReason = new StallReasonIO(DecodeWidth) 455 val fromFtq = new FtqToCtrlIO 456 // from backend 457 val toFtq = Flipped(new CtrlToFtqIO) 458} 459 460class SatpStruct(implicit p: Parameters) extends XSBundle { 461 val mode = UInt(4.W) 462 val asid = UInt(16.W) 463 val ppn = UInt(44.W) 464} 465 466class TlbSatpBundle(implicit p: Parameters) extends SatpStruct { 467 val changed = Bool() 468 469 def apply(satp_value: UInt): Unit = { 470 require(satp_value.getWidth == XLEN) 471 val sa = satp_value.asTypeOf(new SatpStruct) 472 mode := sa.mode 473 asid := sa.asid 474 ppn := Cat(0.U((44-PAddrBits).W), sa.ppn(PAddrBits-1, 0)).asUInt 475 changed := DataChanged(sa.asid) // when ppn is changed, software need do the flush 476 } 477} 478 479class TlbCsrBundle(implicit p: Parameters) extends XSBundle { 480 val satp = new TlbSatpBundle() 481 val priv = new Bundle { 482 val mxr = Bool() 483 val sum = Bool() 484 val imode = UInt(2.W) 485 val dmode = UInt(2.W) 486 } 487 488 override def toPrintable: Printable = { 489 p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " + 490 p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}" 491 } 492} 493 494class SfenceBundle(implicit p: Parameters) extends XSBundle { 495 val valid = Bool() 496 val bits = new Bundle { 497 val rs1 = Bool() 498 val rs2 = Bool() 499 val addr = UInt(VAddrBits.W) 500 val asid = UInt(AsidLength.W) 501 val flushPipe = Bool() 502 } 503 504 override def toPrintable: Printable = { 505 p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}, flushPipe:${bits.flushPipe}" 506 } 507} 508 509// Bundle for load violation predictor updating 510class MemPredUpdateReq(implicit p: Parameters) extends XSBundle { 511 val valid = Bool() 512 513 // wait table update 514 val waddr = UInt(MemPredPCWidth.W) 515 val wdata = Bool() // true.B by default 516 517 // store set update 518 // by default, ldpc/stpc should be xor folded 519 val ldpc = UInt(MemPredPCWidth.W) 520 val stpc = UInt(MemPredPCWidth.W) 521} 522 523class CustomCSRCtrlIO(implicit p: Parameters) extends XSBundle { 524 // Prefetcher 525 val l1I_pf_enable = Output(Bool()) 526 val l2_pf_enable = Output(Bool()) 527 val l1D_pf_enable = Output(Bool()) 528 val l1D_pf_train_on_hit = Output(Bool()) 529 val l1D_pf_enable_agt = Output(Bool()) 530 val l1D_pf_enable_pht = Output(Bool()) 531 val l1D_pf_active_threshold = Output(UInt(4.W)) 532 val l1D_pf_active_stride = Output(UInt(6.W)) 533 val l1D_pf_enable_stride = Output(Bool()) 534 val l2_pf_store_only = Output(Bool()) 535 // ICache 536 val icache_parity_enable = Output(Bool()) 537 // Labeled XiangShan 538 val dsid = Output(UInt(8.W)) // TODO: DsidWidth as parameter 539 // Load violation predictor 540 val lvpred_disable = Output(Bool()) 541 val no_spec_load = Output(Bool()) 542 val storeset_wait_store = Output(Bool()) 543 val storeset_no_fast_wakeup = Output(Bool()) 544 val lvpred_timeout = Output(UInt(5.W)) 545 // Branch predictor 546 val bp_ctrl = Output(new BPUCtrl) 547 // Memory Block 548 val sbuffer_threshold = Output(UInt(4.W)) 549 val ldld_vio_check_enable = Output(Bool()) 550 val soft_prefetch_enable = Output(Bool()) 551 val cache_error_enable = Output(Bool()) 552 val uncache_write_outstanding_enable = Output(Bool()) 553 // Rename 554 val fusion_enable = Output(Bool()) 555 val wfi_enable = Output(Bool()) 556 // Decode 557 val svinval_enable = Output(Bool()) 558 559 // distribute csr write signal 560 val distribute_csr = new DistributedCSRIO() 561 562 val singlestep = Output(Bool()) 563 val frontend_trigger = new FrontendTdataDistributeIO() 564 val mem_trigger = new MemTdataDistributeIO() 565 val trigger_enable = Output(Vec(10, Bool())) 566} 567 568class DistributedCSRIO(implicit p: Parameters) extends XSBundle { 569 // CSR has been written by csr inst, copies of csr should be updated 570 val w = ValidIO(new Bundle { 571 val addr = Output(UInt(12.W)) 572 val data = Output(UInt(XLEN.W)) 573 }) 574} 575 576class DistributedCSRUpdateReq(implicit p: Parameters) extends XSBundle { 577 // Request csr to be updated 578 // 579 // Note that this request will ONLY update CSR Module it self, 580 // copies of csr will NOT be updated, use it with care! 581 // 582 // For each cycle, no more than 1 DistributedCSRUpdateReq is valid 583 val w = ValidIO(new Bundle { 584 val addr = Output(UInt(12.W)) 585 val data = Output(UInt(XLEN.W)) 586 }) 587 def apply(valid: Bool, addr: UInt, data: UInt, src_description: String) = { 588 when(valid){ 589 w.bits.addr := addr 590 w.bits.data := data 591 } 592 println("Distributed CSR update req registered for " + src_description) 593 } 594} 595 596class L1CacheErrorInfo(implicit p: Parameters) extends XSBundle { 597 // L1CacheErrorInfo is also used to encode customized CACHE_ERROR CSR 598 val source = Output(new Bundle() { 599 val tag = Bool() // l1 tag array 600 val data = Bool() // l1 data array 601 val l2 = Bool() 602 }) 603 val opType = Output(new Bundle() { 604 val fetch = Bool() 605 val load = Bool() 606 val store = Bool() 607 val probe = Bool() 608 val release = Bool() 609 val atom = Bool() 610 }) 611 val paddr = Output(UInt(PAddrBits.W)) 612 613 // report error and paddr to beu 614 // bus error unit will receive error info iff ecc_error.valid 615 val report_to_beu = Output(Bool()) 616 617 // there is an valid error 618 // l1 cache error will always be report to CACHE_ERROR csr 619 val valid = Output(Bool()) 620 621 def toL1BusErrorUnitInfo(): L1BusErrorUnitInfo = { 622 val beu_info = Wire(new L1BusErrorUnitInfo) 623 beu_info.ecc_error.valid := report_to_beu 624 beu_info.ecc_error.bits := paddr 625 beu_info 626 } 627} 628 629/* TODO how to trigger on next inst? 6301. If hit is determined at frontend, then set a "next instr" trap at dispatch like singlestep 6312. 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 632xret csr to pc + 4/ + 2 6332.5 The problem is to let it commit. This is the real TODO 6343. If it is load and hit before just treat it as regular load exception 635 */ 636 637// This bundle carries trigger hit info along the pipeline 638// Now there are 10 triggers divided into 5 groups of 2 639// These groups are 640// (if if) (store store) (load loid) (if store) (if load) 641 642// Triggers in the same group can chain, meaning that they only 643// fire is both triggers in the group matches (the triggerHitVec bit is asserted) 644// Chaining of trigger No. (2i) and (2i+1) is indicated by triggerChainVec(i) 645// Timing of 0 means trap at current inst, 1 means trap at next inst 646// Chaining and timing and the validness of a trigger is controlled by csr 647// In two chained triggers, if they have different timing, both won't fire 648//class TriggerCf (implicit p: Parameters) extends XSBundle { 649// val triggerHitVec = Vec(10, Bool()) 650// val triggerTiming = Vec(10, Bool()) 651// val triggerChainVec = Vec(5, Bool()) 652//} 653 654class TriggerCf(implicit p: Parameters) extends XSBundle { 655 // frontend 656 val frontendHit = Vec(4, Bool()) 657// val frontendTiming = Vec(4, Bool()) 658// val frontendHitNext = Vec(4, Bool()) 659 660// val frontendException = Bool() 661 // backend 662 val backendEn = Vec(2, Bool()) // Hit(6) && chain(4) , Hit(8) && chain(4) 663 val backendHit = Vec(6, Bool()) 664// val backendTiming = Vec(6, Bool()) // trigger enable fro chain 665 666 // Two situations not allowed: 667 // 1. load data comparison 668 // 2. store chaining with store 669 def getHitFrontend = frontendHit.reduce(_ || _) 670 def getHitBackend = backendHit.reduce(_ || _) 671 def hit = getHitFrontend || getHitBackend 672 def clear(): Unit = { 673 frontendHit.foreach(_ := false.B) 674 backendEn.foreach(_ := false.B) 675 backendHit.foreach(_ := false.B) 676 } 677} 678 679// these 3 bundles help distribute trigger control signals from CSR 680// to Frontend, Load and Store. 681class FrontendTdataDistributeIO(implicit p: Parameters) extends XSBundle { 682 val t = Valid(new Bundle { 683 val addr = Output(UInt(2.W)) 684 val tdata = new MatchTriggerIO 685 }) 686 } 687 688class MemTdataDistributeIO(implicit p: Parameters) extends XSBundle { 689 val t = Valid(new Bundle { 690 val addr = Output(UInt(3.W)) 691 val tdata = new MatchTriggerIO 692 }) 693} 694 695class MatchTriggerIO(implicit p: Parameters) extends XSBundle { 696 val matchType = Output(UInt(2.W)) 697 val select = Output(Bool()) 698 val timing = Output(Bool()) 699 val action = Output(Bool()) 700 val chain = Output(Bool()) 701 val tdata2 = Output(UInt(64.W)) 702} 703 704class StallReasonIO(width: Int) extends Bundle { 705 val reason = Output(Vec(width, UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 706 val backReason = Flipped(Valid(UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 707} 708 709// custom l2 - l1 interface 710class L2ToL1Hint(implicit p: Parameters) extends XSBundle with HasDCacheParameters { 711 val sourceId = UInt(log2Up(cfg.nMissEntries).W) // tilelink sourceID -> mshr id 712} 713