2017-10-31 01:05:09 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
|
|
|
package freechips.rocketchip.tilelink
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import freechips.rocketchip.config.Parameters
|
|
|
|
import freechips.rocketchip.diplomacy._
|
|
|
|
import freechips.rocketchip.util._
|
|
|
|
|
2017-11-06 20:53:09 +01:00
|
|
|
// Check if a request satisfies some interesting property
|
|
|
|
class RequestPattern(test: TLBundleA => Bool)
|
|
|
|
{
|
|
|
|
def apply(a: TLBundleA) = test(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
object RequestPattern
|
|
|
|
{
|
|
|
|
// Does the request address range overlap a particular pattern of addresses?
|
|
|
|
def overlaps(pattern: Seq[AddressSet])(a: TLBundleA) = {
|
|
|
|
val amask = UIntToOH1(a.size, a.params.addressBits)
|
|
|
|
val abase = a.address
|
|
|
|
pattern.map { case p =>
|
|
|
|
val pbase = UInt(p.base)
|
|
|
|
val pmask = UInt(p.mask & ((BigInt(1) << a.params.addressBits) - 1))
|
|
|
|
(amask | pmask | ~(abase ^ pbase)).andR
|
|
|
|
}.reduce(_ || _)
|
|
|
|
}
|
|
|
|
|
|
|
|
implicit def apply(pattern: Seq[AddressSet]): RequestPattern = new RequestPattern(overlaps(pattern) _)
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:05:09 +01:00
|
|
|
// An ErrorEvaluator is used for test harnesses.
|
2017-11-06 20:53:09 +01:00
|
|
|
// It creates errors in transactions which match the provided test function.
|
2017-10-31 01:05:09 +01:00
|
|
|
// If testOn is true, it will assert fail if these transactions do not already error.
|
|
|
|
// If testOff is true, it will assert fail if these transactions otherwise error.
|
|
|
|
// This helps when building unit tests to confirm that errors are propagated correctly.
|
2017-11-06 20:53:09 +01:00
|
|
|
class TLErrorEvaluator(test: RequestPattern, testOn: Boolean, testOff: Boolean)(implicit p: Parameters) extends LazyModule
|
2017-10-31 01:05:09 +01:00
|
|
|
{
|
|
|
|
val node = TLAdapterNode()
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
(node.in zip node.out) foreach { case ((in, edgeIn), (out, edgeOut)) =>
|
|
|
|
out <> in
|
|
|
|
|
2017-11-06 20:53:09 +01:00
|
|
|
// Should the request receive an error ?
|
|
|
|
val inject_map = Mem(edgeIn.client.endSourceId, Bool())
|
|
|
|
val inject_now = test(in.a.bits)
|
2017-10-31 01:05:09 +01:00
|
|
|
|
|
|
|
val (d_first, d_last, _) = edgeOut.firstlast(out.d)
|
|
|
|
|
2017-11-06 20:53:09 +01:00
|
|
|
when (in.a.fire()) { inject_map.write(in.a.bits.source, inject_now) }
|
2017-10-31 01:05:09 +01:00
|
|
|
|
|
|
|
val bypass = in.a.fire() && in.a.bits.source === in.d.bits.source
|
2017-11-06 20:53:09 +01:00
|
|
|
val d_inject = Mux(bypass, inject_now, inject_map.read(in.d.bits.source)) holdUnless d_first
|
2017-10-31 01:05:09 +01:00
|
|
|
in.d.bits.error := out.d.bits.error || (d_last && d_inject)
|
|
|
|
|
|
|
|
assert (Bool(!testOn) || !out.d.fire() || !d_last || !d_inject || out.d.bits.error, "Error flag was not set!")
|
|
|
|
assert (Bool(!testOff) || !out.d.fire() || !d_last || d_inject || !out.d.bits.error, "Error flag was set!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object TLErrorEvaluator
|
|
|
|
{
|
2017-11-06 20:53:09 +01:00
|
|
|
def apply(test: RequestPattern, testOn: Boolean = false, testOff: Boolean = false)(implicit p: Parameters): TLNode =
|
2017-12-01 20:27:54 +01:00
|
|
|
{
|
|
|
|
val errors = LazyModule(new TLErrorEvaluator(test, testOn, testOff))
|
|
|
|
errors.node
|
|
|
|
}
|
2017-10-31 01:05:09 +01:00
|
|
|
}
|