Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add PTWProber #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/scala/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import chisel3._
import freechips.rocketchip.system.BaseConfig
import freechips.rocketchip.config.{Parameters, Config}
import freechips.rocketchip.tilelink._
import freechips.rocketchip.tile._
import freechips.rocketchip.subsystem._
import freechips.rocketchip.diplomacy.{AsynchronousCrossing, ClockCrossingType}
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.unittest.UnitTests

class WithRingSystemBus(
Expand Down Expand Up @@ -117,3 +118,10 @@ class WithSerialTLROMFile(file: String) extends Config((site, here, up) => {
class WithTilesStartInReset(harts: Int*) extends Config((site, here, up) => {
case TileResetCtrlKey => up(TileResetCtrlKey, site).copy(initResetHarts = up(TileResetCtrlKey, site).initResetHarts ++ harts)
})

class WithRoCCPTWProber(opcode: OpcodeSet = OpcodeSet.custom0) extends Config((site, here, up) => {
case BuildRoCC => up(BuildRoCC) ++ Seq((p: Parameters) => {
val ptw_prober = LazyModule(new PTWProber(opcode)(p))
ptw_prober
})
})
55 changes: 55 additions & 0 deletions src/main/scala/PTWProber.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package testchipip

import chisel3._
import chisel3.util._

import freechips.rocketchip.tile._
import freechips.rocketchip.rocket._
import freechips.rocketchip.config.{Parameters}

/*
* RoCC "accelerator" which translates a virtual address
* Useful for giving user programs info about physical addresses
*/
class PTWProber(opcodes: OpcodeSet)(implicit p: Parameters) extends LazyRoCC(opcodes, 1) {
override lazy val module = new LazyRoCCModuleImp(this) with HasCoreParameters {
val in_q = Queue(io.cmd)
val in_flight = RegInit(false.B)
val resp_q = Module(new Queue(new RoCCResponse, 2))

val vm_enabled = usingVM.B && io.ptw(0).ptbr.mode(io.ptw(0).ptbr.mode.getWidth-1) && in_q.bits.status.dprv <= PRV.S.U

io.ptw(0).req.valid := in_q.valid && resp_q.io.enq.ready && !in_flight && vm_enabled
io.ptw(0).req.bits.valid := in_q.valid
io.ptw(0).req.bits.bits.addr := in_q.bits.rs1(vaddrBits-1, pgIdxBits)
io.ptw(0).req.bits.bits.vstage1 := false.B
io.ptw(0).req.bits.bits.stage2 := false.B
io.ptw(0).req.bits.bits.need_gpa := false.B

when (io.ptw(0).req.fire()) {
in_flight := true.B
} .elsewhen (io.ptw(0).resp.valid) {
in_flight := false.B
}
in_q.ready := Mux(in_flight, io.ptw(0).resp.valid, !vm_enabled && resp_q.io.enq.ready)


resp_q.io.enq.valid := Mux(in_flight, io.ptw(0).resp.valid, !vm_enabled && in_q.valid)
resp_q.io.enq.bits.rd := in_q.bits.inst.rd
resp_q.io.enq.bits.data := Mux(in_flight,
Mux(io.ptw(0).resp.bits.pf, 0.U, Cat(io.ptw(0).resp.bits.pte.ppn, in_q.bits.rs1(pgIdxBits-1,0))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intent here to determine whether a mapping exists or whether an access would succeed?

As far as I know, io.ptw(0).resp.bits.pf only indicates if the PTE is invalid or the reserved bits are non-zero, not necessarily if the permissions are adequate. Of course, this suffices for the first use case but not the latter.

Access exceptions (ae_ptw and ae_final) should probably also mask the result.

in_q.bits.rs1)

dontTouch(io.ptw(0).resp)

io.resp <> resp_q.io.deq

io.fpu_req.valid := false.B
io.fpu_req.bits := DontCare
io.fpu_resp.ready := false.B
io.mem := DontCare
io.mem.req.valid := false.B
io.busy := in_q.valid || resp_q.io.deq.valid
io.interrupt := false.B
}
}