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 20import org.chipsalliance.cde.config.Parameters 21import chisel3._ 22import chisel3.util._ 23import coupledL2.PrefetchCtrlFromCore 24import freechips.rocketchip.diplomacy.{BundleBridgeSource, LazyModule, LazyModuleImp} 25import freechips.rocketchip.tile.HasFPUParameters 26import system.HasSoCParameter 27import utils._ 28import utility._ 29import utility.mbist.{MbistInterface, MbistPipeline} 30import utility.sram.{SramBroadcastBundle, SramHelper} 31import xiangshan.frontend._ 32import xiangshan.backend._ 33import xiangshan.backend.fu.PMPRespBundle 34import xiangshan.backend.trace.TraceCoreInterface 35import xiangshan.mem._ 36import xiangshan.cache.mmu._ 37import xiangshan.cache.mmu.TlbRequestIO 38import scala.collection.mutable.ListBuffer 39 40abstract class XSModule(implicit val p: Parameters) extends Module 41 with HasXSParameter 42 with HasFPUParameters 43 44//remove this trait after impl module logic 45trait NeedImpl { 46 this: RawModule => 47 protected def IO[T <: Data](iodef: T): T = { 48 println(s"[Warn]: (${this.name}) please reomve 'NeedImpl' after implement this module") 49 val io = chisel3.IO(iodef) 50 io <> DontCare 51 io 52 } 53} 54 55abstract class XSBundle(implicit val p: Parameters) extends Bundle 56 with HasXSParameter 57 58abstract class XSCoreBase()(implicit p: config.Parameters) extends LazyModule 59 with HasXSParameter 60{ 61 override def shouldBeInlined: Boolean = false 62 // outer facing nodes 63 val frontend = LazyModule(new Frontend()) 64 val csrOut = BundleBridgeSource(Some(() => new DistributedCSRIO())) 65 val backend = LazyModule(new Backend(backendParams)) 66 67 val memBlock = LazyModule(new MemBlock) 68 69 memBlock.inner.frontendBridge.icache_node := frontend.inner.icache.clientNode 70 memBlock.inner.frontendBridge.instr_uncache_node := frontend.inner.instrUncache.clientNode 71 if (icacheParameters.cacheCtrlAddressOpt.nonEmpty) { 72 frontend.inner.icache.ctrlUnitOpt.get.node := memBlock.inner.frontendBridge.icachectrl_node 73 } 74} 75 76class XSCore()(implicit p: config.Parameters) extends XSCoreBase 77 with HasXSDts 78{ 79 lazy val module = new XSCoreImp(this) 80} 81 82class XSCoreImp(outer: XSCoreBase) extends LazyModuleImp(outer) 83 with HasXSParameter 84 with HasSoCParameter { 85 val io = IO(new Bundle { 86 val hartId = Input(UInt(hartIdLen.W)) 87 val msiInfo = Input(ValidIO(UInt(soc.IMSICParams.MSI_INFO_WIDTH.W))) 88 val msiAck = Output(Bool()) 89 val clintTime = Input(ValidIO(UInt(64.W))) 90 val reset_vector = Input(UInt(PAddrBits.W)) 91 val cpu_halt = Output(Bool()) 92 val l2_flush_done = Input(Bool()) 93 val l2_flush_en = Output(Bool()) 94 val power_down_en = Output(Bool()) 95 val cpu_critical_error = Output(Bool()) 96 val resetInFrontend = Output(Bool()) 97 val traceCoreInterface = new TraceCoreInterface 98 val l2PfCtrl = Output(new PrefetchCtrlFromCore) 99 val perfEvents = Input(Vec(numPCntHc * coreParams.L2NBanks + 1, new PerfEvent)) 100 val beu_errors = Output(new XSL1BusErrors()) 101 val l2_hint = Input(Valid(new L2ToL1Hint())) 102 val l2_tlb_req = Flipped(new TlbRequestIO(nRespDups = 2)) 103 val l2_pmp_resp = new PMPRespBundle 104 val l2PfqBusy = Input(Bool()) 105 val debugTopDown = new Bundle { 106 val robTrueCommit = Output(UInt(64.W)) 107 val robHeadPaddr = Valid(UInt(PAddrBits.W)) 108 val l2MissMatch = Input(Bool()) 109 val l3MissMatch = Input(Bool()) 110 } 111 val topDownInfo = Input(new Bundle { 112 val l2Miss = Bool() 113 val l3Miss = Bool() 114 }) 115 val dft = Option.when(hasDFT)(Input(new SramBroadcastBundle)) 116 val dft_reset = Option.when(hasDFT)(Input(new DFTResetSignals())) 117 }) 118 119 dontTouch(io.l2_flush_done) 120 dontTouch(io.l2_flush_en) 121 dontTouch(io.power_down_en) 122 123 println(s"FPGAPlatform:${env.FPGAPlatform} EnableDebug:${env.EnableDebug}") 124 125 val frontend = outer.frontend.module 126 val backend = outer.backend.module 127 val memBlock = outer.memBlock.module 128 129 frontend.io.hartId := memBlock.io.inner_hartId 130 frontend.io.reset_vector := memBlock.io.inner_reset_vector 131 frontend.io.softPrefetch <> memBlock.io.ifetchPrefetch 132 frontend.io.backend <> backend.io.frontend 133 frontend.io.sfence <> backend.io.frontendSfence 134 frontend.io.tlbCsr <> backend.io.frontendTlbCsr 135 frontend.io.csrCtrl <> backend.io.frontendCsrCtrl 136 frontend.io.fencei <> backend.io.fenceio.fencei 137 138 backend.io.fromTop := memBlock.io.mem_to_ooo.topToBackendBypass 139 140 require(backend.io.mem.stIn.length == memBlock.io.mem_to_ooo.stIn.length) 141 backend.io.mem.stIn.zip(memBlock.io.mem_to_ooo.stIn).foreach { case (sink, source) => 142 sink.valid := source.valid 143 sink.bits := 0.U.asTypeOf(sink.bits) 144 sink.bits.robIdx := source.bits.uop.robIdx 145 sink.bits.ssid := source.bits.uop.ssid 146 sink.bits.storeSetHit := source.bits.uop.storeSetHit 147 // The other signals have not been used 148 } 149 backend.io.mem.memoryViolation := memBlock.io.mem_to_ooo.memoryViolation 150 backend.io.mem.lsqEnqIO <> memBlock.io.ooo_to_mem.enqLsq 151 backend.io.mem.sqDeq := memBlock.io.mem_to_ooo.sqDeq 152 backend.io.mem.lqDeq := memBlock.io.mem_to_ooo.lqDeq 153 backend.io.mem.sqDeqPtr := memBlock.io.mem_to_ooo.sqDeqPtr 154 backend.io.mem.lqDeqPtr := memBlock.io.mem_to_ooo.lqDeqPtr 155 backend.io.mem.lqCancelCnt := memBlock.io.mem_to_ooo.lqCancelCnt 156 backend.io.mem.sqCancelCnt := memBlock.io.mem_to_ooo.sqCancelCnt 157 backend.io.mem.otherFastWakeup := memBlock.io.mem_to_ooo.otherFastWakeup 158 backend.io.mem.stIssuePtr := memBlock.io.mem_to_ooo.stIssuePtr 159 backend.io.mem.ldaIqFeedback := memBlock.io.mem_to_ooo.ldaIqFeedback 160 backend.io.mem.staIqFeedback := memBlock.io.mem_to_ooo.staIqFeedback 161 backend.io.mem.hyuIqFeedback := memBlock.io.mem_to_ooo.hyuIqFeedback 162 backend.io.mem.vstuIqFeedback := memBlock.io.mem_to_ooo.vstuIqFeedback 163 backend.io.mem.vlduIqFeedback := memBlock.io.mem_to_ooo.vlduIqFeedback 164 backend.io.mem.ldCancel := memBlock.io.mem_to_ooo.ldCancel 165 backend.io.mem.wakeup := memBlock.io.mem_to_ooo.wakeup 166 backend.io.mem.writebackLda <> memBlock.io.mem_to_ooo.writebackLda 167 backend.io.mem.writebackSta <> memBlock.io.mem_to_ooo.writebackSta 168 backend.io.mem.writebackHyuLda <> memBlock.io.mem_to_ooo.writebackHyuLda 169 backend.io.mem.writebackHyuSta <> memBlock.io.mem_to_ooo.writebackHyuSta 170 backend.io.mem.writebackStd <> memBlock.io.mem_to_ooo.writebackStd 171 backend.io.mem.writebackVldu <> memBlock.io.mem_to_ooo.writebackVldu 172 backend.io.mem.robLsqIO.mmio := memBlock.io.mem_to_ooo.lsqio.mmio 173 backend.io.mem.robLsqIO.uop := memBlock.io.mem_to_ooo.lsqio.uop 174 175 // memblock error exception writeback, 1 cycle after normal writeback 176 backend.io.mem.s3_delayed_load_error := memBlock.io.mem_to_ooo.s3_delayed_load_error 177 178 backend.io.mem.exceptionAddr.vaddr := memBlock.io.mem_to_ooo.lsqio.vaddr 179 backend.io.mem.exceptionAddr.gpaddr := memBlock.io.mem_to_ooo.lsqio.gpaddr 180 backend.io.mem.exceptionAddr.isForVSnonLeafPTE := memBlock.io.mem_to_ooo.lsqio.isForVSnonLeafPTE 181 backend.io.mem.debugLS := memBlock.io.debug_ls 182 backend.io.mem.lsTopdownInfo := memBlock.io.mem_to_ooo.lsTopdownInfo 183 backend.io.mem.lqCanAccept := memBlock.io.mem_to_ooo.lsqio.lqCanAccept 184 backend.io.mem.sqCanAccept := memBlock.io.mem_to_ooo.lsqio.sqCanAccept 185 backend.io.fenceio.sbuffer.sbIsEmpty := memBlock.io.mem_to_ooo.sbIsEmpty 186 187 backend.io.perf.frontendInfo := frontend.io.frontendInfo 188 backend.io.perf.memInfo := memBlock.io.memInfo 189 backend.io.perf.perfEventsFrontend := frontend.io_perf 190 backend.io.perf.perfEventsLsu := memBlock.io_perf 191 backend.io.perf.perfEventsHc := memBlock.io.inner_hc_perfEvents 192 backend.io.perf.perfEventsBackend := DontCare 193 backend.io.perf.retiredInstr := DontCare 194 backend.io.perf.ctrlInfo := DontCare 195 196 backend.io.mem.storeDebugInfo <> memBlock.io.mem_to_ooo.storeDebugInfo 197 198 // top -> memBlock 199 memBlock.io.fromTopToBackend.clintTime := io.clintTime 200 memBlock.io.fromTopToBackend.msiInfo := io.msiInfo 201 memBlock.io.hartId := io.hartId 202 memBlock.io.l2_flush_done := io.l2_flush_done 203 memBlock.io.outer_reset_vector := io.reset_vector 204 memBlock.io.outer_hc_perfEvents := io.perfEvents 205 // frontend -> memBlock 206 memBlock.io.inner_beu_errors_icache <> frontend.io.error.bits.toL1BusErrorUnitInfo(frontend.io.error.valid) 207 memBlock.io.ooo_to_mem.backendToTopBypass := backend.io.toTop 208 memBlock.io.ooo_to_mem.issueLda <> backend.io.mem.issueLda 209 memBlock.io.ooo_to_mem.issueSta <> backend.io.mem.issueSta 210 memBlock.io.ooo_to_mem.issueStd <> backend.io.mem.issueStd 211 memBlock.io.ooo_to_mem.issueHya <> backend.io.mem.issueHylda 212 backend.io.mem.issueHysta.foreach(_.ready := false.B) // this fake port should not be used 213 memBlock.io.ooo_to_mem.issueVldu <> backend.io.mem.issueVldu 214 215 // By default, instructions do not have exceptions when they enter the function units. 216 memBlock.io.ooo_to_mem.issueUops.map(_.bits.uop.clearExceptions()) 217 memBlock.io.ooo_to_mem.storePc := backend.io.mem.storePcRead 218 memBlock.io.ooo_to_mem.hybridPc := backend.io.mem.hyuPcRead 219 memBlock.io.ooo_to_mem.flushSb := backend.io.fenceio.sbuffer.flushSb 220 memBlock.io.ooo_to_mem.loadFastMatch := 0.U.asTypeOf(memBlock.io.ooo_to_mem.loadFastMatch) 221 memBlock.io.ooo_to_mem.loadFastImm := 0.U.asTypeOf(memBlock.io.ooo_to_mem.loadFastImm) 222 memBlock.io.ooo_to_mem.loadFastFuOpType := 0.U.asTypeOf(memBlock.io.ooo_to_mem.loadFastFuOpType) 223 224 memBlock.io.ooo_to_mem.sfence <> backend.io.mem.sfence 225 226 memBlock.io.redirect := backend.io.mem.redirect 227 memBlock.io.ooo_to_mem.csrCtrl := backend.io.mem.csrCtrl 228 memBlock.io.ooo_to_mem.tlbCsr := backend.io.mem.tlbCsr 229 memBlock.io.ooo_to_mem.lsqio.lcommit := backend.io.mem.robLsqIO.lcommit 230 memBlock.io.ooo_to_mem.lsqio.scommit := backend.io.mem.robLsqIO.scommit 231 memBlock.io.ooo_to_mem.lsqio.pendingMMIOld := backend.io.mem.robLsqIO.pendingMMIOld 232 memBlock.io.ooo_to_mem.lsqio.pendingld := backend.io.mem.robLsqIO.pendingld 233 memBlock.io.ooo_to_mem.lsqio.pendingst := backend.io.mem.robLsqIO.pendingst 234 memBlock.io.ooo_to_mem.lsqio.pendingVst := backend.io.mem.robLsqIO.pendingVst 235 memBlock.io.ooo_to_mem.lsqio.commit := backend.io.mem.robLsqIO.commit 236 memBlock.io.ooo_to_mem.lsqio.pendingPtr := backend.io.mem.robLsqIO.pendingPtr 237 memBlock.io.ooo_to_mem.lsqio.pendingPtrNext := backend.io.mem.robLsqIO.pendingPtrNext 238 memBlock.io.ooo_to_mem.isStoreException := backend.io.mem.isStoreException 239 memBlock.io.ooo_to_mem.isVlsException := backend.io.mem.isVlsException 240 241 memBlock.io.fetch_to_mem.itlb <> frontend.io.ptw 242 memBlock.io.l2_hint.valid := io.l2_hint.valid 243 memBlock.io.l2_hint.bits.sourceId := io.l2_hint.bits.sourceId 244 memBlock.io.l2_tlb_req <> io.l2_tlb_req 245 memBlock.io.l2_pmp_resp <> io.l2_pmp_resp 246 memBlock.io.l2_hint.bits.isKeyword := io.l2_hint.bits.isKeyword 247 memBlock.io.l2PfqBusy := io.l2PfqBusy 248 249 // if l2 prefetcher use stream prefetch, it should be placed in XSCore 250 251 // top-down info 252 memBlock.io.debugTopDown.robHeadVaddr := backend.io.debugTopDown.fromRob.robHeadVaddr 253 frontend.io.debugTopDown.robHeadVaddr := backend.io.debugTopDown.fromRob.robHeadVaddr 254 io.debugTopDown.robHeadPaddr := backend.io.debugTopDown.fromRob.robHeadPaddr 255 io.debugTopDown.robTrueCommit := backend.io.debugRolling.robTrueCommit 256 backend.io.debugTopDown.fromCore.l2MissMatch := io.debugTopDown.l2MissMatch 257 backend.io.debugTopDown.fromCore.l3MissMatch := io.debugTopDown.l3MissMatch 258 backend.io.debugTopDown.fromCore.fromMem := memBlock.io.debugTopDown.toCore 259 memBlock.io.debugRolling := backend.io.debugRolling 260 261 io.cpu_halt := memBlock.io.outer_cpu_halt 262 io.l2_flush_en := memBlock.io.outer_l2_flush_en 263 io.power_down_en := memBlock.io.outer_power_down_en 264 io.cpu_critical_error := memBlock.io.outer_cpu_critical_error 265 io.msiAck := memBlock.io.outer_msi_ack 266 io.beu_errors.icache <> memBlock.io.outer_beu_errors_icache 267 io.beu_errors.dcache <> memBlock.io.error.bits.toL1BusErrorUnitInfo(memBlock.io.error.valid) 268 io.beu_errors.l2 <> DontCare 269 io.l2PfCtrl := backend.io.mem.csrCtrl.pf_ctrl.toL2PrefetchCtrl() 270 271 memBlock.io.resetInFrontendBypass.fromFrontend := frontend.io.resetInFrontend 272 io.resetInFrontend := memBlock.io.resetInFrontendBypass.toL2Top 273 memBlock.io.traceCoreInterfaceBypass.fromBackend <> backend.io.traceCoreInterface 274 io.traceCoreInterface <> memBlock.io.traceCoreInterfaceBypass.toL2Top 275 memBlock.io.topDownInfo.fromL2Top.l2Miss := io.topDownInfo.l2Miss 276 memBlock.io.topDownInfo.fromL2Top.l3Miss := io.topDownInfo.l3Miss 277 memBlock.io.topDownInfo.toBackend.noUopsIssued := backend.io.topDownInfo.noUopsIssued 278 backend.io.topDownInfo.lqEmpty := memBlock.io.topDownInfo.toBackend.lqEmpty 279 backend.io.topDownInfo.sqEmpty := memBlock.io.topDownInfo.toBackend.sqEmpty 280 backend.io.topDownInfo.l1Miss := memBlock.io.topDownInfo.toBackend.l1Miss 281 backend.io.topDownInfo.l2TopMiss.l2Miss := memBlock.io.topDownInfo.toBackend.l2TopMiss.l2Miss 282 backend.io.topDownInfo.l2TopMiss.l3Miss := memBlock.io.topDownInfo.toBackend.l2TopMiss.l3Miss 283 284 285 if (debugOpts.ResetGen) { 286 backend.reset := memBlock.io.reset_backend 287 frontend.reset := backend.io.frontendReset 288 } 289 290 memBlock.io.dft.zip(io.dft).foreach({ case (a, b) => a := b }) 291 memBlock.io.dft_reset.zip(io.dft_reset).foreach({ case (a, b) => a := b }) 292 frontend.io.dft.zip(memBlock.io.dft_frnt).foreach({ case (a, b) => a := b }) 293 frontend.io.dft_reset.zip(memBlock.io.dft_reset_frnt).foreach({ case (a, b) => a := b }) 294 backend.io.dft.zip(memBlock.io.dft_bcknd).foreach({ case (a, b) => a := b }) 295 backend.io.dft_reset.zip(memBlock.io.dft_reset_bcknd).foreach({ case (a, b) => a := b }) 296} 297