From bc8fde6f62fd038e709b4981babda0f7c7ba8418 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Sat, 12 Mar 2016 00:58:12 +0100 Subject: [PATCH] OvmfPkg: VIRTIO_DEVICE_PROTOCOL: widen the Features bitmap to 64 bits 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 Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Tested-by: Ard Biesheuvel Reviewed-by: Jordan Justen --- OvmfPkg/Include/Protocol/VirtioDevice.h | 8 ++++---- .../VirtioMmioDeviceLib/VirtioMmioDevice.h | 4 ++-- .../VirtioMmioDeviceFunctions.c | 10 +++++++--- OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 2 +- OvmfPkg/VirtioNetDxe/DriverBinding.c | 2 +- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 2 +- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h | 4 ++-- OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c | 17 +++++++++++++---- OvmfPkg/VirtioRngDxe/VirtioRng.c | 2 +- OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 2 +- 10 files changed, 33 insertions(+), 20 deletions(-) diff --git a/OvmfPkg/Include/Protocol/VirtioDevice.h b/OvmfPkg/Include/Protocol/VirtioDevice.h index 48fca2e14c..15750f450c 100644 --- a/OvmfPkg/Include/Protocol/VirtioDevice.h +++ b/OvmfPkg/Include/Protocol/VirtioDevice.h @@ -97,7 +97,7 @@ EFI_STATUS @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - @param[out] DeviceFeatures The 32-bit device features field. + @param[out] DeviceFeatures The device features field. @retval EFI_SUCCESS The data was read successfully. @retval EFI_UNSUPPORTED The underlying IO device doesn't support the @@ -108,7 +108,7 @@ typedef EFI_STATUS (EFIAPI *VIRTIO_GET_DEVICE_FEATURES) ( IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *DeviceFeatures + OUT UINT64 *DeviceFeatures ); /** @@ -116,14 +116,14 @@ EFI_STATUS @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - @param[in] Features The 32-bit guest guest features field + @param[in] Features The guest features field **/ typedef EFI_STATUS (EFIAPI *VIRTIO_SET_GUEST_FEATURES) ( IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT32 Features + IN UINT64 Features ); /** diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h index 3e4e5606cc..d445c3dc19 100644 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h @@ -65,7 +65,7 @@ EFI_STATUS EFIAPI VirtioMmioGetDeviceFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *DeviceFeatures + OUT UINT64 *DeviceFeatures ); EFI_STATUS @@ -141,7 +141,7 @@ EFI_STATUS EFIAPI VirtioMmioSetGuestFeatures ( VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Features + UINT64 Features ); #endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_ diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c index 3950c07f7f..4b7d293283 100644 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c @@ -22,7 +22,7 @@ EFI_STATUS EFIAPI VirtioMmioGetDeviceFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *DeviceFeatures + OUT UINT64 *DeviceFeatures ) { VIRTIO_MMIO_DEVICE *Device; @@ -217,14 +217,18 @@ EFI_STATUS EFIAPI VirtioMmioSetGuestFeatures ( VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Features + UINT64 Features ) { VIRTIO_MMIO_DEVICE *Device; Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, Features); + if (Features > MAX_UINT32) { + return EFI_UNSUPPORTED; + } + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, + (UINT32)Features); return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c index 50511a1e44..b35f60c9d2 100644 --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c @@ -593,7 +593,7 @@ VirtioBlkInit ( UINT8 NextDevStat; EFI_STATUS Status; - UINT32 Features; + UINT64 Features; UINT64 NumSectors; UINT32 BlockSize; UINT8 PhysicalBlockExp; diff --git a/OvmfPkg/VirtioNetDxe/DriverBinding.c b/OvmfPkg/VirtioNetDxe/DriverBinding.c index 0ad39cf972..bcf9ebbdad 100644 --- a/OvmfPkg/VirtioNetDxe/DriverBinding.c +++ b/OvmfPkg/VirtioNetDxe/DriverBinding.c @@ -64,7 +64,7 @@ VirtioNetGetFeatures ( { EFI_STATUS Status; UINT8 NextDevStat; - UINT32 Features; + UINT64 Features; UINTN MacIdx; UINT16 LinkStatus; diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index 223030af9e..71b67fa52d 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -360,7 +360,7 @@ VirtioNetInitialize ( EFI_TPL OldTpl; EFI_STATUS Status; UINT8 NextDevStat; - UINT32 Features; + UINT64 Features; if (This == NULL) { return EFI_INVALID_PARAMETER; diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h index 6311ae849d..812061dc0c 100644 --- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h +++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h @@ -83,7 +83,7 @@ EFI_STATUS EFIAPI VirtioPciGetDeviceFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *DeviceFeatures + OUT UINT64 *DeviceFeatures ); EFI_STATUS @@ -125,7 +125,7 @@ EFI_STATUS EFIAPI VirtioPciSetGuestFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT32 Features + IN UINT64 Features ); EFI_STATUS diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c index 9c40fd94a6..d8d30f9af6 100644 --- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c +++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c @@ -101,10 +101,12 @@ EFI_STATUS EFIAPI VirtioPciGetDeviceFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *DeviceFeatures + OUT UINT64 *DeviceFeatures ) { VIRTIO_PCI_DEVICE *Dev; + EFI_STATUS Status; + UINT32 Features32; if (DeviceFeatures == NULL) { return EFI_INVALID_PARAMETER; @@ -112,8 +114,12 @@ VirtioPciGetDeviceFeatures ( Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This); - return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_DEVICE_FEATURES, sizeof (UINT32), - sizeof (UINT32), DeviceFeatures); + Status = VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_DEVICE_FEATURES, + sizeof (UINT32), sizeof (UINT32), &Features32); + if (!EFI_ERROR (Status)) { + *DeviceFeatures = Features32; + } + return Status; } EFI_STATUS @@ -177,13 +183,16 @@ EFI_STATUS EFIAPI VirtioPciSetGuestFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT32 Features + IN UINT64 Features ) { VIRTIO_PCI_DEVICE *Dev; Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This); + if (Features > MAX_UINT32) { + return EFI_UNSUPPORTED; + } return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES, sizeof (UINT32), Features); } diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c index 8eb1aa300b..de4afefe70 100644 --- a/OvmfPkg/VirtioRngDxe/VirtioRng.c +++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c @@ -203,7 +203,7 @@ VirtioRngInit ( UINT8 NextDevStat; EFI_STATUS Status; UINT16 QueueSize; - UINT32 Features; + UINT64 Features; // // Execute virtio-0.9.5, 2.2.1 Device Initialization Sequence. diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c index f5f412a32e..5295288622 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -707,7 +707,7 @@ VirtioScsiInit ( UINT8 NextDevStat; EFI_STATUS Status; - UINT32 Features; + UINT64 Features; UINT16 MaxChannel; // for validation only UINT32 NumQueues; // for validation only UINT16 QueueSize; -- 2.39.2