1/*************************************************************************************** 2 * Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3 * Copyright (c) 2020-2021 Peng Cheng Laboratory 4 * 5 * XiangShan is licensed under Mulan PSL v2. 6 * You can use this software according to the terms and conditions of the Mulan PSL v2. 7 * You may obtain a copy of Mulan PSL v2 at: 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * 14 * See the Mulan PSL v2 for more details. 15 ***************************************************************************************/ 16 17package xiangshan.cache.mmu 18 19import chipsalliance.rocketchip.config.Parameters 20import chisel3._ 21import chisel3.experimental.{ExtModule, chiselName} 22import chisel3.util._ 23import utils._ 24import utility._ 25import freechips.rocketchip.formal.PropertyClass 26import xiangshan.backend.fu.util.HasCSRConst 27 28import scala.math.min 29 30class BankedAsyncDataModuleTemplateWithDup[T <: Data]( 31 gen: T, 32 numEntries: Int, 33 numRead: Int, 34 numDup: Int, 35 numBanks: Int 36) extends Module { 37 val io = IO(new Bundle { 38 val raddr = Vec(numRead, Input(UInt(log2Ceil(numEntries).W))) 39 val rdata = Vec(numRead, Vec(numDup, Output(gen))) 40 val wen = Input(Bool()) 41 val waddr = Input(UInt(log2Ceil(numEntries).W)) 42 val wdata = Input(gen) 43 }) 44 require(numBanks > 1) 45 require(numEntries > numBanks) 46 47 val numBankEntries = numEntries / numBanks 48 def bankOffset(address: UInt): UInt = { 49 address(log2Ceil(numBankEntries) - 1, 0) 50 } 51 52 def bankIndex(address: UInt): UInt = { 53 address(log2Ceil(numEntries) - 1, log2Ceil(numBankEntries)) 54 } 55 56 val dataBanks = Seq.tabulate(numBanks)(i => { 57 val bankEntries = if (i < numBanks - 1) numBankEntries else (numEntries - (i * numBankEntries)) 58 Mem(bankEntries, gen) 59 }) 60 61 // async read, but regnext 62 for (i <- 0 until numRead) { 63 val data_read = Reg(Vec(numDup, Vec(numBanks, gen))) 64 val bank_index = Reg(Vec(numDup, UInt(numBanks.W))) 65 for (j <- 0 until numDup) { 66 bank_index(j) := UIntToOH(bankIndex(io.raddr(i))) 67 for (k <- 0 until numBanks) { 68 data_read(j)(k) := Mux(io.wen && (io.waddr === io.raddr(i)), 69 io.wdata, dataBanks(k)(bankOffset(io.raddr(i)))) 70 } 71 } 72 // next cycle 73 for (j <- 0 until numDup) { 74 io.rdata(i)(j) := Mux1H(bank_index(j), data_read(j)) 75 } 76 } 77 78 // write 79 for (i <- 0 until numBanks) { 80 when (io.wen && (bankIndex(io.waddr) === i.U)) { 81 dataBanks(i)(bankOffset(io.waddr)) := io.wdata 82 } 83 } 84} 85 86@chiselName 87class TLBFA( 88 parentName: String, 89 ports: Int, 90 nSets: Int, 91 nWays: Int, 92 saveLevel: Boolean = false, 93 normalPage: Boolean, 94 superPage: Boolean 95)(implicit p: Parameters) extends TlbModule with HasPerfEvents { 96 97 val io = IO(new TlbStorageIO(nSets, nWays, ports)) 98 io.r.req.map(_.ready := true.B) 99 100 val v = RegInit(VecInit(Seq.fill(nWays)(false.B))) 101 val entries = Reg(Vec(nWays, new TlbEntry(normalPage, superPage))) 102 val g = entries.map(_.perm.g) 103 104 for (i <- 0 until ports) { 105 val req = io.r.req(i) 106 val resp = io.r.resp(i) 107 val access = io.access(i) 108 109 val vpn = req.bits.vpn 110 val vpn_reg = RegEnable(vpn, req.fire()) 111 val vpn_gen_ppn = if(saveLevel) vpn else vpn_reg 112 113 val refill_mask = Mux(io.w.valid, UIntToOH(io.w.bits.wayIdx), 0.U(nWays.W)) 114 val hitVec = VecInit((entries.zipWithIndex).zip(v zip refill_mask.asBools).map{case (e, m) => e._1.hit(vpn, io.csr.satp.asid) && m._1 && !m._2 }) 115 116 hitVec.suggestName("hitVec") 117 118 val hitVecReg = RegEnable(hitVec, req.fire()) 119 assert(!resp.valid || (PopCount(hitVecReg) === 0.U || PopCount(hitVecReg) === 1.U), s"${parentName} fa port${i} multi-hit") 120 121 resp.valid := RegNext(req.valid) 122 resp.bits.hit := Cat(hitVecReg).orR 123 if (nWays == 1) { 124 resp.bits.ppn(0) := entries(0).genPPN(saveLevel, req.valid)(vpn_gen_ppn) 125 resp.bits.perm(0) := entries(0).perm 126 } else { 127 resp.bits.ppn(0) := ParallelMux(hitVecReg zip entries.map(_.genPPN(saveLevel, req.valid)(vpn_gen_ppn))) 128 resp.bits.perm(0) := ParallelMux(hitVecReg zip entries.map(_.perm)) 129 } 130 131 access.sets := get_set_idx(vpn_reg, nSets) // no use 132 access.touch_ways.valid := resp.valid && Cat(hitVecReg).orR 133 access.touch_ways.bits := OHToUInt(hitVecReg) 134 135 resp.bits.hit.suggestName("hit") 136 resp.bits.ppn.suggestName("ppn") 137 resp.bits.perm.suggestName("perm") 138 } 139 140 when (io.w.valid) { 141 v(io.w.bits.wayIdx) := true.B 142 entries(io.w.bits.wayIdx).apply(io.w.bits.data, io.csr.satp.asid, io.w.bits.data_replenish) 143 } 144 // write assert, shoulg not duplicate with the existing entries 145 val w_hit_vec = VecInit(entries.zip(v).map{case (e, vi) => e.hit(io.w.bits.data.entry.tag, io.csr.satp.asid) && vi }) 146 XSError(io.w.valid && Cat(w_hit_vec).orR, s"${parentName} refill, duplicate with existing entries") 147 148 val refill_vpn_reg = RegNext(io.w.bits.data.entry.tag) 149 val refill_wayIdx_reg = RegNext(io.w.bits.wayIdx) 150 when (RegNext(io.w.valid)) { 151 io.access.map { access => 152 access.sets := get_set_idx(refill_vpn_reg, nSets) 153 access.touch_ways.valid := true.B 154 access.touch_ways.bits := refill_wayIdx_reg 155 } 156 } 157 158 val sfence = io.sfence 159 val sfence_vpn = sfence.bits.addr.asTypeOf(new VaBundle().cloneType).vpn 160 val sfenceHit = entries.map(_.hit(sfence_vpn, sfence.bits.asid)) 161 val sfenceHit_noasid = entries.map(_.hit(sfence_vpn, sfence.bits.asid, ignoreAsid = true)) 162 when (io.sfence.valid) { 163 when (sfence.bits.rs1) { // virtual address *.rs1 <- (rs1===0.U) 164 when (sfence.bits.rs2) { // asid, but i do not want to support asid, *.rs2 <- (rs2===0.U) 165 // all addr and all asid 166 v.map(_ := false.B) 167 }.otherwise { 168 // all addr but specific asid 169 v.zipWithIndex.map{ case (a,i) => a := a & (g(i) | !(entries(i).asid === sfence.bits.asid)) } 170 } 171 }.otherwise { 172 when (sfence.bits.rs2) { 173 // specific addr but all asid 174 v.zipWithIndex.map{ case (a,i) => a := a & !sfenceHit_noasid(i) } 175 }.otherwise { 176 // specific addr and specific asid 177 v.zipWithIndex.map{ case (a,i) => a := a & !(sfenceHit(i) && !g(i)) } 178 } 179 } 180 } 181 182 val victim_idx = io.w.bits.wayIdx 183 io.victim.out.valid := v(victim_idx) && io.w.valid && entries(victim_idx).is_normalentry() 184 io.victim.out.bits.entry := ns_to_n(entries(victim_idx)) 185 186 def ns_to_n(ns: TlbEntry): TlbEntry = { 187 val n = Wire(new TlbEntry(pageNormal = true, pageSuper = false)) 188 n.perm := ns.perm 189 n.ppn := ns.ppn 190 n.tag := ns.tag 191 n.asid := ns.asid 192 n 193 } 194 195 XSPerfAccumulate(s"access", io.r.resp.map(_.valid.asUInt()).fold(0.U)(_ + _)) 196 XSPerfAccumulate(s"hit", io.r.resp.map(a => a.valid && a.bits.hit).fold(0.U)(_.asUInt() + _.asUInt())) 197 198 for (i <- 0 until nWays) { 199 XSPerfAccumulate(s"access${i}", io.r.resp.zip(io.access.map(acc => UIntToOH(acc.touch_ways.bits))).map{ case (a, b) => 200 a.valid && a.bits.hit && b(i)}.fold(0.U)(_.asUInt() + _.asUInt())) 201 } 202 for (i <- 0 until nWays) { 203 XSPerfAccumulate(s"refill${i}", io.w.valid && io.w.bits.wayIdx === i.U) 204 } 205 206 val perfEvents = Seq( 207 ("tlbstore_access", io.r.resp.map(_.valid.asUInt()).fold(0.U)(_ + _) ), 208 ("tlbstore_hit ", io.r.resp.map(a => a.valid && a.bits.hit).fold(0.U)(_.asUInt() + _.asUInt())), 209 ) 210 generatePerfEvent() 211 212 println(s"${parentName} tlb_fa: nSets${nSets} nWays:${nWays}") 213} 214 215@chiselName 216class TLBSA( 217 parentName: String, 218 ports: Int, 219 nDups: Int, 220 nSets: Int, 221 nWays: Int, 222 normalPage: Boolean, 223 superPage: Boolean 224)(implicit p: Parameters) extends TlbModule { 225 require(!superPage, "super page should use reg/fa") 226 require(nWays == 1, "nWays larger than 1 causes bad timing") 227 228 // timing optimization to divide v select into two cycles. 229 val VPRE_SELECT = min(8, nSets) 230 val VPOST_SELECT = nSets / VPRE_SELECT 231 val nBanks = 8 232 233 val io = IO(new TlbStorageIO(nSets, nWays, ports, nDups)) 234 235 io.r.req.map(_.ready := true.B) 236 val v = RegInit(VecInit(Seq.fill(nSets)(VecInit(Seq.fill(nWays)(false.B))))) 237 val entries = Module(new BankedAsyncDataModuleTemplateWithDup(new TlbEntry(normalPage, superPage), nSets, ports, nDups, nBanks)) 238 239 for (i <- 0 until ports) { // duplicate sram 240 val req = io.r.req(i) 241 val resp = io.r.resp(i) 242 val access = io.access(i) 243 244 val vpn = req.bits.vpn 245 val vpn_reg = RegEnable(vpn, req.fire()) 246 247 val ridx = get_set_idx(vpn, nSets) 248 val v_resize = v.asTypeOf(Vec(VPRE_SELECT, Vec(VPOST_SELECT, UInt(nWays.W)))) 249 val vidx_resize = RegNext(v_resize(get_set_idx(drop_set_idx(vpn, VPOST_SELECT), VPRE_SELECT))) 250 val vidx = vidx_resize(get_set_idx(vpn_reg, VPOST_SELECT)).asBools.map(_ && RegNext(req.fire())) 251 val vidx_bypass = RegNext((entries.io.waddr === ridx) && entries.io.wen) 252 entries.io.raddr(i) := ridx 253 254 val data = entries.io.rdata(i) 255 val hit = data(0).hit(vpn_reg, io.csr.satp.asid, nSets) && (vidx(0) || vidx_bypass) 256 resp.bits.hit := hit 257 for (d <- 0 until nDups) { 258 resp.bits.ppn(d) := data(d).genPPN()(vpn_reg) 259 resp.bits.perm(d) := data(d).perm 260 } 261 262 resp.valid := { RegNext(req.valid) } 263 resp.bits.hit.suggestName("hit") 264 resp.bits.ppn.suggestName("ppn") 265 resp.bits.perm.suggestName("perm") 266 267 access.sets := get_set_idx(vpn_reg, nSets) // no use 268 access.touch_ways.valid := resp.valid && hit 269 access.touch_ways.bits := 1.U // TODO: set-assoc need no replacer when nset is 1 270 } 271 272 // W ports should be 1, or, check at above will be wrong. 273 entries.io.wen := io.w.valid || io.victim.in.valid 274 entries.io.waddr := Mux(io.w.valid, 275 get_set_idx(io.w.bits.data.entry.tag, nSets), 276 get_set_idx(io.victim.in.bits.entry.tag, nSets)) 277 entries.io.wdata := Mux(io.w.valid, 278 (Wire(new TlbEntry(normalPage, superPage)).apply(io.w.bits.data, io.csr.satp.asid, io.w.bits.data_replenish)), 279 io.victim.in.bits.entry) 280 281 when (io.victim.in.valid) { 282 v(get_set_idx(io.victim.in.bits.entry.tag, nSets))(io.w.bits.wayIdx) := true.B 283 } 284 // w has higher priority than victim 285 when (io.w.valid) { 286 v(get_set_idx(io.w.bits.data.entry.tag, nSets))(io.w.bits.wayIdx) := true.B 287 } 288 289 val refill_vpn_reg = RegNext(Mux(io.victim.in.valid, io.victim.in.bits.entry.tag, io.w.bits.data.entry.tag)) 290 val refill_wayIdx_reg = RegNext(io.w.bits.wayIdx) 291 when (RegNext(io.w.valid || io.victim.in.valid)) { 292 io.access.map { access => 293 access.sets := get_set_idx(refill_vpn_reg, nSets) 294 access.touch_ways.valid := true.B 295 access.touch_ways.bits := refill_wayIdx_reg 296 } 297 } 298 299 val sfence = io.sfence 300 val sfence_vpn = sfence.bits.addr.asTypeOf(new VaBundle().cloneType).vpn 301 when (io.sfence.valid) { 302 when (sfence.bits.rs1) { // virtual address *.rs1 <- (rs1===0.U) 303 v.map(a => a.map(b => b := false.B)) 304 }.otherwise { 305 // specific addr but all asid 306 v(get_set_idx(sfence_vpn, nSets)).map(_ := false.B) 307 } 308 } 309 310 io.victim.out := DontCare 311 io.victim.out.valid := false.B 312 313 XSPerfAccumulate(s"access", io.r.req.map(_.valid.asUInt()).fold(0.U)(_ + _)) 314 XSPerfAccumulate(s"hit", io.r.resp.map(a => a.valid && a.bits.hit).fold(0.U)(_.asUInt() + _.asUInt())) 315 316 for (i <- 0 until nSets) { 317 XSPerfAccumulate(s"refill${i}", (io.w.valid || io.victim.in.valid) && 318 (Mux(io.w.valid, get_set_idx(io.w.bits.data.entry.tag, nSets), get_set_idx(io.victim.in.bits.entry.tag, nSets)) === i.U) 319 ) 320 } 321 322 for (i <- 0 until nSets) { 323 XSPerfAccumulate(s"hit${i}", io.r.resp.map(a => a.valid & a.bits.hit) 324 .zip(io.r.req.map(a => RegNext(get_set_idx(a.bits.vpn, nSets)) === i.U)) 325 .map{a => (a._1 && a._2).asUInt()} 326 .fold(0.U)(_ + _) 327 ) 328 } 329 330 for (i <- 0 until nSets) { 331 XSPerfAccumulate(s"access${i}", io.r.resp.map(_.valid) 332 .zip(io.r.req.map(a => RegNext(get_set_idx(a.bits.vpn, nSets)) === i.U)) 333 .map{a => (a._1 && a._2).asUInt()} 334 .fold(0.U)(_ + _) 335 ) 336 } 337 338 println(s"${parentName} tlb_sa: nSets:${nSets} nWays:${nWays}") 339} 340 341@chiselName 342class TLBFakeSP( 343 ports: Int, 344 nSets: Int, 345 nWays: Int, 346 useDmode: Boolean = false 347 )(implicit p: Parameters) extends TlbModule with HasCSRConst{ 348 349 val io = IO(new TlbStorageIO(nSets, nWays, ports)) 350 io.r.req.map(_.ready := true.B) 351 val mode = if (useDmode) io.csr.priv.dmode else io.csr.priv.imode 352 val vmEnable = if (EnbaleTlbDebug) (io.csr.satp.mode === 8.U) 353 else (io.csr.satp.mode === 8.U && (mode < ModeM)) 354 355 for (i <- 0 until ports) { 356 val req = io.r.req(i) 357 val resp = io.r.resp(i) 358 359 val helper = Module(new PTEHelper()) 360 helper.clock := clock 361 helper.satp := io.csr.satp.ppn 362 helper.enable := req.fire && vmEnable 363 helper.vpn := req.bits.vpn 364 365 val pte = helper.pte.asTypeOf(new PteBundle) 366 val ppn = pte.ppn 367 val vpn_reg = RegNext(req.bits.vpn) 368 val pf = helper.pf 369 val level = helper.level 370 371 resp.valid := RegNext(req.valid) 372 resp.bits.hit := true.B 373 resp.bits.perm(0).pf := pf 374 resp.bits.perm(0).af := false.B 375 resp.bits.perm(0).d := pte.perm.d 376 resp.bits.perm(0).a := pte.perm.a 377 resp.bits.perm(0).g := pte.perm.g 378 resp.bits.perm(0).u := pte.perm.u 379 resp.bits.perm(0).x := pte.perm.x 380 resp.bits.perm(0).w := pte.perm.w 381 resp.bits.perm(0).r := pte.perm.r 382 resp.bits.perm(0).pm := DontCare 383 384 resp.bits.ppn(0) := MuxLookup(level, 0.U, Seq( 385 0.U -> Cat(ppn(ppn.getWidth-1, vpnnLen*2), vpn_reg(vpnnLen*2-1, 0)), 386 1.U -> Cat(ppn(ppn.getWidth-1, vpnnLen), vpn_reg(vpnnLen-1, 0)), 387 2.U -> ppn) 388 ) 389 } 390 391 io.access := DontCare 392 io.victim.out := DontCare 393 394} 395 396@chiselName 397class TLBFakeNP( 398 ports: Int, 399 nDups: Int, 400 nSets: Int, 401 nWays: Int 402 )(implicit p: Parameters) extends TlbModule { 403 404 val io = IO(new TlbStorageIO(nSets, nWays, ports, nDups)) 405 406 io.r.req.map(_.ready := true.B) 407 io.r.resp := DontCare 408 io.access := DontCare 409 io.victim.out := DontCare 410} 411 412object TlbStorage { 413 def apply 414 ( 415 parentName: String, 416 associative: String, 417 ports: Int, 418 nDups: Int = 1, 419 nSets: Int, 420 nWays: Int, 421 saveLevel: Boolean = false, 422 normalPage: Boolean, 423 superPage: Boolean, 424 useDmode: Boolean, 425 SoftTLB: Boolean 426 )(implicit p: Parameters) = { 427 if (SoftTLB) { 428 if (superPage == true) { 429 val storage = Module(new TLBFakeSP(ports, nSets, nWays, useDmode)) 430 storage.suggestName(s"${parentName}_fakesp") 431 storage.io 432 } else { 433 val storage = Module(new TLBFakeNP(ports, nDups, nSets, nWays)) 434 storage.suggestName(s"${parentName}_fakenp") 435 storage.io 436 } 437 } else { 438 if (associative == "fa") { 439 val storage = Module(new TLBFA(parentName, ports, nSets, nWays, saveLevel, normalPage, superPage)) 440 storage.suggestName(s"${parentName}_fa") 441 storage.io 442 } else { 443 val storage = Module(new TLBSA(parentName, ports, nDups, nSets, nWays, normalPage, superPage)) 444 storage.suggestName(s"${parentName}_sa") 445 storage.io 446 } 447 } 448 } 449} 450 451class TlbStorageWrapper(ports: Int, q: TLBParameters, nDups: Int = 1)(implicit p: Parameters) extends TlbModule { 452 val io = IO(new TlbStorageWrapperIO(ports, q, nDups)) 453 454// TODO: wrap Normal page and super page together, wrap the declare & refill dirty codes 455 val normalPage = TlbStorage( 456 parentName = q.name + "_np_storage", 457 associative = q.normalAssociative, 458 ports = ports, 459 nDups = nDups, 460 nSets = q.normalNSets, 461 nWays = q.normalNWays, 462 saveLevel = q.saveLevel, 463 normalPage = true, 464 superPage = false, 465 useDmode = q.useDmode, 466 SoftTLB = coreParams.softTLB 467 ) 468 val superPage = TlbStorage( 469 parentName = q.name + "_sp_storage", 470 associative = q.superAssociative, 471 ports = ports, 472 nSets = q.superNSets, 473 nWays = q.superNWays, 474 normalPage = q.normalAsVictim, 475 superPage = true, 476 useDmode = q.useDmode, 477 SoftTLB = coreParams.softTLB 478 ) 479 480 for (i <- 0 until ports) { 481 normalPage.r_req_apply( 482 valid = io.r.req(i).valid, 483 vpn = io.r.req(i).bits.vpn, 484 i = i 485 ) 486 superPage.r_req_apply( 487 valid = io.r.req(i).valid, 488 vpn = io.r.req(i).bits.vpn, 489 i = i 490 ) 491 } 492 493 for (i <- 0 until ports) { 494 val nq = normalPage.r.req(i) 495 val np = normalPage.r.resp(i) 496 val sq = superPage.r.req(i) 497 val sp = superPage.r.resp(i) 498 val rq = io.r.req(i) 499 val rp = io.r.resp(i) 500 rq.ready := nq.ready && sq.ready // actually, not used 501 rp.valid := np.valid && sp.valid // actually, not used 502 rp.bits.hit := np.bits.hit || sp.bits.hit 503 for (d <- 0 until nDups) { 504 rp.bits.ppn(d) := Mux(sp.bits.hit, sp.bits.ppn(0), np.bits.ppn(d)) 505 rp.bits.perm(d) := Mux(sp.bits.hit, sp.bits.perm(0), np.bits.perm(d)) 506 } 507 rp.bits.super_hit := sp.bits.hit 508 rp.bits.super_ppn := sp.bits.ppn(0) 509 rp.bits.spm := np.bits.perm(0).pm 510 assert(!np.bits.hit || !sp.bits.hit || !rp.valid, s"${q.name} storage ports${i} normal and super multi-hit") 511 } 512 513 normalPage.victim.in <> superPage.victim.out 514 normalPage.victim.out <> superPage.victim.in 515 normalPage.sfence <> io.sfence 516 superPage.sfence <> io.sfence 517 normalPage.csr <> io.csr 518 superPage.csr <> io.csr 519 520 val normal_refill_idx = if (q.outReplace) { 521 io.replace.normalPage.access <> normalPage.access 522 io.replace.normalPage.chosen_set := get_set_idx(io.w.bits.data.entry.tag, q.normalNSets) 523 io.replace.normalPage.refillIdx 524 } else if (q.normalAssociative == "fa") { 525 val re = ReplacementPolicy.fromString(q.normalReplacer, q.normalNWays) 526 re.access(normalPage.access.map(_.touch_ways)) // normalhitVecVec.zipWithIndex.map{ case (hv, i) => get_access(hv, validRegVec(i))}) 527 re.way 528 } else { // set-acco && plru 529 val re = ReplacementPolicy.fromString(q.normalReplacer, q.normalNSets, q.normalNWays) 530 re.access(normalPage.access.map(_.sets), normalPage.access.map(_.touch_ways)) 531 re.way(get_set_idx(io.w.bits.data.entry.tag, q.normalNSets)) 532 } 533 534 val super_refill_idx = if (q.outReplace) { 535 io.replace.superPage.access <> superPage.access 536 io.replace.superPage.chosen_set := DontCare 537 io.replace.superPage.refillIdx 538 } else { 539 val re = ReplacementPolicy.fromString(q.superReplacer, q.superNWays) 540 re.access(superPage.access.map(_.touch_ways)) 541 re.way 542 } 543 544 normalPage.w_apply( 545 valid = { if (q.normalAsVictim) false.B 546 else io.w.valid && io.w.bits.data.entry.level.get === 2.U }, 547 wayIdx = normal_refill_idx, 548 data = io.w.bits.data, 549 data_replenish = io.w.bits.data_replenish 550 ) 551 superPage.w_apply( 552 valid = { if (q.normalAsVictim) io.w.valid 553 else io.w.valid && io.w.bits.data.entry.level.get =/= 2.U }, 554 wayIdx = super_refill_idx, 555 data = io.w.bits.data, 556 data_replenish = io.w.bits.data_replenish 557 ) 558 559 // replacement 560 def get_access(one_hot: UInt, valid: Bool): Valid[UInt] = { 561 val res = Wire(Valid(UInt(log2Up(one_hot.getWidth).W))) 562 res.valid := Cat(one_hot).orR && valid 563 res.bits := OHToUInt(one_hot) 564 res 565 } 566} 567