]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Merge R8->R9 tracker 5935 and 7080 to update runtime arch protocol to DxeCis 0.91...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 14 Dec 2006 10:14:24 +0000 (10:14 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 14 Dec 2006 10:14:24 +0000 (10:14 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2101 6f19259b-4bc3-4df7-8a09-765794883524

18 files changed:
EdkModulePkg/Core/Dxe/DxeMain.h
EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
EdkModulePkg/Core/Dxe/Event/event.c
EdkModulePkg/Core/Dxe/Event/execdata.c
EdkModulePkg/Core/Dxe/Exec.h
EdkModulePkg/Core/Dxe/Image.h
EdkModulePkg/Core/Dxe/Image/Image.c
EdkModulePkg/Universal/Runtime/RuntimeDxe/Crc32.c
EdkModulePkg/Universal/Runtime/RuntimeDxe/PeHotRelocate.c [deleted file]
EdkModulePkg/Universal/Runtime/RuntimeDxe/Runtime.c
EdkModulePkg/Universal/Runtime/RuntimeDxe/Runtime.h
EdkModulePkg/Universal/Runtime/RuntimeDxe/Runtime.msa
MdePkg/Include/Common/BaseTypes.h
MdePkg/Include/Dxe/ArchProtocol/Runtime.h
MdePkg/Include/Dxe/DxeCis.h
MdePkg/Include/Library/BaseLib.h
MdePkg/MdePkg.spd

index 4ff23f3b0be8df6a2d2126d113451e1df9630ff7..28c805703ae813a5be73e31496e91bfbfe3b4bca 100644 (file)
@@ -130,6 +130,7 @@ extern EFI_LOADED_IMAGE_PROTOCOL                *gDxeCoreLoadedImage;
 extern EFI_MEMORY_TYPE_INFORMATION              gMemoryTypeInformation[EfiMaxMemoryType + 1];\r
 \r
 extern BOOLEAN                                  gDispatcherRunning;\r
+extern EFI_RUNTIME_ARCH_PROTOCOL                gRuntimeTemplate;\r
 \r
 //\r
 // Service Initialization Functions\r
@@ -315,27 +316,6 @@ Returns:
 --*/\r
 ;\r
 \r
-EFI_STATUS\r
-CoreShutdownEventServices (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Register all runtime events to make sure they are still available after ExitBootService.\r
-\r
-Arguments:\r
-\r
-  None\r
-    \r
-Returns:\r
-\r
-  EFI_SUCCESS - Always return success\r
-\r
---*/\r
-;\r
-\r
 EFI_STATUS\r
 CoreInitializeImageServices (\r
   IN  VOID *HobStart\r
@@ -358,27 +338,6 @@ Returns:
 --*/\r
 ;\r
 \r
-EFI_STATUS\r
-CoreShutdownImageServices (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Transfer control of runtime images to runtime service\r
-\r
-Arguments:\r
-\r
-  None\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS       - Function successfully returned\r
-\r
---*/\r
-;\r
-\r
 VOID\r
 CoreNotifyOnArchProtocolInstallation (\r
   VOID\r
index 5e5b95af38bb9e3085cc6dfc665f8950f5190b6b..6b1f084e77bba7fcf568da2ad4c1dc6d6c7955a6 100644 (file)
@@ -157,7 +157,7 @@ EFI_METRONOME_ARCH_PROTOCOL       *gMetronome     = NULL;
 EFI_TIMER_ARCH_PROTOCOL           *gTimer         = NULL;\r
 EFI_BDS_ARCH_PROTOCOL             *gBds           = NULL;\r
 EFI_WATCHDOG_TIMER_ARCH_PROTOCOL  *gWatchdogTimer = NULL;\r
-EFI_RUNTIME_ARCH_PROTOCOL         *gRuntime       = NULL;\r
+\r
 \r
 //\r
 // BugBug: I'n not runtime, but is the PPI?\r
@@ -324,6 +324,26 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
 #endif\r
 };\r
 \r
+EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {\r
+  INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),\r
+  INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),\r
+\r
+  //\r
+  // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will\r
+  // prevent people from having pointer math bugs in their code.\r
+  // now you have to use *DescriptorSize to make things work.\r
+  //\r
+  sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),  \r
+  EFI_MEMORY_DESCRIPTOR_VERSION, \r
+  0,\r
+  NULL,\r
+  NULL,\r
+  FALSE,\r
+  FALSE\r
+};\r
+\r
+EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;\r
+\r
 //\r
 // DXE Core Global Variables for the EFI System Table, Boot Services Table, \r
 // DXE Services Table, and Runtime Services Table\r
@@ -886,11 +906,11 @@ CoreExitBootServices (
 \r
 Routine Description:\r
 \r
-  EFI 1.0 API to terminate Boot Services\r
+  Terminates all boot services.\r
 \r
 Arguments:\r
 \r
-  ImageHandle  - Handle that represents the identity of the calling image\r
+  ImageHandle   - Handle that identifies the exiting image.\r
 \r
   MapKey -Key to the latest memory map.\r
 \r
@@ -926,16 +946,6 @@ Returns:
   //\r
   gCpu->DisableInterrupt (gCpu);\r
 \r
-  //\r
-  // Register Runtime events with the Runtime Architectural Protocol\r
-  //\r
-  CoreShutdownEventServices ();\r
-\r
-  //\r
-  // Register Runtime images with the Runtime Architectural Protocol\r
-  //\r
-  CoreShutdownImageServices ();\r
-\r
   //\r
   // Report that ExitBootServices() has been called\r
   //\r
@@ -964,7 +974,12 @@ Returns:
   //\r
   SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0);\r
   gBS = NULL;\r
-\r
+  \r
+  //\r
+  // Update the AtRuntime field in Runtiem AP.\r
+  //\r
+  gRuntime->AtRuntime = TRUE;\r
+  \r
   return Status;\r
 }\r
 \r
index 0ceb82d2c2fb4d9ea27e85482de27b1dccbe7a9b..a4d653c5aab2d9d998323bf0c7eaa6ada332c6c5 100644 (file)
@@ -128,6 +128,8 @@ Returns:
   ARCHITECTURAL_PROTOCOL_ENTRY    *Entry;\r
   VOID                            *Protocol;\r
   BOOLEAN                         Found;\r
+  LIST_ENTRY                      *Link;\r
+  LIST_ENTRY                      TempLinkNode;\r
 \r
   Found = FALSE;\r
   for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
@@ -160,6 +162,34 @@ Returns:
       // When runtime architectural protocol is available, updates CRC32 in the Debug Table\r
       //\r
       CoreUpdateDebugTableCrc32 ();\r
+\r
+      //\r
+      // Update the Runtime Architectural protocol with the template that the core was\r
+      // using so there would not need to be a dependency on the Runtime AP\r
+      //\r
+\r
+      //\r
+      // Copy all the registered Image to new gRuntime protocol\r
+      //\r
+      for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {\r
+        CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
+        InsertTailList (&gRuntime->ImageHead, Link);\r
+      }\r
+      //\r
+      // Copy all the registered Event to new gRuntime protocol\r
+      //\r
+      for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {\r
+        CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
+        InsertTailList (&gRuntime->EventHead, Link);\r
+      }\r
+      \r
+      //\r
+      // Clean up gRuntimeTemplate\r
+      //\r
+      gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;\r
+      gRuntimeTemplate.ImageHead.BackLink    = &gRuntimeTemplate.ImageHead;\r
+      gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;\r
+      gRuntimeTemplate.EventHead.BackLink    = &gRuntimeTemplate.EventHead;\r
     }\r
   }\r
 \r
index ade810c5c18f57731c56e485657570f274bb34a7..08cff427ffa798bd4a6d59672198e971053c0f0b 100644 (file)
@@ -168,50 +168,6 @@ Returns:
 }\r
 \r
 \r
