xref: /XiangShan/src/main/scala/xiangshan/XSTileWrap.scala (revision 30f35717e23156cb95b30a36db530384545b48a4)
18537b88aSTang Haojin/***************************************************************************************
26dd2cbeeSTang Haojin* Copyright (c) 2024-2025 Beijing Institute of Open Source Chip (BOSC)
36dd2cbeeSTang Haojin* Copyright (c) 2024-2025 Institute of Computing Technology, Chinese Academy of Sciences
48537b88aSTang Haojin*
58537b88aSTang Haojin* XiangShan is licensed under Mulan PSL v2.
68537b88aSTang Haojin* You can use this software according to the terms and conditions of the Mulan PSL v2.
78537b88aSTang Haojin* You may obtain a copy of Mulan PSL v2 at:
88537b88aSTang Haojin*          http://license.coscl.org.cn/MulanPSL2
98537b88aSTang Haojin*
108537b88aSTang Haojin* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
118537b88aSTang Haojin* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
128537b88aSTang Haojin* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
138537b88aSTang Haojin*
148537b88aSTang Haojin* See the Mulan PSL v2 for more details.
158537b88aSTang Haojin***************************************************************************************/
168537b88aSTang Haojin
178537b88aSTang Haojinpackage xiangshan
188537b88aSTang Haojin
198537b88aSTang Haojinimport chisel3._
208537b88aSTang Haojinimport chisel3.util._
218537b88aSTang Haojinimport org.chipsalliance.cde.config._
228537b88aSTang Haojinimport freechips.rocketchip.diplomacy._
238537b88aSTang Haojinimport freechips.rocketchip.interrupts._
244a699e27Szhanglinjuanimport freechips.rocketchip.tilelink._
258537b88aSTang Haojinimport freechips.rocketchip.util._
268537b88aSTang Haojinimport system.HasSoCParameter
274b2c87baS梁森 Liang Senimport coupledL2.tl2chi.{AsyncPortIO, CHIAsyncBridgeSource, PortIO}
28*30f35717Scz4eimport utility.sram.SramBroadcastBundle
294b2c87baS梁森 Liang Senimport utility.{DFTResetSignals, IntBuffer, ResetGen}
30725e8ddcSchengguanghuiimport xiangshan.backend.trace.TraceCoreInterface
318537b88aSTang Haojin
328537b88aSTang Haojin// This module is used for XSNoCTop for async time domain and divide different
338537b88aSTang Haojin// voltage domain. Everything in this module should be in the core clock domain
348537b88aSTang Haojin// and higher voltage domain.
358537b88aSTang Haojinclass XSTileWrap()(implicit p: Parameters) extends LazyModule
368537b88aSTang Haojin  with HasXSParameter
378537b88aSTang Haojin  with HasSoCParameter
388537b88aSTang Haojin{
398537b88aSTang Haojin  override def shouldBeInlined: Boolean = false
408537b88aSTang Haojin
418537b88aSTang Haojin  val tile = LazyModule(new XSTile())
428537b88aSTang Haojin
438537b88aSTang Haojin  // interrupts sync
448537b88aSTang Haojin  val clintIntNode = IntIdentityNode()
458537b88aSTang Haojin  val debugIntNode = IntIdentityNode()
468537b88aSTang Haojin  val plicIntNode = IntIdentityNode()
477ff4ebdcSTang Haojin  val beuIntNode = IntIdentityNode()
488bc90631SZehao Liu  val nmiIntNode = IntIdentityNode()
497ff4ebdcSTang Haojin  tile.clint_int_node := IntBuffer(3, cdc = true) := clintIntNode
507ff4ebdcSTang Haojin  tile.debug_int_node := IntBuffer(3, cdc = true) := debugIntNode
517ff4ebdcSTang Haojin  tile.plic_int_node :*= IntBuffer(3, cdc = true) :*= plicIntNode
528bc90631SZehao Liu  tile.nmi_int_node := IntBuffer(3, cdc = true) := nmiIntNode
537ff4ebdcSTang Haojin  beuIntNode := IntBuffer() := tile.beu_int_source
544a699e27Szhanglinjuan
5516ae9ddcSTang Haojin  // seperate TL bus
5616ae9ddcSTang Haojin  println(s"SeperateTLBus = $SeperateTLBus")
5716ae9ddcSTang Haojin  println(s"EnableSeperateTLAsync = $EnableSeperateTLAsync")
584a699e27Szhanglinjuan  // asynchronous bridge source node
5916ae9ddcSTang Haojin  val tlAsyncSourceOpt = Option.when(SeperateTLBus && EnableSeperateTLAsync)(LazyModule(new TLAsyncCrossingSource()))
6016ae9ddcSTang Haojin  tlAsyncSourceOpt.foreach(_.node := tile.sep_tl_opt.get)
614a699e27Szhanglinjuan  // synchronous source node
6216ae9ddcSTang Haojin  val tlSyncSourceOpt = Option.when(SeperateTLBus && !EnableSeperateTLAsync)(TLTempNode())
6316ae9ddcSTang Haojin  tlSyncSourceOpt.foreach(_ := tile.sep_tl_opt.get)
644a699e27Szhanglinjuan
657ff4ebdcSTang Haojin  class XSTileWrapImp(wrapper: LazyModule) extends LazyRawModuleImp(wrapper) {
667ff4ebdcSTang Haojin    val clock = IO(Input(Clock()))
677ff4ebdcSTang Haojin    val reset = IO(Input(AsyncReset()))
687ff4ebdcSTang Haojin    val noc_reset = EnableCHIAsyncBridge.map(_ => IO(Input(AsyncReset())))
697ff4ebdcSTang Haojin    val soc_reset = IO(Input(AsyncReset()))
708537b88aSTang Haojin    val io = IO(new Bundle {
718537b88aSTang Haojin      val hartId = Input(UInt(hartIdLen.W))
728cfc24b2STang Haojin      val msiInfo = Input(ValidIO(UInt(soc.IMSICParams.MSI_INFO_WIDTH.W)))
738cfc24b2STang Haojin      val msiAck = Output(Bool())
748537b88aSTang Haojin      val reset_vector = Input(UInt(PAddrBits.W))
758537b88aSTang Haojin      val cpu_halt = Output(Bool())
7685a8d7caSZehao Liu      val cpu_crtical_error = Output(Bool())
773a3744e4Schengguanghui      val hartResetReq = Input(Bool())
78b30cb8bfSGuanghui Cheng      val hartIsInReset = Output(Bool())
79725e8ddcSchengguanghui      val traceCoreInterface = new TraceCoreInterface
808537b88aSTang Haojin      val debugTopDown = new Bundle {
818537b88aSTang Haojin        val robHeadPaddr = Valid(UInt(PAddrBits.W))
828537b88aSTang Haojin        val l3MissMatch = Input(Bool())
838537b88aSTang Haojin      }
84e836c770SZhaoyang You      val l3Miss = Input(Bool())
85e2725c9eSzhanglinjuan      val chi = EnableCHIAsyncBridge match {
867ff4ebdcSTang Haojin        case Some(param) => new AsyncPortIO(param)
877ff4ebdcSTang Haojin        case None => new PortIO
88e2725c9eSzhanglinjuan      }
898537b88aSTang Haojin      val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None
90e2725c9eSzhanglinjuan      val clintTime = EnableClintAsyncBridge match {
917ff4ebdcSTang Haojin        case Some(param) => Flipped(new AsyncBundle(UInt(64.W), param))
927ff4ebdcSTang Haojin        case None => Input(ValidIO(UInt(64.W)))
93e2725c9eSzhanglinjuan      }
94*30f35717Scz4e      val dft = Option.when(hasDFT)(Input(new SramBroadcastBundle))
95*30f35717Scz4e      val dft_reset = Option.when(hasMbist)(Input(new DFTResetSignals()))
964d7fbe77Syulightenyu      val l2_flush_en = Option.when(EnablePowerDown) (Output(Bool()))
974d7fbe77Syulightenyu      val l2_flush_done = Option.when(EnablePowerDown) (Output(Bool()))
984d7fbe77Syulightenyu      val pwrdown_req_n = Option.when(EnablePowerDown) (Input (Bool()))
994d7fbe77Syulightenyu      val pwrdown_ack_n = Option.when(EnablePowerDown) (Output (Bool()))
1004d7fbe77Syulightenyu      val iso_en = Option.when(EnablePowerDown) (Input (Bool()))
1018537b88aSTang Haojin    })
1028537b88aSTang Haojin
103*30f35717Scz4e    val reset_sync = withClockAndReset(clock, (reset.asBool || io.hartResetReq).asAsyncReset)(ResetGen(2, io.dft_reset))
104*30f35717Scz4e    val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen(2, io.dft_reset)))
105*30f35717Scz4e    val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen(2, io.dft_reset))
1067ff4ebdcSTang Haojin
1077ff4ebdcSTang Haojin    // override LazyRawModuleImp's clock and reset
1087ff4ebdcSTang Haojin    childClock := clock
1097ff4ebdcSTang Haojin    childReset := reset_sync
1107ff4ebdcSTang Haojin
1118537b88aSTang Haojin    tile.module.io.hartId := io.hartId
1126dd2cbeeSTang Haojin    tile.module.io.msiInfo := io.msiInfo
1138537b88aSTang Haojin    tile.module.io.reset_vector := io.reset_vector
114*30f35717Scz4e    tile.module.io.dft.zip(io.dft).foreach({ case (a, b) => a := b })
115*30f35717Scz4e    tile.module.io.dft_reset.zip(io.dft_reset).foreach({ case (a, b) => a := b })
1168537b88aSTang Haojin    io.cpu_halt := tile.module.io.cpu_halt
11785a8d7caSZehao Liu    io.cpu_crtical_error := tile.module.io.cpu_crtical_error
1188cfc24b2STang Haojin    io.msiAck := tile.module.io.msiAck
119b30cb8bfSGuanghui Cheng    io.hartIsInReset := tile.module.io.hartIsInReset
120725e8ddcSchengguanghui    io.traceCoreInterface <> tile.module.io.traceCoreInterface
1218537b88aSTang Haojin    io.debugTopDown <> tile.module.io.debugTopDown
122e836c770SZhaoyang You    tile.module.io.l3Miss := io.l3Miss
1238537b88aSTang Haojin    tile.module.io.nodeID.foreach(_ := io.nodeID.get)
1244d7fbe77Syulightenyu    io.l2_flush_en.foreach { _ := tile.module.io.l2_flush_en.getOrElse(false.B) }
1254d7fbe77Syulightenyu    io.l2_flush_done.foreach { _ := tile.module.io.l2_flush_done.getOrElse(false.B) }
1264d7fbe77Syulightenyu    io.pwrdown_ack_n.foreach { _ := true.B }
1278537b88aSTang Haojin
1288537b88aSTang Haojin    // CLINT Async Queue Sink
129e2725c9eSzhanglinjuan    EnableClintAsyncBridge match {
130e2725c9eSzhanglinjuan      case Some(param) =>
1317ff4ebdcSTang Haojin        val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param)))
1327ff4ebdcSTang Haojin        sink.io.async <> io.clintTime
133e2725c9eSzhanglinjuan        sink.io.deq.ready := true.B
134e2725c9eSzhanglinjuan        tile.module.io.clintTime.valid := sink.io.deq.valid
135e2725c9eSzhanglinjuan        tile.module.io.clintTime.bits := sink.io.deq.bits
136e2725c9eSzhanglinjuan      case None =>
1377ff4ebdcSTang Haojin        tile.module.io.clintTime := io.clintTime
138e2725c9eSzhanglinjuan    }
1398537b88aSTang Haojin
1408537b88aSTang Haojin    // CHI Async Queue Source
141e2725c9eSzhanglinjuan    EnableCHIAsyncBridge match {
142e2725c9eSzhanglinjuan      case Some(param) =>
1437ff4ebdcSTang Haojin        val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param)))
144e2725c9eSzhanglinjuan        source.io.enq <> tile.module.io.chi.get
1457ff4ebdcSTang Haojin        io.chi <> source.io.async
146e2725c9eSzhanglinjuan      case None =>
147e2725c9eSzhanglinjuan        require(enableCHI)
1487ff4ebdcSTang Haojin        io.chi <> tile.module.io.chi.get
1498537b88aSTang Haojin    }
1508537b88aSTang Haojin
1514a699e27Szhanglinjuan    // Seperate DebugModule TL Async Queue Source
15216ae9ddcSTang Haojin    if (SeperateTLBus && EnableSeperateTLAsync) {
15316ae9ddcSTang Haojin      tlAsyncSourceOpt.get.module.clock := clock
15416ae9ddcSTang Haojin      tlAsyncSourceOpt.get.module.reset := soc_reset_sync
1554a699e27Szhanglinjuan    }
1564a699e27Szhanglinjuan
1577ff4ebdcSTang Haojin    withClockAndReset(clock, reset_sync) {
1587ff4ebdcSTang Haojin      // Modules are reset one by one
1597ff4ebdcSTang Haojin      // reset ----> SYNC --> XSTile
1607ff4ebdcSTang Haojin      val resetChain = Seq(Seq(tile.module))
161*30f35717Scz4e      ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform, io.dft_reset)
1627ff4ebdcSTang Haojin    }
1638537b88aSTang Haojin    dontTouch(io.hartId)
1648537b88aSTang Haojin    dontTouch(io.msiInfo)
1658537b88aSTang Haojin  }
1668537b88aSTang Haojin  lazy val module = new XSTileWrapImp(this)
1678537b88aSTang Haojin}
168