diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 8fb18bd32d..87653c4427 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -57,6 +57,7 @@ PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf + CpuArchLib|ArmPkg/Library/CpuArchLib/CpuArchLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf @@ -118,8 +119,8 @@ ArmPkg/Library/SemiHostingSerialPortLib/SemiHostingSerialPortLib.inf ArmPkg/Library/SemihostLib/SemihostLib.inf ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.inf + ArmPkg/Library/CpuArchLib/CpuArchLib.inf - ArmPkg/Drivers/CpuDxe/CpuDxe.inf ArmPkg/Drivers/CpuPei/CpuPei.inf ArmPkg/Drivers/ArmGicDxe/ArmGicDxe.inf ArmPkg/Drivers/ArmGicDxe/ArmGicV2Dxe.inf diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Library/CpuArchLib/AArch64/Mmu.c similarity index 100% rename from ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c rename to ArmPkg/Library/CpuArchLib/AArch64/Mmu.c diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Library/CpuArchLib/Arm/Mmu.c similarity index 100% rename from ArmPkg/Drivers/CpuDxe/Arm/Mmu.c rename to ArmPkg/Library/CpuArchLib/Arm/Mmu.c diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.inf b/ArmPkg/Library/CpuArchLib/CpuArchLib.inf similarity index 78% rename from ArmPkg/Drivers/CpuDxe/CpuDxe.inf rename to ArmPkg/Library/CpuArchLib/CpuArchLib.inf index 9e6b8805af..3284522a6f 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.inf +++ b/ArmPkg/Library/CpuArchLib/CpuArchLib.inf @@ -1,6 +1,6 @@ #/** @file # -# DXE CPU driver +# This library installs CPU Architecture Protocol # # Copyright (c) 2009, Apple Inc. All rights reserved.
# Copyright (c) 2011-2013, ARM Limited. All rights reserved. @@ -11,12 +11,11 @@ [Defines] INF_VERSION = 0x00010005 - BASE_NAME = ArmCpuDxe - FILE_GUID = B8D9777E-D72A-451F-9BDB-BAFB52A68415 - MODULE_TYPE = DXE_DRIVER + BASE_NAME = CpuArchLib + FILE_GUID = 47EE96CC-33FA-482B-8AD6-DD8C21AA3752 + MODULE_TYPE = DXE_CORE VERSION_STRING = 1.0 - - ENTRY_POINT = CpuDxeInitialize + LIBRARY_CLASS = CpuArchLib [Sources.Common] CpuDxe.c @@ -49,7 +48,6 @@ DxeServicesTableLib HobLib MemoryAllocationLib - UefiDriverEntryPoint UefiLib [Protocols] diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c b/ArmPkg/Library/CpuArchLib/CpuDxe.c similarity index 95% rename from ArmPkg/Drivers/CpuDxe/CpuDxe.c rename to ArmPkg/Library/CpuArchLib/CpuDxe.c index 39e5e9beea..4dd428d9c5 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c +++ b/ArmPkg/Library/CpuArchLib/CpuDxe.c @@ -395,9 +395,8 @@ HardwareInterruptProtocolNotify ( } EFI_STATUS -CpuDxeInitialize ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +InitializeCpu ( + VOID ) { EFI_STATUS Status; @@ -475,3 +474,14 @@ CpuDxeInitialize ( return EFI_SUCCESS; } + +/** + Initialize Multi-processor support. + +**/ +VOID +InitializeMpSupport ( + VOID + ) +{ +} diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.h b/ArmPkg/Library/CpuArchLib/CpuDxe.h similarity index 100% rename from ArmPkg/Drivers/CpuDxe/CpuDxe.h rename to ArmPkg/Library/CpuArchLib/CpuDxe.h diff --git a/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c b/ArmPkg/Library/CpuArchLib/CpuMmuCommon.c similarity index 100% rename from ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c rename to ArmPkg/Library/CpuArchLib/CpuMmuCommon.c diff --git a/ArmPkg/Drivers/CpuDxe/Exception.c b/ArmPkg/Library/CpuArchLib/Exception.c similarity index 100% rename from ArmPkg/Drivers/CpuDxe/Exception.c rename to ArmPkg/Library/CpuArchLib/Exception.c diff --git a/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c b/ArmPkg/Library/CpuArchLib/MemoryAttribute.c similarity index 100% rename from ArmPkg/Drivers/CpuDxe/MemoryAttribute.c rename to ArmPkg/Library/CpuArchLib/MemoryAttribute.c diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index c8250dc264..2d23a9ec78 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -236,6 +236,7 @@ MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf + CpuArchLib|ArmPkg/Library/CpuArchLib/CpuArchLib.inf [LibraryClasses.common.DXE_DRIVER] SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index ca1aa13e1f..100e688020 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -235,6 +235,9 @@ NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { @@ -244,7 +247,6 @@ # # Architectural Protocols # - ArmPkg/Drivers/CpuDxe/CpuDxe.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { diff --git a/ArmVirtPkg/ArmVirtCloudHv.fdf b/ArmVirtPkg/ArmVirtCloudHv.fdf index 7bad8ed0b2..d3cb55de2f 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.fdf +++ b/ArmVirtPkg/ArmVirtCloudHv.fdf @@ -112,7 +112,6 @@ READ_LOCK_STATUS = TRUE # # PI DXE Drivers producing Architectural Protocols (EFI Services) # - INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 278ec1b629..c12f48c5af 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -260,6 +260,9 @@ NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { @@ -269,7 +272,6 @@ # # Architectural Protocols # - ArmPkg/Drivers/CpuDxe/CpuDxe.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { diff --git a/ArmVirtPkg/ArmVirtKvmTool.fdf b/ArmVirtPkg/ArmVirtKvmTool.fdf index b20ef9c844..32583d4126 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.fdf +++ b/ArmVirtPkg/ArmVirtKvmTool.fdf @@ -127,7 +127,6 @@ READ_LOCK_STATUS = TRUE # # PI DXE Drivers producing Architectural Protocols (EFI Services) # - INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 6193a4bb05..98a1a3ae1f 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -368,6 +368,9 @@ NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { @@ -377,7 +380,6 @@ # # Architectural Protocols # - ArmPkg/Drivers/CpuDxe/CpuDxe.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc index 622409af8a..7d6d05acf4 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -47,7 +47,6 @@ READ_LOCK_STATUS = TRUE # # PI DXE Drivers producing Architectural Protocols (EFI Services) # - INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc index 61d2536123..ba1f75b6e0 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -290,6 +290,9 @@ NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { @@ -299,7 +302,6 @@ # # Architectural Protocols # - ArmPkg/Drivers/CpuDxe/CpuDxe.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc index 1df6dca23f..27378a049d 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -163,6 +163,9 @@ NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { @@ -172,7 +175,6 @@ # # Architectural Protocols # - ArmPkg/Drivers/CpuDxe/CpuDxe.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/ArmVirtPkg/ArmVirtXen.fdf b/ArmVirtPkg/ArmVirtXen.fdf index d149f9b6d5..fb1a5219ff 100644 --- a/ArmVirtPkg/ArmVirtXen.fdf +++ b/ArmVirtPkg/ArmVirtXen.fdf @@ -144,7 +144,6 @@ READ_LOCK_STATUS = TRUE # # PI DXE Drivers producing Architectural Protocols (EFI Services) # - INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c index cf9d556877..6bd35b9d3d 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -453,7 +453,7 @@ CoreDispatcher ( DEBUG ((DEBUG_INFO, "Loading driver %g\n", &DriverEntry->FileName)); Status = CoreLoadImage ( FALSE, - gDxeCoreImageHandle, + gImageHandle, DriverEntry->FvFileDevicePath, NULL, 0, diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 9ebbd2b853..deb3ced94c 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -85,6 +85,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include // // attributes for reserved memory before it is promoted to system memory @@ -232,14 +233,14 @@ typedef struct { // // DXE Core Global Variables // -extern EFI_SYSTEM_TABLE *gDxeCoreST; -extern EFI_RUNTIME_SERVICES *gDxeCoreRT; -extern EFI_DXE_SERVICES *gDxeCoreDS; -extern EFI_HANDLE gDxeCoreImageHandle; +extern EFI_SYSTEM_TABLE *gST; +extern EFI_RUNTIME_SERVICES *gRT; +extern EFI_DXE_SERVICES *gDS; +extern EFI_HANDLE gImageHandle; -extern BOOLEAN gMemoryMapTerminated; +extern BOOLEAN gMemoryMapTerminated; -extern EFI_DECOMPRESS_PROTOCOL gEfiDecompress; +extern EFI_DECOMPRESS_PROTOCOL gEfiDecompress; extern EFI_RUNTIME_ARCH_PROTOCOL *gRuntime; extern EFI_CPU_ARCH_PROTOCOL *gCpu; @@ -251,20 +252,21 @@ extern EFI_SECURITY2_ARCH_PROTOCOL *gSecurity2; extern EFI_BDS_ARCH_PROTOCOL *gBds; extern EFI_SMM_BASE2_PROTOCOL *gSmmBase2; -extern EFI_TPL gEfiCurrentTpl; +extern EFI_TPL gEfiCurrentTpl; -extern EFI_GUID *gDxeCoreFileName; -extern EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage; +extern EFI_GUID *gDxeCoreFileName; +extern EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage; -extern EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1]; +extern EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1]; -extern BOOLEAN gDispatcherRunning; -extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate; +extern BOOLEAN gDispatcherRunning; +extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate; extern BOOLEAN gMemoryAttributesTableForwardCfi; extern EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable; extern BOOLEAN gLoadFixedAddressCodeMemoryReady; +extern LOADED_IMAGE_PRIVATE_DATA * mCurrentImage; // // Service Initialization Functions // diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index 4f20d6420f..bb64caad50 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -71,6 +71,7 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] BaseMemoryLib @@ -95,6 +96,7 @@ PcdLib ImagePropertiesRecordLib OrderedCollectionLib + CpuArchLib [Guids] gEfiEventMemoryMapChangeGuid ## PRODUCES ## Event diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index da8d411d9b..7d700055c3 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -120,28 +120,6 @@ EFI_DXE_SERVICES mDxeServices = { (EFI_SET_MEMORY_SPACE_CAPABILITIES)CoreSetMemorySpaceCapabilities, // SetMemorySpaceCapabilities }; -EFI_SYSTEM_TABLE mEfiSystemTableTemplate = { - { - EFI_SYSTEM_TABLE_SIGNATURE, // Signature - EFI_SYSTEM_TABLE_REVISION, // Revision - sizeof (EFI_SYSTEM_TABLE), // HeaderSize - 0, // CRC32 - 0 // Reserved - }, - NULL, // FirmwareVendor - 0, // FirmwareRevision - NULL, // ConsoleInHandle - NULL, // ConIn - NULL, // ConsoleOutHandle - NULL, // ConOut - NULL, // StandardErrorHandle - NULL, // StdErr - NULL, // RuntimeServices - &mBootServices, // BootServices - 0, // NumberOfConfigurationTableEntries - NULL // ConfigurationTable -}; - EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = { { EFI_RUNTIME_SERVICES_SIGNATURE, // Signature @@ -166,6 +144,28 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = { (EFI_QUERY_VARIABLE_INFO)CoreEfiNotAvailableYetArg4 // QueryVariableInfo }; +EFI_SYSTEM_TABLE mEfiSystemTableTemplate = { + { + EFI_SYSTEM_TABLE_SIGNATURE, // Signature + EFI_SYSTEM_TABLE_REVISION, // Revision + sizeof (EFI_SYSTEM_TABLE), // HeaderSize + 0, // CRC32 + 0 // Reserved + }, + NULL, // FirmwareVendor + 0, // FirmwareRevision + NULL, // ConsoleInHandle + NULL, // ConIn + NULL, // ConsoleOutHandle + NULL, // ConOut + NULL, // StandardErrorHandle + NULL, // StdErr + &mEfiRuntimeServicesTableTemplate, // RuntimeServices + &mBootServices, // BootServices + 0, // NumberOfConfigurationTableEntries + NULL // ConfigurationTable +}; + EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = { INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead), INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead), @@ -190,18 +190,19 @@ EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate; // DXE Core Global Variables for the EFI System Table, Boot Services Table, // DXE Services Table, and Runtime Services Table // -EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices; -EFI_SYSTEM_TABLE *gDxeCoreST = NULL; +EFI_DXE_SERVICES *gDS = &mDxeServices; +EFI_BOOT_SERVICES *gBS = &mBootServices; +EFI_SYSTEM_TABLE *gST = &mEfiSystemTableTemplate; // -// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory -// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it +// For debug initialize gRT to template. gRT must be allocated from RT memory +// but gRT is used for ASSERT () and DEBUG () type macros so lets give it // a value that will not cause debug infrastructure to crash early on. // -EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate; -EFI_HANDLE gDxeCoreImageHandle = NULL; +EFI_RUNTIME_SERVICES *gRT = &mEfiRuntimeServicesTableTemplate; +EFI_HANDLE gImageHandle = NULL; -BOOLEAN gMemoryMapTerminated = FALSE; +BOOLEAN gMemoryMapTerminated = FALSE; static BOOLEAN mExitBootServicesCalled = FALSE; @@ -245,18 +246,6 @@ DxeMain ( EFI_VECTOR_HANDOFF_INFO *VectorInfoList; EFI_VECTOR_HANDOFF_INFO *VectorInfo; - // - // Setup the default exception handlers - // - VectorInfoList = NULL; - GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart); - if (GuidHob != NULL) { - VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob)); - } - - Status = InitializeCpuExceptionHandlers (VectorInfoList); - ASSERT_EFI_ERROR (Status); - // // Setup Stack Guard // @@ -299,26 +288,63 @@ DxeMain ( // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table // - gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate); - ASSERT (gDxeCoreST != NULL); + gST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate); + ASSERT (gST != NULL); - gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate); - ASSERT (gDxeCoreRT != NULL); + gRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate); + ASSERT (gRT != NULL); - gDxeCoreST->RuntimeServices = gDxeCoreRT; + gST->RuntimeServices = gRT; + + // + // Install the DXE Services Table into the EFI System Tables's Configuration Table + // + Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS); + ASSERT_EFI_ERROR (Status); // // Update DXE Core Loaded Image Protocol with allocated UEFI System Table // - gDxeCoreLoadedImage->SystemTable = gDxeCoreST; + gDxeCoreLoadedImage->SystemTable = gST; + + // + // Initialize the Event Services + // + Status = CoreInitializeEventServices (); + ASSERT_EFI_ERROR (Status); + + // + // Register for the GUIDs of the Architectural Protocols, so the rest of the + // EFI Boot Services and EFI Runtime Services tables can be filled in. + // Also register for the GUIDs of optional protocols. + // + CoreNotifyOnProtocolInstallation (); + + // + // Initialize CPU Architectural Protocol + // + InitializeCpu (); + + MemoryProfileInstallProtocol (); + + CoreInitializeMemoryAttributesTable (); + + CoreInitializeMemoryProtection (); + + ProtectUefiImage (mCurrentImage, &ImageContext); // // Call constructor for all libraries // - ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST); + ProcessLibraryConstructorList (gImageHandle, gST); PERF_CROSSMODULE_END ("PEI"); PERF_CROSSMODULE_BEGIN ("DXE"); + // + // Initialize Multi-processor support + // + InitializeMpSupport (); + // // Log MemoryBaseAddress and MemoryLength again (from // CoreInitializeMemoryServices()), now that library constructors have @@ -338,12 +364,6 @@ DxeMain ( // UefiImageLoaderRelocateImageExtraAction (&ImageContext); - // - // Install the DXE Services Table into the EFI System Tables's Configuration Table - // - Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS); - ASSERT_EFI_ERROR (Status); - // // Install the HOB List into the EFI System Tables's Configuration Table // @@ -383,7 +403,7 @@ DxeMain ( CoreNewDebugImageInfoEntry ( EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, gDxeCoreLoadedImage, - gDxeCoreImageHandle, + gImageHandle, &ImageContext ); @@ -447,26 +467,11 @@ DxeMain ( DEBUG_CODE_END (); - // - // Initialize the Event Services - // - Status = CoreInitializeEventServices (); - ASSERT_EFI_ERROR (Status); - - // - // Give the debug agent a chance to initialize with events. - // - InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE_LATE, HobStart, NULL); - - MemoryProfileInstallProtocol (); - - CoreInitializeMemoryAttributesTable (); - CoreInitializeMemoryProtection (); - // // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated, // and install configuration table // + VectorInfoList = NULL; GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart); if (GuidHob != NULL) { VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob)); @@ -506,26 +511,19 @@ DxeMain ( ); ASSERT_EFI_ERROR (Status); - // - // Register for the GUIDs of the Architectural Protocols, so the rest of the - // EFI Boot Services and EFI Runtime Services tables can be filled in. - // Also register for the GUIDs of optional protocols. - // - CoreNotifyOnProtocolInstallation (); - // // Produce Firmware Volume Protocols, one for each FV in the HOB list. // - Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST); + Status = FwVolBlockDriverInit (gImageHandle, gST); ASSERT_EFI_ERROR (Status); - Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST); + Status = FwVolDriverInit (gImageHandle, gST); ASSERT_EFI_ERROR (Status); // // Produce the Section Extraction Protocol // - Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST); + Status = InitializeSectionExtraction (gImageHandle, gST); ASSERT_EFI_ERROR (Status); // @@ -827,18 +825,18 @@ CoreExitBootServices ( // // Clear the non-runtime values of the EFI System Table // - gDxeCoreST->BootServices = NULL; - gDxeCoreST->ConIn = NULL; - gDxeCoreST->ConsoleInHandle = NULL; - gDxeCoreST->ConOut = NULL; - gDxeCoreST->ConsoleOutHandle = NULL; - gDxeCoreST->StdErr = NULL; - gDxeCoreST->StandardErrorHandle = NULL; + gST->BootServices = NULL; + gST->ConIn = NULL; + gST->ConsoleInHandle = NULL; + gST->ConOut = NULL; + gST->ConsoleOutHandle = NULL; + gST->StdErr = NULL; + gST->StandardErrorHandle = NULL; // // Recompute the 32-bit CRC of the EFI System Table // - CalculateEfiHdrCrc (&gDxeCoreST->Hdr); + CalculateEfiHdrCrc (&gST->Hdr); // // Zero out the Boot Service Table diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c index 3fe02940ed..1f85d33f97 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c @@ -194,10 +194,10 @@ GenericProtocolNotify ( // // It's over kill to do them all every time, but it saves a lot of code. // - CalculateEfiHdrCrc (&gDxeCoreRT->Hdr); + CalculateEfiHdrCrc (&gRT->Hdr); CalculateEfiHdrCrc (&gBS->Hdr); - CalculateEfiHdrCrc (&gDxeCoreST->Hdr); - CalculateEfiHdrCrc (&gDxeCoreDS->Hdr); + CalculateEfiHdrCrc (&gST->Hdr); + CalculateEfiHdrCrc (&gDS->Hdr); } /** diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 6ea89fbc8b..6ddbe60f07 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -1498,7 +1498,7 @@ CoreAddMemorySpace ( EFI_PAGE_SHIFT, PageLength, &PageBaseAddress, - gDxeCoreImageHandle, + gImageHandle, NULL ); @@ -1517,7 +1517,7 @@ CoreAddMemorySpace ( EFI_PAGE_SHIFT, EFI_PAGE_SIZE, &PageBaseAddress, - gDxeCoreImageHandle, + gImageHandle, NULL ); @@ -2735,7 +2735,7 @@ CoreInitializeGcdServices ( 0, MemoryLength, &MemoryBaseAddress, - gDxeCoreImageHandle, + gImageHandle, NULL ); } @@ -2756,7 +2756,7 @@ CoreInitializeGcdServices ( 0, MemoryHob->AllocDescriptor.MemoryLength, &BaseAddress, - gDxeCoreImageHandle, + gImageHandle, NULL ); if (!EFI_ERROR (Status) && @@ -2782,7 +2782,7 @@ CoreInitializeGcdServices ( 0, FirmwareVolumeHob->Length, &BaseAddress, - gDxeCoreImageHandle, + gImageHandle, NULL ); } @@ -2830,7 +2830,7 @@ CoreInitializeGcdServices ( 0, Length, &BaseAddress, - gDxeCoreImageHandle, + gImageHandle, NULL ); } @@ -2872,7 +2872,7 @@ CoreInitializeGcdServices ( 0, Length, &BaseAddress, - gDxeCoreImageHandle, + gImageHandle, NULL ); } diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index 93e69eea73..4a0f83ff2e 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -1047,7 +1047,7 @@ CoreHandleProtocol ( UserHandle, Protocol, Interface, - gDxeCoreImageHandle, + gImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL ); diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 948d3478ee..30a290572f 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -271,7 +271,7 @@ CoreInitializeImageServices ( // // Fill in DXE globals // - gDxeCoreImageHandle = Image->Handle; + gImageHandle = Image->Handle; gDxeCoreLoadedImage = &Image->Info; // @@ -298,8 +298,6 @@ CoreInitializeImageServices ( InitializeListHead (&mAvailableEmulators); - ProtectUefiImage (Image, ImageContext); - return Status; } @@ -1285,7 +1283,7 @@ CoreLoadImageCommon ( // Initialize the fields for an internal driver // Image->Signature = LOADED_IMAGE_PRIVATE_DATA_SIGNATURE; - Image->Info.SystemTable = gDxeCoreST; + Image->Info.SystemTable = gST; Image->Info.DeviceHandle = DeviceHandle; Image->Info.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION; Image->Info.FilePath = DuplicateDevicePath (FilePath); diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index e4daa741b9..15c93ba5ef 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -419,7 +419,7 @@ PromoteMemoryResource ( } Entry->Capabilities |= EFI_MEMORY_TESTED; - Entry->ImageHandle = gDxeCoreImageHandle; + Entry->ImageHandle = gImageHandle; Entry->DeviceHandle = NULL; // diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c index d6e732e021..9074de9670 100644 --- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c +++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c @@ -119,7 +119,7 @@ CoreInitializeDebugImageInfoTable ( // Initialize EFI_SYSTEM_TABLE_POINTER structure // mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE; - mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreST; + mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS)(UINTN)gST; mDebugTable->Crc32 = 0; // diff --git a/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c b/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c index f47f3bd804..e7cc4764b9 100755 --- a/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c @@ -45,18 +45,18 @@ CoreInstallConfigurationTable ( return EFI_INVALID_PARAMETER; } - EfiConfigurationTable = gDxeCoreST->ConfigurationTable; + EfiConfigurationTable = gST->ConfigurationTable; // // Search all the table for an entry that matches Guid // - for (Index = 0; Index < gDxeCoreST->NumberOfTableEntries; Index++) { - if (CompareGuid (Guid, &(gDxeCoreST->ConfigurationTable[Index].VendorGuid))) { + for (Index = 0; Index < gST->NumberOfTableEntries; Index++) { + if (CompareGuid (Guid, &(gST->ConfigurationTable[Index].VendorGuid))) { break; } } - if (Index < gDxeCoreST->NumberOfTableEntries) { + if (Index < gST->NumberOfTableEntries) { // // A match was found, so this is either a modify or a delete operation // @@ -65,7 +65,7 @@ CoreInstallConfigurationTable ( // If Table is not NULL, then this is a modify operation. // Modify the table entry and return. // - gDxeCoreST->ConfigurationTable[Index].VendorTable = Table; + gST->ConfigurationTable[Index].VendorTable = Table; // // Signal Configuration Table change @@ -78,15 +78,15 @@ CoreInstallConfigurationTable ( // // A match was found and Table is NULL, so this is a delete operation. // - gDxeCoreST->NumberOfTableEntries--; + gST->NumberOfTableEntries--; // // Copy over deleted entry // CopyMem ( &(EfiConfigurationTable[Index]), - &(gDxeCoreST->ConfigurationTable[Index + 1]), - (gDxeCoreST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE) + &(gST->ConfigurationTable[Index + 1]), + (gST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE) ); } else { // @@ -101,7 +101,7 @@ CoreInstallConfigurationTable ( } // - // Assume that Index == gDxeCoreST->NumberOfTableEntries + // Assume that Index == gST->NumberOfTableEntries // if ((Index * sizeof (EFI_CONFIGURATION_TABLE)) >= mSystemTableAllocateSize) { // @@ -116,30 +116,30 @@ CoreInstallConfigurationTable ( return EFI_OUT_OF_RESOURCES; } - if (gDxeCoreST->ConfigurationTable != NULL) { + if (gST->ConfigurationTable != NULL) { // // Copy the old table to the new table. // CopyMem ( EfiConfigurationTable, - gDxeCoreST->ConfigurationTable, + gST->ConfigurationTable, Index * sizeof (EFI_CONFIGURATION_TABLE) ); // // Record the old table pointer. // - OldTable = gDxeCoreST->ConfigurationTable; + OldTable = gST->ConfigurationTable; // // As the CoreInstallConfigurationTable() may be re-entered by CoreFreePool() // in its calling stack, updating System table to the new table pointer must // be done before calling CoreFreePool() to free the old table. - // It can make sure the gDxeCoreST->ConfigurationTable point to the new table + // It can make sure the gST->ConfigurationTable point to the new table // and avoid the errors of use-after-free to the old table by the reenter of // CoreInstallConfigurationTable() in CoreFreePool()'s calling stack. // - gDxeCoreST->ConfigurationTable = EfiConfigurationTable; + gST->ConfigurationTable = EfiConfigurationTable; // // Free the old table after updating System Table to the new table pointer. @@ -149,7 +149,7 @@ CoreInstallConfigurationTable ( // // Update System Table // - gDxeCoreST->ConfigurationTable = EfiConfigurationTable; + gST->ConfigurationTable = EfiConfigurationTable; } } @@ -162,13 +162,13 @@ CoreInstallConfigurationTable ( // // This is an add operation, so increment the number of table entries // - gDxeCoreST->NumberOfTableEntries++; + gST->NumberOfTableEntries++; } // // Fix up the CRC-32 in the EFI System Table // - CalculateEfiHdrCrc (&gDxeCoreST->Hdr); + CalculateEfiHdrCrc (&gST->Hdr); // // Signal Configuration Table change diff --git a/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.c b/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.c new file mode 100644 index 0000000000..a683ea5dd3 --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.c @@ -0,0 +1,48 @@ +/** @file + Dummy instance of DXE Services Table Library for DxeCore. + + Relies on and sanity-checks that DxeCore provides the variables itself. + + Copyright (c) 2021, Marvin Häuser. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + The constructor function sanity-checks the variables set by DxeCore. + It will always return EFI_SUCCESS. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +DxeServicesTableLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_DXE_SERVICES *DS; + + // + // ASSERT that DxeCore provides the services correctly and in time + // + DEBUG_CODE_BEGIN (); + Status = EfiGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &DS); + ASSERT_EFI_ERROR (Status); + ASSERT (gDS == DS); + DEBUG_CODE_END (); + ASSERT (gDS != NULL); + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf b/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf new file mode 100644 index 0000000000..dd5633bdf6 --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf @@ -0,0 +1,40 @@ +## @file +# Dummy instance of DXE Services Table Library for DxeCore. +# +# Copyright (c) 2021, Marvin Häuser. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeCoreDxeServicesTableLib + MODULE_UNI_FILE = DxeCoreDxeServicesTableLib.uni + FILE_GUID = 898fc74c-b07c-4b68-bdd3-365c9ce26a9d + MODULE_TYPE = DXE_CORE + VERSION_STRING = 1.0 + LIBRARY_CLASS = DxeServicesTableLib|DXE_CORE + + CONSTRUCTOR = DxeServicesTableLibConstructor + +# +# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64 +# + +[Sources] + DxeCoreDxeServicesTableLib.c + + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses] + UefiLib + DebugLib + + +[Guids] + gEfiDxeServicesTableGuid ## CONSUMES ## SystemTable diff --git a/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.uni b/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.uni new file mode 100644 index 0000000000..0019a62e3f --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.uni @@ -0,0 +1,13 @@ +// /** @file +// Dummy instance of DXE Services Table Library for DxeCore. +// +// Copyright (c) 2021, Marvin Häuser. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Dummy instance for DxeCore" + +#string STR_MODULE_DESCRIPTION #language en-US "DXE Services Table Library retrieves a pointer to the DXE Services Table from the Configuration Table in the EFI System Table." diff --git a/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.c b/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.c new file mode 100644 index 0000000000..aa95351214 --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.c @@ -0,0 +1,44 @@ +/** @file + Dummy instance of UEFI Boot Services Table Library for DxeCore. + + Relies on and sanity-checks that DxeCore provides the variables itself. + + Copyright (c) 2021, Marvin Häuser. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include + +/** + The constructor function sanity-checks the variables set by DxeCore. + It will always return EFI_SUCCESS. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +UefiBootServicesTableLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + // + // ASSERT that DxeCore provides the services correctly and in time + // + ASSERT (gImageHandle == ImageHandle); + ASSERT (gImageHandle != NULL); + ASSERT (gST == SystemTable); + ASSERT (gST != NULL); + ASSERT (gBS == gST->BootServices); + ASSERT (gBS != NULL); + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf b/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf new file mode 100644 index 0000000000..81b70fac3f --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf @@ -0,0 +1,34 @@ +## @file +# Dummy instance of UEFI Boot Services Table Library for DxeCore. +# +# Copyright (c) 2021, Marvin Häuser. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeCoreUefiBootServicesTableLib + MODULE_UNI_FILE = DxeCoreUefiBootServicesTableLib.uni + FILE_GUID = 67ecd0d0-5e42-4933-baee-cb129e4f4c55 + MODULE_TYPE = DXE_CORE + VERSION_STRING = 1.0 + LIBRARY_CLASS = UefiBootServicesTableLib|DXE_CORE + + CONSTRUCTOR = UefiBootServicesTableLibConstructor + +# +# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64 +# + +[Sources] + DxeCoreUefiBootServicesTableLib.c + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses] + DebugLib diff --git a/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.uni b/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.uni new file mode 100644 index 0000000000..4f060a394d --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.uni @@ -0,0 +1,13 @@ +// /** @file +// Dummy instance of UEFI Boot Services Table Library for DxeCore. +// +// Copyright (c) 2021, Marvin Häuser. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Dummy instance of UEFI Boot Services Table Library for DxeCore" + +#string STR_MODULE_DESCRIPTION #language en-US "Dummy instance of UEFI Boot Services Table Library for DxeCore." diff --git a/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.c b/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.c new file mode 100644 index 0000000000..3c92746ab1 --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.c @@ -0,0 +1,39 @@ +/** @file + Dummy instance of UEFI Runtime Services Table Library for DxeCore. + + Relies on and sanity-checks that DxeCore provides the variables itself. + + Copyright (c) 2021, Marvin Häuser. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include + +/** + The constructor function sanity-checks the variables set by DxeCore. + It will always return EFI_SUCCESS. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +UefiRuntimeServicesTableLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + // + // ASSERT that DxeCore provides the services correctly and in time + // + ASSERT (gRT == SystemTable->RuntimeServices); + ASSERT (gRT != NULL); + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf b/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf new file mode 100644 index 0000000000..5ff3fd8eee --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf @@ -0,0 +1,35 @@ +## @file +# Dummy instance of UEFI Runtime Services Table Library for DxeCore. +# +# Copyright (c) 2021, Marvin Häuser. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeCoreUefiRuntimeServicesTableLib + MODULE_UNI_FILE = DxeCoreUefiRuntimeServicesTableLib.uni + FILE_GUID = 59a35203-341d-46b6-96f6-ec69e035b02e + MODULE_TYPE = DXE_CORE + VERSION_STRING = 1.0 + LIBRARY_CLASS = UefiRuntimeServicesTableLib|DXE_CORE + + CONSTRUCTOR = UefiRuntimeServicesTableLibConstructor + +# +# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64 +# + +[Sources] + DxeCoreUefiRuntimeServicesTableLib.c + + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses] + DebugLib diff --git a/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.uni b/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.uni new file mode 100644 index 0000000000..b860b3f996 --- /dev/null +++ b/MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.uni @@ -0,0 +1,13 @@ +// /** @file +// Dummy instance of UEFI Runtime Services Table Library for DxeCore. +// +// Copyright (c) 2021, Marvin Häuser. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Dummy instance of UEFI Runtime Services Table Library for DxeCore" + +#string STR_MODULE_DESCRIPTION #language en-US "Dummy instance of UEFI Runtime Services Table Library for DxeCore." diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 2e9fe859ad..8b2caee209 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -127,6 +127,22 @@ HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf + CpuArchLib|UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf + MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf + LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf + UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf + +[LibraryClasses.IA32.DXE_CORE] + CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf + +[LibraryClasses.X64.DXE_CORE] + CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf [LibraryClasses.common.DXE_DRIVER] HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf @@ -345,6 +361,9 @@ MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdateProgressLibText.inf MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf MdeModulePkg/Library/HobPrintLib/HobPrintLib.inf + MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf MdeModulePkg/Universal/BdsDxe/BdsDxe.inf MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf @@ -527,4 +546,3 @@ MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf [BuildOptions] - diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h index 57b18b94d9..36f23e37ac 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -55,6 +55,9 @@ typedef struct { BOOLEAN QemuFwCfgChecked; BOOLEAN QemuFwCfgSupported; BOOLEAN QemuFwCfgDmaSupported; + + UINT64 PteMemoryEncryptionAddressOrMask; + UINT64 GhcbBase; } EFI_HOB_PLATFORM_INFO; #pragma pack() diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc index 840159d118..28fbc45767 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -256,6 +256,8 @@ ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + CpuArchLib|UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -573,6 +575,9 @@ NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf @@ -595,29 +600,6 @@ MdeModulePkg/Universal/EbcDxe/EbcDxe.inf UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf - UefiCpuPkg/CpuDxe/CpuDxe.inf { - - # - # Directly use DxeMpInitLib. It depends on DxeMpInitLibMpDepLib which - # checks the Protocol of gEfiMpInitLibMpDepProtocolGuid. - # - MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf - NULL|OvmfPkg/Library/MpInitLibDepLib/DxeMpInitLibMpDepLib.inf - } - - UefiCpuPkg/CpuDxe/CpuDxe.inf { - - FILE_GUID = $(UP_CPU_DXE_GUID) - - - # - # Directly use MpInitLibUp. It depends on DxeMpInitLibUpDepLib which - # checks the Protocol of gEfiMpInitLibUpDepProtocolGuid. - # - MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf - NULL|OvmfPkg/Library/MpInitLibDepLib/DxeMpInitLibUpDepLib.inf - } - OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.fdf b/OvmfPkg/IntelTdx/IntelTdxX64.fdf index 01581c0a0b..23c449aeca 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.fdf +++ b/OvmfPkg/IntelTdx/IntelTdxX64.fdf @@ -189,9 +189,6 @@ INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf -INF UefiCpuPkg/CpuDxe/CpuDxe.inf -INF FILE_GUID = $(UP_CPU_DXE_GUID) UefiCpuPkg/CpuDxe/CpuDxe.inf - INF OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf INF OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 735f828797..07e5495463 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -327,6 +327,8 @@ !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + CpuArchLib|UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -731,6 +733,9 @@ NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf @@ -752,7 +757,6 @@ MdeModulePkg/Universal/EbcDxe/EbcDxe.inf UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf - UefiCpuPkg/CpuDxe/CpuDxe.inf OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index bc7bb678b4..010a3cec91 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -218,7 +218,6 @@ INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf -INF UefiCpuPkg/CpuDxe/CpuDxe.inf INF OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf INF OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 4aa7f236a7..572b18352e 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -332,6 +332,8 @@ !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + CpuArchLib|UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -747,6 +749,9 @@ NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf @@ -768,7 +773,6 @@ MdeModulePkg/Universal/EbcDxe/EbcDxe.inf UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf - UefiCpuPkg/CpuDxe/CpuDxe.inf OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index 7f971dd9c2..34a78831f5 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -219,7 +219,6 @@ INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf -INF UefiCpuPkg/CpuDxe/CpuDxe.inf INF OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf INF OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index a167addb60..1797b50530 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -354,6 +354,8 @@ !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + CpuArchLib|UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -793,6 +795,9 @@ NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf @@ -815,29 +820,6 @@ MdeModulePkg/Universal/EbcDxe/EbcDxe.inf UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf - UefiCpuPkg/CpuDxe/CpuDxe.inf { - - # - # Directly use DxeMpInitLib. It depends on DxeMpInitLibMpDepLib which - # checks the Protocol of gEfiMpInitLibMpDepProtocolGuid. - # - MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf - NULL|OvmfPkg/Library/MpInitLibDepLib/DxeMpInitLibMpDepLib.inf - } - - UefiCpuPkg/CpuDxe/CpuDxe.inf { - - FILE_GUID = $(UP_CPU_DXE_GUID) - - - # - # Directly use MpInitLibUp. It depends on DxeMpInitLibUpDepLib which - # checks the Protocol of gEfiMpInitLibUpDepProtocolGuid. - # - MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf - NULL|OvmfPkg/Library/MpInitLibDepLib/DxeMpInitLibUpDepLib.inf - } - OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 547c6ee3b7..9b26b3192c 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -251,9 +251,6 @@ INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf -INF UefiCpuPkg/CpuDxe/CpuDxe.inf -INF FILE_GUID = $(UP_CPU_DXE_GUID) UefiCpuPkg/CpuDxe/CpuDxe.inf - INF OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf INF OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 8562787035..2a666eebdd 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -348,6 +348,9 @@ AmdSevEsInitialize ( Status = PcdSet64S (PcdGhcbBase, GhcbBasePa); ASSERT_RETURN_ERROR (Status); + + PlatformInfoHob->GhcbBase = GhcbBasePa; + Status = PcdSet64S (PcdGhcbSize, EFI_PAGES_TO_SIZE (GhcbPageCount)); ASSERT_RETURN_ERROR (Status); @@ -459,6 +462,8 @@ AmdSevInitialize ( PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask); ASSERT_RETURN_ERROR (PcdStatus); + PlatformInfoHob->PteMemoryEncryptionAddressOrMask = EncryptionMask; + DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask)); // @@ -530,6 +535,7 @@ AmdSevInitialize ( } PcdStatus = PcdSet64S (PcdConfidentialComputingGuestAttr, CCGuestAttr); + PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCGuestAttr; ASSERT_RETURN_ERROR (PcdStatus); } diff --git a/OvmfPkg/PlatformPei/IntelTdx.c b/OvmfPkg/PlatformPei/IntelTdx.c index 8aa796b3e9..a364c77de6 100644 --- a/OvmfPkg/PlatformPei/IntelTdx.c +++ b/OvmfPkg/PlatformPei/IntelTdx.c @@ -30,11 +30,12 @@ **/ VOID IntelTdxInitialize ( - VOID + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { #ifdef MDE_CPU_X64 RETURN_STATUS PcdStatus; + UINT64 PageMask; if (!TdIsEnabled ()) { return; @@ -43,8 +44,12 @@ IntelTdxInitialize ( PcdStatus = PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrIntelTdx); ASSERT_RETURN_ERROR (PcdStatus); - PcdStatus = PcdSet64S (PcdTdxSharedBitMask, TdSharedPageMask ()); + PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCAttrIntelTdx; + + PageMask = TdSharedPageMask (); + PcdStatus = PcdSet64S (PcdTdxSharedBitMask, PageMask); ASSERT_RETURN_ERROR (PcdStatus); + PlatformInfoHob->PcdTdxSharedBitMask = PageMask; #endif } diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 7b4ea1b827..4b74ff3a26 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -368,7 +368,7 @@ InitializePlatform ( PlatformIdInitialization (PeiServices); } - IntelTdxInitialize (); + IntelTdxInitialize (PlatformInfoHob); InstallFeatureControlCallback (PlatformInfoHob); if (PlatformInfoHob->SmmSmramRequire) { RelocateSmBase (); diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 0a59547cfc..39ef3107e9 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -95,7 +95,7 @@ AmdSevInitialize ( **/ VOID IntelTdxInitialize ( - VOID + IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); /** diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.uni b/UefiCpuPkg/CpuDxe/CpuDxe.uni deleted file mode 100644 index 85d977d8c8..0000000000 --- a/UefiCpuPkg/CpuDxe/CpuDxe.uni +++ /dev/null @@ -1,16 +0,0 @@ -// /** @file -// CPU driver installs CPU Architecture Protocol and CPU MP Protocol. -// -// CPU driver installs CPU Architecture Protocol and CPU MP Protocol. -// -// Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
-// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "CPU driver installs CPU Architecture Protocol and CPU MP Protocol." - -#string STR_MODULE_DESCRIPTION #language en-US "CPU driver installs CPU Architecture Protocol and CPU MP Protocol." - diff --git a/UefiCpuPkg/Include/Library/CpuArchLib.h b/UefiCpuPkg/Include/Library/CpuArchLib.h new file mode 100644 index 0000000000..e9521d4e4f --- /dev/null +++ b/UefiCpuPkg/Include/Library/CpuArchLib.h @@ -0,0 +1,31 @@ +/** @file + CPU DXE Module to produce CPU ARCH Protocol. + Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef _CPU_ARCH_LIB_H_ +#define _CPU_ARCH_LIB_H_ + +/** + Initialize the state information for the CPU Architectural Protocol. + + @retval EFI_SUCCESS Thread can be successfully created + @retval EFI_OUT_OF_RESOURCES Can not allocate protocol data structure + @retval EFI_DEVICE_ERROR Can not create the thread +**/ +EFI_STATUS +InitializeCpu ( + VOID + ); + +/** + Initialize Multi-processor support. + +**/ +VOID +InitializeMpSupport ( + VOID + ); + +#endif // _CPU_ARCH_LIB_H_ diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf similarity index 81% rename from UefiCpuPkg/CpuDxe/CpuDxe.inf rename to UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf index b2954ba234..c09c28d996 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.inf +++ b/UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf @@ -1,5 +1,5 @@ ## @file -# CPU driver installs CPU Architecture Protocol and CPU MP protocol. +# This library installs CPU Architecture Protocol and CPU MP protocol. # # Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
# Copyright (c) 2017, AMD Incorporated. All rights reserved.
@@ -11,16 +11,17 @@ [Defines] INF_VERSION = 0x00010005 - BASE_NAME = CpuDxe - MODULE_UNI_FILE = CpuDxe.uni - FILE_GUID = 1A1E4886-9517-440e-9FDE-3BE44CEE2136 - MODULE_TYPE = DXE_DRIVER + BASE_NAME = CpuArchLib + MODULE_UNI_FILE = CpuArchLib.uni + FILE_GUID = EF9CBDF2-BD7C-48F1-9D87-EE83A0269EEE + MODULE_TYPE = DXE_CORE VERSION_STRING = 1.0 - ENTRY_POINT = InitializeCpu + LIBRARY_CLASS = CpuArchLib [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses.common] @@ -33,11 +34,10 @@ HobLib MemoryAllocationLib MpInitLib - PeCoffGetEntryPointLib ReportStatusCodeLib + SerialPortLib TimerLib UefiBootServicesTableLib - UefiDriverEntryPoint UefiLib [LibraryClasses.IA32, LibraryClasses.X64] @@ -82,13 +82,13 @@ [Guids] gIdleLoopEventGuid ## CONSUMES ## Event gEfiVectorHandoffTableGuid ## SOMETIMES_CONSUMES ## SystemTable + gUefiOvmfPkgPlatformInfoGuid ## CONSUMES ## HOB [Ppis] gEfiSecPlatformInformation2PpiGuid ## UNDEFINED # HOB gEfiSecPlatformInformationPpiGuid ## UNDEFINED # HOB [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuArchLib/CpuArchLib.uni b/UefiCpuPkg/Library/CpuArchLib/CpuArchLib.uni new file mode 100644 index 0000000000..2c9429979a --- /dev/null +++ b/UefiCpuPkg/Library/CpuArchLib/CpuArchLib.uni @@ -0,0 +1,13 @@ +// /** @file +// This library installs CPU Architecture Protocol and CPU MP Protocol. +// +// Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "This library installs CPU Architecture Protocol and CPU MP Protocol." + +#string STR_MODULE_DESCRIPTION #language en-US "This library installs CPU Architecture Protocol and CPU MP Protocol." diff --git a/UefiCpuPkg/Library/CpuArchLib/CpuArchLibNull.inf b/UefiCpuPkg/Library/CpuArchLib/CpuArchLibNull.inf new file mode 100644 index 0000000000..febba954bd --- /dev/null +++ b/UefiCpuPkg/Library/CpuArchLib/CpuArchLibNull.inf @@ -0,0 +1,24 @@ +## @file +# This library provides dummy InitializeCpu() for DxeMain.inf. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = CpuArchLib + FILE_GUID = EF9CBDF2-BD7C-48F1-9D87-EE83A0269EEE + MODULE_TYPE = DXE_CORE + VERSION_STRING = 1.0 + LIBRARY_CLASS = CpuArchLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + +[Sources] + CpuDxeNull.c diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/Library/CpuArchLib/CpuDxe.c similarity index 94% rename from UefiCpuPkg/CpuDxe/CpuDxe.c rename to UefiCpuPkg/Library/CpuArchLib/CpuDxe.c index 472de55180..1d539ee3f7 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/Library/CpuArchLib/CpuDxe.c @@ -21,7 +21,7 @@ BOOLEAN mIsFlushingGCD; BOOLEAN mIsAllocatingPageTable = FALSE; UINT64 mTimerPeriod = 0; -EFI_CPU_ARCH_PROTOCOL gCpu = { +EFI_CPU_ARCH_PROTOCOL gCpuImpl = { CpuFlushCpuDataCache, CpuEnableInterrupt, CpuDisableInterrupt, @@ -34,6 +34,8 @@ EFI_CPU_ARCH_PROTOCOL gCpu = { 4 // DmaBufferAlignment }; +EFI_HOB_PLATFORM_INFO *mPlatformInfoHob2 = NULL; + // // CPU Arch Protocol Functions // @@ -947,7 +949,7 @@ FreeMemorySpaceMap: **/ VOID AddLocalApicMemorySpace ( - IN EFI_HANDLE ImageHandle + VOID ) { EFI_STATUS Status; @@ -968,7 +970,7 @@ AddLocalApicMemorySpace ( 0, SIZE_4KB, &BaseAddress, - ImageHandle, + gImageHandle, NULL ); if (EFI_ERROR (Status)) { @@ -985,23 +987,24 @@ AddLocalApicMemorySpace ( /** Initialize the state information for the CPU Architectural Protocol. - @param ImageHandle Image handle this driver. - @param SystemTable Pointer to the System Table. - @retval EFI_SUCCESS Thread can be successfully created - @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure - @retval EFI_DEVICE_ERROR Cannot create the thread + @retval EFI_OUT_OF_RESOURCES Can not allocate protocol data structure + @retval EFI_DEVICE_ERROR Can not create the thread **/ EFI_STATUS -EFIAPI InitializeCpu ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable + VOID ) { - EFI_STATUS Status; - EFI_EVENT IdleLoopEvent; + EFI_STATUS Status; + EFI_EVENT IdleLoopEvent; + EFI_HOB_GUID_TYPE *GuidHob; + + GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid); + if (GuidHob != NULL) { + mPlatformInfoHob2 = (EFI_HOB_PLATFORM_INFO *)(GET_GUID_HOB_DATA (GuidHob)); + } InitializePageTableLib (); @@ -1028,7 +1031,7 @@ InitializeCpu ( Status = gBS->InstallMultipleProtocolInterfaces ( &mCpuHandle, &gEfiCpuArchProtocolGuid, - &gCpu, + &gCpuImpl, NULL ); ASSERT_EFI_ERROR (Status); @@ -1046,7 +1049,7 @@ InitializeCpu ( // // Add and allocate local APIC memory mapped space // - AddLocalApicMemorySpace (ImageHandle); + AddLocalApicMemorySpace (); // // Setup a callback for idle events @@ -1061,7 +1064,5 @@ InitializeCpu ( ); ASSERT_EFI_ERROR (Status); - InitializeMpSupport (); - return Status; } diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/Library/CpuArchLib/CpuDxe.h similarity index 94% rename from UefiCpuPkg/CpuDxe/CpuDxe.h rename to UefiCpuPkg/Library/CpuArchLib/CpuDxe.h index 0e7d88dd35..34a865d1dd 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.h +++ b/UefiCpuPkg/Library/CpuArchLib/CpuDxe.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -293,7 +294,8 @@ PageFaultExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ); -extern BOOLEAN mIsAllocatingPageTable; -extern UINTN mNumberOfProcessors; +extern BOOLEAN mIsAllocatingPageTable; +extern UINTN mNumberOfProcessors; +extern EFI_HOB_PLATFORM_INFO *mPlatformInfoHob2; #endif diff --git a/UefiCpuPkg/CpuDxe/CpuDxeExtra.uni b/UefiCpuPkg/Library/CpuArchLib/CpuDxeExtra.uni similarity index 77% rename from UefiCpuPkg/CpuDxe/CpuDxeExtra.uni rename to UefiCpuPkg/Library/CpuArchLib/CpuDxeExtra.uni index 5bb116fee7..57bf2691e7 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxeExtra.uni +++ b/UefiCpuPkg/Library/CpuArchLib/CpuDxeExtra.uni @@ -9,6 +9,4 @@ #string STR_PROPERTIES_MODULE_NAME #language en-US -"CPU Architectural and CPU Multi-processor DXE Driver" - - +"CPU Architectural and CPU Multi-processor DXE library" diff --git a/UefiCpuPkg/Library/CpuArchLib/CpuDxeNull.c b/UefiCpuPkg/Library/CpuArchLib/CpuDxeNull.c new file mode 100644 index 0000000000..d61890e05b --- /dev/null +++ b/UefiCpuPkg/Library/CpuArchLib/CpuDxeNull.c @@ -0,0 +1,25 @@ +/** + Initialize the state information for the CPU Architectural Protocol. + + @retval EFI_SUCCESS Thread can be successfully created + @retval EFI_OUT_OF_RESOURCES Can not allocate protocol data structure + @retval EFI_DEVICE_ERROR Can not create the thread +**/ +EFI_STATUS +InitializeCpu ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + Initialize Multi-processor support. + +**/ +VOID +InitializeMpSupport ( + VOID + ) +{ +} diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/Library/CpuArchLib/CpuGdt.c similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuGdt.c rename to UefiCpuPkg/Library/CpuArchLib/CpuGdt.c diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/Library/CpuArchLib/CpuGdt.h similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuGdt.h rename to UefiCpuPkg/Library/CpuArchLib/CpuGdt.h diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/Library/CpuArchLib/CpuMp.c similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuMp.c rename to UefiCpuPkg/Library/CpuArchLib/CpuMp.c diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/Library/CpuArchLib/CpuMp.h similarity index 97% rename from UefiCpuPkg/CpuDxe/CpuMp.h rename to UefiCpuPkg/Library/CpuArchLib/CpuMp.h index b461753510..c42a617bcf 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.h +++ b/UefiCpuPkg/Library/CpuArchLib/CpuMp.h @@ -9,15 +9,6 @@ #ifndef _CPU_MP_H_ #define _CPU_MP_H_ -/** - Initialize Multi-processor support. - -**/ -VOID -InitializeMpSupport ( - VOID - ); - /** This service retrieves the number of logical processor in the platform and the number of those logical processors that are enabled on this boot. diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/Library/CpuArchLib/CpuPageTable.c similarity index 96% rename from UefiCpuPkg/CpuDxe/CpuPageTable.c rename to UefiCpuPkg/Library/CpuArchLib/CpuPageTable.c index 6a3f1f34ed..375eb6e4aa 100644 --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c +++ b/UefiCpuPkg/Library/CpuArchLib/CpuPageTable.c @@ -90,13 +90,13 @@ PAGE_ATTRIBUTE_TABLE mPageAttributeTable[] = { PAGE_TABLE_POOL *mPageTablePool = NULL; BOOLEAN mPageTablePoolLock = FALSE; PAGE_TABLE_LIB_PAGING_CONTEXT mPagingContext; -EFI_SMM_BASE2_PROTOCOL *mSmmBase2 = NULL; +EFI_SMM_BASE2_PROTOCOL *mSmmBase2 = NULL; // // Record the page fault exception count for one instruction execution. // UINTN *mPFEntryCount; -UINT64 *(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT]; +UINT64 *(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT]; /** Check if current execution environment is in SMM mode or not, via @@ -308,9 +308,9 @@ GetPageTableEntry ( // Make sure AddressEncMask is contained to smallest supported address field. // - AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; + AddressEncMask = mPlatformInfoHob2->PteMemoryEncryptionAddressOrMask & PAGING_1G_ADDRESS_MASK_64; if (AddressEncMask == 0) { - AddressEncMask = PcdGet64 (PcdTdxSharedBitMask) & PAGING_1G_ADDRESS_MASK_64; + AddressEncMask = mPlatformInfoHob2->PcdTdxSharedBitMask & PAGING_1G_ADDRESS_MASK_64; } if (PagingContext->MachineType == IMAGE_FILE_MACHINE_X64) { @@ -566,7 +566,7 @@ SplitPage ( // Make sure AddressEncMask is contained to smallest supported address field. // - AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; + AddressEncMask = mPlatformInfoHob2->PteMemoryEncryptionAddressOrMask & PAGING_1G_ADDRESS_MASK_64; if (PageAttribute == Page2M) { // diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.h b/UefiCpuPkg/Library/CpuArchLib/CpuPageTable.h similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuPageTable.h rename to UefiCpuPkg/Library/CpuArchLib/CpuPageTable.h diff --git a/UefiCpuPkg/CpuDxe/Ia32/CpuAsm.nasm b/UefiCpuPkg/Library/CpuArchLib/Ia32/CpuAsm.nasm similarity index 100% rename from UefiCpuPkg/CpuDxe/Ia32/CpuAsm.nasm rename to UefiCpuPkg/Library/CpuArchLib/Ia32/CpuAsm.nasm diff --git a/UefiCpuPkg/CpuDxe/Ia32/PagingAttribute.c b/UefiCpuPkg/Library/CpuArchLib/Ia32/PagingAttribute.c similarity index 100% rename from UefiCpuPkg/CpuDxe/Ia32/PagingAttribute.c rename to UefiCpuPkg/Library/CpuArchLib/Ia32/PagingAttribute.c diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.c b/UefiCpuPkg/Library/CpuArchLib/LoongArch64/CpuDxe.c similarity index 100% rename from UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.c rename to UefiCpuPkg/Library/CpuArchLib/LoongArch64/CpuDxe.c diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.h b/UefiCpuPkg/Library/CpuArchLib/LoongArch64/CpuDxe.h similarity index 100% rename from UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.h rename to UefiCpuPkg/Library/CpuArchLib/LoongArch64/CpuDxe.h diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/CpuMp.c b/UefiCpuPkg/Library/CpuArchLib/LoongArch64/CpuMp.c similarity index 100% rename from UefiCpuPkg/CpuDxe/LoongArch64/CpuMp.c rename to UefiCpuPkg/Library/CpuArchLib/LoongArch64/CpuMp.c diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/Exception.c b/UefiCpuPkg/Library/CpuArchLib/LoongArch64/Exception.c similarity index 100% rename from UefiCpuPkg/CpuDxe/LoongArch64/Exception.c rename to UefiCpuPkg/Library/CpuArchLib/LoongArch64/Exception.c diff --git a/UefiCpuPkg/CpuDxe/X64/CpuAsm.nasm b/UefiCpuPkg/Library/CpuArchLib/X64/CpuAsm.nasm similarity index 100% rename from UefiCpuPkg/CpuDxe/X64/CpuAsm.nasm rename to UefiCpuPkg/Library/CpuArchLib/X64/CpuAsm.nasm diff --git a/UefiCpuPkg/CpuDxe/X64/PagingAttribute.c b/UefiCpuPkg/Library/CpuArchLib/X64/PagingAttribute.c similarity index 100% rename from UefiCpuPkg/CpuDxe/X64/PagingAttribute.c rename to UefiCpuPkg/Library/CpuArchLib/X64/PagingAttribute.c diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf index 922c7b12d3..7a2fd88f50 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -14,7 +14,7 @@ FILE_GUID = B88F7146-9834-4c55-BFAC-481CC0C33736 MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.1 - LIBRARY_CLASS = MpInitLib|DXE_DRIVER + LIBRARY_CLASS = MpInitLib|DXE_DRIVER DXE_CORE # # The following information is for reference only and not required by the build tools. @@ -49,6 +49,7 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] @@ -80,16 +81,13 @@ gEfiEventLegacyBootGuid ## SOMETIMES_CONSUMES ## Event gEdkiiMicrocodePatchHobGuid ## SOMETIMES_CONSUMES ## HOB gGhcbApicIdsGuid ## SOMETIMES_CONSUMES ## HOB + gUefiOvmfPkgPlatformInfoGuid ## CONSUMES ## HOB [Guids.LoongArch64] gProcessorResourceHobGuid ## SOMETIMES_CONSUMES ## HOB [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress ## CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index fdcc21d794..84625c0646 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -9,13 +9,17 @@ **/ #include "MpLib.h" + #include #include +#include + #include -EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID; -EFI_GUID mMpHandOffGuid = MP_HANDOFF_GUID; -EFI_GUID mMpHandOffConfigGuid = MP_HANDOFF_CONFIG_GUID; +EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID; +EFI_GUID mMpHandOffGuid = MP_HANDOFF_GUID; +EFI_GUID mMpHandOffConfigGuid = MP_HANDOFF_CONFIG_GUID; +EFI_HOB_PLATFORM_INFO *mPlatformInfoHob = NULL; RELOCATE_AP_LOOP_ENTRY mReservedApLoop; UINTN mReservedTopOfApStack; @@ -589,7 +593,7 @@ CollectProcessorCount ( // FinishedCount is the number of check-in APs. // CpuMpData->CpuCount = CpuMpData->FinishedCount + 1; - ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + ASSERT (CpuMpData->CpuCount <= mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber); return CpuMpData->CpuCount; } @@ -1151,7 +1155,7 @@ AllocateResetVectorBelow1Mb ( // of processors for calculating the total stack area. // ApResetStackSize = (AP_RESET_STACK_SIZE * - PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber); // // Invoke GetWakeupBuffer a second time to allocate the stack area @@ -1303,7 +1307,7 @@ WakeUpAP ( } if (CpuMpData->InitFlag == ApInitConfig) { - if (PcdGet32 (PcdCpuBootLogicalProcessorNumber) > 0) { + if (mPlatformInfoHob->PcdCpuBootLogicalProcessorNumber > 0) { // // The AP enumeration algorithm below is suitable only when the // platform can tell us the *exact* boot CPU count in advance. @@ -1319,7 +1323,7 @@ WakeUpAP ( // TimedWaitForApFinish ( CpuMpData, - PcdGet32 (PcdCpuBootLogicalProcessorNumber) - 1, + mPlatformInfoHob->PcdCpuBootLogicalProcessorNumber - 1, MAX_UINT32 // approx. 71 minutes ); } else { @@ -1357,7 +1361,7 @@ WakeUpAP ( // TimedWaitForApFinish ( CpuMpData, - PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1, + mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber - 1, PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds) ); @@ -2067,6 +2071,12 @@ MpInitLibInitialize ( UINTN ApResetVectorSizeAbove1Mb; UINTN BackupBufferAddr; UINTN ApIdtBase; + EFI_HOB_GUID_TYPE *GuidHob; + + GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid); + if (GuidHob != NULL) { + mPlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)(GET_GUID_HOB_DATA (GuidHob)); + } FirstMpHandOff = GetNextMpHandOffHob (NULL); if (FirstMpHandOff != NULL) { @@ -2086,7 +2096,7 @@ MpInitLibInitialize ( MaxLogicalProcessorNumber += MpHandOff->CpuCount; } } else { - MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + MaxLogicalProcessorNumber = mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber; } ASSERT (MaxLogicalProcessorNumber != 0); @@ -2170,7 +2180,7 @@ MpInitLibInitialize ( CpuMpData->SevEsIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevEs); CpuMpData->SevSnpIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevSnp); CpuMpData->SevEsAPBuffer = (UINTN)-1; - CpuMpData->GhcbBase = PcdGet64 (PcdGhcbBase); + CpuMpData->GhcbBase = mPlatformInfoHob->GhcbBase; CpuMpData->UseSevEsAPMethod = CpuMpData->SevEsIsEnabled && !CpuMpData->SevSnpIsEnabled; if (CpuMpData->SevSnpIsEnabled) { @@ -3342,7 +3352,7 @@ ConfidentialComputingGuestHas ( // // Get the current CC attribute. // - CurrentAttr = PcdGet64 (PcdConfidentialComputingGuestAttr); + CurrentAttr = mPlatformInfoHob->PcdConfidentialComputingGuestAttr; // // If attr is for the AMD group then call AMD specific checks. diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf index d1e8312c02..2dc5e0cc0f 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -49,6 +49,7 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] @@ -70,10 +71,6 @@ CpuPageTableLib [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress ## CONSUMES @@ -91,6 +88,7 @@ gEdkiiMicrocodePatchHobGuid gGhcbApicIdsGuid ## SOMETIMES_CONSUMES gEdkiiEndOfS3ResumeGuid + gUefiOvmfPkgPlatformInfoGuid ## CONSUMES ## HOB [Guids.LoongArch64] gProcessorResourceHobGuid ## SOMETIMES_CONSUMES ## HOB diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 42919debdb..18f01dd7b6 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -76,6 +76,10 @@ ## @libraryclass Provides functions for SMM Relocation Operation. SmmRelocationLib|Include/Library/SmmRelocationLib.h + + ## @libraryclass Installs CPU Architecture Protocol. + ## + CpuArchLib|Include/Library/CpuArchLib.h [LibraryClasses.RISCV64] ## @libraryclass Provides function to initialize the FPU. diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index ff9768375d..66a7082ce5 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -75,6 +75,7 @@ HobLib|MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.inf MemoryAllocationLib|MdeModulePkg/Library/BaseMemoryAllocationLibNull/BaseMemoryAllocationLibNull.inf IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + CpuArchLib|UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf @@ -143,7 +144,6 @@ CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf [Components.IA32, Components.X64] - UefiCpuPkg/CpuDxe/CpuDxe.inf UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf { NULL|UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf @@ -156,8 +156,11 @@ UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf UefiCpuPkg/CpuMpPei/CpuMpPei.inf UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf + UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf + UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf + UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf @@ -176,9 +179,7 @@ UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf - UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf UefiCpuPkg/Library/TdxMeasurementLibNull/TdxMeasurementLibNull.inf - UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf UefiCpuPkg/SecCore/SecCore.inf diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 931e5461c2..98ea4774b9 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -382,6 +382,8 @@ !if $(PERFORMANCE_MEASUREMENT_ENABLE) PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf !endif + CpuArchLib|UefiCpuPkg/Library/CpuArchLib/CpuArchLib.inf + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -726,6 +728,9 @@ SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf !endif NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf + DxeServicesTableLib|MdeModulePkg/Library/DxeCoreDxeServicesTableLib/DxeCoreDxeServicesTableLib.inf + UefiBootServicesTableLib|MdeModulePkg/Library/DxeCoreUefiBootServicesTableLib/DxeCoreUefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeCoreUefiRuntimeServicesTableLib/DxeCoreUefiRuntimeServicesTableLib.inf } # @@ -744,7 +749,6 @@ SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf !endif - UefiCpuPkg/CpuDxe/CpuDxe.inf MdeModulePkg/Universal/BdsDxe/BdsDxe.inf !if $(BOOTSPLASH_IMAGE) MdeModulePkg/Logo/LogoDxe.inf diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayloadPkg.fdf index 283df03ac4..71ca5254e6 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.fdf +++ b/UefiPayloadPkg/UefiPayloadPkg.fdf @@ -161,7 +161,6 @@ INF CryptoPkg/Driver/CryptoDxe.inf !if $(SECURITY_STUB_ENABLE) == TRUE INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf !endif -INF UefiCpuPkg/CpuDxe/CpuDxe.inf !if $(TIMER_SUPPORT) == "HPET" INF PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf