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 top 18 19import chisel3._ 20import chisel3.util._ 21import xiangshan._ 22import utils._ 23import utility._ 24import system._ 25import org.chipsalliance.cde.config._ 26import freechips.rocketchip.tile.{BusErrorUnit, BusErrorUnitParams, XLen} 27import xiangshan.frontend.icache.ICacheParameters 28import freechips.rocketchip.devices.debug._ 29import freechips.rocketchip.tile.MaxHartIdBits 30import xiangshan.backend.dispatch.DispatchParameters 31import xiangshan.backend.exu.ExuParameters 32import xiangshan.cache.DCacheParameters 33import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters} 34import device.{EnableJtag, XSDebugModuleParams} 35import huancun._ 36import coupledL2._ 37 38class BaseConfig(n: Int) extends Config((site, here, up) => { 39 case XLen => 64 40 case DebugOptionsKey => DebugOptions() 41 case SoCParamsKey => SoCParameters() 42 case PMParameKey => PMParameters() 43 case XSTileKey => Seq.tabulate(n){ i => XSCoreParameters(HartId = i) } 44 case ExportDebug => DebugAttachParams(protocols = Set(JTAG)) 45 case DebugModuleKey => Some(XSDebugModuleParams(site(XLen))) 46 case JtagDTMKey => JtagDTMKey 47 case MaxHartIdBits => 2 48 case EnableJtag => true.B 49}) 50 51// Synthesizable minimal XiangShan 52// * It is still an out-of-order, super-scalaer arch 53// * L1 cache included 54// * L2 cache NOT included 55// * L3 cache included 56class MinimalConfig(n: Int = 1) extends Config( 57 new BaseConfig(n).alter((site, here, up) => { 58 case XSTileKey => up(XSTileKey).map( 59 _.copy( 60 DecodeWidth = 2, 61 RenameWidth = 2, 62 CommitWidth = 2, 63 FetchWidth = 4, 64 IssQueSize = 8, 65 NRPhyRegs = 64, 66 VirtualLoadQueueSize = 16, 67 LoadQueueRARSize = 16, 68 LoadQueueRAWSize = 12, 69 LoadQueueReplaySize = 8, 70 LoadUncacheBufferSize = 8, 71 LoadQueueNWriteBanks = 4, // NOTE: make sure that LoadQueue{RAR, RAW, Replay}Size is divided by LoadQueueNWriteBanks. 72 RollbackGroupSize = 8, 73 StoreQueueSize = 12, 74 StoreQueueNWriteBanks = 4, // NOTE: make sure that StoreQueueSize is divided by StoreQueueNWriteBanks 75 StoreQueueForwardWithMask = true, 76 RobSize = 32, 77 FtqSize = 8, 78 IBufSize = 16, 79 IBufNBank = 2, 80 StoreBufferSize = 4, 81 StoreBufferThreshold = 3, 82 dpParams = DispatchParameters( 83 IntDqSize = 12, 84 FpDqSize = 12, 85 LsDqSize = 12, 86 IntDqDeqWidth = 4, 87 FpDqDeqWidth = 4, 88 LsDqDeqWidth = 4 89 ), 90 exuParameters = ExuParameters( 91 JmpCnt = 1, 92 AluCnt = 2, 93 MulCnt = 0, 94 MduCnt = 1, 95 FmacCnt = 1, 96 FmiscCnt = 1, 97 FmiscDivSqrtCnt = 0, 98 LduCnt = 2, 99 StuCnt = 2 100 ), 101 icacheParameters = ICacheParameters( 102 nSets = 64, // 16KB ICache 103 tagECC = Some("parity"), 104 dataECC = Some("parity"), 105 replacer = Some("setplru"), 106 nMissEntries = 2, 107 nReleaseEntries = 1, 108 nProbeEntries = 2, 109 // fdip 110 enableICachePrefetch = true, 111 prefetchToL1 = false, 112 ), 113 dcacheParametersOpt = Some(DCacheParameters( 114 nSets = 64, // 32KB DCache 115 nWays = 8, 116 tagECC = Some("secded"), 117 dataECC = Some("secded"), 118 replacer = Some("setplru"), 119 nMissEntries = 4, 120 nProbeEntries = 4, 121 nReleaseEntries = 8, 122 nMaxPrefetchEntry = 2, 123 )), 124 EnableBPD = false, // disable TAGE 125 EnableLoop = false, 126 itlbParameters = TLBParameters( 127 name = "itlb", 128 fetchi = true, 129 useDmode = false, 130 NWays = 4, 131 ), 132 ldtlbParameters = TLBParameters( 133 name = "ldtlb", 134 NWays = 4, 135 partialStaticPMP = true, 136 outsideRecvFlush = true, 137 outReplace = false 138 ), 139 sttlbParameters = TLBParameters( 140 name = "sttlb", 141 NWays = 4, 142 partialStaticPMP = true, 143 outsideRecvFlush = true, 144 outReplace = false 145 ), 146 pftlbParameters = TLBParameters( 147 name = "pftlb", 148 NWays = 4, 149 partialStaticPMP = true, 150 outsideRecvFlush = true, 151 outReplace = false 152 ), 153 btlbParameters = TLBParameters( 154 name = "btlb", 155 NWays = 4, 156 ), 157 l2tlbParameters = L2TLBParameters( 158 l1Size = 4, 159 l2nSets = 4, 160 l2nWays = 4, 161 l3nSets = 4, 162 l3nWays = 8, 163 spSize = 2, 164 ), 165 L2CacheParamsOpt = Some(L2Param( 166 name = "L2", 167 ways = 8, 168 sets = 128, 169 echoField = Seq(huancun.DirtyField()), 170 prefetch = None 171 )), 172 L2NBanks = 2, 173 prefetcher = None // if L2 pf_recv_node does not exist, disable SMS prefetcher 174 ) 175 ) 176 case SoCParamsKey => 177 val tiles = site(XSTileKey) 178 up(SoCParamsKey).copy( 179 L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy( 180 sets = 1024, 181 inclusive = false, 182 clientCaches = tiles.map{ core => 183 val clientDirBytes = tiles.map{ t => 184 t.L2NBanks * t.L2CacheParamsOpt.map(_.toCacheParams.capacity).getOrElse(0) 185 }.sum 186 val l2params = core.L2CacheParamsOpt.get.toCacheParams 187 l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64) 188 }, 189 simulation = !site(DebugOptionsKey).FPGAPlatform, 190 prefetch = None 191 )), 192 L3NBanks = 1 193 ) 194 }) 195) 196 197// Non-synthesizable MinimalConfig, for fast simulation only 198class MinimalSimConfig(n: Int = 1) extends Config( 199 new MinimalConfig(n).alter((site, here, up) => { 200 case XSTileKey => up(XSTileKey).map(_.copy( 201 dcacheParametersOpt = None, 202 softPTW = true 203 )) 204 case SoCParamsKey => up(SoCParamsKey).copy( 205 L3CacheParamsOpt = None 206 ) 207 }) 208) 209 210class WithNKBL1D(n: Int, ways: Int = 8) extends Config((site, here, up) => { 211 case XSTileKey => 212 val sets = n * 1024 / ways / 64 213 up(XSTileKey).map(_.copy( 214 dcacheParametersOpt = Some(DCacheParameters( 215 nSets = sets, 216 nWays = ways, 217 tagECC = Some("secded"), 218 dataECC = Some("secded"), 219 replacer = Some("setplru"), 220 nMissEntries = 16, 221 nProbeEntries = 8, 222 nReleaseEntries = 18, 223 nMaxPrefetchEntry = 6, 224 )) 225 )) 226}) 227 228class WithNKBL2 229( 230 n: Int, 231 ways: Int = 8, 232 inclusive: Boolean = true, 233 banks: Int = 1 234) extends Config((site, here, up) => { 235 case XSTileKey => 236 require(inclusive, "L2 must be inclusive") 237 val upParams = up(XSTileKey) 238 val l2sets = n * 1024 / banks / ways / 64 239 upParams.map(p => p.copy( 240 L2CacheParamsOpt = Some(L2Param( 241 name = "L2", 242 ways = ways, 243 sets = l2sets, 244 clientCaches = Seq(L1Param( 245 "dcache", 246 sets = 2 * p.dcacheParametersOpt.get.nSets / banks, 247 ways = p.dcacheParametersOpt.get.nWays + 2, 248 aliasBitsOpt = p.dcacheParametersOpt.get.aliasBitsOpt, 249 vaddrBitsOpt = Some(p.VAddrBits - log2Up(p.dcacheParametersOpt.get.blockBytes)) 250 )), 251 reqField = Seq(utility.ReqSourceField()), 252 echoField = Seq(huancun.DirtyField()), 253 prefetch = Some(coupledL2.prefetch.PrefetchReceiverParams()), 254 enablePerf = !site(DebugOptionsKey).FPGAPlatform, 255 elaboratedTopDown = !site(DebugOptionsKey).FPGAPlatform 256 )), 257 L2NBanks = banks 258 )) 259}) 260 261class WithNKBL3(n: Int, ways: Int = 8, inclusive: Boolean = true, banks: Int = 1) extends Config((site, here, up) => { 262 case SoCParamsKey => 263 val sets = n * 1024 / banks / ways / 64 264 val tiles = site(XSTileKey) 265 val clientDirBytes = tiles.map{ t => 266 t.L2NBanks * t.L2CacheParamsOpt.map(_.toCacheParams.capacity).getOrElse(0) 267 }.sum 268 up(SoCParamsKey).copy( 269 L3NBanks = banks, 270 L3CacheParamsOpt = Some(HCCacheParameters( 271 name = "L3", 272 level = 3, 273 ways = ways, 274 sets = sets, 275 inclusive = inclusive, 276 clientCaches = tiles.map{ core => 277 val l2params = core.L2CacheParamsOpt.get.toCacheParams 278 l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64, ways = l2params.ways + 2) 279 }, 280 enablePerf = true, 281 ctrl = Some(CacheCtrl( 282 address = 0x39000000, 283 numCores = tiles.size 284 )), 285 reqField = Seq(utility.ReqSourceField()), 286 sramClkDivBy2 = true, 287 sramDepthDiv = 4, 288 tagECC = Some("secded"), 289 dataECC = Some("secded"), 290 simulation = !site(DebugOptionsKey).FPGAPlatform, 291 prefetch = Some(huancun.prefetch.L3PrefetchReceiverParams()), 292 tpmeta = Some(huancun.prefetch.DefaultTPmetaParameters()) 293 )) 294 ) 295}) 296 297class WithL3DebugConfig extends Config( 298 new WithNKBL3(256, inclusive = false) ++ new WithNKBL2(64) 299) 300 301class MinimalL3DebugConfig(n: Int = 1) extends Config( 302 new WithL3DebugConfig ++ new MinimalConfig(n) 303) 304 305class DefaultL3DebugConfig(n: Int = 1) extends Config( 306 new WithL3DebugConfig ++ new BaseConfig(n) 307) 308 309class WithFuzzer extends Config((site, here, up) => { 310 case DebugOptionsKey => up(DebugOptionsKey).copy( 311 EnablePerfDebug = false, 312 ) 313 case SoCParamsKey => up(SoCParamsKey).copy( 314 L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy( 315 enablePerf = false, 316 )), 317 ) 318 case XSTileKey => up(XSTileKey).zipWithIndex.map{ case (p, i) => 319 p.copy( 320 L2CacheParamsOpt = Some(up(XSTileKey)(i).L2CacheParamsOpt.get.copy( 321 enablePerf = false, 322 )), 323 ) 324 } 325}) 326 327class MinimalAliasDebugConfig(n: Int = 1) extends Config( 328 new WithNKBL3(512, inclusive = false) ++ 329 new WithNKBL2(256, inclusive = true) ++ 330 new WithNKBL1D(128) ++ 331 new MinimalConfig(n) 332) 333 334class MediumConfig(n: Int = 1) extends Config( 335 new WithNKBL3(4096, inclusive = false, banks = 4) 336 ++ new WithNKBL2(512, inclusive = true) 337 ++ new WithNKBL1D(128) 338 ++ new BaseConfig(n) 339) 340 341class FuzzConfig(dummy: Int = 0) extends Config( 342 new WithFuzzer 343 ++ new DefaultConfig(1) 344) 345 346class DefaultConfig(n: Int = 1) extends Config( 347 new WithNKBL3(16 * 1024, inclusive = false, banks = 4, ways = 16) 348 ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4) 349 ++ new WithNKBL1D(64, ways = 4) 350 ++ new BaseConfig(n) 351) 352