|
SimpleKernel 1.17.0
|
Virtio MMIO 传输层 More...
#include <mmio.hpp>


Public Types | |
| enum class | MmioReg : size_t { kMagicValue = 0x000 , kVersion = 0x004 , kDeviceId = 0x008 , kVendorId = 0x00C , kDeviceFeatures = 0x010 , kDeviceFeaturesSel = 0x014 , kDriverFeatures = 0x020 , kDriverFeaturesSel = 0x024 , kQueueSel = 0x030 , kQueueNumMax = 0x034 , kQueueNum = 0x038 , kQueueReady = 0x044 , kQueueNotify = 0x050 , kInterruptStatus = 0x060 , kInterruptAck = 0x064 , kStatus = 0x070 , kQueueDescLow = 0x080 , kQueueDescHigh = 0x084 , kQueueDriverLow = 0x090 , kQueueDriverHigh = 0x094 , kQueueDeviceLow = 0x0A0 , kQueueDeviceHigh = 0x0A4 , kShmSel = 0x0AC , kShmLenLow = 0x0B0 , kShmLenHigh = 0x0B4 , kShmBaseLow = 0x0B8 , kShmBaseHigh = 0x0BC , kQueueReset = 0x0C0 , kConfigGeneration = 0x0FC , kConfig = 0x100 } |
| MMIO 寄存器偏移量 More... | |
Public Types inherited from virtio::Transport | |
| enum class | DeviceStatus : uint32_t { kReset = 0 , kAcknowledge = 1 , kDriver = 2 , kDriverOk = 4 , kFeaturesOk = 8 , kDeviceNeedsReset = 64 , kFailed = 128 } |
| 设备状态位定义 More... | |
Public Member Functions | |
| MmioTransport (uint64_t base) | |
| 构造函数 | |
| auto | IsValid () const -> bool |
| 检查设备是否成功初始化 | |
| auto | GetDeviceId () const -> uint32_t |
| auto | GetVendorId () const -> uint32_t |
| auto | GetStatus () const -> uint32_t |
| auto | SetStatus (uint32_t status) -> void |
| auto | GetDeviceFeatures () -> uint64_t |
| 读取 64 位设备特性 | |
| auto | SetDriverFeatures (uint64_t features) -> void |
| 写入 64 位驱动特性 | |
| auto | GetQueueNumMax (uint32_t queue_idx) -> uint32_t |
| 获取队列最大容量 | |
| auto | SetQueueNum (uint32_t queue_idx, uint32_t num) -> void |
| auto | SetQueueDesc (uint32_t queue_idx, uint64_t addr) -> void |
| 设置描述符表物理地址 | |
| auto | SetQueueAvail (uint32_t queue_idx, uint64_t addr) -> void |
| 设置 Available Ring 物理地址 | |
| auto | SetQueueUsed (uint32_t queue_idx, uint64_t addr) -> void |
| 设置 Used Ring 物理地址 | |
| auto | GetQueueReady (uint32_t queue_idx) -> bool |
| auto | SetQueueReady (uint32_t queue_idx, bool ready) -> void |
| auto | NotifyQueue (uint32_t queue_idx) -> void |
| 通知设备有新的可用缓冲区 | |
| auto | GetInterruptStatus () const -> uint32_t |
| auto | AckInterrupt (uint32_t ack_bits) -> void |
| auto | ReadConfigU8 (uint32_t offset) const -> uint8_t |
| 读取配置空间 8 位值 | |
| auto | ReadConfigU16 (uint32_t offset) const -> uint16_t |
| 读取配置空间 16 位值 | |
| auto | ReadConfigU32 (uint32_t offset) const -> uint32_t |
| 读取配置空间 32 位值 | |
| auto | ReadConfigU64 (uint32_t offset) const -> uint64_t |
| 读取配置空间 64 位值 | |
| auto | GetConfigGeneration () const -> uint32_t |
构造/析构函数 | |
| MmioTransport (MmioTransport &&other) noexcept | |
| auto | operator= (MmioTransport &&) noexcept -> MmioTransport &=delete |
| MmioTransport (const MmioTransport &)=delete | |
| auto | operator= (const MmioTransport &) -> MmioTransport &=delete |
Public Member Functions inherited from virtio::Transport | |
| auto | Reset (this auto &&self) -> void |
| 重置设备 | |
| auto | NeedsReset (this auto const &self) -> bool |
| 检查设备是否需要重置 | |
| auto | IsActive (this auto const &self) -> bool |
| 检查设备是否已激活(DRIVER_OK 已设置) | |
| auto | AcknowledgeInterrupt (this auto &&self) -> void |
| 确认并清除设备中断 | |
Private Attributes | |
| MmioAccessor | mmio_ |
| MMIO 寄存器访问器 | |
| bool | is_valid_ |
| 设备是否成功初始化 | |
| uint32_t | device_id_ |
| 设备 ID(缓存以避免重复读取) | |
| uint32_t | vendor_id_ |
| 供应商 ID(缓存以避免重复读取) | |
Additional Inherited Members | |
Protected Member Functions inherited from virtio::Transport | |
| Transport ()=default | |
| ~Transport ()=default | |
| Transport (Transport &&) noexcept=default | |
| auto | operator= (Transport &&) noexcept -> Transport &=default |
| Transport (const Transport &)=delete | |
| auto | operator= (const Transport &) -> Transport &=delete |
Virtio MMIO 传输层
MMIO virtio 设备通过一组内存映射的控制寄存器和设备特定配置空间进行访问。 所有寄存器值采用小端格式组织。
仅支持 Modern VirtIO (v2, virtio 1.0+)。
寄存器布局包括:
|
strong |
MMIO 寄存器偏移量
Definition at line 67 of file mmio.hpp.
|
inlineexplicit |
构造函数
在构造时完成以下初始化:
| base | MMIO 寄存器基地址 |
Definition at line 126 of file mmio.hpp.

|
inlinenoexcept |
Definition at line 159 of file mmio.hpp.
|
delete |
|
inline |
Definition at line 302 of file mmio.hpp.

|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
delete |
|
deletenoexcept |
|
inline |
|
inline |
|
inline |
读取配置空间 64 位值
使用 generation counter 机制保证读取的 64 位配置数据一致性:
| offset | 相对于配置空间起始的偏移量 |
Definition at line 348 of file mmio.hpp.

|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
|
private |
|
private |