summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/Include/Library
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2020-04-24 09:53:47 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-04-28 22:37:35 +0000
commit611c7f1101267d53b039a04136e55f313c756c5c (patch)
treee2c1d06cbdb7b28844b380a27c1724ad2fbefbb5 /OvmfPkg/Include/Library
parent64ab457d1f218a02f3bdd8efc843e91be76d5385 (diff)
downloadedk2-611c7f1101267d53b039a04136e55f313c756c5c.tar.gz
edk2-611c7f1101267d53b039a04136e55f313c756c5c.tar.bz2
edk2-611c7f1101267d53b039a04136e55f313c756c5c.zip
OvmfPkg: introduce QemuFwCfgSimpleParserLib
We already parse some boolean and integer values from named fw_cfg files (usually into PCDs), and we're going to cover more. Add a dedicated library for centralizing the parsing logic. Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Per Sundstrom <per_sundstrom@yahoo.com> Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2681 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20200424075353.8489-2-lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Diffstat (limited to 'OvmfPkg/Include/Library')
-rw-r--r--OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h128
1 files changed, 128 insertions, 0 deletions
diff --git a/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h b/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h
new file mode 100644
index 0000000000..c6062bae87
--- /dev/null
+++ b/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h
@@ -0,0 +1,128 @@
+/** @file
+ Parse the contents of named fw_cfg files as simple (scalar) data types.
+
+ Copyright (C) 2020, Red Hat, Inc.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef QEMU_FW_CFG_SIMPLE_PARSER_LIB_H_
+#define QEMU_FW_CFG_SIMPLE_PARSER_LIB_H_
+
+#include <Base.h>
+
+/**
+ Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg
+ file into a small array with automatic storage duration. Parse the array as
+ the textual representation of a BOOLEAN.
+
+ @param[in] FileName The name of the fw_cfg file to look up and parse.
+
+ @param[out] Value On success, Value is TRUE if the contents of the fw_cfg
+ file case-insensitively match "true", "yes", "y",
+ "enable", "enabled", "1".
+
+ On success, Value is FALSE if the contents of the fw_cfg
+ file case-insensitively match "false", "no", "n",
+ "disable", "disabled", "0".
+
+ On failure, Value is not changed.
+
+ @retval RETURN_SUCCESS Parsing successful. Value has been set.
+
+ @retval RETURN_UNSUPPORTED Firmware configuration is unavailable.
+
+ @retval RETURN_PROTOCOL_ERROR Parsing failed. Value has not been changed.
+
+ @return Error codes propagated from
+ QemuFwCfgFindFile(). Value has not been
+ changed.
+**/
+RETURN_STATUS
+EFIAPI
+QemuFwCfgParseBool (
+ IN CONST CHAR8 *FileName,
+ OUT BOOLEAN *Value
+ );
+
+/**
+ Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg
+ file into a small array with automatic storage duration. Parse the array as
+ the textual representation of a UINT8.
+
+ @param[in] FileName The name of the fw_cfg file to look up and parse.
+
+ @param[in] ParseAsHex If TRUE, call BaseLib's AsciiStrHexToUint64S() for
+ parsing the fw_cfg file.
+
+ If FALSE, call BaseLib's AsciiStrDecimalToUint64S()
+ for parsing the fw_cfg file.
+
+ @param[out] Value On success, Value has been parsed with the BaseLib
+ function determined by ParseAsHex, and also
+ range-checked for [0, MAX_UINT8].
+
+ On failure, Value is not changed.
+
+ @retval RETURN_SUCCESS Parsing successful. Value has been set.
+
+ @retval RETURN_UNSUPPORTED Firmware configuration is unavailable.
+
+ @retval RETURN_PROTOCOL_ERROR Parsing failed. Value has not been changed.
+
+ @retval RETURN_PROTOCOL_ERROR Parsing succeeded, but the result does not fit
+ in the [0, MAX_UINT8] range. Value has not
+ been changed.
+
+ @return Error codes propagated from
+ QemuFwCfgFindFile() and from the BaseLib
+ function selected by ParseAsHex. Value has not
+ been changed.
+**/
+RETURN_STATUS
+EFIAPI
+QemuFwCfgParseUint8 (
+ IN CONST CHAR8 *FileName,
+ IN BOOLEAN ParseAsHex,
+ OUT UINT8 *Value
+ );
+
+//
+// The following functions behave identically to QemuFwCfgParseUint8(),
+// only their range checks use MAX_UINT16, MAX_UINT32, MAX_UINT64, MAX_UINTN,
+// respectively.
+//
+
+RETURN_STATUS
+EFIAPI
+QemuFwCfgParseUint16 (
+ IN CONST CHAR8 *FileName,
+ IN BOOLEAN ParseAsHex,
+ OUT UINT16 *Value
+ );
+
+RETURN_STATUS
+EFIAPI
+QemuFwCfgParseUint32 (
+ IN CONST CHAR8 *FileName,
+ IN BOOLEAN ParseAsHex,
+ OUT UINT32 *Value
+ );
+
+RETURN_STATUS
+EFIAPI
+QemuFwCfgParseUint64 (
+ IN CONST CHAR8 *FileName,
+ IN BOOLEAN ParseAsHex,
+ OUT UINT64 *Value
+ );
+
+RETURN_STATUS
+EFIAPI
+QemuFwCfgParseUintn (
+ IN CONST CHAR8 *FileName,
+ IN BOOLEAN ParseAsHex,
+ OUT UINTN *Value
+ );
+
+#endif // QEMU_FW_CFG_SIMPLE_PARSER_LIB_H_