From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by mx.groups.io with SMTP id smtpd.web10.531.1659581564348918542 for ; Wed, 03 Aug 2022 19:52:44 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=GB0dQnyo; spf=pass (domain: flex--yuanyu.bounces.google.com, ip: 209.85.210.202, mailfrom: 3eztrygykba4miobmiuccuzs.qcarsjszsryq.ufcidg.wc@flex--yuanyu.bounces.google.com) Received: by mail-pf1-f202.google.com with SMTP id j10-20020a62b60a000000b0052b30f6626bso7310570pff.17 for ; Wed, 03 Aug 2022 19:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=g4ekP9qK9se8yFDfjDkwygnFcBXiNmpoC4DijKftObI=; b=GB0dQnyosONqwB59z8sLlLMiA0E3hYAY3Paj3Q/D/r+NwxNdekSTQhV6QKSyt95L2G 8WSCr6Ps5gnyWA8FjJXSe12O24noTucvAr2/yw2NAIjmBPL5D1gxuYHmY+OBfOrkCaNg T5ljfOdXGPMH+YHZAZ26Z/s1m4zAv7AwCSBC4wOxRMRjeM16VuHuOpAq21xfsyd7+By+ 42QkBGZ44E/rL5lIJCoNCKS5S6RcA7jOcM6PUdmGaTq4dsZMyGNG7DJMW7t57ycRKKob 0TMF0k6AjBo5OHIJqM6iMHWXtDTW8ke/dROmbGcLoKUJcGaQ5f9HTU67AVdo7nyUbNJq N6jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=g4ekP9qK9se8yFDfjDkwygnFcBXiNmpoC4DijKftObI=; b=Os2xxw8swld7lUkj0LPJ5k9sXVEeKBBxho1Ift53AYDSnVw6zd/6XDW8M38vtvp407 YD52QYy47dP71dSc7X/A4Wi80xZB3gJdWSDkREvGumV2xKwLpYIyknHrf8/+A84DnSeU lI0y2YY09KkFwd/brKF1620fOAc0OiMLIO6W6GXfTKgFxMj7zwvheZRjQvP2Akl4Kzbr 2y7FKV1iUvU7wyjJ0o8XLxdVrLRKom6CQ8RRAhsyoK7Hiylxn3SrV17vtR7ZoPnyzJ0/ uFS8Ca03Cq/TOS7ygCZ2Wk5W2xYIA2B5fzO5BqgyFchMcYiis4cas02aYybANxb+g6PL edXQ== X-Gm-Message-State: AJIora8hLqCTiDp2HD6Zu0VcOUr3MfWXENPkmZLX6bvvTorBWbEErKkD sKsHppKnSjEIG7JAguBy/b5rHGRgFLKowATAoUFtvfS9ygT3VxWDPSBZNCqgm+Ac17DHjwoMCQY enyHYg877iYWvth4qIicKFvvKeNKVmXfSV/HRUMQ5RvKP7nBZzYELJDWATjY= X-Google-Smtp-Source: AGRyM1v04eBjCcmYdYHya/RuPGGaD+030f6svw2yiP360BmcmTZzovM3Uc7mCfHjrmVVnmT0yjAOa/7kpwQ= X-Received: from yuanyu.kir.corp.google.com ([2620:15c:29:204:5484:86bb:f3b4:5636]) (user=yuanyu job=sendgmr) by 2002:a05:6a00:1ac8:b0:52b:a671:2ea8 with SMTP id f8-20020a056a001ac800b0052ba6712ea8mr29457890pfv.16.1659581563758; Wed, 03 Aug 2022 19:52:43 -0700 (PDT) Date: Wed, 3 Aug 2022 19:52:38 -0700 In-Reply-To: <20220804025239.918263-1-yuanyu@google.com> Message-Id: <20220804025239.918263-2-yuanyu@google.com> Mime-Version: 1.0 References: <20220804025239.918263-1-yuanyu@google.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog Subject: [PATCH v1 1/2] OvmfPkg: Introduce NetworkCfgLib From: "Yuan Yu" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jordan Justen , Laszlo Ersek , Anthony Perard , Julien Grall Content-Type: text/plain; charset="UTF-8" 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 Cc: Jordan Justen Cc: Laszlo Ersek Cc: Anthony Perard Cc: Julien Grall Signed-off-by: Yuan Yu --- 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 +#include +#include + +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