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, XLen} 30import system._ 31import utility._ 32import utils._ 33import huancun._ 34import openLLC.{OpenLLCParam} 35import xiangshan._ 36import xiangshan.backend.dispatch.DispatchParameters 37import xiangshan.backend.regfile.{IntPregParams, VfPregParams} 38import xiangshan.cache.DCacheParameters 39import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters} 40import device.{EnableJtag, XSDebugModuleParams} 41import huancun._ 42import coupledL2._ 43import coupledL2.prefetch._ 44import xiangshan.frontend.icache.ICacheParameters 45 46class BaseConfig(n: Int) extends Config((site, here, up) => { 47 case XLen => 64 48 case DebugOptionsKey => DebugOptions() 49 case SoCParamsKey => SoCParameters() 50 case PMParameKey => PMParameters() 51 case XSTileKey => Seq.tabulate(n){ i => XSCoreParameters(HartId = i) } 52 case ExportDebug => DebugAttachParams(protocols = Set(JTAG)) 53 case DebugModuleKey => Some(XSDebugModuleParams(site(XLen))) 54 case JtagDTMKey => JtagDTMKey 55 case MaxHartIdBits => log2Up(n) max 6 56 case EnableJtag => true.B 57}) 58 59// Synthesizable minimal XiangShan 60// * It is still an out-of-order, super-scalaer arch 61// * L1 cache included 62// * L2 cache NOT included 63// * L3 cache included 64class MinimalConfig(n: Int = 1) extends Config( 65 new BaseConfig(n).alter((site, here, up) => { 66 case XSTileKey => up(XSTileKey).map( 67 p => p.copy( 68 DecodeWidth = 6, 69 RenameWidth = 6, 70 RobCommitWidth = 8, 71 FetchWidth = 4, 72 VirtualLoadQueueSize = 24, 73 LoadQueueRARSize = 24, 74 LoadQueueRAWSize = 12, 75 LoadQueueReplaySize = 24, 76 LoadUncacheBufferSize = 8, 77 LoadQueueNWriteBanks = 4, // NOTE: make sure that LoadQueue{RAR, RAW, Replay}Size is divided by LoadQueueNWriteBanks. 78 RollbackGroupSize = 8, 79 StoreQueueSize = 20, 80 StoreQueueNWriteBanks = 4, // NOTE: make sure that StoreQueueSize is divided by StoreQueueNWriteBanks 81 StoreQueueForwardWithMask = true, 82 // ============ VLSU ============ 83 VlMergeBufferSize = 16, 84 VsMergeBufferSize = 8, 85 UopWritebackWidth = 2, 86 // ============================== 87 RobSize = 48, 88 RabSize = 96, 89 FtqSize = 8, 90 IBufSize = 24, 91 IBufNBank = 6, 92 StoreBufferSize = 4, 93 StoreBufferThreshold = 3, 94 IssueQueueSize = 10, 95 IssueQueueCompEntrySize = 4, 96 dpParams = DispatchParameters( 97 IntDqSize = 12, 98 FpDqSize = 12, 99 LsDqSize = 12, 100 IntDqDeqWidth = 8, 101 FpDqDeqWidth = 6, 102 VecDqDeqWidth = 6, 103 LsDqDeqWidth = 6 104 ), 105 intPreg = IntPregParams( 106 numEntries = 64, 107 numRead = None, 108 numWrite = None, 109 ), 110 vfPreg = VfPregParams( 111 numEntries = 160, 112 numRead = None, 113 numWrite = None, 114 ), 115 icacheParameters = ICacheParameters( 116 nSets = 64, // 16KB ICache 117 tagECC = Some("parity"), 118 dataECC = Some("parity"), 119 replacer = Some("setplru"), 120 ), 121 dcacheParametersOpt = Some(DCacheParameters( 122 nSets = 64, // 32KB DCache 123 nWays = 8, 124 tagECC = Some("secded"), 125 dataECC = Some("secded"), 126 replacer = Some("setplru"), 127 nMissEntries = 4, 128 nProbeEntries = 4, 129 nReleaseEntries = 8, 130 nMaxPrefetchEntry = 2, 131 enableTagEcc = true, 132 enableDataEcc = true, 133 )), 134 // ============ BPU =============== 135 EnableLoop = false, 136 EnableGHistDiff = false, 137 FtbSize = 256, 138 FtbWays = 2, 139 RasSize = 8, 140 RasSpecSize = 16, 141 TageTableInfos = 142 Seq((512, 4, 6), 143 (512, 9, 6), 144 (1024, 19, 6)), 145 SCNRows = 128, 146 SCNTables = 2, 147 SCHistLens = Seq(0, 5), 148 ITTageTableInfos = 149 Seq((256, 4, 7), 150 (256, 8, 7), 151 (512, 16, 7)), 152 // ================================ 153 itlbParameters = TLBParameters( 154 name = "itlb", 155 fetchi = true, 156 useDmode = false, 157 NWays = 4, 158 ), 159 ldtlbParameters = TLBParameters( 160 name = "ldtlb", 161 NWays = 4, 162 partialStaticPMP = true, 163 outsideRecvFlush = true, 164 outReplace = false, 165 lgMaxSize = 4 166 ), 167 sttlbParameters = TLBParameters( 168 name = "sttlb", 169 NWays = 4, 170 partialStaticPMP = true, 171 outsideRecvFlush = true, 172 outReplace = false, 173 lgMaxSize = 4 174 ), 175 hytlbParameters = TLBParameters( 176 name = "hytlb", 177 NWays = 4, 178 partialStaticPMP = true, 179 outsideRecvFlush = true, 180 outReplace = false, 181 lgMaxSize = 4 182 ), 183 pftlbParameters = TLBParameters( 184 name = "pftlb", 185 NWays = 4, 186 partialStaticPMP = true, 187 outsideRecvFlush = true, 188 outReplace = false, 189 lgMaxSize = 4 190 ), 191 btlbParameters = TLBParameters( 192 name = "btlb", 193 NWays = 4, 194 ), 195 l2tlbParameters = L2TLBParameters( 196 l3Size = 4, 197 l2Size = 4, 198 l1nSets = 4, 199 l1nWays = 4, 200 l1ReservedBits = 1, 201 l0nSets = 4, 202 l0nWays = 8, 203 l0ReservedBits = 0, 204 spSize = 4, 205 ), 206 L2CacheParamsOpt = Some(L2Param( 207 name = "L2", 208 ways = 8, 209 sets = 128, 210 echoField = Seq(huancun.DirtyField()), 211 prefetch = Nil, 212 clientCaches = Seq(L1Param( 213 "dcache", 214 isKeywordBitsOpt = p.dcacheParametersOpt.get.isKeywordBitsOpt 215 )), 216 )), 217 L2NBanks = 2, 218 prefetcher = None // if L2 pf_recv_node does not exist, disable SMS prefetcher 219 ) 220 ) 221 case SoCParamsKey => 222 val tiles = site(XSTileKey) 223 up(SoCParamsKey).copy( 224 L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy( 225 sets = 1024, 226 inclusive = false, 227 clientCaches = tiles.map{ core => 228 val clientDirBytes = tiles.map{ t => 229 t.L2NBanks * t.L2CacheParamsOpt.map(_.toCacheParams.capacity).getOrElse(0) 230 }.sum 231 val l2params = core.L2CacheParamsOpt.get.toCacheParams 232 l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64) 233 }, 234 simulation = !site(DebugOptionsKey).FPGAPlatform, 235 prefetch = None 236 )), 237 L3NBanks = 1 238 ) 239 }) 240) 241 242// Non-synthesizable MinimalConfig, for fast simulation only 243class MinimalSimConfig(n: Int = 1) extends Config( 244 new MinimalConfig(n).alter((site, here, up) => { 245 case XSTileKey => up(XSTileKey).map(_.copy( 246 dcacheParametersOpt = None, 247 softPTW = true 248 )) 249 case SoCParamsKey => up(SoCParamsKey).copy( 250 L3CacheParamsOpt = None 251 ) 252 }) 253) 254 255class WithNKBL1D(n: Int, ways: Int = 8) extends Config((site, here, up) => { 256 case XSTileKey => 257 val sets = n * 1024 / ways / 64 258 up(XSTileKey).map(_.copy( 259 dcacheParametersOpt = Some(DCacheParameters( 260 nSets = sets, 261 nWays = ways, 262 tagECC = Some("secded"), 263 dataECC = Some("secded"), 264 replacer = Some("setplru"), 265 nMissEntries = 16, 266 nProbeEntries = 8, 267 nReleaseEntries = 18, 268 nMaxPrefetchEntry = 6, 269 enableTagEcc = true, 270 enableDataEcc = true 271 )) 272 )) 273}) 274 275class WithNKBL2 276( 277 n: Int, 278 ways: Int = 8, 279 inclusive: Boolean = true, 280 banks: Int = 1, 281 tp: Boolean = true 282) extends Config((site, here, up) => { 283 case XSTileKey => 284 require(inclusive, "L2 must be inclusive") 285 val upParams = up(XSTileKey) 286 val l2sets = n * 1024 / banks / ways / 64 287 upParams.map(p => p.copy( 288 L2CacheParamsOpt = Some(L2Param( 289 name = "L2", 290 ways = ways, 291 sets = l2sets, 292 clientCaches = Seq(L1Param( 293 "dcache", 294 sets = 2 * p.dcacheParametersOpt.get.nSets / banks, 295 ways = p.dcacheParametersOpt.get.nWays + 2, 296 aliasBitsOpt = p.dcacheParametersOpt.get.aliasBitsOpt, 297 vaddrBitsOpt = Some(p.GPAddrBitsSv48x4 - log2Up(p.dcacheParametersOpt.get.blockBytes)), 298 isKeywordBitsOpt = p.dcacheParametersOpt.get.isKeywordBitsOpt 299 )), 300 reqField = Seq(utility.ReqSourceField()), 301 echoField = Seq(huancun.DirtyField()), 302 prefetch = Seq(BOPParameters()) ++ 303 (if (tp) Seq(TPParameters()) else Nil) ++ 304 (if (p.prefetcher.nonEmpty) Seq(PrefetchReceiverParams()) else Nil), 305 enablePerf = !site(DebugOptionsKey).FPGAPlatform && site(DebugOptionsKey).EnablePerfDebug, 306 enableRollingDB = site(DebugOptionsKey).EnableRollingDB, 307 enableMonitor = site(DebugOptionsKey).AlwaysBasicDB, 308 elaboratedTopDown = !site(DebugOptionsKey).FPGAPlatform 309 )), 310 L2NBanks = banks 311 )) 312}) 313 314class WithNKBL3(n: Int, ways: Int = 8, inclusive: Boolean = true, banks: Int = 1) extends Config((site, here, up) => { 315 case SoCParamsKey => 316 val sets = n * 1024 / banks / ways / 64 317 val tiles = site(XSTileKey) 318 val clientDirBytes = tiles.map{ t => 319 t.L2NBanks * t.L2CacheParamsOpt.map(_.toCacheParams.capacity).getOrElse(0) 320 }.sum 321 up(SoCParamsKey).copy( 322 L3NBanks = banks, 323 L3CacheParamsOpt = Some(HCCacheParameters( 324 name = "L3", 325 level = 3, 326 ways = ways, 327 sets = sets, 328 inclusive = inclusive, 329 clientCaches = tiles.map{ core => 330 val l2params = core.L2CacheParamsOpt.get.toCacheParams 331 l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64, ways = l2params.ways + 2) 332 }, 333 enablePerf = !site(DebugOptionsKey).FPGAPlatform && site(DebugOptionsKey).EnablePerfDebug, 334 ctrl = Some(CacheCtrl( 335 address = 0x39000000, 336 numCores = tiles.size 337 )), 338 reqField = Seq(utility.ReqSourceField()), 339 sramClkDivBy2 = true, 340 sramDepthDiv = 4, 341 tagECC = Some("secded"), 342 dataECC = Some("secded"), 343 simulation = !site(DebugOptionsKey).FPGAPlatform, 344 prefetch = Some(huancun.prefetch.L3PrefetchReceiverParams()), 345 tpmeta = Some(huancun.prefetch.DefaultTPmetaParameters()) 346 )), 347 OpenLLCParamsOpt = Some(OpenLLCParam( 348 name = "LLC", 349 ways = ways, 350 sets = sets, 351 banks = banks, 352 fullAddressBits = 48, 353 clientCaches = tiles.map { core => 354 val l2params = core.L2CacheParamsOpt.get 355 l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64, ways = l2params.ways + 2) 356 } 357 )) 358 ) 359}) 360 361class WithL3DebugConfig extends Config( 362 new WithNKBL3(256, inclusive = false) ++ new WithNKBL2(64) 363) 364 365class MinimalL3DebugConfig(n: Int = 1) extends Config( 366 new WithL3DebugConfig ++ new MinimalConfig(n) 367) 368 369class DefaultL3DebugConfig(n: Int = 1) extends Config( 370 new WithL3DebugConfig ++ new BaseConfig(n) 371) 372 373class WithFuzzer extends Config((site, here, up) => { 374 case DebugOptionsKey => up(DebugOptionsKey).copy( 375 EnablePerfDebug = false, 376 ) 377 case SoCParamsKey => up(SoCParamsKey).copy( 378 L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy( 379 enablePerf = false, 380 )), 381 ) 382 case XSTileKey => up(XSTileKey).zipWithIndex.map{ case (p, i) => 383 p.copy( 384 L2CacheParamsOpt = Some(up(XSTileKey)(i).L2CacheParamsOpt.get.copy( 385 enablePerf = false, 386 )), 387 ) 388 } 389}) 390 391class MinimalAliasDebugConfig(n: Int = 1) extends Config( 392 new WithNKBL3(512, inclusive = false) ++ 393 new WithNKBL2(256, inclusive = true) ++ 394 new WithNKBL1D(128) ++ 395 new MinimalConfig(n) 396) 397 398class MediumConfig(n: Int = 1) extends Config( 399 new WithNKBL3(4096, inclusive = false, banks = 4) 400 ++ new WithNKBL2(512, inclusive = true) 401 ++ new WithNKBL1D(128) 402 ++ new BaseConfig(n) 403) 404 405class FuzzConfig(dummy: Int = 0) extends Config( 406 new WithFuzzer 407 ++ new DefaultConfig(1) 408) 409 410class DefaultConfig(n: Int = 1) extends Config( 411 new WithNKBL3(16 * 1024, inclusive = false, banks = 4, ways = 16) 412 ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4) 413 ++ new WithNKBL1D(64, ways = 4) 414 ++ new BaseConfig(n) 415) 416 417class WithCHI extends Config((_, _, _) => { 418 case EnableCHI => true 419}) 420 421class KunminghuV2Config(n: Int = 1) extends Config( 422 new WithCHI 423 ++ new Config((site, here, up) => { 424 case SoCParamsKey => up(SoCParamsKey).copy(L3CacheParamsOpt = None) // There will be no L3 425 }) 426 ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4, tp = false) 427 ++ new WithNKBL1D(64, ways = 4) 428 ++ new DefaultConfig(n) 429) 430 431class KunminghuV2MinimalConfig(n: Int = 1) extends Config( 432 new WithCHI 433 ++ new Config((site, here, up) => { 434 case SoCParamsKey => up(SoCParamsKey).copy(L3CacheParamsOpt = None) // There will be no L3 435 }) 436 ++ new WithNKBL2(128, inclusive = true, banks = 1, tp = false) 437 ++ new WithNKBL1D(32, ways = 4) 438 ++ new MinimalConfig(n) 439) 440 441class XSNoCTopConfig(n: Int = 1) extends Config( 442 (new KunminghuV2Config(n)).alter((site, here, up) => { 443 case SoCParamsKey => up(SoCParamsKey).copy(UseXSNoCTop = true) 444 }) 445) 446 447class XSNoCTopMinimalConfig(n: Int = 1) extends Config( 448 (new KunminghuV2MinimalConfig(n)).alter((site, here, up) => { 449 case SoCParamsKey => up(SoCParamsKey).copy(UseXSNoCTop = true) 450 }) 451) 452 453class FpgaDefaultConfig(n: Int = 1) extends Config( 454 (new WithNKBL3(3 * 1024, inclusive = false, banks = 1, ways = 6) 455 ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4) 456 ++ new WithNKBL1D(64, ways = 4) 457 ++ new BaseConfig(n)).alter((site, here, up) => { 458 case DebugOptionsKey => up(DebugOptionsKey).copy( 459 AlwaysBasicDiff = false, 460 AlwaysBasicDB = false 461 ) 462 case SoCParamsKey => up(SoCParamsKey).copy( 463 L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy( 464 sramClkDivBy2 = false, 465 )), 466 ) 467 }) 468) 469 470class FpgaDiffDefaultConfig(n: Int = 1) extends Config( 471 (new WithNKBL3(3 * 1024, inclusive = false, banks = 1, ways = 6) 472 ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4) 473 ++ new WithNKBL1D(64, ways = 8) 474 ++ new BaseConfig(n)).alter((site, here, up) => { 475 case DebugOptionsKey => up(DebugOptionsKey).copy( 476 AlwaysBasicDiff = true, 477 AlwaysBasicDB = false 478 ) 479 case SoCParamsKey => up(SoCParamsKey).copy( 480 L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy( 481 sramClkDivBy2 = false, 482 )), 483 ) 484 }) 485) 486