TianoCore EDK2 master
Loading...
Searching...
No Matches
QemuFwCfgAcpi.c File Reference

Go to the source code of this file.

Data Structures

struct  BLOB
 

Macros

#define INSTALLED_TABLES_MAX   128
 

Functions

STATIC INTN EFIAPI BlobKeyCompare (IN CONST VOID *StandaloneKey, IN CONST VOID *UserStruct)
 
STATIC INTN EFIAPI BlobCompare (IN CONST VOID *UserStruct1, IN CONST VOID *UserStruct2)
 
STATIC INTN EFIAPI PointerCompare (IN CONST VOID *Pointer1, IN CONST VOID *Pointer2)
 
STATIC INTN EFIAPI AsciiStringCompare (IN CONST VOID *AsciiString1, IN CONST VOID *AsciiString2)
 
STATIC VOID ReleaseAllocationsRestrictedTo32Bit (IN ORDERED_COLLECTION *AllocationsRestrictedTo32Bit)
 
STATIC EFI_STATUS CollectAllocationsRestrictedTo32Bit (OUT ORDERED_COLLECTION **AllocationsRestrictedTo32Bit, IN CONST QEMU_LOADER_ENTRY *LoaderStart, IN CONST QEMU_LOADER_ENTRY *LoaderEnd)
 
STATIC EFI_STATUS EFIAPI ProcessCmdAllocate (IN CONST QEMU_LOADER_ALLOCATE *Allocate, IN OUT ORDERED_COLLECTION *Tracker, IN ORDERED_COLLECTION *AllocationsRestrictedTo32Bit)
 
STATIC EFI_STATUS EFIAPI ProcessCmdAddPointer (IN CONST QEMU_LOADER_ADD_POINTER *AddPointer, IN CONST ORDERED_COLLECTION *Tracker)
 
STATIC EFI_STATUS EFIAPI ProcessCmdAddChecksum (IN CONST QEMU_LOADER_ADD_CHECKSUM *AddChecksum, IN CONST ORDERED_COLLECTION *Tracker)
 
STATIC EFI_STATUS ProcessCmdWritePointer (IN CONST QEMU_LOADER_WRITE_POINTER *WritePointer, IN CONST ORDERED_COLLECTION *Tracker, IN OUT S3_CONTEXT *S3Context OPTIONAL)
 
STATIC VOID UndoCmdWritePointer (IN CONST QEMU_LOADER_WRITE_POINTER *WritePointer)
 
STATIC EFI_STATUS EFIAPI Process2ndPassCmdAddPointer (IN CONST QEMU_LOADER_ADD_POINTER *AddPointer, IN CONST ORDERED_COLLECTION *Tracker, IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN OUT UINTN InstalledKey[INSTALLED_TABLES_MAX], IN OUT INT32 *NumInstalled, IN OUT ORDERED_COLLECTION *SeenPointers)
 
EFI_STATUS EFIAPI InstallQemuFwCfgTables (IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol)
 

Detailed Description

OVMF ACPI support using QEMU's fw-cfg interface

Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
Copyright (C) 2012-2014, Red Hat, Inc.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file QemuFwCfgAcpi.c.

Macro Definition Documentation

◆ INSTALLED_TABLES_MAX

#define INSTALLED_TABLES_MAX   128

Definition at line 835 of file QemuFwCfgAcpi.c.

Function Documentation

◆ AsciiStringCompare()

STATIC INTN EFIAPI AsciiStringCompare ( IN CONST VOID *  AsciiString1,
IN CONST VOID *  AsciiString2 
)

Comparator function for two ASCII strings. Can be used as both Key and UserStruct comparator.

This function exists solely so we can avoid casting &AsciiStrCmp to ORDERED_COLLECTION_USER_COMPARE and ORDERED_COLLECTION_KEY_COMPARE.

Parameters
[in]AsciiString1Pointer to the first ASCII string.
[in]AsciiString2Pointer to the second ASCII string.
Returns
The return value of AsciiStrCmp (AsciiString1, AsciiString2).

Definition at line 145 of file QemuFwCfgAcpi.c.

◆ BlobCompare()

STATIC INTN EFIAPI BlobCompare ( IN CONST VOID *  UserStruct1,
IN CONST VOID *  UserStruct2 
)

