Periphery: dynamically create address map + config string for TL2
This commit is contained in:
parent
8876d83640
commit
b5ce6150c7
@ -289,10 +289,6 @@ trait PeripheryCoreplexLocalInterrupter extends LazyModule with HasPeripheryPara
|
||||
val clint = LazyModule(new CoreplexLocalInterrupter(clintConfig)(innerMMIOParams))
|
||||
// The periphery bus is 32-bit, so we may need to adapt its width to XLen
|
||||
clint.node := TLFragmenter(TLWidthWidget(peripheryBus.node, 4), beatBytes, 256)
|
||||
|
||||
// TL1 legacy
|
||||
val pDevices: ResourceManager[AddrMapEntry]
|
||||
pDevices.add(AddrMapEntry("clint", MemRange(clintConfig.address, clintConfig.size, MemAttr(AddrMapProt.RW))))
|
||||
}
|
||||
|
||||
trait PeripheryCoreplexLocalInterrupterBundle {
|
||||
@ -315,12 +311,8 @@ trait PeripheryBootROM extends LazyModule {
|
||||
implicit val p: Parameters
|
||||
val peripheryBus: TLXbar
|
||||
|
||||
val rom = LazyModule(new TLROM(0x1000, 0x1000, GenerateBootROM(p)))
|
||||
val rom = LazyModule(new TLROM(0x1000, 0x1000, GenerateBootROM(p)) { override def name = "bootrom" })
|
||||
rom.node := TLFragmenter(peripheryBus.node, 4, 256)
|
||||
|
||||
// TL1 legacy address map
|
||||
val pDevices: ResourceManager[AddrMapEntry]
|
||||
pDevices.add(AddrMapEntry("bootrom", MemRange(0x1000, 4096, MemAttr(AddrMapProt.RX))))
|
||||
}
|
||||
|
||||
trait PeripheryBootROMBundle {
|
||||
@ -344,10 +336,6 @@ trait PeripheryTestRAM extends LazyModule {
|
||||
|
||||
val sram = LazyModule(new TLRAM(AddressSet(ramBase, ramSize-1)))
|
||||
sram.node := TLFragmenter(peripheryBus.node, 4, 256)
|
||||
|
||||
// TL1 legacy address map
|
||||
val pDevices: ResourceManager[AddrMapEntry]
|
||||
pDevices.add(AddrMapEntry("testram", MemRange(ramBase, ramSize, MemAttr(AddrMapProt.RW))))
|
||||
}
|
||||
|
||||
trait PeripheryTestRAMBundle {
|
||||
|
@ -27,6 +27,10 @@ abstract class BaseTop(q: Parameters) extends LazyModule {
|
||||
val pBusMasters = new RangeManager
|
||||
val pDevices = new ResourceManager[AddrMapEntry]
|
||||
|
||||
// Add a peripheral bus
|
||||
val peripheryBus = LazyModule(new TLXbar)
|
||||
lazy val peripheryManagers = peripheryBus.node.edgesIn(0).manager.managers
|
||||
|
||||
lazy val c = CoreplexConfig(
|
||||
nTiles = q(NTiles),
|
||||
nExtInterrupts = pInterrupts.sum,
|
||||
@ -36,16 +40,14 @@ abstract class BaseTop(q: Parameters) extends LazyModule {
|
||||
hasExtMMIOPort = true
|
||||
)
|
||||
|
||||
lazy val genGlobalAddrMap = GenerateGlobalAddrMap(q, pDevices.get)
|
||||
lazy val genGlobalAddrMap = GenerateGlobalAddrMap(q, pDevices.get, peripheryManagers)
|
||||
private val qWithMap = q.alterPartial({case GlobalAddrMap => genGlobalAddrMap})
|
||||
|
||||
lazy val genConfigString = GenerateConfigString(qWithMap, c, pDevices.get)
|
||||
lazy val genConfigString = GenerateConfigString(qWithMap, c, pDevices.get, peripheryManagers)
|
||||
implicit val p = qWithMap.alterPartial({
|
||||
case ConfigString => genConfigString
|
||||
case NCoreplexExtClients => pBusMasters.sum})
|
||||
|
||||
// Add a peripheral bus
|
||||
val peripheryBus = LazyModule(new TLXbar)
|
||||
val legacy = LazyModule(new TLLegacy()(p.alterPartial({ case TLId => "L2toMMIO" })))
|
||||
|
||||
peripheryBus.node := TLBuffer(TLWidthWidget(TLHintHandler(legacy.node), legacy.tlDataBytes))
|
||||
|
@ -8,6 +8,7 @@ import uncore.devices._
|
||||
import rocket._
|
||||
import rocket.Util._
|
||||
import coreplex._
|
||||
import uncore.tilelink2._
|
||||
|
||||
import java.nio.file.{Files, Paths}
|
||||
import java.nio.{ByteBuffer, ByteOrder}
|
||||
@ -51,7 +52,7 @@ class GlobalVariable[T] {
|
||||
}
|
||||
|
||||
object GenerateGlobalAddrMap {
|
||||
def apply(p: Parameters, pDevicesEntries: Seq[AddrMapEntry]) = {
|
||||
def apply(p: Parameters, pDevicesEntries: Seq[AddrMapEntry], peripheryManagers: Seq[TLManagerParameters]) = {
|
||||
lazy val intIOAddrMap: AddrMap = {
|
||||
val entries = collection.mutable.ArrayBuffer[AddrMapEntry]()
|
||||
entries += AddrMapEntry("debug", MemSize(4096, MemAttr(AddrMapProt.RWX)))
|
||||
@ -64,8 +65,20 @@ object GenerateGlobalAddrMap {
|
||||
new AddrMap(entries)
|
||||
}
|
||||
|
||||
lazy val tl2AddrMap = new AddrMap(pDevicesEntries, collapse = true)
|
||||
lazy val extIOAddrMap = new AddrMap(AddrMapEntry("TL2", tl2AddrMap) +: p(ExtMMIOPorts), collapse = true)
|
||||
lazy val tl2Devices = peripheryManagers.map { manager =>
|
||||
val attr = MemAttr(
|
||||
(if (manager.supportsGet) AddrMapProt.R else 0) |
|
||||
(if (manager.supportsPutFull) AddrMapProt.W else 0) |
|
||||
(if (manager.executable) AddrMapProt.X else 0))
|
||||
val name = manager.nodePath.last.lazyModule.name // !!!
|
||||
manager.address.zipWithIndex.map { case (address, i) =>
|
||||
require (!address.strided) // TL1 can't do this
|
||||
AddrMapEntry(s"${name}", MemRange(address.base, address.mask+1, attr))
|
||||
}
|
||||
}.flatten
|
||||
|
||||
lazy val tl2AddrMap = new AddrMap(tl2Devices, collapse = true)
|
||||
lazy val extIOAddrMap = new AddrMap(AddrMapEntry("TL2", tl2AddrMap) +: (p(ExtMMIOPorts) ++ pDevicesEntries), collapse = true)
|
||||
|
||||
val memBase = 0x80000000L
|
||||
val memSize = p(ExtMemSize)
|
||||
@ -80,7 +93,7 @@ object GenerateGlobalAddrMap {
|
||||
}
|
||||
|
||||
object GenerateConfigString {
|
||||
def apply(p: Parameters, c: CoreplexConfig, pDevicesEntries: Seq[AddrMapEntry]) = {
|
||||
def apply(p: Parameters, c: CoreplexConfig, pDevicesEntries: Seq[AddrMapEntry], peripheryManagers: Seq[TLManagerParameters]) = {
|
||||
val addrMap = p(GlobalAddrMap)
|
||||
val plicAddr = addrMap("io:int:plic").start
|
||||
val clint = CoreplexLocalInterrupterConfig(0, addrMap("io:ext:TL2:clint").start)
|
||||
@ -136,12 +149,13 @@ object GenerateConfigString {
|
||||
}
|
||||
res append "};\n"
|
||||
pDevicesEntries foreach { entry =>
|
||||
val region = addrMap("io:ext:TL2:" + entry.name)
|
||||
val region = addrMap("io:ext:" + entry.name)
|
||||
res append s"${entry.name} {\n"
|
||||
res append s" addr 0x${region.start.toString(16)};\n"
|
||||
res append s" size 0x${region.size.toString(16)}; \n"
|
||||
res append "}\n"
|
||||
}
|
||||
peripheryManagers.foreach { manager => res append manager.dts }
|
||||
res append '\u0000'
|
||||
res.toString
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user