2012-09-27 21:59:45 +02:00
|
|
|
package uncore
|
2012-04-03 21:03:05 +02:00
|
|
|
import Chisel._
|
|
|
|
|
2014-01-21 21:20:55 +01:00
|
|
|
abstract class CoherenceAgent(implicit conf: TileLinkConfiguration) extends Module {
|
2013-01-17 08:57:35 +01:00
|
|
|
val io = new Bundle {
|
2013-03-20 22:10:16 +01:00
|
|
|
val client = (new TileLinkIO).flip
|
|
|
|
val master = new UncachedTileLinkIO
|
2013-08-12 19:36:44 +02:00
|
|
|
val incoherent = Vec.fill(conf.ln.nClients){Bool()}.asInput
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 23:55:06 +02:00
|
|
|
case class L2CoherenceAgentConfiguration(tl: TileLinkConfiguration, nReleaseTransactions: Int, nAcquireTransactions: Int)
|
|
|
|
|
|
|
|
class L2CoherenceAgent(bankId: Int)(implicit conf: L2CoherenceAgentConfiguration) extends CoherenceAgent()(conf.tl)
|
2013-01-17 08:57:35 +01:00
|
|
|
{
|
2013-08-02 23:55:06 +02:00
|
|
|
implicit val (tl, ln, co) = (conf.tl, conf.tl.ln, conf.tl.co)
|
|
|
|
|
|
|
|
// Create SHRs for outstanding transactions
|
|
|
|
val nTrackers = conf.nReleaseTransactions + conf.nAcquireTransactions
|
2013-08-12 19:36:44 +02:00
|
|
|
val trackerList = (0 until conf.nReleaseTransactions).map(id => Module(new VoluntaryReleaseTracker(id, bankId))) ++
|
|
|
|
(conf.nReleaseTransactions until nTrackers).map(id => Module(new AcquireTracker(id, bankId)))
|
2013-01-17 08:57:35 +01:00
|
|
|
|
2013-08-02 23:55:06 +02:00
|
|
|
// Propagate incoherence flags
|
2013-03-20 22:10:16 +01:00
|
|
|
trackerList.map(_.io.tile_incoherent := io.incoherent.toBits)
|
2013-01-17 08:57:35 +01:00
|
|
|
|
2013-03-26 00:20:12 +01:00
|
|
|
// Handle acquire transaction initiation
|
2013-03-20 22:10:16 +01:00
|
|
|
val acquire = io.client.acquire
|
2013-01-29 01:39:45 +01:00
|
|
|
val any_acquire_conflict = trackerList.map(_.io.has_acquire_conflict).reduce(_||_)
|
2013-04-10 22:46:31 +02:00
|
|
|
val block_acquires = any_acquire_conflict
|
2013-01-17 08:57:35 +01:00
|
|
|
|
2013-08-12 19:36:44 +02:00
|
|
|
val alloc_arb = Module(new Arbiter(Bool(), trackerList.size))
|
2013-03-20 22:10:16 +01:00
|
|
|
for( i <- 0 until trackerList.size ) {
|
|
|
|
val t = trackerList(i).io.client
|
2014-03-29 18:53:49 +01:00
|
|
|
alloc_arb.io.in(i).valid := t.acquire.ready
|
|
|
|
t.acquire.bits := acquire.bits
|
|
|
|
t.acquire.valid := alloc_arb.io.in(i).ready
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
acquire.ready := trackerList.map(_.io.client.acquire.ready).reduce(_||_) && !block_acquires
|
|
|
|
alloc_arb.io.out.ready := acquire.valid && !block_acquires
|
2013-01-17 08:57:35 +01:00
|
|
|
|
|
|
|
// Handle probe request generation
|
2013-09-11 01:15:41 +02:00
|
|
|
val probe_arb = Module(new Arbiter(new LogicalNetworkIO(new Probe), trackerList.size))
|
2013-03-20 22:10:16 +01:00
|
|
|
io.client.probe <> probe_arb.io.out
|
|
|
|
probe_arb.io.in zip trackerList map { case (arb, t) => arb <> t.io.client.probe }
|
2013-01-17 08:57:35 +01:00
|
|
|
|
2013-04-09 23:09:36 +02:00
|
|
|
// Handle releases, which might be voluntary and might have data
|
2013-03-20 22:10:16 +01:00
|
|
|
val release = io.client.release
|
2014-03-29 18:53:49 +01:00
|
|
|
val voluntary = co.isVoluntary(release.bits.payload)
|
2013-01-29 01:39:45 +01:00
|
|
|
val any_release_conflict = trackerList.tail.map(_.io.has_release_conflict).reduce(_||_)
|
2013-04-10 22:46:31 +02:00
|
|
|
val block_releases = Bool(false)
|
2013-08-12 19:36:44 +02:00
|
|
|
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
|
2014-03-29 18:53:49 +01:00
|
|
|
val release_idx = Mux(voluntary, UInt(0), release.bits.payload.master_xact_id)
|
2013-03-20 22:10:16 +01:00
|
|
|
for( i <- 0 until trackerList.size ) {
|
|
|
|
val t = trackerList(i).io.client
|
2014-03-29 18:53:49 +01:00
|
|
|
t.release.bits := release.bits
|
|
|
|
t.release.valid := release.valid && (release_idx === UInt(i)) && !block_releases
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
release.ready := Vec(trackerList.map(_.io.client.release.ready)).read(release_idx) && !block_releases
|
2013-01-17 08:57:35 +01:00
|
|
|
|
|
|
|
// Reply to initial requestor
|
2013-09-11 01:15:41 +02:00
|
|
|
val grant_arb = Module(new Arbiter(new LogicalNetworkIO(new Grant), trackerList.size))
|
2013-03-20 22:10:16 +01:00
|
|
|
io.client.grant <> grant_arb.io.out
|
|
|
|
grant_arb.io.in zip trackerList map { case (arb, t) => arb <> t.io.client.grant }
|
2013-01-17 08:57:35 +01:00
|
|
|
|
|
|
|
// Free finished transactions
|
2014-04-27 00:17:05 +02:00
|
|
|
val ack = io.client.finish
|
|
|
|
trackerList.map(_.io.client.finish.valid := ack.valid)
|
|
|
|
trackerList.map(_.io.client.finish.bits := ack.bits)
|
2013-01-23 05:09:21 +01:00
|
|
|
ack.ready := Bool(true)
|
2013-01-17 08:57:35 +01:00
|
|
|
|
|
|
|
// Create an arbiter for the one memory port
|
2013-08-12 19:36:44 +02:00
|
|
|
val outer_arb = Module(new UncachedTileLinkIOArbiterThatPassesId(trackerList.size))
|
2013-03-20 22:10:16 +01:00
|
|
|
outer_arb.io.in zip trackerList map { case(arb, t) => arb <> t.io.master }
|
|
|
|
io.master <> outer_arb.io.out
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-29 01:39:45 +01:00
|
|
|
|
2014-03-29 18:53:49 +01:00
|
|
|
abstract class XactTracker()(implicit conf: L2CoherenceAgentConfiguration) extends Module {
|
2013-08-02 23:55:06 +02:00
|
|
|
implicit val (tl, ln, co) = (conf.tl, conf.tl.ln, conf.tl.co)
|
2013-01-17 08:57:35 +01:00
|
|
|
val io = new Bundle {
|
2013-03-20 22:10:16 +01:00
|
|
|
val client = (new TileLinkIO).flip
|
|
|
|
val master = new UncachedTileLinkIO
|
2013-08-02 23:55:06 +02:00
|
|
|
val tile_incoherent = Bits(INPUT, ln.nClients)
|
2013-03-20 22:10:16 +01:00
|
|
|
val has_acquire_conflict = Bool(OUTPUT)
|
|
|
|
val has_release_conflict = Bool(OUTPUT)
|
2013-01-29 01:39:45 +01:00
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
val c_acq = io.client.acquire.bits
|
|
|
|
val c_rel = io.client.release.bits
|
|
|
|
val c_gnt = io.client.grant.bits
|
2014-04-27 00:17:05 +02:00
|
|
|
val c_ack = io.client.finish.bits
|
2014-03-29 18:53:49 +01:00
|
|
|
val m_gnt = io.master.grant.bits
|
|
|
|
|
2013-01-29 01:39:45 +01:00
|
|
|
}
|
|
|
|
|
2013-08-02 23:55:06 +02:00
|
|
|
class VoluntaryReleaseTracker(trackerId: Int, bankId: Int)(implicit conf: L2CoherenceAgentConfiguration) extends XactTracker()(conf) {
|
2013-09-10 19:54:51 +02:00
|
|
|
val s_idle :: s_mem :: s_ack :: s_busy :: Nil = Enum(UInt(), 4)
|
2013-08-16 00:27:38 +02:00
|
|
|
val state = Reg(init=s_idle)
|
2013-01-29 01:39:45 +01:00
|
|
|
val xact = Reg{ new Release }
|
2014-03-29 18:53:49 +01:00
|
|
|
val init_client_id = Reg(init=UInt(0, width = log2Up(ln.nClients)))
|
|
|
|
val incoming_rel = io.client.release.bits
|
2013-01-29 01:39:45 +01:00
|
|
|
|
|
|
|
io.has_acquire_conflict := Bool(false)
|
2014-03-29 18:53:49 +01:00
|
|
|
io.has_release_conflict := co.isCoherenceConflict(xact.addr, incoming_rel.payload.addr) &&
|
|
|
|
(state != s_idle)
|
2013-03-20 22:10:16 +01:00
|
|
|
|
|
|
|
io.master.grant.ready := Bool(false)
|
2014-03-29 18:53:49 +01:00
|
|
|
io.master.acquire.valid := Bool(false)
|
|
|
|
io.master.acquire.bits.header.src := UInt(bankId)
|
|
|
|
//io.master.acquire.bits.header.dst TODO
|
|
|
|
io.master.acquire.bits.payload := Acquire(co.getUncachedWriteAcquireType,
|
|
|
|
xact.addr,
|
|
|
|
UInt(trackerId),
|
|
|
|
xact.data)
|
|
|
|
io.client.acquire.ready := Bool(false)
|
2013-03-20 22:10:16 +01:00
|
|
|
io.client.probe.valid := Bool(false)
|
2014-03-29 18:53:49 +01:00
|
|
|
io.client.release.ready := Bool(false)
|
2013-03-20 22:10:16 +01:00
|
|
|
io.client.grant.valid := Bool(false)
|
2013-08-12 19:36:44 +02:00
|
|
|
io.client.grant.bits.header.src := UInt(bankId)
|
2014-03-29 18:53:49 +01:00
|
|
|
io.client.grant.bits.header.dst := init_client_id
|
|
|
|
io.client.grant.bits.payload := Grant(co.getGrantType(xact, UInt(0)),
|
|
|
|
xact.client_xact_id,
|
|
|
|
UInt(trackerId))
|
2013-01-29 01:39:45 +01:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
is(s_idle) {
|
2014-03-29 18:53:49 +01:00
|
|
|
io.client.release.ready := Bool(true)
|
|
|
|
when( io.client.release.valid ) {
|
|
|
|
xact := incoming_rel.payload
|
|
|
|
init_client_id := incoming_rel.header.src
|
|
|
|
state := Mux(co.messageHasData(incoming_rel.payload), s_mem, s_ack)
|
2013-01-29 01:39:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
is(s_mem) {
|
2014-03-29 18:53:49 +01:00
|
|
|
io.master.acquire.valid := Bool(true)
|
|
|
|
when(io.master.acquire.ready) { state := s_ack }
|
2013-01-29 01:39:45 +01:00
|
|
|
}
|
|
|
|
is(s_ack) {
|
2013-03-20 22:10:16 +01:00
|
|
|
io.client.grant.valid := Bool(true)
|
|
|
|
when(io.client.grant.ready) { state := s_idle }
|
2013-01-29 01:39:45 +01:00
|
|
|
}
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
2013-01-29 01:39:45 +01:00
|
|
|
}
|
2013-01-17 08:57:35 +01:00
|
|
|
|
2013-08-02 23:55:06 +02:00
|
|
|
class AcquireTracker(trackerId: Int, bankId: Int)(implicit conf: L2CoherenceAgentConfiguration) extends XactTracker()(conf) {
|
2014-03-29 18:53:49 +01:00
|
|
|
val s_idle :: s_probe :: s_mem_read :: s_mem_write :: s_make_grant :: s_busy :: Nil = Enum(UInt(), 6)
|
2013-08-16 00:27:38 +02:00
|
|
|
val state = Reg(init=s_idle)
|
2013-01-22 02:17:26 +01:00
|
|
|
val xact = Reg{ new Acquire }
|
2014-03-29 18:53:49 +01:00
|
|
|
val init_client_id = Reg(init=UInt(0, width = log2Up(ln.nClients)))
|
2013-01-17 08:57:35 +01:00
|
|
|
//TODO: Will need id reg for merged release xacts
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
val init_sharer_cnt = Reg(init=UInt(0, width = log2Up(ln.nClients)))
|
2013-08-16 00:27:38 +02:00
|
|
|
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))
|
2013-03-26 00:20:12 +01:00
|
|
|
val curr_p_id = PriorityEncoder(probe_flags)
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
val pending_outer_write = co.messageHasData(xact)
|
|
|
|
val pending_outer_read = co.needsOuterRead(xact.a_type, UInt(0))
|
|
|
|
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))
|
|
|
|
|
2013-08-02 23:55:06 +02:00
|
|
|
val probe_initial_flags = Bits(width = ln.nClients)
|
2013-01-23 05:09:21 +01:00
|
|
|
probe_initial_flags := Bits(0)
|
2013-08-02 23:55:06 +02:00
|
|
|
if (ln.nClients > 1) {
|
2013-01-17 08:57:35 +01:00
|
|
|
// issue self-probes for uncached read xacts to facilitate I$ coherence
|
2013-03-26 00:20:12 +01:00
|
|
|
val probe_self = Bool(true) //co.needsSelfProbe(io.client.acquire.bits.payload)
|
2014-03-29 18:53:49 +01:00
|
|
|
val myflag = Mux(probe_self, Bits(0), UIntToOH(c_acq.header.src(log2Up(ln.nClients)-1,0)))
|
2013-01-23 05:09:21 +01:00
|
|
|
probe_initial_flags := ~(io.tile_incoherent | myflag)
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:53:49 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
io.master.acquire.valid := Bool(false)
|
|
|
|
io.master.acquire.bits.header.src := UInt(bankId)
|
|
|
|
//io.master.acquire.bits.header.dst TODO
|
|
|
|
io.master.acquire.bits.payload := outer_read
|
|
|
|
io.master.grant.ready := io.client.grant.ready
|
|
|
|
|
2013-03-20 22:10:16 +01:00
|
|
|
io.client.probe.valid := Bool(false)
|
2013-08-12 19:36:44 +02:00
|
|
|
io.client.probe.bits.header.src := UInt(bankId)
|
2014-03-29 18:53:49 +01:00
|
|
|
io.client.probe.bits.header.dst := curr_p_id
|
|
|
|
io.client.probe.bits.payload := Probe(co.getProbeType(xact.a_type, UInt(0)),
|
|
|
|
xact.addr,
|
|
|
|
UInt(trackerId))
|
|
|
|
|
|
|
|
val grant_type = co.getGrantType(xact.a_type, init_sharer_cnt)
|
|
|
|
io.client.grant.valid := Bool(false)
|
2013-08-12 19:36:44 +02:00
|
|
|
io.client.grant.bits.header.src := UInt(bankId)
|
2014-03-29 18:53:49 +01:00
|
|
|
io.client.grant.bits.header.dst := init_client_id
|
|
|
|
io.client.grant.bits.payload := Grant(grant_type,
|
|
|
|
xact.client_xact_id,
|
|
|
|
UInt(trackerId),
|
|
|
|
m_gnt.payload.data)
|
|
|
|
|
|
|
|
io.client.acquire.ready := Bool(false)
|
|
|
|
io.client.release.ready := Bool(false)
|
2013-01-17 08:57:35 +01:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
is(s_idle) {
|
2014-03-29 18:53:49 +01:00
|
|
|
io.client.acquire.ready := Bool(true)
|
|
|
|
val needs_outer_write = co.messageHasData(c_acq.payload)
|
|
|
|
val needs_outer_read = co.needsOuterRead(c_acq.payload.a_type, UInt(0))
|
|
|
|
when( io.client.acquire.valid ) {
|
|
|
|
xact := c_acq.payload
|
|
|
|
init_client_id := c_acq.header.src
|
|
|
|
init_sharer_cnt := UInt(ln.nClients) // TODO: Broadcast only
|
2013-01-23 05:09:21 +01:00
|
|
|
probe_flags := probe_initial_flags
|
2013-08-02 23:55:06 +02:00
|
|
|
if(ln.nClients > 1) {
|
2013-01-23 05:09:21 +01:00
|
|
|
release_count := PopCount(probe_initial_flags)
|
2014-03-29 18:53:49 +01:00
|
|
|
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))
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
is(s_probe) {
|
2014-03-29 18:53:49 +01:00
|
|
|
// Generate probes
|
|
|
|
io.client.probe.valid := probe_flags.orR
|
2013-03-20 22:10:16 +01:00
|
|
|
when(io.client.probe.ready) {
|
2013-08-12 19:36:44 +02:00
|
|
|
probe_flags := probe_flags & ~(UIntToOH(curr_p_id))
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
// Handle releases, which may have data to be written back
|
|
|
|
when(io.client.release.valid) {
|
|
|
|
when(co.messageHasData(c_rel.payload)) {
|
|
|
|
io.master.acquire.valid := Bool(true)
|
|
|
|
io.master.acquire.bits.payload := outer_write_rel
|
|
|
|
when(io.master.acquire.ready) {
|
|
|
|
io.client.release.ready := Bool(true)
|
|
|
|
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 {
|
|
|
|
io.client.release.ready := Bool(true)
|
|
|
|
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))
|
|
|
|
}
|
2013-04-10 22:46:31 +02:00
|
|
|
}
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
}
|
|
|
|
is(s_mem_read) {
|
|
|
|
io.master.acquire.valid := Bool(true)
|
|
|
|
io.master.acquire.bits.payload := outer_read
|
|
|
|
when(io.master.acquire.ready) {
|
|
|
|
state := Mux(co.requiresAckForGrant(grant_type), s_busy, s_idle)
|
2013-04-30 03:47:37 +02:00
|
|
|
}
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
is(s_mem_write) {
|
|
|
|
io.master.acquire.valid := Bool(true)
|
|
|
|
io.master.acquire.bits.payload := outer_write_acq
|
|
|
|
when(io.master.acquire.ready) {
|
|
|
|
state := Mux(pending_outer_read, s_mem_read, s_make_grant)
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
is(s_make_grant) {
|
2013-03-20 22:10:16 +01:00
|
|
|
io.client.grant.valid := Bool(true)
|
2014-03-29 18:53:49 +01:00
|
|
|
when(io.client.grant.ready) {
|
|
|
|
state := Mux(co.requiresAckForGrant(grant_type), s_busy, s_idle)
|
|
|
|
}
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
|
|
|
is(s_busy) { // Nothing left to do but wait for transaction to complete
|
2014-03-29 18:53:49 +01:00
|
|
|
when(io.master.grant.valid && m_gnt.payload.client_xact_id === UInt(trackerId)) {
|
|
|
|
io.client.grant.valid := Bool(true)
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
2014-04-27 00:17:05 +02:00
|
|
|
when(io.client.finish.valid && c_ack.payload.master_xact_id === UInt(trackerId)) {
|
2014-03-29 18:53:49 +01:00
|
|
|
state := s_idle
|
2013-01-17 08:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|