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