Change names
This commit is contained in:
@@ -22,7 +22,7 @@ import sifive.blocks.devices.uart._
|
|||||||
import sifive.blocks.devices.spi._
|
import sifive.blocks.devices.spi._
|
||||||
|
|
||||||
import chipyard.{BuildTop, BuildSystem}
|
import chipyard.{BuildTop, BuildSystem}
|
||||||
import chipyard.GenericConfig
|
import chipyard.GenericCoreConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Why do we need this?
|
* TODO: Why do we need this?
|
||||||
@@ -147,10 +147,9 @@ class WithControlCore extends Config((site, here, up) => {
|
|||||||
case MaxHartIdBits => log2Up(up(RocketTilesKey, site).size + up(BoomTilesKey, site).size + 1)
|
case MaxHartIdBits => log2Up(up(RocketTilesKey, site).size + up(BoomTilesKey, site).size + 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
class WithTraceIO extends Config((site, here, up) =>
|
class WithTraceIO extends GenericCoreConfig(
|
||||||
GenericConfig(Map("trace" -> true), {
|
properties = Map("trace" -> true),
|
||||||
case RocketTilesKey => false
|
specialCase = (site, here, up) => {
|
||||||
case _ => true
|
|
||||||
}) (site, here, up) orElse {
|
|
||||||
case TracePortKey => Some(TracePortParams())
|
case TracePortKey => Some(TracePortParams())
|
||||||
})
|
}
|
||||||
|
)
|
||||||
@@ -26,65 +26,67 @@ sealed trait CoreEntryBase {
|
|||||||
|
|
||||||
// Implementation of third-party core entries
|
// Implementation of third-party core entries
|
||||||
class CoreEntry[TileParamsT <: TileParams with Product: TypeTag, TileT <: BaseTile : TypeTag](
|
class CoreEntry[TileParamsT <: TileParams with Product: TypeTag, TileT <: BaseTile : TypeTag](
|
||||||
tk: Field[Seq[TileParamsT]],
|
tilesKey: Field[Seq[TileParamsT]],
|
||||||
ck: Field[Seq[RocketCrossingParams]]
|
crossingKey: Field[Seq[RocketCrossingParams]]
|
||||||
) extends CoreEntryBase {
|
) extends CoreEntryBase {
|
||||||
// Use reflection to get the parameter's constructor
|
// Use reflection to get the parameter's constructor
|
||||||
private val mirror = runtimeMirror(getClass.getClassLoader)
|
private val mirror = runtimeMirror(getClass.getClassLoader)
|
||||||
private val paramClass = mirror.runtimeClass(typeOf[TileParamsT].typeSymbol.asClass)
|
private val paramClass = mirror.runtimeClass(typeOf[TileParamsT].typeSymbol.asClass)
|
||||||
private val paramNames = (paramClass.getDeclaredFields map (f => f.getName)).zipWithIndex.toMap
|
private val paramNames = (paramClass.getDeclaredFields map (f => f.getName)).zipWithIndex.toMap
|
||||||
private val paramCtr = paramClass.getConstructors.head
|
private val paramCtor = paramClass.getConstructors.head
|
||||||
|
|
||||||
// Use reflection to get the tile's constructor
|
// Use reflection to get the tile's constructor
|
||||||
private val tileClass = mirror.runtimeClass(typeOf[TileT].typeSymbol.asClass)
|
private val tileClass = mirror.runtimeClass(typeOf[TileT].typeSymbol.asClass)
|
||||||
private val tileCtr = tileClass.getConstructors.filter(ctr => ctr.getParameterTypes()(4) == classOf[Parameters]).head
|
private val tileCtor = tileClass.getConstructors.filter(ctor => ctor.getParameterTypes()(4) == classOf[Parameters]).head
|
||||||
|
|
||||||
// Version of case class' copy() using reflection, where fields to be updated are passed by a map
|
// Version of case class' copy() using reflection, where fields to be updated are passed by a map
|
||||||
def copyTileParam(tileParam: TileParamsT, properties: Map[String, Any]) = {
|
def copyTileParam(tileParam: TileParamsT, properties: Map[String, Any]) = {
|
||||||
val values = tileParam.productIterator.toList
|
val values = tileParam.productIterator.toList
|
||||||
val indexedProperties = properties map { case (key, value) => (paramNames(key), value) }
|
//val filteredProperties = properties filter { case (key, value) => paramNames contains key }
|
||||||
|
val indexedProperties = /*filteredProperties*/ properties map { case (key, value) => (paramNames(key), value) }
|
||||||
val newValues = (0 until values.size) map
|
val newValues = (0 until values.size) map
|
||||||
(i => (if (indexedProperties contains i) indexedProperties(i) else values(i)).asInstanceOf[AnyRef])
|
(i => (if (indexedProperties contains i) indexedProperties(i) else values(i)).asInstanceOf[AnyRef])
|
||||||
paramCtr.newInstance(newValues:_*)
|
paramCtor.newInstance(newValues:_*)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tile parameter lookup using correct type
|
// Tile parameter lookup using correct type
|
||||||
def tileParamsLookup(implicit p: Parameters) = p(tk)
|
def tileParamsLookup(implicit p: Parameters) = p(tilesKey)
|
||||||
|
|
||||||
// If this core meet the requirement given by p, update parameter fields in the map
|
// If this core meet the requirement given by p, update parameter fields in the map
|
||||||
def updateWithFilter(view: View, p: Any => Boolean): PartialFunction[Any, Map[String, Any] => Any] = {
|
def updateWithFilter(view: View, p: Any => Boolean): PartialFunction[Any, Map[String, Any] => Any] = {
|
||||||
case key if (key == tk && p(tk)) => properties => view(tk) map
|
case key if (key == tilesKey && p(tilesKey)) => properties => view(tilesKey) map
|
||||||
(tile => copyTileParam(tile, properties))
|
(tile => copyTileParam(tile, properties))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate a tile and zip it with its parameter info, used by subsystem
|
// Instantiate a tile and zip it with its parameter info, used by subsystem
|
||||||
def instantiateTile(crossingLookup: (Seq[RocketCrossingParams], Int) => Seq[RocketCrossingParams], logicalTreeNode: LogicalTreeNode)
|
def instantiateTile(crossingLookup: (Seq[RocketCrossingParams], Int) => Seq[RocketCrossingParams], logicalTreeNode: LogicalTreeNode)
|
||||||
(implicit p: Parameters, valName: ValName) = {
|
(implicit p: Parameters, valName: ValName) = {
|
||||||
val tileParams = p(tk)
|
val tileParams = p(tilesKey)
|
||||||
val crossings = crossingLookup(p(ck), tileParams.size)
|
val crossings = crossingLookup(p(crossingKey), tileParams.size)
|
||||||
(tileParams zip crossings) map {
|
(tileParams zip crossings) map {
|
||||||
case (param, crossing) => (
|
case (param, crossing) => (
|
||||||
param,
|
param,
|
||||||
crossing,
|
crossing,
|
||||||
LazyModule(tileCtr.newInstance(param, crossing, PriorityMuxHartIdFromSeq(tileParams), logicalTreeNode, p.asInstanceOf[Parameters]).asInstanceOf[TileT])
|
LazyModule(tileCtor.newInstance(param, crossing, PriorityMuxHartIdFromSeq(tileParams), logicalTreeNode, p.asInstanceOf[Parameters]).asInstanceOf[TileT])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Core Generic Config - change properties in the given map
|
// Generic Core Config - change properties in the given map
|
||||||
class GenericConfig(properties: Map[String, Any], filterFunc: Any => Boolean) {
|
class GenericCoreConfig(
|
||||||
val configFunc: (View, View, View) => PartialFunction[Any, Any] = (site, here, up) => scala.Function.unlift((key: Any) => {
|
// Parameter properties to be changed and their new values. Any field not in a core's parameters will be ignored.
|
||||||
|
properties: Map[String, Any],
|
||||||
|
// Function for filtering the list of TilesKey.
|
||||||
|
filterFunc: Any => Boolean = (_ => true),
|
||||||
|
// Handling special cases where partial function input is not a TilesKey.
|
||||||
|
specialCase: (View, View, View) => PartialFunction[Any, Any] = ((_, _, _) => Map.empty)
|
||||||
|
) extends Config((site, here, up) =>
|
||||||
|
scala.Function.unlift((key: Any) => {
|
||||||
val tiles = CoreManager.cores flatMap (core => core.updateWithFilter(up, filterFunc).lift(key))
|
val tiles = CoreManager.cores flatMap (core => core.updateWithFilter(up, filterFunc).lift(key))
|
||||||
if (tiles.size == 0) None else Some(tiles map (tile => tile(properties)))
|
if (tiles.size == 0) None else Some(tiles map (tile => tile(properties)))
|
||||||
})
|
}).orElse(specialCase(site, here, up))
|
||||||
}
|
)
|
||||||
|
|
||||||
// Wrapper object of the class above
|
|
||||||
object GenericConfig {
|
|
||||||
def apply(properties: Map[String, Any], filterFunc: Any => Boolean = (_ => true)) =
|
|
||||||
new GenericConfig(properties, filterFunc).configFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
// A list of all cores.
|
// A list of all cores.
|
||||||
object CoreManager {
|
object CoreManager {
|
||||||
|
|||||||
Reference in New Issue
Block a user