2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.tilelink
|
2016-11-23 06:20:26 +01:00
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import chisel3.internal.sourceinfo.SourceInfo
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.config.Parameters
|
|
|
|
import freechips.rocketchip.diplomacy._
|
|
|
|
import freechips.rocketchip.util._
|
2016-11-23 06:20:26 +01:00
|
|
|
import scala.math.{min,max}
|
|
|
|
|
2016-12-02 02:46:52 +01:00
|
|
|
class TLSourceShrinker(maxInFlight: Int)(implicit p: Parameters) extends LazyModule
|
2016-11-23 06:20:26 +01:00
|
|
|
{
|
2016-11-23 07:01:43 +01:00
|
|
|
require (maxInFlight > 0)
|
|
|
|
|
2017-03-20 23:30:58 +01:00
|
|
|
// The SourceShrinker completely destroys all FIFO property guarantees
|
2017-06-03 00:09:35 +02:00
|
|
|
private val client = TLClientParameters(
|
|
|
|
name = "TLSourceShrinker",
|
|
|
|
sourceId = IdRange(0, maxInFlight))
|
2016-11-23 06:20:26 +01:00
|
|
|
val node = TLAdapterNode(
|
|
|
|
// We erase all client information since we crush the source Ids
|
2017-01-30 00:17:52 +01:00
|
|
|
clientFn = { _ => TLClientPortParameters(clients = Seq(client)) },
|
2017-03-20 23:30:58 +01:00
|
|
|
managerFn = { mp => mp.copy(managers = mp.managers.map(_.copy(fifoId = None))) })
|
2016-11-23 06:20:26 +01:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
val io = new Bundle {
|
|
|
|
val in = node.bundleIn
|
|
|
|
val out = node.bundleOut
|
|
|
|
}
|
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
((io.in zip io.out) zip (node.edgesIn zip node.edgesOut)) foreach { case ((in, out), (edgeIn, edgeOut)) =>
|
|
|
|
// Acquires cannot pass this adapter; it makes Probes impossible
|
|
|
|
require (!edgeIn.client.anySupportProbe ||
|
|
|
|
!edgeOut.manager.anySupportAcquireB)
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
out.b.ready := Bool(true)
|
|
|
|
out.c.valid := Bool(false)
|
|
|
|
out.e.valid := Bool(false)
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
in.c.ready := Bool(true)
|
|
|
|
in.e.ready := Bool(true)
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
if (maxInFlight >= edgeIn.client.endSourceId) {
|
|
|
|
out.a <> in.a
|
|
|
|
in.d <> out.d
|
|
|
|
} else {
|
|
|
|
// State tracking
|
|
|
|
val sourceIdMap = Mem(maxInFlight, in.a.bits.source)
|
|
|
|
val allocated = RegInit(UInt(0, width = maxInFlight))
|
|
|
|
val nextFreeOH = ~(leftOR(~allocated) << 1) & ~allocated
|
|
|
|
val nextFree = OHToUInt(nextFreeOH)
|
|
|
|
val full = allocated.andR()
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
val a_first = edgeIn.first(in.a)
|
|
|
|
val d_last = edgeIn.last(in.d)
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
val block = a_first && full
|
|
|
|
in.a.ready := out.a.ready && !block
|
|
|
|
out.a.valid := in.a.valid && !block
|
|
|
|
out.a.bits := in.a.bits
|
2017-02-25 11:54:42 +01:00
|
|
|
out.a.bits.source := nextFree holdUnless a_first
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-07-26 19:40:40 +02:00
|
|
|
val bypass = Bool(edgeOut.manager.minLatency == 0) && in.a.fire() && a_first && nextFree === out.d.bits.source
|
2017-01-30 00:17:52 +01:00
|
|
|
in.d <> out.d
|
2017-07-26 19:40:40 +02:00
|
|
|
in.d.bits.source := Mux(bypass, in.a.bits.source, sourceIdMap(out.d.bits.source))
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
when (a_first && in.a.fire()) {
|
|
|
|
sourceIdMap(nextFree) := in.a.bits.source
|
|
|
|
}
|
2016-11-23 06:20:26 +01:00
|
|
|
|
2017-01-30 00:17:52 +01:00
|
|
|
val alloc = a_first && in.a.fire()
|
|
|
|
val free = d_last && in.d.fire()
|
|
|
|
val alloc_id = Mux(alloc, nextFreeOH, UInt(0))
|
|
|
|
val free_id = Mux(free, UIntToOH(out.d.bits.source), UInt(0))
|
|
|
|
allocated := (allocated | alloc_id) & ~free_id
|
2016-11-23 07:01:43 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-23 06:20:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object TLSourceShrinker
|
|
|
|
{
|
|
|
|
// applied to the TL source node; y.node := TLSourceShrinker(n)(x.node)
|
2016-12-02 02:46:52 +01:00
|
|
|
def apply(maxInFlight: Int)(x: TLOutwardNode)(implicit p: Parameters, sourceInfo: SourceInfo): TLOutwardNode = {
|
2016-11-23 06:20:26 +01:00
|
|
|
val shrinker = LazyModule(new TLSourceShrinker(maxInFlight))
|
|
|
|
shrinker.node := x
|
|
|
|
shrinker.node
|
|
|
|
}
|
|
|
|
}
|