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.util._ 25import system.HasSoCParameter 26import device.{IMSICAsync, MsiInfoBundle} 27import coupledL2.tl2chi.{PortIO, AsyncPortIO, CHIAsyncBridgeSource} 28import utility.{IntBuffer, ResetGen} 29import xiangshan.backend.trace.TraceCoreInterface 30 31// This module is used for XSNoCTop for async time domain and divide different 32// voltage domain. Everything in this module should be in the core clock domain 33// and higher voltage domain. 34class XSTileWrap()(implicit p: Parameters) extends LazyModule 35 with HasXSParameter 36 with HasSoCParameter 37{ 38 override def shouldBeInlined: Boolean = false 39 40 val tile = LazyModule(new XSTile()) 41 42 // interrupts sync 43 val clintIntNode = IntIdentityNode() 44 val debugIntNode = IntIdentityNode() 45 val plicIntNode = IntIdentityNode() 46 val beuIntNode = IntIdentityNode() 47 val nmiIntNode = IntIdentityNode() 48 tile.clint_int_node := IntBuffer(3, cdc = true) := clintIntNode 49 tile.debug_int_node := IntBuffer(3, cdc = true) := debugIntNode 50 tile.plic_int_node :*= IntBuffer(3, cdc = true) :*= plicIntNode 51 tile.nmi_int_node := IntBuffer(3, cdc = true) := nmiIntNode 52 beuIntNode := IntBuffer() := tile.beu_int_source 53 class XSTileWrapImp(wrapper: LazyModule) extends LazyRawModuleImp(wrapper) { 54 val clock = IO(Input(Clock())) 55 val reset = IO(Input(AsyncReset())) 56 val noc_reset = EnableCHIAsyncBridge.map(_ => IO(Input(AsyncReset()))) 57 val soc_reset = IO(Input(AsyncReset())) 58 val io = IO(new Bundle { 59 val hartId = Input(UInt(hartIdLen.W)) 60 val msiInfo = Input(ValidIO(new MsiInfoBundle)) 61 val reset_vector = Input(UInt(PAddrBits.W)) 62 val cpu_halt = Output(Bool()) 63 val cpu_crtical_error = Output(Bool()) 64 val hartResetReq = Input(Bool()) 65 val hartIsInReset = Output(Bool()) 66 val traceCoreInterface = new TraceCoreInterface 67 val debugTopDown = new Bundle { 68 val robHeadPaddr = Valid(UInt(PAddrBits.W)) 69 val l3MissMatch = Input(Bool()) 70 } 71 val l3Miss = Input(Bool()) 72 val chi = EnableCHIAsyncBridge match { 73 case Some(param) => new AsyncPortIO(param) 74 case None => new PortIO 75 } 76 val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None 77 val clintTime = EnableClintAsyncBridge match { 78 case Some(param) => Flipped(new AsyncBundle(UInt(64.W), param)) 79 case None => Input(ValidIO(UInt(64.W))) 80 } 81 }) 82 83 val reset_sync = withClockAndReset(clock, (reset.asBool || io.hartResetReq).asAsyncReset)(ResetGen()) 84 val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen())) 85 val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen()) 86 87 // override LazyRawModuleImp's clock and reset 88 childClock := clock 89 childReset := reset_sync 90 91 val imsicAsync = withClockAndReset(clock, reset_sync)(Module(new IMSICAsync())) 92 imsicAsync.i.msiInfo := io.msiInfo 93 94 tile.module.io.hartId := io.hartId 95 tile.module.io.msiInfo := imsicAsync.o.msiInfo 96 tile.module.io.reset_vector := io.reset_vector 97 io.cpu_halt := tile.module.io.cpu_halt 98 io.cpu_crtical_error := tile.module.io.cpu_crtical_error 99 io.hartIsInReset := tile.module.io.hartIsInReset 100 io.traceCoreInterface <> tile.module.io.traceCoreInterface 101 io.debugTopDown <> tile.module.io.debugTopDown 102 tile.module.io.l3Miss := io.l3Miss 103 tile.module.io.nodeID.foreach(_ := io.nodeID.get) 104 105 // CLINT Async Queue Sink 106 EnableClintAsyncBridge match { 107 case Some(param) => 108 val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param))) 109 sink.io.async <> io.clintTime 110 sink.io.deq.ready := true.B 111 tile.module.io.clintTime.valid := sink.io.deq.valid 112 tile.module.io.clintTime.bits := sink.io.deq.bits 113 case None => 114 tile.module.io.clintTime := io.clintTime 115 } 116 117 // CHI Async Queue Source 118 EnableCHIAsyncBridge match { 119 case Some(param) => 120 val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param))) 121 source.io.enq <> tile.module.io.chi.get 122 io.chi <> source.io.async 123 case None => 124 require(enableCHI) 125 io.chi <> tile.module.io.chi.get 126 } 127 128 withClockAndReset(clock, reset_sync) { 129 // Modules are reset one by one 130 // reset ----> SYNC --> XSTile 131 val resetChain = Seq(Seq(tile.module)) 132 ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform) 133 } 134 dontTouch(io.hartId) 135 dontTouch(io.msiInfo) 136 } 137 lazy val module = new XSTileWrapImp(this) 138} 139