-EFI_STATUS\r
-CoreShutdownEventServices (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Register all runtime events to make sure they are still available after ExitBootService.\r
-\r
-Arguments:\r
-\r
-  None\r
-    \r
-Returns:\r
-\r
-  EFI_SUCCESS - Always return success.\r
-\r
---*/\r
-{\r
-  LIST_ENTRY        *Link;\r
-  IEVENT            *Event;\r
-\r
-  //\r
-  // The Runtime AP is required for the core to function!\r
-  //\r
-  ASSERT (gRuntime != NULL);\r
-\r
-  for (Link = mRuntimeEventList.ForwardLink; Link != &mRuntimeEventList; Link = Link->ForwardLink) {\r
-    Event = CR (Link, IEVENT, RuntimeLink, EVENT_SIGNATURE);\r
-    gRuntime->RegisterEvent (\r
-                gRuntime, \r
-                Event->Type, \r
-                Event->NotifyTpl, \r
-                Event->NotifyFunction, \r
-                Event->NotifyContext, \r
-                (VOID **)Event\r
-                );\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 VOID\r
 CoreDispatchEventNotifies (\r
   IN EFI_TPL      Priority\r
@@ -559,7 +515,12 @@ Returns:
     //\r
     // Keep a list of all RT events so we can tell the RT AP.\r
     //\r
-    InsertTailList (&mRuntimeEventList, &IEvent->RuntimeLink);\r
+    IEvent->RuntimeData.Type           = Type;\r
+    IEvent->RuntimeData.NotifyTpl      = NotifyTpl;\r
+    IEvent->RuntimeData.NotifyFunction = NotifyFunction;\r
+    IEvent->RuntimeData.NotifyContext  = (VOID *) NotifyContext;\r
+    IEvent->RuntimeData.Event          = (EFI_EVENT *) IEvent;\r
+    InsertTailList (&gRuntime->EventHead, &IEvent->RuntimeData.Link);\r
   }\r
 \r
   CoreAcquireEventLock ();\r
@@ -835,11 +796,11 @@ Returns:
   //\r
   // If the event is queued somewhere, remove it\r
   //\r
-\r
-  if (Event->RuntimeLink.ForwardLink != NULL) {\r
-    RemoveEntryList (&Event->RuntimeLink);\r
+  \r
+  if (Event->RuntimeData.Link.ForwardLink != NULL) {\r
+    RemoveEntryList (&Event->RuntimeData.Link);\r
   }\r
-\r
+  \r
   if (Event->NotifyLink.ForwardLink != NULL) {\r
     RemoveEntryList (&Event->NotifyLink);\r
   }\r
index e7a11c2400308d64e06409cd738e97c24986462e..6e9b68b8be821f1d835e840fb9b8d827e6a64e64 100644 (file)
@@ -49,7 +49,3 @@ UINTN           gEventPending = 0;
 //\r
 LIST_ENTRY      gEventSignalQueue = INITIALIZE_LIST_HEAD_VARIABLE (gEventSignalQueue);\r
 \r
-//\r
-// LIST of runtime events that need to be fired by RT AP.\r
-//\r
-LIST_ENTRY      mRuntimeEventList = INITIALIZE_LIST_HEAD_VARIABLE (mRuntimeEventList);\r
index e7b0f7b66010b2acafca19ad9f1323ce3adf5cc7..376c381459342f961468235256332c3b99b3c36c 100644 (file)
@@ -56,7 +56,7 @@ typedef struct {
   //\r
   // A list of all runtime events\r
   //\r
-  LIST_ENTRY              RuntimeLink;\r
+  EFI_RUNTIME_EVENT_ENTRY   RuntimeData;\r
 \r
   //\r
   // Information by event type\r
@@ -204,6 +204,5 @@ extern UINTN          gEventPending;
 extern LIST_ENTRY     gEventQueue[];\r
 extern LIST_ENTRY     gEventSignalQueue;\r
 extern UINT8          gHSB[];\r
-extern LIST_ENTRY     mRuntimeEventList;\r
 \r
 #endif\r
index 9d3e41260c3c76246d7557418c9c9cb2dbe69e49..87214d35d532e61c8d9d1b1102d7d4e7b8b4856a 100644 (file)
@@ -53,11 +53,9 @@ typedef struct {
 \r
     EFI_EBC_PROTOCOL            *Ebc;           // EBC Protocol pointer\r
 \r
-    BOOLEAN                     RuntimeFixupValid; // True if RT image needs fixup\r
-    VOID                        *RuntimeFixup;     // Copy of fixup data;\r
-    LIST_ENTRY                  Link;              // List of RT LOADED_IMAGE_PRIVATE_DATA\r
+    EFI_RUNTIME_IMAGE_ENTRY     *RuntimeData;   // Runtime image list\r
 \r
-    PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;     // PeCoffLoader ImageContext\r
+    PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext; // PeCoffLoader ImageContext\r
 \r
 } LOADED_IMAGE_PRIVATE_DATA;\r
 \r
index a71c6f643a6321965428a4814263522e18f77e2f..4e6bd0843e8edaba79d170c6365748ce55864f34 100644 (file)
@@ -24,11 +24,6 @@ Abstract:
 // Module Globals\r
 //\r
 \r
-//\r
-// LIST of runtime images that need to be relocated.\r
-//\r
-LIST_ENTRY                 mRuntimeImageList = INITIALIZE_LIST_HEAD_VARIABLE (mRuntimeImageList);\r
-\r
 LOADED_IMAGE_PRIVATE_DATA  *mCurrentImage = NULL;\r
 \r
 LOAD_PE32_IMAGE_PRIVATE_DATA  mLoadPe32PrivateData = {\r
@@ -78,9 +73,7 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage  = {
   NULL,                       // JumpContext\r
   0,                          // Machine\r
   NULL,                       // Ebc\r
-  FALSE,                      // RuntimeFixupValid\r
-  NULL,                       // RuntimeFixup\r
-  { NULL, NULL },             // Link\r
+  NULL,                       // RuntimeData\r
 };\r
 \r
 \r
@@ -173,52 +166,6 @@ Returns:
            );\r
 }\r
 \r
-\r
-EFI_STATUS\r
-CoreShutdownImageServices (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Transfer control of runtime images to runtime service\r
-\r
-Arguments:\r
-\r
-  None\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS       - Function successfully returned\r
-\r
---*/\r
-{\r
-  LIST_ENTRY                  *Link;\r
-  LOADED_IMAGE_PRIVATE_DATA   *Image;\r
-\r
-  //\r
-  // The Runtime AP is required for the core to function!\r
-  //\r
-  ASSERT (gRuntime != NULL);\r
-\r
-  for (Link = mRuntimeImageList.ForwardLink; Link != &mRuntimeImageList; Link = Link->ForwardLink) {\r
-    Image = CR (Link, LOADED_IMAGE_PRIVATE_DATA, Link, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE);\r
-    if (Image->RuntimeFixupValid) {\r
-      gRuntime->RegisterImage (\r
-                  gRuntime,\r
-                  (UINT64)(UINTN)(Image->Info.ImageBase),\r
-                  (EFI_SIZE_TO_PAGES ((UINTN)Image->Info.ImageSize)),\r
-                  Image->RuntimeFixup\r
-                  );\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
 EFI_STATUS\r
 CoreLoadPeImage (\r
   IN VOID                        *Pe32Handle,\r
@@ -253,8 +200,9 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS                            Status;\r
-  UINTN                                 Size;\r
+  EFI_STATUS      Status;\r
+  BOOLEAN         DstBufAlocated;\r
+  UINTN           Size;\r
 \r
   ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));\r
 \r
@@ -281,7 +229,7 @@ Returns:
   //\r
   // Allocate memory of the correct memory type aligned on the required image boundry\r
   //\r
-\r
+  DstBufAlocated = FALSE;\r
   if (DstBuffer == 0) {\r
     //\r
     // Allocate Destination Buffer as caller did not pass it in\r
@@ -308,8 +256,7 @@ Returns:
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-\r
-    Image->ImageBasePage = Image->ImageContext.ImageAddress;\r
+    DstBufAlocated = TRUE;\r
 \r
   } else {\r
     //\r
@@ -334,9 +281,9 @@ Returns:
 \r
     Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);\r
     Image->ImageContext.ImageAddress = DstBuffer;\r
-    Image->ImageBasePage = Image->ImageContext.ImageAddress;\r
   }\r
 \r
+  Image->ImageBasePage = Image->ImageContext.ImageAddress;\r
   Image->ImageContext.ImageAddress =\r
       (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &\r
       ~((UINTN)Image->ImageContext.SectionAlignment - 1);\r
@@ -346,7 +293,7 @@ Returns:
   //\r
   Status = gEfiPeiPeCoffLoader->LoadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -361,13 +308,6 @@ Returns:
         Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
       }\r
-\r
-      //\r
-      // Make a list off all the RT images so we can let the RT AP know about them\r
-      //\r
-      Image->RuntimeFixupValid = TRUE;\r
-      Image->RuntimeFixup = Image->ImageContext.FixupData;\r
-      InsertTailList (&mRuntimeImageList, &Image->Link);\r
     }\r
   }\r
 \r
@@ -376,7 +316,7 @@ Returns:
   //\r
   Status = gEfiPeiPeCoffLoader->RelocateImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -438,7 +378,23 @@ Returns:
   Image->Info.ImageSize     = Image->ImageContext.ImageSize;\r
   Image->Info.ImageCodeType = Image->ImageContext.ImageCodeMemoryType;\r
   Image->Info.ImageDataType = Image->ImageContext.ImageDataMemoryType;\r
-\r
+  if (Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) {\r
+    if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {\r
+      //\r
+      // Make a list off all the RT images so we can let the RT AP know about them.\r
+      //\r
+      Image->RuntimeData = CoreAllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));\r
+      if (Image->RuntimeData == NULL) {\r
+        goto Done;\r
+      }\r
+      Image->RuntimeData->ImageBase      = Image->Info.ImageBase;\r
+      Image->RuntimeData->ImageSize      = (UINT64) (Image->Info.ImageSize);\r
+      Image->RuntimeData->RelocationData = Image->ImageContext.FixupData;\r
+      Image->RuntimeData->Handle         = Image->Handle;\r
+      InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);\r
+    }\r
+  }\r
+  \r
   //\r
   // Fill in the entry point of the image if it is available\r
   //\r
@@ -489,10 +445,19 @@ Returns:
   return EFI_SUCCESS;\r
 \r
 Done:\r
+\r
   //\r
-  // Free memory\r
+  // Free memory.\r
   //\r
-  CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);\r
+  \r
+  if (DstBufAlocated) {\r
+    CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);\r
+  }\r
+  \r
+  if (Image->ImageContext.FixupData != NULL) {\r
+    CoreFreePool (Image->ImageContext.FixupData);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -1168,13 +1133,16 @@ Returns:
                );\r
   }\r
 \r
