xref: /XiangShan/src/main/scala/system/SoC.scala (revision 0fbc6212dd5d9b50739d75dba1967fefc4ba700e)
1006e1884SZihao Yupackage system
2006e1884SZihao Yu
3eb8bdfa7SZihao Yuimport noop._
4006e1884SZihao Yuimport bus.axi4.{AXI4, AXI4Lite}
58f36f779SZihao Yuimport bus.simplebus._
61b2d260fSZihao Yuimport device.AXI4Timer
7006e1884SZihao Yu
8006e1884SZihao Yuimport chisel3._
9096ea47eSzhanglinjuanimport chisel3.util._
10fe820c3dSZihao Yuimport chisel3.util.experimental.BoringUtils
11006e1884SZihao Yu
122f7e16feSZihao Yutrait HasSoCParameter {
13*0fbc6212SZihao Yu  val EnableILA = true
14f1ae1cd3SZihao Yu  val HasL2cache = true
15ccd497e4Szhanglinjuan  val HasPrefetch = true
16303b861dSZihao Yu}
17303b861dSZihao Yu
18303b861dSZihao Yuclass ILABundle extends Bundle {
19303b861dSZihao Yu  val WBUpc = UInt(32.W)
20303b861dSZihao Yu  val WBUvalid = UInt(1.W)
21303b861dSZihao Yu  val WBUrfWen = UInt(1.W)
22303b861dSZihao Yu  val WBUrfDest = UInt(5.W)
23303b861dSZihao Yu  val WBUrfData = UInt(64.W)
24303b861dSZihao Yu  val InstrCnt = UInt(64.W)
25303b861dSZihao Yu}
26303b861dSZihao Yu
272f7e16feSZihao Yuclass NOOPSoC(implicit val p: NOOPConfig) extends Module with HasSoCParameter {
28006e1884SZihao Yu  val io = IO(new Bundle{
29cdd59e9fSZihao Yu    val mem = new AXI4
30ad255e6cSZihao Yu    val mmio = (if (p.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC })
318656be21SWang Huizhe    val frontend = Flipped(new AXI4)
32466eb0a8SZihao Yu    val meip = Input(Bool())
332f7e16feSZihao Yu    val ila = if (p.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
34006e1884SZihao Yu  })
35006e1884SZihao Yu
36006e1884SZihao Yu  val noop = Module(new NOOP)
37635253aaSZihao Yu  val cohMg = Module(new CoherenceManager)
38635253aaSZihao Yu  val xbar = Module(new SimpleBusCrossbarNto1(2))
39635253aaSZihao Yu  cohMg.io.in <> noop.io.imem.mem
40635253aaSZihao Yu  noop.io.dmem.coh <> cohMg.io.out.coh
41635253aaSZihao Yu  xbar.io.in(0) <> cohMg.io.out.mem
42635253aaSZihao Yu  xbar.io.in(1) <> noop.io.dmem.mem
43d2d827d9Szhanglinjuan
448656be21SWang Huizhe  val axi2sb = Module(new AXI42SimpleBusConverter())
458656be21SWang Huizhe  axi2sb.io.in <> io.frontend
468656be21SWang Huizhe  noop.io.frontend <> axi2sb.io.out
478656be21SWang Huizhe
48eb8bdfa7SZihao Yu  if (HasL2cache) {
4935377176Szhanglinjuan    val l2cacheOut = Wire(new SimpleBusC)
50614aaf64SZihao Yu    val l2cacheIn = if (HasPrefetch) {
51096ea47eSzhanglinjuan      val prefetcher = Module(new Prefetcher)
52096ea47eSzhanglinjuan      val l2cacheIn = Wire(new SimpleBusUC)
53ccd497e4Szhanglinjuan      prefetcher.io.in <> xbar.io.out.req
54ccd497e4Szhanglinjuan      l2cacheIn.req <> prefetcher.io.out
5535377176Szhanglinjuan      xbar.io.out.resp <> l2cacheIn.resp
56614aaf64SZihao Yu      l2cacheIn
57614aaf64SZihao Yu    } else xbar.io.out
5839ac6601SZihao Yu    val l2Empty = Wire(Bool())
59b0cf5de6SZihao Yu    l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC) :: Nil, flush = "b00".U, empty = l2Empty, enable = true)(
604cd61964SZihao Yu      CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2))
6135377176Szhanglinjuan    io.mem <> l2cacheOut.mem.toAXI4()
6235377176Szhanglinjuan    l2cacheOut.coh.resp.ready := true.B
6335377176Szhanglinjuan    l2cacheOut.coh.req.valid := false.B
6435377176Szhanglinjuan    l2cacheOut.coh.req.bits := DontCare
65eb8bdfa7SZihao Yu  } else {
66635253aaSZihao Yu    io.mem <> xbar.io.out.toAXI4()
67eb8bdfa7SZihao Yu  }
68096ea47eSzhanglinjuan
69635253aaSZihao Yu  noop.io.imem.coh.resp.ready := true.B
70635253aaSZihao Yu  noop.io.imem.coh.req.valid := false.B
71635253aaSZihao Yu  noop.io.imem.coh.req.bits := DontCare
72096ea47eSzhanglinjuan
731b2d260fSZihao Yu  val addrSpace = List(
741b2d260fSZihao Yu    (0x40000000L, 0x08000000L), // external devices
751b2d260fSZihao Yu    (0x48000000L, 0x00010000L)  // CLINT
761b2d260fSZihao Yu  )
771b2d260fSZihao Yu  val mmioXbar = Module(new SimpleBusCrossbar1toN(addrSpace))
781b2d260fSZihao Yu  mmioXbar.io.in <> noop.io.mmio
79d2d827d9Szhanglinjuan
801b2d260fSZihao Yu  val extDev = mmioXbar.io.out(0)
811b2d260fSZihao Yu  val clint = Module(new AXI4Timer(sim = !p.FPGAPlatform))
821b2d260fSZihao Yu  clint.io.in <> mmioXbar.io.out(1).toAXI4Lite()
831b2d260fSZihao Yu  if (p.FPGAPlatform) io.mmio <> extDev.toAXI4Lite()
841b2d260fSZihao Yu  else io.mmio <> extDev
851b2d260fSZihao Yu
861b2d260fSZihao Yu  val mtipSync = clint.io.extra.get.mtip
87466eb0a8SZihao Yu  val meipSync = RegNext(RegNext(io.meip))
885d41d760SZihao Yu  BoringUtils.addSource(mtipSync, "mtip")
89466eb0a8SZihao Yu  BoringUtils.addSource(meipSync, "meip")
90303b861dSZihao Yu
91303b861dSZihao Yu  // ILA
92303b861dSZihao Yu  if (p.FPGAPlatform) {
93303b861dSZihao Yu    def BoringUtilsConnect(sink: UInt, id: String) {
94303b861dSZihao Yu      val temp = WireInit(0.U(64.W))
95303b861dSZihao Yu      BoringUtils.addSink(temp, id)
96303b861dSZihao Yu      sink := temp
97303b861dSZihao Yu    }
98303b861dSZihao Yu
99303b861dSZihao Yu    val dummy = WireInit(0.U.asTypeOf(new ILABundle))
100303b861dSZihao Yu    val ila = io.ila.getOrElse(dummy)
101303b861dSZihao Yu    BoringUtilsConnect(ila.WBUpc      ,"ilaWBUpc")
102303b861dSZihao Yu    BoringUtilsConnect(ila.WBUvalid   ,"ilaWBUvalid")
103303b861dSZihao Yu    BoringUtilsConnect(ila.WBUrfWen   ,"ilaWBUrfWen")
104303b861dSZihao Yu    BoringUtilsConnect(ila.WBUrfDest  ,"ilaWBUrfDest")
105303b861dSZihao Yu    BoringUtilsConnect(ila.WBUrfData  ,"ilaWBUrfData")
106303b861dSZihao Yu    BoringUtilsConnect(ila.InstrCnt   ,"ilaInstrCnt")
107303b861dSZihao Yu  }
108006e1884SZihao Yu}
109