From: "maobibo" <maobibo@loongson.cn>
To: devel@edk2.groups.io, lichao@loongson.cn
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
Jiewen Yao <jiewen.yao@intel.com>,
Jordan Justen <jordan.l.justen@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [edk2-devel] [PATCH v5 27/36] OvmfPkg/LoongArchVirt: Add serial port hook library
Date: Wed, 3 Jan 2024 18:07:12 +0800 [thread overview]
Message-ID: <4fdedfc1-53a4-9a73-32de-9462cff4236d@loongson.cn> (raw)
In-Reply-To: <20231228100718.1766374-1-lichao@loongson.cn>
On 2023/12/28 下午6:07, Chao Li wrote:
> Add a serial port hook library in LoongArchVirt named
> Fdt16550SerialProtHookLib, this library is referenced from ArmVirtPkg.
>
> LoongArch QEMU virtual machine uses register of LOONGARCH_CSR_KS1 to
> transfer serial port base addres from the PEI phase to the DXE phase.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584
>
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Chao Li <lichao@loongson.cn>
> ---
> .../EarlyFdt16550SerialPortHookLib.c | 52 +++++++++++++++++++
> .../EarlyFdt16550SerialPortHookLib.inf | 37 +++++++++++++
> .../Fdt16550SerialPortHookLib.c | 39 ++++++++++++++
> .../Fdt16550SerialPortHookLib.inf | 33 ++++++++++++
> .../Fdt16550SerialPortHookLib.uni | 14 +++++
> 5 files changed, 175 insertions(+)
> create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c
> create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf
> create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c
> create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf
> create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni
>
> diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c
> new file mode 100644
> index 0000000000..9f1fcc970a
> --- /dev/null
> +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c
> @@ -0,0 +1,52 @@
> +/** @file
> + PEI Phase Early Platform Hook Library instance for 16550 Uart.
> +
> + Copyright (c) 2020 - 2023, Arm Ltd. All rights reserved.<BR>
> + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/FdtSerialPortAddressLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/PlatformHookLib.h>
> +#include <Register/LoongArch64/Csr.h>
> +
> +/** Platform hook to retrieve the 16550 UART base address from the platform
> + Device tree and store it in the reigster LOONGARCH_CSR_KS1.
> +
> + @retval RETURN_SUCCESS Success.
> + @retval RETURN_INVALID_PARAMETER A parameter was invalid.
> + @retval RETURN_NOT_FOUND Serial port information not found.
> +
> +**/
> +RETURN_STATUS
> +EFIAPI
> +PlatformHookSerialPortInitialize (
> + VOID
> + )
> +{
> + RETURN_STATUS Status;
> + VOID *DeviceTreeBase;
> + UINT64 SerialConsoleAddress;
> +
> + if (PcdGet64 (PcdSerialRegisterBase) != 0) {
> + return RETURN_SUCCESS;
> + }
> +
> + DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
> + if (DeviceTreeBase == NULL) {
> + return RETURN_NOT_FOUND;
> + }
> +
> + Status = FdtSerialGetConsolePort (DeviceTreeBase, &SerialConsoleAddress);
> + if (RETURN_ERROR (Status)) {
> + return Status;
> + }
> +
> + CsrWrite (LOONGARCH_CSR_KS1, (UINTN)SerialConsoleAddress);
> +
> + return RETURN_SUCCESS;
> +}
> diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf
> new file mode 100644
> index 0000000000..55b0c03a01
> --- /dev/null
> +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf
> @@ -0,0 +1,37 @@
> +## @file
> +# PEI Phase Early Platform Hook Library instance for 16550 Uart.
> +#
> +# Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
> +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.<BR>
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> + INF_VERSION = 1.29
> + BASE_NAME = EarlyFdt16550SerialPortHookLib
> + MODULE_UNI_FILE = Fdt16550SerialPortHookLib.uni
> + FILE_GUID = 6A5FEBCB-C676-A7C1-A96C-B79D4860EEC5
> + MODULE_TYPE = PEIM
> + VERSION_STRING = 1.0
> + LIBRARY_CLASS = PlatformHookLib|SEC PEI_CORE PEIM
> +
> +[Sources]
> + EarlyFdt16550SerialPortHookLib.c
> +
> +[LibraryClasses]
> + BaseLib
> + PcdLib
> + FdtLib
> + FdtSerialPortAddressLib
> +
> +[Packages]
> + EmbeddedPkg/EmbeddedPkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + OvmfPkg/OvmfPkg.dec
> +
> +[Pcd]
> + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
> diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c
> new file mode 100644
> index 0000000000..fd188f75b8
> --- /dev/null
> +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c
> @@ -0,0 +1,39 @@
> +/** @file
> + Platform Hook Library instance for 16550 Uart.
> +
> + Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
> + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/PlatformHookLib.h>
> +#include <Register/LoongArch64/Csr.h>
> +
> +/** Platform hook to retrieve the 16550 UART base address from register
> + LOONGARCH_CSR_KS1 that caches the UART base address from early boot
> + stage and store it in PcdSerialRegisterBase.
> +
> + @retval RETURN_SUCCESS Success.
> + @retval RETURN_NOT_FOUND Serial Port information not found.
> +
> +**/
> +RETURN_STATUS
> +EFIAPI
> +PlatformHookSerialPortInitialize (
> + VOID
> + )
> +{
> + UINT64 *UartBase;
> +
> + if (PcdGet64 (PcdSerialRegisterBase) != 0) {
> + return RETURN_SUCCESS;
> + }
> +
> + *UartBase = CsrRead (LOONGARCH_CSR_KS1);
> +
> + return (RETURN_STATUS)PcdSet64S (PcdSerialRegisterBase, (UINTN)*UartBase);
> +}
> diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf
> new file mode 100644
> index 0000000000..b5fc03a284
> --- /dev/null
> +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf
> @@ -0,0 +1,33 @@
> +## @file
> +# Platform Hook Library instance for 16550 Uart.
> +#
> +# Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
> +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.<BR>
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> + INF_VERSION = 1.29
> + BASE_NAME = Fdt16550SerialPortHookLib
> + MODULE_UNI_FILE = Fdt16550SerialPortHookLib.uni
> + FILE_GUID = 808335DB-220E-A353-887C-9AA1B7D433A1
> + MODULE_TYPE = BASE
> + VERSION_STRING = 1.0
> + LIBRARY_CLASS = PlatformHookLib|DXE_CORE DXE_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
> + CONSTRUCTOR = PlatformHookSerialPortInitialize
> +
> +[Sources]
> + Fdt16550SerialPortHookLib.c
> +
> +[LibraryClasses]
> + BaseLib
> + PcdLib
> +
> +[Packages]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> +
> +[Pcd]
> + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
> diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni
> new file mode 100644
> index 0000000000..92eb2ed0b4
> --- /dev/null
> +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni
> @@ -0,0 +1,14 @@
> +// /** @file
> +// Platform Hook Library instance for 16550 Uart.
> +//
> +//
> +// Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
> +// Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.<BR>
> +//
> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> +//
> +// **/
> +
> +#string STR_MODULE_ABSTRACT #language en-US "Platform Hook Library instance for 16550 Uart."
> +
> +#string STR_MODULE_DESCRIPTION #language en-US "Platform Hook Library instance for 16550 Uart."
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113065): https://edk2.groups.io/g/devel/message/113065
Mute This Topic: https://groups.io/mt/103398630/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-01-03 10:07 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-28 10:03 [edk2-devel] [PATCH v5 00/36] Enable LoongArch virtual machine in edk2 Chao Li
2023-12-28 10:04 ` [edk2-devel] [PATCH v5 01/36] MdePkg: Add the header file named Csr.h for LoongArch64 Chao Li
2023-12-28 10:04 ` [edk2-devel] [PATCH v5 02/36] MdePkg: Add LoongArch64 FPU function set into BaseCpuLib Chao Li
2023-12-28 10:04 ` [edk2-devel] [PATCH v5 03/36] MdePkg: Add LoongArch64 exception function set into BaseLib Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 04/36] MdePkg: Add LoongArch64 local interrupt " Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 06/36] MdePkg: Add read stable counter operation for LoongArch Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 07/36] MdePkg: Add CSR " Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 08/36] MdePkg: Add IOCSR " Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 09/36] MdePkg: Add a new library named PeiServicesTablePointerLibKs0 Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 10/36] UefiCpuPkg: Add LoongArch64 CPU Timer library Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 11/36] UefiCpuPkg: Add CPU exception library for LoongArch Chao Li
2023-12-28 10:05 ` [edk2-devel] [PATCH v5 12/36] UefiCpuPkg: Add CpuMmuLib.h to UefiCpuPkg Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 13/36] UefiCpuPkg: Add LoongArch64CpuMmuLib " Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 14/36] UefiCpuPkg: Add multiprocessor library for LoongArch64 Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 15/36] UefiCpuPkg: Add CpuDxe driver " Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 16/36] EmbeddedPkg: Add PcdPrePiCpuIoSize width for LOONGARCH64 Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 17/36] ArmVirtPkg: Move PCD of FDT base address and FDT padding to OvmfPkg Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 18/36] UefiCpuPkg: Add a new CPU IO 2 driver named CpuMmio2Dxe Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 19/36] ArmVirtPkg: Enable CpuMmio2Dxe Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 20/36] OvmfPkg/RiscVVirt: " Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 21/36] OvmfPkg/RiscVVirt: Remove PciCpuIo2Dxe from RiscVVirt Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 22/36] ArmVirtPkg: Move the FdtSerialPortAddressLib to OvmfPkg Chao Li
2023-12-28 10:06 ` [edk2-devel] [PATCH v5 23/36] ArmVirtPkg: Move PcdTerminalTypeGuidBuffer and PcdUninstallMemAttrProtocol into OvmfPkg Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 24/36] ArmVirtPkg: Move PlatformBootManagerLib to OvmfPkg Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 25/36] OvmfPkg/LoongArchVirt: Add stable timer driver Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 26/36] OvmfPkg/LoongArchVirt: Add a NULL library named CollectApResouceLibNull Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 27/36] OvmfPkg/LoongArchVirt: Add serial port hook library Chao Li
2024-01-03 10:07 ` maobibo [this message]
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 28/36] OvmfPkg/LoongArchVirt: Add the early serial port output library Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 29/36] OvmfPkg/LoongArchVirt: Add real time clock library Chao Li
2024-01-03 10:07 ` maobibo
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 30/36] OvmfPkg/LoongArchVirt: Add NorFlashQemuLib Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 31/36] OvmfPkg/LoongArchVirt: Add FdtQemuFwCfgLib Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 32/36] OvmfPkg/LoongArchVirt: Add reset system library Chao Li
2024-01-04 1:28 ` maobibo
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 33/36] OvmfPkg/LoongArchVirt: Support SEC phase Chao Li
2024-01-04 1:49 ` maobibo
2024-01-04 6:28 ` Chao Li
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 34/36] OvmfPkg/LoongArchVirt: Support PEI phase Chao Li
2024-01-03 8:12 ` maobibo
2023-12-28 10:07 ` [edk2-devel] [PATCH v5 35/36] OvmfPkg/LoongArchVirt: Add build file Chao Li
2023-12-28 10:08 ` [edk2-devel] [PATCH v5 36/36] OvmfPkg/LoongArchVirt: Add self introduction file Chao Li
[not found] ` <17A4F6E18EBFD408.18542@groups.io>
2023-12-29 6:27 ` [edk2-devel] [PATCH v5 20/36] OvmfPkg/RiscVVirt: Enable CpuMmio2Dxe 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=4fdedfc1-53a4-9a73-32de-9462cff4236d@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