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 dma = xsCore.dma 47 val extDev = TLIdentityNode() 48 49 private val mmioXbar = TLXbar() 50 private val clint = LazyModule(new TLTimer( 51 Seq(AddressSet(0x38000000L, 0x0000ffffL)), 52 sim = !env.FPGAPlatform 53 )) 54 55 mmioXbar := 56 TLBuffer() := 57 DebugIdentityNode() := 58 xsCore.mmio 59 60 clint.node := 61 mmioXbar 62 63 extDev := 64 mmioXbar 65 66 lazy val module = new LazyModuleImp(this){ 67 val io = IO(new Bundle{ 68 val meip = Input(Bool()) 69 val ila = if(env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None 70 }) 71 xsCore.module.io.externalInterrupt.mtip := clint.module.io.mtip 72 xsCore.module.io.externalInterrupt.msip := clint.module.io.msip 73 xsCore.module.io.externalInterrupt.meip := RegNext(RegNext(io.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