2016-09-22 01:54:35 +02:00
|
|
|
package coreplex
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import cde.{Parameters, Field}
|
|
|
|
import junctions._
|
2016-10-04 00:17:36 +02:00
|
|
|
import diplomacy._
|
2016-09-22 01:54:35 +02:00
|
|
|
import uncore.tilelink._
|
|
|
|
import uncore.tilelink2._
|
|
|
|
import uncore.coherence._
|
|
|
|
import uncore.agents._
|
|
|
|
import uncore.devices._
|
|
|
|
import uncore.util._
|
|
|
|
import uncore.converters._
|
|
|
|
import rocket._
|
2016-09-28 06:27:07 +02:00
|
|
|
import util._
|
2016-09-22 01:54:35 +02:00
|
|
|
|
|
|
|
/** Number of memory channels */
|
|
|
|
case object NMemoryChannels extends Field[Int]
|
|
|
|
/** Number of banks per memory channel */
|
|
|
|
case object NBanksPerMemoryChannel extends Field[Int]
|
|
|
|
/** Least significant bit of address used for bank partitioning */
|
|
|
|
case object BankIdLSB extends Field[Int]
|
|
|
|
/** Function for building some kind of coherence manager agent */
|
|
|
|
case object BuildL2CoherenceManager extends Field[(Int, Parameters) => CoherenceAgent]
|
|
|
|
/** Function for building some kind of tile connected to a reset signal */
|
2016-10-27 04:02:04 +02:00
|
|
|
case object BuildTiles extends Field[Seq[Parameters => LazyTile]]
|
2016-09-22 01:54:35 +02:00
|
|
|
/** The file to read the BootROM contents from */
|
|
|
|
case object BootROMFile extends Field[String]
|
|
|
|
|
|
|
|
trait HasCoreplexParameters {
|
|
|
|
implicit val p: Parameters
|
|
|
|
lazy val nBanksPerMemChannel = p(NBanksPerMemoryChannel)
|
|
|
|
lazy val lsb = p(BankIdLSB)
|
|
|
|
lazy val innerParams = p.alterPartial({ case TLId => "L1toL2" })
|
2016-09-27 20:44:11 +02:00
|
|
|
lazy val outerMemParams = p.alterPartial({ case TLId => "L2toMC" })
|
2016-09-23 09:19:08 +02:00
|
|
|
lazy val outerMMIOParams = p.alterPartial({ case TLId => "L2toMMIO" })
|
2016-09-22 01:54:35 +02:00
|
|
|
lazy val globalAddrMap = p(rocketchip.GlobalAddrMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
case class CoreplexConfig(
|
|
|
|
nTiles: Int,
|
|
|
|
nExtInterrupts: Int,
|
|
|
|
nSlaves: Int,
|
|
|
|
nMemChannels: Int,
|
2016-09-22 03:27:31 +02:00
|
|
|
hasSupervisor: Boolean)
|
2016-09-22 01:54:35 +02:00
|
|
|
{
|
2016-10-05 07:22:42 +02:00
|
|
|
val nInterruptPriorities = if (nExtInterrupts <= 1) 0 else (nExtInterrupts min 7)
|
|
|
|
val plicKey = PLICConfig(nTiles, hasSupervisor, nExtInterrupts, nInterruptPriorities)
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|
|
|
|
|
2016-10-25 04:01:32 +02:00
|
|
|
abstract class BaseCoreplex(c: CoreplexConfig)(implicit val p: Parameters) extends LazyModule with HasCoreplexParameters {
|
2016-10-27 04:02:04 +02:00
|
|
|
val lazyTiles = p(BuildTiles) map { _(p) }
|
2016-10-25 04:01:32 +02:00
|
|
|
|
|
|
|
val debugLegacy = LazyModule(new TLLegacy()(outerMMIOParams))
|
2016-10-26 22:52:23 +02:00
|
|
|
val debug = LazyModule(new TLDebugModule())
|
|
|
|
debug.node :=
|
2016-10-25 04:01:32 +02:00
|
|
|
TLHintHandler()(
|
|
|
|
TLBuffer()(
|
|
|
|
TLFragmenter(p(XLen)/8, debugLegacy.tlDataBeats * debugLegacy.tlDataBytes)(
|
|
|
|
TLWidthWidget(debugLegacy.tlDataBytes)(debugLegacy.node))))
|
|
|
|
|
2016-10-26 22:52:23 +02:00
|
|
|
val plicLegacy = LazyModule(new TLLegacy()(outerMMIOParams))
|
|
|
|
val plic = LazyModule(new TLPLIC(c.plicKey))
|
|
|
|
plic.node :=
|
|
|
|
TLHintHandler()(
|
|
|
|
TLBuffer()(
|
|
|
|
TLFragmenter(p(XLen)/8, plicLegacy.tlDataBeats * plicLegacy.tlDataBytes)(
|
|
|
|
TLWidthWidget(plicLegacy.tlDataBytes)(plicLegacy.node))))
|
|
|
|
|
2016-10-25 04:01:32 +02:00
|
|
|
}
|
2016-09-22 01:54:35 +02:00
|
|
|
|
|
|
|
abstract class BaseCoreplexBundle(val c: CoreplexConfig)(implicit val p: Parameters) extends Bundle with HasCoreplexParameters {
|
|
|
|
val master = new Bundle {
|
2016-09-27 20:44:11 +02:00
|
|
|
val mem = Vec(c.nMemChannels, new ClientUncachedTileLinkIO()(outerMemParams))
|
2016-09-23 09:19:08 +02:00
|
|
|
val mmio = new ClientUncachedTileLinkIO()(outerMMIOParams)
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|
|
|
|
val slave = Vec(c.nSlaves, new ClientUncachedTileLinkIO()(innerParams)).flip
|
|
|
|
val interrupts = Vec(c.nExtInterrupts, Bool()).asInput
|
|
|
|
val debug = new DebugBusIO()(p).flip
|
|
|
|
val clint = Vec(c.nTiles, new CoreplexLocalInterrupts).asInput
|
|
|
|
val resetVector = UInt(INPUT, p(XLen))
|
2016-09-22 03:27:31 +02:00
|
|
|
val success = Bool(OUTPUT) // used for testing
|
2016-09-27 20:55:32 +02:00
|
|
|
|
|
|
|
override def cloneType = this.getClass.getConstructors.head.newInstance(c, p).asInstanceOf[this.type]
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract class BaseCoreplexModule[+L <: BaseCoreplex, +B <: BaseCoreplexBundle](
|
2016-10-25 23:28:52 +02:00
|
|
|
c: CoreplexConfig, l: L, b: B)(implicit val p: Parameters) extends LazyModuleImp(l) with HasCoreplexParameters {
|
2016-09-22 01:54:35 +02:00
|
|
|
val outer: L = l
|
|
|
|
val io: B = b
|
|
|
|
|
|
|
|
// Build a set of Tiles
|
2016-10-27 04:02:04 +02:00
|
|
|
val tiles = outer.lazyTiles.map(_.module)
|
2016-09-22 01:54:35 +02:00
|
|
|
val uncoreTileIOs = (tiles zipWithIndex) map { case (tile, i) => Wire(tile.io) }
|
|
|
|
|
|
|
|
val nCachedPorts = tiles.map(tile => tile.io.cached.size).reduce(_ + _)
|
|
|
|
val nUncachedPorts = tiles.map(tile => tile.io.uncached.size).reduce(_ + _)
|
|
|
|
val nBanks = c.nMemChannels * nBanksPerMemChannel
|
|
|
|
|
|
|
|
// Build an uncore backing the Tiles
|
|
|
|
buildUncore(p.alterPartial({
|
|
|
|
case HastiId => "TL"
|
|
|
|
case TLId => "L1toL2"
|
|
|
|
case NCachedTileLinkPorts => nCachedPorts
|
|
|
|
case NUncachedTileLinkPorts => nUncachedPorts
|
|
|
|
}))
|
|
|
|
|
|
|
|
def buildUncore(implicit p: Parameters) = {
|
|
|
|
// Create a simple L1toL2 NoC between the tiles and the banks of outer memory
|
|
|
|
// Cached ports are first in client list, making sharerToClientId just an indentity function
|
|
|
|
// addrToBank is sed to hash physical addresses (of cache blocks) to banks (and thereby memory channels)
|
|
|
|
def sharerToClientId(sharerId: UInt) = sharerId
|
|
|
|
def addrToBank(addr: UInt): UInt = if (nBanks == 0) UInt(0) else {
|
|
|
|
val isMemory = globalAddrMap.isInRegion("mem", addr << log2Up(p(CacheBlockBytes)))
|
|
|
|
Mux(isMemory, addr.extract(lsb + log2Ceil(nBanks) - 1, lsb), UInt(nBanks))
|
|
|
|
}
|
|
|
|
val l1tol2net = Module(new PortedTileLinkCrossbar(addrToBank, sharerToClientId))
|
|
|
|
|
|
|
|
// Create point(s) of coherence serialization
|
|
|
|
val managerEndpoints = List.tabulate(nBanks){id => p(BuildL2CoherenceManager)(id, p)}
|
|
|
|
managerEndpoints.flatMap(_.incoherent).foreach(_ := Bool(false))
|
|
|
|
|
|
|
|
val mmioManager = Module(new MMIOTileLinkManager()(p.alterPartial({
|
|
|
|
case TLId => "L1toL2"
|
|
|
|
case InnerTLId => "L1toL2"
|
|
|
|
case OuterTLId => "L2toMMIO"
|
|
|
|
})))
|
|
|
|
|
|
|
|
// Wire the tiles to the TileLink client ports of the L1toL2 network,
|
|
|
|
// and coherence manager(s) to the other side
|
|
|
|
l1tol2net.io.clients_cached <> uncoreTileIOs.map(_.cached).flatten
|
|
|
|
l1tol2net.io.clients_uncached <> uncoreTileIOs.map(_.uncached).flatten ++ io.slave
|
2016-10-26 22:27:35 +02:00
|
|
|
l1tol2net.io.managers <> managerEndpoints.map(_.innerTL) :+ mmioManager.io.inner // legacy goes here (not mmioManager)
|
2016-09-22 01:54:35 +02:00
|
|
|
|
2016-09-27 20:44:11 +02:00
|
|
|
val mem_ic = Module(new TileLinkMemoryInterconnect(nBanksPerMemChannel, c.nMemChannels)(outerMemParams))
|
2016-09-22 01:54:35 +02:00
|
|
|
|
|
|
|
val backendBuffering = TileLinkDepths(0,0,0,0,0)
|
|
|
|
for ((bank, icPort) <- managerEndpoints zip mem_ic.io.in) {
|
2016-09-23 19:06:09 +02:00
|
|
|
val enqueued = TileLinkEnqueuer(bank.outerTL, backendBuffering)
|
2016-09-27 20:33:20 +02:00
|
|
|
icPort <> TileLinkIOUnwrapper(enqueued)
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
io.master.mem <> mem_ic.io.out
|
|
|
|
|
2016-09-23 09:19:08 +02:00
|
|
|
buildMMIONetwork(TileLinkEnqueuer(mmioManager.io.outer, 1))(outerMMIOParams)
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def buildMMIONetwork(mmio: ClientUncachedTileLinkIO)(implicit p: Parameters) = {
|
|
|
|
val ioAddrMap = globalAddrMap.subMap("io")
|
|
|
|
|
2016-09-22 03:16:04 +02:00
|
|
|
val cBus = Module(new TileLinkRecursiveInterconnect(1, ioAddrMap))
|
|
|
|
cBus.io.in.head <> mmio
|
2016-09-22 01:54:35 +02:00
|
|
|
|
2016-10-26 22:52:23 +02:00
|
|
|
outer.plicLegacy.module.io.legacy <> cBus.port("cbus:plic")
|
2016-09-22 01:54:35 +02:00
|
|
|
for (i <- 0 until io.interrupts.size) {
|
|
|
|
val gateway = Module(new LevelGateway)
|
|
|
|
gateway.io.interrupt := io.interrupts(i)
|
2016-10-26 22:52:23 +02:00
|
|
|
outer.plic.module.io.devices(i) <> gateway.io.plic
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|
|
|
|
|
2016-10-25 04:01:32 +02:00
|
|
|
outer.debugLegacy.module.io.legacy <> cBus.port("cbus:debug")
|
2016-10-26 22:52:23 +02:00
|
|
|
outer.debug.module.io.db <> io.debug
|
2016-09-22 01:54:35 +02:00
|
|
|
|
|
|
|
// connect coreplex-internal interrupts to tiles
|
|
|
|
for ((tile, i) <- (uncoreTileIOs zipWithIndex)) {
|
2016-10-05 07:28:56 +02:00
|
|
|
tile.interrupts <> io.clint(i)
|
2016-10-26 22:52:23 +02:00
|
|
|
tile.interrupts.meip := outer.plic.module.io.harts(c.plicKey.context(i, 'M'))
|
|
|
|
tile.interrupts.seip.foreach(_ := outer.plic.module.io.harts(c.plicKey.context(i, 'S')))
|
|
|
|
tile.interrupts.debug := outer.debug.module.io.debugInterrupts(i)
|
2016-09-29 01:10:32 +02:00
|
|
|
tile.hartid := UInt(i)
|
2016-09-22 01:54:35 +02:00
|
|
|
tile.resetVector := io.resetVector
|
|
|
|
}
|
|
|
|
|
2016-09-22 03:16:04 +02:00
|
|
|
val tileSlavePorts = (0 until c.nTiles) map (i => s"cbus:dmem$i") filter (ioAddrMap contains _)
|
|
|
|
for ((t, m) <- (uncoreTileIOs.map(_.slave).flatten) zip (tileSlavePorts map (cBus port _)))
|
2016-09-22 01:54:35 +02:00
|
|
|
t <> m
|
|
|
|
|
2016-10-26 03:18:06 +02:00
|
|
|
io.master.mmio <> cBus.port("TL2")
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|
2016-09-22 03:27:31 +02:00
|
|
|
|
|
|
|
// Coreplex doesn't know when to stop running
|
|
|
|
io.success := Bool(false)
|
2016-09-22 01:54:35 +02:00
|
|
|
}
|