The virtio-1.0 spec widens the Features bitmap to 64 bits. Modify the
declarations of the GetDeviceFeatures() and SetGuestFeatures() protocol
member functions accordingly.
Normally, a protocol cannot be changed in incompatible ways if the GUID
stays the same; however, we've always been extremely clear that
VIRTIO_DEVICE_PROTOCOL is internal to edk2. See for example the top of
"OvmfPkg/Include/Protocol/VirtioDevice.h".
In this patch, all producers and consumers of the GetDeviceFeatures() and
SetGuestFeatures() protocol members are updated.
The drivers that currently produce these members are "legacy" drivers (in
virtio-1.0 terminology), and they cannot (and will not) handle feature
bits above BIT31. Therefore their conversion is only for compatibility
with the modified protocol interface. The consumers will be responsible
for checking the VIRTIO_DEVICE_PROTOCOL.Revision field, and for not
passing feature bits that these backends cannot handle.
The VirtioMmioGetDeviceFeatures() implementation stores the result of an
MmioRead32() call with normal assignment, so it needs no change beyond
adapting its 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>
Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
\r
@param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
\r
\r
@param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
\r
- @param[out] DeviceFeatures The 32-bit device features field.\r
+ @param[out] DeviceFeatures The device features field.\r
\r
@retval EFI_SUCCESS The data was read successfully.\r
@retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
\r
@retval EFI_SUCCESS The data was read successfully.\r
@retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
EFI_STATUS\r
(EFIAPI *VIRTIO_GET_DEVICE_FEATURES) (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFI_STATUS\r
(EFIAPI *VIRTIO_GET_DEVICE_FEATURES) (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
- OUT UINT32 *DeviceFeatures\r
+ OUT UINT64 *DeviceFeatures\r
\r
@param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
\r
\r
@param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
\r
- @param[in] Features The 32-bit guest guest features field\r
+ @param[in] Features The guest features field\r
\r
**/\r
typedef\r
EFI_STATUS\r
(EFIAPI *VIRTIO_SET_GUEST_FEATURES) (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
\r
**/\r
typedef\r
EFI_STATUS\r
(EFIAPI *VIRTIO_SET_GUEST_FEATURES) (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioMmioGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioMmioGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
- OUT UINT32 *DeviceFeatures\r
+ OUT UINT64 *DeviceFeatures\r
EFIAPI\r
VirtioMmioSetGuestFeatures (\r
VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioMmioSetGuestFeatures (\r
VIRTIO_DEVICE_PROTOCOL *This,\r
);\r
\r
#endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_\r
);\r
\r
#endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_\r
EFIAPI\r
VirtioMmioGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioMmioGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
- OUT UINT32 *DeviceFeatures\r
+ OUT UINT64 *DeviceFeatures\r
)\r
{\r
VIRTIO_MMIO_DEVICE *Device;\r
)\r
{\r
VIRTIO_MMIO_DEVICE *Device;\r
EFIAPI\r
VirtioMmioSetGuestFeatures (\r
VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioMmioSetGuestFeatures (\r
VIRTIO_DEVICE_PROTOCOL *This,\r
)\r
{\r
VIRTIO_MMIO_DEVICE *Device;\r
\r
Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);\r
\r
)\r
{\r
VIRTIO_MMIO_DEVICE *Device;\r
\r
Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);\r
\r
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, Features);\r
+ if (Features > MAX_UINT32) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES,\r
+ (UINT32)Features);\r
\r
return EFI_SUCCESS;\r
}\r
\r
return EFI_SUCCESS;\r
}\r
UINT8 NextDevStat;\r
EFI_STATUS Status;\r
\r
UINT8 NextDevStat;\r
EFI_STATUS Status;\r
\r
UINT64 NumSectors;\r
UINT32 BlockSize;\r
UINT8 PhysicalBlockExp;\r
UINT64 NumSectors;\r
UINT32 BlockSize;\r
UINT8 PhysicalBlockExp;\r
{\r
EFI_STATUS Status;\r
UINT8 NextDevStat;\r
{\r
EFI_STATUS Status;\r
UINT8 NextDevStat;\r
UINTN MacIdx;\r
UINT16 LinkStatus;\r
\r
UINTN MacIdx;\r
UINT16 LinkStatus;\r
\r
EFI_TPL OldTpl;\r
EFI_STATUS Status;\r
UINT8 NextDevStat;\r
EFI_TPL OldTpl;\r
EFI_STATUS Status;\r
UINT8 NextDevStat;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
EFIAPI\r
VirtioPciGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioPciGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
- OUT UINT32 *DeviceFeatures\r
+ OUT UINT64 *DeviceFeatures\r
EFIAPI\r
VirtioPciSetGuestFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioPciSetGuestFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioPciGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioPciGetDeviceFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
- OUT UINT32 *DeviceFeatures\r
+ OUT UINT64 *DeviceFeatures\r
)\r
{\r
VIRTIO_PCI_DEVICE *Dev;\r
)\r
{\r
VIRTIO_PCI_DEVICE *Dev;\r
+ EFI_STATUS Status;\r
+ UINT32 Features32;\r
\r
if (DeviceFeatures == NULL) {\r
return EFI_INVALID_PARAMETER;\r
\r
if (DeviceFeatures == NULL) {\r
return EFI_INVALID_PARAMETER;\r
\r
Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);\r
\r
\r
Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);\r
\r
- return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_DEVICE_FEATURES, sizeof (UINT32),\r
- sizeof (UINT32), DeviceFeatures);\r
+ Status = VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_DEVICE_FEATURES,\r
+ sizeof (UINT32), sizeof (UINT32), &Features32);\r
+ if (!EFI_ERROR (Status)) {\r
+ *DeviceFeatures = Features32;\r
+ }\r
+ return Status;\r
EFIAPI\r
VirtioPciSetGuestFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
EFIAPI\r
VirtioPciSetGuestFeatures (\r
IN VIRTIO_DEVICE_PROTOCOL *This,\r
)\r
{\r
VIRTIO_PCI_DEVICE *Dev;\r
\r
Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);\r
\r
)\r
{\r
VIRTIO_PCI_DEVICE *Dev;\r
\r
Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);\r
\r
+ if (Features > MAX_UINT32) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES,\r
sizeof (UINT32), Features);\r
}\r
return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES,\r
sizeof (UINT32), Features);\r
}\r
UINT8 NextDevStat;\r
EFI_STATUS Status;\r
UINT16 QueueSize;\r
UINT8 NextDevStat;\r
EFI_STATUS Status;\r
UINT16 QueueSize;\r
\r
//\r
// Execute virtio-0.9.5, 2.2.1 Device Initialization Sequence.\r
\r
//\r
// Execute virtio-0.9.5, 2.2.1 Device Initialization Sequence.\r
UINT8 NextDevStat;\r
EFI_STATUS Status;\r
\r
UINT8 NextDevStat;\r
EFI_STATUS Status;\r
\r
UINT16 MaxChannel; // for validation only\r
UINT32 NumQueues; // for validation only\r
UINT16 QueueSize;\r
UINT16 MaxChannel; // for validation only\r
UINT32 NumQueues; // for validation only\r
UINT16 QueueSize;\r