]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Include/Library/HardwareInfoLib.h
Ovmf/HardwareInfoLib: Create Pei lib to parse directly from fw-cfg
[mirror_edk2.git] / OvmfPkg / Include / Library / HardwareInfoLib.h
diff --git a/OvmfPkg/Include/Library/HardwareInfoLib.h b/OvmfPkg/Include/Library/HardwareInfoLib.h
new file mode 100644 (file)
index 0000000..66d964d
--- /dev/null
@@ -0,0 +1,159 @@
+/*/@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