2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.Berkeley for license details.
|
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.rocket
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-10-08 05:15:54 +02:00
|
|
|
import Chisel._
|
2016-09-29 01:10:32 +02:00
|
|
|
import Chisel.ImplicitConversions._
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.config.Parameters
|
|
|
|
import freechips.rocketchip.coreplex.RocketTilesKey
|
|
|
|
import freechips.rocketchip.diplomacy._
|
|
|
|
import freechips.rocketchip.tile._
|
|
|
|
import freechips.rocketchip.tilelink._
|
|
|
|
import freechips.rocketchip.util._
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2017-02-09 22:59:09 +01:00
|
|
|
case class ICacheParams(
|
|
|
|
nSets: Int = 64,
|
|
|
|
nWays: Int = 4,
|
|
|
|
rowBits: Int = 128,
|
2017-03-20 09:29:26 +01:00
|
|
|
nTLBEntries: Int = 32,
|
2017-02-09 22:59:09 +01:00
|
|
|
cacheIdBits: Int = 0,
|
2017-05-23 21:51:48 +02:00
|
|
|
tagECC: Code = new IdentityCode,
|
|
|
|
dataECC: Code = new IdentityCode,
|
2017-04-25 02:14:23 +02:00
|
|
|
itimAddr: Option[BigInt] = None,
|
2017-08-03 02:10:35 +02:00
|
|
|
prefetch: Boolean = false,
|
2017-06-20 17:21:01 +02:00
|
|
|
blockBytes: Int = 64,
|
|
|
|
latency: Int = 2,
|
|
|
|
fetchBytes: Int = 4) extends L1CacheParams {
|
2017-02-09 22:59:09 +01:00
|
|
|
def replacement = new RandomReplacement(nWays)
|
2014-09-01 22:28:58 +02:00
|
|
|
}
|
2014-08-12 03:36:23 +02:00
|
|
|
|
2017-02-09 22:59:09 +01:00
|
|
|
trait HasL1ICacheParameters extends HasL1CacheParameters with HasCoreParameters {
|
|
|
|
val cacheParams = tileParams.icache.get
|
|
|
|
}
|
|
|
|
|
|
|
|
class ICacheReq(implicit p: Parameters) extends CoreBundle()(p) with HasL1ICacheParameters {
|
2016-05-24 02:51:08 +02:00
|
|
|
val addr = UInt(width = vaddrBits)
|
2013-08-12 19:39:11 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 03:49:46 +02:00
|
|
|
class ICacheErrors(implicit p: Parameters) extends CoreBundle()(p)
|
|
|
|
with HasL1ICacheParameters
|
|
|
|
with CanHaveErrors {
|
2017-09-16 03:41:50 +02:00
|
|
|
val correctable = (cacheParams.tagECC.canDetect || cacheParams.dataECC.canDetect).option(Valid(UInt(width = paddrBits)))
|
|
|
|
val uncorrectable = (cacheParams.itimAddr.nonEmpty && cacheParams.dataECC.canDetect).option(Valid(UInt(width = paddrBits)))
|
|
|
|
}
|
|
|
|
|
2017-06-29 06:28:08 +02:00
|
|
|
class ICache(val icacheParams: ICacheParams, val hartid: Int)(implicit p: Parameters) extends LazyModule {
|
2016-12-13 02:38:55 +01:00
|
|
|
lazy val module = new ICacheModule(this)
|
2017-09-14 03:06:03 +02:00
|
|
|
val masterNode = TLClientNode(Seq(TLClientPortParameters(Seq(TLClientParameters(
|
2017-08-03 02:10:35 +02:00
|
|
|
sourceId = IdRange(0, 1 + icacheParams.prefetch.toInt), // 0=refill, 1=hint
|
2017-09-14 03:06:03 +02:00
|
|
|
name = s"Core ${hartid} ICache")))))
|
2017-04-25 02:14:23 +02:00
|
|
|
|
2017-04-27 03:24:39 +02:00
|
|
|
val size = icacheParams.nSets * icacheParams.nWays * icacheParams.blockBytes
|
2017-06-29 06:28:08 +02:00
|
|
|
val device = new SimpleDevice("itim", Seq("sifive,itim0"))
|
2017-04-25 02:14:23 +02:00
|
|
|
val slaveNode = icacheParams.itimAddr.map { itimAddr =>
|
2017-06-20 17:21:01 +02:00
|
|
|
val wordBytes = icacheParams.fetchBytes
|
2017-04-25 02:14:23 +02:00
|
|
|
TLManagerNode(Seq(TLManagerPortParameters(
|
|
|
|
Seq(TLManagerParameters(
|
|
|
|
address = Seq(AddressSet(itimAddr, size-1)),
|
2017-06-28 22:01:40 +02:00
|
|
|
resources = device.reg("mem"),
|
2017-04-25 02:14:23 +02:00
|
|
|
regionType = RegionType.UNCACHED,
|
|
|
|
executable = true,
|
|
|
|
supportsPutFull = TransferSizes(1, wordBytes),
|
2017-05-04 04:29:47 +02:00
|
|
|
supportsPutPartial = TransferSizes(1, wordBytes),
|
2017-04-25 02:14:23 +02:00
|
|
|
supportsGet = TransferSizes(1, wordBytes),
|
|
|
|
fifoId = Some(0))), // requests handled in FIFO order
|
|
|
|
beatBytes = wordBytes,
|
|
|
|
minLatency = 1)))
|
|
|
|
}
|
2016-12-13 02:38:55 +01:00
|
|
|
}
|
|
|
|
|
2017-07-06 08:40:52 +02:00
|
|
|
class ICacheResp(outer: ICache) extends Bundle {
|
|
|
|
val data = UInt(width = outer.icacheParams.fetchBytes*8)
|
2017-08-04 09:37:13 +02:00
|
|
|
val replay = Bool()
|
2017-07-06 08:40:52 +02:00
|
|
|
val ae = Bool()
|
|
|
|
|
|
|
|
override def cloneType = new ICacheResp(outer).asInstanceOf[this.type]
|
|
|
|
}
|
|
|
|
|
2017-08-03 09:52:12 +02:00
|
|
|
class ICachePerfEvents extends Bundle {
|
|
|
|
val acquire = Bool()
|
|
|
|
}
|
|
|
|
|
2016-12-13 02:38:55 +01:00
|
|
|
class ICacheBundle(outer: ICache) extends CoreBundle()(outer.p) {
|
2017-04-27 05:11:43 +02:00
|
|
|
val hartid = UInt(INPUT, hartIdLen)
|
2017-04-25 02:14:23 +02:00
|
|
|
val req = Decoupled(new ICacheReq).flip
|
2017-03-06 06:43:20 +01:00
|
|
|
val s1_paddr = UInt(INPUT, paddrBits) // delayed one cycle w.r.t. req
|
2017-04-25 02:14:23 +02:00
|
|
|
val s2_vaddr = UInt(INPUT, vaddrBits) // delayed two cycles w.r.t. req
|
2016-12-13 02:38:55 +01:00
|
|
|
val s1_kill = Bool(INPUT) // delayed one cycle w.r.t. req
|
|
|
|
val s2_kill = Bool(INPUT) // delayed two cycles; prevents I$ miss emission
|
2017-08-03 02:10:35 +02:00
|
|
|
val s2_prefetch = Bool(INPUT) // should I$ prefetch next line on a miss?
|
2016-12-13 02:38:55 +01:00
|
|
|
|
2017-07-06 08:40:52 +02:00
|
|
|
val resp = Valid(new ICacheResp(outer))
|
2016-12-13 02:38:55 +01:00
|
|
|
val invalidate = Bool(INPUT)
|
2017-08-03 09:52:12 +02:00
|
|
|
|
2017-09-16 03:41:50 +02:00
|
|
|
val errors = new ICacheErrors
|
2017-08-03 09:52:12 +02:00
|
|
|
val perf = new ICachePerfEvents().asOutput
|
2017-04-25 02:14:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// get a tile-specific property without breaking deduplication
|
|
|
|
object GetPropertyByHartId {
|
|
|
|
def apply[T <: Data](tiles: Seq[RocketTileParams], f: RocketTileParams => Option[T], hartId: UInt): T = {
|
|
|
|
PriorityMux(tiles.zipWithIndex.collect { case (t, i) if f(t).nonEmpty => (hartId === i) -> f(t).get })
|
|
|
|
}
|
2016-12-13 02:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class ICacheModule(outer: ICache) extends LazyModuleImp(outer)
|
2017-02-09 22:59:09 +01:00
|
|
|
with HasL1ICacheParameters {
|
2017-06-20 17:21:01 +02:00
|
|
|
override val cacheParams = outer.icacheParams // Use the local parameters
|
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
val io = IO(new ICacheBundle(outer))
|
|
|
|
val (tl_out, edge_out) = outer.masterNode.out(0)
|
|
|
|
val tl_in = outer.slaveNode.map(_.in(0)._1)
|
|
|
|
val edge_in = outer.slaveNode.map(_.in(0)._2)
|
2016-04-02 04:30:39 +02:00
|
|
|
|
2017-05-23 21:51:48 +02:00
|
|
|
val tECC = cacheParams.tagECC
|
|
|
|
val dECC = cacheParams.dataECC
|
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
require(isPow2(nSets) && isPow2(nWays))
|
2016-05-24 02:51:08 +02:00
|
|
|
require(!usingVM || pgIdxBits >= untagBits)
|
2012-01-25 00:13:49 +01:00
|
|
|
|
2017-04-25 02:14:23 +02:00
|
|
|
val scratchpadOn = RegInit(false.B)
|
2017-04-27 07:43:00 +02:00
|
|
|
val scratchpadMax = tl_in.map(tl => Reg(UInt(width = log2Ceil(nSets * (nWays - 1)))))
|
|
|
|
def lineInScratchpad(line: UInt) = scratchpadMax.map(scratchpadOn && line <= _).getOrElse(false.B)
|
2017-09-16 03:41:50 +02:00
|
|
|
val scratchpadBase = outer.icacheParams.itimAddr.map { dummy =>
|
|
|
|
GetPropertyByHartId(p(RocketTilesKey), _.icache.flatMap(_.itimAddr.map(_.U)), io.hartid)
|
2017-04-25 02:14:23 +02:00
|
|
|
}
|
2017-09-16 03:41:50 +02:00
|
|
|
def addrMaybeInScratchpad(addr: UInt) = scratchpadBase.map(base => addr >= base && addr < base + outer.size).getOrElse(false.B)
|
2017-04-25 02:14:23 +02:00
|
|
|
def addrInScratchpad(addr: UInt) = addrMaybeInScratchpad(addr) && lineInScratchpad(addr(untagBits+log2Ceil(nWays)-1, blockOffBits))
|
2017-04-27 07:43:00 +02:00
|
|
|
def scratchpadWay(addr: UInt) = addr.extract(untagBits+log2Ceil(nWays)-1, untagBits)
|
2017-04-25 02:14:23 +02:00
|
|
|
def scratchpadWayValid(way: UInt) = way < nWays - 1
|
|
|
|
def scratchpadLine(addr: UInt) = addr(untagBits+log2Ceil(nWays)-1, blockOffBits)
|
|
|
|
val s0_slaveValid = tl_in.map(_.a.fire()).getOrElse(false.B)
|
|
|
|
val s1_slaveValid = RegNext(s0_slaveValid, false.B)
|
|
|
|
val s2_slaveValid = RegNext(s1_slaveValid, false.B)
|
2017-05-02 02:41:25 +02:00
|
|
|
val s3_slaveValid = RegNext(false.B)
|
2017-04-25 02:14:23 +02:00
|
|
|
|
2017-06-02 23:52:52 +02:00
|
|
|
val s1_valid = Reg(init=Bool(false))
|
|
|
|
val s1_tag_hit = Wire(Vec(nWays, Bool()))
|
|
|
|
val s1_hit = s1_tag_hit.reduce(_||_) || Mux(s1_slaveValid, true.B, addrMaybeInScratchpad(io.s1_paddr))
|
|
|
|
val s2_valid = RegNext(s1_valid && !io.s1_kill, Bool(false))
|
|
|
|
val s2_hit = RegNext(s1_hit)
|
2012-10-10 06:35:03 +02:00
|
|
|
|
2017-06-02 23:52:52 +02:00
|
|
|
val invalidated = Reg(Bool())
|
|
|
|
val refill_valid = RegInit(false.B)
|
2017-08-03 02:10:35 +02:00
|
|
|
val send_hint = RegInit(false.B)
|
|
|
|
val refill_fire = tl_out.a.fire() && !send_hint
|
|
|
|
val hint_outstanding = RegInit(false.B)
|
2017-06-02 23:52:52 +02:00
|
|
|
val s2_miss = s2_valid && !s2_hit && !io.s2_kill && !RegNext(refill_valid)
|
|
|
|
val refill_addr = RegEnable(io.s1_paddr, s1_valid && !(refill_valid || s2_miss))
|
2017-04-25 02:14:23 +02:00
|
|
|
val refill_tag = refill_addr(tagBits+untagBits-1,untagBits)
|
|
|
|
val refill_idx = refill_addr(untagBits-1,blockOffBits)
|
2017-08-03 02:10:35 +02:00
|
|
|
val refill_one_beat = tl_out.d.fire() && edge_out.hasData(tl_out.d.bits)
|
2017-03-06 06:43:20 +01:00
|
|
|
|
2017-08-03 02:10:35 +02:00
|
|
|
io.req.ready := !(refill_one_beat || s0_slaveValid || s3_slaveValid)
|
2017-04-25 02:14:23 +02:00
|
|
|
val s0_valid = io.req.fire()
|
2017-03-06 06:43:20 +01:00
|
|
|
val s0_vaddr = io.req.bits.addr
|
2017-04-20 01:51:39 +02:00
|
|
|
s1_valid := s0_valid
|
2012-10-10 06:35:03 +02:00
|
|
|
|
2017-08-03 02:10:35 +02:00
|
|
|
val (_, _, d_done, refill_cnt) = edge_out.count(tl_out.d)
|
|
|
|
val refill_done = refill_one_beat && d_done
|
2017-04-25 02:14:23 +02:00
|
|
|
tl_out.d.ready := !s3_slaveValid
|
|
|
|
require (edge_out.manager.minLatency > 0)
|
|
|
|
|
|
|
|
val repl_way = if (isDM) UInt(0) else {
|
|
|
|
// pick a way that is not used by the scratchpad
|
2017-08-03 02:10:35 +02:00
|
|
|
val v0 = LFSR16(refill_fire)(log2Up(nWays)-1,0)
|
2017-04-25 02:14:23 +02:00
|
|
|
var v = v0
|
|
|
|
for (i <- log2Ceil(nWays) - 1 to 0 by -1) {
|
|
|
|
val mask = nWays - (BigInt(1) << (i + 1))
|
|
|
|
v = v | (lineInScratchpad(Cat(v0 | mask.U, refill_idx)) << i)
|
|
|
|
}
|
|
|
|
assert(!lineInScratchpad(Cat(v, refill_idx)))
|
|
|
|
v
|
|
|
|
}
|
2012-10-10 06:35:03 +02:00
|
|
|
|
2017-09-22 03:02:32 +02:00
|
|
|
val tag_array = SeqMem(nSets, Vec(nWays, UInt(width = tECC.width(1 + tagBits))))
|
|
|
|
val tag_rdata = tag_array.read(s0_vaddr(untagBits-1,blockOffBits), !refill_done && s0_valid)
|
2017-07-06 08:40:52 +02:00
|
|
|
val accruedRefillError = Reg(Bool())
|
|
|
|
val refillError = tl_out.d.bits.error || (refill_cnt > 0 && accruedRefillError)
|
2012-10-10 06:35:03 +02:00
|
|
|
when (refill_done) {
|
2017-07-06 20:16:56 +02:00
|
|
|
val enc_tag = tECC.encode(Cat(refillError, refill_tag))
|
2017-09-22 03:02:32 +02:00
|
|
|
tag_array.write(refill_idx, Vec.fill(nWays)(enc_tag), Seq.tabulate(nWays)(repl_way === _))
|
2012-11-05 01:39:25 +01:00
|
|
|
}
|
2012-07-12 23:50:12 +02:00
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
val vb_array = Reg(init=Bits(0, nSets*nWays))
|
2017-08-03 02:10:35 +02:00
|
|
|
when (refill_one_beat) {
|
2017-07-06 08:40:52 +02:00
|
|
|
accruedRefillError := refillError
|
2017-04-25 02:14:23 +02:00
|
|
|
// clear bit when refill starts so hit-under-miss doesn't fetch bad data
|
|
|
|
vb_array := vb_array.bitSet(Cat(repl_way, refill_idx), refill_done && !invalidated)
|
2012-10-10 06:35:03 +02:00
|
|
|
}
|
2017-04-03 09:45:26 +02:00
|
|
|
val invalidate = Wire(init = io.invalidate)
|
|
|
|
when (invalidate) {
|
2012-07-12 23:50:12 +02:00
|
|
|
vb_array := Bits(0)
|
2012-10-10 06:35:03 +02:00
|
|
|
invalidated := Bool(true)
|
2012-07-12 23:50:12 +02:00
|
|
|
}
|
2012-10-10 06:35:03 +02:00
|
|
|
|
2017-04-03 09:45:26 +02:00
|
|
|
val s1_tag_disparity = Wire(Vec(nWays, Bool()))
|
2017-07-06 20:16:56 +02:00
|
|
|
val s1_tl_error = Wire(Vec(nWays, Bool()))
|
2017-06-20 17:21:01 +02:00
|
|
|
val wordBits = outer.icacheParams.fetchBytes*8
|
2017-05-23 21:51:48 +02:00
|
|
|
val s1_dout = Wire(Vec(nWays, UInt(width = dECC.width(wordBits))))
|
2012-11-25 07:00:43 +01:00
|
|
|
|
2017-04-27 03:24:39 +02:00
|
|
|
val s0_slaveAddr = tl_in.map(_.a.bits.address).getOrElse(0.U)
|
|
|
|
val s1s3_slaveAddr = Reg(UInt(width = log2Ceil(outer.size)))
|
|
|
|
val s1s3_slaveData = Reg(UInt(width = wordBits))
|
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
for (i <- 0 until nWays) {
|
2017-04-25 02:14:23 +02:00
|
|
|
val s1_idx = io.s1_paddr(untagBits-1,blockOffBits)
|
|
|
|
val s1_tag = io.s1_paddr(tagBits+untagBits-1,untagBits)
|
2017-04-27 07:43:00 +02:00
|
|
|
val scratchpadHit = scratchpadWayValid(i) &&
|
2017-04-25 02:14:23 +02:00
|
|
|
Mux(s1_slaveValid,
|
|
|
|
lineInScratchpad(scratchpadLine(s1s3_slaveAddr)) && scratchpadWay(s1s3_slaveAddr) === i,
|
|
|
|
addrInScratchpad(io.s1_paddr) && scratchpadWay(io.s1_paddr) === i)
|
|
|
|
val s1_vb = vb_array(Cat(UInt(i), s1_idx)) && !s1_slaveValid
|
2017-07-06 20:16:56 +02:00
|
|
|
val enc_tag = tECC.decode(tag_rdata(i))
|
|
|
|
val (tl_error, tag) = Split(enc_tag.uncorrected, tagBits)
|
2017-07-06 08:40:52 +02:00
|
|
|
val tagMatch = s1_vb && tag === s1_tag
|
2017-07-06 20:16:56 +02:00
|
|
|
s1_tag_disparity(i) := s1_vb && enc_tag.error
|
|
|
|
s1_tl_error(i) := tagMatch && tl_error.toBool
|
2017-07-06 08:40:52 +02:00
|
|
|
s1_tag_hit(i) := tagMatch || scratchpadHit
|
2012-10-10 06:35:03 +02:00
|
|
|
}
|
2017-04-25 02:14:23 +02:00
|
|
|
assert(!(s1_valid || s1_slaveValid) || PopCount(s1_tag_hit zip s1_tag_disparity map { case (h, d) => h && !d }) <= 1)
|
2012-10-10 06:35:03 +02:00
|
|
|
|
2017-04-25 02:14:23 +02:00
|
|
|
require(tl_out.d.bits.data.getWidth % wordBits == 0)
|
2017-09-22 03:02:32 +02:00
|
|
|
val data_arrays = Seq.fill(tl_out.d.bits.data.getWidth / wordBits) { SeqMem(nSets * refillCycles, Vec(nWays, UInt(width = dECC.width(wordBits)))) }
|
|
|
|
for ((data_array, i) <- data_arrays zipWithIndex) {
|
2017-04-25 02:14:23 +02:00
|
|
|
def wordMatch(addr: UInt) = addr.extract(log2Ceil(tl_out.d.bits.data.getWidth/8)-1, log2Ceil(wordBits/8)) === i
|
|
|
|
def row(addr: UInt) = addr(untagBits-1, blockOffBits-log2Ceil(refillCycles))
|
|
|
|
val s0_ren = (s0_valid && wordMatch(s0_vaddr)) || (s0_slaveValid && wordMatch(s0_slaveAddr))
|
2017-08-03 02:10:35 +02:00
|
|
|
val wen = (refill_one_beat && !invalidated) || (s3_slaveValid && wordMatch(s1s3_slaveAddr))
|
|
|
|
val mem_idx = Mux(refill_one_beat, (refill_idx << log2Ceil(refillCycles)) | refill_cnt,
|
2017-04-25 02:14:23 +02:00
|
|
|
Mux(s3_slaveValid, row(s1s3_slaveAddr),
|
|
|
|
Mux(s0_slaveValid, row(s0_slaveAddr),
|
|
|
|
row(s0_vaddr))))
|
2017-04-19 02:55:04 +02:00
|
|
|
when (wen) {
|
2017-04-25 02:14:23 +02:00
|
|
|
val data = Mux(s3_slaveValid, s1s3_slaveData, tl_out.d.bits.data(wordBits*(i+1)-1, wordBits*i))
|
|
|
|
val way = Mux(s3_slaveValid, scratchpadWay(s1s3_slaveAddr), repl_way)
|
2017-05-23 21:51:48 +02:00
|
|
|
data_array.write(mem_idx, Vec.fill(nWays)(dECC.encode(data)), (0 until nWays).map(way === _))
|
2017-04-19 02:55:04 +02:00
|
|
|
}
|
2017-04-25 02:14:23 +02:00
|
|
|
val dout = data_array.read(mem_idx, !wen && s0_ren)
|
|
|
|
when (wordMatch(Mux(s1_slaveValid, s1s3_slaveAddr, io.s1_paddr))) {
|
2017-04-19 02:55:04 +02:00
|
|
|
s1_dout := dout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-07 09:58:25 +01:00
|
|
|
// output signals
|
2017-06-20 17:21:01 +02:00
|
|
|
outer.icacheParams.latency match {
|
2016-07-14 21:38:54 +02:00
|
|
|
case 1 =>
|
2017-07-07 19:48:16 +02:00
|
|
|
require(tECC.isInstanceOf[IdentityCode])
|
|
|
|
require(dECC.isInstanceOf[IdentityCode])
|
2017-04-25 02:14:23 +02:00
|
|
|
require(outer.icacheParams.itimAddr.isEmpty)
|
2017-07-06 08:40:52 +02:00
|
|
|
io.resp.bits.data := Mux1H(s1_tag_hit, s1_dout)
|
2017-07-06 20:16:56 +02:00
|
|
|
io.resp.bits.ae := s1_tl_error.asUInt.orR
|
2017-06-02 23:52:52 +02:00
|
|
|
io.resp.valid := s1_valid && s1_hit
|
2017-04-25 02:14:23 +02:00
|
|
|
|
2016-07-14 21:38:54 +02:00
|
|
|
case 2 =>
|
2017-09-16 03:41:50 +02:00
|
|
|
val s1_clk_en = s1_valid || s1_slaveValid
|
|
|
|
val s2_tag_hit = RegEnable(s1_tag_hit, s1_clk_en)
|
|
|
|
val s2_hit_way = OHToUInt(s2_tag_hit)
|
|
|
|
val s2_scratchpad_word_addr = Cat(s2_hit_way, io.s2_vaddr(untagBits-1, log2Ceil(wordBits/8)), UInt(0, log2Ceil(wordBits/8)))
|
|
|
|
val s2_dout = RegEnable(s1_dout, s1_clk_en)
|
2017-04-03 09:45:26 +02:00
|
|
|
val s2_way_mux = Mux1H(s2_tag_hit, s2_dout)
|
|
|
|
|
2017-09-16 03:41:50 +02:00
|
|
|
val s2_tag_disparity = RegEnable(s1_tag_disparity, s1_clk_en).asUInt.orR
|
|
|
|
val s2_tl_error = RegEnable(s1_tl_error.asUInt.orR, s1_clk_en)
|
2017-05-23 21:51:48 +02:00
|
|
|
val s2_data_decoded = dECC.decode(s2_way_mux)
|
2017-04-25 02:14:23 +02:00
|
|
|
val s2_disparity = s2_tag_disparity || s2_data_decoded.error
|
2017-04-03 09:45:26 +02:00
|
|
|
when (s2_valid && s2_disparity) { invalidate := true }
|
|
|
|
|
2017-07-06 08:40:52 +02:00
|
|
|
io.resp.bits.data := s2_data_decoded.uncorrected
|
2017-07-06 20:16:56 +02:00
|
|
|
io.resp.bits.ae := s2_tl_error
|
2017-08-04 09:37:13 +02:00
|
|
|
io.resp.bits.replay := s2_disparity
|
|
|
|
io.resp.valid := s2_valid && s2_hit
|
2017-04-25 02:14:23 +02:00
|
|
|
|
2017-09-16 03:41:50 +02:00
|
|
|
val s1_scratchpad_hit = Mux(s1_slaveValid, lineInScratchpad(scratchpadLine(s1s3_slaveAddr)), addrInScratchpad(io.s1_paddr))
|
|
|
|
val s2_scratchpad_hit = RegEnable(s1_scratchpad_hit, s1_clk_en)
|
|
|
|
io.errors.correctable.foreach { c =>
|
|
|
|
c.valid := s2_valid && Mux(s2_scratchpad_hit, s2_data_decoded.correctable, s2_disparity)
|
|
|
|
c.bits := 0.U
|
|
|
|
}
|
|
|
|
io.errors.uncorrectable.foreach { u =>
|
|
|
|
u.valid := s2_valid && s2_scratchpad_hit && s2_data_decoded.uncorrectable
|
|
|
|
u.bits := scratchpadBase.get + s2_scratchpad_word_addr
|
|
|
|
}
|
|
|
|
|
2017-04-25 02:14:23 +02:00
|
|
|
tl_in.map { tl =>
|
2017-05-04 09:24:13 +02:00
|
|
|
val respValid = RegInit(false.B)
|
|
|
|
tl.a.ready := !(tl_out.d.valid || s1_slaveValid || s2_slaveValid || s3_slaveValid || respValid)
|
2017-04-25 02:14:23 +02:00
|
|
|
val s1_a = RegEnable(tl.a.bits, s0_slaveValid)
|
|
|
|
when (s0_slaveValid) {
|
|
|
|
val a = tl.a.bits
|
|
|
|
s1s3_slaveAddr := tl.a.bits.address
|
|
|
|
s1s3_slaveData := tl.a.bits.data
|
|
|
|
when (edge_in.get.hasData(a)) {
|
|
|
|
val enable = scratchpadWayValid(scratchpadWay(a.address))
|
|
|
|
when (!lineInScratchpad(scratchpadLine(a.address))) {
|
2017-04-27 07:43:00 +02:00
|
|
|
scratchpadMax.get := scratchpadLine(a.address)
|
2017-04-25 02:14:23 +02:00
|
|
|
when (enable) { invalidate := true }
|
|
|
|
}
|
|
|
|
scratchpadOn := enable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!s2_valid || RegNext(RegNext(s0_vaddr)) === io.s2_vaddr)
|
2017-05-04 09:24:13 +02:00
|
|
|
when (!(tl.a.valid || s1_slaveValid || s2_slaveValid || respValid)
|
2017-04-25 02:14:23 +02:00
|
|
|
&& s2_valid && s2_data_decoded.correctable && !s2_tag_disparity) {
|
|
|
|
// handle correctable errors on CPU accesses to the scratchpad.
|
|
|
|
// if there is an in-flight slave-port access to the scratchpad,
|
|
|
|
// report the a miss but don't correct the error (as there is
|
|
|
|
// a structural hazard on s1s3_slaveData/s1s3_slaveAddress).
|
|
|
|
s3_slaveValid := true
|
|
|
|
s1s3_slaveData := s2_data_decoded.corrected
|
2017-09-16 03:41:50 +02:00
|
|
|
s1s3_slaveAddr := s2_scratchpad_word_addr | s1s3_slaveAddr(log2Ceil(wordBits/8)-1, 0)
|
2017-04-25 02:14:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
respValid := s2_slaveValid || (respValid && !tl.d.ready)
|
|
|
|
when (s2_slaveValid) {
|
2017-05-02 02:41:25 +02:00
|
|
|
when (edge_in.get.hasData(s1_a) || s2_data_decoded.correctable) { s3_slaveValid := true }
|
2017-04-25 02:14:23 +02:00
|
|
|
def byteEn(i: Int) = !(edge_in.get.hasData(s1_a) && s1_a.mask(i))
|
|
|
|
s1s3_slaveData := (0 until wordBits/8).map(i => Mux(byteEn(i), s2_data_decoded.corrected, s1s3_slaveData)(8*(i+1)-1, 8*i)).asUInt
|
|
|
|
}
|
|
|
|
|
|
|
|
tl.d.valid := respValid
|
|
|
|
tl.d.bits := Mux(edge_in.get.hasData(s1_a),
|
2017-07-27 01:01:21 +02:00
|
|
|
edge_in.get.AccessAck(s1_a),
|
|
|
|
edge_in.get.AccessAck(s1_a, UInt(0)))
|
2017-04-25 02:14:23 +02:00
|
|
|
tl.d.bits.data := s1s3_slaveData
|
|
|
|
|
|
|
|
// Tie off unused channels
|
|
|
|
tl.b.valid := false
|
|
|
|
tl.c.ready := true
|
|
|
|
tl.e.ready := true
|
|
|
|
}
|
2015-12-03 02:17:49 +01:00
|
|
|
}
|
2017-08-03 02:10:35 +02:00
|
|
|
|
2017-06-02 23:52:52 +02:00
|
|
|
tl_out.a.valid := s2_miss && !refill_valid
|
2017-04-25 02:14:23 +02:00
|
|
|
tl_out.a.bits := edge_out.Get(
|
2016-12-13 02:38:55 +01:00
|
|
|
fromSource = UInt(0),
|
|
|
|
toAddress = (refill_addr >> blockOffBits) << blockOffBits,
|
|
|
|
lgSize = lgCacheBlockBytes)._2
|
2017-08-03 02:10:35 +02:00
|
|
|
if (cacheParams.prefetch) {
|
|
|
|
val (crosses_page, next_block) = Split(refill_addr(pgIdxBits-1, blockOffBits) +& 1, pgIdxBits-blockOffBits)
|
|
|
|
when (tl_out.a.fire()) {
|
|
|
|
send_hint := !hint_outstanding && io.s2_prefetch && !crosses_page
|
|
|
|
when (send_hint) {
|
|
|
|
send_hint := false
|
|
|
|
hint_outstanding := true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
when (refill_done) {
|
|
|
|
send_hint := false
|
|
|
|
}
|
|
|
|
when (tl_out.d.fire() && !refill_one_beat) {
|
|
|
|
hint_outstanding := false
|
|
|
|
}
|
|
|
|
|
|
|
|
when (send_hint) {
|
|
|
|
tl_out.a.valid := true
|
|
|
|
tl_out.a.bits := edge_out.Hint(
|
|
|
|
fromSource = UInt(1),
|
|
|
|
toAddress = Cat(refill_addr >> pgIdxBits, next_block) << blockOffBits,
|
|
|
|
lgSize = lgCacheBlockBytes,
|
|
|
|
param = TLHints.PREFETCH_READ)._2
|
|
|
|
}
|
|
|
|
}
|
2017-03-20 01:18:50 +01:00
|
|
|
tl_out.b.ready := Bool(true)
|
2016-12-13 02:38:55 +01:00
|
|
|
tl_out.c.valid := Bool(false)
|
|
|
|
tl_out.e.valid := Bool(false)
|
2017-04-25 02:14:23 +02:00
|
|
|
assert(!(tl_out.a.valid && addrMaybeInScratchpad(tl_out.a.bits.address)))
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2017-06-02 23:52:52 +02:00
|
|
|
when (!refill_valid) { invalidated := false.B }
|
2017-08-03 02:10:35 +02:00
|
|
|
when (refill_fire) { refill_valid := true.B }
|
2017-06-02 23:52:52 +02:00
|
|
|
when (refill_done) { refill_valid := false.B}
|
2017-08-03 09:52:12 +02:00
|
|
|
|
|
|
|
io.perf.acquire := refill_fire
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|