Introduce NetworkCfgLib which will set PcdNetworkSupport based on "etc/networking" qemu file.
If "etc/networking" (type bool) is TRUE, then PcdNetworkSupport will be TRUE and vice versa. In the following patch, PcdNetworkSupport will be used to enable/disable VirtIo net driver so that VMM will have control over networking functionality in runtime. The default value of PcdNetworkSupport is TRUE, which means if network support is turned on at compile time and VMM doesn't do anything, the VirtIo driver will be enabled. This is to make it consistent with the behavior before this patch. Cc: Ard Biesheuvel <ardb+tianoc...@kernel.org> Cc: Jordan Justen <jordan.l.jus...@intel.com> Cc: Laszlo Ersek <ler...@redhat.com> Cc: Anthony Perard <anthony.per...@citrix.com> Cc: Julien Grall <jul...@xen.org> Signed-off-by: Yuan Yu <yua...@google.com> --- OvmfPkg/OvmfPkg.dec | 3 ++ OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.inf | 29 ++++++++++++++++++ OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.c | 32 ++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 5af76a540529..5dced0568f6c 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -451,6 +451,9 @@ [PcdsDynamic, PcdsDynamicEx] ## This PCD records LASA field in CC EVENTLOG ACPI table. gUefiOvmfPkgTokenSpaceGuid.PcdCcEventlogAcpiTableLasa|0|UINT64|0x67 + ## This PCD controls if network support should be turned on at runtime. + gUefiOvmfPkgTokenSpaceGuid.PcdNetworkSupport|TRUE|BOOLEAN|0x72 + [PcdsFeatureFlag] gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0x1c gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN|0x1d diff --git a/OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.inf b/OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.inf new file mode 100644 index 000000000000..44be171ccc7a --- /dev/null +++ b/OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.inf @@ -0,0 +1,29 @@ +## @file +# Configure some PCDs dynamically +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 1.27 + BASE_NAME = NetworkCfgLib + FILE_GUID = c81bfcf9-7dce-44f7-a9cb-be607f481a86 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL + CONSTRUCTOR = SetNetworkingSupportPcds + +[Sources] + NetworkCfgLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + PcdLib + DebugLib + QemuFwCfgSimpleParserLib + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdNetworkSupport ## SOMETIMES_PRODUCES diff --git a/OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.c b/OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.c new file mode 100644 index 000000000000..e77198dbd4e4 --- /dev/null +++ b/OvmfPkg/Library/NetworkCfgLib/NetworkCfgLib.c @@ -0,0 +1,32 @@ +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/QemuFwCfgSimpleParserLib.h> + +RETURN_STATUS +EFIAPI +SetNetworkingSupportPcds ( + VOID + ) +{ + BOOLEAN FwCfgBool; + RETURN_STATUS Status; + + DEBUG ((DEBUG_INFO, "[network] %a\n", __FUNCTION__)); + + Status = QemuFwCfgParseBool ("etc/networking", &FwCfgBool); + if (RETURN_ERROR (Status)) { + DEBUG ((DEBUG_INFO, + "[network] QemuFwCfgParseBool('etc/networking') failed, will return " + "SUCCESS and continue without overriding PcdNetworkSupport.\n")); + return RETURN_SUCCESS; + } + DEBUG ((DEBUG_INFO, "[network] etc/networking = %d\n", FwCfgBool)); + + Status = PcdSetBoolS (PcdNetworkSupport, FwCfgBool); + if (RETURN_ERROR (Status)) { + return Status; + } + DEBUG ((DEBUG_INFO, "[network] PcdNetworkSupport was set to %d\n", FwCfgBool)); + + return RETURN_SUCCESS; +} -- 2.37.1.559.g78731f0fdb-goog -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#92119): https://edk2.groups.io/g/devel/message/92119 Mute This Topic: https://groups.io/mt/92816625/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-