lgao4 | 8069d49 | 2008-02-25 07:01:44 +0000 | [diff] [blame] | 1 | /** @file
|
lgao4 | eceb3a4 | 2008-07-15 11:12:43 +0000 | [diff] [blame] | 2 | Provide generic extract guided section functions for Dxe phase.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 3 |
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 4 | Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
hhtian | 19388d2 | 2010-04-23 16:37:43 +0000 | [diff] [blame] | 5 | This program and the accompanying materials
|
lgao4 | 8069d49 | 2008-02-25 07:01:44 +0000 | [diff] [blame] | 6 | are licensed and made available under the terms and conditions of the BSD License
|
| 7 | which accompanies this distribution. The full text of the license may be found at
|
myronporter | 2fc59a0 | 2010-06-25 21:56:02 +0000 | [diff] [blame] | 8 | http://opensource.org/licenses/bsd-license.php.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 9 |
|
lgao4 | 8069d49 | 2008-02-25 07:01:44 +0000 | [diff] [blame] | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 12 |
|
lgao4 | 8069d49 | 2008-02-25 07:01:44 +0000 | [diff] [blame] | 13 | **/
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 14 |
|
| 15 | #include <PiDxe.h>
|
| 16 |
|
| 17 | #include <Library/DebugLib.h>
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 18 | #include <Library/BaseMemoryLib.h>
|
| 19 | #include <Library/MemoryAllocationLib.h>
|
| 20 | #include <Library/ExtractGuidedSectionLib.h>
|
| 21 |
|
lgao4 | de2314f | 2008-12-11 07:36:58 +0000 | [diff] [blame] | 22 | #define EXTRACT_HANDLER_TABLE_SIZE 0x10
|
| 23 |
|
jji4 | fe46741 | 2008-10-30 05:58:52 +0000 | [diff] [blame] | 24 | UINT32 mNumberOfExtractHandler = 0;
|
lgao4 | de2314f | 2008-12-11 07:36:58 +0000 | [diff] [blame] | 25 | UINT32 mMaxNumberOfExtractHandler = 0;
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 26 |
|
lgao4 | de2314f | 2008-12-11 07:36:58 +0000 | [diff] [blame] | 27 | GUID *mExtractHandlerGuidTable = NULL;
|
| 28 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER *mExtractDecodeHandlerTable = NULL;
|
| 29 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable = NULL;
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 30 |
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 31 | /**
|
lgao4 | de2314f | 2008-12-11 07:36:58 +0000 | [diff] [blame] | 32 | Reallocates more global memory to store the registered guid and Handler list.
|
| 33 |
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 34 | @retval RETURN_SUCCESS Reallocated more global memory space to store guid and function tables.
|
| 35 | @retval RETURN_OUT_OF_RESOURCES Not enough memory to allocate.
|
lgao4 | de2314f | 2008-12-11 07:36:58 +0000 | [diff] [blame] | 36 | **/
|
| 37 | RETURN_STATUS
|
| 38 | EFIAPI
|
| 39 | ReallocateExtractHandlerTable (
|
| 40 | )
|
| 41 | {
|
| 42 | //
|
| 43 | // Reallocate memory for GuidTable
|
| 44 | //
|
| 45 | mExtractHandlerGuidTable = ReallocatePool (
|
| 46 | mMaxNumberOfExtractHandler * sizeof (GUID),
|
| 47 | (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (GUID),
|
| 48 | mExtractHandlerGuidTable
|
| 49 | );
|
| 50 |
|
| 51 | if (mExtractHandlerGuidTable == NULL) {
|
| 52 | goto Done;
|
| 53 | }
|
| 54 |
|
| 55 | //
|
| 56 | // Reallocate memory for Decode handler Table
|
| 57 | //
|
| 58 | mExtractDecodeHandlerTable = ReallocatePool (
|
| 59 | mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER),
|
| 60 | (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER),
|
| 61 | mExtractDecodeHandlerTable
|
| 62 | );
|
| 63 |
|
| 64 | if (mExtractDecodeHandlerTable == NULL) {
|
| 65 | goto Done;
|
| 66 | }
|
| 67 |
|
| 68 | //
|
| 69 | // Reallocate memory for GetInfo handler Table
|
| 70 | //
|
| 71 | mExtractGetInfoHandlerTable = ReallocatePool (
|
| 72 | mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER),
|
| 73 | (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER),
|
| 74 | mExtractGetInfoHandlerTable
|
| 75 | );
|
| 76 |
|
| 77 | if (mExtractGetInfoHandlerTable == NULL) {
|
| 78 | goto Done;
|
| 79 | }
|
| 80 |
|
| 81 | //
|
| 82 | // Increase max handler number
|
| 83 | //
|
| 84 | mMaxNumberOfExtractHandler = mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE;
|
| 85 | return RETURN_SUCCESS;
|
| 86 |
|
| 87 | Done:
|
| 88 | if (mExtractHandlerGuidTable != NULL) {
|
| 89 | FreePool (mExtractHandlerGuidTable);
|
| 90 | }
|
| 91 | if (mExtractDecodeHandlerTable != NULL) {
|
| 92 | FreePool (mExtractDecodeHandlerTable);
|
| 93 | }
|
| 94 | if (mExtractGetInfoHandlerTable != NULL) {
|
| 95 | FreePool (mExtractGetInfoHandlerTable);
|
| 96 | }
|
| 97 |
|
| 98 | return RETURN_OUT_OF_RESOURCES;
|
| 99 | }
|
| 100 | /**
|
qhuang8 | 0057fda | 2008-12-01 13:46:34 +0000 | [diff] [blame] | 101 | Constructor allocates the global memory to store the registered guid and Handler list.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 102 |
|
| 103 | @param ImageHandle The firmware allocated handle for the EFI image.
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 104 | @param SystemTable A pointer to the EFI System Table.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 105 |
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 106 | @retval RETURN_SUCCESS Allocated the global memory space to store guid and function tables.
|
| 107 | @retval RETURN_OUT_OF_RESOURCES Not enough memory to allocate.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 108 | **/
|
| 109 | RETURN_STATUS
|
| 110 | EFIAPI
|
| 111 | DxeExtractGuidedSectionLibConstructor (
|
| 112 | IN EFI_HANDLE ImageHandle,
|
| 113 | IN EFI_SYSTEM_TABLE *SystemTable
|
| 114 | )
|
| 115 | {
|
lgao4 | de2314f | 2008-12-11 07:36:58 +0000 | [diff] [blame] | 116 | return ReallocateExtractHandlerTable ();
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 117 | }
|
| 118 |
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 119 | /**
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 120 | Retrieve the list GUIDs that have been registered through ExtractGuidedSectionRegisterHandlers().
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 121 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 122 | Sets ExtractHandlerGuidTable so it points at a callee allocated array of registered GUIDs.
|
| 123 | The total number of GUIDs in the array are returned. Since the array of GUIDs is callee allocated
|
| 124 | and caller must treat this array of GUIDs as read-only data.
|
| 125 | If ExtractHandlerGuidTable is NULL, then ASSERT().
|
| 126 |
|
qhuang8 | 0057fda | 2008-12-01 13:46:34 +0000 | [diff] [blame] | 127 | @param[out] ExtractHandlerGuidTable A pointer to the array of GUIDs that have been registered through
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 128 | ExtractGuidedSectionRegisterHandlers().
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 129 |
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 130 | @return The number of the supported extract guided Handler.
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 131 |
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 132 | **/
|
| 133 | UINTN
|
| 134 | EFIAPI
|
| 135 | ExtractGuidedSectionGetGuidList (
|
lgao4 | eceb3a4 | 2008-07-15 11:12:43 +0000 | [diff] [blame] | 136 | OUT GUID **ExtractHandlerGuidTable
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 137 | )
|
| 138 | {
|
| 139 | ASSERT (ExtractHandlerGuidTable != NULL);
|
| 140 |
|
| 141 | *ExtractHandlerGuidTable = mExtractHandlerGuidTable;
|
| 142 | return mNumberOfExtractHandler;
|
| 143 | }
|
| 144 |
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 145 | /**
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 146 | Registers handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and EXTRACT_GUIDED_SECTION_DECODE_HANDLER
|
| 147 | for a specific GUID section type.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 148 |
|
qhuang8 | 0057fda | 2008-12-01 13:46:34 +0000 | [diff] [blame] | 149 | Registers the handlers specified by GetInfoHandler and DecodeHandler with the GUID specified by SectionGuid.
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 150 | If the GUID value specified by SectionGuid has already been registered, then return RETURN_ALREADY_STARTED.
|
| 151 | If there are not enough resources available to register the handlers then RETURN_OUT_OF_RESOURCES is returned.
|
jji4 | 5720947 | 2008-12-05 08:21:57 +0000 | [diff] [blame] | 152 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 153 | If SectionGuid is NULL, then ASSERT().
|
| 154 | If GetInfoHandler is NULL, then ASSERT().
|
| 155 | If DecodeHandler is NULL, then ASSERT().
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 156 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 157 | @param[in] SectionGuid A pointer to the GUID associated with the the handlers
|
| 158 | of the GUIDed section type being registered.
|
myronporter | 2fc59a0 | 2010-06-25 21:56:02 +0000 | [diff] [blame] | 159 | @param[in] GetInfoHandler The pointer to a function that examines a GUIDed section and returns the
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 160 | size of the decoded buffer and the size of an optional scratch buffer
|
| 161 | required to actually decode the data in a GUIDed section.
|
myronporter | 2fc59a0 | 2010-06-25 21:56:02 +0000 | [diff] [blame] | 162 | @param[in] DecodeHandler The pointer to a function that decodes a GUIDed section into a caller
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 163 | allocated output buffer.
|
| 164 |
|
| 165 | @retval RETURN_SUCCESS The handlers were registered.
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 166 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to register the handlers.
|
| 167 |
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 168 | **/
|
| 169 | RETURN_STATUS
|
| 170 | EFIAPI
|
| 171 | ExtractGuidedSectionRegisterHandlers (
|
| 172 | IN CONST GUID *SectionGuid,
|
| 173 | IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,
|
| 174 | IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler
|
| 175 | )
|
| 176 | {
|
lgao4 | e270121 | 2007-10-19 09:11:42 +0000 | [diff] [blame] | 177 | UINT32 Index;
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 178 | //
|
| 179 | // Check input paramter.
|
| 180 | //
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 181 | ASSERT (SectionGuid != NULL);
|
| 182 | ASSERT (GetInfoHandler != NULL);
|
| 183 | ASSERT (DecodeHandler != NULL);
|
lgao4 | e270121 | 2007-10-19 09:11:42 +0000 | [diff] [blame] | 184 |
|
| 185 | //
|
| 186 | // Search the match registered GetInfo handler for the input guided section.
|
| 187 | //
|
| 188 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {
|
| 189 | if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {
|
lgao4 | b911d09 | 2008-08-18 12:11:37 +0000 | [diff] [blame] | 190 | //
|
| 191 | // If the guided handler has been registered before, only update its handler.
|
| 192 | //
|
| 193 | mExtractDecodeHandlerTable [Index] = DecodeHandler;
|
| 194 | mExtractGetInfoHandlerTable [Index] = GetInfoHandler;
|
| 195 | return RETURN_SUCCESS;
|
lgao4 | e270121 | 2007-10-19 09:11:42 +0000 | [diff] [blame] | 196 | }
|
| 197 | }
|
lgao4 | e270121 | 2007-10-19 09:11:42 +0000 | [diff] [blame] | 198 |
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 199 | //
|
| 200 | // Check the global table is enough to contain new Handler.
|
| 201 | //
|
lgao4 | de2314f | 2008-12-11 07:36:58 +0000 | [diff] [blame] | 202 | if (mNumberOfExtractHandler >= mMaxNumberOfExtractHandler) {
|
| 203 | if (ReallocateExtractHandlerTable () != RETURN_SUCCESS) {
|
| 204 | return RETURN_OUT_OF_RESOURCES;
|
| 205 | }
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 206 | }
|
| 207 |
|
| 208 | //
|
| 209 | // Register new Handler and guid value.
|
| 210 | //
|
| 211 | CopyGuid (&mExtractHandlerGuidTable [mNumberOfExtractHandler], SectionGuid);
|
| 212 | mExtractDecodeHandlerTable [mNumberOfExtractHandler] = DecodeHandler;
|
| 213 | mExtractGetInfoHandlerTable [mNumberOfExtractHandler++] = GetInfoHandler;
|
| 214 |
|
| 215 | return RETURN_SUCCESS;
|
| 216 | }
|
| 217 |
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 218 | /**
|
qhuang8 | 0057fda | 2008-12-01 13:46:34 +0000 | [diff] [blame] | 219 | Retrieves a GUID from a GUIDed section and uses that GUID to select an associated handler of type
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 220 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().
|
| 221 | The selected handler is used to retrieve and return the size of the decoded buffer and the size of an
|
| 222 | optional scratch buffer required to actually decode the data in a GUIDed section.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 223 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 224 | Examines a GUIDed section specified by InputSection.
|
| 225 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),
|
| 226 | then RETURN_UNSUPPORTED is returned.
|
| 227 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler
|
| 228 | of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()
|
| 229 | is used to retrieve the OututBufferSize, ScratchSize, and Attributes values. The return status from the handler of
|
| 230 | type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER is returned.
|
klu2 | 518db1d | 2008-12-10 03:14:49 +0000 | [diff] [blame] | 231 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 232 | If InputSection is NULL, then ASSERT().
|
| 233 | If OutputBufferSize is NULL, then ASSERT().
|
| 234 | If ScratchBufferSize is NULL, then ASSERT().
|
| 235 | If SectionAttribute is NULL, then ASSERT().
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 236 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 237 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
|
| 238 | @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required if the buffer
|
| 239 | specified by InputSection were decoded.
|
| 240 | @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space if the buffer specified by
|
| 241 | InputSection were decoded.
|
| 242 | @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes field of
|
| 243 | EFI_GUID_DEFINED_SECTION in the PI Specification.
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 244 |
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 245 | @retval RETURN_SUCCESS Successfully obtained the required information.
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 246 | @retval RETURN_UNSUPPORTED The GUID from the section specified by InputSection does not match any of
|
| 247 | the GUIDs registered with ExtractGuidedSectionRegisterHandlers().
|
| 248 | @retval Others The return status from the handler associated with the GUID retrieved from
|
| 249 | the section specified by InputSection.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 250 |
|
| 251 | **/
|
| 252 | RETURN_STATUS
|
| 253 | EFIAPI
|
| 254 | ExtractGuidedSectionGetInfo (
|
| 255 | IN CONST VOID *InputSection,
|
| 256 | OUT UINT32 *OutputBufferSize,
|
| 257 | OUT UINT32 *ScratchBufferSize,
|
| 258 | OUT UINT16 *SectionAttribute
|
| 259 | )
|
| 260 | {
|
| 261 | UINT32 Index;
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 262 |
|
| 263 | ASSERT (InputSection != NULL);
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 264 | ASSERT (OutputBufferSize != NULL);
|
| 265 | ASSERT (ScratchBufferSize != NULL);
|
| 266 | ASSERT (SectionAttribute != NULL);
|
| 267 |
|
| 268 | //
|
| 269 | // Search the match registered GetInfo handler for the input guided section.
|
| 270 | //
|
| 271 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {
|
| 272 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
|
lgao4 | b911d09 | 2008-08-18 12:11:37 +0000 | [diff] [blame] | 273 | //
|
| 274 | // Call the match handler to getinfo for the input section data.
|
| 275 | //
|
| 276 | return mExtractGetInfoHandlerTable [Index] (
|
| 277 | InputSection,
|
| 278 | OutputBufferSize,
|
| 279 | ScratchBufferSize,
|
| 280 | SectionAttribute
|
| 281 | );
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 282 | }
|
| 283 | }
|
| 284 |
|
| 285 | //
|
| 286 | // Not found, the input guided section is not supported.
|
| 287 | //
|
lgao4 | b911d09 | 2008-08-18 12:11:37 +0000 | [diff] [blame] | 288 | return RETURN_UNSUPPORTED;
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 289 | }
|
| 290 |
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 291 | /**
|
qhuang8 | 0057fda | 2008-12-01 13:46:34 +0000 | [diff] [blame] | 292 | Retrieves the GUID from a GUIDed section and uses that GUID to select an associated handler of type
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 293 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().
|
| 294 | The selected handler is used to decode the data in a GUIDed section and return the result in a caller
|
| 295 | allocated output buffer.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 296 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 297 | Decodes the GUIDed section specified by InputSection.
|
| 298 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),
|
| 299 | then RETURN_UNSUPPORTED is returned.
|
| 300 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler
|
| 301 | of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()
|
| 302 | is used to decode InputSection into the buffer specified by OutputBuffer and the authentication status of this
|
| 303 | decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the data in InputSection,
|
| 304 | then OutputBuffer is set to point at the data in InputSection. Otherwise, the decoded data will be placed in caller
|
| 305 | allocated buffer specified by OutputBuffer. This function is responsible for computing the EFI_AUTH_STATUS_PLATFORM_OVERRIDE
|
klu2 | 518db1d | 2008-12-10 03:14:49 +0000 | [diff] [blame] | 306 | bit of in AuthenticationStatus. The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned.
|
| 307 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 308 | If InputSection is NULL, then ASSERT().
|
| 309 | If OutputBuffer is NULL, then ASSERT().
|
| 310 | If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
|
| 311 | If AuthenticationStatus is NULL, then ASSERT().
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 312 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 313 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
|
| 314 | @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
|
| 315 | @param[in] ScratchBuffer A caller allocated buffer that may be required by this function as a scratch buffer to perform the decode operation.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 316 | @param[out] AuthenticationStatus
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 317 | A pointer to the authentication status of the decoded output buffer. See the definition
|
| 318 | of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI section of the PI
|
| 319 | Specification.
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 320 |
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 321 | @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
|
| 322 | @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
|
| 323 | @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
|
qhuang8 | 4754c98 | 2008-10-31 03:39:53 +0000 | [diff] [blame] | 324 |
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 325 | **/
|
| 326 | RETURN_STATUS
|
| 327 | EFIAPI
|
| 328 | ExtractGuidedSectionDecode (
|
| 329 | IN CONST VOID *InputSection,
|
| 330 | OUT VOID **OutputBuffer,
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 331 | IN VOID *ScratchBuffer, OPTIONAL
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 332 | OUT UINT32 *AuthenticationStatus
|
| 333 | )
|
| 334 | {
|
| 335 | UINT32 Index;
|
| 336 |
|
lgao4 | eceb3a4 | 2008-07-15 11:12:43 +0000 | [diff] [blame] | 337 | //
|
| 338 | // Check the input parameters
|
| 339 | //
|
jji4 | f1db45f | 2008-11-18 11:33:48 +0000 | [diff] [blame] | 340 | ASSERT (InputSection != NULL);
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 341 | ASSERT (OutputBuffer != NULL);
|
| 342 | ASSERT (AuthenticationStatus != NULL);
|
| 343 |
|
| 344 | //
|
lgao4 | eceb3a4 | 2008-07-15 11:12:43 +0000 | [diff] [blame] | 345 | // Search the match registered extract handler for the input guided section.
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 346 | //
|
| 347 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {
|
| 348 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
|
lgao4 | b911d09 | 2008-08-18 12:11:37 +0000 | [diff] [blame] | 349 | //
|
| 350 | // Call the match handler to extract raw data for the input section data.
|
| 351 | //
|
| 352 | return mExtractDecodeHandlerTable [Index] (
|
| 353 | InputSection,
|
| 354 | OutputBuffer,
|
| 355 | ScratchBuffer,
|
| 356 | AuthenticationStatus
|
| 357 | );
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 358 | }
|
| 359 | }
|
| 360 |
|
| 361 | //
|
| 362 | // Not found, the input guided section is not supported.
|
| 363 | //
|
lgao4 | b911d09 | 2008-08-18 12:11:37 +0000 | [diff] [blame] | 364 | return RETURN_UNSUPPORTED;
|
lgao4 | 0fa0015 | 2007-09-30 09:01:06 +0000 | [diff] [blame] | 365 | }
|
ydong10 | 9be899c | 2010-11-04 05:51:32 +0000 | [diff] [blame^] | 366 |
|
| 367 | /**
|
| 368 | Retrieves handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and
|
| 369 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER for a specific GUID section type.
|
| 370 |
|
| 371 | Retrieves the handlers associated with SectionGuid and returns them in
|
| 372 | GetInfoHandler and DecodeHandler.
|
| 373 |
|
| 374 | If the GUID value specified by SectionGuid has not been registered, then
|
| 375 | return RETURN_NOT_FOUND.
|
| 376 |
|
| 377 | If SectionGuid is NULL, then ASSERT().
|
| 378 |
|
| 379 | @param[in] SectionGuid A pointer to the GUID associated with the handlersof the GUIDed
|
| 380 | section type being retrieved.
|
| 381 | @param[out] GetInfoHandler Pointer to a function that examines a GUIDed section and returns
|
| 382 | the size of the decoded buffer and the size of an optional scratch
|
| 383 | buffer required to actually decode the data in a GUIDed section.
|
| 384 | This is an optional parameter that may be NULL. If it is NULL, then
|
| 385 | the previously registered handler is not returned.
|
| 386 | @param[out] DecodeHandler Pointer to a function that decodes a GUIDed section into a caller
|
| 387 | allocated output buffer. This is an optional parameter that may be NULL.
|
| 388 | If it is NULL, then the previously registered handler is not returned.
|
| 389 |
|
| 390 | @retval RETURN_SUCCESS The handlers were retrieved.
|
| 391 | @retval RETURN_NOT_FOUND No handlers have been registered with the specified GUID.
|
| 392 |
|
| 393 | **/
|
| 394 | RETURN_STATUS
|
| 395 | EFIAPI
|
| 396 | ExtractGuidedSectionGetHandlers (
|
| 397 | IN CONST GUID *SectionGuid,
|
| 398 | OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler, OPTIONAL
|
| 399 | OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL
|
| 400 | )
|
| 401 | {
|
| 402 | UINT32 Index;
|
| 403 |
|
| 404 | //
|
| 405 | // Check input parameter.
|
| 406 | //
|
| 407 | ASSERT (SectionGuid != NULL);
|
| 408 |
|
| 409 | //
|
| 410 | // Search the match registered GetInfo handler for the input guided section.
|
| 411 | //
|
| 412 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {
|
| 413 | if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {
|
| 414 |
|
| 415 | //
|
| 416 | // If the guided handler has been registered before, then return the registered handlers.
|
| 417 | //
|
| 418 | if (GetInfoHandler != NULL) {
|
| 419 | *GetInfoHandler = mExtractGetInfoHandlerTable[Index];
|
| 420 | }
|
| 421 | if (DecodeHandler != NULL) {
|
| 422 | *DecodeHandler = mExtractDecodeHandlerTable[Index];
|
| 423 | }
|
| 424 | return RETURN_SUCCESS;
|
| 425 | }
|
| 426 | }
|
| 427 | return RETURN_NOT_FOUND;
|
| 428 | }
|