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