]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
Add capsule > 4GB support. When capsule data is put above 4GB, IA32 PEI transfers...
[mirror_edk2.git] / MdeModulePkg / Universal / CapsuleRuntimeDxe / CapsuleService.c
index fc9fc0e78f6007c34525b8dba75845b6ea58c43d..17f167c978cad91e9d45d93dc52899b9f4efaaba 100644 (file)
@@ -4,8 +4,8 @@
   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. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2011, 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
@@ -27,12 +27,28 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/UefiRuntimeLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PrintLib.h>\r
 \r
 //\r
 // Handle for the installation of Capsule Architecture Protocol.\r
 //\r
 EFI_HANDLE  mNewHandle = NULL;\r
 \r
+//\r
+// The times of calling UpdateCapsule ()\r
+//\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
@@ -72,6 +88,8 @@ UpdateCapsule (
   EFI_CAPSULE_HEADER        *CapsuleHeader;\r
   BOOLEAN                   NeedReset;\r
   BOOLEAN                   InitiateReset;\r
+  CHAR16                    CapsuleVarName[30];\r
+  CHAR16                    *TempVarName;  \r
   \r
   //\r
   // Capsule Count can't be less than one.\r
@@ -80,9 +98,10 @@ UpdateCapsule (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  NeedReset     = FALSE;\r
-  InitiateReset = FALSE;\r
-  CapsuleHeader = NULL;\r
+  NeedReset         = FALSE;\r
+  InitiateReset     = FALSE;\r
+  CapsuleHeader     = NULL;\r
+  CapsuleVarName[0] = 0;\r
 \r
   for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
     //\r
@@ -159,25 +178,41 @@ UpdateCapsule (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Construct variable name CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...\r
+  // if user calls UpdateCapsule multiple times.\r
+  //\r
+  StrCpy (CapsuleVarName, EFI_CAPSULE_VARIABLE_NAME);\r
+  TempVarName = CapsuleVarName + StrLen (CapsuleVarName);\r
+  if (mTimes > 0) {\r
+    UnicodeValueToString (TempVarName, 0, mTimes, 0);\r
+  }\r
+\r
   //\r
   // ScatterGatherList is only referenced if the capsules are defined to persist across\r
   // system reset. Set its value into NV storage to let pre-boot driver to pick it up \r
   // after coming through a system reset.\r
   //\r
   Status = EfiSetVariable (\r
-             EFI_CAPSULE_VARIABLE_NAME,\r
+             CapsuleVarName,\r
              &gEfiCapsuleVendorGuid,\r
              EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
              sizeof (UINTN),\r
              (VOID *) &ScatterGatherList\r
              );\r
-  if (!EFI_ERROR (Status) && InitiateReset) {\r
-    //\r
-    // Firmware that encounters a capsule which has the CAPSULE_FLAGS_INITIATE_RESET Flag set in its header\r
-    // will initiate a reset of the platform which is compatible with the passed-in capsule request and will \r
-    // not return back to the caller.\r
-    //\r
-    EfiResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+  if (!EFI_ERROR (Status)) {\r
+     //\r
+     // Variable has been set successfully, increase variable index.\r
+     //\r
+     mTimes++;\r
+     if(InitiateReset) {\r
+       //\r
+       // Firmware that encounters a capsule which has the CAPSULE_FLAGS_INITIATE_RESET Flag set in its header\r
+       // will initiate a reset of the platform which is compatible with the passed-in capsule request and will \r
+       // not return back to the caller.\r
+       //\r
+       EfiResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+     }\r
   }\r
   return Status;\r
 }\r
@@ -212,6 +247,7 @@ QueryCapsuleCapabilities (
 {\r
   UINTN                     ArrayNumber;\r
   EFI_CAPSULE_HEADER        *CapsuleHeader;\r
+  BOOLEAN                   NeedReset;\r
 \r
   //\r
   // Capsule Count can't be less than one.\r
@@ -228,6 +264,7 @@ QueryCapsuleCapabilities (
   }\r
 \r
   CapsuleHeader = NULL;\r
+  NeedReset     = FALSE;\r
 \r
   for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
     CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
@@ -255,31 +292,31 @@ QueryCapsuleCapabilities (
   }\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
@@ -305,6 +342,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