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