OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress

Virtio 1.0 allows a more flexible virtio ring layout, so we have to set
addresses for descriptors avail flags and use flags separately.  We
continue to use a ring layout compatible with virtio 0.9.5 though, so no
other changes are needed to setup the virtio queues.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
Gerd Hoffmann 2021-08-27 21:44:56 +08:00 committed by mergify[bot]
parent 212a2b9bb8
commit 537a724421
1 changed files with 25 additions and 2 deletions

View File

@ -183,13 +183,36 @@ VirtioMmioSetQueueAddress (
)
{
VIRTIO_MMIO_DEVICE *Device;
UINT64 Address;
ASSERT (RingBaseShift == 0);
Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
(UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
(UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
} else {
Address = (UINTN)Ring->Base;
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO,
(UINT32)Address);
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_HI,
(UINT32)RShiftU64(Address, 32));
Address = (UINTN)Ring->Avail.Flags;
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_LO,
(UINT32)Address);
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_HI,
(UINT32)RShiftU64(Address, 32));
Address = (UINTN)Ring->Used.Flags;
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_LO,
(UINT32)Address);
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_HI,
(UINT32)RShiftU64(Address, 32));
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_READY, 1);
}
return EFI_SUCCESS;
}