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 }) 99 100 val reset_sync = withClockAndReset(clock, (reset.asBool || io.hartResetReq).asAsyncReset)(ResetGen(2, io.dft_reset)) 101 val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen(2, io.dft_reset))) 102 val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen(2, io.dft_reset)) 103 104 // override LazyRawModuleImp's clock and reset 105 childClock := clock 106 childReset := reset_sync 107 108 val imsicAsync = withClockAndReset(clock, reset_sync)(Module(new IMSICAsync())) 109 imsicAsync.i.msiInfo := io.msiInfo 110 111 tile.module.io.hartId := io.hartId 112 tile.module.io.msiInfo := imsicAsync.o.msiInfo 113 tile.module.io.reset_vector := io.reset_vector 114 tile.module.io.dft.zip(io.dft).foreach({case(a, b) => a := b}) 115 tile.module.io.dft_reset.zip(io.dft_reset).foreach({case(a, b) => a := b}) 116 io.cpu_halt := tile.module.io.cpu_halt 117 io.cpu_crtical_error := tile.module.io.cpu_crtical_error 118 io.msiAck := tile.module.io.msiAck 119 io.hartIsInReset := tile.module.io.hartIsInReset 120 io.traceCoreInterface <> tile.module.io.traceCoreInterface 121 io.debugTopDown <> tile.module.io.debugTopDown 122 tile.module.io.l3Miss := io.l3Miss 123 tile.module.io.nodeID.foreach(_ := io.nodeID.get) 124 125 // CLINT Async Queue Sink 126 EnableClintAsyncBridge match { 127 case Some(param) => 128 val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param))) 129 sink.io.async <> io.clintTime 130 sink.io.deq.ready := true.B 131 tile.module.io.clintTime.valid := sink.io.deq.valid 132 tile.module.io.clintTime.bits := sink.io.deq.bits 133 case None => 134 tile.module.io.clintTime := io.clintTime 135 } 136 137 // CHI Async Queue Source 138 EnableCHIAsyncBridge match { 139 case Some(param) => 140 val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param))) 141 source.io.enq <> tile.module.io.chi.get 142 io.chi <> source.io.async 143 case None => 144 require(enableCHI) 145 io.chi <> tile.module.io.chi.get 146 } 147 148 // Seperate DebugModule TL Async Queue Source 149 if (SeperateDMBus && EnableDMAsync) { 150 dmAsyncSourceOpt.get.module.clock := clock 151 dmAsyncSourceOpt.get.module.reset := soc_reset_sync 152 } 153 154 withClockAndReset(clock, reset_sync) { 155 // Modules are reset one by one 156 // reset ----> SYNC --> XSTile 157 val resetChain = Seq(Seq(tile.module)) 158 ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform, io.dft_reset) 159 } 160 dontTouch(io.hartId) 161 dontTouch(io.msiInfo) 162 } 163 lazy val module = new XSTileWrapImp(this) 164} 165