xref: /XiangShan/src/main/scala/xiangshan/XSTileWrap.scala (revision 03a1a638e54b0b04a4d6c88c5f5cbc92c20e76fb)
1/***************************************************************************************
2* Copyright (c) 2024 Beijing Institute of Open Source Chip (BOSC)
3* Copyright (c) 2024 Institute of Computing Technology, Chinese Academy of Sciences
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15***************************************************************************************/
16
17package xiangshan
18
19import chisel3._
20import chisel3.util._
21import org.chipsalliance.cde.config._
22import freechips.rocketchip.diplomacy._
23import freechips.rocketchip.interrupts._
24import freechips.rocketchip.tilelink._
25import freechips.rocketchip.util._
26import system.HasSoCParameter
27import device.IMSICAsync
28import coupledL2.tl2chi.{AsyncPortIO, CHIAsyncBridgeSource, PortIO}
29import utility.sram.SramBroadcastBundle
30import utility.{DFTResetSignals, IntBuffer, ResetGen}
31import xiangshan.backend.trace.TraceCoreInterface
32
33// This module is used for XSNoCTop for async time domain and divide different
34// voltage domain. Everything in this module should be in the core clock domain
35// and higher voltage domain.
36class XSTileWrap()(implicit p: Parameters) extends LazyModule
37  with HasXSParameter
38  with HasSoCParameter
39{
40  override def shouldBeInlined: Boolean = false
41
42  val tile = LazyModule(new XSTile())
43
44  // interrupts sync
45  val clintIntNode = IntIdentityNode()
46  val debugIntNode = IntIdentityNode()
47  val plicIntNode = IntIdentityNode()
48  val beuIntNode = IntIdentityNode()
49  val nmiIntNode = IntIdentityNode()
50  tile.clint_int_node := IntBuffer(3, cdc = true) := clintIntNode
51  tile.debug_int_node := IntBuffer(3, cdc = true) := debugIntNode
52  tile.plic_int_node :*= IntBuffer(3, cdc = true) :*= plicIntNode
53  tile.nmi_int_node := IntBuffer(3, cdc = true) := nmiIntNode
54  beuIntNode := IntBuffer() := tile.beu_int_source
55
56  // seperate DebugModule bus
57  val EnableDMAsync = EnableDMAsyncBridge.isDefined
58  println(s"SeperateDMBus = $SeperateDMBus")
59  println(s"EnableDMAsync = $EnableDMAsync")
60  // asynchronous bridge source node
61  val dmAsyncSourceOpt = Option.when(SeperateDMBus && EnableDMAsync)(LazyModule(new TLAsyncCrossingSource()))
62  dmAsyncSourceOpt.foreach(_.node := tile.sep_dm_opt.get)
63  // synchronous source node
64  val dmSyncSourceOpt = Option.when(SeperateDMBus && !EnableDMAsync)(TLTempNode())
65  dmSyncSourceOpt.foreach(_ := tile.sep_dm_opt.get)
66
67  class XSTileWrapImp(wrapper: LazyModule) extends LazyRawModuleImp(wrapper) {
68    val clock = IO(Input(Clock()))
69    val reset = IO(Input(AsyncReset()))
70    val noc_reset = EnableCHIAsyncBridge.map(_ => IO(Input(AsyncReset())))
71    val soc_reset = IO(Input(AsyncReset()))
72    val io = IO(new Bundle {
73      val hartId = Input(UInt(hartIdLen.W))
74      val msiInfo = Input(ValidIO(UInt(soc.IMSICParams.MSI_INFO_WIDTH.W)))
75      val msiAck = Output(Bool())
76      val reset_vector = Input(UInt(PAddrBits.W))
77      val cpu_halt = Output(Bool())
78      val cpu_crtical_error = Output(Bool())
79      val hartResetReq = Input(Bool())
80      val hartIsInReset = Output(Bool())
81      val traceCoreInterface = new TraceCoreInterface
82      val debugTopDown = new Bundle {
83        val robHeadPaddr = Valid(UInt(PAddrBits.W))
84        val l3MissMatch = Input(Bool())
85      }
86      val l3Miss = Input(Bool())
87      val chi = EnableCHIAsyncBridge match {
88        case Some(param) => new AsyncPortIO(param)
89        case None => new PortIO
90      }
91      val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None
92      val clintTime = EnableClintAsyncBridge match {
93        case Some(param) => Flipped(new AsyncBundle(UInt(64.W), param))
94        case None => Input(ValidIO(UInt(64.W)))
95      }
96      val dft = if(hasMbist) Some(Input(new SramBroadcastBundle)) else None
97      val dft_reset = if(hasMbist) Some(Input(new DFTResetSignals())) else None
98      val l2_flush_en = Option.when(EnablePowerDown) (Output(Bool()))
99      val l2_flush_done = Option.when(EnablePowerDown) (Output(Bool()))
100      val pwrdown_req_n = Option.when(EnablePowerDown) (Input (Bool()))
101      val pwrdown_ack_n = Option.when(EnablePowerDown) (Output (Bool()))
102      val iso_en = Option.when(EnablePowerDown) (Input (Bool()))
103    })
104
105    val reset_sync = withClockAndReset(clock, (reset.asBool || io.hartResetReq).asAsyncReset)(ResetGen(2, io.dft_reset))
106    val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen(2, io.dft_reset)))
107    val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen(2, io.dft_reset))
108
109    // override LazyRawModuleImp's clock and reset
110    childClock := clock
111    childReset := reset_sync
112
113    val imsicAsync = withClockAndReset(clock, reset_sync)(Module(new IMSICAsync()))
114    imsicAsync.i.msiInfo := io.msiInfo
115
116    tile.module.io.hartId := io.hartId
117    tile.module.io.msiInfo := imsicAsync.o.msiInfo
118    tile.module.io.reset_vector := io.reset_vector
119    tile.module.io.dft.zip(io.dft).foreach({case(a, b) => a := b})
120    tile.module.io.dft_reset.zip(io.dft_reset).foreach({case(a, b) => a := b})
121    io.cpu_halt := tile.module.io.cpu_halt
122    io.cpu_crtical_error := tile.module.io.cpu_crtical_error
123    io.msiAck := tile.module.io.msiAck
124    io.hartIsInReset := tile.module.io.hartIsInReset
125    io.traceCoreInterface <> tile.module.io.traceCoreInterface
126    io.debugTopDown <> tile.module.io.debugTopDown
127    tile.module.io.l3Miss := io.l3Miss
128    tile.module.io.nodeID.foreach(_ := io.nodeID.get)
129    io.l2_flush_en.foreach { _ := tile.module.io.l2_flush_en.getOrElse(false.B) }
130    io.l2_flush_done.foreach { _ := tile.module.io.l2_flush_done.getOrElse(false.B) }
131    io.pwrdown_ack_n.foreach { _ := true.B }
132
133    // CLINT Async Queue Sink
134    EnableClintAsyncBridge match {
135      case Some(param) =>
136        val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param)))
137        sink.io.async <> io.clintTime
138        sink.io.deq.ready := true.B
139        tile.module.io.clintTime.valid := sink.io.deq.valid
140        tile.module.io.clintTime.bits := sink.io.deq.bits
141      case None =>
142        tile.module.io.clintTime := io.clintTime
143    }
144
145    // CHI Async Queue Source
146    EnableCHIAsyncBridge match {
147      case Some(param) =>
148        val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param)))
149        source.io.enq <> tile.module.io.chi.get
150        io.chi <> source.io.async
151      case None =>
152        require(enableCHI)
153        io.chi <> tile.module.io.chi.get
154    }
155
156    // Seperate DebugModule TL Async Queue Source
157    if (SeperateDMBus && EnableDMAsync) {
158      dmAsyncSourceOpt.get.module.clock := clock
159      dmAsyncSourceOpt.get.module.reset := soc_reset_sync
160    }
161
162    withClockAndReset(clock, reset_sync) {
163      // Modules are reset one by one
164      // reset ----> SYNC --> XSTile
165      val resetChain = Seq(Seq(tile.module))
166      ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform, io.dft_reset)
167    }
168    dontTouch(io.hartId)
169    dontTouch(io.msiInfo)
170  }
171  lazy val module = new XSTileWrapImp(this)
172}
173