2014-09-13 00:31:38 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
2014-04-23 01:55:35 +02:00
|
|
|
package uncore
|
|
|
|
import Chisel._
|
2015-03-24 10:06:53 +01:00
|
|
|
import scala.reflect.ClassTag
|
2015-07-30 03:04:30 +02:00
|
|
|
import junctions._
|
2015-10-22 03:16:44 +02:00
|
|
|
import cde.{Parameters, Field}
|
2014-04-23 01:55:35 +02:00
|
|
|
|
2014-08-23 10:19:36 +02:00
|
|
|
case object CacheName extends Field[String]
|
2014-08-08 21:21:57 +02:00
|
|
|
case object NSets extends Field[Int]
|
|
|
|
case object NWays extends Field[Int]
|
|
|
|
case object RowBits extends Field[Int]
|
|
|
|
case object Replacer extends Field[() => ReplacementPolicy]
|
2015-12-11 01:40:16 +01:00
|
|
|
case object L2Replacer extends Field[() => SeqReplacementPolicy]
|
2015-02-02 04:57:53 +01:00
|
|
|
case object AmoAluOperandBits extends Field[Int]
|
2015-03-18 06:53:50 +01:00
|
|
|
case object NPrimaryMisses extends Field[Int]
|
|
|
|
case object NSecondaryMisses extends Field[Int]
|
2015-03-11 23:43:41 +01:00
|
|
|
case object CacheBlockBytes extends Field[Int]
|
|
|
|
case object CacheBlockOffsetBits extends Field[Int]
|
2015-04-04 02:24:44 +02:00
|
|
|
case object ECCCode extends Field[Option[Code]]
|
2015-11-22 00:55:11 +01:00
|
|
|
case object CacheIdBits extends Field[Int]
|
|
|
|
case object CacheId extends Field[Int]
|
2016-02-29 23:48:49 +01:00
|
|
|
case object SplitMetadata extends Field[Boolean]
|
2014-05-07 10:51:46 +02:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasCacheParameters {
|
|
|
|
implicit val p: Parameters
|
|
|
|
val nSets = p(NSets)
|
|
|
|
val blockOffBits = p(CacheBlockOffsetBits)
|
2015-11-22 00:55:11 +01:00
|
|
|
val cacheIdBits = p(CacheIdBits)
|
2014-08-12 03:35:49 +02:00
|
|
|
val idxBits = log2Up(nSets)
|
2015-11-22 00:55:11 +01:00
|
|
|
val untagBits = blockOffBits + cacheIdBits + idxBits
|
2015-10-06 06:41:46 +02:00
|
|
|
val tagBits = p(PAddrBits) - untagBits
|
|
|
|
val nWays = p(NWays)
|
2014-08-12 03:35:49 +02:00
|
|
|
val wayBits = log2Up(nWays)
|
|
|
|
val isDM = nWays == 1
|
2015-10-06 06:41:46 +02:00
|
|
|
val rowBits = p(RowBits)
|
2014-08-12 23:55:44 +02:00
|
|
|
val rowBytes = rowBits/8
|
2014-08-12 03:35:49 +02:00
|
|
|
val rowOffBits = log2Up(rowBytes)
|
2015-10-06 06:41:46 +02:00
|
|
|
val code = p(ECCCode).getOrElse(new IdentityCode)
|
2016-02-29 23:48:49 +01:00
|
|
|
val hasSplitMetadata = p(SplitMetadata)
|
2014-08-12 03:35:49 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
abstract class CacheModule(implicit val p: Parameters) extends Module
|
|
|
|
with HasCacheParameters
|
|
|
|
abstract class CacheBundle(implicit val p: Parameters) extends ParameterizedBundle()(p)
|
|
|
|
with HasCacheParameters
|
2014-08-12 03:35:49 +02:00
|
|
|
|
2014-04-23 01:55:35 +02:00
|
|
|
abstract class ReplacementPolicy {
|
|
|
|
def way: UInt
|
|
|
|
def miss: Unit
|
|
|
|
def hit: Unit
|
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class RandomReplacement(ways: Int) extends ReplacementPolicy {
|
2015-07-16 05:24:03 +02:00
|
|
|
private val replace = Wire(Bool())
|
2014-04-23 01:55:35 +02:00
|
|
|
replace := Bool(false)
|
|
|
|
val lfsr = LFSR16(replace)
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
def way = if(ways == 1) UInt(0) else lfsr(log2Up(ways)-1,0)
|
2014-04-23 01:55:35 +02:00
|
|
|
def miss = replace := Bool(true)
|
|
|
|
def hit = {}
|
|
|
|
}
|
|
|
|
|
2015-12-11 01:40:16 +01:00
|
|
|
abstract class SeqReplacementPolicy {
|
|
|
|
def access(set: UInt): Unit
|
|
|
|
def update(valid: Bool, hit: Bool, set: UInt, way: UInt): Unit
|
|
|
|
def way: UInt
|
|
|
|
}
|
|
|
|
|
|
|
|
class SeqRandom(n_ways: Int) extends SeqReplacementPolicy {
|
|
|
|
val logic = new RandomReplacement(n_ways)
|
|
|
|
def access(set: UInt) = { }
|
|
|
|
def update(valid: Bool, hit: Bool, set: UInt, way: UInt) = {
|
|
|
|
when (valid && !hit) { logic.miss }
|
|
|
|
}
|
|
|
|
def way = logic.way
|
|
|
|
}
|
|
|
|
|
|
|
|
class PseudoLRU(n: Int)
|
|
|
|
{
|
|
|
|
val state_reg = Reg(Bits(width = n))
|
|
|
|
def access(way: UInt) {
|
|
|
|
state_reg := get_next_state(state_reg,way)
|
|
|
|
}
|
2016-01-13 00:30:26 +01:00
|
|
|
def get_next_state(state: UInt, way: UInt) = {
|
2015-12-11 01:40:16 +01:00
|
|
|
var next_state = state
|
|
|
|
var idx = UInt(1,1)
|
|
|
|
for (i <- log2Up(n)-1 to 0 by -1) {
|
|
|
|
val bit = way(i)
|
|
|
|
val mask = (UInt(1,n) << idx)(n-1,0)
|
|
|
|
next_state = next_state & ~mask | Mux(bit, UInt(0), mask)
|
|
|
|
//next_state.bitSet(idx, !bit)
|
|
|
|
idx = Cat(idx, bit)
|
|
|
|
}
|
|
|
|
next_state
|
|
|
|
}
|
|
|
|
def replace = get_replace_way(state_reg)
|
|
|
|
def get_replace_way(state: Bits) = {
|
|
|
|
var idx = UInt(1,1)
|
|
|
|
for (i <- 0 until log2Up(n))
|
|
|
|
idx = Cat(idx, state(idx))
|
|
|
|
idx(log2Up(n)-1,0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SeqPLRU(n_sets: Int, n_ways: Int) extends SeqReplacementPolicy {
|
2016-01-14 22:47:47 +01:00
|
|
|
val state = SeqMem(n_sets, Bits(width = n_ways-1))
|
2015-12-11 01:40:16 +01:00
|
|
|
val logic = new PseudoLRU(n_ways)
|
|
|
|
val current_state = Wire(Bits())
|
|
|
|
val plru_way = logic.get_replace_way(current_state)
|
|
|
|
val next_state = Wire(Bits())
|
|
|
|
|
|
|
|
def access(set: UInt) = {
|
|
|
|
current_state := Cat(state.read(set), Bits(0, width = 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
def update(valid: Bool, hit: Bool, set: UInt, way: UInt) = {
|
|
|
|
val update_way = Mux(hit, way, plru_way)
|
|
|
|
next_state := logic.get_next_state(current_state, update_way)
|
|
|
|
when (valid) { state.write(set, next_state(n_ways-1,1)) }
|
|
|
|
}
|
|
|
|
|
|
|
|
def way = plru_way
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
abstract class Metadata(implicit p: Parameters) extends CacheBundle()(p) {
|
2014-08-12 03:35:49 +02:00
|
|
|
val tag = Bits(width = tagBits)
|
2014-05-28 22:35:08 +02:00
|
|
|
val coh: CoherenceMetadata
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class MetaReadReq(implicit p: Parameters) extends CacheBundle()(p) {
|
2014-08-12 03:35:49 +02:00
|
|
|
val idx = Bits(width = idxBits)
|
2016-02-29 23:48:49 +01:00
|
|
|
val way_en = Bits(width = nWays)
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class MetaWriteReq[T <: Metadata](gen: T)(implicit p: Parameters) extends MetaReadReq()(p) {
|
2015-07-16 03:06:27 +02:00
|
|
|
val data = gen.cloneType
|
2015-10-06 06:41:46 +02:00
|
|
|
override def cloneType = new MetaWriteReq(gen)(p).asInstanceOf[this.type]
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class MetadataArray[T <: Metadata](onReset: () => T)(implicit p: Parameters) extends CacheModule()(p) {
|
|
|
|
val rstVal = onReset()
|
2014-04-23 01:55:35 +02:00
|
|
|
val io = new Bundle {
|
2014-04-24 01:24:20 +02:00
|
|
|
val read = Decoupled(new MetaReadReq).flip
|
2015-07-16 03:06:27 +02:00
|
|
|
val write = Decoupled(new MetaWriteReq(rstVal)).flip
|
2016-01-14 22:47:47 +01:00
|
|
|
val resp = Vec(nWays, rstVal.cloneType).asOutput
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
2014-08-12 03:35:49 +02:00
|
|
|
val rst_cnt = Reg(init=UInt(0, log2Up(nSets+1)))
|
|
|
|
val rst = rst_cnt < UInt(nSets)
|
2014-05-28 22:35:08 +02:00
|
|
|
val waddr = Mux(rst, rst_cnt, io.write.bits.idx)
|
|
|
|
val wdata = Mux(rst, rstVal, io.write.bits.data).toBits
|
2015-09-12 00:41:39 +02:00
|
|
|
val wmask = Mux(rst, SInt(-1), io.write.bits.way_en.toSInt).toBools
|
2016-02-29 23:48:49 +01:00
|
|
|
val rmask = Mux(rst, SInt(-1), io.read.bits.way_en.toSInt).toBools
|
2014-04-23 01:55:35 +02:00
|
|
|
when (rst) { rst_cnt := rst_cnt+UInt(1) }
|
|
|
|
|
2015-03-01 02:02:13 +01:00
|
|
|
val metabits = rstVal.getWidth
|
2016-02-29 23:48:49 +01:00
|
|
|
|
|
|
|
if (hasSplitMetadata) {
|
|
|
|
val tag_arrs = List.fill(nWays){ SeqMem(nSets, UInt(width = metabits)) }
|
|
|
|
val tag_readout = Wire(Vec(nWays,rstVal.cloneType))
|
|
|
|
val tags_vec = Wire(Vec.fill(nWays)(UInt(width = metabits)))
|
|
|
|
(0 until nWays).foreach { (i) =>
|
|
|
|
when (rst || (io.write.valid && wmask(i))) {
|
|
|
|
tag_arrs(i).write(waddr, wdata)
|
|
|
|
}
|
|
|
|
tags_vec(i) := tag_arrs(i).read(io.read.bits.idx, io.read.valid && rmask(i))
|
|
|
|
}
|
|
|
|
io.resp := io.resp.fromBits(tags_vec.toBits)
|
|
|
|
} else {
|
|
|
|
val tag_arr = SeqMem(nSets, Vec(nWays, UInt(width = metabits)))
|
|
|
|
when (rst || io.write.valid) {
|
|
|
|
tag_arr.write(waddr, Vec.fill(nWays)(wdata), wmask)
|
|
|
|
}
|
|
|
|
val tags = tag_arr.read(io.read.bits.idx, io.read.valid).toBits
|
|
|
|
io.resp := io.resp.fromBits(tags)
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
io.read.ready := !rst && !io.write.valid // so really this could be a 6T RAM
|
|
|
|
io.write.ready := !rst
|
|
|
|
}
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-10-07 03:19:45 +02:00
|
|
|
case object L2DirectoryRepresentation extends Field[DirectoryRepresentation]
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2HellaCacheParameters extends HasCacheParameters with HasCoherenceAgentParameters {
|
2015-11-22 00:55:11 +01:00
|
|
|
val cacheId = p(CacheId)
|
|
|
|
val idxLSB = cacheIdBits
|
2015-11-21 08:21:14 +01:00
|
|
|
val idxMSB = idxLSB + idxBits - 1
|
|
|
|
val tagLSB = idxLSB + idxBits
|
2016-03-07 08:12:16 +01:00
|
|
|
def inSameSet(addr1: UInt, addr2: UInt): Bool = addr1(idxMSB,idxLSB) === addr2(idxMSB,idxLSB)
|
|
|
|
def haveSameTag(addr1: UInt, addr2: UInt): Bool = addr1 >> UInt(tagLSB) === addr2 >> UInt(tagLSB)
|
2015-10-14 08:42:28 +02:00
|
|
|
//val blockAddrBits = p(TLBlockAddrBits)
|
2015-03-01 02:02:13 +01:00
|
|
|
val refillCyclesPerBeat = outerDataBits/rowBits
|
|
|
|
val refillCycles = refillCyclesPerBeat*outerDataBeats
|
2015-10-06 06:41:46 +02:00
|
|
|
val internalDataBeats = p(CacheBlockBytes)*8/rowBits
|
2015-02-02 04:57:53 +01:00
|
|
|
require(refillCyclesPerBeat == 1)
|
2015-10-06 06:41:46 +02:00
|
|
|
val amoAluOperandBits = p(AmoAluOperandBits)
|
2015-03-01 02:02:13 +01:00
|
|
|
require(amoAluOperandBits <= innerDataBits)
|
|
|
|
require(rowBits == innerDataBits) // TODO: relax this by improving s_data_* states
|
2015-10-06 06:41:46 +02:00
|
|
|
val nSecondaryMisses = p(NSecondaryMisses)
|
2015-03-19 01:55:05 +01:00
|
|
|
val isLastLevelCache = true
|
2015-10-06 06:41:46 +02:00
|
|
|
val ignoresWriteMask = !p(ECCCode).isEmpty
|
2014-12-17 23:28:14 +01:00
|
|
|
}
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
abstract class L2HellaCacheModule(implicit val p: Parameters) extends Module
|
|
|
|
with HasL2HellaCacheParameters {
|
2015-04-14 04:00:40 +02:00
|
|
|
def doInternalOutputArbitration[T <: Data : ClassTag](
|
|
|
|
out: DecoupledIO[T],
|
|
|
|
ins: Seq[DecoupledIO[T]]) {
|
2015-07-16 03:06:27 +02:00
|
|
|
val arb = Module(new RRArbiter(out.bits, ins.size))
|
2015-04-14 04:00:40 +02:00
|
|
|
out <> arb.io.out
|
2015-04-18 01:55:20 +02:00
|
|
|
arb.io.in <> ins
|
2015-04-14 04:00:40 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def doInternalInputRouting[T <: Bundle with HasL2Id](in: ValidIO[T], outs: Seq[ValidIO[T]]) {
|
2015-04-14 04:00:40 +02:00
|
|
|
outs.map(_.bits := in.bits)
|
2015-04-22 07:23:04 +02:00
|
|
|
outs.zipWithIndex.map { case (o,i) => o.valid := in.valid && in.bits.id === UInt(i) }
|
2015-04-14 04:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
abstract class L2HellaCacheBundle(implicit val p: Parameters) extends ParameterizedBundle()(p)
|
|
|
|
with HasL2HellaCacheParameters
|
|
|
|
|
|
|
|
trait HasL2Id extends HasCoherenceAgentParameters {
|
2014-12-19 12:03:53 +01:00
|
|
|
val id = UInt(width = log2Up(nTransactors + 1))
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2InternalRequestState extends HasL2HellaCacheParameters {
|
2014-09-30 23:48:02 +02:00
|
|
|
val tag_match = Bool()
|
|
|
|
val meta = new L2Metadata
|
|
|
|
val way_en = Bits(width = nWays)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2BeatAddr extends HasL2HellaCacheParameters {
|
2015-03-01 02:02:13 +01:00
|
|
|
val addr_beat = UInt(width = log2Up(refillCycles))
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2Data extends HasL2HellaCacheParameters
|
2015-03-01 02:02:13 +01:00
|
|
|
with HasL2BeatAddr {
|
|
|
|
val data = UInt(width = rowBits)
|
2015-02-02 04:57:53 +01:00
|
|
|
def hasData(dummy: Int = 0) = Bool(true)
|
2015-03-01 02:02:13 +01:00
|
|
|
def hasMultibeatData(dummy: Int = 0) = Bool(refillCycles > 1)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2Metadata(implicit p: Parameters) extends Metadata()(p) with HasL2HellaCacheParameters {
|
2015-03-01 02:02:13 +01:00
|
|
|
val coh = new HierarchicalMetadata
|
2015-02-02 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2014-09-30 23:48:02 +02:00
|
|
|
object L2Metadata {
|
2015-10-06 06:41:46 +02:00
|
|
|
def apply(tag: Bits, coh: HierarchicalMetadata)(implicit p: Parameters) = {
|
2015-07-16 05:24:03 +02:00
|
|
|
val meta = Wire(new L2Metadata)
|
2014-09-30 23:48:02 +02:00
|
|
|
meta.tag := tag
|
|
|
|
meta.coh := coh
|
|
|
|
meta
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2MetaReadReq(implicit p: Parameters) extends MetaReadReq()(p) with HasL2Id {
|
2014-09-30 23:48:02 +02:00
|
|
|
val tag = Bits(width = tagBits)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2MetaWriteReq(implicit p: Parameters) extends MetaWriteReq[L2Metadata](new L2Metadata)(p)
|
2014-10-15 20:46:35 +02:00
|
|
|
with HasL2Id {
|
2015-07-16 03:06:27 +02:00
|
|
|
override def cloneType = new L2MetaWriteReq().asInstanceOf[this.type]
|
2014-10-15 20:46:35 +02:00
|
|
|
}
|
2014-12-12 10:11:08 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2MetaResp(implicit p: Parameters) extends L2HellaCacheBundle()(p)
|
2014-09-30 23:48:02 +02:00
|
|
|
with HasL2Id
|
|
|
|
with HasL2InternalRequestState
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2MetaReadIO extends HasL2HellaCacheParameters {
|
2014-11-20 00:55:25 +01:00
|
|
|
val read = Decoupled(new L2MetaReadReq)
|
|
|
|
val resp = Valid(new L2MetaResp).flip
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2MetaWriteIO extends HasL2HellaCacheParameters {
|
2014-11-20 00:55:25 +01:00
|
|
|
val write = Decoupled(new L2MetaWriteReq)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2MetaRWIO(implicit p: Parameters) extends L2HellaCacheBundle()(p)
|
|
|
|
with HasL2MetaReadIO
|
|
|
|
with HasL2MetaWriteIO
|
2014-11-20 00:55:25 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2MetadataArray(implicit p: Parameters) extends L2HellaCacheModule()(p) {
|
2014-11-20 00:55:25 +01:00
|
|
|
val io = new L2MetaRWIO().flip
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-03-01 02:02:13 +01:00
|
|
|
def onReset = L2Metadata(UInt(0), HierarchicalMetadata.onReset)
|
|
|
|
val meta = Module(new MetadataArray(onReset _))
|
2014-09-30 23:48:02 +02:00
|
|
|
meta.io.read <> io.read
|
|
|
|
meta.io.write <> io.write
|
2016-02-29 23:48:49 +01:00
|
|
|
val way_en_1h = (Vec.fill(nWays){Bool(true)}).toBits
|
|
|
|
val s1_way_en_1h = RegEnable(way_en_1h, io.read.valid)
|
|
|
|
meta.io.read.bits.way_en := way_en_1h
|
|
|
|
|
2014-09-30 23:48:02 +02:00
|
|
|
val s1_tag = RegEnable(io.read.bits.tag, io.read.valid)
|
|
|
|
val s1_id = RegEnable(io.read.bits.id, io.read.valid)
|
|
|
|
def wayMap[T <: Data](f: Int => T) = Vec((0 until nWays).map(f))
|
2014-12-12 10:11:08 +01:00
|
|
|
val s1_clk_en = Reg(next = io.read.fire())
|
2014-09-30 23:48:02 +02:00
|
|
|
val s1_tag_eq_way = wayMap((w: Int) => meta.io.resp(w).tag === s1_tag)
|
2016-02-29 23:48:49 +01:00
|
|
|
val s1_tag_match_way = wayMap((w: Int) => s1_tag_eq_way(w) && meta.io.resp(w).coh.outer.isValid() && s1_way_en_1h(w).toBool).toBits
|
2015-12-11 01:40:16 +01:00
|
|
|
val s1_idx = RegEnable(io.read.bits.idx, io.read.valid) // deal with stalls?
|
2014-09-30 23:48:02 +02:00
|
|
|
val s2_tag_match_way = RegEnable(s1_tag_match_way, s1_clk_en)
|
|
|
|
val s2_tag_match = s2_tag_match_way.orR
|
|
|
|
val s2_hit_coh = Mux1H(s2_tag_match_way, wayMap((w: Int) => RegEnable(meta.io.resp(w).coh, s1_clk_en)))
|
|
|
|
|
2015-12-11 01:40:16 +01:00
|
|
|
val replacer = p(L2Replacer)()
|
|
|
|
val s1_hit_way = Wire(Bits())
|
|
|
|
s1_hit_way := Bits(0)
|
|
|
|
(0 until nWays).foreach(i => when (s1_tag_match_way(i)) { s1_hit_way := Bits(i) })
|
|
|
|
replacer.access(io.read.bits.idx)
|
|
|
|
replacer.update(s1_clk_en, s1_tag_match_way.orR, s1_idx, s1_hit_way)
|
|
|
|
|
2014-09-30 23:48:02 +02:00
|
|
|
val s1_replaced_way_en = UIntToOH(replacer.way)
|
|
|
|
val s2_replaced_way_en = UIntToOH(RegEnable(replacer.way, s1_clk_en))
|
|
|
|
val s2_repl_meta = Mux1H(s2_replaced_way_en, wayMap((w: Int) =>
|
|
|
|
RegEnable(meta.io.resp(w), s1_clk_en && s1_replaced_way_en(w))).toSeq)
|
|
|
|
|
|
|
|
io.resp.valid := Reg(next = s1_clk_en)
|
|
|
|
io.resp.bits.id := RegEnable(s1_id, s1_clk_en)
|
|
|
|
io.resp.bits.tag_match := s2_tag_match
|
|
|
|
io.resp.bits.meta := Mux(s2_tag_match,
|
|
|
|
L2Metadata(s2_repl_meta.tag, s2_hit_coh),
|
|
|
|
s2_repl_meta)
|
2015-11-21 19:35:40 +01:00
|
|
|
io.resp.bits.way_en := Mux(s2_tag_match, s2_tag_match_way, s2_replaced_way_en)
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2DataReadReq(implicit p: Parameters) extends L2HellaCacheBundle()(p)
|
2015-03-01 02:02:13 +01:00
|
|
|
with HasL2BeatAddr
|
2015-02-02 04:57:53 +01:00
|
|
|
with HasL2Id {
|
2015-02-17 09:35:18 +01:00
|
|
|
val addr_idx = UInt(width = idxBits)
|
2014-09-30 23:48:02 +02:00
|
|
|
val way_en = Bits(width = nWays)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2DataWriteReq(implicit p: Parameters) extends L2DataReadReq()(p)
|
2015-02-02 04:57:53 +01:00
|
|
|
with HasL2Data {
|
2015-03-01 02:02:13 +01:00
|
|
|
val wmask = Bits(width = rowBits/8)
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2DataResp(implicit p: Parameters) extends L2HellaCacheBundle()(p)
|
|
|
|
with HasL2Id
|
|
|
|
with HasL2Data
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2DataReadIO extends HasL2HellaCacheParameters {
|
2014-11-20 00:55:25 +01:00
|
|
|
val read = Decoupled(new L2DataReadReq)
|
|
|
|
val resp = Valid(new L2DataResp).flip
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
trait HasL2DataWriteIO extends HasL2HellaCacheParameters {
|
2014-11-20 00:55:25 +01:00
|
|
|
val write = Decoupled(new L2DataWriteReq)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2DataRWIO(implicit p: Parameters) extends L2HellaCacheBundle()(p)
|
|
|
|
with HasL2DataReadIO
|
|
|
|
with HasL2DataWriteIO
|
2014-11-20 00:55:25 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2DataArray(delay: Int)(implicit p: Parameters) extends L2HellaCacheModule()(p) {
|
2014-11-20 00:55:25 +01:00
|
|
|
val io = new L2DataRWIO().flip
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2016-01-14 22:47:47 +01:00
|
|
|
val array = SeqMem(nWays*nSets*refillCycles, Vec(rowBits/8, Bits(width=8)))
|
2015-07-11 22:36:14 +02:00
|
|
|
val ren = !io.write.valid && io.read.valid
|
2015-02-17 09:35:18 +01:00
|
|
|
val raddr = Cat(OHToUInt(io.read.bits.way_en), io.read.bits.addr_idx, io.read.bits.addr_beat)
|
2015-07-11 22:36:14 +02:00
|
|
|
val waddr = Cat(OHToUInt(io.write.bits.way_en), io.write.bits.addr_idx, io.write.bits.addr_beat)
|
2015-09-12 00:41:39 +02:00
|
|
|
val wdata = Vec.tabulate(rowBits/8)(i => io.write.bits.data(8*(i+1)-1,8*i))
|
|
|
|
val wmask = io.write.bits.wmask.toBools
|
|
|
|
when (io.write.valid) { array.write(waddr, wdata, wmask) }
|
2015-01-26 00:37:04 +01:00
|
|
|
|
2015-06-12 00:28:23 +02:00
|
|
|
val r_req = Pipe(io.read.fire(), io.read.bits)
|
|
|
|
io.resp := Pipe(r_req.valid, r_req.bits, delay)
|
2015-09-12 00:41:39 +02:00
|
|
|
io.resp.bits.data := Pipe(r_req.valid, array.read(raddr, ren).toBits, delay).bits
|
2015-01-26 00:37:04 +01:00
|
|
|
io.read.ready := !io.write.valid
|
2014-09-30 23:48:02 +02:00
|
|
|
io.write.ready := Bool(true)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2HellaCacheBank(implicit p: Parameters) extends HierarchicalCoherenceAgent()(p)
|
|
|
|
with HasL2HellaCacheParameters {
|
2014-09-30 23:48:02 +02:00
|
|
|
require(isPow2(nSets))
|
|
|
|
require(isPow2(nWays))
|
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
val meta = Module(new L2MetadataArray) // TODO: add delay knob
|
|
|
|
val data = Module(new L2DataArray(1))
|
2015-04-18 01:55:20 +02:00
|
|
|
val tshrfile = Module(new TSHRFile)
|
2015-09-12 00:41:39 +02:00
|
|
|
io.inner <> tshrfile.io.inner
|
2014-09-30 23:48:02 +02:00
|
|
|
io.outer <> tshrfile.io.outer
|
2015-09-12 00:41:39 +02:00
|
|
|
tshrfile.io.incoherent <> io.incoherent
|
|
|
|
meta.io <> tshrfile.io.meta
|
|
|
|
data.io <> tshrfile.io.data
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class TSHRFileIO(implicit p: Parameters) extends HierarchicalTLIO()(p) {
|
2015-03-01 02:02:13 +01:00
|
|
|
val meta = new L2MetaRWIO
|
|
|
|
val data = new L2DataRWIO
|
|
|
|
}
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class TSHRFile(implicit p: Parameters) extends L2HellaCacheModule()(p)
|
|
|
|
with HasCoherenceAgentWiringHelpers {
|
2015-03-01 02:02:13 +01:00
|
|
|
val io = new TSHRFileIO
|
2014-09-30 23:48:02 +02:00
|
|
|
|
|
|
|
// Create TSHRs for outstanding transactions
|
2016-03-07 08:12:16 +01:00
|
|
|
val trackerList =
|
|
|
|
(0 until nReleaseTransactors).map(id =>
|
|
|
|
Module(new L2VoluntaryReleaseTracker(id))) ++
|
|
|
|
(nReleaseTransactors until nTransactors).map(id =>
|
|
|
|
Module(new L2AcquireTracker(id)))
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
// WritebackUnit evicts data from L2, including invalidating L1s
|
2015-04-18 01:55:20 +02:00
|
|
|
val wb = Module(new L2WritebackUnit(nTransactors))
|
2015-11-06 02:20:03 +01:00
|
|
|
val trackerAndWbIOs = trackerList.map(_.io) :+ wb.io
|
2015-04-14 04:00:40 +02:00
|
|
|
doInternalOutputArbitration(wb.io.wb.req, trackerList.map(_.io.wb.req))
|
|
|
|
doInternalInputRouting(wb.io.wb.resp, trackerList.map(_.io.wb.resp))
|
2014-12-19 12:03:53 +01:00
|
|
|
|
2014-09-30 23:48:02 +02:00
|
|
|
// Propagate incoherence flags
|
2015-08-27 18:57:36 +02:00
|
|
|
(trackerList.map(_.io.incoherent) :+ wb.io.incoherent) foreach { _ := io.incoherent }
|
2014-09-30 23:48:02 +02:00
|
|
|
|
|
|
|
// Handle acquire transaction initiation
|
2016-03-07 08:12:16 +01:00
|
|
|
val irel_vs_iacq_conflict =
|
|
|
|
io.inner.acquire.valid &&
|
|
|
|
io.inner.release.valid &&
|
|
|
|
inSameSet(io.inner.acquire.bits.addr_block, io.inner.release.bits.addr_block)
|
|
|
|
doInputRoutingWithAllocation(
|
|
|
|
io.inner.acquire,
|
|
|
|
trackerList.map(_.io.inner.acquire),
|
|
|
|
trackerList.map(_.io.matches.iacq),
|
|
|
|
trackerList.map(_.io.alloc.iacq),
|
|
|
|
allocOverride = !irel_vs_iacq_conflict)
|
|
|
|
|
|
|
|
assert(PopCount(trackerList.map(_.io.alloc.iacq)) <= UInt(1),
|
|
|
|
"At most a single tracker should now be allocated for any given Acquire")
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2014-12-19 12:03:53 +01:00
|
|
|
// Wire releases from clients
|
2016-03-07 08:12:16 +01:00
|
|
|
doInputRoutingWithAllocation(
|
|
|
|
io.inner.release,
|
|
|
|
trackerAndWbIOs.map(_.inner.release),
|
|
|
|
trackerAndWbIOs.map(_.matches.irel),
|
|
|
|
trackerAndWbIOs.map(_.alloc.irel))
|
|
|
|
|
|
|
|
assert(PopCount(trackerAndWbIOs.map(_.alloc.irel)) <= UInt(1),
|
|
|
|
"At most a single tracker should now be allocated for any given Release")
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-03-01 02:02:13 +01:00
|
|
|
// Wire probe requests and grant reply to clients, finish acks from clients
|
2014-12-19 12:03:53 +01:00
|
|
|
doOutputArbitration(io.inner.probe, trackerList.map(_.io.inner.probe) :+ wb.io.inner.probe)
|
2016-03-07 08:12:16 +01:00
|
|
|
doOutputArbitration(io.inner.grant, trackerList.map(_.io.inner.grant) :+ wb.io.inner.grant)
|
2015-03-01 02:02:13 +01:00
|
|
|
doInputRouting(io.inner.finish, trackerList.map(_.io.inner.finish))
|
2014-12-12 10:11:08 +01:00
|
|
|
|
|
|
|
// Create an arbiter for the one memory port
|
2014-12-19 12:03:53 +01:00
|
|
|
val outerList = trackerList.map(_.io.outer) :+ wb.io.outer
|
2015-10-14 08:42:28 +02:00
|
|
|
val outer_arb = Module(new ClientTileLinkIOArbiter(outerList.size)
|
|
|
|
(p.alterPartial({ case TLId => p(OuterTLId)})))
|
2015-04-18 01:55:20 +02:00
|
|
|
outer_arb.io.in <> outerList
|
2014-09-30 23:48:02 +02:00
|
|
|
io.outer <> outer_arb.io.out
|
|
|
|
|
2015-04-14 04:00:40 +02:00
|
|
|
// Wire local memory arrays
|
|
|
|
doInternalOutputArbitration(io.meta.read, trackerList.map(_.io.meta.read))
|
|
|
|
doInternalOutputArbitration(io.meta.write, trackerList.map(_.io.meta.write))
|
|
|
|
doInternalOutputArbitration(io.data.read, trackerList.map(_.io.data.read) :+ wb.io.data.read)
|
|
|
|
doInternalOutputArbitration(io.data.write, trackerList.map(_.io.data.write))
|
|
|
|
doInternalInputRouting(io.meta.resp, trackerList.map(_.io.meta.resp))
|
|
|
|
doInternalInputRouting(io.data.resp, trackerList.map(_.io.data.resp) :+ wb.io.data.resp)
|
2014-12-19 12:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2XactTrackerIO(implicit p: Parameters) extends HierarchicalXactTrackerIO()(p) {
|
2015-03-01 02:02:13 +01:00
|
|
|
val data = new L2DataRWIO
|
|
|
|
val meta = new L2MetaRWIO
|
|
|
|
val wb = new L2WritebackIO
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
abstract class L2XactTracker(implicit p: Parameters) extends XactTracker()(p)
|
|
|
|
with HasL2HellaCacheParameters {
|
2015-04-27 21:56:33 +02:00
|
|
|
class CacheBlockBuffer { // TODO
|
2015-10-06 06:41:46 +02:00
|
|
|
val buffer = Reg(Bits(width = p(CacheBlockBytes)*8))
|
2015-03-11 23:43:41 +01:00
|
|
|
|
2016-01-14 22:47:47 +01:00
|
|
|
def internal = Vec(internalDataBeats, Bits(width = rowBits)).fromBits(buffer)
|
|
|
|
def inner = Vec(innerDataBeats, Bits(width = innerDataBits)).fromBits(buffer)
|
|
|
|
def outer = Vec(outerDataBeats, Bits(width = outerDataBits)).fromBits(buffer)
|
2015-03-11 23:43:41 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 02:02:13 +01:00
|
|
|
def connectDataBeatCounter[S <: L2HellaCacheBundle](inc: Bool, data: S, beat: UInt, full_block: Bool) = {
|
|
|
|
if(data.refillCycles > 1) {
|
2015-03-11 09:56:47 +01:00
|
|
|
val (multi_cnt, multi_done) = Counter(full_block && inc, data.refillCycles)
|
2015-03-01 02:02:13 +01:00
|
|
|
(Mux(!full_block, beat, multi_cnt), Mux(!full_block, inc, multi_done))
|
|
|
|
} else { (UInt(0), inc) }
|
2014-12-19 12:03:53 +01:00
|
|
|
}
|
2015-03-18 01:51:00 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def connectInternalDataBeatCounter[T <: L2HellaCacheBundle with HasL2BeatAddr](
|
2015-03-01 02:02:13 +01:00
|
|
|
in: DecoupledIO[T],
|
|
|
|
beat: UInt = UInt(0),
|
2015-07-29 01:24:45 +02:00
|
|
|
full_block: Bool = Bool(true)): (UInt, Bool) = {
|
2015-03-01 02:02:13 +01:00
|
|
|
connectDataBeatCounter(in.fire(), in.bits, beat, full_block)
|
2014-12-19 12:03:53 +01:00
|
|
|
}
|
2015-03-18 01:51:00 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def connectInternalDataBeatCounter[T <: L2HellaCacheBundle with HasL2Data](
|
2015-03-01 02:02:13 +01:00
|
|
|
in: ValidIO[T],
|
2015-07-29 01:24:45 +02:00
|
|
|
full_block: Bool): Bool = {
|
2015-03-01 02:02:13 +01:00
|
|
|
connectDataBeatCounter(in.valid, in.bits, UInt(0), full_block)._2
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
2015-03-18 01:51:00 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def addPendingBitInternal[T <: L2HellaCacheBundle with HasL2BeatAddr](in: DecoupledIO[T]) =
|
2015-03-18 01:51:00 +01:00
|
|
|
Fill(in.bits.refillCycles, in.fire()) & UIntToOH(in.bits.addr_beat)
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def addPendingBitInternal[T <: L2HellaCacheBundle with HasL2BeatAddr](in: ValidIO[T]) =
|
2015-03-18 06:44:53 +01:00
|
|
|
Fill(in.bits.refillCycles, in.valid) & UIntToOH(in.bits.addr_beat)
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def dropPendingBit[T <: L2HellaCacheBundle with HasL2BeatAddr] (in: DecoupledIO[T]) =
|
2015-03-18 02:07:52 +01:00
|
|
|
~Fill(in.bits.refillCycles, in.fire()) | ~UIntToOH(in.bits.addr_beat)
|
2015-03-18 01:51:00 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def dropPendingBitInternal[T <: L2HellaCacheBundle with HasL2BeatAddr] (in: ValidIO[T]) =
|
2015-03-18 02:07:52 +01:00
|
|
|
~Fill(in.bits.refillCycles, in.valid) | ~UIntToOH(in.bits.addr_beat)
|
2015-04-04 02:24:44 +02:00
|
|
|
|
2015-04-18 01:55:20 +02:00
|
|
|
def addPendingBitWhenBeatHasPartialWritemask(in: DecoupledIO[AcquireFromSrc]): UInt = {
|
|
|
|
val a = in.bits
|
2015-11-16 22:23:17 +01:00
|
|
|
val isPartial = a.wmask() =/= Acquire.fullWriteMask
|
2015-04-18 01:55:20 +02:00
|
|
|
addPendingBitWhenBeat(in.fire() && isPartial && Bool(ignoresWriteMask), a)
|
2015-04-04 02:24:44 +02:00
|
|
|
}
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2VoluntaryReleaseTracker(trackerId: Int)(implicit p: Parameters) extends L2XactTracker()(p) {
|
2015-03-01 02:02:13 +01:00
|
|
|
val io = new L2XactTrackerIO
|
2015-04-27 21:56:33 +02:00
|
|
|
pinAllReadyValidLow(io)
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
val s_idle :: s_meta_read :: s_meta_resp :: s_busy :: s_meta_write :: Nil = Enum(UInt(), 5)
|
2014-09-30 23:48:02 +02:00
|
|
|
val state = Reg(init=s_idle)
|
2014-12-12 10:11:08 +01:00
|
|
|
|
2015-10-22 03:16:44 +02:00
|
|
|
val xact = Reg(new BufferedReleaseFromSrc()(p.alterPartial({case TLId => p(InnerTLId)})))
|
2014-12-12 10:11:08 +01:00
|
|
|
val xact_way_en = Reg{ Bits(width = nWays) }
|
2015-04-27 21:56:33 +02:00
|
|
|
val xact_old_meta = Reg{ new L2Metadata }
|
2015-03-24 10:06:53 +01:00
|
|
|
val coh = xact_old_meta.coh
|
2014-12-12 10:11:08 +01:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
val pending_irels = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
|
|
|
val pending_writes = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
|
|
|
val pending_ignt = Reg(init=Bool(false))
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
val all_pending_done =
|
|
|
|
!(pending_writes.orR ||
|
|
|
|
pending_ignt)
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2016-03-07 08:12:16 +01:00
|
|
|
// These IOs are used for routing in the parent
|
|
|
|
io.matches.iacq := (state =/= s_idle) && inSameSet(io.iacq().addr_block, xact.addr_block)
|
|
|
|
io.matches.irel := (state =/= s_idle) && io.irel().conflicts(xact)
|
|
|
|
io.matches.oprb := (state =/= s_idle) && io.oprb().conflicts(xact)
|
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
// Accept a voluntary Release (and any further beats of data)
|
|
|
|
pending_irels := (pending_irels & dropPendingBitWhenBeatHasData(io.inner.release))
|
2016-02-10 20:12:43 +01:00
|
|
|
io.inner.release.ready := ((state === s_idle) && io.irel().isVoluntary()) || pending_irels.orR
|
2015-10-14 08:42:28 +02:00
|
|
|
when(io.inner.release.fire()) { xact.data_buffer(io.irel().addr_beat) := io.irel().data }
|
2014-10-24 06:50:03 +02:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
// Begin a transaction by getting the current block metadata
|
|
|
|
io.meta.read.valid := state === s_meta_read
|
|
|
|
io.meta.read.bits.id := UInt(trackerId)
|
|
|
|
io.meta.read.bits.idx := xact.addr_block(idxMSB,idxLSB)
|
2015-11-21 08:21:14 +01:00
|
|
|
io.meta.read.bits.tag := xact.addr_block >> UInt(tagLSB)
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
// Write the voluntarily written back data to this cache
|
|
|
|
pending_writes := (pending_writes & dropPendingBit(io.data.write)) |
|
|
|
|
addPendingBitWhenBeatHasData(io.inner.release)
|
|
|
|
val curr_write_beat = PriorityEncoder(pending_writes)
|
|
|
|
io.data.write.valid := state === s_busy && pending_writes.orR
|
2014-11-20 00:55:25 +01:00
|
|
|
io.data.write.bits.id := UInt(trackerId)
|
2014-12-12 10:11:08 +01:00
|
|
|
io.data.write.bits.way_en := xact_way_en
|
2015-03-01 02:02:13 +01:00
|
|
|
io.data.write.bits.addr_idx := xact.addr_block(idxMSB,idxLSB)
|
2015-04-27 21:56:33 +02:00
|
|
|
io.data.write.bits.addr_beat := curr_write_beat
|
2015-08-27 18:57:36 +02:00
|
|
|
io.data.write.bits.wmask := ~UInt(0, io.data.write.bits.wmask.getWidth)
|
2015-10-14 08:42:28 +02:00
|
|
|
io.data.write.bits.data := xact.data_buffer(curr_write_beat)
|
2015-04-27 21:56:33 +02:00
|
|
|
|
|
|
|
// Send an acknowledgement
|
|
|
|
io.inner.grant.valid := state === s_busy && pending_ignt && !pending_irels
|
2016-03-07 08:12:16 +01:00
|
|
|
io.inner.grant.bits := coh.inner.makeGrant(xact)
|
2015-04-27 21:56:33 +02:00
|
|
|
when(io.inner.grant.fire()) { pending_ignt := Bool(false) }
|
|
|
|
|
|
|
|
// End a transaction by updating the block metadata
|
|
|
|
io.meta.write.valid := state === s_meta_write
|
2014-11-20 00:55:25 +01:00
|
|
|
io.meta.write.bits.id := UInt(trackerId)
|
2015-03-01 02:02:13 +01:00
|
|
|
io.meta.write.bits.idx := xact.addr_block(idxMSB,idxLSB)
|
2014-12-12 10:11:08 +01:00
|
|
|
io.meta.write.bits.way_en := xact_way_en
|
2015-11-21 08:21:14 +01:00
|
|
|
io.meta.write.bits.data.tag := xact.addr_block >> UInt(tagLSB)
|
2015-04-18 01:55:20 +02:00
|
|
|
io.meta.write.bits.data.coh.inner := xact_old_meta.coh.inner.onRelease(xact)
|
2015-04-27 21:56:33 +02:00
|
|
|
io.meta.write.bits.data.coh.outer := Mux(xact.hasData(),
|
|
|
|
xact_old_meta.coh.outer.onHit(M_XWR),
|
|
|
|
xact_old_meta.coh.outer)
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
// State machine updates and transaction handler metadata intialization
|
2016-03-07 08:12:16 +01:00
|
|
|
when(state === s_idle && io.inner.release.valid && io.alloc.irel) {
|
2015-04-27 21:56:33 +02:00
|
|
|
xact := io.irel()
|
|
|
|
when(io.irel().hasMultibeatData()) {
|
|
|
|
pending_irels := dropPendingBitWhenBeatHasData(io.inner.release)
|
|
|
|
}. otherwise {
|
|
|
|
pending_irels := UInt(0)
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
2015-04-27 21:56:33 +02:00
|
|
|
pending_writes := addPendingBitWhenBeatHasData(io.inner.release)
|
|
|
|
pending_ignt := io.irel().requiresAck()
|
|
|
|
state := s_meta_read
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
2015-04-27 21:56:33 +02:00
|
|
|
when(state === s_meta_read && io.meta.read.ready) { state := s_meta_resp }
|
|
|
|
when(state === s_meta_resp && io.meta.resp.valid) {
|
|
|
|
xact_old_meta := io.meta.resp.bits.meta
|
|
|
|
xact_way_en := io.meta.resp.bits.way_en
|
|
|
|
state := s_busy
|
|
|
|
}
|
|
|
|
when(state === s_busy && all_pending_done) { state := s_meta_write }
|
|
|
|
when(state === s_meta_write && io.meta.write.ready) { state := s_idle }
|
|
|
|
|
2015-04-14 00:57:06 +02:00
|
|
|
// Checks for illegal behavior
|
|
|
|
assert(!(state === s_meta_resp && io.meta.resp.valid && !io.meta.resp.bits.tag_match),
|
|
|
|
"VoluntaryReleaseTracker accepted Release for a block not resident in this cache!")
|
2015-04-27 21:56:33 +02:00
|
|
|
assert(!(state === s_idle && io.inner.release.fire() && !io.irel().isVoluntary()),
|
|
|
|
"VoluntaryReleaseTracker accepted Release that wasn't voluntary!")
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
|
|
|
|
2015-03-17 07:41:56 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2AcquireTracker(trackerId: Int)(implicit p: Parameters) extends L2XactTracker()(p) {
|
2015-03-01 02:02:13 +01:00
|
|
|
val io = new L2XactTrackerIO
|
2015-04-27 21:56:33 +02:00
|
|
|
pinAllReadyValidLow(io)
|
2014-12-19 12:03:53 +01:00
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
val s_idle :: s_meta_read :: s_meta_resp :: s_wb_req :: s_wb_resp :: s_inner_probe :: s_outer_acquire :: s_busy :: s_meta_write :: Nil = Enum(UInt(), 9)
|
2014-09-30 23:48:02 +02:00
|
|
|
val state = Reg(init=s_idle)
|
2014-12-12 10:11:08 +01:00
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
// State holding transaction metadata
|
2015-11-16 22:23:17 +01:00
|
|
|
val data_buffer = Reg(init=Vec.fill(innerDataBeats)(UInt(0, width = innerDataBits)))
|
2015-09-26 02:06:06 +02:00
|
|
|
val wmask_buffer = Reg(init=Vec.fill(innerDataBeats)(UInt(0, width = innerDataBits/8)))
|
2015-11-16 22:23:17 +01:00
|
|
|
val xact_addr_block = Reg{ io.inner.acquire.bits.addr_block }
|
2014-12-12 10:11:08 +01:00
|
|
|
val xact_tag_match = Reg{ Bool() }
|
|
|
|
val xact_way_en = Reg{ Bits(width = nWays) }
|
2015-03-24 10:06:53 +01:00
|
|
|
val xact_old_meta = Reg{ new L2Metadata }
|
2015-07-16 03:06:27 +02:00
|
|
|
val pending_coh = Reg{ xact_old_meta.coh }
|
2015-11-16 22:23:17 +01:00
|
|
|
val xact_allocate = Reg{ Bool() }
|
2015-11-17 04:07:58 +01:00
|
|
|
val xact_amo_shift_bytes = Reg{ UInt() }
|
2015-11-16 22:23:17 +01:00
|
|
|
val xact_op_code = Reg{ UInt() }
|
|
|
|
val xact_addr_byte = Reg{ UInt() }
|
|
|
|
val xact_op_size = Reg{ UInt() }
|
2016-03-07 08:12:16 +01:00
|
|
|
val xact_vol_irel_r_type = Reg{ io.irel().r_type }
|
|
|
|
val xact_vol_irel_src = Reg{ io.irel().client_id }
|
|
|
|
val xact_vol_irel_client_xact_id = Reg{ io.irel().client_xact_id }
|
2015-11-16 22:23:17 +01:00
|
|
|
|
|
|
|
// Miss queue holds transaction metadata used to make grants
|
|
|
|
val ignt_q = Module(new Queue(
|
|
|
|
new SecondaryMissInfo()(p.alterPartial({ case TLId => p(InnerTLId) })),
|
|
|
|
1 + nSecondaryMisses))
|
|
|
|
|
|
|
|
// Some accessor wires derived from the the above state
|
|
|
|
val xact = ignt_q.io.deq.bits
|
|
|
|
val xact_addr_idx = xact_addr_block(idxMSB,idxLSB)
|
2015-11-21 08:21:14 +01:00
|
|
|
val xact_addr_tag = xact_addr_block >> UInt(tagLSB)
|
2016-03-07 08:12:16 +01:00
|
|
|
val xact_vol_irel = Release(
|
|
|
|
src = xact_vol_irel_src,
|
|
|
|
voluntary = Bool(true),
|
|
|
|
r_type = xact_vol_irel_r_type,
|
|
|
|
client_xact_id = xact_vol_irel_client_xact_id,
|
|
|
|
addr_block = xact_addr_block)
|
|
|
|
(p.alterPartial({ case TLId => p(InnerTLId) }))
|
|
|
|
|
2015-11-16 22:23:17 +01:00
|
|
|
// Counters and scoreboard tracking progress made on processing this transaction
|
2015-04-18 01:55:20 +02:00
|
|
|
val pending_irels = connectTwoWayBeatCounter(
|
2015-04-20 07:06:44 +02:00
|
|
|
max = io.inner.tlNCachingClients,
|
2015-04-18 01:55:20 +02:00
|
|
|
up = io.inner.probe,
|
2016-03-07 08:12:16 +01:00
|
|
|
down = io.inner.release,
|
|
|
|
trackDown = (r: Release) => !r.isVoluntary())._1
|
|
|
|
|
|
|
|
val pending_vol_ignt = connectTwoWayBeatCounter(
|
|
|
|
max = 1,
|
|
|
|
up = io.inner.release,
|
|
|
|
down = io.inner.grant,
|
|
|
|
trackUp = (r: Release) => r.isVoluntary(),
|
|
|
|
trackDown = (g: Grant) => g.isVoluntary())._1
|
2015-11-16 22:23:17 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
val (pending_ognt, oacq_data_idx, oacq_data_done, ognt_data_idx, ognt_data_done) =
|
2015-04-18 01:55:20 +02:00
|
|
|
connectTwoWayBeatCounter(
|
|
|
|
max = 1,
|
|
|
|
up = io.outer.acquire,
|
|
|
|
down = io.outer.grant,
|
|
|
|
beat = xact.addr_beat)
|
2015-11-16 22:23:17 +01:00
|
|
|
|
|
|
|
val (ignt_data_idx, ignt_data_done) = connectOutgoingDataBeatCounter(
|
|
|
|
out = io.inner.grant,
|
|
|
|
beat = ignt_q.io.deq.bits.addr_beat)
|
|
|
|
|
2015-04-18 01:55:20 +02:00
|
|
|
val pending_ifins = connectTwoWayBeatCounter(
|
|
|
|
max = nSecondaryMisses,
|
|
|
|
up = io.inner.grant,
|
|
|
|
down = io.inner.finish,
|
2016-03-07 08:12:16 +01:00
|
|
|
trackUp = (g: Grant) => g.requiresAck())._1
|
2015-11-16 22:23:17 +01:00
|
|
|
|
2015-04-14 04:00:40 +02:00
|
|
|
val pending_puts = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
2015-04-20 07:06:44 +02:00
|
|
|
val pending_iprbs = Reg(init = Bits(0, width = io.inner.tlNCachingClients))
|
2015-04-14 04:00:40 +02:00
|
|
|
val pending_reads = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
|
|
|
val pending_writes = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
|
|
|
val pending_resps = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
2015-11-16 22:23:17 +01:00
|
|
|
val ignt_data_ready = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
|
|
|
val pending_meta_write = Reg(init = Bool(false))
|
2015-03-24 10:06:53 +01:00
|
|
|
|
2015-11-16 22:23:17 +01:00
|
|
|
// Used to decide when to escape from s_busy
|
2015-03-24 10:06:53 +01:00
|
|
|
val all_pending_done =
|
|
|
|
!(pending_reads.orR ||
|
|
|
|
pending_writes.orR ||
|
|
|
|
pending_resps.orR ||
|
|
|
|
pending_puts.orR ||
|
2015-04-22 07:23:04 +02:00
|
|
|
pending_ognt ||
|
2015-03-24 10:06:53 +01:00
|
|
|
ignt_q.io.count > UInt(0) ||
|
2016-03-07 08:12:16 +01:00
|
|
|
pending_vol_ignt ||
|
2015-03-24 10:06:53 +01:00
|
|
|
//pending_meta_write || // Has own state: s_meta_write
|
|
|
|
pending_ifins)
|
|
|
|
|
|
|
|
// Provide a single ALU per tracker to merge Puts and AMOs with data being
|
|
|
|
// refilled, written back, or extant in the cache
|
2015-10-17 04:11:06 +02:00
|
|
|
val amoalu = Module(new AMOALU(rhsIsAligned = true))
|
2015-11-16 22:23:17 +01:00
|
|
|
amoalu.io.addr := Cat(xact_addr_block, xact.addr_beat, xact_addr_byte)
|
|
|
|
amoalu.io.cmd := xact_op_code
|
|
|
|
amoalu.io.typ := xact_op_size
|
2015-03-24 10:06:53 +01:00
|
|
|
amoalu.io.lhs := io.data.resp.bits.data // default, overwritten by calls to mergeData
|
2015-11-16 22:23:17 +01:00
|
|
|
amoalu.io.rhs := data_buffer.head // default, overwritten by calls to mergeData
|
2015-10-14 08:42:28 +02:00
|
|
|
val amo_result = Reg(init = UInt(0, xact.tlDataBits))
|
2015-03-24 10:06:53 +01:00
|
|
|
|
2015-11-16 22:23:17 +01:00
|
|
|
// Utility function for updating the metadata that will be kept in this cache
|
2015-03-24 10:06:53 +01:00
|
|
|
def updatePendingCohWhen(flag: Bool, next: HierarchicalMetadata) {
|
2016-01-14 22:47:47 +01:00
|
|
|
when(flag && pending_coh =/= next) {
|
2015-03-24 10:06:53 +01:00
|
|
|
pending_meta_write := Bool(true)
|
|
|
|
pending_coh := next
|
|
|
|
}
|
|
|
|
}
|
2015-02-02 04:57:53 +01:00
|
|
|
|
2015-12-17 05:56:29 +01:00
|
|
|
def addOtherBits(en: Bool, nBits: Int): UInt =
|
|
|
|
Mux(en, Cat(Fill(nBits - 1, UInt(1, 1)), UInt(0, 1)), UInt(0, nBits))
|
|
|
|
|
|
|
|
def addPendingBitsOnFirstBeat(in: DecoupledIO[Acquire]): UInt =
|
|
|
|
addOtherBits(in.fire() &&
|
|
|
|
in.bits.hasMultibeatData() &&
|
|
|
|
in.bits.addr_beat === UInt(0),
|
|
|
|
in.bits.tlDataBeats)
|
|
|
|
|
|
|
|
def dropPendingBitsOnFirstBeat(in: DecoupledIO[Acquire]): UInt =
|
|
|
|
~addPendingBitsOnFirstBeat(in)
|
|
|
|
|
2015-11-16 22:23:17 +01:00
|
|
|
// Defined here because of Chisel default wire demands, used in s_meta_resp
|
|
|
|
val pending_coh_on_hit = HierarchicalMetadata(
|
|
|
|
io.meta.resp.bits.meta.coh.inner,
|
|
|
|
io.meta.resp.bits.meta.coh.outer.onHit(xact_op_code))
|
|
|
|
|
|
|
|
val pending_coh_on_miss = HierarchicalMetadata.onReset
|
|
|
|
|
|
|
|
// Utility function for applying any buffered stored data to the cache line
|
|
|
|
// before storing it back into the data array
|
2015-03-17 07:41:56 +01:00
|
|
|
def mergeData(dataBits: Int)(beat: UInt, incoming: UInt) {
|
2015-03-16 21:27:05 +01:00
|
|
|
val old_data = incoming // Refilled, written back, or de-cached data
|
2015-11-16 22:23:17 +01:00
|
|
|
val new_data = data_buffer(beat) // Newly Put data is already in the buffer
|
2015-11-17 04:07:58 +01:00
|
|
|
amoalu.io.lhs := old_data >> (xact_amo_shift_bytes << 3)
|
|
|
|
amoalu.io.rhs := new_data >> (xact_amo_shift_bytes << 3)
|
2015-03-17 23:54:21 +01:00
|
|
|
val wmask = FillInterleaved(8, wmask_buffer(beat))
|
2015-11-16 22:23:17 +01:00
|
|
|
data_buffer(beat) := ~wmask & old_data |
|
2015-03-17 12:58:54 +01:00
|
|
|
wmask & Mux(xact.isBuiltInType(Acquire.putAtomicType),
|
2015-11-17 04:07:58 +01:00
|
|
|
amoalu.io.out << (xact_amo_shift_bytes << 3),
|
2015-03-17 07:41:56 +01:00
|
|
|
new_data)
|
2015-03-17 23:54:21 +01:00
|
|
|
when(xact.is(Acquire.putAtomicType) && xact.addr_beat === beat) { amo_result := old_data }
|
2015-02-02 04:57:53 +01:00
|
|
|
}
|
2015-11-16 22:23:17 +01:00
|
|
|
|
|
|
|
// TODO: Deal with the possibility that rowBits != tlDataBits
|
2015-10-06 06:41:46 +02:00
|
|
|
def mergeDataInternal[T <: L2HellaCacheBundle with HasL2Data with HasL2BeatAddr](in: ValidIO[T]) {
|
2015-03-24 10:06:53 +01:00
|
|
|
when(in.valid) { mergeData(rowBits)(in.bits.addr_beat, in.bits.data) }
|
|
|
|
}
|
2015-11-16 22:23:17 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def mergeDataInner[T <: TLBundle with HasTileLinkData with HasTileLinkBeatId](in: DecoupledIO[T]) {
|
2015-04-18 01:55:20 +02:00
|
|
|
when(in.fire() && in.bits.hasData()) {
|
|
|
|
mergeData(innerDataBits)(in.bits.addr_beat, in.bits.data)
|
2015-03-24 10:06:53 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-16 22:23:17 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
def mergeDataOuter[T <: TLBundle with HasTileLinkData with HasTileLinkBeatId](in: DecoupledIO[T]) {
|
2015-03-24 10:06:53 +01:00
|
|
|
when(in.fire() && in.bits.hasData()) {
|
|
|
|
mergeData(outerDataBits)(in.bits.addr_beat, in.bits.data)
|
|
|
|
}
|
|
|
|
}
|
2015-03-17 07:41:56 +01:00
|
|
|
|
2015-11-16 22:23:17 +01:00
|
|
|
// and Puts-under-Put, and either may also merge witha preceding prefetch
|
|
|
|
// that requested the correct permissions (via op_code)
|
|
|
|
def acquiresAreMergeable(sec: AcquireMetadata): Bool = {
|
|
|
|
val allowedTypes = List((Acquire.getType, Acquire.getType),
|
|
|
|
(Acquire.putType, Acquire.putType),
|
|
|
|
(Acquire.putBlockType, Acquire.putBlockType),
|
2015-11-17 08:26:13 +01:00
|
|
|
(Acquire.getPrefetchType, Acquire.getPrefetchType),
|
|
|
|
(Acquire.putPrefetchType, Acquire.putPrefetchType),
|
|
|
|
(Acquire.getPrefetchType, Acquire.getType),
|
|
|
|
(Acquire.putPrefetchType, Acquire.putType),
|
|
|
|
(Acquire.putPrefetchType, Acquire.putBlockType))
|
2015-11-16 22:23:17 +01:00
|
|
|
allowedTypes.map { case(a, b) => xact.isBuiltInType(a) && sec.isBuiltInType(b) }.reduce(_||_) &&
|
|
|
|
xact_op_code === sec.op_code() &&
|
|
|
|
sec.conflicts(xact_addr_block) &&
|
2015-12-16 03:17:19 +01:00
|
|
|
xact_allocate
|
2015-11-16 22:23:17 +01:00
|
|
|
}
|
2015-11-12 20:39:36 +01:00
|
|
|
|
2016-03-07 08:12:16 +01:00
|
|
|
// These IOs are used for routing in the parent
|
|
|
|
val iacq_in_same_set = inSameSet(xact_addr_idx, io.iacq().addr_block)
|
|
|
|
val irel_in_same_set = inSameSet(xact_addr_idx,io.irel().addr_block)
|
|
|
|
val before_wb_alloc = Vec(s_meta_read, s_meta_resp, s_wb_req).contains(state)
|
|
|
|
io.matches.iacq := (state =/= s_idle) && iacq_in_same_set
|
|
|
|
io.matches.irel := (state =/= s_idle) &&
|
|
|
|
Mux(before_wb_alloc, irel_in_same_set, io.irel().conflicts(xact_addr_block))
|
|
|
|
io.matches.oprb := Bool(false) //TODO
|
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
// Actual transaction processing logic begins here:
|
|
|
|
//
|
2015-11-16 22:23:17 +01:00
|
|
|
// First, take care of accpeting new acquires or secondary misses
|
|
|
|
val iacq_can_merge = acquiresAreMergeable(io.iacq()) &&
|
|
|
|
state =/= s_idle && state =/= s_meta_write &&
|
|
|
|
!all_pending_done &&
|
|
|
|
!io.inner.release.fire() &&
|
|
|
|
!io.outer.grant.fire() &&
|
|
|
|
!io.data.resp.valid &&
|
|
|
|
ignt_q.io.enq.ready && ignt_q.io.deq.valid
|
2016-03-07 08:12:16 +01:00
|
|
|
|
2015-12-16 03:17:19 +01:00
|
|
|
val iacq_same_xact = xact.client_xact_id === io.iacq().client_xact_id &&
|
2016-03-07 08:12:16 +01:00
|
|
|
xact.hasMultibeatData() &&
|
|
|
|
ignt_q.io.deq.valid && // i.e. state =/= s_idle
|
|
|
|
pending_puts(io.iacq().addr_beat)
|
|
|
|
|
|
|
|
val iacq_accepted = io.inner.acquire.fire() &&
|
|
|
|
(io.alloc.iacq || iacq_can_merge || iacq_same_xact)
|
2015-11-16 22:23:17 +01:00
|
|
|
|
2016-03-07 08:12:16 +01:00
|
|
|
io.inner.acquire.ready := state === s_idle || iacq_can_merge || iacq_same_xact
|
2015-11-16 22:23:17 +01:00
|
|
|
|
|
|
|
// Handling of primary and secondary misses' data and write mask merging
|
2016-03-07 08:12:16 +01:00
|
|
|
when(iacq_accepted && io.iacq().hasData()) {
|
2015-11-16 22:23:17 +01:00
|
|
|
val beat = io.iacq().addr_beat
|
|
|
|
val full = FillInterleaved(8, io.iacq().wmask())
|
|
|
|
data_buffer(beat) := (~full & data_buffer(beat)) | (full & io.iacq().data)
|
|
|
|
wmask_buffer(beat) := io.iacq().wmask() | wmask_buffer(beat) // assumes wmask_buffer is zeroed
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue some metadata information that we'll use to make coherence updates with later
|
2016-03-07 08:12:16 +01:00
|
|
|
ignt_q.io.enq.valid := iacq_accepted && io.iacq().first()
|
2015-11-16 22:23:17 +01:00
|
|
|
ignt_q.io.enq.bits := io.iacq()
|
2015-04-21 01:32:09 +02:00
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
// Track whether any beats are missing from a PutBlock
|
2015-12-16 03:17:19 +01:00
|
|
|
pending_puts := (pending_puts &
|
|
|
|
dropPendingBitWhenBeatHasData(io.inner.acquire)) |
|
|
|
|
addPendingBitsOnFirstBeat(io.inner.acquire)
|
2014-09-30 23:48:02 +02:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
// Begin a transaction by getting the current block metadata
|
|
|
|
io.meta.read.valid := state === s_meta_read
|
|
|
|
io.meta.read.bits.id := UInt(trackerId)
|
2015-11-16 22:23:17 +01:00
|
|
|
io.meta.read.bits.idx := xact_addr_idx
|
|
|
|
io.meta.read.bits.tag := xact_addr_tag
|
2015-04-27 21:56:33 +02:00
|
|
|
|
|
|
|
// Issue a request to the writeback unit
|
|
|
|
io.wb.req.valid := state === s_wb_req
|
|
|
|
io.wb.req.bits.id := UInt(trackerId)
|
2015-11-16 22:23:17 +01:00
|
|
|
io.wb.req.bits.idx := xact_addr_idx
|
2015-04-27 21:56:33 +02:00
|
|
|
io.wb.req.bits.tag := xact_old_meta.tag
|
|
|
|
io.wb.req.bits.coh := xact_old_meta.coh
|
|
|
|
io.wb.req.bits.way_en := xact_way_en
|
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
// Track which clients yet need to be probed and make Probe message
|
|
|
|
pending_iprbs := pending_iprbs & dropPendingBitAtDest(io.inner.probe)
|
|
|
|
val curr_probe_dst = PriorityEncoder(pending_iprbs)
|
|
|
|
io.inner.probe.valid := state === s_inner_probe && pending_iprbs.orR
|
2015-11-16 22:23:17 +01:00
|
|
|
io.inner.probe.bits := pending_coh.inner.makeProbe(curr_probe_dst, xact, xact_addr_block)
|
2015-03-24 10:06:53 +01:00
|
|
|
|
|
|
|
// Handle incoming releases from clients, which may reduce sharer counts
|
2016-03-07 08:12:16 +01:00
|
|
|
// and/or write back dirty data, and may be unexpected voluntary releases
|
|
|
|
val irel_can_merge = io.irel().conflicts(xact_addr_block) &&
|
|
|
|
io.irel().isVoluntary() &&
|
|
|
|
!Vec(s_idle, s_meta_read, s_meta_resp, s_meta_write).contains(state) &&
|
|
|
|
!all_pending_done &&
|
|
|
|
!io.outer.grant.fire() &&
|
|
|
|
!io.inner.grant.fire() &&
|
|
|
|
!pending_vol_ignt
|
|
|
|
|
|
|
|
val irel_same_xact = io.irel().conflicts(xact_addr_block) &&
|
|
|
|
!io.irel().isVoluntary() &&
|
|
|
|
state === s_inner_probe
|
|
|
|
|
|
|
|
val irel_accepted = io.inner.release.fire() &&
|
|
|
|
(io.alloc.irel || irel_can_merge || irel_same_xact)
|
|
|
|
|
|
|
|
io.inner.release.ready := irel_can_merge || irel_same_xact
|
2015-03-24 10:06:53 +01:00
|
|
|
val pending_coh_on_irel = HierarchicalMetadata(
|
2015-04-18 01:55:20 +02:00
|
|
|
pending_coh.inner.onRelease(io.irel()), // Drop sharer
|
2016-03-07 08:12:16 +01:00
|
|
|
Mux(io.irel().hasData(), // Dirty writeback
|
2015-03-24 10:06:53 +01:00
|
|
|
pending_coh.outer.onHit(M_XWR),
|
|
|
|
pending_coh.outer))
|
|
|
|
updatePendingCohWhen(io.inner.release.fire(), pending_coh_on_irel)
|
|
|
|
mergeDataInner(io.inner.release)
|
2016-03-07 08:12:16 +01:00
|
|
|
when(io.inner.release.fire() && irel_can_merge) {
|
|
|
|
xact_vol_irel_r_type := io.irel().r_type
|
|
|
|
xact_vol_irel_src := io.irel().client_id
|
|
|
|
xact_vol_irel_client_xact_id := io.irel().client_xact_id
|
|
|
|
}
|
2015-03-24 10:06:53 +01:00
|
|
|
|
2015-04-14 00:57:06 +02:00
|
|
|
// Handle misses or coherence permission upgrades by initiating a new transaction in the outer memory:
|
2015-03-24 10:06:53 +01:00
|
|
|
//
|
2015-03-01 02:02:13 +01:00
|
|
|
// If we're allocating in this cache, we can use the current metadata
|
|
|
|
// to make an appropriate custom Acquire, otherwise we copy over the
|
|
|
|
// built-in Acquire from the inner TL to the outer TL
|
2015-05-14 21:37:35 +02:00
|
|
|
io.outer.acquire.valid := state === s_outer_acquire &&
|
2015-11-16 22:23:17 +01:00
|
|
|
(xact_allocate || !pending_puts(oacq_data_idx))
|
|
|
|
io.outer.acquire.bits := Mux(xact_allocate,
|
2015-11-13 00:40:58 +01:00
|
|
|
xact_old_meta.coh.outer.makeAcquire(
|
2015-11-16 22:23:17 +01:00
|
|
|
op_code = xact_op_code,
|
2015-05-14 21:37:35 +02:00
|
|
|
client_xact_id = UInt(0),
|
2015-11-16 22:23:17 +01:00
|
|
|
addr_block = xact_addr_block),
|
|
|
|
BuiltInAcquireBuilder(
|
2015-11-13 00:40:58 +01:00
|
|
|
a_type = xact.a_type,
|
|
|
|
client_xact_id = UInt(0),
|
2015-11-16 22:23:17 +01:00
|
|
|
addr_block = xact_addr_block,
|
|
|
|
addr_beat = oacq_data_idx,
|
|
|
|
data = data_buffer(oacq_data_idx),
|
|
|
|
addr_byte = xact_addr_byte,
|
|
|
|
operand_size = xact_op_size,
|
|
|
|
opcode = xact_op_code,
|
|
|
|
wmask = wmask_buffer(oacq_data_idx),
|
|
|
|
alloc = Bool(false))
|
|
|
|
(p.alterPartial({ case TLId => p(OuterTLId)})))
|
2015-03-24 10:06:53 +01:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
// Handle the response from outer memory
|
2015-03-24 10:06:53 +01:00
|
|
|
io.outer.grant.ready := state === s_busy
|
|
|
|
val pending_coh_on_ognt = HierarchicalMetadata(
|
|
|
|
ManagerMetadata.onReset,
|
2015-11-16 22:23:17 +01:00
|
|
|
pending_coh.outer.onGrant(io.outer.grant.bits, xact_op_code))
|
2015-03-24 10:06:53 +01:00
|
|
|
updatePendingCohWhen(ognt_data_done, pending_coh_on_ognt)
|
|
|
|
mergeDataOuter(io.outer.grant)
|
2014-12-19 12:03:53 +01:00
|
|
|
|
2015-11-16 22:23:17 +01:00
|
|
|
// Going back to the original inner transaction:
|
2015-04-14 00:57:06 +02:00
|
|
|
// We read from the the cache at this level if data wasn't written back or refilled.
|
2015-11-16 22:23:17 +01:00
|
|
|
// We may still merge further Gets, requiring further beats to be read.
|
2015-04-14 00:57:06 +02:00
|
|
|
// If ECC requires a full writemask, we'll read out data on partial writes as well.
|
2015-03-24 10:06:53 +01:00
|
|
|
pending_reads := (pending_reads &
|
|
|
|
dropPendingBit(io.data.read) &
|
|
|
|
dropPendingBitWhenBeatHasData(io.inner.release) &
|
|
|
|
dropPendingBitWhenBeatHasData(io.outer.grant)) |
|
2015-04-04 02:24:44 +02:00
|
|
|
addPendingBitWhenBeatIsGetOrAtomic(io.inner.acquire) |
|
|
|
|
addPendingBitWhenBeatHasPartialWritemask(io.inner.acquire)
|
2015-03-24 10:06:53 +01:00
|
|
|
val curr_read_beat = PriorityEncoder(pending_reads)
|
2015-04-22 07:23:04 +02:00
|
|
|
io.data.read.valid := state === s_busy && pending_reads.orR && !pending_ognt
|
2014-11-20 00:55:25 +01:00
|
|
|
io.data.read.bits.id := UInt(trackerId)
|
2014-12-12 10:11:08 +01:00
|
|
|
io.data.read.bits.way_en := xact_way_en
|
2015-11-16 22:23:17 +01:00
|
|
|
io.data.read.bits.addr_idx := xact_addr_idx
|
2015-03-17 07:41:56 +01:00
|
|
|
io.data.read.bits.addr_beat := curr_read_beat
|
2015-03-24 10:06:53 +01:00
|
|
|
|
|
|
|
pending_resps := (pending_resps & dropPendingBitInternal(io.data.resp)) |
|
|
|
|
addPendingBitInternal(io.data.read)
|
|
|
|
mergeDataInternal(io.data.resp)
|
|
|
|
|
2015-04-14 00:57:06 +02:00
|
|
|
// We write data to the cache at this level if it was Put here with allocate flag,
|
|
|
|
// written back dirty, or refilled from outer memory.
|
2015-12-16 03:17:19 +01:00
|
|
|
pending_writes := (pending_writes &
|
|
|
|
dropPendingBit(io.data.write) &
|
|
|
|
dropPendingBitsOnFirstBeat(io.inner.acquire)) |
|
2015-05-13 02:14:06 +02:00
|
|
|
addPendingBitWhenBeatHasDataAndAllocs(io.inner.acquire) |
|
2015-03-24 10:06:53 +01:00
|
|
|
addPendingBitWhenBeatHasData(io.inner.release) |
|
2015-11-16 22:23:17 +01:00
|
|
|
addPendingBitWhenBeatHasData(io.outer.grant, xact_allocate)
|
2015-03-24 10:06:53 +01:00
|
|
|
val curr_write_beat = PriorityEncoder(pending_writes)
|
|
|
|
io.data.write.valid := state === s_busy &&
|
|
|
|
pending_writes.orR &&
|
2015-04-22 07:23:04 +02:00
|
|
|
!pending_ognt &&
|
2015-03-24 10:06:53 +01:00
|
|
|
!pending_reads(curr_write_beat) &&
|
|
|
|
!pending_resps(curr_write_beat)
|
2014-11-20 00:55:25 +01:00
|
|
|
io.data.write.bits.id := UInt(trackerId)
|
2014-12-12 10:11:08 +01:00
|
|
|
io.data.write.bits.way_en := xact_way_en
|
2015-11-16 22:23:17 +01:00
|
|
|
io.data.write.bits.addr_idx := xact_addr_idx
|
2015-03-17 07:41:56 +01:00
|
|
|
io.data.write.bits.addr_beat := curr_write_beat
|
2016-03-07 08:12:16 +01:00
|
|
|
io.data.write.bits.wmask := SInt(-1) // Always writes a full beat
|
2015-11-16 22:23:17 +01:00
|
|
|
io.data.write.bits.data := data_buffer(curr_write_beat)
|
|
|
|
|
|
|
|
// soon as the data is released, granted, put, or read from the cache
|
|
|
|
ignt_data_ready := ignt_data_ready |
|
|
|
|
addPendingBitWhenBeatHasData(io.inner.release) |
|
|
|
|
addPendingBitWhenBeatHasData(io.outer.grant) |
|
|
|
|
addPendingBitInternal(io.data.resp)
|
2015-12-16 03:17:19 +01:00
|
|
|
// We can issue a grant for a pending write once all data is
|
|
|
|
// received and committed to the data array or outer memory
|
2016-03-07 08:12:16 +01:00
|
|
|
val ignt_ack_ready = !(state === s_idle ||
|
|
|
|
state === s_meta_read ||
|
|
|
|
pending_puts.orR ||
|
|
|
|
pending_writes.orR ||
|
|
|
|
pending_ognt)
|
|
|
|
|
|
|
|
ignt_q.io.deq.ready := !pending_vol_ignt && ignt_data_done
|
|
|
|
io.inner.grant.valid := pending_vol_ignt ||
|
|
|
|
(state === s_busy &&
|
|
|
|
ignt_q.io.deq.valid &&
|
|
|
|
Mux(io.ignt().hasData(),
|
|
|
|
ignt_data_ready(ignt_data_idx),
|
|
|
|
ignt_ack_ready))
|
2015-11-16 22:23:17 +01:00
|
|
|
// Make the Grant message using the data stored in the secondary miss queue
|
2016-03-07 08:12:16 +01:00
|
|
|
val grant_from_acquire = pending_coh.inner.makeGrant(
|
|
|
|
sec = ignt_q.io.deq.bits,
|
|
|
|
manager_xact_id = UInt(trackerId),
|
|
|
|
data = Mux(xact.is(Acquire.putAtomicType),
|
|
|
|
amo_result,
|
|
|
|
data_buffer(ignt_data_idx)))
|
|
|
|
val grant_from_release = pending_coh.inner.makeGrant(xact_vol_irel)
|
|
|
|
io.inner.grant.bits := Mux(pending_vol_ignt, grant_from_release, grant_from_acquire)
|
2015-11-16 22:23:17 +01:00
|
|
|
io.inner.grant.bits.addr_beat := ignt_data_idx // override based on outgoing counter
|
|
|
|
|
|
|
|
val pending_coh_on_ignt = HierarchicalMetadata(
|
|
|
|
pending_coh.inner.onGrant(io.ignt()),
|
|
|
|
Mux(ognt_data_done,
|
|
|
|
pending_coh_on_ognt.outer,
|
|
|
|
pending_coh.outer))
|
2016-03-02 19:59:18 +01:00
|
|
|
updatePendingCohWhen(io.inner.grant.fire() && io.ignt().last(), pending_coh_on_ignt)
|
2015-11-16 22:23:17 +01:00
|
|
|
|
|
|
|
// We must wait for as many Finishes as we sent Grants
|
|
|
|
io.inner.finish.ready := state === s_busy
|
2015-03-24 10:06:53 +01:00
|
|
|
|
2015-04-27 21:56:33 +02:00
|
|
|
// End a transaction by updating the block metadata
|
2015-11-13 22:50:35 +01:00
|
|
|
io.meta.write.valid := state === s_meta_write
|
2014-11-20 00:55:25 +01:00
|
|
|
io.meta.write.bits.id := UInt(trackerId)
|
2015-11-16 22:23:17 +01:00
|
|
|
io.meta.write.bits.idx := xact_addr_idx
|
2014-12-12 10:11:08 +01:00
|
|
|
io.meta.write.bits.way_en := xact_way_en
|
2015-11-16 22:23:17 +01:00
|
|
|
io.meta.write.bits.data.tag := xact_addr_tag
|
2015-03-01 02:02:13 +01:00
|
|
|
io.meta.write.bits.data.coh := pending_coh
|
|
|
|
|
2015-03-24 10:06:53 +01:00
|
|
|
// State machine updates and transaction handler metadata intialization
|
2016-03-07 08:12:16 +01:00
|
|
|
when(state === s_idle && io.inner.acquire.valid && io.alloc.iacq) {
|
2015-11-16 22:23:17 +01:00
|
|
|
xact_addr_block := io.iacq().addr_block
|
|
|
|
xact_allocate := io.iacq().allocate()
|
2015-11-17 04:07:58 +01:00
|
|
|
xact_amo_shift_bytes := io.iacq().amo_shift_bytes()
|
2015-11-16 22:23:17 +01:00
|
|
|
xact_op_code := io.iacq().op_code()
|
|
|
|
xact_addr_byte := io.iacq().addr_byte()
|
|
|
|
xact_op_size := io.iacq().op_size()
|
2015-10-14 08:42:28 +02:00
|
|
|
amo_result := UInt(0)
|
2015-04-14 00:57:06 +02:00
|
|
|
pending_puts := Mux( // Make sure to collect all data from a PutBlock
|
2015-03-24 10:06:53 +01:00
|
|
|
io.iacq().isBuiltInType(Acquire.putBlockType),
|
|
|
|
dropPendingBitWhenBeatHasData(io.inner.acquire),
|
|
|
|
UInt(0))
|
2015-04-14 00:57:06 +02:00
|
|
|
pending_reads := Mux( // GetBlocks and custom types read all beats
|
2015-03-24 10:06:53 +01:00
|
|
|
io.iacq().isBuiltInType(Acquire.getBlockType) || !io.iacq().isBuiltInType(),
|
2015-07-11 23:05:39 +02:00
|
|
|
SInt(-1),
|
2015-04-04 02:24:44 +02:00
|
|
|
(addPendingBitWhenBeatIsGetOrAtomic(io.inner.acquire) |
|
2015-07-11 23:05:39 +02:00
|
|
|
addPendingBitWhenBeatHasPartialWritemask(io.inner.acquire)).toSInt).toUInt
|
2015-05-13 02:14:06 +02:00
|
|
|
pending_writes := addPendingBitWhenBeatHasDataAndAllocs(io.inner.acquire)
|
2015-03-24 10:06:53 +01:00
|
|
|
pending_resps := UInt(0)
|
2015-11-16 22:23:17 +01:00
|
|
|
ignt_data_ready := UInt(0)
|
2015-11-13 22:50:35 +01:00
|
|
|
pending_meta_write := Bool(false)
|
2015-03-24 10:06:53 +01:00
|
|
|
state := s_meta_read
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
2015-03-24 10:06:53 +01:00
|
|
|
when(state === s_meta_read && io.meta.read.ready) { state := s_meta_resp }
|
|
|
|
when(state === s_meta_resp && io.meta.resp.valid) {
|
|
|
|
xact_tag_match := io.meta.resp.bits.tag_match
|
|
|
|
xact_old_meta := io.meta.resp.bits.meta
|
|
|
|
xact_way_en := io.meta.resp.bits.way_en
|
|
|
|
val coh = io.meta.resp.bits.meta.coh
|
|
|
|
val tag_match = io.meta.resp.bits.tag_match
|
2015-11-16 22:23:17 +01:00
|
|
|
val is_hit = (if(!isLastLevelCache) tag_match && coh.outer.isHit(xact_op_code)
|
2015-12-16 03:17:19 +01:00
|
|
|
else tag_match && coh.outer.isValid())
|
2015-03-24 10:06:53 +01:00
|
|
|
val needs_writeback = !tag_match &&
|
2015-11-16 22:23:17 +01:00
|
|
|
xact_allocate &&
|
2015-03-24 10:06:53 +01:00
|
|
|
(coh.outer.requiresVoluntaryWriteback() ||
|
|
|
|
coh.inner.requiresProbesOnVoluntaryWriteback())
|
|
|
|
val needs_inner_probes = tag_match && coh.inner.requiresProbes(xact)
|
2015-11-16 22:23:17 +01:00
|
|
|
val should_update_meta = !tag_match && xact_allocate ||
|
2016-01-14 22:47:47 +01:00
|
|
|
is_hit && pending_coh_on_hit =/= coh
|
2015-11-15 21:51:34 +01:00
|
|
|
// Determine any changes to the coherence metadata
|
2015-11-13 00:40:58 +01:00
|
|
|
when (should_update_meta) { pending_meta_write := Bool(true) }
|
2015-06-25 03:01:56 +02:00
|
|
|
pending_coh := Mux(is_hit, pending_coh_on_hit, Mux(tag_match, coh, pending_coh_on_miss))
|
2015-11-15 21:51:34 +01:00
|
|
|
// If we need to probe some clients, make a bitmask identifying them
|
2015-11-13 00:40:58 +01:00
|
|
|
when (needs_inner_probes) {
|
2015-03-24 10:06:53 +01:00
|
|
|
val full_sharers = coh.inner.full()
|
|
|
|
val mask_self = Mux(
|
|
|
|
xact.requiresSelfProbe(),
|
2015-04-18 01:55:20 +02:00
|
|
|
coh.inner.full() | UIntToOH(xact.client_id),
|
|
|
|
coh.inner.full() & ~UIntToOH(xact.client_id))
|
2015-03-24 10:06:53 +01:00
|
|
|
val mask_incoherent = mask_self & ~io.incoherent.toBits
|
|
|
|
pending_iprbs := mask_incoherent
|
2015-11-15 21:51:34 +01:00
|
|
|
}
|
2015-11-16 22:23:17 +01:00
|
|
|
// If some kind of Put is marked no-allocate but is already in the cache,
|
|
|
|
// we need to write its data to the data array
|
|
|
|
when (is_hit && !xact_allocate && xact.hasData()) {
|
|
|
|
pending_writes := addPendingBitsFromAcquire(xact)
|
2015-12-16 03:17:19 +01:00
|
|
|
xact_allocate := Bool(true)
|
2015-11-12 20:39:36 +01:00
|
|
|
}
|
2015-11-15 21:51:34 +01:00
|
|
|
// Next: request writeback, issue probes, query outer memory, or respond
|
2015-03-24 10:06:53 +01:00
|
|
|
state := Mux(needs_writeback, s_wb_req,
|
|
|
|
Mux(needs_inner_probes, s_inner_probe,
|
|
|
|
Mux(!is_hit, s_outer_acquire, s_busy)))
|
|
|
|
}
|
|
|
|
when(state === s_wb_req && io.wb.req.ready) { state := s_wb_resp }
|
2015-12-17 05:56:29 +01:00
|
|
|
when(state === s_wb_resp && io.wb.resp.valid) { state := s_outer_acquire }
|
2015-03-24 10:06:53 +01:00
|
|
|
when(state === s_inner_probe && !(pending_iprbs.orR || pending_irels)) {
|
|
|
|
// Tag matches, so if this is the last level cache we can use the data without upgrading permissions
|
|
|
|
val skip_outer_acquire =
|
2015-11-16 22:23:17 +01:00
|
|
|
(if(!isLastLevelCache) xact_old_meta.coh.outer.isHit(xact_op_code)
|
2015-12-17 05:56:29 +01:00
|
|
|
else xact_old_meta.coh.outer.isValid())
|
2015-03-24 10:06:53 +01:00
|
|
|
state := Mux(!skip_outer_acquire, s_outer_acquire, s_busy)
|
|
|
|
}
|
|
|
|
when(state === s_outer_acquire && oacq_data_done) { state := s_busy }
|
2015-11-13 22:50:35 +01:00
|
|
|
when(state === s_busy && all_pending_done) {
|
2015-11-16 22:23:17 +01:00
|
|
|
wmask_buffer.foreach { w => w := UInt(0) } // This is the only reg that must be clear in s_idle
|
2015-11-13 22:50:35 +01:00
|
|
|
state := Mux(pending_meta_write, s_meta_write, s_idle)
|
2015-03-17 07:41:56 +01:00
|
|
|
}
|
2015-11-13 22:50:35 +01:00
|
|
|
when(state === s_meta_write && io.meta.write.ready) { state := s_idle }
|
2014-09-30 23:48:02 +02:00
|
|
|
}
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2WritebackReq(implicit p: Parameters) extends L2Metadata()(p) with HasL2Id {
|
2015-04-22 07:23:04 +02:00
|
|
|
val idx = Bits(width = idxBits)
|
2015-03-01 02:02:13 +01:00
|
|
|
val way_en = Bits(width = nWays)
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2WritebackResp(implicit p: Parameters) extends L2HellaCacheBundle()(p) with HasL2Id
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2WritebackIO(implicit p: Parameters) extends L2HellaCacheBundle()(p) {
|
2015-03-01 02:02:13 +01:00
|
|
|
val req = Decoupled(new L2WritebackReq)
|
|
|
|
val resp = Valid(new L2WritebackResp).flip
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2WritebackUnitIO(implicit p: Parameters) extends HierarchicalXactTrackerIO()(p) {
|
2015-03-01 02:02:13 +01:00
|
|
|
val wb = new L2WritebackIO().flip
|
|
|
|
val data = new L2DataRWIO
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class L2WritebackUnit(trackerId: Int)(implicit p: Parameters) extends L2XactTracker()(p) {
|
2015-03-01 02:02:13 +01:00
|
|
|
val io = new L2WritebackUnitIO
|
2015-04-27 21:56:33 +02:00
|
|
|
pinAllReadyValidLow(io)
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
val s_idle :: s_inner_probe :: s_busy :: s_outer_grant :: s_wb_resp :: Nil = Enum(UInt(), 5)
|
2015-03-01 02:02:13 +01:00
|
|
|
val state = Reg(init=s_idle)
|
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
val xact = Reg(new L2WritebackReq)
|
2015-09-26 02:06:06 +02:00
|
|
|
val data_buffer = Reg(init=Vec.fill(innerDataBeats)(UInt(0, width = innerDataBits)))
|
2016-03-07 08:12:16 +01:00
|
|
|
val xact_vol_irel_r_type = Reg{ io.irel().r_type }
|
|
|
|
val xact_vol_irel_src = Reg{ io.irel().client_id }
|
|
|
|
val xact_vol_irel_client_xact_id = Reg{ io.irel().client_xact_id }
|
|
|
|
|
2016-03-07 01:32:14 +01:00
|
|
|
val xact_addr_block = if (cacheIdBits == 0)
|
|
|
|
Cat(xact.tag, xact.idx)
|
|
|
|
else
|
|
|
|
Cat(xact.tag, xact.idx, UInt(cacheId, cacheIdBits))
|
2016-03-07 08:12:16 +01:00
|
|
|
val xact_vol_irel = Release(
|
|
|
|
src = xact_vol_irel_src,
|
|
|
|
voluntary = Bool(true),
|
|
|
|
r_type = xact_vol_irel_r_type,
|
|
|
|
client_xact_id = xact_vol_irel_client_xact_id,
|
|
|
|
addr_block = xact_addr_block)
|
|
|
|
|
|
|
|
val pending_irels = connectTwoWayBeatCounter(
|
|
|
|
max = io.inner.tlNCachingClients,
|
|
|
|
up = io.inner.probe,
|
|
|
|
down = io.inner.release,
|
|
|
|
trackDown = (r: Release) => !r.isVoluntary())._1
|
|
|
|
|
|
|
|
val pending_vol_ignt = connectTwoWayBeatCounter(
|
|
|
|
max = 1,
|
|
|
|
up = io.inner.release,
|
|
|
|
down = io.inner.grant,
|
|
|
|
trackUp = (r: Release) => r.isVoluntary(),
|
|
|
|
trackDown = (g: Grant) => g.isVoluntary())._1
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
val (pending_ognt, orel_data_idx, orel_data_done, ognt_data_idx, ognt_data_done) =
|
2016-03-07 08:12:16 +01:00
|
|
|
connectTwoWayBeatCounter(
|
|
|
|
max = 1,
|
|
|
|
up = io.outer.release,
|
|
|
|
down = io.outer.grant)
|
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
val pending_iprbs = Reg(init = Bits(0, width = io.inner.tlNCachingClients))
|
|
|
|
val pending_reads = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
|
|
|
val pending_resps = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
|
|
|
val pending_orel_data = Reg(init=Bits(0, width = io.inner.tlDataBeats))
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2016-03-07 08:12:16 +01:00
|
|
|
// These IOs are used for routing in the parent
|
|
|
|
io.matches.iacq := (state =/= s_idle) && io.iacq().conflicts(xact_addr_block)
|
|
|
|
io.matches.irel := (state =/= s_idle) && io.irel().conflicts(xact_addr_block)
|
|
|
|
io.matches.oprb := (state =/= s_idle) && io.oprb().conflicts(xact_addr_block)
|
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
// Start the writeback sub-transaction
|
|
|
|
io.wb.req.ready := state === s_idle
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
// Track which clients yet need to be probed and make Probe message
|
|
|
|
pending_iprbs := pending_iprbs & dropPendingBitAtDest(io.inner.probe)
|
|
|
|
val curr_probe_dst = PriorityEncoder(pending_iprbs)
|
|
|
|
io.inner.probe.valid := state === s_inner_probe && pending_iprbs.orR
|
|
|
|
io.inner.probe.bits := xact.coh.inner.makeProbeForVoluntaryWriteback(curr_probe_dst, xact_addr_block)
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
// Handle incoming releases from clients, which may reduce sharer counts
|
|
|
|
// and/or write back dirty data
|
2016-03-07 08:12:16 +01:00
|
|
|
val irel_can_merge = io.irel().conflicts(xact_addr_block) &&
|
|
|
|
io.irel().isVoluntary() &&
|
|
|
|
state === s_inner_probe &&
|
|
|
|
!pending_vol_ignt
|
|
|
|
|
|
|
|
val irel_same_xact = io.irel().conflicts(xact_addr_block) &&
|
|
|
|
!io.irel().isVoluntary() &&
|
|
|
|
state === s_inner_probe
|
|
|
|
|
|
|
|
val irel_accepted = io.inner.release.fire() &&
|
|
|
|
(io.alloc.irel || irel_can_merge || irel_same_xact)
|
|
|
|
|
|
|
|
io.inner.release.ready := irel_can_merge || irel_same_xact
|
|
|
|
val pending_coh_on_irel = HierarchicalMetadata(
|
|
|
|
xact.coh.inner.onRelease(io.irel()), // Drop sharer
|
|
|
|
Mux(io.irel().hasData(), // Dirty writeback
|
|
|
|
xact.coh.outer.onHit(M_XWR),
|
|
|
|
xact.coh.outer))
|
2015-04-22 07:23:04 +02:00
|
|
|
when(io.inner.release.fire()) {
|
2016-03-07 08:12:16 +01:00
|
|
|
xact.coh := pending_coh_on_irel
|
|
|
|
when(io.irel().hasData()) { data_buffer(io.irel().addr_beat) := io.irel().data }
|
|
|
|
when(irel_can_merge) {
|
|
|
|
xact_vol_irel_r_type := io.irel().r_type
|
|
|
|
xact_vol_irel_src := io.irel().client_id
|
|
|
|
xact_vol_irel_client_xact_id := io.irel().client_xact_id
|
|
|
|
}
|
2015-07-02 22:52:40 +02:00
|
|
|
}
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
// If a release didn't write back data, have to read it from data array
|
|
|
|
pending_reads := (pending_reads &
|
|
|
|
dropPendingBit(io.data.read) &
|
|
|
|
dropPendingBitWhenBeatHasData(io.inner.release))
|
|
|
|
val curr_read_beat = PriorityEncoder(pending_reads)
|
|
|
|
io.data.read.valid := state === s_busy && pending_reads.orR
|
|
|
|
io.data.read.bits.id := UInt(trackerId)
|
|
|
|
io.data.read.bits.way_en := xact.way_en
|
|
|
|
io.data.read.bits.addr_idx := xact.idx
|
|
|
|
io.data.read.bits.addr_beat := curr_read_beat
|
|
|
|
io.data.write.valid := Bool(false)
|
|
|
|
|
|
|
|
pending_resps := (pending_resps & dropPendingBitInternal(io.data.resp)) |
|
|
|
|
addPendingBitInternal(io.data.read)
|
|
|
|
when(io.data.resp.valid) {
|
|
|
|
data_buffer(io.data.resp.bits.addr_beat) := io.data.resp.bits.data
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once the data is buffered we can write it back to outer memory
|
|
|
|
pending_orel_data := pending_orel_data |
|
|
|
|
addPendingBitWhenBeatHasData(io.inner.release) |
|
|
|
|
addPendingBitInternal(io.data.resp)
|
|
|
|
io.outer.release.valid := state === s_busy &&
|
|
|
|
(!io.orel().hasData() || pending_orel_data(orel_data_idx))
|
|
|
|
io.outer.release.bits := xact.coh.outer.makeVoluntaryWriteback(
|
2015-03-24 10:06:53 +01:00
|
|
|
client_xact_id = UInt(trackerId),
|
|
|
|
addr_block = xact_addr_block,
|
2015-04-22 07:23:04 +02:00
|
|
|
addr_beat = orel_data_idx,
|
|
|
|
data = data_buffer(orel_data_idx))
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2016-03-07 08:12:16 +01:00
|
|
|
// Ack a voluntary release if we got one
|
|
|
|
io.inner.grant.valid := pending_vol_ignt
|
|
|
|
io.inner.grant.bits := xact.coh.inner.makeGrant(xact_vol_irel)
|
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
// Wait for an acknowledgement
|
|
|
|
io.outer.grant.ready := state === s_outer_grant
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
// Respond to the initiating transaction handler signalling completion of the writeback
|
|
|
|
io.wb.resp.valid := state === s_wb_resp
|
|
|
|
io.wb.resp.bits.id := xact.id
|
2015-03-01 02:02:13 +01:00
|
|
|
|
2015-04-22 07:23:04 +02:00
|
|
|
// State machine updates and transaction handler metadata intialization
|
|
|
|
when(state === s_idle && io.wb.req.valid) {
|
|
|
|
xact := io.wb.req.bits
|
|
|
|
val coh = io.wb.req.bits.coh
|
|
|
|
val needs_inner_probes = coh.inner.requiresProbesOnVoluntaryWriteback()
|
|
|
|
when(needs_inner_probes) { pending_iprbs := coh.inner.full() & ~io.incoherent.toBits }
|
2015-08-27 18:57:36 +02:00
|
|
|
pending_reads := ~UInt(0, width = innerDataBeats)
|
2015-04-22 07:23:04 +02:00
|
|
|
pending_resps := UInt(0)
|
|
|
|
pending_orel_data := UInt(0)
|
|
|
|
state := Mux(needs_inner_probes, s_inner_probe, s_busy)
|
|
|
|
}
|
2016-03-07 08:12:16 +01:00
|
|
|
when(state === s_inner_probe && !(pending_iprbs.orR || pending_irels || pending_vol_ignt)) {
|
2015-04-22 07:23:04 +02:00
|
|
|
state := Mux(xact.coh.outer.requiresVoluntaryWriteback(), s_busy, s_wb_resp)
|
|
|
|
}
|
|
|
|
when(state === s_busy && orel_data_done) {
|
|
|
|
state := Mux(io.orel().requiresAck(), s_outer_grant, s_wb_resp)
|
|
|
|
}
|
|
|
|
when(state === s_outer_grant && ognt_data_done) { state := s_wb_resp }
|
|
|
|
when(state === s_wb_resp ) { state := s_idle }
|
2015-03-01 02:02:13 +01:00
|
|
|
}
|