TianoCore EDK2 master
Loading...
Searching...
No Matches
QemuFwCfgHardwareInfoLib.c
1/*/@file
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.
5
6 Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include <Library/DebugLib.h>
13
14#include <Library/HardwareInfoLib.h>
15
23VOID
24UpdateDataSize (
25 OUT UINTN *DataSize,
26 IN UINTN Value
27 )
28{
29 if (DataSize == NULL) {
30 return;
31 }
32
33 *DataSize = Value;
34}
35
37QemuFwCfgReadNextHardwareInfoByType (
38 IN HARDWARE_INFO_TYPE Type,
39 IN UINTN TypeSize,
40 IN UINTN TotalFileSize,
41 OUT VOID *Data,
42 OUT UINTN *DataSize OPTIONAL,
43 IN OUT UINTN *ReadIndex
44 )
45{
47
48 if ((Data == NULL) ||
49 (ReadIndex == NULL) ||
50 (TypeSize == 0) ||
51 (Type == HardwareInfoTypeUndefined) ||
52 (TotalFileSize == 0))
53 {
54 return EFI_INVALID_PARAMETER;
55 }
56
57 UpdateDataSize (DataSize, 0);
58
59 while (*ReadIndex < TotalFileSize) {
60 QemuFwCfgReadBytes (sizeof (Header), &Header);
61 *ReadIndex += sizeof (Header);
62
63 if ((Header.Size > MAX_UINTN) || (((UINT64)*ReadIndex + Header.Size) > TotalFileSize)) {
64 *ReadIndex = TotalFileSize;
65 return EFI_ABORTED;
66 }
67
68 if ((Header.Type.Value == Type) && (Header.Size <= TypeSize)) {
69 QemuFwCfgReadBytes ((UINTN)Header.Size, Data);
70
71 *ReadIndex += (UINTN)Header.Size;
72 UpdateDataSize (DataSize, (UINTN)Header.Size);
73
74 return EFI_SUCCESS;
75 }
76
77 //
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
81 // check is skipped.
82 //
83 QemuFwCfgSkipBytes ((UINTN)Header.Size);
84 *ReadIndex += (UINTN)Header.Size;
85 }
86
87 return EFI_END_OF_FILE;
88}
UINT64 UINTN
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID EFIAPI QemuFwCfgReadBytes(IN UINTN Size, IN VOID *Buffer OPTIONAL)
Definition: QemuFwCfgNull.c:66
VOID EFIAPI QemuFwCfgSkipBytes(IN UINTN Size)
Definition: QemuFwCfgLib.c:127
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112