16d5ddbceSLemover/*************************************************************************************** 26d5ddbceSLemover* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3f320e0f0SYinan Xu* Copyright (c) 2020-2021 Peng Cheng Laboratory 46d5ddbceSLemover* 56d5ddbceSLemover* XiangShan is licensed under Mulan PSL v2. 66d5ddbceSLemover* You can use this software according to the terms and conditions of the Mulan PSL v2. 76d5ddbceSLemover* You may obtain a copy of Mulan PSL v2 at: 86d5ddbceSLemover* http://license.coscl.org.cn/MulanPSL2 96d5ddbceSLemover* 106d5ddbceSLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 116d5ddbceSLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 126d5ddbceSLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 136d5ddbceSLemover* 146d5ddbceSLemover* See the Mulan PSL v2 for more details. 156d5ddbceSLemover***************************************************************************************/ 166d5ddbceSLemover 176d5ddbceSLemoverpackage xiangshan.cache.mmu 186d5ddbceSLemover 198891a219SYinan Xuimport org.chipsalliance.cde.config.Parameters 206d5ddbceSLemoverimport chisel3._ 216d5ddbceSLemoverimport chisel3.util._ 226d5ddbceSLemoverimport xiangshan._ 236d5ddbceSLemoverimport xiangshan.cache.{HasDCacheParameters, MemoryOpConstants} 246d5ddbceSLemoverimport utils._ 253c02ee8fSwakafaimport utility._ 266d5ddbceSLemoverimport freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 276d5ddbceSLemoverimport freechips.rocketchip.tilelink._ 286d5ddbceSLemover 2945f497a4Shappy-lxclass PTWReapterIO(Width: Int)(implicit p: Parameters) extends MMUIOBaseBundle { 306d5ddbceSLemover val tlb = Flipped(new TlbPtwIO(Width)) 316d5ddbceSLemover val ptw = new TlbPtwIO 3245f497a4Shappy-lx 3335d6335eSZhangZifei def apply(tlb: TlbPtwIO, ptw: TlbPtwIO, sfence: SfenceBundle, csr: TlbCsrBundle): Unit = { 3435d6335eSZhangZifei this.tlb <> tlb 3535d6335eSZhangZifei this.ptw <> ptw 3635d6335eSZhangZifei this.sfence <> sfence 3735d6335eSZhangZifei this.csr <> csr 3835d6335eSZhangZifei } 3935d6335eSZhangZifei 4035d6335eSZhangZifei def apply(tlb: TlbPtwIO, sfence: SfenceBundle, csr: TlbCsrBundle): Unit = { 4135d6335eSZhangZifei this.tlb <> tlb 4235d6335eSZhangZifei this.sfence <> sfence 4335d6335eSZhangZifei this.csr <> csr 4435d6335eSZhangZifei } 4535d6335eSZhangZifei 4645f497a4Shappy-lx} 4745f497a4Shappy-lx 48f1fe8698SLemoverclass PTWRepeater(Width: Int = 1, FenceDelay: Int)(implicit p: Parameters) extends XSModule with HasPtwConst { 4945f497a4Shappy-lx val io = IO(new PTWReapterIO(Width)) 5045f497a4Shappy-lx 516d5ddbceSLemover val req_in = if (Width == 1) { 526d5ddbceSLemover io.tlb.req(0) 536d5ddbceSLemover } else { 546d5ddbceSLemover val arb = Module(new RRArbiter(io.tlb.req(0).bits.cloneType, Width)) 556d5ddbceSLemover arb.io.in <> io.tlb.req 566d5ddbceSLemover arb.io.out 576d5ddbceSLemover } 58f1fe8698SLemover val (tlb, ptw, flush) = (io.tlb, io.ptw, DelayN(io.sfence.valid || io.csr.satp.changed, FenceDelay)) 59935edac4STang Haojin val req = RegEnable(req_in.bits, req_in.fire) 60935edac4STang Haojin val resp = RegEnable(ptw.resp.bits, ptw.resp.fire) 61935edac4STang Haojin val haveOne = BoolStopWatch(req_in.fire, tlb.resp.fire || flush) 62935edac4STang Haojin val sent = BoolStopWatch(ptw.req(0).fire, req_in.fire || flush) 63935edac4STang Haojin val recv = BoolStopWatch(ptw.resp.fire && haveOne, req_in.fire || flush) 646d5ddbceSLemover 656d5ddbceSLemover req_in.ready := !haveOne 666d5ddbceSLemover ptw.req(0).valid := haveOne && !sent 676d5ddbceSLemover ptw.req(0).bits := req 686d5ddbceSLemover 696d5ddbceSLemover tlb.resp.bits := resp 706d5ddbceSLemover tlb.resp.valid := haveOne && recv 716d5ddbceSLemover ptw.resp.ready := !recv 726d5ddbceSLemover 73935edac4STang Haojin XSPerfAccumulate("req_count", ptw.req(0).fire) 74935edac4STang Haojin XSPerfAccumulate("tlb_req_cycle", BoolStopWatch(req_in.fire, tlb.resp.fire || flush)) 75935edac4STang Haojin XSPerfAccumulate("ptw_req_cycle", BoolStopWatch(ptw.req(0).fire, ptw.resp.fire || flush)) 766d5ddbceSLemover 7745f497a4Shappy-lx XSDebug(haveOne, p"haveOne:${haveOne} sent:${sent} recv:${recv} sfence:${flush} req:${req} resp:${resp}") 786d5ddbceSLemover XSDebug(req_in.valid || io.tlb.resp.valid, p"tlb: ${tlb}\n") 796d5ddbceSLemover XSDebug(io.ptw.req(0).valid || io.ptw.resp.valid, p"ptw: ${ptw}\n") 806d5ddbceSLemover assert(!RegNext(recv && io.ptw.resp.valid, init = false.B), "re-receive ptw.resp") 81a8bd30cdSLemover XSError(io.ptw.req(0).valid && io.ptw.resp.valid && !flush, "ptw repeater recv resp when sending") 82a8bd30cdSLemover XSError(io.ptw.resp.valid && (req.vpn =/= io.ptw.resp.bits.entry.tag), "ptw repeater recv resp with wrong tag") 83a8bd30cdSLemover XSError(io.ptw.resp.valid && !io.ptw.resp.ready, "ptw repeater's ptw resp back, but not ready") 849bd9cdfaSLemover TimeOutAssert(sent && !recv, timeOutThreshold, "Repeater doesn't recv resp in time") 856d5ddbceSLemover} 866d5ddbceSLemover 876d5ddbceSLemover/* dtlb 886d5ddbceSLemover * 896d5ddbceSLemover */ 9035d6335eSZhangZifei 91f1fe8698SLemoverclass PTWRepeaterNB(Width: Int = 1, passReady: Boolean = false, FenceDelay: Int)(implicit p: Parameters) extends XSModule with HasPtwConst { 9235d6335eSZhangZifei val io = IO(new PTWReapterIO(Width)) 9335d6335eSZhangZifei 9435d6335eSZhangZifei val req_in = if (Width == 1) { 9535d6335eSZhangZifei io.tlb.req(0) 9635d6335eSZhangZifei } else { 9735d6335eSZhangZifei val arb = Module(new RRArbiter(io.tlb.req(0).bits.cloneType, Width)) 9835d6335eSZhangZifei arb.io.in <> io.tlb.req 9935d6335eSZhangZifei arb.io.out 10035d6335eSZhangZifei } 101f1fe8698SLemover val (tlb, ptw, flush) = (io.tlb, io.ptw, DelayN(io.sfence.valid || io.csr.satp.changed, FenceDelay)) 10235d6335eSZhangZifei /* sent: tlb -> repeater -> ptw 10335d6335eSZhangZifei * recv: ptw -> repeater -> tlb 10435d6335eSZhangZifei * different from PTWRepeater 10535d6335eSZhangZifei */ 10635d6335eSZhangZifei 10735d6335eSZhangZifei // tlb -> repeater -> ptw 108935edac4STang Haojin val req = RegEnable(req_in.bits, req_in.fire) 109935edac4STang Haojin val sent = BoolStopWatch(req_in.fire, ptw.req(0).fire || flush) 11035d6335eSZhangZifei req_in.ready := !sent || { if (passReady) ptw.req(0).ready else false.B } 11135d6335eSZhangZifei ptw.req(0).valid := sent 11235d6335eSZhangZifei ptw.req(0).bits := req 11335d6335eSZhangZifei 11435d6335eSZhangZifei // ptw -> repeater -> tlb 115935edac4STang Haojin val resp = RegEnable(ptw.resp.bits, ptw.resp.fire) 116935edac4STang Haojin val recv = BoolStopWatch(ptw.resp.fire, tlb.resp.fire || flush) 11735d6335eSZhangZifei ptw.resp.ready := !recv || { if (passReady) tlb.resp.ready else false.B } 11835d6335eSZhangZifei tlb.resp.valid := recv 11935d6335eSZhangZifei tlb.resp.bits := resp 12035d6335eSZhangZifei 121935edac4STang Haojin XSPerfAccumulate("req", req_in.fire) 122935edac4STang Haojin XSPerfAccumulate("resp", tlb.resp.fire) 12335d6335eSZhangZifei if (!passReady) { 12435d6335eSZhangZifei XSPerfAccumulate("req_blank", req_in.valid && sent && ptw.req(0).ready) 12535d6335eSZhangZifei XSPerfAccumulate("resp_blank", ptw.resp.valid && recv && tlb.resp.ready) 12635d6335eSZhangZifei XSPerfAccumulate("req_blank_ignore_ready", req_in.valid && sent) 12735d6335eSZhangZifei XSPerfAccumulate("resp_blank_ignore_ready", ptw.resp.valid && recv) 12835d6335eSZhangZifei } 12935d6335eSZhangZifei XSDebug(req_in.valid || io.tlb.resp.valid, p"tlb: ${tlb}\n") 13035d6335eSZhangZifei XSDebug(io.ptw.req(0).valid || io.ptw.resp.valid, p"ptw: ${ptw}\n") 13135d6335eSZhangZifei} 13235d6335eSZhangZifei 133185e6164SHaoyuan Fengclass PTWFilterIO(Width: Int, hasHint: Boolean = false)(implicit p: Parameters) extends MMUIOBaseBundle { 134f1fe8698SLemover val tlb = Flipped(new VectorTlbPtwIO(Width)) 135a0301c0dSLemover val ptw = new TlbPtwIO() 136185e6164SHaoyuan Feng val hint = if (hasHint) Some(new TlbHintIO) else None 137d2b20d1aSTang Haojin val rob_head_miss_in_tlb = Output(Bool()) 13860ebee38STang Haojin val debugTopDown = new Bundle { 13960ebee38STang Haojin val robHeadVaddr = Flipped(Valid(UInt(VAddrBits.W))) 14060ebee38STang Haojin } 1416d5ddbceSLemover 142f1fe8698SLemover def apply(tlb: VectorTlbPtwIO, ptw: TlbPtwIO, sfence: SfenceBundle, csr: TlbCsrBundle): Unit = { 14335d6335eSZhangZifei this.tlb <> tlb 14435d6335eSZhangZifei this.ptw <> ptw 14535d6335eSZhangZifei this.sfence <> sfence 14635d6335eSZhangZifei this.csr <> csr 14735d6335eSZhangZifei } 14835d6335eSZhangZifei 149f1fe8698SLemover def apply(tlb: VectorTlbPtwIO, sfence: SfenceBundle, csr: TlbCsrBundle): Unit = { 15035d6335eSZhangZifei this.tlb <> tlb 15135d6335eSZhangZifei this.sfence <> sfence 15235d6335eSZhangZifei this.csr <> csr 15335d6335eSZhangZifei } 15435d6335eSZhangZifei 15545f497a4Shappy-lx} 15645f497a4Shappy-lx 157185e6164SHaoyuan Fengclass PTWFilterEntryIO(Width: Int, hasHint: Boolean = false)(implicit p: Parameters) extends PTWFilterIO(Width, hasHint){ 158185e6164SHaoyuan Feng val flush = Input(Bool()) 159185e6164SHaoyuan Feng val refill = Output(Bool()) 160185e6164SHaoyuan Feng val memidx = Output(new MemBlockidxBundle) 161185e6164SHaoyuan Feng} 162185e6164SHaoyuan Feng 163185e6164SHaoyuan Fengclass PTWFilterEntry(Width: Int, Size: Int, hasHint: Boolean = false)(implicit p: Parameters) extends XSModule with HasPtwConst { 16471489510SXuan Hu private val LdExuCnt = backendParams.LdExuCnt 165185e6164SHaoyuan Feng 166185e6164SHaoyuan Feng val io = IO(new PTWFilterEntryIO(Width, hasHint)) 167185e6164SHaoyuan Feng require(isPow2(Size), s"Filter Size ($Size) must be a power of 2") 168185e6164SHaoyuan Feng 169185e6164SHaoyuan Feng def firstValidIndex(v: Seq[Bool], valid: Bool): UInt = { 170185e6164SHaoyuan Feng val index = WireInit(0.U(log2Up(Size).W)) 171185e6164SHaoyuan Feng for (i <- 0 until v.size) { 172185e6164SHaoyuan Feng when (v(i) === valid) { 173185e6164SHaoyuan Feng index := i.U 174185e6164SHaoyuan Feng } 175185e6164SHaoyuan Feng } 176185e6164SHaoyuan Feng index 177185e6164SHaoyuan Feng } 178185e6164SHaoyuan Feng 179185e6164SHaoyuan Feng val v = RegInit(VecInit(Seq.fill(Size)(false.B))) 180185e6164SHaoyuan Feng val sent = RegInit(VecInit(Seq.fill(Size)(false.B))) 181185e6164SHaoyuan Feng val vpn = Reg(Vec(Size, UInt(vpnLen.W))) 182185e6164SHaoyuan Feng val memidx = Reg(Vec(Size, new MemBlockidxBundle)) 183185e6164SHaoyuan Feng 184185e6164SHaoyuan Feng val enqvalid = WireInit(VecInit(Seq.fill(Width)(false.B))) 185185e6164SHaoyuan Feng val canenq = WireInit(VecInit(Seq.fill(Width)(false.B))) 186185e6164SHaoyuan Feng val enqidx = WireInit(VecInit(Seq.fill(Width)(0.U(log2Up(Size).W)))) 187185e6164SHaoyuan Feng 188185e6164SHaoyuan Feng //val selectCount = RegInit(0.U(log2Up(Width).W)) 189185e6164SHaoyuan Feng 190185e6164SHaoyuan Feng val entryIsMatchVec = WireInit(VecInit(Seq.fill(Width)(false.B))) 191185e6164SHaoyuan Feng val entryMatchIndexVec = WireInit(VecInit(Seq.fill(Width)(0.U(log2Up(Size).W)))) 192185e6164SHaoyuan Feng val ptwResp_EntryMatchVec = vpn.zip(v).map{ case (pi, vi) => vi && io.ptw.resp.bits.hit(pi, io.csr.satp.asid, true, true)} 193185e6164SHaoyuan Feng val ptwResp_EntryMatchFirst = firstValidIndex(ptwResp_EntryMatchVec, true.B) 194185e6164SHaoyuan Feng val ptwResp_ReqMatchVec = io.tlb.req.map(a => io.ptw.resp.valid && io.ptw.resp.bits.hit(a.bits.vpn, 0.U, allType = true, true)) 195185e6164SHaoyuan Feng 196185e6164SHaoyuan Feng io.refill := Cat(ptwResp_EntryMatchVec).orR && io.ptw.resp.fire 197185e6164SHaoyuan Feng io.ptw.resp.ready := true.B 198185e6164SHaoyuan Feng // DontCare 199185e6164SHaoyuan Feng io.tlb.req.map(_.ready := true.B) 200185e6164SHaoyuan Feng io.tlb.resp.valid := false.B 201185e6164SHaoyuan Feng io.tlb.resp.bits.data := 0.U.asTypeOf(new PtwSectorRespwithMemIdx) 202185e6164SHaoyuan Feng io.tlb.resp.bits.vector := 0.U.asTypeOf(Vec(Width, Bool())) 203185e6164SHaoyuan Feng io.memidx := 0.U.asTypeOf(new MemBlockidxBundle) 204185e6164SHaoyuan Feng 205185e6164SHaoyuan Feng // ugly code, should be optimized later 206*ae970023SXuan Hu require(Width <= 4, s"DTLB Filter Width ($Width) must equal or less than 4") 207185e6164SHaoyuan Feng if (Width == 1) { 208185e6164SHaoyuan Feng require(Size == 8, s"prefetch filter Size ($Size) should be 8") 209185e6164SHaoyuan Feng canenq(0) := !(Cat(v).andR) 210185e6164SHaoyuan Feng enqidx(0) := firstValidIndex(v, false.B) 211185e6164SHaoyuan Feng } else if (Width == 2) { 212185e6164SHaoyuan Feng require(Size == 8, s"store filter Size ($Size) should be 8") 213185e6164SHaoyuan Feng canenq(0) := !(Cat(v.take(Size/2)).andR) 214185e6164SHaoyuan Feng enqidx(0) := firstValidIndex(v.take(Size/2), false.B) 215185e6164SHaoyuan Feng canenq(1) := !(Cat(v.drop(Size/2)).andR) 216185e6164SHaoyuan Feng enqidx(1) := firstValidIndex(v.drop(Size/2), false.B) + (Size/2).U 217185e6164SHaoyuan Feng } else if (Width == 3) { 218185e6164SHaoyuan Feng require(Size == 16, s"load filter Size ($Size) should be 16") 219185e6164SHaoyuan Feng canenq(0) := !(Cat(v.take(8)).andR) 220185e6164SHaoyuan Feng enqidx(0) := firstValidIndex(v.take(8), false.B) 221185e6164SHaoyuan Feng canenq(1) := !(Cat(v.drop(8).take(4)).andR) 222185e6164SHaoyuan Feng enqidx(1) := firstValidIndex(v.drop(8).take(4), false.B) + 8.U 223185e6164SHaoyuan Feng // four entries for prefetch 224185e6164SHaoyuan Feng canenq(2) := !(Cat(v.drop(12)).andR) 225185e6164SHaoyuan Feng enqidx(2) := firstValidIndex(v.drop(12), false.B) + 12.U 226*ae970023SXuan Hu } else if (Width == 4) { 227*ae970023SXuan Hu require(Size == 16, s"load filter Size ($Size) should be 16") 228*ae970023SXuan Hu for (i <- 0 until Width) { 229*ae970023SXuan Hu canenq(i) := !(Cat(VecInit(v.slice(i * 4, (i + 1) * 4))).andR) 230*ae970023SXuan Hu enqidx(i) := firstValidIndex(v.slice(i * 4, (i + 1) * 4), false.B) + (i * 4).U 231*ae970023SXuan Hu } 232185e6164SHaoyuan Feng } 233185e6164SHaoyuan Feng 234185e6164SHaoyuan Feng for (i <- 0 until Width) { 235185e6164SHaoyuan Feng enqvalid(i) := io.tlb.req(i).valid && !ptwResp_ReqMatchVec(i) && !entryIsMatchVec(i) && canenq(i) 236185e6164SHaoyuan Feng when (!enqvalid(i)) { 237185e6164SHaoyuan Feng enqidx(i) := entryMatchIndexVec(i) 238185e6164SHaoyuan Feng } 239185e6164SHaoyuan Feng 240185e6164SHaoyuan Feng val entryIsMatch = vpn.zip(v).map{ case (pi, vi) => vi && pi === io.tlb.req(i).bits.vpn} 241185e6164SHaoyuan Feng entryIsMatchVec(i) := Cat(entryIsMatch).orR 242185e6164SHaoyuan Feng entryMatchIndexVec(i) := firstValidIndex(entryIsMatch, true.B) 243185e6164SHaoyuan Feng 244185e6164SHaoyuan Feng if (i > 0) { 245185e6164SHaoyuan Feng for (j <- 0 until i) { 246185e6164SHaoyuan Feng val newIsMatch = io.tlb.req(i).bits.vpn === io.tlb.req(j).bits.vpn 247185e6164SHaoyuan Feng when (newIsMatch && io.tlb.req(j).valid) { 248185e6164SHaoyuan Feng enqidx(i) := enqidx(j) 249185e6164SHaoyuan Feng canenq(i) := canenq(j) 250185e6164SHaoyuan Feng enqvalid(i) := false.B 251185e6164SHaoyuan Feng } 252185e6164SHaoyuan Feng } 253185e6164SHaoyuan Feng } 254185e6164SHaoyuan Feng 255185e6164SHaoyuan Feng when (enqvalid(i)) { 256185e6164SHaoyuan Feng v(enqidx(i)) := true.B 257185e6164SHaoyuan Feng sent(enqidx(i)) := false.B 258185e6164SHaoyuan Feng vpn(enqidx(i)) := io.tlb.req(i).bits.vpn 259185e6164SHaoyuan Feng memidx(enqidx(i)) := io.tlb.req(i).bits.memidx 260185e6164SHaoyuan Feng } 261185e6164SHaoyuan Feng } 262185e6164SHaoyuan Feng 263185e6164SHaoyuan Feng val issuevec = v.zip(sent).map{ case (v, s) => v && !s} 264185e6164SHaoyuan Feng val issueindex = firstValidIndex(issuevec, true.B) 265185e6164SHaoyuan Feng val canissue = Cat(issuevec).orR 266185e6164SHaoyuan Feng for (i <- 0 until Size) { 267185e6164SHaoyuan Feng io.ptw.req(0).valid := canissue 268185e6164SHaoyuan Feng io.ptw.req(0).bits.vpn := vpn(issueindex) 269185e6164SHaoyuan Feng } 270185e6164SHaoyuan Feng when (io.ptw.req(0).fire) { 271185e6164SHaoyuan Feng sent(issueindex) := true.B 272185e6164SHaoyuan Feng } 273185e6164SHaoyuan Feng 274185e6164SHaoyuan Feng when (io.ptw.resp.fire) { 275185e6164SHaoyuan Feng v.zip(ptwResp_EntryMatchVec).map{ case (vi, mi) => when (mi) { vi := false.B }} 276185e6164SHaoyuan Feng io.memidx := memidx(ptwResp_EntryMatchFirst) 277185e6164SHaoyuan Feng } 278185e6164SHaoyuan Feng 279185e6164SHaoyuan Feng when (io.flush) { 280185e6164SHaoyuan Feng v.map(_ := false.B) 281185e6164SHaoyuan Feng } 282185e6164SHaoyuan Feng 283185e6164SHaoyuan Feng if (hasHint) { 284185e6164SHaoyuan Feng val hintIO = io.hint.getOrElse(new TlbHintIO) 28571489510SXuan Hu for (i <- 0 until LdExuCnt) { 286185e6164SHaoyuan Feng hintIO.req(i).id := enqidx(i) 287185e6164SHaoyuan Feng hintIO.req(i).full := !canenq(i) || ptwResp_ReqMatchVec(i) 288185e6164SHaoyuan Feng } 289185e6164SHaoyuan Feng hintIO.resp.valid := io.refill 290185e6164SHaoyuan Feng hintIO.resp.bits.id := ptwResp_EntryMatchFirst 291185e6164SHaoyuan Feng hintIO.resp.bits.replay_all := PopCount(ptwResp_EntryMatchVec) > 1.U 292185e6164SHaoyuan Feng } 293185e6164SHaoyuan Feng 294185e6164SHaoyuan Feng io.rob_head_miss_in_tlb := VecInit(v.zip(vpn).map{case (vi, vpni) => { 295185e6164SHaoyuan Feng vi && io.debugTopDown.robHeadVaddr.valid && vpni === get_pn(io.debugTopDown.robHeadVaddr.bits) 296185e6164SHaoyuan Feng }}).asUInt.orR 297185e6164SHaoyuan Feng 298185e6164SHaoyuan Feng 299185e6164SHaoyuan Feng // Perf Counter 300185e6164SHaoyuan Feng val counter = PopCount(v) 301185e6164SHaoyuan Feng val inflight_counter = RegInit(0.U(log2Up(Size).W)) 302185e6164SHaoyuan Feng val inflight_full = inflight_counter === Size.U 303185e6164SHaoyuan Feng when (io.ptw.req(0).fire =/= io.ptw.resp.fire) { 304185e6164SHaoyuan Feng inflight_counter := Mux(io.ptw.req(0).fire, inflight_counter + 1.U, inflight_counter - 1.U) 305185e6164SHaoyuan Feng } 306185e6164SHaoyuan Feng 307185e6164SHaoyuan Feng assert(inflight_counter <= Size.U, "inflight should be no more than Size") 308185e6164SHaoyuan Feng when (counter === 0.U) { 309185e6164SHaoyuan Feng assert(!io.ptw.req(0).fire, "when counter is 0, should not req") 310185e6164SHaoyuan Feng } 311185e6164SHaoyuan Feng 312185e6164SHaoyuan Feng when (io.flush) { 313185e6164SHaoyuan Feng inflight_counter := 0.U 314185e6164SHaoyuan Feng } 315185e6164SHaoyuan Feng 316185e6164SHaoyuan Feng XSPerfAccumulate("tlb_req_count", PopCount(Cat(io.tlb.req.map(_.valid)))) 317185e6164SHaoyuan Feng XSPerfAccumulate("tlb_req_count_filtered", PopCount(enqvalid)) 318185e6164SHaoyuan Feng XSPerfAccumulate("ptw_req_count", io.ptw.req(0).fire) 319185e6164SHaoyuan Feng XSPerfAccumulate("ptw_req_cycle", inflight_counter) 320185e6164SHaoyuan Feng XSPerfAccumulate("tlb_resp_count", io.tlb.resp.fire) 321185e6164SHaoyuan Feng XSPerfAccumulate("ptw_resp_count", io.ptw.resp.fire) 322185e6164SHaoyuan Feng XSPerfAccumulate("inflight_cycle", Cat(sent).orR) 323185e6164SHaoyuan Feng 324185e6164SHaoyuan Feng for (i <- 0 until Size + 1) { 325185e6164SHaoyuan Feng XSPerfAccumulate(s"counter${i}", counter === i.U) 326185e6164SHaoyuan Feng } 327185e6164SHaoyuan Feng 328185e6164SHaoyuan Feng for (i <- 0 until Size) { 329185e6164SHaoyuan Feng TimeOutAssert(v(i), timeOutThreshold, s"Filter ${i} doesn't recv resp in time") 330185e6164SHaoyuan Feng } 331185e6164SHaoyuan Feng 332185e6164SHaoyuan Feng} 333185e6164SHaoyuan Feng 334185e6164SHaoyuan Fengclass PTWNewFilter(Width: Int, Size: Int, FenceDelay: Int)(implicit p: Parameters) extends XSModule with HasPtwConst { 335185e6164SHaoyuan Feng require(Size >= Width) 336185e6164SHaoyuan Feng 33771489510SXuan Hu // all load execute unit, including ldu and hyu 33871489510SXuan Hu private val LdExuCnt = backendParams.LdExuCnt 33971489510SXuan Hu // all store address execute unit, including sta and hyu 34071489510SXuan Hu private val StaExuCnt = backendParams.StaExuCnt 34171489510SXuan Hu 342185e6164SHaoyuan Feng val io = IO(new PTWFilterIO(Width, hasHint = true)) 343185e6164SHaoyuan Feng 344185e6164SHaoyuan Feng val load_filter = VecInit(Seq.fill(1) { 34571489510SXuan Hu val load_entry = Module(new PTWFilterEntry(Width = LdExuCnt + 1, Size = loadfiltersize, hasHint = true)) 346185e6164SHaoyuan Feng load_entry.io 347185e6164SHaoyuan Feng }) 348185e6164SHaoyuan Feng 349185e6164SHaoyuan Feng val store_filter = VecInit(Seq.fill(1) { 35071489510SXuan Hu val store_entry = Module(new PTWFilterEntry(Width = StaExuCnt, Size = storefiltersize)) 351185e6164SHaoyuan Feng store_entry.io 352185e6164SHaoyuan Feng }) 353185e6164SHaoyuan Feng 354185e6164SHaoyuan Feng val prefetch_filter = VecInit(Seq.fill(1) { 355185e6164SHaoyuan Feng val prefetch_entry = Module(new PTWFilterEntry(Width = 1, Size = prefetchfiltersize)) 356185e6164SHaoyuan Feng prefetch_entry.io 357185e6164SHaoyuan Feng }) 358185e6164SHaoyuan Feng 359185e6164SHaoyuan Feng val filter = load_filter ++ store_filter ++ prefetch_filter 360185e6164SHaoyuan Feng 36171489510SXuan Hu load_filter.map(_.tlb.req := io.tlb.req.take(LdExuCnt + 1)) 36271489510SXuan Hu store_filter.map(_.tlb.req := io.tlb.req.drop(LdExuCnt + 1).take(StaExuCnt)) 36371489510SXuan Hu prefetch_filter.map(_.tlb.req := io.tlb.req.drop(LdExuCnt + 1 + StaExuCnt)) 364185e6164SHaoyuan Feng 365185e6164SHaoyuan Feng val flush = DelayN(io.sfence.valid || io.csr.satp.changed, FenceDelay) 366185e6164SHaoyuan Feng val ptwResp = RegEnable(io.ptw.resp.bits, io.ptw.resp.fire) 367185e6164SHaoyuan Feng val ptwResp_valid = Cat(filter.map(_.refill)).orR 368185e6164SHaoyuan Feng filter.map(_.tlb.resp.ready := true.B) 369185e6164SHaoyuan Feng filter.map(_.ptw.resp.valid := RegNext(io.ptw.resp.fire, init = false.B)) 370185e6164SHaoyuan Feng filter.map(_.ptw.resp.bits := ptwResp) 371185e6164SHaoyuan Feng filter.map(_.flush := flush) 372185e6164SHaoyuan Feng filter.map(_.sfence := io.sfence) 373185e6164SHaoyuan Feng filter.map(_.csr := io.csr) 374185e6164SHaoyuan Feng filter.map(_.debugTopDown.robHeadVaddr := io.debugTopDown.robHeadVaddr) 375185e6164SHaoyuan Feng 376185e6164SHaoyuan Feng io.tlb.req.map(_.ready := true.B) 377185e6164SHaoyuan Feng io.tlb.resp.valid := ptwResp_valid 378185e6164SHaoyuan Feng io.tlb.resp.bits.data.entry := ptwResp.entry 379185e6164SHaoyuan Feng io.tlb.resp.bits.data.addr_low := ptwResp.addr_low 380185e6164SHaoyuan Feng io.tlb.resp.bits.data.ppn_low := ptwResp.ppn_low 381185e6164SHaoyuan Feng io.tlb.resp.bits.data.valididx := ptwResp.valididx 382185e6164SHaoyuan Feng io.tlb.resp.bits.data.pteidx := ptwResp.pteidx 383185e6164SHaoyuan Feng io.tlb.resp.bits.data.pf := ptwResp.pf 384185e6164SHaoyuan Feng io.tlb.resp.bits.data.af := ptwResp.af 385185e6164SHaoyuan Feng io.tlb.resp.bits.data.memidx := 0.U.asTypeOf(new MemBlockidxBundle) 386185e6164SHaoyuan Feng // vector used to represent different requestors of DTLB 387185e6164SHaoyuan Feng // (e.g. the store DTLB has StuCnt requestors) 388185e6164SHaoyuan Feng // However, it is only necessary to distinguish between different DTLB now 389185e6164SHaoyuan Feng for (i <- 0 until Width) { 390185e6164SHaoyuan Feng io.tlb.resp.bits.vector(i) := false.B 391185e6164SHaoyuan Feng } 392185e6164SHaoyuan Feng io.tlb.resp.bits.vector(0) := load_filter(0).refill 39371489510SXuan Hu io.tlb.resp.bits.vector(LdExuCnt + 1) := store_filter(0).refill 39471489510SXuan Hu io.tlb.resp.bits.vector(LdExuCnt + 1 + StaExuCnt) := prefetch_filter(0).refill 395185e6164SHaoyuan Feng 396185e6164SHaoyuan Feng val hintIO = io.hint.getOrElse(new TlbHintIO) 397185e6164SHaoyuan Feng val load_hintIO = load_filter(0).hint.getOrElse(new TlbHintIO) 39871489510SXuan Hu for (i <- 0 until LdExuCnt) { 399185e6164SHaoyuan Feng hintIO.req(i) := RegNext(load_hintIO.req(i)) 400185e6164SHaoyuan Feng } 401185e6164SHaoyuan Feng hintIO.resp := RegNext(load_hintIO.resp) 402185e6164SHaoyuan Feng 403185e6164SHaoyuan Feng when (load_filter(0).refill) { 404185e6164SHaoyuan Feng io.tlb.resp.bits.vector(0) := true.B 405185e6164SHaoyuan Feng io.tlb.resp.bits.data.memidx := load_filter(0).memidx 406185e6164SHaoyuan Feng } 407185e6164SHaoyuan Feng when (store_filter(0).refill) { 40871489510SXuan Hu io.tlb.resp.bits.vector(LdExuCnt + 1) := true.B 409185e6164SHaoyuan Feng io.tlb.resp.bits.data.memidx := store_filter(0).memidx 410185e6164SHaoyuan Feng } 411185e6164SHaoyuan Feng when (prefetch_filter(0).refill) { 41271489510SXuan Hu io.tlb.resp.bits.vector(LdExuCnt + 1 + StaExuCnt) := true.B 413185e6164SHaoyuan Feng io.tlb.resp.bits.data.memidx := 0.U.asTypeOf(new MemBlockidxBundle) 414185e6164SHaoyuan Feng } 415185e6164SHaoyuan Feng 416185e6164SHaoyuan Feng val ptw_arb = Module(new RRArbiterInit(new PtwReq, 3)) 417185e6164SHaoyuan Feng for (i <- 0 until 3) { 418185e6164SHaoyuan Feng ptw_arb.io.in(i).valid := filter(i).ptw.req(0).valid 419185e6164SHaoyuan Feng ptw_arb.io.in(i).bits.vpn := filter(i).ptw.req(0).bits.vpn 420185e6164SHaoyuan Feng filter(i).ptw.req(0).ready := ptw_arb.io.in(i).ready 421185e6164SHaoyuan Feng } 422185e6164SHaoyuan Feng ptw_arb.io.out.ready := io.ptw.req(0).ready 423185e6164SHaoyuan Feng io.ptw.req(0).valid := ptw_arb.io.out.valid 424185e6164SHaoyuan Feng io.ptw.req(0).bits.vpn := ptw_arb.io.out.bits.vpn 425185e6164SHaoyuan Feng io.ptw.resp.ready := true.B 426185e6164SHaoyuan Feng 427185e6164SHaoyuan Feng io.rob_head_miss_in_tlb := Cat(filter.map(_.rob_head_miss_in_tlb)).orR 428185e6164SHaoyuan Feng} 429185e6164SHaoyuan Feng 430f1fe8698SLemoverclass PTWFilter(Width: Int, Size: Int, FenceDelay: Int)(implicit p: Parameters) extends XSModule with HasPtwConst { 4316d5ddbceSLemover require(Size >= Width) 4326d5ddbceSLemover 43345f497a4Shappy-lx val io = IO(new PTWFilterIO(Width)) 43445f497a4Shappy-lx 4356d5ddbceSLemover val v = RegInit(VecInit(Seq.fill(Size)(false.B))) 436a0301c0dSLemover val ports = Reg(Vec(Size, Vec(Width, Bool()))) // record which port(s) the entry come from, may not able to cover all the ports 4376d5ddbceSLemover val vpn = Reg(Vec(Size, UInt(vpnLen.W))) 4388744445eSMaxpicca-Li val memidx = Reg(Vec(Size, new MemBlockidxBundle)) 4396d5ddbceSLemover val enqPtr = RegInit(0.U(log2Up(Size).W)) // Enq 4406d5ddbceSLemover val issPtr = RegInit(0.U(log2Up(Size).W)) // Iss to Ptw 4416d5ddbceSLemover val deqPtr = RegInit(0.U(log2Up(Size).W)) // Deq 4426d5ddbceSLemover val mayFullDeq = RegInit(false.B) 4436d5ddbceSLemover val mayFullIss = RegInit(false.B) 4446d5ddbceSLemover val counter = RegInit(0.U(log2Up(Size+1).W)) 4456d5ddbceSLemover 446f1fe8698SLemover val flush = DelayN(io.sfence.valid || io.csr.satp.changed, FenceDelay) 447f1fe8698SLemover val tlb_req = WireInit(io.tlb.req) // NOTE: tlb_req is not io.tlb.req, see below codes, just use cloneType 448cccfc98dSLemover tlb_req.suggestName("tlb_req") 449cccfc98dSLemover 450fa9f9690SLemover val inflight_counter = RegInit(0.U(log2Up(Size + 1).W)) 451fa9f9690SLemover val inflight_full = inflight_counter === Size.U 452935edac4STang Haojin when (io.ptw.req(0).fire =/= io.ptw.resp.fire) { 453935edac4STang Haojin inflight_counter := Mux(io.ptw.req(0).fire, inflight_counter + 1.U, inflight_counter - 1.U) 454fa9f9690SLemover } 455fa9f9690SLemover 45687f41827SLemover val canEnqueue = Wire(Bool()) // NOTE: actually enqueue 457935edac4STang Haojin val ptwResp = RegEnable(io.ptw.resp.bits, io.ptw.resp.fire) 458cccfc98dSLemover val ptwResp_OldMatchVec = vpn.zip(v).map{ case (pi, vi) => 45963632028SHaoyuan Feng vi && io.ptw.resp.bits.hit(pi, io.csr.satp.asid, true, true)} 460935edac4STang Haojin val ptwResp_valid = RegNext(io.ptw.resp.fire && Cat(ptwResp_OldMatchVec).orR, init = false.B) 46163632028SHaoyuan Feng // May send repeated requests to L2 tlb with same vpn(26, 3) when sector tlb 462cccfc98dSLemover val oldMatchVec_early = io.tlb.req.map(a => vpn.zip(v).map{ case (pi, vi) => vi && pi === a.bits.vpn}) 46387f41827SLemover val lastReqMatchVec_early = io.tlb.req.map(a => tlb_req.map{ b => b.valid && b.bits.vpn === a.bits.vpn && canEnqueue}) 464cccfc98dSLemover val newMatchVec_early = io.tlb.req.map(a => io.tlb.req.map(b => a.bits.vpn === b.bits.vpn)) 465cccfc98dSLemover 466cccfc98dSLemover (0 until Width) foreach { i => 467cccfc98dSLemover tlb_req(i).valid := RegNext(io.tlb.req(i).valid && 46863632028SHaoyuan Feng !(ptwResp_valid && ptwResp.hit(io.tlb.req(i).bits.vpn, 0.U, true, true)) && 469cccfc98dSLemover !Cat(lastReqMatchVec_early(i)).orR, 470cccfc98dSLemover init = false.B) 471cccfc98dSLemover tlb_req(i).bits := RegEnable(io.tlb.req(i).bits, io.tlb.req(i).valid) 472cccfc98dSLemover } 473cccfc98dSLemover 474cccfc98dSLemover val oldMatchVec = oldMatchVec_early.map(a => RegNext(Cat(a).orR)) 475cccfc98dSLemover val newMatchVec = (0 until Width).map(i => (0 until Width).map(j => 476cccfc98dSLemover RegNext(newMatchVec_early(i)(j)) && tlb_req(j).valid 477cccfc98dSLemover )) 478cccfc98dSLemover val ptwResp_newMatchVec = tlb_req.map(a => 47963632028SHaoyuan Feng ptwResp_valid && ptwResp.hit(a.bits.vpn, 0.U, allType = true, true)) 480cccfc98dSLemover 481cccfc98dSLemover val oldMatchVec2 = (0 until Width).map(i => oldMatchVec_early(i).map(RegNext(_)).map(_ & tlb_req(i).valid)) 482cccfc98dSLemover val update_ports = v.indices.map(i => oldMatchVec2.map(j => j(i))) 483a0301c0dSLemover val ports_init = (0 until Width).map(i => (1 << i).U(Width.W)) 484a0301c0dSLemover val filter_ports = (0 until Width).map(i => ParallelMux(newMatchVec(i).zip(ports_init).drop(i))) 485935edac4STang Haojin val resp_vector = RegEnable(ParallelMux(ptwResp_OldMatchVec zip ports), io.ptw.resp.fire) 4866d5ddbceSLemover 487a0301c0dSLemover def canMerge(index: Int) : Bool = { 488cccfc98dSLemover ptwResp_newMatchVec(index) || oldMatchVec(index) || 489a0301c0dSLemover Cat(newMatchVec(index).take(index)).orR 490a0301c0dSLemover } 491a0301c0dSLemover 492a0301c0dSLemover def filter_req() = { 493a0301c0dSLemover val reqs = tlb_req.indices.map{ i => 4948744445eSMaxpicca-Li val req = Wire(ValidIO(new PtwReqwithMemIdx())) 495a0301c0dSLemover val merge = canMerge(i) 496a0301c0dSLemover req.bits := tlb_req(i).bits 497a0301c0dSLemover req.valid := !merge && tlb_req(i).valid 498a0301c0dSLemover req 499a0301c0dSLemover } 500a0301c0dSLemover reqs 501a0301c0dSLemover } 502a0301c0dSLemover 503a0301c0dSLemover val reqs = filter_req() 504a0301c0dSLemover val req_ports = filter_ports 5056d5ddbceSLemover val isFull = enqPtr === deqPtr && mayFullDeq 5066d5ddbceSLemover val isEmptyDeq = enqPtr === deqPtr && !mayFullDeq 5076d5ddbceSLemover val isEmptyIss = enqPtr === issPtr && !mayFullIss 5086d5ddbceSLemover val accumEnqNum = (0 until Width).map(i => PopCount(reqs.take(i).map(_.valid))) 509cccfc98dSLemover val enqPtrVecInit = VecInit((0 until Width).map(i => enqPtr + i.U)) 510cccfc98dSLemover val enqPtrVec = VecInit((0 until Width).map(i => enqPtrVecInit(accumEnqNum(i)))) 5116d5ddbceSLemover val enqNum = PopCount(reqs.map(_.valid)) 51287f41827SLemover canEnqueue := counter +& enqNum <= Size.U 5136d5ddbceSLemover 514f1fe8698SLemover // the req may recv false ready, but actually received. Filter and TLB will handle it. 515f1fe8698SLemover val enqNum_fake = PopCount(io.tlb.req.map(_.valid)) 516f1fe8698SLemover val canEnqueue_fake = counter +& enqNum_fake <= Size.U 517f1fe8698SLemover io.tlb.req.map(_.ready := canEnqueue_fake) // NOTE: just drop un-fire reqs 518f1fe8698SLemover 5190ab9ba15SLemover // tlb req flushed by ptw resp: last ptw resp && current ptw resp 5200ab9ba15SLemover // the flushed tlb req will fakely enq, with a false valid 52163632028SHaoyuan Feng val tlb_req_flushed = reqs.map(a => io.ptw.resp.valid && io.ptw.resp.bits.hit(a.bits.vpn, 0.U, true, true)) 5220ab9ba15SLemover 523cccfc98dSLemover io.tlb.resp.valid := ptwResp_valid 5248744445eSMaxpicca-Li io.tlb.resp.bits.data.entry := ptwResp.entry 52563632028SHaoyuan Feng io.tlb.resp.bits.data.addr_low := ptwResp.addr_low 52663632028SHaoyuan Feng io.tlb.resp.bits.data.ppn_low := ptwResp.ppn_low 52763632028SHaoyuan Feng io.tlb.resp.bits.data.valididx := ptwResp.valididx 528b0fa7106SHaoyuan Feng io.tlb.resp.bits.data.pteidx := ptwResp.pteidx 5298744445eSMaxpicca-Li io.tlb.resp.bits.data.pf := ptwResp.pf 5308744445eSMaxpicca-Li io.tlb.resp.bits.data.af := ptwResp.af 5318744445eSMaxpicca-Li io.tlb.resp.bits.data.memidx := memidx(OHToUInt(ptwResp_OldMatchVec)) 532a0301c0dSLemover io.tlb.resp.bits.vector := resp_vector 5332c2c1588SLemover 534fa9f9690SLemover val issue_valid = v(issPtr) && !isEmptyIss && !inflight_full 53563632028SHaoyuan Feng val issue_filtered = ptwResp_valid && ptwResp.hit(io.ptw.req(0).bits.vpn, io.csr.satp.asid, allType=true, ignoreAsid=true) 5362c2c1588SLemover val issue_fire_fake = issue_valid && (io.ptw.req(0).ready || (issue_filtered && false.B /*timing-opt*/)) 5372c2c1588SLemover io.ptw.req(0).valid := issue_valid && !issue_filtered 5386d5ddbceSLemover io.ptw.req(0).bits.vpn := vpn(issPtr) 5396d5ddbceSLemover io.ptw.resp.ready := true.B 5406d5ddbceSLemover 5416d5ddbceSLemover reqs.zipWithIndex.map{ 5426d5ddbceSLemover case (req, i) => 5436d5ddbceSLemover when (req.valid && canEnqueue) { 5440ab9ba15SLemover v(enqPtrVec(i)) := !tlb_req_flushed(i) 5456d5ddbceSLemover vpn(enqPtrVec(i)) := req.bits.vpn 5468744445eSMaxpicca-Li memidx(enqPtrVec(i)) := req.bits.memidx 547a0301c0dSLemover ports(enqPtrVec(i)) := req_ports(i).asBools 548a0301c0dSLemover } 549a0301c0dSLemover } 550a0301c0dSLemover for (i <- ports.indices) { 551a0301c0dSLemover when (v(i)) { 552a0301c0dSLemover ports(i) := ports(i).zip(update_ports(i)).map(a => a._1 || a._2) 5536d5ddbceSLemover } 5546d5ddbceSLemover } 5556d5ddbceSLemover 5566d5ddbceSLemover val do_enq = canEnqueue && Cat(reqs.map(_.valid)).orR 5576d5ddbceSLemover val do_deq = (!v(deqPtr) && !isEmptyDeq) 5582c2c1588SLemover val do_iss = issue_fire_fake || (!v(issPtr) && !isEmptyIss) 5596d5ddbceSLemover when (do_enq) { 5606d5ddbceSLemover enqPtr := enqPtr + enqNum 5616d5ddbceSLemover } 5626d5ddbceSLemover when (do_deq) { 5636d5ddbceSLemover deqPtr := deqPtr + 1.U 5646d5ddbceSLemover } 5656d5ddbceSLemover when (do_iss) { 5666d5ddbceSLemover issPtr := issPtr + 1.U 5676d5ddbceSLemover } 5682c2c1588SLemover when (issue_fire_fake && issue_filtered) { // issued but is filtered 5692c2c1588SLemover v(issPtr) := false.B 5702c2c1588SLemover } 5716d5ddbceSLemover when (do_enq =/= do_deq) { 5726d5ddbceSLemover mayFullDeq := do_enq 5736d5ddbceSLemover } 5746d5ddbceSLemover when (do_enq =/= do_iss) { 5756d5ddbceSLemover mayFullIss := do_enq 5766d5ddbceSLemover } 5776d5ddbceSLemover 578935edac4STang Haojin when (io.ptw.resp.fire) { 579cccfc98dSLemover v.zip(ptwResp_OldMatchVec).map{ case (vi, mi) => when (mi) { vi := false.B }} 5806d5ddbceSLemover } 5816d5ddbceSLemover 5826d5ddbceSLemover counter := counter - do_deq + Mux(do_enq, enqNum, 0.U) 583fa9f9690SLemover assert(counter <= Size.U, "counter should be no more than Size") 584fa9f9690SLemover assert(inflight_counter <= Size.U, "inflight should be no more than Size") 5856d5ddbceSLemover when (counter === 0.U) { 586935edac4STang Haojin assert(!io.ptw.req(0).fire, "when counter is 0, should not req") 5876d5ddbceSLemover assert(isEmptyDeq && isEmptyIss, "when counter is 0, should be empty") 5886d5ddbceSLemover } 5896d5ddbceSLemover when (counter === Size.U) { 5906d5ddbceSLemover assert(mayFullDeq, "when counter is Size, should be full") 5916d5ddbceSLemover } 5926d5ddbceSLemover 59345f497a4Shappy-lx when (flush) { 5946d5ddbceSLemover v.map(_ := false.B) 5956d5ddbceSLemover deqPtr := 0.U 5966d5ddbceSLemover enqPtr := 0.U 5976d5ddbceSLemover issPtr := 0.U 5986d5ddbceSLemover ptwResp_valid := false.B 5996d5ddbceSLemover mayFullDeq := false.B 6006d5ddbceSLemover mayFullIss := false.B 6016d5ddbceSLemover counter := 0.U 602fa9f9690SLemover inflight_counter := 0.U 6036d5ddbceSLemover } 6046d5ddbceSLemover 60560ebee38STang Haojin val robHeadVaddr = io.debugTopDown.robHeadVaddr 606d2b20d1aSTang Haojin io.rob_head_miss_in_tlb := VecInit(v.zip(vpn).map{case (vi, vpni) => { 60760ebee38STang Haojin vi && robHeadVaddr.valid && vpni === get_pn(robHeadVaddr.bits) 608d2b20d1aSTang Haojin }}).asUInt.orR 609d2b20d1aSTang Haojin 6106d5ddbceSLemover // perf 6116d5ddbceSLemover XSPerfAccumulate("tlb_req_count", PopCount(Cat(io.tlb.req.map(_.valid)))) 6126d5ddbceSLemover XSPerfAccumulate("tlb_req_count_filtered", Mux(do_enq, accumEnqNum(Width - 1), 0.U)) 613935edac4STang Haojin XSPerfAccumulate("ptw_req_count", io.ptw.req(0).fire) 6146d5ddbceSLemover XSPerfAccumulate("ptw_req_cycle", inflight_counter) 615935edac4STang Haojin XSPerfAccumulate("tlb_resp_count", io.tlb.resp.fire) 616935edac4STang Haojin XSPerfAccumulate("ptw_resp_count", io.ptw.resp.fire) 6176d5ddbceSLemover XSPerfAccumulate("inflight_cycle", !isEmptyDeq) 6186d5ddbceSLemover for (i <- 0 until Size + 1) { 6196d5ddbceSLemover XSPerfAccumulate(s"counter${i}", counter === i.U) 6206d5ddbceSLemover } 6219bd9cdfaSLemover 6229bd9cdfaSLemover for (i <- 0 until Size) { 6239bd9cdfaSLemover TimeOutAssert(v(i), timeOutThreshold, s"Filter ${i} doesn't recv resp in time") 6249bd9cdfaSLemover } 6256d5ddbceSLemover} 62638ba1efdSLemover 62738ba1efdSLemoverobject PTWRepeater { 628f1fe8698SLemover def apply(fenceDelay: Int, 62938ba1efdSLemover tlb: TlbPtwIO, 63038ba1efdSLemover sfence: SfenceBundle, 63138ba1efdSLemover csr: TlbCsrBundle 63238ba1efdSLemover )(implicit p: Parameters) = { 63338ba1efdSLemover val width = tlb.req.size 634f1fe8698SLemover val repeater = Module(new PTWRepeater(width, fenceDelay)) 63535d6335eSZhangZifei repeater.io.apply(tlb, sfence, csr) 63638ba1efdSLemover repeater 63738ba1efdSLemover } 63838ba1efdSLemover 639f1fe8698SLemover def apply(fenceDelay: Int, 64038ba1efdSLemover tlb: TlbPtwIO, 64138ba1efdSLemover ptw: TlbPtwIO, 64238ba1efdSLemover sfence: SfenceBundle, 64338ba1efdSLemover csr: TlbCsrBundle 64438ba1efdSLemover )(implicit p: Parameters) = { 64538ba1efdSLemover val width = tlb.req.size 646f1fe8698SLemover val repeater = Module(new PTWRepeater(width, fenceDelay)) 64735d6335eSZhangZifei repeater.io.apply(tlb, ptw, sfence, csr) 64835d6335eSZhangZifei repeater 64935d6335eSZhangZifei } 65035d6335eSZhangZifei} 65138ba1efdSLemover 65235d6335eSZhangZifeiobject PTWRepeaterNB { 653f1fe8698SLemover def apply(passReady: Boolean, fenceDelay: Int, 65435d6335eSZhangZifei tlb: TlbPtwIO, 65535d6335eSZhangZifei sfence: SfenceBundle, 65635d6335eSZhangZifei csr: TlbCsrBundle 65735d6335eSZhangZifei )(implicit p: Parameters) = { 65835d6335eSZhangZifei val width = tlb.req.size 659f1fe8698SLemover val repeater = Module(new PTWRepeaterNB(width, passReady,fenceDelay)) 66035d6335eSZhangZifei repeater.io.apply(tlb, sfence, csr) 66135d6335eSZhangZifei repeater 66235d6335eSZhangZifei } 66335d6335eSZhangZifei 664f1fe8698SLemover def apply(passReady: Boolean, fenceDelay: Int, 66535d6335eSZhangZifei tlb: TlbPtwIO, 66635d6335eSZhangZifei ptw: TlbPtwIO, 66735d6335eSZhangZifei sfence: SfenceBundle, 66835d6335eSZhangZifei csr: TlbCsrBundle 66935d6335eSZhangZifei )(implicit p: Parameters) = { 67035d6335eSZhangZifei val width = tlb.req.size 671f1fe8698SLemover val repeater = Module(new PTWRepeaterNB(width, passReady, fenceDelay)) 67235d6335eSZhangZifei repeater.io.apply(tlb, ptw, sfence, csr) 67338ba1efdSLemover repeater 67438ba1efdSLemover } 67538ba1efdSLemover} 67638ba1efdSLemover 67738ba1efdSLemoverobject PTWFilter { 678f1fe8698SLemover def apply(fenceDelay: Int, 679f1fe8698SLemover tlb: VectorTlbPtwIO, 68038ba1efdSLemover ptw: TlbPtwIO, 68138ba1efdSLemover sfence: SfenceBundle, 68238ba1efdSLemover csr: TlbCsrBundle, 68338ba1efdSLemover size: Int 68438ba1efdSLemover )(implicit p: Parameters) = { 68538ba1efdSLemover val width = tlb.req.size 686f1fe8698SLemover val filter = Module(new PTWFilter(width, size, fenceDelay)) 68735d6335eSZhangZifei filter.io.apply(tlb, ptw, sfence, csr) 68838ba1efdSLemover filter 68938ba1efdSLemover } 69035d6335eSZhangZifei 691f1fe8698SLemover def apply(fenceDelay: Int, 692f1fe8698SLemover tlb: VectorTlbPtwIO, 69335d6335eSZhangZifei sfence: SfenceBundle, 69435d6335eSZhangZifei csr: TlbCsrBundle, 69535d6335eSZhangZifei size: Int 69635d6335eSZhangZifei )(implicit p: Parameters) = { 69735d6335eSZhangZifei val width = tlb.req.size 698f1fe8698SLemover val filter = Module(new PTWFilter(width, size, fenceDelay)) 69935d6335eSZhangZifei filter.io.apply(tlb, sfence, csr) 70035d6335eSZhangZifei filter 70135d6335eSZhangZifei } 702185e6164SHaoyuan Feng} 70335d6335eSZhangZifei 704185e6164SHaoyuan Fengobject PTWNewFilter { 705185e6164SHaoyuan Feng def apply(fenceDelay: Int, 706185e6164SHaoyuan Feng tlb: VectorTlbPtwIO, 707185e6164SHaoyuan Feng ptw: TlbPtwIO, 708185e6164SHaoyuan Feng sfence: SfenceBundle, 709185e6164SHaoyuan Feng csr: TlbCsrBundle, 710185e6164SHaoyuan Feng size: Int 711185e6164SHaoyuan Feng )(implicit p: Parameters) = { 712185e6164SHaoyuan Feng val width = tlb.req.size 713185e6164SHaoyuan Feng val filter = Module(new PTWNewFilter(width, size, fenceDelay)) 714185e6164SHaoyuan Feng filter.io.apply(tlb, ptw, sfence, csr) 715185e6164SHaoyuan Feng filter 716185e6164SHaoyuan Feng } 717185e6164SHaoyuan Feng 718185e6164SHaoyuan Feng def apply(fenceDelay: Int, 719185e6164SHaoyuan Feng tlb: VectorTlbPtwIO, 720185e6164SHaoyuan Feng sfence: SfenceBundle, 721185e6164SHaoyuan Feng csr: TlbCsrBundle, 722185e6164SHaoyuan Feng size: Int 723185e6164SHaoyuan Feng )(implicit p: Parameters) = { 724185e6164SHaoyuan Feng val width = tlb.req.size 725185e6164SHaoyuan Feng val filter = Module(new PTWNewFilter(width, size, fenceDelay)) 726185e6164SHaoyuan Feng filter.io.apply(tlb, sfence, csr) 727185e6164SHaoyuan Feng filter 728185e6164SHaoyuan Feng } 72938ba1efdSLemover} 730