2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
2016-08-27 00:48:48 +02:00
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.tilelink
|
2016-08-27 00:48:48 +02:00
|
|
|
|
|
|
|
import Chisel._
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.config.Parameters
|
|
|
|
import freechips.rocketchip.diplomacy._
|
|
|
|
import freechips.rocketchip.regmapper._
|
|
|
|
import freechips.rocketchip.util.HeterogeneousBag
|
2016-09-23 00:36:13 +02:00
|
|
|
import scala.math.{min,max}
|
2016-08-27 00:48:48 +02:00
|
|
|
|
2017-09-12 08:33:44 +02:00
|
|
|
case class TLRegisterNode(
|
2017-03-20 22:48:51 +01:00
|
|
|
address: Seq[AddressSet],
|
2017-03-01 08:12:36 +01:00
|
|
|
device: Device,
|
2017-06-28 22:01:40 +02:00
|
|
|
deviceKey: String = "reg/control",
|
2017-03-01 08:12:36 +01:00
|
|
|
concurrency: Int = 0,
|
|
|
|
beatBytes: Int = 4,
|
|
|
|
undefZero: Boolean = true,
|
2017-09-12 08:33:44 +02:00
|
|
|
executable: Boolean = false)(
|
|
|
|
implicit valName: ValName)
|
|
|
|
extends SinkNode(TLImp)(Seq(TLManagerPortParameters(
|
2016-09-28 21:56:03 +02:00
|
|
|
Seq(TLManagerParameters(
|
2017-03-20 22:48:51 +01:00
|
|
|
address = address,
|
2017-03-01 08:12:36 +01:00
|
|
|
resources = Seq(Resource(device, deviceKey)),
|
2016-10-28 03:38:14 +02:00
|
|
|
executable = executable,
|
2016-09-28 21:56:03 +02:00
|
|
|
supportsGet = TransferSizes(1, beatBytes),
|
|
|
|
supportsPutPartial = TransferSizes(1, beatBytes),
|
|
|
|
supportsPutFull = TransferSizes(1, beatBytes),
|
|
|
|
fifoId = Some(0))), // requests are handled in order
|
|
|
|
beatBytes = beatBytes,
|
2017-01-30 00:17:52 +01:00
|
|
|
minLatency = min(concurrency, 1)))) // the Queue adds at most one cycle
|
2016-08-27 00:48:48 +02:00
|
|
|
{
|
2017-03-20 22:48:51 +01:00
|
|
|
val size = 1 << log2Ceil(1 + address.map(_.max).max - address.map(_.base).min)
|
|
|
|
require (size >= beatBytes)
|
|
|
|
address.foreach { case a =>
|
|
|
|
require (a.widen(size-1).base == address.head.widen(size-1).base,
|
|
|
|
s"TLRegisterNode addresses (${address}) must be aligned to its size ${size}")
|
|
|
|
}
|
2016-08-27 00:48:48 +02:00
|
|
|
|
|
|
|
// Calling this method causes the matching TL2 bundle to be
|
|
|
|
// configured to route all requests to the listed RegFields.
|
|
|
|
def regmap(mapping: RegField.Map*) = {
|
2017-09-14 03:06:03 +02:00
|
|
|
val (bundleIn, edge) = this.in(0)
|
|
|
|
val a = bundleIn.a
|
|
|
|
val d = bundleIn.d
|
2016-09-07 08:46:44 +02:00
|
|
|
|
|
|
|
// Please forgive me ...
|
|
|
|
val baseEnd = 0
|
|
|
|
val (sizeEnd, sizeOff) = (edge.bundle.sizeBits + baseEnd, baseEnd)
|
|
|
|
val (sourceEnd, sourceOff) = (edge.bundle.sourceBits + sizeEnd, sizeEnd)
|
|
|
|
|
2017-07-27 01:01:21 +02:00
|
|
|
val params = RegMapperParams(log2Up(size/beatBytes), beatBytes, sourceEnd)
|
2016-08-31 22:37:20 +02:00
|
|
|
val in = Wire(Decoupled(new RegMapperInput(params)))
|
2016-08-30 00:33:10 +02:00
|
|
|
in.bits.read := a.bits.opcode === TLMessages.Get
|
2016-10-14 23:09:39 +02:00
|
|
|
in.bits.index := edge.addr_hi(a.bits)
|
2016-08-30 00:33:10 +02:00
|
|
|
in.bits.data := a.bits.data
|
2016-08-31 00:06:37 +02:00
|
|
|
in.bits.mask := a.bits.mask
|
2017-07-27 01:01:21 +02:00
|
|
|
in.bits.extra := Cat(a.bits.source, a.bits.size)
|
2016-08-30 00:33:10 +02:00
|
|
|
|
2016-10-13 03:10:07 +02:00
|
|
|
// Invoke the register map builder
|
|
|
|
val out = RegMapper(beatBytes, concurrency, undefZero, in, mapping:_*)
|
2016-08-27 00:48:48 +02:00
|
|
|
|
2016-08-30 00:33:10 +02:00
|
|
|
// No flow control needed
|
|
|
|
in.valid := a.valid
|
|
|
|
a.ready := in.ready
|
|
|
|
d.valid := out.valid
|
|
|
|
out.ready := d.ready
|
2016-08-27 00:48:48 +02:00
|
|
|
|
2017-07-27 01:01:21 +02:00
|
|
|
// We must restore the size to enable width adapters to work
|
2016-09-07 08:46:44 +02:00
|
|
|
d.bits := edge.AccessAck(
|
|
|
|
toSource = out.bits.extra(sourceEnd-1, sourceOff),
|
|
|
|
lgSize = out.bits.extra(sizeEnd-1, sizeOff))
|
|
|
|
|
2016-08-27 00:48:48 +02:00
|
|
|
// avoid a Mux on the data bus by manually overriding two fields
|
2016-08-30 00:33:10 +02:00
|
|
|
d.bits.data := out.bits.data
|
|
|
|
d.bits.opcode := Mux(out.bits.read, TLMessages.AccessAckData, TLMessages.AccessAck)
|
2016-09-05 01:47:18 +02:00
|
|
|
|
|
|
|
// Tie off unused channels
|
2017-09-14 03:06:03 +02:00
|
|
|
bundleIn.b.valid := Bool(false)
|
|
|
|
bundleIn.c.ready := Bool(true)
|
|
|
|
bundleIn.e.ready := Bool(true)
|
2016-08-27 00:48:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// register mapped device from a totally abstract register mapped device.
|
|
|
|
// See GPIO.scala in this directory for an example
|
|
|
|
|
2017-03-01 08:12:36 +01:00
|
|
|
abstract class TLRegisterRouterBase(devname: String, devcompat: Seq[String], val address: AddressSet, interrupts: Int, concurrency: Int, beatBytes: Int, undefZero: Boolean, executable: Boolean)(implicit p: Parameters) extends LazyModule
|
2016-08-27 00:48:48 +02:00
|
|
|
{
|
2017-03-01 08:12:36 +01:00
|
|
|
val device = new SimpleDevice(devname, devcompat)
|
2017-06-28 22:01:40 +02:00
|
|
|
val node = TLRegisterNode(Seq(address), device, "reg/control", concurrency, beatBytes, undefZero, executable)
|
2017-03-02 03:23:28 +01:00
|
|
|
val intnode = IntSourceNode(IntSourcePortSimple(num = interrupts, resources = Seq(Resource(device, "int"))))
|
2016-08-27 00:48:48 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
case class TLRegBundleArg()(implicit val p: Parameters)
|
2016-08-27 00:48:48 +02:00
|
|
|
|
2016-09-09 00:17:30 +02:00
|
|
|
class TLRegBundleBase(arg: TLRegBundleArg) extends Bundle
|
|
|
|
{
|
2016-12-02 02:46:52 +01:00
|
|
|
implicit val p = arg.p
|
2016-09-09 00:17:30 +02:00
|
|
|
}
|
|
|
|
|
2016-12-02 02:46:52 +01:00
|
|
|
class TLRegBundle[P](val params: P, arg: TLRegBundleArg)(implicit p: Parameters) extends TLRegBundleBase(arg)
|
2016-09-09 00:17:30 +02:00
|
|
|
|
|
|
|
class TLRegModule[P, B <: TLRegBundleBase](val params: P, bundleBuilder: => B, router: TLRegisterRouterBase)
|
2016-08-31 19:25:46 +02:00
|
|
|
extends LazyModuleImp(router) with HasRegMap
|
2016-08-27 00:48:48 +02:00
|
|
|
{
|
2017-09-14 03:06:03 +02:00
|
|
|
val io = IO(bundleBuilder)
|
|
|
|
val interrupts = if (router.intnode.in.isEmpty) Vec(0, Bool()) else router.intnode.in(0)._1
|
2016-10-29 06:20:49 +02:00
|
|
|
val address = router.address
|
2016-08-31 19:25:46 +02:00
|
|
|
def regmap(mapping: RegField.Map*) = router.node.regmap(mapping:_*)
|
2016-08-27 00:48:48 +02:00
|
|
|
}
|
|
|
|
|
2017-03-01 08:12:36 +01:00
|
|
|
class TLRegisterRouter[B <: TLRegBundleBase, M <: LazyModuleImp](
|
|
|
|
val base: BigInt,
|
|
|
|
val devname: String,
|
|
|
|
val devcompat: Seq[String],
|
|
|
|
val interrupts: Int = 0,
|
|
|
|
val size: BigInt = 4096,
|
|
|
|
val concurrency: Int = 0,
|
|
|
|
val beatBytes: Int = 4,
|
|
|
|
val undefZero: Boolean = true,
|
|
|
|
val executable: Boolean = false)
|
2016-09-09 00:17:30 +02:00
|
|
|
(bundleBuilder: TLRegBundleArg => B)
|
2016-12-02 02:46:52 +01:00
|
|
|
(moduleBuilder: (=> B, TLRegisterRouterBase) => M)(implicit p: Parameters)
|
2017-03-01 08:12:36 +01:00
|
|
|
extends TLRegisterRouterBase(devname, devcompat, AddressSet(base, size-1), interrupts, concurrency, beatBytes, undefZero, executable)
|
2016-08-27 00:48:48 +02:00
|
|
|
{
|
|
|
|
require (isPow2(size))
|
2016-09-12 00:43:04 +02:00
|
|
|
// require (size >= 4096) ... not absolutely required, but highly recommended
|
2016-08-27 00:48:48 +02:00
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
lazy val module = moduleBuilder(bundleBuilder(TLRegBundleArg()), this)
|
2016-08-27 00:48:48 +02:00
|
|
|
}
|
2017-09-15 23:44:07 +02:00
|
|
|
|
|
|
|
// !!! eliminate third trait
|