]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.c
Code Clean up for IfrSupportLib, HiiLib, PeiExtractGuidedSectionLib and DxeExtractGui...
[mirror_edk2.git] / MdePkg / Library / PeiExtractGuidedSectionLib / PeiExtractGuidedSectionLib.c
index a360d59d852f7d39d2c7c2e4b73b9776a5ecee51..72add417b66ba4cc086ffaf60281640512e99fe9 100644 (file)
@@ -1,23 +1,16 @@
-/*++\r
+/** @file\r
+  Provide generic extract guided section functions for PEI phase.\r
 \r
-Copyright (c) 2007, Intel Corporation\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
-http://opensource.org/licenses/bsd-license.php\r
+  Copyright (c) 2007 - 2008, 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
+  http://opensource.org/licenses/bsd-license.php\r
 \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-  PeiExtractGuidedSectionLib.c\r
-\r
-Abstract:\r
-\r
-  Provide generic extract guided section functions. \r
-\r
---*/\r
+**/\r
 \r
 #include <PiPei.h>\r
 \r
@@ -104,6 +97,9 @@ PeiGetExtractGuidedSectionHandlerInfo (
     //\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  //\r
+  // Init HandlerInfo structure\r
+  //\r
   HandlerInfo->Signature = PEI_EXTRACT_HANDLER_INFO_SIGNATURE;\r
   HandlerInfo->NumberOfExtractHandler     = 0;\r
   HandlerInfo->ExtractHandlerGuidTable    = (GUID *) (HandlerInfo + 1);\r
@@ -116,7 +112,9 @@ PeiGetExtractGuidedSectionHandlerInfo (
                                               PcdGet32 (PcdMaximumGuidedExtractHandler) * \r
                                               sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)\r
                                              );\r
-  \r
+  //\r
+  // return the created HandlerInfo.\r
+  //\r
   *InfoPointer = HandlerInfo;\r
   return EFI_SUCCESS;\r
 }\r
