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