[edk2] [RFC v4 12/13] OvmfPkg/QemuFwCfgLib: Add option to dynamic alloc FW_CFG_DMA Access

Brijesh Singh posted 13 patches 7 years, 7 months ago
There is a newer version of this series
[edk2] [RFC v4 12/13] OvmfPkg/QemuFwCfgLib: Add option to dynamic alloc FW_CFG_DMA Access
Posted by Brijesh Singh 7 years, 7 months ago
Update InternalQemuFwCfgDmaBytes() to work with DMA Access pointer.
The change provides the flexibility to dynamically allocate the "Access"
when SEV is enabled.


Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
index 1bf725d8b7ae..73a19772bee1 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
@@ -68,7 +68,8 @@ InternalQemuFwCfgDmaBytes (
   IN     UINT32   Control
   )
 {
-  volatile FW_CFG_DMA_ACCESS Access;
+  volatile FW_CFG_DMA_ACCESS LocalAccess;
+  volatile FW_CFG_DMA_ACCESS *Access;
   UINT32                     AccessHigh, AccessLow;
   UINT32                     Status;
 
@@ -79,9 +80,11 @@ InternalQemuFwCfgDmaBytes (
     return;
   }
 
-  Access.Control = SwapBytes32 (Control);
-  Access.Length  = SwapBytes32 (Size);
-  Access.Address = SwapBytes64 ((UINTN)Buffer);
+  Access = &LocalAccess;
+
+  Access->Control = SwapBytes32 (Control);
+  Access->Length  = SwapBytes32 (Size);
+  Access->Address = SwapBytes64 ((UINTN)Buffer);
 
   //
   // Delimit the transfer from (a) modifications to Access, (b) in case of a
@@ -92,8 +95,8 @@ InternalQemuFwCfgDmaBytes (
   //
   // Start the transfer.
   //
-  AccessHigh = (UINT32)RShiftU64 ((UINTN)&Access, 32);
-  AccessLow  = (UINT32)(UINTN)&Access;
+  AccessHigh = (UINT32)RShiftU64 ((UINTN)Access, 32);
+  AccessLow  = (UINT32)(UINTN)Access;
   IoWrite32 (FW_CFG_IO_DMA_ADDRESS,     SwapBytes32 (AccessHigh));
   IoWrite32 (FW_CFG_IO_DMA_ADDRESS + 4, SwapBytes32 (AccessLow));
 
@@ -106,7 +109,7 @@ InternalQemuFwCfgDmaBytes (
   // Wait for the transfer to complete.
   //
   do {
-    Status = SwapBytes32 (Access.Control);
+    Status = SwapBytes32 (Access->Control);
     ASSERT ((Status & FW_CFG_DMA_CTL_ERROR) == 0);
   } while (Status != 0);
 
-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [RFC v4 12/13] OvmfPkg/QemuFwCfgLib: Add option to dynamic alloc FW_CFG_DMA Access
Posted by Laszlo Ersek 7 years, 7 months ago
On 05/11/17 00:09, Brijesh Singh wrote:
> Update InternalQemuFwCfgDmaBytes() to work with DMA Access pointer.
> The change provides the flexibility to dynamically allocate the "Access"
> when SEV is enabled.
> 
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
> ---
>  OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)

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

Thanks,
Laszlo

> diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
> index 1bf725d8b7ae..73a19772bee1 100644
> --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
> +++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
> @@ -68,7 +68,8 @@ InternalQemuFwCfgDmaBytes (
>    IN     UINT32   Control
>    )
>  {
> -  volatile FW_CFG_DMA_ACCESS Access;
> +  volatile FW_CFG_DMA_ACCESS LocalAccess;
> +  volatile FW_CFG_DMA_ACCESS *Access;
>    UINT32                     AccessHigh, AccessLow;
>    UINT32                     Status;
>  
> @@ -79,9 +80,11 @@ InternalQemuFwCfgDmaBytes (
>      return;
>    }
>  
> -  Access.Control = SwapBytes32 (Control);
> -  Access.Length  = SwapBytes32 (Size);
> -  Access.Address = SwapBytes64 ((UINTN)Buffer);
> +  Access = &LocalAccess;
> +
> +  Access->Control = SwapBytes32 (Control);
> +  Access->Length  = SwapBytes32 (Size);
> +  Access->Address = SwapBytes64 ((UINTN)Buffer);
>  
>    //
>    // Delimit the transfer from (a) modifications to Access, (b) in case of a
> @@ -92,8 +95,8 @@ InternalQemuFwCfgDmaBytes (
>    //
>    // Start the transfer.
>    //
> -  AccessHigh = (UINT32)RShiftU64 ((UINTN)&Access, 32);
> -  AccessLow  = (UINT32)(UINTN)&Access;
> +  AccessHigh = (UINT32)RShiftU64 ((UINTN)Access, 32);
> +  AccessLow  = (UINT32)(UINTN)Access;
>    IoWrite32 (FW_CFG_IO_DMA_ADDRESS,     SwapBytes32 (AccessHigh));
>    IoWrite32 (FW_CFG_IO_DMA_ADDRESS + 4, SwapBytes32 (AccessLow));
>  
> @@ -106,7 +109,7 @@ InternalQemuFwCfgDmaBytes (
>    // Wait for the transfer to complete.
>    //
>    do {
> -    Status = SwapBytes32 (Access.Control);
> +    Status = SwapBytes32 (Access->Control);
>      ASSERT ((Status & FW_CFG_DMA_CTL_ERROR) == 0);
>    } while (Status != 0);
>  
> 

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