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.{Field, Parameters} 20import chisel3._ 21import chisel3.util._ 22import huancun._ 23import system.SoCParamsKey 24import xiangshan.backend.datapath.RdConfig._ 25import xiangshan.backend.datapath.WbConfig._ 26import xiangshan.backend.dispatch.DispatchParameters 27import xiangshan.backend.exu.ExeUnitParams 28import xiangshan.backend.fu.FuConfig._ 29import xiangshan.backend.issue.{IntScheduler, IssueBlockParams, MemScheduler, SchdBlockParams, SchedulerType, VfScheduler, FpScheduler} 30import xiangshan.backend.regfile._ 31import xiangshan.backend.BackendParams 32import xiangshan.cache.DCacheParameters 33import xiangshan.cache.prefetch._ 34import xiangshan.frontend.{BasePredictor, BranchPredictionResp, FTB, FakePredictor, RAS, Tage, ITTage, Tage_SC, FauFTB} 35import xiangshan.frontend.icache.ICacheParameters 36import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters} 37import xiangshan.frontend._ 38import xiangshan.frontend.icache.ICacheParameters 39import freechips.rocketchip.diplomacy.AddressSet 40import freechips.rocketchip.tile.MaxHartIdBits 41import system.SoCParamsKey 42import huancun._ 43import huancun.debug._ 44import xiangshan.cache.wpu.WPUParameters 45import coupledL2._ 46import coupledL2.tl2chi._ 47import xiangshan.backend.datapath.WakeUpConfig 48import xiangshan.mem.prefetch.{PrefetcherParams, SMSParams} 49 50import scala.math.{max, min} 51 52case object XSTileKey extends Field[Seq[XSCoreParameters]] 53 54case object XSCoreParamsKey extends Field[XSCoreParameters] 55 56case class XSCoreParameters 57( 58 HasPrefetch: Boolean = false, 59 HartId: Int = 0, 60 XLEN: Int = 64, 61 VLEN: Int = 128, 62 ELEN: Int = 64, 63 HSXLEN: Int = 64, 64 HasMExtension: Boolean = true, 65 HasCExtension: Boolean = true, 66 HasHExtension: Boolean = true, 67 HasDiv: Boolean = true, 68 HasICache: Boolean = true, 69 HasDCache: Boolean = true, 70 AddrBits: Int = 64, 71 VAddrBitsSv39: Int = 39, 72 GPAddrBitsSv39x4: Int = 41, 73 VAddrBitsSv48: Int = 48, 74 GPAddrBitsSv48x4: Int = 50, 75 HasFPU: Boolean = true, 76 HasVPU: Boolean = true, 77 HasCustomCSRCacheOp: Boolean = true, 78 FetchWidth: Int = 8, 79 AsidLength: Int = 16, 80 VmidLength: Int = 14, 81 EnableBPU: Boolean = true, 82 EnableBPD: Boolean = true, 83 EnableRAS: Boolean = true, 84 EnableLB: Boolean = false, 85 EnableLoop: Boolean = true, 86 EnableSC: Boolean = true, 87 EnbaleTlbDebug: Boolean = false, 88 EnableClockGate: Boolean = true, 89 EnableJal: Boolean = false, 90 EnableFauFTB: Boolean = true, 91 EnableSv48: Boolean = true, 92 UbtbGHRLength: Int = 4, 93 // HistoryLength: Int = 512, 94 EnableGHistDiff: Boolean = true, 95 EnableCommitGHistDiff: Boolean = true, 96 UbtbSize: Int = 256, 97 FtbSize: Int = 2048, 98 RasSize: Int = 16, 99 RasSpecSize: Int = 32, 100 RasCtrSize: Int = 3, 101 CacheLineSize: Int = 512, 102 FtbWays: Int = 4, 103 TageTableInfos: Seq[Tuple3[Int,Int,Int]] = 104 // Sets Hist Tag 105 Seq(( 4096, 8, 8), 106 ( 4096, 13, 8), 107 ( 4096, 32, 8), 108 ( 4096, 119, 8)), 109 ITTageTableInfos: Seq[Tuple3[Int,Int,Int]] = 110 // Sets Hist Tag 111 Seq(( 256, 4, 9), 112 ( 256, 8, 9), 113 ( 512, 13, 9), 114 ( 512, 16, 9), 115 ( 512, 32, 9)), 116 SCNRows: Int = 512, 117 SCNTables: Int = 4, 118 SCCtrBits: Int = 6, 119 SCHistLens: Seq[Int] = Seq(0, 4, 10, 16), 120 numBr: Int = 2, 121 branchPredictor: (BranchPredictionResp, Parameters) => Tuple2[Seq[BasePredictor], BranchPredictionResp] = 122 (resp_in: BranchPredictionResp, p: Parameters) => { 123 val ftb = Module(new FTB()(p)) 124 val uftb = Module(new FauFTB()(p)) 125 val tage = Module(new Tage_SC()(p)) 126 val ras = Module(new RAS()(p)) 127 val ittage = Module(new ITTage()(p)) 128 val preds = Seq(uftb, tage, ftb, ittage, ras) 129 preds.map(_.io := DontCare) 130 131 ftb.io.fauftb_entry_in := uftb.io.fauftb_entry_out 132 ftb.io.fauftb_entry_hit_in := uftb.io.fauftb_entry_hit_out 133 134 uftb.io.in.bits.resp_in(0) := resp_in 135 tage.io.in.bits.resp_in(0) := uftb.io.out 136 ftb.io.in.bits.resp_in(0) := tage.io.out 137 ittage.io.in.bits.resp_in(0) := ftb.io.out 138 ras.io.in.bits.resp_in(0) := ittage.io.out 139 140 (preds, ras.io.out) 141 }, 142 ICacheForceMetaECCError: Boolean = false, 143 ICacheForceDataECCError: Boolean = false, 144 IBufSize: Int = 48, 145 IBufNBank: Int = 6, // IBuffer bank amount, should divide IBufSize 146 DecodeWidth: Int = 6, 147 RenameWidth: Int = 6, 148 CommitWidth: Int = 8, 149 RobCommitWidth: Int = 8, 150 RabCommitWidth: Int = 6, 151 MaxUopSize: Int = 65, 152 EnableRenameSnapshot: Boolean = true, 153 RenameSnapshotNum: Int = 4, 154 FtqSize: Int = 64, 155 EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false 156 IntLogicRegs: Int = 32, 157 FpLogicRegs: Int = 32 + 1 + 1, // 1: I2F, 1: stride 158 VecLogicRegs: Int = 32 + 15, // 15: tmp 159 V0LogicRegs: Int = 1, // V0 160 VlLogicRegs: Int = 1, // Vl 161 V0_IDX: Int = 0, 162 Vl_IDX: Int = 0, 163 NRPhyRegs: Int = 192, 164 VirtualLoadQueueSize: Int = 72, 165 LoadQueueRARSize: Int = 72, 166 LoadQueueRAWSize: Int = 64, // NOTE: make sure that LoadQueueRAWSize is power of 2. 167 RollbackGroupSize: Int = 8, 168 LoadQueueReplaySize: Int = 72, 169 LoadUncacheBufferSize: Int = 20, 170 LoadQueueNWriteBanks: Int = 8, // NOTE: make sure that LoadQueueRARSize/LoadQueueRAWSize is divided by LoadQueueNWriteBanks 171 StoreQueueSize: Int = 64, 172 StoreQueueNWriteBanks: Int = 8, // NOTE: make sure that StoreQueueSize is divided by StoreQueueNWriteBanks 173 StoreQueueForwardWithMask: Boolean = true, 174 VlsQueueSize: Int = 8, 175 RobSize: Int = 160, 176 RabSize: Int = 256, 177 VTypeBufferSize: Int = 64, // used to reorder vtype 178 IssueQueueSize: Int = 24, 179 IssueQueueCompEntrySize: Int = 16, 180 dpParams: DispatchParameters = DispatchParameters( 181 IntDqSize = 16, 182 FpDqSize = 16, 183 LsDqSize = 18, 184 IntDqDeqWidth = 8, 185 FpDqDeqWidth = 6, 186 VecDqDeqWidth = 6, 187 LsDqDeqWidth = 6, 188 ), 189 intPreg: PregParams = IntPregParams( 190 numEntries = 224, 191 numRead = None, 192 numWrite = None, 193 ), 194 fpPreg: PregParams = FpPregParams( 195 numEntries = 192, 196 numRead = None, 197 numWrite = None, 198 ), 199 vfPreg: VfPregParams = VfPregParams( 200 numEntries = 128, 201 numRead = None, 202 numWrite = None, 203 ), 204 v0Preg: V0PregParams = V0PregParams( 205 numEntries = 22, 206 numRead = None, 207 numWrite = None, 208 ), 209 vlPreg: VlPregParams = VlPregParams( 210 numEntries = 32, 211 numRead = None, 212 numWrite = None, 213 ), 214 IntRegCacheSize: Int = 16, 215 MemRegCacheSize: Int = 12, 216 prefetcher: Option[PrefetcherParams] = Some(SMSParams()), 217 IfuRedirectNum: Int = 1, 218 LoadPipelineWidth: Int = 3, 219 StorePipelineWidth: Int = 2, 220 VecLoadPipelineWidth: Int = 2, 221 VecStorePipelineWidth: Int = 2, 222 VecMemSrcInWidth: Int = 2, 223 VecMemInstWbWidth: Int = 1, 224 VecMemDispatchWidth: Int = 1, 225 VecMemDispatchMaxNumber: Int = 16, 226 VecMemUnitStrideMaxFlowNum: Int = 2, 227 VecMemLSQEnqIteratorNumberSeq: Seq[Int] = Seq(16, 2, 2, 2, 2, 2), 228 StoreBufferSize: Int = 16, 229 StoreBufferThreshold: Int = 7, 230 EnsbufferWidth: Int = 2, 231 LoadDependencyWidth: Int = 2, 232 // ============ VLSU ============ 233 VlMergeBufferSize: Int = 16, 234 VsMergeBufferSize: Int = 16, 235 UopWritebackWidth: Int = 2, 236 VLUopWritebackWidth: Int = 2, 237 VSUopWritebackWidth: Int = 1, 238 VSegmentBufferSize: Int = 8, 239 // ============================== 240 UncacheBufferSize: Int = 4, 241 EnableLoadToLoadForward: Boolean = false, 242 EnableFastForward: Boolean = true, 243 EnableLdVioCheckAfterReset: Boolean = true, 244 EnableSoftPrefetchAfterReset: Boolean = true, 245 EnableCacheErrorAfterReset: Boolean = true, 246 EnableAccurateLoadError: Boolean = false, 247 EnableUncacheWriteOutstanding: Boolean = false, 248 EnableHardwareStoreMisalign: Boolean = true, 249 EnableHardwareLoadMisalign: Boolean = true, 250 EnableStorePrefetchAtIssue: Boolean = false, 251 EnableStorePrefetchAtCommit: Boolean = false, 252 EnableAtCommitMissTrigger: Boolean = true, 253 EnableStorePrefetchSMS: Boolean = false, 254 EnableStorePrefetchSPB: Boolean = false, 255 MMUAsidLen: Int = 16, // max is 16, 0 is not supported now 256 MMUVmidLen: Int = 14, 257 ReSelectLen: Int = 7, // load replay queue replay select counter len 258 iwpuParameters: WPUParameters = WPUParameters( 259 enWPU = false, 260 algoName = "mmru", 261 isICache = true, 262 ), 263 dwpuParameters: WPUParameters = WPUParameters( 264 enWPU = false, 265 algoName = "mmru", 266 enCfPred = false, 267 isICache = false, 268 ), 269 itlbParameters: TLBParameters = TLBParameters( 270 name = "itlb", 271 fetchi = true, 272 useDmode = false, 273 NWays = 48, 274 ), 275 itlbPortNum: Int = ICacheParameters().PortNumber + 1, 276 ipmpPortNum: Int = 2 * ICacheParameters().PortNumber + 1, 277 ldtlbParameters: TLBParameters = TLBParameters( 278 name = "ldtlb", 279 NWays = 48, 280 outReplace = false, 281 partialStaticPMP = true, 282 outsideRecvFlush = true, 283 saveLevel = false, 284 lgMaxSize = 4 285 ), 286 sttlbParameters: TLBParameters = TLBParameters( 287 name = "sttlb", 288 NWays = 48, 289 outReplace = false, 290 partialStaticPMP = true, 291 outsideRecvFlush = true, 292 saveLevel = false, 293 lgMaxSize = 4 294 ), 295 hytlbParameters: TLBParameters = TLBParameters( 296 name = "hytlb", 297 NWays = 48, 298 outReplace = false, 299 partialStaticPMP = true, 300 outsideRecvFlush = true, 301 saveLevel = false, 302 lgMaxSize = 4 303 ), 304 pftlbParameters: TLBParameters = TLBParameters( 305 name = "pftlb", 306 NWays = 48, 307 outReplace = false, 308 partialStaticPMP = true, 309 outsideRecvFlush = true, 310 saveLevel = false, 311 lgMaxSize = 4 312 ), 313 l2ToL1tlbParameters: TLBParameters = TLBParameters( 314 name = "l2tlb", 315 NWays = 48, 316 outReplace = false, 317 partialStaticPMP = true, 318 outsideRecvFlush = true, 319 saveLevel = false 320 ), 321 refillBothTlb: Boolean = false, 322 btlbParameters: TLBParameters = TLBParameters( 323 name = "btlb", 324 NWays = 48, 325 ), 326 l2tlbParameters: L2TLBParameters = L2TLBParameters(), 327 NumPerfCounters: Int = 16, 328 icacheParameters: ICacheParameters = ICacheParameters( 329 tagECC = Some("parity"), 330 dataECC = Some("parity"), 331 replacer = Some("setplru"), 332 ), 333 dcacheParametersOpt: Option[DCacheParameters] = Some(DCacheParameters( 334 tagECC = Some("secded"), 335 dataECC = Some("secded"), 336 replacer = Some("setplru"), 337 nMissEntries = 16, 338 nProbeEntries = 8, 339 nReleaseEntries = 18, 340 nMaxPrefetchEntry = 6, 341 )), 342 L2CacheParamsOpt: Option[L2Param] = Some(L2Param( 343 name = "l2", 344 ways = 8, 345 sets = 1024, // default 512KB L2 346 prefetch = Seq(coupledL2.prefetch.PrefetchReceiverParams(), coupledL2.prefetch.BOPParameters(), 347 coupledL2.prefetch.TPParameters()), 348 )), 349 L2NBanks: Int = 1, 350 usePTWRepeater: Boolean = false, 351 softTLB: Boolean = false, // dpi-c l1tlb debug only 352 softPTW: Boolean = false, // dpi-c l2tlb debug only 353 softPTWDelay: Int = 1 354){ 355 def vlWidth = log2Up(VLEN) + 1 356 357 /** 358 * the minimum element length of vector elements 359 */ 360 val minVecElen: Int = 8 361 362 /** 363 * the maximum number of elements in vector register 364 */ 365 val maxElemPerVreg: Int = VLEN / minVecElen 366 367 val allHistLens = SCHistLens ++ ITTageTableInfos.map(_._2) ++ TageTableInfos.map(_._2) :+ UbtbGHRLength 368 val HistoryLength = allHistLens.max + numBr * FtqSize + 9 // 256 for the predictor configs now 369 370 val RegCacheSize = IntRegCacheSize + MemRegCacheSize 371 val RegCacheIdxWidth = log2Up(RegCacheSize) 372 373 val intSchdParams = { 374 implicit val schdType: SchedulerType = IntScheduler() 375 SchdBlockParams(Seq( 376 IssueBlockParams(Seq( 377 ExeUnitParams("ALU0", Seq(AluCfg, MulCfg, BkuCfg), Seq(IntWB(port = 0, 0)), Seq(Seq(IntRD(0, 0)), Seq(IntRD(1, 0))), true, 2), 378 ExeUnitParams("BJU0", Seq(BrhCfg, JmpCfg), Seq(IntWB(port = 0, 1)), Seq(Seq(IntRD(6, 1)), Seq(IntRD(7, 1))), true, 2), 379 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 380 IssueBlockParams(Seq( 381 ExeUnitParams("ALU1", Seq(AluCfg, MulCfg, BkuCfg), Seq(IntWB(port = 1, 0)), Seq(Seq(IntRD(2, 0)), Seq(IntRD(3, 0))), true, 2), 382 ExeUnitParams("BJU1", Seq(BrhCfg, JmpCfg), Seq(IntWB(port = 1, 1)), Seq(Seq(IntRD(4, 1)), Seq(IntRD(5, 1))), true, 2), 383 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 384 IssueBlockParams(Seq( 385 ExeUnitParams("ALU2", Seq(AluCfg), Seq(IntWB(port = 2, 0)), Seq(Seq(IntRD(4, 0)), Seq(IntRD(5, 0))), true, 2), 386 ExeUnitParams("BJU2", Seq(BrhCfg, JmpCfg, I2fCfg, VSetRiWiCfg, VSetRiWvfCfg, I2vCfg), Seq(IntWB(port = 4, 0), VfWB(2, 0), V0WB(port = 2, 0), VlWB(port = 0, 0), FpWB(port = 4, 0)), Seq(Seq(IntRD(2, 1)), Seq(IntRD(3, 1)))), 387 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 388 IssueBlockParams(Seq( 389 ExeUnitParams("ALU3", Seq(AluCfg), Seq(IntWB(port = 3, 0)), Seq(Seq(IntRD(6, 0)), Seq(IntRD(7, 0))), true, 2), 390 ExeUnitParams("BJU3", Seq(CsrCfg, FenceCfg, DivCfg), Seq(IntWB(port = 4, 1)), Seq(Seq(IntRD(0, 1)), Seq(IntRD(1, 1)))), 391 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 392 ), 393 numPregs = intPreg.numEntries, 394 numDeqOutside = 0, 395 schdType = schdType, 396 rfDataWidth = intPreg.dataCfg.dataWidth, 397 numUopIn = dpParams.IntDqDeqWidth, 398 ) 399 } 400 401 val fpSchdParams = { 402 implicit val schdType: SchedulerType = FpScheduler() 403 SchdBlockParams(Seq( 404 IssueBlockParams(Seq( 405 ExeUnitParams("FEX0", Seq(FaluCfg, FcvtCfg, F2vCfg, FmacCfg), Seq(FpWB(port = 0, 0), IntWB(port = 0, 2), VfWB(port = 3, 0), V0WB(port = 3, 0)), Seq(Seq(FpRD(0, 0)), Seq(FpRD(1, 0)), Seq(FpRD(2, 0)))), 406 ), numEntries = 18, numEnq = 2, numComp = 16), 407 IssueBlockParams(Seq( 408 ExeUnitParams("FEX1", Seq(FaluCfg, FmacCfg), Seq(FpWB(port = 1, 0), IntWB(port = 1, 2)), Seq(Seq(FpRD(3, 0)), Seq(FpRD(4, 0)), Seq(FpRD(5, 0)))), 409 ), numEntries = 18, numEnq = 2, numComp = 16), 410 IssueBlockParams(Seq( 411 ExeUnitParams("FEX2", Seq(FaluCfg, FmacCfg), Seq(FpWB(port = 2, 0), IntWB(port = 2, 2)), Seq(Seq(FpRD(6, 0)), Seq(FpRD(7, 0)), Seq(FpRD(8, 0)))), 412 ), numEntries = 18, numEnq = 2, numComp = 16), 413 IssueBlockParams(Seq( 414 ExeUnitParams("FEX3", Seq(FaluCfg, FmacCfg), Seq(FpWB(port = 3, 0), IntWB(port = 3, 2)), Seq(Seq(FpRD(9, 0)), Seq(FpRD(10, 0)), Seq(FpRD(11, 0)))), 415 ), numEntries = 18, numEnq = 2, numComp = 16), 416 IssueBlockParams(Seq( 417 ExeUnitParams("FEX4", Seq(FdivCfg), Seq(FpWB(port = 4, 1)), Seq(Seq(FpRD(2, 1)), Seq(FpRD(5, 1)))), 418 ExeUnitParams("FEX5", Seq(FdivCfg), Seq(FpWB(port = 3, 1)), Seq(Seq(FpRD(8, 1)), Seq(FpRD(11, 1)))), 419 ), numEntries = 18, numEnq = 2, numComp = 16), 420 ), 421 numPregs = fpPreg.numEntries, 422 numDeqOutside = 0, 423 schdType = schdType, 424 rfDataWidth = fpPreg.dataCfg.dataWidth, 425 numUopIn = dpParams.VecDqDeqWidth, 426 ) 427 } 428 429 val vfSchdParams = { 430 implicit val schdType: SchedulerType = VfScheduler() 431 SchdBlockParams(Seq( 432 IssueBlockParams(Seq( 433 ExeUnitParams("VFEX0", Seq(VfmaCfg, VialuCfg, VimacCfg, VppuCfg), Seq(VfWB(port = 0, 0), V0WB(port = 0, 0)), Seq(Seq(VfRD(0, 0)), Seq(VfRD(1, 0)), Seq(VfRD(2, 0)), Seq(V0RD(0, 0)), Seq(VlRD(0, 0)))), 434 ExeUnitParams("VFEX1", Seq(VfaluCfg, VfcvtCfg, VipuCfg, VSetRvfWvfCfg), Seq(VfWB(port = 0, 1), V0WB(port = 0, 1), VlWB(port = 1, 0), IntWB(port = 1, 1), FpWB(port = 0, 1)), Seq(Seq(VfRD(0, 1)), Seq(VfRD(1, 1)), Seq(VfRD(2, 1)), Seq(V0RD(0, 1)), Seq(VlRD(0, 1)))), 435 ), numEntries = 16, numEnq = 2, numComp = 14), 436 IssueBlockParams(Seq( 437 ExeUnitParams("VFEX2", Seq(VfmaCfg, VialuCfg), Seq(VfWB(port = 1, 0), V0WB(port = 1, 0)), Seq(Seq(VfRD(3, 0)), Seq(VfRD(4, 0)), Seq(VfRD(5, 0)), Seq(V0RD(1, 0)), Seq(VlRD(1, 0)))), 438 ExeUnitParams("VFEX3", Seq(VfaluCfg, VfcvtCfg), Seq(VfWB(port = 2, 1), V0WB(port = 2, 1), FpWB(port = 1, 1)), Seq(Seq(VfRD(3, 1)), Seq(VfRD(4, 1)), Seq(VfRD(5, 1)), Seq(V0RD(1, 1)), Seq(VlRD(1, 1)))), 439 ), numEntries = 16, numEnq = 2, numComp = 14), 440 IssueBlockParams(Seq( 441 ExeUnitParams("VFEX4", Seq(VfdivCfg, VidivCfg), Seq(VfWB(port = 3, 1), V0WB(port = 3, 1)), Seq(Seq(VfRD(3, 2)), Seq(VfRD(4, 2)), Seq(VfRD(5, 2)), Seq(V0RD(1, 2)), Seq(VlRD(1, 2)))), 442 ), numEntries = 10, numEnq = 2, numComp = 8), 443 ), 444 numPregs = vfPreg.numEntries, 445 numDeqOutside = 0, 446 schdType = schdType, 447 rfDataWidth = vfPreg.dataCfg.dataWidth, 448 numUopIn = dpParams.VecDqDeqWidth, 449 ) 450 } 451 452 val memSchdParams = { 453 implicit val schdType: SchedulerType = MemScheduler() 454 val rfDataWidth = 64 455 456 SchdBlockParams(Seq( 457 IssueBlockParams(Seq( 458 ExeUnitParams("STA0", Seq(StaCfg, MouCfg), Seq(FakeIntWB()), Seq(Seq(IntRD(7, 2)))), 459 ), numEntries = 16, numEnq = 2, numComp = 14), 460 IssueBlockParams(Seq( 461 ExeUnitParams("STA1", Seq(StaCfg, MouCfg), Seq(FakeIntWB()), Seq(Seq(IntRD(6, 2)))), 462 ), numEntries = 16, numEnq = 2, numComp = 14), 463 IssueBlockParams(Seq( 464 ExeUnitParams("LDU0", Seq(LduCfg), Seq(IntWB(5, 0), FpWB(5, 0)), Seq(Seq(IntRD(8, 0))), true, 2), 465 ), numEntries = 16, numEnq = 2, numComp = 14), 466 IssueBlockParams(Seq( 467 ExeUnitParams("LDU1", Seq(LduCfg), Seq(IntWB(6, 0), FpWB(6, 0)), Seq(Seq(IntRD(9, 0))), true, 2), 468 ), numEntries = 16, numEnq = 2, numComp = 14), 469 IssueBlockParams(Seq( 470 ExeUnitParams("LDU2", Seq(LduCfg), Seq(IntWB(7, 0), FpWB(7, 0)), Seq(Seq(IntRD(10, 0))), true, 2), 471 ), numEntries = 16, numEnq = 2, numComp = 14), 472 IssueBlockParams(Seq( 473 ExeUnitParams("VLSU0", Seq(VlduCfg, VstuCfg, VseglduSeg, VsegstuCfg), Seq(VfWB(4, 0), V0WB(4, 0)), Seq(Seq(VfRD(6, 0)), Seq(VfRD(7, 0)), Seq(VfRD(8, 0)), Seq(V0RD(2, 0)), Seq(VlRD(2, 0)))), 474 ), numEntries = 16, numEnq = 2, numComp = 14), 475 IssueBlockParams(Seq( 476 ExeUnitParams("VLSU1", Seq(VlduCfg, VstuCfg), Seq(VfWB(5, 0), V0WB(5, 0)), Seq(Seq(VfRD(9, 0)), Seq(VfRD(10, 0)), Seq(VfRD(11, 0)), Seq(V0RD(3, 0)), Seq(VlRD(3, 0)))), 477 ), numEntries = 16, numEnq = 2, numComp = 14), 478 IssueBlockParams(Seq( 479 ExeUnitParams("STD0", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(5, 2), FpRD(12, 0)))), 480 ), numEntries = 16, numEnq = 2, numComp = 14), 481 IssueBlockParams(Seq( 482 ExeUnitParams("STD1", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(3, 2), FpRD(13, 0)))), 483 ), numEntries = 16, numEnq = 2, numComp = 14), 484 ), 485 numPregs = intPreg.numEntries max vfPreg.numEntries, 486 numDeqOutside = 0, 487 schdType = schdType, 488 rfDataWidth = rfDataWidth, 489 numUopIn = dpParams.LsDqDeqWidth, 490 ) 491 } 492 493 def PregIdxWidthMax = intPreg.addrWidth max vfPreg.addrWidth 494 495 def iqWakeUpParams = { 496 Seq( 497 WakeUpConfig( 498 Seq("ALU0", "ALU1", "ALU2", "ALU3", "LDU0", "LDU1", "LDU2") -> 499 Seq("ALU0", "BJU0", "ALU1", "BJU1", "ALU2", "BJU2", "ALU3", "BJU3", "LDU0", "LDU1", "LDU2", "STA0", "STA1", "STD0", "STD1") 500 ), 501 // TODO: add load -> fp slow wakeup 502 WakeUpConfig( 503 Seq("FEX0", "FEX1", "FEX2", "FEX3") -> 504 Seq("FEX0", "FEX1", "FEX2", "FEX3", "FEX4", "FEX5") 505 ), 506 WakeUpConfig( 507 Seq("FEX0", "FEX1", "FEX2", "FEX3") -> 508 Seq("STD0", "STD1") 509 ), 510// WakeUpConfig( 511// Seq("VFEX0", "VFEX1", "VFEX2", "VFEX3") -> 512// Seq("VFEX0", "VFEX1", "VFEX2", "VFEX3") 513// ), 514 ).flatten 515 } 516 517 def fakeIntPreg = FakeIntPregParams(intPreg.numEntries, intPreg.numRead, intPreg.numWrite) 518 519 val backendParams: BackendParams = backend.BackendParams( 520 Map( 521 IntScheduler() -> intSchdParams, 522 FpScheduler() -> fpSchdParams, 523 VfScheduler() -> vfSchdParams, 524 MemScheduler() -> memSchdParams, 525 ), 526 Seq( 527 intPreg, 528 fpPreg, 529 vfPreg, 530 v0Preg, 531 vlPreg, 532 fakeIntPreg 533 ), 534 iqWakeUpParams, 535 ) 536} 537 538case object DebugOptionsKey extends Field[DebugOptions] 539 540case class DebugOptions 541( 542 FPGAPlatform: Boolean = false, 543 ResetGen: Boolean = false, 544 EnableDifftest: Boolean = false, 545 AlwaysBasicDiff: Boolean = true, 546 EnableDebug: Boolean = false, 547 EnablePerfDebug: Boolean = true, 548 UseDRAMSim: Boolean = false, 549 EnableConstantin: Boolean = false, 550 EnableChiselDB: Boolean = false, 551 AlwaysBasicDB: Boolean = true, 552 EnableRollingDB: Boolean = false 553) 554 555trait HasXSParameter { 556 557 implicit val p: Parameters 558 559 def PAddrBits = p(SoCParamsKey).PAddrBits // PAddrBits is Phyical Memory addr bits 560 final val PageOffsetWidth = 12 561 def NodeIDWidth = p(SoCParamsKey).NodeIDWidthList(p(CHIIssue)) // NodeID width among NoC 562 563 def coreParams = p(XSCoreParamsKey) 564 def env = p(DebugOptionsKey) 565 566 def XLEN = coreParams.XLEN 567 def VLEN = coreParams.VLEN 568 def ELEN = coreParams.ELEN 569 def HSXLEN = coreParams.HSXLEN 570 val minFLen = 32 571 val fLen = 64 572 def hartIdLen = p(MaxHartIdBits) 573 val xLen = XLEN 574 575 def HasMExtension = coreParams.HasMExtension 576 def HasCExtension = coreParams.HasCExtension 577 def HasHExtension = coreParams.HasHExtension 578 def EnableSv48 = coreParams.EnableSv48 579 def HasDiv = coreParams.HasDiv 580 def HasIcache = coreParams.HasICache 581 def HasDcache = coreParams.HasDCache 582 def AddrBits = coreParams.AddrBits // AddrBits is used in some cases 583 def GPAddrBits = { 584 if (EnableSv48) 585 coreParams.GPAddrBitsSv48x4 586 else 587 coreParams.GPAddrBitsSv39x4 588 } 589 def VAddrBits = { 590 if (HasHExtension) { 591 if (EnableSv48) 592 coreParams.GPAddrBitsSv48x4 593 else 594 coreParams.GPAddrBitsSv39x4 595 } else { 596 if (EnableSv48) 597 coreParams.VAddrBitsSv48 598 else 599 coreParams.VAddrBitsSv39 600 } 601 } // VAddrBits is Virtual Memory addr bits 602 require(PAddrBits == 48 || !EnableSv48) // Paddr bits should be 48 when Sv48 enable 603 604 def VAddrMaxBits = { 605 if(EnableSv48) { 606 coreParams.VAddrBitsSv48 max coreParams.GPAddrBitsSv48x4 607 } else { 608 coreParams.VAddrBitsSv39 max coreParams.GPAddrBitsSv39x4 609 } 610 } 611 612 def AsidLength = coreParams.AsidLength 613 def VmidLength = coreParams.VmidLength 614 def ReSelectLen = coreParams.ReSelectLen 615 def AddrBytes = AddrBits / 8 // unused 616 def DataBits = XLEN 617 def DataBytes = DataBits / 8 618 def VDataBytes = VLEN / 8 619 def HasFPU = coreParams.HasFPU 620 def HasVPU = coreParams.HasVPU 621 def HasCustomCSRCacheOp = coreParams.HasCustomCSRCacheOp 622 def FetchWidth = coreParams.FetchWidth 623 def PredictWidth = FetchWidth * (if (HasCExtension) 2 else 1) 624 def EnableBPU = coreParams.EnableBPU 625 def EnableBPD = coreParams.EnableBPD // enable backing predictor(like Tage) in BPUStage3 626 def EnableRAS = coreParams.EnableRAS 627 def EnableLB = coreParams.EnableLB 628 def EnableLoop = coreParams.EnableLoop 629 def EnableSC = coreParams.EnableSC 630 def EnbaleTlbDebug = coreParams.EnbaleTlbDebug 631 def HistoryLength = coreParams.HistoryLength 632 def EnableGHistDiff = coreParams.EnableGHistDiff 633 def EnableCommitGHistDiff = coreParams.EnableCommitGHistDiff 634 def EnableClockGate = coreParams.EnableClockGate 635 def UbtbGHRLength = coreParams.UbtbGHRLength 636 def UbtbSize = coreParams.UbtbSize 637 def EnableFauFTB = coreParams.EnableFauFTB 638 def FtbSize = coreParams.FtbSize 639 def FtbWays = coreParams.FtbWays 640 def RasSize = coreParams.RasSize 641 def RasSpecSize = coreParams.RasSpecSize 642 def RasCtrSize = coreParams.RasCtrSize 643 644 def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = { 645 coreParams.branchPredictor(resp_in, p) 646 } 647 def numBr = coreParams.numBr 648 def TageTableInfos = coreParams.TageTableInfos 649 def TageBanks = coreParams.numBr 650 def SCNRows = coreParams.SCNRows 651 def SCCtrBits = coreParams.SCCtrBits 652 def SCHistLens = coreParams.SCHistLens 653 def SCNTables = coreParams.SCNTables 654 655 def SCTableInfos = Seq.fill(SCNTables)((SCNRows, SCCtrBits)) zip SCHistLens map { 656 case ((n, cb), h) => (n, cb, h) 657 } 658 def ITTageTableInfos = coreParams.ITTageTableInfos 659 type FoldedHistoryInfo = Tuple2[Int, Int] 660 def foldedGHistInfos = 661 (TageTableInfos.map{ case (nRows, h, t) => 662 if (h > 0) 663 Set((h, min(log2Ceil(nRows/numBr), h)), (h, min(h, t)), (h, min(h, t-1))) 664 else 665 Set[FoldedHistoryInfo]() 666 }.reduce(_++_).toSet ++ 667 SCTableInfos.map{ case (nRows, _, h) => 668 if (h > 0) 669 Set((h, min(log2Ceil(nRows/TageBanks), h))) 670 else 671 Set[FoldedHistoryInfo]() 672 }.reduce(_++_).toSet ++ 673 ITTageTableInfos.map{ case (nRows, h, t) => 674 if (h > 0) 675 Set((h, min(log2Ceil(nRows), h)), (h, min(h, t)), (h, min(h, t-1))) 676 else 677 Set[FoldedHistoryInfo]() 678 }.reduce(_++_) ++ 679 Set[FoldedHistoryInfo]((UbtbGHRLength, log2Ceil(UbtbSize))) 680 ).toList 681 682 683 684 def CacheLineSize = coreParams.CacheLineSize 685 def CacheLineHalfWord = CacheLineSize / 16 686 def ExtHistoryLength = HistoryLength + 64 687 def ICacheForceMetaECCError = coreParams.ICacheForceMetaECCError 688 def ICacheForceDataECCError = coreParams.ICacheForceDataECCError 689 def IBufSize = coreParams.IBufSize 690 def IBufNBank = coreParams.IBufNBank 691 def backendParams: BackendParams = coreParams.backendParams 692 def DecodeWidth = coreParams.DecodeWidth 693 def RenameWidth = coreParams.RenameWidth 694 def CommitWidth = coreParams.CommitWidth 695 def RobCommitWidth = coreParams.RobCommitWidth 696 def RabCommitWidth = coreParams.RabCommitWidth 697 def MaxUopSize = coreParams.MaxUopSize 698 def EnableRenameSnapshot = coreParams.EnableRenameSnapshot 699 def RenameSnapshotNum = coreParams.RenameSnapshotNum 700 def FtqSize = coreParams.FtqSize 701 def EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp 702 def IntLogicRegs = coreParams.IntLogicRegs 703 def FpLogicRegs = coreParams.FpLogicRegs 704 def VecLogicRegs = coreParams.VecLogicRegs 705 def V0LogicRegs = coreParams.V0LogicRegs 706 def VlLogicRegs = coreParams.VlLogicRegs 707 def MaxLogicRegs = Set(IntLogicRegs, FpLogicRegs, VecLogicRegs, V0LogicRegs, VlLogicRegs).max 708 def LogicRegsWidth = log2Ceil(MaxLogicRegs) 709 def V0_IDX = coreParams.V0_IDX 710 def Vl_IDX = coreParams.Vl_IDX 711 def IntPhyRegs = coreParams.intPreg.numEntries 712 def FpPhyRegs = coreParams.fpPreg.numEntries 713 def VfPhyRegs = coreParams.vfPreg.numEntries 714 def V0PhyRegs = coreParams.v0Preg.numEntries 715 def VlPhyRegs = coreParams.vlPreg.numEntries 716 def MaxPhyPregs = IntPhyRegs max VfPhyRegs 717 def PhyRegIdxWidth = log2Up(IntPhyRegs) max log2Up(FpPhyRegs) max log2Up(VfPhyRegs) 718 def RobSize = coreParams.RobSize 719 def RabSize = coreParams.RabSize 720 def VTypeBufferSize = coreParams.VTypeBufferSize 721 def IntRegCacheSize = coreParams.IntRegCacheSize 722 def MemRegCacheSize = coreParams.MemRegCacheSize 723 def RegCacheSize = coreParams.RegCacheSize 724 def RegCacheIdxWidth = coreParams.RegCacheIdxWidth 725 /** 726 * the minimum element length of vector elements 727 */ 728 def minVecElen: Int = coreParams.minVecElen 729 730 /** 731 * the maximum number of elements in vector register 732 */ 733 def maxElemPerVreg: Int = coreParams.maxElemPerVreg 734 735 def IntRefCounterWidth = log2Ceil(RobSize) 736 def LSQEnqWidth = coreParams.dpParams.LsDqDeqWidth 737 def LSQLdEnqWidth = LSQEnqWidth min backendParams.numLoadDp 738 def LSQStEnqWidth = LSQEnqWidth min backendParams.numStoreDp 739 def VirtualLoadQueueSize = coreParams.VirtualLoadQueueSize 740 def LoadQueueRARSize = coreParams.LoadQueueRARSize 741 def LoadQueueRAWSize = coreParams.LoadQueueRAWSize 742 def RollbackGroupSize = coreParams.RollbackGroupSize 743 def LoadQueueReplaySize = coreParams.LoadQueueReplaySize 744 def LoadUncacheBufferSize = coreParams.LoadUncacheBufferSize 745 def LoadQueueNWriteBanks = coreParams.LoadQueueNWriteBanks 746 def StoreQueueSize = coreParams.StoreQueueSize 747 def VirtualLoadQueueMaxStoreQueueSize = VirtualLoadQueueSize max StoreQueueSize 748 def StoreQueueNWriteBanks = coreParams.StoreQueueNWriteBanks 749 def StoreQueueForwardWithMask = coreParams.StoreQueueForwardWithMask 750 def VlsQueueSize = coreParams.VlsQueueSize 751 def dpParams = coreParams.dpParams 752 753 def MemIQSizeMax = backendParams.memSchdParams.get.issueBlockParams.map(_.numEntries).max 754 def IQSizeMax = backendParams.allSchdParams.map(_.issueBlockParams.map(_.numEntries).max).max 755 756 def NumRedirect = backendParams.numRedirect 757 def BackendRedirectNum = NumRedirect + 2 //2: ldReplay + Exception 758 def FtqRedirectAheadNum = NumRedirect 759 def IfuRedirectNum = coreParams.IfuRedirectNum 760 def LoadPipelineWidth = coreParams.LoadPipelineWidth 761 def StorePipelineWidth = coreParams.StorePipelineWidth 762 def VecLoadPipelineWidth = coreParams.VecLoadPipelineWidth 763 def VecStorePipelineWidth = coreParams.VecStorePipelineWidth 764 def VecMemSrcInWidth = coreParams.VecMemSrcInWidth 765 def VecMemInstWbWidth = coreParams.VecMemInstWbWidth 766 def VecMemDispatchWidth = coreParams.VecMemDispatchWidth 767 def VecMemDispatchMaxNumber = coreParams.VecMemDispatchMaxNumber 768 def VecMemUnitStrideMaxFlowNum = coreParams.VecMemUnitStrideMaxFlowNum 769 def VecMemLSQEnqIteratorNumberSeq = coreParams.VecMemLSQEnqIteratorNumberSeq 770 def StoreBufferSize = coreParams.StoreBufferSize 771 def StoreBufferThreshold = coreParams.StoreBufferThreshold 772 def EnsbufferWidth = coreParams.EnsbufferWidth 773 def LoadDependencyWidth = coreParams.LoadDependencyWidth 774 def VlMergeBufferSize = coreParams.VlMergeBufferSize 775 def VsMergeBufferSize = coreParams.VsMergeBufferSize 776 def UopWritebackWidth = coreParams.UopWritebackWidth 777 def VLUopWritebackWidth = coreParams.VLUopWritebackWidth 778 def VSUopWritebackWidth = coreParams.VSUopWritebackWidth 779 def VSegmentBufferSize = coreParams.VSegmentBufferSize 780 def UncacheBufferSize = coreParams.UncacheBufferSize 781 def EnableLoadToLoadForward = coreParams.EnableLoadToLoadForward 782 def EnableFastForward = coreParams.EnableFastForward 783 def EnableLdVioCheckAfterReset = coreParams.EnableLdVioCheckAfterReset 784 def EnableSoftPrefetchAfterReset = coreParams.EnableSoftPrefetchAfterReset 785 def EnableCacheErrorAfterReset = coreParams.EnableCacheErrorAfterReset 786 def EnableAccurateLoadError = coreParams.EnableAccurateLoadError 787 def EnableUncacheWriteOutstanding = coreParams.EnableUncacheWriteOutstanding 788 def EnableHardwareStoreMisalign = coreParams.EnableHardwareStoreMisalign 789 def EnableHardwareLoadMisalign = coreParams.EnableHardwareLoadMisalign 790 def EnableStorePrefetchAtIssue = coreParams.EnableStorePrefetchAtIssue 791 def EnableStorePrefetchAtCommit = coreParams.EnableStorePrefetchAtCommit 792 def EnableAtCommitMissTrigger = coreParams.EnableAtCommitMissTrigger 793 def EnableStorePrefetchSMS = coreParams.EnableStorePrefetchSMS 794 def EnableStorePrefetchSPB = coreParams.EnableStorePrefetchSPB 795 require(LoadPipelineWidth == backendParams.LdExuCnt, "LoadPipelineWidth must be equal exuParameters.LduCnt!") 796 require(StorePipelineWidth == backendParams.StaCnt, "StorePipelineWidth must be equal exuParameters.StuCnt!") 797 def Enable3Load3Store = (LoadPipelineWidth == 3 && StorePipelineWidth == 3) 798 def asidLen = coreParams.MMUAsidLen 799 def vmidLen = coreParams.MMUVmidLen 800 def BTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth 801 def refillBothTlb = coreParams.refillBothTlb 802 def iwpuParam = coreParams.iwpuParameters 803 def dwpuParam = coreParams.dwpuParameters 804 def itlbParams = coreParams.itlbParameters 805 def ldtlbParams = coreParams.ldtlbParameters 806 def sttlbParams = coreParams.sttlbParameters 807 def hytlbParams = coreParams.hytlbParameters 808 def pftlbParams = coreParams.pftlbParameters 809 def l2ToL1Params = coreParams.l2ToL1tlbParameters 810 def btlbParams = coreParams.btlbParameters 811 def l2tlbParams = coreParams.l2tlbParameters 812 def NumPerfCounters = coreParams.NumPerfCounters 813 814 def instBytes = if (HasCExtension) 2 else 4 815 def instOffsetBits = log2Ceil(instBytes) 816 817 def icacheParameters = coreParams.icacheParameters 818 def dcacheParameters = coreParams.dcacheParametersOpt.getOrElse(DCacheParameters()) 819 820 // dcache block cacheline when lr for LRSCCycles - LRSCBackOff cycles 821 // for constrained LR/SC loop 822 def LRSCCycles = 64 823 // for lr storm 824 def LRSCBackOff = 8 825 826 // cache hierarchy configurations 827 def l1BusDataWidth = 256 828 829 // load violation predict 830 def ResetTimeMax2Pow = 20 //1078576 831 def ResetTimeMin2Pow = 10 //1024 832 // wait table parameters 833 def WaitTableSize = 1024 834 def MemPredPCWidth = log2Up(WaitTableSize) 835 def LWTUse2BitCounter = true 836 // store set parameters 837 def SSITSize = WaitTableSize 838 def LFSTSize = 32 839 def SSIDWidth = log2Up(LFSTSize) 840 def LFSTWidth = 4 841 def StoreSetEnable = true // LWT will be disabled if SS is enabled 842 def LFSTEnable = true 843 844 def PCntIncrStep: Int = 6 845 def numPCntHc: Int = 25 846 def numPCntPtw: Int = 19 847 848 def numCSRPCntFrontend = 8 849 def numCSRPCntCtrl = 8 850 def numCSRPCntLsu = 8 851 def numCSRPCntHc = 5 852 def printEventCoding = true 853 854 // Parameters for Sdtrig extension 855 protected def TriggerNum = 4 856 protected def TriggerChainMaxLength = 2 857} 858