.. in case the platform does not received the used buffer from the
device, VirtioFlush() returns EFI_TIMEOUT.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.mar...@arm.com>
---
 OvmfPkg/Include/Library/VirtioLib.h   |  3 +++
 OvmfPkg/Library/VirtioLib/VirtioLib.c | 16 ++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/Include/Library/VirtioLib.h 
b/OvmfPkg/Include/Library/VirtioLib.h
index 36527a5..62f6811 100644
--- a/OvmfPkg/Include/Library/VirtioLib.h
+++ b/OvmfPkg/Include/Library/VirtioLib.h
@@ -170,6 +170,9 @@ VirtioAppendDesc (
 
   @return              Error code from VirtIo->SetQueueNotify() if it fails.
 
+  @retval EFI_TIMEOUT  If it did not received the used buffer from the device
+                       in approximatively less than 10ms
+
   @retval EFI_SUCCESS  Otherwise, the host processed all descriptors.
 
 **/
diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c 
b/OvmfPkg/Library/VirtioLib/VirtioLib.c
index 54cf225..566f596 100644
--- a/OvmfPkg/Library/VirtioLib/VirtioLib.c
+++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c
@@ -3,7 +3,7 @@
   Utility functions used by virtio device drivers.
 
   Copyright (C) 2012, Red Hat, Inc.
-  Portion of Copyright (C) 2013, ARM Ltd.
+  Portion of Copyright (C) 2013-2014, ARM Ltd.
 
   This program and the accompanying materials are licensed and made available
   under the terms and conditions of the BSD License which accompanies this
@@ -252,6 +252,9 @@ VirtioAppendDesc (
 
   @return              Error code from VirtIo->SetQueueNotify() if it fails.
 
+  @retval EFI_TIMEOUT  If it did not received the used buffer from the device
+                       in approximatively less than 10ms
+
   @retval EFI_SUCCESS  Otherwise, the host processed all descriptors.
 
 **/
@@ -267,6 +270,7 @@ VirtioFlush (
   UINT16     NextAvailIdx;
   EFI_STATUS Status;
   UINTN      PollPeriodUsecs;
+  UINTN      Timeout;
 
   //
   // virtio-0.9.5, 2.4.1.2 Updating the Available Ring
@@ -304,16 +308,24 @@ VirtioFlush (
   // Keep slowing down until we reach a poll period of slightly above 1 ms.
   //
   PollPeriodUsecs = 1;
+  Timeout = 0;
   MemoryFence();
-  while (*Ring->Used.Idx != NextAvailIdx) {
+  while ((*Ring->Used.Idx != NextAvailIdx) && (Timeout < 10)) {
     gBS->Stall (PollPeriodUsecs); // calls AcpiTimerLib::MicroSecondDelay
 
     if (PollPeriodUsecs < 1024) {
       PollPeriodUsecs *= 2;
+    } else {
+      Timeout++;
     }
     MemoryFence();
   }
 
   MemoryFence();
+
+  if (Timeout == 10) {
+    return EFI_TIMEOUT;
+  }
+
   return EFI_SUCCESS;
 }
-- 
2.1.1


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to