1bc063562SLemover/*************************************************************************************** 2bc063562SLemover* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3bc063562SLemover* Copyright (c) 2020-2021 Peng Cheng Laboratory 4bc063562SLemover* 5bc063562SLemover* XiangShan is licensed under Mulan PSL v2. 6bc063562SLemover* You can use this software according to the terms and conditions of the Mulan PSL v2. 7bc063562SLemover* You may obtain a copy of Mulan PSL v2 at: 8bc063562SLemover* http://license.coscl.org.cn/MulanPSL2 9bc063562SLemover* 10bc063562SLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11bc063562SLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12bc063562SLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13bc063562SLemover* 14bc063562SLemover* See the Mulan PSL v2 for more details. 15bc063562SLemover***************************************************************************************/ 16bc063562SLemoverpackage xiangshan.cache.mmu 17bc063562SLemover 18bc063562SLemoverimport chisel3._ 19bc063562SLemoverimport chisel3.util._ 20bc063562SLemoverimport chipsalliance.rocketchip.config.Parameters 21bc063562SLemoverimport xiangshan.{SfenceBundle, XSModule} 22bc063562SLemoverimport utils._ 23bc063562SLemover 2445f497a4Shappy-lxclass L2TlbPrefetchIO(implicit p: Parameters) extends MMUIOBaseBundle with HasPtwConst { 25bc063562SLemover val in = Flipped(ValidIO(new Bundle { 26bc063562SLemover val vpn = UInt(vpnLen.W) 27bc063562SLemover })) 28bc063562SLemover val out = DecoupledIO(new Bundle { 29bc063562SLemover val vpn = UInt(vpnLen.W) 30bc063562SLemover val source = UInt(bSourceWidth.W) 31bc063562SLemover }) 32bc063562SLemover} 33bc063562SLemover 34bc063562SLemoverclass L2TlbPrefetch(implicit p: Parameters) extends XSModule with HasPtwConst { 35bc063562SLemover val io = IO(new L2TlbPrefetchIO()) 36bc063562SLemover 37*7797f035SbugGenerator val OldRecordSize = 4 38*7797f035SbugGenerator val old_reqs = Reg(Vec(OldRecordSize, UInt(vpnLen.W))) 39*7797f035SbugGenerator val old_v = VecInit(Seq.fill(OldRecordSize)(RegInit(false.B))) 40*7797f035SbugGenerator val old_index = RegInit(0.U(log2Ceil(OldRecordSize).W)) 41*7797f035SbugGenerator 42*7797f035SbugGenerator def already_have(vpn: UInt): Bool = { 43*7797f035SbugGenerator Cat(old_reqs.zip(old_v).map{ case (o,v) => dup(o,vpn) && v}).orR 44*7797f035SbugGenerator } 45*7797f035SbugGenerator 4645f497a4Shappy-lx val flush = io.sfence.valid || io.csr.satp.changed 47*7797f035SbugGenerator val next_line = get_next_line(io.in.bits.vpn) 48*7797f035SbugGenerator val next_req = RegEnable(next_line, io.in.valid) 49*7797f035SbugGenerator val input_valid = io.in.valid && !flush && !already_have(next_line) 50*7797f035SbugGenerator val v = ValidHold(input_valid, io.out.fire(), flush) 51bc063562SLemover 52bc063562SLemover io.out.valid := v 53*7797f035SbugGenerator io.out.bits.vpn := next_req 54bc063562SLemover io.out.bits.source := prefetchID.U 55*7797f035SbugGenerator 56*7797f035SbugGenerator when (io.out.fire) { 57*7797f035SbugGenerator old_v(old_index) := true.B 58*7797f035SbugGenerator old_reqs(old_index) := next_req 59*7797f035SbugGenerator old_index := Mux((old_index === (OldRecordSize-1).U), 0.U, old_index + 1.U) 60*7797f035SbugGenerator } 61*7797f035SbugGenerator 62*7797f035SbugGenerator when (flush) { 63*7797f035SbugGenerator old_v.map(_ := false.B) 64*7797f035SbugGenerator } 65*7797f035SbugGenerator 66*7797f035SbugGenerator XSPerfAccumulate("l2tlb_prefetch_input_count", input_valid) 67*7797f035SbugGenerator XSPerfAccumulate("l2tlb_prefetch_output_count", io.out.fire()) 68bc063562SLemover} 69