Skip to content

Commit

Permalink
Merge pull request chipsalliance#2220 from chipsalliance/subsystem-bu…
Browse files Browse the repository at this point in the history
…s-attachment-6

refactor HasBusAttachmentFunction to be purely abstract
  • Loading branch information
hcook authored Dec 12, 2019
2 parents 626060a + 24cc853 commit 6d6b7ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/diplomacy/Resources.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ trait DeviceInterrupts
def describeInterrupts(resources: ResourceBindings): Map[String, Seq[ResourceValue]] = {
val int = resources("int")

int.foreach { b => require (b.device.isDefined, "Device ${devname} property 'int' is missing user device") }
int.foreach { b => require (b.device.isDefined, s"Device ${this} property 'int' is missing user device") }
val parents = int.map(_.device.get).distinct
val simple = parents.size == 1 && !alwaysExtended

Expand Down
35 changes: 15 additions & 20 deletions src/main/scala/subsystem/BaseSubsystem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ abstract class BareSubsystemModuleImp[+L <: BareSubsystem](_outer: L) extends La
}


/** This trait contains the cases matched in baseAttachmentFunc below.
* Both can be extended to offer novel attachment locations in subclasses of BaseSubsystem.
trait HasBusAttachmentFunction {
type BusAttachmentFunction = PartialFunction[BaseSubsystemBusAttachment, TLBusWrapper]
def attach: BusAttachmentFunction
}

/** This trait contains the cases matched in baseBusAttachmentFunc below.
* Extend/override them to offer novel attachment locations in subclasses of BaseSubsystem.
*/
trait BaseSubsystemBusAttachment
case object SBUS extends BaseSubsystemBusAttachment
Expand All @@ -47,24 +52,6 @@ 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 with HasBusAttachmentFunction {
Expand All @@ -80,6 +67,14 @@ abstract class BaseSubsystem(implicit p: Parameters) extends BareSubsystem
val mbus = LazyModule(new MemoryBus(p(MemoryBusKey)))
val cbus = LazyModule(new PeripheryBus(p(ControlBusKey)))

def attach: BusAttachmentFunction = {
case SBUS => sbus
case PBUS => pbus
case FBUS => fbus
case MBUS => mbus
case CBUS => cbus
}

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

0 comments on commit 6d6b7ae

Please sign in to comment.