2016-09-10 05:57:20 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
|
|
|
package uncore.tilelink2
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
|
2016-09-14 00:44:36 +02:00
|
|
|
// We detect concurrent puts that put memory into an undefined state.
|
|
|
|
// put0, put0Ack, put1, put1Ack => ok: defined
|
|
|
|
// put0, put1, put0Ack, put1Ack => ok: put1 clears valid (it sees busy>0) defined for FIFO
|
|
|
|
// put0, put1, put1Ack, put0Ack => ok: put1 clears valid (it sees busy>0) defined for FIFO
|
|
|
|
// When the region is FIFO, all writes leave 'valid' set (concurrent puts have defined behaviour)
|
|
|
|
|
|
|
|
// We detect concurrent puts that invalidate an inflight get.
|
|
|
|
// get, getAck, put, putAck => ok: defined
|
|
|
|
// get, put, getAck, putAck => ok: detected by getAck (it sees busy>0)
|
|
|
|
// get, put, putAck, getAck => ok: putAck uses CAM to wipe get validity impossible for FIFO
|
|
|
|
// put, putAck, get, getAck => ok: defined
|
|
|
|
// put, get, putAck, getAck => ok: putAck uses CAM to wipe get validity defined for FIFO
|
|
|
|
// put, get, getAck, putAck => ok: detected by getAck (it sees busy>0) impossible for FIFO
|
|
|
|
// If FIFO, the getAck should check data even if its validity was wiped
|
|
|
|
|
2016-09-10 05:57:20 +02:00
|
|
|
class TLRAMModel extends LazyModule
|
|
|
|
{
|
|
|
|
val node = TLIdentityNode()
|
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
val io = new Bundle {
|
|
|
|
val in = node.bundleIn
|
|
|
|
val out = node.bundleOut
|
|
|
|
}
|
|
|
|
|
2016-09-12 00:44:56 +02:00
|
|
|
// !!! support multiple clients via clock division
|
|
|
|
require (io.out.size == 1)
|
2016-09-10 05:57:20 +02:00
|
|
|
|
2016-09-10 09:24:57 +02:00
|
|
|
val in = io.in(0)
|
|
|
|
val out = io.out(0)
|
|
|
|
|
2016-09-10 05:57:20 +02:00
|
|
|
val edge = node.edgesIn(0)
|
|
|
|
val endAddress = edge.manager.maxAddress + 1
|
|
|
|
val endSourceId = edge.client.endSourceId
|
|
|
|
val maxTransfer = edge.manager.maxTransfer
|
|
|
|
val beatBytes = edge.manager.beatBytes
|
|
|
|
val endAddressHi = (endAddress / beatBytes).intValue
|
|
|
|
val maxLgBeats = log2Up(maxTransfer/beatBytes)
|
|
|
|
val shift = log2Ceil(beatBytes)
|
2016-09-29 01:52:08 +02:00
|
|
|
val decTrees = log2Up(maxTransfer/beatBytes)
|
2016-09-10 05:57:20 +02:00
|
|
|
val addressBits = log2Up(endAddress)
|
|
|
|
val countBits = log2Up(endSourceId)
|
|
|
|
val sizeBits = edge.bundle.sizeBits
|
|
|
|
|
2016-09-10 09:24:57 +02:00
|
|
|
// Reset control logic
|
|
|
|
val wipeIndex = RegInit(UInt(0, width = log2Ceil(endAddressHi) + 1))
|
|
|
|
val wipe = !wipeIndex(log2Ceil(endAddressHi))
|
|
|
|
wipeIndex := wipeIndex + wipe.asUInt
|
|
|
|
|
|
|
|
// Block traffic while wiping Mems
|
|
|
|
in.a.ready := out.a.ready && !wipe
|
|
|
|
out.a.valid := in.a.valid && !wipe
|
|
|
|
out.a.bits := in.a.bits
|
|
|
|
out.d.ready := in.d.ready && !wipe
|
|
|
|
in.d.valid := out.d.valid && !wipe
|
|
|
|
in.d.bits := out.d.bits
|
|
|
|
|
|
|
|
// BCE unsupported
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
out.c.valid := Bool(false)
|
|
|
|
out.e.valid := Bool(false)
|
|
|
|
out.b.ready := Bool(true)
|
|
|
|
in.c.ready := Bool(true)
|
|
|
|
in.e.ready := Bool(true)
|
|
|
|
|
2016-09-10 05:57:20 +02:00
|
|
|
class ByteMonitor extends Bundle {
|
|
|
|
val valid = Bool()
|
|
|
|
val value = UInt(width = 8)
|
|
|
|
}
|
|
|
|
class FlightMonitor extends Bundle {
|
|
|
|
val base = UInt(width = addressBits)
|
|
|
|
val size = UInt(width = sizeBits)
|
|
|
|
val opcode = UInt(width = 3)
|
|
|
|
}
|
|
|
|
|
2016-09-12 00:44:56 +02:00
|
|
|
// Infer as simple dual port BRAM/M10k with write-first/new-data semantics (bypass needed)
|
2016-09-10 05:57:20 +02:00
|
|
|
val shadow = Seq.fill(beatBytes) { Mem(endAddressHi, new ByteMonitor) }
|
|
|
|
val inc_bytes = Seq.fill(beatBytes) { Mem(endAddressHi, UInt(width = countBits)) }
|
|
|
|
val dec_bytes = Seq.fill(beatBytes) { Mem(endAddressHi, UInt(width = countBits)) }
|
|
|
|
val inc_trees = Seq.tabulate(decTrees) { i => Mem(endAddressHi >> (i+1), UInt(width = countBits)) }
|
|
|
|
val dec_trees = Seq.tabulate(decTrees) { i => Mem(endAddressHi >> (i+1), UInt(width = countBits)) }
|
2016-09-10 09:24:57 +02:00
|
|
|
|
|
|
|
val shadow_wen = Wire(init = Fill(beatBytes, wipe))
|
|
|
|
val inc_bytes_wen = Wire(init = Fill(beatBytes, wipe))
|
|
|
|
val dec_bytes_wen = Wire(init = Fill(beatBytes, wipe))
|
|
|
|
val inc_trees_wen = Wire(init = Fill(decTrees, wipe))
|
|
|
|
val dec_trees_wen = Wire(init = Fill(decTrees, wipe))
|
|
|
|
|
2016-09-14 00:44:36 +02:00
|
|
|
// This must be registers b/c we build a CAM from it
|
|
|
|
val flight = Reg(Vec(endSourceId, new FlightMonitor))
|
|
|
|
val valid = Reg(Vec(endSourceId, Bool()))
|
2016-09-12 00:44:56 +02:00
|
|
|
|
|
|
|
// We want to cross flight data from A to D in the same cycle (for combinational TL2 devices)
|
|
|
|
val a_flight = Wire(new FlightMonitor)
|
|
|
|
a_flight.base := edge.address(in.a.bits)
|
|
|
|
a_flight.size := edge.size(in.a.bits)
|
|
|
|
a_flight.opcode := in.a.bits.opcode
|
|
|
|
|
2016-09-14 00:44:36 +02:00
|
|
|
flight(in.a.bits.source) := a_flight
|
2016-09-22 03:47:41 +02:00
|
|
|
val bypass = if (edge.manager.minLatency > 0) Bool(false) else in.a.valid && in.a.bits.source === out.d.bits.source
|
2016-09-14 00:44:36 +02:00
|
|
|
val d_flight = RegNext(Mux(bypass, a_flight, flight(out.d.bits.source)))
|
2016-09-10 05:57:20 +02:00
|
|
|
|
|
|
|
// Process A access requests
|
2016-09-10 09:24:57 +02:00
|
|
|
val a = Reg(next = in.a.bits)
|
|
|
|
val a_fire = Reg(next = in.a.fire(), init = Bool(false))
|
|
|
|
val a_beats1 = edge.numBeats1(a)
|
|
|
|
val a_size = edge.size(a)
|
2016-09-10 05:57:20 +02:00
|
|
|
val a_sizeOH = UIntToOH(a_size)
|
|
|
|
val a_counter = RegInit(UInt(0, width = maxLgBeats))
|
|
|
|
val a_counter1 = a_counter - UInt(1)
|
|
|
|
val a_first = a_counter === UInt(0)
|
2016-09-10 09:24:57 +02:00
|
|
|
val a_addr_hi = a.addr_hi | (a_beats1 & ~a_counter1)
|
|
|
|
val a_base = edge.address(a)
|
2016-09-10 05:57:20 +02:00
|
|
|
val a_mask = edge.mask(a_base, a_size)
|
2016-09-18 02:04:18 +02:00
|
|
|
val a_fifo = edge.manager.hasFifoIdFast(a_base)
|
2016-09-10 05:57:20 +02:00
|
|
|
|
|
|
|
// Grab the concurrency state we need
|
|
|
|
val a_inc_bytes = inc_bytes.map(_.read(a_addr_hi))
|
|
|
|
val a_dec_bytes = dec_bytes.map(_.read(a_addr_hi))
|
|
|
|
val a_inc_trees = inc_trees.zipWithIndex.map{ case (m, i) => m.read(a_addr_hi >> (i+1)) }
|
|
|
|
val a_dec_trees = dec_trees.zipWithIndex.map{ case (m, i) => m.read(a_addr_hi >> (i+1)) }
|
|
|
|
val a_inc_tree = a_inc_trees.fold(UInt(0))(_ + _)
|
|
|
|
val a_dec_tree = a_dec_trees.fold(UInt(0))(_ + _)
|
|
|
|
val a_inc = a_inc_bytes.map(_ + a_inc_tree)
|
|
|
|
val a_dec = a_dec_bytes.map(_ + a_dec_tree)
|
|
|
|
|
2016-09-10 09:24:57 +02:00
|
|
|
when (a_fire) {
|
2016-09-10 05:57:20 +02:00
|
|
|
// Record the request so we can handle it's response
|
|
|
|
a_counter := Mux(a_first, a_beats1, a_counter1)
|
|
|
|
|
2016-09-10 09:24:57 +02:00
|
|
|
assert (a.opcode =/= TLMessages.Acquire)
|
2016-09-10 05:57:20 +02:00
|
|
|
|
2016-09-14 00:44:36 +02:00
|
|
|
// Mark the operation as valid
|
|
|
|
valid(a.source) := Bool(true)
|
|
|
|
|
2016-09-10 05:57:20 +02:00
|
|
|
// Increase the per-byte flight counter for the whole transaction
|
2016-09-14 00:44:36 +02:00
|
|
|
when (a_first && a.opcode =/= TLMessages.Hint && a.opcode =/= TLMessages.Get) {
|
2016-09-10 05:57:20 +02:00
|
|
|
when (a_size <= UInt(shift)) {
|
2016-09-10 09:24:57 +02:00
|
|
|
inc_bytes_wen := a_mask
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
2016-09-10 09:24:57 +02:00
|
|
|
inc_trees_wen := a_sizeOH >> (shift+1)
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 02:08:29 +02:00
|
|
|
when (a.opcode === TLMessages.PutFullData || a.opcode === TLMessages.PutPartialData ||
|
|
|
|
a.opcode === TLMessages.ArithmeticData || a.opcode === TLMessages.LogicalData) {
|
2016-09-10 09:24:57 +02:00
|
|
|
shadow_wen := a.mask
|
2016-09-10 05:57:20 +02:00
|
|
|
for (i <- 0 until beatBytes) {
|
|
|
|
val busy = a_inc(i) - a_dec(i) - (!a_first).asUInt
|
2016-09-10 09:24:57 +02:00
|
|
|
val byte = a.data(8*(i+1)-1, 8*i)
|
|
|
|
when (a.mask(i)) {
|
2016-09-22 02:08:29 +02:00
|
|
|
when (a.opcode === TLMessages.PutFullData) { printf("PF") }
|
|
|
|
when (a.opcode === TLMessages.PutPartialData) { printf("PP") }
|
|
|
|
when (a.opcode === TLMessages.ArithmeticData) { printf("A ") }
|
|
|
|
when (a.opcode === TLMessages.LogicalData) { printf("L ") }
|
|
|
|
printf(" 0x%x := 0x%x #%d %x\n", a_addr_hi << shift | UInt(i), byte, busy, a.param)
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 00:44:36 +02:00
|
|
|
|
|
|
|
when (a.opcode === TLMessages.Get) {
|
2016-09-22 02:08:29 +02:00
|
|
|
printf("G 0x%x - 0%x\n", a_base, a_base | UIntToOH1(a_size, addressBits))
|
2016-09-14 00:44:36 +02:00
|
|
|
}
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-10 09:24:57 +02:00
|
|
|
val a_waddr = Mux(wipe, wipeIndex, a_addr_hi)
|
|
|
|
for (i <- 0 until beatBytes) {
|
|
|
|
val data = Wire(new ByteMonitor)
|
2016-09-14 00:44:36 +02:00
|
|
|
val busy = a_inc(i) =/= a_dec(i) + (!a_first).asUInt
|
2016-09-22 02:08:29 +02:00
|
|
|
val amo = a.opcode === TLMessages.ArithmeticData || a.opcode === TLMessages.LogicalData
|
|
|
|
data.valid := Mux(wipe, Bool(false), (!busy || a_fifo) && !amo)
|
|
|
|
// !!! calculate the AMO?
|
2016-09-10 09:24:57 +02:00
|
|
|
data.value := a.data(8*(i+1)-1, 8*i)
|
|
|
|
when (shadow_wen(i)) {
|
|
|
|
shadow(i).write(a_waddr, data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i <- 0 until beatBytes) {
|
|
|
|
val data = Mux(wipe, UInt(0), a_inc_bytes(i) + UInt(1))
|
|
|
|
when (inc_bytes_wen(i)) {
|
|
|
|
inc_bytes(i).write(a_waddr, data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i <- 0 until inc_trees.size) {
|
|
|
|
val data = Mux(wipe, UInt(0), a_inc_trees(i) + UInt(1))
|
|
|
|
when (inc_trees_wen(i)) {
|
|
|
|
inc_trees(i).write(a_waddr >> (i+1), data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 05:57:20 +02:00
|
|
|
// Process D access responses
|
2016-09-10 09:24:57 +02:00
|
|
|
val d = RegNext(out.d.bits)
|
|
|
|
val d_fire = Reg(next = out.d.fire(), init = Bool(false))
|
|
|
|
val d_beats1 = edge.numBeats1(d)
|
|
|
|
val d_size = edge.size(d)
|
2016-09-10 05:57:20 +02:00
|
|
|
val d_sizeOH = UIntToOH(d_size)
|
|
|
|
val d_counter = RegInit(UInt(0, width = maxLgBeats))
|
|
|
|
val d_counter1 = d_counter - UInt(1)
|
|
|
|
val d_first = d_counter === UInt(0)
|
|
|
|
val d_last = d_counter === UInt(1) || d_beats1 === UInt(0)
|
2016-09-12 00:44:56 +02:00
|
|
|
val d_base = d_flight.base
|
2016-09-10 05:57:20 +02:00
|
|
|
val d_addr_hi = d_base >> shift | (d_beats1 & ~d_counter1)
|
|
|
|
val d_mask = edge.mask(d_base, d_size)
|
2016-09-18 02:04:18 +02:00
|
|
|
val d_fifo = edge.manager.hasFifoIdFast(d_flight.base)
|
2016-09-10 05:57:20 +02:00
|
|
|
|
|
|
|
// Grab the concurrency state we need
|
|
|
|
val d_inc_bytes = inc_bytes.map(_.read(d_addr_hi))
|
|
|
|
val d_dec_bytes = dec_bytes.map(_.read(d_addr_hi))
|
|
|
|
val d_inc_trees = inc_trees.zipWithIndex.map{ case (m, i) => m.read(d_addr_hi >> (i+1)) }
|
|
|
|
val d_dec_trees = dec_trees.zipWithIndex.map{ case (m, i) => m.read(d_addr_hi >> (i+1)) }
|
|
|
|
val d_inc_tree = d_inc_trees.fold(UInt(0))(_ + _)
|
|
|
|
val d_dec_tree = d_dec_trees.fold(UInt(0))(_ + _)
|
|
|
|
val d_inc = d_inc_bytes.map(_ + d_inc_tree)
|
|
|
|
val d_dec = d_dec_bytes.map(_ + d_dec_tree)
|
|
|
|
val d_shadow = shadow.map(_.read(d_addr_hi))
|
2016-09-14 00:44:36 +02:00
|
|
|
val d_valid = valid(d.source)
|
2016-09-10 05:57:20 +02:00
|
|
|
|
2016-09-10 09:24:57 +02:00
|
|
|
when (d_fire) {
|
2016-09-10 05:57:20 +02:00
|
|
|
d_counter := Mux(d_first, d_beats1, d_counter1)
|
|
|
|
|
2016-09-14 00:44:36 +02:00
|
|
|
// Check the response is correct
|
|
|
|
assert (d_size === d_flight.size)
|
2016-09-18 02:04:18 +02:00
|
|
|
assert (edge.manager.findIdStartFast(d_flight.base) <= d.sink)
|
|
|
|
assert (edge.manager.findIdEndFast (d_flight.base) > d.sink)
|
2016-09-14 00:44:36 +02:00
|
|
|
// addr_lo is allowed to differ
|
|
|
|
|
2016-09-10 05:57:20 +02:00
|
|
|
when (d_flight.opcode === TLMessages.Hint) {
|
2016-09-10 09:24:57 +02:00
|
|
|
assert (d.opcode === TLMessages.HintAck)
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-14 00:44:36 +02:00
|
|
|
// Decrease the per-byte flight counter for the whole transaction
|
|
|
|
when (d_last && d_flight.opcode =/= TLMessages.Hint && d_flight.opcode =/= TLMessages.Get) {
|
2016-09-10 05:57:20 +02:00
|
|
|
when (d_size <= UInt(shift)) {
|
2016-09-10 09:24:57 +02:00
|
|
|
dec_bytes_wen := d_mask
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
2016-09-10 09:24:57 +02:00
|
|
|
dec_trees_wen := d_sizeOH >> (shift+1)
|
2016-09-14 00:44:36 +02:00
|
|
|
// NOTE: D channel carries uninterrupted multibeast op, so updating on last is fine
|
|
|
|
for (i <- 0 until endSourceId) {
|
|
|
|
// Does this modification overlap a Get? => wipe it's valid
|
|
|
|
val f_base = flight(i).base
|
|
|
|
val f_size = flight(i).size
|
|
|
|
val f_bits = UIntToOH1(f_size, addressBits)
|
|
|
|
val d_bits = UIntToOH1(d_size, addressBits)
|
|
|
|
val overlap = ~(~(f_base ^ d_base) | (f_bits | d_bits)) === UInt(0)
|
|
|
|
when (overlap) { valid(i) := Bool(false) }
|
|
|
|
}
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
when (d_flight.opcode === TLMessages.PutFullData || d_flight.opcode === TLMessages.PutPartialData) {
|
2016-09-10 09:24:57 +02:00
|
|
|
assert (d.opcode === TLMessages.AccessAck)
|
2016-09-22 02:08:29 +02:00
|
|
|
when (d_flight.opcode === TLMessages.PutFullData) { printf("pf") }
|
|
|
|
when (d_flight.opcode === TLMessages.PutPartialData) { printf("pp") }
|
|
|
|
printf(" 0x%x - 0x%x\n", d_base, d_base | UIntToOH1(d_size, addressBits))
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 02:08:29 +02:00
|
|
|
when (d_flight.opcode === TLMessages.Get || d_flight.opcode === TLMessages.ArithmeticData || d_flight.opcode === TLMessages.LogicalData) {
|
2016-09-10 09:24:57 +02:00
|
|
|
assert (d.opcode === TLMessages.AccessAckData)
|
2016-09-10 05:57:20 +02:00
|
|
|
for (i <- 0 until beatBytes) {
|
2016-09-10 09:24:57 +02:00
|
|
|
val got = d.data(8*(i+1)-1, 8*i)
|
2016-09-10 05:57:20 +02:00
|
|
|
val shadow = Wire(init = d_shadow(i))
|
|
|
|
when (d_mask(i)) {
|
2016-09-14 00:44:36 +02:00
|
|
|
val d_addr = d_addr_hi << shift | UInt(i)
|
2016-09-22 02:08:29 +02:00
|
|
|
when (d_flight.opcode === TLMessages.Get) { printf("g ") }
|
|
|
|
when (d_flight.opcode === TLMessages.ArithmeticData) { printf("a ") }
|
|
|
|
when (d_flight.opcode === TLMessages.LogicalData) { printf("l ") }
|
|
|
|
printf(" 0x%x := 0x%x", d_addr, got)
|
2016-09-10 05:57:20 +02:00
|
|
|
when (!shadow.valid) {
|
2016-09-22 02:08:29 +02:00
|
|
|
printf(", undefined (uninitialized or prior overlapping puts)\n")
|
2016-09-14 00:44:36 +02:00
|
|
|
} .elsewhen (d_inc(i) =/= d_dec(i)) {
|
2016-09-22 02:08:29 +02:00
|
|
|
printf(", undefined (concurrent incomplete puts #%d)\n", d_inc(i) - d_dec(i))
|
2016-09-14 00:44:36 +02:00
|
|
|
} .elsewhen (!d_fifo && !d_valid) {
|
2016-09-22 02:08:29 +02:00
|
|
|
printf(", undefined (concurrent completed put)\n")
|
2016-09-10 05:57:20 +02:00
|
|
|
} .otherwise {
|
2016-09-22 02:08:29 +02:00
|
|
|
printf("\n")
|
2016-09-10 05:57:20 +02:00
|
|
|
assert (shadow.value === got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-10 09:24:57 +02:00
|
|
|
|
|
|
|
val d_waddr = Mux(wipe, wipeIndex, d_addr_hi)
|
|
|
|
for (i <- 0 until beatBytes) {
|
|
|
|
val data = Mux(wipe, UInt(0), d_dec_bytes(i) + UInt(1))
|
|
|
|
when (dec_bytes_wen(i)) {
|
|
|
|
dec_bytes(i).write(d_waddr, data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i <- 0 until dec_trees.size) {
|
|
|
|
val data = Mux(wipe, UInt(0), d_dec_trees(i) + UInt(1))
|
|
|
|
when (dec_trees_wen(i)) {
|
|
|
|
dec_trees(i).write(d_waddr >> (i+1), data)
|
|
|
|
}
|
|
|
|
}
|
2016-09-10 05:57:20 +02:00
|
|
|
}
|
|
|
|
}
|