2016-12-15 23:16:01 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.tilelink
|
2016-12-15 23:16:01 +01:00
|
|
|
|
|
|
|
import Chisel._
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.config.Parameters
|
|
|
|
import freechips.rocketchip.diplomacy._
|
|
|
|
import freechips.rocketchip.amba.apb._
|
2016-12-15 23:16:01 +01:00
|
|
|
import scala.math.{min, max}
|
|
|
|
import APBParameters._
|
|
|
|
|
2017-09-12 08:33:44 +02:00
|
|
|
case class TLToAPBNode()(implicit valName: ValName) extends MixedAdapterNode(TLImp, APBImp)(
|
2017-01-30 00:17:52 +01:00
|
|
|
dFn = { case TLClientPortParameters(clients, unsafeAtomics, minLatency) =>
|
2017-06-03 00:09:35 +02:00
|
|
|
val masters = clients.map { case c => APBMasterParameters(name = c.name, nodePath = c.nodePath) }
|
2017-01-30 00:17:52 +01:00
|
|
|
APBMasterPortParameters(masters)
|
2016-12-15 23:16:01 +01:00
|
|
|
},
|
2017-01-30 00:17:52 +01:00
|
|
|
uFn = { case APBSlavePortParameters(slaves, beatBytes) =>
|
2016-12-15 23:16:01 +01:00
|
|
|
val managers = slaves.map { case s =>
|
|
|
|
TLManagerParameters(
|
|
|
|
address = s.address,
|
2017-03-01 09:03:01 +01:00
|
|
|
resources = s.resources,
|
2016-12-15 23:16:01 +01:00
|
|
|
regionType = s.regionType,
|
|
|
|
executable = s.executable,
|
|
|
|
nodePath = s.nodePath,
|
|
|
|
supportsGet = if (s.supportsRead) TransferSizes(1, beatBytes) else TransferSizes.none,
|
|
|
|
supportsPutPartial = if (s.supportsWrite) TransferSizes(1, beatBytes) else TransferSizes.none,
|
|
|
|
supportsPutFull = if (s.supportsWrite) TransferSizes(1, beatBytes) else TransferSizes.none,
|
|
|
|
fifoId = Some(0)) // a common FIFO domain
|
|
|
|
}
|
2017-01-30 00:17:52 +01:00
|
|
|
TLManagerPortParameters(managers, beatBytes, 1, 0)
|
|
|
|
})
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-03-16 23:34:28 +01:00
|
|
|
// The input side has either a flow queue (aFlow=true) or a pipe queue (aFlow=false)
|
|
|
|
// The output side always has a flow queue
|
|
|
|
class TLToAPB(val aFlow: Boolean = true)(implicit p: Parameters) extends LazyModule
|
2016-12-15 23:16:01 +01:00
|
|
|
{
|
|
|
|
val node = TLToAPBNode()
|
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
2017-09-14 03:06:03 +02:00
|
|
|
(node.in zip node.out) foreach { case ((in, edgeIn), (out, edgeOut)) =>
|
2017-01-30 00:17:52 +01:00
|
|
|
val beatBytes = edgeOut.slave.beatBytes
|
|
|
|
val lgBytes = log2Ceil(beatBytes)
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
// APB has no cache coherence
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
in.c.ready := Bool(true)
|
|
|
|
in.e.ready := Bool(true)
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
// We need a skidpad to capture D output:
|
|
|
|
// We cannot know if the D response will be accepted until we have
|
|
|
|
// presented it on D as valid. We also can't back-pressure APB in the
|
|
|
|
// data phase. Therefore, we must have enough space to save the data
|
|
|
|
// phase result. Whenever we have a queued response, we can not allow
|
|
|
|
// APB to present new responses, so we must quash the address phase.
|
|
|
|
val d = Wire(in.d)
|
|
|
|
in.d <> Queue(d, 1, flow = true)
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
// We need an irrevocable input for APB to stall
|
2017-03-16 23:34:28 +01:00
|
|
|
val a = Queue(in.a, 1, flow = aFlow, pipe = !aFlow)
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
val a_enable = RegInit(Bool(false))
|
|
|
|
val a_sel = a.valid && RegNext(!in.d.valid || in.d.ready)
|
|
|
|
val a_write = edgeIn.hasData(a.bits)
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
when (a_sel) { a_enable := Bool(true) }
|
|
|
|
when (d.fire()) { a_enable := Bool(false) }
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
out.psel := a_sel
|
|
|
|
out.penable := a_enable
|
|
|
|
out.pwrite := a_write
|
|
|
|
out.paddr := a.bits.address
|
|
|
|
out.pprot := PROT_DEFAULT
|
|
|
|
out.pwdata := a.bits.data
|
|
|
|
out.pstrb := Mux(a_write, a.bits.mask, UInt(0))
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
a.ready := a_enable && out.pready
|
|
|
|
d.valid := a_enable && out.pready
|
|
|
|
assert (!d.valid || d.ready)
|
2016-12-15 23:16:01 +01:00
|
|
|
|
2017-07-27 01:01:21 +02:00
|
|
|
d.bits := edgeIn.AccessAck(a.bits, out.prdata, out.pslverr)
|
2017-01-30 00:17:52 +01:00
|
|
|
d.bits.opcode := Mux(a_write, TLMessages.AccessAck, TLMessages.AccessAckData)
|
|
|
|
}
|
2016-12-15 23:16:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object TLToAPB
|
|
|
|
{
|
2017-10-27 09:45:21 +02:00
|
|
|
def apply(aFlow: Boolean = true)(implicit p: Parameters) = LazyModule(new TLToAPB(aFlow)).node
|
2016-12-15 23:16:01 +01:00
|
|
|
}
|