]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/RuntimeDxe/Runtime.c
MdeModulePkg/S3SmmInitDone.h: Fix copyright coding style error.
[mirror_edk2.git] / MdeModulePkg / Core / RuntimeDxe / Runtime.c
index a36dc938bd70e3219db14d8612e7dd7f50babf09..0557457e04ff5faa15308d544797a03444ef962b 100644 (file)
@@ -1,21 +1,6 @@
-/*++\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
-  Runtime.c\r
-\r
-Abstract:\r
-\r
-  Runtime Architectural Protocol as defined in the DXE CIS\r
+/** @file\r
+  This file implements Runtime Architectural Protocol as defined in the\r
+  Platform Initialization specification 1.0 VOLUME 2 DXE Core Interface.\r
 \r
   This code is used to produce the EFI runtime virtual switch over\r
 \r
@@ -30,7 +15,7 @@ Abstract:
   So here is the concept. The code in this module will never ever be called in\r
   virtual mode. This is the code that collects the information needed to convert\r
   to virtual mode (DXE core registers runtime stuff with this code). Since this\r
-  code is used to fixup all runtime images, it CAN NOT fix it's self up. So some\r
+  code is used to fix up all runtime images, it CAN NOT fix it's self up. So some\r
   code has to stay behind and that is us.\r
 \r
   Also you need to be careful about when you allocate memory, as once we are in\r
@@ -49,7 +34,17 @@ Revision History:
   Runtime Arch Protocol definition no longer contains CalculateCrc32. Boot Service\r
   Table now contains an item named CalculateCrc32.\r
 \r
---*/\r
+\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+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
+**/\r
 \r
 #include "Runtime.h"\r
 \r
