diff options
author | Ajan Zhong <ajan.zhong@newfw.com> | 2025-04-26 11:52:17 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2025-07-04 22:39:10 +0000 |
commit | a4db6ecfd964c47c6a26563ebc821789675cd4bb (patch) | |
tree | 49ba2b8ed8b01ee01f4da954dc66862c19fd9356 | |
parent | b95eaaf06aa88783664624ea48b1db116fafca79 (diff) | |
download | edk2-a4db6ecfd964c47c6a26563ebc821789675cd4bb.zip edk2-a4db6ecfd964c47c6a26563ebc821789675cd4bb.tar.gz edk2-a4db6ecfd964c47c6a26563ebc821789675cd4bb.tar.bz2 |
UefiPayloadPkg: Add BlSupportDxe AArch64 support
Introduce AArch64 architecture support in BlSupportDxe. Translation
table would be created based on the memory maps, which is provided
by bootloader, in case MMU is disabled when execution is handed
over to Universal Payload.
Signed-off-by: Ajan Zhong <ajan.zhong@newfw.com>
-rw-r--r-- | UefiPayloadPkg/BlSupportDxe/AArch64/BlSupport.c | 96 | ||||
-rw-r--r-- | UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf | 13 |
2 files changed, 109 insertions, 0 deletions
diff --git a/UefiPayloadPkg/BlSupportDxe/AArch64/BlSupport.c b/UefiPayloadPkg/BlSupportDxe/AArch64/BlSupport.c new file mode 100644 index 0000000..4c5eaa7 --- /dev/null +++ b/UefiPayloadPkg/BlSupportDxe/AArch64/BlSupport.c @@ -0,0 +1,96 @@ +/** @file
+ This file handles post bootloader stage operations for AARCH64 architecture.
+
+ Copyright 2025 Google LLC
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <AArch64/AArch64.h>
+#include <Library/ArmLib.h>
+#include <Library/ArmMmuLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/PcdLib.h>
+#include <Protocol/Cpu.h>
+
+#include "BlSupportDxe.h"
+
+#define MAX_DESCRIPTORS 256
+ARM_MEMORY_REGION_DESCRIPTOR VirtualMemoryTable[MAX_DESCRIPTORS];
+
+STATIC
+EFI_STATUS
+BlUpdateMemoryMap (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *Resource;
+ VOID *TranslationTableBase;
+ UINTN TranslationTableSize;
+ UINTN Idx = 0;
+
+ Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
+
+ while (Hob.Raw != NULL) {
+ Resource = (EFI_HOB_RESOURCE_DESCRIPTOR *)Hob.Raw;
+ Hob.Raw = GET_NEXT_HOB (Hob);
+ Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw);
+
+ VirtualMemoryTable[Idx].PhysicalBase = Resource->PhysicalStart;
+ VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;
+ VirtualMemoryTable[Idx].Length = ALIGN_VALUE (Resource->ResourceLength, EFI_PAGE_SIZE);
+
+ if (Resource->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+ } else if (Resource->ResourceType == EFI_RESOURCE_MEMORY_MAPPED_IO) {
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+ } else {
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
+ }
+
+ Idx++;
+ ASSERT (Idx <= MAX_DESCRIPTORS);
+ }
+
+ Status = ArmConfigureMmu (VirtualMemoryTable, &TranslationTableBase, &TranslationTableSize);
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
+
+/**
+ Architecture level additional operation which needs to be performed before
+ launching payload.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+BlArchAdditionalOps (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ RETURN_STATUS Status = EFI_SUCCESS;
+
+ if (!ArmMmuEnabled ()) {
+ // Enable MMU if MMU is disabled.
+ Status = BlUpdateMemoryMap ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to enable MMU: %r\n", __func__, Status));
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+ }
+
+ return Status;
+}
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf index 43b69e6..4c15fd4 100644 --- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf +++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf @@ -30,10 +30,14 @@ [Sources.IA32, Sources.X64]
X86/BlSupport.c
+[Sources.AARCH64]
+ AArch64/BlSupport.c
+
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec
+ UefiCpuPkg/UefiCpuPkg.dec
[LibraryClasses]
UefiDriverEntryPoint
@@ -44,10 +48,16 @@ UefiLib
HobLib
+[LibraryClasses.AARCH64]
+ ArmMmuLib
+
[Guids]
gUefiAcpiBoardInfoGuid
gEfiGraphicsInfoHobGuid
+[Protocols]
+ gEfiCpuArchProtocolGuid
+
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution
@@ -56,5 +66,8 @@ gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseSize
+[Pcd.AARCH64]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
+
[Depex]
TRUE
|