201 lines
6.0 KiB
Scala
201 lines
6.0 KiB
Scala
package groundtest
|
|
|
|
import Chisel._
|
|
import uncore._
|
|
import junctions._
|
|
import rocket._
|
|
import scala.util.Random
|
|
import cde.{Parameters, Field}
|
|
|
|
case object NGenerators extends Field[Int]
|
|
case object GenerateUncached extends Field[Boolean]
|
|
case object GenerateCached extends Field[Boolean]
|
|
case object MaxGenerateRequests extends Field[Int]
|
|
case object GeneratorStartAddress extends Field[BigInt]
|
|
|
|
trait HasGeneratorParams {
|
|
implicit val p: Parameters
|
|
val nGens = p(NGenerators)
|
|
val genUncached = p(GenerateUncached)
|
|
val genCached = p(GenerateCached)
|
|
val genTimeout = 4096
|
|
val maxRequests = p(MaxGenerateRequests)
|
|
val startAddress = p(GeneratorStartAddress)
|
|
val genWordBits = p(WordBits)
|
|
val genWordBytes = genWordBits / 8
|
|
val wordOffset = log2Up(genWordBytes)
|
|
|
|
require(startAddress % BigInt(genWordBytes) == 0)
|
|
}
|
|
|
|
class UncachedTileLinkGenerator(id: Int)
|
|
(implicit p: Parameters) extends TLModule()(p) with HasGeneratorParams {
|
|
|
|
private val tlBlockOffset = tlBeatAddrBits + tlByteAddrBits
|
|
|
|
val io = new Bundle {
|
|
val mem = new ClientUncachedTileLinkIO
|
|
val finished = Bool(OUTPUT)
|
|
}
|
|
|
|
val (s_start :: s_put :: s_get :: s_finished :: Nil) = Enum(Bits(), 4)
|
|
val state = Reg(init = s_start)
|
|
|
|
val (req_cnt, req_wrap) = Counter(io.mem.grant.fire(), maxRequests)
|
|
|
|
val sending = Reg(init = Bool(false))
|
|
|
|
when (state === s_start) {
|
|
sending := Bool(true)
|
|
state := s_put
|
|
}
|
|
|
|
when (io.mem.acquire.fire()) { sending := Bool(false) }
|
|
when (io.mem.grant.fire()) { sending := Bool(true) }
|
|
when (req_wrap) { state := Mux(state === s_put, s_get, s_finished) }
|
|
|
|
val timeout = Timer(genTimeout, io.mem.acquire.fire(), io.mem.grant.fire())
|
|
assert(!timeout, s"Uncached generator ${id} timed out waiting for grant")
|
|
|
|
io.finished := (state === s_finished)
|
|
|
|
val part_of_full_addr =
|
|
if (genCached) {
|
|
Cat(req_cnt,
|
|
UInt(0, width = 1),
|
|
UInt(0, wordOffset))
|
|
} else {
|
|
Cat(req_cnt,
|
|
UInt(0, wordOffset))
|
|
}
|
|
val another_part_of_full_addr =
|
|
if (log2Ceil(nGens) > 0) {
|
|
Cat(UInt(id, log2Ceil(nGens)),
|
|
part_of_full_addr)
|
|
} else {
|
|
part_of_full_addr
|
|
}
|
|
val full_addr = UInt(startAddress) + another_part_of_full_addr
|
|
|
|
val addr_block = full_addr >> UInt(tlBlockOffset)
|
|
val addr_beat = full_addr(tlBlockOffset - 1, tlByteAddrBits)
|
|
val addr_byte = full_addr(tlByteAddrBits - 1, 0)
|
|
|
|
val data_prefix = Cat(UInt(id, log2Up(nGens)), req_cnt)
|
|
val word_data = Wire(UInt(width = genWordBits))
|
|
word_data := Cat(data_prefix, full_addr)
|
|
val beat_data = Fill(tlDataBits / genWordBits, word_data)
|
|
val wshift = Cat(full_addr(tlByteAddrBits - 1, wordOffset), UInt(0, wordOffset))
|
|
val wmask = Fill(genWordBits / 8, Bits(1, 1)) << wshift
|
|
|
|
val put_acquire = Put(
|
|
client_xact_id = UInt(0),
|
|
addr_block = addr_block,
|
|
addr_beat = addr_beat,
|
|
data = beat_data,
|
|
wmask = Some(wmask),
|
|
alloc = Bool(false))
|
|
|
|
val get_acquire = Get(
|
|
client_xact_id = UInt(0),
|
|
addr_block = addr_block,
|
|
addr_beat = addr_beat,
|
|
addr_byte = addr_byte,
|
|
operand_size = MT_D,
|
|
alloc = Bool(false))
|
|
|
|
io.mem.acquire.valid := sending && !io.finished
|
|
io.mem.acquire.bits := Mux(state === s_put, put_acquire, get_acquire)
|
|
io.mem.grant.ready := !sending && !io.finished
|
|
|
|
def wordFromBeat(addr: UInt, dat: UInt) = {
|
|
val offset = addr(tlByteAddrBits - 1, wordOffset)
|
|
val shift = Cat(offset, UInt(0, wordOffset + 3))
|
|
(dat >> shift)(genWordBits - 1, 0)
|
|
}
|
|
|
|
assert(!io.mem.grant.valid || state =/= s_get ||
|
|
wordFromBeat(full_addr, io.mem.grant.bits.data) === word_data,
|
|
s"Get received incorrect data in uncached generator ${id}")
|
|
}
|
|
|
|
class HellaCacheGenerator(id: Int)
|
|
(implicit p: Parameters) extends L1HellaCacheModule()(p) with HasGeneratorParams {
|
|
val io = new Bundle {
|
|
val finished = Bool(OUTPUT)
|
|
val mem = new HellaCacheIO
|
|
}
|
|
|
|
val timeout = Timer(genTimeout, io.mem.req.fire(), io.mem.resp.valid)
|
|
assert(!timeout, s"Cached generator ${id} timed out waiting for response")
|
|
|
|
val (s_start :: s_write :: s_read :: s_finished :: Nil) = Enum(Bits(), 4)
|
|
val state = Reg(init = s_start)
|
|
val sending = Reg(init = Bool(false))
|
|
|
|
val (req_cnt, req_wrap) = Counter(io.mem.resp.valid, maxRequests)
|
|
|
|
val part_of_req_addr =
|
|
if (log2Ceil(nGens) > 0) {
|
|
if (genUncached) {
|
|
Cat(UInt(id, log2Ceil(nGens)),
|
|
UInt(1, width = 1),
|
|
UInt(0, wordOffset))
|
|
} else {
|
|
Cat(UInt(id, log2Ceil(nGens)),
|
|
UInt(0, wordOffset))
|
|
}
|
|
} else {
|
|
if (genUncached) {
|
|
Cat(UInt(1, width = 1),
|
|
UInt(0, wordOffset))
|
|
} else {
|
|
UInt(0, wordOffset)
|
|
}
|
|
}
|
|
val req_addr = UInt(startAddress) + Cat(req_cnt, part_of_req_addr)
|
|
val req_data = Cat(UInt(id, log2Up(nGens)), req_cnt, req_addr)
|
|
|
|
io.mem.req.valid := sending && !io.finished
|
|
io.mem.req.bits.addr := req_addr
|
|
io.mem.req.bits.data := req_data
|
|
io.mem.req.bits.typ := MT_D
|
|
io.mem.req.bits.cmd := Mux(state === s_write, M_XWR, M_XRD)
|
|
io.mem.req.bits.tag := UInt(0)
|
|
|
|
when (state === s_start) { sending := Bool(true); state := s_write }
|
|
|
|
when (io.mem.req.fire()) { sending := Bool(false) }
|
|
when (io.mem.resp.valid) { sending := Bool(true) }
|
|
|
|
when (req_wrap) { state := Mux(state === s_write, s_read, s_finished) }
|
|
|
|
io.finished := (state === s_finished)
|
|
|
|
assert(!io.mem.resp.valid || !io.mem.resp.bits.has_data ||
|
|
io.mem.resp.bits.data === req_data,
|
|
s"Received incorrect data in cached generator ${id}")
|
|
}
|
|
|
|
class GeneratorTest(id: Int)(implicit p: Parameters)
|
|
extends GroundTest()(p) with HasGeneratorParams {
|
|
|
|
disablePorts(mem = !genUncached, cache = !genCached)
|
|
|
|
val gen_finished = Wire(init = Vec.fill(2){Bool(true)})
|
|
|
|
if (genUncached) {
|
|
val uncacheGen = Module(new UncachedTileLinkGenerator(id))
|
|
io.mem <> uncacheGen.io.mem
|
|
gen_finished(0) := uncacheGen.io.finished
|
|
}
|
|
|
|
if (genCached) {
|
|
val cacheGen = Module(new HellaCacheGenerator(id))
|
|
io.cache <> cacheGen.io.mem
|
|
gen_finished(1) := cacheGen.io.finished
|
|
}
|
|
|
|
io.finished := gen_finished.reduce(_ && _)
|
|
}
|