|
<< Click to Display Table of Contents >> Navigation: ASA-EMulatR Reference Guide > Introduction > Architecture Overview > Chapter 10 – Devices and Memory-Mapped I/O (MMIO) > 10.3 Device Model Overview |
In EMulatR, a device is an object that owns one or more MMIO address ranges, exposes registers via MMIO, executes operations asynchronously, signals completion via interrupts, and may perform DMA into GuestMemory. Devices do not execute in the CPU pipeline.
All device emulators implement the IDeviceEmulator interface (IDeviceEmulator.h, 266 lines), which defines the contract between devices and the MMIO subsystem.
The interface defines five lifecycle and MMIO methods:
initialize(hoseId, basePA, irqVector, ipl) — Phase 3 initialization. Device stores allocated resources, resets registers to power-on defaults. Called from init thread (not concurrent).
onRead(offset, width, &outValue) → MMIOStatus — Handle MMIO read. MMIOManager has already validated PA, access width, and converted offset to BAR-relative. Device reads from internal register, returns immediately (no blocking I/O). May have side effects (clear-on-read ISR, FIFO pop). May be called concurrently from multiple vCPU threads.
onWrite(offset, width, value) → MMIOStatus — Handle MMIO write. Device writes to internal register, triggers side effects (doorbell writes, command start, interrupt mask update). Returns immediately; long operations deferred to worker thread. May be called concurrently.
onReset() — Reset device to power-on state. Clears registers, pending interrupts, aborts in-flight DMA. Called from init/reset thread.
onFence(kind) — Handle global MMIO fence (MB/WMB). Device may need to drain posted write buffers or complete pending DMA. Default implementation is a no-op.
Plus metadata: deviceUid() and deviceName() for routing and diagnostics.
The mmio_DeviceClass enumeration categorizes all device types:
enum class mmio_DeviceClass : quint8 {
INVALID = 0, UNKNOWN,
// Controllers
SCSI_HBA, IDE_CONTROLLER, NIC,
// Child devices
SCSI_DISK, SCSI_TAPE, SCSI_CDROM, SCSI_CONTROLLER,
IDE_DISK, IDE_CDROM,
UART_CONSOLE, UART,
// Infrastructure
HOST_BRIDGE_NODE, BRIDGE
};
See Also: mmioLib/IDeviceEmulator.h; coreLib/mmio_core.h.