3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 This program and the accompanying materials
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
8 http://opensource.org/licenses/bsd-license.php
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.
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/ExtractGuidedSectionLib.h>
19 #include <Library/PcdLib.h>
20 #include <Library/PrePiLib.h>
22 #define PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID { 0x385A982C, 0x2F49, 0x4043, { 0xA5, 0x1E, 0x49, 0x01, 0x02, 0x5C, 0x8B, 0x6B }}
25 UINT32 NumberOfExtractHandler
;
26 GUID
*ExtractHandlerGuidTable
;
27 EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*ExtractDecodeHandlerTable
;
28 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*ExtractGetInfoHandlerTable
;
29 } PRE_PI_EXTRACT_GUIDED_SECTION_DATA
;
31 PRE_PI_EXTRACT_GUIDED_SECTION_DATA
*
36 EFI_HOB_GUID_TYPE
*GuidHob
;
37 GUID SavedDataGuid
= PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID
;
39 GuidHob
= GetFirstGuidHob(&SavedDataGuid
);
42 return (PRE_PI_EXTRACT_GUIDED_SECTION_DATA
*)GuidHob
;
47 ExtractGuidedSectionRegisterHandlers (
48 IN CONST GUID
*SectionGuid
,
49 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler
,
50 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler
53 PRE_PI_EXTRACT_GUIDED_SECTION_DATA
*SavedData
;
56 // Check input paramter.
58 if (SectionGuid
== NULL
) {
59 return RETURN_INVALID_PARAMETER
;
62 SavedData
= GetSavedData();
65 // Search the match registered GetInfo handler for the input guided section.
67 for (Index
= 0; Index
< SavedData
->NumberOfExtractHandler
; Index
++) {
68 if (CompareGuid (&SavedData
->ExtractHandlerGuidTable
[Index
], SectionGuid
)) {
74 // If the guided handler has been registered before, only update its handler.
76 if (Index
< SavedData
->NumberOfExtractHandler
) {
77 SavedData
->ExtractDecodeHandlerTable
[Index
] = DecodeHandler
;
78 SavedData
->ExtractGetInfoHandlerTable
[Index
] = GetInfoHandler
;
79 return RETURN_SUCCESS
;
83 // Check the global table is enough to contain new Handler.
85 if (SavedData
->NumberOfExtractHandler
>= PcdGet32 (PcdMaximumGuidedExtractHandler
)) {
86 return RETURN_OUT_OF_RESOURCES
;
90 // Register new Handler and guid value.
92 CopyGuid (&SavedData
->ExtractHandlerGuidTable
[SavedData
->NumberOfExtractHandler
], SectionGuid
);
93 SavedData
->ExtractDecodeHandlerTable
[SavedData
->NumberOfExtractHandler
] = DecodeHandler
;
94 SavedData
->ExtractGetInfoHandlerTable
[SavedData
->NumberOfExtractHandler
++] = GetInfoHandler
;
96 return RETURN_SUCCESS
;
101 ExtractGuidedSectionGetGuidList (
102 IN OUT GUID
**ExtractHandlerGuidTable
105 PRE_PI_EXTRACT_GUIDED_SECTION_DATA
*SavedData
;
107 ASSERT(ExtractHandlerGuidTable
!= NULL
);
109 SavedData
= GetSavedData();
111 *ExtractHandlerGuidTable
= SavedData
->ExtractHandlerGuidTable
;
112 return SavedData
->NumberOfExtractHandler
;
117 ExtractGuidedSectionGetInfo (
118 IN CONST VOID
*InputSection
,
119 OUT UINT32
*OutputBufferSize
,
120 OUT UINT32
*ScratchBufferSize
,
121 OUT UINT16
*SectionAttribute
124 PRE_PI_EXTRACT_GUIDED_SECTION_DATA
*SavedData
;
127 if (InputSection
== NULL
) {
128 return RETURN_INVALID_PARAMETER
;
131 ASSERT (OutputBufferSize
!= NULL
);
132 ASSERT (ScratchBufferSize
!= NULL
);
133 ASSERT (SectionAttribute
!= NULL
);
135 SavedData
= GetSavedData();
138 // Search the match registered GetInfo handler for the input guided section.
140 for (Index
= 0; Index
< SavedData
->NumberOfExtractHandler
; Index
++) {
141 if (CompareGuid (&SavedData
->ExtractHandlerGuidTable
[Index
], &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
147 // Not found, the input guided section is not supported.
149 if (Index
== SavedData
->NumberOfExtractHandler
) {
150 return RETURN_INVALID_PARAMETER
;
154 // Call the match handler to getinfo for the input section data.
156 return SavedData
->ExtractGetInfoHandlerTable
[Index
] (
166 ExtractGuidedSectionDecode (
167 IN CONST VOID
*InputSection
,
168 OUT VOID
**OutputBuffer
,
169 OUT VOID
*ScratchBuffer
, OPTIONAL
170 OUT UINT32
*AuthenticationStatus
173 PRE_PI_EXTRACT_GUIDED_SECTION_DATA
*SavedData
;
176 if (InputSection
== NULL
) {
177 return RETURN_INVALID_PARAMETER
;
180 ASSERT (OutputBuffer
!= NULL
);
181 ASSERT (AuthenticationStatus
!= NULL
);
183 SavedData
= GetSavedData();
186 // Search the match registered GetInfo handler for the input guided section.
188 for (Index
= 0; Index
< SavedData
->NumberOfExtractHandler
; Index
++) {
189 if (CompareGuid (&SavedData
->ExtractHandlerGuidTable
[Index
], &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
195 // Not found, the input guided section is not supported.
197 if (Index
== SavedData
->NumberOfExtractHandler
) {
198 return RETURN_INVALID_PARAMETER
;
202 // Call the match handler to getinfo for the input section data.
204 return SavedData
->ExtractDecodeHandlerTable
[Index
] (
214 ExtractGuidedSectionLibConstructor (
218 PRE_PI_EXTRACT_GUIDED_SECTION_DATA SavedData
;
219 GUID HobGuid
= PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID
;
222 // Allocate global pool space to store the registered handler and its guid value.
224 SavedData
.ExtractHandlerGuidTable
= (GUID
*)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler
) * sizeof(GUID
));
225 if (SavedData
.ExtractHandlerGuidTable
== NULL
) {
226 return RETURN_OUT_OF_RESOURCES
;
229 SavedData
.ExtractDecodeHandlerTable
= (EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler
) * sizeof(EXTRACT_GUIDED_SECTION_DECODE_HANDLER
));
230 if (SavedData
.ExtractDecodeHandlerTable
== NULL
) {
231 return RETURN_OUT_OF_RESOURCES
;
234 SavedData
.ExtractGetInfoHandlerTable
= (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler
) * sizeof(EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
));
235 if (SavedData
.ExtractGetInfoHandlerTable
== NULL
) {
236 return RETURN_OUT_OF_RESOURCES
;
240 // the initialized number is Zero.
242 SavedData
.NumberOfExtractHandler
= 0;
244 BuildGuidDataHob(&HobGuid
, &SavedData
, sizeof(SavedData
));
246 return RETURN_SUCCESS
;