2012-02-26 02:09:26 +01:00
|
|
|
package rocket
|
2011-11-09 23:52:17 +01:00
|
|
|
|
2012-10-08 05:15:54 +02:00
|
|
|
import Chisel._
|
2014-04-02 02:15:46 +02:00
|
|
|
import uncore._
|
2012-11-27 05:38:45 +01:00
|
|
|
import Util._
|
2011-11-09 23:52:17 +01:00
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
class PTWResp extends Bundle {
|
2014-04-02 02:15:46 +02:00
|
|
|
val error = Bool()
|
2014-08-08 21:23:02 +02:00
|
|
|
val ppn = UInt(width = params(PPNBits))
|
|
|
|
val perm = Bits(width = params(PermBits))
|
2013-08-12 19:39:11 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
class TLBPTWIO extends Bundle {
|
|
|
|
val req = Decoupled(UInt(width = params(VPNBits)))
|
2013-08-12 19:39:11 +02:00
|
|
|
val resp = Valid(new PTWResp).flip
|
2012-11-27 10:28:06 +01:00
|
|
|
val status = new Status().asInput
|
2012-11-06 17:13:44 +01:00
|
|
|
val invalidate = Bool(INPUT)
|
2013-11-25 13:35:15 +01:00
|
|
|
val sret = Bool(INPUT)
|
2012-11-06 17:13:44 +01:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
class DatapathPTWIO extends Bundle {
|
|
|
|
val ptbr = UInt(INPUT, params(PAddrBits))
|
2012-11-06 17:13:44 +01:00
|
|
|
val invalidate = Bool(INPUT)
|
2013-11-25 13:35:15 +01:00
|
|
|
val sret = Bool(INPUT)
|
2012-11-27 10:28:06 +01:00
|
|
|
val status = new Status().asInput
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
class PTW(n: Int) extends Module
|
2011-11-09 23:52:17 +01:00
|
|
|
{
|
2012-11-06 17:13:44 +01:00
|
|
|
val io = new Bundle {
|
2013-08-12 19:39:11 +02:00
|
|
|
val requestor = Vec.fill(n){new TLBPTWIO}.flip
|
2014-08-08 21:23:02 +02:00
|
|
|
val mem = new HellaCacheIO
|
2013-01-07 22:38:59 +01:00
|
|
|
val dpath = new DatapathPTWIO
|
2012-11-06 17:13:44 +01:00
|
|
|
}
|
2011-11-09 23:52:17 +01:00
|
|
|
|
2012-05-01 10:24:36 +02:00
|
|
|
val levels = 3
|
2014-08-08 21:23:02 +02:00
|
|
|
val bitsPerLevel = params(VPNBits)/levels
|
|
|
|
require(params(VPNBits) == levels * bitsPerLevel)
|
2012-05-01 10:24:36 +02:00
|
|
|
|
2013-09-10 19:51:35 +02:00
|
|
|
val s_ready :: s_req :: s_wait :: s_done :: s_error :: Nil = Enum(UInt(), 5)
|
2013-08-16 00:28:15 +02:00
|
|
|
val state = Reg(init=s_ready)
|
2013-08-12 19:39:11 +02:00
|
|
|
val count = Reg(UInt(width = log2Up(levels)))
|
2012-11-27 05:38:45 +01:00
|
|
|
|
2013-08-12 19:39:11 +02:00
|
|
|
val r_req_vpn = Reg(Bits())
|
|
|
|
val r_req_dest = Reg(Bits())
|
|
|
|
val r_pte = Reg(Bits())
|
2011-11-09 23:52:17 +01:00
|
|
|
|
2014-04-17 02:19:08 +02:00
|
|
|
val vpn_idx = Vec((0 until levels).map(i => (r_req_vpn >> (levels-i-1)*bitsPerLevel)(bitsPerLevel-1,0)))(count)
|
2012-03-18 07:00:51 +01:00
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
val arb = Module(new RRArbiter(UInt(width = params(VPNBits)), n))
|
2012-10-10 06:35:03 +02:00
|
|
|
arb.io.in <> io.requestor.map(_.req)
|
|
|
|
arb.io.out.ready := state === s_ready
|
|
|
|
|
|
|
|
when (arb.io.out.fire()) {
|
|
|
|
r_req_vpn := arb.io.out.bits
|
|
|
|
r_req_dest := arb.io.chosen
|
2014-08-08 21:23:02 +02:00
|
|
|
r_pte := Cat(io.dpath.ptbr(params(PAddrBits)-1,params(PgIdxBits)), io.mem.resp.bits.data(params(PgIdxBits)-1,0))
|
2011-11-10 09:23:29 +01:00
|
|
|
}
|
2012-03-17 01:14:43 +01:00
|
|
|
|
2012-11-16 11:39:33 +01:00
|
|
|
when (io.mem.resp.valid) {
|
2012-11-27 11:42:27 +01:00
|
|
|
r_pte := io.mem.resp.bits.data
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
|
2012-05-02 03:23:04 +02:00
|
|
|
io.mem.req.valid := state === s_req
|
2012-11-06 17:13:44 +01:00
|
|
|
io.mem.req.bits.phys := Bool(true)
|
2012-05-02 03:23:04 +02:00
|
|
|
io.mem.req.bits.cmd := M_XRD
|
|
|
|
io.mem.req.bits.typ := MT_D
|
2014-08-08 21:23:02 +02:00
|
|
|
io.mem.req.bits.addr := Cat(r_pte(params(PAddrBits)-1,params(PgIdxBits)), vpn_idx).toUInt << log2Up(params(XprLen)/8)
|
2012-05-02 03:23:04 +02:00
|
|
|
io.mem.req.bits.kill := Bool(false)
|
2011-11-10 06:54:11 +01:00
|
|
|
|
2012-10-10 06:35:03 +02:00
|
|
|
val resp_val = state === s_done || state === s_error
|
|
|
|
val resp_err = state === s_error || state === s_wait
|
2012-11-27 05:38:45 +01:00
|
|
|
|
2014-08-12 03:36:23 +02:00
|
|
|
val r_resp_ppn = io.mem.req.bits.addr >> UInt(params(PgIdxBits))
|
2014-04-17 02:19:08 +02:00
|
|
|
val resp_ppn = Vec((0 until levels-1).map(i => Cat(r_resp_ppn >> bitsPerLevel*(levels-i-1), r_req_vpn(bitsPerLevel*(levels-i-1)-1,0))) :+ r_resp_ppn)(count)
|
2012-05-03 11:29:09 +02:00
|
|
|
|
|
|
|
for (i <- 0 until io.requestor.size) {
|
2013-08-12 19:39:11 +02:00
|
|
|
val me = r_req_dest === UInt(i)
|
2012-10-10 06:35:03 +02:00
|
|
|
io.requestor(i).resp.valid := resp_val && me
|
|
|
|
io.requestor(i).resp.bits.error := resp_err
|
2013-08-24 06:16:28 +02:00
|
|
|
io.requestor(i).resp.bits.perm := r_pte(8,3)
|
2013-08-12 19:39:11 +02:00
|
|
|
io.requestor(i).resp.bits.ppn := resp_ppn.toUInt
|
2012-11-06 17:13:44 +01:00
|
|
|
io.requestor(i).invalidate := io.dpath.invalidate
|
2013-11-25 13:35:15 +01:00
|
|
|
io.requestor(i).sret := io.dpath.sret
|
2012-11-06 17:13:44 +01:00
|
|
|
io.requestor(i).status := io.dpath.status
|
2012-05-03 11:29:09 +02:00
|
|
|
}
|
2011-11-09 23:52:17 +01:00
|
|
|
|
|
|
|
// control state machine
|
|
|
|
switch (state) {
|
|
|
|
is (s_ready) {
|
2012-10-10 06:35:03 +02:00
|
|
|
when (arb.io.out.valid) {
|
2014-01-14 06:43:56 +01:00
|
|
|
state := s_req
|
2011-12-10 09:42:09 +01:00
|
|
|
}
|
2013-08-12 19:39:11 +02:00
|
|
|
count := UInt(0)
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
2012-05-01 10:24:36 +02:00
|
|
|
is (s_req) {
|
2012-05-02 03:23:04 +02:00
|
|
|
when (io.mem.req.ready) {
|
2014-01-14 06:43:56 +01:00
|
|
|
state := s_wait
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
2012-05-01 10:24:36 +02:00
|
|
|
is (s_wait) {
|
2012-05-02 03:23:04 +02:00
|
|
|
when (io.mem.resp.bits.nack) {
|
2012-05-01 10:24:36 +02:00
|
|
|
state := s_req
|
2011-12-10 09:42:09 +01:00
|
|
|
}
|
2012-11-16 11:39:33 +01:00
|
|
|
when (io.mem.resp.valid) {
|
2013-08-24 06:16:28 +02:00
|
|
|
state := s_error
|
|
|
|
when (io.mem.resp.bits.data(0)) {
|
|
|
|
when (!io.mem.resp.bits.data(1)) {
|
|
|
|
state := s_done
|
|
|
|
}.elsewhen (count < levels-1) {
|
2012-05-01 10:24:36 +02:00
|
|
|
state := s_req
|
2013-08-24 06:16:28 +02:00
|
|
|
count := count + 1
|
2012-05-01 10:24:36 +02:00
|
|
|
}
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
2012-05-01 10:24:36 +02:00
|
|
|
}
|
2011-11-09 23:52:17 +01:00
|
|
|
is (s_done) {
|
2014-01-14 06:43:56 +01:00
|
|
|
state := s_ready
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
is (s_error) {
|
2014-01-14 06:43:56 +01:00
|
|
|
state := s_ready
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|