xref: /XiangShan/src/main/scala/xiangshan/XSTileWrap.scala (revision 529b1cfdb56763d8c094232c4acac6d4a784b64f)
18537b88aSTang Haojin/***************************************************************************************
28537b88aSTang Haojin* Copyright (c) 2024 Beijing Institute of Open Source Chip (BOSC)
38537b88aSTang Haojin* Copyright (c) 2024 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
27*529b1cfdSTang Haojinimport device.{IMSICAsync, MsiInfoBundle}
284b2c87baS梁森 Liang Senimport coupledL2.tl2chi.{AsyncPortIO, CHIAsyncBridgeSource, PortIO}
294b2c87baS梁森 Liang Senimport utility.sram.SramBroadcastBundle
304b2c87baS梁森 Liang Senimport utility.{DFTResetSignals, IntBuffer, ResetGen}
31725e8ddcSchengguanghuiimport xiangshan.backend.trace.TraceCoreInterface
328537b88aSTang Haojin
338537b88aSTang Haojin// This module is used for XSNoCTop for async time domain and divide different
348537b88aSTang Haojin// voltage domain. Everything in this module should be in the core clock domain
358537b88aSTang Haojin// and higher voltage domain.
368537b88aSTang Haojinclass XSTileWrap()(implicit p: Parameters) extends LazyModule
378537b88aSTang Haojin  with HasXSParameter
388537b88aSTang Haojin  with HasSoCParameter
398537b88aSTang Haojin{
408537b88aSTang Haojin  override def shouldBeInlined: Boolean = false
418537b88aSTang Haojin
428537b88aSTang Haojin  val tile = LazyModule(new XSTile())
438537b88aSTang Haojin
448537b88aSTang Haojin  // interrupts sync
458537b88aSTang Haojin  val clintIntNode = IntIdentityNode()
468537b88aSTang Haojin  val debugIntNode = IntIdentityNode()
478537b88aSTang Haojin  val plicIntNode = IntIdentityNode()
487ff4ebdcSTang Haojin  val beuIntNode = IntIdentityNode()
498bc90631SZehao Liu  val nmiIntNode = IntIdentityNode()
507ff4ebdcSTang Haojin  tile.clint_int_node := IntBuffer(3, cdc = true) := clintIntNode
517ff4ebdcSTang Haojin  tile.debug_int_node := IntBuffer(3, cdc = true) := debugIntNode
527ff4ebdcSTang Haojin  tile.plic_int_node :*= IntBuffer(3, cdc = true) :*= plicIntNode
538bc90631SZehao Liu  tile.nmi_int_node := IntBuffer(3, cdc = true) := nmiIntNode
547ff4ebdcSTang Haojin  beuIntNode := IntBuffer() := tile.beu_int_source
554a699e27Szhanglinjuan
564a699e27Szhanglinjuan  // seperate DebugModule bus
574a699e27Szhanglinjuan  val EnableDMAsync = EnableDMAsyncBridge.isDefined
584a699e27Szhanglinjuan  println(s"SeperateDMBus = $SeperateDMBus")
594a699e27Szhanglinjuan  println(s"EnableDMAsync = $EnableDMAsync")
604a699e27Szhanglinjuan  // asynchronous bridge source node
614a699e27Szhanglinjuan  val dmAsyncSourceOpt = Option.when(SeperateDMBus && EnableDMAsync)(LazyModule(new TLAsyncCrossingSource()))
624a699e27Szhanglinjuan  dmAsyncSourceOpt.foreach(_.node := tile.sep_dm_opt.get)
634a699e27Szhanglinjuan  // synchronous source node
644a699e27Szhanglinjuan  val dmSyncSourceOpt = Option.when(SeperateDMBus && !EnableDMAsync)(TLTempNode())
654a699e27Szhanglinjuan  dmSyncSourceOpt.foreach(_ := tile.sep_dm_opt.get)
664a699e27Szhanglinjuan
677ff4ebdcSTang Haojin  class XSTileWrapImp(wrapper: LazyModule) extends LazyRawModuleImp(wrapper) {
687ff4ebdcSTang Haojin    val clock = IO(Input(Clock()))
697ff4ebdcSTang Haojin    val reset = IO(Input(AsyncReset()))
707ff4ebdcSTang Haojin    val noc_reset = EnableCHIAsyncBridge.map(_ => IO(Input(AsyncReset())))
717ff4ebdcSTang Haojin    val soc_reset = IO(Input(AsyncReset()))
728537b88aSTang Haojin    val io = IO(new Bundle {
738537b88aSTang Haojin      val hartId = Input(UInt(hartIdLen.W))
74*529b1cfdSTang Haojin      val msiInfo = Input(ValidIO(new MsiInfoBundle))
758537b88aSTang Haojin      val reset_vector = Input(UInt(PAddrBits.W))
768537b88aSTang Haojin      val cpu_halt = Output(Bool())
7785a8d7caSZehao Liu      val cpu_crtical_error = Output(Bool())
783a3744e4Schengguanghui      val hartResetReq = Input(Bool())
79b30cb8bfSGuanghui Cheng      val hartIsInReset = Output(Bool())
80725e8ddcSchengguanghui      val traceCoreInterface = new TraceCoreInterface
818537b88aSTang Haojin      val debugTopDown = new Bundle {
828537b88aSTang Haojin        val robHeadPaddr = Valid(UInt(PAddrBits.W))
838537b88aSTang Haojin        val l3MissMatch = Input(Bool())
848537b88aSTang Haojin      }
85e836c770SZhaoyang You      val l3Miss = Input(Bool())
86e2725c9eSzhanglinjuan      val chi = EnableCHIAsyncBridge match {
877ff4ebdcSTang Haojin        case Some(param) => new AsyncPortIO(param)
887ff4ebdcSTang Haojin        case None => new PortIO
89e2725c9eSzhanglinjuan      }
908537b88aSTang Haojin      val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None
91e2725c9eSzhanglinjuan      val clintTime = EnableClintAsyncBridge match {
927ff4ebdcSTang Haojin        case Some(param) => Flipped(new AsyncBundle(UInt(64.W), param))
937ff4ebdcSTang Haojin        case None => Input(ValidIO(UInt(64.W)))
94e2725c9eSzhanglinjuan      }
954b2c87baS梁森 Liang Sen      val dft = if(hasMbist) Some(Input(new SramBroadcastBundle)) else None
964b2c87baS梁森 Liang Sen      val dft_reset = if(hasMbist) Some(Input(new DFTResetSignals())) else None
974d7fbe77Syulightenyu      val l2_flush_en = Option.when(EnablePowerDown) (Output(Bool()))
984d7fbe77Syulightenyu      val l2_flush_done = Option.when(EnablePowerDown) (Output(Bool()))
994d7fbe77Syulightenyu      val pwrdown_req_n = Option.when(EnablePowerDown) (Input (Bool()))
1004d7fbe77Syulightenyu      val pwrdown_ack_n = Option.when(EnablePowerDown) (Output (Bool()))
1014d7fbe77Syulightenyu      val iso_en = Option.when(EnablePowerDown) (Input (Bool()))
1028537b88aSTang Haojin    })
1038537b88aSTang Haojin
1044b2c87baS梁森 Liang Sen    val reset_sync = withClockAndReset(clock, (reset.asBool || io.hartResetReq).asAsyncReset)(ResetGen(2, io.dft_reset))
1054b2c87baS梁森 Liang Sen    val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen(2, io.dft_reset)))
1064b2c87baS梁森 Liang Sen    val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen(2, io.dft_reset))
1077ff4ebdcSTang Haojin
1087ff4ebdcSTang Haojin    // override LazyRawModuleImp's clock and reset
1097ff4ebdcSTang Haojin    childClock := clock
1107ff4ebdcSTang Haojin    childReset := reset_sync
1117ff4ebdcSTang Haojin
1127ff4ebdcSTang Haojin    val imsicAsync = withClockAndReset(clock, reset_sync)(Module(new IMSICAsync()))
1138537b88aSTang Haojin    imsicAsync.i.msiInfo := io.msiInfo
1148537b88aSTang Haojin
1158537b88aSTang Haojin    tile.module.io.hartId := io.hartId
1168537b88aSTang Haojin    tile.module.io.msiInfo := imsicAsync.o.msiInfo
1178537b88aSTang Haojin    tile.module.io.reset_vector := io.reset_vector
1184b2c87baS梁森 Liang Sen    tile.module.io.dft.zip(io.dft).foreach({case(a, b) => a := b})
1194b2c87baS梁森 Liang Sen    tile.module.io.dft_reset.zip(io.dft_reset).foreach({case(a, b) => a := b})
1208537b88aSTang Haojin    io.cpu_halt := tile.module.io.cpu_halt
12185a8d7caSZehao Liu    io.cpu_crtical_error := tile.module.io.cpu_crtical_error
122b30cb8bfSGuanghui Cheng    io.hartIsInReset := tile.module.io.hartIsInReset
123725e8ddcSchengguanghui    io.traceCoreInterface <> tile.module.io.traceCoreInterface
1248537b88aSTang Haojin    io.debugTopDown <> tile.module.io.debugTopDown
125e836c770SZhaoyang You    tile.module.io.l3Miss := io.l3Miss
1268537b88aSTang Haojin    tile.module.io.nodeID.foreach(_ := io.nodeID.get)
1274d7fbe77Syulightenyu    io.l2_flush_en.foreach { _ := tile.module.io.l2_flush_en.getOrElse(false.B) }
1284d7fbe77Syulightenyu    io.l2_flush_done.foreach { _ := tile.module.io.l2_flush_done.getOrElse(false.B) }
1294d7fbe77Syulightenyu    io.pwrdown_ack_n.foreach { _ := true.B }
1308537b88aSTang Haojin
1318537b88aSTang Haojin    // CLINT Async Queue Sink
132e2725c9eSzhanglinjuan    EnableClintAsyncBridge match {
133e2725c9eSzhanglinjuan      case Some(param) =>
1347ff4ebdcSTang Haojin        val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param)))
1357ff4ebdcSTang Haojin        sink.io.async <> io.clintTime
136e2725c9eSzhanglinjuan        sink.io.deq.ready := true.B
137e2725c9eSzhanglinjuan        tile.module.io.clintTime.valid := sink.io.deq.valid
138e2725c9eSzhanglinjuan        tile.module.io.clintTime.bits := sink.io.deq.bits
139e2725c9eSzhanglinjuan      case None =>
1407ff4ebdcSTang Haojin        tile.module.io.clintTime := io.clintTime
141e2725c9eSzhanglinjuan    }
1428537b88aSTang Haojin
1438537b88aSTang Haojin    // CHI Async Queue Source
144e2725c9eSzhanglinjuan    EnableCHIAsyncBridge match {
145e2725c9eSzhanglinjuan      case Some(param) =>
1467ff4ebdcSTang Haojin        val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param)))
147e2725c9eSzhanglinjuan        source.io.enq <> tile.module.io.chi.get
1487ff4ebdcSTang Haojin        io.chi <> source.io.async
149e2725c9eSzhanglinjuan      case None =>
150e2725c9eSzhanglinjuan        require(enableCHI)
1517ff4ebdcSTang Haojin        io.chi <> tile.module.io.chi.get
1528537b88aSTang Haojin    }
1538537b88aSTang Haojin
1544a699e27Szhanglinjuan    // Seperate DebugModule TL Async Queue Source
1554a699e27Szhanglinjuan    if (SeperateDMBus && EnableDMAsync) {
1564a699e27Szhanglinjuan      dmAsyncSourceOpt.get.module.clock := clock
1574a699e27Szhanglinjuan      dmAsyncSourceOpt.get.module.reset := soc_reset_sync
1584a699e27Szhanglinjuan    }
1594a699e27Szhanglinjuan
1607ff4ebdcSTang Haojin    withClockAndReset(clock, reset_sync) {
1617ff4ebdcSTang Haojin      // Modules are reset one by one
1627ff4ebdcSTang Haojin      // reset ----> SYNC --> XSTile
1637ff4ebdcSTang Haojin      val resetChain = Seq(Seq(tile.module))
1644b2c87baS梁森 Liang Sen      ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform, io.dft_reset)
1657ff4ebdcSTang Haojin    }
1668537b88aSTang Haojin    dontTouch(io.hartId)
1678537b88aSTang Haojin    dontTouch(io.msiInfo)
1688537b88aSTang Haojin  }
1698537b88aSTang Haojin  lazy val module = new XSTileWrapImp(this)
1708537b88aSTang Haojin}
171