From: "Chao Li" <lichao@loongson.cn>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
Jiewen Yao <jiewen.yao@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Leif Lindholm <quic_llindhol@quicinc.com>,
Sami Mujawar <sami.mujawar@arm.com>,
Sunil V L <sunilvl@ventanamicro.com>,
Andrei Warkentin <andrei.warkentin@intel.com>
Subject: [edk2-devel] [PATCH v2 2/7] OvmfPkg: Add the way of HOBs in QemuFwCfgLibMmio
Date: Thu, 25 Apr 2024 12:18:16 +0800 [thread overview]
Message-ID: <20240425041816.1386268-1-lichao@loongson.cn> (raw)
In-Reply-To: <20240425041728.1385891-1-lichao@loongson.cn>
Added the HOB methods to load and store the QEMU firmware configure
address, data address and DMA address, which are not enabled during the
DXE stage.
Build-tested only (with "ArmVirtQemu.dsc and RiscVVirtQemu.dsc").
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4755
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Sunil V L <sunilvl@ventanamicro.com>
Cc: Andrei Warkentin <andrei.warkentin@intel.com>
Signed-off-by: Chao Li <lichao@loongson.cn>
---
.../Library/QemuFwCfgLib/QemuFwCfgLibMmio.c | 176 +++++++++++++++++-
.../Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf | 1 +
.../QemuFwCfgLib/QemuFwCfgLibMmioInternal.h | 51 +++++
3 files changed, 218 insertions(+), 10 deletions(-)
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.c
index dc949c8e26..c7cf5719e2 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.c
@@ -8,11 +8,16 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+#include <Base.h>
#include <Uefi.h>
+#include <Pi/PiBootMode.h>
+#include <Pi/PiHob.h>
+
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
#include <Library/IoLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/UefiBootServicesTableLib.h>
@@ -21,6 +26,157 @@
#include "QemuFwCfgLibMmioInternal.h"
+EFI_GUID mFwCfgSelectorAddressGuid = FW_CONFIG_SELECTOR_ADDRESS_HOB_GUID;
+EFI_GUID mFwCfgDataAddressGuid = FW_CONFIG_DATA_ADDRESS_HOB_GUID;
+EFI_GUID mFwCfgDmaAddressGuid = FW_CONFIG_DMA_ADDRESS_HOB_GUID;
+
+/**
+ Build firmware configure selector address HOB.
+
+ @param[in] FwCfgSelectorAddress Firmware configure selector address
+
+ @retval NULL
+**/
+VOID
+QemuBuildFwCfgSelectorHob (
+ IN UINT64 FwCfgSelectorAddress
+ )
+{
+ BuildGuidDataHob (
+ &mFwCfgSelectorAddressGuid,
+ (VOID *)&FwCfgSelectorAddress,
+ sizeof (UINT64)
+ );
+}
+
+/**
+ Build firmware configure data address HOB.
+
+ @param[in] FwCfgDataAddress Firmware configure data address.
+
+ @retval NULL
+**/
+VOID
+QemuBuildFwCfgDataHob (
+ IN UINT64 FwCfgDataAddress
+ )
+{
+ BuildGuidDataHob (
+ &mFwCfgDataAddressGuid,
+ (VOID *)&FwCfgDataAddress,
+ sizeof (UINT64)
+ );
+}
+
+/**
+ Build firmware configure DMA address HOB.
+
+ @param[in] FwCfgDmaAddress Firmware configure DMA address.
+
+ @retval NULL
+**/
+VOID
+QemuBuildFwCfgDmaHob (
+ IN UINT64 FwCfgDmaAddress
+ )
+{
+ BuildGuidDataHob (
+ &mFwCfgDmaAddressGuid,
+ (VOID *)&FwCfgDmaAddress,
+ sizeof (UINT64)
+ );
+}
+
+/**
+ To get firmware configure selector address.
+
+ @param VOID
+
+ @retval firmware configure selector address
+**/
+UINTN
+EFIAPI
+QemuGetFwCfgSelectorAddress (
+ VOID
+ )
+{
+ UINTN FwCfgSelectorAddress;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ VOID *DataInHob;
+
+ FwCfgSelectorAddress = mFwCfgSelectorAddress;
+ GuidHob = NULL;
+ DataInHob = NULL;
+
+ if (FwCfgSelectorAddress == 0) {
+ GuidHob = GetFirstGuidHob (&mFwCfgSelectorAddressGuid);
+ DataInHob = GET_GUID_HOB_DATA (GuidHob);
+ FwCfgSelectorAddress = (UINT64)(*(UINTN *)DataInHob);
+ }
+
+ return FwCfgSelectorAddress;
+}
+
+/**
+ To get firmware configure Data address.
+
+ @param VOID
+
+ @retval firmware configure data address
+**/
+UINTN
+EFIAPI
+QemuGetFwCfgDataAddress (
+ VOID
+ )
+{
+ UINTN FwCfgDataAddress;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ VOID *DataInHob;
+
+ FwCfgDataAddress = mFwCfgDataAddress;
+ GuidHob = NULL;
+ DataInHob = NULL;
+
+ if (FwCfgDataAddress == 0) {
+ GuidHob = GetFirstGuidHob (&mFwCfgDataAddressGuid);
+ DataInHob = GET_GUID_HOB_DATA (GuidHob);
+ FwCfgDataAddress = (UINT64)(*(UINTN *)DataInHob);
+ }
+
+ return FwCfgDataAddress;
+}
+
+/**
+ To get firmware DMA address.
+
+ @param VOID
+
+ @retval firmware DMA address
+**/
+UINTN
+EFIAPI
+QemuGetFwCfgDmaAddress (
+ VOID
+ )
+{
+ UINTN FwCfgDmaAddress;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ VOID *DataInHob;
+
+ FwCfgDmaAddress = mFwCfgDmaAddress;
+ GuidHob = NULL;
+ DataInHob = NULL;
+
+ if (FwCfgDmaAddress == 0) {
+ GuidHob = GetFirstGuidHob (&mFwCfgDmaAddressGuid);
+ DataInHob = GET_GUID_HOB_DATA (GuidHob);
+ FwCfgDmaAddress = (UINT64)(*(UINTN *)DataInHob);
+ }
+
+ return FwCfgDmaAddress;
+}
+
/**
Returns a boolean indicating if the firmware configuration interface
is available or not.
@@ -37,7 +193,7 @@ QemuFwCfgIsAvailable (
VOID
)
{
- return (BOOLEAN)(mFwCfgSelectorAddress != 0 && mFwCfgDataAddress != 0);
+ return (BOOLEAN)(QemuGetFwCfgSelectorAddress () != 0 && QemuGetFwCfgDataAddress () != 0);
}
/**
@@ -56,7 +212,7 @@ QemuFwCfgSelectItem (
)
{
if (QemuFwCfgIsAvailable ()) {
- MmioWrite16 (mFwCfgSelectorAddress, SwapBytes16 ((UINT16)QemuFwCfgItem));
+ MmioWrite16 (QemuGetFwCfgSelectorAddress (), SwapBytes16 ((UINT16)QemuFwCfgItem));
}
}
@@ -86,30 +242,30 @@ MmioReadBytes (
#if defined (MDE_CPU_AARCH64) || defined (MDE_CPU_RISCV64) || defined (MDE_CPU_LOONGARCH64)
while (Ptr < End) {
- *(UINT64 *)Ptr = MmioRead64 (mFwCfgDataAddress);
+ *(UINT64 *)Ptr = MmioRead64 (QemuGetFwCfgDataAddress ());
Ptr += 8;
}
if (Left & 4) {
- *(UINT32 *)Ptr = MmioRead32 (mFwCfgDataAddress);
+ *(UINT32 *)Ptr = MmioRead32 (QemuGetFwCfgDataAddress ());
Ptr += 4;
}
#else
while (Ptr < End) {
- *(UINT32 *)Ptr = MmioRead32 (mFwCfgDataAddress);
+ *(UINT32 *)Ptr = MmioRead32 (QemuGetFwCfgDataAddress ());
Ptr += 4;
}
#endif
if (Left & 2) {
- *(UINT16 *)Ptr = MmioRead16 (mFwCfgDataAddress);
+ *(UINT16 *)Ptr = MmioRead16 (QemuGetFwCfgDataAddress ());
Ptr += 2;
}
if (Left & 1) {
- *Ptr = MmioRead8 (mFwCfgDataAddress);
+ *Ptr = MmioRead8 (QemuGetFwCfgDataAddress ());
}
}
@@ -162,9 +318,9 @@ DmaTransferBytes (
// This will fire off the transfer.
//
#if defined (MDE_CPU_AARCH64) || defined (MDE_CPU_RISCV64) || defined (MDE_CPU_LOONGARCH64)
- MmioWrite64 (mFwCfgDmaAddress, SwapBytes64 ((UINT64)&Access));
+ MmioWrite64 (QemuGetFwCfgDmaAddress (), SwapBytes64 ((UINT64)&Access));
#else
- MmioWrite32 ((UINT32)(mFwCfgDmaAddress + 4), SwapBytes32 ((UINT32)&Access));
+ MmioWrite32 ((UINT32)(QemuGetFwCfgDmaAddress () + 4), SwapBytes32 ((UINT32)&Access));
#endif
//
@@ -233,7 +389,7 @@ MmioWriteBytes (
UINTN Idx;
for (Idx = 0; Idx < Size; ++Idx) {
- MmioWrite8 (mFwCfgDataAddress, ((UINT8 *)Buffer)[Idx]);
+ MmioWrite8 (QemuGetFwCfgDataAddress (), ((UINT8 *)Buffer)[Idx]);
}
}
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf
index f2596f270e..8e191f2d22 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf
@@ -40,6 +40,7 @@ [LibraryClasses]
BaseLib
BaseMemoryLib
DebugLib
+ HobLib
IoLib
UefiBootServicesTableLib
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmioInternal.h b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmioInternal.h
index d7d645f700..18148f9997 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmioInternal.h
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmioInternal.h
@@ -16,6 +16,21 @@ extern UINTN mFwCfgSelectorAddress;
extern UINTN mFwCfgDataAddress;
extern UINTN mFwCfgDmaAddress;
+#define FW_CONFIG_SELECTOR_ADDRESS_HOB_GUID \
+ { \
+ 0x3cc47b04, 0x0d3e, 0xaa64, { 0x06, 0xa6, 0x4b, 0xdc, 0x9a, 0x2c, 0x61, 0x19 } \
+ }
+
+#define FW_CONFIG_DATA_ADDRESS_HOB_GUID \
+ { \
+ 0xef854788, 0x10f3, 0x8e7a, { 0x3e, 0xd0, 0x4d, 0x16, 0xc1, 0x79, 0x55, 0x2f } \
+ }
+
+#define FW_CONFIG_DMA_ADDRESS_HOB_GUID \
+ { \
+ 0x547cfaee, 0xa056, 0x3183, { 0x97, 0x47, 0x19, 0x83, 0x77, 0xd2, 0xa1, 0x07 } \
+ }
+
/**
Reads firmware configuration bytes into a buffer
@@ -96,6 +111,42 @@ EFIAPI
IN UINTN Size
);
+/**
+ Build firmware configure selector address HOB.
+
+ @param[in] FwCfgSelectorAddress Firmware configure selector address
+
+ @retval NULL
+**/
+VOID
+QemuBuildFwCfgSelectorHob (
+ IN UINT64 FwCfgSelectorAddress
+ );
+
+/**
+ Build firmware configure data address HOB.
+
+ @param[in] FwCfgDataAddress Firmware configure data address.
+
+ @retval NULL
+**/
+VOID
+QemuBuildFwCfgDataHob (
+ IN UINT64 FwCfgDataAddress
+ );
+
+/**
+ Build firmware configure DMA address HOB.
+
+ @param[in] FwCfgDmaAddress Firmware configure DMA address.
+
+ @retval NULL
+**/
+VOID
+QemuBuildFwCfgDmaHob (
+ IN UINT64 FwCfgDmaAddress
+ );
+
/**
Slow READ_BYTES_FUNCTION.
**/
--
2.27.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#118257): https://edk2.groups.io/g/devel/message/118257
Mute This Topic: https://groups.io/mt/105724969/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-04-25 4:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 4:17 [edk2-devel] [PATCH v2 0/7] Adjust the QemuFwCfgLibMmio and add PEI stage Chao Li
2024-04-25 4:18 ` [edk2-devel] [PATCH v2 1/7] OvmfPkg: Separate QemuFwCfgLibMmio.c into two files Chao Li
2024-04-25 4:18 ` Chao Li [this message]
2024-04-25 7:40 ` [edk2-devel] [PATCH v2 2/7] OvmfPkg: Add the way of HOBs in QemuFwCfgLibMmio Gerd Hoffmann
2024-04-25 8:09 ` Chao Li
2024-04-25 8:11 ` Ard Biesheuvel
2024-04-25 8:16 ` Chao Li
2024-04-25 4:18 ` [edk2-devel] [PATCH v2 3/7] OvmfPkg: Add the QemuFwCfgMmioLib PEI stage version Chao Li
2024-04-25 7:53 ` Gerd Hoffmann
2024-04-25 8:06 ` Chao Li
2024-04-25 9:02 ` Gerd Hoffmann
2024-04-25 9:23 ` Chao Li
2024-04-25 4:18 ` [edk2-devel] [PATCH v2 4/7] OvmfPkg: Copy the same new INF as QemuFwCfgLibMmio.inf Chao Li
2024-04-25 4:18 ` [edk2-devel] [PATCH v2 5/7] ArmVirtPkg: Enable QemuFwCfgMmioDxeLib.inf Chao Li
2024-04-25 4:18 ` [edk2-devel] [PATCH v2 6/7] OvmfPkg/RiscVVirt: " Chao Li
2024-04-25 4:18 ` [edk2-devel] [PATCH v2 7/7] OvmfPkg: Remove QemuFwCfgLibMmio.inf Chao Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240425041816.1386268-1-lichao@loongson.cn \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox