From c1f6fbc3ebaf0196c52c137e7d51ec9fb6bd9a67 Mon Sep 17 00:00:00 2001 From: Henry Cook Date: Mon, 9 Mar 2020 22:11:31 -0700 Subject: [PATCH] tilelink: enhance TLBusWrapper with connectivity and topology case classes --- src/main/scala/tilelink/BusWrapper.scala | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/main/scala/tilelink/BusWrapper.scala b/src/main/scala/tilelink/BusWrapper.scala index f2cf771c5bd..bcf67869d6a 100644 --- a/src/main/scala/tilelink/BusWrapper.scala +++ b/src/main/scala/tilelink/BusWrapper.scala @@ -6,6 +6,7 @@ import Chisel._ import freechips.rocketchip.config.Parameters import freechips.rocketchip.diplomacy._ import freechips.rocketchip.prci._ +import freechips.rocketchip.subsystem._ // TODO this class should be moved to package subsystem import freechips.rocketchip.util._ /** Specifies widths of various attachement points in the SoC */ @@ -86,6 +87,61 @@ abstract class TLBusWrapper(params: HasTLBusParams, val busName: String)(implici } } +trait TLBusWrapperInstantiationLike { + def instantiate(context: HasLocations, loc: Location[TLBusWrapper])(implicit p: Parameters): TLBusWrapper +} + +trait TLBusWrapperConnectionLike { + val xType: ClockCrossingType + def inject(implicit p: Parameters): TLNode = TLNameNode("temp") + def connect(context: HasLocations, from: Location[TLBusWrapper], to: Location[TLBusWrapper])(implicit p: Parameters): Unit +} + +case class TLBusWrapperCrossToConnection + (xType: ClockCrossingType) + (nodeView: (TLBusWrapper, Parameters) => TLInwardNode = { case(w, p) => w.crossInHelper(xType)(p) }, + inject: Parameters => TLNode = { _ => TLNameNode("temp") }) + extends TLBusWrapperConnectionLike +{ + def connect(context: HasLocations, from: Location[TLBusWrapper], to: Location[TLBusWrapper])(implicit p: Parameters): Unit = { + val masterTLBus = context.locateTLBusWrapper(from) + val slaveTLBus = context.locateTLBusWrapper(to) + slaveTLBus.clockGroupNode := asyncMux(xType, context.asyncClockGroupsNode, masterTLBus.clockGroupNode) + masterTLBus.coupleTo(s"bus_named_${masterTLBus.busName}") { + nodeView(slaveTLBus,p) :*= TLWidthWidget(masterTLBus.beatBytes) :*= inject(p) :*= _ + // TODO does BankBinder injection need to be (_ :=* bb :*= _) + } + } +} + +case class TLBusWrapperCrossFromConnection + (xType: ClockCrossingType) + (nodeView: (TLBusWrapper, Parameters) => TLOutwardNode = { case(w, p) => w.crossOutHelper(xType)(p) }, + inject: Parameters => TLNode = { _ => TLNameNode("temp") }) + extends TLBusWrapperConnectionLike +{ + def connect(context: HasLocations, from: Location[TLBusWrapper], to: Location[TLBusWrapper])(implicit p: Parameters): Unit = FlipRendering { implicit p => + val masterTLBus = context.locateTLBusWrapper(to) + val slaveTLBus = context.locateTLBusWrapper(from) + masterTLBus.clockGroupNode := asyncMux(xType, context.asyncClockGroupsNode, slaveTLBus.clockGroupNode) + slaveTLBus.coupleFrom(s"bus_named_${masterTLBus.busName}") { + _ :=* inject(p) :=* TLWidthWidget(masterTLBus.beatBytes) :=* nodeView(masterTLBus, p) + } + } +} + +class TLBusWrapperTopology( + val instantiations: Seq[(Location[TLBusWrapper], TLBusWrapperInstantiationLike)], + val connections: Seq[(Location[TLBusWrapper], Location[TLBusWrapper], TLBusWrapperConnectionLike)] +) extends CanInstantiateWithinContext with CanConnectWithinContext { + def instantiate(context: HasLocations)(implicit p: Parameters): Unit = { + instantiations.foreach { case (loc, params) => params.instantiate(context, loc) } + } + def connect(context: HasLocations)(implicit p: Parameters): Unit = { + connections.foreach { case (from, to, params) => params.connect(context, from, to) } + } +} + trait CanAttachTLSlaves extends HasTLBusParams { this: TLBusWrapper => def toSlave[D,U,E,B <: Data] (name: Option[String] = None, buffer: BufferParams = BufferParams.none)