@@ -90,28 +85,21 @@ EFI_RUNTIME_ARCH_PROTOCOL     mRuntime = {
 //\r
 // Worker Functions\r
 //\r
-STATIC\r
-VOID\r
-RuntimeDriverCalculateEfiHdrCrc (\r
-  IN OUT EFI_TABLE_HEADER  *Hdr\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
-  Calcualte the 32-bit CRC in a EFI table using the Runtime Drivers\r
+  Calculate the 32-bit CRC in a EFI table using the Runtime Drivers\r
   internal function.  The EFI Boot Services Table can not be used because\r
-  the EFI Boot Services Table was destroyed at ExitBootServices()\r
+  the EFI Boot Services Table was destroyed at ExitBootServices().\r
+  This is a internal function.\r
 \r
-Arguments:\r
 \r
-  Hdr  - Pointer to an EFI standard header\r
+  @param Hdr             Pointer to an EFI standard header\r
 \r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
+**/\r
+VOID\r
+RuntimeDriverCalculateEfiHdrCrc (\r
+  IN OUT EFI_TABLE_HEADER  *Hdr\r
+  )\r
 {\r
   UINT32  Crc;\r
 \r
@@ -122,32 +110,27 @@ Returns:
   Hdr->CRC32 = Crc;\r
 }\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeDriverConvertPointer (\r
-  IN     UINTN  DebugDisposition,\r
-  IN OUT VOID   **ConvertAddress\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\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
+  @param DebugDisposition Supplies type information for the pointer being converted.\r
+  @param 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
-  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
+  @retval  EFI_SUCCESS              The pointer pointed to by Address was modified.\r
+  @retval  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
+  @retval  EFI_INVALID_PARAMETER    One of the parameters has an invalid value.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeDriverConvertPointer (\r
+  IN     UINTN  DebugDisposition,\r
+  IN OUT VOID   **ConvertAddress\r
+  )\r
 {\r
   UINTN                 Address;\r
   UINT64                VirtEndOfRange;\r
@@ -169,17 +152,17 @@ Returns:
   // If this is a null pointer, return if it's allowed\r
   //\r
   if (Address == 0) {\r
-    if (DebugDisposition & EFI_OPTIONAL_POINTER) {\r
+    if ((DebugDisposition & EFI_OPTIONAL_PTR) != 0) {\r
       return EFI_SUCCESS;\r
     }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  VirtEntry             = mVirtualMap;\r
+  VirtEntry = mVirtualMap;\r
   for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {\r
     //\r
-    // To prevent the inclusion of 64-bit math functions a UINTN was placed in\r
+    //  To prevent the inclusion of 64-bit math functions a UINTN was placed in\r
     //  front of VirtEntry->NumberOfPages to cast it to a 32-bit thing on IA-32\r
     //  platforms. If you get this ASSERT remove the UINTN and do a 64-bit\r
     //  multiply.\r
@@ -199,41 +182,57 @@ Returns:
       }\r
     }\r
 \r
-    VirtEntry = NextMemoryDescriptor (VirtEntry, mVirtualMapDescriptorSize);\r
+    VirtEntry = NEXT_MEMORY_DESCRIPTOR (VirtEntry, mVirtualMapDescriptorSize);\r
   }\r
 \r
   return EFI_NOT_FOUND;\r
 }\r
 \r
-STATIC\r
-EFI_STATUS\r
-RuntimeDriverConvertInternalPointer (\r
-  IN OUT VOID   **ConvertAddress\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Determines the new virtual address that is to be used on subsequent memory accesses\r
   for internal pointers.\r
+  This is a internal function.\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
+  @param 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
-  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
+  @retval  EFI_SUCCESS              The pointer pointed to by Address was modified.\r
+  @retval  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
+  @retval  EFI_INVALID_PARAMETER    One of the parameters has an invalid value.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+RuntimeDriverConvertInternalPointer (\r
+  IN OUT VOID   **ConvertAddress\r
+  )\r
 {\r
   return RuntimeDriverConvertPointer (0x0, ConvertAddress);\r
 }\r
 \r
+/**\r
+\r
+  Changes the runtime addressing mode of EFI firmware from physical to virtual.\r
+\r
+\r
+  @param MemoryMapSize   The size in bytes of VirtualMap.\r
+  @param DescriptorSize  The size in bytes of an entry in the VirtualMap.\r
+  @param DescriptorVersion The version of the structure entries in VirtualMap.\r
+  @param VirtualMap      An array of memory descriptors which contain new virtual\r
+                         address mapping information for all runtime ranges.\r
+\r
+  @retval  EFI_SUCCESS            The virtual address map has been applied.\r
+  @retval  EFI_UNSUPPORTED        EFI firmware is not at runtime, or the EFI firmware is already in\r
+                                  virtual address mapped mode.\r
+  @retval  EFI_INVALID_PARAMETER  DescriptorSize or DescriptorVersion is invalid.\r
+  @retval  EFI_NO_MAPPING         A virtual address was not supplied for a range in the memory\r
+                                  map that requires a mapping.\r
+  @retval  EFI_NOT_FOUND          A virtual address was supplied for an address that is not found\r
+                                  in the memory map.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeDriverSetVirtualAddressMap (\r
@@ -242,44 +241,12 @@ 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
   EFI_RUNTIME_EVENT_ENTRY       *RuntimeEvent;\r
   EFI_RUNTIME_IMAGE_ENTRY       *RuntimeImage;\r
   LIST_ENTRY                    *Link;\r
   EFI_PHYSICAL_ADDRESS          VirtImageBase;\r
-  UINTN                         Index;\r
-  UINTN                         Index1;\r
-  UINTN                         Index2;\r
-  UINTN                         Index3;\r
-  EFI_CAPSULE_TABLE             *CapsuleTable; \r
-  EFI_CAPSULE_INFO_TABLE        *CapsuleInfoTable; \r
 \r
   //\r
   // Can only switch to virtual addresses once the memory map is locked down,\r
@@ -308,18 +275,21 @@ Returns:
   mVirtualMap               = VirtualMap;\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
-  // mEfiAtRuntime global So this ReportStatusCode will work\r
+  // ReporstStatusCodeLib will check and make sure this service can be called in runtime mode.\r
+  //\r
+  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_SET_VIRTUAL_ADDRESS_MAP));\r
+\r
+  //\r
+  // Report Status Code here since EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event will be signalled.\r
   //\r
-  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValueSetVirtualAddressMap));\r
+  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_VIRTUAL_ADDRESS_CHANGE_EVENT));\r
 \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 = mRuntime.EventHead.ForwardLink; Link != &mRuntime.EventHead; Link = Link->ForwardLink) {\r
-    RuntimeEvent = _CR (Link, EFI_RUNTIME_EVENT_ENTRY, Link);\r
+    RuntimeEvent = BASE_CR (Link, EFI_RUNTIME_EVENT_ENTRY, Link);\r
     if ((RuntimeEvent->Type & EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {\r
       RuntimeEvent->NotifyFunction (\r
                       RuntimeEvent->Event,\r
@@ -332,7 +302,7 @@ Returns:
   // Relocate runtime images. All runtime images are stored in a list in Runtime AP.\r
   //\r
   for (Link = mRuntime.ImageHead.ForwardLink; Link != &mRuntime.ImageHead; Link = Link->ForwardLink) {\r
-    RuntimeImage = _CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link);\r
+    RuntimeImage = BASE_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
@@ -349,7 +319,7 @@ Returns:
         RuntimeImage->RelocationData\r
         );\r
 \r
-      InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN)RuntimeImage->ImageSize);\r
+      InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN) RuntimeImage->ImageSize);\r
     }\r
   }\r
 \r
@@ -372,44 +342,8 @@ Returns:
   RuntimeDriverCalculateEfiHdrCrc (&gRT->Hdr);\r
 \r
   //\r
-  // BugBug: PI requires System Configuration Tables Conversion.\r
-  // Currently, we do not implement it.\r
+  // UEFI don't require System Configuration Tables Conversion.\r
   //\r
-  for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r
-    //\r
-    // CapsuleInfoGuid in ConfigTable refers to an array of CapsuleGuid, it is information\r
-    // from which you can tell which vendorGuids in ConfigTable are related to CapsuleTable.\r
-    // Each CapsuleTable points to a array of capsules across a system reset. Then convert \r
-    // the array contents to make these capsules visiable in Runtime.\r
-    //\r
-\r
-    //\r
-    // Firstly, Get CapsulInfoGuid in ConfigTable, it points to CapsuleInfoTable, which\r
-    // gather all the installed capsules' guids.\r
-    //\r
-    if (CompareGuid (&gEfiCapsuleInfoGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
-      CapsuleInfoTable = gST->ConfigurationTable[Index].VendorTable;\r
-      //\r
-      // For each known CapsuleGuid in CapsuleInfoTable, loop the whole ConfigTable to\r
-      // find out this guid related to CapsuleTable.\r
-      //\r
-      for (Index1 = 0; Index1 < CapsuleInfoTable->CapsuleGuidNumber; Index1++) {\r
-        for (Index2 = 0; Index2 < gST->NumberOfTableEntries; Index2++) {\r
-          //\r
-          // Find out certain CapsuleTable, go through its contents array, and convert them.\r
-          //\r
-          if (CompareGuid (&CapsuleInfoTable->CapsuleGuidPtr[Index1], &(gST->ConfigurationTable[Index2].VendorGuid))) {\r
-            CapsuleTable = gST->ConfigurationTable[Index2].VendorTable;\r
-            for (Index3 = 0; Index3 < CapsuleTable->CapsuleArrayNumber; Index3++) {\r
-              RuntimeDriverConvertInternalPointer ((VOID **) &CapsuleTable->CapsulePtr[Index3]);\r
-            }     \r
-            RuntimeDriverConvertInternalPointer ((VOID **) &(gST->ConfigurationTable[Index2].VendorTable));\r
-          }\r
-        }\r
-      }\r
-      break;\r
-    }\r
-  }\r
 \r
   //\r
   // Convert the runtime fields of the EFI System Table and recompute the CRC-32\r
@@ -431,35 +365,31 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Entry Point for Runtime driver.\r
+\r
+  This function installs Runtime Architectural Protocol and registers CalculateCrc32 boot services table,\r
+  SetVirtualAddressMap & ConvertPointer runtime services table.\r
+\r
+  @param ImageHandle     Image handle of this driver.\r
+  @param SystemTable     a Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCEESS  Runtime Driver Architectural Protocol is successfully installed\r
+  @return  Others       Some error occurs when installing Runtime Driver Architectural Protocol.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeDriverInitialize (\r
   IN EFI_HANDLE                            ImageHandle,\r
   IN EFI_SYSTEM_TABLE                      *SystemTable\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Install Runtime AP. This code includes the EfiDriverLib, but it functions at\r
-  RT in physical mode. The only Lib services are gBS, gRT, and the DEBUG and\r
-  ASSERT macros (they do ReportStatusCode).\r
-\r
-Arguments:\r
-  (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
-\r
-Returns:\r
-\r
-  EFI_SUCEESS - Runtime Driver Architectural Protocol Installed\r
-\r
-  Other       - Return value from gBS->InstallMultipleProtocolInterfaces\r
-\r
---*/\r
 {\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
+  // This image needs to be excluded from relocation for virtual mode, so cache\r
   // a copy of the Loaded Image protocol to test later.\r
   //\r
   Status = gBS->HandleProtocol (\r
@@ -470,11 +400,6 @@ Returns:
   ASSERT_EFI_ERROR (Status);\r
   mMyImageBase = MyLoadedImage->ImageBase;\r
 \r
-  //\r
-  // Initialize the table used to compute 32-bit CRCs\r
-  //\r
-  RuntimeDriverInitializeCrc32Table ();\r
-\r
   //\r
   // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables\r
   //\r
@@ -493,5 +418,5 @@ Returns:
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r