xref: /XiangShan/src/main/scala/top/Configs.scala (revision dc4fac130426dbec49b49d778b9105d79b4a8eab)
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        )),
132        // ============ BPU ===============
133        EnableLoop = false,
134        EnableGHistDiff = false,
135        FtbSize = 256,
136        FtbWays = 2,
137        RasSize = 8,
138        RasSpecSize = 16,
139        TageTableInfos =
140          Seq((512, 4, 6),
141            (512, 9, 6),
142            (1024, 19, 6)),
143        SCNRows = 128,
144        SCNTables = 2,
145        SCHistLens = Seq(0, 5),
146        ITTageTableInfos =
147          Seq((256, 4, 7),
148            (256, 8, 7),
149            (512, 16, 7)),
150        // ================================
151        itlbParameters = TLBParameters(
152          name = "itlb",
153          fetchi = true,
154          useDmode = false,
155          NWays = 4,
156        ),
157        ldtlbParameters = TLBParameters(
158          name = "ldtlb",
159          NWays = 4,
160          partialStaticPMP = true,
161          outsideRecvFlush = true,
162          outReplace = false,
163          lgMaxSize = 4
164        ),
165        sttlbParameters = TLBParameters(
166          name = "sttlb",
167          NWays = 4,
168          partialStaticPMP = true,
169          outsideRecvFlush = true,
170          outReplace = false,
171          lgMaxSize = 4
172        ),
173        hytlbParameters = TLBParameters(
174          name = "hytlb",
175          NWays = 4,
176          partialStaticPMP = true,
177          outsideRecvFlush = true,
178          outReplace = false,
179          lgMaxSize = 4
180        ),
181        pftlbParameters = TLBParameters(
182          name = "pftlb",
183          NWays = 4,
184          partialStaticPMP = true,
185          outsideRecvFlush = true,
186          outReplace = false,
187          lgMaxSize = 4
188        ),
189        btlbParameters = TLBParameters(
190          name = "btlb",
191          NWays = 4,
192        ),
193        l2tlbParameters = L2TLBParameters(
194          l3Size = 4,
195          l2Size = 4,
196          l1nSets = 4,
197          l1nWays = 4,
198          l1ReservedBits = 1,
199          l0nSets = 4,
200          l0nWays = 8,
201          l0ReservedBits = 0,
202          spSize = 4,
203        ),
204        L2CacheParamsOpt = Some(L2Param(
205          name = "L2",
206          ways = 8,
207          sets = 128,
208          echoField = Seq(huancun.DirtyField()),
209          prefetch = Nil,
210          clientCaches = Seq(L1Param(
211            "dcache",
212            isKeywordBitsOpt = p.dcacheParametersOpt.get.isKeywordBitsOpt
213          )),
214        )),
215        L2NBanks = 2,
216        prefetcher = None // if L2 pf_recv_node does not exist, disable SMS prefetcher
217      )
218    )
219    case SoCParamsKey =>
220      val tiles = site(XSTileKey)
221      up(SoCParamsKey).copy(
222        L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy(
223          sets = 1024,
224          inclusive = false,
225          clientCaches = tiles.map{ core =>
226            val clientDirBytes = tiles.map{ t =>
227              t.L2NBanks * t.L2CacheParamsOpt.map(_.toCacheParams.capacity).getOrElse(0)
228            }.sum
229            val l2params = core.L2CacheParamsOpt.get.toCacheParams
230            l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64)
231          },
232          simulation = !site(DebugOptionsKey).FPGAPlatform,
233          prefetch = None
234        )),
235        L3NBanks = 1
236      )
237  })
238)
239
240// Non-synthesizable MinimalConfig, for fast simulation only
241class MinimalSimConfig(n: Int = 1) extends Config(
242  new MinimalConfig(n).alter((site, here, up) => {
243    case XSTileKey => up(XSTileKey).map(_.copy(
244      dcacheParametersOpt = None,
245      softPTW = true
246    ))
247    case SoCParamsKey => up(SoCParamsKey).copy(
248      L3CacheParamsOpt = None
249    )
250  })
251)
252
253class WithNKBL1D(n: Int, ways: Int = 8) extends Config((site, here, up) => {
254  case XSTileKey =>
255    val sets = n * 1024 / ways / 64
256    up(XSTileKey).map(_.copy(
257      dcacheParametersOpt = Some(DCacheParameters(
258        nSets = sets,
259        nWays = ways,
260        tagECC = Some("secded"),
261        dataECC = Some("secded"),
262        replacer = Some("setplru"),
263        nMissEntries = 16,
264        nProbeEntries = 8,
265        nReleaseEntries = 18,
266        nMaxPrefetchEntry = 6,
267      ))
268    ))
269})
270
271class WithNKBL2
272(
273  n: Int,
274  ways: Int = 8,
275  inclusive: Boolean = true,
276  banks: Int = 1,
277  tp: Boolean = true
278) extends Config((site, here, up) => {
279  case XSTileKey =>
280    require(inclusive, "L2 must be inclusive")
281    val upParams = up(XSTileKey)
282    val l2sets = n * 1024 / banks / ways / 64
283    upParams.map(p => p.copy(
284      L2CacheParamsOpt = Some(L2Param(
285        name = "L2",
286        ways = ways,
287        sets = l2sets,
288        clientCaches = Seq(L1Param(
289          "dcache",
290          sets = 2 * p.dcacheParametersOpt.get.nSets / banks,
291          ways = p.dcacheParametersOpt.get.nWays + 2,
292          aliasBitsOpt = p.dcacheParametersOpt.get.aliasBitsOpt,
293          vaddrBitsOpt = Some(p.GPAddrBitsSv48x4 - log2Up(p.dcacheParametersOpt.get.blockBytes)),
294          isKeywordBitsOpt = p.dcacheParametersOpt.get.isKeywordBitsOpt
295        )),
296        reqField = Seq(utility.ReqSourceField()),
297        echoField = Seq(huancun.DirtyField()),
298        prefetch = Seq(BOPParameters()) ++
299          (if (tp) Seq(TPParameters()) else Nil) ++
300          (if (p.prefetcher.nonEmpty) Seq(PrefetchReceiverParams()) else Nil),
301        enablePerf = !site(DebugOptionsKey).FPGAPlatform && site(DebugOptionsKey).EnablePerfDebug,
302        enableRollingDB = site(DebugOptionsKey).EnableRollingDB,
303        enableMonitor = site(DebugOptionsKey).AlwaysBasicDB,
304        elaboratedTopDown = !site(DebugOptionsKey).FPGAPlatform
305      )),
306      L2NBanks = banks
307    ))
308})
309
310class WithNKBL3(n: Int, ways: Int = 8, inclusive: Boolean = true, banks: Int = 1) extends Config((site, here, up) => {
311  case SoCParamsKey =>
312    val sets = n * 1024 / banks / ways / 64
313    val tiles = site(XSTileKey)
314    val clientDirBytes = tiles.map{ t =>
315      t.L2NBanks * t.L2CacheParamsOpt.map(_.toCacheParams.capacity).getOrElse(0)
316    }.sum
317    up(SoCParamsKey).copy(
318      L3NBanks = banks,
319      L3CacheParamsOpt = Some(HCCacheParameters(
320        name = "L3",
321        level = 3,
322        ways = ways,
323        sets = sets,
324        inclusive = inclusive,
325        clientCaches = tiles.map{ core =>
326          val l2params = core.L2CacheParamsOpt.get.toCacheParams
327          l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64, ways = l2params.ways + 2)
328        },
329        enablePerf = !site(DebugOptionsKey).FPGAPlatform && site(DebugOptionsKey).EnablePerfDebug,
330        ctrl = Some(CacheCtrl(
331          address = 0x39000000,
332          numCores = tiles.size
333        )),
334        reqField = Seq(utility.ReqSourceField()),
335        sramClkDivBy2 = true,
336        sramDepthDiv = 4,
337        tagECC = Some("secded"),
338        dataECC = Some("secded"),
339        simulation = !site(DebugOptionsKey).FPGAPlatform,
340        prefetch = Some(huancun.prefetch.L3PrefetchReceiverParams()),
341        tpmeta = Some(huancun.prefetch.DefaultTPmetaParameters())
342      )),
343      OpenLLCParamsOpt = Some(OpenLLCParam(
344        name = "LLC",
345        ways = ways,
346        sets = sets,
347        banks = banks,
348        fullAddressBits = 48,
349        clientCaches = tiles.map { core =>
350          val l2params = core.L2CacheParamsOpt.get
351          l2params.copy(sets = 2 * clientDirBytes / core.L2NBanks / l2params.ways / 64, ways = l2params.ways + 2)
352        }
353      ))
354    )
355})
356
357class WithL3DebugConfig extends Config(
358  new WithNKBL3(256, inclusive = false) ++ new WithNKBL2(64)
359)
360
361class MinimalL3DebugConfig(n: Int = 1) extends Config(
362  new WithL3DebugConfig ++ new MinimalConfig(n)
363)
364
365class DefaultL3DebugConfig(n: Int = 1) extends Config(
366  new WithL3DebugConfig ++ new BaseConfig(n)
367)
368
369class WithFuzzer extends Config((site, here, up) => {
370  case DebugOptionsKey => up(DebugOptionsKey).copy(
371    EnablePerfDebug = false,
372  )
373  case SoCParamsKey => up(SoCParamsKey).copy(
374    L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy(
375      enablePerf = false,
376    )),
377  )
378  case XSTileKey => up(XSTileKey).zipWithIndex.map{ case (p, i) =>
379    p.copy(
380      L2CacheParamsOpt = Some(up(XSTileKey)(i).L2CacheParamsOpt.get.copy(
381        enablePerf = false,
382      )),
383    )
384  }
385})
386
387class MinimalAliasDebugConfig(n: Int = 1) extends Config(
388  new WithNKBL3(512, inclusive = false) ++
389    new WithNKBL2(256, inclusive = true) ++
390    new WithNKBL1D(128) ++
391    new MinimalConfig(n)
392)
393
394class MediumConfig(n: Int = 1) extends Config(
395  new WithNKBL3(4096, inclusive = false, banks = 4)
396    ++ new WithNKBL2(512, inclusive = true)
397    ++ new WithNKBL1D(128)
398    ++ new BaseConfig(n)
399)
400
401class FuzzConfig(dummy: Int = 0) extends Config(
402  new WithFuzzer
403    ++ new DefaultConfig(1)
404)
405
406class DefaultConfig(n: Int = 1) extends Config(
407  new WithNKBL3(16 * 1024, inclusive = false, banks = 4, ways = 16)
408    ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4)
409    ++ new WithNKBL1D(64, ways = 4)
410    ++ new BaseConfig(n)
411)
412
413class WithCHI extends Config((_, _, _) => {
414  case EnableCHI => true
415})
416
417class KunminghuV2Config(n: Int = 1) extends Config(
418  new WithCHI
419    ++ new Config((site, here, up) => {
420      case SoCParamsKey => up(SoCParamsKey).copy(L3CacheParamsOpt = None) // There will be no L3
421    })
422    ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4, tp = false)
423    ++ new WithNKBL1D(64, ways = 4)
424    ++ new DefaultConfig(n)
425)
426
427class KunminghuV2MinimalConfig(n: Int = 1) extends Config(
428  new WithCHI
429    ++ new Config((site, here, up) => {
430      case SoCParamsKey => up(SoCParamsKey).copy(L3CacheParamsOpt = None) // There will be no L3
431    })
432    ++ new WithNKBL2(128, inclusive = true, banks = 1, tp = false)
433    ++ new WithNKBL1D(32, ways = 4)
434    ++ new MinimalConfig(n)
435)
436
437class XSNoCTopConfig(n: Int = 1) extends Config(
438  (new KunminghuV2Config(n)).alter((site, here, up) => {
439    case SoCParamsKey => up(SoCParamsKey).copy(UseXSNoCTop = true)
440  })
441)
442
443class XSNoCTopMinimalConfig(n: Int = 1) extends Config(
444  (new KunminghuV2MinimalConfig(n)).alter((site, here, up) => {
445    case SoCParamsKey => up(SoCParamsKey).copy(UseXSNoCTop = true)
446  })
447)
448
449class FpgaDefaultConfig(n: Int = 1) extends Config(
450  (new WithNKBL3(3 * 1024, inclusive = false, banks = 1, ways = 6)
451    ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4)
452    ++ new WithNKBL1D(64, ways = 4)
453    ++ new BaseConfig(n)).alter((site, here, up) => {
454    case DebugOptionsKey => up(DebugOptionsKey).copy(
455      AlwaysBasicDiff = false,
456      AlwaysBasicDB = false
457    )
458    case SoCParamsKey => up(SoCParamsKey).copy(
459      L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy(
460        sramClkDivBy2 = false,
461      )),
462    )
463  })
464)
465
466class FpgaDiffDefaultConfig(n: Int = 1) extends Config(
467  (new WithNKBL3(3 * 1024, inclusive = false, banks = 1, ways = 6)
468    ++ new WithNKBL2(2 * 512, inclusive = true, banks = 4)
469    ++ new WithNKBL1D(64, ways = 8)
470    ++ new BaseConfig(n)).alter((site, here, up) => {
471    case DebugOptionsKey => up(DebugOptionsKey).copy(
472      AlwaysBasicDiff = true,
473      AlwaysBasicDB = false
474    )
475    case SoCParamsKey => up(SoCParamsKey).copy(
476      L3CacheParamsOpt = Some(up(SoCParamsKey).L3CacheParamsOpt.get.copy(
477        sramClkDivBy2 = false,
478      )),
479    )
480  })
481)
482