[edk2] [PATCH v3 04/23] OvmfPkg/VirtioMmioDeviceLib: implement IOMMU-like member functions

Brijesh Singh posted 21 patches 7 years, 4 months ago
[edk2] [PATCH v3 04/23] OvmfPkg/VirtioMmioDeviceLib: implement IOMMU-like member functions
Posted by Brijesh Singh 7 years, 4 months ago
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>
---
 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h          | 36 +++++++++++++
 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c          |  8 ++-
 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c | 57 ++++++++++++++++++++
 3 files changed, 99 insertions(+), 2 deletions(-)

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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v3 04/23] OvmfPkg/VirtioMmioDeviceLib: implement IOMMU-like member functions
Posted by Laszlo Ersek 7 years, 4 months ago
On 08/23/17 14:22, Brijesh Singh wrote:
> 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>
> ---
>  OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h          | 36 +++++++++++++
>  OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c          |  8 ++-
>  OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c | 57 ++++++++++++++++++++
>  3 files changed, 99 insertions(+), 2 deletions(-)

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks,
Laszlo

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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel