Parameters.scala 13.0 KB
Newer Older
L
Lemover 已提交
1 2
/***************************************************************************************
* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
Y
Yinan Xu 已提交
3
* Copyright (c) 2020-2021 Peng Cheng Laboratory
L
Lemover 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16
*
* XiangShan is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*          http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

17 18 19 20 21 22 23
package xiangshan

import chipsalliance.rocketchip.config.{Field, Parameters}
import chisel3._
import chisel3.util._
import xiangshan.backend.exu._
import xiangshan.backend.dispatch.DispatchParameters
24
import xiangshan.cache.DCacheParameters
25 26
import xiangshan.cache.prefetch._
import huancun.{CacheParameters, HCCacheParameters}
27
import xiangshan.frontend.{BIM, BasePredictor, BranchPredictionResp, FTB, FakePredictor, ICacheParameters, MicroBTB, RAS, Tage, ITTage, Tage_SC}
28
import xiangshan.cache.mmu.{TLBParameters, L2TLBParameters}
29
import freechips.rocketchip.diplomacy.AddressSet
30
import system.SoCParamsKey
J
Jiawei Lin 已提交
31 32 33

case object XSTileKey extends Field[Seq[XSCoreParameters]]

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
case object XSCoreParamsKey extends Field[XSCoreParameters]

case class XSCoreParameters
(
  HasPrefetch: Boolean = false,
  HartId: Int = 0,
  XLEN: Int = 64,
  HasMExtension: Boolean = true,
  HasCExtension: Boolean = true,
  HasDiv: Boolean = true,
  HasICache: Boolean = true,
  HasDCache: Boolean = true,
  AddrBits: Int = 64,
  VAddrBits: Int = 39,
  HasFPU: Boolean = true,
Z
zhanglinjuan 已提交
49
  HasCustomCSRCacheOp: Boolean = true,
50
  FetchWidth: Int = 8,
51
  AsidLength: Int = 16,
52 53 54 55 56
  EnableBPU: Boolean = true,
  EnableBPD: Boolean = true,
  EnableRAS: Boolean = true,
  EnableLB: Boolean = false,
  EnableLoop: Boolean = true,
57
  EnableSC: Boolean = true,
58 59 60 61
  EnbaleTlbDebug: Boolean = false,
  EnableJal: Boolean = false,
  EnableUBTB: Boolean = true,
  HistoryLength: Int = 64,
62
  PathHistoryLength: Int = 16,
63 64 65
  BtbSize: Int = 2048,
  JbtacSize: Int = 1024,
  JbtacBanks: Int = 8,
66
  RasSize: Int = 32,
67 68 69
  CacheLineSize: Int = 512,
  UBtbWays: Int = 16,
  BtbWays: Int = 2,
70 71
  branchPredictor: Function2[BranchPredictionResp, Parameters, Tuple2[Seq[BasePredictor], BranchPredictionResp]] =
    ((resp_in: BranchPredictionResp, p: Parameters) => {
Z
zoujr 已提交
72 73 74 75 76 77 78
      // val loop = Module(new LoopPredictor)
      // val tage = (if(EnableBPD) { if (EnableSC) Module(new Tage_SC)
      //                             else          Module(new Tage) }
      //             else          { Module(new FakeTage) })
      val ftb = Module(new FTB()(p))
      val ubtb = Module(new MicroBTB()(p))
      val bim = Module(new BIM()(p))
79
      val tage = Module(new Tage_SC()(p))
L
Lingrui98 已提交
80
      val ras = Module(new RAS()(p))
81
      val ittage = Module(new ITTage()(p))
L
Lingrui98 已提交
82
      // val tage = Module(new Tage()(p))
Z
zoujr 已提交
83
      // val fake = Module(new FakePredictor()(p))
Z
zoujr 已提交
84 85

      // val preds = Seq(loop, tage, btb, ubtb, bim)
86
      val preds = Seq(bim, ubtb, tage, ftb, ittage, ras)
Z
zoujr 已提交
87 88 89 90 91 92 93
      preds.map(_.io := DontCare)

      // ubtb.io.resp_in(0)  := resp_in
      // bim.io.resp_in(0)   := ubtb.io.resp
      // btb.io.resp_in(0)   := bim.io.resp
      // tage.io.resp_in(0)  := btb.io.resp
      // loop.io.resp_in(0)  := tage.io.resp
L
Lingrui98 已提交
94
      bim.io.in.bits.resp_in(0)  := resp_in
95 96 97
      ubtb.io.in.bits.resp_in(0) := bim.io.out.resp
      tage.io.in.bits.resp_in(0) := ubtb.io.out.resp
      ftb.io.in.bits.resp_in(0)  := tage.io.out.resp
98 99
      ittage.io.in.bits.resp_in(0)  := ftb.io.out.resp
      ras.io.in.bits.resp_in(0) := ittage.io.out.resp
Y
Yinan Xu 已提交
100

L
Lingrui98 已提交
101
      (preds, ras.io.out.resp)
Z
zoujr 已提交
102
    }),
103 104 105 106
  IBufSize: Int = 48,
  DecodeWidth: Int = 6,
  RenameWidth: Int = 6,
  CommitWidth: Int = 6,
L
Lingrui98 已提交
107
  FtqSize: Int = 64,
108 109
  EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false
  IssQueSize: Int = 16,
110
  NRPhyRegs: Int = 192,
111 112 113 114
  NRIntReadPorts: Int = 14,
  NRIntWritePorts: Int = 8,
  NRFpReadPorts: Int = 14,
  NRFpWritePorts: Int = 8,
115 116
  LoadQueueSize: Int = 80,
  StoreQueueSize: Int = 64,
117
  RobSize: Int = 256,
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
  dpParams: DispatchParameters = DispatchParameters(
    IntDqSize = 16,
    FpDqSize = 16,
    LsDqSize = 16,
    IntDqDeqWidth = 4,
    FpDqDeqWidth = 4,
    LsDqDeqWidth = 4
  ),
  exuParameters: ExuParameters = ExuParameters(
    JmpCnt = 1,
    AluCnt = 4,
    MulCnt = 0,
    MduCnt = 2,
    FmacCnt = 4,
    FmiscCnt = 2,
    FmiscDivSqrtCnt = 0,
    LduCnt = 2,
    StuCnt = 2
  ),
  LoadPipelineWidth: Int = 2,
  StorePipelineWidth: Int = 2,
  StoreBufferSize: Int = 16,
140
  StoreBufferThreshold: Int = 7,
141
  EnableFastForward: Boolean = true,
142
  EnableLdVioCheckAfterReset: Boolean = true,
143
  RefillSize: Int = 512,
144
  MMUAsidLen: Int = 16, // max is 16, 0 is not supported now
145 146 147 148 149
  itlbParameters: TLBParameters = TLBParameters(
    name = "itlb",
    fetchi = true,
    useDmode = false,
    sameCycle = true,
150
    normalNWays = 32,
151
    normalReplacer = Some("plru"),
152
    superNWays = 4,
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    superReplacer = Some("plru"),
    shouldBlock = true
  ),
  ldtlbParameters: TLBParameters = TLBParameters(
    name = "ldtlb",
    normalNSets = 128,
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
    superNWays = 8,
    normalAsVictim = true,
    outReplace = true
  ),
  sttlbParameters: TLBParameters = TLBParameters(
    name = "sttlb",
    normalNSets = 128,
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
    superNWays = 8,
    normalAsVictim = true,
    outReplace = true
  ),
176
  refillBothTlb: Boolean = false,
177 178 179 180 181 182
  btlbParameters: TLBParameters = TLBParameters(
    name = "btlb",
    normalNSets = 1,
    normalNWays = 64,
    superNWays = 4,
  ),
183
  l2tlbParameters: L2TLBParameters = L2TLBParameters(),
L
Lemover 已提交
184
  NumPMP: Int = 16, // 0 or 16 or 64
185
  NumPMA: Int = 16,
186
  NumPerfCounters: Int = 16,
187 188 189 190 191 192
  icacheParameters: ICacheParameters = ICacheParameters(
    tagECC = Some("parity"),
    dataECC = Some("parity"),
    replacer = Some("setplru"),
    nMissEntries = 2
  ),
J
Jiawei Lin 已提交
193
  dcacheParametersOpt: Option[DCacheParameters] = Some(DCacheParameters(
194 195 196 197
    tagECC = Some("secded"),
    dataECC = Some("secded"),
    replacer = Some("setplru"),
    nMissEntries = 16,
W
William Wang 已提交
198 199
    nProbeEntries = 8,
    nReleaseEntries = 18
J
Jiawei Lin 已提交
200 201
  )),
  L2CacheParamsOpt: Option[HCCacheParameters] = Some(HCCacheParameters(
202 203 204 205 206
    name = "l2",
    level = 2,
    ways = 8,
    sets = 1024, // default 512KB L2
    prefetch = Some(huancun.prefetch.BOPParameters())
J
Jiawei Lin 已提交
207
  )),
J
Jiawei Lin 已提交
208
  L2NBanks: Int = 1,
209
  usePTWRepeater: Boolean = false,
J
Jiawei Lin 已提交
210
  softPTW: Boolean = false // dpi-c debug only
211 212
){
  val loadExuConfigs = Seq.fill(exuParameters.LduCnt)(LdExeUnitCfg)
213
  val storeExuConfigs = Seq.fill(exuParameters.StuCnt)(StaExeUnitCfg) ++ Seq.fill(exuParameters.StuCnt)(StdExeUnitCfg)
214

215
  val intExuConfigs = (Seq.fill(exuParameters.AluCnt)(AluExeUnitCfg) ++
216
    Seq.fill(exuParameters.MduCnt)(MulDivExeUnitCfg) :+ JumpCSRExeUnitCfg)
217 218 219 220 221 222 223 224 225 226 227 228 229

  val fpExuConfigs =
    Seq.fill(exuParameters.FmacCnt)(FmacExeUnitCfg) ++
      Seq.fill(exuParameters.FmiscCnt)(FmiscExeUnitCfg)

  val exuConfigs: Seq[ExuConfig] = intExuConfigs ++ fpExuConfigs ++ loadExuConfigs ++ storeExuConfigs
}

case object DebugOptionsKey extends Field[DebugOptions]

case class DebugOptions
(
  FPGAPlatform: Boolean = true,
230
  EnableDebug: Boolean = true,
231 232 233 234 235 236 237 238
  EnablePerfDebug: Boolean = true,
  UseDRAMSim: Boolean = false
)

trait HasXSParameter {

  implicit val p: Parameters

239 240
  val PAddrBits = p(SoCParamsKey).PAddrBits // PAddrBits is Phyical Memory addr bits

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
  val coreParams = p(XSCoreParamsKey)
  val env = p(DebugOptionsKey)

  val XLEN = coreParams.XLEN
  val hardId = coreParams.HartId
  val minFLen = 32
  val fLen = 64
  def xLen = XLEN

  val HasMExtension = coreParams.HasMExtension
  val HasCExtension = coreParams.HasCExtension
  val HasDiv = coreParams.HasDiv
  val HasIcache = coreParams.HasICache
  val HasDcache = coreParams.HasDCache
  val AddrBits = coreParams.AddrBits // AddrBits is used in some cases
  val VAddrBits = coreParams.VAddrBits // VAddrBits is Virtual Memory addr bits
257
  val AsidLength = coreParams.AsidLength
258 259 260 261
  val AddrBytes = AddrBits / 8 // unused
  val DataBits = XLEN
  val DataBytes = DataBits / 8
  val HasFPU = coreParams.HasFPU
Z
zhanglinjuan 已提交
262
  val HasCustomCSRCacheOp = coreParams.HasCustomCSRCacheOp
263 264 265 266 267 268 269 270 271 272
  val FetchWidth = coreParams.FetchWidth
  val PredictWidth = FetchWidth * (if (HasCExtension) 2 else 1)
  val EnableBPU = coreParams.EnableBPU
  val EnableBPD = coreParams.EnableBPD // enable backing predictor(like Tage) in BPUStage3
  val EnableRAS = coreParams.EnableRAS
  val EnableLB = coreParams.EnableLB
  val EnableLoop = coreParams.EnableLoop
  val EnableSC = coreParams.EnableSC
  val EnbaleTlbDebug = coreParams.EnbaleTlbDebug
  val HistoryLength = coreParams.HistoryLength
273
  val PathHistoryLength = coreParams.PathHistoryLength
274 275 276 277 278 279 280
  val BtbSize = coreParams.BtbSize
  // val BtbWays = 4
  val BtbBanks = PredictWidth
  // val BtbSets = BtbSize / BtbWays
  val JbtacSize = coreParams.JbtacSize
  val JbtacBanks = coreParams.JbtacBanks
  val RasSize = coreParams.RasSize
Z
zoujr 已提交
281

282 283
  def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = {
    coreParams.branchPredictor(resp_in, p)
Z
zoujr 已提交
284 285
  }

286 287 288 289 290 291 292 293 294 295 296 297 298 299
  val CacheLineSize = coreParams.CacheLineSize
  val CacheLineHalfWord = CacheLineSize / 16
  val ExtHistoryLength = HistoryLength + 64
  val UBtbWays = coreParams.UBtbWays
  val BtbWays = coreParams.BtbWays
  val IBufSize = coreParams.IBufSize
  val DecodeWidth = coreParams.DecodeWidth
  val RenameWidth = coreParams.RenameWidth
  val CommitWidth = coreParams.CommitWidth
  val FtqSize = coreParams.FtqSize
  val IssQueSize = coreParams.IssQueSize
  val EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp
  val NRPhyRegs = coreParams.NRPhyRegs
  val PhyRegIdxWidth = log2Up(NRPhyRegs)
Y
Yinan Xu 已提交
300
  val RobSize = coreParams.RobSize
301
  val IntRefCounterWidth = log2Ceil(RobSize)
302
  val StdFreeListSize = NRPhyRegs - 32
303
  val MEFreeListSize = NRPhyRegs
304 305 306 307 308
  val LoadQueueSize = coreParams.LoadQueueSize
  val StoreQueueSize = coreParams.StoreQueueSize
  val dpParams = coreParams.dpParams
  val exuParameters = coreParams.exuParameters
  val NRMemReadPorts = exuParameters.LduCnt + 2 * exuParameters.StuCnt
309 310 311 312
  val NRIntReadPorts = 2 * exuParameters.AluCnt + NRMemReadPorts
  val NRIntWritePorts = exuParameters.AluCnt + exuParameters.MduCnt + exuParameters.LduCnt
  val NRFpReadPorts = 3 * exuParameters.FmacCnt + exuParameters.StuCnt
  val NRFpWritePorts = exuParameters.FpExuCnt + exuParameters.LduCnt
313 314 315
  val LoadPipelineWidth = coreParams.LoadPipelineWidth
  val StorePipelineWidth = coreParams.StorePipelineWidth
  val StoreBufferSize = coreParams.StoreBufferSize
316
  val StoreBufferThreshold = coreParams.StoreBufferThreshold
317
  val EnableFastForward = coreParams.EnableFastForward
W
William Wang 已提交
318
  val EnableLdVioCheckAfterReset = coreParams.EnableLdVioCheckAfterReset
319
  val RefillSize = coreParams.RefillSize
320
  val asidLen = coreParams.MMUAsidLen
321
  val BTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth
322
  val refillBothTlb = coreParams.refillBothTlb
323 324 325 326
  val itlbParams = coreParams.itlbParameters
  val ldtlbParams = coreParams.ldtlbParameters
  val sttlbParams = coreParams.sttlbParameters
  val btlbParams = coreParams.btlbParameters
327
  val l2tlbParams = coreParams.l2tlbParameters
L
Lemover 已提交
328
  val NumPMP = coreParams.NumPMP
329
  val NumPMA = coreParams.NumPMA
L
Lemover 已提交
330
  val PlatformGrain: Int = log2Up(coreParams.RefillSize/8) // set PlatformGrain to avoid itlb, dtlb, ptw size conflict
331 332
  val NumPerfCounters = coreParams.NumPerfCounters

333 334 335 336 337
  val NumRs = (exuParameters.JmpCnt+1)/2 + (exuParameters.AluCnt+1)/2 + (exuParameters.MulCnt+1)/2 + 
              (exuParameters.MduCnt+1)/2 + (exuParameters.FmacCnt+1)/2 +  + (exuParameters.FmiscCnt+1)/2 + 
              (exuParameters.FmiscDivSqrtCnt+1)/2 + (exuParameters.LduCnt+1)/2 +
              ((exuParameters.StuCnt+1)/2) + ((exuParameters.StuCnt+1)/2) 

338 339 340
  val instBytes = if (HasCExtension) 2 else 4
  val instOffsetBits = log2Ceil(instBytes)

341
  val icacheParameters = coreParams.icacheParameters
J
Jiawei Lin 已提交
342
  val dcacheParameters = coreParams.dcacheParametersOpt.getOrElse(DCacheParameters())
343 344 345 346 347 348

  val LRSCCycles = 100

  // cache hierarchy configurations
  val l1BusDataWidth = 256

349 350 351 352 353 354 355 356 357 358 359 360 361
  // load violation predict
  val ResetTimeMax2Pow = 20 //1078576
  val ResetTimeMin2Pow = 10 //1024
  // wait table parameters
  val WaitTableSize = 1024
  val MemPredPCWidth = log2Up(WaitTableSize)
  val LWTUse2BitCounter = true
  // store set parameters
  val SSITSize = WaitTableSize
  val LFSTSize = 32
  val SSIDWidth = log2Up(LFSTSize)
  val LFSTWidth = 4
  val StoreSetEnable = true // LWT will be disabled if SS is enabled
362

363 364 365 366
  val loadExuConfigs = coreParams.loadExuConfigs
  val storeExuConfigs = coreParams.storeExuConfigs

  val intExuConfigs = coreParams.intExuConfigs
367

368
  val fpExuConfigs = coreParams.fpExuConfigs
369

370
  val exuConfigs = coreParams.exuConfigs
371

372 373 374 375 376 377 378 379 380
  val PCntIncrStep: Int = 6
  val numPCntHc: Int = 25
  val numPCntPtw: Int = 19

  val numCSRPCntFrontend = 8
  val numCSRPCntCtrl     = 8
  val numCSRPCntLsu      = 8
  val numCSRPCntHc       = 5
  val print_perfcounter  = false
381
}