Re: [edk2-devel] [PATCH] Platform/Loongson: Remove minimium memory size limitation
On 2024/3/25 下午5:25, xianglai wrote: From: Bibo Mao Temparory stack memory on PEI is hardcoded now, also minimium memory size 256M is hardcoded now. Here memory map table from fw cfg can be parsed. If there is memory map entry contains pei stack, it can be published as usable memory at PEI stage. Signed-off-by: Bibo Mao Signed-off-by: Xianglai Li Cc: Bibo Mao Cc: Chao Li --- .../Loongson/LoongArchQemuPkg/Loongson.dec| 2 - .../Loongson/LoongArchQemuPkg/Loongson.dsc| 6 --- .../LoongArchQemuPkg/PlatformPei/MemDetect.c | 37 ++- .../PlatformPei/PlatformPei.inf | 2 - 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec index e638b835e4..c2c6cc9596 100644 --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec @@ -48,8 +48,6 @@ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase|0|UINT64|0x000b gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x000c - gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop|0x0|UINT64|0x000d - gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom|0x0|UINT64|0x000e gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x000f gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x0010 diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc index 58aa16d3a9..aab2ca9b28 100644 --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc @@ -356,12 +356,6 @@ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase | 0x1 gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize | 0x1 gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase| 0x10 - # - # minimal memory for uefi bios should be 512M - # 0x - 0x1000 - # 0x9000 - 0xA000 - # - gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop| 0x1000 gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions | 0x06 gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile| { 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 } diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c index 7e6a4a3aa9..03d1b0b75d 100644 --- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c @@ -40,12 +40,47 @@ PublishPeiMemory ( UINT64 Base; UINT64 Size; UINT64 RamTop; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTNFwCfgSize; + UINTNProcessed; + LOONGARCH_MEMMAP_ENTRY MemoryMapEntry; // // Determine the range of memory to use during PEI // Base = PcdGet64 (PcdSecPeiTempRamBase) + PcdGet32 (PcdSecPeiTempRamSize); - RamTop = PcdGet64 (PcdUefiRamTop); + RamTop = 0; + + Status = QemuFwCfgFindFile ("etc/memmap", , ); + if (EFI_ERROR (Status)) { +return Status; + } + + if (FwCfgSize % sizeof MemoryMapEntry != 0) { +return EFI_PROTOCOL_ERROR; + } + + QemuFwCfgSelectItem (FwCfgItem); + for (Processed = 0; Processed < FwCfgSize; Processed += sizeof MemoryMapEntry) { +QemuFwCfgReadBytes (sizeof MemoryMapEntry, ); +if (MemoryMapEntry.Type != EfiAcpiAddressRangeMemory) { + continue; +} + +/* + * Find memory map entry where PEI temp stack is located + */ +if ((MemoryMapEntry.BaseAddr <= Base) && +(Base < (MemoryMapEntry.BaseAddr + MemoryMapEntry.Length))) { +RamTop = MemoryMapEntry.BaseAddr + MemoryMapEntry.Length; Xianglai, Will it be better if there is one "break" sentence? Regards Bibo Mao +} + } + + if (RamTop == 0) { +DEBUG ((DEBUG_ERROR, "ERROR: No memory map entry contains temp stack \n")); +ASSERT (FALSE); + } + Size = RamTop - Base; // diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf index 6cc3513b63..65591a4d7b 100644 --- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf @@ -64,8 +64,6 @@ [FixedPcd] gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize - gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom - gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117098):
Re: [edk2-devel] [PATCH v6 25/36] OvmfPkg/LoongArchVirt: Add stable timer driver
On 2024/1/5 下午5:45, Chao Li wrote: Add a CPU timer driver named StableTimerDxe, which proviedes EFI_TIMER_ARCH_PROTOCOL for LoongArch. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Baoqi Zhang --- .../Drivers/StableTimerDxe/Timer.c| 381 ++ .../Drivers/StableTimerDxe/Timer.h| 127 ++ .../Drivers/StableTimerDxe/TimerDxe.inf | 41 ++ 3 files changed, 549 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.c create mode 100644 OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.h create mode 100644 OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/TimerDxe.inf diff --git a/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.c b/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.c new file mode 100644 index 00..0e0f10970a --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.c @@ -0,0 +1,381 @@ +/** @file + Timer Architectural Protocol as defined in the DXE CIS + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include "Timer.h" + +// +// The handle onto which the Timer Architectural Protocol will be installed +// +EFI_HANDLE mTimerHandle = NULL; +EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL; + +// +// The Timer Architectural Protocol that this driver produces +// +EFI_TIMER_ARCH_PROTOCOL mTimer = { + TimerDriverRegisterHandler, + TimerDriverSetTimerPeriod, + TimerDriverGetTimerPeriod, + TimerDriverGenerateSoftInterrupt +}; + +// +// Pointer to the CPU Architectural Protocol instance +// +EFI_CPU_ARCH_PROTOCOL *mCpu; + +// +// The notification function to call on every timer interrupt. +// A bug in the compiler prevents us from initializing this here. +// +EFI_TIMER_NOTIFY mTimerNotifyFunction; + +/** + Sets the counter value for timer. + + @param CountThe 16-bit counter value to program into stable timer. + + @retval VOID +**/ +VOID +SetPitCount ( + IN UINT64 Count + ) +{ + if (Count <= 4) { +return; + } + + Count &= LOONGARCH_CSR_TMCFG_TIMEVAL; + Count |= LOONGARCH_CSR_TMCFG_EN | LOONGARCH_CSR_TMCFG_PERIOD; + CsrWrite (LOONGARCH_CSR_TMCFG, Count); +} + +/** + Timer Interrupt Handler. + + @param InterruptTypeThe type of interrupt that occurred + @param SystemContextA pointer to the system context when the interrupt occurred + + @retval VOID +**/ +VOID +EFIAPI +TimerInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + EFI_TPL OriginalTPL; + + OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL); + + // + // Clear interrupt. + // + CsrWrite (LOONGARCH_CSR_TINTCLR, 0x1); + + if (mTimerNotifyFunction != NULL) { +// +// @bug : This does not handle missed timer interrupts +// +mTimerNotifyFunction (mTimerPeriod); + } + + gBS->RestoreTPL (OriginalTPL); +} + +/** + This function registers the handler NotifyFunction so it is called every time + the timer interrupt fires. It also passes the amount of time since the last + handler call to the NotifyFunction. If NotifyFunction is NULL, then the + handler is unregistered. If the handler is registered, then EFI_SUCCESS is + returned. If the CPU does not support registering a timer interrupt handler, + then EFI_UNSUPPORTED is returned. If an attempt is made to register a handler + when a handler is already registered, then EFI_ALREADY_STARTED is returned. + If an attempt is made to unregister a handler when a handler is not registered, + then EFI_INVALID_PARAMETER is returned. If an error occurs attempting to + register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR + is returned. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param NotifyFunction The function to call when a timer interrupt fires. This + function executes at TPL_HIGH_LEVEL. The DXE Core will + register a handler for the timer interrupt, so it can know + how much time has passed. This information is used to + signal timer based events. NULL will unregister the handler. + + @retvalEFI_SUCCESSThe timer handler was registered. + @retvalEFI_UNSUPPORTEDThe platform does not support timer interrupts. + @retvalEFI_ALREADY_STARTEDNotifyFunction is not NULL, and a handler is already +registered. + @retvalEFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not +previously registered. + @retvalEFI_DEVICE_ERROR
Re: [edk2-devel] [PATCH v6 26/36] OvmfPkg/LoongArchVirt: Add a NULL library named CollectApResouceLibNull
On 2024/1/10 上午10:47, Chao Li wrote: Hi Bibo, Thanks, Chao On 2024/1/10 09:24, maobibo wrote: On 2024/1/5 下午5:45, Chao Li wrote: This Library is used to collect APs resources, but is currently NULL for OvmfPkg, because it is not used by the LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li --- .../CollectApResourceLibNull.c | 38 +++ .../CollectApResourceLibNull.inf | 31 +++ .../CollectApResourceLibNull.uni | 9 + 3 files changed, 78 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c new file mode 100644 index 00..19995c1193 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c @@ -0,0 +1,38 @@ +/** @file + LoongArch64 CPU Collect AP resource NULL Library functions. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include "../../../UefiCpuPkg/Library/LoongArch64MpInitLib/MpLib.h" The included path is a little strange, should we put CollectApResouceLibNull library in ovmf package or UefiCpuPkg/Library/LoongArch64MpInitLib package? This library is a private because virtual-matchines collect AP resouces differently from physical machines, so I thought would be fine if it was located in OvmfPkg/LoongArchVirt/Library. Ok, that sounds good to me. Reviewed-by: Bibo Mao Regards Bibo Mao + +VOID +SaveProcessorResourceData ( + IN PROCESSOR_RESOURCE_DATA * + ); + +VOID +EFIAPI +SaveProcessorResource ( + PROCESSOR_RESOURCE_DATA *mProcessorResource + ) +{ + SaveProcessorResourceData (mProcessorResource); +} + +VOID +EFIAPI +CollectAllProcessorResource ( + VOID + ) +{ + return; +} diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf new file mode 100644 index 00..c166df6bbd --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf @@ -0,0 +1,31 @@ +## @file +# LoongArch64 CPU Collect AP resource NULL Library. +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 1.29 + BASE_NAME = CollectApResourceLibNull + MODULE_UNI_FILE = CollectApResourceLibNull.uni + FILE_GUID = 8C3B54BF-6A9F-E8B4-4D57-67B3AB578DD6 + MODULE_TYPE = PEIM + VERSION_STRING = 1.1 + LIBRARY_CLASS = PEIM + +[Sources.common] + CollectApResourceLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + HobLib + MemoryAllocationLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni new file mode 100644 index 00..d1638ab11e --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni @@ -0,0 +1,9 @@ +// @file +// LoongArch64 CPU Collect AP resource NULL Library. +// +// Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved. +// SPDX-License-Identifier: BSD-2-Clause-Patent + +#string STR_MODULE_ABSTRACT #language en-US "CPU Collect AP resource NULL Library." + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Collect AP resource NULL Library." -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113522): https://edk2.groups.io/g/devel/message/113522 Mute This Topic: https://groups.io/mt/103540125/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v6 36/36] OvmfPkg/LoongArchVirt: Add self introduction file
On 2024/1/5 下午5:46, Chao Li wrote: Add self introduction file for LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li --- OvmfPkg/LoongArchVirt/Readme.md | 67 + 1 file changed, 67 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Readme.md diff --git a/OvmfPkg/LoongArchVirt/Readme.md b/OvmfPkg/LoongArchVirt/Readme.md new file mode 100644 index 00..57fc74c296 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Readme.md @@ -0,0 +1,67 @@ +# LoongArch QEMU virt platform + +## Overview + + LoongArch QEMU virt is a generic platform that dose not require any actual hardware. + The minimum required QEMU version is [8.1](https://gitlab.com/qemu-project/qemu/-/tags), the minimum required GCC version is [GCC13](https://gcc.gnu.org/gcc-13/), the minimum required Binutils version is [2.40](https://ftp.gnu.org/gnu/binutils/). + +## Prepare (X86 Linux Environment) + +### Fedora39 +Install LoongArch64 cross compiler, LoongArch system QEMU. + +yum install gcc-loongarch64-linux-gnu +yum install qemu-system-loongarch64 + +### Others X86 OS ENV + Configure cross-tools + +**Download:** + +wget https://github.com/loongson/build-tools/releases/download/2023.08.08/x86_64-cross-tools-loongarch64-binutils_2.41-gcc_13.2.0.tar.xz + +**Configure the cross-tools environment:** + +mkdir /opt/loongarch64_cross-toolchain/ +tar -vxf x86_64-cross-tools-loongarch64-binutils_2.41-gcc_13.2.0.tar.xz -C /opt/loongarch64_cross-toolchain/ +export PATH=/opt/loongarch64_cross-toolchain/cross-tools/bin:$PATH + +Note: Please obtain [the latest cross-compilation](https://github.com/loongson/build-tools) toolchains. + + Build QEMU + +git clone https://gitlab.com/qemu-project/qemu.git + +Note: Please refer to QEMU compilation rules, located in qemu/doc/system/loongarch/virt.rst. + + +## Build LoongArch QEMU virtual machine firmware + Get edk2 resouces + +git clone --recurse-submodule https://github.com/tianocore/edk2.git + + Building LoongArch QEMU virt FW with GCC + +export WORKSPACE=`pwd` +export GCC5_LOONGARCH64_PREFIX=loongarch64-unknown-linux-gnu- +export PACKAGES_PATH=$WORKSPACE/edk2 +export EDK_TOOLS_PATH=$WORKSPACE/edk2/BaseTools +source edk2/edksetup.sh --reconfig +make -C edk2/BaseTools +source edk2/edksetup.sh BaseTools +build -b RELEASE -t GCC5 -a LOONGARCH64 -p OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc + +## Test LoongArch QEMU virtual machine firmware +qemu-system-loongarch64 \ +-m 4G \ +-M virt \ +-smp 2 \ +-cpu la464 \ +-bios Build/LoongArchVirtQemu/RELEASE_GCC5/FV/QEMU_EFI.fd \ +-serial stdio + +## Test LoongArch QEMU virtual machine OS + +* Download ArchLinux QCOW [images](https://mirrors.pku.edu.cn/loongarch/archlinux/images) for LoongArch. + +* [Running LoongArch ArchLinux on virtual machine](https://mirrors.pku.edu.cn/loongarch/archlinux/images/README.html). Reviewed-by: Bibo Mao -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113506): https://edk2.groups.io/g/devel/message/113506 Mute This Topic: https://groups.io/mt/103540138/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v6 35/36] OvmfPkg/LoongArchVirt: Add build file
On 2024/1/5 下午5:46, Chao Li wrote: Add infrastructure files to build edk2 for LoongArch QEMU virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc | 34 + OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc | 679 OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf | 313 + OvmfPkg/LoongArchVirt/VarStore.fdf.inc | 67 ++ 4 files changed, 1093 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc create mode 100644 OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc create mode 100644 OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf create mode 100644 OvmfPkg/LoongArchVirt/VarStore.fdf.inc diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc b/OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc new file mode 100644 index 00..22373bec6a --- /dev/null +++ b/OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc @@ -0,0 +1,34 @@ +## @file +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +DEFINE BLOCK_SIZE = 0x1000 + + +# FW total +DEFINE FW_BASE_ADDRESS= 0x1c00 +DEFINE FW_BLOCKS = 0x400 +DEFINE FW_SIZE= 0x40 + + +#Flash code layout +#Set Sec size in flash +DEFINE SECFV_SIZE = 0x0001 + +#Set Pei size in flash +DEFINE PEIFV_SIZE = 0x0004 + +#Set Dxe size in flash +DEFINE DXEFV_SIZE = 0x0035 + +#Set FVMAIN size +DEFINE FVMAIN_SIZE= $(SECFV_SIZE) + $(PEIFV_SIZE) +$(DXEFV_SIZE) + +#Set Memory layout +DEFINE SEC_PEI_TEMP_RAM_BASE = 0x1 +DEFINE SEC_PEI_TEMP_RAM_SIZE = 0x8 +DEFINE DEVICE_TREE_RAM_BASE = 0x10 diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc new file mode 100644 index 00..0a6b5f830b --- /dev/null +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc @@ -0,0 +1,679 @@ +## @file +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + + +# +# Defines Section - statements that will be processed to create a Makefile. +# +### +[Defines] + PLATFORM_NAME = LoongArchVirtQemu + PLATFORMPKG_NAME = LoongArchVirtQemu + PLATFORM_GUID = 7926ea52-b0dc-4ee8-ac63-341eebd84ed4 + PLATFORM_VERSION = 0.1 + DSC_SPECIFICATION = 0x00010005 + OUTPUT_DIRECTORY = Build/$(PLATFORM_NAME) + SUPPORTED_ARCHITECTURES= LOONGARCH64 + BUILD_TARGETS = DEBUG|RELEASE + SKUID_IDENTIFIER = DEFAULT + FLASH_DEFINITION = OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf + TTY_TERMINAL = FALSE + +!include LoongArchVirt.fdf.inc + + # + # Defines for default states. These can be changed on the command line. + # -D FLAG=VALUE + DEFINE TTY_TERMINAL= FALSE + DEFINE SECURE_BOOT_ENABLE = FALSE + DEFINE TPM2_ENABLE = FALSE + DEFINE TPM2_CONFIG_ENABLE = FALSE + + # + # Network definition + # + DEFINE NETWORK_IP6_ENABLE = FALSE + DEFINE NETWORK_HTTP_BOOT_ENABLE= FALSE + DEFINE NETWORK_SNP_ENABLE = FALSE + DEFINE NETWORK_TLS_ENABLE = FALSE + DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE + DEFINE NETWORK_ISCSI_ENABLE= FALSE + +!include NetworkPkg/NetworkDefines.dsc.inc + +# +# Defines for default states. These can be changed on the command line. +# -D FLAG=VALUE + +[BuildOptions] + GCC:RELEASE_*_*_CC_FLAGS = -DSPEEDUP + + # + # Disable deprecated APIs. + # + GCC:*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES + +!include NetworkPkg/NetworkBuildOptions.dsc.inc + +[BuildOptions.LOONGARCH64.EDKII.SEC] + *_*_*_CC_FLAGS = + +# +# Default page size is 16K for loongarch qemu tcg +# code section separated with data section with 16K page alignment, else data +# write operation in the same page with code section will cause qemu TB flush. +# +[BuildOptions.common.EDKII.DXE_CORE,BuildOptions.common.EDKII.DXE_DRIVER,BuildOptions.common.EDKII.UEFI_DRIVER,BuildOptions.common.EDKII.UEFI_APPLICATION] +
Re: [edk2-devel] [PATCH v6 31/36] OvmfPkg/LoongArchVirt: Add FdtQemuFwCfgLib
On 2024/1/5 下午5:46, Chao Li wrote: This library for PEI phase, and obtains the QemuFwCfg base address by directly parsing the FDT, reads and writes the data in QemuFwCfg by operating on the QemuFwCfg base address. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- .../FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c | 504 ++ .../FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.inf| 42 ++ .../FdtQemuFwCfgLib/QemuFwCfgLibInternal.h| 73 +++ .../Library/FdtQemuFwCfgLib/QemuFwCfgPei.c| 117 4 files changed, 736 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgLibInternal.h create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgPei.c diff --git a/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c new file mode 100644 index 00..a1f114b327 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c @@ -0,0 +1,504 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: +- FwCfg - firmWare Configure +- CTL - Control +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "QemuFwCfgLibInternal.h" + +EFI_GUID mFwCfgSelectorAddressGuid = FW_CONFIG_SELECTOR_ADDRESS_HOB_GUID; +EFI_GUID mFwCfgDataAddressGuid = FW_CONFIG_DATA_ADDRESS_HOB_GUID; + +STATIC UINTN mFwCfgSelectorAddress; +STATIC UINTN mFwCfgDataAddress; + +/** + 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 (); +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 (); +DataInHob= GET_GUID_HOB_DATA (GuidHob); +FwCfgDataAddress = (UINT64)(*(UINTN *)DataInHob); + } + + return FwCfgDataAddress; +} + +/** + Selects a firmware configuration item for reading. + + Following this call, any data read from this item will start from + the beginning of the configuration item's data. + + @param[in] QemuFwCfgItem - Firmware Configuration item to read +**/ +VOID +EFIAPI +QemuFwCfgSelectItem ( + IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem + ) +{ + UINTN FwCfgSelectorAddress; + + FwCfgSelectorAddress = QemuGetFwCfgSelectorAddress (); + MmioWrite16 (FwCfgSelectorAddress, SwapBytes16 ((UINT16)(UINTN)QemuFwCfgItem)); +} + +/** + Slow READ_BYTES_FUNCTION. + + @param[in] The size of the data to be read. + @param[in] BufferThe buffer that stores the readout data. +**/ +VOID +EFIAPI +MmioReadBytes ( + IN UINTN Size, + IN VOID *Buffer OPTIONAL + ) +{ + UINTN Left; + UINT8 *Ptr; + UINT8 *End; + UINTN FwCfgDataAddress; + + Left = Size & 7; + + Size -= Left; + Ptr = Buffer; + End = Ptr + Size; + + FwCfgDataAddress = QemuGetFwCfgDataAddress (); + while (Ptr < End) { +*(UINT64 *)Ptr = MmioRead64 (FwCfgDataAddress); +Ptr += 8; + } + + if (Left & 4) { +*(UINT32 *)Ptr = MmioRead32 (FwCfgDataAddress); +Ptr += 4; + } + + if (Left & 2) { +*(UINT16 *)Ptr = MmioRead16 (FwCfgDataAddress); +Ptr += 2; + } + + if (Left & 1) { +*Ptr = MmioRead8 (FwCfgDataAddress); + } +} + +/** + Slow WRITE_BYTES_FUNCTION. + + @param[in] The size of the data to be write. + @param[in] BufferThe buffer that stores the writein data. +**/ +VOID +EFIAPI +MmioWriteBytes ( + IN UINTN Size, + IN VOID *Buffer OPTIONAL + ) +{ + UINTN Idx; + UINTN FwCfgDataAddress; + + FwCfgDataAddress =
Re: [edk2-devel] [PATCH v6 30/36] OvmfPkg/LoongArchVirt: Add NorFlashQemuLib
On 2024/1/5 下午5:46, Chao Li wrote: Add NorFlashQemuLib for LoongArch, it is referenced from ArmVirtPkg. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- .../Library/NorFlashQemuLib/NorFlashQemuLib.c | 140 ++ .../NorFlashQemuLib/NorFlashQemuLib.inf | 43 ++ 2 files changed, 183 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.inf diff --git a/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.c b/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.c new file mode 100644 index 00..ae9af09c4c --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.c @@ -0,0 +1,140 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +#include + +#define QEMU_NOR_BLOCK_SIZE SIZE_128KB + +EFI_STATUS +VirtNorFlashPlatformInitialization ( + VOID + ) +{ + return EFI_SUCCESS; +} + +STATIC VIRT_NOR_FLASH_DESCRIPTION mNorFlashDevices; + +EFI_STATUS +VirtNorFlashPlatformGetDevices ( + OUT VIRT_NOR_FLASH_DESCRIPTION **NorFlashDescriptions, + OUT UINT32 *Count + ) +{ + FDT_CLIENT_PROTOCOL *FdtClient; + INT32Node; + EFI_STATUS Status; + EFI_STATUS FindNodeStatus; + CONST UINT32 *Reg; + UINT32 PropSize; + UINT64 Base; + UINT64 Size; + + Status = gBS->LocateProtocol ( + , + NULL, + (VOID **) + ); + ASSERT_EFI_ERROR (Status); + + FindNodeStatus = FdtClient->FindCompatibleNode ( +FdtClient, +"cfi-flash", + +); + ASSERT_EFI_ERROR (FindNodeStatus); + + Status = FdtClient->GetNodeProperty ( +FdtClient, +Node, +"reg", +(CONST VOID **), + +); + if (EFI_ERROR (Status)) { +DEBUG (( + DEBUG_ERROR, + "%a: GetNodeProperty () failed (Status == %r)\n", + __func__, + Status + )); +return Status; + } + + ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0); + + if (PropSize < (4 * sizeof (UINT32))) { +DEBUG (( + DEBUG_ERROR, + "%a: reg node size(%d) is too small \n", + __func__, + PropSize + )); +return EFI_NOT_FOUND; + } + + Base = SwapBytes64 (ReadUnaligned64 ((VOID *)[0])); + Size = SwapBytes64 (ReadUnaligned64 ((VOID *)[2])); + + mNorFlashDevices.DeviceBaseAddress = (UINTN)Base; + mNorFlashDevices.RegionBaseAddress = (UINTN)Base; + mNorFlashDevices.Size = (UINTN)Size; + mNorFlashDevices.BlockSize = QEMU_NOR_BLOCK_SIZE; + + Status = PcdSet32S (PcdFlashNvStorageVariableBase, Base); + ASSERT_EFI_ERROR (Status); + + /* + * Base is the value of PcdFlashNvStorageVariableBase, + * PcdFlashNvStorageFtwWorkingBase can be got by + * PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize + */ + Base += PcdGet32 (PcdFlashNvStorageVariableSize); + Status = PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base); + ASSERT_EFI_ERROR (Status); + + /* + * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase, + * PcdFlashNvStorageFtwSpareBase can be got by + * PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize. + */ + Base += PcdGet32 (PcdFlashNvStorageFtwWorkingSize); + Status = PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base); + ASSERT_EFI_ERROR (Status); + + // + // UEFI takes ownership of the NOR flash, and exposes its functionality + // through the UEFI Runtime Services GetVariable, SetVariable, etc. This + // means we need to disable it in the device tree to prevent the OS from + // attaching its device driver as well. + // Note that this also hides other flash banks, but the only other flash + // bank we expect to encounter is the one that carries the UEFI executable + // code, which is not intended to be guest updatable, and is usually backed + // in a readonly manner by QEMU anyway. + // + Status = FdtClient->SetNodeProperty ( +FdtClient, +Node, +"status", +"disabled", +sizeof ("disabled") +); + if (EFI_ERROR (Status)) { +DEBUG ((DEBUG_WARN, "Failed to set NOR flash status to 'disabled'\n")); + } + + *NorFlashDescriptions = +
Re: [edk2-devel] [PATCH v6 28/36] OvmfPkg/LoongArchVirt: Add the early serial port output library
On 2024/1/5 下午5:45, Chao Li wrote: Add a early serial port output library into LoongArchVirt that named EarlyFdtSerialPortLib16550, this library is referenced from MdeModulePkg. This library is used in the PEI phase. Since the serial port address can not be saved in memory of the LoongArch QEMU virtual machine in the PEI phase, the serial prot base address will be obtained from the FDT before each output. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li --- .../EarlyFdtSerialPortLib16550.c | 815 ++ .../EarlyFdtSerialPortLib16550.inf| 46 + 2 files changed, 861 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/EarlyFdtSerialPortLib16550.c create mode 100644 OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/EarlyFdtSerialPortLib16550.inf diff --git a/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/EarlyFdtSerialPortLib16550.c b/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/EarlyFdtSerialPortLib16550.c new file mode 100644 index 00..8cc108501c --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/EarlyFdtSerialPortLib16550.c @@ -0,0 +1,815 @@ +/** @file + 16550 UART Serial Port library functions + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +// +// PCI Defintions. +// +#define PCI_BRIDGE_32_BIT_IO_SPACE 0x01 + +// +// 16550 UART register offsets and bitfields +// +#define R_UART_RXBUF 0// LCR_DLAB = 0 +#define R_UART_TXBUF 0// LCR_DLAB = 0 +#define R_UART_BAUD_LOW0// LCR_DLAB = 1 +#define R_UART_BAUD_HIGH 1// LCR_DLAB = 1 +#define R_UART_IER 1// LCR_DLAB = 0 +#define R_UART_FCR 2 +#define B_UART_FCR_FIFOE BIT0 +#define B_UART_FCR_FIFO64 BIT5 +#define R_UART_LCR 3 +#define B_UART_LCR_DLABBIT7 +#define R_UART_MCR 4 +#define B_UART_MCR_DTRCBIT0 +#define B_UART_MCR_RTS BIT1 +#define R_UART_LSR 5 +#define B_UART_LSR_RXRDY BIT0 +#define B_UART_LSR_TXRDY BIT5 +#define B_UART_LSR_TEMTBIT6 +#define R_UART_MSR 6 +#define B_UART_MSR_CTS BIT4 +#define B_UART_MSR_DSR BIT5 +#define B_UART_MSR_RI BIT6 +#define B_UART_MSR_DCD BIT7 + +/** + Read an 8-bit 16550 register. If PcdSerialUseMmio is TRUE, then the value is read from + MMIO space. If PcdSerialUseMmio is FALSE, then the value is read from I/O space. The + parameter Offset is added to the base address of the 16550 registers that is specified + by PcdSerialRegisterBase. PcdSerialRegisterAccessWidth specifies the MMIO space access + width and defaults to 8 bit access, and supports 8 or 32 bit access. + + @param BaseThe base address register of UART device. + @param Offset The offset of the 16550 register to read. + + @return The value read from the 16550 register. +**/ +UINT8 +SerialPortReadRegister ( + UINTN Base, + UINTN Offset + ) +{ + if (PcdGetBool (PcdSerialUseMmio)) { +if (PcdGet8 (PcdSerialRegisterAccessWidth) == 32) { + return (UINT8)MmioRead32 (Base + Offset * PcdGet32 (PcdSerialRegisterStride)); +} + +return MmioRead8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride)); + } else { +return IoRead8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride)); + } +} + +/** + Write an 8-bit 16550 register. If PcdSerialUseMmio is TRUE, then the value is written to + MMIO space. If PcdSerialUseMmio is FALSE, then the value is written to I/O space. The + parameter Offset is added to the base address of the 16550 registers that is specified + by PcdSerialRegisterBase. PcdSerialRegisterAccessWidth specifies the MMIO space access + width and defaults to 8 bit access, and supports 8 or 32 bit access. + + @param BaseThe base address register of UART device. + @param Offset The offset of the 16550 register to write. + @param Value The value to write to the 16550 register specified by Offset. + + @return The value written to the 16550 register. +**/ +UINT8 +SerialPortWriteRegister ( + UINTN Base, + UINTN Offset, + UINT8 Value + ) +{ + if (PcdGetBool (PcdSerialUseMmio)) { +if (PcdGet8 (PcdSerialRegisterAccessWidth) == 32) { + return (UINT8)MmioWrite32 (Base + Offset * PcdGet32 (PcdSerialRegisterStride), (UINT8)Value); +} + +return MmioWrite8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride), Value); + } else { +return IoWrite8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride), Value); + } +} + +/** + Retrieve the I/O or MMIO base address register for the PCI UART device. + + This function assumes Root Bus Numer is Zero, and enables I/O and MMIO in
Re: [edk2-devel] [PATCH v6 26/36] OvmfPkg/LoongArchVirt: Add a NULL library named CollectApResouceLibNull
On 2024/1/5 下午5:45, Chao Li wrote: This Library is used to collect APs resources, but is currently NULL for OvmfPkg, because it is not used by the LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li --- .../CollectApResourceLibNull.c| 38 +++ .../CollectApResourceLibNull.inf | 31 +++ .../CollectApResourceLibNull.uni | 9 + 3 files changed, 78 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c new file mode 100644 index 00..19995c1193 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.c @@ -0,0 +1,38 @@ +/** @file + LoongArch64 CPU Collect AP resource NULL Library functions. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include "../../../UefiCpuPkg/Library/LoongArch64MpInitLib/MpLib.h" The included path is a little strange, should we put CollectApResouceLibNull library in ovmf package or UefiCpuPkg/Library/LoongArch64MpInitLib package? Regards Bibo Mao + +VOID +SaveProcessorResourceData ( + IN PROCESSOR_RESOURCE_DATA * + ); + +VOID +EFIAPI +SaveProcessorResource ( + PROCESSOR_RESOURCE_DATA *mProcessorResource + ) +{ + SaveProcessorResourceData (mProcessorResource); +} + +VOID +EFIAPI +CollectAllProcessorResource ( + VOID + ) +{ + return; +} diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf new file mode 100644 index 00..c166df6bbd --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.inf @@ -0,0 +1,31 @@ +## @file +# LoongArch64 CPU Collect AP resource NULL Library. +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION= 1.29 + BASE_NAME = CollectApResourceLibNull + MODULE_UNI_FILE= CollectApResourceLibNull.uni + FILE_GUID = 8C3B54BF-6A9F-E8B4-4D57-67B3AB578DD6 + MODULE_TYPE= PEIM + VERSION_STRING = 1.1 + LIBRARY_CLASS = PEIM + +[Sources.common] + CollectApResourceLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + HobLib + MemoryAllocationLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni new file mode 100644 index 00..d1638ab11e --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResourceLibNull.uni @@ -0,0 +1,9 @@ +// @file +// LoongArch64 CPU Collect AP resource NULL Library. +// +// Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved. +// SPDX-License-Identifier: BSD-2-Clause-Patent + +#string STR_MODULE_ABSTRACT #language en-US "CPU Collect AP resource NULL Library." + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Collect AP resource NULL Library." -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113499): https://edk2.groups.io/g/devel/message/113499 Mute This Topic: https://groups.io/mt/103540125/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v6 33/36] OvmfPkg/LoongArchVirt: Support SEC phase
On 2024/1/5 下午5:46, Chao Li wrote: Add SEC code for LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S | 180 +++ OvmfPkg/LoongArchVirt/Sec/SecMain.c | 507 ++ OvmfPkg/LoongArchVirt/Sec/SecMain.inf | 53 ++ 3 files changed, 740 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S create mode 100644 OvmfPkg/LoongArchVirt/Sec/SecMain.c create mode 100644 OvmfPkg/LoongArchVirt/Sec/SecMain.inf diff --git a/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S b/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S new file mode 100644 index 00..ed099ba0fc --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S @@ -0,0 +1,180 @@ +#-- +# +# Start for Loongson LoongArch processor +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# @par Glossary: +#- CSR - CPU Status Register +#- EBASE - Exception Base Address +#-- +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ +#endif + +#include +#include +#include + +#define BOOTCORE_ID 0 +// +// For coding convenience, define the maximum valid +// LoongArch exception. +// Since UEFI V2.11, it will be present in DebugSupport.h. +// +#define MAX_LOONGARCH_EXCEPTION 64 + +ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) +ASM_PFX(_ModuleEntryPoint): + /* Disable interrupt */ + li.d $t0, (1 << 2) + csrxchg $zero, $t0, LOONGARCH_CSR_CRMD + + /* Read physical cpu number id */ + bl GetApicId + li.d $t0, BOOTCORE_ID //0 + bne $a0, $t0, SlaveMain + + /* Set BSP stack */ + li.d $t0, FixedPcdGet64(PcdOvmfSecPeiTempRamBase) + FixedPcdGet32(PcdOvmfSecPeiTempRamSize) # stack base + move $sp, $t0 + addi.d $sp, $sp, -0x8 + + /* Load the exception vector base address */ + li.d $s0, FixedPcdGet64(PcdCpuExceptionVectorBaseAddress) + + /* Construct SEC and PEI step exception environment */ + la.pcrel $a1, ExceptionEntryStart + la.pcrel $t0, ExceptionEntryEnd + sub.d$a2, $t0, $a1 + li.w $t0, (MAX_LOONGARCH_EXCEPTION + MAX_LOONGARCH_INTERRUPT) * 512 + bgeu $a2, $t0, DeadLoop + move $a0, $s0 + bl CopyMem + + /* Configure BSP reset ebase */ + move $a0, $s0 + bl SetExceptionBaseAddress + +CallEntry: + /* Call C function make sure parameter true */ + li.d $a0, FixedPcdGet64(PcdOvmfFdBaseAddress) # FW base + addi.d $a1, $sp, 0x8 + bl SecCoreStartupWithStack +# End of _ModuleEntryPoint + +ASM_PFX(ClearMailBox): + /* Clear mailbox */ + li.d $t1, LOONGARCH_IOCSR_MBUF3 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF2 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF1 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF0 + iocsrwr.d $zero, $t1 + jirl $zero, $ra, 0 +# End of ClearMailBox + +ASM_PFX(EnableIPI): + /* Enable IPI interrupt */ + li.d $t1, (1 << 12) + csrxchg $t1, $t1, LOONGARCH_CSR_ECFG + + addi.d$t2, $zero, -1 + li.d $t1, LOONGARCH_IOCSR_IPI_EN + iocsrwr.w $t2, $t1 + jirl $zero, $ra, 0 +# End of EeableIPI + +#/** +# Get APIC ID for every CPU. +# +# @param NULL +# @return APICID +# +# UINTN +# EFI_API +# GetApicId ( +# VOID +# ) +#**/ +ASM_PFX(GetApicId): + csrrd $a0, LOONGARCH_CSR_CPUNUM + andi $a0, $a0, 0x3ff + jirl $zero, $ra, 0 +# End of GetApicId + +ASM_PFX(ApInitStack): + li.d $t1, SIZE_1KB + csrrd $t0, LOONGARCH_CSR_TMID + mul.d $t1, $t0, $t1 + li.d $t2, FixedPcdGet32(PcdCpuMaxLogicalProcessorNumber) + bgeu $t0, $t2, DeadLoop + li.d $t0, FixedPcdGet64(PcdOvmfSecPeiTempRamBase) + FixedPcdGet32(PcdOvmfSecPeiTempRamSize) - SIZE_64KB + sub.d $sp, $t0, $t1 + addi.d $sp, $sp, -0x8 + jirl $zero, $ra, 0 +# End of ApInitStack + +ASM_PFX(SlaveMain): + /* Set AP exception handle in flash */ + la.pcrel $a0, ApException + blSetExceptionBaseAddress + + /* Clean up local mail box and open INT */ + blClearMailBox + blEnableIPI + blEnableInterrupts + +WaitForWake: + /* Wait for wakeup */ + blCpuSleep + b WaitForWake +# End of SlaveMain + +.align 12 +ASM_PFX(ApException): + csrrd $t0, LOONGARCH_CSR_ESTAT + srli.d$t0, $t0, 12 + beqz $t0, DeadLoop + + li.d $t0, LOONGARCH_IOCSR_IPI_STATUS + iocsrrd.w $t1, $t0 + li.d $t0, LOONGARCH_IOCSR_IPI_CLEAR + iocsrwr.w $t1, $t0 + + /* Read mail buf and jump to specified entry */ + li.d $t1, LOONGARCH_IOCSR_MBUF0 + iocsrrd.d $t0, $t1 + beqz $t0,
Re: [edk2-devel] [PATCH v5 33/36] OvmfPkg/LoongArchVirt: Support SEC phase
On 2023/12/28 下午6:07, Chao Li wrote: Add SEC code for LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S | 183 +++ OvmfPkg/LoongArchVirt/Sec/SecMain.c | 507 ++ OvmfPkg/LoongArchVirt/Sec/SecMain.inf | 53 ++ 3 files changed, 743 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S create mode 100644 OvmfPkg/LoongArchVirt/Sec/SecMain.c create mode 100644 OvmfPkg/LoongArchVirt/Sec/SecMain.inf diff --git a/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S b/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S new file mode 100644 index 00..145f8ffc59 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S @@ -0,0 +1,183 @@ +#-- +# +# Start for Loongson LoongArch processor +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# @par Glossary: +#- CSR - CPU Status Register +#- EBASE - Exception Base Address +#-- +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ +#endif + +#include +#include +#include + +#define BOOTCORE_ID 0 + +// +// For coding convenience, define the maximum valid +// LoongArch exception. +// Since UEFI V2.11, it will be present in DebugSupport.h. +// +#define MAX_LOONGARCH_EXCEPTION 64 + +ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) +ASM_PFX(_ModuleEntryPoint): + /* Disable interrupt */ + li.d $t0, (1 << 2) + csrxchg $zero, $t0, LOONGARCH_CSR_CRMD + + /* Read physical cpu number id */ + bl GetApicId + li.d $t0, BOOTCORE_ID //0 + bne $a0, $t0, SlaveMain + + /* Configure BSP reset ebase */ + li.d $a0, FixedPcdGet64(PcdCpuExceptionVectorBaseAddress) + bl SetExceptionBaseAddress + move $t1, $a0 what is usage of PcdCpuExceptionVectorBaseAddress about BSP here? Is there actual exception handler in PcdCpuExceptionVectorBaseAddress in sec stage? + + /* Set BSP stack */ + li.d $t0, FixedPcdGet64(PcdOvmfSecPeiTempRamBase) + FixedPcdGet32(PcdOvmfSecPeiTempRamSize) # stack base + move $sp, $t0 + addi.d $sp, $sp, -0x8 + + /* Construct SEC and PEI step exception environment */ + la.pcrel $a1, ExceptionEntryStart + la.pcrel $t0, ExceptionEntryEnd + sub.d$a2, $t0, $a1 + li.w $t0, (MAX_LOONGARCH_EXCEPTION + MAX_LOONGARCH_INTERRUPT) * 512 + bgeu $a2, $t0, DeadLoop + move $a0, $t1 + bl CopyMem + +CallEntry: + /* Call C function make sure parameter true */ + li.d $a0, FixedPcdGet64(PcdOvmfFdBaseAddress) # FW base + addi.d $a1, $sp, 0x8 + bl SecCoreStartupWithStack +# End of _ModuleEntryPoint + +ASM_PFX(ClearMailBox): + /* Clear mailbox */ + li.d $t1, LOONGARCH_IOCSR_MBUF3 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF2 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF1 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF0 + iocsrwr.d $zero, $t1 + jirl $zero, $ra, 0 +# End of ClearMailBox + +ASM_PFX(EnableIPI): + /* Enable IPI interrupt */ + li.d $t1, (1 << 12) + csrxchg $t1, $t1, LOONGARCH_CSR_ECFG + + addi.d$t2, $zero, -1 + li.d $t1, LOONGARCH_IOCSR_IPI_EN + iocsrwr.w $t2, $t1 + jirl $zero, $ra, 0 +# End of EeableIPI + +#/** +# Get APIC ID for every CPU. +# +# @param NULL +# @return APICID +# +# UINTN +# EFI_API +# GetApicId ( +# VOID +# ) +#**/ +ASM_PFX(GetApicId): + csrrd $a0, LOONGARCH_CSR_CPUNUM + andi $a0, $a0, 0x3ff + jirl $zero, $ra, 0 +# End of GetApicId + +ASM_PFX(ApInitStack): + li.d $t1, SIZE_1KB + csrrd $t0, LOONGARCH_CSR_TMID + mul.d $t1, $t0, $t1 + li.d $t2, FixedPcdGet32(PcdCpuMaxLogicalProcessorNumber) + bgeu $t0, $t2, DeadLoop + li.d $t0, FixedPcdGet64(PcdOvmfSecPeiTempRamBase) + FixedPcdGet32(PcdOvmfSecPeiTempRamSize) - SIZE_64KB + sub.d $sp, $t0, $t1 + addi.d $sp, $sp, -0x8 + jirl $zero, $ra, 0 +# End of ApInitStack + +ASM_PFX(SlaveMain): + /* Set AP exception handle in flash */ + la.pcrel $a0, ApException + blSetExceptionBaseAddress + + /* Clean up local mail box and open INT */ + blClearMailBox + blEnableIPI + blEnableInterrupts There will be potential problem if ipi interrupt happens after EnableInterrupts and before CpuSleep. + +WaitForWake: + /* Wait for wakeup */ + blCpuSleep + li.d $t1, LOONGARCH_IOCSR_MBUF0 + iocsrrd.w $t2, $t1 + beqz $t2, WaitForWake + + /* Disable global interrupt */ + blDisableInterrupts + + /* Disable IPI interrupt */ + li.d $t0, (1 << 12) + csrxchg $zero, $t0, LOONGARCH_CSR_ECFG
Re: [edk2-devel] [PATCH v5 32/36] OvmfPkg/LoongArchVirt: Add reset system library
On 2023/12/28 下午6:07, Chao Li wrote: This library provides interface related to restart and shudown the LoongArch64 virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- .../BaseResetSystemAcpiGed.c | 148 ++ .../BaseResetSystemAcpiGedLib.inf | 36 +++ .../DxeResetSystemAcpiGed.c | 259 ++ .../DxeResetSystemAcpiGedLib.inf | 41 +++ .../ResetSystemAcpiLib/ResetSystemAcpiGed.c | 125 + .../ResetSystemAcpiLib/ResetSystemAcpiGed.h | 23 ++ 6 files changed, 632 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGedLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeResetSystemAcpiGed.c create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeResetSystemAcpiGedLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAcpiGed.c create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAcpiGed.h diff --git a/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c new file mode 100644 index 00..9fd1ada9d3 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c @@ -0,0 +1,148 @@ +/** @file + Base ResetSystem library implementation. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include "ResetSystemAcpiGed.h" + +/** + Get configuration item data by the firmware configuration file name. + + @param[in] Name - Name of file to look up. + + @returnVOID* The Pointer of Value of Firmware Configuration item read. +**/ +VOID * +GetFwCfgData ( + CONST CHAR8 *Name + ) +{ + FIRMWARE_CONFIG_ITEM FwCfgItem; + EFI_STATUSStatus; + UINTN FwCfgSize; + VOID *Data; + + Status = QemuFwCfgFindFile (Name, , ); + if (EFI_ERROR (Status)) { +DEBUG ((DEBUG_ERROR, "%a %d read %s error Status %d \n", __func__, __LINE__, Name, Status)); +return NULL; + } + + Data = AllocatePool (FwCfgSize); + if (Data == NULL) { +return NULL; + } + + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (FwCfgSize, Data); + + return Data; +} + +/** + Find the power manager related info from ACPI table + + @retval RETURN_SUCCESS Successfully find out all the required information. + @retval RETURN_NOT_FOUND Failed to find the required info. +**/ +STATIC EFI_STATUS +GetPowerManagerByParseAcpiInfo ( + VOID + ) +{ + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt = NULL; + EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp = NULL; + EFI_ACPI_DESCRIPTION_HEADER *Xsdt = NULL; + EFI_ACPI_DESCRIPTION_HEADER *Rsdt = NULL; + VOID *AcpiTables = NULL; + UINT32*Entry32= NULL; + UINTN Entry32Num; + UINT32*Signature = NULL; + UINTN Idx; + + Rsdp = GetFwCfgData ("etc/acpi/rsdp"); + if (Rsdp == NULL) { +DEBUG ((DEBUG_ERROR, "%a %d read etc/acpi/rsdp error \n", __func__, __LINE__)); +return RETURN_NOT_FOUND; + } + + AcpiTables = GetFwCfgData ("etc/acpi/tables"); + if (AcpiTables == NULL) { +DEBUG ((DEBUG_ERROR, "%a %d read etc/acpi/tables error \n", __func__, __LINE__)); +FreePool (Rsdp); +return RETURN_NOT_FOUND; + } + + Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)AcpiTables + Rsdp->RsdtAddress); + Entry32= (UINT32 *)(Rsdt + 1); + Entry32Num = (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> 2; + for (Idx = 0; Idx < Entry32Num; Idx++) { +Signature = (UINT32 *)((UINTN)Entry32[Idx] + (UINTN)AcpiTables); +if (*Signature == EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) { + Fadt = (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature; + DEBUG ((DEBUG_INFO, "Found Fadt in Rsdt\n")); + goto Done; +} + } + + Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)AcpiTables + Rsdp->XsdtAddress); + Entry32= (UINT32 *)(Xsdt + 1); + Entry32Num = (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> 2; + for (Idx = 0; Idx < Entry32Num; Idx++) { +Signature = (UINT32 *)((UINTN)Entry32[Idx] + (UINTN)AcpiTables); +if (*Signature == EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) { +
Re: [edk2-devel] [PATCH v5 29/36] OvmfPkg/LoongArchVirt: Add real time clock library
On 2023/12/28 下午6:07, Chao Li wrote: This library is provides real time clock for LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Chao Li Co-authored-by: Baoqi Zhang Co-authored-by: Xianglai Li --- .../DxeLsRealTimeClockLib.c | 327 ++ .../DxeLsRealTimeClockLib.inf | 41 +++ .../LsRealTimeClockLib/LsRealTimeClock.h | 47 +++ .../PeiLsRealTimeClockLib.c | 31 ++ .../PeiLsRealTimeClockLib.inf | 29 ++ 5 files changed, 475 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTimeClockLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTimeClockLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/LsRealTimeClock.h create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTimeClockLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTimeClockLib.inf diff --git a/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTimeClockLib.c b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTimeClockLib.c new file mode 100644 index 00..e990728069 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTimeClockLib.c @@ -0,0 +1,327 @@ +/** @file + Implement EFI RealTimeClock runtime services via RTC Lib. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "LsRealTimeClock.h" + +STATIC BOOLEANmInitialized = FALSE; +STATIC EFI_EVENT mRtcVirtualAddrChangeEvent; +STATIC UINTN mRtcBase; + +/* + Enable Real-time clock. + + @param VOID + + @retval VOID + */ +VOID +InitRtc ( + VOID + ) +{ + UINTN Val; + EFI_HOB_GUID_TYPE *GuidHob = NULL; + VOID *DataInHob = NULL; + + if (!mInitialized) { +/* Enable rtc */ +GuidHob = GetFirstGuidHob (); +if (GuidHob) { + DataInHob = GET_GUID_HOB_DATA (GuidHob); + mRtcBase = (UINT64)(*(UINTN *)DataInHob); + Val = MmioRead32 (mRtcBase + RTC_CTRL_REG); + Val |= TOY_ENABLE_BIT | OSC_ENABLE_BIT; + MmioWrite32 (mRtcBase + RTC_CTRL_REG, Val); + mInitialized = TRUE; +} else { + DebugPrint (EFI_D_INFO, "RTC register address not found!\n"); + ASSERT (FALSE); +} + } +} + +/** + Returns the current time and date information, and the time-keeping capabilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapshot of the current time. + @param Capabilities An optional pointer to a buffer to receive the real time clock + device's capabilities. + + @retval EFI_SUCCESSThe operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error. + @retval EFI_SECURITY_VIOLATION The time could not be retrieved due to an authentication failure. +**/ +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + UINT32 Val; + + // Ensure Time is a valid pointer + if (Time == NULL) { +return EFI_INVALID_PARAMETER; + } + + Val= MmioRead32 (mRtcBase + TOY_READ1_REG); + Time->Year = Val + 1900; + + Val = MmioRead32 (mRtcBase + TOY_READ0_REG); + Time->Month = (Val >> TOY_MON_SHIFT) & TOY_MON_MASK; + Time->Day= (Val >> TOY_DAY_SHIFT) & TOY_DAY_MASK; + Time->Hour = (Val >> TOY_HOUR_SHIFT) & TOY_HOUR_MASK; + Time->Minute = (Val >> TOY_MIN_SHIFT) & TOY_MIN_MASK; + Time->Second = (Val >> TOY_SEC_SHIFT) & TOY_SEC_MASK; + Time->Nanosecond = 0; + return EFI_SUCCESS; +} + +/** + Sets the current local time and date information. + + @param Time A pointer to the current time. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error. +**/ +EFI_STATUS +EFIAPI +LibSetTime ( + IN EFI_TIME *Time + ) +{ + UINT32 Val; + + // Initialize the hardware if not already done + + Val = 0; + Val |= (Time->Second << TOY_SEC_SHIFT); + Val |= (Time->Minute << TOY_MIN_SHIFT); + Val |= (Time->Hour << TOY_HOUR_SHIFT); + Val |= (Time->Day<< TOY_DAY_SHIFT); + Val |= (Time->Month << TOY_MON_SHIFT); + MmioWrite32 (mRtcBase + TOY_WRITE0_REG, Val); + + Val = Time->Year - 1900; + MmioWrite32 (mRtcBase + TOY_WRITE1_REG, Val); + return EFI_SUCCESS;
Re: [edk2-devel] [PATCH v5 27/36] OvmfPkg/LoongArchVirt: Add serial port hook library
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 Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Chao Li --- .../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 00..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. + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** 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_SUCCESSSuccess. + @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, ); + 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 00..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. +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. +# +# 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 00..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. + Copyright (c) 2024 Loongson
Re: [edk2-devel] [PATCH v5 34/36] OvmfPkg/LoongArchVirt: Support PEI phase
On 2023/12/28 下午6:07, Chao Li wrote: Platfrom PEI module for LoongArch platfrom initialization. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- OvmfPkg/LoongArchVirt/PlatformPei/Fv.c| 39 ++ OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c | 201 + OvmfPkg/LoongArchVirt/PlatformPei/Platform.c | 393 ++ OvmfPkg/LoongArchVirt/PlatformPei/Platform.h | 146 +++ .../LoongArchVirt/PlatformPei/PlatformPei.inf | 72 5 files changed, 851 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Fv.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Platform.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Platform.h create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c b/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c new file mode 100644 index 00..d46326f135 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c @@ -0,0 +1,39 @@ +/** @file + Build FV related hobs for platform. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include "Platform.h" + +/** + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI + and DXE know about them. + + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. +**/ +EFI_STATUS +PeiFvInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n")); + + // + // Create a memory allocation HOB for the PEI FV. + // + BuildMemoryAllocationHob ( +FixedPcdGet64 (PcdOvmfSecPeiTempRamBase), +FixedPcdGet32 (PcdOvmfSecPeiTempRamSize), +EfiBootServicesData +); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c b/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c new file mode 100644 index 00..9c90413524 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c @@ -0,0 +1,201 @@ +/** @file + Memory Detection for Virtual Machines. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +// The package level header files this module uses +// +#include + +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Platform.h" + +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS (128) +#define LOONGARCH_FW_RAM_TOPBASE_256MB + +/** + Publish PEI core memory + + @return EFI_SUCCESS The PEIM initialized successfully. +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ) +{ + EFI_STATUS Status; + UINT64 Base; + UINT64 Size; + UINT64 RamTop; + + // + // Determine the range of memory to use during PEI + // + Base = FixedPcdGet64 (PcdOvmfSecPeiTempRamBase) + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize); + RamTop = LOONGARCH_FW_RAM_TOP; + Size = RamTop - Base; + + // + // Publish this memory to the PEI Core + // + Status = PublishSystemMemory (Base, Size); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "Publish Memory Initialize done.\n")); + return Status; +} + +/** + Peform Memory Detection + Publish system RAM and reserve memory regions +**/ +VOID +InitializeRamRegions ( + VOID + ) +{ + EFI_STATUSStatus; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + MEMMAP_ENTRY MemoryMapEntry; + MEMMAP_ENTRY *StartEntry; + MEMMAP_ENTRY *pEntry; + UINTN Processed; + + Status = QemuFwCfgFindFile ("etc/memmap", , ); + if (EFI_ERROR (Status)) { +DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __func__, __LINE__, Status)); +return; + } + + if (FwCfgSize % sizeof MemoryMapEntry != 0) { +DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize)); +return; + } + + QemuFwCfgSelectItem (FwCfgItem); + StartEntry = AllocatePages (EFI_SIZE_TO_PAGES (FwCfgSize)); + QemuFwCfgReadBytes (FwCfgSize, StartEntry); + for (Processed = 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); Processed++) { +pEntry = StartEntry + Processed; +if (pEntry->Length == 0) { + continue; +} + +DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p type %d\n", pEntry->BaseAddr, pEntry->Length, pEntry->Type)); +if (pEntry->Type != EfiAcpiAddressRangeMemory) { + continue; +} + +AddMemoryRangeHob (pEntry->BaseAddr, pEntry->BaseAddr + pEntry->Length); + } + + // + // When 0 address protection is enabled, + // 0-4k memory needs to be preallocated to prevent UEFI
Re: [edk2-devel] [PATCH v1 00/29] Enable LoongArch virtual machine in edk2
On 2023/11/3 下午4:09, Chao Li wrote: Hi Bibo, Yes, you are right, MpInitLib is most used on the physical machines, but in LoongArch, this library is a public library, so it is the minimum requirement that it can worke on physical machines and virtual machines. This library has been tested on the actual and virtual machines to ensure it works right. If so, it is ok for me-:) Regards Bibo Mao Thanks, Chao 在 2023/11/3 15:51, maobibo 写道: On 2023/11/3 下午3:08, Chao Li wrote: Hi Ray, Thanks for review. I think the MpInitLib is necessary, because this library will serve PEI and DEX phases. In LoongArch, the MP initialization function will be called first in the PEI phase. It will wake up all of AP, collect accurate online cores, and all APs will fill in their self information to prepare for next wakeup. The second time the MP initialization function is called will in DXE phase, usually located CpuDxe, I guess you are checked this code. This time the MP service HOB will be brought from PEI to DXE phase, and the MP protocal will be registered to prepare for service DXE phase. Like you saied, why not use the MP PPI? I think it's just that the code hasn't been added yet, and I think LoongArch will definitely need the MP PPI in the future, like memory trainning, configure APs local registers, etc. It is necessary for physical machine like memory trainning/configure APs local register etc, however I doubt whether it is useful for LoongArch virt-machine, I do not see the advantages for wakeup APs in UEFI BIOS. ACPI FADT table is prepared in qemu side rather than BIOS side. Regards Bibo Mao Thanks, Chao 在 2023/11/3 13:10, Ni, Ray 写道: Chao, MpInitLib is to avoid code duplication between CpuMpPeim and CpuDxe. If you only need MP protocol but not MP PPI, do you still need to add MpInitLib? Can MpInitLib code be included in CpuDxe folder? Thanks, Ray *From:* Chao Li *Sent:* Friday, November 3, 2023 9:03 AM *To:* devel@edk2.groups.io *Cc:* Kinney, Michael D ; Gao, Liming ; Liu, Zhiguang ; Dong, Eric ; Ni, Ray ; Kumar, Rahul R ; Gerd Hoffmann ; Leif Lindholm ; Ard Biesheuvel ; Abner Chang ; Daniel Schaefer ; Sami Mujawar ; Yao, Jiewen ; Justen, Jordan L *Subject:* [PATCH v1 00/29] Enable LoongArch virtual machine in edk2 This patch set will enable LoongArch virtual machine in edk2, the new LoongArch virtual machine is located in OvmfPkg/LoongArchVirt/, it is a generic platform that dose not require any actual hardware. Patch1-Patch14: Submit the common library and driver for LoongArch virtual machine and real hardware. Such as base help functions, exception handel, MMU library, multiprocessor library etc. Patch15-Patch16: Add PrePiCpuIoSize for LoongArch64. and move ArmVirtPkg two PCDs into OvmfPkg for easier use by other architectures. Patch17-Patch29: LoongArch virtual machine private code, include SEC and PEI phase code, some library and drivers. Modfied modues: MdePkg, UefiCpuPkg, EmbeddedPkg, ArmVirtPkg, OvmfPkg. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Abner Chang Cc: Daniel Schaefer Cc: Sami Mujawar Cc: Jiewen Yao Cc: Jordan Justen Chao Li (29): MdePkg: Add the header file named Csr.h for LoongArch64 MdePkg: Add LoongArch64 FPU function set into BaseCpuLib MdePkg: Add LoongArch64 exception function set into BaseLib MdePkg: Add LoongArch64 local interrupt function set into BaseLib MdePkg: Add LoongArch Cpucfg function MdePkg: Add read stable counter operation for LoongArch MdePkg: Add CSR operation for LoongArch MdePkg: Add IOCSR operation for LoongArch UefiCpuPkg: Add LoongArch64 CPU Timer library UefiCpuPkg: Add CPU exception library for LoongArch UefiCpuPkg: Add CpuMmuLib.h to UefiCpuPkg UefiCpuPkg: Add LoongArch64CpuMmuLib to UefiCpuPkg UefiCpuPkg: Add multiprocessor library for LoongArch64 UefiCpuPkg: Add CpuDxe driver for LoongArch64 EmbeddedPkg: Add PcdPrePiCpuIoSize width for LOONGARCH64 ArmVirtPkg: Move PCD of FDT base address and FDT padding to OvmfPkg OvmfPkg/LoongArchVirt: Add PciCpuIo2Dxe module OvmfPkg/LoongArchVirt: Add stable timer driver OvmfPkg/LoongArchVirt: Add a NULL library named CollectApResouceLibNull OvmfPkg/LoongArchVirt: Add serial port library OvmfPkg/LoongArchVirt: Add real time clock library OvmfPkg/LoongArchVirt: Add NorFlashQemuLib OvmfPkg/LoongArchVirt: Add PeiServiceTablePointerLib OvmfPkg/LoongArchVirt: Add platform boot manager library OvmfPkg/LoongArchVirt: Add FdtQemuFwCfgLib OvmfPkg/LoongArchVirt: Add reset system library OvmfPkg/LoongArchVirt: Support SEC phase OvmfPkg/LoongArchVirt: Support PEI phase OvmfPkg/LoongArchVirt: Add build file ArmVirtPkg/ArmVirtCloudHv.dsc | 2
Re: [edk2-devel] [PATCH v1 00/29] Enable LoongArch virtual machine in edk2
On 2023/11/3 下午3:08, Chao Li wrote: Hi Ray, Thanks for review. I think the MpInitLib is necessary, because this library will serve PEI and DEX phases. In LoongArch, the MP initialization function will be called first in the PEI phase. It will wake up all of AP, collect accurate online cores, and all APs will fill in their self information to prepare for next wakeup. The second time the MP initialization function is called will in DXE phase, usually located CpuDxe, I guess you are checked this code. This time the MP service HOB will be brought from PEI to DXE phase, and the MP protocal will be registered to prepare for service DXE phase. Like you saied, why not use the MP PPI? I think it's just that the code hasn't been added yet, and I think LoongArch will definitely need the MP PPI in the future, like memory trainning, configure APs local registers, etc. It is necessary for physical machine like memory trainning/configure APs local register etc, however I doubt whether it is useful for LoongArch virt-machine, I do not see the advantages for wakeup APs in UEFI BIOS. ACPI FADT table is prepared in qemu side rather than BIOS side. Regards Bibo Mao Thanks, Chao 在 2023/11/3 13:10, Ni, Ray 写道: Chao, MpInitLib is to avoid code duplication between CpuMpPeim and CpuDxe. If you only need MP protocol but not MP PPI, do you still need to add MpInitLib? Can MpInitLib code be included in CpuDxe folder? Thanks, Ray *From:* Chao Li *Sent:* Friday, November 3, 2023 9:03 AM *To:* devel@edk2.groups.io *Cc:* Kinney, Michael D ; Gao, Liming ; Liu, Zhiguang ; Dong, Eric ; Ni, Ray ; Kumar, Rahul R ; Gerd Hoffmann ; Leif Lindholm ; Ard Biesheuvel ; Abner Chang ; Daniel Schaefer ; Sami Mujawar ; Yao, Jiewen ; Justen, Jordan L *Subject:* [PATCH v1 00/29] Enable LoongArch virtual machine in edk2 This patch set will enable LoongArch virtual machine in edk2, the new LoongArch virtual machine is located in OvmfPkg/LoongArchVirt/, it is a generic platform that dose not require any actual hardware. Patch1-Patch14: Submit the common library and driver for LoongArch virtual machine and real hardware. Such as base help functions, exception handel, MMU library, multiprocessor library etc. Patch15-Patch16: Add PrePiCpuIoSize for LoongArch64. and move ArmVirtPkg two PCDs into OvmfPkg for easier use by other architectures. Patch17-Patch29: LoongArch virtual machine private code, include SEC and PEI phase code, some library and drivers. Modfied modues: MdePkg, UefiCpuPkg, EmbeddedPkg, ArmVirtPkg, OvmfPkg. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Abner Chang Cc: Daniel Schaefer Cc: Sami Mujawar Cc: Jiewen Yao Cc: Jordan Justen Chao Li (29): MdePkg: Add the header file named Csr.h for LoongArch64 MdePkg: Add LoongArch64 FPU function set into BaseCpuLib MdePkg: Add LoongArch64 exception function set into BaseLib MdePkg: Add LoongArch64 local interrupt function set into BaseLib MdePkg: Add LoongArch Cpucfg function MdePkg: Add read stable counter operation for LoongArch MdePkg: Add CSR operation for LoongArch MdePkg: Add IOCSR operation for LoongArch UefiCpuPkg: Add LoongArch64 CPU Timer library UefiCpuPkg: Add CPU exception library for LoongArch UefiCpuPkg: Add CpuMmuLib.h to UefiCpuPkg UefiCpuPkg: Add LoongArch64CpuMmuLib to UefiCpuPkg UefiCpuPkg: Add multiprocessor library for LoongArch64 UefiCpuPkg: Add CpuDxe driver for LoongArch64 EmbeddedPkg: Add PcdPrePiCpuIoSize width for LOONGARCH64 ArmVirtPkg: Move PCD of FDT base address and FDT padding to OvmfPkg OvmfPkg/LoongArchVirt: Add PciCpuIo2Dxe module OvmfPkg/LoongArchVirt: Add stable timer driver OvmfPkg/LoongArchVirt: Add a NULL library named CollectApResouceLibNull OvmfPkg/LoongArchVirt: Add serial port library OvmfPkg/LoongArchVirt: Add real time clock library OvmfPkg/LoongArchVirt: Add NorFlashQemuLib OvmfPkg/LoongArchVirt: Add PeiServiceTablePointerLib OvmfPkg/LoongArchVirt: Add platform boot manager library OvmfPkg/LoongArchVirt: Add FdtQemuFwCfgLib OvmfPkg/LoongArchVirt: Add reset system library OvmfPkg/LoongArchVirt: Support SEC phase OvmfPkg/LoongArchVirt: Support PEI phase OvmfPkg/LoongArchVirt: Add build file ArmVirtPkg/ArmVirtCloudHv.dsc | 2 +- ArmVirtPkg/ArmVirtKvmTool.dsc | 2 +- ArmVirtPkg/ArmVirtPkg.dec | 14 - ArmVirtPkg/ArmVirtQemu.dsc | 2 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- ArmVirtPkg/ArmVirtXen.dsc | 2 +- .../ArmVirtPsciResetSystemPeiLib.inf | 3 +- .../CloudHvVirtMemInfoPeiLib.inf | 3 +- .../DebugLibFdtPL011UartFlash.inf | 3 +-
Re: [edk2-devel] [edk2-platforms] Platform/Loongson: Set common page size to 16k
在 2023/5/11 09:33, xianglai li 写道: > Default page size is 16K for loongarch qemu tcg code section > separated with data section with 16K page alignment, > And data write operation in the same page with code section > will cause qemu TB flush. Xianglai, Could you add more data supporting? such as size of dxe ffs image and dxe compaction ffs. Regards Bibo, Mao > > Cc: Ard Biesheuvel > Cc: Bibo Mao > Cc: Chao Li > Cc: Leif Lindholm > Cc: Liming Gao > Cc: Michael D Kinney > Signed-off-by: xianglai li > --- > Platform/Loongson/LoongArchQemuPkg/Loongson.dsc | 7 ++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc > b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc > index 6875e39cc6..13b27d84b8 100644 > --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc > +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc > @@ -61,8 +61,13 @@ > [BuildOptions.LOONGARCH64.EDKII.SEC] >*_*_*_CC_FLAGS = > > +# > +# default page size is 16K for loongarch qemu tcg > +# code section separated with data section with 16K page alignment, else data > +# write operation in the same page with code section will cause qemu TB flush > +# > > [BuildOptions.common.EDKII.DXE_CORE,BuildOptions.common.EDKII.DXE_DRIVER,BuildOptions.common.EDKII.UEFI_DRIVER,BuildOptions.common.EDKII.UEFI_APPLICATION] > - GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000 > + GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x4000 > > [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] >GCC:*_*_LOONGARCH64_DLINK_FLAGS = -z common-page-size=0x1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104648): https://edk2.groups.io/g/devel/message/104648 Mute This Topic: https://groups.io/mt/98819415/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] On integrating LoongArch EDK2 firmware into QEMU build process
Cc to Chao Li who is maintainer of edk2 about LoongArch support. Hi Chao, Fedora38 is used to build edk2 binary in qemu CI, cross gcc-12 is integrated on Fedora38. There is one issue when gcc-12 is used to build edk2 loongarch like this: > ... but when trying to use them to compile the loongarch firmware gcc > throws errors: > > loongarch64-linux-gnu-gcc: error: unrecognized command-line option > ‘-mno-explicit-reloc what is your option about this issue? Regards Bibo, Mao 在 2023/4/1 13:11, maobibo 写道: > > > On 2023/3/31 20:12, Gerd Hoffmann wrote: >> On Fri, Mar 31, 2023 at 08:54:16AM +0800, maobibo wrote: >>> Xuerui, >>> >>> Thanks for your mail, it is a good suggestion. Now we are planing to >>> move LoongArch uefi bios from edk2-platform to edk2 repo, so that uefi >>> bios supporting LoongArch can be auto compiled and uploaded to qemu >>> repo. Only that process is somwhat slow since lacking of hands, >>> however we are doing this. >> >> Good, so I think it makes sense for qemu to just wait for that to >> happen. >> >> Related question: What are the requirements to build the firmware? >> Fedora 38 ships cross compiler packages ... >> >> binutils-loongarch64-linux-gnu-2.39-3.fc38.x86_64 >> gcc-loongarch64-linux-gnu-12.2.1-5.fc38.x86_64 >> >> ... but when trying to use them to compile the loongarch firmware gcc >> throws errors: >> >> loongarch64-linux-gnu-gcc: error: unrecognized command-line option >> ‘-mno-explicit-relocs’ >> >> I suspect gcc-12 is just too old? > There is a little different about relocation between gcc-12 and gcc-13 on > LoongArch, gcc-13 is required for edk2 compiler now. > > However I think it is actually is one issue if gcc-12 can not be used and > gcc-12 is popular latest compiler for all architectures. We will solve this > problem. > > Regards > Bibo, Mao > > >> >> take care, >> Gerd >> > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#102377): https://edk2.groups.io/g/devel/message/102377 Mute This Topic: https://groups.io/mt/98030924/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [edk2-platforms][PATCH V1 4/4] Platform/Loongson: Fixed the bug during page table creation.
在 2023/1/4 11:10, xianglai li 写道: > 1.Open the NULL pointer protection policy. > 2.Fixed the bug of converting huge page to page entry. > 3.Adjust the access level of page entry. > 4.Optimize the existence of page entry judgment functions. Can we split the patch into 4 small patches? All the fixes are mixed together is hard to review :) regards bibo,mao > > Cc: Ard Biesheuvel > Cc: Bibo Mao > Cc: Chao Li > Cc: Leif Lindholm > Cc: Liming Gao > Cc: Michael D Kinney > Signed-off-by: xianglai li > --- > .../Library/MmuLib/MmuLibCore.c | 123 +- > .../Library/MmuLib/MmuLibCorePei.c| 1 + > .../LoongArchQemuPkg/Library/MmuLib/page.h| 5 +- > .../Loongson/LoongArchQemuPkg/Loongson.dsc| 2 + > 4 files changed, 99 insertions(+), 32 deletions(-) > > diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuLibCore.c > b/Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuLibCore.c > index b932e3d568..42f92745be 100644 > --- a/Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuLibCore.c > +++ b/Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuLibCore.c > @@ -449,6 +449,29 @@ GetPteAddress ( >return PteOffset (Pmd, Address); > } > > +/** > + Gets the Attributes of Huge Page. > + > + @param Pmd A pointer to the page middle directory. > + > + @retval Value of Attributes. > +**/ > +UINTN > +GetHugePageAttributes ( > + IN PMD *Pmd > + ) > +{ > + UINTN Attributes; > + UINTN GlobalFlag; > + UINTN HugeVal = PMD_VAL(*Pmd); > + > + Attributes = HugeVal & (~HUGEP_PAGE_MASK); > + GlobalFlag = ((Attributes & (1 << PAGE_HGLOBAL_SHIFT)) >> > PAGE_HGLOBAL_SHIFT) << PAGE_GLOBAL_SHIFT; > + Attributes &= ~(1 << PAGE_HGLOBAL_SHIFT); > + Attributes |= GlobalFlag; > + return Attributes; > +} > + > /** >Establishes a page table entry based on the specified memory region. > > @@ -477,13 +500,13 @@ MemoryMapPteRange ( > return EFI_OUT_OF_RESOURCES; >} > > + DEBUG ((DEBUG_VERBOSE, > +"%a %d Address %p End %p Attributes %llx\n", > +__func__, __LINE__, Address, End, Attributes)); > + >do { > UpDate = FALSE; > PteVal = MAKE_PTE (Address, Attributes); > -DEBUG ((DEBUG_VERBOSE, > - "%a %d Address %p PGD_INDEX %p PUD_INDEX %p PMD_INDEX %p PTE_INDEX > %p MAKE_PTE %p\n", > - __func__, __LINE__, Address, PGD_INDEX (Address), PUD_INDEX > (Address), PMD_INDEX (Address), > - PTE_INDEX (Address), PteVal)); > > if ((!pte_none (*Pte)) && > (PTE_VAL(*Pte) != PTE_VAL(PteVal))) > @@ -500,6 +523,61 @@ MemoryMapPteRange ( >return EFI_SUCCESS; > } > > +/** > + Convert Huge Page to Page. > + > + @param Pmd A pointer to the page middle directory. > + @param Address The memory space start address. > + @param End The end address of the memory space. > + @param Attributes Memory space Attributes. > + > + @retval EFI_SUCCESS The page table entry was created successfully. > + @retval EFI_OUT_OF_RESOURCES Page table entry establishment failed due > to resource exhaustion. > +**/ > +EFI_STATUS > +ConvertHugePageToPage ( > + IN PMD *Pmd, > + IN UINTN Address, > + IN UINTN End, > + IN UINTN Attributes > + ) > +{ > + UINTN OldAttributes; > + UINTN AddressEnd_HugePage; > + UINTN AddressStart_HugePage; > + EFI_STATUS Status; > + > + if ((pmd_none (*Pmd)) || > + ((!pmd_none (*Pmd)) && > + (!IS_HUGE_PAGE (Pmd->PmdVal > + { > +Status |= MemoryMapPteRange (Pmd, Address, End, Attributes); > + } else { > +OldAttributes = GetHugePageAttributes(Pmd); > +SetPmd (Pmd, (PTE *)PcdGet64 (PcdInvalidPte)); > +AddressStart_HugePage = Address & PMD_MASK; > +AddressEnd_HugePage = AddressStart_HugePage + HUGE_PAGE_SIZE; > +if (End >= AddressEnd_HugePage) { > + if (Address > AddressStart_HugePage) { > +Status |= MemoryMapPteRange (Pmd, AddressStart_HugePage, Address, > OldAttributes); > +Status |= MemoryMapPteRange (Pmd, Address, AddressEnd_HugePage, > Attributes); > + } else { > +Status |= MemoryMapPteRange (Pmd, AddressStart_HugePage, > AddressEnd_HugePage, Attributes); > + } > +} else { > + if (Address > AddressStart_HugePage) { > +Status |= MemoryMapPteRange (Pmd, AddressStart_HugePage, Address, > OldAttributes); > +Status |= MemoryMapPteRange (Pmd, Address, End, Attributes); > + } else { > +Status |= MemoryMapPteRange (Pmd, AddressStart_HugePage, End, > Attributes); > + } > + Status |= MemoryMapPteRange (Pmd, End, AddressEnd_HugePage, > OldAttributes); > +} > + } > + > + return Status; > +} > + > /** >Establishes a page middle directory based on the specified memory region. > > @@ -520,10 +598,7 @@ MemoryMapPmdRange ( >) > { >PMD *Pmd; > - PTE *Pte; >UINTN Next; > - UINTN AddressStart_HugePage; > - UINTN AddressEnd_HugePage; > >Pmd = PmdAllocGet (Pud, Address); >if (!Pmd) { > @@
Re: [edk2-devel] [edk2-platforms][PATCH V1 3/4] Platform/Loongson: Support pflash for loongarch.
在 2023/1/4 11:10, xianglai li 写道: > Add pflash driver for loongarch. > > Cc: Ard Biesheuvel > Cc: Bibo Mao > Cc: Chao Li > Cc: Leif Lindholm > Cc: Liming Gao > Cc: Michael D Kinney > Signed-off-by: xianglai li > --- > .../Library/NorFlashQemuLib/NorFlashQemuLib.c | 138 ++ > .../NorFlashQemuLib/NorFlashQemuLib.inf | 43 ++ > .../Loongson/LoongArchQemuPkg/Loongson.dsc| 19 ++- > .../Loongson/LoongArchQemuPkg/Loongson.fdf| 4 +- > .../LoongArchQemuPkg/VarStore.fdf.inc | 67 + > 5 files changed, 260 insertions(+), 11 deletions(-) > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf > create mode 100644 Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc > > diff --git > a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > > b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > new file mode 100644 > index 00..2565e5ae70 > --- /dev/null > +++ > b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > @@ -0,0 +1,138 @@ > +/** @file > + > + Copyright (c) 2023 Loongson Technology Corporation Limited. All rights > reserved. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > + > +#include > +#include > +#include > +#include > + > +#include > + > +#define QEMU_NOR_BLOCK_SIZE SIZE_128KB > + > +#define MAX_FLASH_BANKS 1 > + > +EFI_STATUS > +VirtNorFlashPlatformInitialization ( > + VOID > + ) > +{ > + return EFI_SUCCESS; > +} > + > +STATIC VIRT_NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS]; > + > +EFI_STATUS > +VirtNorFlashPlatformGetDevices ( > + OUT VIRT_NOR_FLASH_DESCRIPTION **NorFlashDescriptions, > + OUT UINT32 *Count > + ) > +{ > + FDT_CLIENT_PROTOCOL *FdtClient; > + INT32Node; > + EFI_STATUS Status; > + EFI_STATUS FindNodeStatus; > + CONST UINT32 *Reg; > + UINT32 PropSize; > + UINT32 Num; > + UINT64 Base; > + UINT64 Size; > + > + Status = gBS->LocateProtocol ( > + , > + NULL, > + (VOID **) > + ); > + ASSERT_EFI_ERROR (Status); > + > + Num = 0; > + for (FindNodeStatus = FdtClient->FindCompatibleNode ( > + FdtClient, > + "cfi-flash", > + > + ); > + !EFI_ERROR (FindNodeStatus) && Num < MAX_FLASH_BANKS; > + FindNodeStatus = FdtClient->FindNextCompatibleNode ( > + FdtClient, > + "cfi-flash", > + Node, > + > + )) > + { > +Status = FdtClient->GetNodeProperty ( > + FdtClient, > + Node, > + "reg", > + (CONST VOID **), > + > + ); > +if (EFI_ERROR (Status)) { > + DEBUG (( > +DEBUG_ERROR, > +"%a: GetNodeProperty () failed (Status == %r)\n", > +__FUNCTION__, > +Status > +)); > + continue; > +} > + > +ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0); > + > +while (PropSize >= (4 * sizeof (UINT32)) && Num < MAX_FLASH_BANKS) { > + Base = SwapBytes64 (ReadUnaligned64 ((VOID *)[0])); > + Size = SwapBytes64 (ReadUnaligned64 ((VOID *)[2])); > + Reg += 4; > + > + PropSize -= 4 * sizeof (UINT32); > + > + mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base; > + mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base; > + mNorFlashDevices[Num].Size = (UINTN)Size; > + mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE; > + Num++; > +} Why is there while-loop? There is only one emulated plash device instead, and variable Base will be overwritten during the loop. > + > + Status = PcdSet32S (PcdFlashNvStorageVariableBase, Base); > + ASSERT_EFI_ERROR (Status); > + Can you add some notation as bellowing? /* * Base is the value of PcdFlashNvStorageVariableBase, * PcdFlashNvStorageFtwWorkingBase can be got by * PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize */ > + Base += PcdGet32 (PcdFlashNvStorageVariableSize); > + Status = PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base); > + ASSERT_EFI_ERROR (Status); > + ditto > + Base += PcdGet32 (PcdFlashNvStorageFtwWorkingSize); > + Status = PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base); > + ASSERT_EFI_ERROR (Status); > + > +// > +// UEFI takes ownership of the NOR flash, and exposes
Re: [edk2-devel] [edk2-platforms][PATCH V5 00/15] Platform: Add Loongson support.
Ping for reviewing, Any comments is welcome. >From edk2 mailing list, Soft Feature Freeze start on 2022-11-07 for >edk2-stable202211, is edk2-platform is affected also? And there are series of submition for Riscv ovmf supports recently, we will adopt the new multi-arch schemes on Loongarch virt machine also after both Riscv virt machine and Loongarch virt machine code are merged. Is that ok? regards bibo, mao 在 2022/11/11 17:12, xianglai li 写道: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4054 > > The uploaded code generates firmware to support Linux launching on the > LoongArch platform under qemu, > So it will run in a virtual machine. > > LoongArch is the general processor architecture of Loongson. > You can get the latest LoongArch documents or LoongArch tools at > https://github.com/loongson/. > > You can also view the code through the Loongson community. > The edk2 code in Loongson community: > https://github.com/loongson/edk2/tree/LoongArch > The edk2-platform code in Loonson community: > https://github.com/loongson/edk2-platforms > The qemu code in Loongson community: > https://gitlab.com/qemu-project/qemu.git > The LoongArch Documentation in Loongson community: > https://github.com/loongson/LoongArch-Documentation/tree/main/docs > The all patches at: > https://github.com/loongson/edk2-platforms/tree/devel-LoongArch-patch > > v2 changes: > - Remove the inline assembly from StableTimerLib. > - troubleshoot TAB strings, convert TAB characters to spaces. > - remove smm related code, loongarch has no smm mode. > > v3 changes: > - delete ExtractHandler related code. > - Boot UEFI with low 256M memory. > - Modify common interrupt handling. > > v4 changes: > - Remove qemu flash related code. > - Modify fdt base address. > > v5 changes: > - Add Udf driver support. > - Split readme file into a separate patch. > - Modify the code style >- delete extra blank lines >- use the assembly function definition macros in MdePkg >- sort out the PCD variable Token value. > > Cc: Bibo Mao > Cc: Chao Li > Cc: Leif Lindholm > Cc: Liming Gao > Cc: Michael D Kinney > > xianglai li (15): > Platform/Loongson: Add Serial Port library > Platform/Loongson: Support SEC > Platform/Loongson: Add PeiServicesTablePointerLib. > Platform/Loongson: Add QemuFwCfgLib. > Platform/Loongson: Add MmuLib. > Platform/Loongson: Add StableTimerLib. > Platform/Loongson: Support PEI phase. > Platform/Loongson: Add CPU DXE driver. > Platform/Loongson: Add PciCpuIoDxe driver. > Platform/Loongson: Add timer Dxe driver. > Platform/Loongson: Add RealTime Clock lib. > Platform/Loongson: Add Platform Boot Manager Lib. > Platform/Loongson: Add Reset System Lib. > Platform/Loongson: Support Dxe > Platform/Loongson: Add Readme. > > .../LoongArchQemuPkg/Drivers/CpuDxe/CpuDxe.c | 367 > .../LoongArchQemuPkg/Drivers/CpuDxe/CpuDxe.h | 199 + > .../Drivers/CpuDxe/CpuDxe.inf | 59 ++ > .../Drivers/CpuDxe/LoongArch64/Exception.c| 335 +++ > .../Drivers/CpuDxe/LoongArch64/Fpu.S | 97 ++ > .../Drivers/CpuDxe/LoongArch64/LoongArch.S| 321 +++ > .../Drivers/PciCpuIo2Dxe/PciCpuIo2Dxe.c | 538 > .../Drivers/PciCpuIo2Dxe/PciCpuIo2Dxe.h | 207 + > .../Drivers/PciCpuIo2Dxe/PciCpuIo2Dxe.inf | 44 + > .../Drivers/StableTimerDxe/Timer.c| 388 > .../Drivers/StableTimerDxe/Timer.h| 172 > .../Drivers/StableTimerDxe/TimerConfig.S | 38 + > .../Drivers/StableTimerDxe/TimerDxe.inf | 44 + > .../LoongArchQemuPkg/Include/Library/Cpu.h| 237 + > .../LoongArchQemuPkg/Include/Library/MmuLib.h | 85 ++ > .../Include/Library/QemuFwCfgLib.h| 174 > .../Include/Library/StableTimer.h | 59 ++ > .../Include/LoongArchQemuPlatform.h | 95 ++ > .../LsRealTimeClockLib/LsRealTimeClock.h | 40 + > .../LsRealTimeClockLib/LsRealTimeClockLib.c | 335 +++ > .../LsRealTimeClockLib/LsRealTimeClockLib.inf | 44 + > .../LoongArchQemuPkg/Library/MmuLib/Mmu.S | 155 > .../Library/MmuLib/MmuBaseLib.inf | 40 + > .../Library/MmuLib/MmuBaseLibPei.inf | 47 + > .../Library/MmuLib/MmuLibCore.c | 831 ++ > .../Library/MmuLib/MmuLibCore.h | 40 + > .../Library/MmuLib/MmuLibCorePei.c| 231 + > .../LoongArchQemuPkg/Library/MmuLib/mmu.h | 190 > .../LoongArchQemuPkg/Library/MmuLib/page.h| 280 ++ > .../LoongArchQemuPkg/Library/MmuLib/pte.h | 57 ++ > .../PeiServicesTablePointer.c | 79 ++ > .../PeiServicesTablePointer.h | 39 + > .../PeiServicesTablePointerLib.S | 40 + > .../PeiServicesTablePointerLib.inf| 32 + > .../PlatformBootManagerLib/PlatformBm.c | 742 > .../PlatformBootManagerLib/PlatformBm.h | 112 +++ >
Re: [edk2-devel] [edk2-platforms][PATCH V4 05/14] Platform/Loongson: Add MmuLib.
在 2022/10/21 15:11, xianglai li 写道: > Read the memory map information through the QemuFwCfg interface, > then build the page table through the memory map information, > and finally enable Mmu. > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4054 > > Signed-off-by: xianglai li > --- > .../LoongArchQemuPkg/Include/Library/MmuLib.h | 85 ++ > .../LoongArchQemuPkg/Library/MmuLib/Mmu.S | 35 + > .../Library/MmuLib/MmuBaseLib.inf | 35 + > .../Library/MmuLib/MmuBaseLibPei.inf | 42 + > .../Library/MmuLib/MmuLibCore.c | 908 ++ > .../Library/MmuLib/MmuLibCore.h | 39 + > .../Library/MmuLib/MmuLibCorePei.c| 236 + > .../LoongArchQemuPkg/Library/MmuLib/mmu.h | 104 ++ > .../LoongArchQemuPkg/Library/MmuLib/page.h| 267 + > .../LoongArchQemuPkg/Library/MmuLib/pte.h | 57 ++ > 10 files changed, 1808 insertions(+) > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Include/Library/MmuLib.h > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/Mmu.S > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuBaseLib.inf > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuBaseLibPei.inf > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuLibCore.c > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuLibCore.h > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/MmuLibCorePei.c > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/mmu.h > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/page.h > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/pte.h > > diff --git a/Platform/Loongson/LoongArchQemuPkg/Include/Library/MmuLib.h > b/Platform/Loongson/LoongArchQemuPkg/Include/Library/MmuLib.h > new file mode 100644 > index 00..6c501eca07 > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Include/Library/MmuLib.h > @@ -0,0 +1,85 @@ > +/** @file > + > + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights > reserved. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + @par Glossary: > +- EXC - execute > +**/ > +#ifndef MMU_LIB_H_ > +#define MMU_LIB_H_ > +/** > + write operation is performed Count times from the first element of Buffer. > +Convert EFI Attributes to Loongarch Attributes. > + @param[in] EfiAttributes Efi Attributes. > + > + @retval LoongArch Attributes. > +**/ > +UINTN > +EfiAttributeToLoongArchAttribute ( > + IN UINTN EfiAttributes > + ); > + > +/** > + Finds the length and memory properties of the memory region corresponding > to the specified base address. > + > + @param[in] BaseAddressTo find the base address of the memory region. > + @param[in] EndAddress To find the end address of the memory region. > + @param[out] RegionLengthThe length of the memory region found. > + @param[out] RegionAttributesProperties of the memory region found. > + > + @retval EFI_SUCCESSThe corresponding memory area was successfully > found > + EFI_NOT_FOUNDNo memory area found > +**/ > +EFI_STATUS > +GetLoongArchMemoryRegion ( > + IN UINTN BaseAddress, > + IN UINTN EndAddress, > + OUTUINTN *RegionLength, > + OUTUINTN *RegionAttributes > + ); > + > +/** > + Sets the Attributes of the specified memory region > + > + @param[in] BaseAddress The base address of the memory region to set the > Attributes. > + @param[in] Length The length of the memory region to set the > Attributes. > + @param[in] Attributes The Attributes to be set. > + > + @retval EFI_SUCCESSThe Attributes was set successfully > + > +**/ > +EFI_STATUS > +LoongArchSetMemoryAttributes ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINTN Length, > + IN UINTN Attributes > + ); > + > +/** > + Sets the non-executable Attributes for the specified memory region > + > + @param[in] BaseAddress The base address of the memory region to set the > Attributes. > + @param[in] Length The length of the memory region to set the > Attributes. > + > + @retval EFI_SUCCESSThe Attributes was set successfully > +**/ > +EFI_STATUS > +LoongArchSetMemoryRegionNoExec ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINTNLength > + ); > +/** > + Create a page table and initialize the MMU. > + > + @param[] VOID > + > + @retval VOID > +**/ > +VOID > +EFIAPI > +ConfigureMmu ( > + VOID > + ); > +#endif > diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/Mmu.S > b/Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/Mmu.S > new file mode 100644 > index 00..a697b54e65 > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Library/MmuLib/Mmu.S > @@ -0,0 +1,35 @@ >
Re: [edk2-devel] [edk2-platforms][PATCH V4 01/14] Platform/Loongson: Add Serial Port library
Hi xianglai, I reply inline. 在 2022/10/21 15:11, xianglai li 写道: > Serial Port library for LoongarchQemuPkg > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4054 > > Signed-off-by: xianglai li > --- > .../LoongArchQemuPkg/Include/Library/Cpu.h| 387 +++ > .../Include/LoongArchQemuPlatform.h | 97 +++ > .../Library/SerialPortLib/SerialPortLib.c | 612 ++ > .../Library/SerialPortLib/SerialPortLib.inf | 36 ++ > 4 files changed, 1132 insertions(+) > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Include/Library/Cpu.h > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib/SerialPortLib.c > create mode 100644 > Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib/SerialPortLib.inf > > diff --git a/Platform/Loongson/LoongArchQemuPkg/Include/Library/Cpu.h > b/Platform/Loongson/LoongArchQemuPkg/Include/Library/Cpu.h > new file mode 100644 > index 00..8c3c21bd96 > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Include/Library/Cpu.h > @@ -0,0 +1,387 @@ > +/** @file > + > + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights > reserved. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + @par Glossary: > +- EXC - Exception > +- INT - Interrupt > +- FPU - Floating Point Unit > +- CSR - CPU Status Register > +- READQ - Read Quad Word > +**/ > +#ifndef LOONGARCH_CPU_H_ > +#define LOONGARCH_CPU_H_ > + > +/* Exception types decoded by machdep exception decoder */ > +#define EXC_INT 0 /* HW interrupt */ > +#define EXC_TLBL1 /* TLB miss on a load */ > +#define EXC_TLBS2 /* TLB miss on a store */ > +#define EXC_TLBI3 /* TLB miss on a ifetch */ > +#define EXC_TLBM4 /* TLB modified fault */ > +#define EXC_TLBRI 5 /* TLB Read-Inhibit exception */ > +#define EXC_TLBXI 6 /* TLB Execution-Inhibit > exception */ > +#define EXC_TLBPE 7 /* TLB Privilege Error */ > +#define EXC_ADE 8 /* Address Error */ > +#define EXC_ALE 9 /* Unalign Access */ > +#define EXC_OOB 10 /* Out of bounds */ > +#define EXC_SYS 11 /* System call */ > +#define EXC_BP 12 /* Breakpoint */ > +#define EXC_INE 13 /* Inst. Not Exist */ > +#define EXC_IPE 14 /* Inst. Privileged Error */ > +#define EXC_FPDIS 15 /* FPU Disabled */ > +#define EXC_LSXDIS 16 /* LSX Disabled */ > +#define EXC_LASXDIS 17 /* LASX Disabled */ > +#define EXC_FPE 18 /* Floating Point Exception */ > +#define EXC_WATCH 19 /* Watch address reference */ > +#define EXC_BAD 255 /* Undecodeable */ > + > +#define COPY_SIGCODE// copy sigcode above user stack in exec > +#define ZERO$r0 /* wired zero */ > +#define RA $r1 /* return address */ > +#define GP $r2 /* global pointer - caller saved for > PIC */ > +#define SP $r3 /* stack pointer */ > +#define V0 $r4 /* return value - caller saved */ > +#define V1 $r5 > +#define A0 $r4 /* argument registers */ > +#define A1 $r5 > +#define A2 $r6 > +#define A3 $r7 > +#define A4 $r8 /* arg reg 64 bit; caller saved in > 32 bit */ > +#define A5 $r9 > +#define A6 $r10 > +#define A7 $r11 > +#define T0 $r12 /* caller saved */ > +#define T1 $r13 > +#define T2 $r14 > +#define T3 $r15 > +#define T4 $r16 /* callee saved */ > +#define T5 $r17 > +#define T6 $r18 > +#define T7 $r19 > +#define T8 $r20 /* caller saved */ > +#define TP $r21 /* TLS */ > +#define FP $r22 /* frame pointer */ > +#define S0 $r23 /* callee saved */ > +#define S1 $r24 > +#define S2 $r25 > +#define S3 $r26 > +#define S4 $r27 > +#define S5 $r28 > +#define S6 $r29 > +#define S7 $r30 > +#define S8
Re: [edk2-devel] Confirm your bibo_...@163.com email address
On 11/26/2021 10:24 AM, Groups.io Notification wrote: > Hello, > > Thank you for your interest in the https://edk2.groups.io/g/devel group at > Groups.io. If you did not request or do not want to join > devel@edk2.groups.io, please ignore this message. > > If you only want to send and receive messages from devel@edk2.groups.io, > reply to this email to confirm your email address and activate your > membership. > > * Messages will be sent to you at bibo_...@163.com > * Send messages to devel@edk2.groups.io > > If you want to use the resources and read messages on the website, please > click on the link below to confirm your email address, set up a password, and > choose other subscription settings: > > Confirm account ( > https://groups.io/confirm?email=bibo_mao%40163.com=651175686279419 > ) > > Cheers, > The Groups.io Team > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84118): https://edk2.groups.io/g/devel/message/84118 Mute This Topic: https://groups.io/mt/87342734/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] one possible issue with ovmf fvb
On 11/25/2021 06:38 PM, Gerd Hoffmann wrote: > Hi, > >> PcdStatus = PcdSet64S (PcdFlashNvStorageVariableBase64, (UINT32)(UINTN) >> Ptr); >> ASSERT_RETURN_ERROR (PcdStatus); > > I guess you are referring to that UINT32 cast? > Not sure why it is there. I think you can just drop it. Yes, it is. There will be problem if the loongarch bios uses ovmf fvb dxe and there is only one flat memory hob. UEFI bios memory may be allocated with 64bit address, so there will be problem. I will submit one patch to fix this in order to use these common code. regards bibo, mao > >> Can uefi bios manage memory beyond 4G? > > The X64 builds can do that just fine, although they usually store > everything below 4G, so issues like the one above go unnoticed. > > HTH, > Gerd > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84117): https://edk2.groups.io/g/devel/message/84117 Mute This Topic: https://groups.io/mt/87299942/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] one possible issue with ovmf fvb
Hi Gerd, I am porting Loongarch Qemu uefi bios, and I want to use reuse ovmf code. And I encounter one problem when using OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c here is piece of code: --- Initialize = TRUE; if (PcdGet64 (PcdEmuVariableNvStoreReserved) != 0) { Ptr = (VOID*)(UINTN) PcdGet64 (PcdEmuVariableNvStoreReserved); DEBUG (( DEBUG_INFO, "EMU Variable FVB: Using pre-reserved block at %p\n", Ptr )); Status = ValidateFvHeader (Ptr); if (!EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "EMU Variable FVB: Found valid pre-existing FV\n")); Initialize = FALSE; } } else { Ptr = AllocateRuntimePages (EFI_SIZE_TO_PAGES (EMU_FVB_SIZE)); } mEmuVarsFvb.BufferPtr = Ptr; // // Initialize the main FV header and variable store header // if (Initialize) { SetMem (Ptr, EMU_FVB_SIZE, ERASED_UINT8); InitializeFvAndVariableStoreHeaders (Ptr); } PcdStatus = PcdSet64S (PcdFlashNvStorageVariableBase64, (UINT32)(UINTN) Ptr); ASSERT_RETURN_ERROR (PcdStatus); On my tcg vm, Ptr will be 64-bit physical address if memory exceeds 4G, I do not know whether there is similar issue on x64 ovmf. ditto for the following PcdFlashNvStorageFtwSpareBase/PcdFlashNvStorageFtwWorkingBase Can uefi bios manage memory beyond 4G? regards bibo, mao -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84116): https://edk2.groups.io/g/devel/message/84116 Mute This Topic: https://groups.io/mt/87342733/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-