]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.c
MdePkg: Fix typos in comments
[mirror_edk2.git] / MdePkg / Library / DxeExtractGuidedSectionLib / DxeExtractGuidedSectionLib.c
index 5f03a982cf77945fce60830059d6a9864578db15..8b8e52829b2f5e09014a7dbaf4ae33aa43281ec2 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
   Provide generic extract guided section functions for Dxe phase.\r
 \r
-  Copyright (c) 2007 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2007 - 2012, 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
+  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
 #include <PiDxe.h>\r
 \r
 #include <Library/DebugLib.h>\r
-#include <Library/PcdLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/ExtractGuidedSectionLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#define EXTRACT_HANDLER_TABLE_SIZE   0x10\r
 \r
-GUID                 *mExtractHandlerGuidTable;\r
 UINT32               mNumberOfExtractHandler = 0;\r
+UINT32               mMaxNumberOfExtractHandler = 0;\r
 \r
-EXTRACT_GUIDED_SECTION_DECODE_HANDLER   *mExtractDecodeHandlerTable;\r
-EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable;\r
+GUID                 *mExtractHandlerGuidTable = NULL;\r
+EXTRACT_GUIDED_SECTION_DECODE_HANDLER   *mExtractDecodeHandlerTable = NULL;\r
+EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable = NULL;\r
 \r
 /**\r
-  Constructor allocates the global memory to store the registered guid and Handler list.\r
-\r
-  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
-  @param  SystemTable   A pointer to the EFI System Table.\r
+  Reallocates more global memory to store the registered guid and Handler list.\r
 \r
-  @retval  RETURN_SUCCESS            Allocate the global memory space to store guid and function tables.\r
-  @retval  RETURN_OUT_OF_RESOURCES   No enough memory to allocated.\r
+  @retval  RETURN_SUCCESS            Reallocated more global memory space to store guid and function tables.\r
+  @retval  RETURN_OUT_OF_RESOURCES   Not enough memory to allocate.\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-DxeExtractGuidedSectionLibConstructor (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
+ReallocateExtractHandlerTable (\r
   )\r
-{\r
+{ \r
   //\r
-  // Allocate global pool space to store the registered handler and its guid value.\r
+  // Reallocate memory for GuidTable\r
   //\r
-  mExtractHandlerGuidTable    = (GUID *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID));\r
+  mExtractHandlerGuidTable = ReallocatePool (\r
+                               mMaxNumberOfExtractHandler * sizeof (GUID), \r
+                               (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (GUID), \r
+                               mExtractHandlerGuidTable\r
+                             );\r
+\r
   if (mExtractHandlerGuidTable == NULL) {\r
-    return RETURN_OUT_OF_RESOURCES;\r
+    goto Done;\r
   }\r
-  \r
-  mExtractDecodeHandlerTable  = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));\r
+\r
+  //\r
+  // Reallocate memory for Decode handler Table\r
+  //\r
+  mExtractDecodeHandlerTable = ReallocatePool (\r
+                               mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER), \r
+                               (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER), \r
+                               mExtractDecodeHandlerTable\r
+                             );\r
+\r
   if (mExtractDecodeHandlerTable == NULL) {\r
-    FreePool (mExtractHandlerGuidTable);\r
-    return RETURN_OUT_OF_RESOURCES;\r
+    goto Done;\r
   }\r
 \r
-  mExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));\r
+  //\r
+  // Reallocate memory for GetInfo handler Table\r
+  //\r
+  mExtractGetInfoHandlerTable = ReallocatePool (\r
+                               mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER), \r
+                               (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER), \r
+                               mExtractGetInfoHandlerTable\r
+                             );\r
+\r
   if (mExtractGetInfoHandlerTable == NULL) {\r
+    goto Done;\r
+  }\r
+  \r
+  //\r
+  // Increase max handler number\r
+  //\r
+  mMaxNumberOfExtractHandler = mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE;\r
+  return RETURN_SUCCESS;\r
+\r
+Done:\r
+  if (mExtractHandlerGuidTable != NULL) {\r
     FreePool (mExtractHandlerGuidTable);\r
+  }\r
+  if (mExtractDecodeHandlerTable != NULL) {\r
     FreePool (mExtractDecodeHandlerTable);\r
-    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
+  if (mExtractGetInfoHandlerTable != NULL) {\r
+    FreePool (mExtractGetInfoHandlerTable);\r
   }\r
   \r
-  return RETURN_SUCCESS;\r
+  return RETURN_OUT_OF_RESOURCES;\r
+}\r
+/**\r
+  Constructor allocates the global memory to store the registered guid and Handler list.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval  RETURN_SUCCESS            Allocated the global memory space to store guid and function tables.\r
+  @retval  RETURN_OUT_OF_RESOURCES   Not enough memory to allocate.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+DxeExtractGuidedSectionLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return ReallocateExtractHandlerTable ();\r
 }\r
 \r
 /**\r
@@ -77,7 +128,7 @@ DxeExtractGuidedSectionLibConstructor (
   @param[out]  ExtractHandlerGuidTable  A pointer to the array of GUIDs that have been registered through\r
                                         ExtractGuidedSectionRegisterHandlers().\r
 \r
-  @return the number of the supported extract guided Handler.\r
+  @return The number of the supported extract guided Handler.\r
 \r
 **/\r
 UINTN\r
