@@ -15,14 +15,16 @@
WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __VIRTIO_DEVICE_H__
#define __VIRTIO_DEVICE_H__
+#include <IndustryStandard/Virtio.h>
+
// VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0
#define VIRTIO_SPEC_REVISION(major,minor,revision) \
((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
#define VIRTIO_DEVICE_PROTOCOL_GUID { \
0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\
}
@@ -123,32 +125,30 @@ typedef
EFI_STATUS
(EFIAPI *VIRTIO_SET_GUEST_FEATURES) (
IN VIRTIO_DEVICE_PROTOCOL *This,
IN UINT64 Features
);
/**
- Write the queue address field in the Virtio Header.
-
- The parameter Address must be the base address of the virtqueue divided
- by 4096.
+ Write the queue address field(s) in the Virtio Header.
@param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
- @param[in] Address The 32-bit Queue Address field
+ @param[in] Ring The initialized VRING object to take the
+ addresses from.
@retval EFI_SUCCESS The data was written successfully.
@retval EFI_UNSUPPORTED The underlying IO device doesn't support the
provided address offset and write size.
**/
typedef
EFI_STATUS
(EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) (
IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT32 Address
+ IN VRING *Ring
);
/**
Write the queue select field in the Virtio Header.
Writing to the queue select field sets the index of the queue to which
@@ -108,16 +108,16 @@ EFIAPI
VirtioMmioSetQueueSel (
VIRTIO_DEVICE_PROTOCOL *This,
UINT16 Sel
);
EFI_STATUS
VirtioMmioSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN VRING *Ring
);
EFI_STATUS
EFIAPI
VirtioMmioSetQueueAlignment (
VIRTIO_DEVICE_PROTOCOL *This,
UINT32 Alignment
@@ -120,16 +120,16 @@ VirtioPciSetGuestFeatures (
IN VIRTIO_DEVICE_PROTOCOL *This,
IN UINT64 Features
);
EFI_STATUS
EFIAPI
VirtioPciSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN VRING *Ring
);
EFI_STATUS
EFIAPI
VirtioPciSetQueueSel (
VIRTIO_DEVICE_PROTOCOL *This,
UINT16 Sel
@@ -176,23 +176,24 @@ VirtioMmioSetQueueSel (
VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel);
return EFI_SUCCESS;
}
EFI_STATUS
VirtioMmioSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN VRING *Ring
)
{
VIRTIO_MMIO_DEVICE *Device;
Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, Address);
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
+ (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
VirtioMmioSetGuestFeatures (
@@ -726,16 +726,15 @@ VirtioBlkInit (
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
// step 4c -- Report GPFN (guest-physical frame number) of queue.
//
- Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
- (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
+ Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
// step 5 -- Report understood features. There are no virtio-blk specific
@@ -91,16 +91,15 @@ VirtioNetInitRing (
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
// step 4c -- report GPFN (guest-physical frame number) of queue
//
- Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
- (UINT32) ((UINTN) Ring->Base >> EFI_PAGE_SHIFT));
+ Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, Ring);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
return EFI_SUCCESS;
ReleaseQueue:
@@ -177,24 +177,24 @@ VirtioPciSetGuestFeatures (
return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES,
sizeof (UINT32), Features);
}
EFI_STATUS
EFIAPI
VirtioPciSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN VRING *Ring
)
{
VIRTIO_PCI_DEVICE *Dev;
Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_ADDRESS, sizeof (UINT32),
- Address);
+ (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
}
EFI_STATUS
EFIAPI
VirtioPciSetQueueSel (
VIRTIO_DEVICE_PROTOCOL *This,
UINT16 Sel
@@ -280,16 +280,15 @@ VirtioRngInit (
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
// step 4c -- Report GPFN (guest-physical frame number) of queue.
//
- Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
- (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
+ Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
// step 5 -- Report understood features and guest-tuneables. None are
// currently defined for VirtioRng, and no generic features are needed by
@@ -837,16 +837,15 @@ VirtioScsiInit (
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
// step 4c -- Report GPFN (guest-physical frame number) of queue.
//
- Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
- (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
+ Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
// step 5 -- Report understood features and guest-tuneables. We want none of
// the known (or unknown) VIRTIO_SCSI_F_* or VIRTIO_F_* capabilities (see
In virtio-1.0, it is not enough to pass the base address of the virtio queue to the hypervisor (as a frame number); instead it will want the addresses of the descriptor table, the available ring, and the used ring separately. Pass the VRING object to the SetQueueAddress() member function; this will enable a virtio-1.0 implementation. Convert the current producers and consumers to this prototype. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Jordan Justen <jordan.l.justen@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- OvmfPkg/Include/Protocol/VirtioDevice.h | 12 ++++++------ OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h | 4 ++-- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h | 4 ++-- OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c | 7 ++++--- OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 3 +-- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 3 +-- OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c | 6 +++--- OvmfPkg/VirtioRngDxe/VirtioRng.c | 3 +-- OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 3 +-- 9 files changed, 21 insertions(+), 24 deletions(-) -- 1.8.3.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel