]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: VirtioLib: add Virtio10WriteFeatures() function
authorLaszlo Ersek <lersek@redhat.com>
Sat, 12 Mar 2016 19:37:42 +0000 (20:37 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 6 Apr 2016 17:21:50 +0000 (19:21 +0200)
In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap
through the new VSTAT_FEATURES_OK status bit. (For example if the driver
requests a higher level feature but clears a prerequisite feature.) This
function is a small wrapper around
VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also verifies if the VirtIo
1.0 device accepts the feature bitmap.

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/Library/VirtioLib.h
OvmfPkg/Library/VirtioLib/VirtioLib.c

index decd4418af3d997739e8f39fef3c32fa2bc23759..5badfb32917fab75f85a8eedb647adb22ee0463b 100644 (file)
@@ -189,4 +189,50 @@ VirtioFlush (
   OUT    UINT32                 *UsedLen    OPTIONAL\r
   );\r
 \r
+\r
+/**\r
+\r
+  Report the feature bits to the VirtIo 1.0 device that the VirtIo 1.0 driver\r
+  understands.\r
+\r
+  In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap through\r
+  the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a\r
+  higher level feature but clears a prerequisite feature.) This function is a\r
+  small wrapper around VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also\r
+  verifies if the VirtIo 1.0 device accepts the feature bitmap.\r
+\r
+  @param[in]     VirtIo        Report feature bits to this device.\r
+\r
+  @param[in]     Features      The set of feature bits that the driver wishes\r
+                               to report. The caller is responsible to perform\r
+                               any masking before calling this function; the\r
+                               value is directly written with\r
+                               VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures().\r
+\r
+  @param[in,out] DeviceStatus  On input, the status byte most recently written\r
+                               to the device's status register. On output (even\r
+                               on error), DeviceStatus will be updated so that\r
+                               it is suitable for further status bit\r
+                               manipulation and writing to the device's status\r
+                               register.\r
+\r
+  @retval  EFI_SUCCESS      The device accepted the configuration in Features.\r
+\r
+  @return  EFI_UNSUPPORTED  The device rejected the configuration in Features.\r
+\r
+  @retval  EFI_UNSUPPORTED  VirtIo->Revision is smaller than 1.0.0.\r
+\r
+  @return                   Error codes from the SetGuestFeatures(),\r
+                            SetDeviceStatus(), GetDeviceStatus() member\r
+                            functions.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Virtio10WriteFeatures (\r
+  IN     VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+  IN     UINT64                 Features,\r
+  IN OUT UINT8                  *DeviceStatus\r
+  );\r
+\r
 #endif // _VIRTIO_LIB_H_\r
index 4b1d78b5a03eb45a808b8e09ef89561d8082e468..845f206369a39208bda7bf8c0d65285c6afe2dc7 100644 (file)
@@ -339,3 +339,78 @@ VirtioFlush (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+\r
+/**\r
+\r
+  Report the feature bits to the VirtIo 1.0 device that the VirtIo 1.0 driver\r
+  understands.\r
+\r
+  In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap through\r
+  the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a\r
+  higher level feature but clears a prerequisite feature.) This function is a\r
+  small wrapper around VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also\r
+  verifies if the VirtIo 1.0 device accepts the feature bitmap.\r
+\r
+  @param[in]     VirtIo        Report feature bits to this device.\r
+\r
+  @param[in]     Features      The set of feature bits that the driver wishes\r
+                               to report. The caller is responsible to perform\r
+                               any masking before calling this function; the\r
+                               value is directly written with\r
+                               VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures().\r
+\r
+  @param[in,out] DeviceStatus  On input, the status byte most recently written\r
+                               to the device's status register. On output (even\r
+                               on error), DeviceStatus will be updated so that\r
+                               it is suitable for further status bit\r
+                               manipulation and writing to the device's status\r
+                               register.\r
+\r
+  @retval  EFI_SUCCESS      The device accepted the configuration in Features.\r
+\r
+  @return  EFI_UNSUPPORTED  The device rejected the configuration in Features.\r
+\r
+  @retval  EFI_UNSUPPORTED  VirtIo->Revision is smaller than 1.0.0.\r
+\r
+  @return                   Error codes from the SetGuestFeatures(),\r
+                            SetDeviceStatus(), GetDeviceStatus() member\r
+                            functions.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Virtio10WriteFeatures (\r
+  IN     VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+  IN     UINT64                 Features,\r
+  IN OUT UINT8                  *DeviceStatus\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  if (VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = VirtIo->SetGuestFeatures (VirtIo, Features);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  *DeviceStatus |= VSTAT_FEATURES_OK;\r
+  Status = VirtIo->SetDeviceStatus (VirtIo, *DeviceStatus);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = VirtIo->GetDeviceStatus (VirtIo, DeviceStatus);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if ((*DeviceStatus & VSTAT_FEATURES_OK) == 0) {\r
+    Status = EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return Status;\r
+}\r