1006e1884SZihao Yupackage system 2006e1884SZihao Yu 3eb8bdfa7SZihao Yuimport noop._ 4006e1884SZihao Yuimport bus.axi4.{AXI4, AXI4Lite} 58f36f779SZihao Yuimport bus.simplebus._ 6006e1884SZihao Yu 7006e1884SZihao Yuimport chisel3._ 8096ea47eSzhanglinjuanimport chisel3.util._ 9fe820c3dSZihao Yuimport chisel3.util.experimental.BoringUtils 10006e1884SZihao Yu 112f7e16feSZihao Yutrait HasSoCParameter { 122f7e16feSZihao Yu val EnableILA = false 13f1ae1cd3SZihao Yu val HasL2cache = true 142f7e16feSZihao Yu val HasPrefetch = false 15303b861dSZihao Yu} 16303b861dSZihao Yu 17303b861dSZihao Yuclass ILABundle extends Bundle { 18303b861dSZihao Yu val WBUpc = UInt(32.W) 19303b861dSZihao Yu val WBUvalid = UInt(1.W) 20303b861dSZihao Yu val WBUrfWen = UInt(1.W) 21303b861dSZihao Yu val WBUrfDest = UInt(5.W) 22303b861dSZihao Yu val WBUrfData = UInt(64.W) 23303b861dSZihao Yu val InstrCnt = UInt(64.W) 24303b861dSZihao Yu} 25303b861dSZihao Yu 262f7e16feSZihao Yuclass NOOPSoC(implicit val p: NOOPConfig) extends Module with HasSoCParameter { 27006e1884SZihao Yu val io = IO(new Bundle{ 28cdd59e9fSZihao Yu val mem = new AXI4 29ad255e6cSZihao Yu val mmio = (if (p.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC }) 30fe820c3dSZihao Yu val mtip = Input(Bool()) 31466eb0a8SZihao Yu val meip = Input(Bool()) 322f7e16feSZihao Yu val ila = if (p.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None 33006e1884SZihao Yu }) 34006e1884SZihao Yu 35006e1884SZihao Yu val noop = Module(new NOOP) 36096ea47eSzhanglinjuan 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 44eb8bdfa7SZihao Yu if (HasL2cache) { 4535377176Szhanglinjuan val l2cacheOut = Wire(new SimpleBusC) 4635377176Szhanglinjuan if (HasPrefetch) { 47096ea47eSzhanglinjuan val prefetcher = Module(new Prefetcher) 48096ea47eSzhanglinjuan prefetcher.io.in <> noop.io.prefetchReq 49096ea47eSzhanglinjuan val l2cacheIn = Wire(new SimpleBusUC) 50d2d827d9Szhanglinjuan val l2cacheInReqArb = Module(new Arbiter(chiselTypeOf(noop.io.prefetchReq.bits), 2)) 5135377176Szhanglinjuan l2cacheInReqArb.io.in(0) <> xbar.io.out.req 52096ea47eSzhanglinjuan l2cacheInReqArb.io.in(1) <> prefetcher.io.out 53096ea47eSzhanglinjuan l2cacheIn.req <> l2cacheInReqArb.io.out 5435377176Szhanglinjuan xbar.io.out.resp <> l2cacheIn.resp 55*4cd61964SZihao Yu l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC), flush = "b00".U, enable = true)( 56*4cd61964SZihao Yu CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2)) 5735377176Szhanglinjuan } else { 58*4cd61964SZihao Yu l2cacheOut <> Cache(in = xbar.io.out, mmio = 0.U.asTypeOf(new SimpleBusUC), flush = "b00".U, enable = true)( 59*4cd61964SZihao Yu CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2)) 6035377176Szhanglinjuan } 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 6935377176Szhanglinjuan if (!HasPrefetch) { 7035377176Szhanglinjuan noop.io.prefetchReq.ready := true.B 7135377176Szhanglinjuan } 72096ea47eSzhanglinjuan 73635253aaSZihao Yu noop.io.imem.coh.resp.ready := true.B 74635253aaSZihao Yu noop.io.imem.coh.req.valid := false.B 75635253aaSZihao Yu noop.io.imem.coh.req.bits := DontCare 76096ea47eSzhanglinjuan 77ad255e6cSZihao Yu if (p.FPGAPlatform) io.mmio <> noop.io.mmio.toAXI4Lite() 78006e1884SZihao Yu else io.mmio <> noop.io.mmio 79d2d827d9Szhanglinjuan 805d41d760SZihao Yu val mtipSync = RegNext(RegNext(io.mtip)) 81466eb0a8SZihao Yu val meipSync = RegNext(RegNext(io.meip)) 825d41d760SZihao Yu BoringUtils.addSource(mtipSync, "mtip") 83466eb0a8SZihao Yu BoringUtils.addSource(meipSync, "meip") 84303b861dSZihao Yu 85303b861dSZihao Yu // ILA 86303b861dSZihao Yu if (p.FPGAPlatform) { 87303b861dSZihao Yu def BoringUtilsConnect(sink: UInt, id: String) { 88303b861dSZihao Yu val temp = WireInit(0.U(64.W)) 89303b861dSZihao Yu BoringUtils.addSink(temp, id) 90303b861dSZihao Yu sink := temp 91303b861dSZihao Yu } 92303b861dSZihao Yu 93303b861dSZihao Yu val dummy = WireInit(0.U.asTypeOf(new ILABundle)) 94303b861dSZihao Yu val ila = io.ila.getOrElse(dummy) 95303b861dSZihao Yu BoringUtilsConnect(ila.WBUpc ,"ilaWBUpc") 96303b861dSZihao Yu BoringUtilsConnect(ila.WBUvalid ,"ilaWBUvalid") 97303b861dSZihao Yu BoringUtilsConnect(ila.WBUrfWen ,"ilaWBUrfWen") 98303b861dSZihao Yu BoringUtilsConnect(ila.WBUrfDest ,"ilaWBUrfDest") 99303b861dSZihao Yu BoringUtilsConnect(ila.WBUrfData ,"ilaWBUrfData") 100303b861dSZihao Yu BoringUtilsConnect(ila.InstrCnt ,"ilaInstrCnt") 101303b861dSZihao Yu } 102006e1884SZihao Yu} 103