1006e1884SZihao Yupackage system 2006e1884SZihao Yu 3*1e3fad10SLinJiaweiimport noop.{Cache,CacheConfig} 4006e1884SZihao Yuimport bus.axi4.{AXI4, AXI4Lite} 58f36f779SZihao Yuimport bus.simplebus._ 61b2d260fSZihao Yuimport device.AXI4Timer 7006e1884SZihao Yuimport chisel3._ 8096ea47eSzhanglinjuanimport chisel3.util._ 9fe820c3dSZihao Yuimport chisel3.util.experimental.BoringUtils 10*1e3fad10SLinJiaweiimport xiangshan.{XSConfig, XSCore} 11006e1884SZihao Yu 122f7e16feSZihao Yutrait HasSoCParameter { 130fbc6212SZihao Yu val EnableILA = true 14f1ae1cd3SZihao Yu val HasL2cache = true 15ccd497e4Szhanglinjuan val HasPrefetch = true 16303b861dSZihao Yu} 17303b861dSZihao Yu 18*1e3fad10SLinJiaweiclass ILABundle extends Bundle {} 19303b861dSZihao Yu 20*1e3fad10SLinJiaweiclass XSSoc(implicit val p: XSConfig) extends Module with HasSoCParameter { 21006e1884SZihao Yu val io = IO(new Bundle{ 22cdd59e9fSZihao Yu val mem = new AXI4 23*1e3fad10SLinJiawei val mmio = if (p.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC } 248656be21SWang Huizhe val frontend = Flipped(new AXI4) 25466eb0a8SZihao Yu val meip = Input(Bool()) 262f7e16feSZihao Yu val ila = if (p.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None 27006e1884SZihao Yu }) 28006e1884SZihao Yu 29*1e3fad10SLinJiawei val xsCore = Module(new XSCore) 30635253aaSZihao Yu val cohMg = Module(new CoherenceManager) 31635253aaSZihao Yu val xbar = Module(new SimpleBusCrossbarNto1(2)) 32*1e3fad10SLinJiawei cohMg.io.in <> xsCore.io.imem.mem 33*1e3fad10SLinJiawei xsCore.io.dmem.coh <> cohMg.io.out.coh 34635253aaSZihao Yu xbar.io.in(0) <> cohMg.io.out.mem 35*1e3fad10SLinJiawei xbar.io.in(1) <> xsCore.io.dmem.mem 36d2d827d9Szhanglinjuan 378656be21SWang Huizhe val axi2sb = Module(new AXI42SimpleBusConverter()) 388656be21SWang Huizhe axi2sb.io.in <> io.frontend 39*1e3fad10SLinJiawei xsCore.io.frontend <> axi2sb.io.out 408656be21SWang Huizhe 41eb8bdfa7SZihao Yu if (HasL2cache) { 4235377176Szhanglinjuan val l2cacheOut = Wire(new SimpleBusC) 43614aaf64SZihao Yu val l2cacheIn = if (HasPrefetch) { 44096ea47eSzhanglinjuan val prefetcher = Module(new Prefetcher) 45096ea47eSzhanglinjuan val l2cacheIn = Wire(new SimpleBusUC) 46ccd497e4Szhanglinjuan prefetcher.io.in <> xbar.io.out.req 47ccd497e4Szhanglinjuan l2cacheIn.req <> prefetcher.io.out 4835377176Szhanglinjuan xbar.io.out.resp <> l2cacheIn.resp 49614aaf64SZihao Yu l2cacheIn 50614aaf64SZihao Yu } else xbar.io.out 5139ac6601SZihao Yu val l2Empty = Wire(Bool()) 52b0cf5de6SZihao Yu l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC) :: Nil, flush = "b00".U, empty = l2Empty, enable = true)( 534cd61964SZihao Yu CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2)) 5435377176Szhanglinjuan io.mem <> l2cacheOut.mem.toAXI4() 5535377176Szhanglinjuan l2cacheOut.coh.resp.ready := true.B 5635377176Szhanglinjuan l2cacheOut.coh.req.valid := false.B 5735377176Szhanglinjuan l2cacheOut.coh.req.bits := DontCare 58eb8bdfa7SZihao Yu } else { 59635253aaSZihao Yu io.mem <> xbar.io.out.toAXI4() 60eb8bdfa7SZihao Yu } 61*1e3fad10SLinJiawei xsCore.io.imem.coh.resp.ready := true.B 62*1e3fad10SLinJiawei xsCore.io.imem.coh.req.valid := false.B 63*1e3fad10SLinJiawei xsCore.io.imem.coh.req.bits := DontCare 64096ea47eSzhanglinjuan 651b2d260fSZihao Yu val addrSpace = List( 661b2d260fSZihao Yu (0x40000000L, 0x08000000L), // external devices 671b2d260fSZihao Yu (0x48000000L, 0x00010000L) // CLINT 681b2d260fSZihao Yu ) 691b2d260fSZihao Yu val mmioXbar = Module(new SimpleBusCrossbar1toN(addrSpace)) 70*1e3fad10SLinJiawei mmioXbar.io.in <> xsCore.io.mmio 71d2d827d9Szhanglinjuan 721b2d260fSZihao Yu val extDev = mmioXbar.io.out(0) 731b2d260fSZihao Yu val clint = Module(new AXI4Timer(sim = !p.FPGAPlatform)) 741b2d260fSZihao Yu clint.io.in <> mmioXbar.io.out(1).toAXI4Lite() 751b2d260fSZihao Yu if (p.FPGAPlatform) io.mmio <> extDev.toAXI4Lite() 761b2d260fSZihao Yu else io.mmio <> extDev 771b2d260fSZihao Yu 781b2d260fSZihao Yu val mtipSync = clint.io.extra.get.mtip 79466eb0a8SZihao Yu val meipSync = RegNext(RegNext(io.meip)) 805d41d760SZihao Yu BoringUtils.addSource(mtipSync, "mtip") 81466eb0a8SZihao Yu BoringUtils.addSource(meipSync, "meip") 82006e1884SZihao Yu}