@@ -125,14 +123,14 @@ PeiGetExtractGuidedSectionHandlerInfo (
   Get the supported exract guided section Handler guid list.\r
   If ExtractHandlerGuidTable = NULL, then ASSERT.\r
 \r
-  @param[in, out]  ExtractHandlerGuidTable   The extract Handler guid pointer list.
+  @param[out]  ExtractHandlerGuidTable   The extract Handler guid pointer list.
 \r
-  @retval  return the number of the supported extract guided Handler.
+  @return the number of the supported extract guided Handler.
 **/\r
 UINTN\r
 EFIAPI\r
 ExtractGuidedSectionGetGuidList (\r
-  IN OUT  GUID  **ExtractHandlerGuidTable\r
+  OUT  GUID  **ExtractHandlerGuidTable\r
   )\r
 {\r
   EFI_STATUS Status;\r
@@ -140,11 +138,17 @@ ExtractGuidedSectionGetGuidList (
 \r
   ASSERT (ExtractHandlerGuidTable != NULL);\r
 \r
+  //\r
+  // Get all registered handler information\r
+  //\r
   Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
+  //\r
+  // Get GuidTable and Table Number\r
+  //\r
   *ExtractHandlerGuidTable = HandlerInfo->ExtractHandlerGuidTable;\r
   return HandlerInfo->NumberOfExtractHandler;\r
 }\r
@@ -192,19 +196,15 @@ ExtractGuidedSectionRegisterHandlers (
   //\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r
-      break;\r
+      //\r
+      // If the guided handler has been registered before, only update its handler.\r
+      //\r
+      HandlerInfo->ExtractDecodeHandlerTable [Index] = DecodeHandler;\r
+      HandlerInfo->ExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
+      return RETURN_SUCCESS;\r
     }\r
   }\r
 \r
-  //\r
-  // If the guided handler has been registered before, only update its handler.\r
-  //\r
-  if (Index < HandlerInfo->NumberOfExtractHandler) {\r
-    HandlerInfo->ExtractDecodeHandlerTable [Index] = DecodeHandler;\r
-    HandlerInfo->ExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
-    return RETURN_SUCCESS;\r
-  }\r
-\r
   //\r
   // Check the global table is enough to contain new Handler.\r
   //\r
@@ -239,8 +239,8 @@ ExtractGuidedSectionRegisterHandlers (
   @param[out] SectionAttribute      The attribute of the input guided section.\r
 
   @retval  RETURN_SUCCESS           Get the required information successfully.\r
-  @retval  RETURN_INVALID_PARAMETER The input data can't be parsed correctly. \r
-                                    The GUID in InputSection does not match any registered guid list.\r
+  @retval  RETURN_UNSUPPORTED       Guided section data is not supported.\r
+  @retval  RETURN_INVALID_PARAMETER The input data is not the valid guided section.\r
 \r
 **/\r
 RETURN_STATUS\r
@@ -268,7 +268,7 @@ ExtractGuidedSectionGetInfo (
   ASSERT (SectionAttribute != NULL);\r
 \r
   //\r
-  // Get the registered handler information.\r
+  // Get all registered handler information.\r
   //\r
   Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
   if (EFI_ERROR (Status)) {\r
@@ -280,26 +280,22 @@ ExtractGuidedSectionGetInfo (
   //\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-      break;\r
+      //\r
+      // Call the match handler to getinfo for the input section data.\r
+      //\r
+      return HandlerInfo->ExtractGetInfoHandlerTable [Index] (\r
+                InputSection,\r
+                OutputBufferSize,\r
+                ScratchBufferSize,\r
+                SectionAttribute\r
+              );\r
     }\r
   }\r
 \r
   //\r
   // Not found, the input guided section is not supported. \r
   //\r
-  if (Index == HandlerInfo->NumberOfExtractHandler) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Call the match handler to getinfo for the input section data.\r
-  //\r
-  return HandlerInfo->ExtractGetInfoHandlerTable [Index] (\r
-            InputSection,\r
-            OutputBufferSize,\r
-            ScratchBufferSize,\r
-            SectionAttribute\r
-          );\r
+  return RETURN_UNSUPPORTED;\r
 }\r
 \r
 /**
@@ -323,8 +319,8 @@ ExtractGuidedSectionGetInfo (
                             authentication status of the output buffer. 
 
   @retval  RETURN_SUCCESS           Get the output data, size and AuthenticationStatus successfully.\r
-  @retval  RETURN_INVALID_PARAMETER The input data can't be parsed correctly. \r
-                                    The GUID in InputSection does not match any registered guid list.\r
+  @retval  RETURN_UNSUPPORTED       Guided section data is not supported to be decoded.\r
+  @retval  RETURN_INVALID_PARAMETER The input data is not the valid guided section.
 
 **/\r
 RETURN_STATUS\r
@@ -340,41 +336,42 @@ ExtractGuidedSectionDecode (
   EFI_STATUS Status;\r
   PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
   \r
+  //\r
+  // Check input parameter\r
+  //\r
   if (InputSection == NULL) {\r
     return RETURN_INVALID_PARAMETER;\r
-  }\r
-  \r
+  }  \r
   ASSERT (OutputBuffer != NULL);\r
   ASSERT (AuthenticationStatus != NULL);\r
-  \r
+\r
+  //\r
+  // Get all registered handler information.\r
+  //  \r
   Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
   //\r
-  // Search the match registered GetInfo handler for the input guided section.\r
+  // Search the match registered Extract handler for the input guided section.\r
   //\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-      break;\r
+      //\r
+      // Call the match handler to extract raw data for the input guided section.\r
+      //\r
+      return HandlerInfo->ExtractDecodeHandlerTable [Index] (\r
+                InputSection,\r
+                OutputBuffer,\r
+                ScratchBuffer,\r
+                AuthenticationStatus\r
+              );\r
     }\r
   }\r
 \r
   //\r
   // Not found, the input guided section is not supported. \r
   //\r
-  if (Index == HandlerInfo->NumberOfExtractHandler) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Call the match handler to getinfo for the input section data.\r
-  //\r
-  return HandlerInfo->ExtractDecodeHandlerTable [Index] (\r
-            InputSection,\r
-            OutputBuffer,\r
-            ScratchBuffer,\r
-            AuthenticationStatus\r
-          );\r
+  return RETURN_UNSUPPORTED;\r
 }\r