16#define UINT64_STRING_MAX_SIZE \
17 MAX (sizeof "18446744073709551615", sizeof "0xFFFFFFFFFFFFFFFF")
23#define BOOL_STRING_MAX_SIZE (sizeof "disabled")
28#define CRLF_LENGTH (sizeof "\r\n" - 1)
34 "true",
"yes",
"y",
"enable",
"enabled",
"1"
37 "false",
"no",
"n",
"disable",
"disabled",
"0"
94 FIRMWARE_CONFIG_ITEM FwCfgItem;
106 if (FwCfgSize > *BufferSize) {
116 if ((FwCfgSize > 0) && (Buffer[FwCfgSize - 1] ==
'\0')) {
117 *BufferSize = FwCfgSize;
124 if (FwCfgSize == *BufferSize) {
128 Buffer[FwCfgSize] =
'\0';
129 *BufferSize = FwCfgSize + 1;
152 UINTN InSize, OutSize;
154 InSize = *BufferSize;
158 (Buffer[InSize - 3] ==
'\r') && (Buffer[InSize - 2] ==
'\n'))
160 OutSize = InSize - 2;
161 }
else if ((InSize >= 2) && (Buffer[InSize - 2] ==
'\n')) {
162 OutSize = InSize - 1;
165 if (OutSize < InSize) {
166 Buffer[OutSize - 1] =
'\0';
167 *BufferSize = OutSize;
211 IN BOOLEAN ParseAsHex,
216 UINTN Uint64StringSize;
217 CHAR8 Uint64String[UINT64_STRING_MAX_SIZE + CRLF_LENGTH];
218 RETURN_STATUS Status;
222 Uint64StringSize =
sizeof Uint64String;
244 if ((EndPointer == Uint64String) || (*EndPointer !=
'\0') || (Uint64 > Limit)) {
258QemuFwCfgSimpleParserInit (
275 UINTN BoolStringSize;
276 CHAR8 BoolString[BOOL_STRING_MAX_SIZE + CRLF_LENGTH];
277 RETURN_STATUS Status;
280 BoolStringSize =
sizeof BoolString;
288 for (Idx = 0; Idx <
ARRAY_SIZE (mTrueString); ++Idx) {
295 for (Idx = 0; Idx <
ARRAY_SIZE (mFalseString); ++Idx) {
296 if (
AsciiStriCmp (BoolString, mFalseString[Idx]) == 0) {
309 IN BOOLEAN ParseAsHex,
313 RETURN_STATUS Status;
326 *Value = (UINT8)Uint64;
332QemuFwCfgParseUint16 (
334 IN BOOLEAN ParseAsHex,
338 RETURN_STATUS Status;
351 *Value = (UINT16)Uint64;
357QemuFwCfgParseUint32 (
359 IN BOOLEAN ParseAsHex,
363 RETURN_STATUS Status;
376 *Value = (UINT32)Uint64;
382QemuFwCfgParseUint64 (
384 IN BOOLEAN ParseAsHex,
388 RETURN_STATUS Status;
409 IN BOOLEAN ParseAsHex,
413 RETURN_STATUS Status;
426 *Value = (
UINTN)Uint64;
INTN EFIAPI AsciiStriCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
RETURN_STATUS EFIAPI AsciiStrHexToUint64S(IN CONST CHAR8 *String, OUT CHAR8 **EndPointer OPTIONAL, OUT UINT64 *Data)
RETURN_STATUS EFIAPI AsciiStrDecimalToUint64S(IN CONST CHAR8 *String, OUT CHAR8 **EndPointer OPTIONAL, OUT UINT64 *Data)
#define RETURN_PROTOCOL_ERROR
#define RETURN_ERROR(StatusCode)
#define RETURN_UNSUPPORTED
#define ARRAY_SIZE(Array)
RETURN_STATUS EFIAPI QemuFwCfgFindFile(IN CONST CHAR8 *Name, OUT FIRMWARE_CONFIG_ITEM *Item, OUT UINTN *Size)
VOID EFIAPI QemuFwCfgReadBytes(IN UINTN Size, IN VOID *Buffer OPTIONAL)
VOID EFIAPI QemuFwCfgSelectItem(IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem)
BOOLEAN EFIAPI QemuFwCfgIsAvailable(VOID)
STATIC VOID StripNewline(IN OUT UINTN *BufferSize, IN OUT CHAR8 *Buffer)
RETURN_STATUS EFIAPI QemuFwCfgParseUint8(IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, OUT UINT8 *Value)
RETURN_STATUS EFIAPI QemuFwCfgParseBool(IN CONST CHAR8 *FileName, OUT BOOLEAN *Value)
STATIC RETURN_STATUS QemuFwCfgGetAsString(IN CONST CHAR8 *FileName, IN OUT UINTN *BufferSize, OUT CHAR8 *Buffer)
STATIC RETURN_STATUS QemuFwCfgParseUint64WithLimit(IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, IN UINT64 Limit, OUT UINT64 *Value)