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._
|
|
|
|
import Node._
|
|
|
|
import Constants._
|
2012-11-27 05:38:45 +01:00
|
|
|
import Util._
|
2011-11-09 23:52:17 +01:00
|
|
|
|
2012-11-06 17:13:44 +01:00
|
|
|
class IOTLBPTW extends Bundle {
|
|
|
|
val req = new FIFOIO()(UFix(width = VPN_BITS))
|
|
|
|
val resp = new PipeIO()(new Bundle {
|
|
|
|
val error = Bool()
|
|
|
|
val ppn = UFix(width = PPN_BITS)
|
|
|
|
val perm = Bits(width = PERM_BITS)
|
|
|
|
}).flip
|
|
|
|
|
|
|
|
val status = Bits(INPUT, width = 32)
|
|
|
|
val invalidate = Bool(INPUT)
|
|
|
|
}
|
|
|
|
|
|
|
|
class IODatapathPTW extends Bundle {
|
|
|
|
val ptbr = UFix(INPUT, PADDR_BITS)
|
|
|
|
val invalidate = Bool(INPUT)
|
|
|
|
val status = Bits(INPUT, 32)
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
|
2012-11-06 11:55:45 +01:00
|
|
|
class PTW(n: Int)(implicit conf: RocketConfiguration) extends Component
|
2011-11-09 23:52:17 +01:00
|
|
|
{
|
2012-11-06 17:13:44 +01:00
|
|
|
val io = new Bundle {
|
|
|
|
val requestor = Vec(n) { new IOTLBPTW }.flip
|
|
|
|
val mem = new ioHellaCache()(conf.dcache)
|
|
|
|
val dpath = new IODatapathPTW
|
|
|
|
}
|
2011-11-09 23:52:17 +01:00
|
|
|
|
2012-05-01 10:24:36 +02:00
|
|
|
val levels = 3
|
|
|
|
val bitsPerLevel = VPN_BITS/levels
|
|
|
|
require(VPN_BITS == levels * bitsPerLevel)
|
|
|
|
|
|
|
|
val s_ready :: s_req :: s_wait :: s_done :: s_error :: Nil = Enum(5) { UFix() };
|
2012-11-27 05:38:45 +01:00
|
|
|
val state = Reg(resetVal = s_ready)
|
|
|
|
val count = Reg{UFix(width = log2Up(levels))}
|
|
|
|
|
|
|
|
val r_req_vpn = Reg{Bits()}
|
|
|
|
val r_req_dest = Reg{Bits()}
|
|
|
|
val r_req_addr = Reg{UFix(width = PADDR_BITS.max(VADDR_BITS))}
|
|
|
|
val r_resp_perm = Reg{Bits()}
|
2011-11-09 23:52:17 +01:00
|
|
|
|
2012-05-01 10:24:36 +02:00
|
|
|
val vpn_idxs = (1 until levels).map(i => r_req_vpn((levels-i)*bitsPerLevel-1, (levels-i-1)*bitsPerLevel))
|
|
|
|
val vpn_idx = (2 until levels).foldRight(vpn_idxs(0))((i,j) => Mux(count === UFix(i-1), vpn_idxs(i-1), j))
|
2012-03-18 07:00:51 +01:00
|
|
|
|
2012-11-06 11:55:45 +01:00
|
|
|
val arb = new RRArbiter(n)(UFix(width = VPN_BITS))
|
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
|
2012-11-27 05:38:45 +01:00
|
|
|
r_req_addr := Cat(io.dpath.ptbr(PADDR_BITS-1,PGIDX_BITS), arb.io.out.bits(VPN_BITS-1,VPN_BITS-bitsPerLevel)) << log2Up(conf.xprlen/8)
|
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 05:38:45 +01:00
|
|
|
r_req_addr := Cat(io.mem.resp.bits.data(PADDR_BITS-1, PGIDX_BITS), vpn_idx).toUFix << log2Up(conf.xprlen/8)
|
2012-11-16 11:39:33 +01:00
|
|
|
r_resp_perm := io.mem.resp.bits.data(9,4);
|
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
|
2012-11-27 05:38:45 +01:00
|
|
|
io.mem.req.bits.addr := r_req_addr
|
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
|
2011-11-10 09:23:29 +01:00
|
|
|
|
2012-11-16 11:39:33 +01:00
|
|
|
val resp_ptd = io.mem.resp.bits.data(1,0) === Bits(1)
|
|
|
|
val resp_pte = io.mem.resp.bits.data(1,0) === Bits(2)
|
2012-11-27 05:38:45 +01:00
|
|
|
|
|
|
|
val r_resp_ppn = r_req_addr >> PGIDX_BITS
|
|
|
|
val resp_ppns = (0 until levels-1).map(i => Cat(r_resp_ppn >> VPN_BITS-bitsPerLevel*(i+1), r_req_vpn(VPN_BITS-1-bitsPerLevel*(i+1), 0)))
|
2012-05-01 10:24:36 +02:00
|
|
|
val resp_ppn = (0 until levels-1).foldRight(r_resp_ppn)((i,j) => Mux(count === UFix(i), resp_ppns(i), j))
|
2012-05-03 11:29:09 +02:00
|
|
|
|
|
|
|
for (i <- 0 until io.requestor.size) {
|
|
|
|
val me = r_req_dest === UFix(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
|
|
|
|
io.requestor(i).resp.bits.perm := r_resp_perm
|
|
|
|
io.requestor(i).resp.bits.ppn := resp_ppn.toUFix
|
2012-11-06 17:13:44 +01:00
|
|
|
io.requestor(i).invalidate := io.dpath.invalidate
|
|
|
|
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) {
|
2012-05-01 10:24:36 +02:00
|
|
|
state := s_req;
|
2011-12-10 09:42:09 +01:00
|
|
|
}
|
2012-05-01 10:24:36 +02:00
|
|
|
count := UFix(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) {
|
2012-05-01 10:24:36 +02: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) {
|
2011-11-09 23:52:17 +01:00
|
|
|
when (resp_pte) { // page table entry
|
2012-05-01 10:24:36 +02:00
|
|
|
state := s_done
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
2012-02-12 02:20:33 +01:00
|
|
|
.otherwise {
|
2012-05-01 10:24:36 +02:00
|
|
|
count := count + UFix(1)
|
|
|
|
when (resp_ptd && count < UFix(levels-1)) {
|
|
|
|
state := s_req
|
|
|
|
}
|
|
|
|
.otherwise {
|
|
|
|
state := s_error
|
|
|
|
}
|
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) {
|
2012-02-12 02:20:33 +01:00
|
|
|
state := s_ready;
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
is (s_error) {
|
2012-02-12 02:20:33 +01:00
|
|
|
state := s_ready;
|
2011-11-09 23:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|