2017-01-18 03:52:47 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.tilelink
|
2017-01-18 03:52:47 +01:00
|
|
|
|
|
|
|
import Chisel._
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.config.Parameters
|
|
|
|
import freechips.rocketchip.diplomacy._
|
2017-01-18 03:52:47 +01:00
|
|
|
import scala.math.{min,max}
|
|
|
|
import TLMessages._
|
|
|
|
|
|
|
|
class TLCacheCork(unsafe: Boolean = false)(implicit p: Parameters) extends LazyModule
|
|
|
|
{
|
|
|
|
val node = TLAdapterNode(
|
2017-01-30 00:17:52 +01:00
|
|
|
clientFn = { case cp =>
|
2017-01-18 03:52:47 +01:00
|
|
|
cp.copy(clients = cp.clients.map { c => c.copy(
|
2017-04-11 21:34:18 +02:00
|
|
|
supportsProbe = TransferSizes.none,
|
2017-01-18 03:52:47 +01:00
|
|
|
sourceId = IdRange(c.sourceId.start*2, c.sourceId.end*2))})},
|
2017-01-30 00:17:52 +01:00
|
|
|
managerFn = { case mp =>
|
2017-03-24 02:19:04 +01:00
|
|
|
mp.copy(
|
|
|
|
endSinkId = 1,
|
2017-10-11 03:06:58 +02:00
|
|
|
managers = mp.managers.map { m => m.copy(
|
|
|
|
supportsAcquireB = if (m.regionType == RegionType.UNCACHED) m.supportsGet else m.supportsAcquireB,
|
|
|
|
supportsAcquireT = if (m.regionType == RegionType.UNCACHED) m.supportsPutFull else m.supportsAcquireT)})})
|
2017-01-18 03:52:47 +01:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
2017-09-14 03:06:03 +02:00
|
|
|
(node.in zip node.out) foreach { case ((in, edgeIn), (out, edgeOut)) =>
|
2017-02-09 22:59:09 +01:00
|
|
|
val clients = edgeIn.client.clients
|
|
|
|
val caches = clients.filter(_.supportsProbe)
|
|
|
|
require (clients.size == 1 || caches.size == 0 || unsafe, "Only one client can safely use a TLCacheCork")
|
2017-05-23 04:37:11 +02:00
|
|
|
require (caches.size <= 1 || unsafe, "Only one caching client allowed")
|
2017-01-30 00:17:52 +01:00
|
|
|
edgeOut.manager.managers.foreach { case m =>
|
2017-05-23 04:37:11 +02:00
|
|
|
require (!m.supportsAcquireB || unsafe, "Cannot support caches beyond the Cork")
|
2017-07-27 09:25:07 +02:00
|
|
|
require (m.regionType <= RegionType.UNCACHED)
|
2017-01-30 00:17:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The Cork turns [Acquire=>Get] => [AccessAckData=>GrantData]
|
|
|
|
// and [ReleaseData=>PutFullData] => [AccessAck=>ReleaseAck]
|
|
|
|
// We need to encode information sufficient to reverse the transformation in output.
|
|
|
|
// A caveat is that we get Acquire+Release with the same source and must keep the
|
|
|
|
// source unique after transformation onto the A channel.
|
|
|
|
// The coding scheme is:
|
|
|
|
// Put: 1, Release: 0 => AccessAck
|
|
|
|
// *: 0, Acquire: 1 => AccessAckData
|
|
|
|
|
2017-07-27 23:07:24 +02:00
|
|
|
// Take requests from A to A or D (if BtoT Acquire)
|
2017-01-30 00:17:52 +01:00
|
|
|
val a_a = Wire(out.a)
|
2017-07-27 23:07:24 +02:00
|
|
|
val a_d = Wire(in.d)
|
|
|
|
val isPut = in.a.bits.opcode === PutFullData || in.a.bits.opcode === PutPartialData
|
2017-10-05 21:49:49 +02:00
|
|
|
val toD = (in.a.bits.opcode === AcquireBlock && in.a.bits.param === TLPermissions.BtoT) ||
|
|
|
|
(in.a.bits.opcode === AcquirePerm)
|
2017-07-27 23:07:24 +02:00
|
|
|
in.a.ready := Mux(toD, a_d.ready, a_a.ready)
|
|
|
|
|
|
|
|
a_a.valid := in.a.valid && !toD
|
|
|
|
a_a.bits := in.a.bits
|
2017-01-30 00:17:52 +01:00
|
|
|
a_a.bits.source := in.a.bits.source << 1 | Mux(isPut, UInt(1), UInt(0))
|
|
|
|
|
|
|
|
// Transform Acquire into Get
|
2017-10-05 21:49:49 +02:00
|
|
|
when (in.a.bits.opcode === AcquireBlock || in.a.bits.opcode === AcquirePerm) {
|
2017-01-30 00:17:52 +01:00
|
|
|
a_a.bits.opcode := Get
|
|
|
|
a_a.bits.param := UInt(0)
|
|
|
|
a_a.bits.source := in.a.bits.source << 1 | UInt(1)
|
|
|
|
}
|
|
|
|
|
2017-07-27 23:07:24 +02:00
|
|
|
// Upgrades are instantly successful
|
|
|
|
a_d.valid := in.a.valid && toD
|
2017-07-28 03:22:06 +02:00
|
|
|
a_d.bits := edgeIn.Grant(
|
|
|
|
fromSink = UInt(0),
|
|
|
|
toSource = in.a.bits.source,
|
|
|
|
lgSize = in.a.bits.size,
|
|
|
|
capPermissions = TLPermissions.toT)
|
2017-07-27 23:07:24 +02:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
// Take ReleaseData from C to A; Release from C to D
|
|
|
|
val c_a = Wire(out.a)
|
|
|
|
c_a.valid := in.c.valid && in.c.bits.opcode === ReleaseData
|
2017-07-28 03:22:06 +02:00
|
|
|
c_a.bits := edgeOut.Put(
|
|
|
|
fromSource = in.c.bits.source << 1,
|
|
|
|
toAddress = in.c.bits.address,
|
|
|
|
lgSize = in.c.bits.size,
|
|
|
|
data = in.c.bits.data)._2
|
2017-01-30 00:17:52 +01:00
|
|
|
|
2017-07-27 23:07:24 +02:00
|
|
|
// Releases without Data succeed instantly
|
2017-01-30 00:17:52 +01:00
|
|
|
val c_d = Wire(in.d)
|
|
|
|
c_d.valid := in.c.valid && in.c.bits.opcode === Release
|
2017-07-28 03:22:06 +02:00
|
|
|
c_d.bits := edgeIn.ReleaseAck(in.c.bits)
|
2017-01-30 00:17:52 +01:00
|
|
|
|
|
|
|
assert (!in.c.valid || in.c.bits.opcode === Release || in.c.bits.opcode === ReleaseData)
|
|
|
|
in.c.ready := Mux(in.c.bits.opcode === Release, c_d.ready, c_a.ready)
|
|
|
|
|
|
|
|
// Discard E
|
|
|
|
in.e.ready := Bool(true)
|
|
|
|
|
|
|
|
// Block B; should never happen
|
|
|
|
out.b.ready := Bool(false)
|
|
|
|
assert (!out.b.valid)
|
|
|
|
|
|
|
|
// Take responses from D and transform them
|
|
|
|
val d_d = Wire(in.d)
|
|
|
|
d_d <> out.d
|
|
|
|
d_d.bits.source := out.d.bits.source >> 1
|
2017-10-11 09:30:51 +02:00
|
|
|
if (unsafe) { d_d.bits.sink := UInt(0) }
|
2017-01-30 00:17:52 +01:00
|
|
|
|
|
|
|
when (out.d.bits.opcode === AccessAckData && out.d.bits.source(0)) {
|
|
|
|
d_d.bits.opcode := GrantData
|
2017-10-02 23:49:25 +02:00
|
|
|
d_d.bits.param := TLPermissions.toT
|
2017-01-30 00:17:52 +01:00
|
|
|
}
|
|
|
|
when (out.d.bits.opcode === AccessAck && !out.d.bits.source(0)) {
|
|
|
|
d_d.bits.opcode := ReleaseAck
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine the sources of messages into the channels
|
|
|
|
TLArbiter(TLArbiter.lowestIndexFirst)(out.a, (edgeOut.numBeats1(c_a.bits), c_a), (edgeOut.numBeats1(a_a.bits), a_a))
|
2017-07-27 23:07:24 +02:00
|
|
|
TLArbiter(TLArbiter.lowestIndexFirst)(in.d, (edgeIn .numBeats1(d_d.bits), d_d), (UInt(0), Queue(c_d, 2)), (UInt(0), Queue(a_d, 2)))
|
2017-01-30 00:17:52 +01:00
|
|
|
|
|
|
|
// Tie off unused ports
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
out.c.valid := Bool(false)
|
|
|
|
out.e.valid := Bool(false)
|
2017-01-18 03:52:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object TLCacheCork
|
|
|
|
{
|
2017-10-27 09:45:21 +02:00
|
|
|
def apply(unsafe: Boolean = false)(implicit p: Parameters): TLNode = LazyModule(new TLCacheCork(unsafe)).node
|
2017-01-18 03:52:47 +01:00
|
|
|
}
|