xref: /XiangShan/src/main/scala/xiangshan/XSTile.scala (revision c3abb8b6b92c14ec0f3dbbac60a8caa531994a95)
1package xiangshan
2
3import chisel3._
4import chipsalliance.rocketchip.config.{Config, Parameters}
5import chisel3.util.{Valid, ValidIO}
6import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp, LazyModuleImpLike}
7import freechips.rocketchip.diplomaticobjectmodel.logicaltree.GenericLogicalTreeNode
8import freechips.rocketchip.interrupts.{IntSinkNode, IntSinkPortParameters, IntSinkPortSimple}
9import freechips.rocketchip.tile.{BusErrorUnit, BusErrorUnitParams, BusErrors}
10import freechips.rocketchip.tilelink.{BankBinder, TLBuffer, TLIdentityNode, TLTempNode, TLXbar}
11import huancun.debug.TLLogger
12import huancun.{HCCacheParamsKey, HuanCun}
13import system.HasSoCParameter
14import top.BusPerfMonitor
15import utils.ResetGen
16
17class L1CacheErrorInfo(implicit val p: Parameters) extends Bundle with HasSoCParameter {
18  val paddr = Valid(UInt(soc.PAddrBits.W))
19  // for now, we only detect ecc
20  val ecc_error = Valid(Bool())
21}
22
23class XSL1BusErrors()(implicit val p: Parameters) extends BusErrors {
24  val icache = new L1CacheErrorInfo
25  val dcache = new L1CacheErrorInfo
26
27  override def toErrorList: List[Option[(ValidIO[UInt], String, String)]] =
28    List(
29      Some(icache.paddr, s"IBUS", s"Icache bus error"),
30      Some(icache.ecc_error, s"I_ECC", s"Icache ecc error"),
31      Some(dcache.paddr, s"DBUS", s"Dcache bus error"),
32      Some(dcache.ecc_error, s"D_ECC", s"Dcache ecc error")
33    )
34}
35
36/**
37  *   XSTileMisc contains every module except Core and L2 Cache
38  */
39class XSTileMisc()(implicit p: Parameters) extends LazyModule
40  with HasXSParameter
41  with HasSoCParameter
42{
43  val l1_xbar = TLXbar()
44  val mmio_xbar = TLXbar()
45  val memory_port = TLIdentityNode()
46  val beu = LazyModule(new BusErrorUnit(
47    new XSL1BusErrors(), BusErrorUnitParams(0x38010000), new GenericLogicalTreeNode
48  ))
49  val busPMU = BusPerfMonitor(enable = !debugOpts.FPGAPlatform)
50  val l1d_logger = TLLogger(s"L2_L1D_$hardId", !debugOpts.FPGAPlatform)
51  val l2_binder = coreParams.L2CacheParamsOpt.map(_ => BankBinder(coreParams.L2NBanks, 64))
52
53  val i_mmio_port = TLTempNode()
54  val d_mmio_port = TLTempNode()
55
56  busPMU := l1d_logger
57  l1_xbar :=* busPMU
58
59  l2_binder match {
60    case Some(binder) =>
61      memory_port :=* binder
62    case None =>
63      memory_port := l1_xbar
64  }
65
66  mmio_xbar := TLBuffer() := i_mmio_port
67  mmio_xbar := TLBuffer() := d_mmio_port
68  beu.node := TLBuffer() := mmio_xbar
69
70  lazy val module = new LazyModuleImp(this){
71    val beu_errors = IO(Input(chiselTypeOf(beu.module.io.errors)))
72    beu.module.io.errors <> beu_errors
73  }
74}
75
76class XSTile()(implicit p: Parameters) extends LazyModule
77  with HasXSParameter
78  with HasSoCParameter
79{
80  private val core = LazyModule(new XSCore())
81  private val misc = LazyModule(new XSTileMisc())
82  private val l2cache = coreParams.L2CacheParamsOpt.map(l2param =>
83    LazyModule(new HuanCun()(new Config((_, _, _) => {
84      case HCCacheParamsKey => l2param
85    })))
86  )
87
88  // public ports
89  val memory_port = misc.memory_port
90  val uncache = misc.mmio_xbar
91  val clint_int_sink = core.clint_int_sink
92  val plic_int_sink = core.plic_int_sink
93  val debug_int_sink = core.debug_int_sink
94  val beu_int_source = misc.beu.intNode
95
96  if (coreParams.dcacheParametersOpt.nonEmpty) {
97    misc.l1d_logger := core.memBlock.dcache.clientNode
98  }
99  misc.busPMU := TLLogger(s"L2_L1I_$hardId", !debugOpts.FPGAPlatform) := core.frontend.icache.clientNode
100  if (!coreParams.softPTW) {
101    misc.busPMU := TLLogger(s"L2_PTW_$hardId", !debugOpts.FPGAPlatform) := core.ptw.node
102  }
103  l2cache match {
104    case Some(l2) =>
105      misc.l2_binder.get :*= l2.node :*= misc.l1_xbar
106    case None =>
107  }
108
109  misc.i_mmio_port := core.frontend.instrUncache.clientNode
110  misc.d_mmio_port := core.memBlock.uncache.clientNode
111
112  lazy val module = new LazyModuleImp(this){
113    val io = IO(new Bundle {
114      val hartId = Input(UInt(64.W))
115      val reset = Input(Bool())
116    })
117
118    core.module.io.hartId := io.hartId
119
120    misc.module.beu_errors <> core.module.io.beu_errors
121
122    // Modules are reset one by one
123    // io_reset ----
124    //             |
125    //             v
126    // reset ----> OR_SYNC --> {Misc, L2 Cache, Cores}
127    val l2cacheMod = if (l2cache.isDefined) Seq(l2cache.get.module) else Seq()
128    val resetChain = Seq(
129      Seq(misc.module, core.module) ++ l2cacheMod
130    )
131    ResetGen(resetChain, reset.asBool || io.reset, !debugOpts.FPGAPlatform)
132  }
133}
134