]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.c
MdePkg BaseMemoryLibSse2: Convert Ia32/ZeroMem.asm to NASM
[mirror_edk2.git] / MdePkg / Library / PeiExtractGuidedSectionLib / PeiExtractGuidedSectionLib.c
index 4da3d8afa187f01f4abb446717e3f148585ba5e7..c471ae9ab3c0fe1b2bccc85b5c4dab69b3cd8eae 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
   Provide generic extract guided section functions for PEI 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
@@ -20,7 +20,7 @@
 #include <Library/HobLib.h>\r
 #include <Library/ExtractGuidedSectionLib.h>\r
 \r
-#define PEI_EXTRACT_HANDLER_INFO_SIGNATURE EFI_SIGNATURE_32 ('P', 'E', 'H', 'I')\r
+#define PEI_EXTRACT_HANDLER_INFO_SIGNATURE SIGNATURE_32 ('P', 'E', 'H', 'I')\r
 \r
 typedef struct {\r
   UINT32                                  Signature;\r
@@ -34,7 +34,7 @@ typedef struct {
   Build guid hob for the global memory to store the registered guid and Handler list.\r
   If GuidHob exists, HandlerInfo will be directly got from Guid hob data.\r
 \r
-  @param[in, out]  InfoPointer   Pointer to pei handler info structure.\r
+  @param[in, out]  InfoPointer   The pointer to pei handler information structure.\r
 \r
   @retval  RETURN_SUCCESS            Build Guid hob for the global memory space to store guid and function tables.\r
   @retval  RETURN_OUT_OF_RESOURCES   No enough memory to allocated.\r
@@ -48,7 +48,7 @@ PeiGetExtractGuidedSectionHandlerInfo (
   EFI_PEI_HOB_POINTERS                    Hob;\r
   \r
   //\r
-  // First try to get handler info from guid hob specified by CallerId.\r
+  // First try to get handler information from guid hob specified by CallerId.\r
   //\r
   Hob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GetHobList ());\r
   while (Hob.Raw != NULL) {\r
@@ -67,7 +67,7 @@ PeiGetExtractGuidedSectionHandlerInfo (
           HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) (\r
                                                       (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable + \r
                                                       PcdGet32 (PcdMaximumGuidedExtractHandler) * \r
-                                                      sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)\r
+                                                      sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER)\r
                                                      );\r
         }\r
         //\r
@@ -94,6 +94,7 @@ PeiGetExtractGuidedSectionHandlerInfo (
     //\r
     // No enough resource to build guid hob.\r
     //\r
+    *InfoPointer = NULL;\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   //\r
@@ -109,7 +110,7 @@ PeiGetExtractGuidedSectionHandlerInfo (
   HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) (\r
                                               (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable + \r
                                               PcdGet32 (PcdMaximumGuidedExtractHandler) * \r
-                                              sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)\r
+                                              sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER)\r
                                              );\r
   //\r
   // return the created HandlerInfo.\r
@@ -124,7 +125,6 @@ PeiGetExtractGuidedSectionHandlerInfo (
   Sets ExtractHandlerGuidTable so it points at a callee allocated array of registered GUIDs.\r
   The total number of GUIDs in the array are returned. Since the array of GUIDs is callee allocated\r
   and caller must treat this array of GUIDs as read-only data. \r
-  \r
   If ExtractHandlerGuidTable is NULL, then ASSERT().\r
 \r
   @param[out]  ExtractHandlerGuidTable  A pointer to the array of GUIDs that have been registered through\r
@@ -149,12 +149,14 @@ ExtractGuidedSectionGetGuidList (
   //\r
   Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    *ExtractHandlerGuidTable = NULL;\r
+    return 0;\r
   }\r
 \r
   //\r
   // Get GuidTable and Table Number\r
   //\r
+  ASSERT (HandlerInfo != NULL);\r
   *ExtractHandlerGuidTable = HandlerInfo->ExtractHandlerGuidTable;\r
   return HandlerInfo->NumberOfExtractHandler;\r
 }\r
@@ -173,10 +175,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
@@ -215,6 +217,7 @@ ExtractGuidedSectionRegisterHandlers (
   //\r
   // Search the match registered GetInfo handler for the input guided section.\r
   //\r
+  ASSERT (HandlerInfo != NULL);\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r
       //\r
@@ -239,7 +242,17 @@ ExtractGuidedSectionRegisterHandlers (
   CopyGuid (HandlerInfo->ExtractHandlerGuidTable + HandlerInfo->NumberOfExtractHandler, SectionGuid);\r
   HandlerInfo->ExtractDecodeHandlerTable [HandlerInfo->NumberOfExtractHandler] = DecodeHandler;\r
   HandlerInfo->ExtractGetInfoHandlerTable [HandlerInfo->NumberOfExtractHandler++] = GetInfoHandler;\r
-  \r
+\r
+  //\r
+  // Build the Guided Section GUID HOB to record the GUID itself.\r
+  // Then the content of the GUIDed HOB will be the same as the GUID value itself.\r
+  //\r
+  BuildGuidDataHob (\r
+    (EFI_GUID *) SectionGuid,\r
+    (VOID *) SectionGuid,\r
+    sizeof (GUID)\r
+    );\r
+\r
   return RETURN_SUCCESS;\r
 }\r
 \r
@@ -289,6 +302,7 @@ ExtractGuidedSectionGetInfo (
   UINT32 Index;\r
   EFI_STATUS Status;\r
   PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
+  EFI_GUID *SectionDefinitionGuid;\r
   \r
   //\r
   // Check input paramter\r
@@ -305,14 +319,21 @@ ExtractGuidedSectionGetInfo (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  \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
+  ASSERT (HandlerInfo != NULL);\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
-    if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {\r
       //\r
-      // Call the match handler to get info for the input section data.\r
+      // Call the match handler to get information for the input section data.\r
       //\r
       return HandlerInfo->ExtractGetInfoHandlerTable [Index] (\r
                 InputSection,\r
@@ -376,6 +397,7 @@ ExtractGuidedSectionDecode (
   UINT32     Index;\r
   EFI_STATUS Status;\r
   PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
+  EFI_GUID *SectionDefinitionGuid;\r
   \r
   //\r
   // Check input parameter\r
@@ -392,11 +414,18 @@ ExtractGuidedSectionDecode (
     return Status;\r
   }\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
+  ASSERT (HandlerInfo != NULL);\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
-    if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {\r
       //\r
       // Call the match handler to extract raw data for the input guided section.\r
       //\r
@@ -414,3 +443,77 @@ 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
+  EFI_STATUS                               Status;\r
+  UINT32                                   Index;\r
+  PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO  *HandlerInfo;\r
+\r
+  //\r
+  // Check input parameter\r
+  //\r
+  ASSERT (SectionGuid != NULL);\r
+\r
+  //\r
+  // Get the 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
+  //\r
+  ASSERT (HandlerInfo != NULL);\r
+  for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
+    if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + 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 = HandlerInfo->ExtractGetInfoHandlerTable[Index];\r
+      }\r
+      if (DecodeHandler != NULL) {\r
+        *DecodeHandler = HandlerInfo->ExtractDecodeHandlerTable[Index];\r
+      }\r
+      return RETURN_SUCCESS;\r
+    }\r
+  }\r
+  return RETURN_NOT_FOUND;\r
+}\r