OvmfPkg/VirtioMmioDeviceLib: implement IOMMU-like member functions
authorBrijesh Singh <brijesh.singh@amd.com>
Wed, 23 Aug 2017 10:57:16 +0000 (06:57 -0400)
committerLaszlo Ersek <lersek@redhat.com>
Fri, 25 Aug 2017 08:42:18 +0000 (10:42 +0200)
The patch implements the newly added IOMMU-like member functions by
respectively delegating the job to:

- VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages () ->
    MemoryAllocationLib.AllocatePages()

- VIRTIO_DEVICE_PROTOCOL.FreeSharedPages () ->
    MemoryAllocationLib.FreePages ()

- VIRTIO_DEVICE_PROTOCOL.MapSharedBuffer () -> no-op

- VIRTIO_DEVICE_PROTOCOL.UnmapSharedBuffer () -> no-op

Suggested-by: Laszlo Ersek <lersek@redhat.com>
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>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c

index b1d443ea70070f6f29cf27754dd0b689be2de962..fce934e1e9532c316aaa3c33a930b6880e4e120d 100644 (file)
@@ -3,6 +3,7 @@
   This driver produces Virtio Device Protocol instances for Virtio Mmio devices.\r
 \r
   Copyright (C) 2013, ARM Ltd.\r
   This driver produces Virtio Device Protocol instances for Virtio Mmio devices.\r
 \r
   Copyright (C) 2013, ARM Ltd.\r
+  Copyright (C) 2017, AMD Inc. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials are licensed and made available\r
   under the terms and conditions of the BSD License which accompanies this\r
 \r
   This program and the accompanying materials are licensed and made available\r
   under the terms and conditions of the BSD License which accompanies this\r
@@ -15,7 +16,6 @@
 **/\r
 \r
 #include <Library/BaseMemoryLib.h>\r
 **/\r
 \r
 #include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 \r
 #include "VirtioMmioDevice.h"\r
 #include <Library/UefiBootServicesTableLib.h>\r
 \r
 #include "VirtioMmioDevice.h"\r
@@ -35,7 +35,11 @@ static VIRTIO_DEVICE_PROTOCOL mMmioDeviceProtocolTemplate = {
     VirtioMmioGetDeviceStatus,             // GetDeviceStatus\r
     VirtioMmioSetDeviceStatus,             // SetDeviceStatus\r
     VirtioMmioDeviceWrite,                 // WriteDevice\r
     VirtioMmioGetDeviceStatus,             // GetDeviceStatus\r
     VirtioMmioSetDeviceStatus,             // SetDeviceStatus\r
     VirtioMmioDeviceWrite,                 // WriteDevice\r
-    VirtioMmioDeviceRead                   // ReadDevice\r
+    VirtioMmioDeviceRead,                  // ReadDevice\r
+    VirtioMmioAllocateSharedPages,         // AllocateSharedPages\r
+    VirtioMmioFreeSharedPages,             // FreeSharedPages\r
+    VirtioMmioMapSharedBuffer,             // MapSharedBuffer\r
+    VirtioMmioUnmapSharedBuffer            // UnmapSharedBuffer\r
 };\r
 \r
 /**\r
 };\r
 \r
 /**\r
index bedd635e1a861f489e6a1486912192ad11a981ab..e5881d537f09349bf8f0518ee761d88c5151f26a 100644 (file)
@@ -3,6 +3,7 @@
   Internal definitions for the VirtIo MMIO Device driver\r
 \r
   Copyright (C) 2013, ARM Ltd\r
   Internal definitions for the VirtIo MMIO Device driver\r
 \r
   Copyright (C) 2013, ARM Ltd\r
+  Copyright (C) 2017, AMD Inc. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials are licensed and made available\r
   under the terms and conditions of the BSD License which accompanies this\r
 \r
   This program and the accompanying materials are licensed and made available\r
   under the terms and conditions of the BSD License which accompanies this\r
@@ -25,6 +26,7 @@
 #include <Library/IoLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/VirtioMmioDeviceLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/VirtioMmioDeviceLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
 \r
 #define VIRTIO_MMIO_DEVICE_SIGNATURE  SIGNATURE_32 ('V', 'M', 'I', 'O')\r
 \r
 \r
 #define VIRTIO_MMIO_DEVICE_SIGNATURE  SIGNATURE_32 ('V', 'M', 'I', 'O')\r
 \r
@@ -137,4 +139,38 @@ VirtioMmioSetGuestFeatures (
   IN UINT64                  Features\r
   );\r
 \r
   IN UINT64                  Features\r
   );\r
 \r
+EFI_STATUS\r
+EFIAPI\r
+VirtioMmioAllocateSharedPages (\r
+  IN  VIRTIO_DEVICE_PROTOCOL        *This,\r
+  IN  UINTN                         NumPages,\r
+  OUT VOID                          **HostAddress\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+VirtioMmioFreeSharedPages (\r
+  IN  VIRTIO_DEVICE_PROTOCOL        *This,\r
+  IN  UINTN                         NumPages,\r
+  IN  VOID                          *HostAddress\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioMmioMapSharedBuffer (\r
+  IN      VIRTIO_DEVICE_PROTOCOL        *This,\r
+  IN      VIRTIO_MAP_OPERATION          Operation,\r
+  IN      VOID                          *HostAddress,\r
+  IN OUT  UINTN                         *NumberOfBytes,\r
+  OUT     EFI_PHYSICAL_ADDRESS          *DeviceAddress,\r
+  OUT     VOID                          **Mapping\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioMmioUnmapSharedBuffer (\r
+  IN  VIRTIO_DEVICE_PROTOCOL        *This,\r
+  IN  VOID                          *Mapping\r
+  );\r
+\r
 #endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_\r
 #endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_\r
index 9142d4a162c06f43659aa57b649afe7e0226ed84..644ec65e1788b1e319d1f6c7bcf4ee33295cda17 100644 (file)
@@ -293,3 +293,60 @@ VirtioMmioDeviceRead (
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioMmioAllocateSharedPages (\r
+  IN  VIRTIO_DEVICE_PROTOCOL  *This,\r
+  IN  UINTN                   NumPages,\r
+  OUT VOID                    **HostAddress\r
+  )\r
+{\r
+  VOID        *Buffer;\r
+\r
+  Buffer = AllocatePages (NumPages);\r
+  if (Buffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  *HostAddress = Buffer;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+VirtioMmioFreeSharedPages (\r
+  IN  VIRTIO_DEVICE_PROTOCOL  *This,\r
+  IN  UINTN                   NumPages,\r
+  IN  VOID                    *HostAddress\r
+  )\r
+{\r
+  FreePages (HostAddress, NumPages);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioMmioMapSharedBuffer (\r
+  IN      VIRTIO_DEVICE_PROTOCOL  *This,\r
+  IN      VIRTIO_MAP_OPERATION    Operation,\r
+  IN      VOID                    *HostAddress,\r
+  IN OUT  UINTN                   *NumberOfBytes,\r
+  OUT     EFI_PHYSICAL_ADDRESS    *DeviceAddress,\r
+  OUT     VOID                    **Mapping\r
+  )\r
+{\r
+  *DeviceAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r
+  *Mapping = NULL;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioMmioUnmapSharedBuffer (\r
+  IN VIRTIO_DEVICE_PROTOCOL    *This,\r
+  IN VOID                      *Mapping\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r