Comparator function for two user structures.

Parameters
[in]UserStruct1Pointer to the first user structure.
[in]UserStruct2Pointer to the second user structure.
Return values
<0If UserStruct1 compares less than UserStruct2.
0If UserStruct1 compares equal to UserStruct2.
>0If UserStruct1 compares greater than UserStruct2.

Definition at line 84 of file QemuFwCfgAcpi.c.

◆ BlobKeyCompare()

STATIC INTN EFIAPI BlobKeyCompare ( IN CONST VOID *  StandaloneKey,
IN CONST VOID *  UserStruct 
)

Compare a standalone key against a user structure containing an embedded key.

Parameters
[in]StandaloneKeyPointer to the bare key.
[in]UserStructPointer to the user structure with the embedded key.
Return values
<0If StandaloneKey compares less than UserStruct's key.
0If StandaloneKey compares equal to UserStruct's key.
>0If StandaloneKey compares greater than UserStruct's key.

Definition at line 57 of file QemuFwCfgAcpi.c.

◆ CollectAllocationsRestrictedTo32Bit()

STATIC EFI_STATUS CollectAllocationsRestrictedTo32Bit ( OUT ORDERED_COLLECTION **  AllocationsRestrictedTo32Bit,
IN CONST QEMU_LOADER_ENTRY LoaderStart,
IN CONST QEMU_LOADER_ENTRY LoaderEnd 
)

Iterate over the linker/loader script, and collect the names of the fw_cfg blobs that are referenced by QEMU_LOADER_ADD_POINTER.PointeeFile fields, such that QEMU_LOADER_ADD_POINTER.PointerSize is less than 8. This means that the pointee blob's address will have to be patched into a narrower-than-8 byte pointer field, hence the pointee blob must not be allocated from 64-bit address space.

Parameters
[out]AllocationsRestrictedTo32BitThe ORDERED_COLLECTION structure linking (not copying / owning) such QEMU_LOADER_ADD_POINTER.PointeeFile fields that name the blobs restricted from 64-bit allocation.
[in]LoaderStartPoints to the first entry in the linker/loader script.
[in]LoaderEndPoints one past the last entry in the linker/loader script.
Return values
EFI_SUCCESSAllocationsRestrictedTo32Bit has been populated.
EFI_OUT_OF_RESOURCESMemory allocation failed.
EFI_PROTOCOL_ERRORInvalid linker/loader script contents.

Definition at line 211 of file QemuFwCfgAcpi.c.

◆ InstallQemuFwCfgTables()

EFI_STATUS EFIAPI InstallQemuFwCfgTables ( IN EFI_ACPI_TABLE_PROTOCOL AcpiProtocol)

Download, process, and install ACPI table data from the QEMU loader interface.

Parameters
[in]AcpiProtocolThe ACPI table protocol used to install tables.
Return values
EFI_UNSUPPORTEDFirmware configuration is unavailable, or QEMU loader command with unsupported parameters has been found.
EFI_NOT_FOUNDThe host doesn't export the required fw_cfg files.
EFI_OUT_OF_RESOURCESMemory allocation failed, or more than INSTALLED_TABLES_MAX tables found.
EFI_PROTOCOL_ERRORFound invalid fw_cfg contents.
Returns
Status codes returned by AcpiProtocol->InstallAcpiTable().

Definition at line 1099 of file QemuFwCfgAcpi.c.

◆ PointerCompare()

STATIC INTN EFIAPI PointerCompare ( IN CONST VOID *  Pointer1,
IN CONST VOID *  Pointer2 
)

Comparator function for two opaque pointers, ordering on (unsigned) pointer value itself. Can be used as both Key and UserStruct comparator.

Parameters
[in]Pointer1First pointer.
[in]Pointer2Second pointer.
Return values
<0If Pointer1 compares less than Pointer2.
0If Pointer1 compares equal to Pointer2.
>0If Pointer1 compares greater than Pointer2.

Definition at line 113 of file QemuFwCfgAcpi.c.

◆ Process2ndPassCmdAddPointer()

