1
0
rocket-chip/src/main/scala/RocketChip.scala

326 lines
13 KiB
Scala
Raw Normal View History

2014-09-12 19:15:04 +02:00
// See LICENSE for license details.
2014-09-01 05:26:55 +02:00
package rocketchip
2012-10-09 22:05:56 +02:00
import Chisel._
import cde.{Parameters, Field}
import junctions._
2012-10-09 22:05:56 +02:00
import uncore._
import rocket._
import rocket.Util._
2012-10-09 22:05:56 +02:00
/** Top-level parameters of RocketChip, values set in e.g. PublicConfigs.scala */
/** 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]
/** Number of outstanding memory requests */
case object NOutstandingMemReqsPerChannel extends Field[Int]
/** Number of exteral MMIO ports */
case object NExtMMIOChannels extends Field[Int]
/** Whether to divide HTIF clock */
case object UseHtifClockDiv extends Field[Boolean]
/** Function for building some kind of coherence manager agent */
2015-11-22 01:11:22 +01:00
case object BuildL2CoherenceManager extends Field[(Int, Parameters) => CoherenceAgent]
/** Function for building some kind of tile connected to a reset signal */
2015-10-06 19:47:38 +02:00
case object BuildTiles extends Field[Seq[(Bool, Parameters) => Tile]]
2016-03-15 02:03:33 +01:00
/** A string describing on-chip devices, readable by target software */
case object ConfigString extends Field[Array[Byte]]
/** Number of L1 clients besides the CPU cores */
case object ExtraL1Clients extends Field[Int]
2016-05-10 09:27:31 +02:00
/** Number of external interrupt sources */
case object NExtInterrupts extends Field[Int]
/** Interrupt controller configuration */
case object PLICKey extends Field[PLICConfig]
2016-01-07 06:38:35 +01:00
case object UseStreamLoopback extends Field[Boolean]
case object StreamLoopbackSize extends Field[Int]
case object StreamLoopbackWidth extends Field[Int]
/** Utility trait for quick access to some relevant parameters */
trait HasTopLevelParameters {
implicit val p: Parameters
lazy val nTiles = p(NTiles)
lazy val nCachedTilePorts = p(TLKey("L1toL2")).nCachingClients
2015-11-18 03:21:52 +01:00
lazy val nUncachedTilePorts =
p(TLKey("L1toL2")).nCachelessClients - p(ExtraL1Clients)
lazy val htifW = p(HtifKey).width
2015-10-06 19:47:38 +02:00
lazy val csrAddrBits = 12
lazy val nMemChannels = p(NMemoryChannels)
lazy val nBanksPerMemChannel = p(NBanksPerMemoryChannel)
lazy val nBanks = nMemChannels*nBanksPerMemChannel
lazy val lsb = p(BankIdLSB)
lazy val nMemReqs = p(NOutstandingMemReqsPerChannel)
lazy val mifAddrBits = p(MIFAddrBits)
lazy val mifDataBeats = p(MIFDataBeats)
lazy val xLen = p(XLen)
lazy val nSCR = p(HtifKey).nSCR
lazy val scrAddrBits = log2Up(nSCR)
lazy val scrDataBits = 64
lazy val scrDataBytes = scrDataBits / 8
//require(lsb + log2Up(nBanks) < mifAddrBits)
}
class MemBackupCtrlIO extends Bundle {
val en = Bool(INPUT)
val in_valid = Bool(INPUT)
val out_ready = Bool(INPUT)
val out_valid = Bool(OUTPUT)
}
2012-10-09 22:05:56 +02:00
/** Top-level io for the chip */
2015-10-06 19:47:38 +02:00
class BasicTopIO(implicit val p: Parameters) extends ParameterizedBundle()(p)
with HasTopLevelParameters {
val host = new HostIO(htifW)
}
2012-10-09 22:05:56 +02:00
2015-10-06 19:47:38 +02:00
class TopIO(implicit p: Parameters) extends BasicTopIO()(p) {
2016-01-15 00:06:30 +01:00
val mem = Vec(nMemChannels, new NastiIO)
2016-05-10 09:27:31 +02:00
val interrupts = Vec(p(NExtInterrupts), Bool()).asInput
val mmio = Vec(p(NExtMMIOChannels), new NastiIO)
}
object TopUtils {
// Connect two Nasti interfaces with queues in-between
def connectNasti(outer: NastiIO, inner: NastiIO)(implicit p: Parameters) {
val mifDataBeats = p(MIFDataBeats)
outer.ar <> Queue(inner.ar)
outer.aw <> Queue(inner.aw)
outer.w <> Queue(inner.w, mifDataBeats)
inner.r <> Queue(outer.r, mifDataBeats)
inner.b <> Queue(outer.b)
}
2016-04-27 23:57:54 +02:00
def connectTilelinkNasti(nasti: NastiIO, tl: ClientUncachedTileLinkIO)(implicit p: Parameters) = {
val conv = Module(new NastiIOTileLinkIOConverter())
conv.io.tl <> tl
TopUtils.connectNasti(nasti, conv.io.nasti)
}
2016-05-01 05:59:36 +02:00
def makeBootROM()(implicit p: Parameters) = {
val rom = java.nio.ByteBuffer.allocate(32)
rom.order(java.nio.ByteOrder.LITTLE_ENDIAN)
// for now, have the reset vector jump straight to memory
val addrHashMap = p(GlobalAddrHashMap)
2016-05-01 05:59:36 +02:00
val resetToMemDist = addrHashMap("mem").start - p(ResetVector)
require(resetToMemDist == (resetToMemDist.toInt >> 12 << 12))
val configStringAddr = p(ResetVector).toInt + rom.capacity
rom.putInt(0x00000297 + resetToMemDist.toInt) // auipc t0, &mem - &here
rom.putInt(0x00028067) // jr t0
rom.putInt(0) // reserved
rom.putInt(configStringAddr) // pointer to config string
rom.putInt(0) // default trap vector
rom.putInt(0) // ...
rom.putInt(0) // ...
rom.putInt(0) // ...
rom.array() ++ p(ConfigString).toSeq
}
}
/** Top-level module for the chip */
//TODO: Remove this wrapper once multichannel DRAM controller is provided
class Top(topParams: Parameters) extends Module with HasTopLevelParameters {
implicit val p = topParams
val io = new TopIO
// Build an Uncore and a set of Tiles
val innerTLParams = p.alterPartial({case TLId => "L1toL2" })
2015-10-06 19:47:38 +02:00
val uncore = Module(new Uncore()(innerTLParams))
2016-05-03 22:55:59 +02:00
val tileList = uncore.io.prci zip p(BuildTiles) map { case(prci, tile) => tile(prci.reset, p) }
// Connect each tile to the HTIF
2016-05-03 22:55:59 +02:00
for ((prci, tile) <- uncore.io.prci zip tileList) {
2016-05-03 03:08:33 +02:00
tile.io.prci <> prci
}
// Connect the uncore to the tile memory ports, HostIO and MemIO
uncore.io.tiles_cached <> tileList.map(_.io.cached).flatten
uncore.io.tiles_uncached <> tileList.map(_.io.uncached).flatten
2015-08-04 03:54:56 +02:00
io.host <> uncore.io.host
2016-05-10 09:27:31 +02:00
uncore.io.interrupts <> io.interrupts
2016-04-29 01:15:31 +02:00
io.mmio <> uncore.io.mmio
io.mem <> uncore.io.mem
2012-10-09 22:05:56 +02:00
}
/** Wrapper around everything that isn't a Tile.
*
* Usually this is clocked and/or place-and-routed separately from the Tiles.
* Contains the Host-Target InterFace module (HTIF).
*/
class Uncore(implicit val p: Parameters) extends Module
with HasTopLevelParameters {
2012-10-09 22:05:56 +02:00
val io = new Bundle {
val host = new HostIO(htifW)
2016-01-15 00:06:30 +01:00
val mem = Vec(nMemChannels, new NastiIO)
val tiles_cached = Vec(nCachedTilePorts, new ClientTileLinkIO).flip
val tiles_uncached = Vec(nUncachedTilePorts, new ClientUncachedTileLinkIO).flip
2016-05-03 03:08:33 +02:00
val prci = Vec(nTiles, new PRCITileIO).asOutput
val mmio = Vec(p(NExtMMIOChannels), new NastiIO)
2016-05-10 09:27:31 +02:00
val interrupts = Vec(p(NExtInterrupts), Bool()).asInput
2013-04-23 02:38:13 +02:00
}
2015-10-06 19:47:38 +02:00
val htif = Module(new Htif(CSRs.mreset)) // One HTIF module per chip
val outmemsys = Module(new OuterMemorySystem) // NoC, LLC and SerDes
outmemsys.io.incoherent := htif.io.cpu.map(_.reset)
outmemsys.io.htif_uncached <> htif.io.mem
outmemsys.io.tiles_uncached <> io.tiles_uncached
outmemsys.io.tiles_cached <> io.tiles_cached
2016-04-27 23:57:54 +02:00
val addrMap = p(GlobalAddrMap)
val addrHashMap = p(GlobalAddrHashMap)
2016-04-27 23:57:54 +02:00
val scrFile = Module(new SCRFile("UNCORE_SCR", 0))
scrFile.io.smi <> htif.io.scr
// scrFile.io.scr <> (... your SCR connections ...)
2016-04-27 23:57:54 +02:00
buildMMIONetwork(p.alterPartial({case TLId => "MMIO_Outermost"}))
// Wire the htif to the memory port(s) and host interface
2015-08-04 03:54:56 +02:00
io.mem <> outmemsys.io.mem
if(p(UseHtifClockDiv)) {
2016-04-27 23:57:54 +02:00
VLSIUtils.padOutHTIFWithDividedClock(htif.io.host, scrFile.io.scr, io.host, htifW)
} else {
2016-04-27 23:57:54 +02:00
io.host <> htif.io.host
}
2016-05-03 22:55:59 +02:00
// Tie off HTIF CSR ports
htif.io.cpu.foreach { _.csr.resp.valid := Bool(false) }
2016-04-27 23:57:54 +02:00
def buildMMIONetwork(implicit p: Parameters) = {
2016-04-29 01:15:31 +02:00
val (ioBase, ioAddrMap) = addrHashMap.subMap("io")
val ioAddrHashMap = new AddrHashMap(ioAddrMap, ioBase)
2016-04-27 23:57:54 +02:00
val mmioNarrower = Module(new TileLinkIONarrower("L2toMMIO", "MMIO_Outermost"))
2016-04-29 01:15:31 +02:00
val mmioNetwork = Module(new TileLinkRecursiveInterconnect(1, ioAddrMap, ioBase))
2016-04-27 23:57:54 +02:00
mmioNarrower.io.in <> outmemsys.io.mmio
mmioNetwork.io.in.head <> mmioNarrower.io.out
val rtc = Module(new RTC(p(NTiles)))
2016-04-29 01:15:31 +02:00
val rtcAddr = ioAddrHashMap("int:rtc")
require(rtc.size <= rtcAddr.region.size)
rtc.io.tl <> mmioNetwork.io.out(rtcAddr.port)
2016-05-03 03:08:33 +02:00
2016-05-10 09:27:31 +02:00
val plic = Module(new PLIC(p(PLICKey)))
val plicAddr = ioAddrHashMap("int:plic")
plic.io.tl <> mmioNetwork.io.out(plicAddr.port)
for (i <- 0 until io.interrupts.size) {
val gateway = Module(new LevelGateway)
gateway.io.interrupt := io.interrupts(i)
plic.io.devices(i) <> gateway.io.plic
}
2016-05-03 03:08:33 +02:00
for (i <- 0 until nTiles) {
val prci = Module(new PRCI)
val prciAddr = ioAddrHashMap(s"int:prci$i")
prci.io.tl <> mmioNetwork.io.out(prciAddr.port)
prci.io.id := UInt(i)
prci.io.interrupts.mtip := rtc.io.irqs(i)
2016-05-10 09:27:31 +02:00
prci.io.interrupts.meip := plic.io.harts(plic.cfg.context(i, 'M'))
if (p(UseVM))
prci.io.interrupts.seip := plic.io.harts(plic.cfg.context(i, 'S'))
2016-05-03 03:08:33 +02:00
prci.io.interrupts.debug := Bool(false)
io.prci(i) := prci.io.tile
io.prci(i).reset := Reg(next=Reg(next=htif.io.cpu(i).reset)) // TODO
}
2016-04-27 23:57:54 +02:00
2016-05-01 05:59:36 +02:00
val bootROM = Module(new ROMSlave(TopUtils.makeBootROM()))
val bootROMAddr = ioAddrHashMap("int:bootrom")
bootROM.io <> mmioNetwork.io.out(bootROMAddr.port)
2016-04-29 01:15:31 +02:00
val debugModule = Module(new ROMSlave(Seq())) // TODO
val debugModuleAddr = ioAddrHashMap("int:debug")
debugModule.io <> mmioNetwork.io.out(debugModuleAddr.port)
val mmioEndpoint = p(NExtMMIOChannels) match {
case 0 => Module(new NastiErrorSlave).io
case 1 => io.mmio(0)
// The memory map presently has only one external I/O region
}
TopUtils.connectTilelinkNasti(mmioEndpoint, mmioNetwork.io.out(ioAddrHashMap("ext").port))
}
2012-10-09 22:05:56 +02:00
}
/** The whole outer memory hierarchy, including a NoC, some kind of coherence
* manager agent, and a converter from TileLink to MemIO.
*/
2015-10-06 19:47:38 +02:00
class OuterMemorySystem(implicit val p: Parameters) extends Module with HasTopLevelParameters {
val io = new Bundle {
val tiles_cached = Vec(nCachedTilePorts, new ClientTileLinkIO).flip
val tiles_uncached = Vec(nUncachedTilePorts, new ClientUncachedTileLinkIO).flip
val htif_uncached = (new ClientUncachedTileLinkIO).flip
2016-01-15 00:06:30 +01:00
val incoherent = Vec(nTiles, Bool()).asInput
val mem = Vec(nMemChannels, new NastiIO)
2016-04-27 23:57:54 +02:00
val mmio = new ClientUncachedTileLinkIO()(p.alterPartial({case TLId => "L2toMMIO"}))
2012-10-09 22:05:56 +02:00
}
val addrHashMap = p(GlobalAddrHashMap)
// Create a simple L1toL2 NoC between the tiles+htif 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
2016-04-27 23:57:54 +02:00
def addrToBank(addr: UInt): UInt = {
val isMemory = addrHashMap.isInRegion("mem", addr << log2Up(p(CacheBlockBytes)))
Mux(isMemory,
if (nBanks > 1) addr(lsb + log2Up(nBanks) - 1, lsb) else UInt(0),
UInt(nBanks))
}
val preBuffering = TileLinkDepths(2,2,2,2,2)
val l1tol2net = Module(new PortedTileLinkCrossbar(addrToBank, sharerToClientId, preBuffering))
// Create point(s) of coherence serialization
val managerEndpoints = List.tabulate(nBanks){id => p(BuildL2CoherenceManager)(id, p)}
managerEndpoints.foreach { _.incoherent := io.incoherent }
val mmioManager = Module(new MMIOTileLinkManager()(p.alterPartial({
case TLId => "L1toL2"
case InnerTLId => "L1toL2"
2016-03-31 00:57:13 +02:00
case OuterTLId => "L2toMMIO"
})))
2016-04-27 23:57:54 +02:00
io.mmio <> mmioManager.io.outer
// Wire the tiles and htif to the TileLink client ports of the L1toL2 network,
// and coherence manager(s) to the other side
l1tol2net.io.clients_cached <> io.tiles_cached
2016-04-27 23:57:54 +02:00
l1tol2net.io.clients_uncached <> io.tiles_uncached ++ Seq(io.htif_uncached)
l1tol2net.io.managers <> managerEndpoints.map(_.innerTL) :+ mmioManager.io.inner
// Create a converter between TileLinkIO and MemIO for each channel
val outerTLParams = p.alterPartial({ case TLId => "L2toMC" })
2015-10-21 06:10:54 +02:00
val outermostTLParams = p.alterPartial({case TLId => "Outermost"})
val backendBuffering = TileLinkDepths(0,0,0,0,0)
2016-03-15 02:03:33 +01:00
// TODO: the code to print this stuff should live somewhere else
println("Generated Address Map")
2016-04-29 01:15:31 +02:00
for ((name, base, region) <- addrHashMap.sortedEntries) {
println(f"\t$name%s $base%x - ${base + region.size - 1}%x")
}
2016-03-15 02:03:33 +01:00
println("Generated Configuration String")
println(new String(p(ConfigString)))
2016-04-29 01:15:31 +02:00
val mem_ic = Module(new TileLinkMemoryInterconnect(nBanksPerMemChannel, nMemChannels)(outermostTLParams))
for ((bank, icPort) <- managerEndpoints zip mem_ic.io.in) {
2015-10-06 19:47:38 +02:00
val unwrap = Module(new ClientTileLinkIOUnwrapper()(outerTLParams))
2015-10-14 21:16:22 +02:00
val narrow = Module(new TileLinkIONarrower("L2toMC", "Outermost"))
unwrap.io.in <> ClientTileLinkEnqueuer(bank.outerTL, backendBuffering)(outerTLParams)
narrow.io.in <> unwrap.io.out
2016-04-29 01:15:31 +02:00
icPort <> narrow.io.out
}
for ((nasti, tl) <- io.mem zip mem_ic.io.out) {
2016-04-27 23:57:54 +02:00
TopUtils.connectTilelinkNasti(nasti, tl)(outermostTLParams)
// Memory cache type should be normal non-cacheable bufferable
// TODO why is this happening here? Would 0000 (device) be OK instead?
nasti.ar.bits.cache := UInt("b0011")
nasti.aw.bits.cache := UInt("b0011")
}
2012-10-09 22:05:56 +02:00
}