2015-08-06 12:48:35 -07:00
|
|
|
/// See LICENSE for license details.
|
2015-07-29 18:02:58 -07:00
|
|
|
|
|
|
|
package junctions
|
|
|
|
import Chisel._
|
|
|
|
import scala.math.max
|
2015-08-06 12:48:35 -07:00
|
|
|
import scala.collection.mutable.ArraySeq
|
2015-10-21 18:15:46 -07:00
|
|
|
import cde.{Parameters, Field}
|
2015-07-29 18:02:58 -07:00
|
|
|
|
2015-10-05 20:33:55 -07:00
|
|
|
case object NastiKey extends Field[NastiParameters]
|
2015-07-29 18:02:58 -07:00
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
case class NastiParameters(dataBits: Int, addrBits: Int, idBits: Int)
|
2015-08-06 12:48:35 -07:00
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
trait HasNastiParameters {
|
|
|
|
implicit val p: Parameters
|
2016-01-28 14:50:24 -08:00
|
|
|
val nastiExternal = p(NastiKey)
|
|
|
|
val nastiXDataBits = nastiExternal.dataBits
|
2015-07-29 18:02:58 -07:00
|
|
|
val nastiWStrobeBits = nastiXDataBits / 8
|
2016-01-28 14:50:24 -08:00
|
|
|
val nastiXAddrBits = nastiExternal.addrBits
|
|
|
|
val nastiWIdBits = nastiExternal.idBits
|
|
|
|
val nastiRIdBits = nastiExternal.idBits
|
2015-07-29 18:02:58 -07:00
|
|
|
val nastiXIdBits = max(nastiWIdBits, nastiRIdBits)
|
|
|
|
val nastiXUserBits = 1
|
|
|
|
val nastiAWUserBits = nastiXUserBits
|
|
|
|
val nastiWUserBits = nastiXUserBits
|
|
|
|
val nastiBUserBits = nastiXUserBits
|
|
|
|
val nastiARUserBits = nastiXUserBits
|
|
|
|
val nastiRUserBits = nastiXUserBits
|
|
|
|
val nastiXLenBits = 8
|
|
|
|
val nastiXSizeBits = 3
|
|
|
|
val nastiXBurstBits = 2
|
|
|
|
val nastiXCacheBits = 4
|
|
|
|
val nastiXProtBits = 3
|
|
|
|
val nastiXQosBits = 4
|
|
|
|
val nastiXRegionBits = 4
|
|
|
|
val nastiXRespBits = 2
|
|
|
|
|
|
|
|
def bytesToXSize(bytes: UInt) = MuxLookup(bytes, UInt("b111"), Array(
|
|
|
|
UInt(1) -> UInt(0),
|
|
|
|
UInt(2) -> UInt(1),
|
|
|
|
UInt(4) -> UInt(2),
|
|
|
|
UInt(8) -> UInt(3),
|
|
|
|
UInt(16) -> UInt(4),
|
|
|
|
UInt(32) -> UInt(5),
|
|
|
|
UInt(64) -> UInt(6),
|
|
|
|
UInt(128) -> UInt(7)))
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:33:55 -07:00
|
|
|
abstract class NastiModule(implicit val p: Parameters) extends Module
|
|
|
|
with HasNastiParameters
|
|
|
|
abstract class NastiBundle(implicit val p: Parameters) extends ParameterizedBundle()(p)
|
2015-10-02 15:37:41 -07:00
|
|
|
with HasNastiParameters
|
2015-07-29 18:02:58 -07:00
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
abstract class NastiChannel(implicit p: Parameters) extends NastiBundle()(p)
|
|
|
|
abstract class NastiMasterToSlaveChannel(implicit p: Parameters) extends NastiChannel()(p)
|
|
|
|
abstract class NastiSlaveToMasterChannel(implicit p: Parameters) extends NastiChannel()(p)
|
|
|
|
|
|
|
|
trait HasNastiMetadata extends HasNastiParameters {
|
2015-07-29 18:02:58 -07:00
|
|
|
val addr = UInt(width = nastiXAddrBits)
|
|
|
|
val len = UInt(width = nastiXLenBits)
|
|
|
|
val size = UInt(width = nastiXSizeBits)
|
|
|
|
val burst = UInt(width = nastiXBurstBits)
|
|
|
|
val lock = Bool()
|
|
|
|
val cache = UInt(width = nastiXCacheBits)
|
|
|
|
val prot = UInt(width = nastiXProtBits)
|
|
|
|
val qos = UInt(width = nastiXQosBits)
|
|
|
|
val region = UInt(width = nastiXRegionBits)
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
trait HasNastiData extends HasNastiParameters {
|
2015-07-29 18:02:58 -07:00
|
|
|
val data = UInt(width = nastiXDataBits)
|
|
|
|
val last = Bool()
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:33:55 -07:00
|
|
|
class NastiIO(implicit val p: Parameters) extends ParameterizedBundle()(p) {
|
2015-10-02 14:19:51 -07:00
|
|
|
val aw = Decoupled(new NastiWriteAddressChannel)
|
|
|
|
val w = Decoupled(new NastiWriteDataChannel)
|
|
|
|
val b = Decoupled(new NastiWriteResponseChannel).flip
|
|
|
|
val ar = Decoupled(new NastiReadAddressChannel)
|
|
|
|
val r = Decoupled(new NastiReadDataChannel).flip
|
|
|
|
}
|
|
|
|
|
|
|
|
class NastiAddressChannel(implicit p: Parameters) extends NastiMasterToSlaveChannel()(p)
|
|
|
|
with HasNastiMetadata
|
2015-07-29 18:02:58 -07:00
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiResponseChannel(implicit p: Parameters) extends NastiSlaveToMasterChannel()(p) {
|
2015-07-29 18:02:58 -07:00
|
|
|
val resp = UInt(width = nastiXRespBits)
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiWriteAddressChannel(implicit p: Parameters) extends NastiAddressChannel()(p) {
|
2015-07-29 18:02:58 -07:00
|
|
|
val id = UInt(width = nastiWIdBits)
|
|
|
|
val user = UInt(width = nastiAWUserBits)
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiWriteDataChannel(implicit p: Parameters) extends NastiMasterToSlaveChannel()(p)
|
|
|
|
with HasNastiData {
|
2015-07-29 18:02:58 -07:00
|
|
|
val strb = UInt(width = nastiWStrobeBits)
|
|
|
|
val user = UInt(width = nastiWUserBits)
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiWriteResponseChannel(implicit p: Parameters) extends NastiResponseChannel()(p) {
|
2015-07-29 18:02:58 -07:00
|
|
|
val id = UInt(width = nastiWIdBits)
|
|
|
|
val user = UInt(width = nastiBUserBits)
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiReadAddressChannel(implicit p: Parameters) extends NastiAddressChannel()(p) {
|
2015-07-29 18:02:58 -07:00
|
|
|
val id = UInt(width = nastiRIdBits)
|
|
|
|
val user = UInt(width = nastiARUserBits)
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiReadDataChannel(implicit p: Parameters) extends NastiResponseChannel()(p)
|
|
|
|
with HasNastiData {
|
2015-07-29 18:02:58 -07:00
|
|
|
val id = UInt(width = nastiRIdBits)
|
|
|
|
val user = UInt(width = nastiRUserBits)
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:04:49 -08:00
|
|
|
object NastiConstants {
|
|
|
|
val BURST_FIXED = UInt("b00")
|
|
|
|
val BURST_INCR = UInt("b01")
|
|
|
|
val BURST_WRAP = UInt("b10")
|
|
|
|
|
|
|
|
val RESP_OKAY = UInt("b00")
|
|
|
|
val RESP_EXOKAY = UInt("b01")
|
|
|
|
val RESP_SLVERR = UInt("b10")
|
|
|
|
val RESP_DECERR = UInt("b11")
|
|
|
|
}
|
|
|
|
|
|
|
|
import NastiConstants._
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
object NastiWriteAddressChannel {
|
2016-01-05 20:04:49 -08:00
|
|
|
def apply(id: UInt, addr: UInt, size: UInt,
|
|
|
|
len: UInt = UInt(0), burst: UInt = BURST_INCR)
|
|
|
|
(implicit p: Parameters) = {
|
2015-10-02 14:19:51 -07:00
|
|
|
val aw = Wire(new NastiWriteAddressChannel)
|
2015-09-10 17:32:40 -07:00
|
|
|
aw.id := id
|
|
|
|
aw.addr := addr
|
|
|
|
aw.len := len
|
|
|
|
aw.size := size
|
2016-01-05 20:04:49 -08:00
|
|
|
aw.burst := burst
|
2015-09-10 17:32:40 -07:00
|
|
|
aw.lock := Bool(false)
|
|
|
|
aw.cache := UInt("b0000")
|
|
|
|
aw.prot := UInt("b000")
|
|
|
|
aw.qos := UInt("b0000")
|
|
|
|
aw.region := UInt("b0000")
|
|
|
|
aw.user := UInt(0)
|
|
|
|
aw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
object NastiReadAddressChannel {
|
2016-01-05 20:04:49 -08:00
|
|
|
def apply(id: UInt, addr: UInt, size: UInt,
|
|
|
|
len: UInt = UInt(0), burst: UInt = BURST_INCR)
|
|
|
|
(implicit p: Parameters) = {
|
2015-10-02 14:19:51 -07:00
|
|
|
val ar = Wire(new NastiReadAddressChannel)
|
2015-09-10 17:32:40 -07:00
|
|
|
ar.id := id
|
|
|
|
ar.addr := addr
|
|
|
|
ar.len := len
|
|
|
|
ar.size := size
|
2016-01-05 20:04:49 -08:00
|
|
|
ar.burst := burst
|
2015-09-10 17:32:40 -07:00
|
|
|
ar.lock := Bool(false)
|
|
|
|
ar.cache := UInt(0)
|
|
|
|
ar.prot := UInt(0)
|
|
|
|
ar.qos := UInt(0)
|
|
|
|
ar.region := UInt(0)
|
|
|
|
ar.user := UInt(0)
|
|
|
|
ar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
object NastiWriteDataChannel {
|
|
|
|
def apply(data: UInt, last: Bool = Bool(true))(implicit p: Parameters): NastiWriteDataChannel = {
|
|
|
|
val w = Wire(new NastiWriteDataChannel)
|
|
|
|
w.strb := Fill(w.nastiWStrobeBits, UInt(1, 1))
|
2015-09-10 17:32:40 -07:00
|
|
|
w.data := data
|
|
|
|
w.last := last
|
|
|
|
w.user := UInt(0)
|
|
|
|
w
|
|
|
|
}
|
2015-10-02 14:19:51 -07:00
|
|
|
def apply(data: UInt, strb: UInt, last: Bool)
|
|
|
|
(implicit p: Parameters): NastiWriteDataChannel = {
|
|
|
|
val w = apply(data, last)
|
|
|
|
w.strb := strb
|
|
|
|
w
|
|
|
|
}
|
2015-09-10 17:32:40 -07:00
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
object NastiReadDataChannel {
|
|
|
|
def apply(id: UInt, data: UInt, last: Bool = Bool(true), resp: UInt = UInt(0))(
|
|
|
|
implicit p: Parameters) = {
|
|
|
|
val r = Wire(new NastiReadDataChannel)
|
2015-09-10 17:32:40 -07:00
|
|
|
r.id := id
|
|
|
|
r.data := data
|
|
|
|
r.last := last
|
|
|
|
r.resp := resp
|
|
|
|
r.user := UInt(0)
|
|
|
|
r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
object NastiWriteResponseChannel {
|
|
|
|
def apply(id: UInt, resp: UInt = UInt(0))(implicit p: Parameters) = {
|
|
|
|
val b = Wire(new NastiWriteResponseChannel)
|
2015-09-10 17:32:40 -07:00
|
|
|
b.id := id
|
|
|
|
b.resp := resp
|
|
|
|
b.user := UInt(0)
|
|
|
|
b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:33:55 -07:00
|
|
|
class MemIONastiIOConverter(cacheBlockOffsetBits: Int)(implicit p: Parameters) extends MIFModule
|
2015-10-02 14:19:51 -07:00
|
|
|
with HasNastiParameters {
|
2015-07-29 18:02:58 -07:00
|
|
|
val io = new Bundle {
|
2015-10-02 14:19:51 -07:00
|
|
|
val nasti = (new NastiIO).flip
|
2015-07-29 18:02:58 -07:00
|
|
|
val mem = new MemIO
|
|
|
|
}
|
|
|
|
|
|
|
|
require(mifDataBits == nastiXDataBits, "Data sizes between LLC and MC don't agree")
|
|
|
|
val (mif_cnt_out, mif_wrap_out) = Counter(io.mem.resp.fire(), mifDataBeats)
|
2015-08-06 12:46:32 -07:00
|
|
|
|
2015-09-10 17:55:10 -07:00
|
|
|
assert(!io.nasti.aw.valid || io.nasti.aw.bits.size === UInt(log2Up(mifDataBits/8)),
|
2015-10-02 14:19:51 -07:00
|
|
|
"Nasti data size does not match MemIO data size")
|
2015-09-10 17:55:10 -07:00
|
|
|
assert(!io.nasti.ar.valid || io.nasti.ar.bits.size === UInt(log2Up(mifDataBits/8)),
|
2015-10-02 14:19:51 -07:00
|
|
|
"Nasti data size does not match MemIO data size")
|
2015-09-10 17:55:10 -07:00
|
|
|
assert(!io.nasti.aw.valid || io.nasti.aw.bits.len === UInt(mifDataBeats - 1),
|
2015-10-02 14:19:51 -07:00
|
|
|
"Nasti length does not match number of MemIO beats")
|
2015-09-10 17:55:10 -07:00
|
|
|
assert(!io.nasti.ar.valid || io.nasti.ar.bits.len === UInt(mifDataBeats - 1),
|
2015-10-02 14:19:51 -07:00
|
|
|
"Nasti length does not match number of MemIO beats")
|
2015-09-10 17:55:10 -07:00
|
|
|
|
2015-08-06 12:46:32 -07:00
|
|
|
// according to the spec, we can't send b until the last transfer on w
|
|
|
|
val b_ok = Reg(init = Bool(true))
|
|
|
|
when (io.nasti.aw.fire()) { b_ok := Bool(false) }
|
|
|
|
when (io.nasti.w.fire() && io.nasti.w.bits.last) { b_ok := Bool(true) }
|
|
|
|
|
|
|
|
val id_q = Module(new Queue(UInt(width = nastiWIdBits), 2))
|
2015-10-19 21:43:59 -07:00
|
|
|
id_q.io.enq.valid := io.nasti.aw.valid && io.mem.req_cmd.ready
|
2015-08-06 12:46:32 -07:00
|
|
|
id_q.io.enq.bits := io.nasti.aw.bits.id
|
|
|
|
id_q.io.deq.ready := io.nasti.b.ready && b_ok
|
|
|
|
|
2015-07-29 18:02:58 -07:00
|
|
|
io.mem.req_cmd.bits.addr := Mux(io.nasti.aw.valid, io.nasti.aw.bits.addr, io.nasti.ar.bits.addr) >>
|
|
|
|
UInt(cacheBlockOffsetBits)
|
|
|
|
io.mem.req_cmd.bits.tag := Mux(io.nasti.aw.valid, io.nasti.aw.bits.id, io.nasti.ar.bits.id)
|
|
|
|
io.mem.req_cmd.bits.rw := io.nasti.aw.valid
|
2015-08-06 12:46:32 -07:00
|
|
|
io.mem.req_cmd.valid := (io.nasti.aw.valid && id_q.io.enq.ready) || io.nasti.ar.valid
|
2015-07-29 18:02:58 -07:00
|
|
|
io.nasti.ar.ready := io.mem.req_cmd.ready && !io.nasti.aw.valid
|
2015-08-06 12:46:32 -07:00
|
|
|
io.nasti.aw.ready := io.mem.req_cmd.ready && id_q.io.enq.ready
|
2015-07-29 18:02:58 -07:00
|
|
|
|
2015-08-06 12:46:32 -07:00
|
|
|
io.nasti.b.valid := id_q.io.deq.valid && b_ok
|
|
|
|
io.nasti.b.bits.id := id_q.io.deq.bits
|
2015-07-29 18:02:58 -07:00
|
|
|
io.nasti.b.bits.resp := UInt(0)
|
|
|
|
|
|
|
|
io.nasti.w.ready := io.mem.req_data.ready
|
|
|
|
io.mem.req_data.valid := io.nasti.w.valid
|
|
|
|
io.mem.req_data.bits.data := io.nasti.w.bits.data
|
|
|
|
assert(!io.nasti.w.valid || io.nasti.w.bits.strb.andR, "MemIO must write full cache line")
|
|
|
|
|
|
|
|
io.nasti.r.valid := io.mem.resp.valid
|
|
|
|
io.nasti.r.bits.data := io.mem.resp.bits.data
|
|
|
|
io.nasti.r.bits.last := mif_wrap_out
|
|
|
|
io.nasti.r.bits.id := io.mem.resp.bits.tag
|
|
|
|
io.nasti.r.bits.resp := UInt(0)
|
|
|
|
io.mem.resp.ready := io.nasti.r.ready
|
|
|
|
}
|
2015-08-06 12:48:35 -07:00
|
|
|
|
2015-09-10 17:33:48 -07:00
|
|
|
/** Arbitrate among arbN masters requesting to a single slave */
|
2015-10-05 20:33:55 -07:00
|
|
|
class NastiArbiter(val arbN: Int)(implicit p: Parameters) extends NastiModule {
|
2015-08-06 12:48:35 -07:00
|
|
|
val io = new Bundle {
|
2016-01-14 13:38:00 -08:00
|
|
|
val master = Vec(arbN, new NastiIO).flip
|
2015-10-02 14:19:51 -07:00
|
|
|
val slave = new NastiIO
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (arbN > 1) {
|
|
|
|
val arbIdBits = log2Up(arbN)
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
val ar_arb = Module(new RRArbiter(new NastiReadAddressChannel, arbN))
|
|
|
|
val aw_arb = Module(new RRArbiter(new NastiWriteAddressChannel, arbN))
|
2015-08-06 12:48:35 -07:00
|
|
|
|
|
|
|
val slave_r_arb_id = io.slave.r.bits.id(arbIdBits - 1, 0)
|
|
|
|
val slave_b_arb_id = io.slave.b.bits.id(arbIdBits - 1, 0)
|
|
|
|
|
|
|
|
val w_chosen = Reg(UInt(width = arbIdBits))
|
|
|
|
val w_done = Reg(init = Bool(true))
|
|
|
|
|
|
|
|
when (aw_arb.io.out.fire()) {
|
|
|
|
w_chosen := aw_arb.io.chosen
|
|
|
|
w_done := Bool(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
when (io.slave.w.fire() && io.slave.w.bits.last) {
|
|
|
|
w_done := Bool(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i <- 0 until arbN) {
|
|
|
|
val m_ar = io.master(i).ar
|
|
|
|
val m_aw = io.master(i).aw
|
|
|
|
val m_r = io.master(i).r
|
|
|
|
val m_b = io.master(i).b
|
|
|
|
val a_ar = ar_arb.io.in(i)
|
|
|
|
val a_aw = aw_arb.io.in(i)
|
|
|
|
val m_w = io.master(i).w
|
|
|
|
|
|
|
|
a_ar <> m_ar
|
|
|
|
a_ar.bits.id := Cat(m_ar.bits.id, UInt(i, arbIdBits))
|
|
|
|
|
|
|
|
a_aw <> m_aw
|
|
|
|
a_aw.bits.id := Cat(m_aw.bits.id, UInt(i, arbIdBits))
|
|
|
|
|
|
|
|
m_r.valid := io.slave.r.valid && slave_r_arb_id === UInt(i)
|
|
|
|
m_r.bits := io.slave.r.bits
|
|
|
|
m_r.bits.id := io.slave.r.bits.id >> UInt(arbIdBits)
|
|
|
|
|
|
|
|
m_b.valid := io.slave.b.valid && slave_b_arb_id === UInt(i)
|
|
|
|
m_b.bits := io.slave.b.bits
|
|
|
|
m_b.bits.id := io.slave.b.bits.id >> UInt(arbIdBits)
|
|
|
|
|
|
|
|
m_w.ready := io.slave.w.ready && w_chosen === UInt(i) && !w_done
|
|
|
|
}
|
|
|
|
|
|
|
|
io.slave.r.ready := io.master(slave_r_arb_id).r.ready
|
|
|
|
io.slave.b.ready := io.master(slave_b_arb_id).b.ready
|
|
|
|
|
|
|
|
io.slave.w.bits := io.master(w_chosen).w.bits
|
|
|
|
io.slave.w.valid := io.master(w_chosen).w.valid && !w_done
|
|
|
|
|
|
|
|
io.slave.ar <> ar_arb.io.out
|
2015-09-25 11:03:24 -07:00
|
|
|
|
|
|
|
io.slave.aw.bits <> aw_arb.io.out.bits
|
|
|
|
io.slave.aw.valid := aw_arb.io.out.valid && w_done
|
2015-08-06 12:48:35 -07:00
|
|
|
aw_arb.io.out.ready := io.slave.aw.ready && w_done
|
|
|
|
|
|
|
|
} else { io.slave <> io.master.head }
|
|
|
|
}
|
|
|
|
|
|
|
|
/** A slave that send decode error for every request it receives */
|
2015-10-05 20:33:55 -07:00
|
|
|
class NastiErrorSlave(implicit p: Parameters) extends NastiModule {
|
2015-10-02 14:19:51 -07:00
|
|
|
val io = (new NastiIO).flip
|
2015-08-06 12:48:35 -07:00
|
|
|
|
2015-09-18 09:42:41 -07:00
|
|
|
when (io.ar.fire()) { printf("Invalid read address %x\n", io.ar.bits.addr) }
|
|
|
|
when (io.aw.fire()) { printf("Invalid write address %x\n", io.aw.bits.addr) }
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
val r_queue = Module(new Queue(new NastiReadAddressChannel, 2))
|
2015-09-22 09:42:57 -07:00
|
|
|
r_queue.io.enq <> io.ar
|
|
|
|
|
|
|
|
val responding = Reg(init = Bool(false))
|
|
|
|
val beats_left = Reg(init = UInt(0, nastiXLenBits))
|
|
|
|
|
|
|
|
when (!responding && r_queue.io.deq.valid) {
|
|
|
|
responding := Bool(true)
|
|
|
|
beats_left := r_queue.io.deq.bits.len
|
|
|
|
}
|
|
|
|
|
|
|
|
io.r.valid := r_queue.io.deq.valid && responding
|
|
|
|
io.r.bits.id := r_queue.io.deq.bits.id
|
|
|
|
io.r.bits.data := UInt(0)
|
2016-01-05 20:04:49 -08:00
|
|
|
io.r.bits.resp := RESP_DECERR
|
2015-09-22 09:42:57 -07:00
|
|
|
io.r.bits.last := beats_left === UInt(0)
|
|
|
|
|
|
|
|
r_queue.io.deq.ready := io.r.fire() && io.r.bits.last
|
|
|
|
|
|
|
|
when (io.r.fire()) {
|
|
|
|
when (beats_left === UInt(0)) {
|
|
|
|
responding := Bool(false)
|
|
|
|
} .otherwise {
|
2015-11-26 12:57:04 -08:00
|
|
|
beats_left := beats_left - UInt(1)
|
2015-09-22 09:42:57 -07:00
|
|
|
}
|
|
|
|
}
|
2015-08-06 12:48:35 -07:00
|
|
|
|
|
|
|
val draining = Reg(init = Bool(false))
|
|
|
|
io.w.ready := draining
|
|
|
|
|
|
|
|
when (io.aw.fire()) { draining := Bool(true) }
|
|
|
|
when (io.w.fire() && io.w.bits.last) { draining := Bool(false) }
|
|
|
|
|
|
|
|
val b_queue = Module(new Queue(UInt(width = nastiWIdBits), 2))
|
|
|
|
b_queue.io.enq.valid := io.aw.valid && !draining
|
|
|
|
b_queue.io.enq.bits := io.aw.bits.id
|
|
|
|
io.aw.ready := b_queue.io.enq.ready && !draining
|
|
|
|
io.b.valid := b_queue.io.deq.valid && !draining
|
|
|
|
io.b.bits.id := b_queue.io.deq.bits
|
|
|
|
io.b.bits.resp := Bits("b11")
|
|
|
|
b_queue.io.deq.ready := io.b.ready && !draining
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
/** Take a single Nasti master and route its requests to various slaves
|
2015-10-23 16:25:17 -07:00
|
|
|
* @param nSlaves the number of slaves
|
|
|
|
* @param routeSel a function which takes an address and produces
|
|
|
|
* a one-hot encoded selection of the slave to write to */
|
|
|
|
class NastiRouter(nSlaves: Int, routeSel: UInt => UInt)(implicit p: Parameters)
|
|
|
|
extends NastiModule {
|
2015-08-06 12:48:35 -07:00
|
|
|
|
|
|
|
val io = new Bundle {
|
2015-10-02 14:19:51 -07:00
|
|
|
val master = (new NastiIO).flip
|
2016-01-14 13:38:00 -08:00
|
|
|
val slave = Vec(nSlaves, new NastiIO)
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
val ar_route = routeSel(io.master.ar.bits.addr)
|
|
|
|
val aw_route = routeSel(io.master.aw.bits.addr)
|
|
|
|
|
2015-08-06 12:48:35 -07:00
|
|
|
var ar_ready = Bool(false)
|
|
|
|
var aw_ready = Bool(false)
|
|
|
|
var w_ready = Bool(false)
|
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
io.slave.zipWithIndex.foreach { case (s, i) =>
|
|
|
|
s.ar.valid := io.master.ar.valid && ar_route(i)
|
2015-08-06 12:48:35 -07:00
|
|
|
s.ar.bits := io.master.ar.bits
|
2015-10-23 16:25:17 -07:00
|
|
|
ar_ready = ar_ready || (s.ar.ready && ar_route(i))
|
2015-08-06 12:48:35 -07:00
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
s.aw.valid := io.master.aw.valid && aw_route(i)
|
2015-08-06 12:48:35 -07:00
|
|
|
s.aw.bits := io.master.aw.bits
|
2015-10-23 16:25:17 -07:00
|
|
|
aw_ready = aw_ready || (s.aw.ready && aw_route(i))
|
2015-08-06 12:48:35 -07:00
|
|
|
|
|
|
|
val chosen = Reg(init = Bool(false))
|
|
|
|
when (s.w.fire() && s.w.bits.last) { chosen := Bool(false) }
|
2016-03-28 12:22:43 -07:00
|
|
|
when (s.aw.fire()) { chosen := Bool(true) }
|
2015-08-06 12:48:35 -07:00
|
|
|
|
|
|
|
s.w.valid := io.master.w.valid && chosen
|
|
|
|
s.w.bits := io.master.w.bits
|
|
|
|
w_ready = w_ready || (s.w.ready && chosen)
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
val r_invalid = !ar_route.orR
|
|
|
|
val w_invalid = !aw_route.orR
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
val err_slave = Module(new NastiErrorSlave)
|
2015-10-23 16:25:17 -07:00
|
|
|
err_slave.io.ar.valid := r_invalid && io.master.ar.valid
|
2015-08-06 12:48:35 -07:00
|
|
|
err_slave.io.ar.bits := io.master.ar.bits
|
2015-10-23 16:25:17 -07:00
|
|
|
err_slave.io.aw.valid := w_invalid && io.master.aw.valid
|
2015-08-06 12:48:35 -07:00
|
|
|
err_slave.io.aw.bits := io.master.aw.bits
|
|
|
|
err_slave.io.w.valid := io.master.w.valid
|
|
|
|
err_slave.io.w.bits := io.master.w.bits
|
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
io.master.ar.ready := ar_ready || (r_invalid && err_slave.io.ar.ready)
|
|
|
|
io.master.aw.ready := aw_ready || (w_invalid && err_slave.io.aw.ready)
|
2015-08-06 12:48:35 -07:00
|
|
|
io.master.w.ready := w_ready || err_slave.io.w.ready
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
val b_arb = Module(new RRArbiter(new NastiWriteResponseChannel, nSlaves + 1))
|
2015-10-20 18:36:19 -07:00
|
|
|
val r_arb = Module(new JunctionsPeekingArbiter(
|
|
|
|
new NastiReadDataChannel, nSlaves + 1,
|
|
|
|
// we can unlock if it's the last beat
|
|
|
|
(r: NastiReadDataChannel) => r.last))
|
2015-08-06 12:48:35 -07:00
|
|
|
|
|
|
|
for (i <- 0 until nSlaves) {
|
|
|
|
b_arb.io.in(i) <> io.slave(i).b
|
|
|
|
r_arb.io.in(i) <> io.slave(i).r
|
|
|
|
}
|
|
|
|
|
|
|
|
b_arb.io.in(nSlaves) <> err_slave.io.b
|
|
|
|
r_arb.io.in(nSlaves) <> err_slave.io.r
|
|
|
|
|
|
|
|
io.master.b <> b_arb.io.out
|
|
|
|
io.master.r <> r_arb.io.out
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
/** Crossbar between multiple Nasti masters and slaves
|
|
|
|
* @param nMasters the number of Nasti masters
|
|
|
|
* @param nSlaves the number of Nasti slaves
|
2015-10-23 16:25:17 -07:00
|
|
|
* @param routeSel a function selecting the slave to route an address to */
|
|
|
|
class NastiCrossbar(nMasters: Int, nSlaves: Int, routeSel: UInt => UInt)
|
2015-10-05 20:33:55 -07:00
|
|
|
(implicit p: Parameters) extends NastiModule {
|
2015-08-06 12:48:35 -07:00
|
|
|
val io = new Bundle {
|
2016-01-14 13:38:00 -08:00
|
|
|
val masters = Vec(nMasters, new NastiIO).flip
|
|
|
|
val slaves = Vec(nSlaves, new NastiIO)
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
if (nMasters == 1) {
|
|
|
|
val router = Module(new NastiRouter(nSlaves, routeSel))
|
|
|
|
router.io.master <> io.masters.head
|
|
|
|
io.slaves <> router.io.slave
|
|
|
|
} else {
|
|
|
|
val routers = Vec.fill(nMasters) { Module(new NastiRouter(nSlaves, routeSel)).io }
|
|
|
|
val arbiters = Vec.fill(nSlaves) { Module(new NastiArbiter(nMasters)).io }
|
2015-08-06 12:48:35 -07:00
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
for (i <- 0 until nMasters) {
|
|
|
|
routers(i).master <> io.masters(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i <- 0 until nSlaves) {
|
|
|
|
arbiters(i).master <> Vec(routers.map(r => r.slave(i)))
|
|
|
|
io.slaves(i) <> arbiters(i).slave
|
|
|
|
}
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
2015-10-23 16:25:17 -07:00
|
|
|
}
|
2015-08-06 12:48:35 -07:00
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiInterconnectIO(val nMasters: Int, val nSlaves: Int)
|
|
|
|
(implicit p: Parameters) extends Bundle {
|
2015-08-06 12:48:35 -07:00
|
|
|
/* This is a bit confusing. The interconnect is a slave to the masters and
|
|
|
|
* a master to the slaves. Hence why the declarations seem to be backwards. */
|
2016-01-14 13:38:00 -08:00
|
|
|
val masters = Vec(nMasters, new NastiIO).flip
|
|
|
|
val slaves = Vec(nSlaves, new NastiIO)
|
2015-08-06 12:48:35 -07:00
|
|
|
override def cloneType =
|
2015-10-02 14:19:51 -07:00
|
|
|
new NastiInterconnectIO(nMasters, nSlaves).asInstanceOf[this.type]
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:33:55 -07:00
|
|
|
abstract class NastiInterconnect(implicit p: Parameters) extends NastiModule()(p) {
|
2015-08-06 12:48:35 -07:00
|
|
|
val nMasters: Int
|
|
|
|
val nSlaves: Int
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
lazy val io = new NastiInterconnectIO(nMasters, nSlaves)
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-02 14:19:51 -07:00
|
|
|
class NastiRecursiveInterconnect(
|
2016-01-14 16:41:32 -08:00
|
|
|
val nMasters: Int, val nSlaves: Int,
|
|
|
|
addrmap: AddrMap, base: BigInt)
|
2015-11-18 12:15:56 -08:00
|
|
|
(implicit p: Parameters) extends NastiInterconnect()(p) {
|
2015-08-06 12:48:35 -07:00
|
|
|
var lastEnd = base
|
|
|
|
var slaveInd = 0
|
|
|
|
val levelSize = addrmap.size
|
|
|
|
val realAddrMap = new ArraySeq[(BigInt, BigInt)](addrmap.size)
|
|
|
|
|
2015-11-18 12:15:56 -08:00
|
|
|
addrmap.zipWithIndex.foreach { case (AddrMapEntry(name, startOpt, region), i) =>
|
2015-08-06 12:48:35 -07:00
|
|
|
val start = startOpt.getOrElse(lastEnd)
|
|
|
|
val size = region.size
|
2015-11-18 12:15:56 -08:00
|
|
|
|
|
|
|
require(bigIntPow2(size),
|
|
|
|
s"Region $name size $size is not a power of 2")
|
|
|
|
require(start % size == 0,
|
|
|
|
f"Region $name start address 0x$start%x not divisible by 0x$size%x" )
|
2016-01-14 16:41:32 -08:00
|
|
|
require(start >= lastEnd,
|
|
|
|
f"Region $name start address 0x$start%x before previous region end")
|
|
|
|
|
|
|
|
realAddrMap(i) = (start, size)
|
|
|
|
lastEnd = start + size
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
val routeSel = (addr: UInt) => {
|
|
|
|
Vec(realAddrMap.map { case (start, size) =>
|
|
|
|
addr >= UInt(start) && addr < UInt(start + size)
|
|
|
|
}).toBits
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:25:17 -07:00
|
|
|
val xbar = Module(new NastiCrossbar(nMasters, levelSize, routeSel))
|
|
|
|
xbar.io.masters <> io.masters
|
|
|
|
|
|
|
|
addrmap.zip(realAddrMap).zip(xbar.io.slaves).zipWithIndex.foreach {
|
|
|
|
case (((entry, (start, size)), xbarSlave), i) => {
|
2015-10-02 14:19:51 -07:00
|
|
|
entry.region match {
|
2015-09-22 09:43:22 -07:00
|
|
|
case MemSize(_, _) =>
|
2015-10-23 16:25:17 -07:00
|
|
|
io.slaves(slaveInd) <> xbarSlave
|
2015-08-06 12:48:35 -07:00
|
|
|
slaveInd += 1
|
|
|
|
case MemSubmap(_, submap) =>
|
2016-01-07 11:55:19 -08:00
|
|
|
if (submap.isEmpty) {
|
|
|
|
val err_slave = Module(new NastiErrorSlave)
|
|
|
|
err_slave.io <> xbarSlave
|
|
|
|
} else {
|
|
|
|
val subSlaves = submap.countSlaves
|
2016-01-15 15:16:54 -08:00
|
|
|
val outputs = io.slaves.drop(slaveInd).take(subSlaves)
|
2016-01-07 11:55:19 -08:00
|
|
|
val ic = Module(new NastiRecursiveInterconnect(1, subSlaves, submap, start))
|
|
|
|
ic.io.masters.head <> xbarSlave
|
2016-01-15 15:16:54 -08:00
|
|
|
for ((o, s) <- outputs zip ic.io.slaves)
|
|
|
|
o <> s
|
2016-01-07 11:55:19 -08:00
|
|
|
slaveInd += subSlaves
|
|
|
|
}
|
2015-08-06 12:48:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 12:15:56 -08:00
|
|
|
|
|
|
|
class ChannelHelper(nChannels: Int)
|
|
|
|
(implicit val p: Parameters) extends HasNastiParameters {
|
|
|
|
|
|
|
|
val dataBytes = p(MIFDataBits) * p(MIFDataBeats) / 8
|
|
|
|
val chanSelBits = log2Ceil(nChannels)
|
|
|
|
val selOffset = log2Up(dataBytes)
|
|
|
|
val blockOffset = selOffset + chanSelBits
|
|
|
|
|
|
|
|
def getSelect(addr: UInt) =
|
2016-01-14 16:41:32 -08:00
|
|
|
if (nChannels > 1) addr(blockOffset - 1, selOffset) else UInt(0)
|
2015-11-18 12:15:56 -08:00
|
|
|
|
|
|
|
def getAddr(addr: UInt) =
|
2016-01-14 16:41:32 -08:00
|
|
|
if (nChannels > 1)
|
|
|
|
Cat(addr(nastiXAddrBits - 1, blockOffset), addr(selOffset - 1, 0))
|
|
|
|
else addr
|
2015-11-18 12:15:56 -08:00
|
|
|
}
|
|
|
|
|
2016-01-14 16:41:32 -08:00
|
|
|
class NastiMemoryInterconnect(
|
|
|
|
nBanksPerChannel: Int, nChannels: Int)
|
|
|
|
(implicit p: Parameters) extends NastiInterconnect()(p) {
|
2015-11-18 12:15:56 -08:00
|
|
|
|
|
|
|
val nBanks = nBanksPerChannel * nChannels
|
2016-01-14 16:41:32 -08:00
|
|
|
val nMasters = nBanks
|
|
|
|
val nSlaves = nChannels
|
2015-11-18 12:15:56 -08:00
|
|
|
|
|
|
|
val chanHelper = new ChannelHelper(nChannels)
|
|
|
|
def connectChannel(outer: NastiIO, inner: NastiIO) {
|
|
|
|
outer <> inner
|
|
|
|
outer.ar.bits.addr := chanHelper.getAddr(inner.ar.bits.addr)
|
|
|
|
outer.aw.bits.addr := chanHelper.getAddr(inner.aw.bits.addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i <- 0 until nChannels) {
|
|
|
|
/* Bank assignments to channels are strided so that consecutive banks
|
|
|
|
* map to different channels. That way, consecutive cache lines also
|
|
|
|
* map to different channels */
|
2016-01-14 16:41:32 -08:00
|
|
|
val banks = (i until nBanks by nChannels).map(j => io.masters(j))
|
2015-11-18 12:15:56 -08:00
|
|
|
|
2016-01-14 16:41:32 -08:00
|
|
|
val channelArb = Module(new NastiArbiter(nBanksPerChannel))
|
|
|
|
channelArb.io.master <> banks
|
2015-11-18 12:15:56 -08:00
|
|
|
connectChannel(io.slaves(i), channelArb.io.slave)
|
|
|
|
}
|
|
|
|
}
|
2016-02-16 23:50:23 -08:00
|
|
|
|
|
|
|
/** Allows users to switch between various memory configurations. Note that
|
|
|
|
* this is a dangerous operation: not only does switching the select input to
|
|
|
|
* this module violate Nasti, it also causes the memory of the machine to
|
|
|
|
* become garbled. It's expected that select only changes at boot time, as
|
|
|
|
* part of the memory controller configuration. */
|
2016-02-17 10:41:01 -08:00
|
|
|
class NastiMemorySelectorIO(val nBanks: Int, val maxMemChannels: Int, nConfigs: Int)
|
|
|
|
(implicit p: Parameters)
|
|
|
|
extends NastiInterconnectIO(nBanks, maxMemChannels) {
|
|
|
|
val select = UInt(INPUT, width = log2Up(nConfigs))
|
|
|
|
override def cloneType =
|
|
|
|
new NastiMemorySelectorIO(nMasters, nSlaves, nConfigs).asInstanceOf[this.type]
|
|
|
|
}
|
|
|
|
|
|
|
|
class NastiMemorySelector(nBanks: Int, maxMemChannels: Int, configs: Seq[Int])
|
|
|
|
(implicit p: Parameters)
|
|
|
|
extends NastiInterconnect()(p) {
|
2016-02-16 23:50:23 -08:00
|
|
|
val nMasters = nBanks
|
|
|
|
val nSlaves = maxMemChannels
|
|
|
|
val nConfigs = configs.size
|
|
|
|
|
2016-02-17 10:41:01 -08:00
|
|
|
override lazy val io = new NastiMemorySelectorIO(nBanks, maxMemChannels, nConfigs)
|
2016-02-16 23:50:23 -08:00
|
|
|
|
|
|
|
def muxOnSelect(up: DecoupledIO[Bundle], dn: DecoupledIO[Bundle], active: Bool): Unit = {
|
|
|
|
when (active) { dn.bits := up.bits }
|
|
|
|
when (active) { up.ready := dn.ready }
|
|
|
|
when (active) { dn.valid := up.valid }
|
|
|
|
}
|
|
|
|
|
|
|
|
def muxOnSelect(up: NastiIO, dn: NastiIO, active: Bool): Unit = {
|
|
|
|
muxOnSelect(up.aw, dn.aw, active)
|
|
|
|
muxOnSelect(up.w, dn.w, active)
|
|
|
|
muxOnSelect(dn.b, up.b, active)
|
|
|
|
muxOnSelect(up.ar, dn.ar, active)
|
|
|
|
muxOnSelect(dn.r, up.r, active)
|
|
|
|
}
|
|
|
|
|
|
|
|
def muxOnSelect(up: Vec[NastiIO], dn: Vec[NastiIO], active: Bool) : Unit = {
|
|
|
|
for (i <- 0 until up.size)
|
|
|
|
muxOnSelect(up(i), dn(i), active)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disconnects a vector of Nasti ports, which involves setting them to
|
|
|
|
* invalid. Due to Chisel reasons, we need to also set the bits to 0 (since
|
|
|
|
* there can't be any unconnected inputs). */
|
|
|
|
def disconnectSlave(slave: Vec[NastiIO]) = {
|
|
|
|
slave.foreach{ m =>
|
|
|
|
m.aw.valid := Bool(false)
|
|
|
|
m.aw.bits := m.aw.bits.fromBits( UInt(0) )
|
|
|
|
m.w.valid := Bool(false)
|
|
|
|
m.w.bits := m.w.bits.fromBits( UInt(0) )
|
|
|
|
m.b.ready := Bool(false)
|
|
|
|
m.ar.valid := Bool(false)
|
|
|
|
m.ar.bits := m.ar.bits.fromBits( UInt(0) )
|
|
|
|
m.r.ready := Bool(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def disconnectMaster(master: Vec[NastiIO]) = {
|
|
|
|
master.foreach{ m =>
|
|
|
|
m.aw.ready := Bool(false)
|
|
|
|
m.w.ready := Bool(false)
|
|
|
|
m.b.valid := Bool(false)
|
|
|
|
m.b.bits := m.b.bits.fromBits( UInt(0) )
|
|
|
|
m.ar.ready := Bool(false)
|
|
|
|
m.r.valid := Bool(false)
|
|
|
|
m.r.bits := m.r.bits.fromBits( UInt(0) )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Provides default wires on all our outputs. */
|
|
|
|
disconnectMaster(io.masters)
|
|
|
|
disconnectSlave(io.slaves)
|
|
|
|
|
|
|
|
/* Constructs interconnects for each of the layouts suggested by the
|
|
|
|
* configuration and switches between them based on the select input. */
|
|
|
|
configs.zipWithIndex.foreach{ case (nChannels, select) =>
|
|
|
|
val nBanksPerChannel = nBanks / nChannels
|
|
|
|
val ic = Module(new NastiMemoryInterconnect(nBanksPerChannel, nChannels))
|
|
|
|
disconnectMaster(ic.io.slaves)
|
|
|
|
disconnectSlave(ic.io.masters)
|
|
|
|
muxOnSelect( io.masters, ic.io.masters, io.select === UInt(select))
|
|
|
|
muxOnSelect(ic.io.slaves, io.slaves, io.select === UInt(select))
|
|
|
|
}
|
|
|
|
}
|