1/*************************************************************************************** 2* Copyright (c) 2024-2025 Beijing Institute of Open Source Chip (BOSC) 3* Copyright (c) 2024-2025 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 coupledL2.tl2chi.{AsyncPortIO, CHIAsyncBridgeSource, PortIO} 28import utility.sram.{SramBroadcastBundle, SramMbistBundle} 29import utility.{DFTResetSignals, IntBuffer, ResetGen} 30import xiangshan.backend.trace.TraceCoreInterface 31 32// This module is used for XSNoCTop for async time domain and divide different 33// voltage domain. Everything in this module should be in the core clock domain 34// and higher voltage domain. 35class XSTileWrap()(implicit p: Parameters) extends LazyModule 36 with HasXSParameter 37 with HasSoCParameter 38{ 39 override def shouldBeInlined: Boolean = false 40 41 val tile = LazyModule(new XSTile()) 42 43 // interrupts sync 44 val clintIntNode = IntIdentityNode() 45 val debugIntNode = IntIdentityNode() 46 val plicIntNode = IntIdentityNode() 47 val beuIntNode = IntIdentityNode() 48 val nmiIntNode = IntIdentityNode() 49 tile.clint_int_node := IntBuffer(3, cdc = true) := clintIntNode 50 tile.debug_int_node := IntBuffer(3, cdc = true) := debugIntNode 51 tile.plic_int_node :*= IntBuffer(3, cdc = true) :*= plicIntNode 52 tile.nmi_int_node := IntBuffer(3, cdc = true) := nmiIntNode 53 beuIntNode := IntBuffer() := tile.beu_int_source 54 55 // seperate TL bus 56 println(s"SeperateTLBus = $SeperateTLBus") 57 println(s"EnableSeperateTLAsync = $EnableSeperateTLAsync") 58 // asynchronous bridge source node 59 val tlAsyncSourceOpt = Option.when(SeperateTLBus && EnableSeperateTLAsync)(LazyModule(new TLAsyncCrossingSource())) 60 tlAsyncSourceOpt.foreach(_.node := tile.sep_tl_opt.get) 61 // synchronous source node 62 val tlSyncSourceOpt = Option.when(SeperateTLBus && !EnableSeperateTLAsync)(TLTempNode()) 63 tlSyncSourceOpt.foreach(_ := tile.sep_tl_opt.get) 64 65 class XSTileWrapImp(wrapper: LazyModule) extends LazyRawModuleImp(wrapper) { 66 val clock = IO(Input(Clock())) 67 val reset = IO(Input(AsyncReset())) 68 val noc_reset = EnableCHIAsyncBridge.map(_ => IO(Input(AsyncReset()))) 69 val soc_reset = IO(Input(AsyncReset())) 70 val io = IO(new Bundle { 71 val hartId = Input(UInt(hartIdLen.W)) 72 val msiInfo = Input(ValidIO(UInt(soc.IMSICParams.MSI_INFO_WIDTH.W))) 73 val msiAck = Output(Bool()) 74 val reset_vector = Input(UInt(PAddrBits.W)) 75 val cpu_halt = Output(Bool()) 76 val cpu_crtical_error = Output(Bool()) 77 val hartResetReq = Input(Bool()) 78 val hartIsInReset = Output(Bool()) 79 val traceCoreInterface = new TraceCoreInterface 80 val debugTopDown = new Bundle { 81 val robHeadPaddr = Valid(UInt(PAddrBits.W)) 82 val l3MissMatch = Input(Bool()) 83 } 84 val l3Miss = Input(Bool()) 85 val chi = EnableCHIAsyncBridge match { 86 case Some(param) => new AsyncPortIO(param) 87 case None => new PortIO 88 } 89 val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None 90 val clintTime = EnableClintAsyncBridge match { 91 case Some(param) => Flipped(new AsyncBundle(UInt(64.W), param)) 92 case None => Input(ValidIO(UInt(64.W))) 93 } 94 val sramTest = new Bundle() { 95 val mbist = Option.when(hasMbist)(Input(new SramMbistBundle)) 96 val mbistReset = Option.when(hasMbist)(Input(new DFTResetSignals())) 97 val sramCtl = Option.when(hasSramCtl)(Input(UInt(64.W))) 98 } 99 val l2_flush_en = Option.when(EnablePowerDown) (Output(Bool())) 100 val l2_flush_done = Option.when(EnablePowerDown) (Output(Bool())) 101 val pwrdown_req_n = Option.when(EnablePowerDown) (Input (Bool())) 102 val pwrdown_ack_n = Option.when(EnablePowerDown) (Output (Bool())) 103 val iso_en = Option.when(EnablePowerDown) (Input (Bool())) 104 }) 105 106 val reset_sync = withClockAndReset(clock, (reset.asBool || io.hartResetReq).asAsyncReset)(ResetGen(2, io.sramTest.mbistReset)) 107 val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen(2, io.sramTest.mbistReset))) 108 val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen(2, io.sramTest.mbistReset)) 109 110 // override LazyRawModuleImp's clock and reset 111 childClock := clock 112 childReset := reset_sync 113 114 tile.module.io.hartId := io.hartId 115 tile.module.io.msiInfo := io.msiInfo 116 tile.module.io.reset_vector := io.reset_vector 117 tile.module.io.sramTest := io.sramTest 118 io.cpu_halt := tile.module.io.cpu_halt 119 io.cpu_crtical_error := tile.module.io.cpu_crtical_error 120 io.msiAck := tile.module.io.msiAck 121 io.hartIsInReset := tile.module.io.hartIsInReset 122 io.traceCoreInterface <> tile.module.io.traceCoreInterface 123 io.debugTopDown <> tile.module.io.debugTopDown 124 tile.module.io.l3Miss := io.l3Miss 125 tile.module.io.nodeID.foreach(_ := io.nodeID.get) 126 io.l2_flush_en.foreach { _ := tile.module.io.l2_flush_en.getOrElse(false.B) } 127 io.l2_flush_done.foreach { _ := tile.module.io.l2_flush_done.getOrElse(false.B) } 128 io.pwrdown_ack_n.foreach { _ := true.B } 129 130 // CLINT Async Queue Sink 131 EnableClintAsyncBridge match { 132 case Some(param) => 133 val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param))) 134 sink.io.async <> io.clintTime 135 sink.io.deq.ready := true.B 136 tile.module.io.clintTime.valid := sink.io.deq.valid 137 tile.module.io.clintTime.bits := sink.io.deq.bits 138 case None => 139 tile.module.io.clintTime := io.clintTime 140 } 141 142 // CHI Async Queue Source 143 EnableCHIAsyncBridge match { 144 case Some(param) => 145 val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param))) 146 source.io.enq <> tile.module.io.chi.get 147 io.chi <> source.io.async 148 case None => 149 require(enableCHI) 150 io.chi <> tile.module.io.chi.get 151 } 152 153 // Seperate DebugModule TL Async Queue Source 154 if (SeperateTLBus && EnableSeperateTLAsync) { 155 tlAsyncSourceOpt.get.module.clock := clock 156 tlAsyncSourceOpt.get.module.reset := soc_reset_sync 157 } 158 159 withClockAndReset(clock, reset_sync) { 160 // Modules are reset one by one 161 // reset ----> SYNC --> XSTile 162 val resetChain = Seq(Seq(tile.module)) 163 ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform, io.sramTest.mbistReset) 164 } 165 dontTouch(io.hartId) 166 dontTouch(io.msiInfo) 167 } 168 lazy val module = new XSTileWrapImp(this) 169} 170