mirror of
				https://github.com/acidanthera/audk.git
				synced 2025-11-03 21:17:23 +01:00 
			
		
		
		
	OvmfPkg/VirtioLib: alloc VRING buffer with AllocateSharedPages()
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>
This commit is contained in:
		
							parent
							
								
									fef6becb55
								
							
						
					
					
						commit
						b0338c5329
					
				@ -42,9 +42,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  @param[out] Ring              The virtio ring to set up.
 | 
					  @param[out] Ring              The virtio ring to set up.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @retval EFI_OUT_OF_RESOURCES  AllocatePages() failed to allocate contiguous
 | 
					  @return                       Status codes propagated from
 | 
				
			||||||
                                pages for the requested QueueSize. Fields of
 | 
					                                VirtIo->AllocateSharedPages().
 | 
				
			||||||
                                Ring have indeterminate value.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @retval EFI_SUCCESS           Allocation and setup successful. Ring->Base
 | 
					  @retval EFI_SUCCESS           Allocation and setup successful. Ring->Base
 | 
				
			||||||
                                (and nothing else) is responsible for
 | 
					                                (and nothing else) is responsible for
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,6 @@
 | 
				
			|||||||
#include <Library/BaseLib.h>
 | 
					#include <Library/BaseLib.h>
 | 
				
			||||||
#include <Library/BaseMemoryLib.h>
 | 
					#include <Library/BaseMemoryLib.h>
 | 
				
			||||||
#include <Library/DebugLib.h>
 | 
					#include <Library/DebugLib.h>
 | 
				
			||||||
#include <Library/MemoryAllocationLib.h>
 | 
					 | 
				
			||||||
#include <Library/UefiBootServicesTableLib.h>
 | 
					#include <Library/UefiBootServicesTableLib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <Library/VirtioLib.h>
 | 
					#include <Library/VirtioLib.h>
 | 
				
			||||||
@ -44,9 +43,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  @param[out] Ring              The virtio ring to set up.
 | 
					  @param[out] Ring              The virtio ring to set up.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @retval EFI_OUT_OF_RESOURCES  AllocatePages() failed to allocate contiguous
 | 
					  @return                       Status codes propagated from
 | 
				
			||||||
                                pages for the requested QueueSize. Fields of
 | 
					                                VirtIo->AllocateSharedPages().
 | 
				
			||||||
                                Ring have indeterminate value.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @retval EFI_SUCCESS           Allocation and setup successful. Ring->Base
 | 
					  @retval EFI_SUCCESS           Allocation and setup successful. Ring->Base
 | 
				
			||||||
                                (and nothing else) is responsible for
 | 
					                                (and nothing else) is responsible for
 | 
				
			||||||
@ -61,6 +59,7 @@ VirtioRingInit (
 | 
				
			|||||||
  OUT VRING                  *Ring
 | 
					  OUT VRING                  *Ring
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  EFI_STATUS     Status;
 | 
				
			||||||
  UINTN          RingSize;
 | 
					  UINTN          RingSize;
 | 
				
			||||||
  volatile UINT8 *RingPagesPtr;
 | 
					  volatile UINT8 *RingPagesPtr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -79,10 +78,17 @@ VirtioRingInit (
 | 
				
			|||||||
                sizeof *Ring->Used.AvailEvent,
 | 
					                sizeof *Ring->Used.AvailEvent,
 | 
				
			||||||
                EFI_PAGE_SIZE);
 | 
					                EFI_PAGE_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  // Allocate a shared ring buffer
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
  Ring->NumPages = EFI_SIZE_TO_PAGES (RingSize);
 | 
					  Ring->NumPages = EFI_SIZE_TO_PAGES (RingSize);
 | 
				
			||||||
  Ring->Base = AllocatePages (Ring->NumPages);
 | 
					  Status = VirtIo->AllocateSharedPages (
 | 
				
			||||||
  if (Ring->Base == NULL) {
 | 
					                     VirtIo,
 | 
				
			||||||
    return EFI_OUT_OF_RESOURCES;
 | 
					                     Ring->NumPages,
 | 
				
			||||||
 | 
					                     &Ring->Base
 | 
				
			||||||
 | 
					                     );
 | 
				
			||||||
 | 
					  if (EFI_ERROR (Status)) {
 | 
				
			||||||
 | 
					    return Status;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  SetMem (Ring->Base, RingSize, 0x00);
 | 
					  SetMem (Ring->Base, RingSize, 0x00);
 | 
				
			||||||
  RingPagesPtr = Ring->Base;
 | 
					  RingPagesPtr = Ring->Base;
 | 
				
			||||||
@ -143,7 +149,7 @@ VirtioRingUninit (
 | 
				
			|||||||
  IN OUT VRING                  *Ring
 | 
					  IN OUT VRING                  *Ring
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  FreePages (Ring->Base, Ring->NumPages);
 | 
					  VirtIo->FreeSharedPages (VirtIo, Ring->NumPages, Ring->Base);
 | 
				
			||||||
  SetMem (Ring, sizeof *Ring, 0x00);
 | 
					  SetMem (Ring, sizeof *Ring, 0x00);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -32,5 +32,4 @@
 | 
				
			|||||||
  BaseLib
 | 
					  BaseLib
 | 
				
			||||||
  BaseMemoryLib
 | 
					  BaseMemoryLib
 | 
				
			||||||
  DebugLib
 | 
					  DebugLib
 | 
				
			||||||
  MemoryAllocationLib
 | 
					 | 
				
			||||||
  UefiBootServicesTableLib
 | 
					  UefiBootServicesTableLib
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user