xref: /XiangShan/src/main/scala/system/SoC.scala (revision 1865a66fb06dc0d7bdecc30c42ad77e8f09a8f7f)
1package system
2
3import chipsalliance.rocketchip.config.Parameters
4import device.{AXI4Timer, TLTimer}
5import chisel3._
6import chisel3.util._
7import freechips.rocketchip.diplomacy.{AddressSet, LazyModule, LazyModuleImp}
8import freechips.rocketchip.tilelink.{TLBuffer, TLFuzzer, TLIdentityNode, TLXbar}
9import utils.DebugIdentityNode
10import xiangshan.{HasXSParameter, XSCore}
11
12
13case class SoCParameters
14(
15  EnableILA: Boolean = false,
16  HasL2Cache: Boolean = false,
17  HasPrefetch: Boolean = false
18)
19
20trait HasSoCParameter extends HasXSParameter{
21  val soc = top.Parameters.get.socParameters
22  val EnableILA = soc.EnableILA
23  val HasL2cache = soc.HasL2Cache
24  val HasPrefetch = soc.HasPrefetch
25}
26
27class ILABundle extends Bundle {}
28
29
30class DummyCore()(implicit p: Parameters) extends LazyModule {
31  val mem = TLFuzzer(nOperations = 10)
32  val mmio = TLFuzzer(nOperations = 10)
33
34  lazy val module = new LazyModuleImp(this){
35
36  }
37}
38
39
40class XSSoc()(implicit p: Parameters) extends LazyModule with HasSoCParameter {
41
42  private val xsCore = LazyModule(new XSCore())
43
44  // only mem and extDev visible externally
45  val mem = xsCore.mem
46  val extDev = TLIdentityNode()
47
48  private val mmioXbar = TLXbar()
49  private val clint = LazyModule(new TLTimer(
50    Seq(AddressSet(0x38000000L, 0x0000ffffL)),
51    sim = !env.FPGAPlatform
52  ))
53
54  mmioXbar :=
55    TLBuffer() :=
56    DebugIdentityNode() :=
57    xsCore.mmio
58
59  clint.node :=
60    mmioXbar
61
62  extDev :=
63    mmioXbar
64
65  lazy val module = new LazyModuleImp(this){
66    val io = IO(new Bundle{
67      val meip = Input(Bool())
68      val ila = if(env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
69    })
70    val mtipSync = WireInit(0.U(1.W)) //clint.module.mtip
71    val meipSync = RegNext(RegNext(io.meip))
72    ExcitingUtils.addSource(mtipSync, "mtip")
73    ExcitingUtils.addSource(meipSync, "meip")
74  }
75
76}
77
78
79//class XSSoc extends Module with HasSoCParameter {
80//  val io = IO(new Bundle{
81//    val mem = new TLCached(l1BusParams)
82//    val mmio = new TLCached(l1BusParams)
83//    val frontend = Flipped(new AXI4) //TODO: do we need it ?
84//    val meip = Input(Bool())
85//    val ila = if (env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
86//  })
87//
88//  val xsCore = Module(new XSCore)
89//
90//  io.frontend <> DontCare
91//
92//  io.mem <> xsCore.io.mem
93//
94//  val addrSpace = List(
95//    (0x40000000L, 0x40000000L), // external devices
96//    (0x38000000L, 0x00010000L)  // CLINT
97//  )
98//  val mmioXbar = Module(new NaiveTL1toN(addrSpace, xsCore.io.mem.params))
99//  mmioXbar.io.in <> xsCore.io.mmio
100//
101//  val extDev = mmioXbar.io.out(0)
102//  val clint = Module(new AXI4Timer(sim = !env.FPGAPlatform))
103//  clint.io.in <> AXI4ToAXI4Lite(MMIOTLToAXI4(mmioXbar.io.out(1)))
104//
105//  io.mmio <> extDev
106//
107//  val mtipSync = clint.io.extra.get.mtip
108//  val meipSync = RegNext(RegNext(io.meip))
109//  ExcitingUtils.addSource(mtipSync, "mtip")
110//  ExcitingUtils.addSource(meipSync, "meip")
111//}
112