2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
2016-08-26 23:16:17 +02:00
|
|
|
|
|
|
|
package uncore.tilelink2
|
|
|
|
|
|
|
|
import Chisel._
|
2017-05-12 15:25:58 +02:00
|
|
|
import chisel3.experimental.chiselName
|
2016-12-02 02:46:52 +01:00
|
|
|
import config._
|
2016-10-04 00:17:36 +02:00
|
|
|
import diplomacy._
|
2017-02-25 11:54:42 +01:00
|
|
|
import util._
|
2016-08-26 23:16:17 +02:00
|
|
|
|
2017-06-16 21:55:59 +02:00
|
|
|
class TLRAM(address: AddressSet, executable: Boolean = true, beatBytes: Int = 4, name: Option[String] = None)(implicit p: Parameters) extends LazyModule
|
2016-08-26 23:16:17 +02:00
|
|
|
{
|
2017-06-16 21:55:59 +02:00
|
|
|
val device = name.map(new SimpleDevice(_, Nil)).getOrElse(new MemoryDevice)
|
2017-01-30 00:17:52 +01:00
|
|
|
val node = TLManagerNode(Seq(TLManagerPortParameters(
|
2016-09-28 21:56:03 +02:00
|
|
|
Seq(TLManagerParameters(
|
|
|
|
address = List(address),
|
2017-06-28 22:01:40 +02:00
|
|
|
resources = device.reg("mem"),
|
2016-09-28 21:56:03 +02:00
|
|
|
regionType = RegionType.UNCACHED,
|
|
|
|
executable = executable,
|
|
|
|
supportsGet = TransferSizes(1, beatBytes),
|
|
|
|
supportsPutPartial = TransferSizes(1, beatBytes),
|
|
|
|
supportsPutFull = TransferSizes(1, beatBytes),
|
|
|
|
fifoId = Some(0))), // requests are handled in order
|
|
|
|
beatBytes = beatBytes,
|
2017-01-30 00:17:52 +01:00
|
|
|
minLatency = 1))) // no bypass needed for this device
|
2016-08-26 23:16:17 +02:00
|
|
|
|
2016-08-30 20:46:05 +02:00
|
|
|
// We require the address range to include an entire beat (for the write mask)
|
|
|
|
require ((address.mask & (beatBytes-1)) == beatBytes-1)
|
|
|
|
|
2017-05-12 15:25:58 +02:00
|
|
|
lazy val module = new Implementation
|
|
|
|
@chiselName class Implementation extends LazyModuleImp(this) {
|
2016-08-26 23:16:17 +02:00
|
|
|
val io = new Bundle {
|
|
|
|
val in = node.bundleIn
|
|
|
|
}
|
2016-08-30 20:46:05 +02:00
|
|
|
|
|
|
|
def bigBits(x: BigInt, tail: List[Boolean] = List.empty[Boolean]): List[Boolean] =
|
|
|
|
if (x == 0) tail.reverse else bigBits(x >> 1, ((x & 1) == 1) :: tail)
|
2016-09-07 08:46:44 +02:00
|
|
|
val mask = bigBits(address.mask >> log2Ceil(beatBytes))
|
2016-08-30 20:46:05 +02:00
|
|
|
|
|
|
|
val in = io.in(0)
|
2016-10-14 23:09:39 +02:00
|
|
|
val edge = node.edgesIn(0)
|
|
|
|
|
|
|
|
val addrBits = (mask zip edge.addr_hi(in.a.bits).toBools).filter(_._1).map(_._2)
|
2016-08-30 20:46:05 +02:00
|
|
|
val memAddress = Cat(addrBits.reverse)
|
|
|
|
val mem = SeqMem(1 << addrBits.size, Vec(beatBytes, Bits(width = 8)))
|
|
|
|
|
|
|
|
val d_full = RegInit(Bool(false))
|
|
|
|
val d_read = Reg(Bool())
|
|
|
|
val d_size = Reg(UInt())
|
|
|
|
val d_source = Reg(UInt())
|
2016-09-07 08:46:44 +02:00
|
|
|
val d_addr = Reg(UInt())
|
2016-08-30 20:46:05 +02:00
|
|
|
val d_data = Wire(UInt())
|
|
|
|
|
|
|
|
// Flow control
|
|
|
|
when (in.d.fire()) { d_full := Bool(false) }
|
|
|
|
when (in.a.fire()) { d_full := Bool(true) }
|
|
|
|
in.d.valid := d_full
|
|
|
|
in.a.ready := in.d.ready || !d_full
|
|
|
|
|
2016-09-07 08:46:44 +02:00
|
|
|
in.d.bits := edge.AccessAck(d_addr, UInt(0), d_source, d_size)
|
2016-08-30 20:46:05 +02:00
|
|
|
// avoid data-bus Mux
|
|
|
|
in.d.bits.data := d_data
|
|
|
|
in.d.bits.opcode := Mux(d_read, TLMessages.AccessAckData, TLMessages.AccessAck)
|
|
|
|
|
|
|
|
val read = in.a.bits.opcode === TLMessages.Get
|
|
|
|
val rdata = Wire(Vec(beatBytes, Bits(width = 8)))
|
|
|
|
val wdata = Vec.tabulate(beatBytes) { i => in.a.bits.data(8*(i+1)-1, 8*i) }
|
|
|
|
d_data := Cat(rdata.reverse)
|
|
|
|
when (in.a.fire()) {
|
|
|
|
d_read := read
|
|
|
|
d_size := in.a.bits.size
|
|
|
|
d_source := in.a.bits.source
|
2016-09-07 08:46:44 +02:00
|
|
|
d_addr := edge.addr_lo(in.a.bits)
|
2016-08-30 20:46:05 +02:00
|
|
|
}
|
2016-09-05 01:47:18 +02:00
|
|
|
|
2016-09-08 19:38:38 +02:00
|
|
|
// exactly this pattern is required to get a RWM memory
|
|
|
|
when (in.a.fire() && !read) {
|
|
|
|
mem.write(memAddress, wdata, in.a.bits.mask.toBools)
|
|
|
|
}
|
2016-10-28 08:44:10 +02:00
|
|
|
val ren = in.a.fire() && read
|
2017-02-25 11:54:42 +01:00
|
|
|
rdata := mem.readAndHold(memAddress, ren)
|
2016-09-08 19:38:38 +02:00
|
|
|
|
2016-09-05 01:47:18 +02:00
|
|
|
// Tie off unused channels
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
in.c.ready := Bool(true)
|
|
|
|
in.e.ready := Bool(true)
|
2016-09-02 20:13:43 +02:00
|
|
|
}
|
2016-08-26 23:16:17 +02:00
|
|
|
}
|
2016-09-29 00:11:05 +02:00
|
|
|
|
|
|
|
/** Synthesizeable unit testing */
|
|
|
|
import unittest._
|
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
class TLRAMSimple(ramBeatBytes: Int, txns: Int)(implicit p: Parameters) extends LazyModule {
|
|
|
|
val fuzz = LazyModule(new TLFuzzer(txns))
|
2017-04-13 20:51:10 +02:00
|
|
|
val model = LazyModule(new TLRAMModel("SRAMSimple"))
|
2016-09-29 00:11:05 +02:00
|
|
|
val ram = LazyModule(new TLRAM(AddressSet(0x0, 0x3ff), beatBytes = ramBeatBytes))
|
|
|
|
|
|
|
|
model.node := fuzz.node
|
2017-03-11 02:10:41 +01:00
|
|
|
ram.node := TLDelayer(0.25)(model.node)
|
2016-09-29 00:11:05 +02:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) with HasUnitTestIO {
|
|
|
|
io.finished := fuzz.module.io.finished
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
class TLRAMSimpleTest(ramBeatBytes: Int, txns: Int = 5000, timeout: Int = 500000)(implicit p: Parameters) extends UnitTest(timeout) {
|
|
|
|
io.finished := Module(LazyModule(new TLRAMSimple(ramBeatBytes, txns)).module).io.finished
|
2016-09-29 00:11:05 +02:00
|
|
|
}
|