]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/VariablePei/Variable.c
Reviewed the code comments in the Include/Protocol directory for typos, grammar issue...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / VariablePei / Variable.c
index e050fbcf9d3f3edea3a43744ee5a813e370f0082..3a747846b3c77a17171ad34ec3419e5a4c9ebd75 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
-\r
-Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
+/** @file\r
+  Framework PEIM to provide the Variable functionality\r
+  \r
+Copyright (c) 2006 - 2009 Intel Corporation. <BR>\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
@@ -10,13 +11,7 @@ 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
-  Framework PEIM to provide the Variable functionality\r
-\r
---*/\r
+**/\r
 \r
 \r
 #include "Variable.h"\r
@@ -24,17 +19,17 @@ Abstract:
 //\r
 // Module globals\r
 //\r
-static EFI_PEI_READ_ONLY_VARIABLE_PPI mVariablePpi = {\r
+EFI_PEI_READ_ONLY_VARIABLE_PPI mVariablePpi = {\r
   PeiGetVariable,\r
   PeiGetNextVariableName\r
 };\r
 \r
-static EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariable2Ppi = {\r
+EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariable2Ppi = {\r
   PeiGetVariable2,\r
   PeiGetNextVariableName2\r
 };\r
 \r
-static EFI_PEI_PPI_DESCRIPTOR     mPpiListVariable[] = {\r
+EFI_PEI_PPI_DESCRIPTOR     mPpiListVariable[] = {\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_PPI),\r
     &gEfiPeiReadOnlyVariable2PpiGuid,\r
@@ -49,166 +44,241 @@ static EFI_PEI_PPI_DESCRIPTOR     mPpiListVariable[] = {
 \r
 EFI_GUID mEfiVariableIndexTableGuid = EFI_VARIABLE_INDEX_TABLE_GUID;\r
 \r
+/**\r
+  Provide the functionality of the variable services.\r
+\r
+  @param  FileHandle      Handle of the file being invoked.\r
+  @param  PeiServices     Describes the list of possible PEI Services.\r
+\r
+  @return EFI_SUCCESS     If the interface could be successfully installed.\r
+  @return EFI_UNSUPPORTED If current boot path is in recovery mode, then does not\r
+                          install this interface.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeimInitializeVariableServices (\r
-  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
-  IN EFI_PEI_SERVICES          **PeiServices\r
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
-/*++\r
-\r
-Routine Description:\r
+{\r
+  EFI_BOOT_MODE BootMode;\r
+  EFI_STATUS    Status;\r
 \r
-  Provide the functionality of the variable services.\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
+  // \r
+  Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  return (**PeiServices).InstallPpi (PeiServices, &mPpiListVariable[0]);\r
 \r
-Arguments:\r
+}\r
 \r
-  FfsHeadher  - The FFS file header\r
-  PeiServices - General purpose services available to every PEIM.\r
+/**\r
+  This code gets the pointer to the first variable memory pointer byte\r
 \r
-Returns:\r
+  @param VarStoreHeader        Pointer to the Variable Store Header.\r
 \r
-  Status -  EFI_SUCCESS if the interface could be successfully\r
-            installed\r
+  @return VARIABLE_HEADER*      Pointer to last unavailable Variable Header\r
 \r
---*/\r
+**/\r
+VARIABLE_HEADER *\r
+GetStartPointer (\r
+  IN VARIABLE_STORE_HEADER       *VarStoreHeader\r
+  )\r
 {\r
   //\r
-  // Publish the variable capability to other modules\r
+  // The end of variable store\r
   //\r
-  return (**PeiServices).InstallPpi ((CONST EFI_PEI_SERVICES **) PeiServices, &mPpiListVariable[0]);\r
+  return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);\r
+}\r
+\r
+/**\r
+  This code gets the pointer to the last variable memory pointer byte\r
 \r
+  @param VarStoreHeader        Pointer to the Variable Store Header.\r
+\r
+  @return  VARIABLE_HEADER*      Pointer to last unavailable Variable Header\r
+\r
+**/\r
+VARIABLE_HEADER *\r
+GetEndPointer (\r
+  IN VARIABLE_STORE_HEADER       *VarStoreHeader\r
+  )\r
+\r
+{\r
+  //\r
+  // The end of variable store\r
+  //\r
+  return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);\r
 }\r
 \r
+/**\r
 \r
-UINT32\r
-NameSizeOfVariable (\r
+  This code checks if variable header is valid or not.\r
+\r
+  @param Variable              Pointer to the Variable Header.\r
+\r
+  @retval TRUE            Variable header is valid.\r
+  @retval FALSE           Variable header is not valid.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsValidVariableHeader (\r
   IN  VARIABLE_HEADER   *Variable\r
   )\r
 {\r
-  //\r
-  // Check whether the header is valid fully;\r
-  // Tricky: The unprogramed data in FLASH equals 0xff.\r
-  // \r
-  if (Variable->DataSize == (UINT32) -1 || \r
-      Variable->Attributes == (UINT32) -1 || \r
-      Variable->NameSize == (UINT32) -1) {\r
-    return 0;\r
+  if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {\r
+    return FALSE;\r
   }\r
-  return Variable->NameSize;\r
+\r
+  return TRUE;\r
 }\r
 \r
-UINT32\r
-DataSizeOfVariable (\r
+/**\r
+  This code gets the size of name of variable.\r
+\r
+  @param Variable            Pointer to the Variable Header.\r
+\r
+  @return UINTN               Size of variable in bytes\r
+\r
+**/\r
+UINTN\r
+NameSizeOfVariable (\r
   IN  VARIABLE_HEADER   *Variable\r
   )\r
 {\r
-  //\r
-  // Check whether the header is valid fully;\r
-  // Tricky: The unprogramed data in FLASH equals 0xff.\r
-  // \r
-  if (Variable->DataSize == (UINT32) -1 || \r
-      Variable->Attributes == (UINT32) -1 || \r
-      Variable->NameSize == (UINT32) -1) {\r
+  if (Variable->State    == (UINT8) (-1) ||\r
+      Variable->DataSize == (UINT32) -1 ||\r
+      Variable->NameSize == (UINT32) -1 ||\r
+      Variable->Attributes == (UINT32) -1) {\r
     return 0;\r
   }\r
-  return Variable->DataSize;\r
+  return (UINTN) Variable->NameSize;\r
 }\r
 \r
-UINT32\r
-AttributesOfVariable (\r
+/**\r
+  This code gets the size of name of variable.\r
+\r
+  @param Variable            Pointer to the Variable Header.\r
+\r
+  @return  UINTN               Size of variable in bytes\r
+\r
+**/\r
+UINTN\r
+DataSizeOfVariable (\r
   IN  VARIABLE_HEADER   *Variable\r
   )\r
 {\r
-\r
-  //\r
-  // Check whether the header is valid fully;\r
-  // Tricky: The unprogramed data in FLASH equals 0xff.\r
-  // \r
-  if (Variable->DataSize == (UINT32) -1 || \r
-      Variable->Attributes == (UINT32) -1 || \r
-      Variable->NameSize == (UINT32) -1) {\r
+  if (Variable->State    == (UINT8)  -1 ||\r
+      Variable->DataSize == (UINT32) -1 ||\r
+      Variable->NameSize == (UINT32) -1 ||\r
+      Variable->Attributes == (UINT32) -1) {\r
     return 0;\r
   }\r
-  return Variable->Attributes;\r
+  return (UINTN) Variable->DataSize;\r
 }\r
 \r
-STATIC\r
-VARIABLE_HEADER *\r
-GetNextVariablePtr (\r
-  IN VARIABLE_HEADER  *Variable\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
+  This code gets the pointer to the variable name.\r
 \r
-  This code checks if variable header is valid or not.\r
+  @param Variable            Pointer to the Variable Header.\r
 \r
-Arguments:\r
-  Variable       Pointer to the Variable Header.\r
+  @return CHAR16*              Pointer to Variable Name\r
 \r
-Returns:\r
-  TRUE            Variable header is valid.\r
-  FALSE           Variable header is not valid.\r
+**/\r
+CHAR16 *\r
+GetVariableNamePtr (\r
+  IN  VARIABLE_HEADER   *Variable\r
+  )\r
 \r
---*/\r
 {\r
-  return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + DataSizeOfVariable (Variable) + GET_PAD_SIZE (DataSizeOfVariable (Variable)));\r
+\r
+  return (CHAR16 *) (Variable + 1);\r
 }\r
 \r
-STATIC\r
-BOOLEAN\r
-EFIAPI\r
-IsValidVariableHeader (\r
+/**\r
+  This code gets the pointer to the variable data.\r
+\r
+  @param Variable            Pointer to the Variable Header.\r
+\r
+  @return  UINT8*              Pointer to Variable Data\r
+\r
+**/\r
+UINT8 *\r
+GetVariableDataPtr (\r
   IN  VARIABLE_HEADER   *Variable\r
   )\r
-/*++\r
+{\r
+  UINTN Value;\r
+  \r
+  //\r
+  // Be careful about pad size for alignment\r
+  //\r
+  Value =  (UINTN) GetVariableNamePtr (Variable);\r
+  Value += NameSizeOfVariable (Variable);\r
+  Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));\r
+\r
+  return (UINT8 *) Value;\r
+}\r
 \r
-Routine Description:\r
+/**\r
+  This code gets the pointer to the next variable header.\r
 \r
-  This code checks if variable header is valid or not.\r
+  @param Variable              Pointer to the Variable Header.\r
 \r
-Arguments:\r
-  Variable              Pointer to the Variable Header.\r
+  @return VARIABLE_HEADER*      Pointer to next variable header.\r
 \r
-Returns:\r
-  TRUE            Variable header is valid.\r
-  FALSE           Variable header is not valid.\r
+**/\r
+VARIABLE_HEADER *\r
+GetNextVariablePtr (\r
+  IN  VARIABLE_HEADER   *Variable\r
+  )\r
 \r
---*/\r
 {\r
-  if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {\r
-    return FALSE;\r
+  UINTN Value;\r
+\r
+  if (!IsValidVariableHeader (Variable)) {\r
+    return NULL;\r
   }\r
 \r
-  return TRUE;\r
+  Value =  (UINTN) GetVariableDataPtr (Variable);\r
+  Value += DataSizeOfVariable (Variable);\r
+  Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));\r
+\r
+  //\r
+  // Be careful about pad size for alignment\r
+  //\r
+  return (VARIABLE_HEADER *) HEADER_ALIGN (Value);\r
 }\r
 \r
-STATIC\r
+/**\r
+  This code gets the pointer to the variable name.\r
+\r
+  @param VarStoreHeader  Pointer to the Variable Store Header.\r
+\r
+  @retval EfiRaw        Variable store is raw\r
+  @retval EfiValid      Variable store is valid\r
+  @retval EfiInvalid    Variable store is invalid\r
+\r
+**/\r
 VARIABLE_STORE_STATUS\r
 EFIAPI\r
 GetVariableStoreStatus (\r
   IN VARIABLE_STORE_HEADER *VarStoreHeader\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This code gets the pointer to the variable name.\r
-\r
-Arguments:\r
 \r
-  VarStoreHeader  Pointer to the Variable Store Header.\r
-\r
-Returns:\r
-\r
-  EfiRaw        Variable store is raw\r
-  EfiValid      Variable store is valid\r
-  EfiInvalid    Variable store is invalid\r
-\r
---*/\r
 {\r
-  if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\r
+       \r
+  if (CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid) &&\r
       VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
       VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
       ) {\r
@@ -216,7 +286,10 @@ Returns:
     return EfiValid;\r
   }\r
 \r
-  if (VarStoreHeader->Signature == 0xffffffff &&\r
+  if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&\r
+      ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&\r
+      ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&\r
+      ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&\r
       VarStoreHeader->Size == 0xffffffff &&\r
       VarStoreHeader->Format == 0xff &&\r
       VarStoreHeader->State == 0xff\r
@@ -228,7 +301,19 @@ Returns:
   }\r
 }\r
 \r
-STATIC\r
+/**\r
+  This function compares a variable with variable entries in database\r
+\r
+  @param Variable       - Pointer to the variable in our database\r
+  @param VariableName   - Name of the variable to compare to 'Variable'\r
+  @param VendorGuid     - GUID of the variable to compare to 'Variable'\r
+  @param PtrTrack       - Variable Track Pointer structure that contains\r
+                   Variable Information.\r
+\r
+  @retval  EFI_SUCCESS    - Found match variable\r
+  @retval EFI_NOT_FOUND  - Variable not found\r
+\r
+**/\r
 EFI_STATUS\r
 CompareWithValidVariable (\r
   IN  VARIABLE_HEADER               *Variable,\r
@@ -236,27 +321,10 @@ CompareWithValidVariable (
   IN  CONST EFI_GUID                *VendorGuid,\r
   OUT VARIABLE_POINTER_TRACK        *PtrTrack\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function compares a variable with variable entries in database\r
-\r
-Arguments:\r
-\r
-  Variable       - Pointer to the variable in our database\r
-  VariableName   - Name of the variable to compare to 'Variable'\r
-  VendorGuid     - GUID of the variable to compare to 'Variable'\r
-  PtrTrack       - Variable Track Pointer structure that contains\r
-                   Variable Information.\r
 \r
-Returns:\r
-\r
-  EFI_SUCCESS    - Found match variable\r
-  EFI_NOT_FOUND  - Variable not found\r
-\r
---*/\r
 {\r
+  VOID  *Point;\r
+\r
   if (VariableName[0] == 0) {\r
     PtrTrack->CurrPtr = Variable;\r
     return EFI_SUCCESS;\r
@@ -272,7 +340,8 @@ Returns:
         (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])\r
         ) {\r
       ASSERT (NameSizeOfVariable (Variable) != 0);\r
-      if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), NameSizeOfVariable (Variable))) {\r
+      Point = (VOID *) GetVariableNamePtr (Variable);\r
+      if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) {\r
         PtrTrack->CurrPtr = Variable;\r
         return EFI_SUCCESS;\r
       }\r
@@ -282,36 +351,29 @@ Returns:
   return EFI_NOT_FOUND;\r
 }\r
 \r
-STATIC\r
+/**\r
+  This code finds variable in storage blocks (Non-Volatile)\r
+\r
+  @param PeiServices    - General purpose services available to every PEIM.\r
+  @param VariableName   - Name of the variable to be found\r
+  @param VendorGuid     - Vendor GUID to be found.\r
+  @param PtrTrack       - Variable Track Pointer structure that contains\r
+                   Variable Information.\r
+\r
+  @retval EFI_SUCCESS      - Variable found successfully\r
+  @retval EFI_NOT_FOUND    - Variable not found\r
+  @retval EFI_INVALID_PARAMETER  - Invalid variable name\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FindVariable (\r
-  IN EFI_PEI_SERVICES         **PeiServices,\r
+  IN        EFI_PEI_SERVICES   **PeiServices,\r
   IN CONST  CHAR16            *VariableName,\r
   IN CONST  EFI_GUID          *VendorGuid,\r
   OUT VARIABLE_POINTER_TRACK  *PtrTrack\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This code finds variable in storage blocks (Non-Volatile)\r
-\r
-Arguments:\r
-\r
-  PeiServices    - General purpose services available to every PEIM.\r
-  VariableName   - Name of the variable to be found\r
-  VendorGuid     - Vendor GUID to be found.\r
-  PtrTrack       - Variable Track Pointer structure that contains\r
-                   Variable Information.\r
 \r
-Returns:\r
-\r
-  EFI_SUCCESS      - Variable found successfully\r
-  EFI_NOT_FOUND    - Variable not found\r
-  EFI_INVALID_PARAMETER  - Invalid variable name\r
-\r
---*/\r
 {\r
   EFI_HOB_GUID_TYPE       *GuidHob;\r
   VARIABLE_STORE_HEADER   *VariableStoreHeader;\r
@@ -321,7 +383,7 @@ Returns:
   UINT32                  Count;\r
   UINT8                   *VariableBase;\r
 \r
-  if (VariableName != 0 && VendorGuid == NULL) {\r
+  if (VariableName[0] != 0 && VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
@@ -341,6 +403,7 @@ Returns:
     for (Count = 0; Count < IndexTable->Length; Count++)\r
     {\r
       MaxIndex = GetVariableByIndex (IndexTable, Count);\r
+\r
       if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
         PtrTrack->StartPtr  = IndexTable->StartPtr;\r
         PtrTrack->EndPtr    = IndexTable->EndPtr;\r
@@ -363,6 +426,14 @@ Returns:
       Variable = IndexTable->StartPtr;\r
     } else {\r
       VariableBase = (UINT8 *) (UINTN) PcdGet32 (PcdFlashNvStorageVariableBase);\r
+\r
+      //\r
+      // Check if FV header is valid.\r
+      //\r
+      if (((EFI_FIRMWARE_VOLUME_HEADER *) VariableBase)->Signature != EFI_FVH_SIGNATURE) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+\r
       VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r
                             ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r
 \r
@@ -376,8 +447,8 @@ Returns:
       //\r
       // Find the variable by walk through non-volatile variable store\r
       //\r
-      IndexTable->StartPtr  = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
-      IndexTable->EndPtr    = (VARIABLE_HEADER *) ((UINTN) VariableStoreHeader + VariableStoreHeader->Size);\r
+      IndexTable->StartPtr  = GetStartPointer (VariableStoreHeader);\r
+      IndexTable->EndPtr    = GetEndPointer (VariableStoreHeader);\r
 \r
       //\r
       // Start Pointers for the variable.\r
@@ -392,7 +463,7 @@ Returns:
   PtrTrack->StartPtr  = IndexTable->StartPtr;\r
   PtrTrack->EndPtr    = IndexTable->EndPtr;\r
 \r
-  while (IsValidVariableHeader (Variable) && (Variable <= IndexTable->EndPtr)) {\r
+  while ((Variable < IndexTable->EndPtr) && IsValidVariableHeader (Variable)) {\r
     if (Variable->State == VAR_ADDED) {\r
       //\r
       // Record Variable in VariableIndex HOB\r
@@ -421,51 +492,45 @@ Returns:
   return EFI_NOT_FOUND;\r
 }\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetVariable (\r
-  IN EFI_PEI_SERVICES             **PeiServices,\r
-  IN CHAR16                       *VariableName,\r
-  IN EFI_GUID                     * VendorGuid,\r
-  OUT UINT32                             *Attributes OPTIONAL,\r
-  IN OUT UINTN                           *DataSize,\r
-  OUT VOID                               *Data\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
+/**\r
   Provide the read variable functionality of the variable services.\r
 \r
-Arguments:\r
+  @param PeiServices - General purpose services available to every PEIM.\r
 \r
-  PeiServices - General purpose services available to every PEIM.\r
+  @param VariableName     - The variable name\r
 \r
-  VariableName     - The variable name\r
+  @param VendorGuid       - The vendor's GUID\r
 \r
-  VendorGuid       - The vendor's GUID\r
+  @param Attributes       - Pointer to the attribute\r
 \r
-  Attributes       - Pointer to the attribute\r
+  @param DataSize         - Size of data\r
 \r
-  DataSize         - Size of data\r
+  @param Data             - Pointer to data\r
 \r
-  Data             - Pointer to data\r
+  @retval EFI_SUCCESS           - The interface could be successfully installed\r
 \r
-Returns:\r
+  @retval EFI_NOT_FOUND         - The variable could not be discovered\r
 \r
-  EFI_SUCCESS           - The interface could be successfully installed\r
+  @retval EFI_BUFFER_TOO_SMALL  - The caller buffer is not large enough\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
+EFI_STATUS\r
+EFIAPI\r
+PeiGetVariable (\r
+  IN EFI_PEI_SERVICES             **PeiServices,\r
+  IN CHAR16                       *VariableName,\r
+  IN EFI_GUID                     * VendorGuid,\r
+  OUT UINT32                             *Attributes OPTIONAL,\r
+  IN OUT UINTN                           *DataSize,\r
+  OUT VOID                               *Data\r
+  )\r
 \r
---*/\r
 {\r
   VARIABLE_POINTER_TRACK  Variable;\r
   UINTN                   VarDataSize;\r
   EFI_STATUS              Status;\r
 \r
-  if (VariableName == NULL || VendorGuid == NULL) {\r
+  if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
@@ -481,7 +546,14 @@ Returns:
   //\r
   VarDataSize = DataSizeOfVariable (Variable.CurrPtr);\r
   if (*DataSize >= VarDataSize) {\r
-    (*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize);\r
+    //\r
+    // PO-TKW: Address one checking in this place\r
+    //\r
+    if (Data == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
 \r
     if (Attributes != NULL) {\r
       *Attributes = Variable.CurrPtr->Attributes;\r
@@ -495,49 +567,42 @@ Returns:
   }\r
 }\r
 \r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetVariable2 (\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
-\r
-Routine Description:\r
-\r
+/**\r
   Provide the read variable functionality of the variable services.\r
 \r
-Arguments:\r
+  @param PeiServices - General purpose services available to every PEIM.\r
 \r
-  PeiServices - General purpose services available to every PEIM.\r
+  @param VariableName     - The variable name\r
 \r
-  VariableName     - The variable name\r
+  @param VendorGuid       - The vendor's GUID\r
 \r
-  VendorGuid       - The vendor's GUID\r
+  @param Attributes       - Pointer to the attribute\r
 \r
-  Attributes       - Pointer to the attribute\r
+  @param DataSize         - Size of data\r
 \r
-  DataSize         - Size of data\r
+  @param Data             - Pointer to data\r
 \r
-  Data             - Pointer to data\r
+  @retval EFI_SUCCESS           - The interface could be successfully installed\r
 \r
-Returns:\r
+  @retval EFI_NOT_FOUND         - The variable could not be discovered\r
 \r
-  EFI_SUCCESS           - The interface could be successfully installed\r
+  @retval EFI_BUFFER_TOO_SMALL  - The caller buffer is not large enough\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
+EFI_STATUS\r
+EFIAPI\r
+PeiGetVariable2 (\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
---*/\r
 {\r
   return PeiGetVariable (\r
-           GetPeiServicesTablePointer (),\r
+           (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
            (CHAR16*)VariableName,\r
            (EFI_GUID*)VariableGuid,\r
            Attributes,\r
@@ -546,46 +611,40 @@ Returns:
            );\r
 }\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetNextVariableName (\r
-  IN EFI_PEI_SERVICES             **PeiServices,\r
-  IN OUT UINTN                    *VariableNameSize,\r
-  IN OUT CHAR16                   *VariableName,\r
-  IN OUT EFI_GUID                 *VendorGuid\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
+/**\r
   Provide the get next variable functionality of the variable services.\r
 \r
-Arguments:\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 VendorGuid         - A pointer to the EFI_GUID structure.\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
-  VendorGuid         - A pointer to the EFI_GUID structure.\r
+  @param VariableNameSize - Size of the variable name\r
 \r
-  VariableNameSize - Size of the variable name\r
+  @param VariableName     - The variable name\r
 \r
-  VariableName     - The variable name\r
+  @param VendorGuid       - The vendor's GUID\r
 \r
-  VendorGuid       - The vendor's GUID\r
+  @retval EFI_SUCCESS - The interface could be successfully installed\r
 \r
-Returns:\r
+  @retval EFI_NOT_FOUND - The variable could not be discovered\r
 \r
-  EFI_SUCCESS - The interface could be successfully installed\r
-\r
-  EFI_NOT_FOUND - The variable could not be discovered\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetNextVariableName (\r
+  IN EFI_PEI_SERVICES             **PeiServices,\r
+  IN OUT UINTN                    *VariableNameSize,\r
+  IN OUT CHAR16                   *VariableName,\r
+  IN OUT EFI_GUID                 *VendorGuid\r
+  )\r
 \r
---*/\r
 {\r
   VARIABLE_POINTER_TRACK  Variable;\r
   UINTN                   VarNameSize;\r
   EFI_STATUS              Status;\r
 \r
-  if (VariableName == NULL) {\r
+  if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -609,7 +668,7 @@ Returns:
 \r
         VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);\r
         if (VarNameSize <= *VariableNameSize) {\r
-          (*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize);\r
+          (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);\r
 \r
           (*PeiServices)->CopyMem (VendorGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));\r
 \r
@@ -634,45 +693,41 @@ Returns:
   return EFI_NOT_FOUND;\r
 }\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetNextVariableName2 (\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
-\r
-Routine Description:\r
-\r
+/**\r
   Provide the get next variable functionality of the variable services.\r
 \r
-Arguments:\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
 \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
+  @param VariableNameSize - Size of the variable name\r
 \r
-  VariableNameSize - Size of the variable name\r
+  @param VariableName     - The variable name\r
 \r
-  VariableName     - The variable name\r
+  @param VendorGuid       - The vendor's GUID\r
 \r
-  VendorGuid       - The vendor's GUID\r
 \r
-Returns:\r
+  @retval EFI_SUCCESS - The interface could be successfully installed\r
 \r
-  EFI_SUCCESS - The interface could be successfully installed\r
+  @retval EFI_NOT_FOUND - The variable could not be discovered\r
 \r
-  EFI_NOT_FOUND - The variable could not be discovered\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetNextVariableName2 (\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
---*/\r
 {\r
   return PeiGetNextVariableName (\r
-           GetPeiServicesTablePointer (),\r
+           (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
            VariableNameSize,\r
            VariableName,\r
            VariableGuid\r
            );\r
 }\r
+\r