xref: /XiangShan/src/main/scala/xiangshan/frontend/Frontend.scala (revision 744c623c9712d7d524de00ea02e793c0c57a1984)
1package xiangshan.frontend
2import utils.XSInfo
3import chisel3._
4import chisel3.util._
5import utils.PipelineConnect
6import xiangshan._
7import xiangshan.cache._
8import xiangshan.cache.prefetch.L1plusPrefetcher
9
10
11class Frontend extends XSModule with HasL1plusCacheParameters {
12  val io = IO(new Bundle() {
13    val icacheMemAcq = DecoupledIO(new L1plusCacheReq)
14    val icacheMemGrant = Flipped(DecoupledIO(new L1plusCacheResp))
15    val l1plusFlush = Output(Bool())
16    val fencei = Input(Bool())
17    val ptw = new TlbPtwIO
18    val backend = new FrontendToBackendIO
19    val sfence = Input(new SfenceBundle)
20    val tlbCsr = Input(new TlbCsrBundle)
21    val mmio_acquire = DecoupledIO(new InsUncacheReq)
22    val mmio_grant  = Flipped(DecoupledIO(new InsUncacheResp))
23    val mmio_flush = Output(Bool())
24  })
25
26  val ifu = Module(new IFU)
27  val ibuffer =  Module(new Ibuffer)
28  val l1plusPrefetcher = Module(new L1plusPrefetcher)
29
30
31  val needFlush = io.backend.redirect_cfiUpdate.valid
32
33  // from backend
34  ifu.io.redirect <> io.backend.redirect_cfiUpdate
35  ifu.io.commitUpdate <> io.backend.commit_cfiUpdate
36  ifu.io.ftqEnqPtr <> io.backend.ftqEnqPtr
37  ifu.io.ftqLeftOne <> io.backend.ftqLeftOne
38  // to icache
39  val grantClientId = clientId(io.icacheMemGrant.bits.id)
40  val grantEntryId = entryId(io.icacheMemGrant.bits.id)
41  ifu.io.icacheMemGrant.valid := io.icacheMemGrant.valid && grantClientId === icacheMissQueueId.U
42  ifu.io.icacheMemGrant.bits := io.icacheMemGrant.bits
43  ifu.io.icacheMemGrant.bits.id := Cat(0.U(clientIdWidth.W), grantEntryId)
44  io.mmio_acquire <> ifu.io.mmio_acquire
45  io.mmio_flush   <> ifu.io.mmio_flush
46  ifu.io.mmio_grant <> io.mmio_grant
47  l1plusPrefetcher.io.mem_grant.valid := io.icacheMemGrant.valid && grantClientId === l1plusPrefetcherId.U
48  l1plusPrefetcher.io.mem_grant.bits := io.icacheMemGrant.bits
49  l1plusPrefetcher.io.mem_grant.bits.id := Cat(0.U(clientIdWidth.W), grantEntryId)
50  io.icacheMemGrant.ready := Mux(grantClientId === icacheMissQueueId.U,
51    ifu.io.icacheMemGrant.ready,
52    l1plusPrefetcher.io.mem_grant.ready)
53  ifu.io.fencei := io.fencei
54  // to tlb
55  ifu.io.sfence := io.sfence
56  ifu.io.tlbCsr := io.tlbCsr
57  // from icache and l1plus prefetcher
58  io.l1plusFlush := ifu.io.l1plusFlush
59  l1plusPrefetcher.io.in.valid := ifu.io.prefetchTrainReq.valid
60  l1plusPrefetcher.io.in.bits := ifu.io.prefetchTrainReq.bits
61  val memAcquireArb = Module(new Arbiter(new L1plusCacheReq, nClients))
62  memAcquireArb.io.in(icacheMissQueueId) <> ifu.io.icacheMemAcq
63  memAcquireArb.io.in(icacheMissQueueId).bits.id := Cat(icacheMissQueueId.U(clientIdWidth.W),
64    entryId(ifu.io.icacheMemAcq.bits.id))
65  memAcquireArb.io.in(l1plusPrefetcherId) <> l1plusPrefetcher.io.mem_acquire
66  memAcquireArb.io.in(l1plusPrefetcherId).bits.id := Cat(l1plusPrefetcherId.U(clientIdWidth.W),
67    entryId(l1plusPrefetcher.io.mem_acquire.bits.id))
68  io.icacheMemAcq <> memAcquireArb.io.out
69  // itlb to ptw
70  io.ptw <> ifu.io.ptw
71  // ifu to ibuffer
72  ibuffer.io.in <> ifu.io.fetchPacket
73  // backend to ibuffer
74  ibuffer.io.flush := needFlush
75  // ibuffer to backend
76  io.backend.cfVec <> ibuffer.io.out
77  // ifu to backend
78  io.backend.fetchInfo <> ifu.io.toFtq
79
80  // for(out <- ibuffer.io.out){
81  //   XSInfo(out.fire(),
82  //     p"inst:${Hexadecimal(out.bits.instr)} pc:${Hexadecimal(out.bits.pc)}\n"
83  //   )
84  // }
85
86
87}