2 This file contains the form processing code to the HII database.
4 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
5 All rights reserved. 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 "HiiDatabase.h"
21 IN EFI_HII_PROTOCOL
*This
,
22 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
23 IN OUT UINTN
*BufferSize
,
30 This function allows a program to extract a form or form package that has
31 previously been registered with the EFI HII database.
40 return EFI_UNSUPPORTED
;
46 IN EFI_HII_PROTOCOL
*This
,
47 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
48 IN EFI_FORM_ID FormId
,
49 IN OUT UINTN
*BufferLengthTemp
,
56 This function allows a program to extract a form or form package that has
57 previously been registered with the EFI HII database.
60 This - A pointer to the EFI_HII_PROTOCOL instance.
62 Handle - Handle on which the form resides. Type FRAMEWORK_EFI_HII_HANDLE is defined in
63 EFI_HII_PROTOCOL.NewPack() in the Packages section.
65 FormId - The ID of the form to return. If the ID is zero, the entire form package is returned.
66 Type EFI_FORM_ID is defined in "Related Definitions" below.
68 BufferLength - On input, the length of the Buffer. On output, the length of the returned buffer, if
69 the length was sufficient and, if it was not, the length that is required to fit the
72 Buffer - The buffer designed to receive the form(s).
76 EFI_SUCCESS - Buffer filled with the requested forms. BufferLength
79 EFI_INVALID_PARAMETER - The handle is unknown.
81 EFI_NOT_FOUND - A form on the requested handle cannot be found with the
84 EFI_BUFFER_TOO_SMALL - The buffer provided was not large enough to allow the form to be stored.
89 return EFI_UNSUPPORTED
;
95 IN EFI_HII_PROTOCOL
*This
,
96 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
98 OUT EFI_HII_VARIABLE_PACK_LIST
**VariablePackList
104 This function allows a program to extract the NV Image
105 that represents the default storage image
108 This - A pointer to the EFI_HII_PROTOCOL instance.
109 Handle - The HII handle from which will have default data retrieved.
110 UINTN - Mask used to retrieve the default image.
111 VariablePackList - Callee allocated, tightly-packed, link list data
112 structure that contain all default varaible packs
113 from the Hii Database.
116 EFI_NOT_FOUND - If Hii database does not contain any default images.
117 EFI_INVALID_PARAMETER - Invalid input parameter.
118 EFI_SUCCESS - Operation successful.
126 ThunkUpdateFormCallBack (
127 IN EFI_HANDLE CallbackHandle
,
128 IN CONST HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY
*HandleMapEntry
132 EFI_FORM_CALLBACK_PROTOCOL
*FrameworkFormCallbackProtocol
;
133 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccessProtocol
;
134 EFI_HANDLE UefiDriverHandle
;
135 HII_TRHUNK_CONFIG_ACCESS_PROTOCOL_INSTANCE
*ConfigAccessProtocolInstance
;
137 Status
= gBS
->HandleProtocol (
139 &gEfiFormCallbackProtocolGuid
,
140 (VOID
**) &FrameworkFormCallbackProtocol
142 if (EFI_ERROR (Status
)) {
143 return EFI_INVALID_PARAMETER
;
146 Status
= mUefiHiiDatabaseProtocol
->GetPackageListHandle (
147 mUefiHiiDatabaseProtocol
,
148 HandleMapEntry
->UefiHiiHandle
,
151 ASSERT_EFI_ERROR (Status
);
152 Status
= gBS
->HandleProtocol (
154 &gEfiHiiConfigAccessProtocolGuid
,
155 (VOID
**) &ConfigAccessProtocol
157 ASSERT_EFI_ERROR (Status
);
159 ConfigAccessProtocolInstance
= HII_TRHUNK_CONFIG_ACCESS_PROTOCOL_INSTANCE_FROM_PROTOCOL (ConfigAccessProtocol
);
161 ConfigAccessProtocolInstance
->FrameworkFormCallbackProtocol
= FrameworkFormCallbackProtocol
;
166 #define LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL 0x1000
169 AppendToUpdateBuffer (
170 IN CONST UINT8
*OpCodeBuf
,
172 OUT EFI_HII_UPDATE_DATA
*UefiData
177 if (UefiData
->Offset
+ BufSize
> UefiData
->BufferSize
) {
178 NewBuff
= AllocateCopyPool (UefiData
->BufferSize
+ LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL
, UefiData
->Data
);
179 if (NewBuff
== NULL
) {
180 return EFI_OUT_OF_RESOURCES
;
182 UefiData
->BufferSize
+= LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL
;
183 FreePool (UefiData
->Data
);
184 UefiData
->Data
= NewBuff
;
187 CopyMem (UefiData
->Data
+ UefiData
->Offset
, OpCodeBuf
, BufSize
);
188 UefiData
->Offset
+= (UINT32
) BufSize
;
194 Framework2UefiCreateSubtitleOpCode (
195 IN CONST FRAMEWORK_EFI_IFR_SUBTITLE
*FwSubTitle
,
196 OUT EFI_HII_UPDATE_DATA
*UefiData
199 EFI_IFR_SUBTITLE USubTitle
;
201 ZeroMem (&USubTitle
, sizeof(USubTitle
));
203 USubTitle
.Header
.OpCode
= EFI_IFR_SUBTITLE_OP
;
204 USubTitle
.Header
.Length
= sizeof (EFI_IFR_SUBTITLE
);
206 USubTitle
.Statement
.Prompt
= FwSubTitle
->SubTitle
;
208 return AppendToUpdateBuffer ((UINT8
*)&USubTitle
, sizeof(EFI_IFR_SUBTITLE
), UefiData
);
212 Framework2UefiCreateTextOpCode (
213 IN CONST FRAMEWORK_EFI_IFR_TEXT
*FwText
,
214 OUT EFI_HII_UPDATE_DATA
*UefiData
219 ZeroMem (&UText
, sizeof(UText
));
221 UText
.Header
.OpCode
= EFI_IFR_TEXT_OP
;
222 UText
.Header
.Length
= sizeof (EFI_IFR_TEXT
);
224 UText
.Statement
.Help
= FwText
->Help
;
226 UText
.Statement
.Prompt
= FwText
->Text
;
227 UText
.TextTwo
= FwText
->TextTwo
;
229 return AppendToUpdateBuffer ((UINT8
*) &UText
, sizeof(EFI_IFR_TEXT
), UefiData
);
234 ThunkFrameworkUpdateDataToUefiUpdateData (
235 IN CONST FRAMEWORK_EFI_HII_UPDATE_DATA
*Data
,
237 OUT EFI_HII_UPDATE_DATA
**UefiData
240 FRAMEWORK_EFI_IFR_OP_HEADER
*FrameworkOpcodeBuffer
;
241 EFI_HII_UPDATE_DATA
*UefiUpdateDataBuffer
;
245 UefiUpdateDataBuffer
= AllocateZeroPool (sizeof (EFI_HII_UPDATE_DATA
));
246 if (UefiUpdateDataBuffer
== NULL
) {
247 return EFI_OUT_OF_RESOURCES
;
250 UefiUpdateDataBuffer
->Data
= AllocateZeroPool (LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL
);
251 if (UefiUpdateDataBuffer
->Data
== NULL
) {
252 return EFI_OUT_OF_RESOURCES
;
255 UefiUpdateDataBuffer
->BufferSize
= LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL
;
256 UefiUpdateDataBuffer
->Offset
= 0;
258 FrameworkOpcodeBuffer
= (FRAMEWORK_EFI_IFR_OP_HEADER
*) &Data
->Data
;
260 for (Index
= 0; Index
< Data
->DataCount
; Index
++) {
261 switch (FrameworkOpcodeBuffer
->OpCode
) {
262 case FRAMEWORK_EFI_IFR_SUBTITLE_OP
:
263 Status
= Framework2UefiCreateSubtitleOpCode ((FRAMEWORK_EFI_IFR_SUBTITLE
*) FrameworkOpcodeBuffer
, UefiUpdateDataBuffer
);
266 case FRAMEWORK_EFI_IFR_TEXT_OP
:
267 Status
= Framework2UefiCreateTextOpCode ((FRAMEWORK_EFI_IFR_TEXT
*) FrameworkOpcodeBuffer
, UefiUpdateDataBuffer
);
272 return EFI_UNSUPPORTED
;
275 if (EFI_ERROR (Status
)) {
276 FreePool (UefiUpdateDataBuffer
->Data
);
277 FreePool (UefiUpdateDataBuffer
);
281 FrameworkOpcodeBuffer
= (FRAMEWORK_EFI_IFR_OP_HEADER
*)((UINT8
*) FrameworkOpcodeBuffer
+ FrameworkOpcodeBuffer
->Length
);
284 *UefiData
= UefiUpdateDataBuffer
;
291 IN EFI_HII_PROTOCOL
*This
,
292 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
293 IN EFI_FORM_LABEL Label
,
295 IN FRAMEWORK_EFI_HII_UPDATE_DATA
*Data
300 This function allows the caller to update a form that has
301 previously been registered with the EFI HII database.
304 Handle - Hii Handle associated with the Formset to modify
305 Label - Update information starting immediately after this label in the IFR
306 AddData - If TRUE, add data. If FALSE, remove data
307 Data - If adding data, this is the pointer to the data to add
310 EFI_SUCCESS - Update success.
316 EFI_HII_THUNK_PRIVATE_DATA
*Private
;
317 HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY
*HandleMapEntry
;
318 EFI_HII_UPDATE_DATA
*UefiHiiUpdateData
;
319 EFI_HII_HANDLE UefiHiiHandle
;
321 Status
= EFI_SUCCESS
;
323 Private
= EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
325 HandleMapEntry
= FrameworkHiiHandleToMapDatabaseEntry (Private
, Handle
);
327 if (HandleMapEntry
== NULL
) {
328 return EFI_NOT_FOUND
;
331 if (Data
->FormSetUpdate
) {
332 Status
= ThunkUpdateFormCallBack ((EFI_HANDLE
) (UINTN
) Data
->FormCallbackHandle
, HandleMapEntry
);
333 if (EFI_ERROR (Status
)) {
338 if (Data
->DataCount
!= 0) {
339 if (HandleMapEntry
->IsPackageListWithOnlyStringPackages
) {
340 UefiHiiHandle
= TagGuidToUefiIfrHiiHandle (Private
, &HandleMapEntry
->TagGuid
);
342 if (UefiHiiHandle
== NULL
) {
343 return EFI_INVALID_PARAMETER
;
346 UefiHiiHandle
= HandleMapEntry
->UefiHiiHandle
;
349 UefiHiiUpdateData
= NULL
;
351 ThunkFrameworkUpdateDataToUefiUpdateData (Data
, AddData
, &UefiHiiUpdateData
);
353 Status
= IfrLibUpdateForm (UefiHiiHandle
, NULL
, 0, Label
, AddData
, UefiHiiUpdateData
);
354 ASSERT_EFI_ERROR (Status
);
356 if (UefiHiiUpdateData
!= NULL
) {
357 SafeFreePool (UefiHiiUpdateData
->Data
);
358 SafeFreePool (UefiHiiUpdateData
);