@@ -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