1package xiangshan.frontend 2import utils.XSInfo 3import chisel3._ 4import chisel3.util._ 5import chipsalliance.rocketchip.config.Parameters 6import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 7import utils.PipelineConnect 8import xiangshan._ 9import xiangshan.cache._ 10import xiangshan.cache.prefetch.L1plusPrefetcher 11import xiangshan.backend.fu.{HasExceptionNO, CustomCSRCtrlIO} 12 13class Frontend()(implicit p: Parameters) extends LazyModule with HasXSParameter{ 14 15 val instrUncache = LazyModule(new InstrUncache()) 16 17 lazy val module = new FrontendImp(this) 18} 19 20 21class FrontendImp (outer: Frontend) extends LazyModuleImp(outer) 22 with HasL1plusCacheParameters 23 with HasXSParameter 24 with HasExceptionNO 25 with HasXSLog 26{ 27 val io = IO(new Bundle() { 28 val icacheMemAcq = DecoupledIO(new L1plusCacheReq) 29 val icacheMemGrant = Flipped(DecoupledIO(new L1plusCacheResp)) 30 val l1plusFlush = Output(Bool()) 31 val fencei = Input(Bool()) 32 val ptw = new TlbPtwIO 33 val backend = new FrontendToBackendIO 34 val sfence = Input(new SfenceBundle) 35 val tlbCsr = Input(new TlbCsrBundle) 36 val csrCtrl = Input(new CustomCSRCtrlIO) 37 }) 38 39 val ifu = Module(new IFU) 40 val ibuffer = Module(new Ibuffer) 41 val l1plusPrefetcher = Module(new L1plusPrefetcher) 42 val instrUncache = outer.instrUncache.module 43 44 val needFlush = io.backend.redirect_cfiUpdate.valid 45 46 // from backend 47 ifu.io.redirect <> io.backend.redirect_cfiUpdate 48 ifu.io.commitUpdate <> io.backend.commit_cfiUpdate 49 ifu.io.ftqEnqPtr <> io.backend.ftqEnqPtr 50 ifu.io.ftqLeftOne <> io.backend.ftqLeftOne 51 // to icache 52 val grantClientId = clientId(io.icacheMemGrant.bits.id) 53 val grantEntryId = entryId(io.icacheMemGrant.bits.id) 54 ifu.io.icacheMemGrant.valid := io.icacheMemGrant.valid && grantClientId === icacheMissQueueId.U 55 ifu.io.icacheMemGrant.bits := io.icacheMemGrant.bits 56 ifu.io.icacheMemGrant.bits.id := Cat(0.U(clientIdWidth.W), grantEntryId) 57 l1plusPrefetcher.io.mem_grant.valid := io.icacheMemGrant.valid && grantClientId === l1plusPrefetcherId.U 58 l1plusPrefetcher.io.mem_grant.bits := io.icacheMemGrant.bits 59 l1plusPrefetcher.io.mem_grant.bits.id := Cat(0.U(clientIdWidth.W), grantEntryId) 60 io.icacheMemGrant.ready := Mux(grantClientId === icacheMissQueueId.U, 61 ifu.io.icacheMemGrant.ready, 62 l1plusPrefetcher.io.mem_grant.ready) 63 ifu.io.fencei := io.fencei 64 65 66 instrUncache.io.req <> ifu.io.mmio_acquire 67 instrUncache.io.resp <> ifu.io.mmio_grant 68 instrUncache.io.flush <> ifu.io.mmio_flush 69 // to tlb 70 ifu.io.sfence := io.sfence 71 ifu.io.tlbCsr := io.tlbCsr 72 // from icache and l1plus prefetcher 73 io.l1plusFlush := ifu.io.l1plusFlush 74 l1plusPrefetcher.io.in.valid := ifu.io.prefetchTrainReq.valid 75 l1plusPrefetcher.io.in.bits := ifu.io.prefetchTrainReq.bits 76 l1plusPrefetcher.io.enable := RegNext(io.csrCtrl.l1plus_pf_enable) 77 val memAcquireArb = Module(new Arbiter(new L1plusCacheReq, nClients)) 78 memAcquireArb.io.in(icacheMissQueueId) <> ifu.io.icacheMemAcq 79 memAcquireArb.io.in(icacheMissQueueId).bits.id := Cat(icacheMissQueueId.U(clientIdWidth.W), 80 entryId(ifu.io.icacheMemAcq.bits.id)) 81 memAcquireArb.io.in(l1plusPrefetcherId) <> l1plusPrefetcher.io.mem_acquire 82 memAcquireArb.io.in(l1plusPrefetcherId).bits.id := Cat(l1plusPrefetcherId.U(clientIdWidth.W), 83 entryId(l1plusPrefetcher.io.mem_acquire.bits.id)) 84 io.icacheMemAcq <> memAcquireArb.io.out 85 // itlb to ptw 86 io.ptw <> ifu.io.ptw 87 // ifu to ibuffer 88 ibuffer.io.in <> ifu.io.fetchPacket 89 // backend to ibuffer 90 ibuffer.io.flush := needFlush 91 // ibuffer to backend 92 io.backend.cfVec <> ibuffer.io.out 93 // ifu to backend 94 io.backend.fetchInfo <> ifu.io.toFtq 95 96 // for(out <- ibuffer.io.out){ 97 // XSInfo(out.fire(), 98 // p"inst:${Hexadecimal(out.bits.instr)} pc:${Hexadecimal(out.bits.pc)}\n" 99 // ) 100 // } 101 102 103}