16d5ddbceSLemover/*************************************************************************************** 2e3da8badSTang Haojin* Copyright (c) 2024 Beijing Institute of Open Source Chip (BOSC) 3e3da8badSTang Haojin* Copyright (c) 2020-2024 Institute of Computing Technology, Chinese Academy of Sciences 4f320e0f0SYinan Xu* Copyright (c) 2020-2021 Peng Cheng Laboratory 56d5ddbceSLemover* 66d5ddbceSLemover* XiangShan is licensed under Mulan PSL v2. 76d5ddbceSLemover* You can use this software according to the terms and conditions of the Mulan PSL v2. 86d5ddbceSLemover* You may obtain a copy of Mulan PSL v2 at: 96d5ddbceSLemover* http://license.coscl.org.cn/MulanPSL2 106d5ddbceSLemover* 116d5ddbceSLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 126d5ddbceSLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 136d5ddbceSLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 146d5ddbceSLemover* 156d5ddbceSLemover* See the Mulan PSL v2 for more details. 166d5ddbceSLemover***************************************************************************************/ 176d5ddbceSLemover 186d5ddbceSLemoverpackage xiangshan.cache.mmu 196d5ddbceSLemover 208891a219SYinan Xuimport org.chipsalliance.cde.config.Parameters 216d5ddbceSLemoverimport chisel3._ 226d5ddbceSLemoverimport chisel3.util._ 236d5ddbceSLemoverimport xiangshan._ 246d5ddbceSLemoverimport xiangshan.cache.{HasDCacheParameters, MemoryOpConstants} 256d5ddbceSLemoverimport utils._ 263c02ee8fSwakafaimport utility._ 276d5ddbceSLemoverimport freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 286d5ddbceSLemoverimport freechips.rocketchip.tilelink._ 296d5ddbceSLemover 306d5ddbceSLemover/* ptw cache caches the page table of all the three layers 316d5ddbceSLemover * ptw cache resp at next cycle 326d5ddbceSLemover * the cache should not be blocked 336d5ddbceSLemover * when miss queue if full, just block req outside 346d5ddbceSLemover */ 353889e11eSLemover 363889e11eSLemoverclass PageCachePerPespBundle(implicit p: Parameters) extends PtwBundle { 373889e11eSLemover val hit = Bool() 383889e11eSLemover val pre = Bool() 394c0e0181SXiaokun-Pei val ppn = UInt(gvpnLen.W) 403889e11eSLemover val perm = new PtePermBundle() 413889e11eSLemover val ecc = Bool() 423889e11eSLemover val level = UInt(2.W) 438d8ac704SLemover val v = Bool() 443889e11eSLemover 453889e11eSLemover def apply(hit: Bool, pre: Bool, ppn: UInt, perm: PtePermBundle = 0.U.asTypeOf(new PtePermBundle()), 46e3da8badSTang Haojin ecc: Bool = false.B, level: UInt = 0.U, valid: Bool = true.B): Unit = { 473889e11eSLemover this.hit := hit && !ecc 483889e11eSLemover this.pre := pre 493889e11eSLemover this.ppn := ppn 503889e11eSLemover this.perm := perm 513889e11eSLemover this.ecc := ecc && hit 523889e11eSLemover this.level := level 538d8ac704SLemover this.v := valid 543889e11eSLemover } 553889e11eSLemover} 563889e11eSLemover 5763632028SHaoyuan Fengclass PageCacheMergePespBundle(implicit p: Parameters) extends PtwBundle { 5863632028SHaoyuan Feng assert(tlbcontiguous == 8, "Only support tlbcontiguous = 8!") 5963632028SHaoyuan Feng val hit = Bool() 6063632028SHaoyuan Feng val pre = Bool() 614c0e0181SXiaokun-Pei val ppn = Vec(tlbcontiguous, UInt(gvpnLen.W)) 6263632028SHaoyuan Feng val perm = Vec(tlbcontiguous, new PtePermBundle()) 6363632028SHaoyuan Feng val ecc = Bool() 6463632028SHaoyuan Feng val level = UInt(2.W) 6563632028SHaoyuan Feng val v = Vec(tlbcontiguous, Bool()) 664ed5afbdSXiaokun-Pei val af = Vec(tlbcontiguous, Bool()) 6763632028SHaoyuan Feng 6863632028SHaoyuan Feng def apply(hit: Bool, pre: Bool, ppn: Vec[UInt], perm: Vec[PtePermBundle] = Vec(tlbcontiguous, 0.U.asTypeOf(new PtePermBundle())), 694ed5afbdSXiaokun-Pei ecc: Bool = false.B, level: UInt = 0.U, valid: Vec[Bool] = Vec(tlbcontiguous, true.B), accessFault: Vec[Bool] = Vec(tlbcontiguous, true.B)): Unit = { 7063632028SHaoyuan Feng this.hit := hit && !ecc 7163632028SHaoyuan Feng this.pre := pre 7263632028SHaoyuan Feng this.ppn := ppn 7363632028SHaoyuan Feng this.perm := perm 7463632028SHaoyuan Feng this.ecc := ecc && hit 7563632028SHaoyuan Feng this.level := level 7663632028SHaoyuan Feng this.v := valid 774ed5afbdSXiaokun-Pei this.af := accessFault 7863632028SHaoyuan Feng } 7963632028SHaoyuan Feng} 8063632028SHaoyuan Feng 813889e11eSLemoverclass PageCacheRespBundle(implicit p: Parameters) extends PtwBundle { 82*3ea4388cSHaoyuan Feng val l3 = if (EnableSv48) Some(new PageCachePerPespBundle) else None 833889e11eSLemover val l2 = new PageCachePerPespBundle 84*3ea4388cSHaoyuan Feng val l1 = new PageCachePerPespBundle 85*3ea4388cSHaoyuan Feng val l0 = new PageCacheMergePespBundle 863889e11eSLemover val sp = new PageCachePerPespBundle 873889e11eSLemover} 883889e11eSLemover 893889e11eSLemoverclass PtwCacheReq(implicit p: Parameters) extends PtwBundle { 903889e11eSLemover val req_info = new L2TlbInnerBundle() 913889e11eSLemover val isFirst = Bool() 92*3ea4388cSHaoyuan Feng val bypassed = if (EnableSv48) Vec(4, Bool()) else Vec(3, Bool()) 93325f0a4eSpeixiaokun val isHptwReq = Bool() 94d0de7e4aSpeixiaokun val hptwId = UInt(log2Up(l2tlbParams.llptwsize).W) 953889e11eSLemover} 963889e11eSLemover 973889e11eSLemoverclass PtwCacheIO()(implicit p: Parameters) extends MMUIOBaseBundle with HasPtwConst { 983889e11eSLemover val req = Flipped(DecoupledIO(new PtwCacheReq())) 996d5ddbceSLemover val resp = DecoupledIO(new Bundle { 10045f497a4Shappy-lx val req_info = new L2TlbInnerBundle() 10194133605SLemover val isFirst = Bool() 1026d5ddbceSLemover val hit = Bool() 103bc063562SLemover val prefetch = Bool() // is the entry fetched by prefetch 1041f4a7c0cSLemover val bypassed = Bool() 1056d5ddbceSLemover val toFsm = new Bundle { 106*3ea4388cSHaoyuan Feng val l3Hit = if (EnableSv48) Some(Bool()) else None 1076d5ddbceSLemover val l2Hit = Bool() 108*3ea4388cSHaoyuan Feng val l1Hit = Bool() 1094c0e0181SXiaokun-Pei val ppn = UInt(gvpnLen.W) 11030104977Speixiaokun val stage1Hit = Bool() // find stage 1 pte in cache, but need to search stage 2 pte in cache at PTW 1116d5ddbceSLemover } 1126979864eSXiaokun-Pei val stage1 = new PtwMergeResp() 113325f0a4eSpeixiaokun val isHptwReq = Bool() 114d0de7e4aSpeixiaokun val toHptw = new Bundle { 115*3ea4388cSHaoyuan Feng val l3Hit = if (EnableSv48) Some(Bool()) else None 116d0de7e4aSpeixiaokun val l2Hit = Bool() 117*3ea4388cSHaoyuan Feng val l1Hit = Bool() 118d0de7e4aSpeixiaokun val ppn = UInt(ppnLen.W) 119d0de7e4aSpeixiaokun val id = UInt(log2Up(l2tlbParams.llptwsize).W) 120d0de7e4aSpeixiaokun val resp = new HptwResp() // used if hit 12183d93d53Speixiaokun val bypassed = Bool() 122d0de7e4aSpeixiaokun } 1236d5ddbceSLemover }) 1246d5ddbceSLemover val refill = Flipped(ValidIO(new Bundle { 1255854c1edSLemover val ptes = UInt(blockBits.W) 1267797f035SbugGenerator val levelOH = new Bundle { 1277797f035SbugGenerator // NOTE: levelOH has (Level+1) bits, each stands for page cache entries 1287797f035SbugGenerator val sp = Bool() 129*3ea4388cSHaoyuan Feng val l0 = Bool() 1307797f035SbugGenerator val l1 = Bool() 131*3ea4388cSHaoyuan Feng val l2 = Bool() 132*3ea4388cSHaoyuan Feng val l3 = if (EnableSv48) Some(Bool()) else None 1337797f035SbugGenerator def apply(levelUInt: UInt, valid: Bool) = { 134*3ea4388cSHaoyuan Feng sp := GatedValidRegNext((levelUInt === 1.U || levelUInt === 2.U || levelUInt === 3.U) && valid, false.B) 135*3ea4388cSHaoyuan Feng l0 := GatedValidRegNext((levelUInt === 0.U) & valid, false.B) 136*3ea4388cSHaoyuan Feng l1 := GatedValidRegNext((levelUInt === 1.U) & valid, false.B) 137*3ea4388cSHaoyuan Feng l2 := GatedValidRegNext((levelUInt === 2.U) & valid, false.B) 138*3ea4388cSHaoyuan Feng l3.map(_ := GatedValidRegNext((levelUInt === 3.U) & valid, false.B)) 1397797f035SbugGenerator } 1407797f035SbugGenerator } 1417797f035SbugGenerator // duplicate level and sel_pte for each page caches, for better fanout 1427797f035SbugGenerator val req_info_dup = Vec(3, new L2TlbInnerBundle()) 143*3ea4388cSHaoyuan Feng val level_dup = Vec(3, UInt(log2Up(Level + 1).W)) 1447797f035SbugGenerator val sel_pte_dup = Vec(3, UInt(XLEN.W)) 1456d5ddbceSLemover })) 1467797f035SbugGenerator val sfence_dup = Vec(4, Input(new SfenceBundle())) 1477797f035SbugGenerator val csr_dup = Vec(3, Input(new TlbCsrBundle())) 1486d5ddbceSLemover} 1496d5ddbceSLemover 1501ca0e4f3SYinan Xuclass PtwCache()(implicit p: Parameters) extends XSModule with HasPtwConst with HasPerfEvents { 1516d5ddbceSLemover val io = IO(new PtwCacheIO) 1527196f5a2SLemover val ecc = Code.fromString(l2tlbParams.ecc) 153*3ea4388cSHaoyuan Feng val l1EntryType = new PTWEntriesWithEcc(ecc, num = PtwL1SectorSize, tagLen = PtwL1TagLen, level = 1, hasPerm = false) 154*3ea4388cSHaoyuan Feng val l0EntryType = new PTWEntriesWithEcc(ecc, num = PtwL0SectorSize, tagLen = PtwL0TagLen, level = 0, hasPerm = true) 1557196f5a2SLemover 1566d5ddbceSLemover // TODO: four caches make the codes dirty, think about how to deal with it 1576d5ddbceSLemover 1587797f035SbugGenerator val sfence_dup = io.sfence_dup 1596d5ddbceSLemover val refill = io.refill.bits 1607797f035SbugGenerator val refill_prefetch_dup = io.refill.bits.req_info_dup.map(a => from_pre(a.source)) 1614ed5afbdSXiaokun-Pei val refill_h = io.refill.bits.req_info_dup.map(a => Mux(a.s2xlate === allStage, onlyStage1, a.s2xlate)) 162d0de7e4aSpeixiaokun val flush_dup = sfence_dup.zip(io.csr_dup).map(f => f._1.valid || f._2.satp.changed || f._2.vsatp.changed || f._2.hgatp.changed) 1637797f035SbugGenerator val flush = flush_dup(0) 1646d5ddbceSLemover 1656d5ddbceSLemover // when refill, refuce to accept new req 1665854c1edSLemover val rwHarzad = if (sramSinglePort) io.refill.valid else false.B 1673889e11eSLemover 1683889e11eSLemover // handle hand signal and req_info 1696c4dcc2dSLemover // TODO: replace with FlushableQueue 1706c4dcc2dSLemover val stageReq = Wire(Decoupled(new PtwCacheReq())) // enq stage & read page cache valid 1716c4dcc2dSLemover val stageDelay = Wire(Vec(2, Decoupled(new PtwCacheReq()))) // page cache resp 1726c4dcc2dSLemover val stageCheck = Wire(Vec(2, Decoupled(new PtwCacheReq()))) // check hit & check ecc 1736c4dcc2dSLemover val stageResp = Wire(Decoupled(new PtwCacheReq())) // deq stage 1747797f035SbugGenerator 1757797f035SbugGenerator val stageDelay_valid_1cycle = OneCycleValid(stageReq.fire, flush) // catch ram data 1767797f035SbugGenerator val stageCheck_valid_1cycle = OneCycleValid(stageDelay(1).fire, flush) // replace & perf counter 1777797f035SbugGenerator val stageResp_valid_1cycle_dup = Wire(Vec(2, Bool())) 1787797f035SbugGenerator stageResp_valid_1cycle_dup.map(_ := OneCycleValid(stageCheck(1).fire, flush)) // ecc flush 1797797f035SbugGenerator 1806c4dcc2dSLemover stageReq <> io.req 1816c4dcc2dSLemover PipelineConnect(stageReq, stageDelay(0), stageDelay(1).ready, flush, rwHarzad) 1827797f035SbugGenerator InsideStageConnect(stageDelay(0), stageDelay(1), stageDelay_valid_1cycle) 1836c4dcc2dSLemover PipelineConnect(stageDelay(1), stageCheck(0), stageCheck(1).ready, flush) 1847797f035SbugGenerator InsideStageConnect(stageCheck(0), stageCheck(1), stageCheck_valid_1cycle) 1856c4dcc2dSLemover PipelineConnect(stageCheck(1), stageResp, io.resp.ready, flush) 1866c4dcc2dSLemover stageResp.ready := !stageResp.valid || io.resp.ready 1876d5ddbceSLemover 188*3ea4388cSHaoyuan Feng // l3: level 3 non-leaf pte 189*3ea4388cSHaoyuan Feng val l3 = if (EnableSv48) Some(Reg(Vec(l2tlbParams.l3Size, new PtwEntry(tagLen = PtwL3TagLen)))) else None 190*3ea4388cSHaoyuan Feng val l3v = if (EnableSv48) Some(RegInit(0.U(l2tlbParams.l3Size.W))) else None 191*3ea4388cSHaoyuan Feng val l3g = if (EnableSv48) Some(Reg(UInt(l2tlbParams.l3Size.W))) else None 192*3ea4388cSHaoyuan Feng val l3asids = if (EnableSv48) Some(l3.get.map(_.asid)) else None 193*3ea4388cSHaoyuan Feng val l3vmids = if (EnableSv48) Some(l3.get.map(_.vmid)) else None 194*3ea4388cSHaoyuan Feng val l3h = if (EnableSv48) Some(Reg(Vec(l2tlbParams.l3Size, UInt(2.W)))) else None 1956d5ddbceSLemover 196*3ea4388cSHaoyuan Feng // l2: level 2 non-leaf pte 197*3ea4388cSHaoyuan Feng val l2 = Reg(Vec(l2tlbParams.l2Size, new PtwEntry(tagLen = PtwL2TagLen))) 198*3ea4388cSHaoyuan Feng val l2v = RegInit(0.U(l2tlbParams.l2Size.W)) 199*3ea4388cSHaoyuan Feng val l2g = Reg(UInt(l2tlbParams.l2Size.W)) 200*3ea4388cSHaoyuan Feng val l2asids = l2.map(_.asid) 201*3ea4388cSHaoyuan Feng val l2vmids = l2.map(_.vmid) 202*3ea4388cSHaoyuan Feng val l2h = Reg(Vec(l2tlbParams.l2Size, UInt(2.W))) 203*3ea4388cSHaoyuan Feng 204*3ea4388cSHaoyuan Feng // l1: level 1 non-leaf pte 205*3ea4388cSHaoyuan Feng val l1 = Module(new SRAMTemplate( 206*3ea4388cSHaoyuan Feng l1EntryType, 207*3ea4388cSHaoyuan Feng set = l2tlbParams.l1nSets, 208*3ea4388cSHaoyuan Feng way = l2tlbParams.l1nWays, 2095854c1edSLemover singlePort = sramSinglePort 2106d5ddbceSLemover )) 211*3ea4388cSHaoyuan Feng val l1v = RegInit(0.U((l2tlbParams.l1nSets * l2tlbParams.l1nWays).W)) 212*3ea4388cSHaoyuan Feng val l1g = Reg(UInt((l2tlbParams.l1nSets * l2tlbParams.l1nWays).W)) 213*3ea4388cSHaoyuan Feng val l1h = Reg(Vec(l2tlbParams.l1nSets, Vec(l2tlbParams.l1nWays, UInt(2.W)))) 214*3ea4388cSHaoyuan Feng def getl1vSet(vpn: UInt) = { 215*3ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l1nWays) == log2Down(l2tlbParams.l1nWays)) 216*3ea4388cSHaoyuan Feng val set = genPtwL1SetIdx(vpn) 217*3ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l1nSets)) 218*3ea4388cSHaoyuan Feng val l1vVec = l1v.asTypeOf(Vec(l2tlbParams.l1nSets, UInt(l2tlbParams.l1nWays.W))) 219*3ea4388cSHaoyuan Feng l1vVec(set) 2206d5ddbceSLemover } 221*3ea4388cSHaoyuan Feng def getl1hSet(vpn: UInt) = { 222*3ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l1nWays) == log2Down(l2tlbParams.l1nWays)) 223*3ea4388cSHaoyuan Feng val set = genPtwL1SetIdx(vpn) 224*3ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l1nSets)) 225*3ea4388cSHaoyuan Feng l1h(set) 22645f497a4Shappy-lx } 2276d5ddbceSLemover 228*3ea4388cSHaoyuan Feng // l0: level 0 leaf pte of 4KB pages 229*3ea4388cSHaoyuan Feng val l0 = Module(new SRAMTemplate( 230*3ea4388cSHaoyuan Feng l0EntryType, 231*3ea4388cSHaoyuan Feng set = l2tlbParams.l0nSets, 232*3ea4388cSHaoyuan Feng way = l2tlbParams.l0nWays, 2335854c1edSLemover singlePort = sramSinglePort 2346d5ddbceSLemover )) 235*3ea4388cSHaoyuan Feng val l0v = RegInit(0.U((l2tlbParams.l0nSets * l2tlbParams.l0nWays).W)) 236*3ea4388cSHaoyuan Feng val l0g = Reg(UInt((l2tlbParams.l0nSets * l2tlbParams.l0nWays).W)) 237*3ea4388cSHaoyuan Feng val l0h = Reg(Vec(l2tlbParams.l0nSets, Vec(l2tlbParams.l0nWays, UInt(2.W)))) 238*3ea4388cSHaoyuan Feng def getl0vSet(vpn: UInt) = { 239*3ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l0nWays) == log2Down(l2tlbParams.l0nWays)) 240*3ea4388cSHaoyuan Feng val set = genPtwL0SetIdx(vpn) 241*3ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l0nSets)) 242*3ea4388cSHaoyuan Feng val l0vVec = l0v.asTypeOf(Vec(l2tlbParams.l0nSets, UInt(l2tlbParams.l0nWays.W))) 243*3ea4388cSHaoyuan Feng l0vVec(set) 2446d5ddbceSLemover } 245*3ea4388cSHaoyuan Feng def getl0hSet(vpn: UInt) = { 246*3ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l0nWays) == log2Down(l2tlbParams.l0nWays)) 247*3ea4388cSHaoyuan Feng val set = genPtwL0SetIdx(vpn) 248*3ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l0nSets)) 249*3ea4388cSHaoyuan Feng l0h(set) 25045f497a4Shappy-lx } 2516d5ddbceSLemover 252*3ea4388cSHaoyuan Feng // sp: level 1/2/3 leaf pte of 512GB/1GB/2MB super pages 2535854c1edSLemover val sp = Reg(Vec(l2tlbParams.spSize, new PtwEntry(tagLen = SPTagLen, hasPerm = true, hasLevel = true))) 2545854c1edSLemover val spv = RegInit(0.U(l2tlbParams.spSize.W)) 2555854c1edSLemover val spg = Reg(UInt(l2tlbParams.spSize.W)) 2561dd3e32dSHaoyuan Feng val spasids = sp.map(_.asid) 257d0de7e4aSpeixiaokun val spvmids = sp.map(_.vmid) 258d61cd5eeSpeixiaokun val sph = Reg(Vec(l2tlbParams.spSize, UInt(2.W))) 2596d5ddbceSLemover 2606d5ddbceSLemover // Access Perf 261*3ea4388cSHaoyuan Feng val l3AccessPerf = if(EnableSv48) Some(Wire(Vec(l2tlbParams.l3Size, Bool()))) else None 262*3ea4388cSHaoyuan Feng val l2AccessPerf = Wire(Vec(l2tlbParams.l2Size, Bool())) 263*3ea4388cSHaoyuan Feng val l1AccessPerf = Wire(Vec(l2tlbParams.l1nWays, Bool())) 264*3ea4388cSHaoyuan Feng val l0AccessPerf = Wire(Vec(l2tlbParams.l0nWays, Bool())) 2655854c1edSLemover val spAccessPerf = Wire(Vec(l2tlbParams.spSize, Bool())) 266*3ea4388cSHaoyuan Feng if (EnableSv48) l3AccessPerf.map(_.map(_ := false.B)) 2676d5ddbceSLemover l2AccessPerf.map(_ := false.B) 268*3ea4388cSHaoyuan Feng l1AccessPerf.map(_ := false.B) 269*3ea4388cSHaoyuan Feng l0AccessPerf.map(_ := false.B) 2706d5ddbceSLemover spAccessPerf.map(_ := false.B) 2716d5ddbceSLemover 2723889e11eSLemover 2731f4a7c0cSLemover 27482978df9Speixiaokun def vpn_match(vpn1: UInt, vpn2: UInt, level: Int) = { 275*3ea4388cSHaoyuan Feng (vpn1(vpnLen-1, vpnnLen*level+3) === vpn2(vpnLen-1, vpnnLen*level+3)) 2761f4a7c0cSLemover } 2771f4a7c0cSLemover // NOTE: not actually bypassed, just check if hit, re-access the page cache 278d0de7e4aSpeixiaokun def refill_bypass(vpn: UInt, level: Int, h_search: UInt) = { 2796f508cb5Speixiaokun val change_h = MuxLookup(h_search, noS2xlate)(Seq( 280980ddf4cSpeixiaokun allStage -> onlyStage1, 281980ddf4cSpeixiaokun onlyStage1 -> onlyStage1, 282980ddf4cSpeixiaokun onlyStage2 -> onlyStage2 283980ddf4cSpeixiaokun )) 2844ed5afbdSXiaokun-Pei val change_refill_h = MuxLookup(io.refill.bits.req_info_dup(0).s2xlate, noS2xlate)(Seq( 2854ed5afbdSXiaokun-Pei allStage -> onlyStage1, 2864ed5afbdSXiaokun-Pei onlyStage1 -> onlyStage1, 2874ed5afbdSXiaokun-Pei onlyStage2 -> onlyStage2 2884ed5afbdSXiaokun-Pei )) 289d0de7e4aSpeixiaokun val refill_vpn = io.refill.bits.req_info_dup(0).vpn 2904ed5afbdSXiaokun-Pei io.refill.valid && (level.U === io.refill.bits.level_dup(0)) && vpn_match(refill_vpn, vpn, level) && change_h === change_refill_h 2911f4a7c0cSLemover } 2921f4a7c0cSLemover 29382978df9Speixiaokun val vpn_search = stageReq.bits.req_info.vpn 2946f508cb5Speixiaokun val h_search = MuxLookup(stageReq.bits.req_info.s2xlate, noS2xlate)(Seq( 29509280d15Speixiaokun allStage -> onlyStage1, 29609280d15Speixiaokun onlyStage1 -> onlyStage1, 29709280d15Speixiaokun onlyStage2 -> onlyStage2 29809280d15Speixiaokun )) 299*3ea4388cSHaoyuan Feng 300*3ea4388cSHaoyuan Feng // l3 301*3ea4388cSHaoyuan Feng val l3Hit = if(EnableSv48) Some(Wire(Bool())) else None 302*3ea4388cSHaoyuan Feng val l3HitPPN = if(EnableSv48) Some(Wire(UInt(ppnLen.W))) else None 303*3ea4388cSHaoyuan Feng val l3Pre = if(EnableSv48) Some(Wire(Bool())) else None 304*3ea4388cSHaoyuan Feng val ptwl3replace = if(EnableSv48) Some(ReplacementPolicy.fromString(l2tlbParams.l3Replacer, l2tlbParams.l3Size)) else None 305*3ea4388cSHaoyuan Feng if (EnableSv48) { 306*3ea4388cSHaoyuan Feng val hitVecT = l3.get.zipWithIndex.map { 307*3ea4388cSHaoyuan Feng case (e, i) => (e.hit(vpn_search, io.csr_dup(2).satp.asid, io.csr_dup(2).vsatp.asid, io.csr_dup(2).hgatp.asid, s2xlate = h_search =/= noS2xlate) 308*3ea4388cSHaoyuan Feng && l3v.get(i) && h_search === l3h.get(i)) 309d0de7e4aSpeixiaokun } 3106c4dcc2dSLemover val hitVec = hitVecT.map(RegEnable(_, stageReq.fire)) 3111f4a7c0cSLemover 312*3ea4388cSHaoyuan Feng // stageDelay, but check for l3 313*3ea4388cSHaoyuan Feng val hitPPN = DataHoldBypass(ParallelPriorityMux(hitVec zip l3.get.map(_.ppn)), stageDelay_valid_1cycle) 314*3ea4388cSHaoyuan Feng val hitPre = DataHoldBypass(ParallelPriorityMux(hitVec zip l3.get.map(_.prefetch)), stageDelay_valid_1cycle) 3151f4a7c0cSLemover val hit = DataHoldBypass(ParallelOR(hitVec), stageDelay_valid_1cycle) 3166d5ddbceSLemover 317*3ea4388cSHaoyuan Feng when (hit && stageDelay_valid_1cycle) { ptwl3replace.get.access(OHToUInt(hitVec)) } 3186d5ddbceSLemover 319*3ea4388cSHaoyuan Feng l3AccessPerf.get.zip(hitVec).map{ case (l, h) => l := h && stageDelay_valid_1cycle} 320*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l3Size) { 321*3ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l3] l3(${i.U}) ${l3.get(i)} hit:${l3.get(i).hit(vpn_search, io.csr_dup(2).satp.asid, io.csr_dup(2).vsatp.asid, io.csr_dup(2).hgatp.asid, s2xlate = h_search =/= noS2xlate)}\n") 3226d5ddbceSLemover } 323*3ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l3] l3v:${Binary(l3v.get)} hitVecT:${Binary(VecInit(hitVecT).asUInt)}\n") 324*3ea4388cSHaoyuan Feng XSDebug(stageDelay(0).valid, p"[l3] l3Hit:${hit} l3HitPPN:0x${Hexadecimal(hitPPN)} hitVec:${VecInit(hitVec).asUInt}\n") 3256d5ddbceSLemover 326*3ea4388cSHaoyuan Feng VecInit(hitVecT).suggestName(s"l3_hitVecT") 327*3ea4388cSHaoyuan Feng VecInit(hitVec).suggestName(s"l3_hitVec") 328*3ea4388cSHaoyuan Feng 329*3ea4388cSHaoyuan Feng // synchronize with other entries with RegEnable 330*3ea4388cSHaoyuan Feng l3Hit.map(_ := RegEnable(hit, stageDelay(1).fire)) 331*3ea4388cSHaoyuan Feng l3HitPPN.map(_ := RegEnable(hitPPN, stageDelay(1).fire)) 332*3ea4388cSHaoyuan Feng l3Pre.map(_ := RegEnable(hitPre, stageDelay(1).fire)) 333*3ea4388cSHaoyuan Feng } 334*3ea4388cSHaoyuan Feng 335*3ea4388cSHaoyuan Feng // l2 336*3ea4388cSHaoyuan Feng val ptwl2replace = ReplacementPolicy.fromString(l2tlbParams.l2Replacer, l2tlbParams.l2Size) 337*3ea4388cSHaoyuan Feng val (l2Hit, l2HitPPN, l2Pre) = { 338*3ea4388cSHaoyuan Feng val hitVecT = l2.zipWithIndex.map { 339*3ea4388cSHaoyuan Feng case (e, i) => (e.hit(vpn_search, io.csr_dup(2).satp.asid, io.csr_dup(2).vsatp.asid, io.csr_dup(2).hgatp.asid, s2xlate = h_search =/= noS2xlate) 340*3ea4388cSHaoyuan Feng && l2v(i) && h_search === l2h(i)) 341*3ea4388cSHaoyuan Feng } 342*3ea4388cSHaoyuan Feng val hitVec = hitVecT.map(RegEnable(_, stageReq.fire)) 343*3ea4388cSHaoyuan Feng 344*3ea4388cSHaoyuan Feng // stageDelay, but check for l2 345*3ea4388cSHaoyuan Feng val hitPPN = DataHoldBypass(ParallelPriorityMux(hitVec zip l2.map(_.ppn)), stageDelay_valid_1cycle) 346*3ea4388cSHaoyuan Feng val hitPre = DataHoldBypass(ParallelPriorityMux(hitVec zip l2.map(_.prefetch)), stageDelay_valid_1cycle) 347*3ea4388cSHaoyuan Feng val hit = DataHoldBypass(ParallelOR(hitVec), stageDelay_valid_1cycle) 348*3ea4388cSHaoyuan Feng 349*3ea4388cSHaoyuan Feng when (hit && stageDelay_valid_1cycle) { ptwl2replace.access(OHToUInt(hitVec)) } 350*3ea4388cSHaoyuan Feng 351*3ea4388cSHaoyuan Feng l2AccessPerf.zip(hitVec).map{ case (l, h) => l := h && stageDelay_valid_1cycle} 352*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l2Size) { 353*3ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l2] l2(${i.U}) ${l2(i)} hit:${l2(i).hit(vpn_search, io.csr_dup(2).satp.asid, io.csr_dup(2).vsatp.asid, io.csr_dup(2).hgatp.asid, s2xlate = h_search =/= noS2xlate)}\n") 354*3ea4388cSHaoyuan Feng } 355*3ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l2] l2v:${Binary(l2v)} hitVecT:${Binary(VecInit(hitVecT).asUInt)}\n") 356*3ea4388cSHaoyuan Feng XSDebug(stageDelay(0).valid, p"[l2] l2Hit:${hit} l2HitPPN:0x${Hexadecimal(hitPPN)} hitVec:${VecInit(hitVec).asUInt}\n") 357*3ea4388cSHaoyuan Feng 358*3ea4388cSHaoyuan Feng VecInit(hitVecT).suggestName(s"l2_hitVecT") 359*3ea4388cSHaoyuan Feng VecInit(hitVec).suggestName(s"l2_hitVec") 3606d5ddbceSLemover 3616c4dcc2dSLemover // synchronize with other entries with RegEnable 3626c4dcc2dSLemover (RegEnable(hit, stageDelay(1).fire), 3636c4dcc2dSLemover RegEnable(hitPPN, stageDelay(1).fire), 3646c4dcc2dSLemover RegEnable(hitPre, stageDelay(1).fire)) 3656d5ddbceSLemover } 3666d5ddbceSLemover 367*3ea4388cSHaoyuan Feng // l1 368*3ea4388cSHaoyuan Feng val ptwl1replace = ReplacementPolicy.fromString(l2tlbParams.l1Replacer,l2tlbParams.l1nWays,l2tlbParams.l1nSets) 369*3ea4388cSHaoyuan Feng val (l1Hit, l1HitPPN, l1Pre, l1eccError) = { 370*3ea4388cSHaoyuan Feng val ridx = genPtwL1SetIdx(vpn_search) 371*3ea4388cSHaoyuan Feng l1.io.r.req.valid := stageReq.fire 372*3ea4388cSHaoyuan Feng l1.io.r.req.bits.apply(setIdx = ridx) 373*3ea4388cSHaoyuan Feng val vVec_req = getl1vSet(vpn_search) 374*3ea4388cSHaoyuan Feng val hVec_req = getl1hSet(vpn_search) 3756c4dcc2dSLemover 3766c4dcc2dSLemover // delay one cycle after sram read 37782978df9Speixiaokun val delay_vpn = stageDelay(0).bits.req_info.vpn 3786f508cb5Speixiaokun val delay_h = MuxLookup(stageDelay(0).bits.req_info.s2xlate, noS2xlate)(Seq( 379980ddf4cSpeixiaokun allStage -> onlyStage1, 380980ddf4cSpeixiaokun onlyStage1 -> onlyStage1, 381980ddf4cSpeixiaokun onlyStage2 -> onlyStage2 382980ddf4cSpeixiaokun )) 383*3ea4388cSHaoyuan Feng val data_resp = DataHoldBypass(l1.io.r.resp.data, stageDelay_valid_1cycle) 3847797f035SbugGenerator val vVec_delay = RegEnable(vVec_req, stageReq.fire) 385d0de7e4aSpeixiaokun val hVec_delay = RegEnable(hVec_req, stageReq.fire) 386d0de7e4aSpeixiaokun val hitVec_delay = VecInit(data_resp.zip(vVec_delay.asBools).zip(hVec_delay).map { case ((wayData, v), h) => 387b188e334Speixiaokun wayData.entries.hit(delay_vpn, io.csr_dup(1).satp.asid, io.csr_dup(1).vsatp.asid, io.csr_dup(1).hgatp.asid, s2xlate = delay_h =/= noS2xlate) && v && (delay_h === h)}) 3886c4dcc2dSLemover 3896c4dcc2dSLemover // check hit and ecc 39082978df9Speixiaokun val check_vpn = stageCheck(0).bits.req_info.vpn 3916c4dcc2dSLemover val ramDatas = RegEnable(data_resp, stageDelay(1).fire) 392935edac4STang Haojin val vVec = RegEnable(vVec_delay, stageDelay(1).fire).asBools 3936c4dcc2dSLemover 3947797f035SbugGenerator val hitVec = RegEnable(hitVec_delay, stageDelay(1).fire) 3957196f5a2SLemover val hitWayEntry = ParallelPriorityMux(hitVec zip ramDatas) 3967196f5a2SLemover val hitWayData = hitWayEntry.entries 3976c4dcc2dSLemover val hit = ParallelOR(hitVec) 398*3ea4388cSHaoyuan Feng val hitWay = ParallelPriorityMux(hitVec zip (0 until l2tlbParams.l1nWays).map(_.U(log2Up(l2tlbParams.l1nWays).W))) 399eef81af7SHaoyuan Feng val eccError = WireInit(false.B) 400eef81af7SHaoyuan Feng if (l2tlbParams.enablePTWECC) { 401eef81af7SHaoyuan Feng eccError := hitWayEntry.decode() 402eef81af7SHaoyuan Feng } else { 403eef81af7SHaoyuan Feng eccError := false.B 404eef81af7SHaoyuan Feng } 4057196f5a2SLemover 406*3ea4388cSHaoyuan Feng ridx.suggestName(s"l1_ridx") 407*3ea4388cSHaoyuan Feng ramDatas.suggestName(s"l1_ramDatas") 408*3ea4388cSHaoyuan Feng hitVec.suggestName(s"l1_hitVec") 409*3ea4388cSHaoyuan Feng hitWayData.suggestName(s"l1_hitWayData") 410*3ea4388cSHaoyuan Feng hitWay.suggestName(s"l1_hitWay") 4116d5ddbceSLemover 412*3ea4388cSHaoyuan Feng when (hit && stageCheck_valid_1cycle) { ptwl1replace.access(genPtwL1SetIdx(check_vpn), hitWay) } 4136d5ddbceSLemover 414*3ea4388cSHaoyuan Feng l1AccessPerf.zip(hitVec).map{ case (l, h) => l := h && stageCheck_valid_1cycle } 415*3ea4388cSHaoyuan Feng XSDebug(stageDelay_valid_1cycle, p"[l1] ridx:0x${Hexadecimal(ridx)}\n") 416*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l1nWays) { 417*3ea4388cSHaoyuan Feng XSDebug(stageCheck_valid_1cycle, p"[l1] ramDatas(${i.U}) ${ramDatas(i)} l1v:${vVec(i)} hit:${hit}\n") 4186d5ddbceSLemover } 419*3ea4388cSHaoyuan Feng XSDebug(stageCheck_valid_1cycle, p"[l1] l1Hit:${hit} l1HitPPN:0x${Hexadecimal(hitWayData.ppns(genPtwL1SectorIdx(check_vpn)))} hitVec:${Binary(hitVec.asUInt)} hitWay:${hitWay} vidx:${vVec}\n") 4206d5ddbceSLemover 421*3ea4388cSHaoyuan Feng (hit, hitWayData.ppns(genPtwL1SectorIdx(check_vpn)), hitWayData.prefetch, eccError) 4226d5ddbceSLemover } 4236d5ddbceSLemover 424*3ea4388cSHaoyuan Feng // l0 425*3ea4388cSHaoyuan Feng val ptwl0replace = ReplacementPolicy.fromString(l2tlbParams.l0Replacer,l2tlbParams.l0nWays,l2tlbParams.l0nSets) 426*3ea4388cSHaoyuan Feng val (l0Hit, l0HitData, l0Pre, l0eccError) = { 427*3ea4388cSHaoyuan Feng val ridx = genPtwL0SetIdx(vpn_search) 428*3ea4388cSHaoyuan Feng l0.io.r.req.valid := stageReq.fire 429*3ea4388cSHaoyuan Feng l0.io.r.req.bits.apply(setIdx = ridx) 430*3ea4388cSHaoyuan Feng val vVec_req = getl0vSet(vpn_search) 431*3ea4388cSHaoyuan Feng val hVec_req = getl0hSet(vpn_search) 4326c4dcc2dSLemover 4336c4dcc2dSLemover // delay one cycle after sram read 43482978df9Speixiaokun val delay_vpn = stageDelay(0).bits.req_info.vpn 4356f508cb5Speixiaokun val delay_h = MuxLookup(stageDelay(0).bits.req_info.s2xlate, noS2xlate)(Seq( 436980ddf4cSpeixiaokun allStage -> onlyStage1, 437980ddf4cSpeixiaokun onlyStage1 -> onlyStage1, 438980ddf4cSpeixiaokun onlyStage2 -> onlyStage2 439980ddf4cSpeixiaokun )) 440*3ea4388cSHaoyuan Feng val data_resp = DataHoldBypass(l0.io.r.resp.data, stageDelay_valid_1cycle) 4417797f035SbugGenerator val vVec_delay = RegEnable(vVec_req, stageReq.fire) 442d0de7e4aSpeixiaokun val hVec_delay = RegEnable(hVec_req, stageReq.fire) 443d0de7e4aSpeixiaokun val hitVec_delay = VecInit(data_resp.zip(vVec_delay.asBools).zip(hVec_delay).map { case ((wayData, v), h) => 444*3ea4388cSHaoyuan Feng wayData.entries.hit(delay_vpn, io.csr_dup(0).satp.asid, io.csr_dup(0).vsatp.asid, io.csr_dup(0).hgatp.asid, s2xlate = delay_h =/= noS2xlate) && v && (delay_h === h)}) 4456c4dcc2dSLemover 4466c4dcc2dSLemover // check hit and ecc 44782978df9Speixiaokun val check_vpn = stageCheck(0).bits.req_info.vpn 4486c4dcc2dSLemover val ramDatas = RegEnable(data_resp, stageDelay(1).fire) 449935edac4STang Haojin val vVec = RegEnable(vVec_delay, stageDelay(1).fire).asBools 4506c4dcc2dSLemover 4517797f035SbugGenerator val hitVec = RegEnable(hitVec_delay, stageDelay(1).fire) 4527196f5a2SLemover val hitWayEntry = ParallelPriorityMux(hitVec zip ramDatas) 4537196f5a2SLemover val hitWayData = hitWayEntry.entries 4547196f5a2SLemover val hitWayEcc = hitWayEntry.ecc 4556c4dcc2dSLemover val hit = ParallelOR(hitVec) 456*3ea4388cSHaoyuan Feng val hitWay = ParallelPriorityMux(hitVec zip (0 until l2tlbParams.l0nWays).map(_.U(log2Up(l2tlbParams.l0nWays).W))) 457eef81af7SHaoyuan Feng val eccError = WireInit(false.B) 458eef81af7SHaoyuan Feng if (l2tlbParams.enablePTWECC) { 459eef81af7SHaoyuan Feng eccError := hitWayEntry.decode() 460eef81af7SHaoyuan Feng } else { 461eef81af7SHaoyuan Feng eccError := false.B 462eef81af7SHaoyuan Feng } 4636d5ddbceSLemover 464*3ea4388cSHaoyuan Feng when (hit && stageCheck_valid_1cycle) { ptwl0replace.access(genPtwL0SetIdx(check_vpn), hitWay) } 4657196f5a2SLemover 466*3ea4388cSHaoyuan Feng l0AccessPerf.zip(hitVec).map{ case (l, h) => l := h && stageCheck_valid_1cycle } 467*3ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l0] ridx:0x${Hexadecimal(ridx)}\n") 468*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l0nWays) { 469*3ea4388cSHaoyuan Feng XSDebug(stageCheck_valid_1cycle, p"[l0] ramDatas(${i.U}) ${ramDatas(i)} l0v:${vVec(i)} hit:${hitVec(i)}\n") 4706d5ddbceSLemover } 471*3ea4388cSHaoyuan Feng XSDebug(stageCheck_valid_1cycle, p"[l0] l0Hit:${hit} l0HitData:${hitWayData} hitVec:${Binary(hitVec.asUInt)} hitWay:${hitWay} v:${vVec}\n") 4726d5ddbceSLemover 473*3ea4388cSHaoyuan Feng ridx.suggestName(s"l0_ridx") 474*3ea4388cSHaoyuan Feng ramDatas.suggestName(s"l0_ramDatas") 475*3ea4388cSHaoyuan Feng hitVec.suggestName(s"l0_hitVec") 476*3ea4388cSHaoyuan Feng hitWay.suggestName(s"l0_hitWay") 4776d5ddbceSLemover 4783889e11eSLemover (hit, hitWayData, hitWayData.prefetch, eccError) 4796d5ddbceSLemover } 480*3ea4388cSHaoyuan Feng val l0HitPPN = l0HitData.ppns 481*3ea4388cSHaoyuan Feng val l0HitPerm = l0HitData.perms.getOrElse(0.U.asTypeOf(Vec(PtwL0SectorSize, new PtePermBundle))) 482*3ea4388cSHaoyuan Feng val l0HitValid = l0HitData.vs 483*3ea4388cSHaoyuan Feng val l0HitAf = l0HitData.af 4846d5ddbceSLemover 4856d5ddbceSLemover // super page 4865854c1edSLemover val spreplace = ReplacementPolicy.fromString(l2tlbParams.spReplacer, l2tlbParams.spSize) 4878d8ac704SLemover val (spHit, spHitData, spPre, spValid) = { 488b188e334Speixiaokun val hitVecT = sp.zipWithIndex.map { case (e, i) => e.hit(vpn_search, io.csr_dup(0).satp.asid, io.csr_dup(0).vsatp.asid, io.csr_dup(0).hgatp.asid, s2xlate = h_search =/= noS2xlate) && spv(i) && (sph(i) === h_search) } 4896c4dcc2dSLemover val hitVec = hitVecT.map(RegEnable(_, stageReq.fire)) 4906d5ddbceSLemover val hitData = ParallelPriorityMux(hitVec zip sp) 4916c4dcc2dSLemover val hit = ParallelOR(hitVec) 4926d5ddbceSLemover 4936c4dcc2dSLemover when (hit && stageDelay_valid_1cycle) { spreplace.access(OHToUInt(hitVec)) } 4946d5ddbceSLemover 4956c4dcc2dSLemover spAccessPerf.zip(hitVec).map{ case (s, h) => s := h && stageDelay_valid_1cycle } 4965854c1edSLemover for (i <- 0 until l2tlbParams.spSize) { 497b188e334Speixiaokun XSDebug(stageReq.fire, p"[sp] sp(${i.U}) ${sp(i)} hit:${sp(i).hit(vpn_search, io.csr_dup(0).satp.asid, io.csr_dup(0).vsatp.asid, io.csr_dup(0).hgatp.asid, s2xlate = h_search =/= noS2xlate)} spv:${spv(i)}\n") 4986d5ddbceSLemover } 4996c4dcc2dSLemover XSDebug(stageDelay_valid_1cycle, p"[sp] spHit:${hit} spHitData:${hitData} hitVec:${Binary(VecInit(hitVec).asUInt)}\n") 5006d5ddbceSLemover 5016d5ddbceSLemover VecInit(hitVecT).suggestName(s"sp_hitVecT") 5026d5ddbceSLemover VecInit(hitVec).suggestName(s"sp_hitVec") 5036d5ddbceSLemover 5046c4dcc2dSLemover (RegEnable(hit, stageDelay(1).fire), 5056c4dcc2dSLemover RegEnable(hitData, stageDelay(1).fire), 5066c4dcc2dSLemover RegEnable(hitData.prefetch, stageDelay(1).fire), 507935edac4STang Haojin RegEnable(hitData.v, stageDelay(1).fire)) 5086d5ddbceSLemover } 5096d5ddbceSLemover val spHitPerm = spHitData.perm.getOrElse(0.U.asTypeOf(new PtePermBundle)) 5106d5ddbceSLemover val spHitLevel = spHitData.level.getOrElse(0.U) 5116d5ddbceSLemover 5126c4dcc2dSLemover val check_res = Wire(new PageCacheRespBundle) 513*3ea4388cSHaoyuan Feng check_res.l3.map(_.apply(l3Hit.get, l3Pre.get, l3HitPPN.get)) 514*3ea4388cSHaoyuan Feng check_res.l2.apply(l2Hit, l2Pre, l2HitPPN) 515*3ea4388cSHaoyuan Feng check_res.l1.apply(l1Hit, l1Pre, l1HitPPN, ecc = l1eccError) 516*3ea4388cSHaoyuan Feng check_res.l0.apply(l0Hit, l0Pre, l0HitPPN, l0HitPerm, l0eccError, valid = l0HitValid, accessFault = l0HitAf) 5176c4dcc2dSLemover check_res.sp.apply(spHit, spPre, spHitData.ppn, spHitPerm, false.B, spHitLevel, spValid) 5186d5ddbceSLemover 5196c4dcc2dSLemover val resp_res = Reg(new PageCacheRespBundle) 5206c4dcc2dSLemover when (stageCheck(1).fire) { resp_res := check_res } 5213889e11eSLemover 5221f4a7c0cSLemover // stageResp bypass 523*3ea4388cSHaoyuan Feng val bypassed = if (EnableSv48) Wire(Vec(4, Bool())) else Wire(Vec(3, Bool())) 5241f4a7c0cSLemover bypassed.indices.foreach(i => 5251f4a7c0cSLemover bypassed(i) := stageResp.bits.bypassed(i) || 5266967f5d5Speixiaokun ValidHoldBypass(refill_bypass(stageResp.bits.req_info.vpn, i, stageResp.bits.req_info.s2xlate), 5271f4a7c0cSLemover OneCycleValid(stageCheck(1).fire, false.B) || io.refill.valid) 5281f4a7c0cSLemover ) 5291f4a7c0cSLemover 53083d93d53Speixiaokun // stageResp bypass to hptw 531*3ea4388cSHaoyuan Feng val hptw_bypassed = if (EnableSv48) Wire(Vec(4, Bool())) else Wire(Vec(3, Bool())) 53283d93d53Speixiaokun hptw_bypassed.indices.foreach(i => 53383d93d53Speixiaokun hptw_bypassed(i) := stageResp.bits.bypassed(i) || 53483d93d53Speixiaokun ValidHoldBypass(refill_bypass(stageResp.bits.req_info.vpn, i, stageResp.bits.req_info.s2xlate), 53583d93d53Speixiaokun io.resp.fire) 53683d93d53Speixiaokun ) 53783d93d53Speixiaokun 53830104977Speixiaokun val isAllStage = stageResp.bits.req_info.s2xlate === allStage 539c0991f6aSpeixiaokun val isOnlyStage2 = stageResp.bits.req_info.s2xlate === onlyStage2 540*3ea4388cSHaoyuan Feng val stage1Hit = (resp_res.l0.hit || resp_res.sp.hit) && isAllStage 541da605600Speixiaokun val idx = stageResp.bits.req_info.vpn(2, 0) 542*3ea4388cSHaoyuan Feng val stage1Pf = !Mux(resp_res.l0.hit, resp_res.l0.v(idx), resp_res.sp.v) 5436c4dcc2dSLemover io.resp.bits.req_info := stageResp.bits.req_info 5446c4dcc2dSLemover io.resp.bits.isFirst := stageResp.bits.isFirst 545*3ea4388cSHaoyuan Feng io.resp.bits.hit := (resp_res.l0.hit || resp_res.sp.hit) && (!isAllStage || isAllStage && stage1Pf) 546*3ea4388cSHaoyuan Feng if (EnableSv48) { 547*3ea4388cSHaoyuan Feng io.resp.bits.bypassed := (bypassed(0) || (bypassed(1) && !resp_res.l1.hit) || (bypassed(2) && !resp_res.l2.hit) || (bypassed(3) && !resp_res.l3.get.hit)) && !isAllStage 548*3ea4388cSHaoyuan Feng } else { 549*3ea4388cSHaoyuan Feng io.resp.bits.bypassed := (bypassed(0) || (bypassed(1) && !resp_res.l1.hit) || (bypassed(2) && !resp_res.l2.hit)) && !isAllStage 550*3ea4388cSHaoyuan Feng } 551*3ea4388cSHaoyuan Feng io.resp.bits.prefetch := resp_res.l0.pre && resp_res.l0.hit || resp_res.sp.pre && resp_res.sp.hit 552*3ea4388cSHaoyuan Feng io.resp.bits.toFsm.l3Hit.map(_ := resp_res.l3.get.hit && !stage1Hit && !isOnlyStage2 && !stageResp.bits.isHptwReq) 553325f0a4eSpeixiaokun io.resp.bits.toFsm.l2Hit := resp_res.l2.hit && !stage1Hit && !isOnlyStage2 && !stageResp.bits.isHptwReq 554*3ea4388cSHaoyuan Feng io.resp.bits.toFsm.l1Hit := resp_res.l1.hit && !stage1Hit && !isOnlyStage2 && !stageResp.bits.isHptwReq 555*3ea4388cSHaoyuan Feng io.resp.bits.toFsm.ppn := Mux(resp_res.l1.hit, resp_res.l1.ppn, Mux(resp_res.l2.hit, resp_res.l2.ppn, resp_res.l3.getOrElse(0.U.asTypeOf(new PageCachePerPespBundle)).ppn)) 556980ddf4cSpeixiaokun io.resp.bits.toFsm.stage1Hit := stage1Hit 557d0de7e4aSpeixiaokun 558325f0a4eSpeixiaokun io.resp.bits.isHptwReq := stageResp.bits.isHptwReq 559*3ea4388cSHaoyuan Feng if (EnableSv48) { 560*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.bypassed := (hptw_bypassed(0) || (hptw_bypassed(1) && !resp_res.l1.hit) || (hptw_bypassed(2) && !resp_res.l2.hit) || (hptw_bypassed(3) && !resp_res.l3.get.hit)) && stageResp.bits.isHptwReq 561*3ea4388cSHaoyuan Feng } else { 562*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.bypassed := (hptw_bypassed(0) || (hptw_bypassed(1) && !resp_res.l1.hit) || (hptw_bypassed(2) && !resp_res.l2.hit)) && stageResp.bits.isHptwReq 563*3ea4388cSHaoyuan Feng } 564d0de7e4aSpeixiaokun io.resp.bits.toHptw.id := stageResp.bits.hptwId 565*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.l3Hit.map(_ := resp_res.l3.get.hit && stageResp.bits.isHptwReq) 566325f0a4eSpeixiaokun io.resp.bits.toHptw.l2Hit := resp_res.l2.hit && stageResp.bits.isHptwReq 567*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.l1Hit := resp_res.l1.hit && stageResp.bits.isHptwReq 568*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.ppn := Mux(resp_res.l1.hit, resp_res.l1.ppn, Mux(resp_res.l2.hit, resp_res.l2.ppn, resp_res.l3.getOrElse(0.U.asTypeOf(new PageCachePerPespBundle)).ppn))(ppnLen - 1, 0) 56982978df9Speixiaokun io.resp.bits.toHptw.resp.entry.tag := stageResp.bits.req_info.vpn 570eb4bf3f2Speixiaokun io.resp.bits.toHptw.resp.entry.asid := DontCare 571d61cd5eeSpeixiaokun io.resp.bits.toHptw.resp.entry.vmid.map(_ := io.csr_dup(0).hgatp.asid) 572*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.entry.level.map(_ := Mux(resp_res.l0.hit, 0.U, resp_res.sp.level)) 573d0de7e4aSpeixiaokun io.resp.bits.toHptw.resp.entry.prefetch := from_pre(stageResp.bits.req_info.source) 574*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.entry.ppn := Mux(resp_res.l0.hit, resp_res.l0.ppn(idx), resp_res.sp.ppn)(ppnLen - 1, 0) 575*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.entry.perm.map(_ := Mux(resp_res.l0.hit, resp_res.l0.perm(idx), resp_res.sp.perm)) 576*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.entry.v := Mux(resp_res.l0.hit, resp_res.l0.v(idx), resp_res.sp.v) 577d0de7e4aSpeixiaokun io.resp.bits.toHptw.resp.gpf := !io.resp.bits.toHptw.resp.entry.v 578*3ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.gaf := Mux(resp_res.l0.hit, resp_res.l0.af(idx), false.B) 579d0de7e4aSpeixiaokun 5806979864eSXiaokun-Pei io.resp.bits.stage1.entry.map(_.tag := stageResp.bits.req_info.vpn(vpnLen - 1, 3)) 5816979864eSXiaokun-Pei io.resp.bits.stage1.entry.map(_.asid := Mux(stageResp.bits.req_info.hasS2xlate(), io.csr_dup(0).vsatp.asid, io.csr_dup(0).satp.asid)) // DontCare 5826979864eSXiaokun-Pei io.resp.bits.stage1.entry.map(_.vmid.map(_ := io.csr_dup(0).hgatp.asid)) 583*3ea4388cSHaoyuan Feng if (EnableSv48) { 584*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry.map(_.level.map(_ := Mux(resp_res.l0.hit, 0.U, 585*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.level, 586*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, 1.U, 587*3ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, 2.U, 3.U)))))) 588*3ea4388cSHaoyuan Feng } else { 589*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry.map(_.level.map(_ := Mux(resp_res.l0.hit, 0.U, 590*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.level, 591*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, 1.U, 2.U))))) 592*3ea4388cSHaoyuan Feng } 5936979864eSXiaokun-Pei io.resp.bits.stage1.entry.map(_.prefetch := from_pre(stageResp.bits.req_info.source)) 59463632028SHaoyuan Feng for (i <- 0 until tlbcontiguous) { 595*3ea4388cSHaoyuan Feng if (EnableSv48) { 596*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(gvpnLen - 1, sectortlbwidth), 597*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(gvpnLen - 1, sectortlbwidth), 598*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(gvpnLen - 1, sectortlbwidth), 599*3ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, resp_res.l2.ppn(gvpnLen - 1, sectortlbwidth), 600*3ea4388cSHaoyuan Feng resp_res.l3.get.ppn(gvpnLen - 1, sectortlbwidth))))) 601*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn_low := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(sectortlbwidth - 1, 0), 602*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(sectortlbwidth - 1, 0), 603*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(sectortlbwidth - 1, 0), 604*3ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, resp_res.l2.ppn(sectortlbwidth - 1, 0), 605*3ea4388cSHaoyuan Feng resp_res.l3.get.ppn(sectortlbwidth - 1, 0))))) 606*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).v := Mux(resp_res.l0.hit, resp_res.l0.v(i), 607*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.v, 608*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.v, 609*3ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, resp_res.l2.v, 610*3ea4388cSHaoyuan Feng resp_res.l3.get.v)))) 611*3ea4388cSHaoyuan Feng } else { 612*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(gvpnLen - 1, sectortlbwidth), 613*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(gvpnLen - 1, sectortlbwidth), 614*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(gvpnLen - 1, sectortlbwidth), 615*3ea4388cSHaoyuan Feng resp_res.l2.ppn(gvpnLen - 1, sectortlbwidth)))) 616*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn_low := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(sectortlbwidth - 1, 0), 617*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(sectortlbwidth - 1, 0), 618*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(sectortlbwidth - 1, 0), 619*3ea4388cSHaoyuan Feng resp_res.l2.ppn(sectortlbwidth - 1, 0)))) 620*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).v := Mux(resp_res.l0.hit, resp_res.l0.v(i), 621*3ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.v, 622*3ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.v, 623*3ea4388cSHaoyuan Feng resp_res.l2.v))) 624*3ea4388cSHaoyuan Feng } 625*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).perm.map(_ := Mux(resp_res.l0.hit, resp_res.l0.perm(i), resp_res.sp.perm)) 6266979864eSXiaokun-Pei io.resp.bits.stage1.entry(i).pf := !io.resp.bits.stage1.entry(i).v 627*3ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).af := Mux(resp_res.l0.hit, resp_res.l0.af(i), false.B) 62863632028SHaoyuan Feng } 629da605600Speixiaokun io.resp.bits.stage1.pteidx := UIntToOH(idx).asBools 630*3ea4388cSHaoyuan Feng io.resp.bits.stage1.not_super := Mux(resp_res.l0.hit, true.B, false.B) 6316c4dcc2dSLemover io.resp.valid := stageResp.valid 632*3ea4388cSHaoyuan Feng XSError(stageResp.valid && resp_res.l0.hit && resp_res.sp.hit, "normal page and super page both hit") 633*3ea4388cSHaoyuan Feng XSError(stageResp.valid && io.resp.bits.hit && bypassed(0), "page cache, bypassed but hit") 6346d5ddbceSLemover 6356d5ddbceSLemover // refill Perf 636*3ea4388cSHaoyuan Feng val l3RefillPerf = if (EnableSv48) Some(Wire(Vec(l2tlbParams.l3Size, Bool()))) else None 637*3ea4388cSHaoyuan Feng val l2RefillPerf = Wire(Vec(l2tlbParams.l2Size, Bool())) 638*3ea4388cSHaoyuan Feng val l1RefillPerf = Wire(Vec(l2tlbParams.l1nWays, Bool())) 639*3ea4388cSHaoyuan Feng val l0RefillPerf = Wire(Vec(l2tlbParams.l0nWays, Bool())) 6405854c1edSLemover val spRefillPerf = Wire(Vec(l2tlbParams.spSize, Bool())) 641*3ea4388cSHaoyuan Feng l3RefillPerf.map(_.map(_ := false.B)) 6426d5ddbceSLemover l2RefillPerf.map(_ := false.B) 643*3ea4388cSHaoyuan Feng l1RefillPerf.map(_ := false.B) 644*3ea4388cSHaoyuan Feng l0RefillPerf.map(_ := false.B) 6456d5ddbceSLemover spRefillPerf.map(_ := false.B) 6466d5ddbceSLemover 6476d5ddbceSLemover // refill 648*3ea4388cSHaoyuan Feng l1.io.w.req <> DontCare 649*3ea4388cSHaoyuan Feng l0.io.w.req <> DontCare 650*3ea4388cSHaoyuan Feng l1.io.w.req.valid := false.B 651*3ea4388cSHaoyuan Feng l0.io.w.req.valid := false.B 6526d5ddbceSLemover 6536d5ddbceSLemover val memRdata = refill.ptes 6545854c1edSLemover val memPtes = (0 until (l2tlbParams.blockBytes/(XLEN/8))).map(i => memRdata((i+1)*XLEN-1, i*XLEN).asTypeOf(new PteBundle)) 6557797f035SbugGenerator val memSelData = io.refill.bits.sel_pte_dup 6567797f035SbugGenerator val memPte = memSelData.map(a => a.asTypeOf(new PteBundle)) 657b848eea5SLemover 6586d5ddbceSLemover // TODO: handle sfenceLatch outsize 659*3ea4388cSHaoyuan Feng if (EnableSv48) { 660*3ea4388cSHaoyuan Feng when (!flush_dup(2) && refill.levelOH.l3.get && !memPte(2).isLeaf() && !memPte(2).isPf(refill.level_dup(2)) && Mux(refill.req_info_dup(2).s2xlate === allStage, true.B, !memPte(2).isAf())) { 661*3ea4388cSHaoyuan Feng val refillIdx = replaceWrapper(l3v.get, ptwl3replace.get.way) 662*3ea4388cSHaoyuan Feng refillIdx.suggestName(s"Ptwl3RefillIdx") 6636d5ddbceSLemover val rfOH = UIntToOH(refillIdx) 664*3ea4388cSHaoyuan Feng l3.get(refillIdx).refill( 665*3ea4388cSHaoyuan Feng refill.req_info_dup(2).vpn, 666*3ea4388cSHaoyuan Feng Mux(refill.req_info_dup(2).s2xlate =/= noS2xlate, io.csr_dup(2).vsatp.asid, io.csr_dup(2).satp.asid), 667*3ea4388cSHaoyuan Feng io.csr_dup(2).hgatp.asid, 668*3ea4388cSHaoyuan Feng memSelData(2), 669*3ea4388cSHaoyuan Feng 3.U, 670*3ea4388cSHaoyuan Feng refill_prefetch_dup(2) 67145f497a4Shappy-lx ) 672*3ea4388cSHaoyuan Feng ptwl2replace.access(refillIdx) 673*3ea4388cSHaoyuan Feng l3v.get := l3v.get | rfOH 674*3ea4388cSHaoyuan Feng l3g.get := (l3g.get & ~rfOH) | Mux(memPte(2).perm.g, rfOH, 0.U) 675*3ea4388cSHaoyuan Feng l3h.get(refillIdx) := refill_h(2) 6766d5ddbceSLemover 677*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l3Size) { 678*3ea4388cSHaoyuan Feng l3RefillPerf.get(i) := i.U === refillIdx 6796d5ddbceSLemover } 6806d5ddbceSLemover 681*3ea4388cSHaoyuan Feng XSDebug(p"[l3 refill] refillIdx:${refillIdx} refillEntry:${l3.get(refillIdx).genPtwEntry(refill.req_info_dup(2).vpn, Mux(refill.req_info_dup(2).s2xlate =/= noS2xlate, io.csr_dup(2).vsatp.asid, io.csr_dup(2).satp.asid), memSelData(2), 0.U, prefetch = refill_prefetch_dup(2))}\n") 682*3ea4388cSHaoyuan Feng XSDebug(p"[l3 refill] l3v:${Binary(l3v.get)}->${Binary(l3v.get | rfOH)} l3g:${Binary(l3g.get)}->${Binary((l3g.get & ~rfOH) | Mux(memPte(2).perm.g, rfOH, 0.U))}\n") 6836d5ddbceSLemover 684*3ea4388cSHaoyuan Feng refillIdx.suggestName(s"l3_refillIdx") 685*3ea4388cSHaoyuan Feng rfOH.suggestName(s"l3_rfOH") 686*3ea4388cSHaoyuan Feng } 6876d5ddbceSLemover } 6886d5ddbceSLemover 689*3ea4388cSHaoyuan Feng when (!flush_dup(2) && refill.levelOH.l2 && !memPte(2).isLeaf() && !memPte(2).isPf(refill.level_dup(2)) && Mux(refill.req_info_dup(2).s2xlate === allStage, true.B, !memPte(2).isAf())) { 690*3ea4388cSHaoyuan Feng val refillIdx = replaceWrapper(l2v, ptwl2replace.way) 691*3ea4388cSHaoyuan Feng refillIdx.suggestName(s"Ptwl2RefillIdx") 692*3ea4388cSHaoyuan Feng val rfOH = UIntToOH(refillIdx) 693*3ea4388cSHaoyuan Feng l2(refillIdx).refill( 694*3ea4388cSHaoyuan Feng refill.req_info_dup(2).vpn, 695*3ea4388cSHaoyuan Feng Mux(refill.req_info_dup(2).s2xlate =/= noS2xlate, io.csr_dup(2).vsatp.asid, io.csr_dup(2).satp.asid), 696*3ea4388cSHaoyuan Feng io.csr_dup(2).hgatp.asid, 697*3ea4388cSHaoyuan Feng memSelData(2), 698*3ea4388cSHaoyuan Feng 2.U, 699*3ea4388cSHaoyuan Feng refill_prefetch_dup(2) 700*3ea4388cSHaoyuan Feng ) 701*3ea4388cSHaoyuan Feng ptwl2replace.access(refillIdx) 702*3ea4388cSHaoyuan Feng l2v := l2v | rfOH 703*3ea4388cSHaoyuan Feng l2g := (l2g & ~rfOH) | Mux(memPte(2).perm.g, rfOH, 0.U) 704*3ea4388cSHaoyuan Feng l2h(refillIdx) := refill_h(2) 705*3ea4388cSHaoyuan Feng 706*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l2Size) { 707*3ea4388cSHaoyuan Feng l2RefillPerf(i) := i.U === refillIdx 708*3ea4388cSHaoyuan Feng } 709*3ea4388cSHaoyuan Feng 710*3ea4388cSHaoyuan Feng XSDebug(p"[l2 refill] refillIdx:${refillIdx} refillEntry:${l2(refillIdx).genPtwEntry(refill.req_info_dup(2).vpn, Mux(refill.req_info_dup(2).s2xlate =/= noS2xlate, io.csr_dup(2).vsatp.asid, io.csr_dup(2).satp.asid), memSelData(2), 0.U, prefetch = refill_prefetch_dup(2))}\n") 711*3ea4388cSHaoyuan Feng XSDebug(p"[l2 refill] l2v:${Binary(l2v)}->${Binary(l2v | rfOH)} l2g:${Binary(l2g)}->${Binary((l2g & ~rfOH) | Mux(memPte(2).perm.g, rfOH, 0.U))}\n") 712*3ea4388cSHaoyuan Feng 713*3ea4388cSHaoyuan Feng refillIdx.suggestName(s"l2_refillIdx") 714*3ea4388cSHaoyuan Feng rfOH.suggestName(s"l2_rfOH") 715*3ea4388cSHaoyuan Feng } 716*3ea4388cSHaoyuan Feng 717*3ea4388cSHaoyuan Feng when (!flush_dup(1) && refill.levelOH.l1 && !memPte(1).isLeaf() && !memPte(1).isPf(refill.level_dup(1)) && Mux(refill.req_info_dup(1).s2xlate === allStage, true.B, !memPte(1).isAf())) { 718*3ea4388cSHaoyuan Feng val refillIdx = genPtwL1SetIdx(refill.req_info_dup(1).vpn) 719*3ea4388cSHaoyuan Feng val victimWay = replaceWrapper(getl1vSet(refill.req_info_dup(1).vpn), ptwl1replace.way(refillIdx)) 7206d5ddbceSLemover val victimWayOH = UIntToOH(victimWay) 7216d5ddbceSLemover val rfvOH = UIntToOH(Cat(refillIdx, victimWay)) 722*3ea4388cSHaoyuan Feng val wdata = Wire(l1EntryType) 7233889e11eSLemover wdata.gen( 72482978df9Speixiaokun vpn = refill.req_info_dup(1).vpn, 725cca17e78Speixiaokun asid = Mux(refill.req_info_dup(1).s2xlate =/= noS2xlate, io.csr_dup(1).vsatp.asid, io.csr_dup(1).satp.asid), 726d0de7e4aSpeixiaokun vmid = io.csr_dup(1).hgatp.asid, 72745f497a4Shappy-lx data = memRdata, 72845f497a4Shappy-lx levelUInt = 1.U, 7294ed5afbdSXiaokun-Pei refill_prefetch_dup(1), 7304ed5afbdSXiaokun-Pei refill.req_info_dup(1).s2xlate 73145f497a4Shappy-lx ) 732*3ea4388cSHaoyuan Feng l1.io.w.apply( 7336d5ddbceSLemover valid = true.B, 7346d5ddbceSLemover setIdx = refillIdx, 7357196f5a2SLemover data = wdata, 7366d5ddbceSLemover waymask = victimWayOH 7376d5ddbceSLemover ) 738*3ea4388cSHaoyuan Feng ptwl1replace.access(refillIdx, victimWay) 739*3ea4388cSHaoyuan Feng l1v := l1v | rfvOH 740*3ea4388cSHaoyuan Feng l1g := l1g & ~rfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, rfvOH, 0.U) 741*3ea4388cSHaoyuan Feng l1h(refillIdx)(victimWay) := refill_h(1) 7426d5ddbceSLemover 743*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l1nWays) { 744*3ea4388cSHaoyuan Feng l1RefillPerf(i) := i.U === victimWay 7456d5ddbceSLemover } 7466d5ddbceSLemover 747*3ea4388cSHaoyuan Feng XSDebug(p"[l1 refill] refillIdx:0x${Hexadecimal(refillIdx)} victimWay:${victimWay} victimWayOH:${Binary(victimWayOH)} rfvOH(in UInt):${Cat(refillIdx, victimWay)}\n") 748*3ea4388cSHaoyuan Feng XSDebug(p"[l1 refill] refilldata:0x${wdata}\n") 749*3ea4388cSHaoyuan Feng XSDebug(p"[l1 refill] l1v:${Binary(l1v)} -> ${Binary(l1v | rfvOH)}\n") 750*3ea4388cSHaoyuan Feng XSDebug(p"[l1 refill] l1g:${Binary(l1g)} -> ${Binary(l1g & ~rfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, rfvOH, 0.U))}\n") 7516d5ddbceSLemover 752*3ea4388cSHaoyuan Feng refillIdx.suggestName(s"l1_refillIdx") 753*3ea4388cSHaoyuan Feng victimWay.suggestName(s"l1_victimWay") 754*3ea4388cSHaoyuan Feng victimWayOH.suggestName(s"l1_victimWayOH") 755*3ea4388cSHaoyuan Feng rfvOH.suggestName(s"l1_rfvOH") 7566d5ddbceSLemover } 7576d5ddbceSLemover 758*3ea4388cSHaoyuan Feng when (!flush_dup(0) && refill.levelOH.l0) { 759*3ea4388cSHaoyuan Feng val refillIdx = genPtwL0SetIdx(refill.req_info_dup(0).vpn) 760*3ea4388cSHaoyuan Feng val victimWay = replaceWrapper(getl0vSet(refill.req_info_dup(0).vpn), ptwl0replace.way(refillIdx)) 7616d5ddbceSLemover val victimWayOH = UIntToOH(victimWay) 7626d5ddbceSLemover val rfvOH = UIntToOH(Cat(refillIdx, victimWay)) 763*3ea4388cSHaoyuan Feng val wdata = Wire(l0EntryType) 7643889e11eSLemover wdata.gen( 765*3ea4388cSHaoyuan Feng vpn = refill.req_info_dup(0).vpn, 766*3ea4388cSHaoyuan Feng asid = Mux(refill.req_info_dup(0).s2xlate =/= noS2xlate, io.csr_dup(0).vsatp.asid, io.csr_dup(0).satp.asid), 767*3ea4388cSHaoyuan Feng vmid = io.csr_dup(0).hgatp.asid, 76845f497a4Shappy-lx data = memRdata, 769*3ea4388cSHaoyuan Feng levelUInt = 0.U, 770*3ea4388cSHaoyuan Feng refill_prefetch_dup(0), 771*3ea4388cSHaoyuan Feng refill.req_info_dup(0).s2xlate 77245f497a4Shappy-lx ) 773*3ea4388cSHaoyuan Feng l0.io.w.apply( 7746d5ddbceSLemover valid = true.B, 7756d5ddbceSLemover setIdx = refillIdx, 7767196f5a2SLemover data = wdata, 7776d5ddbceSLemover waymask = victimWayOH 7786d5ddbceSLemover ) 779*3ea4388cSHaoyuan Feng ptwl0replace.access(refillIdx, victimWay) 780*3ea4388cSHaoyuan Feng l0v := l0v | rfvOH 781*3ea4388cSHaoyuan Feng l0g := l0g & ~rfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, rfvOH, 0.U) 782*3ea4388cSHaoyuan Feng l0h(refillIdx)(victimWay) := refill_h(0) 7836d5ddbceSLemover 784*3ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l0nWays) { 785*3ea4388cSHaoyuan Feng l0RefillPerf(i) := i.U === victimWay 7866d5ddbceSLemover } 7876d5ddbceSLemover 788*3ea4388cSHaoyuan Feng XSDebug(p"[l0 refill] refillIdx:0x${Hexadecimal(refillIdx)} victimWay:${victimWay} victimWayOH:${Binary(victimWayOH)} rfvOH(in UInt):${Cat(refillIdx, victimWay)}\n") 789*3ea4388cSHaoyuan Feng XSDebug(p"[l0 refill] refilldata:0x${wdata}\n") 790*3ea4388cSHaoyuan Feng XSDebug(p"[l0 refill] l0v:${Binary(l0v)} -> ${Binary(l0v | rfvOH)}\n") 791*3ea4388cSHaoyuan Feng XSDebug(p"[l0 refill] l0g:${Binary(l0g)} -> ${Binary(l0g & ~rfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, rfvOH, 0.U))}\n") 7926d5ddbceSLemover 793*3ea4388cSHaoyuan Feng refillIdx.suggestName(s"l0_refillIdx") 794*3ea4388cSHaoyuan Feng victimWay.suggestName(s"l0_victimWay") 795*3ea4388cSHaoyuan Feng victimWayOH.suggestName(s"l0_victimWayOH") 796*3ea4388cSHaoyuan Feng rfvOH.suggestName(s"l0_rfvOH") 7976d5ddbceSLemover } 7987797f035SbugGenerator 7998d8ac704SLemover 8008d8ac704SLemover // misc entries: super & invalid 8014ed5afbdSXiaokun-Pei when (!flush_dup(0) && refill.levelOH.sp && (memPte(0).isLeaf() || memPte(0).isPf(refill.level_dup(0))) && Mux(refill.req_info_dup(0).s2xlate === allStage, true.B, !memPte(0).isAf())) { 8025854c1edSLemover val refillIdx = spreplace.way// LFSR64()(log2Up(l2tlbParams.spSize)-1,0) // TODO: may be LRU 8036d5ddbceSLemover val rfOH = UIntToOH(refillIdx) 80445f497a4Shappy-lx sp(refillIdx).refill( 8057797f035SbugGenerator refill.req_info_dup(0).vpn, 806b188e334Speixiaokun Mux(refill.req_info_dup(0).s2xlate =/= noS2xlate, io.csr_dup(0).vsatp.asid, io.csr_dup(0).satp.asid), 807d0de7e4aSpeixiaokun io.csr_dup(0).hgatp.asid, 8087797f035SbugGenerator memSelData(0), 809*3ea4388cSHaoyuan Feng refill.level_dup(0), 8107797f035SbugGenerator refill_prefetch_dup(0), 8117797f035SbugGenerator !memPte(0).isPf(refill.level_dup(0)), 81245f497a4Shappy-lx ) 8136d5ddbceSLemover spreplace.access(refillIdx) 8146d5ddbceSLemover spv := spv | rfOH 8157797f035SbugGenerator spg := spg & ~rfOH | Mux(memPte(0).perm.g, rfOH, 0.U) 8164ed5afbdSXiaokun-Pei sph(refillIdx) := refill_h(0) 8176d5ddbceSLemover 8185854c1edSLemover for (i <- 0 until l2tlbParams.spSize) { 8196d5ddbceSLemover spRefillPerf(i) := i.U === refillIdx 8206d5ddbceSLemover } 8216d5ddbceSLemover 822b188e334Speixiaokun XSDebug(p"[sp refill] refillIdx:${refillIdx} refillEntry:${sp(refillIdx).genPtwEntry(refill.req_info_dup(0).vpn, Mux(refill.req_info_dup(0).s2xlate =/= noS2xlate, io.csr_dup(0).vsatp.asid, io.csr_dup(0).satp.asid), memSelData(0), refill.level_dup(0), refill_prefetch_dup(0))}\n") 8237797f035SbugGenerator XSDebug(p"[sp refill] spv:${Binary(spv)}->${Binary(spv | rfOH)} spg:${Binary(spg)}->${Binary(spg & ~rfOH | Mux(memPte(0).perm.g, rfOH, 0.U))}\n") 8246d5ddbceSLemover 8256d5ddbceSLemover refillIdx.suggestName(s"sp_refillIdx") 8266d5ddbceSLemover rfOH.suggestName(s"sp_rfOH") 8276d5ddbceSLemover } 8286d5ddbceSLemover 829*3ea4388cSHaoyuan Feng val l1eccFlush = resp_res.l1.ecc && stageResp_valid_1cycle_dup(0) // RegNext(l1eccError, init = false.B) 830*3ea4388cSHaoyuan Feng val l0eccFlush = resp_res.l0.ecc && stageResp_valid_1cycle_dup(1) // RegNext(l0eccError, init = false.B) 8316c4dcc2dSLemover val eccVpn = stageResp.bits.req_info.vpn 8327196f5a2SLemover 833*3ea4388cSHaoyuan Feng XSError(l1eccFlush, "l2tlb.cache.l1 ecc error. Should not happen at sim stage") 834*3ea4388cSHaoyuan Feng XSError(l0eccFlush, "l2tlb.cache.l0 ecc error. Should not happen at sim stage") 835*3ea4388cSHaoyuan Feng when (l1eccFlush) { 836*3ea4388cSHaoyuan Feng val flushSetIdxOH = UIntToOH(genPtwL1SetIdx(eccVpn)) 837*3ea4388cSHaoyuan Feng val flushMask = VecInit(flushSetIdxOH.asBools.map { a => Fill(l2tlbParams.l1nWays, a.asUInt) }).asUInt 838*3ea4388cSHaoyuan Feng l1v := l1v & ~flushMask 839*3ea4388cSHaoyuan Feng l1g := l1g & ~flushMask 8407196f5a2SLemover } 8417196f5a2SLemover 842*3ea4388cSHaoyuan Feng when (l0eccFlush) { 843*3ea4388cSHaoyuan Feng val flushSetIdxOH = UIntToOH(genPtwL0SetIdx(eccVpn)) 844*3ea4388cSHaoyuan Feng val flushMask = VecInit(flushSetIdxOH.asBools.map { a => Fill(l2tlbParams.l0nWays, a.asUInt) }).asUInt 845*3ea4388cSHaoyuan Feng l0v := l0v & ~flushMask 846*3ea4388cSHaoyuan Feng l0g := l0g & ~flushMask 8477196f5a2SLemover } 8487196f5a2SLemover 849*3ea4388cSHaoyuan Feng // sfence for l0 850*3ea4388cSHaoyuan Feng val sfence_valid_l0 = sfence_dup(0).valid && !sfence_dup(0).bits.hg && !sfence_dup(0).bits.hv 851*3ea4388cSHaoyuan Feng when (sfence_valid_l0) { 852*3ea4388cSHaoyuan Feng val l0hhit = VecInit(l0h.flatMap(_.map{a => io.csr_dup(0).priv.virt && a === onlyStage1 || !io.csr_dup(0).priv.virt && a === noS2xlate})).asUInt 853*3ea4388cSHaoyuan Feng val sfence_vpn = sfence_dup(0).bits.addr(sfence_dup(0).bits.addr.getWidth-1, offLen) 854*3ea4388cSHaoyuan Feng when (sfence_dup(0).bits.rs1/*va*/) { 855*3ea4388cSHaoyuan Feng when (sfence_dup(0).bits.rs2) { 8567797f035SbugGenerator // all va && all asid 857*3ea4388cSHaoyuan Feng l0v := l0v & ~l0hhit 8587797f035SbugGenerator } .otherwise { 8597797f035SbugGenerator // all va && specific asid except global 860*3ea4388cSHaoyuan Feng l0v := l0v & (l0g | ~l0hhit) 8617797f035SbugGenerator } 8627797f035SbugGenerator } .otherwise { 863*3ea4388cSHaoyuan Feng // val flushMask = UIntToOH(genTlbl1Idx(sfence.bits.addr(sfence.bits.addr.getWidth-1, offLen))) 864*3ea4388cSHaoyuan Feng val flushSetIdxOH = UIntToOH(genPtwL0SetIdx(sfence_vpn)) 865*3ea4388cSHaoyuan Feng // val flushMask = VecInit(flushSetIdxOH.asBools.map(Fill(l2tlbParams.l0nWays, _.asUInt))).asUInt 866*3ea4388cSHaoyuan Feng val flushMask = VecInit(flushSetIdxOH.asBools.map { a => Fill(l2tlbParams.l0nWays, a.asUInt) }).asUInt 8677797f035SbugGenerator flushSetIdxOH.suggestName(s"sfence_nrs1_flushSetIdxOH") 8687797f035SbugGenerator flushMask.suggestName(s"sfence_nrs1_flushMask") 8697797f035SbugGenerator 870*3ea4388cSHaoyuan Feng when (sfence_dup(0).bits.rs2) { 8717797f035SbugGenerator // specific leaf of addr && all asid 872*3ea4388cSHaoyuan Feng l0v := l0v & ~flushMask & ~l0hhit 8737797f035SbugGenerator } .otherwise { 8747797f035SbugGenerator // specific leaf of addr && specific asid 875*3ea4388cSHaoyuan Feng l0v := l0v & (~flushMask | l0g | ~l0hhit) 8767797f035SbugGenerator } 8777797f035SbugGenerator } 8787797f035SbugGenerator } 8797797f035SbugGenerator 880*3ea4388cSHaoyuan Feng // hfencev, simple implementation for l0 881*3ea4388cSHaoyuan Feng val hfencev_valid_l0 = sfence_dup(0).valid && sfence_dup(0).bits.hv 882*3ea4388cSHaoyuan Feng when(hfencev_valid_l0) { 883*3ea4388cSHaoyuan Feng val flushMask = VecInit(l0h.flatMap(_.map(_ === onlyStage1))).asUInt 884*3ea4388cSHaoyuan Feng l0v := l0v & ~flushMask // all VS-stage l0 pte 885d0de7e4aSpeixiaokun } 886d0de7e4aSpeixiaokun 887*3ea4388cSHaoyuan Feng // hfenceg, simple implementation for l0 888*3ea4388cSHaoyuan Feng val hfenceg_valid_l0 = sfence_dup(0).valid && sfence_dup(0).bits.hg 889*3ea4388cSHaoyuan Feng when(hfenceg_valid_l0) { 890*3ea4388cSHaoyuan Feng val flushMask = VecInit(l0h.flatMap(_.map(_ === onlyStage2))).asUInt 891*3ea4388cSHaoyuan Feng l0v := l0v & ~flushMask // all G-stage l0 pte 892d0de7e4aSpeixiaokun } 893d0de7e4aSpeixiaokun 894*3ea4388cSHaoyuan Feng val l2asidhit = VecInit(l2asids.map(_ === sfence_dup(2).bits.id)).asUInt 895d0de7e4aSpeixiaokun val spasidhit = VecInit(spasids.map(_ === sfence_dup(0).bits.id)).asUInt 896d0de7e4aSpeixiaokun val sfence_valid = sfence_dup(0).valid && !sfence_dup(0).bits.hg && !sfence_dup(0).bits.hv 897d0de7e4aSpeixiaokun when (sfence_valid) { 898*3ea4388cSHaoyuan Feng val l2vmidhit = VecInit(l2vmids.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.asid)).asUInt 899cca17e78Speixiaokun val spvmidhit = VecInit(spvmids.map(_.getOrElse(0.U) === io.csr_dup(0).hgatp.asid)).asUInt 900*3ea4388cSHaoyuan Feng val l2hhit = VecInit(l2h.map{a => io.csr_dup(2).priv.virt && a === onlyStage1 || !io.csr_dup(2).priv.virt && a === noS2xlate}).asUInt 901e5da58f0Speixiaokun val sphhit = VecInit(sph.map{a => io.csr_dup(0).priv.virt && a === onlyStage1 || !io.csr_dup(0).priv.virt && a === noS2xlate}).asUInt 902*3ea4388cSHaoyuan Feng val l1hhit = VecInit(l1h.flatMap(_.map{a => io.csr_dup(1).priv.virt && a === onlyStage1 || !io.csr_dup(1).priv.virt && a === noS2xlate})).asUInt 9037797f035SbugGenerator val sfence_vpn = sfence_dup(0).bits.addr(sfence_dup(0).bits.addr.getWidth-1, offLen) 9047797f035SbugGenerator 9057797f035SbugGenerator when (sfence_dup(0).bits.rs1/*va*/) { 9067797f035SbugGenerator when (sfence_dup(0).bits.rs2) { 9076d5ddbceSLemover // all va && all asid 908*3ea4388cSHaoyuan Feng l1v := l1v & ~l1hhit 909*3ea4388cSHaoyuan Feng l2v := l2v & ~(l2hhit & VecInit(l2vmidhit.asBools.map{a => io.csr_dup(2).priv.virt && a || !io.csr_dup(2).priv.virt}).asUInt) 910447c794eSpeixiaokun spv := spv & ~(sphhit & VecInit(spvmidhit.asBools.map{a => io.csr_dup(0).priv.virt && a || !io.csr_dup(0).priv.virt}).asUInt) 9116d5ddbceSLemover } .otherwise { 9126d5ddbceSLemover // all va && specific asid except global 913*3ea4388cSHaoyuan Feng l1v := l1v & (l1g | ~l1hhit) 914*3ea4388cSHaoyuan Feng l2v := l2v & ~(~l2g & l2hhit & l2asidhit & VecInit(l2vmidhit.asBools.map{a => io.csr_dup(2).priv.virt && a || !io.csr_dup(2).priv.virt}).asUInt) 9155f64f303Speixiaokun spv := spv & ~(~spg & sphhit & spasidhit & VecInit(spvmidhit.asBools.map{a => io.csr_dup(0).priv.virt && a || !io.csr_dup(0).priv.virt}).asUInt) 9166d5ddbceSLemover } 9176d5ddbceSLemover } .otherwise { 9187797f035SbugGenerator when (sfence_dup(0).bits.rs2) { 9196d5ddbceSLemover // specific leaf of addr && all asid 920a0c90508Speixiaokun spv := spv & ~(sphhit & VecInit(sp.map(_.hit(sfence_vpn, sfence_dup(0).bits.id, sfence_dup(0).bits.id, io.csr_dup(0).hgatp.asid, ignoreAsid = true, s2xlate = io.csr_dup(0).priv.virt))).asUInt) 9216d5ddbceSLemover } .otherwise { 9226d5ddbceSLemover // specific leaf of addr && specific asid 923a0c90508Speixiaokun spv := spv & ~(~spg & sphhit & VecInit(sp.map(_.hit(sfence_vpn, sfence_dup(0).bits.id, sfence_dup(0).bits.id, io.csr_dup(0).hgatp.asid, s2xlate = io.csr_dup(0).priv.virt))).asUInt) 924d0de7e4aSpeixiaokun } 925d0de7e4aSpeixiaokun } 926d0de7e4aSpeixiaokun } 927d0de7e4aSpeixiaokun 928d0de7e4aSpeixiaokun val hfencev_valid = sfence_dup(0).valid && sfence_dup(0).bits.hv 929d0de7e4aSpeixiaokun when (hfencev_valid) { 930*3ea4388cSHaoyuan Feng val l2vmidhit = VecInit(l2vmids.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.asid)).asUInt 931cca17e78Speixiaokun val spvmidhit = VecInit(spvmids.map(_.getOrElse(0.U) === io.csr_dup(0).hgatp.asid)).asUInt 932*3ea4388cSHaoyuan Feng val l2hhit = VecInit(l2h.map(_ === onlyStage1)).asUInt 933cca17e78Speixiaokun val sphhit = VecInit(sph.map(_ === onlyStage1)).asUInt 934*3ea4388cSHaoyuan Feng val l1hhit = VecInit(l1h.flatMap(_.map(_ === onlyStage1))).asUInt 935d0de7e4aSpeixiaokun val hfencev_vpn = sfence_dup(0).bits.addr(sfence_dup(0).bits.addr.getWidth-1, offLen) 936d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs1) { 937d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 938*3ea4388cSHaoyuan Feng l1v := l1v & ~l1hhit 939*3ea4388cSHaoyuan Feng l2v := l2v & ~(l2hhit & l2vmidhit) 940447c794eSpeixiaokun spv := spv & ~(sphhit & spvmidhit) 941d0de7e4aSpeixiaokun }.otherwise { 942*3ea4388cSHaoyuan Feng l1v := l1v & (l1g | ~l1hhit) 943*3ea4388cSHaoyuan Feng l2v := l2v & ~(~l2g & l2hhit & l2asidhit & l2vmidhit) 944d0de7e4aSpeixiaokun spv := spv & ~(~spg & sphhit & spasidhit & spvmidhit) 945d0de7e4aSpeixiaokun } 946d0de7e4aSpeixiaokun }.otherwise { 947d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 948a0c90508Speixiaokun spv := spv & ~(sphhit & VecInit(sp.map(_.hit(hfencev_vpn, sfence_dup(0).bits.id, sfence_dup(0).bits.id, io.csr_dup(0).hgatp.asid, ignoreAsid = true, s2xlate = true.B))).asUInt) 949d0de7e4aSpeixiaokun }.otherwise { 950a0c90508Speixiaokun spv := spv & ~(~spg & sphhit & VecInit(sp.map(_.hit(hfencev_vpn, sfence_dup(0).bits.id, sfence_dup(0).bits.id, io.csr_dup(0).hgatp.asid, s2xlate = true.B))).asUInt) 951d0de7e4aSpeixiaokun } 952d0de7e4aSpeixiaokun } 953d0de7e4aSpeixiaokun } 954d0de7e4aSpeixiaokun 955d0de7e4aSpeixiaokun 956d0de7e4aSpeixiaokun val hfenceg_valid = sfence_dup(0).valid && sfence_dup(0).bits.hg 957d0de7e4aSpeixiaokun when(hfenceg_valid) { 958*3ea4388cSHaoyuan Feng val l2vmidhit = VecInit(l2vmids.map(_.getOrElse(0.U) === sfence_dup(2).bits.id)).asUInt 959cca17e78Speixiaokun val spvmidhit = VecInit(spvmids.map(_.getOrElse(0.U) === sfence_dup(0).bits.id)).asUInt 960*3ea4388cSHaoyuan Feng val l2hhit = VecInit(l2h.map(_ === onlyStage2)).asUInt 961cca17e78Speixiaokun val sphhit = VecInit(sph.map(_ === onlyStage2)).asUInt 962*3ea4388cSHaoyuan Feng val l1hhit = VecInit(l1h.flatMap(_.map(_ === onlyStage2))).asUInt 963887df0f4Speixiaokun val hfenceg_gvpn = (sfence_dup(0).bits.addr << 2)(sfence_dup(0).bits.addr.getWidth - 1, offLen) 964d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs1) { 965d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 966d0de7e4aSpeixiaokun l1v := l1v & ~l1hhit 967*3ea4388cSHaoyuan Feng l2v := l2v & ~l2hhit 968d0de7e4aSpeixiaokun spv := spv & ~sphhit 969d0de7e4aSpeixiaokun }.otherwise { 970*3ea4388cSHaoyuan Feng l1v := l1v & ~l1hhit 971*3ea4388cSHaoyuan Feng l2v := l2v & ~(l2hhit & l2vmidhit) 972d0de7e4aSpeixiaokun spv := spv & ~(sphhit & spvmidhit) 973d0de7e4aSpeixiaokun } 974d0de7e4aSpeixiaokun }.otherwise { 975d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 9768fe4f15fSXiaokun-Pei spv := spv & ~(sphhit & VecInit(sp.map(_.hit(hfenceg_gvpn, 0.U, 0.U, sfence_dup(0).bits.id, ignoreAsid = true, s2xlate = false.B))).asUInt) 977d0de7e4aSpeixiaokun }.otherwise { 9788fe4f15fSXiaokun-Pei spv := spv & ~(~spg & sphhit & VecInit(sp.map(_.hit(hfenceg_gvpn, 0.U, 0.U, sfence_dup(0).bits.id, ignoreAsid = true, s2xlate = true.B))).asUInt) 9796d5ddbceSLemover } 9806d5ddbceSLemover } 9816d5ddbceSLemover } 9826d5ddbceSLemover 983*3ea4388cSHaoyuan Feng if (EnableSv48) { 984*3ea4388cSHaoyuan Feng val l3asidhit = VecInit(l3asids.get.map(_ === sfence_dup(2).bits.id)).asUInt 985*3ea4388cSHaoyuan Feng val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.asid)).asUInt 986*3ea4388cSHaoyuan Feng val l3hhit = VecInit(l3h.get.map{a => io.csr_dup(2).priv.virt && a === onlyStage1 || !io.csr_dup(2).priv.virt && a === noS2xlate}).asUInt 987*3ea4388cSHaoyuan Feng 988*3ea4388cSHaoyuan Feng when (sfence_valid) { 989*3ea4388cSHaoyuan Feng val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.asid)).asUInt 990*3ea4388cSHaoyuan Feng val l3hhit = VecInit(l3h.get.map{a => io.csr_dup(2).priv.virt && a === onlyStage1 || !io.csr_dup(2).priv.virt && a === noS2xlate}).asUInt 991*3ea4388cSHaoyuan Feng val sfence_vpn = sfence_dup(2).bits.addr(sfence_dup(2).bits.addr.getWidth-1, offLen) 992*3ea4388cSHaoyuan Feng 993*3ea4388cSHaoyuan Feng when (sfence_dup(2).bits.rs1/*va*/) { 994*3ea4388cSHaoyuan Feng when (sfence_dup(2).bits.rs2) { 995*3ea4388cSHaoyuan Feng // all va && all asid 996*3ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(l3hhit & VecInit(l3vmidhit.asBools.map{a => io.csr_dup(2).priv.virt && a || !io.csr_dup(2).priv.virt}).asUInt)) 997*3ea4388cSHaoyuan Feng } .otherwise { 998*3ea4388cSHaoyuan Feng // all va && specific asid except global 999*3ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(~l3g.get & l3hhit & l3asidhit & VecInit(l3vmidhit.asBools.map{a => io.csr_dup(2).priv.virt && a || !io.csr_dup(2).priv.virt}).asUInt)) 1000*3ea4388cSHaoyuan Feng } 1001*3ea4388cSHaoyuan Feng } 1002*3ea4388cSHaoyuan Feng } 1003*3ea4388cSHaoyuan Feng 1004*3ea4388cSHaoyuan Feng when (hfencev_valid) { 1005*3ea4388cSHaoyuan Feng val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.asid)).asUInt 1006*3ea4388cSHaoyuan Feng val l3hhit = VecInit(l3h.get.map(_ === onlyStage1)).asUInt 1007*3ea4388cSHaoyuan Feng val hfencev_vpn = sfence_dup(2).bits.addr(sfence_dup(2).bits.addr.getWidth-1, offLen) 1008*3ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs1) { 1009*3ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs2) { 1010*3ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(l3hhit & l3vmidhit)) 1011*3ea4388cSHaoyuan Feng }.otherwise { 1012*3ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(~l3g.get & l3hhit & l3asidhit & l3vmidhit)) 1013*3ea4388cSHaoyuan Feng } 1014*3ea4388cSHaoyuan Feng } 1015*3ea4388cSHaoyuan Feng } 1016*3ea4388cSHaoyuan Feng 1017*3ea4388cSHaoyuan Feng when (hfenceg_valid) { 1018*3ea4388cSHaoyuan Feng val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === sfence_dup(2).bits.id)).asUInt 1019*3ea4388cSHaoyuan Feng val l3hhit = VecInit(l3h.get.map(_ === onlyStage2)).asUInt 1020*3ea4388cSHaoyuan Feng val hfenceg_gvpn = (sfence_dup(2).bits.addr << 2)(sfence_dup(2).bits.addr.getWidth - 1, offLen) 1021*3ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs1) { 1022*3ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs2) { 1023*3ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~l3hhit) 1024*3ea4388cSHaoyuan Feng }.otherwise { 1025*3ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(l3hhit & l3vmidhit)) 1026*3ea4388cSHaoyuan Feng } 1027*3ea4388cSHaoyuan Feng } 1028*3ea4388cSHaoyuan Feng } 1029*3ea4388cSHaoyuan Feng } 1030*3ea4388cSHaoyuan Feng 10317797f035SbugGenerator def InsideStageConnect(in: DecoupledIO[PtwCacheReq], out: DecoupledIO[PtwCacheReq], inFire: Bool): Unit = { 10322c86e165SZhangZifei in.ready := !in.valid || out.ready 10332c86e165SZhangZifei out.valid := in.valid 10342c86e165SZhangZifei out.bits := in.bits 10351f4a7c0cSLemover out.bits.bypassed.zip(in.bits.bypassed).zipWithIndex.map{ case (b, i) => 10367797f035SbugGenerator val bypassed_reg = Reg(Bool()) 1037d0de7e4aSpeixiaokun val bypassed_wire = refill_bypass(in.bits.req_info.vpn, i, in.bits.req_info.s2xlate) && io.refill.valid 10387797f035SbugGenerator when (inFire) { bypassed_reg := bypassed_wire } 10397797f035SbugGenerator .elsewhen (io.refill.valid) { bypassed_reg := bypassed_reg || bypassed_wire } 10407797f035SbugGenerator 10417797f035SbugGenerator b._1 := b._2 || (bypassed_wire || (bypassed_reg && !inFire)) 10421f4a7c0cSLemover } 10432c86e165SZhangZifei } 10442c86e165SZhangZifei 10456d5ddbceSLemover // Perf Count 1046*3ea4388cSHaoyuan Feng val resp_l0 = resp_res.l0.hit 10476c4dcc2dSLemover val resp_sp = resp_res.sp.hit 1048*3ea4388cSHaoyuan Feng val resp_l3_pre = if (EnableSv48) Some(resp_res.l3.get.pre) else None 10496c4dcc2dSLemover val resp_l2_pre = resp_res.l2.pre 1050*3ea4388cSHaoyuan Feng val resp_l1_pre = resp_res.l1.pre 1051*3ea4388cSHaoyuan Feng val resp_l0_pre = resp_res.l0.pre 10526c4dcc2dSLemover val resp_sp_pre = resp_res.sp.pre 1053935edac4STang Haojin val base_valid_access_0 = !from_pre(io.resp.bits.req_info.source) && io.resp.fire 1054bc063562SLemover XSPerfAccumulate("access", base_valid_access_0) 1055*3ea4388cSHaoyuan Feng if (EnableSv48) { 1056*3ea4388cSHaoyuan Feng XSPerfAccumulate("l3_hit", base_valid_access_0 && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1057*3ea4388cSHaoyuan Feng } 1058*3ea4388cSHaoyuan Feng XSPerfAccumulate("l2_hit", base_valid_access_0 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1059*3ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit", base_valid_access_0 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1060*3ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit", base_valid_access_0 && resp_l0) 1061bc063562SLemover XSPerfAccumulate("sp_hit", base_valid_access_0 && resp_sp) 1062bc063562SLemover XSPerfAccumulate("pte_hit",base_valid_access_0 && io.resp.bits.hit) 1063bc063562SLemover 1064*3ea4388cSHaoyuan Feng if (EnableSv48) { 1065*3ea4388cSHaoyuan Feng XSPerfAccumulate("l3_hit_pre", base_valid_access_0 && resp_l3_pre.get && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1066*3ea4388cSHaoyuan Feng } 1067*3ea4388cSHaoyuan Feng XSPerfAccumulate("l2_hit_pre", base_valid_access_0 && resp_l2_pre && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1068*3ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit_pre", base_valid_access_0 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1069*3ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit_pre", base_valid_access_0 && resp_l0_pre && resp_l0) 1070bc063562SLemover XSPerfAccumulate("sp_hit_pre", base_valid_access_0 && resp_sp_pre && resp_sp) 1071*3ea4388cSHaoyuan Feng XSPerfAccumulate("pte_hit_pre",base_valid_access_0 && (resp_l0_pre && resp_l0 || resp_sp_pre && resp_sp) && io.resp.bits.hit) 1072bc063562SLemover 1073935edac4STang Haojin val base_valid_access_1 = from_pre(io.resp.bits.req_info.source) && io.resp.fire 1074bc063562SLemover XSPerfAccumulate("pre_access", base_valid_access_1) 1075*3ea4388cSHaoyuan Feng if (EnableSv48) { 1076*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l3_hit", base_valid_access_1 && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1077*3ea4388cSHaoyuan Feng } 1078*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l2_hit", base_valid_access_1 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1079*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit", base_valid_access_1 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1080*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit", base_valid_access_1 && resp_l0) 1081bc063562SLemover XSPerfAccumulate("pre_sp_hit", base_valid_access_1 && resp_sp) 1082bc063562SLemover XSPerfAccumulate("pre_pte_hit",base_valid_access_1 && io.resp.bits.hit) 1083bc063562SLemover 1084*3ea4388cSHaoyuan Feng if (EnableSv48) { 1085*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l3_hit_pre", base_valid_access_1 && resp_l3_pre.get && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1086*3ea4388cSHaoyuan Feng } 1087*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l2_hit_pre", base_valid_access_1 && resp_l2_pre && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1088*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit_pre", base_valid_access_1 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1089*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit_pre", base_valid_access_1 && resp_l0_pre && resp_l0) 1090bc063562SLemover XSPerfAccumulate("pre_sp_hit_pre", base_valid_access_1 && resp_sp_pre && resp_sp) 1091*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_pte_hit_pre",base_valid_access_1 && (resp_l0_pre && resp_l0 || resp_sp_pre && resp_sp) && io.resp.bits.hit) 1092bc063562SLemover 1093935edac4STang Haojin val base_valid_access_2 = stageResp.bits.isFirst && !from_pre(io.resp.bits.req_info.source) && io.resp.fire 1094bc063562SLemover XSPerfAccumulate("access_first", base_valid_access_2) 1095*3ea4388cSHaoyuan Feng if (EnableSv48) { 1096*3ea4388cSHaoyuan Feng XSPerfAccumulate("l3_hit_first", base_valid_access_2 && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1097*3ea4388cSHaoyuan Feng } 1098*3ea4388cSHaoyuan Feng XSPerfAccumulate("l2_hit_first", base_valid_access_2 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1099*3ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit_first", base_valid_access_2 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1100*3ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit_first", base_valid_access_2 && resp_l0) 1101bc063562SLemover XSPerfAccumulate("sp_hit_first", base_valid_access_2 && resp_sp) 1102bc063562SLemover XSPerfAccumulate("pte_hit_first",base_valid_access_2 && io.resp.bits.hit) 1103bc063562SLemover 1104*3ea4388cSHaoyuan Feng if (EnableSv48) { 1105*3ea4388cSHaoyuan Feng XSPerfAccumulate("l3_hit_pre_first", base_valid_access_2 && resp_l3_pre.get && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1106*3ea4388cSHaoyuan Feng } 1107*3ea4388cSHaoyuan Feng XSPerfAccumulate("l2_hit_pre_first", base_valid_access_2 && resp_l2_pre && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1108*3ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit_pre_first", base_valid_access_2 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1109*3ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit_pre_first", base_valid_access_2 && resp_l0_pre && resp_l0) 1110bc063562SLemover XSPerfAccumulate("sp_hit_pre_first", base_valid_access_2 && resp_sp_pre && resp_sp) 1111*3ea4388cSHaoyuan Feng XSPerfAccumulate("pte_hit_pre_first",base_valid_access_2 && (resp_l0_pre && resp_l0 || resp_sp_pre && resp_sp) && io.resp.bits.hit) 1112bc063562SLemover 1113935edac4STang Haojin val base_valid_access_3 = stageResp.bits.isFirst && from_pre(io.resp.bits.req_info.source) && io.resp.fire 1114bc063562SLemover XSPerfAccumulate("pre_access_first", base_valid_access_3) 1115*3ea4388cSHaoyuan Feng if (EnableSv48) { 1116*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l3_hit_first", base_valid_access_3 && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1117*3ea4388cSHaoyuan Feng } 1118*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l2_hit_first", base_valid_access_3 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1119*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit_first", base_valid_access_3 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1120*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit_first", base_valid_access_3 && resp_l0) 1121bc063562SLemover XSPerfAccumulate("pre_sp_hit_first", base_valid_access_3 && resp_sp) 1122bc063562SLemover XSPerfAccumulate("pre_pte_hit_first", base_valid_access_3 && io.resp.bits.hit) 1123bc063562SLemover 1124*3ea4388cSHaoyuan Feng if (EnableSv48) { 1125*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l3_hit_pre_first", base_valid_access_3 && resp_l3_pre.get && io.resp.bits.toFsm.l3Hit.get && !io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1126*3ea4388cSHaoyuan Feng } 1127*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l2_hit_pre_first", base_valid_access_3 && resp_l2_pre && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1128*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit_pre_first", base_valid_access_3 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 1129*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit_pre_first", base_valid_access_3 && resp_l0_pre && resp_l0) 1130bc063562SLemover XSPerfAccumulate("pre_sp_hit_pre_first", base_valid_access_3 && resp_sp_pre && resp_sp) 1131*3ea4388cSHaoyuan Feng XSPerfAccumulate("pre_pte_hit_pre_first",base_valid_access_3 && (resp_l0_pre && resp_l0 || resp_sp_pre && resp_sp) && io.resp.bits.hit) 1132bc063562SLemover 11336d5ddbceSLemover XSPerfAccumulate("rwHarzad", io.req.valid && !io.req.ready) 11346d5ddbceSLemover XSPerfAccumulate("out_blocked", io.resp.valid && !io.resp.ready) 1135*3ea4388cSHaoyuan Feng if (EnableSv48) { 1136*3ea4388cSHaoyuan Feng l3AccessPerf.get.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l3AccessIndex${i}", l) } 1137*3ea4388cSHaoyuan Feng } 1138*3ea4388cSHaoyuan Feng l2AccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l2AccessIndex${i}", l) } 1139*3ea4388cSHaoyuan Feng l1AccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l1AccessIndex${i}", l) } 1140*3ea4388cSHaoyuan Feng l0AccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l0AccessIndex${i}", l) } 11416d5ddbceSLemover spAccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"SPAccessIndex${i}", l) } 1142*3ea4388cSHaoyuan Feng if (EnableSv48) { 1143*3ea4388cSHaoyuan Feng l3RefillPerf.get.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l3RefillIndex${i}", l) } 1144*3ea4388cSHaoyuan Feng } 1145*3ea4388cSHaoyuan Feng l2RefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l2RefillIndex${i}", l) } 1146*3ea4388cSHaoyuan Feng l1RefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l1RefillIndex${i}", l) } 1147*3ea4388cSHaoyuan Feng l0RefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l0RefillIndex${i}", l) } 11486d5ddbceSLemover spRefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"SPRefillIndex${i}", l) } 11496d5ddbceSLemover 1150*3ea4388cSHaoyuan Feng if (EnableSv48) { 1151*3ea4388cSHaoyuan Feng XSPerfAccumulate("l3Refill", Cat(l3RefillPerf.get).orR) 1152*3ea4388cSHaoyuan Feng } 1153bc063562SLemover XSPerfAccumulate("l2Refill", Cat(l2RefillPerf).orR) 1154*3ea4388cSHaoyuan Feng XSPerfAccumulate("l1Refill", Cat(l1RefillPerf).orR) 1155*3ea4388cSHaoyuan Feng XSPerfAccumulate("l0Refill", Cat(l0RefillPerf).orR) 1156bc063562SLemover XSPerfAccumulate("spRefill", Cat(spRefillPerf).orR) 1157*3ea4388cSHaoyuan Feng if (EnableSv48) { 1158*3ea4388cSHaoyuan Feng XSPerfAccumulate("l3Refill_pre", Cat(l3RefillPerf.get).orR && refill_prefetch_dup(0)) 1159*3ea4388cSHaoyuan Feng } 11607797f035SbugGenerator XSPerfAccumulate("l2Refill_pre", Cat(l2RefillPerf).orR && refill_prefetch_dup(0)) 1161*3ea4388cSHaoyuan Feng XSPerfAccumulate("l1Refill_pre", Cat(l1RefillPerf).orR && refill_prefetch_dup(0)) 1162*3ea4388cSHaoyuan Feng XSPerfAccumulate("l0Refill_pre", Cat(l0RefillPerf).orR && refill_prefetch_dup(0)) 11637797f035SbugGenerator XSPerfAccumulate("spRefill_pre", Cat(spRefillPerf).orR && refill_prefetch_dup(0)) 1164bc063562SLemover 11656d5ddbceSLemover // debug 11667797f035SbugGenerator XSDebug(sfence_dup(0).valid, p"[sfence] original v and g vector:\n") 1167*3ea4388cSHaoyuan Feng if (EnableSv48) { 1168*3ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l3v:${Binary(l3v.get)}\n") 1169*3ea4388cSHaoyuan Feng } 11707797f035SbugGenerator XSDebug(sfence_dup(0).valid, p"[sfence] l2v:${Binary(l2v)}\n") 1171*3ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l1v:${Binary(l1v)}\n") 1172*3ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l0v:${Binary(l0v)}\n") 1173*3ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l0g:${Binary(l0g)}\n") 11747797f035SbugGenerator XSDebug(sfence_dup(0).valid, p"[sfence] spv:${Binary(spv)}\n") 11757797f035SbugGenerator XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] new v and g vector:\n") 1176*3ea4388cSHaoyuan Feng if (EnableSv48) { 1177*3ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l3v:${Binary(l3v.get)}\n") 1178*3ea4388cSHaoyuan Feng } 11797797f035SbugGenerator XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l2v:${Binary(l2v)}\n") 1180*3ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l1v:${Binary(l1v)}\n") 1181*3ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l0v:${Binary(l0v)}\n") 1182*3ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l0g:${Binary(l0g)}\n") 11837797f035SbugGenerator XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] spv:${Binary(spv)}\n") 1184cd365d4cSrvcoresjw 1185cd365d4cSrvcoresjw val perfEvents = Seq( 118656be8e20SYinan Xu ("access ", base_valid_access_0 ), 1187cd365d4cSrvcoresjw ("l2_hit ", l2Hit ), 1188*3ea4388cSHaoyuan Feng ("l1_hit ", l1Hit ), 1189*3ea4388cSHaoyuan Feng ("l0_hit ", l0Hit ), 1190cd365d4cSrvcoresjw ("sp_hit ", spHit ), 1191*3ea4388cSHaoyuan Feng ("pte_hit ", l0Hit || spHit ), 1192cd365d4cSrvcoresjw ("rwHarzad ", io.req.valid && !io.req.ready ), 1193cd365d4cSrvcoresjw ("out_blocked ", io.resp.valid && !io.resp.ready), 1194cd365d4cSrvcoresjw ) 11951ca0e4f3SYinan Xu generatePerfEvent() 11966d5ddbceSLemover} 1197