]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Compatibility/ReadOnlyVariable2ToReadOnlyVariableThunk/ReadOnlyVariable2ToReadOnlyVariableThunk.c
Add an ASSERT to make sure this thunk module can only be used together with a PI...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / ReadOnlyVariable2ToReadOnlyVariableThunk / ReadOnlyVariable2ToReadOnlyVariableThunk.c
index 832dc520e557653d7a2df6868396dff7d683e30e..7e2ca126d1dcdc50d0a35307ea6bb974b5997fb9 100644 (file)
@@ -1,4 +1,15 @@
-/*++\r
+/** @file\r
+Module produce EFI_PEI_READ_ONLY_VARIABLE2_PPI on top of EFI_PEI_READ_ONLY_VARIABLE_PPI.\r
+UEFI PI Spec supersedes Intel's Framework Specs. \r
+EFI_PEI_READ_ONLY_VARIABLE_PPI defined in Intel Framework Pkg is replaced by EFI_PEI_READ_ONLY_VARIABLE2_PPI\r
+in MdePkg.\r
+This module produces EFI_PEI_READ_ONLY_VARIABLE2_PPI on top of EFI_PEI_READ_ONLY_VARIABLE_PPI. \r
+This module is used on platform when both of these two conditions are true:\r
+1) Framework module produces EFI_PEI_READ_ONLY_VARIABLE_PPI is present.\r
+2) The platform has PI modules that only consumes EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r
+\r
+This module can't be used together with ReadOnlyVariableToReadOnlyVariable2Thunk module.\r
+\r
 \r
 Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
 All rights reserved. This program and the accompanying materials\r
@@ -10,17 +21,12 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 Module Name:\r
 \r
-  Variable.c\r
-\r
-Abstract:\r
-\r
-  PEIM to provide the Variable functionality\r
-\r
---*/\r
+**/\r
 \r
 #include <PiPei.h>\r
 #include <Ppi/ReadOnlyVariable2.h>\r
 #include <Ppi/ReadOnlyVariable.h>\r
+#include <Ppi/ReadOnlyVariableThunkPresent.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PeiServicesTablePointerLib.h>\r
 #include <Library/PeiServicesLib.h>\r
@@ -62,6 +68,13 @@ EFI_PEI_PPI_DESCRIPTOR     mPpiListVariable = {
   &mVariablePpi\r
 };\r
 \r
+\r
+EFI_PEI_PPI_DESCRIPTOR     mReadOnlyVariableThunkPresent = {\r
+    (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+    &gPeiReadonlyVariableThunkPresentPpiGuid,\r
+    NULL\r
+};\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 PeimInitializeReadOnlyVariable2 (\r
@@ -86,12 +99,46 @@ Returns:
 \r
 --*/\r
 {\r
+  VOID        *Interface;\r
+  EFI_STATUS  Status;\r
+  //\r
+  // This thunk module can only be used together with a PI PEI core, as we \r
+  // assume PeiServices Pointer Table can be located in a standard way defined\r
+  // in PI spec.\r
+  //\r
+  ASSERT ((*PeiServices)->Hdr.Revision >= 0x00010000);\r
+\r
+  //\r
+  // Make sure ReadOnlyVariable2ToReadOnlyVariable module is not present. If so, the call chain will form a\r
+  // infinite loop: ReadOnlyVariable2 -> ReadOnlyVariable -> ReadOnlyVariable2 -> ....\r
+  //\r
+  Status = PeiServicesLocatePpi (&gPeiReadonlyVariableThunkPresentPpiGuid, 0, NULL, &Interface);\r
+  ASSERT (Status == EFI_NOT_FOUND);\r
+  \r
+  Status = PeiServicesInstallPpi (&mReadOnlyVariableThunkPresent);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
   //\r
   // Publish the variable capability to other modules\r
   //\r
   return PeiServicesInstallPpi (&mPpiListVariable);\r
 }\r
 \r
+/**\r
+  Provide the read variable functionality of the variable services.\r
+\r
+  @param  PeiServices           General purpose services available to every PEIM.\r
+  @param  VariableName          The variable name\r
+  @param  VendorGuid            The vendor's GUID\r
+  @param  Attributes            Pointer to the attribute\r
+  @param  DataSize              Size of data\r
+  @param  Data                  Pointer to data\r
+\r
+  @retval EFI_SUCCESS           The interface could be successfully installed\r
+  @retval EFI_NOT_FOUND         The variable could not be discovered\r
+  @retval EFI_BUFFER_TOO_SMALL  The caller buffer is not large enough\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiGetVariable (\r
@@ -102,35 +149,6 @@ PeiGetVariable (
   IN OUT    UINTN                           *DataSize,\r
   OUT       VOID                            *Data\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Provide the read variable functionality of the variable services.\r
-\r
-Arguments:\r
-\r
-  PeiServices - General purpose services available to every PEIM.\r
-\r
-  VariableName     - The variable name\r
-\r
-  VendorGuid       - The vendor's GUID\r
-\r
-  Attributes       - Pointer to the attribute\r
-\r
-  DataSize         - Size of data\r
-\r
-  Data             - Pointer to data\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS           - The interface could be successfully installed\r
-\r
-  EFI_NOT_FOUND         - The variable could not be discovered\r
-\r
-  EFI_BUFFER_TOO_SMALL  - The caller buffer is not large enough\r
-\r
---*/\r
 {\r
   EFI_STATUS                     Status;\r
   EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;\r
@@ -153,6 +171,21 @@ Returns:
                              );\r
 }\r
 \r
+/**\r
+  Provide the get next variable functionality of the variable services.\r
+\r
+  @param  PeiServices           General purpose services available to every PEIM.\r
+  @param  VariabvleNameSize     The variable name's size.\r
+  @param  VariableName          A pointer to the variable's name.\r
+  @param  VariableGuid          A pointer to the EFI_GUID structure.\r
+  @param  VariableNameSize      Size of the variable name\r
+  @param  VariableName          The variable name\r
+  @param  VendorGuid            The vendor's GUID\r
+\r
+  @retval EFI_SUCCESS           The interface could be successfully installed\r
+  @retval EFI_NOT_FOUND         The variable could not be discovered\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiGetNextVariableName (\r
@@ -161,32 +194,6 @@ PeiGetNextVariableName (
   IN OUT CHAR16                             *VariableName,\r
   IN OUT EFI_GUID                           *VariableGuid\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Provide the get next variable functionality of the variable services.\r
-\r
-Arguments:\r
-\r
-  PeiServices        - General purpose services available to every PEIM.\r
-  VariabvleNameSize  - The variable name's size.\r
-  VariableName       - A pointer to the variable's name.\r
-  VariableGuid       - A pointer to the EFI_GUID structure.\r
-\r
-  VariableNameSize - Size of the variable name\r
-\r
-  VariableName     - The variable name\r
-\r
-  VendorGuid       - The vendor's GUID\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - The interface could be successfully installed\r
-\r
-  EFI_NOT_FOUND - The variable could not be discovered\r
-\r
---*/\r
 {\r
   EFI_STATUS                     Status;\r
   EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;\r