xref: /XiangShan/src/main/scala/top/Configs.scala (revision a0301c0d86a76a8bbed79fab2db5e6571a62b88a)
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 system._
24import chipsalliance.rocketchip.config._
25import freechips.rocketchip.tile.{BusErrorUnit, BusErrorUnitParams, XLen}
26import xiangshan.frontend.{ICacheParameters}
27import freechips.rocketchip.devices.debug._
28import freechips.rocketchip.tile.MaxHartIdBits
29import sifive.blocks.inclusivecache.{InclusiveCache, InclusiveCacheMicroParameters, CacheParameters}
30import xiangshan.backend.dispatch.DispatchParameters
31import xiangshan.backend.exu.ExuParameters
32import xiangshan.backend.dispatch.DispatchParameters
33import xiangshan.cache.{DCacheParameters, L1plusCacheParameters}
34import xiangshan.cache.prefetch.{BOPParameters, L1plusPrefetcherParameters, L2PrefetcherParameters, StreamPrefetchParameters}
35import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters}
36import device.{XSDebugModuleParams, EnableJtag}
37
38class DefaultConfig(n: Int) extends Config((site, here, up) => {
39  case XLen => 64
40  case DebugOptionsKey => DebugOptions()
41  case SoCParamsKey => SoCParameters(
42    cores = List.tabulate(n){ i => XSCoreParameters(HartId = i) }
43  )
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 => false.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 DefaultConfig(n).alter((site, here, up) => {
58    case SoCParamsKey => up(SoCParamsKey).copy(
59      cores = up(SoCParamsKey).cores.map(_.copy(
60        DecodeWidth = 2,
61        RenameWidth = 2,
62        FetchWidth = 4,
63        IssQueSize = 8,
64        NRPhyRegs = 64,
65        LoadQueueSize = 16,
66        StoreQueueSize = 12,
67        RoqSize = 32,
68        BrqSize = 8,
69        FtqSize = 8,
70        IBufSize = 16,
71        StoreBufferSize = 4,
72        StoreBufferThreshold = 3,
73        dpParams = DispatchParameters(
74          IntDqSize = 12,
75          FpDqSize = 12,
76          LsDqSize = 12,
77          IntDqDeqWidth = 4,
78          FpDqDeqWidth = 4,
79          LsDqDeqWidth = 4
80        ),
81        exuParameters = ExuParameters(
82          JmpCnt = 1,
83          AluCnt = 2,
84          MulCnt = 0,
85          MduCnt = 1,
86          FmacCnt = 1,
87          FmiscCnt = 1,
88          FmiscDivSqrtCnt = 0,
89          LduCnt = 2,
90          StuCnt = 2
91        ),
92        icacheParameters = ICacheParameters(
93          nSets = 64, // 16KB ICache
94          tagECC = Some("parity"),
95          dataECC = Some("parity"),
96          replacer = Some("setplru"),
97          nMissEntries = 2
98        ),
99        dcacheParameters = DCacheParameters(
100          nSets = 64, // 32KB DCache
101          nWays = 8,
102          tagECC = Some("secded"),
103          dataECC = Some("secded"),
104          replacer = Some("setplru"),
105          nMissEntries = 4,
106          nProbeEntries = 4,
107          nReleaseEntries = 4,
108          nStoreReplayEntries = 4,
109        ),
110        EnableBPD = false, // disable TAGE
111        EnableLoop = false,
112        itlbParameters = TLBParameters(
113          name = "itlb",
114          fetchi = true,
115          useDmode = false,
116          sameCycle = true,
117          normalReplacer = Some("plru"),
118          superReplacer = Some("plru"),
119          normalNWays = 4,
120          normalNSets = 1,
121          superNWays = 2,
122          shouldBlock = true
123        ),
124        ldtlbParameters = TLBParameters(
125          name = "ldtlb",
126          normalNSets = 4, // when da or sa
127          normalNWays = 1, // when fa or sa
128          normalAssociative = "sa",
129          normalReplacer = Some("setplru"),
130          superNWays = 4,
131          normalAsVictim = true,
132          outReplace = true
133        ),
134        sttlbParameters = TLBParameters(
135          name = "sttlb",
136          normalNSets = 4, // when da or sa
137          normalNWays = 1, // when fa or sa
138          normalAssociative = "sa",
139          normalReplacer = Some("setplru"),
140          normalAsVictim = true,
141          superNWays = 4,
142          outReplace = true
143        ),
144        btlbParameters = TLBParameters(
145          name = "btlb",
146          normalNSets = 1,
147          normalNWays = 8,
148          superNWays = 2
149        ),
150        l2tlbParameters = L2TLBParameters(
151          l1Size = 4,
152          l2nSets = 4,
153          l2nWays = 4,
154          l3nSets = 4,
155          l3nWays = 8,
156          spSize = 2,
157          missQueueSize = 8
158        ),
159        useFakeL2Cache = true, // disable L2 Cache
160      )),
161      L3Size = 256 * 1024, // 256KB L3 Cache
162    )
163  })
164)
165
166// Non-synthesizable MinimalConfig, for fast simulation only
167class MinimalSimConfig(n: Int = 1) extends Config(
168  new MinimalConfig(n).alter((site, here, up) => {
169    case SoCParamsKey => up(SoCParamsKey).copy(
170      cores = up(SoCParamsKey).cores.map(_.copy(
171        useFakeDCache = true,
172        useFakePTW = true,
173        useFakeL1plusCache = true,
174      )),
175      useFakeL3Cache = true
176    )
177  })
178)