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 chipsalliance.rocketchip.config.{Field, Parameters} 20import chisel3._ 21import chisel3.util._ 22import xiangshan.backend.exu._ 23import xiangshan.backend.fu._ 24import xiangshan.backend.fu.fpu._ 25import xiangshan.backend.dispatch.DispatchParameters 26import xiangshan.cache.{DCacheParameters, ICacheParameters, L1plusCacheParameters} 27import xiangshan.cache.prefetch.{BOPParameters, L1plusPrefetcherParameters, L2PrefetcherParameters, StreamPrefetchParameters} 28 29case object XSCoreParamsKey extends Field[XSCoreParameters] 30 31case class XSCoreParameters 32( 33 HasPrefetch: Boolean = false, 34 HartId: Int = 0, 35 XLEN: Int = 64, 36 HasMExtension: Boolean = true, 37 HasCExtension: Boolean = true, 38 HasDiv: Boolean = true, 39 HasICache: Boolean = true, 40 HasDCache: Boolean = true, 41 AddrBits: Int = 64, 42 VAddrBits: Int = 39, 43 PAddrBits: Int = 40, 44 HasFPU: Boolean = true, 45 FetchWidth: Int = 8, 46 EnableBPU: Boolean = true, 47 EnableBPD: Boolean = true, 48 EnableRAS: Boolean = true, 49 EnableLB: Boolean = false, 50 EnableLoop: Boolean = true, 51 EnableSC: Boolean = true, 52 EnbaleTlbDebug: Boolean = false, 53 EnableJal: Boolean = false, 54 EnableUBTB: Boolean = true, 55 HistoryLength: Int = 64, 56 BtbSize: Int = 2048, 57 JbtacSize: Int = 1024, 58 JbtacBanks: Int = 8, 59 RasSize: Int = 16, 60 CacheLineSize: Int = 512, 61 UBtbWays: Int = 16, 62 BtbWays: Int = 2, 63 64 EnableL1plusPrefetcher: Boolean = true, 65 IBufSize: Int = 48, 66 DecodeWidth: Int = 6, 67 RenameWidth: Int = 6, 68 CommitWidth: Int = 6, 69 BrqSize: Int = 32, 70 FtqSize: Int = 48, 71 EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false 72 IssQueSize: Int = 16, 73 NRPhyRegs: Int = 160, 74 NRIntReadPorts: Int = 14, 75 NRIntWritePorts: Int = 8, 76 NRFpReadPorts: Int = 14, 77 NRFpWritePorts: Int = 8, 78 LoadQueueSize: Int = 64, 79 StoreQueueSize: Int = 48, 80 RoqSize: Int = 192, 81 dpParams: DispatchParameters = DispatchParameters( 82 IntDqSize = 16, 83 FpDqSize = 16, 84 LsDqSize = 16, 85 IntDqDeqWidth = 4, 86 FpDqDeqWidth = 4, 87 LsDqDeqWidth = 4 88 ), 89 exuParameters: ExuParameters = ExuParameters( 90 JmpCnt = 1, 91 AluCnt = 4, 92 MulCnt = 0, 93 MduCnt = 2, 94 FmacCnt = 4, 95 FmiscCnt = 2, 96 FmiscDivSqrtCnt = 0, 97 LduCnt = 2, 98 StuCnt = 2 99 ), 100 LoadPipelineWidth: Int = 2, 101 StorePipelineWidth: Int = 2, 102 StoreBufferSize: Int = 16, 103 StoreBufferThreshold: Int = 7, 104 EnableFastForward: Boolean = true, 105 RefillSize: Int = 512, 106 TlbEntrySize: Int = 32, 107 TlbSPEntrySize: Int = 4, 108 PtwL3EntrySize: Int = 4096, //(256 * 16) or 512 109 PtwSPEntrySize: Int = 16, 110 PtwL1EntrySize: Int = 16, 111 PtwL2EntrySize: Int = 2048, //(256 * 8) 112 PtwMissQueueSize: Int = 8, 113 NumPerfCounters: Int = 16, 114 icacheParameters: ICacheParameters = ICacheParameters( 115 tagECC = Some("parity"), 116 dataECC = Some("parity"), 117 replacer = Some("setplru"), 118 nMissEntries = 2 119 ), 120 l1plusCacheParameters: L1plusCacheParameters = L1plusCacheParameters( 121 tagECC = Some("secded"), 122 dataECC = Some("secded"), 123 replacer = Some("setplru"), 124 nMissEntries = 8 125 ), 126 dcacheParameters: DCacheParameters = DCacheParameters( 127 tagECC = Some("secded"), 128 dataECC = Some("secded"), 129 replacer = Some("setplru"), 130 nMissEntries = 16, 131 nProbeEntries = 16, 132 nReleaseEntries = 16, 133 nStoreReplayEntries = 16 134 ), 135 L2Size: Int = 512 * 1024, // 512KB 136 L2NWays: Int = 8, 137 usePTWRepeater: Boolean = false, 138 useFakePTW: Boolean = false, 139 useFakeDCache: Boolean = false, 140 useFakeL1plusCache: Boolean = false, 141 useFakeL2Cache: Boolean = false 142){ 143 val loadExuConfigs = Seq.fill(exuParameters.LduCnt)(LdExeUnitCfg) 144 val storeExuConfigs = Seq.fill(exuParameters.StuCnt)(StExeUnitCfg) 145 146 val intExuConfigs = Seq.fill(exuParameters.AluCnt)(AluExeUnitCfg) ++ 147 Seq.fill(exuParameters.MduCnt)(MulDivExeUnitCfg) :+ JumpCSRExeUnitCfg 148 149 val fpExuConfigs = 150 Seq.fill(exuParameters.FmacCnt)(FmacExeUnitCfg) ++ 151 Seq.fill(exuParameters.FmiscCnt)(FmiscExeUnitCfg) 152 153 val exuConfigs: Seq[ExuConfig] = intExuConfigs ++ fpExuConfigs ++ loadExuConfigs ++ storeExuConfigs 154} 155 156case object DebugOptionsKey extends Field[DebugOptions] 157 158case class DebugOptions 159( 160 FPGAPlatform: Boolean = true, 161 EnableDebug: Boolean = true, 162 EnablePerfDebug: Boolean = true, 163 UseDRAMSim: Boolean = false 164) 165 166trait HasXSParameter { 167 168 implicit val p: Parameters 169 170 val coreParams = p(XSCoreParamsKey) 171 val env = p(DebugOptionsKey) 172 173 val XLEN = coreParams.XLEN 174 val hardId = coreParams.HartId 175 val minFLen = 32 176 val fLen = 64 177 def xLen = XLEN 178 179 val HasMExtension = coreParams.HasMExtension 180 val HasCExtension = coreParams.HasCExtension 181 val HasDiv = coreParams.HasDiv 182 val HasIcache = coreParams.HasICache 183 val HasDcache = coreParams.HasDCache 184 val AddrBits = coreParams.AddrBits // AddrBits is used in some cases 185 val VAddrBits = coreParams.VAddrBits // VAddrBits is Virtual Memory addr bits 186 val PAddrBits = coreParams.PAddrBits // PAddrBits is Phyical Memory addr bits 187 val AddrBytes = AddrBits / 8 // unused 188 val DataBits = XLEN 189 val DataBytes = DataBits / 8 190 val HasFPU = coreParams.HasFPU 191 val FetchWidth = coreParams.FetchWidth 192 val PredictWidth = FetchWidth * (if (HasCExtension) 2 else 1) 193 val EnableBPU = coreParams.EnableBPU 194 val EnableBPD = coreParams.EnableBPD // enable backing predictor(like Tage) in BPUStage3 195 val EnableRAS = coreParams.EnableRAS 196 val EnableLB = coreParams.EnableLB 197 val EnableLoop = coreParams.EnableLoop 198 val EnableSC = coreParams.EnableSC 199 val EnbaleTlbDebug = coreParams.EnbaleTlbDebug 200 val HistoryLength = coreParams.HistoryLength 201 val BtbSize = coreParams.BtbSize 202 // val BtbWays = 4 203 val BtbBanks = PredictWidth 204 // val BtbSets = BtbSize / BtbWays 205 val JbtacSize = coreParams.JbtacSize 206 val JbtacBanks = coreParams.JbtacBanks 207 val RasSize = coreParams.RasSize 208 val CacheLineSize = coreParams.CacheLineSize 209 val CacheLineHalfWord = CacheLineSize / 16 210 val ExtHistoryLength = HistoryLength + 64 211 val UBtbWays = coreParams.UBtbWays 212 val BtbWays = coreParams.BtbWays 213 val EnableL1plusPrefetcher = coreParams.EnableL1plusPrefetcher 214 val IBufSize = coreParams.IBufSize 215 val DecodeWidth = coreParams.DecodeWidth 216 val RenameWidth = coreParams.RenameWidth 217 val CommitWidth = coreParams.CommitWidth 218 val BrqSize = coreParams.BrqSize 219 val FtqSize = coreParams.FtqSize 220 val IssQueSize = coreParams.IssQueSize 221 val EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp 222 val BrTagWidth = log2Up(BrqSize) 223 val NRPhyRegs = coreParams.NRPhyRegs 224 val PhyRegIdxWidth = log2Up(NRPhyRegs) 225 val RoqSize = coreParams.RoqSize 226 val LoadQueueSize = coreParams.LoadQueueSize 227 val StoreQueueSize = coreParams.StoreQueueSize 228 val dpParams = coreParams.dpParams 229 val exuParameters = coreParams.exuParameters 230 val NRMemReadPorts = exuParameters.LduCnt + 2 * exuParameters.StuCnt 231 val NRIntReadPorts = 2 * exuParameters.AluCnt + NRMemReadPorts 232 val NRIntWritePorts = exuParameters.AluCnt + exuParameters.MduCnt + exuParameters.LduCnt 233 val NRFpReadPorts = 3 * exuParameters.FmacCnt + exuParameters.StuCnt 234 val NRFpWritePorts = exuParameters.FpExuCnt + exuParameters.LduCnt 235 val LoadPipelineWidth = coreParams.LoadPipelineWidth 236 val StorePipelineWidth = coreParams.StorePipelineWidth 237 val StoreBufferSize = coreParams.StoreBufferSize 238 val StoreBufferThreshold = coreParams.StoreBufferThreshold 239 val EnableFastForward = coreParams.EnableFastForward 240 val RefillSize = coreParams.RefillSize 241 val DTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth 242 val TlbEntrySize = coreParams.TlbEntrySize 243 val TlbSPEntrySize = coreParams.TlbSPEntrySize 244 val PtwL3EntrySize = coreParams.PtwL3EntrySize 245 val PtwSPEntrySize = coreParams.PtwSPEntrySize 246 val PtwL1EntrySize = coreParams.PtwL1EntrySize 247 val PtwL2EntrySize = coreParams.PtwL2EntrySize 248 val PtwMissQueueSize = coreParams.PtwMissQueueSize 249 val NumPerfCounters = coreParams.NumPerfCounters 250 251 val instBytes = if (HasCExtension) 2 else 4 252 val instOffsetBits = log2Ceil(instBytes) 253 254 val icacheParameters = coreParams.icacheParameters 255 val l1plusCacheParameters = coreParams.l1plusCacheParameters 256 val dcacheParameters = coreParams.dcacheParameters 257 258 val LRSCCycles = 100 259 260 261 // cache hierarchy configurations 262 val l1BusDataWidth = 256 263 264 val usePTWRepeater = coreParams.usePTWRepeater 265 val useFakeDCache = coreParams.useFakeDCache 266 val useFakePTW = coreParams.useFakePTW 267 val useFakeL1plusCache = coreParams.useFakeL1plusCache 268 // L2 configurations 269 val useFakeL2Cache = useFakeDCache && useFakePTW && useFakeL1plusCache || coreParams.useFakeL2Cache 270 val L1BusWidth = 256 271 val L2Size = coreParams.L2Size 272 val L2BlockSize = 64 273 val L2NWays = coreParams.L2NWays 274 val L2NSets = L2Size / L2BlockSize / L2NWays 275 276 // L3 configurations 277 val L2BusWidth = 256 278 279 // icache prefetcher 280 val l1plusPrefetcherParameters = L1plusPrefetcherParameters( 281 enable = true, 282 _type = "stream", 283 streamParams = StreamPrefetchParameters( 284 streamCnt = 2, 285 streamSize = 4, 286 ageWidth = 4, 287 blockBytes = l1plusCacheParameters.blockBytes, 288 reallocStreamOnMissInstantly = true, 289 cacheName = "icache" 290 ) 291 ) 292 293 // dcache prefetcher 294 val l2PrefetcherParameters = L2PrefetcherParameters( 295 enable = true, 296 _type = "bop", // "stream" or "bop" 297 streamParams = StreamPrefetchParameters( 298 streamCnt = 4, 299 streamSize = 4, 300 ageWidth = 4, 301 blockBytes = L2BlockSize, 302 reallocStreamOnMissInstantly = true, 303 cacheName = "dcache" 304 ), 305 bopParams = BOPParameters( 306 rrTableEntries = 256, 307 rrTagBits = 12, 308 scoreBits = 5, 309 roundMax = 50, 310 badScore = 1, 311 blockBytes = L2BlockSize, 312 nEntries = dcacheParameters.nMissEntries * 2 // TODO: this is too large 313 ), 314 ) 315 316 // load violation predict 317 val ResetTimeMax2Pow = 20 //1078576 318 val ResetTimeMin2Pow = 10 //1024 319 // wait table parameters 320 val WaitTableSize = 1024 321 val MemPredPCWidth = log2Up(WaitTableSize) 322 val LWTUse2BitCounter = true 323 // store set parameters 324 val SSITSize = WaitTableSize 325 val LFSTSize = 32 326 val SSIDWidth = log2Up(LFSTSize) 327 val LFSTWidth = 4 328 val StoreSetEnable = true // LWT will be disabled if SS is enabled 329 330 val loadExuConfigs = coreParams.loadExuConfigs 331 val storeExuConfigs = coreParams.storeExuConfigs 332 333 val intExuConfigs = coreParams.intExuConfigs 334 335 val fpExuConfigs = coreParams.fpExuConfigs 336 337 val exuConfigs = coreParams.exuConfigs 338 339} 340