Skip to content

Commit

Permalink
Move xLen/pgLevels to tile-local parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryz123 committed Jun 30, 2024
1 parent f388fb1 commit 53bf263
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/groundtest/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import freechips.rocketchip.devices.debug.{DebugModuleKey}
import freechips.rocketchip.subsystem._
import freechips.rocketchip.system.BaseConfig
import freechips.rocketchip.rocket.{DCacheParams}
import freechips.rocketchip.tile.{XLen}

/** Actual testing target Configs */

Expand Down Expand Up @@ -39,7 +38,8 @@ class WithTraceGen(
n: Int = 2,
overrideMemOffset: Option[BigInt] = None)(
params: Seq[DCacheParams] = List.fill(n){ DCacheParams(nSets = 16, nWays = 1) },
nReqs: Int = 8192
nReqs: Int = 8192,
wordBits: Int = 32
) extends Config((site, here, up) => {
case TilesLocated(InSubsystem) => {
val prev = up(TilesLocated(InSubsystem), site)
Expand All @@ -50,7 +50,7 @@ class WithTraceGen(
tileParams = TraceGenParams(
tileId = i + idOffset,
dcache = Some(dcp),
wordBits = site(XLen),
wordBits = wordBits,
addrBits = 32,
addrBag = {
val nSets = dcp.nSets
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/groundtest/TraceGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ import freechips.rocketchip.prci.{ClockSinkParameters, ClockCrossingType}
// to repeatedly recompile with a different address bag.)

case class TraceGenParams(
wordBits: Int, // p(XLen)
addrBits: Int, // p(PAddrBits)
addrBag: List[BigInt], // p(AddressBag)
wordBits: Int,
addrBits: Int,
addrBag: List[BigInt],
maxRequests: Int,
memStart: BigInt, //p(ExtMem).base
memStart: BigInt,
numGens: Int,
dcache: Option[DCacheParams] = Some(DCacheParams()),
tileId: Int = 0
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/rocket/RVC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ class RVCExpander(useAddiForMv: Boolean = false)(implicit val p: Parameters) ext

if (usingCompressed) {
io.rvc := io.in(1,0) =/= 3.U
val decoder = new RVCDecoder(io.in, p(XLen), fLen, useAddiForMv)
val decoder = new RVCDecoder(io.in, xLen, fLen, useAddiForMv)
io.out := decoder.decode
io.ill := decoder.ill
} else {
io.rvc := false.B
io.out := new RVCDecoder(io.in, p(XLen), fLen, useAddiForMv).passthrough
io.out := new RVCDecoder(io.in, xLen, fLen, useAddiForMv).passthrough
io.ill := false.B // only used for RVC
}
}
2 changes: 2 additions & 0 deletions src/main/scala/rocket/RocketCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import freechips.rocketchip.util.property
import scala.collection.mutable.ArrayBuffer

case class RocketCoreParams(
xLen: Int = 64,
pgLevels: Int = 32, // sv39 default
bootFreqHz: BigInt = 0,
useVM: Boolean = true,
useUser: Boolean = false,
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/rocket/TLB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import freechips.rocketchip.util.UIntIsOneOf
import freechips.rocketchip.util.SeqToAugmentedSeq
import freechips.rocketchip.util.SeqBoolBitwiseOps

case object PgLevels extends Field[Int](2)
case object ASIdBits extends Field[Int](0)
case object VMIdBits extends Field[Int](0)

Expand Down
24 changes: 13 additions & 11 deletions src/main/scala/subsystem/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,44 @@ import freechips.rocketchip.diplomacy.{
import freechips.rocketchip.resources.{
DTSModel, DTSCompat, DTSTimebase, BigIntHexContext
}
import freechips.rocketchip.rocket.{PgLevels}
import freechips.rocketchip.tile.{
XLen, MaxHartIdBits, RocketTileParams
MaxHartIdBits, RocketTileParams
}
import freechips.rocketchip.util.ClockGateModelFile
import scala.reflect.ClassTag

case object MaxXLen extends Field[Int]

class BaseSubsystemConfig extends Config ((site, here, up) => {
// Tile parameters
case PgLevels => if (site(XLen) == 64) 3 /* Sv39 */ else 2 /* Sv32 */
case XLen => 64 // Applies to all cores
case MaxXLen => (site(PossibleTileLocations).flatMap(loc => site(TilesLocated(loc)))
.map(_.tileParams.core.xLen) :+ 32).max
case MaxHartIdBits => log2Up((site(PossibleTileLocations).flatMap(loc => site(TilesLocated(loc)))
.map(_.tileParams.tileId) :+ 0).max+1)
// Interconnect parameters
case SystemBusKey => SystemBusParams(
beatBytes = site(XLen)/8,
beatBytes = site(MaxXLen)/8,
blockBytes = site(CacheBlockBytes))
case ControlBusKey => PeripheryBusParams(
beatBytes = site(XLen)/8,
beatBytes = site(MaxXLen)/8,
blockBytes = site(CacheBlockBytes),
dtsFrequency = Some(100000000), // Default to 100 MHz cbus clock
errorDevice = Some(BuiltInErrorDeviceParams(
errorParams = DevNullParams(List(AddressSet(0x3000, 0xfff)), maxAtomic=site(XLen)/8, maxTransfer=4096))))
errorParams = DevNullParams(List(AddressSet(0x3000, 0xfff)), maxAtomic=site(MaxXLen)/8, maxTransfer=4096))))
case PeripheryBusKey => PeripheryBusParams(
beatBytes = site(XLen)/8,
beatBytes = site(MaxXLen)/8,
blockBytes = site(CacheBlockBytes),
dtsFrequency = Some(100000000)) // Default to 100 MHz pbus clock
case MemoryBusKey => MemoryBusParams(
beatBytes = site(XLen)/8,
beatBytes = site(MaxXLen)/8,
blockBytes = site(CacheBlockBytes))
case FrontBusKey => FrontBusParams(
beatBytes = site(XLen)/8,
beatBytes = site(MaxXLen)/8,
blockBytes = site(CacheBlockBytes))
// Additional device Parameters
case BootROMLocated(InSubsystem) => Some(BootROMParams(contentFileName = "./bootrom/bootrom.img"))
case HasTilesExternalResetVectorKey => false
case DebugModuleKey => Some(DefaultDebugModuleParams(site(XLen)))
case DebugModuleKey => Some(DefaultDebugModuleParams(site(MaxXLen)))
case CLINTKey => Some(CLINTParams())
case PLICKey => Some(PLICParams())
case TilesLocated(InSubsystem) => Nil
Expand Down
14 changes: 7 additions & 7 deletions src/main/scala/subsystem/RocketConfigs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import org.chipsalliance.cde.config._
import org.chipsalliance.diplomacy.lazymodule._

import freechips.rocketchip.prci.{SynchronousCrossing, AsynchronousCrossing, RationalCrossing, ClockCrossingType}
import freechips.rocketchip.rocket.{PgLevels, RocketCoreParams, MulDivParams, DCacheParams, ICacheParams, BTBParams, DebugROBParams}
import freechips.rocketchip.rocket.{RocketCoreParams, MulDivParams, DCacheParams, ICacheParams, BTBParams, DebugROBParams}
import freechips.rocketchip.tile.{
XLen, MaxHartIdBits, RocketTileParams, BuildRoCC, AccumulatorExample, OpcodeSet, TranslatorExample, CharacterCountExample, BlackBoxExample
MaxHartIdBits, RocketTileParams, BuildRoCC, AccumulatorExample, OpcodeSet, TranslatorExample, CharacterCountExample, BlackBoxExample
}

class WithNBigCores(
Expand Down Expand Up @@ -49,8 +49,6 @@ class WithNBigCores(
))
}



class WithNMedCores(
n: Int,
crossing: RocketCrossingParams = RocketCrossingParams(),
Expand Down Expand Up @@ -118,10 +116,11 @@ class WithNSmallCores(
})

class With1TinyCore extends Config((site, here, up) => {
case XLen => 32
case TilesLocated(InSubsystem) => {
val tiny = RocketTileParams(
core = RocketCoreParams(
xLen = 32,
pgLevels = 2, // sv32
useVM = false,
fpu = None,
mulDiv = Some(MulDivParams(mulUnroll = 8))),
Expand Down Expand Up @@ -326,10 +325,11 @@ class WithRocketCacheRowBits(n: Int) extends Config((site, here, up) => {
})

class WithRV32 extends Config((site, here, up) => {
case XLen => 32
case TilesLocated(location) => up(TilesLocated(location), site) map {
case tp: RocketTileAttachParams => tp.copy(tileParams = tp.tileParams.copy(
core = tp.tileParams.core.copy(
xLen = 32,
pgLevels = 2, // sv32
fpu = tp.tileParams.core.fpu.map(_.copy(fLen = 32)),
mulDiv = Some(MulDivParams(mulUnroll = 8)))))
case t => t
Expand Down Expand Up @@ -411,7 +411,7 @@ class WithFastMulDiv extends Config((site, here, up) => {
case TilesLocated(location) => up(TilesLocated(location), site) map {
case tp: RocketTileAttachParams => tp.copy(tileParams = tp.tileParams.copy(
core = tp.tileParams.core.copy(mulDiv = Some(
MulDivParams(mulUnroll = 8, mulEarlyOut = (site(XLen) > 32), divEarlyOut = true)))))
MulDivParams(mulUnroll = 8, mulEarlyOut = tp.tileParams.core.xLen > 32, divEarlyOut = true)))))
case t => t
}
})
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/tile/BaseTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.chipsalliance.diplomacy.bundlebridge._

import freechips.rocketchip.resources.{PropertyMap, PropertyOption, ResourceReference, DTSTimebase}
import freechips.rocketchip.interrupts.{IntInwardNode, IntOutwardNode}
import freechips.rocketchip.rocket.{ICacheParams, DCacheParams, BTBParams, PgLevels, ASIdBits, VMIdBits, TraceAux, BPWatch}
import freechips.rocketchip.rocket.{ICacheParams, DCacheParams, BTBParams, ASIdBits, VMIdBits, TraceAux, BPWatch}
import freechips.rocketchip.subsystem.{
HierarchicalElementParams, InstantiableHierarchicalElementParams, HierarchicalElementCrossingParamsLike,
CacheBlockBytes, SystemBusKey, BaseHierarchicalElement, InsertTimingClosureRegistersOnHartIds, BaseHierarchicalElementModuleImp
Expand Down Expand Up @@ -61,12 +61,12 @@ trait HasNonDiplomaticTileParameters {
def usingPTW: Boolean = usingVM
def usingDataScratchpad: Boolean = tileParams.dcache.flatMap(_.scratch).isDefined

def xLen: Int = p(XLen)
def xLen: Int = tileParams.core.xLen
def xBytes: Int = xLen / 8
def iLen: Int = 32
def pgIdxBits: Int = 12
def pgLevelBits: Int = 10 - log2Ceil(xLen / 32)
def pgLevels: Int = p(PgLevels)
def pgLevels: Int = tileParams.core.pgLevels
def maxSVAddrBits: Int = pgIdxBits + pgLevels * pgLevelBits
def maxHypervisorExtraAddrBits: Int = 2
def hypervisorExtraAddrBits: Int = {
Expand Down Expand Up @@ -128,7 +128,7 @@ trait HasNonDiplomaticTileParameters {
tileParams.core.customIsaExt.map(Seq(_))
).flatten
val multiLetterString = multiLetterExt.mkString("_")
s"rv${p(XLen)}$ie$m$a$f$d$c$v$h$multiLetterString"
s"rv$xLen$ie$m$a$f$d$c$v$h$multiLetterString"
}

def tileProperties: PropertyMap = {
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/tile/BusErrorUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class L1BusErrors(implicit p: Parameters) extends CoreBundle()(p) with BusErrors

case class BusErrorUnitParams(addr: BigInt, size: Int = 4096)

class BusErrorUnit[T <: BusErrors](t: => T, params: BusErrorUnitParams)(implicit p: Parameters) extends LazyModule {
class BusErrorUnit[T <: BusErrors](t: => T, params: BusErrorUnitParams, beatBytes: Int)(implicit p: Parameters) extends LazyModule {
val regWidth = 64
val device = new SimpleDevice("bus-error-unit", Seq("sifive,buserror0"))
val intNode = IntSourceNode(IntSourcePortSimple(resources = device.int))
val node = TLRegisterNode(
address = Seq(AddressSet(params.addr, params.size-1)),
device = device,
beatBytes = p(XLen)/8)
beatBytes = beatBytes)

lazy val module = new Impl
class Impl extends LazyModuleImp(this) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/tile/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.chipsalliance.cde.config._
import freechips.rocketchip.rocket._
import freechips.rocketchip.util._

case object XLen extends Field[Int]
case object MaxHartIdBits extends Field[Int]

// These parameters can be varied per-core
Expand Down Expand Up @@ -51,6 +50,8 @@ trait CoreParams {
val mtvecInit: Option[BigInt]
val mtvecWritable: Boolean
val traceHasWdata: Boolean
val xLen: Int
val pgLevels: Int
def traceCustom: Option[Data] = None
def customIsaExt: Option[String] = None
def customCSRs(implicit p: Parameters): CustomCSRs = new CustomCSRs
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/tile/RocketTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RocketTile private(
dtim_adapter.foreach(lm => connectTLSlave(lm.node, lm.node.portParams.head.beatBytes))

val bus_error_unit = rocketParams.beuAddr map { a =>
val beu = LazyModule(new BusErrorUnit(new L1BusErrors, BusErrorUnitParams(a)))
val beu = LazyModule(new BusErrorUnit(new L1BusErrors, BusErrorUnitParams(a), xLen/8))
intOutwardNode.get := beu.intNode
connectTLSlave(beu.node, xBytes)
beu
Expand Down

0 comments on commit 53bf263

Please sign in to comment.