16d5ddbceSLemover/*************************************************************************************** 28882eb68SXin Tian* Copyright (c) 2021-2025 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 58882eb68SXin Tian* Copyright (c) 2024-2025 Institute of Information Engineering, Chinese Academy of Sciences 66d5ddbceSLemover* 76d5ddbceSLemover* XiangShan is licensed under Mulan PSL v2. 86d5ddbceSLemover* You can use this software according to the terms and conditions of the Mulan PSL v2. 96d5ddbceSLemover* You may obtain a copy of Mulan PSL v2 at: 106d5ddbceSLemover* http://license.coscl.org.cn/MulanPSL2 116d5ddbceSLemover* 126d5ddbceSLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 136d5ddbceSLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 146d5ddbceSLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 156d5ddbceSLemover* 166d5ddbceSLemover* See the Mulan PSL v2 for more details. 176d5ddbceSLemover***************************************************************************************/ 186d5ddbceSLemover 196d5ddbceSLemoverpackage xiangshan.cache.mmu 206d5ddbceSLemover 218891a219SYinan Xuimport org.chipsalliance.cde.config.Parameters 226d5ddbceSLemoverimport chisel3._ 236d5ddbceSLemoverimport chisel3.util._ 246d5ddbceSLemoverimport xiangshan._ 256d5ddbceSLemoverimport xiangshan.cache.{HasDCacheParameters, MemoryOpConstants} 266d5ddbceSLemoverimport utils._ 273c02ee8fSwakafaimport utility._ 28abc4432bSHaoyuan Fengimport coupledL2.utils.SplittedSRAM 296d5ddbceSLemoverimport freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 306d5ddbceSLemoverimport freechips.rocketchip.tilelink._ 314b2c87baS梁森 Liang Senimport utility.mbist.MbistPipeline 326d5ddbceSLemover 336d5ddbceSLemover/* ptw cache caches the page table of all the three layers 346d5ddbceSLemover * ptw cache resp at next cycle 356d5ddbceSLemover * the cache should not be blocked 366d5ddbceSLemover * when miss queue if full, just block req outside 376d5ddbceSLemover */ 383889e11eSLemover 393889e11eSLemoverclass PageCachePerPespBundle(implicit p: Parameters) extends PtwBundle { 403889e11eSLemover val hit = Bool() 413889e11eSLemover val pre = Bool() 424c0e0181SXiaokun-Pei val ppn = UInt(gvpnLen.W) 43002c10a4SYanqin Li val pbmt = UInt(ptePbmtLen.W) 443889e11eSLemover val perm = new PtePermBundle() 45718a93f5SHaoyuan Feng val n = UInt(pteNLen.W) 463889e11eSLemover val ecc = Bool() 473889e11eSLemover val level = UInt(2.W) 488d8ac704SLemover val v = Bool() 498882eb68SXin Tian val bitmapCheck = Option.when(HasBitmapCheck)(new Bundle { 508882eb68SXin Tian val jmp_bitmap_check = Bool() 518882eb68SXin Tian val pte = UInt(XLEN.W) // Page Table Entry 528882eb68SXin Tian }) 533889e11eSLemover 54718a93f5SHaoyuan Feng def apply(hit: Bool, pre: Bool, ppn: UInt, pbmt: UInt = 0.U, n: UInt = 0.U, 55002c10a4SYanqin Li perm: PtePermBundle = 0.U.asTypeOf(new PtePermBundle()), 568882eb68SXin Tian ecc: Bool = false.B, level: UInt = 0.U, valid: Bool = true.B, jmp_bitmap_check: Bool = false.B, 578882eb68SXin Tian pte: UInt = 0.U): Unit = { 583889e11eSLemover this.hit := hit && !ecc 593889e11eSLemover this.pre := pre 603889e11eSLemover this.ppn := ppn 61718a93f5SHaoyuan Feng this.n := n 62002c10a4SYanqin Li this.pbmt := pbmt 633889e11eSLemover this.perm := perm 643889e11eSLemover this.ecc := ecc && hit 653889e11eSLemover this.level := level 668d8ac704SLemover this.v := valid 678882eb68SXin Tian if (HasBitmapCheck) { 688882eb68SXin Tian this.bitmapCheck.get.jmp_bitmap_check := jmp_bitmap_check 698882eb68SXin Tian this.bitmapCheck.get.pte := pte 708882eb68SXin Tian } 713889e11eSLemover } 723889e11eSLemover} 733889e11eSLemover 7463632028SHaoyuan Fengclass PageCacheMergePespBundle(implicit p: Parameters) extends PtwBundle { 7563632028SHaoyuan Feng assert(tlbcontiguous == 8, "Only support tlbcontiguous = 8!") 7663632028SHaoyuan Feng val hit = Bool() 7763632028SHaoyuan Feng val pre = Bool() 784c0e0181SXiaokun-Pei val ppn = Vec(tlbcontiguous, UInt(gvpnLen.W)) 79002c10a4SYanqin Li val pbmt = Vec(tlbcontiguous, UInt(ptePbmtLen.W)) 8063632028SHaoyuan Feng val perm = Vec(tlbcontiguous, new PtePermBundle()) 8163632028SHaoyuan Feng val ecc = Bool() 8263632028SHaoyuan Feng val level = UInt(2.W) 8363632028SHaoyuan Feng val v = Vec(tlbcontiguous, Bool()) 848882eb68SXin Tian val bitmapCheck = Option.when(HasBitmapCheck)(new Bundle { 858882eb68SXin Tian val jmp_bitmap_check = Bool() 868882eb68SXin Tian val hitway = UInt(l2tlbParams.l0nWays.W) 878882eb68SXin Tian val ptes = Vec(tlbcontiguous, UInt(XLEN.W)) // Page Table Entry Vector 888882eb68SXin Tian val cfs = Vec(tlbcontiguous, Bool()) // Bitmap Check Failed Vector 898882eb68SXin Tian }) 9063632028SHaoyuan Feng 91002c10a4SYanqin Li def apply(hit: Bool, pre: Bool, ppn: Vec[UInt], pbmt: Vec[UInt] = Vec(tlbcontiguous, 0.U), 92002c10a4SYanqin Li perm: Vec[PtePermBundle] = Vec(tlbcontiguous, 0.U.asTypeOf(new PtePermBundle())), 938882eb68SXin Tian ecc: Bool = false.B, level: UInt = 0.U, valid: Vec[Bool] = Vec(tlbcontiguous, true.B), 948882eb68SXin Tian jmp_bitmap_check: Bool = false.B, 958882eb68SXin Tian hitway: UInt = 0.U, ptes: Vec[UInt] , cfs: Vec[Bool]): Unit = { 9663632028SHaoyuan Feng this.hit := hit && !ecc 9763632028SHaoyuan Feng this.pre := pre 9863632028SHaoyuan Feng this.ppn := ppn 99002c10a4SYanqin Li this.pbmt := pbmt 10063632028SHaoyuan Feng this.perm := perm 10163632028SHaoyuan Feng this.ecc := ecc && hit 10263632028SHaoyuan Feng this.level := level 10363632028SHaoyuan Feng this.v := valid 1048882eb68SXin Tian if (HasBitmapCheck) { 1058882eb68SXin Tian this.bitmapCheck.get.jmp_bitmap_check := jmp_bitmap_check 1068882eb68SXin Tian this.bitmapCheck.get.hitway := hitway 1078882eb68SXin Tian this.bitmapCheck.get.ptes := ptes 1088882eb68SXin Tian this.bitmapCheck.get.cfs := cfs 1098882eb68SXin Tian } 11063632028SHaoyuan Feng } 11163632028SHaoyuan Feng} 11263632028SHaoyuan Feng 1133889e11eSLemoverclass PageCacheRespBundle(implicit p: Parameters) extends PtwBundle { 1143ea4388cSHaoyuan Feng val l3 = if (EnableSv48) Some(new PageCachePerPespBundle) else None 1153889e11eSLemover val l2 = new PageCachePerPespBundle 1163ea4388cSHaoyuan Feng val l1 = new PageCachePerPespBundle 1173ea4388cSHaoyuan Feng val l0 = new PageCacheMergePespBundle 1183889e11eSLemover val sp = new PageCachePerPespBundle 1193889e11eSLemover} 1203889e11eSLemover 1213889e11eSLemoverclass PtwCacheReq(implicit p: Parameters) extends PtwBundle { 1223889e11eSLemover val req_info = new L2TlbInnerBundle() 1233889e11eSLemover val isFirst = Bool() 1243ea4388cSHaoyuan Feng val bypassed = if (EnableSv48) Vec(4, Bool()) else Vec(3, Bool()) 125325f0a4eSpeixiaokun val isHptwReq = Bool() 126d0de7e4aSpeixiaokun val hptwId = UInt(log2Up(l2tlbParams.llptwsize).W) 1273889e11eSLemover} 1283889e11eSLemover 1293889e11eSLemoverclass PtwCacheIO()(implicit p: Parameters) extends MMUIOBaseBundle with HasPtwConst { 1303889e11eSLemover val req = Flipped(DecoupledIO(new PtwCacheReq())) 1316d5ddbceSLemover val resp = DecoupledIO(new Bundle { 13245f497a4Shappy-lx val req_info = new L2TlbInnerBundle() 13394133605SLemover val isFirst = Bool() 1346d5ddbceSLemover val hit = Bool() 135bc063562SLemover val prefetch = Bool() // is the entry fetched by prefetch 1361f4a7c0cSLemover val bypassed = Bool() 1376d5ddbceSLemover val toFsm = new Bundle { 1383ea4388cSHaoyuan Feng val l3Hit = if (EnableSv48) Some(Bool()) else None 1396d5ddbceSLemover val l2Hit = Bool() 1403ea4388cSHaoyuan Feng val l1Hit = Bool() 1414c0e0181SXiaokun-Pei val ppn = UInt(gvpnLen.W) 14230104977Speixiaokun val stage1Hit = Bool() // find stage 1 pte in cache, but need to search stage 2 pte in cache at PTW 1438882eb68SXin Tian val bitmapCheck = Option.when(HasBitmapCheck)(new Bundle { 1448882eb68SXin Tian val jmp_bitmap_check = Bool() // find pte in l0 or sp, but need bitmap check 1458882eb68SXin Tian val toLLPTW = Bool() 1468882eb68SXin Tian val hitway = UInt(l2tlbParams.l0nWays.W) 1478882eb68SXin Tian val pte = UInt(XLEN.W) // Page Table Entry 1488882eb68SXin Tian val ptes = Vec(tlbcontiguous, UInt(XLEN.W)) // Page Table Entry Vector 1498882eb68SXin Tian val cfs = Vec(tlbcontiguous, Bool()) // Bitmap Check Failed Vector 1508882eb68SXin Tian val SPlevel = UInt(log2Up(Level).W) 1518882eb68SXin Tian }) 1526d5ddbceSLemover } 1536979864eSXiaokun-Pei val stage1 = new PtwMergeResp() 154325f0a4eSpeixiaokun val isHptwReq = Bool() 155d0de7e4aSpeixiaokun val toHptw = new Bundle { 1563ea4388cSHaoyuan Feng val l3Hit = if (EnableSv48) Some(Bool()) else None 157d0de7e4aSpeixiaokun val l2Hit = Bool() 1583ea4388cSHaoyuan Feng val l1Hit = Bool() 159d0de7e4aSpeixiaokun val ppn = UInt(ppnLen.W) 160d0de7e4aSpeixiaokun val id = UInt(log2Up(l2tlbParams.llptwsize).W) 161d0de7e4aSpeixiaokun val resp = new HptwResp() // used if hit 16283d93d53Speixiaokun val bypassed = Bool() 1638882eb68SXin Tian val bitmapCheck = Option.when(HasBitmapCheck)(new Bundle { 1648882eb68SXin Tian val jmp_bitmap_check = Bool() // find pte in l0 or sp, but need bitmap check 1658882eb68SXin Tian val hitway = UInt(l2tlbParams.l0nWays.W) 1668882eb68SXin Tian val pte = UInt(XLEN.W) // Page Table Entry 1678882eb68SXin Tian val ptes = Vec(tlbcontiguous, UInt(XLEN.W)) // Page Table Entry Vector 1688882eb68SXin Tian val cfs = Vec(tlbcontiguous, Bool()) // Bitmap Check Failed Vector 1698882eb68SXin Tian val fromSP = Bool() 1708882eb68SXin Tian val SPlevel = UInt(log2Up(Level).W) 1718882eb68SXin Tian }) 172d0de7e4aSpeixiaokun } 1736d5ddbceSLemover }) 1746d5ddbceSLemover val refill = Flipped(ValidIO(new Bundle { 1755854c1edSLemover val ptes = UInt(blockBits.W) 1767797f035SbugGenerator val levelOH = new Bundle { 1777797f035SbugGenerator // NOTE: levelOH has (Level+1) bits, each stands for page cache entries 1787797f035SbugGenerator val sp = Bool() 1793ea4388cSHaoyuan Feng val l0 = Bool() 1807797f035SbugGenerator val l1 = Bool() 1813ea4388cSHaoyuan Feng val l2 = Bool() 1823ea4388cSHaoyuan Feng val l3 = if (EnableSv48) Some(Bool()) else None 1837797f035SbugGenerator def apply(levelUInt: UInt, valid: Bool) = { 1843ea4388cSHaoyuan Feng sp := GatedValidRegNext((levelUInt === 1.U || levelUInt === 2.U || levelUInt === 3.U) && valid, false.B) 1853ea4388cSHaoyuan Feng l0 := GatedValidRegNext((levelUInt === 0.U) & valid, false.B) 1863ea4388cSHaoyuan Feng l1 := GatedValidRegNext((levelUInt === 1.U) & valid, false.B) 1873ea4388cSHaoyuan Feng l2 := GatedValidRegNext((levelUInt === 2.U) & valid, false.B) 1883ea4388cSHaoyuan Feng l3.map(_ := GatedValidRegNext((levelUInt === 3.U) & valid, false.B)) 1897797f035SbugGenerator } 1907797f035SbugGenerator } 1917797f035SbugGenerator // duplicate level and sel_pte for each page caches, for better fanout 1927797f035SbugGenerator val req_info_dup = Vec(3, new L2TlbInnerBundle()) 1933ea4388cSHaoyuan Feng val level_dup = Vec(3, UInt(log2Up(Level + 1).W)) 1947797f035SbugGenerator val sel_pte_dup = Vec(3, UInt(XLEN.W)) 1956d5ddbceSLemover })) 1968882eb68SXin Tian // when refill l0,save way info for late bitmap wakeup convenient 1978882eb68SXin Tian // valid at same cycle of refill.levelOH.l0 1988882eb68SXin Tian val l0_way_info = Option.when(HasBitmapCheck)(Output(UInt(l2tlbParams.l0nWays.W))) 1997797f035SbugGenerator val sfence_dup = Vec(4, Input(new SfenceBundle())) 2007797f035SbugGenerator val csr_dup = Vec(3, Input(new TlbCsrBundle())) 2018882eb68SXin Tian val bitmap_wakeup = Option.when(HasBitmapCheck)(Flipped(ValidIO(new Bundle { 2028882eb68SXin Tian val setIndex = Input(UInt(PtwL0SetIdxLen.W)) 2038882eb68SXin Tian val tag = Input(UInt(SPTagLen.W)) 2048882eb68SXin Tian val isSp = Input(Bool()) 2058882eb68SXin Tian val way_info = UInt(l2tlbParams.l0nWays.W) 2068882eb68SXin Tian val pte_index = UInt(sectortlbwidth.W) 2078882eb68SXin Tian val check_success = Bool() 2088882eb68SXin Tian }))) 2096d5ddbceSLemover} 2106d5ddbceSLemover 2111ca0e4f3SYinan Xuclass PtwCache()(implicit p: Parameters) extends XSModule with HasPtwConst with HasPerfEvents { 2126d5ddbceSLemover val io = IO(new PtwCacheIO) 2137196f5a2SLemover val ecc = Code.fromString(l2tlbParams.ecc) 214abc4432bSHaoyuan Feng val l1EntryType = new PTWEntriesWithEcc(ecc, num = PtwL1SectorSize, tagLen = PtwL1TagLen, level = 1, hasPerm = false, ReservedBits = l2tlbParams.l1ReservedBits) 215abc4432bSHaoyuan Feng val l0EntryType = new PTWEntriesWithEcc(ecc, num = PtwL0SectorSize, tagLen = PtwL0TagLen, level = 0, hasPerm = true, ReservedBits = l2tlbParams.l0ReservedBits) 2167196f5a2SLemover 2178882eb68SXin Tian // use two additional regs to record corresponding cache entry whether via bitmap check 2188882eb68SXin Tian // 32(l0nSets)* 8 (l0nWays) * 8 (tlbcontiguous) 2198882eb68SXin Tian val l0BitmapReg = RegInit(VecInit(Seq.fill(l2tlbParams.l0nSets)(VecInit(Seq.fill(l2tlbParams.l0nWays)(VecInit(Seq.fill(tlbcontiguous)(0.U(1.W)))))))) 2208882eb68SXin Tian val spBitmapReg = RegInit(VecInit(Seq.fill(l2tlbParams.spSize)(0.U(1.W)))) 2218882eb68SXin Tian 2228882eb68SXin Tian val bitmapEnable = io.csr_dup(0).mbmc.BME === 1.U && io.csr_dup(0).mbmc.CMODE === 0.U 2236d5ddbceSLemover // TODO: four caches make the codes dirty, think about how to deal with it 2246d5ddbceSLemover 2257797f035SbugGenerator val sfence_dup = io.sfence_dup 2266d5ddbceSLemover val refill = io.refill.bits 2277797f035SbugGenerator val refill_prefetch_dup = io.refill.bits.req_info_dup.map(a => from_pre(a.source)) 2284ed5afbdSXiaokun-Pei val refill_h = io.refill.bits.req_info_dup.map(a => Mux(a.s2xlate === allStage, onlyStage1, a.s2xlate)) 229d0de7e4aSpeixiaokun 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) 2307797f035SbugGenerator val flush = flush_dup(0) 2316d5ddbceSLemover 2326d5ddbceSLemover // when refill, refuce to accept new req 2335854c1edSLemover val rwHarzad = if (sramSinglePort) io.refill.valid else false.B 2343889e11eSLemover 2353889e11eSLemover // handle hand signal and req_info 2366c4dcc2dSLemover // TODO: replace with FlushableQueue 2376c4dcc2dSLemover val stageReq = Wire(Decoupled(new PtwCacheReq())) // enq stage & read page cache valid 2386c4dcc2dSLemover val stageDelay = Wire(Vec(2, Decoupled(new PtwCacheReq()))) // page cache resp 2396c4dcc2dSLemover val stageCheck = Wire(Vec(2, Decoupled(new PtwCacheReq()))) // check hit & check ecc 2406c4dcc2dSLemover val stageResp = Wire(Decoupled(new PtwCacheReq())) // deq stage 2417797f035SbugGenerator 2427797f035SbugGenerator val stageDelay_valid_1cycle = OneCycleValid(stageReq.fire, flush) // catch ram data 2437797f035SbugGenerator val stageCheck_valid_1cycle = OneCycleValid(stageDelay(1).fire, flush) // replace & perf counter 2447797f035SbugGenerator val stageResp_valid_1cycle_dup = Wire(Vec(2, Bool())) 2457797f035SbugGenerator stageResp_valid_1cycle_dup.map(_ := OneCycleValid(stageCheck(1).fire, flush)) // ecc flush 2467797f035SbugGenerator 2476c4dcc2dSLemover stageReq <> io.req 2486c4dcc2dSLemover PipelineConnect(stageReq, stageDelay(0), stageDelay(1).ready, flush, rwHarzad) 2497797f035SbugGenerator InsideStageConnect(stageDelay(0), stageDelay(1), stageDelay_valid_1cycle) 2506c4dcc2dSLemover PipelineConnect(stageDelay(1), stageCheck(0), stageCheck(1).ready, flush) 2517797f035SbugGenerator InsideStageConnect(stageCheck(0), stageCheck(1), stageCheck_valid_1cycle) 2526c4dcc2dSLemover PipelineConnect(stageCheck(1), stageResp, io.resp.ready, flush) 2536c4dcc2dSLemover stageResp.ready := !stageResp.valid || io.resp.ready 2546d5ddbceSLemover 2553ea4388cSHaoyuan Feng // l3: level 3 non-leaf pte 2563ea4388cSHaoyuan Feng val l3 = if (EnableSv48) Some(Reg(Vec(l2tlbParams.l3Size, new PtwEntry(tagLen = PtwL3TagLen)))) else None 2573ea4388cSHaoyuan Feng val l3v = if (EnableSv48) Some(RegInit(0.U(l2tlbParams.l3Size.W))) else None 2583ea4388cSHaoyuan Feng val l3g = if (EnableSv48) Some(Reg(UInt(l2tlbParams.l3Size.W))) else None 2593ea4388cSHaoyuan Feng val l3asids = if (EnableSv48) Some(l3.get.map(_.asid)) else None 2603ea4388cSHaoyuan Feng val l3vmids = if (EnableSv48) Some(l3.get.map(_.vmid)) else None 2613ea4388cSHaoyuan Feng val l3h = if (EnableSv48) Some(Reg(Vec(l2tlbParams.l3Size, UInt(2.W)))) else None 2626d5ddbceSLemover 2633ea4388cSHaoyuan Feng // l2: level 2 non-leaf pte 2643ea4388cSHaoyuan Feng val l2 = Reg(Vec(l2tlbParams.l2Size, new PtwEntry(tagLen = PtwL2TagLen))) 2653ea4388cSHaoyuan Feng val l2v = RegInit(0.U(l2tlbParams.l2Size.W)) 2663ea4388cSHaoyuan Feng val l2g = Reg(UInt(l2tlbParams.l2Size.W)) 2673ea4388cSHaoyuan Feng val l2asids = l2.map(_.asid) 2683ea4388cSHaoyuan Feng val l2vmids = l2.map(_.vmid) 2693ea4388cSHaoyuan Feng val l2h = Reg(Vec(l2tlbParams.l2Size, UInt(2.W))) 2703ea4388cSHaoyuan Feng 2713ea4388cSHaoyuan Feng // l1: level 1 non-leaf pte 272abc4432bSHaoyuan Feng val l1 = Module(new SplittedSRAM( 2733ea4388cSHaoyuan Feng l1EntryType, 2743ea4388cSHaoyuan Feng set = l2tlbParams.l1nSets, 2753ea4388cSHaoyuan Feng way = l2tlbParams.l1nWays, 276d4265a7fSHaoyuan Feng waySplit = 1, 277abc4432bSHaoyuan Feng dataSplit = 4, 278abc4432bSHaoyuan Feng singlePort = sramSinglePort, 2794b2c87baS梁森 Liang Sen readMCP2 = false, 280602aa9f1Scz4e hasMbist = hasMbist, 281602aa9f1Scz4e hasSramCtl = hasSramCtl 2826d5ddbceSLemover )) 2834b2c87baS梁森 Liang Sen val mbistPlL1 = MbistPipeline.PlaceMbistPipeline(1, s"MbistPipePtwL1", hasMbist) 2843ea4388cSHaoyuan Feng val l1v = RegInit(0.U((l2tlbParams.l1nSets * l2tlbParams.l1nWays).W)) 2853ea4388cSHaoyuan Feng val l1g = Reg(UInt((l2tlbParams.l1nSets * l2tlbParams.l1nWays).W)) 2863ea4388cSHaoyuan Feng val l1h = Reg(Vec(l2tlbParams.l1nSets, Vec(l2tlbParams.l1nWays, UInt(2.W)))) 287f9395f72SHaoyuan Feng val l1asids = Reg(Vec(l2tlbParams.l1nSets, Vec(l2tlbParams.l1nWays, UInt(l2tlbParams.hashAsidWidth.W)))) 288f9395f72SHaoyuan Feng val l1vmids = Reg(Vec(l2tlbParams.l1nSets, Vec(l2tlbParams.l1nWays, UInt(l2tlbParams.hashAsidWidth.W)))) 2893ea4388cSHaoyuan Feng def getl1vSet(vpn: UInt) = { 2903ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l1nWays) == log2Down(l2tlbParams.l1nWays)) 2913ea4388cSHaoyuan Feng val set = genPtwL1SetIdx(vpn) 2923ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l1nSets)) 2933ea4388cSHaoyuan Feng val l1vVec = l1v.asTypeOf(Vec(l2tlbParams.l1nSets, UInt(l2tlbParams.l1nWays.W))) 2943ea4388cSHaoyuan Feng l1vVec(set) 2956d5ddbceSLemover } 2963ea4388cSHaoyuan Feng def getl1hSet(vpn: UInt) = { 2973ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l1nWays) == log2Down(l2tlbParams.l1nWays)) 2983ea4388cSHaoyuan Feng val set = genPtwL1SetIdx(vpn) 2993ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l1nSets)) 3003ea4388cSHaoyuan Feng l1h(set) 30145f497a4Shappy-lx } 3026d5ddbceSLemover 3033ea4388cSHaoyuan Feng // l0: level 0 leaf pte of 4KB pages 304abc4432bSHaoyuan Feng val l0 = Module(new SplittedSRAM( 3053ea4388cSHaoyuan Feng l0EntryType, 3063ea4388cSHaoyuan Feng set = l2tlbParams.l0nSets, 3073ea4388cSHaoyuan Feng way = l2tlbParams.l0nWays, 308d4265a7fSHaoyuan Feng waySplit = 2, 309abc4432bSHaoyuan Feng dataSplit = 4, 310abc4432bSHaoyuan Feng singlePort = sramSinglePort, 3114b2c87baS梁森 Liang Sen readMCP2 = false, 312602aa9f1Scz4e hasMbist = hasMbist, 313602aa9f1Scz4e hasSramCtl = hasSramCtl 3146d5ddbceSLemover )) 3154b2c87baS梁森 Liang Sen val mbistPlL0 = MbistPipeline.PlaceMbistPipeline(1, s"MbistPipePtwL0", hasMbist) 3163ea4388cSHaoyuan Feng val l0v = RegInit(0.U((l2tlbParams.l0nSets * l2tlbParams.l0nWays).W)) 3173ea4388cSHaoyuan Feng val l0g = Reg(UInt((l2tlbParams.l0nSets * l2tlbParams.l0nWays).W)) 3183ea4388cSHaoyuan Feng val l0h = Reg(Vec(l2tlbParams.l0nSets, Vec(l2tlbParams.l0nWays, UInt(2.W)))) 319f9395f72SHaoyuan Feng val l0asids = Reg(Vec(l2tlbParams.l0nSets, Vec(l2tlbParams.l0nWays, UInt(l2tlbParams.hashAsidWidth.W)))) 320f9395f72SHaoyuan Feng val l0vmids = Reg(Vec(l2tlbParams.l0nSets, Vec(l2tlbParams.l0nWays, UInt(l2tlbParams.hashAsidWidth.W)))) 321f9395f72SHaoyuan Feng val l0vpns = Reg(Vec(l2tlbParams.l0nSets, Vec(l2tlbParams.l0nWays, UInt(l2tlbParams.hashVpnWidth.W)))) 3223ea4388cSHaoyuan Feng def getl0vSet(vpn: UInt) = { 3233ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l0nWays) == log2Down(l2tlbParams.l0nWays)) 3243ea4388cSHaoyuan Feng val set = genPtwL0SetIdx(vpn) 3253ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l0nSets)) 3263ea4388cSHaoyuan Feng val l0vVec = l0v.asTypeOf(Vec(l2tlbParams.l0nSets, UInt(l2tlbParams.l0nWays.W))) 3273ea4388cSHaoyuan Feng l0vVec(set) 3286d5ddbceSLemover } 3293ea4388cSHaoyuan Feng def getl0hSet(vpn: UInt) = { 3303ea4388cSHaoyuan Feng require(log2Up(l2tlbParams.l0nWays) == log2Down(l2tlbParams.l0nWays)) 3313ea4388cSHaoyuan Feng val set = genPtwL0SetIdx(vpn) 3323ea4388cSHaoyuan Feng require(set.getWidth == log2Up(l2tlbParams.l0nSets)) 3333ea4388cSHaoyuan Feng l0h(set) 33445f497a4Shappy-lx } 3356d5ddbceSLemover 3363ea4388cSHaoyuan Feng // sp: level 1/2/3 leaf pte of 512GB/1GB/2MB super pages 337718a93f5SHaoyuan Feng val sp = Reg(Vec(l2tlbParams.spSize, new PtwEntry(tagLen = SPTagLen, hasPerm = true, hasLevel = true, hasNapot = true))) 3385854c1edSLemover val spv = RegInit(0.U(l2tlbParams.spSize.W)) 3395854c1edSLemover val spg = Reg(UInt(l2tlbParams.spSize.W)) 3401dd3e32dSHaoyuan Feng val spasids = sp.map(_.asid) 341d0de7e4aSpeixiaokun val spvmids = sp.map(_.vmid) 342d61cd5eeSpeixiaokun val sph = Reg(Vec(l2tlbParams.spSize, UInt(2.W))) 3436d5ddbceSLemover 3448882eb68SXin Tian if (HasBitmapCheck) { 3458882eb68SXin Tian // wakeup corresponding entry 3468882eb68SXin Tian when (io.bitmap_wakeup.get.valid) { 3478882eb68SXin Tian when (io.bitmap_wakeup.get.bits.isSp) { 3488882eb68SXin Tian for (i <- 0 until l2tlbParams.spSize) { 3498882eb68SXin Tian when (sp(i).tag === io.bitmap_wakeup.get.bits.tag && spv(i) === 1.U) { 3508882eb68SXin Tian spBitmapReg(i) := io.bitmap_wakeup.get.bits.check_success 3518882eb68SXin Tian } 3528882eb68SXin Tian } 3538882eb68SXin Tian } .otherwise { 3548882eb68SXin Tian val wakeup_setindex = io.bitmap_wakeup.get.bits.setIndex 3558882eb68SXin Tian l0BitmapReg(wakeup_setindex)(OHToUInt(io.bitmap_wakeup.get.bits.way_info))(io.bitmap_wakeup.get.bits.pte_index) := io.bitmap_wakeup.get.bits.check_success 3568882eb68SXin Tian assert(l0v(wakeup_setindex * l2tlbParams.l0nWays.U + OHToUInt(io.bitmap_wakeup.get.bits.way_info)) === 1.U, 3578882eb68SXin Tian "Wakeuped entry must be valid!") 3588882eb68SXin Tian } 3598882eb68SXin Tian } 3608882eb68SXin Tian } 3618882eb68SXin Tian 3626d5ddbceSLemover // Access Perf 3633ea4388cSHaoyuan Feng val l3AccessPerf = if(EnableSv48) Some(Wire(Vec(l2tlbParams.l3Size, Bool()))) else None 3643ea4388cSHaoyuan Feng val l2AccessPerf = Wire(Vec(l2tlbParams.l2Size, Bool())) 3653ea4388cSHaoyuan Feng val l1AccessPerf = Wire(Vec(l2tlbParams.l1nWays, Bool())) 3663ea4388cSHaoyuan Feng val l0AccessPerf = Wire(Vec(l2tlbParams.l0nWays, Bool())) 3675854c1edSLemover val spAccessPerf = Wire(Vec(l2tlbParams.spSize, Bool())) 3683ea4388cSHaoyuan Feng if (EnableSv48) l3AccessPerf.map(_.map(_ := false.B)) 3696d5ddbceSLemover l2AccessPerf.map(_ := false.B) 3703ea4388cSHaoyuan Feng l1AccessPerf.map(_ := false.B) 3713ea4388cSHaoyuan Feng l0AccessPerf.map(_ := false.B) 3726d5ddbceSLemover spAccessPerf.map(_ := false.B) 3736d5ddbceSLemover 3743889e11eSLemover 3751f4a7c0cSLemover 37682978df9Speixiaokun def vpn_match(vpn1: UInt, vpn2: UInt, level: Int) = { 3773ea4388cSHaoyuan Feng (vpn1(vpnLen-1, vpnnLen*level+3) === vpn2(vpnLen-1, vpnnLen*level+3)) 3781f4a7c0cSLemover } 3791f4a7c0cSLemover // NOTE: not actually bypassed, just check if hit, re-access the page cache 380d0de7e4aSpeixiaokun def refill_bypass(vpn: UInt, level: Int, h_search: UInt) = { 3816f508cb5Speixiaokun val change_h = MuxLookup(h_search, noS2xlate)(Seq( 382980ddf4cSpeixiaokun allStage -> onlyStage1, 383980ddf4cSpeixiaokun onlyStage1 -> onlyStage1, 384980ddf4cSpeixiaokun onlyStage2 -> onlyStage2 385980ddf4cSpeixiaokun )) 3864ed5afbdSXiaokun-Pei val change_refill_h = MuxLookup(io.refill.bits.req_info_dup(0).s2xlate, noS2xlate)(Seq( 3874ed5afbdSXiaokun-Pei allStage -> onlyStage1, 3884ed5afbdSXiaokun-Pei onlyStage1 -> onlyStage1, 3894ed5afbdSXiaokun-Pei onlyStage2 -> onlyStage2 3904ed5afbdSXiaokun-Pei )) 391d0de7e4aSpeixiaokun val refill_vpn = io.refill.bits.req_info_dup(0).vpn 3924ed5afbdSXiaokun-Pei io.refill.valid && (level.U === io.refill.bits.level_dup(0)) && vpn_match(refill_vpn, vpn, level) && change_h === change_refill_h 3931f4a7c0cSLemover } 3941f4a7c0cSLemover 39582978df9Speixiaokun val vpn_search = stageReq.bits.req_info.vpn 3966f508cb5Speixiaokun val h_search = MuxLookup(stageReq.bits.req_info.s2xlate, noS2xlate)(Seq( 39709280d15Speixiaokun allStage -> onlyStage1, 39809280d15Speixiaokun onlyStage1 -> onlyStage1, 39909280d15Speixiaokun onlyStage2 -> onlyStage2 40009280d15Speixiaokun )) 4013ea4388cSHaoyuan Feng 4023ea4388cSHaoyuan Feng // l3 4033ea4388cSHaoyuan Feng val l3Hit = if(EnableSv48) Some(Wire(Bool())) else None 404776b48dbSHaoyuan Feng val l3HitPPN = if(EnableSv48) Some(Wire(UInt(gvpnLen.W))) else None 405002c10a4SYanqin Li val l3HitPbmt = if(EnableSv48) Some(Wire(UInt(ptePbmtLen.W))) else None 4063ea4388cSHaoyuan Feng val l3Pre = if(EnableSv48) Some(Wire(Bool())) else None 4073ea4388cSHaoyuan Feng val ptwl3replace = if(EnableSv48) Some(ReplacementPolicy.fromString(l2tlbParams.l3Replacer, l2tlbParams.l3Size)) else None 4083ea4388cSHaoyuan Feng if (EnableSv48) { 4093ea4388cSHaoyuan Feng val hitVecT = l3.get.zipWithIndex.map { 41097929664SXiaokun-Pei case (e, i) => (e.hit(vpn_search, io.csr_dup(2).satp.asid, io.csr_dup(2).vsatp.asid, io.csr_dup(2).hgatp.vmid, s2xlate = h_search =/= noS2xlate) 4113ea4388cSHaoyuan Feng && l3v.get(i) && h_search === l3h.get(i)) 412d0de7e4aSpeixiaokun } 4136c4dcc2dSLemover val hitVec = hitVecT.map(RegEnable(_, stageReq.fire)) 4141f4a7c0cSLemover 4153ea4388cSHaoyuan Feng // stageDelay, but check for l3 4163ea4388cSHaoyuan Feng val hitPPN = DataHoldBypass(ParallelPriorityMux(hitVec zip l3.get.map(_.ppn)), stageDelay_valid_1cycle) 417002c10a4SYanqin Li val hitPbmt = DataHoldBypass(ParallelPriorityMux(hitVec zip l3.get.map(_.pbmt)), stageDelay_valid_1cycle) 4183ea4388cSHaoyuan Feng val hitPre = DataHoldBypass(ParallelPriorityMux(hitVec zip l3.get.map(_.prefetch)), stageDelay_valid_1cycle) 4191f4a7c0cSLemover val hit = DataHoldBypass(ParallelOR(hitVec), stageDelay_valid_1cycle) 4206d5ddbceSLemover 4213ea4388cSHaoyuan Feng when (hit && stageDelay_valid_1cycle) { ptwl3replace.get.access(OHToUInt(hitVec)) } 4226d5ddbceSLemover 4233ea4388cSHaoyuan Feng l3AccessPerf.get.zip(hitVec).map{ case (l, h) => l := h && stageDelay_valid_1cycle} 4243ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l3Size) { 42597929664SXiaokun-Pei 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.vmid, s2xlate = h_search =/= noS2xlate)}\n") 4266d5ddbceSLemover } 4273ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l3] l3v:${Binary(l3v.get)} hitVecT:${Binary(VecInit(hitVecT).asUInt)}\n") 4283ea4388cSHaoyuan Feng XSDebug(stageDelay(0).valid, p"[l3] l3Hit:${hit} l3HitPPN:0x${Hexadecimal(hitPPN)} hitVec:${VecInit(hitVec).asUInt}\n") 4296d5ddbceSLemover 4303ea4388cSHaoyuan Feng VecInit(hitVecT).suggestName(s"l3_hitVecT") 4313ea4388cSHaoyuan Feng VecInit(hitVec).suggestName(s"l3_hitVec") 4323ea4388cSHaoyuan Feng 4333ea4388cSHaoyuan Feng // synchronize with other entries with RegEnable 4343ea4388cSHaoyuan Feng l3Hit.map(_ := RegEnable(hit, stageDelay(1).fire)) 4353ea4388cSHaoyuan Feng l3HitPPN.map(_ := RegEnable(hitPPN, stageDelay(1).fire)) 436002c10a4SYanqin Li l3HitPbmt.map(_ := RegEnable(hitPbmt, stageDelay(1).fire)) 4373ea4388cSHaoyuan Feng l3Pre.map(_ := RegEnable(hitPre, stageDelay(1).fire)) 4383ea4388cSHaoyuan Feng } 4393ea4388cSHaoyuan Feng 4403ea4388cSHaoyuan Feng // l2 4413ea4388cSHaoyuan Feng val ptwl2replace = ReplacementPolicy.fromString(l2tlbParams.l2Replacer, l2tlbParams.l2Size) 442002c10a4SYanqin Li val (l2Hit, l2HitPPN, l2HitPbmt, l2Pre) = { 4433ea4388cSHaoyuan Feng val hitVecT = l2.zipWithIndex.map { 44497929664SXiaokun-Pei case (e, i) => (e.hit(vpn_search, io.csr_dup(2).satp.asid, io.csr_dup(2).vsatp.asid, io.csr_dup(2).hgatp.vmid, s2xlate = h_search =/= noS2xlate) 4453ea4388cSHaoyuan Feng && l2v(i) && h_search === l2h(i)) 4463ea4388cSHaoyuan Feng } 4473ea4388cSHaoyuan Feng val hitVec = hitVecT.map(RegEnable(_, stageReq.fire)) 4483ea4388cSHaoyuan Feng 4493ea4388cSHaoyuan Feng // stageDelay, but check for l2 4503ea4388cSHaoyuan Feng val hitPPN = DataHoldBypass(ParallelPriorityMux(hitVec zip l2.map(_.ppn)), stageDelay_valid_1cycle) 451002c10a4SYanqin Li val hitPbmt = DataHoldBypass(ParallelPriorityMux(hitVec zip l2.map(_.pbmt)), stageDelay_valid_1cycle) 4523ea4388cSHaoyuan Feng val hitPre = DataHoldBypass(ParallelPriorityMux(hitVec zip l2.map(_.prefetch)), stageDelay_valid_1cycle) 4533ea4388cSHaoyuan Feng val hit = DataHoldBypass(ParallelOR(hitVec), stageDelay_valid_1cycle) 4543ea4388cSHaoyuan Feng 4553ea4388cSHaoyuan Feng when (hit && stageDelay_valid_1cycle) { ptwl2replace.access(OHToUInt(hitVec)) } 4563ea4388cSHaoyuan Feng 4573ea4388cSHaoyuan Feng l2AccessPerf.zip(hitVec).map{ case (l, h) => l := h && stageDelay_valid_1cycle} 4583ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l2Size) { 45997929664SXiaokun-Pei 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.vmid, s2xlate = h_search =/= noS2xlate)}\n") 4603ea4388cSHaoyuan Feng } 4613ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l2] l2v:${Binary(l2v)} hitVecT:${Binary(VecInit(hitVecT).asUInt)}\n") 4623ea4388cSHaoyuan Feng XSDebug(stageDelay(0).valid, p"[l2] l2Hit:${hit} l2HitPPN:0x${Hexadecimal(hitPPN)} hitVec:${VecInit(hitVec).asUInt}\n") 4633ea4388cSHaoyuan Feng 4643ea4388cSHaoyuan Feng VecInit(hitVecT).suggestName(s"l2_hitVecT") 4653ea4388cSHaoyuan Feng VecInit(hitVec).suggestName(s"l2_hitVec") 4666d5ddbceSLemover 4676c4dcc2dSLemover // synchronize with other entries with RegEnable 4686c4dcc2dSLemover (RegEnable(hit, stageDelay(1).fire), 4696c4dcc2dSLemover RegEnable(hitPPN, stageDelay(1).fire), 470002c10a4SYanqin Li RegEnable(hitPbmt, stageDelay(1).fire), 4716c4dcc2dSLemover RegEnable(hitPre, stageDelay(1).fire)) 4726d5ddbceSLemover } 4736d5ddbceSLemover 4743ea4388cSHaoyuan Feng // l1 4753ea4388cSHaoyuan Feng val ptwl1replace = ReplacementPolicy.fromString(l2tlbParams.l1Replacer,l2tlbParams.l1nWays,l2tlbParams.l1nSets) 476002c10a4SYanqin Li val (l1Hit, l1HitPPN, l1HitPbmt, l1Pre, l1eccError) = { 4773ea4388cSHaoyuan Feng val ridx = genPtwL1SetIdx(vpn_search) 4783ea4388cSHaoyuan Feng l1.io.r.req.valid := stageReq.fire 4793ea4388cSHaoyuan Feng l1.io.r.req.bits.apply(setIdx = ridx) 4803ea4388cSHaoyuan Feng val vVec_req = getl1vSet(vpn_search) 4813ea4388cSHaoyuan Feng val hVec_req = getl1hSet(vpn_search) 4826c4dcc2dSLemover 4836c4dcc2dSLemover // delay one cycle after sram read 48482978df9Speixiaokun val delay_vpn = stageDelay(0).bits.req_info.vpn 4856f508cb5Speixiaokun val delay_h = MuxLookup(stageDelay(0).bits.req_info.s2xlate, noS2xlate)(Seq( 486980ddf4cSpeixiaokun allStage -> onlyStage1, 487980ddf4cSpeixiaokun onlyStage1 -> onlyStage1, 488980ddf4cSpeixiaokun onlyStage2 -> onlyStage2 489980ddf4cSpeixiaokun )) 4903ea4388cSHaoyuan Feng val data_resp = DataHoldBypass(l1.io.r.resp.data, stageDelay_valid_1cycle) 4917797f035SbugGenerator val vVec_delay = RegEnable(vVec_req, stageReq.fire) 492d0de7e4aSpeixiaokun val hVec_delay = RegEnable(hVec_req, stageReq.fire) 493d0de7e4aSpeixiaokun val hitVec_delay = VecInit(data_resp.zip(vVec_delay.asBools).zip(hVec_delay).map { case ((wayData, v), h) => 49497929664SXiaokun-Pei wayData.entries.hit(delay_vpn, io.csr_dup(1).satp.asid, io.csr_dup(1).vsatp.asid, io.csr_dup(1).hgatp.vmid, s2xlate = delay_h =/= noS2xlate) && v && (delay_h === h)}) 4956c4dcc2dSLemover 4966c4dcc2dSLemover // check hit and ecc 49782978df9Speixiaokun val check_vpn = stageCheck(0).bits.req_info.vpn 4986c4dcc2dSLemover val ramDatas = RegEnable(data_resp, stageDelay(1).fire) 499935edac4STang Haojin val vVec = RegEnable(vVec_delay, stageDelay(1).fire).asBools 5006c4dcc2dSLemover 5017797f035SbugGenerator val hitVec = RegEnable(hitVec_delay, stageDelay(1).fire) 5027196f5a2SLemover val hitWayEntry = ParallelPriorityMux(hitVec zip ramDatas) 5037196f5a2SLemover val hitWayData = hitWayEntry.entries 5046c4dcc2dSLemover val hit = ParallelOR(hitVec) 5053ea4388cSHaoyuan Feng val hitWay = ParallelPriorityMux(hitVec zip (0 until l2tlbParams.l1nWays).map(_.U(log2Up(l2tlbParams.l1nWays).W))) 506eef81af7SHaoyuan Feng val eccError = WireInit(false.B) 507eef81af7SHaoyuan Feng if (l2tlbParams.enablePTWECC) { 508eef81af7SHaoyuan Feng eccError := hitWayEntry.decode() 509eef81af7SHaoyuan Feng } else { 510eef81af7SHaoyuan Feng eccError := false.B 511eef81af7SHaoyuan Feng } 5127196f5a2SLemover 5133ea4388cSHaoyuan Feng ridx.suggestName(s"l1_ridx") 5143ea4388cSHaoyuan Feng ramDatas.suggestName(s"l1_ramDatas") 5153ea4388cSHaoyuan Feng hitVec.suggestName(s"l1_hitVec") 5163ea4388cSHaoyuan Feng hitWayData.suggestName(s"l1_hitWayData") 5173ea4388cSHaoyuan Feng hitWay.suggestName(s"l1_hitWay") 5186d5ddbceSLemover 5193ea4388cSHaoyuan Feng when (hit && stageCheck_valid_1cycle) { ptwl1replace.access(genPtwL1SetIdx(check_vpn), hitWay) } 5206d5ddbceSLemover 5213ea4388cSHaoyuan Feng l1AccessPerf.zip(hitVec).map{ case (l, h) => l := h && stageCheck_valid_1cycle } 5223ea4388cSHaoyuan Feng XSDebug(stageDelay_valid_1cycle, p"[l1] ridx:0x${Hexadecimal(ridx)}\n") 5233ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l1nWays) { 5243ea4388cSHaoyuan Feng XSDebug(stageCheck_valid_1cycle, p"[l1] ramDatas(${i.U}) ${ramDatas(i)} l1v:${vVec(i)} hit:${hit}\n") 5256d5ddbceSLemover } 5263ea4388cSHaoyuan 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") 5276d5ddbceSLemover 528002c10a4SYanqin Li (hit, hitWayData.ppns(genPtwL1SectorIdx(check_vpn)), hitWayData.pbmts(genPtwL1SectorIdx(check_vpn)), hitWayData.prefetch, eccError) 5296d5ddbceSLemover } 5304b2c87baS梁森 Liang Sen val te = ClockGate.genTeSink 5314b2c87baS梁森 Liang Sen val l0_masked_clock = ClockGate(te.cgen, stageReq.fire | (!flush_dup(0) && refill.levelOH.l0) | mbistPlL0.map(_.mbist.req).getOrElse(false.B), clock) 5324b2c87baS梁森 Liang Sen val l1_masked_clock = ClockGate(te.cgen, stageReq.fire | (!flush_dup(1) && refill.levelOH.l1) | mbistPlL1.map(_.mbist.req).getOrElse(false.B), clock) 533b32e9518SHuijin Li l0.clock := l0_masked_clock 534b32e9518SHuijin Li l1.clock := l1_masked_clock 5353ea4388cSHaoyuan Feng // l0 5363ea4388cSHaoyuan Feng val ptwl0replace = ReplacementPolicy.fromString(l2tlbParams.l0Replacer,l2tlbParams.l0nWays,l2tlbParams.l0nSets) 5378882eb68SXin Tian val (l0Hit, l0HitData, l0Pre, l0eccError, l0HitWay, l0BitmapCheckResult, l0JmpBitmapCheck) = { 5383ea4388cSHaoyuan Feng val ridx = genPtwL0SetIdx(vpn_search) 5393ea4388cSHaoyuan Feng l0.io.r.req.valid := stageReq.fire 5403ea4388cSHaoyuan Feng l0.io.r.req.bits.apply(setIdx = ridx) 5413ea4388cSHaoyuan Feng val vVec_req = getl0vSet(vpn_search) 5423ea4388cSHaoyuan Feng val hVec_req = getl0hSet(vpn_search) 5436c4dcc2dSLemover 5446c4dcc2dSLemover // delay one cycle after sram read 54582978df9Speixiaokun val delay_vpn = stageDelay(0).bits.req_info.vpn 5466f508cb5Speixiaokun val delay_h = MuxLookup(stageDelay(0).bits.req_info.s2xlate, noS2xlate)(Seq( 547980ddf4cSpeixiaokun allStage -> onlyStage1, 548980ddf4cSpeixiaokun onlyStage1 -> onlyStage1, 549980ddf4cSpeixiaokun onlyStage2 -> onlyStage2 550980ddf4cSpeixiaokun )) 5513ea4388cSHaoyuan Feng val data_resp = DataHoldBypass(l0.io.r.resp.data, stageDelay_valid_1cycle) 5527797f035SbugGenerator val vVec_delay = RegEnable(vVec_req, stageReq.fire) 553d0de7e4aSpeixiaokun val hVec_delay = RegEnable(hVec_req, stageReq.fire) 554d0de7e4aSpeixiaokun val hitVec_delay = VecInit(data_resp.zip(vVec_delay.asBools).zip(hVec_delay).map { case ((wayData, v), h) => 55597929664SXiaokun-Pei wayData.entries.hit(delay_vpn, io.csr_dup(0).satp.asid, io.csr_dup(0).vsatp.asid, io.csr_dup(0).hgatp.vmid, s2xlate = delay_h =/= noS2xlate) && v && (delay_h === h)}) 5566c4dcc2dSLemover 5576c4dcc2dSLemover // check hit and ecc 55882978df9Speixiaokun val check_vpn = stageCheck(0).bits.req_info.vpn 5596c4dcc2dSLemover val ramDatas = RegEnable(data_resp, stageDelay(1).fire) 560935edac4STang Haojin val vVec = RegEnable(vVec_delay, stageDelay(1).fire).asBools 5616c4dcc2dSLemover 5627797f035SbugGenerator val hitVec = RegEnable(hitVec_delay, stageDelay(1).fire) 5637196f5a2SLemover val hitWayEntry = ParallelPriorityMux(hitVec zip ramDatas) 5647196f5a2SLemover val hitWayData = hitWayEntry.entries 5657196f5a2SLemover val hitWayEcc = hitWayEntry.ecc 5663ea4388cSHaoyuan Feng val hitWay = ParallelPriorityMux(hitVec zip (0 until l2tlbParams.l0nWays).map(_.U(log2Up(l2tlbParams.l0nWays).W))) 5678882eb68SXin Tian 5688882eb68SXin Tian val ishptw = RegEnable(stageDelay(0).bits.isHptwReq,stageDelay(1).fire) 5698882eb68SXin Tian val s2x_info = RegEnable(stageDelay(0).bits.req_info.s2xlate,stageDelay(1).fire) 5708882eb68SXin Tian val pte_index = RegEnable(stageDelay(0).bits.req_info.vpn(sectortlbwidth - 1, 0),stageDelay(1).fire) 5718882eb68SXin Tian val jmp_bitmap_check = WireInit(false.B) 5728882eb68SXin Tian val hit = WireInit(false.B) 5738882eb68SXin Tian val l0bitmapreg = WireInit((VecInit(Seq.fill(l2tlbParams.l0nWays)(VecInit(Seq.fill(tlbcontiguous)(0.U(1.W))))))) 5748882eb68SXin Tian if (HasBitmapCheck) { 5758882eb68SXin Tian l0bitmapreg := RegEnable(RegNext(l0BitmapReg(ridx)), stageDelay(1).fire) 5768882eb68SXin Tian // cause llptw will trigger bitmapcheck 5778882eb68SXin Tian // add a coniditonal logic 5788882eb68SXin Tian // (s2x_info =/= allStage || ishptw) 5798882eb68SXin Tian hit := Mux(bitmapEnable && (s2x_info =/= allStage || ishptw), ParallelOR(hitVec) && l0bitmapreg(hitWay)(pte_index) === 1.U, ParallelOR(hitVec)) 5808882eb68SXin Tian when (bitmapEnable && (s2x_info =/= allStage || ishptw) && ParallelOR(hitVec) && l0bitmapreg(hitWay)(pte_index) === 0.U) { 5818882eb68SXin Tian jmp_bitmap_check := true.B 5828882eb68SXin Tian } 5838882eb68SXin Tian } else { 5848882eb68SXin Tian hit := ParallelOR(hitVec) 5858882eb68SXin Tian } 586eef81af7SHaoyuan Feng val eccError = WireInit(false.B) 587eef81af7SHaoyuan Feng if (l2tlbParams.enablePTWECC) { 588eef81af7SHaoyuan Feng eccError := hitWayEntry.decode() 589eef81af7SHaoyuan Feng } else { 590eef81af7SHaoyuan Feng eccError := false.B 591eef81af7SHaoyuan Feng } 5926d5ddbceSLemover 5933ea4388cSHaoyuan Feng when (hit && stageCheck_valid_1cycle) { ptwl0replace.access(genPtwL0SetIdx(check_vpn), hitWay) } 5947196f5a2SLemover 5953ea4388cSHaoyuan Feng l0AccessPerf.zip(hitVec).map{ case (l, h) => l := h && stageCheck_valid_1cycle } 5963ea4388cSHaoyuan Feng XSDebug(stageReq.fire, p"[l0] ridx:0x${Hexadecimal(ridx)}\n") 5973ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l0nWays) { 5983ea4388cSHaoyuan Feng XSDebug(stageCheck_valid_1cycle, p"[l0] ramDatas(${i.U}) ${ramDatas(i)} l0v:${vVec(i)} hit:${hitVec(i)}\n") 5996d5ddbceSLemover } 6003ea4388cSHaoyuan Feng XSDebug(stageCheck_valid_1cycle, p"[l0] l0Hit:${hit} l0HitData:${hitWayData} hitVec:${Binary(hitVec.asUInt)} hitWay:${hitWay} v:${vVec}\n") 6016d5ddbceSLemover 6023ea4388cSHaoyuan Feng ridx.suggestName(s"l0_ridx") 6033ea4388cSHaoyuan Feng ramDatas.suggestName(s"l0_ramDatas") 6043ea4388cSHaoyuan Feng hitVec.suggestName(s"l0_hitVec") 6053ea4388cSHaoyuan Feng hitWay.suggestName(s"l0_hitWay") 6066d5ddbceSLemover 6078882eb68SXin Tian (hit, hitWayData, hitWayData.prefetch, eccError, UIntToOH(hitWay), l0bitmapreg(hitWay), jmp_bitmap_check) 6086d5ddbceSLemover } 6093ea4388cSHaoyuan Feng val l0HitPPN = l0HitData.ppns 610002c10a4SYanqin Li val l0HitPbmt = l0HitData.pbmts 6113ea4388cSHaoyuan Feng val l0HitPerm = l0HitData.perms.getOrElse(0.U.asTypeOf(Vec(PtwL0SectorSize, new PtePermBundle))) 612e0c1f271SHaoyuan Feng val l0HitValid = VecInit(l0HitData.onlypf.map(!_)) 6138882eb68SXin Tian val l0Ptes = WireInit(VecInit(Seq.fill(tlbcontiguous)(0.U(XLEN.W)))) // L0 lavel Page Table Entry Vector 6148882eb68SXin Tian val l0cfs = WireInit(VecInit(Seq.fill(tlbcontiguous)(false.B))) // L0 lavel Bitmap Check Failed Vector 6158882eb68SXin Tian if (HasBitmapCheck) { 6168882eb68SXin Tian for (i <- 0 until tlbcontiguous) { 6178882eb68SXin Tian l0Ptes(i) := Cat(l0HitData.pbmts(i).asUInt,l0HitPPN(i), 0.U(2.W),l0HitPerm(i).asUInt,l0HitValid(i).asUInt) 6188882eb68SXin Tian l0cfs(i) := !l0BitmapCheckResult(i) 6198882eb68SXin Tian } 6208882eb68SXin Tian } 6216d5ddbceSLemover 6226d5ddbceSLemover // super page 6235854c1edSLemover val spreplace = ReplacementPolicy.fromString(l2tlbParams.spReplacer, l2tlbParams.spSize) 6248882eb68SXin Tian val (spHit, spHitData, spPre, spValid, spJmpBitmapCheck) = { 625718a93f5SHaoyuan Feng 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.vmid, allType = true, s2xlate = h_search =/= noS2xlate) && spv(i) && (sph(i) === h_search) } 6266c4dcc2dSLemover val hitVec = hitVecT.map(RegEnable(_, stageReq.fire)) 6276d5ddbceSLemover val hitData = ParallelPriorityMux(hitVec zip sp) 6288882eb68SXin Tian val ishptw = RegEnable(stageReq.bits.isHptwReq, stageReq.fire) 6298882eb68SXin Tian val s2x_info = RegEnable(stageReq.bits.req_info.s2xlate, stageReq.fire) 6308882eb68SXin Tian val jmp_bitmap_check = WireInit(false.B) 6318882eb68SXin Tian val hit = WireInit(false.B) 6328882eb68SXin Tian if (HasBitmapCheck) { 6338882eb68SXin Tian hit := Mux(bitmapEnable && (s2x_info =/= allStage || ishptw), ParallelOR(hitVec) && spBitmapReg(OHToUInt(hitVec)) === 1.U, ParallelOR(hitVec)) 6348882eb68SXin Tian when (bitmapEnable && (s2x_info =/= allStage || ishptw) && ParallelOR(hitVec) && spBitmapReg(OHToUInt(hitVec)) === 0.U) { 6358882eb68SXin Tian jmp_bitmap_check := true.B 6368882eb68SXin Tian } 6378882eb68SXin Tian } else { 6388882eb68SXin Tian hit := ParallelOR(hitVec) 6398882eb68SXin Tian } 6406d5ddbceSLemover 6416c4dcc2dSLemover when (hit && stageDelay_valid_1cycle) { spreplace.access(OHToUInt(hitVec)) } 6426d5ddbceSLemover 6436c4dcc2dSLemover spAccessPerf.zip(hitVec).map{ case (s, h) => s := h && stageDelay_valid_1cycle } 6445854c1edSLemover for (i <- 0 until l2tlbParams.spSize) { 64597929664SXiaokun-Pei 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.vmid, s2xlate = h_search =/= noS2xlate)} spv:${spv(i)}\n") 6466d5ddbceSLemover } 6476c4dcc2dSLemover XSDebug(stageDelay_valid_1cycle, p"[sp] spHit:${hit} spHitData:${hitData} hitVec:${Binary(VecInit(hitVec).asUInt)}\n") 6486d5ddbceSLemover 6496d5ddbceSLemover VecInit(hitVecT).suggestName(s"sp_hitVecT") 6506d5ddbceSLemover VecInit(hitVec).suggestName(s"sp_hitVec") 6516d5ddbceSLemover 6526c4dcc2dSLemover (RegEnable(hit, stageDelay(1).fire), 6536c4dcc2dSLemover RegEnable(hitData, stageDelay(1).fire), 6546c4dcc2dSLemover RegEnable(hitData.prefetch, stageDelay(1).fire), 6558882eb68SXin Tian RegEnable(hitData.v, stageDelay(1).fire), 6568882eb68SXin Tian RegEnable(jmp_bitmap_check, stageDelay(1).fire)) 6576d5ddbceSLemover } 6586d5ddbceSLemover val spHitPerm = spHitData.perm.getOrElse(0.U.asTypeOf(new PtePermBundle)) 6596d5ddbceSLemover val spHitLevel = spHitData.level.getOrElse(0.U) 6608882eb68SXin Tian val spPte = Cat(spHitData.pbmt.asUInt,spHitData.ppn, 0.U(2.W), spHitPerm.asUInt,spHitData.v.asUInt) // Super-page Page Table Entry 6616d5ddbceSLemover 6626c4dcc2dSLemover val check_res = Wire(new PageCacheRespBundle) 6637fbc7393SYanqin Li check_res.l3.map(_.apply(l3Hit.get, l3Pre.get, l3HitPPN.get, l3HitPbmt.get)) 664002c10a4SYanqin Li check_res.l2.apply(l2Hit, l2Pre, l2HitPPN, l2HitPbmt) 665002c10a4SYanqin Li check_res.l1.apply(l1Hit, l1Pre, l1HitPPN, l1HitPbmt, ecc = l1eccError) 6668882eb68SXin Tian check_res.l0.apply(l0Hit, l0Pre, l0HitPPN, l0HitPbmt, l0HitPerm, l0eccError, valid = l0HitValid, jmp_bitmap_check = l0JmpBitmapCheck, hitway = l0HitWay, ptes = l0Ptes, cfs = l0cfs) 6678882eb68SXin Tian check_res.sp.apply(spHit, spPre, spHitData.ppn, spHitData.pbmt, spHitData.n.getOrElse(0.U), spHitPerm, false.B, spHitLevel, spValid, spJmpBitmapCheck, spPte) 6686d5ddbceSLemover 6696c4dcc2dSLemover val resp_res = Reg(new PageCacheRespBundle) 6706c4dcc2dSLemover when (stageCheck(1).fire) { resp_res := check_res } 6713889e11eSLemover 6721f4a7c0cSLemover // stageResp bypass 6733ea4388cSHaoyuan Feng val bypassed = if (EnableSv48) Wire(Vec(4, Bool())) else Wire(Vec(3, Bool())) 6741f4a7c0cSLemover bypassed.indices.foreach(i => 6751f4a7c0cSLemover bypassed(i) := stageResp.bits.bypassed(i) || 6766967f5d5Speixiaokun ValidHoldBypass(refill_bypass(stageResp.bits.req_info.vpn, i, stageResp.bits.req_info.s2xlate), 6771f4a7c0cSLemover OneCycleValid(stageCheck(1).fire, false.B) || io.refill.valid) 6781f4a7c0cSLemover ) 6791f4a7c0cSLemover 68083d93d53Speixiaokun // stageResp bypass to hptw 6813ea4388cSHaoyuan Feng val hptw_bypassed = if (EnableSv48) Wire(Vec(4, Bool())) else Wire(Vec(3, Bool())) 68283d93d53Speixiaokun hptw_bypassed.indices.foreach(i => 68383d93d53Speixiaokun hptw_bypassed(i) := stageResp.bits.bypassed(i) || 68483d93d53Speixiaokun ValidHoldBypass(refill_bypass(stageResp.bits.req_info.vpn, i, stageResp.bits.req_info.s2xlate), 68583d93d53Speixiaokun io.resp.fire) 68683d93d53Speixiaokun ) 68783d93d53Speixiaokun 68830104977Speixiaokun val isAllStage = stageResp.bits.req_info.s2xlate === allStage 689c0991f6aSpeixiaokun val isOnlyStage2 = stageResp.bits.req_info.s2xlate === onlyStage2 6903ea4388cSHaoyuan Feng val stage1Hit = (resp_res.l0.hit || resp_res.sp.hit) && isAllStage 691da605600Speixiaokun val idx = stageResp.bits.req_info.vpn(2, 0) 6923ea4388cSHaoyuan Feng val stage1Pf = !Mux(resp_res.l0.hit, resp_res.l0.v(idx), resp_res.sp.v) 6936c4dcc2dSLemover io.resp.bits.req_info := stageResp.bits.req_info 6946c4dcc2dSLemover io.resp.bits.isFirst := stageResp.bits.isFirst 6953ea4388cSHaoyuan Feng io.resp.bits.hit := (resp_res.l0.hit || resp_res.sp.hit) && (!isAllStage || isAllStage && stage1Pf) 6963ea4388cSHaoyuan Feng if (EnableSv48) { 69726175c3fSHaoyuan Feng io.resp.bits.bypassed := ((bypassed(0) && !resp_res.l0.hit) || (bypassed(1) && !resp_res.l1.hit) || (bypassed(2) && !resp_res.l2.hit) || (bypassed(3) && !resp_res.l3.get.hit)) && !isAllStage 6983ea4388cSHaoyuan Feng } else { 69926175c3fSHaoyuan Feng io.resp.bits.bypassed := ((bypassed(0) && !resp_res.l0.hit) || (bypassed(1) && !resp_res.l1.hit) || (bypassed(2) && !resp_res.l2.hit)) && !isAllStage 7003ea4388cSHaoyuan Feng } 7013ea4388cSHaoyuan Feng io.resp.bits.prefetch := resp_res.l0.pre && resp_res.l0.hit || resp_res.sp.pre && resp_res.sp.hit 7023ea4388cSHaoyuan Feng io.resp.bits.toFsm.l3Hit.map(_ := resp_res.l3.get.hit && !stage1Hit && !isOnlyStage2 && !stageResp.bits.isHptwReq) 703325f0a4eSpeixiaokun io.resp.bits.toFsm.l2Hit := resp_res.l2.hit && !stage1Hit && !isOnlyStage2 && !stageResp.bits.isHptwReq 7043ea4388cSHaoyuan Feng io.resp.bits.toFsm.l1Hit := resp_res.l1.hit && !stage1Hit && !isOnlyStage2 && !stageResp.bits.isHptwReq 7053ea4388cSHaoyuan 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)) 706980ddf4cSpeixiaokun io.resp.bits.toFsm.stage1Hit := stage1Hit 7078882eb68SXin Tian if (HasBitmapCheck) { 7088882eb68SXin Tian io.resp.bits.toFsm.bitmapCheck.get.jmp_bitmap_check := resp_res.l0.bitmapCheck.get.jmp_bitmap_check || resp_res.sp.bitmapCheck.get.jmp_bitmap_check 7098882eb68SXin Tian io.resp.bits.toFsm.bitmapCheck.get.toLLPTW := resp_res.l0.bitmapCheck.get.jmp_bitmap_check && (stageResp.bits.req_info.s2xlate === noS2xlate || stageResp.bits.req_info.s2xlate === onlyStage1) 7108882eb68SXin Tian io.resp.bits.toFsm.bitmapCheck.get.hitway := resp_res.l0.bitmapCheck.get.hitway 7118882eb68SXin Tian io.resp.bits.toFsm.bitmapCheck.get.pte := resp_res.sp.bitmapCheck.get.pte 7128882eb68SXin Tian io.resp.bits.toFsm.bitmapCheck.get.ptes := resp_res.l0.bitmapCheck.get.ptes 7138882eb68SXin Tian io.resp.bits.toFsm.bitmapCheck.get.cfs := resp_res.l0.bitmapCheck.get.cfs 7148882eb68SXin Tian io.resp.bits.toFsm.bitmapCheck.get.SPlevel := resp_res.sp.level 7158882eb68SXin Tian } 716d0de7e4aSpeixiaokun 717325f0a4eSpeixiaokun io.resp.bits.isHptwReq := stageResp.bits.isHptwReq 7183ea4388cSHaoyuan Feng if (EnableSv48) { 71926175c3fSHaoyuan Feng io.resp.bits.toHptw.bypassed := ((hptw_bypassed(0) && !resp_res.l0.hit) || (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 7203ea4388cSHaoyuan Feng } else { 72126175c3fSHaoyuan Feng io.resp.bits.toHptw.bypassed := ((hptw_bypassed(0) && !resp_res.l0.hit) || (hptw_bypassed(1) && !resp_res.l1.hit) || (hptw_bypassed(2) && !resp_res.l2.hit)) && stageResp.bits.isHptwReq 7223ea4388cSHaoyuan Feng } 723d0de7e4aSpeixiaokun io.resp.bits.toHptw.id := stageResp.bits.hptwId 7243ea4388cSHaoyuan Feng io.resp.bits.toHptw.l3Hit.map(_ := resp_res.l3.get.hit && stageResp.bits.isHptwReq) 725325f0a4eSpeixiaokun io.resp.bits.toHptw.l2Hit := resp_res.l2.hit && stageResp.bits.isHptwReq 7263ea4388cSHaoyuan Feng io.resp.bits.toHptw.l1Hit := resp_res.l1.hit && stageResp.bits.isHptwReq 7273ea4388cSHaoyuan 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) 72882978df9Speixiaokun io.resp.bits.toHptw.resp.entry.tag := stageResp.bits.req_info.vpn 729eb4bf3f2Speixiaokun io.resp.bits.toHptw.resp.entry.asid := DontCare 73097929664SXiaokun-Pei io.resp.bits.toHptw.resp.entry.vmid.map(_ := io.csr_dup(0).hgatp.vmid) 7313ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.entry.level.map(_ := Mux(resp_res.l0.hit, 0.U, resp_res.sp.level)) 732d0de7e4aSpeixiaokun io.resp.bits.toHptw.resp.entry.prefetch := from_pre(stageResp.bits.req_info.source) 7333ea4388cSHaoyuan 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) 734002c10a4SYanqin Li io.resp.bits.toHptw.resp.entry.pbmt := Mux(resp_res.l0.hit, resp_res.l0.pbmt(idx), resp_res.sp.pbmt) 735718a93f5SHaoyuan Feng io.resp.bits.toHptw.resp.entry.n.map(_ := Mux(resp_res.sp.hit, resp_res.sp.n, 0.U)) 7363ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.entry.perm.map(_ := Mux(resp_res.l0.hit, resp_res.l0.perm(idx), resp_res.sp.perm)) 7373ea4388cSHaoyuan Feng io.resp.bits.toHptw.resp.entry.v := Mux(resp_res.l0.hit, resp_res.l0.v(idx), resp_res.sp.v) 738d0de7e4aSpeixiaokun io.resp.bits.toHptw.resp.gpf := !io.resp.bits.toHptw.resp.entry.v 739e0c1f271SHaoyuan Feng io.resp.bits.toHptw.resp.gaf := false.B 7408882eb68SXin Tian if (HasBitmapCheck) { 7418882eb68SXin Tian io.resp.bits.toHptw.bitmapCheck.get.jmp_bitmap_check := resp_res.l0.bitmapCheck.get.jmp_bitmap_check || resp_res.sp.bitmapCheck.get.jmp_bitmap_check 7428882eb68SXin Tian io.resp.bits.toHptw.bitmapCheck.get.hitway := resp_res.l0.bitmapCheck.get.hitway 7438882eb68SXin Tian io.resp.bits.toHptw.bitmapCheck.get.pte := resp_res.sp.bitmapCheck.get.pte 7448882eb68SXin Tian io.resp.bits.toHptw.bitmapCheck.get.ptes := resp_res.l0.bitmapCheck.get.ptes 7458882eb68SXin Tian io.resp.bits.toHptw.bitmapCheck.get.cfs := resp_res.l0.bitmapCheck.get.cfs 7468882eb68SXin Tian io.resp.bits.toHptw.bitmapCheck.get.fromSP := resp_res.sp.bitmapCheck.get.jmp_bitmap_check 7478882eb68SXin Tian io.resp.bits.toHptw.bitmapCheck.get.SPlevel := resp_res.sp.level 7488882eb68SXin Tian } 749d0de7e4aSpeixiaokun 7506979864eSXiaokun-Pei io.resp.bits.stage1.entry.map(_.tag := stageResp.bits.req_info.vpn(vpnLen - 1, 3)) 7516979864eSXiaokun-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 75297929664SXiaokun-Pei io.resp.bits.stage1.entry.map(_.vmid.map(_ := io.csr_dup(0).hgatp.vmid)) 7533ea4388cSHaoyuan Feng if (EnableSv48) { 7543ea4388cSHaoyuan Feng io.resp.bits.stage1.entry.map(_.level.map(_ := Mux(resp_res.l0.hit, 0.U, 7553ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.level, 7563ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, 1.U, 7573ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, 2.U, 3.U)))))) 7583ea4388cSHaoyuan Feng } else { 7593ea4388cSHaoyuan Feng io.resp.bits.stage1.entry.map(_.level.map(_ := Mux(resp_res.l0.hit, 0.U, 7603ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.level, 7613ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, 1.U, 2.U))))) 7623ea4388cSHaoyuan Feng } 7636979864eSXiaokun-Pei io.resp.bits.stage1.entry.map(_.prefetch := from_pre(stageResp.bits.req_info.source)) 76463632028SHaoyuan Feng for (i <- 0 until tlbcontiguous) { 7653ea4388cSHaoyuan Feng if (EnableSv48) { 7663ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(gvpnLen - 1, sectortlbwidth), 7673ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(gvpnLen - 1, sectortlbwidth), 7683ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(gvpnLen - 1, sectortlbwidth), 7693ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, resp_res.l2.ppn(gvpnLen - 1, sectortlbwidth), 7703ea4388cSHaoyuan Feng resp_res.l3.get.ppn(gvpnLen - 1, sectortlbwidth))))) 7713ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn_low := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(sectortlbwidth - 1, 0), 7723ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(sectortlbwidth - 1, 0), 7733ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(sectortlbwidth - 1, 0), 7743ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, resp_res.l2.ppn(sectortlbwidth - 1, 0), 7753ea4388cSHaoyuan Feng resp_res.l3.get.ppn(sectortlbwidth - 1, 0))))) 7763ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).v := Mux(resp_res.l0.hit, resp_res.l0.v(i), 7773ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.v, 7783ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.v, 7793ea4388cSHaoyuan Feng Mux(resp_res.l2.hit, resp_res.l2.v, 7803ea4388cSHaoyuan Feng resp_res.l3.get.v)))) 7813ea4388cSHaoyuan Feng } else { 7823ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(gvpnLen - 1, sectortlbwidth), 7833ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(gvpnLen - 1, sectortlbwidth), 7843ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(gvpnLen - 1, sectortlbwidth), 7853ea4388cSHaoyuan Feng resp_res.l2.ppn(gvpnLen - 1, sectortlbwidth)))) 7863ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).ppn_low := Mux(resp_res.l0.hit, resp_res.l0.ppn(i)(sectortlbwidth - 1, 0), 7873ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.ppn(sectortlbwidth - 1, 0), 7883ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.ppn(sectortlbwidth - 1, 0), 7893ea4388cSHaoyuan Feng resp_res.l2.ppn(sectortlbwidth - 1, 0)))) 7903ea4388cSHaoyuan Feng io.resp.bits.stage1.entry(i).v := Mux(resp_res.l0.hit, resp_res.l0.v(i), 7913ea4388cSHaoyuan Feng Mux(resp_res.sp.hit, resp_res.sp.v, 7923ea4388cSHaoyuan Feng Mux(resp_res.l1.hit, resp_res.l1.v, 7933ea4388cSHaoyuan Feng resp_res.l2.v))) 7943ea4388cSHaoyuan Feng } 795002c10a4SYanqin Li io.resp.bits.stage1.entry(i).pbmt := Mux(resp_res.l0.hit, resp_res.l0.pbmt(i), 796002c10a4SYanqin Li Mux(resp_res.sp.hit, resp_res.sp.pbmt, 797002c10a4SYanqin Li Mux(resp_res.l1.hit, resp_res.l1.pbmt, 798002c10a4SYanqin Li resp_res.l2.pbmt))) 799718a93f5SHaoyuan Feng io.resp.bits.stage1.entry(i).n.map(_ := Mux(resp_res.sp.hit, resp_res.sp.n, 0.U)) 80097929664SXiaokun-Pei io.resp.bits.stage1.entry(i).perm.map(_ := Mux(resp_res.l0.hit, resp_res.l0.perm(i), Mux(resp_res.sp.hit, resp_res.sp.perm, 0.U.asTypeOf(new PtePermBundle)))) 8016979864eSXiaokun-Pei io.resp.bits.stage1.entry(i).pf := !io.resp.bits.stage1.entry(i).v 802e0c1f271SHaoyuan Feng io.resp.bits.stage1.entry(i).af := false.B 8038882eb68SXin Tian io.resp.bits.stage1.entry(i).cf := l0cfs(i) // L0 lavel Bitmap Check Failed Vector 80463632028SHaoyuan Feng } 805da605600Speixiaokun io.resp.bits.stage1.pteidx := UIntToOH(idx).asBools 8063ea4388cSHaoyuan Feng io.resp.bits.stage1.not_super := Mux(resp_res.l0.hit, true.B, false.B) 8076962b4ffSHaoyuan Feng io.resp.bits.stage1.not_merge := false.B 8086c4dcc2dSLemover io.resp.valid := stageResp.valid 8093ea4388cSHaoyuan Feng XSError(stageResp.valid && resp_res.l0.hit && resp_res.sp.hit, "normal page and super page both hit") 8106d5ddbceSLemover 8116d5ddbceSLemover // refill Perf 8123ea4388cSHaoyuan Feng val l3RefillPerf = if (EnableSv48) Some(Wire(Vec(l2tlbParams.l3Size, Bool()))) else None 8133ea4388cSHaoyuan Feng val l2RefillPerf = Wire(Vec(l2tlbParams.l2Size, Bool())) 8143ea4388cSHaoyuan Feng val l1RefillPerf = Wire(Vec(l2tlbParams.l1nWays, Bool())) 8153ea4388cSHaoyuan Feng val l0RefillPerf = Wire(Vec(l2tlbParams.l0nWays, Bool())) 8165854c1edSLemover val spRefillPerf = Wire(Vec(l2tlbParams.spSize, Bool())) 8173ea4388cSHaoyuan Feng l3RefillPerf.map(_.map(_ := false.B)) 8186d5ddbceSLemover l2RefillPerf.map(_ := false.B) 8193ea4388cSHaoyuan Feng l1RefillPerf.map(_ := false.B) 8203ea4388cSHaoyuan Feng l0RefillPerf.map(_ := false.B) 8216d5ddbceSLemover spRefillPerf.map(_ := false.B) 8226d5ddbceSLemover 8236d5ddbceSLemover // refill 8243ea4388cSHaoyuan Feng l1.io.w.req <> DontCare 8253ea4388cSHaoyuan Feng l0.io.w.req <> DontCare 8263ea4388cSHaoyuan Feng l1.io.w.req.valid := false.B 8273ea4388cSHaoyuan Feng l0.io.w.req.valid := false.B 8286d5ddbceSLemover 8296d5ddbceSLemover val memRdata = refill.ptes 8305854c1edSLemover val memPtes = (0 until (l2tlbParams.blockBytes/(XLEN/8))).map(i => memRdata((i+1)*XLEN-1, i*XLEN).asTypeOf(new PteBundle)) 8317797f035SbugGenerator val memSelData = io.refill.bits.sel_pte_dup 8327797f035SbugGenerator val memPte = memSelData.map(a => a.asTypeOf(new PteBundle)) 833dd286b6aSYanqin Li val mPBMTE = io.csr.mPBMTE 834dd286b6aSYanqin Li val hPBMTE = io.csr.hPBMTE 835dd286b6aSYanqin Li val pbmte = Mux(refill.req_info_dup(0).s2xlate === onlyStage1 || refill.req_info_dup(0).s2xlate === allStage, hPBMTE, mPBMTE) 836b848eea5SLemover 8378882eb68SXin Tian def Tran2D(flushMask: UInt): Vec[UInt] = { 8388882eb68SXin Tian val tran2D = Wire(Vec(l2tlbParams.l0nSets,UInt(l2tlbParams.l0nWays.W))) 8398882eb68SXin Tian for (i <- 0 until l2tlbParams.l0nSets) { 8408882eb68SXin Tian tran2D(i) := flushMask((i + 1) * l2tlbParams.l0nWays - 1, i * l2tlbParams.l0nWays) 8418882eb68SXin Tian } 8428882eb68SXin Tian tran2D 8438882eb68SXin Tian } 8448882eb68SXin Tian def updateL0BitmapReg(l0BitmapReg: Vec[Vec[Vec[UInt]]], tran2D: Vec[UInt]) = { 8458882eb68SXin Tian for (i <- 0 until l2tlbParams.l0nSets) { 8468882eb68SXin Tian for (j <- 0 until l2tlbParams.l0nWays) { 8478882eb68SXin Tian when (tran2D(i)(j) === 0.U) { 8488882eb68SXin Tian for (k <- 0 until tlbcontiguous) { 8498882eb68SXin Tian l0BitmapReg(i)(j)(k) := 0.U 8508882eb68SXin Tian } 8518882eb68SXin Tian } 8528882eb68SXin Tian } 8538882eb68SXin Tian } 8548882eb68SXin Tian } 8558882eb68SXin Tian def TranVec(flushMask: UInt): Vec[UInt] = { 8568882eb68SXin Tian val vec = Wire(Vec(l2tlbParams.spSize,UInt(1.W))) 8578882eb68SXin Tian for (i <- 0 until l2tlbParams.spSize) { 8588882eb68SXin Tian vec(i) := flushMask(i) 8598882eb68SXin Tian } 8608882eb68SXin Tian vec 8618882eb68SXin Tian } 8628882eb68SXin Tian def updateSpBitmapReg(spBitmapReg: Vec[UInt], vec : Vec[UInt]) = { 8638882eb68SXin Tian for (i <- 0 until l2tlbParams.spSize) { 8648882eb68SXin Tian spBitmapReg(i) := spBitmapReg(i) & vec(i) 8658882eb68SXin Tian } 8668882eb68SXin Tian } 8678882eb68SXin Tian 8686d5ddbceSLemover // TODO: handle sfenceLatch outsize 8693ea4388cSHaoyuan Feng if (EnableSv48) { 8708b33cd30Sklin02 val l3Refill = 8716962b4ffSHaoyuan Feng !flush_dup(2) && 8726962b4ffSHaoyuan Feng refill.levelOH.l3.get && 8736962b4ffSHaoyuan Feng !memPte(2).isLeaf() && 874fc4ea7c0SHaoyuan Feng memPte(2).canRefill(refill.level_dup(2), refill.req_info_dup(2).s2xlate, pbmte, io.csr_dup(2).hgatp.mode) 8758b33cd30Sklin02 val l3RefillIdx = replaceWrapper(l3v.get, ptwl3replace.get.way).suggestName(s"l3_refillIdx") 8768b33cd30Sklin02 val l3RfOH = UIntToOH(l3RefillIdx).asUInt.suggestName(s"l3_rfOH") 8778b33cd30Sklin02 when (l3Refill) { 8788b33cd30Sklin02 l3.get(l3RefillIdx).refill( 8793ea4388cSHaoyuan Feng refill.req_info_dup(2).vpn, 8803ea4388cSHaoyuan Feng Mux(refill.req_info_dup(2).s2xlate =/= noS2xlate, io.csr_dup(2).vsatp.asid, io.csr_dup(2).satp.asid), 88197929664SXiaokun-Pei io.csr_dup(2).hgatp.vmid, 8823ea4388cSHaoyuan Feng memSelData(2), 8833ea4388cSHaoyuan Feng 3.U, 8843ea4388cSHaoyuan Feng refill_prefetch_dup(2) 88545f497a4Shappy-lx ) 8868b33cd30Sklin02 ptwl2replace.access(l3RefillIdx) 8878b33cd30Sklin02 l3v.get := l3v.get | l3RfOH 8888b33cd30Sklin02 l3g.get := (l3g.get & ~l3RfOH) | Mux(memPte(2).perm.g, l3RfOH, 0.U) 8898b33cd30Sklin02 l3h.get(l3RefillIdx) := refill_h(2) 8906d5ddbceSLemover 8913ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l3Size) { 8928b33cd30Sklin02 l3RefillPerf.get(i) := i.U === l3RefillIdx 8936d5ddbceSLemover } 8943ea4388cSHaoyuan Feng } 8958b33cd30Sklin02 XSDebug(l3Refill, p"[l3 refill] refillIdx:${l3RefillIdx} refillEntry:${l3.get(l3RefillIdx).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") 8968b33cd30Sklin02 XSDebug(l3Refill, p"[l3 refill] l3v:${Binary(l3v.get)}->${Binary(l3v.get | l3RfOH)} l3g:${Binary(l3g.get)}->${Binary((l3g.get & ~l3RfOH) | Mux(memPte(2).perm.g, l3RfOH, 0.U))}\n") 8976d5ddbceSLemover } 8986d5ddbceSLemover 8996962b4ffSHaoyuan Feng // L2 refill 9008b33cd30Sklin02 val l2Refill = 9016962b4ffSHaoyuan Feng !flush_dup(2) && 9026962b4ffSHaoyuan Feng refill.levelOH.l2 && 9036962b4ffSHaoyuan Feng !memPte(2).isLeaf() && 904fc4ea7c0SHaoyuan Feng memPte(2).canRefill(refill.level_dup(2), refill.req_info_dup(2).s2xlate, pbmte, io.csr_dup(2).hgatp.mode) 9058b33cd30Sklin02 val l2RefillIdx = replaceWrapper(l2v, ptwl2replace.way).suggestName(s"l2_refillIdx") 9068b33cd30Sklin02 val l2RfOH = UIntToOH(l2RefillIdx).asUInt.suggestName(s"l2_rfOH") 9078b33cd30Sklin02 when ( 9088b33cd30Sklin02 l2Refill 909dd286b6aSYanqin Li ) { 9108b33cd30Sklin02 l2(l2RefillIdx).refill( 9113ea4388cSHaoyuan Feng refill.req_info_dup(2).vpn, 9123ea4388cSHaoyuan Feng Mux(refill.req_info_dup(2).s2xlate =/= noS2xlate, io.csr_dup(2).vsatp.asid, io.csr_dup(2).satp.asid), 91397929664SXiaokun-Pei io.csr_dup(2).hgatp.vmid, 9143ea4388cSHaoyuan Feng memSelData(2), 9153ea4388cSHaoyuan Feng 2.U, 9163ea4388cSHaoyuan Feng refill_prefetch_dup(2) 9173ea4388cSHaoyuan Feng ) 9188b33cd30Sklin02 ptwl2replace.access(l2RefillIdx) 9198b33cd30Sklin02 l2v := l2v | l2RfOH 9208b33cd30Sklin02 l2g := (l2g & ~l2RfOH) | Mux(memPte(2).perm.g, l2RfOH, 0.U) 9218b33cd30Sklin02 l2h(l2RefillIdx) := refill_h(2) 9223ea4388cSHaoyuan Feng 9233ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l2Size) { 9248b33cd30Sklin02 l2RefillPerf(i) := i.U === l2RefillIdx 9253ea4388cSHaoyuan Feng } 9263ea4388cSHaoyuan Feng } 9278b33cd30Sklin02 XSDebug(l2Refill, p"[l2 refill] refillIdx:${l2RefillIdx} refillEntry:${l2(l2RefillIdx).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") 9288b33cd30Sklin02 XSDebug(l2Refill, p"[l2 refill] l2v:${Binary(l2v)}->${Binary(l2v | l2RfOH)} l2g:${Binary(l2g)}->${Binary((l2g & ~l2RfOH) | Mux(memPte(2).perm.g, l2RfOH, 0.U))}\n") 9293ea4388cSHaoyuan Feng 9306962b4ffSHaoyuan Feng // L1 refill 9318b33cd30Sklin02 val l1Refill = !flush_dup(1) && refill.levelOH.l1 9328b33cd30Sklin02 val l1RefillIdx = genPtwL1SetIdx(refill.req_info_dup(1).vpn).suggestName(s"l1_refillIdx") 9338b33cd30Sklin02 val l1VictimWay = replaceWrapper(getl1vSet(refill.req_info_dup(1).vpn), ptwl1replace.way(l1RefillIdx)).suggestName(s"l1_victimWay") 9348b33cd30Sklin02 val l1VictimWayOH = UIntToOH(l1VictimWay).suggestName(s"l1_victimWayOH") 9358b33cd30Sklin02 val l1RfvOH = UIntToOH(Cat(l1RefillIdx, l1VictimWay)).asUInt.suggestName(s"l1_rfvOH") 9368b33cd30Sklin02 val l1Wdata = Wire(l1EntryType) 937f9395f72SHaoyuan Feng val l1Wvpn = refill.req_info_dup(1).vpn 938f9395f72SHaoyuan Feng val l1Wasid = Mux(refill.req_info_dup(1).s2xlate =/= noS2xlate, io.csr_dup(1).vsatp.asid, io.csr_dup(1).satp.asid) 9398b33cd30Sklin02 l1Wdata.gen( 940f9395f72SHaoyuan Feng vpn = l1Wvpn, 941f9395f72SHaoyuan Feng asid = l1Wasid, 94297929664SXiaokun-Pei vmid = io.csr_dup(1).hgatp.vmid, 94345f497a4Shappy-lx data = memRdata, 94445f497a4Shappy-lx levelUInt = 1.U, 9454ed5afbdSXiaokun-Pei refill_prefetch_dup(1), 946dd286b6aSYanqin Li refill.req_info_dup(1).s2xlate, 947e0c1f271SHaoyuan Feng pbmte, 948fc4ea7c0SHaoyuan Feng io.csr_dup(1).hgatp.mode 94945f497a4Shappy-lx ) 9508b33cd30Sklin02 when (l1Refill) { 9513ea4388cSHaoyuan Feng l1.io.w.apply( 9526d5ddbceSLemover valid = true.B, 9538b33cd30Sklin02 setIdx = l1RefillIdx, 9548b33cd30Sklin02 data = l1Wdata, 9558b33cd30Sklin02 waymask = l1VictimWayOH 9566d5ddbceSLemover ) 9578b33cd30Sklin02 ptwl1replace.access(l1RefillIdx, l1VictimWay) 9588b33cd30Sklin02 l1v := l1v | l1RfvOH 9598b33cd30Sklin02 l1g := l1g & ~l1RfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, l1RfvOH, 0.U) 9608b33cd30Sklin02 l1h(l1RefillIdx)(l1VictimWay) := refill_h(1) 961f9395f72SHaoyuan Feng l1asids(l1RefillIdx)(l1VictimWay) := XORFold(l1Wasid, l2tlbParams.hashAsidWidth) 962f9395f72SHaoyuan Feng l1vmids(l1RefillIdx)(l1VictimWay) := XORFold(io.csr_dup(1).hgatp.vmid, l2tlbParams.hashAsidWidth) 9636d5ddbceSLemover 9643ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l1nWays) { 9658b33cd30Sklin02 l1RefillPerf(i) := i.U === l1VictimWay 9666d5ddbceSLemover } 9676d5ddbceSLemover } 9688b33cd30Sklin02 XSDebug(l1Refill, p"[l1 refill] refillIdx:0x${Hexadecimal(l1RefillIdx)} victimWay:${l1VictimWay} victimWayOH:${Binary(l1VictimWayOH)} rfvOH(in UInt):${Cat(l1RefillIdx, l1VictimWay)}\n") 9698b33cd30Sklin02 XSDebug(l1Refill, p"[l1 refill] refilldata:0x${l1Wdata}\n") 9708b33cd30Sklin02 XSDebug(l1Refill, p"[l1 refill] l1v:${Binary(l1v)} -> ${Binary(l1v | l1RfvOH)}\n") 9718b33cd30Sklin02 XSDebug(l1Refill, p"[l1 refill] l1g:${Binary(l1g)} -> ${Binary(l1g & ~l1RfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, l1RfvOH, 0.U))}\n") 9726d5ddbceSLemover 9736962b4ffSHaoyuan Feng // L0 refill 974718a93f5SHaoyuan Feng val l0Refill = !flush_dup(0) && refill.levelOH.l0 && !memPte(0).isNapot(refill.level_dup(0)) 9758b33cd30Sklin02 val l0RefillIdx = genPtwL0SetIdx(refill.req_info_dup(0).vpn).suggestName(s"l0_refillIdx") 9768b33cd30Sklin02 val l0VictimWay = replaceWrapper(getl0vSet(refill.req_info_dup(0).vpn), ptwl0replace.way(l0RefillIdx)).suggestName(s"l0_victimWay") 9778b33cd30Sklin02 val l0VictimWayOH = UIntToOH(l0VictimWay).asUInt.suggestName(s"l0_victimWayOH") 9788b33cd30Sklin02 val l0RfvOH = UIntToOH(Cat(l0RefillIdx, l0VictimWay)).suggestName(s"l0_rfvOH") 9798b33cd30Sklin02 val l0Wdata = Wire(l0EntryType) 9808882eb68SXin Tian // trans the l0 way info, for late wakeup logic 9818882eb68SXin Tian if (HasBitmapCheck) { 9828882eb68SXin Tian io.l0_way_info.get := l0VictimWayOH 9838882eb68SXin Tian } 984f9395f72SHaoyuan Feng val l0Wvpn = refill.req_info_dup(0).vpn 985f9395f72SHaoyuan Feng val l0Wasid = Mux(refill.req_info_dup(0).s2xlate =/= noS2xlate, io.csr_dup(0).vsatp.asid, io.csr_dup(0).satp.asid) 9868b33cd30Sklin02 l0Wdata.gen( 987f9395f72SHaoyuan Feng vpn = l0Wvpn, 988f9395f72SHaoyuan Feng asid = l0Wasid, 98997929664SXiaokun-Pei vmid = io.csr_dup(0).hgatp.vmid, 99045f497a4Shappy-lx data = memRdata, 9913ea4388cSHaoyuan Feng levelUInt = 0.U, 9923ea4388cSHaoyuan Feng refill_prefetch_dup(0), 993dd286b6aSYanqin Li refill.req_info_dup(0).s2xlate, 994e0c1f271SHaoyuan Feng pbmte, 995fc4ea7c0SHaoyuan Feng io.csr_dup(0).hgatp.mode 99645f497a4Shappy-lx ) 9978b33cd30Sklin02 when (l0Refill) { 9983ea4388cSHaoyuan Feng l0.io.w.apply( 9996d5ddbceSLemover valid = true.B, 10008b33cd30Sklin02 setIdx = l0RefillIdx, 10018b33cd30Sklin02 data = l0Wdata, 10028b33cd30Sklin02 waymask = l0VictimWayOH 10036d5ddbceSLemover ) 10048b33cd30Sklin02 ptwl0replace.access(l0RefillIdx, l0VictimWay) 10058b33cd30Sklin02 l0v := l0v | l0RfvOH 10068b33cd30Sklin02 l0g := l0g & ~l0RfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, l0RfvOH, 0.U) 10078b33cd30Sklin02 l0h(l0RefillIdx)(l0VictimWay) := refill_h(0) 10088882eb68SXin Tian if (HasBitmapCheck) {updateL0BitmapReg(l0BitmapReg, Tran2D(~l0RfvOH))} 1009f9395f72SHaoyuan Feng l0asids(l0RefillIdx)(l0VictimWay) := XORFold(l0Wasid, l2tlbParams.hashAsidWidth) 1010f9395f72SHaoyuan Feng l0vmids(l0RefillIdx)(l0VictimWay) := XORFold(io.csr_dup(0).hgatp.vmid, l2tlbParams.hashAsidWidth) 1011f9395f72SHaoyuan Feng l0vpns(l0RefillIdx)(l0VictimWay) := XORFold(l0Wvpn(vpnLen - 1, vpnLen - PtwL0TagLen), l2tlbParams.hashVpnWidth) 10126d5ddbceSLemover 10133ea4388cSHaoyuan Feng for (i <- 0 until l2tlbParams.l0nWays) { 10148b33cd30Sklin02 l0RefillPerf(i) := i.U === l0VictimWay 10156d5ddbceSLemover } 10166d5ddbceSLemover } 10178b33cd30Sklin02 XSDebug(l0Refill, p"[l0 refill] refillIdx:0x${Hexadecimal(l0RefillIdx)} victimWay:${l0VictimWay} victimWayOH:${Binary(l0VictimWayOH)} rfvOH(in UInt):${Cat(l0RefillIdx, l0VictimWay)}\n") 10188b33cd30Sklin02 XSDebug(l0Refill, p"[l0 refill] refilldata:0x${l0Wdata}\n") 10198b33cd30Sklin02 XSDebug(l0Refill, p"[l0 refill] l0v:${Binary(l0v)} -> ${Binary(l0v | l0RfvOH)}\n") 10208b33cd30Sklin02 XSDebug(l0Refill, p"[l0 refill] l0g:${Binary(l0g)} -> ${Binary(l0g & ~l0RfvOH | Mux(Cat(memPtes.map(_.perm.g)).andR, l0RfvOH, 0.U))}\n") 10217797f035SbugGenerator 10228d8ac704SLemover 10238d8ac704SLemover // misc entries: super & invalid 10248b33cd30Sklin02 val spRefill = 10256962b4ffSHaoyuan Feng !flush_dup(0) && 10260a56a7dcSHaoyuan Feng (refill.levelOH.sp || (refill.levelOH.l0 && memPte(0).isNapot(refill.level_dup(0)))) && 1027fc4ea7c0SHaoyuan Feng ((memPte(0).isLeaf() && memPte(0).canRefill(refill.level_dup(0), refill.req_info_dup(0).s2xlate, pbmte, io.csr_dup(0).hgatp.mode)) || 1028e0c1f271SHaoyuan Feng memPte(0).onlyPf(refill.level_dup(0), refill.req_info_dup(0).s2xlate, pbmte)) 10298b33cd30Sklin02 val spRefillIdx = spreplace.way.suggestName(s"sp_refillIdx") // LFSR64()(log2Up(l2tlbParams.spSize)-1,0) // TODO: may be LRU 10308b33cd30Sklin02 val spRfOH = UIntToOH(spRefillIdx).asUInt.suggestName(s"sp_rfOH") 10318b33cd30Sklin02 when (spRefill) { 10328b33cd30Sklin02 sp(spRefillIdx).refill( 10337797f035SbugGenerator refill.req_info_dup(0).vpn, 1034b188e334Speixiaokun Mux(refill.req_info_dup(0).s2xlate =/= noS2xlate, io.csr_dup(0).vsatp.asid, io.csr_dup(0).satp.asid), 103597929664SXiaokun-Pei io.csr_dup(0).hgatp.vmid, 10367797f035SbugGenerator memSelData(0), 10373ea4388cSHaoyuan Feng refill.level_dup(0), 10387797f035SbugGenerator refill_prefetch_dup(0), 1039e0c1f271SHaoyuan Feng !memPte(0).onlyPf(refill.level_dup(0), refill.req_info_dup(0).s2xlate, pbmte) 104045f497a4Shappy-lx ) 10418b33cd30Sklin02 spreplace.access(spRefillIdx) 10428b33cd30Sklin02 spv := spv | spRfOH 10438b33cd30Sklin02 spg := spg & ~spRfOH | Mux(memPte(0).perm.g, spRfOH, 0.U) 10448b33cd30Sklin02 sph(spRefillIdx) := refill_h(0) 10458882eb68SXin Tian if (HasBitmapCheck) {updateSpBitmapReg(spBitmapReg, TranVec(~spRfOH))} 10466d5ddbceSLemover 10475854c1edSLemover for (i <- 0 until l2tlbParams.spSize) { 10488b33cd30Sklin02 spRefillPerf(i) := i.U === spRefillIdx 10496d5ddbceSLemover } 10506d5ddbceSLemover } 10518b33cd30Sklin02 XSDebug(spRefill, p"[sp refill] refillIdx:${spRefillIdx} refillEntry:${sp(spRefillIdx).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") 10528b33cd30Sklin02 XSDebug(spRefill, p"[sp refill] spv:${Binary(spv)}->${Binary(spv | spRfOH)} spg:${Binary(spg)}->${Binary(spg & ~spRfOH | Mux(memPte(0).perm.g, spRfOH, 0.U))}\n") 10536d5ddbceSLemover 10543ea4388cSHaoyuan Feng val l1eccFlush = resp_res.l1.ecc && stageResp_valid_1cycle_dup(0) // RegNext(l1eccError, init = false.B) 10553ea4388cSHaoyuan Feng val l0eccFlush = resp_res.l0.ecc && stageResp_valid_1cycle_dup(1) // RegNext(l0eccError, init = false.B) 10566c4dcc2dSLemover val eccVpn = stageResp.bits.req_info.vpn 10577196f5a2SLemover 10583ea4388cSHaoyuan Feng XSError(l1eccFlush, "l2tlb.cache.l1 ecc error. Should not happen at sim stage") 10593ea4388cSHaoyuan Feng XSError(l0eccFlush, "l2tlb.cache.l0 ecc error. Should not happen at sim stage") 10603ea4388cSHaoyuan Feng when (l1eccFlush) { 10613ea4388cSHaoyuan Feng val flushSetIdxOH = UIntToOH(genPtwL1SetIdx(eccVpn)) 10623ea4388cSHaoyuan Feng val flushMask = VecInit(flushSetIdxOH.asBools.map { a => Fill(l2tlbParams.l1nWays, a.asUInt) }).asUInt 10633ea4388cSHaoyuan Feng l1v := l1v & ~flushMask 10643ea4388cSHaoyuan Feng l1g := l1g & ~flushMask 10657196f5a2SLemover } 10667196f5a2SLemover 10673ea4388cSHaoyuan Feng when (l0eccFlush) { 10683ea4388cSHaoyuan Feng val flushSetIdxOH = UIntToOH(genPtwL0SetIdx(eccVpn)) 10693ea4388cSHaoyuan Feng val flushMask = VecInit(flushSetIdxOH.asBools.map { a => Fill(l2tlbParams.l0nWays, a.asUInt) }).asUInt 10703ea4388cSHaoyuan Feng l0v := l0v & ~flushMask 10713ea4388cSHaoyuan Feng l0g := l0g & ~flushMask 10727196f5a2SLemover } 10737196f5a2SLemover 1074f9395f72SHaoyuan Feng // sfence logic 1075f9395f72SHaoyuan Feng val l0hashAsid = XORFold(sfence_dup(0).bits.id, l2tlbParams.hashAsidWidth) 1076f9395f72SHaoyuan Feng val l1hashAsid = XORFold(sfence_dup(1).bits.id, l2tlbParams.hashAsidWidth) 1077f9395f72SHaoyuan Feng val l0asidhit = VecInit(l0asids.flatMap(_.map(_ === l0hashAsid))).asUInt 1078f9395f72SHaoyuan Feng val l1asidhit = VecInit(l1asids.flatMap(_.map(_ === l1hashAsid))).asUInt 10793ea4388cSHaoyuan Feng val l2asidhit = VecInit(l2asids.map(_ === sfence_dup(2).bits.id)).asUInt 1080d0de7e4aSpeixiaokun val spasidhit = VecInit(spasids.map(_ === sfence_dup(0).bits.id)).asUInt 1081f9395f72SHaoyuan Feng 1082d0de7e4aSpeixiaokun val sfence_valid = sfence_dup(0).valid && !sfence_dup(0).bits.hg && !sfence_dup(0).bits.hv 1083d0de7e4aSpeixiaokun when (sfence_valid) { 1084f9395f72SHaoyuan Feng val l0hashVmid = XORFold(io.csr_dup(0).hgatp.vmid, l2tlbParams.hashAsidWidth) 1085f9395f72SHaoyuan Feng val l1hashVmid = XORFold(io.csr_dup(1).hgatp.vmid, l2tlbParams.hashAsidWidth) 1086f9395f72SHaoyuan Feng val l0vmidhit = VecInit(l0vmids.flatMap(_.map(_ === l0hashVmid))).asUInt 1087f9395f72SHaoyuan Feng val l1vmidhit = VecInit(l1vmids.flatMap(_.map(_ === l1hashVmid))).asUInt 108897929664SXiaokun-Pei val l2vmidhit = VecInit(l2vmids.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.vmid)).asUInt 108997929664SXiaokun-Pei val spvmidhit = VecInit(spvmids.map(_.getOrElse(0.U) === io.csr_dup(0).hgatp.vmid)).asUInt 1090f9395f72SHaoyuan Feng 1091f9395f72SHaoyuan 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 1092f9395f72SHaoyuan 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 10933ea4388cSHaoyuan Feng val l2hhit = VecInit(l2h.map{a => io.csr_dup(2).priv.virt && a === onlyStage1 || !io.csr_dup(2).priv.virt && a === noS2xlate}).asUInt 1094e5da58f0Speixiaokun val sphhit = VecInit(sph.map{a => io.csr_dup(0).priv.virt && a === onlyStage1 || !io.csr_dup(0).priv.virt && a === noS2xlate}).asUInt 1095f9395f72SHaoyuan Feng val l0virthit = l0hhit & VecInit(l0vmidhit.asBools.map{a => io.csr_dup(0).priv.virt && a || !io.csr_dup(0).priv.virt}).asUInt 1096f9395f72SHaoyuan Feng val l1virthit = l1hhit & VecInit(l1vmidhit.asBools.map{a => io.csr_dup(1).priv.virt && a || !io.csr_dup(1).priv.virt}).asUInt 1097f9395f72SHaoyuan Feng val l2virthit = l2hhit & VecInit(l2vmidhit.asBools.map{a => io.csr_dup(2).priv.virt && a || !io.csr_dup(2).priv.virt}).asUInt 1098f9395f72SHaoyuan Feng val spvirthit = sphhit & VecInit(spvmidhit.asBools.map{a => io.csr_dup(0).priv.virt && a || !io.csr_dup(0).priv.virt}).asUInt 1099f9395f72SHaoyuan Feng 11007797f035SbugGenerator val sfence_vpn = sfence_dup(0).bits.addr(sfence_dup(0).bits.addr.getWidth-1, offLen) 1101f9395f72SHaoyuan Feng val l0hashVpn = XORFold(sfence_vpn(vpnLen - 1, vpnLen - PtwL0TagLen), l2tlbParams.hashVpnWidth) 1102f9395f72SHaoyuan Feng val l0vpnhit = VecInit(l0vpns.flatMap(_.map(_ === l0hashVpn))).asUInt 1103f9395f72SHaoyuan Feng val l0flushSetIdx = UIntToOH(genPtwL0SetIdx(sfence_vpn)) 1104f9395f72SHaoyuan Feng val l0flushMask = VecInit(l0flushSetIdx.asBools.map{a => Fill(l2tlbParams.l0nWays, a.asUInt)}).asUInt 11057797f035SbugGenerator 11067797f035SbugGenerator when (sfence_dup(0).bits.rs1/*va*/) { 11077797f035SbugGenerator when (sfence_dup(0).bits.rs2) { 11086d5ddbceSLemover // all va && all asid 1109f9395f72SHaoyuan Feng l0v := l0v & ~l0virthit 1110f9395f72SHaoyuan Feng l1v := l1v & ~l1virthit 1111f9395f72SHaoyuan Feng l2v := l2v & ~l2virthit 1112f9395f72SHaoyuan Feng spv := spv & ~spvirthit 11136d5ddbceSLemover } .otherwise { 11146d5ddbceSLemover // all va && specific asid except global 1115f9395f72SHaoyuan Feng l0v := l0v & ~(l0virthit & ~l0g & l0asidhit) 1116f9395f72SHaoyuan Feng l1v := l1v & ~(l1virthit & ~l1g & l1asidhit) 1117f9395f72SHaoyuan Feng l2v := l2v & ~(l2virthit & ~l2g & l2asidhit) 1118f9395f72SHaoyuan Feng spv := spv & ~(spvirthit & ~spg & spasidhit) 11196d5ddbceSLemover } 11206d5ddbceSLemover } .otherwise { 11217797f035SbugGenerator when (sfence_dup(0).bits.rs2) { 11226d5ddbceSLemover // specific leaf of addr && all asid 1123f9395f72SHaoyuan Feng l0v := l0v & ~(l0virthit & l0vpnhit & l0flushMask) 112497929664SXiaokun-Pei spv := spv & ~(sphhit & VecInit(sp.map(_.hit(sfence_vpn, sfence_dup(0).bits.id, sfence_dup(0).bits.id, io.csr_dup(0).hgatp.vmid, ignoreAsid = true, s2xlate = io.csr_dup(0).priv.virt))).asUInt) 11256d5ddbceSLemover } .otherwise { 11266d5ddbceSLemover // specific leaf of addr && specific asid 1127f9395f72SHaoyuan Feng l0v := l0v & ~(l0virthit & ~l0g & l0asidhit & l0vpnhit & l0flushMask) 112897929664SXiaokun-Pei 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.vmid, s2xlate = io.csr_dup(0).priv.virt))).asUInt) 1129d0de7e4aSpeixiaokun } 1130d0de7e4aSpeixiaokun } 1131d0de7e4aSpeixiaokun } 1132d0de7e4aSpeixiaokun 1133d0de7e4aSpeixiaokun val hfencev_valid = sfence_dup(0).valid && sfence_dup(0).bits.hv 1134d0de7e4aSpeixiaokun when (hfencev_valid) { 1135f9395f72SHaoyuan Feng val l0hashVmid = XORFold(io.csr_dup(0).hgatp.vmid, l2tlbParams.hashAsidWidth) 1136f9395f72SHaoyuan Feng val l1hashVmid = XORFold(io.csr_dup(1).hgatp.vmid, l2tlbParams.hashAsidWidth) 1137f9395f72SHaoyuan Feng val l0vmidhit = VecInit(l0vmids.flatMap(_.map(_ === l0hashVmid))).asUInt 1138f9395f72SHaoyuan Feng val l1vmidhit = VecInit(l1vmids.flatMap(_.map(_ === l1hashVmid))).asUInt 113997929664SXiaokun-Pei val l2vmidhit = VecInit(l2vmids.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.vmid)).asUInt 114097929664SXiaokun-Pei val spvmidhit = VecInit(spvmids.map(_.getOrElse(0.U) === io.csr_dup(0).hgatp.vmid)).asUInt 1141f9395f72SHaoyuan Feng 1142f9395f72SHaoyuan Feng val l0hhit = VecInit(l0h.flatMap(_.map(_ === onlyStage1))).asUInt 1143f9395f72SHaoyuan Feng val l1hhit = VecInit(l1h.flatMap(_.map(_ === onlyStage1))).asUInt 11443ea4388cSHaoyuan Feng val l2hhit = VecInit(l2h.map(_ === onlyStage1)).asUInt 1145cca17e78Speixiaokun val sphhit = VecInit(sph.map(_ === onlyStage1)).asUInt 1146f9395f72SHaoyuan Feng 1147d0de7e4aSpeixiaokun val hfencev_vpn = sfence_dup(0).bits.addr(sfence_dup(0).bits.addr.getWidth-1, offLen) 1148f9395f72SHaoyuan Feng val l0hashVpn = XORFold(hfencev_vpn(vpnLen - 1, vpnLen - PtwL0TagLen), l2tlbParams.hashVpnWidth) 1149f9395f72SHaoyuan Feng val l0vpnhit = VecInit(l0vpns.flatMap(_.map(_ === l0hashVpn))).asUInt 1150f9395f72SHaoyuan Feng val l0flushSetIdx = UIntToOH(genPtwL0SetIdx(hfencev_vpn)) 1151f9395f72SHaoyuan Feng val l0flushMask = VecInit(l0flushSetIdx.asBools.map{a => Fill(l2tlbParams.l0nWays, a.asUInt)}).asUInt 1152f9395f72SHaoyuan Feng 1153d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs1) { 1154d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 1155f9395f72SHaoyuan Feng l0v := l0v & ~(l0hhit & l0vmidhit) 1156f9395f72SHaoyuan Feng l1v := l1v & ~(l1hhit & l1vmidhit) 11573ea4388cSHaoyuan Feng l2v := l2v & ~(l2hhit & l2vmidhit) 1158447c794eSpeixiaokun spv := spv & ~(sphhit & spvmidhit) 1159d0de7e4aSpeixiaokun }.otherwise { 1160f9395f72SHaoyuan Feng l0v := l0v & ~(l0hhit & l0vmidhit & ~l0g & l0asidhit) 1161f9395f72SHaoyuan Feng l1v := l1v & ~(l1hhit & l1vmidhit & ~l1g & l1asidhit) 1162f9395f72SHaoyuan Feng l2v := l2v & ~(l2hhit & l2vmidhit & ~l2g & l2asidhit) 1163f9395f72SHaoyuan Feng spv := spv & ~(sphhit & spvmidhit & ~spg & spasidhit) 1164d0de7e4aSpeixiaokun } 1165d0de7e4aSpeixiaokun }.otherwise { 1166d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 1167f9395f72SHaoyuan Feng l0v := l0v & ~(l0hhit & l0vmidhit & l0vpnhit & l0flushMask) 116897929664SXiaokun-Pei spv := spv & ~(sphhit & VecInit(sp.map(_.hit(hfencev_vpn, sfence_dup(0).bits.id, sfence_dup(0).bits.id, io.csr_dup(0).hgatp.vmid, ignoreAsid = true, s2xlate = true.B))).asUInt) 1169d0de7e4aSpeixiaokun }.otherwise { 1170f9395f72SHaoyuan Feng l0v := l0v & ~(l0hhit & l0vmidhit & ~l0g & l0asidhit & l0vpnhit & l0flushMask) 117197929664SXiaokun-Pei 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.vmid, s2xlate = true.B))).asUInt) 1172d0de7e4aSpeixiaokun } 1173d0de7e4aSpeixiaokun } 1174d0de7e4aSpeixiaokun } 1175d0de7e4aSpeixiaokun 1176d0de7e4aSpeixiaokun 1177d0de7e4aSpeixiaokun val hfenceg_valid = sfence_dup(0).valid && sfence_dup(0).bits.hg 1178d0de7e4aSpeixiaokun when(hfenceg_valid) { 1179f9395f72SHaoyuan Feng val l0hashVmid = XORFold(sfence_dup(0).bits.id, l2tlbParams.hashAsidWidth) 1180f9395f72SHaoyuan Feng val l1hashVmid = XORFold(sfence_dup(1).bits.id, l2tlbParams.hashAsidWidth) 1181f9395f72SHaoyuan Feng val l0vmidhit = VecInit(l0vmids.flatMap(_.map(_ === l0hashVmid))).asUInt 1182f9395f72SHaoyuan Feng val l1vmidhit = VecInit(l1vmids.flatMap(_.map(_ === l1hashVmid))).asUInt 11833ea4388cSHaoyuan Feng val l2vmidhit = VecInit(l2vmids.map(_.getOrElse(0.U) === sfence_dup(2).bits.id)).asUInt 1184cca17e78Speixiaokun val spvmidhit = VecInit(spvmids.map(_.getOrElse(0.U) === sfence_dup(0).bits.id)).asUInt 1185f9395f72SHaoyuan Feng 1186f9395f72SHaoyuan Feng val l0hhit = VecInit(l0h.flatMap(_.map(_ === onlyStage2))).asUInt 1187f9395f72SHaoyuan Feng val l1hhit = VecInit(l1h.flatMap(_.map(_ === onlyStage2))).asUInt 11883ea4388cSHaoyuan Feng val l2hhit = VecInit(l2h.map(_ === onlyStage2)).asUInt 1189cca17e78Speixiaokun val sphhit = VecInit(sph.map(_ === onlyStage2)).asUInt 1190f9395f72SHaoyuan Feng 1191887df0f4Speixiaokun val hfenceg_gvpn = (sfence_dup(0).bits.addr << 2)(sfence_dup(0).bits.addr.getWidth - 1, offLen) 1192f9395f72SHaoyuan Feng val l0hashVpn = XORFold(hfenceg_gvpn(vpnLen - 1, vpnLen - PtwL0TagLen), l2tlbParams.hashVpnWidth) 1193f9395f72SHaoyuan Feng val l0vpnhit = VecInit(l0vpns.flatMap(_.map(_ === l0hashVpn))).asUInt 1194f9395f72SHaoyuan Feng val l0flushSetIdx = UIntToOH(genPtwL0SetIdx(hfenceg_gvpn)) 1195f9395f72SHaoyuan Feng val l0flushMask = VecInit(l0flushSetIdx.asBools.map{a => Fill(l2tlbParams.l0nWays, a.asUInt)}).asUInt 1196f9395f72SHaoyuan Feng 1197d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs1) { 1198d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 1199f9395f72SHaoyuan Feng l0v := l0v & ~l0hhit 1200d0de7e4aSpeixiaokun l1v := l1v & ~l1hhit 12013ea4388cSHaoyuan Feng l2v := l2v & ~l2hhit 1202d0de7e4aSpeixiaokun spv := spv & ~sphhit 1203d0de7e4aSpeixiaokun }.otherwise { 1204f9395f72SHaoyuan Feng l0v := l0v & ~(l0hhit & l0vmidhit) 1205f9395f72SHaoyuan Feng l1v := l1v & ~(l1hhit & l1vmidhit) 12063ea4388cSHaoyuan Feng l2v := l2v & ~(l2hhit & l2vmidhit) 1207d0de7e4aSpeixiaokun spv := spv & ~(sphhit & spvmidhit) 1208d0de7e4aSpeixiaokun } 1209d0de7e4aSpeixiaokun }.otherwise { 1210d0de7e4aSpeixiaokun when(sfence_dup(0).bits.rs2) { 1211f9395f72SHaoyuan Feng l0v := l0v & ~(l0hhit & l0vpnhit & l0flushMask) 12128fe4f15fSXiaokun-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) 1213d0de7e4aSpeixiaokun }.otherwise { 1214f9395f72SHaoyuan Feng l0v := l0v & ~(l0hhit & l0vmidhit & l0vpnhit & l0flushMask) 1215*c31be712SHaoyuan Feng spv := spv & ~(sphhit & VecInit(sp.map(_.hit(hfenceg_gvpn, 0.U, 0.U, sfence_dup(0).bits.id, ignoreAsid = true, s2xlate = true.B))).asUInt) 12166d5ddbceSLemover } 12176d5ddbceSLemover } 12186d5ddbceSLemover } 12196d5ddbceSLemover 12203ea4388cSHaoyuan Feng if (EnableSv48) { 12213ea4388cSHaoyuan Feng val l3asidhit = VecInit(l3asids.get.map(_ === sfence_dup(2).bits.id)).asUInt 122297929664SXiaokun-Pei val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.vmid)).asUInt 12233ea4388cSHaoyuan 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 12243ea4388cSHaoyuan Feng 12253ea4388cSHaoyuan Feng when (sfence_valid) { 122697929664SXiaokun-Pei val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.vmid)).asUInt 12273ea4388cSHaoyuan 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 12283ea4388cSHaoyuan Feng val sfence_vpn = sfence_dup(2).bits.addr(sfence_dup(2).bits.addr.getWidth-1, offLen) 12293ea4388cSHaoyuan Feng 12303ea4388cSHaoyuan Feng when (sfence_dup(2).bits.rs1/*va*/) { 12313ea4388cSHaoyuan Feng when (sfence_dup(2).bits.rs2) { 12323ea4388cSHaoyuan Feng // all va && all asid 12333ea4388cSHaoyuan 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)) 12343ea4388cSHaoyuan Feng } .otherwise { 12353ea4388cSHaoyuan Feng // all va && specific asid except global 12363ea4388cSHaoyuan 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)) 12373ea4388cSHaoyuan Feng } 12383ea4388cSHaoyuan Feng } 12393ea4388cSHaoyuan Feng } 12403ea4388cSHaoyuan Feng 12413ea4388cSHaoyuan Feng when (hfencev_valid) { 124297929664SXiaokun-Pei val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === io.csr_dup(2).hgatp.vmid)).asUInt 12433ea4388cSHaoyuan Feng val l3hhit = VecInit(l3h.get.map(_ === onlyStage1)).asUInt 12443ea4388cSHaoyuan Feng val hfencev_vpn = sfence_dup(2).bits.addr(sfence_dup(2).bits.addr.getWidth-1, offLen) 12453ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs1) { 12463ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs2) { 12473ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(l3hhit & l3vmidhit)) 12483ea4388cSHaoyuan Feng }.otherwise { 12493ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(~l3g.get & l3hhit & l3asidhit & l3vmidhit)) 12503ea4388cSHaoyuan Feng } 12513ea4388cSHaoyuan Feng } 12523ea4388cSHaoyuan Feng } 12533ea4388cSHaoyuan Feng 12543ea4388cSHaoyuan Feng when (hfenceg_valid) { 12553ea4388cSHaoyuan Feng val l3vmidhit = VecInit(l3vmids.get.map(_.getOrElse(0.U) === sfence_dup(2).bits.id)).asUInt 12563ea4388cSHaoyuan Feng val l3hhit = VecInit(l3h.get.map(_ === onlyStage2)).asUInt 12573ea4388cSHaoyuan Feng val hfenceg_gvpn = (sfence_dup(2).bits.addr << 2)(sfence_dup(2).bits.addr.getWidth - 1, offLen) 12583ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs1) { 12593ea4388cSHaoyuan Feng when(sfence_dup(2).bits.rs2) { 12603ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~l3hhit) 12613ea4388cSHaoyuan Feng }.otherwise { 12623ea4388cSHaoyuan Feng l3v.map(_ := l3v.get & ~(l3hhit & l3vmidhit)) 12633ea4388cSHaoyuan Feng } 12643ea4388cSHaoyuan Feng } 12653ea4388cSHaoyuan Feng } 12663ea4388cSHaoyuan Feng } 12673ea4388cSHaoyuan Feng 12687797f035SbugGenerator def InsideStageConnect(in: DecoupledIO[PtwCacheReq], out: DecoupledIO[PtwCacheReq], inFire: Bool): Unit = { 12692c86e165SZhangZifei in.ready := !in.valid || out.ready 12702c86e165SZhangZifei out.valid := in.valid 12712c86e165SZhangZifei out.bits := in.bits 12721f4a7c0cSLemover out.bits.bypassed.zip(in.bits.bypassed).zipWithIndex.map{ case (b, i) => 12737797f035SbugGenerator val bypassed_reg = Reg(Bool()) 1274d0de7e4aSpeixiaokun val bypassed_wire = refill_bypass(in.bits.req_info.vpn, i, in.bits.req_info.s2xlate) && io.refill.valid 12757797f035SbugGenerator when (inFire) { bypassed_reg := bypassed_wire } 12767797f035SbugGenerator .elsewhen (io.refill.valid) { bypassed_reg := bypassed_reg || bypassed_wire } 12777797f035SbugGenerator 12787797f035SbugGenerator b._1 := b._2 || (bypassed_wire || (bypassed_reg && !inFire)) 12791f4a7c0cSLemover } 12802c86e165SZhangZifei } 12812c86e165SZhangZifei 12826d5ddbceSLemover // Perf Count 12833ea4388cSHaoyuan Feng val resp_l0 = resp_res.l0.hit 12846c4dcc2dSLemover val resp_sp = resp_res.sp.hit 12853ea4388cSHaoyuan Feng val resp_l3_pre = if (EnableSv48) Some(resp_res.l3.get.pre) else None 12866c4dcc2dSLemover val resp_l2_pre = resp_res.l2.pre 12873ea4388cSHaoyuan Feng val resp_l1_pre = resp_res.l1.pre 12883ea4388cSHaoyuan Feng val resp_l0_pre = resp_res.l0.pre 12896c4dcc2dSLemover val resp_sp_pre = resp_res.sp.pre 1290935edac4STang Haojin val base_valid_access_0 = !from_pre(io.resp.bits.req_info.source) && io.resp.fire 1291bc063562SLemover XSPerfAccumulate("access", base_valid_access_0) 12923ea4388cSHaoyuan Feng if (EnableSv48) { 12933ea4388cSHaoyuan 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) 12943ea4388cSHaoyuan Feng } 12953ea4388cSHaoyuan Feng XSPerfAccumulate("l2_hit", base_valid_access_0 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 12963ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit", base_valid_access_0 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 12973ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit", base_valid_access_0 && resp_l0) 1298bc063562SLemover XSPerfAccumulate("sp_hit", base_valid_access_0 && resp_sp) 1299bc063562SLemover XSPerfAccumulate("pte_hit",base_valid_access_0 && io.resp.bits.hit) 1300bc063562SLemover 13013ea4388cSHaoyuan Feng if (EnableSv48) { 13023ea4388cSHaoyuan 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) 13033ea4388cSHaoyuan Feng } 13043ea4388cSHaoyuan 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) 13053ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit_pre", base_valid_access_0 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13063ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit_pre", base_valid_access_0 && resp_l0_pre && resp_l0) 1307bc063562SLemover XSPerfAccumulate("sp_hit_pre", base_valid_access_0 && resp_sp_pre && resp_sp) 13083ea4388cSHaoyuan Feng XSPerfAccumulate("pte_hit_pre",base_valid_access_0 && (resp_l0_pre && resp_l0 || resp_sp_pre && resp_sp) && io.resp.bits.hit) 1309bc063562SLemover 1310935edac4STang Haojin val base_valid_access_1 = from_pre(io.resp.bits.req_info.source) && io.resp.fire 1311bc063562SLemover XSPerfAccumulate("pre_access", base_valid_access_1) 13123ea4388cSHaoyuan Feng if (EnableSv48) { 13133ea4388cSHaoyuan 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) 13143ea4388cSHaoyuan Feng } 13153ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l2_hit", base_valid_access_1 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13163ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit", base_valid_access_1 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13173ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit", base_valid_access_1 && resp_l0) 1318bc063562SLemover XSPerfAccumulate("pre_sp_hit", base_valid_access_1 && resp_sp) 1319bc063562SLemover XSPerfAccumulate("pre_pte_hit",base_valid_access_1 && io.resp.bits.hit) 1320bc063562SLemover 13213ea4388cSHaoyuan Feng if (EnableSv48) { 13223ea4388cSHaoyuan 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) 13233ea4388cSHaoyuan Feng } 13243ea4388cSHaoyuan 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) 13253ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit_pre", base_valid_access_1 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13263ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit_pre", base_valid_access_1 && resp_l0_pre && resp_l0) 1327bc063562SLemover XSPerfAccumulate("pre_sp_hit_pre", base_valid_access_1 && resp_sp_pre && resp_sp) 13283ea4388cSHaoyuan Feng XSPerfAccumulate("pre_pte_hit_pre",base_valid_access_1 && (resp_l0_pre && resp_l0 || resp_sp_pre && resp_sp) && io.resp.bits.hit) 1329bc063562SLemover 1330935edac4STang Haojin val base_valid_access_2 = stageResp.bits.isFirst && !from_pre(io.resp.bits.req_info.source) && io.resp.fire 1331bc063562SLemover XSPerfAccumulate("access_first", base_valid_access_2) 13323ea4388cSHaoyuan Feng if (EnableSv48) { 13333ea4388cSHaoyuan 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) 13343ea4388cSHaoyuan Feng } 13353ea4388cSHaoyuan Feng XSPerfAccumulate("l2_hit_first", base_valid_access_2 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13363ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit_first", base_valid_access_2 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13373ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit_first", base_valid_access_2 && resp_l0) 1338bc063562SLemover XSPerfAccumulate("sp_hit_first", base_valid_access_2 && resp_sp) 1339bc063562SLemover XSPerfAccumulate("pte_hit_first",base_valid_access_2 && io.resp.bits.hit) 1340bc063562SLemover 13413ea4388cSHaoyuan Feng if (EnableSv48) { 13423ea4388cSHaoyuan 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) 13433ea4388cSHaoyuan Feng } 13443ea4388cSHaoyuan 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) 13453ea4388cSHaoyuan Feng XSPerfAccumulate("l1_hit_pre_first", base_valid_access_2 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13463ea4388cSHaoyuan Feng XSPerfAccumulate("l0_hit_pre_first", base_valid_access_2 && resp_l0_pre && resp_l0) 1347bc063562SLemover XSPerfAccumulate("sp_hit_pre_first", base_valid_access_2 && resp_sp_pre && resp_sp) 13483ea4388cSHaoyuan Feng XSPerfAccumulate("pte_hit_pre_first",base_valid_access_2 && (resp_l0_pre && resp_l0 || resp_sp_pre && resp_sp) && io.resp.bits.hit) 1349bc063562SLemover 1350935edac4STang Haojin val base_valid_access_3 = stageResp.bits.isFirst && from_pre(io.resp.bits.req_info.source) && io.resp.fire 1351bc063562SLemover XSPerfAccumulate("pre_access_first", base_valid_access_3) 13523ea4388cSHaoyuan Feng if (EnableSv48) { 13533ea4388cSHaoyuan 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) 13543ea4388cSHaoyuan Feng } 13553ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l2_hit_first", base_valid_access_3 && io.resp.bits.toFsm.l2Hit && !io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13563ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit_first", base_valid_access_3 && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13573ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit_first", base_valid_access_3 && resp_l0) 1358bc063562SLemover XSPerfAccumulate("pre_sp_hit_first", base_valid_access_3 && resp_sp) 1359bc063562SLemover XSPerfAccumulate("pre_pte_hit_first", base_valid_access_3 && io.resp.bits.hit) 1360bc063562SLemover 13613ea4388cSHaoyuan Feng if (EnableSv48) { 13623ea4388cSHaoyuan 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) 13633ea4388cSHaoyuan Feng } 13643ea4388cSHaoyuan 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) 13653ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l1_hit_pre_first", base_valid_access_3 && resp_l1_pre && io.resp.bits.toFsm.l1Hit && !io.resp.bits.hit) 13663ea4388cSHaoyuan Feng XSPerfAccumulate("pre_l0_hit_pre_first", base_valid_access_3 && resp_l0_pre && resp_l0) 1367bc063562SLemover XSPerfAccumulate("pre_sp_hit_pre_first", base_valid_access_3 && resp_sp_pre && resp_sp) 13683ea4388cSHaoyuan 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) 1369bc063562SLemover 13706d5ddbceSLemover XSPerfAccumulate("rwHarzad", io.req.valid && !io.req.ready) 13716d5ddbceSLemover XSPerfAccumulate("out_blocked", io.resp.valid && !io.resp.ready) 13723ea4388cSHaoyuan Feng if (EnableSv48) { 13733ea4388cSHaoyuan Feng l3AccessPerf.get.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l3AccessIndex${i}", l) } 13743ea4388cSHaoyuan Feng } 13753ea4388cSHaoyuan Feng l2AccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l2AccessIndex${i}", l) } 13763ea4388cSHaoyuan Feng l1AccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l1AccessIndex${i}", l) } 13773ea4388cSHaoyuan Feng l0AccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l0AccessIndex${i}", l) } 13786d5ddbceSLemover spAccessPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"SPAccessIndex${i}", l) } 13793ea4388cSHaoyuan Feng if (EnableSv48) { 13803ea4388cSHaoyuan Feng l3RefillPerf.get.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l3RefillIndex${i}", l) } 13813ea4388cSHaoyuan Feng } 13823ea4388cSHaoyuan Feng l2RefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l2RefillIndex${i}", l) } 13833ea4388cSHaoyuan Feng l1RefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l1RefillIndex${i}", l) } 13843ea4388cSHaoyuan Feng l0RefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"l0RefillIndex${i}", l) } 13856d5ddbceSLemover spRefillPerf.zipWithIndex.map{ case (l, i) => XSPerfAccumulate(s"SPRefillIndex${i}", l) } 13866d5ddbceSLemover 13873ea4388cSHaoyuan Feng if (EnableSv48) { 13883ea4388cSHaoyuan Feng XSPerfAccumulate("l3Refill", Cat(l3RefillPerf.get).orR) 13893ea4388cSHaoyuan Feng } 1390bc063562SLemover XSPerfAccumulate("l2Refill", Cat(l2RefillPerf).orR) 13913ea4388cSHaoyuan Feng XSPerfAccumulate("l1Refill", Cat(l1RefillPerf).orR) 13923ea4388cSHaoyuan Feng XSPerfAccumulate("l0Refill", Cat(l0RefillPerf).orR) 1393bc063562SLemover XSPerfAccumulate("spRefill", Cat(spRefillPerf).orR) 13943ea4388cSHaoyuan Feng if (EnableSv48) { 13953ea4388cSHaoyuan Feng XSPerfAccumulate("l3Refill_pre", Cat(l3RefillPerf.get).orR && refill_prefetch_dup(0)) 13963ea4388cSHaoyuan Feng } 13977797f035SbugGenerator XSPerfAccumulate("l2Refill_pre", Cat(l2RefillPerf).orR && refill_prefetch_dup(0)) 13983ea4388cSHaoyuan Feng XSPerfAccumulate("l1Refill_pre", Cat(l1RefillPerf).orR && refill_prefetch_dup(0)) 13993ea4388cSHaoyuan Feng XSPerfAccumulate("l0Refill_pre", Cat(l0RefillPerf).orR && refill_prefetch_dup(0)) 14007797f035SbugGenerator XSPerfAccumulate("spRefill_pre", Cat(spRefillPerf).orR && refill_prefetch_dup(0)) 1401bc063562SLemover 14026d5ddbceSLemover // debug 14037797f035SbugGenerator XSDebug(sfence_dup(0).valid, p"[sfence] original v and g vector:\n") 14043ea4388cSHaoyuan Feng if (EnableSv48) { 14053ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l3v:${Binary(l3v.get)}\n") 14063ea4388cSHaoyuan Feng } 14077797f035SbugGenerator XSDebug(sfence_dup(0).valid, p"[sfence] l2v:${Binary(l2v)}\n") 14083ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l1v:${Binary(l1v)}\n") 14093ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l0v:${Binary(l0v)}\n") 14103ea4388cSHaoyuan Feng XSDebug(sfence_dup(0).valid, p"[sfence] l0g:${Binary(l0g)}\n") 14117797f035SbugGenerator XSDebug(sfence_dup(0).valid, p"[sfence] spv:${Binary(spv)}\n") 14127797f035SbugGenerator XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] new v and g vector:\n") 14133ea4388cSHaoyuan Feng if (EnableSv48) { 14143ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l3v:${Binary(l3v.get)}\n") 14153ea4388cSHaoyuan Feng } 14167797f035SbugGenerator XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l2v:${Binary(l2v)}\n") 14173ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l1v:${Binary(l1v)}\n") 14183ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l0v:${Binary(l0v)}\n") 14193ea4388cSHaoyuan Feng XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] l0g:${Binary(l0g)}\n") 14207797f035SbugGenerator XSDebug(RegNext(sfence_dup(0).valid), p"[sfence] spv:${Binary(spv)}\n") 1421cd365d4cSrvcoresjw 1422cd365d4cSrvcoresjw val perfEvents = Seq( 142356be8e20SYinan Xu ("access ", base_valid_access_0 ), 1424cd365d4cSrvcoresjw ("l2_hit ", l2Hit ), 14253ea4388cSHaoyuan Feng ("l1_hit ", l1Hit ), 14263ea4388cSHaoyuan Feng ("l0_hit ", l0Hit ), 1427cd365d4cSrvcoresjw ("sp_hit ", spHit ), 14283ea4388cSHaoyuan Feng ("pte_hit ", l0Hit || spHit ), 1429cd365d4cSrvcoresjw ("rwHarzad ", io.req.valid && !io.req.ready ), 1430cd365d4cSrvcoresjw ("out_blocked ", io.resp.valid && !io.resp.ready ), 1431cd365d4cSrvcoresjw ) 14321ca0e4f3SYinan Xu generatePerfEvent() 14336d5ddbceSLemover} 1434