STATIC EFI_STATUS EFIAPI Process2ndPassCmdAddPointer ( IN CONST QEMU_LOADER_ADD_POINTER AddPointer,
IN CONST ORDERED_COLLECTION Tracker,
IN EFI_ACPI_TABLE_PROTOCOL AcpiProtocol,
IN OUT UINTN  InstalledKey[INSTALLED_TABLES_MAX],
IN OUT INT32 *  NumInstalled,
IN OUT ORDERED_COLLECTION SeenPointers 
)

Process a QEMU_LOADER_ADD_POINTER command in order to see if its target byte array is an ACPI table, and if so, install it.

This function assumes that the entire QEMU linker/loader command file has been processed successfully in a prior first pass.

Parameters
[in]AddPointerThe QEMU_LOADER_ADD_POINTER command to process.
[in]TrackerThe ORDERED_COLLECTION tracking the BLOB user structures.
[in]AcpiProtocolThe ACPI table protocol used to install tables.
[in,out]InstalledKeyOn input, an array of INSTALLED_TABLES_MAX UINTN elements, allocated by the caller. On output, the function will have stored (appended) the AcpiProtocol-internal key of the ACPI table that the function has installed, if the AddPointer command identified an ACPI table that is different from RSDT and XSDT.
[in,out]NumInstalledOn input, the number of entries already used in InstalledKey; it must be in [0, INSTALLED_TABLES_MAX] inclusive. On output, the parameter is incremented if the AddPointer command identified an ACPI table that is different from RSDT and XSDT.
[in,out]SeenPointersThe ORDERED_COLLECTION tracking the absolute target addresses that have been pointed-to by QEMU_LOADER_ADD_POINTER commands thus far. If a target address is encountered for the first time, and it identifies an ACPI table that is different from RDST and XSDT, the table is installed. If a target address is seen for the second or later times, it is skipped without taking any action.
Return values
EFI_INVALID_PARAMETERNumInstalled was outside the allowed range on input.
EFI_OUT_OF_RESOURCESThe AddPointer command identified an ACPI table different from RSDT and XSDT, but there was no more room in InstalledKey.
EFI_SUCCESSAddPointer has been processed. Either its absolute target address has been encountered before, or an ACPI table different from RSDT and XSDT has been installed (reflected by InstalledKey and NumInstalled), or RSDT or XSDT has been identified but not installed, or the fw_cfg blob pointed-into by AddPointer has been marked as hosting something else than just direct ACPI table contents.
Returns
Error codes returned by AcpiProtocol->InstallAcpiTable().

Definition at line 899 of file QemuFwCfgAcpi.c.

◆ ProcessCmdAddChecksum()

STATIC EFI_STATUS EFIAPI ProcessCmdAddChecksum ( IN CONST QEMU_LOADER_ADD_CHECKSUM AddChecksum,
IN CONST ORDERED_COLLECTION Tracker 
)

Process a QEMU_LOADER_ADD_CHECKSUM command.

Parameters
[in]AddChecksumThe QEMU_LOADER_ADD_CHECKSUM command to process.
[in]TrackerThe ORDERED_COLLECTION tracking the BLOB user structures created thus far.
Return values
EFI_PROTOCOL_ERRORMalformed fw_cfg file name has been found in AddChecksum, or the AddChecksum command references a file unknown to Tracker, or the range to checksum is invalid.
EFI_SUCCESSThe requested range has been checksummed.

Definition at line 578 of file QemuFwCfgAcpi.c.

◆ ProcessCmdAddPointer()

STATIC EFI_STATUS EFIAPI ProcessCmdAddPointer ( IN CONST QEMU_LOADER_ADD_POINTER AddPointer,
IN CONST ORDERED_COLLECTION Tracker 
)

Process a QEMU_LOADER_ADD_POINTER command.

Parameters
[in]AddPointerThe QEMU_LOADER_ADD_POINTER command to process.
[in]TrackerThe ORDERED_COLLECTION tracking the BLOB user structures created thus far.
Return values
EFI_PROTOCOL_ERRORMalformed fw_cfg file name(s) have been found in AddPointer, or the AddPointer command references a file unknown to Tracker, or the pointer to relocate has invalid location, size, or value, or the relocated pointer value is not representable in the given pointer size.
EFI_SUCCESSThe pointer field inside the pointer blob has been relocated.

Definition at line 466 of file QemuFwCfgAcpi.c.

