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 hartIsInReset = Output(Bool()) 115 val debugTopDown = new Bundle { 116 val robHeadPaddr = Valid(UInt(PAddrBits.W)) 117 val l3MissMatch = Input(Bool()) 118 } 119 val chi = if (enableCHI) Some(new PortIO) else None 120 val nodeID = if (enableCHI) Some(Input(UInt(NodeIDWidth.W))) else None 121 val clintTime = Input(ValidIO(UInt(64.W))) 122 }) 123 124 dontTouch(io.hartId) 125 dontTouch(io.msiInfo) 126 if (!io.chi.isEmpty) { dontTouch(io.chi.get) } 127 128 val core_soft_rst = core_reset_sink.in.head._1 // unused 129 130 l2top.module.io.hartId.fromTile := io.hartId 131 core.module.io.hartId := l2top.module.io.hartId.toCore 132 core.module.io.reset_vector := l2top.module.io.reset_vector.toCore 133 core.module.io.msiInfo := io.msiInfo 134 core.module.io.clintTime := io.clintTime 135 l2top.module.io.reset_vector.fromTile := io.reset_vector 136 l2top.module.io.cpu_halt.fromCore := core.module.io.cpu_halt 137 io.cpu_halt := l2top.module.io.cpu_halt.toTile 138 139 l2top.module.io.hartIsInReset.resetInFrontend := core.module.io.resetInFrontend 140 io.hartIsInReset := l2top.module.io.hartIsInReset.toTile 141 142 l2top.module.io.beu_errors.icache <> core.module.io.beu_errors.icache 143 l2top.module.io.beu_errors.dcache <> core.module.io.beu_errors.dcache 144 if (enableL2) { 145 // TODO: add ECC interface of L2 146 147 l2top.module.io.beu_errors.l2 <> 0.U.asTypeOf(l2top.module.io.beu_errors.l2) 148 core.module.io.l2_hint.bits.sourceId := l2top.module.io.l2_hint.bits.sourceId 149 core.module.io.l2_hint.bits.isKeyword := l2top.module.io.l2_hint.bits.isKeyword 150 core.module.io.l2_hint.valid := l2top.module.io.l2_hint.valid 151 152 core.module.io.l2PfqBusy := false.B 153 core.module.io.debugTopDown.l2MissMatch := l2top.module.io.debugTopDown.l2MissMatch 154 l2top.module.io.debugTopDown.robHeadPaddr := core.module.io.debugTopDown.robHeadPaddr 155 l2top.module.io.debugTopDown.robTrueCommit := core.module.io.debugTopDown.robTrueCommit 156 l2top.module.io.l2_pmp_resp := core.module.io.l2_pmp_resp 157 core.module.io.l2_tlb_req <> l2top.module.io.l2_tlb_req 158 159 core.module.io.perfEvents <> l2top.module.io.perfEvents 160 } else { 161 162 l2top.module.io.beu_errors.l2 <> 0.U.asTypeOf(l2top.module.io.beu_errors.l2) 163 core.module.io.l2_hint.bits.sourceId := l2top.module.io.l2_hint.bits.sourceId 164 core.module.io.l2_hint.bits.isKeyword := l2top.module.io.l2_hint.bits.isKeyword 165 core.module.io.l2_hint.valid := l2top.module.io.l2_hint.valid 166 167 core.module.io.l2PfqBusy := false.B 168 core.module.io.debugTopDown.l2MissMatch := false.B 169 170 core.module.io.l2_tlb_req.req.valid := false.B 171 core.module.io.l2_tlb_req.req.bits := DontCare 172 core.module.io.l2_tlb_req.req_kill := DontCare 173 core.module.io.l2_tlb_req.resp.ready := true.B 174 175 core.module.io.perfEvents <> DontCare 176 } 177 178 io.debugTopDown.robHeadPaddr := core.module.io.debugTopDown.robHeadPaddr 179 core.module.io.debugTopDown.l3MissMatch := io.debugTopDown.l3MissMatch 180 181 io.chi.foreach(_ <> l2top.module.io.chi.get) 182 l2top.module.io.nodeID.foreach(_ := io.nodeID.get) 183 184 if (debugOpts.ResetGen && enableL2) { 185 core.module.reset := l2top.module.reset_core 186 } 187 } 188 189 lazy val module = new XSTileImp(this) 190} 191