2014-04-23 01:55:35 +02:00
|
|
|
package uncore
|
|
|
|
import Chisel._
|
|
|
|
|
2014-04-27 04:11:36 +02:00
|
|
|
trait CacheConfig {
|
2014-04-23 01:55:35 +02:00
|
|
|
def sets: Int
|
|
|
|
def ways: Int
|
|
|
|
def tl: TileLinkConfiguration
|
|
|
|
def as: AddressSpaceConfiguration
|
|
|
|
def dm: Boolean
|
|
|
|
def states: Int
|
|
|
|
def lines: Int
|
|
|
|
def tagbits: Int
|
|
|
|
def idxbits: Int
|
|
|
|
def offbits: Int
|
|
|
|
def untagbits: Int
|
|
|
|
def rowbits: Int
|
|
|
|
}
|
|
|
|
|
2014-04-27 04:11:36 +02:00
|
|
|
case class L2CacheConfig(
|
|
|
|
val sets: Int, val ways: Int,
|
|
|
|
val nrpq: Int, val nsdq: Int,
|
|
|
|
val nReleaseTransactions: Int,
|
|
|
|
val nAcquireTransactions: Int,
|
|
|
|
val tl: TileLinkConfiguration,
|
|
|
|
val as: AddressSpaceConfiguration)
|
|
|
|
extends CoherenceAgentConfiguration
|
|
|
|
with CacheConfig
|
|
|
|
{
|
2014-04-23 01:55:35 +02:00
|
|
|
def states = tl.co.nMasterStates
|
|
|
|
def lines = sets*ways
|
|
|
|
def dm = ways == 1
|
|
|
|
def offbits = 0
|
|
|
|
def lineaddrbits = tl.addrBits
|
|
|
|
def idxbits = log2Up(sets)
|
|
|
|
def waybits = log2Up(ways)
|
|
|
|
def untagbits = offbits + idxbits
|
|
|
|
def tagbits = lineaddrbits - idxbits
|
2014-04-27 04:11:36 +02:00
|
|
|
def wordbits = 64
|
|
|
|
def wordbytes = wordbits/8
|
|
|
|
def wordoffbits = log2Up(wordbytes)
|
2014-04-23 01:55:35 +02:00
|
|
|
def rowbits = tl.dataBits
|
|
|
|
def rowbytes = rowbits/8
|
|
|
|
def rowoffbits = log2Up(rowbytes)
|
|
|
|
def refillcycles = tl.dataBits/(rowbits)
|
|
|
|
def statebits = log2Up(states)
|
2014-05-07 10:51:46 +02:00
|
|
|
def nTSHRs = nReleaseTransactions + nAcquireTransactions
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
require(states > 0)
|
|
|
|
require(isPow2(sets))
|
|
|
|
require(isPow2(ways)) // TODO: relax this
|
2014-04-27 04:11:36 +02:00
|
|
|
require(refillcycles == 1) //TODO: relax this?
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract trait CacheBundle extends Bundle {
|
2014-04-27 04:11:36 +02:00
|
|
|
implicit val cacheconf: CacheConfig
|
|
|
|
override def clone = this.getClass.getConstructors.head.newInstance(cacheconf).asInstanceOf[this.type]
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract trait L2CacheBundle extends Bundle {
|
2014-04-27 04:11:36 +02:00
|
|
|
implicit val l2cacheconf: L2CacheConfig
|
|
|
|
override def clone = this.getClass.getConstructors.head.newInstance(l2cacheconf).asInstanceOf[this.type]
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 10:51:46 +02:00
|
|
|
trait HasL2Id extends L2CacheBundle {
|
|
|
|
val id = UInt(width = log2Up(l2cacheconf.nTSHRs))
|
|
|
|
}
|
|
|
|
|
|
|
|
trait HasL2InternalRequestState extends L2CacheBundle {
|
|
|
|
val tag_match = Bool()
|
2014-05-28 22:35:08 +02:00
|
|
|
val old_meta = new L2Metadata
|
2014-05-07 10:51:46 +02:00
|
|
|
val way_en = Bits(width = l2cacheconf.ways)
|
|
|
|
}
|
|
|
|
|
2014-04-23 01:55:35 +02:00
|
|
|
abstract class ReplacementPolicy {
|
|
|
|
def way: UInt
|
|
|
|
def miss: Unit
|
|
|
|
def hit: Unit
|
|
|
|
}
|
|
|
|
|
2014-04-27 04:11:36 +02:00
|
|
|
class RandomReplacement(implicit val cacheconf: CacheConfig) extends ReplacementPolicy {
|
2014-04-23 01:55:35 +02:00
|
|
|
private val replace = Bool()
|
|
|
|
replace := Bool(false)
|
|
|
|
val lfsr = LFSR16(replace)
|
|
|
|
|
2014-04-27 04:11:36 +02:00
|
|
|
def way = if(cacheconf.dm) UInt(0) else lfsr(log2Up(cacheconf.ways)-1,0)
|
2014-04-23 01:55:35 +02:00
|
|
|
def miss = replace := Bool(true)
|
|
|
|
def hit = {}
|
|
|
|
}
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
abstract class Metadata(implicit val cacheconf: CacheConfig) extends CacheBundle {
|
2014-04-27 04:11:36 +02:00
|
|
|
val tag = Bits(width = cacheconf.tagbits)
|
2014-05-28 22:35:08 +02:00
|
|
|
val coh: CoherenceMetadata
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-04-27 04:11:36 +02:00
|
|
|
class MetaReadReq(implicit val cacheconf: CacheConfig) extends CacheBundle {
|
|
|
|
val idx = Bits(width = cacheconf.idxbits)
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
class MetaWriteReq[T <: Metadata](gen: T)(implicit conf: CacheConfig) extends MetaReadReq {
|
2014-04-23 01:55:35 +02:00
|
|
|
val way_en = Bits(width = conf.ways)
|
2014-05-01 10:44:59 +02:00
|
|
|
val data = gen.clone
|
|
|
|
override def clone = new MetaWriteReq(gen)(conf).asInstanceOf[this.type]
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
class MetadataArray[T <: Metadata](makeRstVal: () => T)(implicit conf: CacheConfig) extends Module {
|
2014-04-23 01:55:35 +02:00
|
|
|
implicit val tl = conf.tl
|
2014-05-28 22:35:08 +02:00
|
|
|
val rstVal = makeRstVal()
|
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
|
2014-05-06 21:59:45 +02:00
|
|
|
val write = Decoupled(new MetaWriteReq(rstVal.clone)).flip
|
|
|
|
val resp = Vec.fill(conf.ways){rstVal.clone.asOutput}
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
2014-05-06 21:59:45 +02:00
|
|
|
val metabits = rstVal.getWidth
|
2014-04-23 01:55:35 +02:00
|
|
|
val rst_cnt = Reg(init=UInt(0, log2Up(conf.sets+1)))
|
|
|
|
val rst = rst_cnt < UInt(conf.sets)
|
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
|
|
|
|
val wmask = Mux(rst, SInt(-1), io.write.bits.way_en)
|
2014-04-23 01:55:35 +02:00
|
|
|
when (rst) { rst_cnt := rst_cnt+UInt(1) }
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
val tag_arr = Mem(UInt(width = metabits*conf.ways), conf.sets, seqRead = true)
|
2014-04-23 01:55:35 +02:00
|
|
|
when (rst || io.write.valid) {
|
2014-05-28 22:35:08 +02:00
|
|
|
tag_arr.write(waddr, Fill(conf.ways, wdata), FillInterleaved(metabits, wmask))
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
val tags = tag_arr(RegEnable(io.read.bits.idx, io.read.valid))
|
2014-04-23 01:55:35 +02:00
|
|
|
for (w <- 0 until conf.ways) {
|
2014-05-28 22:35:08 +02:00
|
|
|
val m = tags(metabits*(w+1)-1, metabits*w)
|
2014-05-06 21:59:45 +02:00
|
|
|
io.resp(w) := rstVal.clone.fromBits(m)
|
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-05-28 22:35:08 +02:00
|
|
|
object L2Metadata {
|
|
|
|
def apply(tag: Bits, coh: MasterMetadata)(implicit conf: L2CacheConfig) = {
|
|
|
|
val meta = new L2Metadata
|
2014-05-07 10:51:46 +02:00
|
|
|
meta.tag := tag
|
2014-05-28 22:35:08 +02:00
|
|
|
meta.coh := coh
|
2014-05-07 10:51:46 +02:00
|
|
|
meta
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 22:35:08 +02:00
|
|
|
class L2Metadata(implicit val l2cacheconf: L2CacheConfig) extends Metadata
|
2014-05-07 10:51:46 +02:00
|
|
|
with L2CacheBundle {
|
2014-05-28 22:35:08 +02:00
|
|
|
val coh = l2cacheconf.tl.co.masterMetadataOnFlush.clone
|
2014-05-07 10:51:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-05-28 22:35:08 +02:00
|
|
|
class L3Metadata(implicit conf: L3CacheConfig) extends Metadata
|
|
|
|
with L3CacheBundle {
|
|
|
|
val coh = MixedMetaData(conf.innerTL.co, conf.outerTL.co) ?
|
2014-05-07 10:51:46 +02:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
class L2MetaReadReq(implicit val l2cacheconf: L2CacheConfig) extends MetaReadReq
|
|
|
|
with HasL2Id {
|
|
|
|
val tag = Bits(width = l2cacheconf.tagbits)
|
|
|
|
}
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
class L2MetaWriteReq(implicit val l2cacheconf: L2CacheConfig) extends MetaWriteReq[L2Metadata](new L2Metadata)
|
2014-05-07 10:51:46 +02:00
|
|
|
with HasL2Id
|
|
|
|
|
|
|
|
class L2MetaResp(implicit val l2cacheconf: L2CacheConfig) extends L2CacheBundle
|
|
|
|
with HasL2Id
|
|
|
|
with HasL2InternalRequestState
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
class L2MetadataArray(implicit conf: L2CacheConfig) extends Module {
|
2014-05-07 10:51:46 +02:00
|
|
|
implicit val tl = conf.tl
|
|
|
|
val io = new Bundle {
|
|
|
|
val read = Decoupled(new L2MetaReadReq).flip
|
|
|
|
val write = Decoupled(new L2MetaWriteReq).flip
|
|
|
|
val resp = Valid(new L2MetaResp)
|
|
|
|
}
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
val meta = Module(new MetadataArray(() => L2Metadata(UInt(0), tl.co.masterMetadataOnFlush)))
|
2014-05-07 10:51:46 +02:00
|
|
|
meta.io.read <> io.read
|
|
|
|
meta.io.write <> io.write
|
|
|
|
|
|
|
|
val s1_clk_en = Reg(next = io.read.fire())
|
|
|
|
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 conf.ways).map(f))
|
|
|
|
val s1_tag_eq_way = wayMap((w: Int) => meta.io.resp(w).tag === s1_tag)
|
2014-05-28 22:35:08 +02:00
|
|
|
val s1_tag_match_way = wayMap((w: Int) => s1_tag_eq_way(w) && tl.co.isValid(meta.io.resp(w).coh)).toBits
|
2014-05-07 10:51:46 +02:00
|
|
|
val s2_tag_match_way = RegEnable(s1_tag_match_way, s1_clk_en)
|
|
|
|
val s2_tag_match = s2_tag_match_way.orR
|
2014-05-28 22:35:08 +02:00
|
|
|
val s2_hit_coh = Mux1H(s2_tag_match_way, wayMap((w: Int) => RegEnable(meta.io.resp(w).coh, s1_clk_en)))
|
|
|
|
//val s2_hit = s2_tag_match && tl.co.isHit(s2_req.cmd, s2_hit_state) && s2_hit_state === tl.co.newStateOnHit(s2_req.cmd, s2_hit_state)
|
2014-05-07 10:51:46 +02:00
|
|
|
|
|
|
|
val replacer = new RandomReplacement
|
|
|
|
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.old_meta := Mux(s2_tag_match,
|
2014-05-28 22:35:08 +02:00
|
|
|
L2Metadata(s2_repl_meta.tag, s2_hit_coh),
|
2014-05-07 10:51:46 +02:00
|
|
|
s2_repl_meta)
|
|
|
|
io.resp.bits.way_en := Mux(s2_tag_match, s2_tag_match_way, s2_replaced_way_en)
|
|
|
|
}
|
|
|
|
|
|
|
|
class L2DataReadReq(implicit val l2cacheconf: L2CacheConfig) extends L2CacheBundle
|
|
|
|
with HasL2Id {
|
2014-04-27 04:11:36 +02:00
|
|
|
val way_en = Bits(width = l2cacheconf.ways)
|
|
|
|
val addr = Bits(width = l2cacheconf.tl.addrBits)
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 10:51:46 +02:00
|
|
|
class L2DataWriteReq(implicit l2cacheconf: L2CacheConfig) extends L2DataReadReq {
|
|
|
|
val wmask = Bits(width = l2cacheconf.tl.writeMaskBits)
|
|
|
|
val data = Bits(width = l2cacheconf.tl.dataBits)
|
|
|
|
}
|
|
|
|
|
|
|
|
class L2DataResp(implicit val l2cacheconf: L2CacheConfig) extends L2CacheBundle
|
|
|
|
with HasL2Id {
|
|
|
|
val data = Bits(width = l2cacheconf.tl.dataBits)
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class L2DataArray(implicit conf: L2CacheConfig) extends Module {
|
|
|
|
val io = new Bundle {
|
|
|
|
val read = Decoupled(new L2DataReadReq).flip
|
|
|
|
val write = Decoupled(new L2DataWriteReq).flip
|
2014-05-07 10:51:46 +02:00
|
|
|
val resp = Valid(new L2DataResp)
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-04-27 04:11:36 +02:00
|
|
|
val waddr = io.write.bits.addr
|
|
|
|
val raddr = io.read.bits.addr
|
|
|
|
val wmask = FillInterleaved(conf.wordbits, io.write.bits.wmask)
|
2014-05-07 10:51:46 +02:00
|
|
|
val resp = (0 until conf.ways).map { w =>
|
2014-04-23 01:55:35 +02:00
|
|
|
val array = Mem(Bits(width=conf.rowbits), conf.sets*conf.refillcycles, seqRead = true)
|
|
|
|
when (io.write.bits.way_en(w) && io.write.valid) {
|
|
|
|
array.write(waddr, io.write.bits.data, wmask)
|
|
|
|
}
|
2014-05-07 10:51:46 +02:00
|
|
|
array(RegEnable(raddr, io.read.bits.way_en(w) && io.read.valid))
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
2014-05-07 10:51:46 +02:00
|
|
|
io.resp.valid := ShiftRegister(io.read.valid, 2)
|
|
|
|
io.resp.bits.id := ShiftRegister(io.read.bits.id, 2)
|
|
|
|
io.resp.bits.data := Mux1H(ShiftRegister(io.read.bits.way_en, 2), resp)
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
io.read.ready := Bool(true)
|
|
|
|
io.write.ready := Bool(true)
|
|
|
|
}
|
|
|
|
|
2014-05-01 10:44:59 +02:00
|
|
|
class L2InternalAcquire(implicit val l2cacheconf: L2CacheConfig) extends Acquire()(l2cacheconf.tl)
|
2014-05-07 10:51:46 +02:00
|
|
|
with HasL2InternalRequestState
|
2014-04-27 04:11:36 +02:00
|
|
|
|
2014-05-01 10:44:59 +02:00
|
|
|
class L2InternalRelease(implicit val l2cacheconf: L2CacheConfig) extends Release()(l2cacheconf.tl)
|
2014-05-07 10:51:46 +02:00
|
|
|
with HasL2InternalRequestState
|
2014-04-27 04:11:36 +02:00
|
|
|
|
|
|
|
class InternalTileLinkIO(implicit val l2cacheconf: L2CacheConfig) extends L2CacheBundle {
|
|
|
|
implicit val (tl, ln) = (l2cacheconf.tl, l2cacheconf.tl.ln)
|
2014-05-01 10:44:59 +02:00
|
|
|
val acquire = new DecoupledIO(new LogicalNetworkIO(new L2InternalAcquire))
|
2014-04-27 04:11:36 +02:00
|
|
|
val probe = new DecoupledIO(new LogicalNetworkIO(new Probe)).flip
|
2014-05-01 10:44:59 +02:00
|
|
|
val release = new DecoupledIO(new LogicalNetworkIO(new L2InternalRelease))
|
2014-04-27 04:11:36 +02:00
|
|
|
val grant = new DecoupledIO(new LogicalNetworkIO(new Grant)).flip
|
|
|
|
val finish = new DecoupledIO(new LogicalNetworkIO(new Finish))
|
|
|
|
}
|
|
|
|
|
|
|
|
class L2HellaCache(bankId: Int)(implicit conf: L2CacheConfig) extends CoherenceAgent {
|
2014-04-23 01:55:35 +02:00
|
|
|
implicit val (tl, ln, co) = (conf.tl, conf.tl.ln, conf.tl.co)
|
|
|
|
|
2014-04-27 04:11:36 +02:00
|
|
|
val tshrfile = Module(new TSHRFile(bankId))
|
2014-05-28 22:35:08 +02:00
|
|
|
val meta = Module(new L2MetadataArray)
|
2014-05-01 10:44:59 +02:00
|
|
|
val data = Module(new L2DataArray)
|
|
|
|
|
2014-04-30 01:49:18 +02:00
|
|
|
tshrfile.io.inner <> io.inner
|
2014-05-07 10:51:46 +02:00
|
|
|
tshrfile.io.meta_read <> meta.io.read
|
|
|
|
tshrfile.io.meta_write <> meta.io.write
|
|
|
|
tshrfile.io.meta_resp <> meta.io.resp
|
|
|
|
tshrfile.io.data_read <> data.io.read
|
|
|
|
tshrfile.io.data_write <> data.io.write
|
|
|
|
tshrfile.io.data_resp <> data.io.resp
|
2014-04-30 01:49:18 +02:00
|
|
|
io.outer <> tshrfile.io.outer
|
2014-04-27 04:11:36 +02:00
|
|
|
io.incoherent <> tshrfile.io.incoherent
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TSHRFile(bankId: Int)(implicit conf: L2CacheConfig) extends Module {
|
|
|
|
implicit val (tl, ln, co) = (conf.tl, conf.tl.ln, conf.tl.co)
|
|
|
|
val io = new Bundle {
|
2014-05-07 10:51:46 +02:00
|
|
|
val inner = (new TileLinkIO).flip
|
2014-04-27 04:11:36 +02:00
|
|
|
val outer = new UncachedTileLinkIO
|
|
|
|
val incoherent = Vec.fill(ln.nClients){Bool()}.asInput
|
2014-05-07 10:51:46 +02:00
|
|
|
val meta_read = Decoupled(new L2MetaReadReq)
|
|
|
|
val meta_write = Decoupled(new L2MetaWriteReq)
|
|
|
|
val meta_resp = Valid(new L2MetaResp).flip
|
|
|
|
val data_read = Decoupled(new L2DataReadReq)
|
|
|
|
val data_write = Decoupled(new L2DataWriteReq)
|
|
|
|
val data_resp = Valid(new L2DataResp).flip
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wiring helper funcs
|
|
|
|
def doOutputArbitration[T <: Data](out: DecoupledIO[T], ins: Seq[DecoupledIO[T]]) {
|
|
|
|
val arb = Module(new RRArbiter(out.bits.clone, ins.size))
|
|
|
|
out <> arb.io.out
|
2014-05-28 22:35:08 +02:00
|
|
|
arb.io.in zip ins map { case (a, in) => a <> in }
|
|
|
|
}
|
|
|
|
|
|
|
|
def doInputRouting[T <: HasL2Id](in: ValidIO[T], outs: Seq[ValidIO[T]]) {
|
|
|
|
outs.map(_.bits := in.bits)
|
|
|
|
outs.zipWithIndex.map { case (o, i) => o.valid := UInt(i) === in.bits.id }
|
2014-04-27 04:11:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create TSHRs for outstanding transactions
|
2014-04-23 01:55:35 +02:00
|
|
|
val nTrackers = conf.nReleaseTransactions + conf.nAcquireTransactions
|
2014-05-07 10:51:46 +02:00
|
|
|
val trackerList = (0 until conf.nReleaseTransactions).map { id =>
|
|
|
|
Module(new L2VoluntaryReleaseTracker(id, bankId))
|
|
|
|
} ++ (conf.nReleaseTransactions until nTrackers).map { id =>
|
|
|
|
Module(new L2AcquireTracker(id, bankId))
|
|
|
|
}
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
// Propagate incoherence flags
|
|
|
|
trackerList.map(_.io.tile_incoherent := io.incoherent.toBits)
|
|
|
|
|
|
|
|
// Handle acquire transaction initiation
|
2014-04-30 01:49:18 +02:00
|
|
|
val acquire = io.inner.acquire
|
2014-04-23 01:55:35 +02:00
|
|
|
val any_acquire_conflict = trackerList.map(_.io.has_acquire_conflict).reduce(_||_)
|
|
|
|
val block_acquires = any_acquire_conflict
|
|
|
|
|
|
|
|
val alloc_arb = Module(new Arbiter(Bool(), trackerList.size))
|
|
|
|
for( i <- 0 until trackerList.size ) {
|
2014-04-30 01:49:18 +02:00
|
|
|
val t = trackerList(i).io.inner
|
2014-04-23 01:55:35 +02:00
|
|
|
alloc_arb.io.in(i).valid := t.acquire.ready
|
|
|
|
t.acquire.bits := acquire.bits
|
|
|
|
t.acquire.valid := alloc_arb.io.in(i).ready
|
|
|
|
}
|
2014-04-30 01:49:18 +02:00
|
|
|
acquire.ready := trackerList.map(_.io.inner.acquire.ready).reduce(_||_) && !block_acquires
|
2014-04-23 01:55:35 +02:00
|
|
|
alloc_arb.io.out.ready := acquire.valid && !block_acquires
|
|
|
|
|
2014-05-07 10:51:46 +02:00
|
|
|
// Handle probe requests
|
|
|
|
doOutputArbitration(io.inner.probe, trackerList.map(_.io.inner.probe))
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
// Handle releases, which might be voluntary and might have data
|
2014-04-30 01:49:18 +02:00
|
|
|
val release = io.inner.release
|
2014-04-23 01:55:35 +02:00
|
|
|
val voluntary = co.isVoluntary(release.bits.payload)
|
|
|
|
val any_release_conflict = trackerList.tail.map(_.io.has_release_conflict).reduce(_||_)
|
|
|
|
val block_releases = Bool(false)
|
|
|
|
val conflict_idx = Vec(trackerList.map(_.io.has_release_conflict)).lastIndexWhere{b: Bool => b}
|
|
|
|
//val release_idx = Mux(voluntary, Mux(any_release_conflict, conflict_idx, UInt(0)), release.bits.payload.master_xact_id) // TODO: Add merging logic to allow allocated AcquireTracker to handle conflicts, send all necessary grants, use first sufficient response
|
|
|
|
val release_idx = Mux(voluntary, UInt(0), release.bits.payload.master_xact_id)
|
|
|
|
for( i <- 0 until trackerList.size ) {
|
2014-04-30 01:49:18 +02:00
|
|
|
val t = trackerList(i).io.inner
|
2014-04-23 01:55:35 +02:00
|
|
|
t.release.bits := release.bits
|
|
|
|
t.release.valid := release.valid && (release_idx === UInt(i)) && !block_releases
|
|
|
|
}
|
2014-04-30 01:49:18 +02:00
|
|
|
release.ready := Vec(trackerList.map(_.io.inner.release.ready)).read(release_idx) && !block_releases
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
// Reply to initial requestor
|
2014-05-07 10:51:46 +02:00
|
|
|
doOutputArbitration(io.inner.grant, trackerList.map(_.io.inner.grant))
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
// Free finished transactions
|
2014-04-30 01:49:18 +02:00
|
|
|
val ack = io.inner.finish
|
|
|
|
trackerList.map(_.io.inner.finish.valid := ack.valid)
|
|
|
|
trackerList.map(_.io.inner.finish.bits := ack.bits)
|
2014-04-23 01:55:35 +02:00
|
|
|
ack.ready := Bool(true)
|
|
|
|
|
2014-05-07 10:51:46 +02:00
|
|
|
// Arbitrate for the outer memory port
|
2014-04-23 01:55:35 +02:00
|
|
|
val outer_arb = Module(new UncachedTileLinkIOArbiterThatPassesId(trackerList.size))
|
2014-04-30 01:49:18 +02:00
|
|
|
outer_arb.io.in zip trackerList map { case(arb, t) => arb <> t.io.outer }
|
2014-04-27 04:11:36 +02:00
|
|
|
io.outer <> outer_arb.io.out
|
2014-05-07 10:51:46 +02:00
|
|
|
|
|
|
|
// Local memory
|
|
|
|
doOutputArbitration(io.meta_read, trackerList.map(_.io.meta_read))
|
|
|
|
doOutputArbitration(io.meta_write, trackerList.map(_.io.meta_write))
|
|
|
|
doOutputArbitration(io.data_read, trackerList.map(_.io.data_read))
|
|
|
|
doOutputArbitration(io.data_write, trackerList.map(_.io.data_write))
|
2014-05-28 22:35:08 +02:00
|
|
|
doInputRouting(io.meta_resp, trackerList.map(_.io.meta_resp))
|
|
|
|
doInputRouting(io.data_resp, trackerList.map(_.io.data_resp))
|
2014-05-07 10:51:46 +02:00
|
|
|
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
abstract class L2XactTracker()(implicit conf: L2CacheConfig) extends Module {
|
|
|
|
implicit val (tl, ln, co) = (conf.tl, conf.tl.ln, conf.tl.co)
|
|
|
|
val io = new Bundle {
|
2014-05-07 10:51:46 +02:00
|
|
|
val inner = (new TileLinkIO).flip
|
2014-04-30 01:49:18 +02:00
|
|
|
val outer = new UncachedTileLinkIO
|
2014-04-23 01:55:35 +02:00
|
|
|
val tile_incoherent = Bits(INPUT, ln.nClients)
|
|
|
|
val has_acquire_conflict = Bool(OUTPUT)
|
|
|
|
val has_release_conflict = Bool(OUTPUT)
|
2014-05-07 10:51:46 +02:00
|
|
|
val meta_read = Decoupled(new L2MetaReadReq)
|
|
|
|
val meta_write = Decoupled(new L2MetaWriteReq)
|
|
|
|
val meta_resp = Valid(new L2MetaResp).flip
|
|
|
|
val data_read = Decoupled(new L2DataReadReq)
|
|
|
|
val data_write = Decoupled(new L2DataWriteReq)
|
|
|
|
val data_resp = Valid(new L2DataResp).flip
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
|
2014-04-30 01:49:18 +02:00
|
|
|
val c_acq = io.inner.acquire.bits
|
|
|
|
val c_rel = io.inner.release.bits
|
|
|
|
val c_gnt = io.inner.grant.bits
|
|
|
|
val c_ack = io.inner.finish.bits
|
|
|
|
val m_gnt = io.outer.grant.bits
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class L2VoluntaryReleaseTracker(trackerId: Int, bankId: Int)(implicit conf: L2CacheConfig) extends L2XactTracker()(conf) {
|
|
|
|
val s_idle :: s_mem :: s_ack :: s_busy :: Nil = Enum(UInt(), 4)
|
|
|
|
val state = Reg(init=s_idle)
|
|
|
|
val xact = Reg{ new Release }
|
|
|
|
val init_client_id = Reg(init=UInt(0, width = log2Up(ln.nClients)))
|
2014-05-28 22:35:08 +02:00
|
|
|
val new_meta = Reg(new L2Metadata)
|
2014-04-30 01:49:18 +02:00
|
|
|
val incoming_rel = io.inner.release.bits
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
io.has_acquire_conflict := Bool(false)
|
|
|
|
io.has_release_conflict := co.isCoherenceConflict(xact.addr, incoming_rel.payload.addr) &&
|
|
|
|
(state != s_idle)
|
|
|
|
|
2014-04-30 01:49:18 +02:00
|
|
|
io.outer.grant.ready := Bool(false)
|
|
|
|
io.outer.acquire.valid := Bool(false)
|
|
|
|
io.outer.acquire.bits.header.src := UInt(bankId)
|
|
|
|
//io.outer.acquire.bits.header.dst TODO
|
|
|
|
io.outer.acquire.bits.payload := Acquire(co.getUncachedWriteAcquireType,
|
2014-04-23 01:55:35 +02:00
|
|
|
xact.addr,
|
|
|
|
UInt(trackerId),
|
|
|
|
xact.data)
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.acquire.ready := Bool(false)
|
|
|
|
io.inner.probe.valid := Bool(false)
|
|
|
|
io.inner.release.ready := Bool(false)
|
|
|
|
io.inner.grant.valid := Bool(false)
|
|
|
|
io.inner.grant.bits.header.src := UInt(bankId)
|
|
|
|
io.inner.grant.bits.header.dst := init_client_id
|
|
|
|
io.inner.grant.bits.payload := Grant(co.getGrantType(xact, UInt(0)),
|
2014-04-23 01:55:35 +02:00
|
|
|
xact.client_xact_id,
|
|
|
|
UInt(trackerId))
|
|
|
|
|
2014-05-28 22:35:08 +02:00
|
|
|
|
2014-04-23 01:55:35 +02:00
|
|
|
switch (state) {
|
|
|
|
is(s_idle) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.release.ready := Bool(true)
|
|
|
|
when( io.inner.release.valid ) {
|
2014-04-23 01:55:35 +02:00
|
|
|
xact := incoming_rel.payload
|
|
|
|
init_client_id := incoming_rel.header.src
|
2014-05-28 22:35:08 +02:00
|
|
|
state := s_mem
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-28 22:35:08 +02:00
|
|
|
/*
|
|
|
|
is(s_meta_read) {
|
|
|
|
when(io.meta_read.ready) state := s_meta_resp
|
|
|
|
}
|
|
|
|
is(s_meta_resp) {
|
|
|
|
when(io.meta_resp.valid) {
|
|
|
|
new_meta := L2Metadata(io.meta.resp.bits.old_meta.tag, io.meta.resp.bits.old_meta.sharers, io.meta.resp.bits
|
|
|
|
old_meta := io.meta.resp.bits.old_meta
|
|
|
|
state := Mux(s_meta_write
|
|
|
|
Mux(co.messageHasData(xact), s_mem, s_ack)
|
|
|
|
}
|
|
|
|
*/
|
2014-04-23 01:55:35 +02:00
|
|
|
is(s_mem) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.outer.acquire.valid := Bool(true)
|
|
|
|
when(io.outer.acquire.ready) { state := s_ack }
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
is(s_ack) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.grant.valid := Bool(true)
|
|
|
|
when(io.inner.grant.ready) { state := s_idle }
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class L2AcquireTracker(trackerId: Int, bankId: Int)(implicit conf: L2CacheConfig) extends L2XactTracker()(conf) {
|
|
|
|
val s_idle :: s_probe :: s_mem_read :: s_mem_write :: s_make_grant :: s_busy :: Nil = Enum(UInt(), 6)
|
|
|
|
val state = Reg(init=s_idle)
|
|
|
|
val xact = Reg{ new Acquire }
|
|
|
|
val init_client_id = Reg(init=UInt(0, width = log2Up(ln.nClients)))
|
|
|
|
//TODO: Will need id reg for merged release xacts
|
|
|
|
|
|
|
|
val init_sharer_cnt = Reg(init=UInt(0, width = log2Up(ln.nClients)))
|
|
|
|
val release_count = if (ln.nClients == 1) UInt(0) else Reg(init=UInt(0, width = log2Up(ln.nClients)))
|
|
|
|
val probe_flags = Reg(init=Bits(0, width = ln.nClients))
|
|
|
|
val curr_p_id = PriorityEncoder(probe_flags)
|
|
|
|
|
|
|
|
val pending_outer_write = co.messageHasData(xact)
|
2014-05-28 22:35:08 +02:00
|
|
|
val pending_outer_read = co.requiresOuterRead(xact.a_type)
|
2014-04-23 01:55:35 +02:00
|
|
|
val outer_write_acq = Acquire(co.getUncachedWriteAcquireType,
|
|
|
|
xact.addr, UInt(trackerId), xact.data)
|
|
|
|
val outer_write_rel = Acquire(co.getUncachedWriteAcquireType,
|
|
|
|
xact.addr, UInt(trackerId), c_rel.payload.data)
|
|
|
|
val outer_read = Acquire(co.getUncachedReadAcquireType, xact.addr, UInt(trackerId))
|
|
|
|
|
|
|
|
val probe_initial_flags = Bits(width = ln.nClients)
|
|
|
|
probe_initial_flags := Bits(0)
|
|
|
|
if (ln.nClients > 1) {
|
|
|
|
// issue self-probes for uncached read xacts to facilitate I$ coherence
|
2014-04-30 01:49:18 +02:00
|
|
|
val probe_self = Bool(true) //co.needsSelfProbe(io.inner.acquire.bits.payload)
|
2014-04-23 01:55:35 +02:00
|
|
|
val myflag = Mux(probe_self, Bits(0), UIntToOH(c_acq.header.src(log2Up(ln.nClients)-1,0)))
|
|
|
|
probe_initial_flags := ~(io.tile_incoherent | myflag)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.has_acquire_conflict := co.isCoherenceConflict(xact.addr, c_acq.payload.addr) && (state != s_idle)
|
|
|
|
io.has_release_conflict := co.isCoherenceConflict(xact.addr, c_rel.payload.addr) && (state != s_idle)
|
|
|
|
|
2014-04-30 01:49:18 +02:00
|
|
|
io.outer.acquire.valid := Bool(false)
|
|
|
|
io.outer.acquire.bits.header.src := UInt(bankId)
|
|
|
|
//io.outer.acquire.bits.header.dst TODO
|
|
|
|
io.outer.acquire.bits.payload := outer_read
|
|
|
|
io.outer.grant.ready := io.inner.grant.ready
|
2014-04-23 01:55:35 +02:00
|
|
|
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.probe.valid := Bool(false)
|
|
|
|
io.inner.probe.bits.header.src := UInt(bankId)
|
|
|
|
io.inner.probe.bits.header.dst := curr_p_id
|
2014-05-28 22:35:08 +02:00
|
|
|
io.inner.probe.bits.payload := Probe(co.getProbeType(xact.a_type, conf.tl.co.masterMetadataOnFlush),
|
2014-04-23 01:55:35 +02:00
|
|
|
xact.addr,
|
|
|
|
UInt(trackerId))
|
|
|
|
|
|
|
|
val grant_type = co.getGrantType(xact.a_type, init_sharer_cnt)
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.grant.valid := Bool(false)
|
|
|
|
io.inner.grant.bits.header.src := UInt(bankId)
|
|
|
|
io.inner.grant.bits.header.dst := init_client_id
|
|
|
|
io.inner.grant.bits.payload := Grant(grant_type,
|
2014-04-23 01:55:35 +02:00
|
|
|
xact.client_xact_id,
|
|
|
|
UInt(trackerId),
|
|
|
|
m_gnt.payload.data)
|
|
|
|
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.acquire.ready := Bool(false)
|
|
|
|
io.inner.release.ready := Bool(false)
|
2014-04-23 01:55:35 +02:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
is(s_idle) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.acquire.ready := Bool(true)
|
2014-04-23 01:55:35 +02:00
|
|
|
val needs_outer_write = co.messageHasData(c_acq.payload)
|
2014-05-28 22:35:08 +02:00
|
|
|
val needs_outer_read = co.requiresOuterRead(c_acq.payload.a_type)
|
2014-04-30 01:49:18 +02:00
|
|
|
when( io.inner.acquire.valid ) {
|
2014-04-23 01:55:35 +02:00
|
|
|
xact := c_acq.payload
|
|
|
|
init_client_id := c_acq.header.src
|
|
|
|
init_sharer_cnt := UInt(ln.nClients) // TODO: Broadcast only
|
|
|
|
probe_flags := probe_initial_flags
|
|
|
|
if(ln.nClients > 1) {
|
|
|
|
release_count := PopCount(probe_initial_flags)
|
|
|
|
state := Mux(probe_initial_flags.orR, s_probe,
|
|
|
|
Mux(needs_outer_write, s_mem_write,
|
|
|
|
Mux(needs_outer_read, s_mem_read, s_make_grant)))
|
|
|
|
} else state := Mux(needs_outer_write, s_mem_write,
|
|
|
|
Mux(needs_outer_read, s_mem_read, s_make_grant))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(s_probe) {
|
|
|
|
// Generate probes
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.probe.valid := probe_flags.orR
|
|
|
|
when(io.inner.probe.ready) {
|
2014-04-23 01:55:35 +02:00
|
|
|
probe_flags := probe_flags & ~(UIntToOH(curr_p_id))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle releases, which may have data to be written back
|
2014-04-30 01:49:18 +02:00
|
|
|
when(io.inner.release.valid) {
|
2014-04-23 01:55:35 +02:00
|
|
|
when(co.messageHasData(c_rel.payload)) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.outer.acquire.valid := Bool(true)
|
|
|
|
io.outer.acquire.bits.payload := outer_write_rel
|
|
|
|
when(io.outer.acquire.ready) {
|
|
|
|
io.inner.release.ready := Bool(true)
|
2014-04-23 01:55:35 +02:00
|
|
|
if(ln.nClients > 1) release_count := release_count - UInt(1)
|
|
|
|
when(release_count === UInt(1)) {
|
|
|
|
state := Mux(pending_outer_write, s_mem_write,
|
|
|
|
Mux(pending_outer_read, s_mem_read, s_make_grant))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} .otherwise {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.release.ready := Bool(true)
|
2014-04-23 01:55:35 +02:00
|
|
|
if(ln.nClients > 1) release_count := release_count - UInt(1)
|
|
|
|
when(release_count === UInt(1)) {
|
|
|
|
state := Mux(pending_outer_write, s_mem_write,
|
|
|
|
Mux(pending_outer_read, s_mem_read, s_make_grant))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(s_mem_read) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.outer.acquire.valid := Bool(true)
|
|
|
|
io.outer.acquire.bits.payload := outer_read
|
|
|
|
when(io.outer.acquire.ready) {
|
2014-04-23 01:55:35 +02:00
|
|
|
state := Mux(co.requiresAckForGrant(grant_type), s_busy, s_idle)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(s_mem_write) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.outer.acquire.valid := Bool(true)
|
|
|
|
io.outer.acquire.bits.payload := outer_write_acq
|
|
|
|
when(io.outer.acquire.ready) {
|
2014-04-23 01:55:35 +02:00
|
|
|
state := Mux(pending_outer_read, s_mem_read, s_make_grant)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(s_make_grant) {
|
2014-04-30 01:49:18 +02:00
|
|
|
io.inner.grant.valid := Bool(true)
|
|
|
|
when(io.inner.grant.ready) {
|
2014-04-23 01:55:35 +02:00
|
|
|
state := Mux(co.requiresAckForGrant(grant_type), s_busy, s_idle)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(s_busy) { // Nothing left to do but wait for transaction to complete
|
2014-04-30 01:49:18 +02:00
|
|
|
when(io.outer.grant.valid && m_gnt.payload.client_xact_id === UInt(trackerId)) {
|
|
|
|
io.inner.grant.valid := Bool(true)
|
2014-04-23 01:55:35 +02:00
|
|
|
}
|
2014-04-30 01:49:18 +02:00
|
|
|
when(io.inner.finish.valid && c_ack.payload.master_xact_id === UInt(trackerId)) {
|
2014-04-23 01:55:35 +02:00
|
|
|
state := s_idle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|