summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Core/RuntimeDxe
diff options
context:
space:
mode:
authorkx <kx@radix.pro>2024-06-04 06:43:08 +0300
committerkx <kx@radix.pro>2024-06-04 06:43:08 +0300
commit7e2ccccace24636f29ddc210b94606abd4c7e42b (patch)
tree545d43ea12671048956cafeb12303e84d601e571 /MdeModulePkg/Core/RuntimeDxe
parent27b044605cd5f6b33a3d231576003850b3fe305b (diff)
downloadedk2-trunk.tar.xz
Renormalized end-of-lines from master@27b044605cd5f6b33a3d231576003850b3fe305btrunk
Diffstat (limited to 'MdeModulePkg/Core/RuntimeDxe')
-rw-r--r--MdeModulePkg/Core/RuntimeDxe/Crc32.c88
-rw-r--r--MdeModulePkg/Core/RuntimeDxe/Runtime.c872
-rw-r--r--MdeModulePkg/Core/RuntimeDxe/Runtime.h254
-rw-r--r--MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf120
-rw-r--r--MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.uni36
-rw-r--r--MdeModulePkg/Core/RuntimeDxe/RuntimeDxeExtra.uni28
6 files changed, 699 insertions, 699 deletions
diff --git a/MdeModulePkg/Core/RuntimeDxe/Crc32.c b/MdeModulePkg/Core/RuntimeDxe/Crc32.c
index fa3e0decdb..699f30f081 100644
--- a/MdeModulePkg/Core/RuntimeDxe/Crc32.c
+++ b/MdeModulePkg/Core/RuntimeDxe/Crc32.c
@@ -1,44 +1,44 @@
-/** @file
- This file implements CalculateCrc32 Boot Services as defined in
- Platform Initialization specification 1.0 VOLUME 2 DXE Core Interface.
-
- This Boot Services is in the Runtime Driver because this service is
- also required by SetVirtualAddressMap() when the EFI System Table and
- EFI Runtime Services Table are converted from physical address to
- virtual addresses. This requires that the 32-bit CRC be recomputed.
-
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include <Uefi.h>
-#include <Library/BaseLib.h>
-
-/**
- Calculate CRC32 for target data.
-
- @param Data The target data.
- @param DataSize The target data size.
- @param CrcOut The CRC32 for target data.
-
- @retval EFI_SUCCESS The CRC32 for target data is calculated successfully.
- @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not
- calculated.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverCalculateCrc32 (
- IN VOID *Data,
- IN UINTN DataSize,
- OUT UINT32 *CrcOut
- )
-{
- if ((Data == NULL) || (DataSize == 0) || (CrcOut == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- *CrcOut = CalculateCrc32 (Data, DataSize);
- return EFI_SUCCESS;
-}
+/** @file
+ This file implements CalculateCrc32 Boot Services as defined in
+ Platform Initialization specification 1.0 VOLUME 2 DXE Core Interface.
+
+ This Boot Services is in the Runtime Driver because this service is
+ also required by SetVirtualAddressMap() when the EFI System Table and
+ EFI Runtime Services Table are converted from physical address to
+ virtual addresses. This requires that the 32-bit CRC be recomputed.
+
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+
+/**
+ Calculate CRC32 for target data.
+
+ @param Data The target data.
+ @param DataSize The target data size.
+ @param CrcOut The CRC32 for target data.
+
+ @retval EFI_SUCCESS The CRC32 for target data is calculated successfully.
+ @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not
+ calculated.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverCalculateCrc32 (
+ IN VOID *Data,
+ IN UINTN DataSize,
+ OUT UINT32 *CrcOut
+ )
+{
+ if ((Data == NULL) || (DataSize == 0) || (CrcOut == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *CrcOut = CalculateCrc32 (Data, DataSize);
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Core/RuntimeDxe/Runtime.c b/MdeModulePkg/Core/RuntimeDxe/Runtime.c
index c66ed71e35..b9bc67b0c3 100644
--- a/MdeModulePkg/Core/RuntimeDxe/Runtime.c
+++ b/MdeModulePkg/Core/RuntimeDxe/Runtime.c
@@ -1,436 +1,436 @@
-/** @file
- This file implements Runtime Architectural Protocol as defined in the
- Platform Initialization specification 1.0 VOLUME 2 DXE Core Interface.
-
- This code is used to produce the EFI runtime virtual switch over
-
- THIS IS VERY DANGEROUS CODE BE VERY CAREFUL IF YOU CHANGE IT
-
- The transition for calling EFI Runtime functions in physical mode to calling
- them in virtual mode is very very complex. Every pointer in needs to be
- converted from physical mode to virtual mode. Be very careful walking linked
- lists! Then to make it really hard the code it's self needs be relocated into
- the new virtual address space.
-
- So here is the concept. The code in this module will never ever be called in
- virtual mode. This is the code that collects the information needed to convert
- to virtual mode (DXE core registers runtime stuff with this code). Since this
- code is used to fix up all runtime images, it CAN NOT fix it's self up. So some
- code has to stay behind and that is us.
-
- Also you need to be careful about when you allocate memory, as once we are in
- runtime (including our EVT_SIGNAL_EXIT_BOOT_SERVICES event) you can no longer
- allocate memory.
-
- Any runtime driver that gets loaded before us will not be callable in virtual
- mode. This is due to the fact that the DXE core can not register the info
- needed with us. This is good, since it keeps the code in this file from
- getting registered.
-
-
-Revision History:
-
- - Move the CalculateCrc32 function from Runtime Arch Protocol to Boot Service.
- Runtime Arch Protocol definition no longer contains CalculateCrc32. Boot Service
- Table now contains an item named CalculateCrc32.
-
-
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "Runtime.h"
-
-//
-// Global Variables
-//
-EFI_MEMORY_DESCRIPTOR *mVirtualMap = NULL;
-UINTN mVirtualMapDescriptorSize;
-UINTN mVirtualMapMaxIndex;
-VOID *mMyImageBase;
-
-//
-// The handle onto which the Runtime Architectural Protocol instance is installed
-//
-EFI_HANDLE mRuntimeHandle = NULL;
-
-//
-// The Runtime Architectural Protocol instance produced by this driver
-//
-EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {
- INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.ImageHead),
- INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.EventHead),
-
- //
- // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will
- // prevent people from having pointer math bugs in their code.
- // now you have to use *DescriptorSize to make things work.
- //
- sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),
- EFI_MEMORY_DESCRIPTOR_VERSION,
- 0,
- NULL,
- NULL,
- FALSE,
- FALSE
-};
-
-//
-// Worker Functions
-//
-
-/**
-
- Calculate the 32-bit CRC in a EFI table using the Runtime Drivers
- internal function. The EFI Boot Services Table can not be used because
- the EFI Boot Services Table was destroyed at ExitBootServices().
- This is a internal function.
-
-
- @param Hdr Pointer to an EFI standard header
-
-**/
-VOID
-RuntimeDriverCalculateEfiHdrCrc (
- IN OUT EFI_TABLE_HEADER *Hdr
- )
-{
- UINT32 Crc;
-
- Hdr->CRC32 = 0;
-
- Crc = 0;
- RuntimeDriverCalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
- Hdr->CRC32 = Crc;
-}
-
-/**
-
- Determines the new virtual address that is to be used on subsequent memory accesses.
-
-
- @param DebugDisposition Supplies type information for the pointer being converted.
- @param ConvertAddress A pointer to a pointer that is to be fixed to be the value needed
- for the new virtual address mappings being applied.
-
- @retval EFI_SUCCESS The pointer pointed to by Address was modified.
- @retval EFI_NOT_FOUND The pointer pointed to by Address was not found to be part
- of the current memory map. This is normally fatal.
- @retval EFI_INVALID_PARAMETER 1) Address is NULL.
- 2) *Address is NULL and DebugDisposition does
- not have the EFI_OPTIONAL_PTR bit set.
- @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
- The platform should describe this runtime service as unsupported at runtime
- via an EFI_RT_PROPERTIES_TABLE configuration table.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverConvertPointer (
- IN UINTN DebugDisposition,
- IN OUT VOID **ConvertAddress
- )
-{
- UINTN Address;
- UINT64 VirtEndOfRange;
- EFI_MEMORY_DESCRIPTOR *VirtEntry;
- UINTN Index;
-
- //
- // Make sure ConvertAddress is a valid pointer
- //
- if (ConvertAddress == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Get the address to convert
- //
- Address = (UINTN)*ConvertAddress;
-
- //
- // If this is a null pointer, return if it's allowed
- //
- if (Address == 0) {
- if ((DebugDisposition & EFI_OPTIONAL_PTR) != 0) {
- return EFI_SUCCESS;
- }
-
- return EFI_INVALID_PARAMETER;
- }
-
- VirtEntry = mVirtualMap;
- for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {
- //
- // To prevent the inclusion of 64-bit math functions a UINTN was placed in
- // front of VirtEntry->NumberOfPages to cast it to a 32-bit thing on IA-32
- // platforms. If you get this ASSERT remove the UINTN and do a 64-bit
- // multiply.
- //
- ASSERT (((UINTN)VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));
-
- if ((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {
- if (Address >= VirtEntry->PhysicalStart) {
- VirtEndOfRange = VirtEntry->PhysicalStart + (((UINTN)VirtEntry->NumberOfPages) * EFI_PAGE_SIZE);
- if (Address < VirtEndOfRange) {
- //
- // Compute new address
- //
- *ConvertAddress = (VOID *)(Address - (UINTN)VirtEntry->PhysicalStart + (UINTN)VirtEntry->VirtualStart);
- return EFI_SUCCESS;
- }
- }
- }
-
- VirtEntry = NEXT_MEMORY_DESCRIPTOR (VirtEntry, mVirtualMapDescriptorSize);
- }
-
- return EFI_NOT_FOUND;
-}
-
-/**
-
- Determines the new virtual address that is to be used on subsequent memory accesses
- for internal pointers.
- This is a internal function.
-
-
- @param ConvertAddress A pointer to a pointer that is to be fixed to be the value needed
- for the new virtual address mappings being applied.
-
- @retval EFI_SUCCESS The pointer pointed to by Address was modified.
- @retval EFI_NOT_FOUND The pointer pointed to by Address was not found to be part
- of the current memory map. This is normally fatal.
- @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
-
-**/
-EFI_STATUS
-RuntimeDriverConvertInternalPointer (
- IN OUT VOID **ConvertAddress
- )
-{
- return RuntimeDriverConvertPointer (0x0, ConvertAddress);
-}
-
-/**
-
- Changes the runtime addressing mode of EFI firmware from physical to virtual.
-
-
- @param MemoryMapSize The size in bytes of VirtualMap.
- @param DescriptorSize The size in bytes of an entry in the VirtualMap.
- @param DescriptorVersion The version of the structure entries in VirtualMap.
- @param VirtualMap An array of memory descriptors which contain new virtual
- address mapping information for all runtime ranges.
-
- @retval EFI_SUCCESS The virtual address map has been applied.
- @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
- virtual address mapped mode.
- @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is invalid.
- @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
- map that requires a mapping.
- @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
- in the memory map.
- @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
- The platform should describe this runtime service as unsupported at runtime
- via an EFI_RT_PROPERTIES_TABLE configuration table.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverSetVirtualAddressMap (
- IN UINTN MemoryMapSize,
- IN UINTN DescriptorSize,
- IN UINT32 DescriptorVersion,
- IN EFI_MEMORY_DESCRIPTOR *VirtualMap
- )
-{
- EFI_STATUS Status;
- EFI_RUNTIME_EVENT_ENTRY *RuntimeEvent;
- EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
- LIST_ENTRY *Link;
- EFI_PHYSICAL_ADDRESS VirtImageBase;
-
- //
- // Can only switch to virtual addresses once the memory map is locked down,
- // and can only set it once
- //
- if (!mRuntime.AtRuntime || mRuntime.VirtualMode) {
- return EFI_UNSUPPORTED;
- }
-
- //
- // Only understand the original descriptor format
- //
- if ((DescriptorVersion != EFI_MEMORY_DESCRIPTOR_VERSION) || (DescriptorSize < sizeof (EFI_MEMORY_DESCRIPTOR))) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // We are now committed to go to virtual mode, so lets get to it!
- //
- mRuntime.VirtualMode = TRUE;
-
- //
- // ConvertPointer() needs this mVirtualMap to do the conversion. So set up
- // globals we need to parse the virtual address map.
- //
- mVirtualMapDescriptorSize = DescriptorSize;
- mVirtualMapMaxIndex = MemoryMapSize / DescriptorSize;
- mVirtualMap = VirtualMap;
-
- //
- // ReporstStatusCodeLib will check and make sure this service can be called in runtime mode.
- //
- REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_SET_VIRTUAL_ADDRESS_MAP));
-
- //
- // Report Status Code here since EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event will be signalled.
- //
- REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_VIRTUAL_ADDRESS_CHANGE_EVENT));
-
- //
- // Signal all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE events.
- // All runtime events are stored in a list in Runtime AP.
- //
- for (Link = mRuntime.EventHead.ForwardLink; Link != &mRuntime.EventHead; Link = Link->ForwardLink) {
- RuntimeEvent = BASE_CR (Link, EFI_RUNTIME_EVENT_ENTRY, Link);
- if ((RuntimeEvent->Type & EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {
- //
- // Work around the bug in the Platform Init specification (v1.7),
- // reported as Mantis#2017: "EFI_RUNTIME_EVENT_ENTRY.Event" should have
- // type EFI_EVENT, not (EFI_EVENT*). The PI spec documents the field
- // correctly as "The EFI_EVENT returned by CreateEvent()", but the type
- // of the field doesn't match the natural language description. Therefore
- // we need an explicit cast here.
- //
- RuntimeEvent->NotifyFunction (
- (EFI_EVENT)RuntimeEvent->Event,
- RuntimeEvent->NotifyContext
- );
- }
- }
-
- //
- // Relocate runtime images. All runtime images are stored in a list in Runtime AP.
- //
- for (Link = mRuntime.ImageHead.ForwardLink; Link != &mRuntime.ImageHead; Link = Link->ForwardLink) {
- RuntimeImage = BASE_CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link);
- //
- // We don't want to relocate our selves, as we only run in physical mode.
- //
- if (mMyImageBase != RuntimeImage->ImageBase) {
- VirtImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase;
- Status = RuntimeDriverConvertPointer (0, (VOID **)&VirtImageBase);
- ASSERT_EFI_ERROR (Status);
-
- PeCoffLoaderRelocateImageForRuntime (
- (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase,
- VirtImageBase,
- (UINTN)RuntimeImage->ImageSize,
- RuntimeImage->RelocationData
- );
-
- InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN)RuntimeImage->ImageSize);
- }
- }
-
- //
- // Convert all the Runtime Services except ConvertPointer() and SetVirtualAddressMap()
- // and recompute the CRC-32
- //
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetTime);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetTime);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetWakeupTime);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetWakeupTime);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->ResetSystem);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetNextHighMonotonicCount);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetVariable);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetVariable);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetNextVariableName);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->QueryVariableInfo);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->UpdateCapsule);
- RuntimeDriverConvertInternalPointer ((VOID **)&gRT->QueryCapsuleCapabilities);
- RuntimeDriverCalculateEfiHdrCrc (&gRT->Hdr);
-
- //
- // UEFI don't require System Configuration Tables Conversion.
- //
-
- //
- // Convert the runtime fields of the EFI System Table and recompute the CRC-32
- //
- RuntimeDriverConvertInternalPointer ((VOID **)&gST->FirmwareVendor);
- RuntimeDriverConvertInternalPointer ((VOID **)&gST->ConfigurationTable);
- RuntimeDriverConvertInternalPointer ((VOID **)&gST->RuntimeServices);
- RuntimeDriverCalculateEfiHdrCrc (&gST->Hdr);
-
- //
- // At this point, gRT and gST are physical pointers, but the contents of these tables
- // have been converted to runtime.
- //
- //
- // mVirtualMap is only valid during SetVirtualAddressMap() call
- //
- mVirtualMap = NULL;
- mVirtualMapMaxIndex = 0;
-
- return EFI_SUCCESS;
-}
-
-/**
- Entry Point for Runtime driver.
-
- This function installs Runtime Architectural Protocol and registers CalculateCrc32 boot services table,
- SetVirtualAddressMap & ConvertPointer runtime services table.
-
- @param ImageHandle Image handle of this driver.
- @param SystemTable a Pointer to the EFI System Table.
-
- @retval EFI_SUCEESS Runtime Driver Architectural Protocol is successfully installed
- @return Others Some error occurs when installing Runtime Driver Architectural Protocol.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
- EFI_LOADED_IMAGE_PROTOCOL *MyLoadedImage;
-
- //
- // This image needs to be excluded from relocation for virtual mode, so cache
- // a copy of the Loaded Image protocol to test later.
- //
- Status = gBS->HandleProtocol (
- ImageHandle,
- &gEfiLoadedImageProtocolGuid,
- (VOID **)&MyLoadedImage
- );
- ASSERT_EFI_ERROR (Status);
- mMyImageBase = MyLoadedImage->ImageBase;
-
- //
- // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables
- //
- gBS->CalculateCrc32 = RuntimeDriverCalculateCrc32;
- gRT->SetVirtualAddressMap = RuntimeDriverSetVirtualAddressMap;
- gRT->ConvertPointer = RuntimeDriverConvertPointer;
-
- //
- // Install the Runtime Architectural Protocol onto a new handle
- //
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mRuntimeHandle,
- &gEfiRuntimeArchProtocolGuid,
- &mRuntime,
- NULL
- );
- ASSERT_EFI_ERROR (Status);
-
- return Status;
-}
+/** @file
+ This file implements Runtime Architectural Protocol as defined in the
+ Platform Initialization specification 1.0 VOLUME 2 DXE Core Interface.
+
+ This code is used to produce the EFI runtime virtual switch over
+
+ THIS IS VERY DANGEROUS CODE BE VERY CAREFUL IF YOU CHANGE IT
+
+ The transition for calling EFI Runtime functions in physical mode to calling
+ them in virtual mode is very very complex. Every pointer in needs to be
+ converted from physical mode to virtual mode. Be very careful walking linked
+ lists! Then to make it really hard the code it's self needs be relocated into
+ the new virtual address space.
+
+ So here is the concept. The code in this module will never ever be called in
+ virtual mode. This is the code that collects the information needed to convert
+ to virtual mode (DXE core registers runtime stuff with this code). Since this
+ code is used to fix up all runtime images, it CAN NOT fix it's self up. So some
+ code has to stay behind and that is us.
+
+ Also you need to be careful about when you allocate memory, as once we are in
+ runtime (including our EVT_SIGNAL_EXIT_BOOT_SERVICES event) you can no longer
+ allocate memory.
+
+ Any runtime driver that gets loaded before us will not be callable in virtual
+ mode. This is due to the fact that the DXE core can not register the info
+ needed with us. This is good, since it keeps the code in this file from
+ getting registered.
+
+
+Revision History:
+
+ - Move the CalculateCrc32 function from Runtime Arch Protocol to Boot Service.
+ Runtime Arch Protocol definition no longer contains CalculateCrc32. Boot Service
+ Table now contains an item named CalculateCrc32.
+
+
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Runtime.h"
+
+//
+// Global Variables
+//
+EFI_MEMORY_DESCRIPTOR *mVirtualMap = NULL;
+UINTN mVirtualMapDescriptorSize;
+UINTN mVirtualMapMaxIndex;
+VOID *mMyImageBase;
+
+//
+// The handle onto which the Runtime Architectural Protocol instance is installed
+//
+EFI_HANDLE mRuntimeHandle = NULL;
+
+//
+// The Runtime Architectural Protocol instance produced by this driver
+//
+EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {
+ INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.ImageHead),
+ INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.EventHead),
+
+ //
+ // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will
+ // prevent people from having pointer math bugs in their code.
+ // now you have to use *DescriptorSize to make things work.
+ //
+ sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),
+ EFI_MEMORY_DESCRIPTOR_VERSION,
+ 0,
+ NULL,
+ NULL,
+ FALSE,
+ FALSE
+};
+
+//
+// Worker Functions
+//
+
+/**
+
+ Calculate the 32-bit CRC in a EFI table using the Runtime Drivers
+ internal function. The EFI Boot Services Table can not be used because
+ the EFI Boot Services Table was destroyed at ExitBootServices().
+ This is a internal function.
+
+
+ @param Hdr Pointer to an EFI standard header
+
+**/
+VOID
+RuntimeDriverCalculateEfiHdrCrc (
+ IN OUT EFI_TABLE_HEADER *Hdr
+ )
+{
+ UINT32 Crc;
+
+ Hdr->CRC32 = 0;
+
+ Crc = 0;
+ RuntimeDriverCalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
+ Hdr->CRC32 = Crc;
+}
+
+/**
+
+ Determines the new virtual address that is to be used on subsequent memory accesses.
+
+
+ @param DebugDisposition Supplies type information for the pointer being converted.
+ @param ConvertAddress A pointer to a pointer that is to be fixed to be the value needed
+ for the new virtual address mappings being applied.
+
+ @retval EFI_SUCCESS The pointer pointed to by Address was modified.
+ @retval EFI_NOT_FOUND The pointer pointed to by Address was not found to be part
+ of the current memory map. This is normally fatal.
+ @retval EFI_INVALID_PARAMETER 1) Address is NULL.
+ 2) *Address is NULL and DebugDisposition does
+ not have the EFI_OPTIONAL_PTR bit set.
+ @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
+ The platform should describe this runtime service as unsupported at runtime
+ via an EFI_RT_PROPERTIES_TABLE configuration table.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverConvertPointer (
+ IN UINTN DebugDisposition,
+ IN OUT VOID **ConvertAddress
+ )
+{
+ UINTN Address;
+ UINT64 VirtEndOfRange;
+ EFI_MEMORY_DESCRIPTOR *VirtEntry;
+ UINTN Index;
+
+ //
+ // Make sure ConvertAddress is a valid pointer
+ //
+ if (ConvertAddress == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Get the address to convert
+ //
+ Address = (UINTN)*ConvertAddress;
+
+ //
+ // If this is a null pointer, return if it's allowed
+ //
+ if (Address == 0) {
+ if ((DebugDisposition & EFI_OPTIONAL_PTR) != 0) {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_INVALID_PARAMETER;
+ }
+
+ VirtEntry = mVirtualMap;
+ for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {
+ //
+ // To prevent the inclusion of 64-bit math functions a UINTN was placed in
+ // front of VirtEntry->NumberOfPages to cast it to a 32-bit thing on IA-32
+ // platforms. If you get this ASSERT remove the UINTN and do a 64-bit
+ // multiply.
+ //
+ ASSERT (((UINTN)VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));
+
+ if ((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {
+ if (Address >= VirtEntry->PhysicalStart) {
+ VirtEndOfRange = VirtEntry->PhysicalStart + (((UINTN)VirtEntry->NumberOfPages) * EFI_PAGE_SIZE);
+ if (Address < VirtEndOfRange) {
+ //
+ // Compute new address
+ //
+ *ConvertAddress = (VOID *)(Address - (UINTN)VirtEntry->PhysicalStart + (UINTN)VirtEntry->VirtualStart);
+ return EFI_SUCCESS;
+ }
+ }
+ }
+
+ VirtEntry = NEXT_MEMORY_DESCRIPTOR (VirtEntry, mVirtualMapDescriptorSize);
+ }
+
+ return EFI_NOT_FOUND;
+}
+
+/**
+
+ Determines the new virtual address that is to be used on subsequent memory accesses
+ for internal pointers.
+ This is a internal function.
+
+
+ @param ConvertAddress A pointer to a pointer that is to be fixed to be the value needed
+ for the new virtual address mappings being applied.
+
+ @retval EFI_SUCCESS The pointer pointed to by Address was modified.
+ @retval EFI_NOT_FOUND The pointer pointed to by Address was not found to be part
+ of the current memory map. This is normally fatal.
+ @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
+
+**/
+EFI_STATUS
+RuntimeDriverConvertInternalPointer (
+ IN OUT VOID **ConvertAddress
+ )
+{
+ return RuntimeDriverConvertPointer (0x0, ConvertAddress);
+}
+
+/**
+
+ Changes the runtime addressing mode of EFI firmware from physical to virtual.
+
+
+ @param MemoryMapSize The size in bytes of VirtualMap.
+ @param DescriptorSize The size in bytes of an entry in the VirtualMap.
+ @param DescriptorVersion The version of the structure entries in VirtualMap.
+ @param VirtualMap An array of memory descriptors which contain new virtual
+ address mapping information for all runtime ranges.
+
+ @retval EFI_SUCCESS The virtual address map has been applied.
+ @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
+ virtual address mapped mode.
+ @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is invalid.
+ @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
+ map that requires a mapping.
+ @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
+ in the memory map.
+ @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
+ The platform should describe this runtime service as unsupported at runtime
+ via an EFI_RT_PROPERTIES_TABLE configuration table.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverSetVirtualAddressMap (
+ IN UINTN MemoryMapSize,
+ IN UINTN DescriptorSize,
+ IN UINT32 DescriptorVersion,
+ IN EFI_MEMORY_DESCRIPTOR *VirtualMap
+ )
+{
+ EFI_STATUS Status;
+ EFI_RUNTIME_EVENT_ENTRY *RuntimeEvent;
+ EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
+ LIST_ENTRY *Link;
+ EFI_PHYSICAL_ADDRESS VirtImageBase;
+
+ //
+ // Can only switch to virtual addresses once the memory map is locked down,
+ // and can only set it once
+ //
+ if (!mRuntime.AtRuntime || mRuntime.VirtualMode) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Only understand the original descriptor format
+ //
+ if ((DescriptorVersion != EFI_MEMORY_DESCRIPTOR_VERSION) || (DescriptorSize < sizeof (EFI_MEMORY_DESCRIPTOR))) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // We are now committed to go to virtual mode, so lets get to it!
+ //
+ mRuntime.VirtualMode = TRUE;
+
+ //
+ // ConvertPointer() needs this mVirtualMap to do the conversion. So set up
+ // globals we need to parse the virtual address map.
+ //
+ mVirtualMapDescriptorSize = DescriptorSize;
+ mVirtualMapMaxIndex = MemoryMapSize / DescriptorSize;
+ mVirtualMap = VirtualMap;
+
+ //
+ // ReporstStatusCodeLib will check and make sure this service can be called in runtime mode.
+ //
+ REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_SET_VIRTUAL_ADDRESS_MAP));
+
+ //
+ // Report Status Code here since EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event will be signalled.
+ //
+ REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_VIRTUAL_ADDRESS_CHANGE_EVENT));
+
+ //
+ // Signal all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE events.
+ // All runtime events are stored in a list in Runtime AP.
+ //
+ for (Link = mRuntime.EventHead.ForwardLink; Link != &mRuntime.EventHead; Link = Link->ForwardLink) {
+ RuntimeEvent = BASE_CR (Link, EFI_RUNTIME_EVENT_ENTRY, Link);
+ if ((RuntimeEvent->Type & EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {
+ //
+ // Work around the bug in the Platform Init specification (v1.7),
+ // reported as Mantis#2017: "EFI_RUNTIME_EVENT_ENTRY.Event" should have
+ // type EFI_EVENT, not (EFI_EVENT*). The PI spec documents the field
+ // correctly as "The EFI_EVENT returned by CreateEvent()", but the type
+ // of the field doesn't match the natural language description. Therefore
+ // we need an explicit cast here.
+ //
+ RuntimeEvent->NotifyFunction (
+ (EFI_EVENT)RuntimeEvent->Event,
+ RuntimeEvent->NotifyContext
+ );
+ }
+ }
+
+ //
+ // Relocate runtime images. All runtime images are stored in a list in Runtime AP.
+ //
+ for (Link = mRuntime.ImageHead.ForwardLink; Link != &mRuntime.ImageHead; Link = Link->ForwardLink) {
+ RuntimeImage = BASE_CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link);
+ //
+ // We don't want to relocate our selves, as we only run in physical mode.
+ //
+ if (mMyImageBase != RuntimeImage->ImageBase) {
+ VirtImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase;
+ Status = RuntimeDriverConvertPointer (0, (VOID **)&VirtImageBase);
+ ASSERT_EFI_ERROR (Status);
+
+ PeCoffLoaderRelocateImageForRuntime (
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase,
+ VirtImageBase,
+ (UINTN)RuntimeImage->ImageSize,
+ RuntimeImage->RelocationData
+ );
+
+ InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN)RuntimeImage->ImageSize);
+ }
+ }
+
+ //
+ // Convert all the Runtime Services except ConvertPointer() and SetVirtualAddressMap()
+ // and recompute the CRC-32
+ //
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetTime);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetTime);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetWakeupTime);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetWakeupTime);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->ResetSystem);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetNextHighMonotonicCount);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetVariable);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetVariable);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetNextVariableName);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->QueryVariableInfo);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->UpdateCapsule);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gRT->QueryCapsuleCapabilities);
+ RuntimeDriverCalculateEfiHdrCrc (&gRT->Hdr);
+
+ //
+ // UEFI don't require System Configuration Tables Conversion.
+ //
+
+ //
+ // Convert the runtime fields of the EFI System Table and recompute the CRC-32
+ //
+ RuntimeDriverConvertInternalPointer ((VOID **)&gST->FirmwareVendor);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gST->ConfigurationTable);
+ RuntimeDriverConvertInternalPointer ((VOID **)&gST->RuntimeServices);
+ RuntimeDriverCalculateEfiHdrCrc (&gST->Hdr);
+
+ //
+ // At this point, gRT and gST are physical pointers, but the contents of these tables
+ // have been converted to runtime.
+ //
+ //
+ // mVirtualMap is only valid during SetVirtualAddressMap() call
+ //
+ mVirtualMap = NULL;
+ mVirtualMapMaxIndex = 0;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Entry Point for Runtime driver.
+
+ This function installs Runtime Architectural Protocol and registers CalculateCrc32 boot services table,
+ SetVirtualAddressMap & ConvertPointer runtime services table.
+
+ @param ImageHandle Image handle of this driver.
+ @param SystemTable a Pointer to the EFI System Table.
+
+ @retval EFI_SUCEESS Runtime Driver Architectural Protocol is successfully installed
+ @return Others Some error occurs when installing Runtime Driver Architectural Protocol.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE_PROTOCOL *MyLoadedImage;
+
+ //
+ // This image needs to be excluded from relocation for virtual mode, so cache
+ // a copy of the Loaded Image protocol to test later.
+ //
+ Status = gBS->HandleProtocol (
+ ImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **)&MyLoadedImage
+ );
+ ASSERT_EFI_ERROR (Status);
+ mMyImageBase = MyLoadedImage->ImageBase;
+
+ //
+ // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables
+ //
+ gBS->CalculateCrc32 = RuntimeDriverCalculateCrc32;
+ gRT->SetVirtualAddressMap = RuntimeDriverSetVirtualAddressMap;
+ gRT->ConvertPointer = RuntimeDriverConvertPointer;
+
+ //
+ // Install the Runtime Architectural Protocol onto a new handle
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &mRuntimeHandle,
+ &gEfiRuntimeArchProtocolGuid,
+ &mRuntime,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
diff --git a/MdeModulePkg/Core/RuntimeDxe/Runtime.h b/MdeModulePkg/Core/RuntimeDxe/Runtime.h
index 1e28b98d78..f661124f89 100644
--- a/MdeModulePkg/Core/RuntimeDxe/Runtime.h
+++ b/MdeModulePkg/Core/RuntimeDxe/Runtime.h
@@ -1,127 +1,127 @@
-/** @file
- Runtime Architectural Protocol as defined in the DXE CIS.
-
- This code is used to produce the EFI runtime architectural protocol.
-
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _RUNTIME_H_
-#define _RUNTIME_H_
-
-#include <PiDxe.h>
-#include <Protocol/LoadedImage.h>
-#include <Protocol/Runtime.h>
-#include <Library/BaseLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/DebugLib.h>
-#include <Library/ReportStatusCodeLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/CacheMaintenanceLib.h>
-#include <Library/PeCoffLib.h>
-
-//
-// Function Prototypes
-//
-
-/**
- Calculate CRC32 for target data.
-
- @param Data The target data.
- @param DataSize The target data size.
- @param CrcOut The CRC32 for target data.
-
- @retval EFI_SUCCESS The CRC32 for target data is calculated successfully.
- @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not
- calculated.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverCalculateCrc32 (
- IN VOID *Data,
- IN UINTN DataSize,
- OUT UINT32 *CrcOut
- );
-
-/**
- Determines the new virtual address that is to be used on subsequent memory accesses.
-
-
- @param DebugDisposition Supplies type information for the pointer being converted.
- @param ConvertAddress A pointer to a pointer that is to be fixed to be the value needed
- for the new virtual address mappings being applied.
-
- @retval EFI_SUCCESS The pointer pointed to by Address was modified.
- @retval EFI_NOT_FOUND The pointer pointed to by Address was not found to be part
- of the current memory map. This is normally fatal.
- @retval EFI_INVALID_PARAMETER 1) Address is NULL.
- 2) *Address is NULL and DebugDisposition does
- not have the EFI_OPTIONAL_PTR bit set.
- @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
- The platform should describe this runtime service as unsupported at runtime
- via an EFI_RT_PROPERTIES_TABLE configuration table.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverConvertPointer (
- IN UINTN DebugDisposition,
- IN OUT VOID **ConvertAddress
- );
-
-/**
- Changes the runtime addressing mode of EFI firmware from physical to virtual.
-
- @param MemoryMapSize The size in bytes of VirtualMap.
- @param DescriptorSize The size in bytes of an entry in the VirtualMap.
- @param DescriptorVersion The version of the structure entries in VirtualMap.
- @param VirtualMap An array of memory descriptors which contain new virtual
- address mapping information for all runtime ranges.
-
- @retval EFI_SUCCESS The virtual address map has been applied.
- @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
- virtual address mapped mode.
- @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is invalid.
- @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
- map that requires a mapping.
- @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
- in the memory map.
- @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
- The platform should describe this runtime service as unsupported at runtime
- via an EFI_RT_PROPERTIES_TABLE configuration table.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverSetVirtualAddressMap (
- IN UINTN MemoryMapSize,
- IN UINTN DescriptorSize,
- IN UINT32 DescriptorVersion,
- IN EFI_MEMORY_DESCRIPTOR *VirtualMap
- );
-
-/**
- Install Runtime AP. This code includes the EfiRuntimeLib, but it only
- functions at RT in physical mode.
-
- @param ImageHandle Image handle of this driver.
- @param SystemTable Pointer to the EFI System Table.
-
- @retval EFI_SUCEESS Runtime Driver Architectural Protocol Installed
- @return Other value if gBS->InstallMultipleProtocolInterfaces fails. Check
- gBS->InstallMultipleProtocolInterfaces for details.
-
-**/
-EFI_STATUS
-EFIAPI
-RuntimeDriverInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- );
-
-#endif
+/** @file
+ Runtime Architectural Protocol as defined in the DXE CIS.
+
+ This code is used to produce the EFI runtime architectural protocol.
+
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _RUNTIME_H_
+#define _RUNTIME_H_
+
+#include <PiDxe.h>
+#include <Protocol/LoadedImage.h>
+#include <Protocol/Runtime.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/DebugLib.h>
+#include <Library/ReportStatusCodeLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include <Library/CacheMaintenanceLib.h>
+#include <Library/PeCoffLib.h>
+
+//
+// Function Prototypes
+//
+
+/**
+ Calculate CRC32 for target data.
+
+ @param Data The target data.
+ @param DataSize The target data size.
+ @param CrcOut The CRC32 for target data.
+
+ @retval EFI_SUCCESS The CRC32 for target data is calculated successfully.
+ @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not
+ calculated.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverCalculateCrc32 (
+ IN VOID *Data,
+ IN UINTN DataSize,
+ OUT UINT32 *CrcOut
+ );
+
+/**
+ Determines the new virtual address that is to be used on subsequent memory accesses.
+
+
+ @param DebugDisposition Supplies type information for the pointer being converted.
+ @param ConvertAddress A pointer to a pointer that is to be fixed to be the value needed
+ for the new virtual address mappings being applied.
+
+ @retval EFI_SUCCESS The pointer pointed to by Address was modified.
+ @retval EFI_NOT_FOUND The pointer pointed to by Address was not found to be part
+ of the current memory map. This is normally fatal.
+ @retval EFI_INVALID_PARAMETER 1) Address is NULL.
+ 2) *Address is NULL and DebugDisposition does
+ not have the EFI_OPTIONAL_PTR bit set.
+ @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
+ The platform should describe this runtime service as unsupported at runtime
+ via an EFI_RT_PROPERTIES_TABLE configuration table.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverConvertPointer (
+ IN UINTN DebugDisposition,
+ IN OUT VOID **ConvertAddress
+ );
+
+/**
+ Changes the runtime addressing mode of EFI firmware from physical to virtual.
+
+ @param MemoryMapSize The size in bytes of VirtualMap.
+ @param DescriptorSize The size in bytes of an entry in the VirtualMap.
+ @param DescriptorVersion The version of the structure entries in VirtualMap.
+ @param VirtualMap An array of memory descriptors which contain new virtual
+ address mapping information for all runtime ranges.
+
+ @retval EFI_SUCCESS The virtual address map has been applied.
+ @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
+ virtual address mapped mode.
+ @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is invalid.
+ @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
+ map that requires a mapping.
+ @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
+ in the memory map.
+ @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
+ The platform should describe this runtime service as unsupported at runtime
+ via an EFI_RT_PROPERTIES_TABLE configuration table.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverSetVirtualAddressMap (
+ IN UINTN MemoryMapSize,
+ IN UINTN DescriptorSize,
+ IN UINT32 DescriptorVersion,
+ IN EFI_MEMORY_DESCRIPTOR *VirtualMap
+ );
+
+/**
+ Install Runtime AP. This code includes the EfiRuntimeLib, but it only
+ functions at RT in physical mode.
+
+ @param ImageHandle Image handle of this driver.
+ @param SystemTable Pointer to the EFI System Table.
+
+ @retval EFI_SUCEESS Runtime Driver Architectural Protocol Installed
+ @return Other value if gBS->InstallMultipleProtocolInterfaces fails. Check
+ gBS->InstallMultipleProtocolInterfaces for details.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDriverInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+#endif
diff --git a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
index 694c7690fa..56e677b96d 100644
--- a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+++ b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
@@ -1,60 +1,60 @@
-## @file
-# Module that produces EFI runtime virtual switch over services.
-#
-# This runtime module installs Runtime Architectural Protocol and registers
-# CalculateCrc32 boot services table, SetVirtualAddressMap & ConvertPointer
-# runtime services table.
-#
-# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-#
-##
-
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = RuntimeDxe
- MODULE_UNI_FILE = RuntimeDxe.uni
- FILE_GUID = B601F8C4-43B7-4784-95B1-F4226CB40CEE
- MODULE_TYPE = DXE_RUNTIME_DRIVER
- VERSION_STRING = 1.0
-
- ENTRY_POINT = RuntimeDriverInitialize
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 EBC
-#
-
-[Sources]
- Crc32.c
- Runtime.h
- Runtime.c
-
-
-[Packages]
- MdePkg/MdePkg.dec
-
-[LibraryClasses]
- PeCoffLib
- CacheMaintenanceLib
- UefiBootServicesTableLib
- UefiLib
- UefiRuntimeServicesTableLib
- ReportStatusCodeLib
- DebugLib
- UefiDriverEntryPoint
- BaseLib
-
-[Protocols]
- gEfiRuntimeArchProtocolGuid ## PRODUCES
- gEfiLoadedImageProtocolGuid ## CONSUMES
-
-[depex]
- TRUE
-
-[UserExtensions.TianoCore."ExtraFiles"]
- RuntimeDxeExtra.uni
+## @file
+# Module that produces EFI runtime virtual switch over services.
+#
+# This runtime module installs Runtime Architectural Protocol and registers
+# CalculateCrc32 boot services table, SetVirtualAddressMap & ConvertPointer
+# runtime services table.
+#
+# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = RuntimeDxe
+ MODULE_UNI_FILE = RuntimeDxe.uni
+ FILE_GUID = B601F8C4-43B7-4784-95B1-F4226CB40CEE
+ MODULE_TYPE = DXE_RUNTIME_DRIVER
+ VERSION_STRING = 1.0
+
+ ENTRY_POINT = RuntimeDriverInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 EBC
+#
+
+[Sources]
+ Crc32.c
+ Runtime.h
+ Runtime.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ PeCoffLib
+ CacheMaintenanceLib
+ UefiBootServicesTableLib
+ UefiLib
+ UefiRuntimeServicesTableLib
+ ReportStatusCodeLib
+ DebugLib
+ UefiDriverEntryPoint
+ BaseLib
+
+[Protocols]
+ gEfiRuntimeArchProtocolGuid ## PRODUCES
+ gEfiLoadedImageProtocolGuid ## CONSUMES
+
+[depex]
+ TRUE
+
+[UserExtensions.TianoCore."ExtraFiles"]
+ RuntimeDxeExtra.uni
diff --git a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.uni b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.uni
index e5dcf451a7..bd7fe94844 100644
--- a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.uni
+++ b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.uni
@@ -1,18 +1,18 @@
-// /** @file
-// Module that produces EFI runtime virtual switch over services.
-//
-// This runtime module installs Runtime Architectural Protocol and registers
-// CalculateCrc32 boot services table, SetVirtualAddressMap & ConvertPointer
-// runtime services table.
-//
-// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "Module that produces EFI runtime virtual switchover services"
-
-#string STR_MODULE_DESCRIPTION #language en-US "This runtime module installs Runtime Architectural Protocol and registers the CalculateCrc32 boot services table, and SetVirtualAddressMap and ConvertPointer runtime services table."
-
+// /** @file
+// Module that produces EFI runtime virtual switch over services.
+//
+// This runtime module installs Runtime Architectural Protocol and registers
+// CalculateCrc32 boot services table, SetVirtualAddressMap & ConvertPointer
+// runtime services table.
+//
+// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Module that produces EFI runtime virtual switchover services"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This runtime module installs Runtime Architectural Protocol and registers the CalculateCrc32 boot services table, and SetVirtualAddressMap and ConvertPointer runtime services table."
+
diff --git a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxeExtra.uni b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxeExtra.uni
index eca04e74f5..d79c521eaa 100644
--- a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxeExtra.uni
+++ b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxeExtra.uni
@@ -1,14 +1,14 @@
-// /** @file
-// RuntimeDxe Localized Strings and Content
-//
-// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#string STR_PROPERTIES_MODULE_NAME
-#language en-US
-"Core Runtime Services Driver"
-
-
+// /** @file
+// RuntimeDxe Localized Strings and Content
+//
+// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_PROPERTIES_MODULE_NAME
+#language en-US
+"Core Runtime Services Driver"
+
+