@@ -106,10 +157,10 @@ ExtractGuidedSectionGetGuidList (
 \r
   @param[in]  SectionGuid    A pointer to the GUID associated with the the handlers\r
                              of the GUIDed section type being registered.\r
-  @param[in]  GetInfoHandler Pointer to a function that examines a GUIDed section and returns the\r
+  @param[in]  GetInfoHandler The pointer to a function that examines a GUIDed section and returns the\r
                              size of the decoded buffer and the size of an optional scratch buffer\r
                              required to actually decode the data in a GUIDed section.\r
-  @param[in]  DecodeHandler  Pointer to a function that decodes a GUIDed section into a caller\r
+  @param[in]  DecodeHandler  The pointer to a function that decodes a GUIDed section into a caller\r
                              allocated output buffer. \r
 \r
   @retval  RETURN_SUCCESS           The handlers were registered.\r
@@ -125,8 +176,10 @@ ExtractGuidedSectionRegisterHandlers (
   )\r
 {\r
   UINT32 Index;\r
+  VOID   *GuidData;\r
+\r
   //\r
-  // Check input paramter.\r
+  // Check input parameter.\r
   //\r
   ASSERT (SectionGuid != NULL);\r
   ASSERT (GetInfoHandler != NULL);\r
@@ -149,8 +202,10 @@ ExtractGuidedSectionRegisterHandlers (
   //\r
   // Check the global table is enough to contain new Handler.\r
   //\r
-  if (mNumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r
-    return RETURN_OUT_OF_RESOURCES;\r
+  if (mNumberOfExtractHandler >= mMaxNumberOfExtractHandler) {\r
+    if (ReallocateExtractHandlerTable () != RETURN_SUCCESS) {\r
+      return RETURN_OUT_OF_RESOURCES;\r
+    }\r
   }\r
   \r
   //\r
@@ -159,7 +214,16 @@ ExtractGuidedSectionRegisterHandlers (
   CopyGuid (&mExtractHandlerGuidTable [mNumberOfExtractHandler], SectionGuid);\r
   mExtractDecodeHandlerTable [mNumberOfExtractHandler] = DecodeHandler;\r
   mExtractGetInfoHandlerTable [mNumberOfExtractHandler++] = GetInfoHandler;\r
-  \r
+\r
+  //\r
+  // Install the Guided Section GUID configuration table to record the GUID itself.\r
+  // Then the content of the configuration table buffer will be the same as the GUID value itself.\r
+  //\r
+  GuidData = AllocateCopyPool (sizeof (GUID), (VOID *) SectionGuid);\r
+  if (GuidData != NULL) {\r
+    gBS->InstallConfigurationTable ((EFI_GUID *) SectionGuid, GuidData);\r
+  }\r
+\r
   return RETURN_SUCCESS;\r
 }\r
 \r
@@ -190,7 +254,7 @@ ExtractGuidedSectionRegisterHandlers (
   @param[out] SectionAttribute   A pointer to the attributes of the GUIDed section.  See the Attributes field of\r
                                  EFI_GUID_DEFINED_SECTION in the PI Specification.\r
 \r
-  @retval  RETURN_SUCCESS      Get the required information successfully.\r
+  @retval  RETURN_SUCCESS      Successfully obtained the required information.\r
   @retval  RETURN_UNSUPPORTED  The GUID from the section specified by InputSection does not match any of\r
                                the GUIDs registered with ExtractGuidedSectionRegisterHandlers().\r
   @retval  Others              The return status from the handler associated with the GUID retrieved from\r
@@ -207,17 +271,24 @@ ExtractGuidedSectionGetInfo (
   )\r
 {\r
   UINT32 Index;\r
+  EFI_GUID *SectionDefinitionGuid;\r
 \r
   ASSERT (InputSection != NULL);  \r
   ASSERT (OutputBufferSize != NULL);\r
   ASSERT (ScratchBufferSize != NULL);\r
   ASSERT (SectionAttribute != NULL);\r
+\r
+  if (IS_SECTION2 (InputSection)) {\r
+    SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid);\r
+  } else {\r
+    SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid);\r
+  }\r
  \r
   //\r
   // Search the match registered GetInfo handler for the input guided section.\r
   //\r
   for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
-    if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionDefinitionGuid)) {\r
       //\r
       // Call the match handler to getinfo for the input section data.\r
       //\r
@@ -281,6 +352,7 @@ ExtractGuidedSectionDecode (
   )\r
 {\r
   UINT32 Index;\r
+  EFI_GUID *SectionDefinitionGuid;\r
   \r
   //\r
   // Check the input parameters\r
@@ -289,11 +361,17 @@ ExtractGuidedSectionDecode (
   ASSERT (OutputBuffer != NULL);\r
   ASSERT (AuthenticationStatus != NULL);\r
 \r
+  if (IS_SECTION2 (InputSection)) {\r
+    SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid);\r
+  } else {\r
+    SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid);\r
+  }\r
+\r
   //\r
   // Search the match registered extract handler for the input guided section.\r
   //\r
   for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
-    if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionDefinitionGuid)) {\r
       //\r
       // Call the match handler to extract raw data for the input section data.\r
       //\r
@@ -311,3 +389,66 @@ ExtractGuidedSectionDecode (
   //\r
   return RETURN_UNSUPPORTED;\r
 }\r
+\r
+/**\r
+  Retrieves handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and \r
+  EXTRACT_GUIDED_SECTION_DECODE_HANDLER for a specific GUID section type.\r
+  \r
+  Retrieves the handlers associated with SectionGuid and returns them in \r
+  GetInfoHandler and DecodeHandler.\r
+\r
+  If the GUID value specified by SectionGuid has not been registered, then \r
+  return RETURN_NOT_FOUND.\r
+  \r
+  If SectionGuid is NULL, then ASSERT().\r
+\r
+  @param[in]  SectionGuid    A pointer to the GUID associated with the handlersof the GUIDed \r
+                             section type being retrieved.\r
+  @param[out] GetInfoHandler Pointer to a function that examines a GUIDed section and returns \r
+                             the size of the decoded buffer and the size of an optional scratch \r
+                             buffer required to actually decode the data in a GUIDed section.  \r
+                             This is an optional parameter that may be NULL. If it is NULL, then \r
+                             the previously registered handler is not returned.\r
+  @param[out] DecodeHandler  Pointer to a function that decodes a GUIDed section into a caller\r
+                             allocated output buffer. This is an optional parameter that may be NULL.\r
+                             If it is NULL, then the previously registered handler is not returned.\r
+\r
+  @retval  RETURN_SUCCESS     The handlers were retrieved.\r
+  @retval  RETURN_NOT_FOUND   No handlers have been registered with the specified GUID.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+ExtractGuidedSectionGetHandlers (\r
+  IN CONST   GUID                                     *SectionGuid,\r
+  OUT        EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER  *GetInfoHandler,  OPTIONAL\r
+  OUT        EXTRACT_GUIDED_SECTION_DECODE_HANDLER    *DecodeHandler    OPTIONAL\r
+  )\r
+{\r
+  UINT32 Index; \r
+\r
+  //\r
+  // Check input parameter.\r
+  //\r
+  ASSERT (SectionGuid != NULL);\r
+\r
+  //\r
+  // Search the match registered GetInfo handler for the input guided section.\r
+  //\r
+  for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
+    if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {\r
+      \r
+      //\r
+      // If the guided handler has been registered before, then return the registered handlers.\r
+      //\r
+      if (GetInfoHandler != NULL) {\r
+        *GetInfoHandler = mExtractGetInfoHandlerTable[Index];\r
+      }\r
+      if (DecodeHandler != NULL) {\r
+        *DecodeHandler = mExtractDecodeHandlerTable[Index];\r
+      }\r
+      return RETURN_SUCCESS;\r
+    }\r
+  }\r
+  return RETURN_NOT_FOUND;\r
+}\r