OvmfPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the OvmfPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Andrew Fish <afish@apple.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:09 -08:00
committed by mergify[bot]
parent d1050b9dff
commit ac0a286f4d
445 changed files with 30894 additions and 26369 deletions

View File

@@ -23,10 +23,10 @@
#include "QemuFwCfgLibInternal.h"
STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
STATIC BOOLEAN mQemuFwCfgDmaSupported;
STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
STATIC BOOLEAN mQemuFwCfgDmaSupported;
STATIC EDKII_IOMMU_PROTOCOL *mIoMmuProtocol;
STATIC EDKII_IOMMU_PROTOCOL *mIoMmuProtocol;
/**
Returns a boolean indicating if the firmware configuration interface
@@ -47,21 +47,20 @@ QemuFwCfgIsAvailable (
return InternalQemuFwCfgIsAvailable ();
}
RETURN_STATUS
EFIAPI
QemuFwCfgInitialize (
VOID
)
{
UINT32 Signature;
UINT32 Revision;
UINT32 Signature;
UINT32 Revision;
//
// Enable the access routines while probing to see if it is supported.
// For probing we always use the IO Port (IoReadFifo8()) access method.
//
mQemuFwCfgSupported = TRUE;
mQemuFwCfgSupported = TRUE;
mQemuFwCfgDmaSupported = FALSE;
QemuFwCfgSelectItem (QemuFwCfgItemSignature);
@@ -72,7 +71,8 @@ QemuFwCfgInitialize (
DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision));
if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
(Revision < 1)
) {
)
{
DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
mQemuFwCfgSupported = FALSE;
return RETURN_SUCCESS;
@@ -86,18 +86,24 @@ QemuFwCfgInitialize (
}
if (mQemuFwCfgDmaSupported && MemEncryptSevIsEnabled ()) {
EFI_STATUS Status;
EFI_STATUS Status;
//
// IoMmuDxe driver must have installed the IOMMU protocol. If we are not
// able to locate the protocol then something must have gone wrong.
//
Status = gBS->LocateProtocol (&gEdkiiIoMmuProtocolGuid, NULL,
(VOID **)&mIoMmuProtocol);
Status = gBS->LocateProtocol (
&gEdkiiIoMmuProtocolGuid,
NULL,
(VOID **)&mIoMmuProtocol
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR,
DEBUG ((
DEBUG_ERROR,
"QemuFwCfgSevDma %a:%a Failed to locate IOMMU protocol.\n",
gEfiCallerBaseName, __FUNCTION__));
gEfiCallerBaseName,
__FUNCTION__
));
ASSERT (FALSE);
CpuDeadLoop ();
}
@@ -106,7 +112,6 @@ QemuFwCfgInitialize (
return RETURN_SUCCESS;
}
/**
Returns a boolean indicating if the firmware configuration interface is
available for library-internal purposes.
@@ -148,8 +153,8 @@ InternalQemuFwCfgDmaIsAvailable (
STATIC
VOID
AllocFwCfgDmaAccessBuffer (
OUT VOID **Access,
OUT VOID **MapInfo
OUT VOID **Access,
OUT VOID **MapInfo
)
{
UINTN Size;
@@ -159,7 +164,7 @@ AllocFwCfgDmaAccessBuffer (
EFI_PHYSICAL_ADDRESS DmaAddress;
VOID *Mapping;
Size = sizeof (FW_CFG_DMA_ACCESS);
Size = sizeof (FW_CFG_DMA_ACCESS);
NumPages = EFI_SIZE_TO_PAGES (Size);
//
@@ -176,9 +181,12 @@ AllocFwCfgDmaAccessBuffer (
EDKII_IOMMU_ATTRIBUTE_DUAL_ADDRESS_CYCLE
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR,
"%a:%a failed to allocate FW_CFG_DMA_ACCESS\n", gEfiCallerBaseName,
__FUNCTION__));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to allocate FW_CFG_DMA_ACCESS\n",
gEfiCallerBaseName,
__FUNCTION__
));
ASSERT (FALSE);
CpuDeadLoop ();
}
@@ -202,9 +210,12 @@ AllocFwCfgDmaAccessBuffer (
);
if (EFI_ERROR (Status)) {
mIoMmuProtocol->FreeBuffer (mIoMmuProtocol, NumPages, HostAddress);
DEBUG ((DEBUG_ERROR,
"%a:%a failed to Map() FW_CFG_DMA_ACCESS\n", gEfiCallerBaseName,
__FUNCTION__));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to Map() FW_CFG_DMA_ACCESS\n",
gEfiCallerBaseName,
__FUNCTION__
));
ASSERT (FALSE);
CpuDeadLoop ();
}
@@ -212,14 +223,19 @@ AllocFwCfgDmaAccessBuffer (
if (Size < sizeof (FW_CFG_DMA_ACCESS)) {
mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
mIoMmuProtocol->FreeBuffer (mIoMmuProtocol, NumPages, HostAddress);
DEBUG ((DEBUG_ERROR,
"%a:%a failed to Map() - requested 0x%Lx got 0x%Lx\n", gEfiCallerBaseName,
__FUNCTION__, (UINT64)sizeof (FW_CFG_DMA_ACCESS), (UINT64)Size));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to Map() - requested 0x%Lx got 0x%Lx\n",
gEfiCallerBaseName,
__FUNCTION__,
(UINT64)sizeof (FW_CFG_DMA_ACCESS),
(UINT64)Size
));
ASSERT (FALSE);
CpuDeadLoop ();
}
*Access = HostAddress;
*Access = HostAddress;
*MapInfo = Mapping;
}
@@ -231,8 +247,8 @@ AllocFwCfgDmaAccessBuffer (
STATIC
VOID
FreeFwCfgDmaAccessBuffer (
IN VOID *Access,
IN VOID *Mapping
IN VOID *Access,
IN VOID *Mapping
)
{
UINTN NumPages;
@@ -242,18 +258,26 @@ FreeFwCfgDmaAccessBuffer (
Status = mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR,
"%a:%a failed to UnMap() Mapping 0x%Lx\n", gEfiCallerBaseName,
__FUNCTION__, (UINT64)(UINTN)Mapping));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to UnMap() Mapping 0x%Lx\n",
gEfiCallerBaseName,
__FUNCTION__,
(UINT64)(UINTN)Mapping
));
ASSERT (FALSE);
CpuDeadLoop ();
}
Status = mIoMmuProtocol->FreeBuffer (mIoMmuProtocol, NumPages, Access);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR,
"%a:%a failed to Free() 0x%Lx\n", gEfiCallerBaseName, __FUNCTION__,
(UINT64)(UINTN)Access));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to Free() 0x%Lx\n",
gEfiCallerBaseName,
__FUNCTION__,
(UINT64)(UINTN)Access
));
ASSERT (FALSE);
CpuDeadLoop ();
}
@@ -274,41 +298,51 @@ MapFwCfgDmaDataBuffer (
OUT VOID **MapInfo
)
{
EFI_STATUS Status;
UINTN NumberOfBytes;
VOID *Mapping;
EFI_PHYSICAL_ADDRESS PhysicalAddress;
EFI_STATUS Status;
UINTN NumberOfBytes;
VOID *Mapping;
EFI_PHYSICAL_ADDRESS PhysicalAddress;
NumberOfBytes = Size;
Status = mIoMmuProtocol->Map (
mIoMmuProtocol,
(IsWrite ?
EdkiiIoMmuOperationBusMasterRead64 :
EdkiiIoMmuOperationBusMasterWrite64),
HostAddress,
&NumberOfBytes,
&PhysicalAddress,
&Mapping
);
Status = mIoMmuProtocol->Map (
mIoMmuProtocol,
(IsWrite ?
EdkiiIoMmuOperationBusMasterRead64 :
EdkiiIoMmuOperationBusMasterWrite64),
HostAddress,
&NumberOfBytes,
&PhysicalAddress,
&Mapping
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR,
"%a:%a failed to Map() Address 0x%Lx Size 0x%Lx\n", gEfiCallerBaseName,
__FUNCTION__, (UINT64)(UINTN)HostAddress, (UINT64)Size));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to Map() Address 0x%Lx Size 0x%Lx\n",
gEfiCallerBaseName,
__FUNCTION__,
(UINT64)(UINTN)HostAddress,
(UINT64)Size
));
ASSERT (FALSE);
CpuDeadLoop ();
}
if (NumberOfBytes < Size) {
mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
DEBUG ((DEBUG_ERROR,
"%a:%a failed to Map() - requested 0x%x got 0x%Lx\n", gEfiCallerBaseName,
__FUNCTION__, Size, (UINT64)NumberOfBytes));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to Map() - requested 0x%x got 0x%Lx\n",
gEfiCallerBaseName,
__FUNCTION__,
Size,
(UINT64)NumberOfBytes
));
ASSERT (FALSE);
CpuDeadLoop ();
}
*DeviceAddress = PhysicalAddress;
*MapInfo = Mapping;
*MapInfo = Mapping;
}
STATIC
@@ -321,9 +355,13 @@ UnmapFwCfgDmaDataBuffer (
Status = mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR,
"%a:%a failed to UnMap() Mapping 0x%Lx\n", gEfiCallerBaseName,
__FUNCTION__, (UINT64)(UINTN)Mapping));
DEBUG ((
DEBUG_ERROR,
"%a:%a failed to UnMap() Mapping 0x%Lx\n",
gEfiCallerBaseName,
__FUNCTION__,
(UINT64)(UINTN)Mapping
));
ASSERT (FALSE);
CpuDeadLoop ();
}
@@ -346,29 +384,31 @@ UnmapFwCfgDmaDataBuffer (
**/
VOID
InternalQemuFwCfgDmaBytes (
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
)
{
volatile FW_CFG_DMA_ACCESS LocalAccess;
volatile FW_CFG_DMA_ACCESS *Access;
UINT32 AccessHigh, AccessLow;
UINT32 Status;
VOID *AccessMapping, *DataMapping;
VOID *DataBuffer;
volatile FW_CFG_DMA_ACCESS LocalAccess;
volatile FW_CFG_DMA_ACCESS *Access;
UINT32 AccessHigh, AccessLow;
UINT32 Status;
VOID *AccessMapping, *DataMapping;
VOID *DataBuffer;
ASSERT (Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP);
ASSERT (
Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP
);
if (Size == 0) {
return;
}
Access = &LocalAccess;
Access = &LocalAccess;
AccessMapping = NULL;
DataMapping = NULL;
DataBuffer = Buffer;
DataMapping = NULL;
DataBuffer = Buffer;
//
// When SEV is enabled, map Buffer to DMA address before issuing the DMA
@@ -397,7 +437,7 @@ InternalQemuFwCfgDmaBytes (
&DataMapping
);
DataBuffer = (VOID *) (UINTN) DataBufferAddress;
DataBuffer = (VOID *)(UINTN)DataBufferAddress;
}
}
@@ -416,7 +456,7 @@ InternalQemuFwCfgDmaBytes (
//
AccessHigh = (UINT32)RShiftU64 ((UINTN)Access, 32);
AccessLow = (UINT32)(UINTN)Access;
IoWrite32 (FW_CFG_IO_DMA_ADDRESS, SwapBytes32 (AccessHigh));
IoWrite32 (FW_CFG_IO_DMA_ADDRESS, SwapBytes32 (AccessHigh));
IoWrite32 (FW_CFG_IO_DMA_ADDRESS + 4, SwapBytes32 (AccessLow));
//

View File

@@ -19,7 +19,6 @@
#include "QemuFwCfgLibInternal.h"
/**
Selects a firmware configuration item for reading.
@@ -32,11 +31,11 @@
VOID
EFIAPI
QemuFwCfgSelectItem (
IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
)
{
DEBUG ((DEBUG_INFO, "Select Item: 0x%x\n", (UINT16)(UINTN) QemuFwCfgItem));
IoWrite16 (FW_CFG_IO_SELECTOR, (UINT16)(UINTN) QemuFwCfgItem);
DEBUG ((DEBUG_INFO, "Select Item: 0x%x\n", (UINT16)(UINTN)QemuFwCfgItem));
IoWrite16 (FW_CFG_IO_SELECTOR, (UINT16)(UINTN)QemuFwCfgItem);
}
/**
@@ -49,18 +48,18 @@ QemuFwCfgSelectItem (
VOID
EFIAPI
InternalQemuFwCfgReadBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
IN UINTN Size,
IN VOID *Buffer OPTIONAL
)
{
if (InternalQemuFwCfgDmaIsAvailable () && Size <= MAX_UINT32) {
if (InternalQemuFwCfgDmaIsAvailable () && (Size <= MAX_UINT32)) {
InternalQemuFwCfgDmaBytes ((UINT32)Size, Buffer, FW_CFG_DMA_CTL_READ);
return;
}
IoReadFifo8 (FW_CFG_IO_DATA, Size, Buffer);
}
/**
Reads firmware configuration bytes into a buffer
@@ -75,8 +74,8 @@ InternalQemuFwCfgReadBytes (
VOID
EFIAPI
QemuFwCfgReadBytes (
IN UINTN Size,
IN VOID *Buffer
IN UINTN Size,
IN VOID *Buffer
)
{
if (InternalQemuFwCfgIsAvailable ()) {
@@ -100,20 +99,20 @@ QemuFwCfgReadBytes (
VOID
EFIAPI
QemuFwCfgWriteBytes (
IN UINTN Size,
IN VOID *Buffer
IN UINTN Size,
IN VOID *Buffer
)
{
if (InternalQemuFwCfgIsAvailable ()) {
if (InternalQemuFwCfgDmaIsAvailable () && Size <= MAX_UINT32) {
if (InternalQemuFwCfgDmaIsAvailable () && (Size <= MAX_UINT32)) {
InternalQemuFwCfgDmaBytes ((UINT32)Size, Buffer, FW_CFG_DMA_CTL_WRITE);
return;
}
IoWriteFifo8 (FW_CFG_IO_DATA, Size, Buffer);
}
}
/**
Skip bytes in the firmware configuration item.
@@ -126,17 +125,17 @@ QemuFwCfgWriteBytes (
VOID
EFIAPI
QemuFwCfgSkipBytes (
IN UINTN Size
IN UINTN Size
)
{
UINTN ChunkSize;
UINT8 SkipBuffer[256];
UINTN ChunkSize;
UINT8 SkipBuffer[256];
if (!InternalQemuFwCfgIsAvailable ()) {
return;
}
if (InternalQemuFwCfgDmaIsAvailable () && Size <= MAX_UINT32) {
if (InternalQemuFwCfgDmaIsAvailable () && (Size <= MAX_UINT32)) {
InternalQemuFwCfgDmaBytes ((UINT32)Size, NULL, FW_CFG_DMA_CTL_SKIP);
return;
}
@@ -157,7 +156,6 @@ QemuFwCfgSkipBytes (
}
}
/**
Reads a UINT8 firmware configuration value
@@ -170,14 +168,13 @@ QemuFwCfgRead8 (
VOID
)
{
UINT8 Result;
UINT8 Result;
QemuFwCfgReadBytes (sizeof (Result), &Result);
return Result;
}
/**
Reads a UINT16 firmware configuration value
@@ -190,14 +187,13 @@ QemuFwCfgRead16 (
VOID
)
{
UINT16 Result;
UINT16 Result;
QemuFwCfgReadBytes (sizeof (Result), &Result);
return Result;
}
/**
Reads a UINT32 firmware configuration value
@@ -210,14 +206,13 @@ QemuFwCfgRead32 (
VOID
)
{
UINT32 Result;
UINT32 Result;
QemuFwCfgReadBytes (sizeof (Result), &Result);
return Result;
}
/**
Reads a UINT64 firmware configuration value
@@ -230,14 +225,13 @@ QemuFwCfgRead64 (
VOID
)
{
UINT64 Result;
UINT64 Result;
QemuFwCfgReadBytes (sizeof (Result), &Result);
return Result;
}
/**
Find the configuration item corresponding to the firmware configuration file.
@@ -259,8 +253,8 @@ QemuFwCfgFindFile (
OUT UINTN *Size
)
{
UINT32 Count;
UINT32 Idx;
UINT32 Count;
UINT32 Idx;
if (!InternalQemuFwCfgIsAvailable ()) {
return RETURN_UNSUPPORTED;
@@ -270,15 +264,15 @@ QemuFwCfgFindFile (
Count = SwapBytes32 (QemuFwCfgRead32 ());
for (Idx = 0; Idx < Count; ++Idx) {
UINT32 FileSize;
UINT16 FileSelect;
UINT16 FileReserved;
CHAR8 FName[QEMU_FW_CFG_FNAME_SIZE];
UINT32 FileSize;
UINT16 FileSelect;
UINT16 FileReserved;
CHAR8 FName[QEMU_FW_CFG_FNAME_SIZE];
FileSize = QemuFwCfgRead32 ();
FileSelect = QemuFwCfgRead16 ();
FileReserved = QemuFwCfgRead16 ();
(VOID) FileReserved; /* Force a do-nothing reference. */
(VOID)FileReserved; /* Force a do-nothing reference. */
InternalQemuFwCfgReadBytes (sizeof (FName), FName);
if (AsciiStrCmp (Name, FName) == 0) {

View File

@@ -25,7 +25,6 @@ InternalQemuFwCfgIsAvailable (
VOID
);
/**
Returns a boolean indicating whether QEMU provides the DMA-like access method
for fw_cfg.
@@ -55,9 +54,9 @@ InternalQemuFwCfgDmaIsAvailable (
**/
VOID
InternalQemuFwCfgDmaBytes (
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
);
#endif

View File

@@ -20,9 +20,9 @@
#include <Protocol/FdtClient.h>
STATIC UINTN mFwCfgSelectorAddress;
STATIC UINTN mFwCfgDataAddress;
STATIC UINTN mFwCfgDmaAddress;
STATIC UINTN mFwCfgSelectorAddress;
STATIC UINTN mFwCfgDataAddress;
STATIC UINTN mFwCfgDmaAddress;
/**
Reads firmware configuration bytes into a buffer
@@ -32,7 +32,7 @@ STATIC UINTN mFwCfgDmaAddress;
**/
typedef
VOID (EFIAPI READ_BYTES_FUNCTION) (
VOID(EFIAPI READ_BYTES_FUNCTION)(
IN UINTN Size,
IN VOID *Buffer OPTIONAL
);
@@ -45,7 +45,7 @@ VOID (EFIAPI READ_BYTES_FUNCTION) (
**/
typedef
VOID (EFIAPI WRITE_BYTES_FUNCTION) (
VOID(EFIAPI WRITE_BYTES_FUNCTION)(
IN UINTN Size,
IN VOID *Buffer OPTIONAL
);
@@ -57,27 +57,26 @@ VOID (EFIAPI WRITE_BYTES_FUNCTION) (
**/
typedef
VOID (EFIAPI SKIP_BYTES_FUNCTION) (
VOID(EFIAPI SKIP_BYTES_FUNCTION)(
IN UINTN Size
);
//
// Forward declaration of the two implementations we have.
//
STATIC READ_BYTES_FUNCTION MmioReadBytes;
STATIC WRITE_BYTES_FUNCTION MmioWriteBytes;
STATIC SKIP_BYTES_FUNCTION MmioSkipBytes;
STATIC READ_BYTES_FUNCTION DmaReadBytes;
STATIC WRITE_BYTES_FUNCTION DmaWriteBytes;
STATIC SKIP_BYTES_FUNCTION DmaSkipBytes;
STATIC READ_BYTES_FUNCTION MmioReadBytes;
STATIC WRITE_BYTES_FUNCTION MmioWriteBytes;
STATIC SKIP_BYTES_FUNCTION MmioSkipBytes;
STATIC READ_BYTES_FUNCTION DmaReadBytes;
STATIC WRITE_BYTES_FUNCTION DmaWriteBytes;
STATIC SKIP_BYTES_FUNCTION DmaSkipBytes;
//
// These correspond to the implementation we detect at runtime.
//
STATIC READ_BYTES_FUNCTION *InternalQemuFwCfgReadBytes = MmioReadBytes;
STATIC WRITE_BYTES_FUNCTION *InternalQemuFwCfgWriteBytes = MmioWriteBytes;
STATIC SKIP_BYTES_FUNCTION *InternalQemuFwCfgSkipBytes = MmioSkipBytes;
STATIC READ_BYTES_FUNCTION *InternalQemuFwCfgReadBytes = MmioReadBytes;
STATIC WRITE_BYTES_FUNCTION *InternalQemuFwCfgWriteBytes = MmioWriteBytes;
STATIC SKIP_BYTES_FUNCTION *InternalQemuFwCfgSkipBytes = MmioSkipBytes;
/**
Returns a boolean indicating if the firmware configuration interface
@@ -98,36 +97,46 @@ QemuFwCfgIsAvailable (
return (BOOLEAN)(mFwCfgSelectorAddress != 0 && mFwCfgDataAddress != 0);
}
RETURN_STATUS
EFIAPI
QemuFwCfgInitialize (
VOID
)
{
EFI_STATUS Status;
FDT_CLIENT_PROTOCOL *FdtClient;
CONST UINT64 *Reg;
UINT32 RegSize;
UINTN AddressCells, SizeCells;
UINT64 FwCfgSelectorAddress;
UINT64 FwCfgSelectorSize;
UINT64 FwCfgDataAddress;
UINT64 FwCfgDataSize;
UINT64 FwCfgDmaAddress;
UINT64 FwCfgDmaSize;
EFI_STATUS Status;
FDT_CLIENT_PROTOCOL *FdtClient;
CONST UINT64 *Reg;
UINT32 RegSize;
UINTN AddressCells, SizeCells;
UINT64 FwCfgSelectorAddress;
UINT64 FwCfgSelectorSize;
UINT64 FwCfgDataAddress;
UINT64 FwCfgDataSize;
UINT64 FwCfgDmaAddress;
UINT64 FwCfgDmaSize;
Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
(VOID **)&FdtClient);
Status = gBS->LocateProtocol (
&gFdtClientProtocolGuid,
NULL,
(VOID **)&FdtClient
);
ASSERT_EFI_ERROR (Status);
Status = FdtClient->FindCompatibleNodeReg (FdtClient, "qemu,fw-cfg-mmio",
(CONST VOID **)&Reg, &AddressCells, &SizeCells,
&RegSize);
Status = FdtClient->FindCompatibleNodeReg (
FdtClient,
"qemu,fw-cfg-mmio",
(CONST VOID **)&Reg,
&AddressCells,
&SizeCells,
&RegSize
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN,
DEBUG ((
DEBUG_WARN,
"%a: No 'qemu,fw-cfg-mmio' compatible DT node found (Status == %r)\n",
__FUNCTION__, Status));
__FUNCTION__,
Status
));
return EFI_SUCCESS;
}
@@ -156,8 +165,12 @@ QemuFwCfgInitialize (
mFwCfgSelectorAddress = FwCfgSelectorAddress;
mFwCfgDataAddress = FwCfgDataAddress;
DEBUG ((DEBUG_INFO, "Found FwCfg @ 0x%Lx/0x%Lx\n", FwCfgSelectorAddress,
FwCfgDataAddress));
DEBUG ((
DEBUG_INFO,
"Found FwCfg @ 0x%Lx/0x%Lx\n",
FwCfgSelectorAddress,
FwCfgDataAddress
));
if (SwapBytes64 (Reg[1]) >= 0x18) {
FwCfgDmaAddress = FwCfgDataAddress + 0x10;
@@ -174,7 +187,7 @@ QemuFwCfgInitialize (
}
if (QemuFwCfgIsAvailable ()) {
UINT32 Signature;
UINT32 Signature;
QemuFwCfgSelectItem (QemuFwCfgItemSignature);
Signature = QemuFwCfgRead32 ();
@@ -184,15 +197,15 @@ QemuFwCfgInitialize (
// feature bitmap (which we read without DMA) to confirm the feature.
//
if (FwCfgDmaAddress != 0) {
UINT32 Features;
UINT32 Features;
QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
Features = QemuFwCfgRead32 ();
if ((Features & FW_CFG_F_DMA) != 0) {
mFwCfgDmaAddress = FwCfgDmaAddress;
InternalQemuFwCfgReadBytes = DmaReadBytes;
mFwCfgDmaAddress = FwCfgDmaAddress;
InternalQemuFwCfgReadBytes = DmaReadBytes;
InternalQemuFwCfgWriteBytes = DmaWriteBytes;
InternalQemuFwCfgSkipBytes = DmaSkipBytes;
InternalQemuFwCfgSkipBytes = DmaSkipBytes;
}
}
} else {
@@ -200,10 +213,10 @@ QemuFwCfgInitialize (
mFwCfgDataAddress = 0;
}
}
return RETURN_SUCCESS;
}
/**
Selects a firmware configuration item for reading.
@@ -216,7 +229,7 @@ QemuFwCfgInitialize (
VOID
EFIAPI
QemuFwCfgSelectItem (
IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
)
{
if (QemuFwCfgIsAvailable ()) {
@@ -224,7 +237,6 @@ QemuFwCfgSelectItem (
}
}
/**
Slow READ_BYTES_FUNCTION.
**/
@@ -232,50 +244,53 @@ STATIC
VOID
EFIAPI
MmioReadBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
IN UINTN Size,
IN VOID *Buffer OPTIONAL
)
{
UINTN Left;
UINT8 *Ptr;
UINT8 *End;
UINTN Left;
UINT8 *Ptr;
UINT8 *End;
#if defined(MDE_CPU_AARCH64) || defined(MDE_CPU_RISCV64)
#if defined (MDE_CPU_AARCH64) || defined (MDE_CPU_RISCV64)
Left = Size & 7;
#else
#else
Left = Size & 3;
#endif
#endif
Size -= Left;
Ptr = Buffer;
End = Ptr + Size;
Ptr = Buffer;
End = Ptr + Size;
#if defined(MDE_CPU_AARCH64) || defined(MDE_CPU_RISCV64)
#if defined (MDE_CPU_AARCH64) || defined (MDE_CPU_RISCV64)
while (Ptr < End) {
*(UINT64 *)Ptr = MmioRead64 (mFwCfgDataAddress);
Ptr += 8;
Ptr += 8;
}
if (Left & 4) {
*(UINT32 *)Ptr = MmioRead32 (mFwCfgDataAddress);
Ptr += 4;
Ptr += 4;
}
#else
#else
while (Ptr < End) {
*(UINT32 *)Ptr = MmioRead32 (mFwCfgDataAddress);
Ptr += 4;
Ptr += 4;
}
#endif
#endif
if (Left & 2) {
*(UINT16 *)Ptr = MmioRead16 (mFwCfgDataAddress);
Ptr += 2;
Ptr += 2;
}
if (Left & 1) {
*Ptr = MmioRead8 (mFwCfgDataAddress);
}
}
/**
Transfer an array of bytes, or skip a number of bytes, using the DMA
interface.
@@ -294,16 +309,18 @@ MmioReadBytes (
STATIC
VOID
DmaTransferBytes (
IN UINTN Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
IN UINTN Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
)
{
volatile FW_CFG_DMA_ACCESS Access;
UINT32 Status;
volatile FW_CFG_DMA_ACCESS Access;
UINT32 Status;
ASSERT (Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP);
ASSERT (
Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP
);
if (Size == 0) {
return;
@@ -323,11 +340,11 @@ DmaTransferBytes (
//
// This will fire off the transfer.
//
#if defined(MDE_CPU_AARCH64) || defined(MDE_CPU_RISCV64)
#if defined (MDE_CPU_AARCH64) || defined (MDE_CPU_RISCV64)
MmioWrite64 (mFwCfgDmaAddress, SwapBytes64 ((UINT64)&Access));
#else
#else
MmioWrite32 ((UINT32)(mFwCfgDmaAddress + 4), SwapBytes32 ((UINT32)&Access));
#endif
#endif
//
// We shouldn't look at Access.Control before starting the transfer.
@@ -345,7 +362,6 @@ DmaTransferBytes (
MemoryFence ();
}
/**
Fast READ_BYTES_FUNCTION.
**/
@@ -353,14 +369,13 @@ STATIC
VOID
EFIAPI
DmaReadBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
IN UINTN Size,
IN VOID *Buffer OPTIONAL
)
{
DmaTransferBytes (Size, Buffer, FW_CFG_DMA_CTL_READ);
}
/**
Reads firmware configuration bytes into a buffer
@@ -374,8 +389,8 @@ DmaReadBytes (
VOID
EFIAPI
QemuFwCfgReadBytes (
IN UINTN Size,
IN VOID *Buffer
IN UINTN Size,
IN VOID *Buffer
)
{
if (QemuFwCfgIsAvailable ()) {
@@ -385,7 +400,6 @@ QemuFwCfgReadBytes (
}
}
/**
Slow WRITE_BYTES_FUNCTION.
**/
@@ -393,18 +407,17 @@ STATIC
VOID
EFIAPI
MmioWriteBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
IN UINTN Size,
IN VOID *Buffer OPTIONAL
)
{
UINTN Idx;
UINTN Idx;
for (Idx = 0; Idx < Size; ++Idx) {
MmioWrite8 (mFwCfgDataAddress, ((UINT8 *)Buffer)[Idx]);
}
}
/**
Fast WRITE_BYTES_FUNCTION.
**/
@@ -412,14 +425,13 @@ STATIC
VOID
EFIAPI
DmaWriteBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
IN UINTN Size,
IN VOID *Buffer OPTIONAL
)
{
DmaTransferBytes (Size, Buffer, FW_CFG_DMA_CTL_WRITE);
}
/**
Write firmware configuration bytes from a buffer
@@ -433,8 +445,8 @@ DmaWriteBytes (
VOID
EFIAPI
QemuFwCfgWriteBytes (
IN UINTN Size,
IN VOID *Buffer
IN UINTN Size,
IN VOID *Buffer
)
{
if (QemuFwCfgIsAvailable ()) {
@@ -442,7 +454,6 @@ QemuFwCfgWriteBytes (
}
}
/**
Slow SKIP_BYTES_FUNCTION.
**/
@@ -450,11 +461,11 @@ STATIC
VOID
EFIAPI
MmioSkipBytes (
IN UINTN Size
IN UINTN Size
)
{
UINTN ChunkSize;
UINT8 SkipBuffer[256];
UINTN ChunkSize;
UINT8 SkipBuffer[256];
//
// Emulate the skip by reading data in chunks, and throwing it away. The
@@ -470,7 +481,6 @@ MmioSkipBytes (
}
}
/**
Fast SKIP_BYTES_FUNCTION.
**/
@@ -478,13 +488,12 @@ STATIC
VOID
EFIAPI
DmaSkipBytes (
IN UINTN Size
IN UINTN Size
)
{
DmaTransferBytes (Size, NULL, FW_CFG_DMA_CTL_SKIP);
}
/**
Skip bytes in the firmware configuration item.
@@ -497,7 +506,7 @@ DmaSkipBytes (
VOID
EFIAPI
QemuFwCfgSkipBytes (
IN UINTN Size
IN UINTN Size
)
{
if (QemuFwCfgIsAvailable ()) {
@@ -505,7 +514,6 @@ QemuFwCfgSkipBytes (
}
}
/**
Reads a UINT8 firmware configuration value
@@ -518,13 +526,12 @@ QemuFwCfgRead8 (
VOID
)
{
UINT8 Result;
UINT8 Result;
QemuFwCfgReadBytes (sizeof Result, &Result);
return Result;
}
/**
Reads a UINT16 firmware configuration value
@@ -537,13 +544,12 @@ QemuFwCfgRead16 (
VOID
)
{
UINT16 Result;
UINT16 Result;
QemuFwCfgReadBytes (sizeof Result, &Result);
return Result;
}
/**
Reads a UINT32 firmware configuration value
@@ -556,13 +562,12 @@ QemuFwCfgRead32 (
VOID
)
{
UINT32 Result;
UINT32 Result;
QemuFwCfgReadBytes (sizeof Result, &Result);
return Result;
}
/**
Reads a UINT64 firmware configuration value
@@ -575,13 +580,12 @@ QemuFwCfgRead64 (
VOID
)
{
UINT64 Result;
UINT64 Result;
QemuFwCfgReadBytes (sizeof Result, &Result);
return Result;
}
/**
Find the configuration item corresponding to the firmware configuration file.
@@ -603,8 +607,8 @@ QemuFwCfgFindFile (
OUT UINTN *Size
)
{
UINT32 Count;
UINT32 Idx;
UINT32 Count;
UINT32 Idx;
if (!QemuFwCfgIsAvailable ()) {
return RETURN_UNSUPPORTED;
@@ -614,9 +618,9 @@ QemuFwCfgFindFile (
Count = SwapBytes32 (QemuFwCfgRead32 ());
for (Idx = 0; Idx < Count; ++Idx) {
UINT32 FileSize;
UINT16 FileSelect;
CHAR8 FName[QEMU_FW_CFG_FNAME_SIZE];
UINT32 FileSize;
UINT16 FileSelect;
CHAR8 FName[QEMU_FW_CFG_FNAME_SIZE];
FileSize = QemuFwCfgRead32 ();
FileSelect = QemuFwCfgRead16 ();
@@ -624,7 +628,7 @@ QemuFwCfgFindFile (
InternalQemuFwCfgReadBytes (sizeof (FName), FName);
if (AsciiStrCmp (Name, FName) == 0) {
*Item = (FIRMWARE_CONFIG_ITEM) SwapBytes16 (FileSelect);
*Item = (FIRMWARE_CONFIG_ITEM)SwapBytes16 (FileSelect);
*Size = SwapBytes32 (FileSize);
return RETURN_SUCCESS;
}

View File

@@ -32,7 +32,6 @@ QemuFwCfgIsAvailable (
return FALSE;
}
/**
Selects a firmware configuration item for reading.
@@ -45,13 +44,12 @@ QemuFwCfgIsAvailable (
VOID
EFIAPI
QemuFwCfgSelectItem (
IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
)
{
ASSERT (FALSE);
}
/**
Reads firmware configuration bytes into a buffer
@@ -66,14 +64,13 @@ QemuFwCfgSelectItem (
VOID
EFIAPI
QemuFwCfgReadBytes (
IN UINTN Size,
IN VOID *Buffer OPTIONAL
IN UINTN Size,
IN VOID *Buffer OPTIONAL
)
{
ASSERT (FALSE);
}
/**
Writes firmware configuration bytes from a buffer
@@ -88,14 +85,13 @@ QemuFwCfgReadBytes (
VOID
EFIAPI
QemuFwCfgWriteBytes (
IN UINTN Size,
IN VOID *Buffer
IN UINTN Size,
IN VOID *Buffer
)
{
ASSERT (FALSE);
}
/**
Skip bytes in the firmware configuration item.
@@ -108,13 +104,12 @@ QemuFwCfgWriteBytes (
VOID
EFIAPI
QemuFwCfgSkipBytes (
IN UINTN Size
IN UINTN Size
)
{
ASSERT (FALSE);
}
/**
Reads a UINT8 firmware configuration value
@@ -131,7 +126,6 @@ QemuFwCfgRead8 (
return 0;
}
/**
Reads a UINT16 firmware configuration value
@@ -148,7 +142,6 @@ QemuFwCfgRead16 (
return 0;
}
/**
Reads a UINT32 firmware configuration value
@@ -165,7 +158,6 @@ QemuFwCfgRead32 (
return 0;
}
/**
Reads a UINT64 firmware configuration value
@@ -182,7 +174,6 @@ QemuFwCfgRead64 (
return 0;
}
/**
Find the configuration item corresponding to the firmware configuration file.
@@ -206,4 +197,3 @@ QemuFwCfgFindFile (
{
return RETURN_UNSUPPORTED;
}

View File

@@ -17,9 +17,8 @@
#include "QemuFwCfgLibInternal.h"
STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
STATIC BOOLEAN mQemuFwCfgDmaSupported;
STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
STATIC BOOLEAN mQemuFwCfgDmaSupported;
/**
Returns a boolean indicating if the firmware configuration interface
@@ -40,21 +39,20 @@ QemuFwCfgIsAvailable (
return InternalQemuFwCfgIsAvailable ();
}
RETURN_STATUS
EFIAPI
QemuFwCfgInitialize (
VOID
)
{
UINT32 Signature;
UINT32 Revision;
UINT32 Signature;
UINT32 Revision;
//
// Enable the access routines while probing to see if it is supported.
// For probing we always use the IO Port (IoReadFifo8()) access method.
//
mQemuFwCfgSupported = TRUE;
mQemuFwCfgSupported = TRUE;
mQemuFwCfgDmaSupported = FALSE;
QemuFwCfgSelectItem (QemuFwCfgItemSignature);
@@ -65,7 +63,8 @@ QemuFwCfgInitialize (
DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision));
if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
(Revision < 1)
) {
)
{
DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
mQemuFwCfgSupported = FALSE;
return RETURN_SUCCESS;
@@ -87,10 +86,10 @@ QemuFwCfgInitialize (
DEBUG ((DEBUG_INFO, "QemuFwCfg interface (DMA) is supported.\n"));
}
}
return RETURN_SUCCESS;
}
/**
Returns a boolean indicating if the firmware configuration interface is
available for library-internal purposes.
@@ -140,17 +139,19 @@ InternalQemuFwCfgDmaIsAvailable (
**/
VOID
InternalQemuFwCfgDmaBytes (
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
)
{
volatile FW_CFG_DMA_ACCESS Access;
UINT32 AccessHigh, AccessLow;
UINT32 Status;
volatile FW_CFG_DMA_ACCESS Access;
UINT32 AccessHigh, AccessLow;
UINT32 Status;
ASSERT (Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP);
ASSERT (
Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP
);
if (Size == 0) {
return;
@@ -177,7 +178,7 @@ InternalQemuFwCfgDmaBytes (
//
AccessHigh = (UINT32)RShiftU64 ((UINTN)&Access, 32);
AccessLow = (UINT32)(UINTN)&Access;
IoWrite32 (FW_CFG_IO_DMA_ADDRESS, SwapBytes32 (AccessHigh));
IoWrite32 (FW_CFG_IO_DMA_ADDRESS, SwapBytes32 (AccessHigh));
IoWrite32 (FW_CFG_IO_DMA_ADDRESS + 4, SwapBytes32 (AccessLow));
//
@@ -198,4 +199,3 @@ InternalQemuFwCfgDmaBytes (
//
MemoryFence ();
}

View File

@@ -33,8 +33,8 @@ QemuFwCfgIsAvailable (
VOID
)
{
UINT32 Signature;
UINT32 Revision;
UINT32 Signature;
UINT32 Revision;
QemuFwCfgSelectItem (QemuFwCfgItemSignature);
Signature = QemuFwCfgRead32 ();
@@ -44,7 +44,8 @@ QemuFwCfgIsAvailable (
DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision));
if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
(Revision < 1)
) {
)
{
DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
return FALSE;
}
@@ -53,7 +54,6 @@ QemuFwCfgIsAvailable (
return TRUE;
}
/**
Returns a boolean indicating if the firmware configuration interface is
available for library-internal purposes.
@@ -108,9 +108,9 @@ InternalQemuFwCfgDmaIsAvailable (
**/
VOID
InternalQemuFwCfgDmaBytes (
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
IN UINT32 Size,
IN OUT VOID *Buffer OPTIONAL,
IN UINT32 Control
)
{
//