]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioLib: alloc VRING buffer with AllocateSharedPages()
authorBrijesh Singh <brijesh.singh@amd.com>
Wed, 23 Aug 2017 10:57:18 +0000 (06:57 -0400)
committerLaszlo Ersek <lersek@redhat.com>
Fri, 25 Aug 2017 08:42:19 +0000 (10:42 +0200)
The VRING buffer is a communication area between guest and hypervisor.
Allocate it using VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages() so that
it can be mapped later with VirtioRingMap() for bi-directional access.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
[lersek@redhat.com: correct typo in VirtioRingInit() comment blocks]
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/Include/Library/VirtioLib.h
OvmfPkg/Library/VirtioLib/VirtioLib.c
OvmfPkg/Library/VirtioLib/VirtioLib.inf

index 6a422deba2d97d51ac05ab6dbe7754d908cd7fd8..547b4ee497b85b2168ebec8dce25db895f2ff0ad 100644 (file)
@@ -42,9 +42,8 @@
 \r
   @param[out] Ring              The virtio ring to set up.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  AllocatePages() failed to allocate contiguous\r
-                                pages for the requested QueueSize. Fields of\r
-                                Ring have indeterminate value.\r
+  @return                       Status codes propagated from\r
+                                VirtIo->AllocateSharedPages().\r
 \r
   @retval EFI_SUCCESS           Allocation and setup successful. Ring->Base\r
                                 (and nothing else) is responsible for\r
index 84acfe6183d36bf0304fc935dd288a1f2ad47244..40ea17dfaf86ad0dc1aed0c2a3dd55bcf64eb992 100644 (file)
@@ -19,7 +19,6 @@
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 \r
 #include <Library/VirtioLib.h>\r
@@ -44,9 +43,8 @@
 \r
   @param[out] Ring              The virtio ring to set up.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  AllocatePages() failed to allocate contiguous\r
-                                pages for the requested QueueSize. Fields of\r
-                                Ring have indeterminate value.\r
+  @return                       Status codes propagated from\r
+                                VirtIo->AllocateSharedPages().\r
 \r
   @retval EFI_SUCCESS           Allocation and setup successful. Ring->Base\r
                                 (and nothing else) is responsible for\r
@@ -61,6 +59,7 @@ VirtioRingInit (
   OUT VRING                  *Ring\r
   )\r
 {\r
+  EFI_STATUS     Status;\r
   UINTN          RingSize;\r
   volatile UINT8 *RingPagesPtr;\r
 \r
@@ -79,10 +78,17 @@ VirtioRingInit (
                 sizeof *Ring->Used.AvailEvent,\r
                 EFI_PAGE_SIZE);\r
 \r
+  //\r
+  // Allocate a shared ring buffer\r
+  //\r
   Ring->NumPages = EFI_SIZE_TO_PAGES (RingSize);\r
-  Ring->Base = AllocatePages (Ring->NumPages);\r
-  if (Ring->Base == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  Status = VirtIo->AllocateSharedPages (\r
+                     VirtIo,\r
+                     Ring->NumPages,\r
+                     &Ring->Base\r
+                     );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
   SetMem (Ring->Base, RingSize, 0x00);\r
   RingPagesPtr = Ring->Base;\r
@@ -143,7 +149,7 @@ VirtioRingUninit (
   IN OUT VRING                  *Ring\r
   )\r
 {\r
-  FreePages (Ring->Base, Ring->NumPages);\r
+  VirtIo->FreeSharedPages (VirtIo, Ring->NumPages, Ring->Base);\r
   SetMem (Ring, sizeof *Ring, 0x00);\r
 }\r
 \r
index fb5897a88ecf897b51cc9f89400f5ff257480443..e33856de38c4de26cff6017ff677c8988b1c5c67 100644 (file)
@@ -32,5 +32,4 @@
   BaseLib\r
   BaseMemoryLib\r
   DebugLib\r
-  MemoryAllocationLib\r
   UefiBootServicesTableLib\r