2014-09-13 03:06:41 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
2012-02-26 02:09:26 +01:00
|
|
|
package rocket
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-10-08 05:15:54 +02:00
|
|
|
import Chisel._
|
2015-10-22 03:18:32 +02:00
|
|
|
import cde.{Parameters, Field}
|
2016-01-22 00:37:29 +01:00
|
|
|
import junctions.{ParameterizedBundle, DecoupledHelper}
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2015-10-06 06:48:05 +02:00
|
|
|
class HellaCacheArbiter(n: Int)(implicit p: Parameters) extends Module
|
2012-10-08 22:06:45 +02:00
|
|
|
{
|
2012-11-06 08:52:32 +01:00
|
|
|
val io = new Bundle {
|
2016-01-14 22:57:45 +01:00
|
|
|
val requestor = Vec(n, new HellaCacheIO).flip
|
2014-08-08 21:23:02 +02:00
|
|
|
val mem = new HellaCacheIO
|
2012-11-06 08:52:32 +01:00
|
|
|
}
|
2012-10-08 22:06:45 +02:00
|
|
|
|
2016-05-22 01:55:42 +02:00
|
|
|
val s1_id = Reg(UInt())
|
|
|
|
val s2_id = Reg(next=s1_id)
|
2012-11-06 17:13:44 +01:00
|
|
|
|
2016-04-27 20:22:04 +02:00
|
|
|
io.mem.invalidate_lr := io.requestor.map(_.invalidate_lr).reduce(_||_)
|
2012-11-06 17:13:44 +01:00
|
|
|
io.mem.req.valid := io.requestor.map(_.req.valid).reduce(_||_)
|
|
|
|
io.requestor(0).req.ready := io.mem.req.ready
|
|
|
|
for (i <- 1 until n)
|
|
|
|
io.requestor(i).req.ready := io.requestor(i-1).req.ready && !io.requestor(i-1).req.valid
|
|
|
|
|
2016-04-02 04:30:39 +02:00
|
|
|
for (i <- n-1 to 0 by -1) {
|
2012-11-06 17:13:44 +01:00
|
|
|
val req = io.requestor(i).req
|
2016-04-02 04:30:39 +02:00
|
|
|
def connect_s0() = {
|
2012-11-06 17:13:44 +01:00
|
|
|
io.mem.req.bits.cmd := req.bits.cmd
|
|
|
|
io.mem.req.bits.typ := req.bits.typ
|
|
|
|
io.mem.req.bits.addr := req.bits.addr
|
|
|
|
io.mem.req.bits.phys := req.bits.phys
|
2013-08-12 19:39:11 +02:00
|
|
|
io.mem.req.bits.tag := Cat(req.bits.tag, UInt(i, log2Up(n)))
|
2016-05-22 01:55:42 +02:00
|
|
|
s1_id := UInt(i)
|
2012-11-06 17:13:44 +01:00
|
|
|
}
|
2016-04-02 04:30:39 +02:00
|
|
|
def connect_s1() = {
|
|
|
|
io.mem.s1_kill := io.requestor(i).s1_kill
|
|
|
|
io.mem.s1_data := io.requestor(i).s1_data
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == n-1) {
|
|
|
|
connect_s0()
|
|
|
|
connect_s1()
|
|
|
|
} else {
|
|
|
|
when (req.valid) { connect_s0() }
|
2016-05-22 01:55:42 +02:00
|
|
|
when (s1_id === UInt(i)) { connect_s1() }
|
2012-11-06 17:13:44 +01:00
|
|
|
}
|
2012-10-08 22:06:45 +02:00
|
|
|
}
|
|
|
|
|
2012-11-06 17:13:44 +01:00
|
|
|
for (i <- 0 until n) {
|
|
|
|
val resp = io.requestor(i).resp
|
2013-08-12 19:39:11 +02:00
|
|
|
val tag_hit = io.mem.resp.bits.tag(log2Up(n)-1,0) === UInt(i)
|
2012-11-06 17:13:44 +01:00
|
|
|
resp.valid := io.mem.resp.valid && tag_hit
|
|
|
|
io.requestor(i).xcpt := io.mem.xcpt
|
2013-09-15 07:34:53 +02:00
|
|
|
io.requestor(i).ordered := io.mem.ordered
|
2016-05-22 01:55:42 +02:00
|
|
|
io.requestor(i).s2_nack := io.mem.s2_nack && s2_id === UInt(i)
|
2012-11-06 17:13:44 +01:00
|
|
|
resp.bits := io.mem.resp.bits
|
2015-08-06 00:28:31 +02:00
|
|
|
resp.bits.tag := io.mem.resp.bits.tag >> log2Up(n)
|
2014-01-16 09:16:09 +01:00
|
|
|
|
2016-05-14 02:54:23 +02:00
|
|
|
io.requestor(i).replay_next := io.mem.replay_next
|
2012-10-08 22:06:45 +02:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 19:22:31 +01:00
|
|
|
|
|
|
|
class InOrderArbiter[T <: Data, U <: Data](reqTyp: T, respTyp: U, n: Int)
|
|
|
|
(implicit p: Parameters) extends Module {
|
|
|
|
val io = new Bundle {
|
|
|
|
val in_req = Vec(n, Decoupled(reqTyp)).flip
|
|
|
|
val in_resp = Vec(n, Decoupled(respTyp))
|
|
|
|
val out_req = Decoupled(reqTyp)
|
|
|
|
val out_resp = Decoupled(respTyp).flip
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n > 1) {
|
|
|
|
val route_q = Module(new Queue(UInt(width = log2Up(n)), 2))
|
|
|
|
val req_arb = Module(new RRArbiter(reqTyp, n))
|
|
|
|
req_arb.io.in <> io.in_req
|
|
|
|
|
|
|
|
val req_helper = DecoupledHelper(
|
|
|
|
req_arb.io.out.valid,
|
|
|
|
route_q.io.enq.ready,
|
|
|
|
io.out_req.ready)
|
|
|
|
|
|
|
|
io.out_req.bits := req_arb.io.out.bits
|
|
|
|
io.out_req.valid := req_helper.fire(io.out_req.ready)
|
|
|
|
|
|
|
|
route_q.io.enq.bits := req_arb.io.chosen
|
|
|
|
route_q.io.enq.valid := req_helper.fire(route_q.io.enq.ready)
|
|
|
|
|
|
|
|
req_arb.io.out.ready := req_helper.fire(req_arb.io.out.valid)
|
|
|
|
|
|
|
|
val resp_sel = route_q.io.deq.bits
|
|
|
|
val resp_ready = io.in_resp(resp_sel).ready
|
|
|
|
val resp_helper = DecoupledHelper(
|
|
|
|
resp_ready,
|
|
|
|
route_q.io.deq.valid,
|
|
|
|
io.out_resp.valid)
|
|
|
|
|
|
|
|
val resp_valid = resp_helper.fire(resp_ready)
|
|
|
|
for (i <- 0 until n) {
|
|
|
|
io.in_resp(i).bits := io.out_resp.bits
|
|
|
|
io.in_resp(i).valid := resp_valid && resp_sel === UInt(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
route_q.io.deq.ready := resp_helper.fire(route_q.io.deq.valid)
|
|
|
|
io.out_resp.ready := resp_helper.fire(io.out_resp.valid)
|
|
|
|
} else {
|
|
|
|
io.out_req <> io.in_req.head
|
|
|
|
io.in_resp.head <> io.out_resp
|
|
|
|
}
|
|
|
|
}
|