Skip to content

Commit

Permalink
subsystem: refine Attachable trait to be based on LocationMap
Browse files Browse the repository at this point in the history
  • Loading branch information
hcook committed Apr 16, 2020
1 parent 78beb3a commit e7b9aa7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 28 deletions.
55 changes: 55 additions & 0 deletions src/main/scala/subsystem/Attachable.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip.subsystem

import scala.language.dynamics
import freechips.rocketchip.config.Parameters
import freechips.rocketchip.diplomacy.{LazyModule, LazyScope}
import freechips.rocketchip.diplomaticobjectmodel.HasLogicalTreeNode
import freechips.rocketchip.prci.ClockGroupEphemeralNode
import freechips.rocketchip.tilelink.TLBusWrapper
import freechips.rocketchip.util.{Location, LocationMap}

/** These traits are intended to make it possible to configure to which
* buses optional devices are attached, even after a subsystem has been instantiated.
* Consider them experimental for now.
*/

trait LazyScopeWithParameters extends LazyScope { this: LazyModule =>
implicit val p: Parameters
}

trait HasLogicalHierarchy extends LazyScopeWithParameters with HasLogicalTreeNode { this: LazyModule => }

trait HasPRCILocations extends HasLogicalHierarchy { this: LazyModule =>
implicit val asyncClockGroupsNode: ClockGroupEphemeralNode
val ibus: InterruptBusWrapper
}

// TODO make this trait extend Dynamic itself and add the locations to anyLocationMap?
trait HasLocations extends HasPRCILocations { this: LazyModule =>
val anyLocationMap = new LocationMap[Any]
def selectDynamic(name: String): Any = anyLocationMap.selectDynamic(name)
def updateDynamic(name: String)(value: Any): Unit = anyLocationMap.updateDynamic(name)(value)

val tlBusWrapperLocationMap = new LocationMap[TLBusWrapper]
def locateTLBusWrapper(location: TLBusWrapperLocation): TLBusWrapper = locateTLBusWrapper(location.name)
def locateTLBusWrapper(name: String): TLBusWrapper = tlBusWrapperLocationMap.selectDynamic(name)
}

trait CanInstantiateWithinContext {
def instantiate(context: HasLocations)(implicit p: Parameters): Unit
}

trait CanConnectWithinContext {
def connect(context: HasLocations)(implicit p: Parameters): Unit
}

/** Attachable things provide a standard interface by which other things may attach themselves to this target.
* Right now the trait is mostly for backwards compatibility, and in case it eventually becomes valuable
* to be able to define additional resources available to agents trying to attach themselves, other than
* what is being made available via LocationMaps in trait HasLocations.
*/
trait Attachable extends HasLocations { this: LazyModule =>
def locateTLBusWrapper(location: TLBusWrapperLocation): TLBusWrapper
}
30 changes: 2 additions & 28 deletions src/main/scala/subsystem/BaseSubsystem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,8 @@ abstract class BareSubsystemModuleImp[+L <: BareSubsystem](_outer: L) extends La
println(outer.dts)
}

/** These traits are intended to make it possible to configure to which
* buses optional devices are attached, even after a subsystem has been instantiated.
* Consider them experimental for now.
*/

trait Attachable extends LazyScope
with HasLogicalTreeNode
with HasBusLocationFunction { this: LazyModule =>
implicit val p: Parameters
implicit val asyncClockGroupsNode: ClockGroupEphemeralNode
val ibus: InterruptBusWrapper
}

trait HasBusLocationFunction {
type BusLocationFunction = PartialFunction[TLBusWrapperLocation, TLBusWrapper]
def locateTLBusWrapper: BusLocationFunction
}

/** This class the cases matched in baseBusLocateFunc below.
* Extend/override them to offer novel attachment locations.
/** This trait contains the cases matched in baseBusAttachmentFunc below.
* Extend/override them to offer novel attachment locations in subclasses of BaseSubsystem.
*/
class TLBusWrapperLocation(name: String) extends Location[TLBusWrapper](name)
case object SBUS extends TLBusWrapperLocation("subsystem_sbus")
Expand Down Expand Up @@ -95,14 +77,6 @@ abstract class BaseSubsystem(implicit p: Parameters) extends BareSubsystem
val mbus = LazyModule(new MemoryBus(p(MemoryBusKey)))
val cbus = LazyModule(new PeripheryBus(p(ControlBusKey), "subsystem_cbus"))

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

implicit val asyncClockGroupsNode = p(AsyncClockGroupsKey)
val async_clock_groups =
p(SubsystemDriveAsyncClockGroupsKey)
Expand Down

0 comments on commit e7b9aa7

Please sign in to comment.