2 Qemu fw-cfg wrappers for hardware info parsing.
3 Provides an alternative to parse hardware information from a fw-cfg
4 file without relying on dynamic memory allocations.
6 Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugLib.h>
12 #include <Library/QemuFwCfgLib.h>
14 #include <Library/HardwareInfoLib.h>
17 Update an optional pointer value if possible
19 @param[out] DataSize Pointer to variable to be updated
20 @param[in] Value Value to set the pointed variable to.
29 if (DataSize
== NULL
) {
37 QemuFwCfgReadNextHardwareInfoByType (
38 IN HARDWARE_INFO_TYPE Type
,
40 IN UINTN TotalFileSize
,
42 OUT UINTN
*DataSize OPTIONAL
,
43 IN OUT UINTN
*ReadIndex
46 HARDWARE_INFO_HEADER Header
;
49 (ReadIndex
== NULL
) ||
51 (Type
== HardwareInfoTypeUndefined
) ||
54 return EFI_INVALID_PARAMETER
;
57 UpdateDataSize (DataSize
, 0);
59 while (*ReadIndex
< TotalFileSize
) {
60 QemuFwCfgReadBytes (sizeof (Header
), &Header
);
61 *ReadIndex
+= sizeof (Header
);
63 if ((Header
.Size
> MAX_UINTN
) || (((UINT64
)*ReadIndex
+ Header
.Size
) > TotalFileSize
)) {
64 *ReadIndex
= TotalFileSize
;
68 if ((Header
.Type
.Value
== Type
) && (Header
.Size
<= TypeSize
)) {
69 QemuFwCfgReadBytes ((UINTN
)Header
.Size
, Data
);
71 *ReadIndex
+= (UINTN
)Header
.Size
;
72 UpdateDataSize (DataSize
, (UINTN
)Header
.Size
);
78 // Skip the bytes corresponding to the next element as it is
79 // not of the expected type and/or size. The TotalFileSize
80 // and individual elements sizes should match so the size
83 QemuFwCfgSkipBytes ((UINTN
)Header
.Size
);
84 *ReadIndex
+= (UINTN
)Header
.Size
;
87 return EFI_END_OF_FILE
;