From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 71CDD74003E for ; Thu, 25 Apr 2024 04:18:25 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=JU7/im2J0cgWLOBl8pEyTSfLtgvcD/p4fC1yBm4z+nY=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1714018703; v=1; b=SYWM/7dBqlvFQMikcuTHQ/iodVhZMSuC1jTEuES1375sCCu9YSDzRtCqSIz3qLcezbHnMrcq L7ofwtGveBdgOrQXJ2vHoesWRMQFWrI0dOtbCJZgPcMNS9sLIWBEiimECB3U+RAmptaeK6eekBJ DZPaQsqm8oqcdEJnA4Cn7SKathcs+LguJEXLHTg4ow7udtCW4mDwneAvu5AnT8tMDRGSDBPI0Ke nU2H7prpFrVMl/H8geo2HikFSMd9OKsUQEdzs1CD4PFDf+Qj5LvxPhQ9wzm98RAX0HQpK7Z6tUp SD/ifU0sRipKB/hbsZrmWY/lQawksmSL5AqiLnxBfs8fg== X-Received: by 127.0.0.2 with SMTP id 29nSYY7687511xaDpGwMT9qV; Wed, 24 Apr 2024 21:18:23 -0700 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.9085.1714018701165517550 for ; Wed, 24 Apr 2024 21:18:23 -0700 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxCuqK2SlmgKICAA--.436S3; Thu, 25 Apr 2024 12:18:18 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxIlaJ2SlmGrkEAA--.695S2; Thu, 25 Apr 2024 12:18:17 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Gerd Hoffmann , Leif Lindholm , Sami Mujawar , Sunil V L , Andrei Warkentin Subject: [edk2-devel] [PATCH v2 2/7] OvmfPkg: Add the way of HOBs in QemuFwCfgLibMmio Date: Thu, 25 Apr 2024 12:18:16 +0800 Message-Id: <20240425041816.1386268-1-lichao@loongson.cn> In-Reply-To: <20240425041728.1385891-1-lichao@loongson.cn> References: <20240425041728.1385891-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxIlaJ2SlmGrkEAA--.695S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQASCGYpxJMBJQADsk X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Wed, 24 Apr 2024 21:18:23 -0700 Resent-From: lichao@loongson.cn Reply-To: devel@edk2.groups.io,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: h0lQdk1MxvtDzopNm2h6Er5fx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b="SYWM/7dB"; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io 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 Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Leif Lindholm Cc: Sami Mujawar Cc: Sunil V L Cc: Andrei Warkentin Signed-off-by: Chao Li --- .../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 #include +#include +#include + #include #include #include +#include #include #include #include @@ -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] -=-=-=-=-=-=-=-=-=-=-=-