◆ ProcessCmdAllocate()

STATIC EFI_STATUS EFIAPI ProcessCmdAllocate ( IN CONST QEMU_LOADER_ALLOCATE Allocate,
IN OUT ORDERED_COLLECTION Tracker,
IN ORDERED_COLLECTION AllocationsRestrictedTo32Bit 
)

Process a QEMU_LOADER_ALLOCATE command.

Parameters
[in]AllocateThe QEMU_LOADER_ALLOCATE command to process.
[in,out]TrackerThe ORDERED_COLLECTION tracking the BLOB user structures created thus far.
[in]AllocationsRestrictedTo32BitThe ORDERED_COLLECTION populated by the function CollectAllocationsRestrictedTo32Bit, naming the fw_cfg blobs that must not be allocated from 64-bit address space.
Return values
EFI_SUCCESSAn area of whole AcpiNVS pages has been allocated for the blob contents, and the contents have been saved. A BLOB object (user structure) has been allocated from pool memory, referencing the blob contents. The BLOB user structure has been linked into Tracker.
EFI_PROTOCOL_ERRORMalformed fw_cfg file name has been found in Allocate, or the Allocate command references a file that is already known by Tracker.
EFI_UNSUPPORTEDUnsupported alignment request has been found in Allocate.
EFI_OUT_OF_RESOURCESPool allocation failed.
Returns
Error codes from QemuFwCfgFindFile() and gBS->AllocatePages().

Definition at line 318 of file QemuFwCfgAcpi.c.

◆ ProcessCmdWritePointer()

STATIC EFI_STATUS ProcessCmdWritePointer ( IN CONST QEMU_LOADER_WRITE_POINTER WritePointer,
IN CONST ORDERED_COLLECTION Tracker,
IN OUT S3_CONTEXT *S3Context  OPTIONAL 
)

Process a QEMU_LOADER_WRITE_POINTER command.

Parameters
[in]WritePointerThe QEMU_LOADER_WRITE_POINTER command to process.
[in]TrackerThe ORDERED_COLLECTION tracking the BLOB user structures created thus far.
[in,out]S3ContextThe S3_CONTEXT object capturing the fw_cfg actions of successfully processed QEMU_LOADER_WRITE_POINTER commands, to be replayed at S3 resume. S3Context may be NULL if S3 is disabled.
Return values
EFI_PROTOCOL_ERRORMalformed fw_cfg file name(s) have been found in WritePointer. Or, the WritePointer command references a file unknown to Tracker or the fw_cfg directory. Or, the pointer object to rewrite has invalid location, size, or initial relative value. Or, the pointer value to store does not fit in the given pointer size.
EFI_SUCCESSThe pointer object inside the writeable fw_cfg file has been written. If S3Context is not NULL, then WritePointer has been condensed into S3Context.
Returns
Error codes propagated from SaveCondensedWritePointerToS3Context(). The pointer object inside the writeable fw_cfg file has not been written.

Definition at line 666 of file QemuFwCfgAcpi.c.

◆ ReleaseAllocationsRestrictedTo32Bit()

STATIC VOID ReleaseAllocationsRestrictedTo32Bit ( IN ORDERED_COLLECTION AllocationsRestrictedTo32Bit)

Release the ORDERED_COLLECTION structure populated by CollectAllocationsRestrictedTo32Bit() (below).

This function may be called by CollectAllocationsRestrictedTo32Bit() itself, on the error path.

Parameters
[in]AllocationsRestrictedTo32BitThe ORDERED_COLLECTION structure to release.

Definition at line 165 of file QemuFwCfgAcpi.c.

◆ UndoCmdWritePointer()

STATIC VOID UndoCmdWritePointer ( IN CONST QEMU_LOADER_WRITE_POINTER WritePointer)

Undo a QEMU_LOADER_WRITE_POINTER command.

This function revokes (zeroes out) a guest memory reference communicated to QEMU earlier. The caller is responsible for invoking this function only on such QEMU_LOADER_WRITE_POINTER commands that have been successfully processed by ProcessCmdWritePointer().

Parameters
[in]WritePointerThe QEMU_LOADER_WRITE_POINTER command to undo.

Definition at line 800 of file QemuFwCfgAcpi.c.