src/virtio/mmio.bend checks
raw source on the hub · import 0x79c2f5323029fcb91b9cbd02db6800f6/src/virtio/mmio.bend as Mmio
3 imports
import Base import ../lib/u64.bend as U import ../lib/bytes.bend as B
Types
type QueueCfg source · line 30 · raw
Data
QueueCfg@num_max:U32 -> @num:U32 -> @ready:Bool -> @desc:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> @driver:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> @device:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> QueueCfg
type VirtioMmio source · line 33 · raw
Data
VirtioMmio@device_id:U32 -> @device_features:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> @driver_features:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> @device_features_sel:U32 -> @driver_features_sel:U32 -> @queue_sel:U32 -> @queues:List<&2, QueueCfg> -> @status:U32 -> @interrupt_status:U32 -> @config_generation:U32 -> @config:List<&2, U32> -> VirtioMmio
type MmioEvent source · line 49 · raw
Data
What a register write asks the device to do.
NoEventMmioEvent
Notify@queue:U32 -> MmioEvent
The driver wrote QueueNotify with this queue index.
DeviceResetMmioEvent
The driver wrote 0 to Status.
DriverOkMmioEvent
The driver set DRIVER_OK (status value 4) in this write.
Definitions
def Mmio.vendor_id source · line 27 · raw
U32
def Mmio.pick source · line 59 · raw
@b:Bool -> @x:U32 -> @y:U32 -> U32
x when b holds, else y.
def Mmio.pick_ev source · line 66 · raw
@b:Bool -> @x:MmioEvent -> @y:MmioEvent -> MmioEvent
def Mmio.pick_b source · line 73 · raw
@b:Bool -> @x:Bool -> @y:Bool -> Bool
def Mmio.pick_n source · line 80 · raw
@b:Bool -> @x:Nat -> @y:Nat -> Nat
def Mmio.pick_l source · line 87 · raw
@b:Bool -> @x:List<&2, U32> -> @y:List<&2, U32> -> List<&2, U32>
def Mmio.pick_q source · line 94 · raw
@b:Bool -> @x:QueueCfg -> @y:QueueCfg -> QueueCfg
def Mmio.half source · line 103 · raw
@+off:U32 -> @+lo:U32 -> @+v:U32 -> @a:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> 0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64
A 64-bit queue address whose low half sits at offset lo and high half at lo + 4: a write to either replaces that half.
def Mmio.qwrite source · line 111 · raw
@c:QueueCfg -> @+off:U32 -> @+v:U32 -> QueueCfg
A queue register write (QueueNum, QueueReady, the six address halves). A QueueNum above QueueNumMax is dropped (the old value stays): the guest's number sizes the device's loops.
def Mmio.qset source · line 125 · raw
@qs:List<&2, QueueCfg> -> @+i:U32 -> @+sel:U32 -> @+off:U32 -> @+v:U32 -> List<&2, QueueCfg>
Applies a queue register write to queue sel; i counts the list position.
def Mmio.qget.go source · line 132 · raw
@here:Bool -> @h:QueueCfg -> @r:Maybe<&2, QueueCfg> -> Maybe<&2, QueueCfg>
def Mmio.qget source · line 140 · raw
@qs:List<&2, QueueCfg> -> @+i:U32 -> @+sel:U32 -> Maybe<&2, QueueCfg>
Queue sel; i counts the list position.
def Mmio.qreset source · line 148 · raw
@qs:List<&2, QueueCfg> -> List<&2, QueueCfg>
A queue's reset values: num 0, not ready, addresses 0.
def Mmio.qread source · line 158 · raw
@m:Maybe<&2, QueueCfg> -> @+off:U32 -> U32
QueueNumMax and QueueReady of the selected queue; 0 for a missing one.
def Mmio.word source · line 168 · raw
@+sel:U32 -> @a:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> U32
The 32-bit feature word sel: 0 low, 1 high, others 0.
def Mmio.set_word source · line 174 · raw
@on:Bool -> @+sel:U32 -> @+v:U32 -> @a:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> 0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64
A DriverFeatures write (when on) to the word sel; other selectors drop it.
def Mmio.cfg_from source · line 184 · raw
@cfg:List<&2, U32> -> @+k:U32 -> List<&2, U32>
Config bytes from offset k on.
def Mmio.width source · line 192 · raw
@+size:U32 -> Nat
The byte count of a config access: 1, 2, else 4.
def Mmio.peek source · line 197 · raw
@s:VirtioMmio -> @+off:U32 -> @+size:U32 -> U32
A side-effect-free read. Write-only and unknown registers read 0; the shared memory length and base (176..188, 0xb0..0xbc) read -1: no region.
def Mmio.status source · line 213 · raw
@s:VirtioMmio -> U32
def Mmio.status_ev source · line 220 · raw
@zero:Bool -> @+old:U32 -> @+v:U32 -> MmioEvent
The event of a Status write of v over the old status: 0 resets, a write that newly sets DRIVER_OK (4) reports it.
def Mmio.event source · line 227 · raw
@+old:U32 -> @+off:U32 -> @+v:U32 -> MmioEvent
def Mmio.reset_if source · line 232 · raw
@on:Bool -> @s:VirtioMmio -> VirtioMmio
The reset of the driver's side of the device (when on).
def Mmio.next source · line 243 · raw
@s:VirtioMmio -> @+off:U32 -> @+v:U32 -> VirtioMmio
The state after a write. InterruptACK clears the acked bits; writes to read-only registers and config space are dropped.
def VirtioMmio.new source · line 263 · raw
@device_id:U32 -> @features:0x79c2f5323029fcb91b9cbd02db6800f6/src/lib/u64.U64 -> @nqueues:Nat -> @num_max:U32 -> @config:List<&2, U32> -> VirtioMmio
A device of the given id and features with nqueues queues of num_max entries each and the given config space bytes.
def VirtioMmio.read source · line 268 · raw
@s:VirtioMmio -> @off:U32 -> @size:U32 -> Pair(VirtioMmio, U32)
Reads a 32-bit register (config space reads may be 1, 2 or 4 bytes: size).
def VirtioMmio.write source · line 275 · raw
@s:VirtioMmio -> @off:U32 -> @v:U32 -> Pair(VirtioMmio, MmioEvent)
The new state and the event are independent, but stay sequential: as a parallel let this tripped a race in Bend 2.0.39's multithreaded native runtime ("frontier drained without a result"; see AGENTS.md).
def VirtioMmio.queue source · line 283 · raw
@s:VirtioMmio -> @q:U32 -> Maybe<&2, QueueCfg>
The configuration of queue q, if it exists.
def VirtioMmio.accepts source · line 290 · raw
@s:VirtioMmio -> @+mask:U32 -> Bool
Sets bits in InterruptStatus (1 = used buffer, 2 = config change). Whether the driver accepted a feature of the low word (its bit mask).
def VirtioMmio.config_word source · line 296 · raw
@s:VirtioMmio -> U32
The first 32-bit word of the config space, little-endian.
def VirtioMmio.raise source · line 301 · raw
@s:VirtioMmio -> @bits:U32 -> VirtioMmio
def VirtioMmio.irq source · line 307 · raw
@s:VirtioMmio -> Bool
The interrupt line's level: InterruptStatus is non-zero.
def VirtioMmio.config_changed source · line 315 · raw
@s:VirtioMmio -> @cfg:List<&2, U32> -> VirtioMmio
The device changed its config space (virtio-balloon's target): the new bytes, ConfigGeneration one more, and interrupt status bit 2 (config change) raised.
def VirtioMmio.with_config source · line 322 · raw
@s:VirtioMmio -> @cfg:List<&2, U32> -> VirtioMmio
Replaces the config space (a device whose config depends on what the driver selected, as virtio-input's).