-  if (Image->RuntimeFixupValid) {\r
-    //\r
-    // Remove the Image from the Runtime Image list as we are about to Free it!\r
-    //\r
-    RemoveEntryList (&Image->Link);\r
+  if (Image->RuntimeData != NULL) {\r
+    if (Image->RuntimeData->Link.ForwardLink != NULL) {\r
+      //\r
+      // Remove the Image from the Runtime Image list as we are about to Free it!\r
+      //\r
+      RemoveEntryList (&Image->RuntimeData->Link);\r
+    }\r
+    CoreFreePool (Image->RuntimeData);\r
   }\r
-\r
+  \r
   //\r
   // Free the Image from memory\r
   //\r
index 675a5503c3e0eecaf32c200887802a684a501cb0..3692d978f46f11d9f085fca19425c6bf497fee62 100644 (file)
@@ -41,10 +41,20 @@ RuntimeDriverCalculateCrc32 (
 \r
 Routine Description:\r
 \r
+  Calculate CRC32 for target data\r
+\r
 Arguments:\r
 \r
+  Data     - The target data.\r
+  DataSize - The target data size.\r
+  CrcOut   - The CRC32 for target data.\r
+\r
 Returns:\r
 \r
+  EFI_SUCCESS           - The CRC32 for target data is calculated successfully.\r
+  EFI_INVALID_PARAMETER - Some parameter is not valid, so the CRC32 is not \r
+                          calculated.\r
+\r
 --*/\r
 {\r
   UINT32  Crc;\r
@@ -72,10 +82,16 @@ ReverseBits (
 \r
 Routine Description:\r
 \r
+  Reverse bits for 32bit data.\r
+\r
 Arguments:\r
 \r
+  Value - the data to be reversed.\r
+\r
 Returns:\r
 \r
+  UINT32 data reversed.\r
+\r
 --*/\r
 {\r
   UINTN   Index;\r
@@ -99,10 +115,16 @@ RuntimeDriverInitializeCrc32Table (
 \r
 Routine Description:\r
 \r
+  Initialize CRC32 table.\r
+\r
 Arguments:\r
 \r
+  None.\r
+\r
 Returns:\r
 \r
+  None.\r
+\r
 --*/\r
 {\r
   UINTN   TableEntry;\r
diff --git a/EdkModulePkg/Universal/Runtime/RuntimeDxe/PeHotRelocate.c b/EdkModulePkg/Universal/Runtime/RuntimeDxe/PeHotRelocate.c
deleted file mode 100644 (file)
index fd980a7..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-Module Name:\r
-\r
-  PeHotRelocate.c\r
-\r
-Abstract:\r
-\r
-\r
---*/\r
-\r
-#include "Runtime.h"\r
-\r
-STATIC\r
-VOID *\r
-RuntimePeImageAddress (\r
-  IN   RUNTIME_IMAGE_RELOCATION_DATA  *Image,\r
-  IN   UINTN                          Address\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Converts an image address to the loaded address\r
-\r
-Arguments:\r
-\r
-  Image         - The relocation data of the image being loaded\r
-\r
-  Address       - The address to be converted to the loaded address\r
-\r
-Returns:\r
-\r
-  NULL if the address can not be converted, otherwise, the converted address\r
-\r
---*/\r
-{\r
-  if (Address >= (Image->ImageSize) << EFI_PAGE_SHIFT) {\r
-    return NULL;\r
-  }\r
-\r
-  return (CHAR8 *) ((UINTN) Image->ImageBase + Address);\r
-}\r
-\r
index 61dbd9c1fc6c842338c7ff4b30a0fbcaa859669d..e6946bd897ed5735835fd1182031834bf01a63e2 100644 (file)
@@ -55,16 +55,12 @@ Revision History:
 #include "Runtime.h"\r
 \r
 //\r
-// This is a only short term solution.\r
-// There is a change coming to the Runtime AP that\r
-// will make it so the Runtime driver will not have to allocate any buffers. \r
+// Global Variables\r
 //\r
-#define MAX_RUNTIME_IMAGE_NUM (64)\r
-#define MAX_RUNTIME_EVENT_NUM (64)\r
-RUNTIME_IMAGE_RELOCATION_DATA mRuntimeImageBuffer[MAX_RUNTIME_IMAGE_NUM];\r
-RUNTIME_NOTIFY_EVENT_DATA     mRuntimeEventBuffer[MAX_RUNTIME_EVENT_NUM];\r
-UINTN                         mRuntimeImageNumber;\r
-UINTN                         mRuntimeEventNumber;\r
+EFI_MEMORY_DESCRIPTOR         *mVirtualMap                = NULL;\r
+UINTN                         mVirtualMapDescriptorSize;\r
+UINTN                         mVirtualMapMaxIndex;\r
+VOID                          *mMyImageBase;\r
 \r
 //\r
 // The handle onto which the Runtime Architectural Protocol instance is installed\r
@@ -75,26 +71,23 @@ EFI_HANDLE                    mRuntimeHandle = NULL;
 // The Runtime Architectural Protocol instance produced by this driver\r
 //\r
 EFI_RUNTIME_ARCH_PROTOCOL     mRuntime = {\r
-  RuntimeDriverRegisterImage,\r
-  RuntimeDriverRegisterEvent\r
-};\r
-\r
-//\r
-// Global Variables\r
-//\r
-LIST_ENTRY                    mRelocationList             = INITIALIZE_LIST_HEAD_VARIABLE(mRelocationList);\r
-LIST_ENTRY                    mEventList                  = INITIALIZE_LIST_HEAD_VARIABLE(mEventList);\r
-BOOLEAN                       mEfiVirtualMode             = FALSE;\r
-EFI_GUID                      mLocalEfiUgaIoProtocolGuid  = EFI_UGA_IO_PROTOCOL_GUID;\r
-EFI_MEMORY_DESCRIPTOR         *mVirtualMap                = NULL;\r
-UINTN                         mVirtualMapDescriptorSize;\r
-UINTN                         mVirtualMapMaxIndex;\r
+  INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.ImageHead),\r
+  INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.EventHead),\r
 \r
-EFI_LOADED_IMAGE_PROTOCOL     *mMyLoadedImage;\r
+  //\r
+  // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will\r
+  // prevent people from having pointer math bugs in their code.\r
+  // now you have to use *DescriptorSize to make things work.\r
+  //\r
+  sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),  \r
+  EFI_MEMORY_DESCRIPTOR_VERSION, \r
+  0,\r
+  NULL,\r
+  NULL,\r
+  FALSE,\r
+  FALSE\r
+};\r
 \r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-STATIC EFI_GUID mEfiCapsuleHeaderGuid = EFI_CAPSULE_GUID;\r
-#endif\r
 //\r
 // Worker Functions\r
 //\r
@@ -131,134 +124,30 @@ Returns:
 \r
 EFI_STATUS\r
 EFIAPI\r
-RuntimeDriverRegisterImage (\r
-  IN  EFI_RUNTIME_ARCH_PROTOCOL  *This,\r
-  IN  EFI_PHYSICAL_ADDRESS       ImageBase,\r
-  IN  UINTN                      ImageSize,\r
-  IN  VOID                       *RelocationData\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  When a SetVirtualAddressMap() is performed all the runtime images loaded by \r
-  DXE must be fixed up with the new virtual address map. To facilitate this the \r
-  Runtime Architectural Protocol needs to be informed of every runtime driver \r
-  that is registered.  All the runtime images loaded by DXE should be registered \r
-  with this service by the DXE Core when ExitBootServices() is called.  The \r
-  images that are registered with this service must have successfully been \r
-  loaded into memory with the Boot Service LoadImage().  As a result, no \r
-  parameter checking needs to be performed.\r
-\r
-Arguments:\r
-\r
-  This           - The EFI_RUNTIME_ARCH_PROTOCOL instance. \r
-\r
-  ImageBase      - Start of image that has been loaded in memory. It is either \r
-                   a pointer to the DOS or PE header of the image.\r
-\r
-  ImageSize      - Size of the image in bytes.\r
-\r
-  RelocationData - Information about the fixups that were performed on ImageBase \r
-                   when it was loaded into memory. This information is needed \r
-                   when the virtual mode fix-ups are reapplied so that data that \r
-                   has been programmatically updated will not be fixed up. If \r
-                   code updates a global variable the code is responsible for \r
-                   fixing up the variable for virtual mode.\r
-\r
-Returns: \r
-\r
-  EFI_SUCCESS          - The ImageBase has been registered.\r
-\r
---*/\r
-{\r
-  RUNTIME_IMAGE_RELOCATION_DATA *RuntimeImage;\r
-\r
-  if (mMyLoadedImage->ImageBase == (VOID *) (UINTN) ImageBase) {\r
-    //\r
-    // We don't want to relocate our selves, as we only run in physical mode.\r
-    //\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  RuntimeImage = &mRuntimeImageBuffer[mRuntimeImageNumber];\r
-  mRuntimeImageNumber++;\r
-  ASSERT (mRuntimeImageNumber < MAX_RUNTIME_IMAGE_NUM);\r
-\r
-  RuntimeImage->Valid           = TRUE;\r
-  RuntimeImage->ImageBase       = ImageBase;\r
-  RuntimeImage->ImageSize       = ImageSize;\r
-  RuntimeImage->RelocationData  = RelocationData;\r
-\r
-  InsertTailList (&mRelocationList, &RuntimeImage->Link);\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeDriverRegisterEvent (\r
-  IN EFI_RUNTIME_ARCH_PROTOCOL  *This,\r
-  IN UINT32                     Type,\r
-  IN EFI_TPL                    NotifyTpl,\r
-  IN EFI_EVENT_NOTIFY           NotifyFunction,\r
-  IN VOID                       *NotifyContext,\r
-  IN EFI_EVENT                  *Event\r
+RuntimeDriverConvertPointer (\r
+  IN     UINTN  DebugDisposition,\r
+  IN OUT VOID   **ConvertAddress\r
   )\r
 /*++\r
 \r
 Routine Description:\r
 \r
-  This function is used to support the required runtime events. Currently only \r
-  runtime events of type EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE needs to be \r
-  registered with this service.  All the runtime events that exist in the DXE \r
-  Core should be registered with this service when ExitBootServices() is called.  \r
-  All the events that are registered with this service must have been created \r
-  with the Boot Service CreateEvent().  As a result, no parameter checking needs \r
-  to be performed.\r
+  Determines the new virtual address that is to be used on subsequent memory accesses.\r
 \r
 Arguments:\r
+  \r
+  DebugDisposition    - Supplies type information for the pointer being converted.\r
+  ConvertAddress      - A pointer to a pointer that is to be fixed to be the value needed\r
+                        for the new virtual address mappings being applied.\r
 \r
-  This           - The EFI_RUNTIME_ARCH_PROTOCOL instance. \r
-\r
-  Type           - The same as Type passed into CreateEvent().\r
-\r
-  NotifyTpl      - The same as NotifyTpl passed into CreateEvent().\r
-\r
-  NotifyFunction - The same as NotifyFunction passed into CreateEvent().\r
-\r
-  NotifyContext  - The same as NotifyContext passed into CreateEvent().\r
-\r
-  Event          - The EFI_EVENT returned by CreateEvent().  Event must be in \r
-                   runtime memory.\r
-\r
-Returns: \r
+Returns:\r
 \r
-  EFI_SUCCESS          - The Event has been registered.\r
+  EFI_SUCCESS             - The pointer pointed to by Address was modified.\r
+  EFI_NOT_FOUND           - The pointer pointed to by Address was not found to be part\r
+                            of the current memory map. This is normally fatal.\r
+  EFI_INVALID_PARAMETER   - One of the parameters has an invalid value.\r
 \r
 --*/\r
-{\r
-  RUNTIME_NOTIFY_EVENT_DATA *RuntimeEvent;\r
-\r
-  RuntimeEvent = &mRuntimeEventBuffer[mRuntimeEventNumber];\r
-  mRuntimeEventNumber++;\r
-  ASSERT (mRuntimeEventNumber < MAX_RUNTIME_EVENT_NUM);\r
-\r
-  RuntimeEvent->Type            = Type;\r
-  RuntimeEvent->NotifyTpl       = NotifyTpl;\r
-  RuntimeEvent->NotifyFunction  = NotifyFunction;\r
-  RuntimeEvent->NotifyContext   = NotifyContext;\r
-  RuntimeEvent->Event           = Event;\r
-\r
-  InsertTailList (&mEventList, &RuntimeEvent->Link);\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeDriverConvertPointer (\r
-  IN     UINTN  DebugDisposition,\r
-  IN OUT VOID   **ConvertAddress\r
-  )\r
 {\r
   UINTN                 Address;\r
   VOID                  *PlabelConvertAddress;\r
@@ -297,7 +186,7 @@ RuntimeDriverConvertPointer (
     //  platforms. If you get this ASSERT remove the UINTN and do a 64-bit\r
     //  multiply.\r
     //\r
-    ASSERT ((VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));\r
+    ASSERT (((UINTN) VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));\r
 \r
     if ((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {\r
       if (Address >= VirtEntry->PhysicalStart) {\r
@@ -339,6 +228,26 @@ EFI_STATUS
 RuntimeDriverConvertInternalPointer (\r
   IN OUT VOID   **ConvertAddress\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Determines the new virtual address that is to be used on subsequent memory accesses \r
+  for internal pointers.\r
+\r
+Arguments:\r
+  \r
+  ConvertAddress  - A pointer to a pointer that is to be fixed to be the value needed\r
+                    for the new virtual address mappings being applied.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             - The pointer pointed to by Address was modified.\r
+  EFI_NOT_FOUND           - The pointer pointed to by Address was not found to be part\r
+                            of the current memory map. This is normally fatal.\r
+  EFI_INVALID_PARAMETER   - One of the parameters has an invalid value.\r
+\r
+--*/\r
 {\r
   return RuntimeDriverConvertPointer (0x0, ConvertAddress);\r
 }\r
@@ -351,10 +260,36 @@ RuntimeDriverSetVirtualAddressMap (
   IN UINT32                 DescriptorVersion,\r
   IN EFI_MEMORY_DESCRIPTOR  *VirtualMap\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Changes the runtime addressing mode of EFI firmware from physical to virtual.\r
+\r
+Arguments:\r
+  \r
+  MemoryMapSize     - The size in bytes of VirtualMap.\r
+  DescriptorSize    - The size in bytes of an entry in the VirtualMap.\r
+  DescriptorVersion - The version of the structure entries in VirtualMap.\r
+  VirtualMap        - An array of memory descriptors which contain new virtual\r
+                      address mapping information for all runtime ranges.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The virtual address map has been applied.\r
+  EFI_UNSUPPORTED       - EFI firmware is not at runtime, or the EFI firmware is already in\r
+                          virtual address mapped mode.\r
+  EFI_INVALID_PARAMETER - DescriptorSize or DescriptorVersion is invalid.\r
+  EFI_NO_MAPPING        - A virtual address was not supplied for a range in the memory\r
+                          map that requires a mapping.\r
+  EFI_NOT_FOUND         - A virtual address was supplied for an address that is not found\r
+                          in the memory map.\r
+\r
+--*/  \r
 {\r
   EFI_STATUS                    Status;\r
-  RUNTIME_NOTIFY_EVENT_DATA     *RuntimeEvent;\r
-  RUNTIME_IMAGE_RELOCATION_DATA *RuntimeImage;\r
+  EFI_RUNTIME_EVENT_ENTRY       *RuntimeEvent;\r
+  EFI_RUNTIME_IMAGE_ENTRY       *RuntimeImage;\r
   LIST_ENTRY                    *Link;\r
   UINTN                         Index;\r
   UINTN                         Index1;\r
@@ -369,7 +304,7 @@ RuntimeDriverSetVirtualAddressMap (
   // Can only switch to virtual addresses once the memory map is locked down,\r
   // and can only set it once\r
   //\r
-  if (!EfiAtRuntime () || mEfiVirtualMode) {\r
+  if (!mRuntime.AtRuntime || mRuntime.VirtualMode) {\r
     return EFI_UNSUPPORTED;\r
   }\r
   //\r
@@ -379,44 +314,18 @@ RuntimeDriverSetVirtualAddressMap (
     return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
-  // BugBug: Add code here to verify the memory map. We should\r
-  //  cache a copy of the system memory map in the EFI System Table\r
-  //  as a GUID pointer pair.\r
-  //\r
-  //\r
-  // Make sure all virtual translations are satisfied\r
-  //\r
-  mVirtualMapMaxIndex = MemoryMapSize / DescriptorSize;\r
-\r
-  //\r
-  // BugBug :The following code does not work hence commented out.\r
-  // Need to be replaced by something that works.\r
-  //\r
-  //  VirtEntry = VirtualMap;\r
-  //  for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {\r
-  //    if (((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) &&\r
-  //        (VirtEntry->VirtualStart != 0) ) {\r
-  //        return EFI_NO_MAPPING;\r
-  //    }\r
-  //    VirtEntry = NextMemoryDescriptor(VirtEntry, DescriptorSize);\r
-  //  }\r
-  //\r
   // We are now committed to go to virtual mode, so lets get to it!\r
   //\r
-  mEfiVirtualMode = TRUE;\r
+  mRuntime.VirtualMode = TRUE;\r
 \r
   //\r
   // ConvertPointer() needs this mVirtualMap to do the conversion. So set up\r
   // globals we need to parse the virtual address map.\r
   //\r
   mVirtualMapDescriptorSize = DescriptorSize;\r
+  mVirtualMapMaxIndex       = MemoryMapSize / DescriptorSize;\r
   mVirtualMap               = VirtualMap;\r
 \r
-  //\r
-  // Signal all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE events.\r
-  // The core call RuntimeDriverRegisterEvent() for\r
-  // every runtime event and we stored them in the mEventList\r
-  //\r
   //\r
   // Currently the bug in StatusCode/RuntimeLib has been fixed, it will\r
   // check whether in Runtime or not (this is judged by looking at\r
@@ -428,19 +337,11 @@ RuntimeDriverSetVirtualAddressMap (
           );\r
 \r
   //\r
-  // BugBug - Commented out for now because the status code driver is not\r
-  // ready for runtime yet. The Status Code driver calls data hub with does\r
-  // a bunch of Boot Service things (locks, AllocatePool) and hangs somewhere\r
-  // on the way.\r
-  //\r
-  //  ReportStatusCode (\r
-  //        EfiProgressCode,  EfiMaxErrorSeverity,\r
-  //        0x03, 0x01, 12, // ReadyToBoot Progress code\r
-  //        0x00, 30, L"ConvertPointer"\r
-  //        );\r
+  // Signal all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE events.\r
+  // All runtime events are stored in a list in Runtime AP.\r
   //\r
-  for (Link = mEventList.ForwardLink; Link != &mEventList; Link = Link->ForwardLink) {\r
-    RuntimeEvent = _CR (Link, RUNTIME_NOTIFY_EVENT_DATA, Link);\r
+  for (Link = mRuntime.EventHead.ForwardLink; Link != &mRuntime.EventHead; Link = Link->ForwardLink) {\r
+    RuntimeEvent = _CR (Link, EFI_RUNTIME_EVENT_ENTRY, Link);\r
     if ((RuntimeEvent->Type & EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) == EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {\r
       RuntimeEvent->NotifyFunction (\r
                       RuntimeEvent->Event,\r
@@ -448,29 +349,32 @@ RuntimeDriverSetVirtualAddressMap (
                       );\r
     }\r
   }\r
+\r
   //\r
-  // Relocate runtime images. Runtime images loaded before the runtime AP was\r
-  // started will not be relocated, since they would not have gotten registered.\r
-  // This includes the code in this file.\r
+  // Relocate runtime images. All runtime images are stored in a list in Runtime AP.\r
   //\r
-  for (Link = mRelocationList.ForwardLink; Link != &mRelocationList; Link = Link->ForwardLink) {\r
-    RuntimeImage = _CR (Link, RUNTIME_IMAGE_RELOCATION_DATA, Link);\r
-    if (RuntimeImage->Valid) {\r
+  for (Link = mRuntime.ImageHead.ForwardLink; Link != &mRuntime.ImageHead; Link = Link->ForwardLink) {\r
+    RuntimeImage = _CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link);\r
+    //\r
+    // We don't want to relocate our selves, as we only run in physical mode.\r
+    //\r
+    if (mMyImageBase != RuntimeImage->ImageBase) {\r
 \r
-      VirtImageBase = RuntimeImage->ImageBase;\r
+      VirtImageBase = (EFI_PHYSICAL_ADDRESS) (UINTN) RuntimeImage->ImageBase;\r
       Status  = RuntimeDriverConvertPointer (0, (VOID **) &VirtImageBase);\r
       ASSERT_EFI_ERROR (Status);\r
 \r
       PeCoffLoaderRelocateImageForRuntime (\r
-        RuntimeImage->ImageBase,\r
+        (EFI_PHYSICAL_ADDRESS) (UINTN) RuntimeImage->ImageBase,\r
         VirtImageBase,\r
-        RuntimeImage->ImageSize,\r
+        (UINTN) RuntimeImage->ImageSize,\r
         RuntimeImage->RelocationData\r
         );\r
       \r
-      InvalidateInstructionCacheRange ((VOID *)(UINTN)RuntimeImage->ImageBase, (UINTN)RuntimeImage->ImageSize);\r
+      InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN)RuntimeImage->ImageSize);\r
     }\r
   }\r
+\r
   //\r
   // Convert all the Runtime Services except ConvertPointer() and SetVirtualAddressMap()\r
   // and recompute the CRC-32\r
@@ -480,6 +384,9 @@ RuntimeDriverSetVirtualAddressMap (
   RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetWakeupTime);\r
   RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetWakeupTime);\r
   RuntimeDriverConvertInternalPointer ((VOID **) &gRT->ResetSystem);\r
+#if (EFI_SPECIFICATION_VERSION < 0x00020000)\r
+  RuntimeDriverConvertInternalPointer ((VOID **) &gRT->ReportStatusCode);\r
+#endif\r
   RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextHighMonotonicCount);\r
   RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetVariable);\r
   RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetVariable);\r
@@ -495,7 +402,7 @@ RuntimeDriverSetVirtualAddressMap (
   // Convert the UGA OS Handoff Table if it is present in the Configuration Table\r
   //\r
   for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r
-    if (CompareGuid (&mLocalEfiUgaIoProtocolGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
+    if (CompareGuid (&gEfiUgaIoProtocolGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
       DriverOsHandoffHeader = gST->ConfigurationTable[Index].VendorTable;\r
       for (Index1 = 0; Index1 < DriverOsHandoffHeader->NumberOfEntries; Index1++) {\r
         DriverOsHandoff = (EFI_DRIVER_OS_HANDOFF *)\r
@@ -511,8 +418,9 @@ RuntimeDriverSetVirtualAddressMap (
 \r
       RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &(gST->ConfigurationTable[Index].VendorTable));\r
     }\r
+\r
 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-    if (CompareGuid (&mEfiCapsuleHeaderGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
+    if (CompareGuid (&gEfiCapsuleGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
       CapsuleTable = gST->ConfigurationTable[Index].VendorTable;\r
       for (Index1 = 0; Index1 < CapsuleTable->CapsuleArrayNumber; Index1++) {\r
         RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &CapsuleTable->CapsulePtr[Index1]);\r
@@ -565,7 +473,8 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS                Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL *MyLoadedImage;\r
 \r
   //\r
   // This image needs to be exclued from relocation for virtual mode, so cache\r
@@ -574,9 +483,10 @@ Returns:
   Status = gBS->HandleProtocol (\r
                   ImageHandle,\r
                   &gEfiLoadedImageProtocolGuid,\r
-                  (VOID **) &mMyLoadedImage\r
+                  &MyLoadedImage\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
+  mMyImageBase = MyLoadedImage->ImageBase;\r
 \r
   //\r
   // Initialize the table used to compute 32-bit CRCs\r
@@ -586,7 +496,7 @@ Returns:
   //\r
   // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables\r
   //\r
-  gBS->CalculateCrc32         = RuntimeDriverCalculateCrc32;\r
+  gBS->CalculateCrc32       = RuntimeDriverCalculateCrc32;\r
   gRT->SetVirtualAddressMap = RuntimeDriverSetVirtualAddressMap;\r
   gRT->ConvertPointer       = RuntimeDriverConvertPointer;\r
 \r
@@ -600,9 +510,6 @@ Returns:
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-\r
-  mRuntimeImageNumber = 0;\r
-  mRuntimeEventNumber = 0;\r
-\r
-  return Status;\r
+  \r
+  return EFI_SUCCESS;\r
 }\r
index 1aa0af5767a2999d6cd2edba0b40846f86485041..c2e4b39666df16744c9def2d282f5944b682245a 100644 (file)
@@ -17,88 +17,152 @@ Abstract:
 \r
   Runtime Architectural Protocol as defined in the DXE CIS\r
 \r
-  This code is used to produce the EFI runtime virtual switch over\r
+  This code is used to produce the EFI runtime architectural protocol.\r
 \r
 --*/\r
 \r
 #ifndef _RUNTIME_H_\r
 #define _RUNTIME_H_\r
 \r
-//\r
-// Data structures\r
-//\r
-typedef struct {\r
-  LIST_ENTRY            Link;\r
-  BOOLEAN               Valid;\r
-  EFI_PHYSICAL_ADDRESS  ImageBase;\r
-  UINTN                 ImageSize;  // In no. of pages\r
-  VOID                  *RelocationData;\r
-} RUNTIME_IMAGE_RELOCATION_DATA;\r
-\r
-typedef struct {\r
-  LIST_ENTRY          Link;\r
-  IN UINT32           Type;\r
-  IN EFI_TPL          NotifyTpl;\r
-  IN EFI_EVENT_NOTIFY NotifyFunction;\r
-  IN VOID             *NotifyContext;\r
-  IN EFI_EVENT        Event;\r
-} RUNTIME_NOTIFY_EVENT_DATA;\r
-\r
 //\r
 // Function Prototypes\r
 //\r
-VOID\r
-RelocatePeImageForRuntime (\r
-  RUNTIME_IMAGE_RELOCATION_DATA  *Image\r
-  );\r
-\r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeDriverCalculateCrc32 (\r
   IN  VOID    *Data,\r
   IN  UINTN   DataSize,\r
   OUT UINT32  *CrcOut\r
-  );\r
+  )\r
+/*++\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeDriverRegisterImage (\r
-  IN  EFI_RUNTIME_ARCH_PROTOCOL         *This,\r
-  IN  EFI_PHYSICAL_ADDRESS              ImageBase,\r
-  IN  UINTN                             ImageSize,\r
-  IN  VOID                              *RelocationData\r
-  );\r
+Routine Description:\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeDriverRegisterEvent (\r
-  IN EFI_RUNTIME_ARCH_PROTOCOL          *This,\r
-  IN UINT32                             Type,\r
-  IN EFI_TPL                            NotifyTpl,\r
-  IN EFI_EVENT_NOTIFY                   NotifyFunction,\r
-  IN VOID                               *NotifyContext,\r
-  IN EFI_EVENT                          *Event\r
-  );\r
+  Calculate CRC32 for target data\r
+\r
+Arguments:\r
+\r
+  Data     - The target data.\r
+  DataSize - The target data size.\r
+  CrcOut   - The CRC32 for target data.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The CRC32 for target data is calculated successfully.\r
+  EFI_INVALID_PARAMETER - Some parameter is not valid, so the CRC32 is not \r
+                          calculated.\r
+\r
+--*/\r
+;\r
 \r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeDriverConvertPointer (\r
   IN     UINTN  DebugDisposition,\r
   IN OUT VOID   **ConvertAddress\r
-  );\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Determines the new virtual address that is to be used on subsequent memory accesses.\r
+\r
+Arguments:\r
+  \r
+  DebugDisposition    - Supplies type information for the pointer being converted.\r
+  ConvertAddress      - A pointer to a pointer that is to be fixed to be the value needed\r
+                        for the new virtual address mappings being applied.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             - The pointer pointed to by Address was modified.\r
+  EFI_NOT_FOUND           - The pointer pointed to by Address was not found to be part\r
+                            of the current memory map. This is normally fatal.\r
+  EFI_INVALID_PARAMETER   - One of the parameters has an invalid value.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeDriverSetVirtualAddressMap (\r
+  IN UINTN                  MemoryMapSize,\r
+  IN UINTN                  DescriptorSize,\r
+  IN UINT32                 DescriptorVersion,\r
+  IN EFI_MEMORY_DESCRIPTOR  *VirtualMap\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Changes the runtime addressing mode of EFI firmware from physical to virtual.\r
+\r
+Arguments:\r
+  \r
+  MemoryMapSize     - The size in bytes of VirtualMap.\r
+  DescriptorSize    - The size in bytes of an entry in the VirtualMap.\r
+  DescriptorVersion - The version of the structure entries in VirtualMap.\r
+  VirtualMap        - An array of memory descriptors which contain new virtual\r
+                      address mapping information for all runtime ranges.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The virtual address map has been applied.\r
+  EFI_UNSUPPORTED       - EFI firmware is not at runtime, or the EFI firmware is already in\r
+                          virtual address mapped mode.\r
+  EFI_INVALID_PARAMETER - DescriptorSize or DescriptorVersion is invalid.\r
+  EFI_NO_MAPPING        - A virtual address was not supplied for a range in the memory\r
+                          map that requires a mapping.\r
+  EFI_NOT_FOUND         - A virtual address was supplied for an address that is not found\r
+                          in the memory map.\r
+\r
+--*/\r
+;\r
 \r
 VOID\r
 RuntimeDriverInitializeCrc32Table (\r
   VOID\r
-  );\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize CRC32 table.\r
+\r
+Arguments:\r
+\r
+  None.\r
+\r
+Returns:\r
+\r
+  None.\r
+\r
+--*/\r
+;\r
 \r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeDriverInitialize (\r
   IN EFI_HANDLE                            ImageHandle,\r
   IN EFI_SYSTEM_TABLE                      *SystemTable\r
-  );\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Install Runtime AP. This code includes the EfiRuntimeLib, but it only \r
+  functions at RT in physical mode. \r
 \r
+Arguments:\r
+  \r
+  ImageHandle   - Image handle of this driver.\r
+  SystemTable   - Pointer to the EFI System Table.\r
 \r
+Returns:\r
+\r
+  EFI_SUCEESS - Runtime Driver Architectural Protocol installed.\r
+\r
+--*/\r
+;\r
 \r
 #endif\r
index 936d81afc65bb48be4e04e720c2b06fc8a7111f6..619c0980df891bb81652e9776f765b70d54c9dbb 100644 (file)
     <Protocol Usage="ALWAYS_CONSUMED">\r
       <ProtocolCName>gEfiLoadedImageProtocolGuid</ProtocolCName>\r
     </Protocol>\r
-    <Protocol Usage="ALWAYS_CONSUMED">\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiUgaIoProtocolGuid</ProtocolCName>\r
+    </Protocol> \r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
       <ProtocolCName>gEfiRuntimeArchProtocolGuid</ProtocolCName>\r
     </Protocol>\r
   </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiCapsuleGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
   <Externs>\r
     <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
     <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
index 92e9c141f725800f2061420e98e68f4dcfc18cc5..3af38facbea3dc2610f3757063e0979da416134b 100644 (file)
@@ -203,4 +203,14 @@ typedef INTN RETURN_STATUS;
 \r
 typedef UINT64 PHYSICAL_ADDRESS;\r
 \r
+//\r
+// LIST_ENTRY definition\r
+//\r
+typedef struct _LIST_ENTRY LIST_ENTRY;\r
+\r
+struct _LIST_ENTRY {\r
+  LIST_ENTRY  *ForwardLink;\r
+  LIST_ENTRY  *BackLink;\r
+};\r
+\r
 #endif\r
index feb2d8f294ab878e645223c636cd5de0881a9341..1f7504a9fc5f0126b650cc4ec1389135368dac45 100644 (file)
@@ -25,7 +25,7 @@
   Module Name:  Runtime.h\r
 \r
   @par Revision Reference:\r
-  Version 0.90.\r
+  Version 0.91.\r
 \r
 **/\r
 \r
 // Global ID for the Runtime Architectural Protocol\r
 //\r
 #define EFI_RUNTIME_ARCH_PROTOCOL_GUID \\r
-  { 0x96d08253, 0x8483, 0x11d4, {0xbc, 0xf1, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }\r
+  { 0xb7dfb4e1, 0x52f, 0x449f, {0x87, 0xbe, 0x98, 0x18, 0xfc, 0x91, 0xb7, 0x33 } }\r
 \r
-typedef struct _EFI_RUNTIME_ARCH_PROTOCOL   EFI_RUNTIME_ARCH_PROTOCOL;\r
+typedef struct _EFI_RUNTIME_ARCH_PROTOCOL  EFI_RUNTIME_ARCH_PROTOCOL;\r
 \r
-/**\r
-  When a SetVirtualAddressMap() is performed all the runtime images loaded by \r
-  DXE must be fixed up with the new virtual address map. To facilitate this the \r
-  Runtime Architectural Protocol needs to be informed of every runtime driver \r
-  that is registered.  All the runtime images loaded by DXE should be registered \r
-  with this service by the DXE Core when ExitBootServices() is called.  The \r
-  images that are registered with this service must have successfully been \r
-  loaded into memory with the Boot Service LoadImage().  As a result, no \r
-  parameter checking needs to be performed.\r
-\r
-  @param  This             The EFI_RUNTIME_ARCH_PROTOCOL instance.\r
-  @param  ImageBase        Start of image that has been loaded in memory. It is either\r
-                           a pointer to the DOS or PE header of the image.\r
-  @param  ImageSize        Size of the image in bytes.\r
-  @param  RelocationData   Information about the fixups that were performed on ImageBase\r
-                           when it was loaded into memory. This information is needed\r
-                           when the virtual mode fix-ups are reapplied so that data that\r
-                           has been programmatically updated will not be fixed up. If\r
-                           code updates a global variable the code is responsible for\r
-                           fixing up the variable for virtual mode.\r
-\r
-  @retval EFI_SUCCESS           The ImageBase has been registered.\r
-  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to register ImageBase.\r
+//\r
+// LIST_ENTRY from BaseType \r
+//\r
+typedef LIST_ENTRY EFI_LIST_ENTRY;\r
 \r
-**/\r
-typedef\r
-EFI_STATUS\r
-(EFIAPI *EFI_RUNTIME_REGISTER_IMAGE) (\r
-  IN EFI_RUNTIME_ARCH_PROTOCOL  *This,\r
-  IN  EFI_PHYSICAL_ADDRESS              ImageBase,   \r
-  IN  UINTN                             ImageSize,     \r
-  IN  VOID                              *RelocationData    \r
-  );\r
+typedef struct _EFI_RUNTIME_IMAGE_ENTRY  EFI_RUNTIME_IMAGE_ENTRY;\r
 \r
+struct _EFI_RUNTIME_IMAGE_ENTRY {\r
+  VOID                    *ImageBase;\r
+  UINT64                  ImageSize;\r
+  VOID                    *RelocationData;\r
+  EFI_HANDLE              Handle;\r
+  EFI_LIST_ENTRY          Link;\r
+};\r
 \r
-/**\r
-  This function is used to support the required runtime events. Currently only \r
-  runtime events of type EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE needs to be \r
-  registered with this service.  All the runtime events that exist in the DXE \r
-  Core should be registered with this service when ExitBootServices() is called.  \r
-  All the events that are registered with this service must have been created \r
-  with the Boot Service CreateEvent().  As a result, no parameter checking needs \r
-  to be performed.\r
-\r
-  @param  This             The EFI_RUNTIME_ARCH_PROTOCOL instance.\r
-  @param  Type             The same as Type passed into CreateEvent().\r
-  @param  NotifyTpl        The same as NotifyTpl passed into CreateEvent().\r
-  @param  NotifyFunction   The same as NotifyFunction passed into CreateEvent().\r
-  @param  NotifyContext    The same as NotifyContext passed into CreateEvent().\r
-  @param  Event            The EFI_EVENT returned by CreateEvent(). Event must be in\r
-                           runtime memory.\r
-\r
-  @retval EFI_SUCCESS           The Event has been registered.\r
-  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to register Event.\r
+typedef struct _EFI_RUNTIME_EVENT_ENTRY  EFI_RUNTIME_EVENT_ENTRY;\r
 \r
-**/\r
-typedef\r
-EFI_STATUS\r
-(EFIAPI *EFI_RUNTIME_REGISTER_EVENT) (\r
-  IN EFI_RUNTIME_ARCH_PROTOCOL  *This,\r
-  IN UINT32                             Type,\r
-  IN EFI_TPL                            NotifyTpl,\r
-  IN EFI_EVENT_NOTIFY                   NotifyFunction,\r
-  IN VOID                               *NotifyContext,\r
-  IN EFI_EVENT                          *Event\r
-  );\r
+struct _EFI_RUNTIME_EVENT_ENTRY {\r
+  UINT32                  Type;\r
+  EFI_TPL                 NotifyTpl;\r
+  EFI_EVENT_NOTIFY        NotifyFunction;\r
+  VOID                    *NotifyContext;\r
+  EFI_EVENT               *Event;\r
+  EFI_LIST_ENTRY          Link;\r
+};\r
 \r
 //\r
 // Interface stucture for the Runtime Architectural Protocol\r
 //\r
 /**\r
   @par Protocol Description:\r
-  The DXE driver that produces this protocol must be a runtime driver.  This \r
-  driver is responsible for initializing the SetVirtualAddressMap() and \r
-  ConvertPointer() fields of the EFI Runtime Services Table and the \r
-  CalculateCrc32() field of the EFI Boot Services Table.  See the Runtime \r
-  Services chapter and the Boot Services chapter for details on these services.\r
-  After the two fields of the EFI Runtime Services Table and the one field of \r
-  the EFI Boot Services Table have been initialized, the driver must install \r
-  the EFI_RUNTIME_ARCH_PROTOCOL_GUID on a new handle with an EFI_RUNTIME_ARCH_ \r
-  PROTOCOL interface pointer.  The installation of this protocol informs the \r
-  DXE core that the virtual memory services and the 32-bit CRC services are \r
-  now available, and the DXE core must update the 32-bit CRC of the EFI Runtime \r
-  Services Table and the 32-bit CRC of the EFI Boot Services Table.\r
-\r
-  All runtime core services are provided by the EFI_RUNTIME_ARCH_PROTOCOL.  \r
-  This includes the support for registering runtime images that must be \r
-  re-fixed up when a transition is made from physical mode to virtual mode. \r
-  This protocol also supports all events that are defined to fire at runtime. \r
-  This protocol also contains a CRC-32 function that will be used by the DXE \r
-  core as a boot service. The EFI_RUNTIME_ARCH_PROTOCOL needs the CRC-32 \r
-  function when a transition is made from physical mode to virtual mode and \r
-  the EFI System Table and EFI Runtime Table are fixed up with virtual pointers.\r
-\r
-  @param RegisterRuntimeImage\r
-  Register a runtime image so it can be converted to virtual mode if the EFI Runtime Services \r
-  SetVirtualAddressMap() is called.\r
-\r
-  @param RegisterRuntimeEvent\r
-  Register an event than needs to be notified at runtime. \r
+  Allows the runtime functionality of the DXE Foundation to be contained in a \r
+  separate driver. It also provides hooks for the DXE Foundation to export \r
+  information that is needed at runtime. As such, this protocol allows the DXE \r
+  Foundation to manage runtime drivers and events. This protocol also implies \r
+  that the runtime services required to transition to virtual mode, \r
+  SetVirtualAddressMap() and ConvertPointer(), have been registered into the \r
+  EFI Runtime Table in the EFI System Partition.  This protocol must be produced \r
+  by a runtime DXE driver and may only be consumed by the DXE Foundation.\r
+\r
+  @param ImageHead\r
+  A list of type EFI_RUNTIME_IMAGE_ENTRY.\r
+\r
+  @param EventHead\r
+  A list of type EFI_RUNTIME_EVENT_ENTRY.\r
+\r
+  @param MemoryDescriptorSize\r
+  Size of a memory descriptor that is return by GetMemoryMap().\r
+\r
+  @param MemoryDescriptorVersion\r
+  Version of a memory descriptor that is return by GetMemoryMap().\r
+\r
+  @param MemoryMapSize \r
+  Size of the memory map in bytes contained in MemoryMapPhysical and MemoryMapVirtual. \r
+\r
+  @param MemoryMapPhysical\r
+  Pointer to a runtime buffer that contains a copy of \r
+  the memory map returned via GetMemoryMap().\r
+\r
+  @param MemoryMapVirtual\r
+  Pointer to MemoryMapPhysical that is updated to virtual mode after SetVirtualAddressMap().\r
+\r
+  @param VirtualMode\r
+  Boolean that is TRUE if SetVirtualAddressMap() has been called.\r
+\r
+  @param AtRuntime\r
+  Boolean that is TRUE if ExitBootServices () has been called.\r
 \r
 **/\r
 struct _EFI_RUNTIME_ARCH_PROTOCOL {\r
-  EFI_RUNTIME_REGISTER_IMAGE  RegisterImage;\r
-  EFI_RUNTIME_REGISTER_EVENT  RegisterEvent;\r
+  EFI_LIST_ENTRY          ImageHead;\r
+  EFI_LIST_ENTRY          EventHead;\r
+  UINTN                   MemoryDescriptorSize;\r
+  UINT32                  MemoryDesciptorVersion;\r
+  UINTN                   MemoryMapSize;\r
+  EFI_MEMORY_DESCRIPTOR   *MemoryMapPhysical;\r
+  EFI_MEMORY_DESCRIPTOR   *MemoryMapVirtual;\r
+  BOOLEAN                 VirtualMode;\r
+  BOOLEAN                 AtRuntime;\r
 };\r
 \r
 extern EFI_GUID gEfiRuntimeArchProtocolGuid;\r
index d04801446240c99c55bbd2b772d15e4e62620573..9b1d5ce966ed7e18ac67808f6353c56739b06401 100644 (file)
@@ -449,7 +449,7 @@ EFI_STATUS
 // DXE Services Table\r
 //\r
 #define EFI_DXE_SERVICES_SIGNATURE  0x565245535f455844ULL\r
-#define EFI_DXE_SERVICES_REVISION   ((0 << 16) | (25))\r
+#define EFI_DXE_SERVICES_REVISION   ((0 << 16) | (90))\r
 \r
 typedef struct {\r
   EFI_TABLE_HEADER                Hdr;\r
index 266df7733c09ca902e97e62044f1b09bca620d95..7f494f71b5806d6cd5de0217d04cc8d639cc477c 100644 (file)
@@ -696,16 +696,6 @@ BcdToDecimal8 (
   IN      UINT8                     Value\r
   );\r
 \r
-//\r
-// LIST_ENTRY definition\r
-//\r
-typedef struct _LIST_ENTRY LIST_ENTRY;\r
-\r
-struct _LIST_ENTRY {\r
-  LIST_ENTRY  *ForwardLink;\r
-  LIST_ENTRY  *BackLink;\r
-};\r
-\r
 //\r
 // Linked List Functions and Macros\r
 //\r
index d112aac93f493b43feb6d1be35da90cd04de225d..86fa64c265a75831de690198a8a53ff33e473719 100644 (file)
     </Entry>\r
     <Entry Name="Runtime">\r
       <C_Name>gEfiRuntimeArchProtocolGuid</C_Name>\r
-      <GuidValue>96D08253-8483-11D4-BCF1-0080C73C8881</GuidValue>\r
+      <GuidValue>b7dfb4e1-052f-449f-87be-9818fc91b733</GuidValue>\r
       <HelpText/>\r
     </Entry>\r
     <Entry Name="Security">\r