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 29import utility.{DFTResetSignals, IntBuffer, ResetGen} 30import xiangshan.backend.trace.TraceCoreInterface 31import utils.PowerSwitchBuffer 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 TL bus 57 println(s"SeperateTLBus = $SeperateTLBus") 58 println(s"EnableSeperateTLAsync = $EnableSeperateTLAsync") 59 // asynchronous bridge source node 60 val tlAsyncSourceOpt = Option.when(SeperateTLBus && EnableSeperateTLAsync)(LazyModule(new TLAsyncCrossingSource())) 61 tlAsyncSourceOpt.foreach(_.node := tile.sep_tl_opt.get) 62 // synchronous source node 63 val tlSyncSourceOpt = Option.when(SeperateTLBus && !EnableSeperateTLAsync)(TLTempNode()) 64 tlSyncSourceOpt.foreach(_ := tile.sep_tl_opt.get) 65 66 class XSTileWrapImp(wrapper: LazyModule) extends LazyRawModuleImp(wrapper) { 67 val clock = IO(Input(Clock())) 68 val reset = IO(Input(AsyncReset())) 69 val noc_reset = EnableCHIAsyncBridge.map(_ => IO(Input(AsyncReset()))) 70 val soc_reset = IO(Input(AsyncReset())) 71 val io = IO(new Bundle { 72 val hartId = Input(UInt(hartIdLen.W)) 73 val msiInfo = Input(ValidIO(UInt(soc.IMSICParams.MSI_INFO_WIDTH.W))) 74 val msiAck = Output(Bool()) 75 val reset_vector = Input(UInt(PAddrBits.W)) 76 val cpu_halt = Output(Bool()) 77 val cpu_crtical_error = Output(Bool()) 78 val hartResetReq = Input(Bool()) 79 val hartIsInReset = Output(Bool()) 80 val traceCoreInterface = new TraceCoreInterface 81 val debugTopDown = new Bundle { 82 val robHeadPaddr = Valid(UInt(PAddrBits.W)) 83 val l3MissMatch = Input(Bool()) 84 } 85 val l3Miss = Input(Bool()) 86 val chi = EnableCHIAsyncBridge match { 87 case Some(param) => new AsyncPortIO(param) 88 case None => new PortIO 89 } 90 val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None 91 val clintTime = EnableClintAsyncBridge match { 92 case Some(param) => Flipped(new AsyncBundle(UInt(64.W), param)) 93 case None => Input(ValidIO(UInt(64.W))) 94 } 95 val dft = Option.when(hasDFT)(Input(new SramBroadcastBundle)) 96 val dft_reset = Option.when(hasMbist)(Input(new DFTResetSignals())) 97 val l2_flush_en = Option.when(EnablePowerDown) (Output(Bool())) 98 val l2_flush_done = Option.when(EnablePowerDown) (Output(Bool())) 99 val pwrdown_req_n = Option.when(EnablePowerDown) (Input (Bool())) 100 val pwrdown_ack_n = Option.when(EnablePowerDown) (Output (Bool())) 101 val iso_en = Option.when(EnablePowerDown) (Input (Bool())) 102 }) 103 104 val reset_sync = withClockAndReset(clock, (reset.asBool || io.hartResetReq).asAsyncReset)(ResetGen(2, io.dft_reset)) 105 val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen(2, io.dft_reset))) 106 val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen(2, io.dft_reset)) 107 108 // override LazyRawModuleImp's clock and reset 109 childClock := clock 110 childReset := reset_sync 111 112 tile.module.io.hartId := io.hartId 113 tile.module.io.msiInfo := io.msiInfo 114 tile.module.io.reset_vector := io.reset_vector 115 tile.module.io.dft.zip(io.dft).foreach({ case (a, b) => a := b }) 116 tile.module.io.dft_reset.zip(io.dft_reset).foreach({ case (a, b) => a := b }) 117 io.cpu_halt := tile.module.io.cpu_halt 118 io.cpu_crtical_error := tile.module.io.cpu_crtical_error 119 io.msiAck := tile.module.io.msiAck 120 io.hartIsInReset := tile.module.io.hartIsInReset 121 io.traceCoreInterface <> tile.module.io.traceCoreInterface 122 io.debugTopDown <> tile.module.io.debugTopDown 123 tile.module.io.l3Miss := io.l3Miss 124 tile.module.io.nodeID.foreach(_ := io.nodeID.get) 125 io.l2_flush_en.foreach { _ := tile.module.io.l2_flush_en.getOrElse(false.B) } 126 io.l2_flush_done.foreach { _ := tile.module.io.l2_flush_done.getOrElse(false.B) } 127 io.pwrdown_ack_n.foreach { _ := DontCare } 128 io.pwrdown_ack_n zip io.pwrdown_req_n foreach { case (ack, req) => 129 val powerSwitchBuffer = Module(new PowerSwitchBuffer) 130 ack := powerSwitchBuffer.ack 131 powerSwitchBuffer.sleep := req 132 } 133 134 // CLINT Async Queue Sink 135 EnableClintAsyncBridge match { 136 case Some(param) => 137 val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param))) 138 sink.io.async <> io.clintTime 139 sink.io.deq.ready := true.B 140 tile.module.io.clintTime.valid := sink.io.deq.valid 141 tile.module.io.clintTime.bits := sink.io.deq.bits 142 case None => 143 tile.module.io.clintTime := io.clintTime 144 } 145 146 // CHI Async Queue Source 147 EnableCHIAsyncBridge match { 148 case Some(param) => 149 val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param))) 150 source.io.enq <> tile.module.io.chi.get 151 io.chi <> source.io.async 152 case None => 153 require(enableCHI) 154 io.chi <> tile.module.io.chi.get 155 } 156 157 // Seperate DebugModule TL Async Queue Source 158 if (SeperateTLBus && EnableSeperateTLAsync) { 159 tlAsyncSourceOpt.get.module.clock := clock 160 tlAsyncSourceOpt.get.module.reset := soc_reset_sync 161 } 162 163 withClockAndReset(clock, reset_sync) { 164 // Modules are reset one by one 165 // reset ----> SYNC --> XSTile 166 val resetChain = Seq(Seq(tile.module)) 167 ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform, io.dft_reset) 168 } 169 dontTouch(io.hartId) 170 dontTouch(io.msiInfo) 171 io.pwrdown_req_n.foreach(dontTouch(_)) 172 io.pwrdown_ack_n.foreach(dontTouch(_)) 173 io.iso_en.foreach(dontTouch(_)) 174 } 175 lazy val module = new XSTileWrapImp(this) 176} 177