tilelink: Filter now support arbitrary filter functions
This commit is contained in:
parent
7adfd5c431
commit
13d3ffbcaa
@ -68,7 +68,7 @@ trait HasMemoryBus extends HasSystemBus with HasPeripheryBus with HasInterruptBu
|
|||||||
for (bank <- 0 until nBanksPerChannel) {
|
for (bank <- 0 until nBanksPerChannel) {
|
||||||
val offset = (bank * nMemoryChannels) + channel
|
val offset = (bank * nMemoryChannels) + channel
|
||||||
in := sbus.toMemoryBus
|
in := sbus.toMemoryBus
|
||||||
mbus.fromCoherenceManager := TLFilter(AddressSet(offset * blockBytes, mask))(out)
|
mbus.fromCoherenceManager := TLFilter(TLFilter.Mmask(AddressSet(offset * blockBytes, mask)))(out)
|
||||||
}
|
}
|
||||||
mbus
|
mbus
|
||||||
}
|
}
|
||||||
|
@ -8,31 +8,45 @@ import freechips.rocketchip.config.Parameters
|
|||||||
import freechips.rocketchip.diplomacy._
|
import freechips.rocketchip.diplomacy._
|
||||||
import scala.math.{min,max}
|
import scala.math.{min,max}
|
||||||
|
|
||||||
class TLFilter(select: AddressSet)(implicit p: Parameters) extends LazyModule
|
class TLFilter(
|
||||||
|
Mfilter: TLManagerParameters => Option[TLManagerParameters] = TLFilter.Midentity,
|
||||||
|
Cfilter: TLClientParameters => Option[TLClientParameters] = TLFilter.Cidentity
|
||||||
|
)(implicit p: Parameters) extends LazyModule
|
||||||
{
|
{
|
||||||
val node = TLAdapterNode(
|
val node = TLAdapterNode(
|
||||||
clientFn = { cp => cp },
|
clientFn = { cp => cp.copy(clients = cp.clients.flatMap { c =>
|
||||||
managerFn = { mp =>
|
val out = Cfilter(c)
|
||||||
mp.copy(managers = mp.managers.map { m =>
|
out.map { o => // Confirm the filter only REMOVES capability
|
||||||
val filtered = m.address.map(_.intersect(select)).flatten
|
require (c.sourceId.contains(o.sourceId))
|
||||||
val alignment = select.alignment /* alignment 0 means 'select' selected everything */
|
require (c.supportsProbe.contains(o.supportsProbe))
|
||||||
val maxTransfer = 1 << 30
|
require (c.supportsArithmetic.contains(o.supportsArithmetic))
|
||||||
val capTransfer = if (alignment == 0 || alignment > maxTransfer) maxTransfer else alignment.toInt
|
require (c.supportsLogical.contains(o.supportsLogical))
|
||||||
val cap = TransferSizes(1, capTransfer)
|
require (c.supportsGet.contains(o.supportsGet))
|
||||||
if (filtered.isEmpty) { None } else {
|
require (c.supportsPutFull.contains(o.supportsPutFull))
|
||||||
Some(m.copy(
|
require (c.supportsPutPartial.contains(o.supportsPutPartial))
|
||||||
address = filtered,
|
require (c.supportsHint.contains(o.supportsHint))
|
||||||
supportsAcquireT = m.supportsAcquireT .intersect(cap),
|
require (!c.requestFifo || o.requestFifo)
|
||||||
supportsAcquireB = m.supportsAcquireB .intersect(cap),
|
}
|
||||||
supportsArithmetic = m.supportsArithmetic.intersect(cap),
|
out
|
||||||
supportsLogical = m.supportsLogical .intersect(cap),
|
})},
|
||||||
supportsGet = m.supportsGet .intersect(cap),
|
managerFn = { mp => mp.copy(managers = mp.managers.flatMap { m =>
|
||||||
supportsPutFull = m.supportsPutFull .intersect(cap),
|
val out = Mfilter(m)
|
||||||
supportsPutPartial = m.supportsPutPartial.intersect(cap),
|
out.map { o => // Confirm the filter only REMOVES capability
|
||||||
supportsHint = m.supportsHint .intersect(cap)))
|
o.address.foreach { a => require (m.address.map(_.contains(a)).reduce(_||_)) }
|
||||||
}
|
require (o.regionType <= m.regionType)
|
||||||
}.flatten)
|
// we allow executable to be changed both ways
|
||||||
})
|
require (m.supportsAcquireT.contains(o.supportsAcquireT))
|
||||||
|
require (m.supportsAcquireB.contains(o.supportsAcquireB))
|
||||||
|
require (m.supportsArithmetic.contains(o.supportsArithmetic))
|
||||||
|
require (m.supportsLogical.contains(o.supportsLogical))
|
||||||
|
require (m.supportsGet.contains(o.supportsGet))
|
||||||
|
require (m.supportsPutFull.contains(o.supportsPutFull))
|
||||||
|
require (m.supportsPutPartial.contains(o.supportsPutPartial))
|
||||||
|
require (m.supportsHint.contains(o.supportsHint))
|
||||||
|
require (m.fifoId == o.fifoId) // could relax this, but hard to validate
|
||||||
|
}
|
||||||
|
out
|
||||||
|
})})
|
||||||
|
|
||||||
lazy val module = new LazyModuleImp(this) {
|
lazy val module = new LazyModuleImp(this) {
|
||||||
val io = new Bundle {
|
val io = new Bundle {
|
||||||
@ -45,9 +59,40 @@ class TLFilter(select: AddressSet)(implicit p: Parameters) extends LazyModule
|
|||||||
|
|
||||||
object TLFilter
|
object TLFilter
|
||||||
{
|
{
|
||||||
|
def Midentity: TLManagerParameters => Option[TLManagerParameters] = { m => Some(m) }
|
||||||
|
def Cidentity: TLClientParameters => Option[TLClientParameters] = { c => Some(c) }
|
||||||
|
def Mmask(select: AddressSet): TLManagerParameters => Option[TLManagerParameters] = { m =>
|
||||||
|
val filtered = m.address.map(_.intersect(select)).flatten
|
||||||
|
val alignment = select.alignment /* alignment 0 means 'select' selected everything */
|
||||||
|
val maxTransfer = 1 << 30
|
||||||
|
val capTransfer = if (alignment == 0 || alignment > maxTransfer) maxTransfer else alignment.toInt
|
||||||
|
val cap = TransferSizes(1, capTransfer)
|
||||||
|
if (filtered.isEmpty) { None } else {
|
||||||
|
Some(m.copy(
|
||||||
|
address = filtered,
|
||||||
|
supportsAcquireT = m.supportsAcquireT .intersect(cap),
|
||||||
|
supportsAcquireB = m.supportsAcquireB .intersect(cap),
|
||||||
|
supportsArithmetic = m.supportsArithmetic.intersect(cap),
|
||||||
|
supportsLogical = m.supportsLogical .intersect(cap),
|
||||||
|
supportsGet = m.supportsGet .intersect(cap),
|
||||||
|
supportsPutFull = m.supportsPutFull .intersect(cap),
|
||||||
|
supportsPutPartial = m.supportsPutPartial.intersect(cap),
|
||||||
|
supportsHint = m.supportsHint .intersect(cap)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
def Mnocache: TLManagerParameters => Option[TLManagerParameters] = { m =>
|
||||||
|
if (m.supportsAcquireB) None else Some(m)
|
||||||
|
}
|
||||||
|
def Cnocache: TLClientParameters => Option[TLClientParameters] = { c =>
|
||||||
|
if (c.supportsProbe) None else Some(c)
|
||||||
|
}
|
||||||
|
|
||||||
// applied to the TL source node; y.node := TLBuffer(x.node)
|
// applied to the TL source node; y.node := TLBuffer(x.node)
|
||||||
def apply(select: AddressSet)(x: TLOutwardNode)(implicit p: Parameters, sourceInfo: SourceInfo): TLOutwardNode = {
|
def apply(
|
||||||
val filter = LazyModule(new TLFilter(select))
|
Mfilter: TLManagerParameters => Option[TLManagerParameters] = TLFilter.Midentity,
|
||||||
|
Cfilter: TLClientParameters => Option[TLClientParameters] = TLFilter.Cidentity
|
||||||
|
)(x: TLOutwardNode)(implicit p: Parameters, sourceInfo: SourceInfo): TLOutwardNode = {
|
||||||
|
val filter = LazyModule(new TLFilter(Mfilter, Cfilter))
|
||||||
filter.node := x
|
filter.node := x
|
||||||
filter.node
|
filter.node
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user