2014-09-13 00:31:38 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
2012-10-11 00:42:39 +02:00
|
|
|
package uncore
|
2012-03-26 02:03:58 +02:00
|
|
|
import Chisel._
|
|
|
|
import scala.math._
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
case object PAddrBits extends Field[Int]
|
|
|
|
case object VAddrBits extends Field[Int]
|
|
|
|
case object PgIdxBits extends Field[Int]
|
|
|
|
case object ASIdBits extends Field[Int]
|
|
|
|
case object PermBits extends Field[Int]
|
|
|
|
case object PPNBits extends Field[Int]
|
|
|
|
case object VPNBits extends Field[Int]
|
|
|
|
|
|
|
|
case object MIFAddrBits extends Field[Int]
|
|
|
|
case object MIFDataBits extends Field[Int]
|
|
|
|
case object MIFTagBits extends Field[Int]
|
|
|
|
case object MIFDataBeats extends Field[Int]
|
|
|
|
|
|
|
|
trait HasMemData extends Bundle {
|
|
|
|
val data = Bits(width = params(MIFDataBits))
|
2014-04-02 02:14:45 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
trait HasMemAddr extends Bundle {
|
|
|
|
val addr = UInt(width = params(MIFAddrBits))
|
2013-08-02 23:55:06 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
trait HasMemTag extends Bundle {
|
|
|
|
val tag = UInt(width = params(MIFTagBits))
|
2013-08-02 23:55:06 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemReqCmd extends HasMemAddr with HasMemTag {
|
2013-08-12 19:36:44 +02:00
|
|
|
val rw = Bool()
|
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemResp extends HasMemData with HasMemTag
|
2013-08-12 19:36:44 +02:00
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemData extends HasMemData
|
2013-08-12 19:36:44 +02:00
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemIO extends Bundle {
|
2013-08-12 19:36:44 +02:00
|
|
|
val req_cmd = Decoupled(new MemReqCmd)
|
|
|
|
val req_data = Decoupled(new MemData)
|
|
|
|
val resp = Decoupled(new MemResp).flip
|
2013-08-02 23:55:06 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemPipeIO extends Bundle {
|
2013-08-12 19:36:44 +02:00
|
|
|
val req_cmd = Decoupled(new MemReqCmd)
|
|
|
|
val req_data = Decoupled(new MemData)
|
|
|
|
val resp = Valid(new MemResp).flip
|
2013-08-02 23:55:06 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemSerializedIO(w: Int) extends Bundle
|
2012-03-26 02:03:58 +02:00
|
|
|
{
|
2013-08-12 19:36:44 +02:00
|
|
|
val req = Decoupled(Bits(width = w))
|
|
|
|
val resp = Valid(Bits(width = w)).flip
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemSerdes(w: Int) extends Module
|
2012-03-26 02:03:58 +02:00
|
|
|
{
|
|
|
|
val io = new Bundle {
|
2014-03-29 18:53:49 +01:00
|
|
|
val wide = new MemIO().flip
|
|
|
|
val narrow = new MemSerializedIO(w)
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
|
|
|
val abits = io.wide.req_cmd.bits.toBits.getWidth
|
|
|
|
val dbits = io.wide.req_data.bits.toBits.getWidth
|
|
|
|
val rbits = io.wide.resp.bits.getWidth
|
2014-08-08 21:21:57 +02:00
|
|
|
val dbeats = params(MIFDataBeats)
|
2012-03-26 02:03:58 +02:00
|
|
|
|
2013-08-12 19:36:44 +02:00
|
|
|
val out_buf = Reg(Bits())
|
|
|
|
val in_buf = Reg(Bits())
|
2012-03-26 02:03:58 +02:00
|
|
|
|
2013-09-10 19:54:51 +02:00
|
|
|
val s_idle :: s_read_addr :: s_write_addr :: s_write_idle :: s_write_data :: Nil = Enum(UInt(), 5)
|
2013-08-16 00:27:38 +02:00
|
|
|
val state = Reg(init=s_idle)
|
|
|
|
val send_cnt = Reg(init=UInt(0, log2Up((max(abits, dbits)+w-1)/w)))
|
2014-08-08 21:21:57 +02:00
|
|
|
val data_send_cnt = Reg(init=UInt(0, log2Up(dbeats)))
|
2013-08-12 19:36:44 +02:00
|
|
|
val adone = io.narrow.req.ready && send_cnt === UInt((abits-1)/w)
|
|
|
|
val ddone = io.narrow.req.ready && send_cnt === UInt((dbits-1)/w)
|
2012-03-26 02:03:58 +02:00
|
|
|
|
2012-03-26 08:03:20 +02:00
|
|
|
when (io.narrow.req.valid && io.narrow.req.ready) {
|
2013-08-12 19:36:44 +02:00
|
|
|
send_cnt := send_cnt + UInt(1)
|
|
|
|
out_buf := out_buf >> UInt(w)
|
2012-03-26 08:03:20 +02:00
|
|
|
}
|
|
|
|
when (io.wide.req_cmd.valid && io.wide.req_cmd.ready) {
|
|
|
|
out_buf := io.wide.req_cmd.bits.toBits
|
|
|
|
}
|
|
|
|
when (io.wide.req_data.valid && io.wide.req_data.ready) {
|
|
|
|
out_buf := io.wide.req_data.bits.toBits
|
|
|
|
}
|
|
|
|
|
|
|
|
io.wide.req_cmd.ready := state === s_idle
|
|
|
|
io.wide.req_data.ready := state === s_write_idle
|
|
|
|
io.narrow.req.valid := state === s_read_addr || state === s_write_addr || state === s_write_data
|
|
|
|
io.narrow.req.bits := out_buf
|
|
|
|
|
|
|
|
when (state === s_idle && io.wide.req_cmd.valid) {
|
|
|
|
state := Mux(io.wide.req_cmd.bits.rw, s_write_addr, s_read_addr)
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
|
|
|
when (state === s_read_addr && adone) {
|
|
|
|
state := s_idle
|
2013-08-12 19:36:44 +02:00
|
|
|
send_cnt := UInt(0)
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
|
|
|
when (state === s_write_addr && adone) {
|
|
|
|
state := s_write_idle
|
2013-08-12 19:36:44 +02:00
|
|
|
send_cnt := UInt(0)
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
|
|
|
when (state === s_write_idle && io.wide.req_data.valid) {
|
|
|
|
state := s_write_data
|
|
|
|
}
|
|
|
|
when (state === s_write_data && ddone) {
|
2013-08-12 19:36:44 +02:00
|
|
|
data_send_cnt := data_send_cnt + UInt(1)
|
2014-08-08 21:21:57 +02:00
|
|
|
state := Mux(data_send_cnt === UInt(dbeats-1), s_idle, s_write_idle)
|
2013-08-12 19:36:44 +02:00
|
|
|
send_cnt := UInt(0)
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
|
|
|
|
2013-08-16 00:27:38 +02:00
|
|
|
val recv_cnt = Reg(init=UInt(0, log2Up((rbits+w-1)/w)))
|
2014-08-08 21:21:57 +02:00
|
|
|
val data_recv_cnt = Reg(init=UInt(0, log2Up(dbeats)))
|
2013-08-16 00:27:38 +02:00
|
|
|
val resp_val = Reg(init=Bool(false))
|
2012-03-26 02:03:58 +02:00
|
|
|
|
|
|
|
resp_val := Bool(false)
|
|
|
|
when (io.narrow.resp.valid) {
|
2013-08-12 19:36:44 +02:00
|
|
|
recv_cnt := recv_cnt + UInt(1)
|
|
|
|
when (recv_cnt === UInt((rbits-1)/w)) {
|
|
|
|
recv_cnt := UInt(0)
|
|
|
|
data_recv_cnt := data_recv_cnt + UInt(1)
|
2012-03-26 02:03:58 +02:00
|
|
|
resp_val := Bool(true)
|
|
|
|
}
|
2012-10-19 01:56:36 +02:00
|
|
|
in_buf := Cat(io.narrow.resp.bits, in_buf((rbits+w-1)/w*w-1,w))
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
io.wide.resp.valid := resp_val
|
2013-08-25 00:24:17 +02:00
|
|
|
io.wide.resp.bits := io.wide.resp.bits.fromBits(in_buf)
|
2012-03-26 02:03:58 +02:00
|
|
|
}
|
2012-03-26 08:03:20 +02:00
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemDesserIO(w: Int) extends Bundle {
|
2014-03-29 18:53:49 +01:00
|
|
|
val narrow = new MemSerializedIO(w).flip
|
|
|
|
val wide = new MemIO
|
2012-10-19 01:56:36 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemDesser(w: Int) extends Module // test rig side
|
2012-03-26 08:03:20 +02:00
|
|
|
{
|
2012-10-19 01:56:36 +02:00
|
|
|
val io = new MemDesserIO(w)
|
2012-03-26 08:03:20 +02:00
|
|
|
val abits = io.wide.req_cmd.bits.toBits.getWidth
|
|
|
|
val dbits = io.wide.req_data.bits.toBits.getWidth
|
|
|
|
val rbits = io.wide.resp.bits.getWidth
|
2014-08-08 21:21:57 +02:00
|
|
|
val dbeats = params(MIFDataBeats)
|
2012-03-26 08:03:20 +02:00
|
|
|
|
|
|
|
require(dbits >= abits && rbits >= dbits)
|
2013-08-16 00:27:38 +02:00
|
|
|
val recv_cnt = Reg(init=UInt(0, log2Up((rbits+w-1)/w)))
|
2014-08-08 21:21:57 +02:00
|
|
|
val data_recv_cnt = Reg(init=UInt(0, log2Up(dbeats)))
|
2013-08-12 19:36:44 +02:00
|
|
|
val adone = io.narrow.req.valid && recv_cnt === UInt((abits-1)/w)
|
|
|
|
val ddone = io.narrow.req.valid && recv_cnt === UInt((dbits-1)/w)
|
|
|
|
val rdone = io.narrow.resp.valid && recv_cnt === UInt((rbits-1)/w)
|
2012-03-26 08:03:20 +02:00
|
|
|
|
2013-09-10 19:54:51 +02:00
|
|
|
val s_cmd_recv :: s_cmd :: s_data_recv :: s_data :: s_reply :: Nil = Enum(UInt(), 5)
|
2013-08-16 00:27:38 +02:00
|
|
|
val state = Reg(init=s_cmd_recv)
|
2012-03-26 08:03:20 +02:00
|
|
|
|
2013-08-12 19:36:44 +02:00
|
|
|
val in_buf = Reg(Bits())
|
2012-03-26 08:03:20 +02:00
|
|
|
when (io.narrow.req.valid && io.narrow.req.ready || io.narrow.resp.valid) {
|
2013-08-12 19:36:44 +02:00
|
|
|
recv_cnt := recv_cnt + UInt(1)
|
2012-10-19 01:56:36 +02:00
|
|
|
in_buf := Cat(io.narrow.req.bits, in_buf((rbits+w-1)/w*w-1,w))
|
2012-03-26 08:03:20 +02:00
|
|
|
}
|
|
|
|
io.narrow.req.ready := state === s_cmd_recv || state === s_data_recv
|
|
|
|
|
|
|
|
when (state === s_cmd_recv && adone) {
|
|
|
|
state := s_cmd
|
2013-08-12 19:36:44 +02:00
|
|
|
recv_cnt := UInt(0)
|
2012-03-26 08:03:20 +02:00
|
|
|
}
|
|
|
|
when (state === s_cmd && io.wide.req_cmd.ready) {
|
|
|
|
state := Mux(io.wide.req_cmd.bits.rw, s_data_recv, s_reply)
|
|
|
|
}
|
|
|
|
when (state === s_data_recv && ddone) {
|
|
|
|
state := s_data
|
2013-08-12 19:36:44 +02:00
|
|
|
recv_cnt := UInt(0)
|
2012-03-26 08:03:20 +02:00
|
|
|
}
|
|
|
|
when (state === s_data && io.wide.req_data.ready) {
|
|
|
|
state := s_data_recv
|
2014-08-08 21:21:57 +02:00
|
|
|
when (data_recv_cnt === UInt(dbeats-1)) {
|
2012-03-26 08:03:20 +02:00
|
|
|
state := s_cmd_recv
|
|
|
|
}
|
2013-08-12 19:36:44 +02:00
|
|
|
data_recv_cnt := data_recv_cnt + UInt(1)
|
2012-03-26 08:03:20 +02:00
|
|
|
}
|
|
|
|
when (rdone) { // state === s_reply
|
2014-08-08 21:21:57 +02:00
|
|
|
when (data_recv_cnt === UInt(dbeats-1)) {
|
2012-03-26 08:03:20 +02:00
|
|
|
state := s_cmd_recv
|
|
|
|
}
|
2013-08-12 19:36:44 +02:00
|
|
|
recv_cnt := UInt(0)
|
|
|
|
data_recv_cnt := data_recv_cnt + UInt(1)
|
2012-03-26 08:03:20 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 19:36:44 +02:00
|
|
|
val req_cmd = in_buf >> UInt(((rbits+w-1)/w - (abits+w-1)/w)*w)
|
2012-03-26 08:03:20 +02:00
|
|
|
io.wide.req_cmd.valid := state === s_cmd
|
2012-10-11 00:42:39 +02:00
|
|
|
io.wide.req_cmd.bits := io.wide.req_cmd.bits.fromBits(req_cmd)
|
2012-03-26 08:03:20 +02:00
|
|
|
|
|
|
|
io.wide.req_data.valid := state === s_data
|
2013-08-12 19:36:44 +02:00
|
|
|
io.wide.req_data.bits.data := in_buf >> UInt(((rbits+w-1)/w - (dbits+w-1)/w)*w)
|
2012-03-26 08:03:20 +02:00
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
val dataq = Module(new Queue(new MemResp, dbeats))
|
2012-03-26 08:03:20 +02:00
|
|
|
dataq.io.enq <> io.wide.resp
|
2013-08-12 19:36:44 +02:00
|
|
|
dataq.io.deq.ready := recv_cnt === UInt((rbits-1)/w)
|
2012-03-26 08:03:20 +02:00
|
|
|
|
|
|
|
io.narrow.resp.valid := dataq.io.deq.valid
|
2013-08-12 19:36:44 +02:00
|
|
|
io.narrow.resp.bits := dataq.io.deq.bits.toBits >> (recv_cnt * UInt(w))
|
2012-03-26 08:03:20 +02:00
|
|
|
}
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
//Adapter betweewn an UncachedTileLinkIO and a mem controller MemIO
|
2014-08-08 21:21:57 +02:00
|
|
|
class MemIOUncachedTileLinkIOConverter(qDepth: Int) extends Module {
|
2014-03-29 18:53:49 +01:00
|
|
|
val io = new Bundle {
|
|
|
|
val uncached = new UncachedTileLinkIO().flip
|
|
|
|
val mem = new MemIO
|
|
|
|
}
|
2014-08-08 21:21:57 +02:00
|
|
|
val co = params(TLCoherence)
|
|
|
|
val tbits = params(MIFTagBits)
|
|
|
|
val dbits = params(MIFDataBits)
|
2014-08-12 03:35:49 +02:00
|
|
|
val dbeats = params(MIFDataBeats)
|
2014-08-08 21:21:57 +02:00
|
|
|
require(params(TLDataBits) == dbits*dbeats)
|
|
|
|
//require(params(TLClientXactIdBits) <= params(MIFTagBits))
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
val mem_cmd_q = Module(new Queue(new MemReqCmd, qDepth))
|
|
|
|
val mem_data_q = Module(new Queue(new MemData, qDepth))
|
2014-08-08 21:21:57 +02:00
|
|
|
val cnt_max = dbeats
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
val cnt_out = Reg(UInt(width = log2Up(cnt_max+1)))
|
|
|
|
val active_out = Reg(init=Bool(false))
|
|
|
|
val cmd_sent_out = Reg(init=Bool(false))
|
|
|
|
val buf_out = Reg(Bits())
|
|
|
|
val tag_out = Reg(Bits())
|
|
|
|
val addr_out = Reg(Bits())
|
|
|
|
val has_data = Reg(init=Bool(false))
|
|
|
|
|
|
|
|
val cnt_in = Reg(UInt(width = log2Up(cnt_max+1)))
|
|
|
|
val active_in = Reg(init=Bool(false))
|
|
|
|
val buf_in = Reg(Bits())
|
2014-08-08 21:21:57 +02:00
|
|
|
val tag_in = Reg(UInt(width = tbits))
|
2014-03-29 18:53:49 +01:00
|
|
|
|
|
|
|
// Decompose outgoing TL Acquires into MemIO cmd and data
|
|
|
|
when(!active_out && io.uncached.acquire.valid) {
|
|
|
|
active_out := Bool(true)
|
|
|
|
cmd_sent_out := Bool(false)
|
|
|
|
cnt_out := UInt(0)
|
|
|
|
buf_out := io.uncached.acquire.bits.payload.data
|
|
|
|
tag_out := io.uncached.acquire.bits.payload.client_xact_id
|
|
|
|
addr_out := io.uncached.acquire.bits.payload.addr
|
2014-08-08 21:21:57 +02:00
|
|
|
has_data := co.messageHasData(io.uncached.acquire.bits.payload)
|
2014-03-29 18:53:49 +01:00
|
|
|
}
|
|
|
|
when(active_out) {
|
|
|
|
when(mem_cmd_q.io.enq.fire()) {
|
|
|
|
cmd_sent_out := Bool(true)
|
|
|
|
}
|
|
|
|
when(mem_data_q.io.enq.fire()) {
|
|
|
|
cnt_out := cnt_out + UInt(1)
|
2014-08-08 21:21:57 +02:00
|
|
|
buf_out := buf_out >> UInt(dbits)
|
2014-03-29 18:53:49 +01:00
|
|
|
}
|
|
|
|
when(cmd_sent_out && (!has_data || cnt_out === UInt(cnt_max))) {
|
|
|
|
active_out := Bool(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
io.uncached.acquire.ready := !active_out
|
|
|
|
mem_cmd_q.io.enq.valid := active_out && !cmd_sent_out
|
|
|
|
mem_cmd_q.io.enq.bits.rw := has_data
|
|
|
|
mem_cmd_q.io.enq.bits.tag := tag_out
|
|
|
|
mem_cmd_q.io.enq.bits.addr := addr_out
|
|
|
|
mem_data_q.io.enq.valid := active_out && has_data && cnt_out < UInt(cnt_max)
|
|
|
|
mem_data_q.io.enq.bits.data := buf_out
|
|
|
|
io.mem.req_cmd <> mem_cmd_q.io.deq
|
|
|
|
io.mem.req_data <> mem_data_q.io.deq
|
|
|
|
|
|
|
|
// Aggregate incoming MemIO responses into TL Grants
|
|
|
|
io.mem.resp.ready := !active_in || cnt_in < UInt(cnt_max)
|
|
|
|
io.uncached.grant.valid := active_in && (cnt_in === UInt(cnt_max))
|
|
|
|
io.uncached.grant.bits.payload := Grant(UInt(0), tag_in, UInt(0), buf_in)
|
|
|
|
when(!active_in && io.mem.resp.valid) {
|
|
|
|
active_in := Bool(true)
|
|
|
|
cnt_in := UInt(1)
|
2014-08-08 21:21:57 +02:00
|
|
|
buf_in := io.mem.resp.bits.data << UInt(dbits*(cnt_max-1))
|
2014-03-29 18:53:49 +01:00
|
|
|
tag_in := io.mem.resp.bits.tag
|
|
|
|
}
|
|
|
|
when(active_in) {
|
|
|
|
when(io.uncached.grant.fire()) {
|
|
|
|
active_in := Bool(false)
|
|
|
|
}
|
|
|
|
when(io.mem.resp.fire()) {
|
2014-08-08 21:21:57 +02:00
|
|
|
buf_in := Cat(io.mem.resp.bits.data, buf_in(cnt_max*dbits-1,dbits))
|
2014-03-29 18:53:49 +01:00
|
|
|
cnt_in := cnt_in + UInt(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 00:11:24 +02:00
|
|
|
class HellaFlowQueue[T <: Data](val entries: Int)(data: => T) extends Module
|
|
|
|
{
|
|
|
|
val io = new QueueIO(data, entries)
|
|
|
|
require(isPow2(entries) && entries > 1)
|
|
|
|
|
|
|
|
val do_flow = Bool()
|
|
|
|
val do_enq = io.enq.fire() && !do_flow
|
|
|
|
val do_deq = io.deq.fire() && !do_flow
|
|
|
|
|
|
|
|
val maybe_full = Reg(init=Bool(false))
|
|
|
|
val enq_ptr = Counter(do_enq, entries)._1
|
|
|
|
val deq_ptr = Counter(do_deq, entries)._1
|
|
|
|
when (do_enq != do_deq) { maybe_full := do_enq }
|
|
|
|
|
|
|
|
val ptr_match = enq_ptr === deq_ptr
|
|
|
|
val empty = ptr_match && !maybe_full
|
|
|
|
val full = ptr_match && maybe_full
|
|
|
|
val atLeastTwo = full || enq_ptr - deq_ptr >= UInt(2)
|
|
|
|
do_flow := empty && io.deq.ready
|
|
|
|
|
|
|
|
val ram = Mem(data, entries, seqRead = true)
|
|
|
|
val ram_addr = Reg(Bits())
|
|
|
|
val ram_out_valid = Reg(Bool())
|
|
|
|
ram_out_valid := Bool(false)
|
|
|
|
when (do_enq) { ram(enq_ptr) := io.enq.bits }
|
|
|
|
when (io.deq.ready && (atLeastTwo || !io.deq.valid && !empty)) {
|
|
|
|
ram_out_valid := Bool(true)
|
|
|
|
ram_addr := Mux(io.deq.valid, deq_ptr + UInt(1), deq_ptr)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.deq.valid := Mux(empty, io.enq.valid, ram_out_valid)
|
|
|
|
io.enq.ready := !full
|
|
|
|
io.deq.bits := Mux(empty, io.enq.bits, ram(ram_addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
class HellaQueue[T <: Data](val entries: Int)(data: => T) extends Module
|
|
|
|
{
|
|
|
|
val io = new QueueIO(data, entries)
|
|
|
|
|
|
|
|
val fq = Module(new HellaFlowQueue(entries)(data))
|
|
|
|
io.enq <> fq.io.enq
|
|
|
|
io.deq <> Queue(fq.io.deq, 1, pipe = true)
|
|
|
|
}
|
|
|
|
|
|
|
|
object HellaQueue
|
|
|
|
{
|
|
|
|
def apply[T <: Data](enq: DecoupledIO[T], entries: Int) = {
|
|
|
|
val q = Module((new HellaQueue(entries)) { enq.bits.clone })
|
|
|
|
q.io.enq.valid := enq.valid // not using <> so that override is allowed
|
|
|
|
q.io.enq.bits := enq.bits
|
|
|
|
enq.ready := q.io.enq.ready
|
|
|
|
q.io.deq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MemPipeIOMemIOConverter(numRequests: Int, refillCycles: Int) extends Module {
|
|
|
|
val io = new Bundle {
|
|
|
|
val cpu = new MemIO().flip
|
|
|
|
val mem = new MemPipeIO
|
|
|
|
}
|
|
|
|
|
|
|
|
val numEntries = numRequests * refillCycles
|
|
|
|
val size = log2Down(numEntries) + 1
|
|
|
|
|
|
|
|
val inc = Bool()
|
|
|
|
val dec = Bool()
|
|
|
|
val count = Reg(init=UInt(numEntries, size))
|
|
|
|
val watermark = count >= UInt(refillCycles)
|
|
|
|
|
|
|
|
when (inc && !dec) {
|
|
|
|
count := count + UInt(1)
|
|
|
|
}
|
|
|
|
when (!inc && dec) {
|
|
|
|
count := count - UInt(refillCycles)
|
|
|
|
}
|
|
|
|
when (inc && dec) {
|
|
|
|
count := count - UInt(refillCycles-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
val cmdq_mask = io.cpu.req_cmd.bits.rw || watermark
|
|
|
|
|
|
|
|
io.mem.req_cmd.valid := io.cpu.req_cmd.valid && cmdq_mask
|
|
|
|
io.cpu.req_cmd.ready := io.mem.req_cmd.ready && cmdq_mask
|
|
|
|
io.mem.req_cmd.bits := io.cpu.req_cmd.bits
|
|
|
|
|
|
|
|
io.mem.req_data <> io.cpu.req_data
|
|
|
|
|
|
|
|
val resp_dataq = Module((new HellaQueue(numEntries)) { new MemResp })
|
|
|
|
resp_dataq.io.enq <> io.mem.resp
|
|
|
|
io.cpu.resp <> resp_dataq.io.deq
|
|
|
|
|
|
|
|
inc := resp_dataq.io.deq.fire()
|
|
|
|
dec := io.mem.req_cmd.fire() && !io.mem.req_cmd.bits.rw
|
|
|
|
}
|
|
|
|
|
|
|
|
class MemPipeIOUncachedTileLinkIOConverter(outstanding: Int, refillCycles: Int) extends Module {
|
|
|
|
val io = new Bundle {
|
|
|
|
val uncached = new UncachedTileLinkIO().flip
|
|
|
|
val mem = new MemPipeIO
|
|
|
|
}
|
|
|
|
|
|
|
|
val a = Module(new MemIOUncachedTileLinkIOConverter(2))
|
|
|
|
val b = Module(new MemPipeIOMemIOConverter(outstanding, refillCycles))
|
|
|
|
a.io.uncached <> io.uncached
|
|
|
|
b.io.cpu.req_cmd <> Queue(a.io.mem.req_cmd, 2)
|
|
|
|
b.io.cpu.req_data <> Queue(a.io.mem.req_data, refillCycles)
|
|
|
|
a.io.mem.resp <> b.io.cpu.resp
|
|
|
|
b.io.mem <> io.mem
|
|
|
|
}
|