2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
2016-08-19 20:08:35 +02:00
|
|
|
|
|
|
|
package uncore.tilelink2
|
|
|
|
|
|
|
|
import Chisel._
|
2016-08-31 19:37:30 +02:00
|
|
|
import chisel3.internal.sourceinfo.SourceInfo
|
2016-10-04 00:17:36 +02:00
|
|
|
import diplomacy._
|
|
|
|
import scala.collection.mutable.ListBuffer
|
2016-08-19 20:08:35 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
object TLImp extends NodeImp[TLClientPortParameters, TLManagerPortParameters, TLEdgeOut, TLEdgeIn, TLBundle]
|
2016-09-29 23:30:19 +02:00
|
|
|
{
|
2016-10-04 00:17:36 +02:00
|
|
|
def edgeO(pd: TLClientPortParameters, pu: TLManagerPortParameters): TLEdgeOut = new TLEdgeOut(pd, pu)
|
|
|
|
def edgeI(pd: TLClientPortParameters, pu: TLManagerPortParameters): TLEdgeIn = new TLEdgeIn(pd, pu)
|
|
|
|
def bundleO(eo: Seq[TLEdgeOut]): Vec[TLBundle] = {
|
|
|
|
require (!eo.isEmpty)
|
|
|
|
Vec(eo.size, TLBundle(eo.map(_.bundle).reduce(_.union(_))))
|
|
|
|
}
|
|
|
|
def bundleI(ei: Seq[TLEdgeIn]): Vec[TLBundle] = {
|
|
|
|
require (!ei.isEmpty)
|
2016-10-26 02:47:32 +02:00
|
|
|
Vec(ei.size, TLBundle(ei.map(_.bundle).reduce(_.union(_))))
|
2016-10-04 00:17:36 +02:00
|
|
|
}
|
2016-09-29 23:30:19 +02:00
|
|
|
|
2016-10-09 21:34:10 +02:00
|
|
|
var emitMonitors = true
|
2016-10-13 06:02:31 +02:00
|
|
|
var stressTestDecoupled = false
|
|
|
|
var combinationalCheck = false
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
def colour = "#000000" // black
|
2016-10-28 23:00:55 +02:00
|
|
|
override def labelI(ei: TLEdgeIn) = (ei.manager.beatBytes * 8).toString
|
|
|
|
override def labelO(eo: TLEdgeOut) = (eo.manager.beatBytes * 8).toString
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
def connect(bo: => TLBundle, bi: => TLBundle, ei: => TLEdgeIn)(implicit sourceInfo: SourceInfo): (Option[LazyModule], () => Unit) = {
|
2016-10-09 21:34:10 +02:00
|
|
|
val monitor = if (emitMonitors) {
|
|
|
|
Some(LazyModule(new TLMonitor(() => new TLBundleSnoop(bo.params), () => ei, sourceInfo)))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
(monitor, () => {
|
2016-10-04 00:17:36 +02:00
|
|
|
bi <> bo
|
2016-10-09 21:34:10 +02:00
|
|
|
monitor.foreach { _.module.io.in := TLBundleSnoop(bo) }
|
2016-10-13 06:02:31 +02:00
|
|
|
if (combinationalCheck) {
|
|
|
|
// It is forbidden for valid to depend on ready in TL2
|
|
|
|
// If someone did that, then this will create a detectable combinational loop
|
|
|
|
bo.a.ready := bi.a.ready && bo.a.valid
|
|
|
|
bi.b.ready := bo.b.ready && bi.b.valid
|
|
|
|
bo.c.ready := bi.c.ready && bo.c.valid
|
|
|
|
bi.d.ready := bo.d.ready && bi.d.valid
|
|
|
|
bo.e.ready := bi.e.ready && bo.e.valid
|
|
|
|
}
|
|
|
|
if (stressTestDecoupled) {
|
|
|
|
// Randomly stall the transfers
|
|
|
|
val allow = LFSRNoiseMaker(5)
|
|
|
|
bi.a.valid := bo.a.valid && allow(0)
|
|
|
|
bo.a.ready := bi.a.ready && allow(0)
|
|
|
|
bo.b.valid := bi.b.valid && allow(1)
|
|
|
|
bi.b.ready := bo.b.ready && allow(1)
|
|
|
|
bi.c.valid := bo.c.valid && allow(2)
|
|
|
|
bo.c.ready := bi.c.ready && allow(2)
|
|
|
|
bo.d.valid := bi.d.valid && allow(3)
|
|
|
|
bi.d.ready := bo.d.ready && allow(3)
|
|
|
|
bi.e.valid := bo.e.valid && allow(4)
|
|
|
|
bo.e.ready := bi.e.ready && allow(4)
|
|
|
|
// Inject garbage whenever not valid
|
|
|
|
val bits_a = bo.a.bits.fromBits(LFSRNoiseMaker(bo.a.bits.asUInt.getWidth))
|
|
|
|
val bits_b = bi.b.bits.fromBits(LFSRNoiseMaker(bi.b.bits.asUInt.getWidth))
|
|
|
|
val bits_c = bo.c.bits.fromBits(LFSRNoiseMaker(bo.c.bits.asUInt.getWidth))
|
|
|
|
val bits_d = bi.d.bits.fromBits(LFSRNoiseMaker(bi.d.bits.asUInt.getWidth))
|
|
|
|
val bits_e = bo.e.bits.fromBits(LFSRNoiseMaker(bo.e.bits.asUInt.getWidth))
|
|
|
|
when (!bi.a.valid) { bi.a.bits := bits_a }
|
|
|
|
when (!bo.b.valid) { bo.b.bits := bits_b }
|
|
|
|
when (!bi.c.valid) { bi.c.bits := bits_c }
|
|
|
|
when (!bo.d.valid) { bo.d.bits := bits_d }
|
|
|
|
when (!bi.e.valid) { bi.e.bits := bits_e }
|
|
|
|
}
|
2016-10-04 00:17:36 +02:00
|
|
|
})
|
|
|
|
}
|
2016-09-29 23:30:19 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
override def mixO(pd: TLClientPortParameters, node: OutwardNode[TLClientPortParameters, TLManagerPortParameters, TLBundle]): TLClientPortParameters =
|
2016-10-15 01:18:57 +02:00
|
|
|
pd.copy(clients = pd.clients.map { c => c.copy (nodePath = node +: c.nodePath) })
|
2016-10-04 00:17:36 +02:00
|
|
|
override def mixI(pu: TLManagerPortParameters, node: InwardNode[TLClientPortParameters, TLManagerPortParameters, TLBundle]): TLManagerPortParameters =
|
2016-10-15 01:18:57 +02:00
|
|
|
pu.copy(managers = pu.managers.map { m => m.copy (nodePath = node +: m.nodePath) })
|
|
|
|
override def getO(pu: TLManagerPortParameters): Option[BaseNode] = {
|
|
|
|
val head = pu.managers.map(_.nodePath.headOption)
|
|
|
|
if (head.exists(!_.isDefined) || head.map(_.get).distinct.size != 1) {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
val subproblem = pu.copy(managers = pu.managers.map(m => m.copy(nodePath = m.nodePath.tail)))
|
|
|
|
getO(subproblem) match {
|
|
|
|
case Some(x) => Some(x)
|
|
|
|
case None => Some(head(0).get)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-04 00:17:36 +02:00
|
|
|
}
|
2016-09-08 23:41:08 +02:00
|
|
|
|
2016-10-26 03:04:26 +02:00
|
|
|
// Nodes implemented inside modules
|
2016-10-04 00:17:36 +02:00
|
|
|
case class TLIdentityNode() extends IdentityNode(TLImp)
|
|
|
|
case class TLClientNode(portParams: TLClientPortParameters, numPorts: Range.Inclusive = 1 to 1)
|
|
|
|
extends SourceNode(TLImp)(portParams, numPorts)
|
|
|
|
case class TLManagerNode(portParams: TLManagerPortParameters, numPorts: Range.Inclusive = 1 to 1)
|
|
|
|
extends SinkNode(TLImp)(portParams, numPorts)
|
2016-09-26 10:18:53 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
object TLClientNode
|
|
|
|
{
|
|
|
|
def apply(params: TLClientParameters) =
|
|
|
|
new TLClientNode(TLClientPortParameters(Seq(params)), 1 to 1)
|
2016-09-08 23:41:08 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
object TLManagerNode
|
2016-08-19 20:08:35 +02:00
|
|
|
{
|
2016-10-04 00:17:36 +02:00
|
|
|
def apply(beatBytes: Int, params: TLManagerParameters) =
|
2016-11-03 01:53:32 +01:00
|
|
|
new TLManagerNode(TLManagerPortParameters(Seq(params), beatBytes, minLatency = 0), 1 to 1)
|
2016-09-29 23:30:19 +02:00
|
|
|
}
|
2016-09-08 23:41:08 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
case class TLAdapterNode(
|
|
|
|
clientFn: Seq[TLClientPortParameters] => TLClientPortParameters,
|
|
|
|
managerFn: Seq[TLManagerPortParameters] => TLManagerPortParameters,
|
|
|
|
numClientPorts: Range.Inclusive = 1 to 1,
|
|
|
|
numManagerPorts: Range.Inclusive = 1 to 1)
|
|
|
|
extends InteriorNode(TLImp)(clientFn, managerFn, numClientPorts, numManagerPorts)
|
|
|
|
|
2016-10-26 03:04:26 +02:00
|
|
|
// Nodes passed from an inner module
|
|
|
|
case class TLOutputNode() extends OutputNode(TLImp)
|
|
|
|
case class TLInputNode() extends InputNode(TLImp)
|
|
|
|
|
|
|
|
// Nodes used for external ports
|
|
|
|
case class TLBlindOutputNode(portParams: TLManagerPortParameters) extends BlindOutputNode(TLImp)(portParams)
|
|
|
|
case class TLBlindInputNode(portParams: TLClientPortParameters) extends BlindInputNode(TLImp)(portParams)
|
|
|
|
|
2016-11-24 03:53:03 +01:00
|
|
|
case class TLInternalOutputNode(portParams: TLManagerPortParameters) extends InternalOutputNode(TLImp)(portParams)
|
|
|
|
case class TLInternalInputNode(portParams: TLClientPortParameters) extends InternalInputNode(TLImp)(portParams)
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
/** Synthesizeable unit tests */
|
|
|
|
import unittest._
|
|
|
|
|
|
|
|
class TLInputNodeTest extends UnitTest(500000) {
|
|
|
|
class Acceptor extends LazyModule {
|
|
|
|
val node = TLInputNode()
|
|
|
|
val tlram = LazyModule(new TLRAM(AddressSet(0x54321000, 0xfff)))
|
|
|
|
tlram.node := node
|
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
val io = new Bundle {
|
|
|
|
val in = node.bundleIn
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 23:30:19 +02:00
|
|
|
}
|
2016-08-31 22:30:06 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
val fuzzer = LazyModule(new TLFuzzer(5000))
|
|
|
|
LazyModule(new Acceptor).node := TLFragmenter(4, 64)(fuzzer.node)
|
2016-09-29 23:30:19 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
io.finished := Module(fuzzer.module).io.finished
|
2016-09-29 23:30:19 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
object TLAsyncImp extends NodeImp[TLAsyncClientPortParameters, TLAsyncManagerPortParameters, TLAsyncEdgeParameters, TLAsyncEdgeParameters, TLAsyncBundle]
|
2016-09-29 23:30:19 +02:00
|
|
|
{
|
2016-10-04 00:17:36 +02:00
|
|
|
def edgeO(pd: TLAsyncClientPortParameters, pu: TLAsyncManagerPortParameters): TLAsyncEdgeParameters = TLAsyncEdgeParameters(pd, pu)
|
|
|
|
def edgeI(pd: TLAsyncClientPortParameters, pu: TLAsyncManagerPortParameters): TLAsyncEdgeParameters = TLAsyncEdgeParameters(pd, pu)
|
|
|
|
def bundleO(eo: Seq[TLAsyncEdgeParameters]): Vec[TLAsyncBundle] = {
|
|
|
|
require (eo.size == 1)
|
|
|
|
Vec(eo.size, new TLAsyncBundle(eo(0).bundle))
|
2016-09-09 06:11:31 +02:00
|
|
|
}
|
2016-10-04 00:17:36 +02:00
|
|
|
def bundleI(ei: Seq[TLAsyncEdgeParameters]): Vec[TLAsyncBundle] = {
|
|
|
|
require (ei.size == 1)
|
2016-10-26 02:47:32 +02:00
|
|
|
Vec(ei.size, new TLAsyncBundle(ei(0).bundle))
|
2016-09-09 06:11:31 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
def colour = "#ff0000" // red
|
2016-10-28 23:00:55 +02:00
|
|
|
override def labelI(ei: TLAsyncEdgeParameters) = ei.manager.depth.toString
|
|
|
|
override def labelO(eo: TLAsyncEdgeParameters) = eo.manager.depth.toString
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
def connect(bo: => TLAsyncBundle, bi: => TLAsyncBundle, ei: => TLAsyncEdgeParameters)(implicit sourceInfo: SourceInfo): (Option[LazyModule], () => Unit) = {
|
|
|
|
(None, () => { bi <> bo })
|
2016-08-31 19:37:30 +02:00
|
|
|
}
|
2016-08-19 20:08:35 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
override def mixO(pd: TLAsyncClientPortParameters, node: OutwardNode[TLAsyncClientPortParameters, TLAsyncManagerPortParameters, TLAsyncBundle]): TLAsyncClientPortParameters =
|
|
|
|
pd.copy(base = pd.base.copy(clients = pd.base.clients.map { c => c.copy (nodePath = node +: c.nodePath) }))
|
|
|
|
override def mixI(pu: TLAsyncManagerPortParameters, node: InwardNode[TLAsyncClientPortParameters, TLAsyncManagerPortParameters, TLAsyncBundle]): TLAsyncManagerPortParameters =
|
|
|
|
pu.copy(base = pu.base.copy(managers = pu.base.managers.map { m => m.copy (nodePath = node +: m.nodePath) }))
|
2016-08-31 04:26:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
case class TLAsyncIdentityNode() extends IdentityNode(TLAsyncImp)
|
|
|
|
case class TLAsyncOutputNode() extends OutputNode(TLAsyncImp)
|
|
|
|
case class TLAsyncInputNode() extends InputNode(TLAsyncImp)
|
|
|
|
|
|
|
|
case class TLAsyncSourceNode() extends MixedNode(TLImp, TLAsyncImp)(
|
|
|
|
dFn = { case (1, s) => s.map(TLAsyncClientPortParameters(_)) },
|
|
|
|
uFn = { case (1, s) => s.map(_.base) },
|
|
|
|
numPO = 1 to 1,
|
|
|
|
numPI = 1 to 1)
|
|
|
|
|
|
|
|
case class TLAsyncSinkNode(depth: Int) extends MixedNode(TLAsyncImp, TLImp)(
|
|
|
|
dFn = { case (1, s) => s.map(_.base) },
|
|
|
|
uFn = { case (1, s) => s.map(TLAsyncManagerPortParameters(depth, _)) },
|
|
|
|
numPO = 1 to 1,
|
|
|
|
numPI = 1 to 1)
|