1package system 2 3import noop._ 4import bus.axi4.{AXI4, AXI4Lite} 5import bus.simplebus._ 6 7import chisel3._ 8import chisel3.util._ 9import chisel3.util.experimental.BoringUtils 10 11trait HasSoCParameter { 12 val EnableILA = false 13 val HasL2cache = true 14 val HasPrefetch = true 15} 16 17class ILABundle extends Bundle { 18 val WBUpc = UInt(32.W) 19 val WBUvalid = UInt(1.W) 20 val WBUrfWen = UInt(1.W) 21 val WBUrfDest = UInt(5.W) 22 val WBUrfData = UInt(64.W) 23 val InstrCnt = UInt(64.W) 24} 25 26class NOOPSoC(implicit val p: NOOPConfig) extends Module with HasSoCParameter { 27 val io = IO(new Bundle{ 28 val mem = new AXI4 29 val mmio = (if (p.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC }) 30 val frontend = Flipped(new AXI4) 31 val mtip = Input(Bool()) 32 val meip = Input(Bool()) 33 val ila = if (p.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None 34 }) 35 36 val noop = Module(new NOOP) 37 val cohMg = Module(new CoherenceManager) 38 val xbar = Module(new SimpleBusCrossbarNto1(2)) 39 cohMg.io.in <> noop.io.imem.mem 40 noop.io.dmem.coh <> cohMg.io.out.coh 41 xbar.io.in(0) <> cohMg.io.out.mem 42 xbar.io.in(1) <> noop.io.dmem.mem 43 44 val axi2sb = Module(new AXI42SimpleBusConverter()) 45 axi2sb.io.in <> io.frontend 46 noop.io.frontend <> axi2sb.io.out 47 48 if (HasL2cache) { 49 val l2cacheOut = Wire(new SimpleBusC) 50 val l2cacheIn = if (HasPrefetch) { 51 val prefetcher = Module(new Prefetcher) 52 val l2cacheIn = Wire(new SimpleBusUC) 53 prefetcher.io.in <> xbar.io.out.req 54 l2cacheIn.req <> prefetcher.io.out 55 xbar.io.out.resp <> l2cacheIn.resp 56 l2cacheIn 57 } else xbar.io.out 58 val l2Empty = Wire(Bool()) 59 l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC) :: Nil, flush = "b00".U, empty = l2Empty, enable = true)( 60 CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2)) 61 io.mem <> l2cacheOut.mem.toAXI4() 62 l2cacheOut.coh.resp.ready := true.B 63 l2cacheOut.coh.req.valid := false.B 64 l2cacheOut.coh.req.bits := DontCare 65 } else { 66 io.mem <> xbar.io.out.toAXI4() 67 } 68 69 noop.io.imem.coh.resp.ready := true.B 70 noop.io.imem.coh.req.valid := false.B 71 noop.io.imem.coh.req.bits := DontCare 72 73 if (p.FPGAPlatform) io.mmio <> noop.io.mmio.toAXI4Lite() 74 else io.mmio <> noop.io.mmio 75 76 val mtipSync = RegNext(RegNext(io.mtip)) 77 val meipSync = RegNext(RegNext(io.meip)) 78 BoringUtils.addSource(mtipSync, "mtip") 79 BoringUtils.addSource(meipSync, "meip") 80 81 // ILA 82 if (p.FPGAPlatform) { 83 def BoringUtilsConnect(sink: UInt, id: String) { 84 val temp = WireInit(0.U(64.W)) 85 BoringUtils.addSink(temp, id) 86 sink := temp 87 } 88 89 val dummy = WireInit(0.U.asTypeOf(new ILABundle)) 90 val ila = io.ila.getOrElse(dummy) 91 BoringUtilsConnect(ila.WBUpc ,"ilaWBUpc") 92 BoringUtilsConnect(ila.WBUvalid ,"ilaWBUvalid") 93 BoringUtilsConnect(ila.WBUrfWen ,"ilaWBUrfWen") 94 BoringUtilsConnect(ila.WBUrfDest ,"ilaWBUrfDest") 95 BoringUtilsConnect(ila.WBUrfData ,"ilaWBUrfData") 96 BoringUtilsConnect(ila.InstrCnt ,"ilaInstrCnt") 97 } 98} 99