Add functions to map and unmap the ring buffer with BusMasterCommonBuffer so that ring can be accessed by both guest and hypervisor.
Cc: Ard Biesheuvel <[email protected]> Cc: Jordan Justen <[email protected]> Cc: Tom Lendacky <[email protected]> Cc: Laszlo Ersek <[email protected]> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh <[email protected]> --- OvmfPkg/Include/Library/VirtioLib.h | 25 +++++++++++ OvmfPkg/Library/VirtioLib/VirtioLib.c | 44 ++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h index ca0b217a04eb..1efb02a68cf1 100644 --- a/OvmfPkg/Include/Library/VirtioLib.h +++ b/OvmfPkg/Include/Library/VirtioLib.h @@ -62,6 +62,31 @@ VirtioRingInit ( /** + Map the ring buffer so that it can be accessed equally by both guest + and hypervisor. + + @param[in] VirtIo The virtio device instance. + + @param[in] Ring The virtio ring to map. + + @param[out] RingBaseShift + + @param[out] Mapping A resulting token to pass to + VirtIo->UnmapSharedBuffer(). + + @return Status from VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioRingMap ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VRING *Ring, + OUT UINT64 *RingBaseShift, + OUT VOID **Mapping + ); + +/** + Tear down the internal resources of a configured virtio ring. The caller is responsible to stop the host from using this ring before diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/VirtioLib/VirtioLib.c index 5b64d18a8d6f..7d07dcc09d3d 100644 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c @@ -498,3 +498,47 @@ Failed: *Mapping = NULL; return EFI_OUT_OF_RESOURCES; } + +/** + + Map the ring buffer so that it can be accessed equally by both guest + and hypervisor. + + @param[in] VirtIo The virtio device instance. + + @param[in] Ring The virtio ring to map. + + @param[out] RingBaseShift RingBaseShift + + @param[out] Mapping A resulting token to pass to + VirtIo->UnmapSharedBuffer(). + + @return Status code from VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioRingMap ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VRING *Ring, + OUT UINT64 *RingBaseShift, + OUT VOID **Mapping + ) +{ + EFI_STATUS Status; + PHYSICAL_ADDRESS DeviceAddress; + + Status = VirtioMapAllBytesInSharedBuffer ( + VirtIo, + VirtioOperationBusMasterCommonBuffer, + Ring->Base, + EFI_PAGES_TO_SIZE (Ring->NumPages), + &DeviceAddress, + Mapping + ); + if (EFI_ERROR (Status)) { + return Status; + } + + *RingBaseShift = DeviceAddress - (UINT64)(UINTN)Ring->Base; + return EFI_SUCCESS; +} -- 2.7.4 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

