17VirtioMmioGetDeviceFeatures (
19 OUT UINT64 *DeviceFeatures
23 UINT32 LowBits, HighBits;
25 if (DeviceFeatures ==
NULL) {
26 return EFI_INVALID_PARAMETER;
29 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
31 if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
32 *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
34 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES_SEL, 0);
35 LowBits = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
36 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES_SEL, 1);
37 HighBits = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
38 *DeviceFeatures =
LShiftU64 (HighBits, 32) | LowBits;
46VirtioMmioGetQueueSize (
48 OUT UINT16 *QueueNumMax
53 if (QueueNumMax ==
NULL) {
54 return EFI_INVALID_PARAMETER;
57 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
59 *QueueNumMax = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM_MAX) & 0xFFFF;
66VirtioMmioGetDeviceStatus (
68 OUT UINT8 *DeviceStatus
73 if (DeviceStatus ==
NULL) {
74 return EFI_INVALID_PARAMETER;
77 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
79 *DeviceStatus = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_STATUS) & 0xFF;
86VirtioMmioSetQueueSize (
93 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
95 if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
96 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, QueueSize);
98 Device->QueueNum = QueueSize;
106VirtioMmioSetDeviceStatus (
108 IN UINT8 DeviceStatus
113 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
115 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_STATUS, DeviceStatus);
122VirtioMmioSetQueueNotify (
124 IN UINT16 QueueNotify
129 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
131 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NOTIFY, QueueNotify);
138VirtioMmioSetQueueAlignment (
145 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
147 if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
148 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_ALIGN, Alignment);
156VirtioMmioSetPageSize (
163 if (PageSize != EFI_PAGE_SIZE) {
164 return EFI_UNSUPPORTED;
167 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
169 if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
170 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE, PageSize);
178VirtioMmioSetQueueSel (
185 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
187 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel);
189 if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
190 Device->QueueNum = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM_MAX) & 0xFFFF;
198VirtioMmioSetQueueAddress (
201 IN UINT64 RingBaseShift
207 ASSERT (RingBaseShift == 0);
209 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
211 if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
214 VIRTIO_MMIO_OFFSET_QUEUE_PFN,
215 (UINT32)((
UINTN)Ring->Base >> EFI_PAGE_SHIFT)
218 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, Device->QueueNum);
220 Address = (
UINTN)Ring->Base;
223 VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO,
228 VIRTIO_MMIO_OFFSET_QUEUE_DESC_HI,
232 Address = (
UINTN)Ring->Avail.Flags;
235 VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_LO,
240 VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_HI,
244 Address = (
UINTN)Ring->Used.Flags;
247 VIRTIO_MMIO_OFFSET_QUEUE_USED_LO,
252 VIRTIO_MMIO_OFFSET_QUEUE_USED_HI,
256 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_READY, 1);
264VirtioMmioSetGuestFeatures (
271 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
273 if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
274 if (Features > MAX_UINT32) {
275 return EFI_UNSUPPORTED;
280 VIRTIO_MMIO_OFFSET_GUEST_FEATURES,
284 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES_SEL, 0);
287 VIRTIO_MMIO_OFFSET_GUEST_FEATURES,
290 VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES_SEL, 1);
293 VIRTIO_MMIO_OFFSET_GUEST_FEATURES,
303VirtioMmioDeviceWrite (
310 UINTN DstBaseAddress;
313 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
318 if ((FieldSize != 1) && (FieldSize != 2) &&
319 (FieldSize != 4) && (FieldSize != 8))
321 return EFI_INVALID_PARAMETER;
327 DstBaseAddress = Device->BaseAddress +
328 VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset;
341VirtioMmioDeviceRead (
349 UINTN SrcBaseAddress;
352 Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
357 ASSERT (FieldSize == BufferSize);
362 if ((FieldSize != 1) && (FieldSize != 2) &&
363 (FieldSize != 4) && (FieldSize != 8))
365 return EFI_INVALID_PARAMETER;
371 SrcBaseAddress = Device->BaseAddress +
372 VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset;
385VirtioMmioAllocateSharedPages (
388 OUT VOID **HostAddress
394 if (Buffer ==
NULL) {
395 return EFI_OUT_OF_RESOURCES;
398 *HostAddress = Buffer;
404VirtioMmioFreeSharedPages (
415VirtioMmioMapSharedBuffer (
417 IN VIRTIO_MAP_OPERATION Operation,
418 IN VOID *HostAddress,
432VirtioMmioUnmapSharedBuffer (
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
UINT8 *EFIAPI MmioReadBuffer8(IN UINTN StartAddress, IN UINTN Length, OUT UINT8 *Buffer)
UINT8 *EFIAPI MmioWriteBuffer8(IN UINTN StartAddress, IN UINTN Length, IN CONST UINT8 *Buffer)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
UINT64 EFI_PHYSICAL_ADDRESS