OvmfPkg: VIRTIO_DEVICE_PROTOCOL: widen the Features bitmap to 64 bits
authorLaszlo Ersek <lersek@redhat.com>
Fri, 11 Mar 2016 23:58:12 +0000 (00:58 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 6 Apr 2016 11:04:03 +0000 (13:04 +0200)
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>
OvmfPkg/Include/Protocol/VirtioDevice.h
OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
OvmfPkg/VirtioBlkDxe/VirtioBlk.c
OvmfPkg/VirtioNetDxe/DriverBinding.c
OvmfPkg/VirtioNetDxe/SnpInitialize.c
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c
OvmfPkg/VirtioRngDxe/VirtioRng.c
OvmfPkg/VirtioScsiDxe/VirtioScsi.c

index 48fca2e14c256e1c29ba193f24c13dc26e38a7c2..15750f450cb2497d831c6ce7aa1541029de1298f 100644 (file)
@@ -97,7 +97,7 @@ EFI_STATUS
 \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
@@ -108,7 +108,7 @@ typedef
 EFI_STATUS\r
 (EFIAPI *VIRTIO_GET_DEVICE_FEATURES) (\r
   IN VIRTIO_DEVICE_PROTOCOL *This,\r
-  OUT UINT32                *DeviceFeatures\r
+  OUT UINT64                *DeviceFeatures\r
   );\r
 \r
 /**\r
@@ -116,14 +116,14 @@ EFI_STATUS
 \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
-  IN UINT32                   Features\r
+  IN UINT64                   Features\r
   );\r
 \r
 /**\r
index 3e4e5606ccad09dd8bf7cb8d476c0a7e2e46cb2f..d445c3dc197d86d50796860203571a85d5d8a6cd 100644 (file)
@@ -65,7 +65,7 @@ EFI_STATUS
 EFIAPI\r
 VirtioMmioGetDeviceFeatures (\r
   IN VIRTIO_DEVICE_PROTOCOL *This,\r
-  OUT UINT32                *DeviceFeatures\r
+  OUT UINT64                *DeviceFeatures\r
   );\r
 \r
 EFI_STATUS\r
@@ -141,7 +141,7 @@ EFI_STATUS
 EFIAPI\r
 VirtioMmioSetGuestFeatures (\r
   VIRTIO_DEVICE_PROTOCOL *This,\r
-  UINT32                  Features\r
+  UINT64                  Features\r
   );\r
 \r
 #endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_\r
index 3950c07f7f5d9a0ef1ab54b461b740e1eec82010..4b7d2932836295ebba9c969f2b342420350e413d 100644 (file)
@@ -22,7 +22,7 @@ EFI_STATUS
 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
@@ -217,14 +217,18 @@ EFI_STATUS
 EFIAPI\r
 VirtioMmioSetGuestFeatures (\r
   VIRTIO_DEVICE_PROTOCOL *This,\r
-  UINT32                  Features\r
+  UINT64                  Features\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
index 50511a1e446bb2d2433b20238cf42a13468eed4b..b35f60c9d23385ac3205e30b225aa284354dafb3 100644 (file)
@@ -593,7 +593,7 @@ VirtioBlkInit (
   UINT8      NextDevStat;\r
   EFI_STATUS Status;\r
 \r
-  UINT32     Features;\r
+  UINT64     Features;\r
   UINT64     NumSectors;\r
   UINT32     BlockSize;\r
   UINT8      PhysicalBlockExp;\r
index 0ad39cf9729c0981922b4ab9069b7c64be1beb4e..bcf9ebbdadbdfc4dc495b240d3a62b74cad49664 100644 (file)
@@ -64,7 +64,7 @@ VirtioNetGetFeatures (
 {\r
   EFI_STATUS Status;\r
   UINT8      NextDevStat;\r
-  UINT32     Features;\r
+  UINT64     Features;\r
   UINTN      MacIdx;\r
   UINT16     LinkStatus;\r
 \r
index 223030af9e5d34bac079e1c7cee797d21b3d3d82..71b67fa52df9978a1dd3e9375bf596ddc42618c8 100644 (file)
@@ -360,7 +360,7 @@ VirtioNetInitialize (
   EFI_TPL    OldTpl;\r
   EFI_STATUS Status;\r
   UINT8      NextDevStat;\r
-  UINT32     Features;\r
+  UINT64     Features;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
index 6311ae849d182b61bb49203309ebada420711b78..812061dc0c25b6dd65ec38cb097548e35963b6af 100644 (file)
@@ -83,7 +83,7 @@ EFI_STATUS
 EFIAPI\r
 VirtioPciGetDeviceFeatures (\r
   IN VIRTIO_DEVICE_PROTOCOL *This,\r
-  OUT UINT32                *DeviceFeatures\r
+  OUT UINT64                *DeviceFeatures\r
   );\r
 \r
 EFI_STATUS\r
@@ -125,7 +125,7 @@ EFI_STATUS
 EFIAPI\r
 VirtioPciSetGuestFeatures (\r
   IN VIRTIO_DEVICE_PROTOCOL  *This,\r
-  IN UINT32                   Features\r
+  IN UINT64                   Features\r
   );\r
 \r
 EFI_STATUS\r
index 9c40fd94a6e8ef802c27649100a1b9dada5d6acf..d8d30f9af63d6d7638928020c0e02bae462d320a 100644 (file)
@@ -101,10 +101,12 @@ EFI_STATUS
 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
+  EFI_STATUS                Status;\r
+  UINT32                    Features32;\r
 \r
   if (DeviceFeatures == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -112,8 +114,12 @@ VirtioPciGetDeviceFeatures (
 \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
 }\r
 \r
 EFI_STATUS\r
@@ -177,13 +183,16 @@ EFI_STATUS
 EFIAPI\r
 VirtioPciSetGuestFeatures (\r
   IN VIRTIO_DEVICE_PROTOCOL  *This,\r
-  IN UINT32                   Features\r
+  IN UINT64                   Features\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
index 8eb1aa300b50677d97b02edcd306dff0e3661477..de4afefe7000c68217457ac2983f7c1a2eb80f11 100644 (file)
@@ -203,7 +203,7 @@ VirtioRngInit (
   UINT8      NextDevStat;\r
   EFI_STATUS Status;\r
   UINT16     QueueSize;\r
-  UINT32     Features;\r
+  UINT64     Features;\r
 \r
   //\r
   // Execute virtio-0.9.5, 2.2.1 Device Initialization Sequence.\r
index f5f412a32e9b8909a4d40e029c76bb177ae90b11..52952886226b57c186cd72f15a04e18aec025e18 100644 (file)
@@ -707,7 +707,7 @@ VirtioScsiInit (
   UINT8      NextDevStat;\r
   EFI_STATUS Status;\r
 \r
-  UINT32     Features;\r
+  UINT64     Features;\r
   UINT16     MaxChannel; // for validation only\r
   UINT32     NumQueues;  // for validation only\r
   UINT16     QueueSize;\r