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