PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf\r
PciHostBridgeLib|OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf\r
PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
\r
!if $(TPM2_ENABLE) == TRUE\r
Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf\r
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
BlobVerifierLib|OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashes.inf\r
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
\r
!if $(SOURCE_DEBUG_ENABLE) == TRUE\r
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf\r
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf\r
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
\r
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf\r
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf\r
LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf\r
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
!if $(SMM_REQUIRE) == FALSE\r
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
!endif\r
--- /dev/null
+/*/@file\r
+ Hardware info parsing functions.\r
+ Binary data is expected as a consecutive series of header - object pairs.\r
+ Complete library providing static Qemu fw-cfg wrappers as well as list-like\r
+ interface to dynamically manipulate hardware info objects and parsing from\r
+ a generic blob.\r
+\r
+ Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef __HARDWARE_INFO_LIB_H__\r
+#define __HARDWARE_INFO_LIB_H__\r
+\r
+#include "../Library/HardwareInfoLib/HardwareInfoTypesLib.h"\r
+\r
+/**\r
+ Read, if available, the next Type element in the FwCfg file.\r
+ The FwCfg item must already be selected, this is a wrapper around\r
+ QemuFwCfgReadBytes and the Data pointer should be set to an existent\r
+ memory location with TypeSize bytes allocated for the date to be\r
+ properly written. If a Type element is found in the file which has a\r
+ size (in the header) greater than TypeSize, it is skipped.\r
+\r
+ @param[in] Type Hardware Info Type to search for\r
+ @param[in] TypeSize Size (in bytes) of the structure intended to\r
+ be used to dereference the data\r
+ @param[in] TotalFileSize Total size (in bytes) of the FwCfg file from\r
+ which the data is read.\r
+ @param[out] Data Pointer to a memory allocated instance into\r
+ which the data is written to.\r
+ @param[out] DataSize Size in bytes of the actually filled\r
+ data available in the Data object after a\r
+ successful operation\r
+ @param[inout] ReadIndex Index of the next byte to be read. Incremented\r
+ accordingly after a read operation to reflect\r
+ up to date status\r
+\r
+ @retval EFI_SUCCESS Next element found and read into Data\r
+ @retval EFI_INVALID_PARAMETER Operation failed\r
+ @retval EFI_END_OF_FILE End of the file reached, no more elements\r
+ to read.\r
+**/\r
+EFI_STATUS\r
+QemuFwCfgReadNextHardwareInfoByType (\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize,\r
+ IN UINTN TotalFileSize,\r
+ OUT VOID *Data,\r
+ OUT UINTN *DataSize OPTIONAL,\r
+ IN OUT UINTN *ReadIndex\r
+ );\r
+\r
+/**\r
+ Parse binary data containing resource information of multiple hardware\r
+ elements into a list of interpreted resources.\r
+ The translation is done on a copy-parse base so the blob can be freed\r
+ afterwards.\r
+\r
+ @param[in] Blob Binary data to be parsed\r
+ @param[in] BlobSize Size (in bytes) of the binary data\r
+ @param[in] TypeFilter Optional type to filter entries. Set to\r
+ undefined to disable filtering and retrieve all\r
+ @param[out] ListHead Head of the list to populate hardware information\r
+\r
+ @retval EFI_SUCCESS Succeed.\r
+ @retval EFI_INVALID_PARAMETER Provided Blob inforation is invalid\r
+ @retval EFI_OUT_OF_RESOURCES Out of memory, list populated as far as\r
+ possible\r
+**/\r
+EFI_STATUS\r
+CreateHardwareInfoList (\r
+ IN UINT8 *Blob,\r
+ IN UINTN BlobSize,\r
+ IN HARDWARE_INFO_TYPE TypeFilter,\r
+ OUT LIST_ENTRY *ListHead\r
+ );\r
+\r
+/**\r
+ Free the dynamically allocated list of HADWARE_INFO items populated\r
+ during parsing of Blob\r
+\r
+ @param ListHead Head of the list to be destroyed\r
+**/\r
+VOID\r
+FreeHardwareInfoList (\r
+ IN OUT LIST_ENTRY *ListHead\r
+ );\r
+\r
+/**\r
+ Retrieve the number of hardware components of a specific type\r
+ in the list.\r
+\r
+ @param[in] ListHead Head of the hardware info list\r
+ @param[in] Type Type of hardware elements to count\r
+ @param[in] TypeSize Size (in bytes) of the structure intended to\r
+ be used to dereference the data\r
+ @return Count of elements of Type found\r
+**/\r
+UINTN\r
+GetHardwareInfoCountByType (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize\r
+ );\r
+\r
+/**\r
+ Get the First Hardware Info entry in the list of the specified type\r
+\r
+ @param[in] ListHead Head of the hardware info list\r
+ @param[in] Type Hardware Info Type to search for\r
+ @param[in] TypeSize Size (in bytes) of the structure intended to\r
+ be used to dereference the data\r
+ @return Link of first entry of specified type or list head if not found\r
+**/\r
+LIST_ENTRY *\r
+GetFirstHardwareInfoByType (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize\r
+ );\r
+\r
+/**\r
+ Get the Next Hardware Info entry in the list with the specified\r
+ type, which follows the provided Node.\r
+\r
+ @param[in] ListHead Head of the hardware info list\r
+ @param[in] Node Current, already processed, node's link\r
+ @param[in] Type Hardware Info Type to search for\r
+ @param[in] TypeSize Size (in bytes) of the structure intended to\r
+ be used to dereference the data\r
+ @return Link of next entry, after Node, of the specified type.\r
+ List head otherwise\r
+**/\r
+LIST_ENTRY *\r
+GetNextHardwareInfoByType (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN LIST_ENTRY *Node,\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize\r
+ );\r
+\r
+/**\r
+ Assess if Node stands at the end of the doubly linked list\r
+\r
+ @param[in] ListHead Head of the hardware info list\r
+ @param[in] Node Current Node link\r
+\r
+ @retval TRUE Node is at the end of the list\r
+ @retval FALSE Node is not at the end of the list\r
+**/\r
+BOOLEAN\r
+EndOfHardwareInfoList (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN LIST_ENTRY *Node\r
+ );\r
+\r
+#endif // __HARDWARE_INFO_LIB_H__\r
--- /dev/null
+/*/@file\r
+ Hardware info parsing functions.\r
+ Binary data is expected as a consecutive series of header - object pairs.\r
+ Provides static Qemu fw-cfg wrappers as well as list-like interface to\r
+ dynamically manipulate hardware info objects and parsing from a generic\r
+ blob.\r
+\r
+ Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/DebugLib.h>\r
+\r
+#include <Library/HardwareInfoLib.h>\r
+\r
+EFI_STATUS\r
+CreateHardwareInfoList (\r
+ IN UINT8 *Blob,\r
+ IN UINTN BlobSize,\r
+ IN HARDWARE_INFO_TYPE TypeFilter,\r
+ OUT LIST_ENTRY *ListHead\r
+ )\r
+{\r
+ ASSERT (FALSE);\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+VOID\r
+FreeHardwareInfoList (\r
+ IN OUT LIST_ENTRY *ListHead\r
+ )\r
+{\r
+ ASSERT (FALSE);\r
+}\r
+\r
+UINTN\r
+GetHardwareInfoCountByType (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize\r
+ )\r
+{\r
+ ASSERT (FALSE);\r
+ return 0;\r
+}\r
+\r
+LIST_ENTRY *\r
+GetFirstHardwareInfoByType (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize\r
+ )\r
+{\r
+ ASSERT (FALSE);\r
+ return ListHead;\r
+}\r
+\r
+LIST_ENTRY *\r
+GetNextHardwareInfoByType (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN LIST_ENTRY *Node,\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize\r
+ )\r
+{\r
+ ASSERT (FALSE);\r
+ return ListHead;\r
+}\r
+\r
+BOOLEAN\r
+EndOfHardwareInfoList (\r
+ IN LIST_ENTRY *ListHead,\r
+ IN LIST_ENTRY *Node\r
+ )\r
+{\r
+ ASSERT (FALSE);\r
+ return TRUE;\r
+}\r
--- /dev/null
+## @file\r
+# Hardware information library wrappers over Qemu fw-cfg functionality to parse,\r
+# in a static manner, non-discoverable hardware information.\r
+#\r
+# Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = PeiHardwareInfoLib\r
+ FILE_GUID = 3D5011B3-9CBB-4C0B-88E8-1D758283C659\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = PeiHardwareInfoLib\r
+\r
+#\r
+# The following information is for reference only and not required by the build\r
+# tools.\r
+#\r
+# VALID_ARCHITECTURES = X64\r
+#\r
+\r
+[Sources]\r
+ HardwareInfoPei.c\r
+ QemuFwCfgHardwareInfoLib.c\r
+ HardwareInfoPciHostBridgeLib.c\r
+\r
+[Packages]\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ MdePkg/MdePkg.dec\r
+ OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+ DebugLib\r
+ QemuFwCfgLib\r
--- /dev/null
+/*/@file\r
+ Qemu fw-cfg wrappers for hardware info parsing.\r
+ Provides an alternative to parse hardware information from a fw-cfg\r
+ file without relying on dynamic memory allocations.\r
+\r
+ Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/QemuFwCfgLib.h>\r
+\r
+#include <Library/HardwareInfoLib.h>\r
+\r
+/**\r
+ Update an optional pointer value if possible\r
+\r
+ @param[out] DataSize Pointer to variable to be updated\r
+ @param[in] Value Value to set the pointed variable to.\r
+**/\r
+STATIC\r
+VOID\r
+UpdateDataSize (\r
+ OUT UINTN *DataSize,\r
+ IN UINTN Value\r
+ )\r
+{\r
+ if (DataSize == NULL) {\r
+ return;\r
+ }\r
+\r
+ *DataSize = Value;\r
+}\r
+\r
+EFI_STATUS\r
+QemuFwCfgReadNextHardwareInfoByType (\r
+ IN HARDWARE_INFO_TYPE Type,\r
+ IN UINTN TypeSize,\r
+ IN UINTN TotalFileSize,\r
+ OUT VOID *Data,\r
+ OUT UINTN *DataSize OPTIONAL,\r
+ IN OUT UINTN *ReadIndex\r
+ )\r
+{\r
+ HARDWARE_INFO_HEADER Header;\r
+\r
+ if ((Data == NULL) ||\r
+ (ReadIndex == NULL) ||\r
+ (TypeSize == 0) ||\r
+ (Type == HardwareInfoTypeUndefined) ||\r
+ (TotalFileSize == 0))\r
+ {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ UpdateDataSize (DataSize, 0);\r
+\r
+ while (*ReadIndex < TotalFileSize) {\r
+ QemuFwCfgReadBytes (sizeof (Header), &Header);\r
+ *ReadIndex += sizeof (Header);\r
+\r
+ if ((Header.Size > MAX_UINTN) || (((UINT64)*ReadIndex + Header.Size) > TotalFileSize)) {\r
+ *ReadIndex = TotalFileSize;\r
+ return EFI_ABORTED;\r
+ }\r
+\r
+ if ((Header.Type.Value == Type) && (Header.Size <= TypeSize)) {\r
+ QemuFwCfgReadBytes ((UINTN)Header.Size, Data);\r
+\r
+ *ReadIndex += (UINTN)Header.Size;\r
+ UpdateDataSize (DataSize, (UINTN)Header.Size);\r
+\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // Skip the bytes corresponding to the next element as it is\r
+ // not of the expected type and/or size. The TotalFileSize\r
+ // and individual elements sizes should match so the size\r
+ // check is skipped.\r
+ //\r
+ QemuFwCfgSkipBytes ((UINTN)Header.Size);\r
+ *ReadIndex += (UINTN)Header.Size;\r
+ }\r
+\r
+ return EFI_END_OF_FILE;\r
+}\r
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf\r
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
\r
!if $(SOURCE_DEBUG_ENABLE) == TRUE\r
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf\r
#\r
PeilessStartupLib|Include/Library/PeilessStartupLib.h\r
\r
+ ## @libraryclass HardwareInfoLib\r
+ #\r
+ HardwareInfoLib|Include/Library/HardwareInfoLib.h\r
+\r
[Guids]\r
gUefiOvmfPkgTokenSpaceGuid = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}}\r
gEfiXenInfoGuid = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}\r
LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf\r
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf\r
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLibNull.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
!if $(SMM_REQUIRE) == FALSE\r
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
!endif\r
LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf\r
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf\r
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLibNull.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
!if $(SMM_REQUIRE) == FALSE\r
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
!endif\r
LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf\r
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf\r
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
\r
!if $(SMM_REQUIRE) == FALSE\r
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf\r
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf\r
+ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf\r
\r
!if $(SOURCE_DEBUG_ENABLE) == TRUE\r
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf\r