summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/Include
diff options
context:
space:
mode:
authorNicolas Ojeda Leon <ncoleon@amazon.com>2022-01-19 10:49:15 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2022-06-22 15:34:16 +0000
commit2b1a5b8c613301311113e1efc6fc65478e2e6365 (patch)
tree2dfd284b81505c0675d8ea49080944502cf56f03 /OvmfPkg/Include
parent6c9f218bc0d967bea99b139e190a11b703de4d6c (diff)
downloadedk2-2b1a5b8c613301311113e1efc6fc65478e2e6365.tar.gz
edk2-2b1a5b8c613301311113e1efc6fc65478e2e6365.tar.bz2
edk2-2b1a5b8c613301311113e1efc6fc65478e2e6365.zip
Ovmf/HardwareInfoLib: Create Pei lib to parse directly from fw-cfg
Define the HardwareInfoLib API and create the PeiHardwareInfoLib which implements it, specifically for Pei usage, supporting only static accesses to parse data directly from a fw-cfg file. All list-like APIs are implemented as unsupported and only a fw-cfg wrapper to read hardware info elements is provided. The Hardware Info library is intended to describe non-discoverable hardware information and share that from the host to the guest in Ovmf platforms. The QEMU fw-cfg extension for this library provides a first variation to parse hardware info by reading it directly from a fw-cfg file. This library offers a wrapper function to the plain QmeuFwCfgReadBytes which, specifically, parses header-data pairs out of the binary values in the file. For this purpose, the approach is incremental, reading the file block by block and outputting the values only for a specific known hardware type (e.g. PCI host bridges). One element is returned in each call until the end of the file is reached. Considering fw-cfg as the first means to transport hardware info from the host to the guest, this wrapping library offers the possibility to statically, and in steps, read a specific type of hardware info elements out of the file. This method reads one hardware element of a specific type at a time, without the need to pre-allocate memory and read the whole file or dynamically allocate memory for each new element found. As a usage example, the static approach followed by this library enables early UEFI stages to use and read hardware information supplied by the host. For instance, in early times of the PEI stage, hardware information can be parsed out from a fw-cfg file prescinding from memory services, that may not yet be available, and avoiding dynamic memory allocations. Cc: Alexander Graf <graf@amazon.de> Cc: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Nicolas Ojeda Leon <ncoleon@amazon.com>
Diffstat (limited to 'OvmfPkg/Include')
-rw-r--r--OvmfPkg/Include/Library/HardwareInfoLib.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/OvmfPkg/Include/Library/HardwareInfoLib.h b/OvmfPkg/Include/Library/HardwareInfoLib.h
new file mode 100644
index 0000000000..66d964dab5
--- /dev/null
+++ b/OvmfPkg/Include/Library/HardwareInfoLib.h
@@ -0,0 +1,159 @@
+/*/@file
+ Hardware info parsing functions.
+ Binary data is expected as a consecutive series of header - object pairs.
+ Complete library providing static Qemu fw-cfg wrappers as well as list-like
+ interface to dynamically manipulate hardware info objects and parsing from
+ a generic blob.
+
+ Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __HARDWARE_INFO_LIB_H__
+#define __HARDWARE_INFO_LIB_H__
+
+#include "../Library/HardwareInfoLib/HardwareInfoTypesLib.h"
+
+/**
+ Read, if available, the next Type element in the FwCfg file.
+ The FwCfg item must already be selected, this is a wrapper around
+ QemuFwCfgReadBytes and the Data pointer should be set to an existent
+ memory location with TypeSize bytes allocated for the date to be
+ properly written. If a Type element is found in the file which has a
+ size (in the header) greater than TypeSize, it is skipped.
+
+ @param[in] Type Hardware Info Type to search for
+ @param[in] TypeSize Size (in bytes) of the structure intended to
+ be used to dereference the data
+ @param[in] TotalFileSize Total size (in bytes) of the FwCfg file from
+ which the data is read.
+ @param[out] Data Pointer to a memory allocated instance into
+ which the data is written to.
+ @param[out] DataSize Size in bytes of the actually filled
+ data available in the Data object after a
+ successful operation
+ @param[inout] ReadIndex Index of the next byte to be read. Incremented
+ accordingly after a read operation to reflect
+ up to date status
+
+ @retval EFI_SUCCESS Next element found and read into Data
+ @retval EFI_INVALID_PARAMETER Operation failed
+ @retval EFI_END_OF_FILE End of the file reached, no more elements
+ to read.
+**/
+EFI_STATUS
+QemuFwCfgReadNextHardwareInfoByType (
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize,
+ IN UINTN TotalFileSize,
+ OUT VOID *Data,
+ OUT UINTN *DataSize OPTIONAL,
+ IN OUT UINTN *ReadIndex
+ );
+
+/**
+ Parse binary data containing resource information of multiple hardware
+ elements into a list of interpreted resources.
+ The translation is done on a copy-parse base so the blob can be freed
+ afterwards.
+
+ @param[in] Blob Binary data to be parsed
+ @param[in] BlobSize Size (in bytes) of the binary data
+ @param[in] TypeFilter Optional type to filter entries. Set to
+ undefined to disable filtering and retrieve all
+ @param[out] ListHead Head of the list to populate hardware information
+
+ @retval EFI_SUCCESS Succeed.
+ @retval EFI_INVALID_PARAMETER Provided Blob inforation is invalid
+ @retval EFI_OUT_OF_RESOURCES Out of memory, list populated as far as
+ possible
+**/
+EFI_STATUS
+CreateHardwareInfoList (
+ IN UINT8 *Blob,
+ IN UINTN BlobSize,
+ IN HARDWARE_INFO_TYPE TypeFilter,
+ OUT LIST_ENTRY *ListHead
+ );
+
+/**
+ Free the dynamically allocated list of HADWARE_INFO items populated
+ during parsing of Blob
+
+ @param ListHead Head of the list to be destroyed
+**/
+VOID
+FreeHardwareInfoList (
+ IN OUT LIST_ENTRY *ListHead
+ );
+
+/**
+ Retrieve the number of hardware components of a specific type
+ in the list.
+
+ @param[in] ListHead Head of the hardware info list
+ @param[in] Type Type of hardware elements to count
+ @param[in] TypeSize Size (in bytes) of the structure intended to
+ be used to dereference the data
+ @return Count of elements of Type found
+**/
+UINTN
+GetHardwareInfoCountByType (
+ IN LIST_ENTRY *ListHead,
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize
+ );
+
+/**
+ Get the First Hardware Info entry in the list of the specified type
+
+ @param[in] ListHead Head of the hardware info list
+ @param[in] Type Hardware Info Type to search for
+ @param[in] TypeSize Size (in bytes) of the structure intended to
+ be used to dereference the data
+ @return Link of first entry of specified type or list head if not found
+**/
+LIST_ENTRY *
+GetFirstHardwareInfoByType (
+ IN LIST_ENTRY *ListHead,
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize
+ );
+
+/**
+ Get the Next Hardware Info entry in the list with the specified
+ type, which follows the provided Node.
+
+ @param[in] ListHead Head of the hardware info list
+ @param[in] Node Current, already processed, node's link
+ @param[in] Type Hardware Info Type to search for
+ @param[in] TypeSize Size (in bytes) of the structure intended to
+ be used to dereference the data
+ @return Link of next entry, after Node, of the specified type.
+ List head otherwise
+**/
+LIST_ENTRY *
+GetNextHardwareInfoByType (
+ IN LIST_ENTRY *ListHead,
+ IN LIST_ENTRY *Node,
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize
+ );
+
+/**
+ Assess if Node stands at the end of the doubly linked list
+
+ @param[in] ListHead Head of the hardware info list
+ @param[in] Node Current Node link
+
+ @retval TRUE Node is at the end of the list
+ @retval FALSE Node is not at the end of the list
+**/
+BOOLEAN
+EndOfHardwareInfoList (
+ IN LIST_ENTRY *ListHead,
+ IN LIST_ENTRY *Node
+ );
+
+#endif // __HARDWARE_INFO_LIB_H__