1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 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 org.chipsalliance.cde.config.{Config, Parameters} 20import chisel3._ 21import chisel3.util.{Valid, ValidIO, log2Up} 22import freechips.rocketchip.diplomacy._ 23import freechips.rocketchip.interrupts._ 24import freechips.rocketchip.tile.{BusErrorUnit, BusErrorUnitParams, BusErrors} 25import freechips.rocketchip.tilelink._ 26import freechips.rocketchip.amba.axi4._ 27import device.MsiInfoBundle 28import system.HasSoCParameter 29import top.{BusPerfMonitor, ArgParser, Generator} 30import utility.{DelayN, ResetGen, TLClientsMerger, TLEdgeBuffer, TLLogger, Constantin, ChiselDB, FileRegisters} 31import coupledL2.EnableCHI 32import coupledL2.tl2chi.PortIO 33 34class XSTile()(implicit p: Parameters) extends LazyModule 35 with HasXSParameter 36 with HasSoCParameter 37{ 38 override def shouldBeInlined: Boolean = false 39 val core = LazyModule(new XSCore()) 40 val l2top = LazyModule(new L2Top()) 41 42 val enableL2 = coreParams.L2CacheParamsOpt.isDefined 43 // =========== Public Ports ============ 44 val memBlock = core.memBlock.inner 45 val core_l3_pf_port = memBlock.l3_pf_sender_opt 46 val memory_port = if (enableCHI && enableL2) None else Some(l2top.inner.memory_port.get) 47 val tl_uncache = l2top.inner.mmio_port 48 // val axi4_uncache = if (enableCHI) Some(AXI4UserYanker()) else None 49 val beu_int_source = l2top.inner.beu.intNode 50 val core_reset_sink = BundleBridgeSink(Some(() => Reset())) 51 val clint_int_node = l2top.inner.clint_int_node 52 val plic_int_node = l2top.inner.plic_int_node 53 val debug_int_node = l2top.inner.debug_int_node 54 val nmi_int_node = l2top.inner.nmi_int_node 55 memBlock.clint_int_sink := clint_int_node 56 memBlock.plic_int_sink :*= plic_int_node 57 memBlock.debug_int_sink := debug_int_node 58 memBlock.nmi_int_sink := nmi_int_node 59 60 // =========== Components' Connection ============ 61 // L1 to l1_xbar 62 coreParams.dcacheParametersOpt.map { _ => 63 l2top.inner.misc_l2_pmu := l2top.inner.l1d_logger := memBlock.dcache_port := 64 memBlock.l1d_to_l2_buffer.node := memBlock.dcache.clientNode 65 } 66 67 l2top.inner.misc_l2_pmu := l2top.inner.l1i_logger := memBlock.frontendBridge.icache_node 68 if (!coreParams.softPTW) { 69 l2top.inner.misc_l2_pmu := l2top.inner.ptw_logger := l2top.inner.ptw_to_l2_buffer.node := memBlock.ptw_to_l2_buffer.node 70 } 71 72 // L2 Prefetch 73 l2top.inner.l2cache match { 74 case Some(l2) => 75 l2.pf_recv_node.foreach(recv => { 76 println("Connecting L1 prefetcher to L2!") 77 recv := memBlock.l2_pf_sender_opt.get 78 }) 79 case None => 80 } 81 82 // CMO 83 l2top.inner.l2cache match { 84 case Some(l2) => 85 l2.cmo_sink_node.foreach(recv => { 86 recv := memBlock.cmo_sender.get 87 }) 88 l2.cmo_source_node.foreach(resp => { 89 memBlock.cmo_reciver.get := resp 90 }) 91 case None => 92 } 93 94 val core_l3_tpmeta_source_port = l2top.inner.l2cache match { 95 case Some(l2) => l2.tpmeta_source_node 96 case None => None 97 } 98 val core_l3_tpmeta_sink_port = l2top.inner.l2cache match { 99 case Some(l2) => l2.tpmeta_sink_node 100 case None => None 101 } 102 103 // mmio 104 l2top.inner.i_mmio_port := l2top.inner.i_mmio_buffer.node := memBlock.frontendBridge.instr_uncache_node 105 l2top.inner.d_mmio_port := memBlock.uncache.clientNode 106 107 // =========== IO Connection ============ 108 class XSTileImp(wrapper: LazyModule) extends LazyModuleImp(wrapper) { 109 val io = IO(new Bundle { 110 val hartId = Input(UInt(hartIdLen.W)) 111 val msiInfo = Input(ValidIO(new MsiInfoBundle)) 112 val reset_vector = Input(UInt(PAddrBits.W)) 113 val cpu_halt = Output(Bool()) 114 val cpu_crtical_error = Output(Bool()) 115 val hartIsInReset = Output(Bool()) 116 val debugTopDown = new Bundle { 117 val robHeadPaddr = Valid(UInt(PAddrBits.W)) 118 val l3MissMatch = Input(Bool()) 119 } 120 val chi = if (enableCHI) Some(new PortIO) else None 121 val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None 122 val clintTime = Input(ValidIO(UInt(64.W))) 123 }) 124 125 dontTouch(io.hartId) 126 dontTouch(io.msiInfo) 127 if (!io.chi.isEmpty) { dontTouch(io.chi.get) } 128 129 val core_soft_rst = core_reset_sink.in.head._1 // unused 130 131 l2top.module.io.hartId.fromTile := io.hartId 132 core.module.io.hartId := l2top.module.io.hartId.toCore 133 core.module.io.reset_vector := l2top.module.io.reset_vector.toCore 134 core.module.io.msiInfo := io.msiInfo 135 core.module.io.clintTime := io.clintTime 136 l2top.module.io.reset_vector.fromTile := io.reset_vector 137 l2top.module.io.cpu_halt.fromCore := core.module.io.cpu_halt 138 io.cpu_halt := l2top.module.io.cpu_halt.toTile 139 l2top.module.io.cpu_critical_error.fromCore := core.module.io.cpu_critical_error 140 io.cpu_crtical_error := l2top.module.io.cpu_critical_error.toTile 141 142 l2top.module.io.hartIsInReset.resetInFrontend := core.module.io.resetInFrontend 143 io.hartIsInReset := l2top.module.io.hartIsInReset.toTile 144 145 l2top.module.io.beu_errors.icache <> core.module.io.beu_errors.icache 146 l2top.module.io.beu_errors.dcache <> core.module.io.beu_errors.dcache 147 if (enableL2) { 148 // TODO: add ECC interface of L2 149 150 l2top.module.io.beu_errors.l2 <> 0.U.asTypeOf(l2top.module.io.beu_errors.l2) 151 core.module.io.l2_hint.bits.sourceId := l2top.module.io.l2_hint.bits.sourceId 152 core.module.io.l2_hint.bits.isKeyword := l2top.module.io.l2_hint.bits.isKeyword 153 core.module.io.l2_hint.valid := l2top.module.io.l2_hint.valid 154 155 core.module.io.l2PfqBusy := false.B 156 core.module.io.debugTopDown.l2MissMatch := l2top.module.io.debugTopDown.l2MissMatch 157 l2top.module.io.debugTopDown.robHeadPaddr := core.module.io.debugTopDown.robHeadPaddr 158 l2top.module.io.debugTopDown.robTrueCommit := core.module.io.debugTopDown.robTrueCommit 159 l2top.module.io.l2_pmp_resp := core.module.io.l2_pmp_resp 160 core.module.io.l2_tlb_req <> l2top.module.io.l2_tlb_req 161 162 core.module.io.perfEvents <> l2top.module.io.perfEvents 163 } else { 164 165 l2top.module.io.beu_errors.l2 <> 0.U.asTypeOf(l2top.module.io.beu_errors.l2) 166 core.module.io.l2_hint.bits.sourceId := l2top.module.io.l2_hint.bits.sourceId 167 core.module.io.l2_hint.bits.isKeyword := l2top.module.io.l2_hint.bits.isKeyword 168 core.module.io.l2_hint.valid := l2top.module.io.l2_hint.valid 169 170 core.module.io.l2PfqBusy := false.B 171 core.module.io.debugTopDown.l2MissMatch := false.B 172 173 core.module.io.l2_tlb_req.req.valid := false.B 174 core.module.io.l2_tlb_req.req.bits := DontCare 175 core.module.io.l2_tlb_req.req_kill := DontCare 176 core.module.io.l2_tlb_req.resp.ready := true.B 177 178 core.module.io.perfEvents <> DontCare 179 } 180 181 io.debugTopDown.robHeadPaddr := core.module.io.debugTopDown.robHeadPaddr 182 core.module.io.debugTopDown.l3MissMatch := io.debugTopDown.l3MissMatch 183 184 io.chi.foreach(_ <> l2top.module.io.chi.get) 185 l2top.module.io.nodeID.foreach(_ := io.nodeID.get) 186 187 if (debugOpts.ResetGen && enableL2) { 188 core.module.reset := l2top.module.reset_core 189 } 190 } 191 192 lazy val module = new XSTileImp(this) 193} 194