]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/Pei/Variable.c
if it's in recovery mode, variable region is unreliable, so the ReadOnlyVariable2Ppi...
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / Pei / Variable.c
index 26cbe60d67456f2bb2a99233915d43d10e4ef0df..320d4526c7fe4e840a58f91a79047f33bf6d6f8b 100644 (file)
@@ -3,7 +3,7 @@
   Implement ReadOnly Variable Services required by PEIM and install\r
   PEI ReadOnly Varaiable2 PPI. These services operates the non volatile storage space.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\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
@@ -32,6 +32,17 @@ EFI_PEI_PPI_DESCRIPTOR     mPpiListVariable = {
   &mVariablePpi\r
 };\r
 \r
+EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpiRecovery = {\r
+  PeiGetVariableRecovery,\r
+  PeiGetNextVariableNameRecovery\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR     mPpiListVariableRecovery = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiReadOnlyVariable2PpiGuid,\r
+  &mVariablePpiRecovery\r
+};\r
+\r
 EFI_GUID mEfiVariableIndexTableGuid = EFI_VARIABLE_INDEX_TABLE_GUID;\r
 \r
 \r
@@ -57,15 +68,16 @@ PeimInitializeVariableServices (
   EFI_STATUS    Status;\r
 \r
   //\r
-  // Check if this is recovery boot path. If no, publish the variable access capability\r
-  // to other modules. If yes, the content of variable area is not reliable. Therefore,\r
-  // in this case we should not provide variable service to other pei modules. \r
+  // Check if this is recovery boot path.\r
+  // If no, provide other modules the access capability to variable area in NV storage.\r
+  // If yes, the content of variable area is not reliable. Therefore,\r
+  // we provide a dummy ReadOnlyVariable2Ppi interface to other pei modules.\r
   // \r
   Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode);\r
   ASSERT_EFI_ERROR (Status);\r
   \r
   if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
-    return EFI_UNSUPPORTED;\r
+    return PeiServicesInstallPpi (&mPpiListVariableRecovery);\r
   }\r
 \r
   return PeiServicesInstallPpi (&mPpiListVariable);\r
@@ -672,3 +684,84 @@ PeiGetNextVariableName (
 \r
   return EFI_NOT_FOUND;\r
 }\r
+\r
+/**\r
+  This service retrieves a variable's value using its name and GUID.\r
+\r
+  Read the specified variable from the UEFI variable store. If the Data \r
+  buffer is too small to hold the contents of the variable, the error\r
+  EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the required buffer\r
+  size to obtain the data.\r
+\r
+  @param  This                  A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r
+  @param  VariableName          A pointer to a null-terminated string that is the variable's name.\r
+  @param  VariableGuid          A pointer to an EFI_GUID that is the variable's GUID. The combination of\r
+                                VariableGuid and VariableName must be unique.\r
+  @param  Attributes            If non-NULL, on return, points to the variable's attributes.\r
+  @param  DataSize              On entry, points to the size in bytes of the Data buffer.\r
+                                On return, points to the size of the data returned in Data.\r
+  @param  Data                  Points to the buffer which will hold the returned variable value.\r
+\r
+  @retval EFI_SUCCESS           The variable was read successfully.\r
+  @retval EFI_NOT_FOUND         The variable could not be found.\r
+  @retval EFI_BUFFER_TOO_SMALL  The DataSize is too small for the resulting data. \r
+                                DataSize is updated with the size required for \r
+                                the specified variable.\r
+  @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize or Data is NULL.\r
+  @retval EFI_DEVICE_ERROR      The variable could not be retrieved because of a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetVariableRecovery (\r
+  IN CONST  EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
+  IN CONST  CHAR16                          *VariableName,\r
+  IN CONST  EFI_GUID                        *VariableGuid,\r
+  OUT       UINT32                          *Attributes,\r
+  IN OUT    UINTN                           *DataSize,\r
+  OUT       VOID                            *Data\r
+  )\r
+{\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+  Return the next variable name and GUID.\r
+\r
+  This function is called multiple times to retrieve the VariableName \r
+  and VariableGuid of all variables currently available in the system. \r
+  On each call, the previous results are passed into the interface, \r
+  and, on return, the interface returns the data for the next \r
+  interface. When the entire variable list has been returned, \r
+  EFI_NOT_FOUND is returned.\r
+\r
+  @param  This              A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r
+\r
+  @param  VariableNameSize  On entry, points to the size of the buffer pointed to by VariableName.\r
+  @param  VariableName      On entry, a pointer to a null-terminated string that is the variable's name.\r
+                            On return, points to the next variable's null-terminated name string.\r
+\r
+  @param  VariableGuid      On entry, a pointer to an UEFI _GUID that is the variable's GUID. \r
+                            On return, a pointer to the next variable's GUID.\r
+\r
+  @retval EFI_SUCCESS           The variable was read successfully.\r
+  @retval EFI_NOT_FOUND         The variable could not be found.\r
+  @retval EFI_BUFFER_TOO_SMALL  The VariableNameSize is too small for the resulting\r
+                                data. VariableNameSize is updated with the size\r
+                                required for the specified variable.\r
+  @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or\r
+                                VariableNameSize is NULL.\r
+  @retval EFI_DEVICE_ERROR      The variable could not be retrieved because of a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetNextVariableNameRecovery (\r
+  IN CONST  EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
+  IN OUT UINTN                              *VariableNameSize,\r
+  IN OUT CHAR16                             *VariableName,\r
+  IN OUT EFI_GUID                           *VariableGuid\r
+  )\r
+{\r
+  return EFI_NOT_FOUND;\r
+}\r