OvmfPkg/VirtioNetDxe: add Tx packet map/unmap helper functions

When device is behind IOMMU, driver is require to pass the device address
of TxBuf in the Tx VRING. The patch adds helper functions and data
structure to map and unmap the TxBuf system physical address to a device
address.

Since the TxBuf is returned back to caller from VirtioNetGetStatus() hence
we use OrderedCollection interface to save the TxBuf system physical to
device address mapping. After the TxBuf is succesfully transmitted
VirtioNetUnmapTxBuf() does the reverse lookup in OrderedCollection data
structure to get the system physical address of TxBuf for a given device
address.

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>
Tested-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Brijesh Singh
2017-09-14 16:22:45 -05:00
committed by Laszlo Ersek
parent 76ad23ca82
commit bd114d9f77
4 changed files with 279 additions and 2 deletions

View File

@@ -26,6 +26,7 @@
#include <Protocol/DevicePath.h>
#include <Protocol/DriverBinding.h>
#include <Protocol/SimpleNetwork.h>
#include <Library/OrderedCollectionLib.h>
#define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
@@ -100,6 +101,7 @@ typedef struct {
VIRTIO_1_0_NET_REQ *TxSharedReq; // VirtioNetInitTx
VOID *TxSharedReqMap; // VirtioNetInitTx
UINT16 TxLastUsed; // VirtioNetInitTx
ORDERED_COLLECTION *TxBufCollection; // VirtioNetInitTx
} VNET_DEV;
@@ -280,6 +282,42 @@ VirtioNetUninitRing (
IN VOID *RingMap
);
//
// utility functions to map caller-supplied Tx buffer system physical address
// to a device address and vice versa
//
EFI_STATUS
EFIAPI
VirtioNetMapTxBuf (
IN VNET_DEV *Dev,
IN VOID *Buffer,
IN UINTN NumberOfBytes,
OUT EFI_PHYSICAL_ADDRESS *DeviceAddress
);
EFI_STATUS
EFIAPI
VirtioNetUnmapTxBuf (
IN VNET_DEV *Dev,
OUT VOID **Buffer,
IN EFI_PHYSICAL_ADDRESS DeviceAddress
);
INTN
EFIAPI
VirtioNetTxBufMapInfoCompare (
IN CONST VOID *UserStruct1,
IN CONST VOID *UserStruct2
);
INTN
EFIAPI
VirtioNetTxBufDeviceAddressCompare (
IN CONST VOID *StandaloneKey,
IN CONST VOID *UserStruct
);
//
// event callbacks
//