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 hartIsInReset = Output(Bool()) 65 val traceCoreInterface = new TraceCoreInterface 66 val debugTopDown = new Bundle { 67 val robHeadPaddr = Valid(UInt(PAddrBits.W)) 68 val l3MissMatch = Input(Bool()) 69 } 70 val chi = EnableCHIAsyncBridge match { 71 case Some(param) => new AsyncPortIO(param) 72 case None => new PortIO 73 } 74 val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None 75 val clintTime = EnableClintAsyncBridge match { 76 case Some(param) => Flipped(new AsyncBundle(UInt(64.W), param)) 77 case None => Input(ValidIO(UInt(64.W))) 78 } 79 }) 80 81 val reset_sync = withClockAndReset(clock, reset)(ResetGen()) 82 val noc_reset_sync = EnableCHIAsyncBridge.map(_ => withClockAndReset(clock, noc_reset.get)(ResetGen())) 83 val soc_reset_sync = withClockAndReset(clock, soc_reset)(ResetGen()) 84 85 // override LazyRawModuleImp's clock and reset 86 childClock := clock 87 childReset := reset_sync 88 89 val imsicAsync = withClockAndReset(clock, reset_sync)(Module(new IMSICAsync())) 90 imsicAsync.i.msiInfo := io.msiInfo 91 92 tile.module.io.hartId := io.hartId 93 tile.module.io.msiInfo := imsicAsync.o.msiInfo 94 tile.module.io.reset_vector := io.reset_vector 95 io.cpu_halt := tile.module.io.cpu_halt 96 io.cpu_crtical_error := tile.module.io.cpu_crtical_error 97 io.hartIsInReset := tile.module.io.hartIsInReset 98 io.traceCoreInterface <> tile.module.io.traceCoreInterface 99 io.debugTopDown <> tile.module.io.debugTopDown 100 tile.module.io.nodeID.foreach(_ := io.nodeID.get) 101 102 // CLINT Async Queue Sink 103 EnableClintAsyncBridge match { 104 case Some(param) => 105 val sink = withClockAndReset(clock, soc_reset_sync)(Module(new AsyncQueueSink(UInt(64.W), param))) 106 sink.io.async <> io.clintTime 107 sink.io.deq.ready := true.B 108 tile.module.io.clintTime.valid := sink.io.deq.valid 109 tile.module.io.clintTime.bits := sink.io.deq.bits 110 case None => 111 tile.module.io.clintTime := io.clintTime 112 } 113 114 // CHI Async Queue Source 115 EnableCHIAsyncBridge match { 116 case Some(param) => 117 val source = withClockAndReset(clock, noc_reset_sync.get)(Module(new CHIAsyncBridgeSource(param))) 118 source.io.enq <> tile.module.io.chi.get 119 io.chi <> source.io.async 120 case None => 121 require(enableCHI) 122 io.chi <> tile.module.io.chi.get 123 } 124 125 withClockAndReset(clock, reset_sync) { 126 // Modules are reset one by one 127 // reset ----> SYNC --> XSTile 128 val resetChain = Seq(Seq(tile.module)) 129 ResetGen(resetChain, reset_sync, !debugOpts.FPGAPlatform) 130 } 131 dontTouch(io.hartId) 132 dontTouch(io.msiInfo) 133 } 134 lazy val module = new XSTileWrapImp(this) 135} 136