]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Forms.c
add in data type cast to ensure stringent compilers are happy.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Forms.c
1 /**@file
2 This file contains the form processing code to the HII database.
3
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
9
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.
12
13 **/
14
15
16 #include "HiiDatabase.h"
17
18 EFI_STATUS
19 EFIAPI
20 HiiExportDatabase (
21 IN EFI_HII_PROTOCOL *This,
22 IN FRAMEWORK_EFI_HII_HANDLE Handle,
23 IN OUT UINTN *BufferSize,
24 OUT VOID *Buffer
25 )
26 /*++
27
28 Routine Description:
29
30 This function allows a program to extract a form or form package that has
31 previously been registered with the EFI HII database.
32
33 Arguments:
34
35 Returns:
36
37 --*/
38 {
39 ASSERT (FALSE);
40 return EFI_UNSUPPORTED;
41 }
42
43 EFI_STATUS
44 EFIAPI
45 HiiGetForms (
46 IN EFI_HII_PROTOCOL *This,
47 IN FRAMEWORK_EFI_HII_HANDLE Handle,
48 IN EFI_FORM_ID FormId,
49 IN OUT UINTN *BufferLengthTemp,
50 OUT UINT8 *Buffer
51 )
52 /*++
53
54 Routine Description:
55
56 This function allows a program to extract a form or form package that has
57 previously been registered with the EFI HII database.
58
59 Arguments:
60 This - A pointer to the EFI_HII_PROTOCOL instance.
61
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.
64
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.
67
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
70 requested form(s).
71
72 Buffer - The buffer designed to receive the form(s).
73
74 Returns:
75
76 EFI_SUCCESS - Buffer filled with the requested forms. BufferLength
77 was updated.
78
79 EFI_INVALID_PARAMETER - The handle is unknown.
80
81 EFI_NOT_FOUND - A form on the requested handle cannot be found with the
82 requested FormId.
83
84 EFI_BUFFER_TOO_SMALL - The buffer provided was not large enough to allow the form to be stored.
85
86 --*/
87 {
88 ASSERT (FALSE);
89 return EFI_UNSUPPORTED;
90 }
91
92 EFI_STATUS
93 EFIAPI
94 HiiGetDefaultImage (
95 IN EFI_HII_PROTOCOL *This,
96 IN FRAMEWORK_EFI_HII_HANDLE Handle,
97 IN UINTN DefaultMask,
98 OUT EFI_HII_VARIABLE_PACK_LIST **VariablePackList
99 )
100 /*++
101
102 Routine Description:
103
104 This function allows a program to extract the NV Image
105 that represents the default storage image
106
107 Arguments:
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.
114
115 Returns:
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.
119
120 --*/
121 {
122 return EFI_SUCCESS;
123 }
124
125 EFI_STATUS
126 ThunkUpdateFormCallBack (
127 IN EFI_HANDLE CallbackHandle,
128 IN CONST HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY *HandleMapEntry
129 )
130 {
131 EFI_STATUS Status;
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;
136
137 Status = gBS->HandleProtocol (
138 CallbackHandle,
139 &gEfiFormCallbackProtocolGuid,
140 (VOID **) &FrameworkFormCallbackProtocol
141 );
142 if (EFI_ERROR (Status)) {
143 return EFI_INVALID_PARAMETER;
144 }
145
146 Status = mUefiHiiDatabaseProtocol->GetPackageListHandle (
147 mUefiHiiDatabaseProtocol,
148 HandleMapEntry->UefiHiiHandle,
149 &UefiDriverHandle
150 );
151 ASSERT_EFI_ERROR (Status);
152 Status = gBS->HandleProtocol (
153 UefiDriverHandle,
154 &gEfiHiiConfigAccessProtocolGuid,
155 (VOID **) &ConfigAccessProtocol
156 );
157 ASSERT_EFI_ERROR (Status);
158
159 ConfigAccessProtocolInstance = HII_TRHUNK_CONFIG_ACCESS_PROTOCOL_INSTANCE_FROM_PROTOCOL (ConfigAccessProtocol);
160
161 ConfigAccessProtocolInstance->FrameworkFormCallbackProtocol = FrameworkFormCallbackProtocol;
162
163 return EFI_SUCCESS;
164 }
165
166 #define LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL 0x1000
167
168 EFI_STATUS
169 AppendToUpdateBuffer (
170 IN CONST UINT8 *OpCodeBuf,
171 IN UINTN BufSize,
172 OUT EFI_HII_UPDATE_DATA *UefiData
173 )
174 {
175 UINT8 * NewBuff;
176
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;
181 }
182 UefiData->BufferSize += LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL;
183 FreePool (UefiData->Data);
184 UefiData->Data = NewBuff;
185 }
186
187 CopyMem (UefiData->Data + UefiData->Offset, OpCodeBuf, BufSize);
188 UefiData->Offset += (UINT32) BufSize;
189
190 return EFI_SUCCESS;
191 }
192
193 EFI_STATUS
194 Framework2UefiCreateSubtitleOpCode (
195 IN CONST FRAMEWORK_EFI_IFR_SUBTITLE *FwSubTitle,
196 OUT EFI_HII_UPDATE_DATA *UefiData
197 )
198 {
199 EFI_IFR_SUBTITLE USubTitle;
200
201 ZeroMem (&USubTitle, sizeof(USubTitle));
202
203 USubTitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;
204 USubTitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);
205
206 USubTitle.Statement.Prompt = FwSubTitle->SubTitle;
207
208 return AppendToUpdateBuffer ((UINT8 *)&USubTitle, sizeof(EFI_IFR_SUBTITLE), UefiData);
209 }
210
211 EFI_STATUS
212 Framework2UefiCreateTextOpCode (
213 IN CONST FRAMEWORK_EFI_IFR_TEXT *FwText,
214 OUT EFI_HII_UPDATE_DATA *UefiData
215 )
216 {
217 EFI_IFR_TEXT UText;
218
219 ZeroMem (&UText, sizeof(UText));
220
221 UText.Header.OpCode = EFI_IFR_TEXT_OP;
222 UText.Header.Length = sizeof (EFI_IFR_TEXT);
223
224 UText.Statement.Help = FwText->Help;
225
226 UText.Statement.Prompt = FwText->Text;
227 UText.TextTwo = FwText->TextTwo;
228
229 return AppendToUpdateBuffer ((UINT8 *) &UText, sizeof(EFI_IFR_TEXT), UefiData);
230 }
231
232
233 EFI_STATUS
234 ThunkFrameworkUpdateDataToUefiUpdateData (
235 IN CONST FRAMEWORK_EFI_HII_UPDATE_DATA *Data,
236 IN BOOLEAN AddData,
237 OUT EFI_HII_UPDATE_DATA **UefiData
238 )
239 {
240 FRAMEWORK_EFI_IFR_OP_HEADER *FrameworkOpcodeBuffer;
241 EFI_HII_UPDATE_DATA *UefiUpdateDataBuffer;
242 UINTN Index;
243 EFI_STATUS Status;
244
245 UefiUpdateDataBuffer = AllocateZeroPool (sizeof (EFI_HII_UPDATE_DATA));
246 if (UefiUpdateDataBuffer == NULL) {
247 return EFI_OUT_OF_RESOURCES;
248 }
249
250 UefiUpdateDataBuffer->Data = AllocateZeroPool (LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL);
251 if (UefiUpdateDataBuffer->Data == NULL) {
252 return EFI_OUT_OF_RESOURCES;
253 }
254
255 UefiUpdateDataBuffer->BufferSize = LOCAL_UPDATE_DATA_BUFFER_INCREMENTAL;
256 UefiUpdateDataBuffer->Offset = 0;
257
258 FrameworkOpcodeBuffer = (FRAMEWORK_EFI_IFR_OP_HEADER *) &Data->Data;
259
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);
264 break;
265
266 case FRAMEWORK_EFI_IFR_TEXT_OP:
267 Status = Framework2UefiCreateTextOpCode ((FRAMEWORK_EFI_IFR_TEXT *) FrameworkOpcodeBuffer, UefiUpdateDataBuffer);
268 break;
269
270 default:
271 ASSERT (FALSE);
272 return EFI_UNSUPPORTED;
273 }
274
275 if (EFI_ERROR (Status)) {
276 FreePool (UefiUpdateDataBuffer->Data);
277 FreePool (UefiUpdateDataBuffer);
278 return Status;
279 }
280
281 FrameworkOpcodeBuffer = (FRAMEWORK_EFI_IFR_OP_HEADER *)((UINT8 *) FrameworkOpcodeBuffer + FrameworkOpcodeBuffer->Length);
282 }
283
284 *UefiData = UefiUpdateDataBuffer;
285
286 return EFI_SUCCESS;
287 }
288 EFI_STATUS
289 EFIAPI
290 HiiUpdateForm (
291 IN EFI_HII_PROTOCOL *This,
292 IN FRAMEWORK_EFI_HII_HANDLE Handle,
293 IN EFI_FORM_LABEL Label,
294 IN BOOLEAN AddData,
295 IN FRAMEWORK_EFI_HII_UPDATE_DATA *Data
296 )
297 /*++
298
299 Routine Description:
300 This function allows the caller to update a form that has
301 previously been registered with the EFI HII database.
302
303 Arguments:
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
308
309 Returns:
310 EFI_SUCCESS - Update success.
311 Other - Update fail.
312
313 --*/
314 {
315 EFI_STATUS Status;
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;
320
321 Status = EFI_SUCCESS;
322
323 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
324
325 HandleMapEntry = FrameworkHiiHandleToMapDatabaseEntry (Private, Handle);
326
327 if (HandleMapEntry == NULL) {
328 return EFI_NOT_FOUND;
329 }
330
331 if (Data->FormSetUpdate) {
332 Status = ThunkUpdateFormCallBack ((EFI_HANDLE) (UINTN) Data->FormCallbackHandle, HandleMapEntry);
333 if (EFI_ERROR (Status)) {
334 return Status;
335 }
336 }
337
338 if (Data->DataCount != 0) {
339 if (HandleMapEntry->IsPackageListWithOnlyStringPackages) {
340 UefiHiiHandle = TagGuidToUefiIfrHiiHandle (Private, &HandleMapEntry->TagGuid);
341
342 if (UefiHiiHandle == NULL) {
343 return EFI_INVALID_PARAMETER;
344 }
345 } else {
346 UefiHiiHandle = HandleMapEntry->UefiHiiHandle;
347 }
348
349 UefiHiiUpdateData = NULL;
350
351 ThunkFrameworkUpdateDataToUefiUpdateData (Data, AddData, &UefiHiiUpdateData);
352
353 Status = IfrLibUpdateForm (UefiHiiHandle, NULL, 0, Label, AddData, UefiHiiUpdateData);
354 ASSERT_EFI_ERROR (Status);
355
356 if (UefiHiiUpdateData != NULL) {
357 SafeFreePool (UefiHiiUpdateData->Data);
358 SafeFreePool (UefiHiiUpdateData);
359 }
360 }
361
362 return Status;
363 }