]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
Enable UEFI firmware to support FMP capsule format.
[mirror_edk2.git] / MdeModulePkg / Universal / CapsuleRuntimeDxe / CapsuleService.c
index a3b53262ef3a29f702f724ac75f698813d9082c3..0861a64778db48abc97ad9354150a36d88f958a9 100644 (file)
@@ -4,7 +4,7 @@
   It installs the Capsule Architectural Protocol defined in PI1.0a to signify \r
   the capsule runtime services are ready.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -19,6 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Protocol/Capsule.h>\r
 #include <Guid/CapsuleVendor.h>\r
+#include <Guid/FmpCapsule.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/PcdLib.h>\r
@@ -29,7 +30,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiRuntimeLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/PrintLib.h>\r
-\r
+#include <Library/BaseMemoryLib.h>\r
 //\r
 // Handle for the installation of Capsule Architecture Protocol.\r
 //\r
@@ -40,6 +41,15 @@ EFI_HANDLE  mNewHandle = NULL;
 //\r
 UINTN       mTimes      = 0;\r
 \r
+/**\r
+  Create the variable to save the base address of page table and stack\r
+  for transferring into long mode in IA32 PEI.\r
+**/\r
+VOID\r
+SaveLongModeContext (\r
+  VOID\r
+  );\r
+\r
 /**\r
   Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended\r
   consumption, the firmware may process the capsule immediately. If the payload should persist\r
@@ -64,6 +74,11 @@ UINTN       mTimes      = 0;
   @retval EFI_INVALID_PARAMETER CapsuleCount is Zero.\r
   @retval EFI_INVALID_PARAMETER For across reset capsule image, ScatterGatherList is NULL.\r
   @retval EFI_UNSUPPORTED       CapsuleImage is not recognized by the firmware.\r
+  @retval EFI_OUT_OF_RESOURCES  When ExitBootServices() has been previously called this error indicates the capsule \r
+                                is compatible with this platform but is not capable of being submitted or processed \r
+                                in runtime. The caller may resubmit the capsule prior to ExitBootServices().\r
+  @retval EFI_OUT_OF_RESOURCES  When ExitBootServices() has not been previously called then this error indicates \r
+                                the capsule is compatible with this platform but there are insufficient resources to process.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -110,12 +125,23 @@ UpdateCapsule (
     if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET)) == CAPSULE_FLAGS_INITIATE_RESET) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
+\r
+    //\r
+    // Check FMP capsule flag \r
+    //\r
+    if (CompareGuid(&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)\r
+     && (CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0 ) {\r
+       return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
     //\r
     // Check Capsule image without populate flag by firmware support capsule function  \r
     //\r
-    if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
-        (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
-      return EFI_UNSUPPORTED;\r
+    if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
+      Status = SupportCapsuleImage (CapsuleHeader);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
     }\r
   }\r
 \r
@@ -131,7 +157,7 @@ UpdateCapsule (
     //\r
     if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) == 0) {\r
       if (EfiAtRuntime ()) { \r
-        Status = EFI_UNSUPPORTED;\r
+        Status = EFI_OUT_OF_RESOURCES;\r
       } else {\r
         Status = ProcessCapsuleImage(CapsuleHeader);\r
       }\r
@@ -236,8 +262,10 @@ QueryCapsuleCapabilities (
   OUT EFI_RESET_TYPE       *ResetType\r
   )\r
 {\r
+  EFI_STATUS                Status;\r
   UINTN                     ArrayNumber;\r
   EFI_CAPSULE_HEADER        *CapsuleHeader;\r
+  BOOLEAN                   NeedReset;\r
 \r
   //\r
   // Capsule Count can't be less than one.\r
@@ -254,6 +282,7 @@ QueryCapsuleCapabilities (
   }\r
 \r
   CapsuleHeader = NULL;\r
+  NeedReset     = FALSE;\r
 \r
   for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
     CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
@@ -271,41 +300,52 @@ QueryCapsuleCapabilities (
     if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET)) == CAPSULE_FLAGS_INITIATE_RESET) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
+\r
+    //\r
+    // Check FMP capsule flag \r
+    //\r
+    if (CompareGuid(&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)\r
+     && (CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0 ) {\r
+       return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
     //\r
     // Check Capsule image without populate flag is supported by firmware\r
     //\r
-    if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
-        (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
-      return EFI_UNSUPPORTED;\r
+    if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
+      Status = SupportCapsuleImage (CapsuleHeader);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
     }\r
   }\r
 \r
   //\r
-  // Assume that capsules have the same flags on reseting or not.\r
+  // Find out whether there is any capsule defined to persist across system reset. \r
   //\r
-  CapsuleHeader = CapsuleHeaderArray[0];\r
-  if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
+  for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r
+    CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
+    if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
+      NeedReset = TRUE;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (NeedReset) {\r
     //\r
     //Check if the platform supports update capsule across a system reset\r
     //\r
     if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r
       return EFI_UNSUPPORTED;\r
     }\r
-    *ResetType = EfiResetWarm;   \r
+    *ResetType = EfiResetWarm;\r
+    *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule);\r
   } else {\r
     //\r
     // For non-reset capsule image.\r
     //\r
     *ResetType = EfiResetCold;\r
-  }\r
-  \r
-  //\r
-  // The support max capsule image size\r
-  //\r
-  if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r
-    *MaxiumCapsuleSize = PcdGet32(PcdMaxSizePopulateCapsule);\r
-  } else {\r
-    *MaxiumCapsuleSize = PcdGet32(PcdMaxSizeNonPopulateCapsule);\r
+    *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -331,6 +371,15 @@ CapsuleServiceInitialize (
 {\r
   EFI_STATUS  Status;\r
   \r
+  //\r
+  // When PEI phase is IA32, DXE phase is X64, it is possible that capsule data are \r
+  // put above 4GB, so capsule PEI will transfer to long mode to get capsule data.\r
+  // The page table and stack is used to transfer processor mode from IA32 to long mode.\r
+  // Create the base address of page table and stack, and save them into variable.\r
+  // This is not needed when capsule with reset type is not supported.\r
+  //\r
+  SaveLongModeContext ();\r
+    \r
   //\r
   // Install capsule runtime services into UEFI runtime service tables.\r
   //\r