Skip to content

Commit

Permalink
BaseSubsystem: Move attachment function into trait
Browse files Browse the repository at this point in the history
  • Loading branch information
rmac-sifive committed Nov 19, 2019
1 parent 71008b9 commit 92a44bd
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/main/scala/subsystem/BaseSubsystem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,28 @@ case object FBUS extends BaseSubsystemBusAttachment
case object MBUS extends BaseSubsystemBusAttachment
case object CBUS extends BaseSubsystemBusAttachment

trait HasBusAttachmentFunction {
val sbus: SystemBus
val pbus: PeripheryBus
val fbus: FrontBus
val mbus: MemoryBus
val cbus: PeripheryBus

type BusAttachmentFunction = PartialFunction[BaseSubsystemBusAttachment, TLBusWrapper]
def baseBusAttachmentFunc: BusAttachmentFunction = {
case SBUS => sbus
case PBUS => pbus
case FBUS => fbus
case MBUS => mbus
case CBUS => cbus
}
def attach(where: BaseSubsystemBusAttachment): TLBusWrapper = baseBusAttachmentFunc(where)
}

/** Base Subsystem class with no peripheral devices or ports added */
abstract class BaseSubsystem(implicit p: Parameters) extends BareSubsystem with HasLogicalTreeNode {
abstract class BaseSubsystem(implicit p: Parameters) extends BareSubsystem
with HasLogicalTreeNode with HasBusAttachmentFunction {

override val module: BaseSubsystemModuleImp[BaseSubsystem]

// These are wrappers around the standard buses available in all subsytems, where
Expand All @@ -60,16 +80,6 @@ abstract class BaseSubsystem(implicit p: Parameters) extends BareSubsystem with
val mbus = LazyModule(new MemoryBus(p(MemoryBusKey)))
val cbus = LazyModule(new PeripheryBus(p(ControlBusKey)))

type BusAttachmentFunction = PartialFunction[BaseSubsystemBusAttachment, TLBusWrapper]
protected def baseBusAttachmentFunc: BusAttachmentFunction = {
case SBUS => sbus
case PBUS => pbus
case FBUS => fbus
case MBUS => mbus
case CBUS => cbus
}
protected def attach(where: BaseSubsystemBusAttachment): TLBusWrapper = baseBusAttachmentFunc(where)

// Collect information for use in DTS
lazy val topManagers = sbus.unifyManagers
ResourceBinding {
Expand Down

0 comments on commit 92a44bd

Please sign in to comment.