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.frontend.icache 18 19import org.chipsalliance.cde.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import difftest._ 23import freechips.rocketchip.tilelink.ClientStates 24import xiangshan._ 25import xiangshan.cache.mmu._ 26import utils._ 27import utility._ 28import xiangshan.backend.fu.{PMPReqBundle, PMPRespBundle} 29import xiangshan.frontend.{FtqICacheInfo, FtqToICacheRequestBundle, ExceptionType} 30 31class ICacheMainPipeReq(implicit p: Parameters) extends ICacheBundle 32{ 33 val vaddr = UInt(VAddrBits.W) 34 def vSetIdx = get_idx(vaddr) 35} 36 37class ICacheMainPipeResp(implicit p: Parameters) extends ICacheBundle 38{ 39 val vaddr = UInt(VAddrBits.W) 40 val data = UInt((blockBits).W) 41 val paddr = UInt(PAddrBits.W) 42 val gpaddr = UInt(GPAddrBits.W) 43 val exception = UInt(ExceptionType.width.W) 44 val pmp_mmio = Bool() 45 val itlb_pbmt = UInt(Pbmt.width.W) 46} 47 48class ICacheMainPipeBundle(implicit p: Parameters) extends ICacheBundle 49{ 50 val req = Flipped(Decoupled(new FtqToICacheRequestBundle)) 51 val resp = Vec(PortNumber, ValidIO(new ICacheMainPipeResp)) 52 val topdownIcacheMiss = Output(Bool()) 53 val topdownItlbMiss = Output(Bool()) 54} 55 56class ICacheMetaReqBundle(implicit p: Parameters) extends ICacheBundle{ 57 val toIMeta = DecoupledIO(new ICacheReadBundle) 58 val fromIMeta = Input(new ICacheMetaRespBundle) 59} 60 61class ICacheDataReqBundle(implicit p: Parameters) extends ICacheBundle{ 62 val toIData = Vec(partWayNum, DecoupledIO(new ICacheReadBundle)) 63 val fromIData = Input(new ICacheDataRespBundle) 64} 65 66class ICacheMSHRBundle(implicit p: Parameters) extends ICacheBundle{ 67 val req = Decoupled(new ICacheMissReq) 68 val resp = Flipped(ValidIO(new ICacheMissResp)) 69} 70 71class ICachePMPBundle(implicit p: Parameters) extends ICacheBundle{ 72 val req = Valid(new PMPReqBundle()) 73 val resp = Input(new PMPRespBundle()) 74} 75 76class ICachePerfInfo(implicit p: Parameters) extends ICacheBundle{ 77 val only_0_hit = Bool() 78 val only_0_miss = Bool() 79 val hit_0_hit_1 = Bool() 80 val hit_0_miss_1 = Bool() 81 val miss_0_hit_1 = Bool() 82 val miss_0_miss_1 = Bool() 83 val hit_0_except_1 = Bool() 84 val miss_0_except_1 = Bool() 85 val except_0 = Bool() 86 val bank_hit = Vec(2,Bool()) 87 val hit = Bool() 88} 89 90class ICacheMainPipeInterface(implicit p: Parameters) extends ICacheBundle { 91 val hartId = Input(UInt(hartIdLen.W)) 92 /*** internal interface ***/ 93 val dataArray = new ICacheDataReqBundle 94 /** prefetch io */ 95 val touch = Vec(PortNumber,ValidIO(new ReplacerTouch)) 96 val wayLookupRead = Flipped(DecoupledIO(new WayLookupInfo)) 97 98 val mshr = new ICacheMSHRBundle 99 val errors = Output(Vec(PortNumber, ValidIO(new L1CacheErrorInfo))) 100 /*** outside interface ***/ 101 //val fetch = Vec(PortNumber, new ICacheMainPipeBundle) 102 /* when ftq.valid is high in T + 1 cycle 103 * the ftq component must be valid in T cycle 104 */ 105 val fetch = new ICacheMainPipeBundle 106 val pmp = Vec(PortNumber, new ICachePMPBundle) 107 val respStall = Input(Bool()) 108 109 val csr_parity_enable = Input(Bool()) 110 val flush = Input(Bool()) 111 112 val perfInfo = Output(new ICachePerfInfo) 113} 114 115class ICacheDB(implicit p: Parameters) extends ICacheBundle { 116 val blk_vaddr = UInt((VAddrBits - blockOffBits).W) 117 val blk_paddr = UInt((PAddrBits - blockOffBits).W) 118 val hit = Bool() 119} 120 121class ICacheMainPipe(implicit p: Parameters) extends ICacheModule 122{ 123 val io = IO(new ICacheMainPipeInterface) 124 125 /** Input/Output port */ 126 val (fromFtq, toIFU) = (io.fetch.req, io.fetch.resp) 127 val (toData, fromData) = (io.dataArray.toIData, io.dataArray.fromIData) 128 val (toMSHR, fromMSHR) = (io.mshr.req, io.mshr.resp) 129 val (toPMP, fromPMP) = (io.pmp.map(_.req), io.pmp.map(_.resp)) 130 val fromWayLookup = io.wayLookupRead 131 132 // Statistics on the frequency distribution of FTQ fire interval 133 val cntFtqFireInterval = RegInit(0.U(32.W)) 134 cntFtqFireInterval := Mux(fromFtq.fire, 1.U, cntFtqFireInterval + 1.U) 135 XSPerfHistogram("ftq2icache_fire", 136 cntFtqFireInterval, fromFtq.fire, 137 1, 300, 1, right_strict = true) 138 139 /** pipeline control signal */ 140 val s1_ready, s2_ready = Wire(Bool()) 141 val s0_fire, s1_fire , s2_fire = Wire(Bool()) 142 val s0_flush, s1_flush , s2_flush = Wire(Bool()) 143 144 /** 145 ****************************************************************************** 146 * ICache Stage 0 147 * - send req to data SRAM 148 * - get waymask and tlb info from wayLookup 149 ****************************************************************************** 150 */ 151 152 /** s0 control */ 153 // 0,1,2,3 -> dataArray(data); 4 -> mainPipe 154 // Ftq RegNext Register 155 val fromFtqReq = fromFtq.bits.pcMemRead 156 val s0_valid = fromFtq.valid 157 val s0_req_valid_all = (0 until partWayNum + 1).map(i => fromFtq.bits.readValid(i)) 158 val s0_req_vaddr_all = (0 until partWayNum + 1).map(i => VecInit(Seq(fromFtqReq(i).startAddr, fromFtqReq(i).nextlineStart))) 159 val s0_req_vSetIdx_all = (0 until partWayNum + 1).map(i => VecInit(s0_req_vaddr_all(i).map(get_idx))) 160 val s0_req_offset_all = (0 until partWayNum + 1).map(i => s0_req_vaddr_all(i)(0)(log2Ceil(blockBytes)-1, 0)) 161 val s0_doubleline_all = (0 until partWayNum + 1).map(i => fromFtq.bits.readValid(i) && fromFtqReq(i).crossCacheline) 162 163 val s0_req_vaddr = s0_req_vaddr_all.last 164 val s0_req_vSetIdx = s0_req_vSetIdx_all.last 165 val s0_doubleline = s0_doubleline_all.last 166 167 /** 168 ****************************************************************************** 169 * get waymask and tlb info from wayLookup 170 ****************************************************************************** 171 */ 172 fromWayLookup.ready := s0_fire 173 val s0_waymasks = VecInit(fromWayLookup.bits.waymask.map(_.asTypeOf(Vec(nWays, Bool())))) 174 val s0_req_ptags = fromWayLookup.bits.ptag 175 val s0_req_gpaddr = fromWayLookup.bits.gpaddr 176 val s0_itlb_exception = fromWayLookup.bits.itlb_exception 177 val s0_itlb_pbmt = fromWayLookup.bits.itlb_pbmt 178 val s0_meta_corrupt = fromWayLookup.bits.meta_corrupt 179 val s0_hits = VecInit(fromWayLookup.bits.waymask.map(_.orR)) 180 181 when(s0_fire){ 182 assert((0 until PortNumber).map(i => s0_req_vSetIdx(i) === fromWayLookup.bits.vSetIdx(i)).reduce(_&&_), 183 "vSetIdxs from ftq and wayLookup are different! vaddr0=0x%x ftq: vidx0=0x%x vidx1=0x%x wayLookup: vidx0=0x%x vidx1=0x%x", 184 s0_req_vaddr(0), s0_req_vSetIdx(0), s0_req_vSetIdx(1), fromWayLookup.bits.vSetIdx(0), fromWayLookup.bits.vSetIdx(1)) 185 } 186 187 /** 188 ****************************************************************************** 189 * data SRAM request 190 ****************************************************************************** 191 */ 192 for(i <- 0 until partWayNum) { 193 toData(i).valid := s0_req_valid_all(i) 194 toData(i).bits.isDoubleLine := s0_doubleline_all(i) 195 toData(i).bits.vSetIdx := s0_req_vSetIdx_all(i) 196 toData(i).bits.blkOffset := s0_req_offset_all(i) 197 toData(i).bits.wayMask := s0_waymasks 198 } 199 200 val s0_can_go = toData.last.ready && fromWayLookup.valid && s1_ready 201 s0_flush := io.flush 202 s0_fire := s0_valid && s0_can_go && !s0_flush 203 204 fromFtq.ready := s0_can_go 205 206 /** 207 ****************************************************************************** 208 * ICache Stage 1 209 * - PMP check 210 * - get Data SRAM read responses (latched for pipeline stop) 211 * - monitor missUint response port 212 ****************************************************************************** 213 */ 214 val s1_valid = generatePipeControl(lastFire = s0_fire, thisFire = s1_fire, thisFlush = s1_flush, lastFlush = false.B) 215 216 val s1_req_vaddr = RegEnable(s0_req_vaddr, 0.U.asTypeOf(s0_req_vaddr), s0_fire) 217 val s1_req_ptags = RegEnable(s0_req_ptags, 0.U.asTypeOf(s0_req_ptags), s0_fire) 218 val s1_req_gpaddr = RegEnable(s0_req_gpaddr, 0.U.asTypeOf(s0_req_gpaddr), s0_fire) 219 val s1_doubleline = RegEnable(s0_doubleline, 0.U.asTypeOf(s0_doubleline), s0_fire) 220 val s1_SRAMhits = RegEnable(s0_hits, 0.U.asTypeOf(s0_hits), s0_fire) 221 val s1_itlb_exception = RegEnable(s0_itlb_exception, 0.U.asTypeOf(s0_itlb_exception), s0_fire) 222 val s1_itlb_pbmt = RegEnable(s0_itlb_pbmt, 0.U.asTypeOf(s0_itlb_pbmt), s0_fire) 223 val s1_waymasks = RegEnable(s0_waymasks, 0.U.asTypeOf(s0_waymasks), s0_fire) 224 val s1_meta_corrupt = RegEnable(s0_meta_corrupt, 0.U.asTypeOf(s0_meta_corrupt), s0_fire) 225 226 val s1_req_vSetIdx = s1_req_vaddr.map(get_idx) 227 val s1_req_paddr = s1_req_vaddr.zip(s1_req_ptags).map{case(vaddr, ptag) => get_paddr_from_ptag(vaddr, ptag)} 228 val s1_req_offset = s1_req_vaddr(0)(log2Ceil(blockBytes)-1, 0) 229 230 /** 231 ****************************************************************************** 232 * update replacement status register 233 ****************************************************************************** 234 */ 235 (0 until PortNumber).foreach{ i => 236 io.touch(i).bits.vSetIdx := s1_req_vSetIdx(i) 237 io.touch(i).bits.way := OHToUInt(s1_waymasks(i)) 238 } 239 io.touch(0).valid := RegNext(s0_fire) && s1_SRAMhits(0) 240 io.touch(1).valid := RegNext(s0_fire) && s1_SRAMhits(1) && s1_doubleline 241 242 /** 243 ****************************************************************************** 244 * PMP check 245 ****************************************************************************** 246 */ 247 toPMP.zipWithIndex.foreach { case (p, i) => 248 // if itlb has exception, paddr can be invalid, therefore pmp check can be skipped 249 p.valid := s1_valid // && s1_itlb_exception === ExceptionType.none 250 p.bits.addr := s1_req_paddr(i) 251 p.bits.size := 3.U // TODO 252 p.bits.cmd := TlbCmd.exec 253 } 254 val s1_pmp_exception = VecInit(fromPMP.map(ExceptionType.fromPMPResp)) 255 val s1_pmp_mmio = VecInit(fromPMP.map(_.mmio)) 256 257 // also raise af when meta array corrupt is detected, to cancel fetch 258 val s1_meta_exception = VecInit(s1_meta_corrupt.map(ExceptionType.fromECC(io.csr_parity_enable, _))) 259 260 // merge s1 itlb/pmp/meta exceptions, itlb has the highest priority, pmp next, meta lowest 261 val s1_exception_out = ExceptionType.merge( 262 s1_itlb_exception, 263 s1_pmp_exception, 264 s1_meta_exception 265 ) 266 267 // DO NOT merge pmp mmio and itlb pbmt here, we need them to be passed to IFU separately 268 269 /** 270 ****************************************************************************** 271 * select data from MSHR, SRAM 272 ****************************************************************************** 273 */ 274 val s1_MSHR_match = VecInit((0 until PortNumber).map(i => (s1_req_vSetIdx(i) === fromMSHR.bits.vSetIdx) && 275 (s1_req_ptags(i) === getPhyTagFromBlk(fromMSHR.bits.blkPaddr)) && 276 fromMSHR.valid && !fromMSHR.bits.corrupt)) 277 val s1_MSHR_hits = Seq(s1_valid && s1_MSHR_match(0), 278 s1_valid && (s1_MSHR_match(1) && s1_doubleline)) 279 val s1_MSHR_datas = fromMSHR.bits.data.asTypeOf(Vec(ICacheDataBanks, UInt((blockBits/ICacheDataBanks).W))) 280 281 val s1_hits = (0 until PortNumber).map(i => ValidHoldBypass(s1_MSHR_hits(i) || (RegNext(s0_fire) && s1_SRAMhits(i)), s1_fire || s1_flush)) 282 283 val s1_bankIdxLow = s1_req_offset >> log2Ceil(blockBytes/ICacheDataBanks) 284 val s1_bankMSHRHit = VecInit((0 until ICacheDataBanks).map(i => (i.U >= s1_bankIdxLow) && s1_MSHR_hits(0) || 285 (i.U < s1_bankIdxLow) && s1_MSHR_hits(1))) 286 val s1_datas = VecInit((0 until ICacheDataBanks).map(i => DataHoldBypass(Mux(s1_bankMSHRHit(i), s1_MSHR_datas(i), fromData.datas(i)), 287 s1_bankMSHRHit(i) || RegNext(s0_fire)))) 288 val s1_codes = DataHoldBypass(fromData.codes, RegNext(s0_fire)) 289 290 s1_flush := io.flush 291 s1_ready := s2_ready || !s1_valid 292 s1_fire := s1_valid && s2_ready && !s1_flush 293 294 /** 295 ****************************************************************************** 296 * ICache Stage 2 297 * - send request to MSHR if ICache miss 298 * - monitor missUint response port 299 * - response to IFU 300 ****************************************************************************** 301 */ 302 303 val s2_valid = generatePipeControl(lastFire = s1_fire, thisFire = s2_fire, thisFlush = s2_flush, lastFlush = false.B) 304 305 val s2_req_vaddr = RegEnable(s1_req_vaddr, 0.U.asTypeOf(s1_req_vaddr), s1_fire) 306 val s2_req_ptags = RegEnable(s1_req_ptags, 0.U.asTypeOf(s1_req_ptags), s1_fire) 307 val s2_req_gpaddr = RegEnable(s1_req_gpaddr, 0.U.asTypeOf(s1_req_gpaddr), s1_fire) 308 val s2_doubleline = RegEnable(s1_doubleline, 0.U.asTypeOf(s1_doubleline), s1_fire) 309 val s2_exception = RegEnable(s1_exception_out, 0.U.asTypeOf(s1_exception_out), s1_fire) // includes itlb/pmp/meta exception 310 val s2_pmp_mmio = RegEnable(s1_pmp_mmio, 0.U.asTypeOf(s1_pmp_mmio), s1_fire) 311 val s2_itlb_pbmt = RegEnable(s1_itlb_pbmt, 0.U.asTypeOf(s1_itlb_pbmt), s1_fire) 312 313 val s2_req_vSetIdx = s2_req_vaddr.map(get_idx) 314 val s2_req_offset = s2_req_vaddr(0)(log2Ceil(blockBytes)-1, 0) 315 val s2_req_paddr = s2_req_vaddr.zip(s2_req_ptags).map{case(vaddr, ptag) => get_paddr_from_ptag(vaddr, ptag)} 316 317 val s2_SRAMhits = RegEnable(s1_SRAMhits, 0.U.asTypeOf(s1_SRAMhits), s1_fire) 318 val s2_codes = RegEnable(s1_codes, 0.U.asTypeOf(s1_codes), s1_fire) 319 val s2_hits = RegInit(VecInit(Seq.fill(PortNumber)(false.B))) 320 val s2_datas = RegInit(VecInit(Seq.fill(ICacheDataBanks)(0.U((blockBits/ICacheDataBanks).W)))) 321 322 /** 323 ****************************************************************************** 324 * report data parity error 325 ****************************************************************************** 326 */ 327 // check data error 328 val s2_bankSel = getBankSel(s2_req_offset, s2_valid) 329 val s2_bank_corrupt = (0 until ICacheDataBanks).map(i => (encode(s2_datas(i)) =/= s2_codes(i))) 330 val s2_data_corrupt = (0 until PortNumber).map(port => (0 until ICacheDataBanks).map(bank => 331 s2_bank_corrupt(bank) && s2_bankSel(port)(bank).asBool).reduce(_||_) && s2_SRAMhits(port)) 332 // meta error is checked in prefetch pipeline 333 val s2_meta_corrupt = RegEnable(s1_meta_corrupt, 0.U.asTypeOf(s1_meta_corrupt), s1_fire) 334 // send errors to top 335 (0 until PortNumber).map{ i => 336 io.errors(i).valid := io.csr_parity_enable && RegNext(s1_fire) && (s2_meta_corrupt(i) || s2_data_corrupt(i)) 337 io.errors(i).bits.report_to_beu := io.csr_parity_enable && RegNext(s1_fire) && (s2_meta_corrupt(i) || s2_data_corrupt(i)) 338 io.errors(i).bits.paddr := s2_req_paddr(i) 339 io.errors(i).bits.source := DontCare 340 io.errors(i).bits.source.tag := s2_meta_corrupt(i) 341 io.errors(i).bits.source.data := s2_data_corrupt(i) 342 io.errors(i).bits.source.l2 := false.B 343 io.errors(i).bits.opType := DontCare 344 io.errors(i).bits.opType.fetch := true.B 345 } 346 347 /** 348 ****************************************************************************** 349 * monitor missUint response port 350 ****************************************************************************** 351 */ 352 val s2_MSHR_match = VecInit((0 until PortNumber).map( i => 353 (s2_req_vSetIdx(i) === fromMSHR.bits.vSetIdx) && 354 (s2_req_ptags(i) === getPhyTagFromBlk(fromMSHR.bits.blkPaddr)) && 355 fromMSHR.valid // we don't care about whether it's corrupt here 356 )) 357 val s2_MSHR_hits = Seq(s2_valid && s2_MSHR_match(0), 358 s2_valid && s2_MSHR_match(1) && s2_doubleline) 359 val s2_MSHR_datas = fromMSHR.bits.data.asTypeOf(Vec(ICacheDataBanks, UInt((blockBits/ICacheDataBanks).W))) 360 361 val s2_bankIdxLow = s2_req_offset >> log2Ceil(blockBytes/ICacheDataBanks) 362 val s2_bankMSHRHit = VecInit((0 until ICacheDataBanks).map( i => 363 ((i.U >= s2_bankIdxLow) && s2_MSHR_hits(0)) || ((i.U < s2_bankIdxLow) && s2_MSHR_hits(1)) 364 )) 365 366 (0 until ICacheDataBanks).foreach{ i => 367 when(s1_fire) { 368 s2_datas := s1_datas 369 }.elsewhen(s2_bankMSHRHit(i) && !fromMSHR.bits.corrupt) { 370 // if corrupt, no need to update s2_datas (it's wrong anyway), to save power 371 s2_datas(i) := s2_MSHR_datas(i) 372 } 373 } 374 375 (0 until PortNumber).foreach{ i => 376 when(s1_fire) { 377 s2_hits := s1_hits 378 }.elsewhen(s2_MSHR_hits(i)) { 379 // update s2_hits even if it's corrupt, to let s2_fire 380 s2_hits(i) := true.B 381 } 382 } 383 384 val s2_l2_corrupt = RegInit(VecInit(Seq.fill(PortNumber)(false.B))) 385 (0 until PortNumber).foreach{ i => 386 when(s1_fire) { 387 s2_l2_corrupt(i) := false.B 388 }.elsewhen(s2_MSHR_hits(i)) { 389 s2_l2_corrupt(i) := fromMSHR.bits.corrupt 390 } 391 } 392 393 /** 394 ****************************************************************************** 395 * send request to MSHR if ICache miss 396 ****************************************************************************** 397 */ 398 399 // merge pmp mmio and itlb pbmt 400 val s2_mmio = VecInit((s2_pmp_mmio zip s2_itlb_pbmt).map{ case (mmio, pbmt) => 401 mmio || Pbmt.isUncache(pbmt) 402 }) 403 404 /* s2_exception includes itlb pf/gpf/af, pmp af and meta corruption (af), neither of which should be fetched 405 * mmio should not be fetched, it will be fetched by IFU mmio fsm 406 * also, if previous has exception, latter port should also not be fetched 407 */ 408 val s2_miss = VecInit((0 until PortNumber).map { i => 409 !s2_hits(i) && (if (i==0) true.B else s2_doubleline) && 410 s2_exception.take(i+1).map(_ === ExceptionType.none).reduce(_&&_) && 411 s2_mmio.take(i+1).map(!_).reduce(_&&_) 412 }) 413 414 val toMSHRArbiter = Module(new Arbiter(new ICacheMissReq, PortNumber)) 415 416 // To avoid sending duplicate requests. 417 val has_send = RegInit(VecInit(Seq.fill(PortNumber)(false.B))) 418 (0 until PortNumber).foreach{ i => 419 when(s1_fire) { 420 has_send(i) := false.B 421 }.elsewhen(toMSHRArbiter.io.in(i).fire) { 422 has_send(i) := true.B 423 } 424 } 425 426 (0 until PortNumber).map{ i => 427 toMSHRArbiter.io.in(i).valid := s2_valid && s2_miss(i) && !has_send(i) && !s2_flush 428 toMSHRArbiter.io.in(i).bits.blkPaddr := getBlkAddr(s2_req_paddr(i)) 429 toMSHRArbiter.io.in(i).bits.vSetIdx := s2_req_vSetIdx(i) 430 } 431 toMSHR <> toMSHRArbiter.io.out 432 433 XSPerfAccumulate("to_missUnit_stall", toMSHR.valid && !toMSHR.ready) 434 435 val s2_fetch_finish = !s2_miss.reduce(_||_) 436 437 // also raise af if data/l2 corrupt is detected 438 val s2_data_exception = VecInit(s2_data_corrupt.map(ExceptionType.fromECC(io.csr_parity_enable, _))) 439 val s2_l2_exception = VecInit(s2_l2_corrupt.map(ExceptionType.fromECC(true.B, _))) 440 441 // merge s2 exceptions, itlb has the highest priority, meta next, meta/data/l2 lowest (and we dont care about prioritizing between this three) 442 val s2_exception_out = ExceptionType.merge( 443 s2_exception, // includes itlb/pmp/meta exception 444 s2_data_exception, 445 s2_l2_exception 446 ) 447 448 /** 449 ****************************************************************************** 450 * response to IFU 451 ****************************************************************************** 452 */ 453 (0 until PortNumber).foreach{ i => 454 if(i == 0) { 455 toIFU(i).valid := s2_fire 456 toIFU(i).bits.exception := s2_exception_out(i) 457 toIFU(i).bits.pmp_mmio := s2_pmp_mmio(i) // pass pmp_mmio instead of merged mmio to IFU 458 toIFU(i).bits.itlb_pbmt := s2_itlb_pbmt(i) 459 toIFU(i).bits.data := s2_datas.asTypeOf(UInt(blockBits.W)) 460 } else { 461 toIFU(i).valid := s2_fire && s2_doubleline 462 toIFU(i).bits.exception := Mux(s2_doubleline, s2_exception_out(i), ExceptionType.none) 463 toIFU(i).bits.pmp_mmio := s2_pmp_mmio(i) && s2_doubleline 464 toIFU(i).bits.itlb_pbmt := Mux(s2_doubleline, s2_itlb_pbmt(i), Pbmt.pma) 465 toIFU(i).bits.data := DontCare 466 } 467 toIFU(i).bits.vaddr := s2_req_vaddr(i) 468 toIFU(i).bits.paddr := s2_req_paddr(i) 469 toIFU(i).bits.gpaddr := s2_req_gpaddr // Note: toIFU(1).bits.gpaddr is actually DontCare in current design 470 } 471 472 s2_flush := io.flush 473 s2_ready := (s2_fetch_finish && !io.respStall) || !s2_valid 474 s2_fire := s2_valid && s2_fetch_finish && !io.respStall && !s2_flush 475 476 /** 477 ****************************************************************************** 478 * report Tilelink corrupt error 479 ****************************************************************************** 480 */ 481 (0 until PortNumber).map{ i => 482 when(RegNext(s2_fire && s2_l2_corrupt(i))){ 483 io.errors(i).valid := true.B 484 io.errors(i).bits.report_to_beu := false.B // l2 should have report that to bus error unit, no need to do it again 485 io.errors(i).bits.paddr := RegNext(s2_req_paddr(i)) 486 io.errors(i).bits.source.tag := false.B 487 io.errors(i).bits.source.data := false.B 488 io.errors(i).bits.source.l2 := true.B 489 } 490 } 491 492 /** 493 ****************************************************************************** 494 * performance info. TODO: need to simplify the logic 495 ***********************************************************s******************* 496 */ 497 io.perfInfo.only_0_hit := s2_hits(0) && !s2_doubleline 498 io.perfInfo.only_0_miss := !s2_hits(0) && !s2_doubleline 499 io.perfInfo.hit_0_hit_1 := s2_hits(0) && s2_hits(1) && s2_doubleline 500 io.perfInfo.hit_0_miss_1 := s2_hits(0) && !s2_hits(1) && s2_doubleline 501 io.perfInfo.miss_0_hit_1 := !s2_hits(0) && s2_hits(1) && s2_doubleline 502 io.perfInfo.miss_0_miss_1 := !s2_hits(0) && !s2_hits(1) && s2_doubleline 503 io.perfInfo.hit_0_except_1 := s2_hits(0) && (s2_exception(1) =/= ExceptionType.none) && s2_doubleline 504 io.perfInfo.miss_0_except_1 := !s2_hits(0) && (s2_exception(1) =/= ExceptionType.none) && s2_doubleline 505 io.perfInfo.bank_hit(0) := s2_hits(0) 506 io.perfInfo.bank_hit(1) := s2_hits(1) && s2_doubleline 507 io.perfInfo.except_0 := s2_exception(0) =/= ExceptionType.none 508 io.perfInfo.hit := s2_hits(0) && (!s2_doubleline || s2_hits(1)) 509 510 /** <PERF> fetch bubble generated by icache miss */ 511 XSPerfAccumulate("icache_bubble_s2_miss", s2_valid && !s2_fetch_finish ) 512 XSPerfAccumulate("icache_bubble_s0_wayLookup", s0_valid && !fromWayLookup.ready) 513 514 io.fetch.topdownIcacheMiss := !s2_fetch_finish 515 io.fetch.topdownItlbMiss := s0_valid && !fromWayLookup.ready 516 517 // class ICacheTouchDB(implicit p: Parameters) extends ICacheBundle{ 518 // val blkPaddr = UInt((PAddrBits - blockOffBits).W) 519 // val vSetIdx = UInt(idxBits.W) 520 // val waymask = UInt(log2Ceil(nWays).W) 521 // } 522 523 // val isWriteICacheTouchTable = WireInit(Constantin.createRecord("isWriteICacheTouchTable" + p(XSCoreParamsKey).HartId.toString)) 524 // val ICacheTouchTable = ChiselDB.createTable("ICacheTouchTable" + p(XSCoreParamsKey).HartId.toString, new ICacheTouchDB) 525 526 // val ICacheTouchDumpData = Wire(Vec(PortNumber, new ICacheTouchDB)) 527 // (0 until PortNumber).foreach{ i => 528 // ICacheTouchDumpData(i).blkPaddr := getBlkAddr(s2_req_paddr(i)) 529 // ICacheTouchDumpData(i).vSetIdx := s2_req_vSetIdx(i) 530 // ICacheTouchDumpData(i).waymask := OHToUInt(s2_tag_match_vec(i)) 531 // ICacheTouchTable.log( 532 // data = ICacheTouchDumpData(i), 533 // en = io.touch(i).valid, 534 // site = "req_" + i.toString, 535 // clock = clock, 536 // reset = reset 537 // ) 538 // } 539 540 /** 541 ****************************************************************************** 542 * difftest refill check 543 ****************************************************************************** 544 */ 545 if (env.EnableDifftest) { 546 val discards = (0 until PortNumber).map { i => 547 val discard = toIFU(i).bits.exception =/= ExceptionType.none || toIFU(i).bits.pmp_mmio || 548 Pbmt.isUncache(toIFU(i).bits.itlb_pbmt) 549 discard 550 } 551 val blkPaddrAll = s2_req_paddr.map(addr => addr(PAddrBits - 1, blockOffBits) << blockOffBits) 552 (0 until ICacheDataBanks).map { i => 553 val diffMainPipeOut = DifftestModule(new DiffRefillEvent, dontCare = true) 554 diffMainPipeOut.coreid := io.hartId 555 diffMainPipeOut.index := (3 + i).U 556 557 val bankSel = getBankSel(s2_req_offset, s2_valid).reduce(_|_) 558 val lineSel = getLineSel(s2_req_offset) 559 560 diffMainPipeOut.valid := s2_fire && bankSel(i).asBool && Mux(lineSel(i), !discards(1), !discards(0)) 561 diffMainPipeOut.addr := Mux(lineSel(i), blkPaddrAll(1) + (i.U << (log2Ceil(blockBytes/ICacheDataBanks))), 562 blkPaddrAll(0) + (i.U << (log2Ceil(blockBytes/ICacheDataBanks)))) 563 564 diffMainPipeOut.data := s2_datas(i).asTypeOf(diffMainPipeOut.data) 565 diffMainPipeOut.idtfr := DontCare 566 } 567 } 568}