]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c
Add #defines that were removed from IntelFrameworkPkg/Include/Protocol/FrameworkFormC...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / ConfigAccess.c
1 /**@file
2 This file implements functions related to Config Access Protocols installed by
3 by HII Thunk Modules. These Config access Protocols are used to thunk UEFI Config
4 Access Callback to Framework HII Callback and EFI Variable Set/Get operations.
5
6 Copyright (c) 2008, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "HiiDatabase.h"
18 #include "UefiIfrParser.h"
19
20 //
21 // Defintions required for EFI_FORM_CALLBACK_PROTOCOL, but they are not defined in the Framwork HII 0.92 Specification
22 //
23 #define RESET_REQUIRED 1 // Flags setting to signify that the callback operation resulted in an eventual
24 // reset to be done upon exit of the browser
25 #define EXIT_REQUIRED 2 // Flags setting to signify that after the processing of the callback results - exit the browser
26 #define SAVE_REQUIRED 4 // Flags setting to signify that after the processing of the callback results - save the NV data
27 #define NV_CHANGED 8 // Flags setting to signify that after the processing of the callback results - turn the NV flag on
28 #define NV_NOT_CHANGED 16 // Flags setting to signify that after the processing of the callback results - turn the NV flag off
29
30
31 BOOLEAN mHiiPackageListUpdated = FALSE;
32
33 HII_VENDOR_DEVICE_PATH mUefiHiiVendorDevicePath = {
34 {
35 {
36 {
37 HARDWARE_DEVICE_PATH,
38 HW_VENDOR_DP,
39 {
40 (UINT8) (sizeof (HII_VENDOR_DEVICE_PATH_NODE)),
41 (UINT8) ((sizeof (HII_VENDOR_DEVICE_PATH_NODE)) >> 8)
42 }
43 },
44 EFI_CALLER_ID_GUID
45 },
46 0,
47 0
48 },
49 {
50 END_DEVICE_PATH_TYPE,
51 END_ENTIRE_DEVICE_PATH_SUBTYPE,
52 {
53 (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL)),
54 (UINT8) ((sizeof (EFI_DEVICE_PATH_PROTOCOL)) >> 8)
55 }
56 }
57 };
58
59 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate = {
60 CONFIG_ACCESS_PRIVATE_SIGNATURE,
61 {
62 ThunkExtractConfig,
63 ThunkRouteConfig,
64 ThunkCallback
65 }, //ConfigAccessProtocol
66 NULL, //FormCallbackProtocol
67 NULL
68 };
69
70 /**
71 Get the first EFI_IFR_VARSTORE from the FormSet.
72
73 @param FormSet The Form Set.
74
75 @retval FORMSET_STORAGE * Return the first EFI_IFR_VARSTORE.
76 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
77 **/
78 FORMSET_STORAGE *
79 GetFirstStorageOfFormSet (
80 IN CONST FORM_BROWSER_FORMSET * FormSet
81 )
82 {
83 LIST_ENTRY *StorageList;
84 FORMSET_STORAGE *Storage;
85
86 StorageList = GetFirstNode (&FormSet->StorageListHead);
87
88 if (!IsNull (&FormSet->StorageListHead, StorageList)) {
89 Storage = FORMSET_STORAGE_FROM_LINK (StorageList);
90 return Storage;
91 }
92
93 return NULL;
94 }
95
96 /**
97 Get the EFI_IFR_VARSTORE where the Question's value is stored.
98
99 @param FormSet The Form Set.
100
101 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
102 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
103 **/
104 FORMSET_STORAGE *
105 GetStorageFromQuestionId (
106 IN CONST FORM_BROWSER_FORMSET * FormSet,
107 IN EFI_QUESTION_ID QuestionId
108 )
109 {
110 LIST_ENTRY *FormList;
111 LIST_ENTRY *StatementList;
112 FORM_BROWSER_FORM *Form;
113 FORM_BROWSER_STATEMENT *Statement;
114
115 FormList = GetFirstNode (&FormSet->FormListHead);
116
117 while (!IsNull (&FormSet->FormListHead, FormList)) {
118 Form = FORM_BROWSER_FORM_FROM_LINK (FormList);
119
120 StatementList = GetFirstNode (&Form->StatementListHead);
121
122 while (!IsNull (&Form->StatementListHead, StatementList)) {
123 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (StatementList);
124 if ((QuestionId == Statement->QuestionId) && (Statement->Storage != NULL)) {
125 //
126 // UEFI Question ID is unique in a FormSet.
127 //
128 ASSERT (Statement->Storage->Type == EFI_HII_VARSTORE_BUFFER);
129 return Statement->Storage;
130 }
131 StatementList = GetNextNode (&Form->StatementListHead, StatementList);
132 }
133
134 FormList = GetNextNode (&FormSet->FormListHead, FormList);
135 }
136
137 return NULL;
138 }
139
140 /**
141 Get the EFI_IFR_VARSTORE based the ID.
142
143 @param FormSet The Form Set.
144
145 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE with the ID.
146 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
147 **/
148 FORMSET_STORAGE *
149 GetStorageFromVarStoreId (
150 IN CONST FORM_BROWSER_FORMSET * FormSet,
151 IN EFI_VARSTORE_ID VarStoreId
152 )
153 {
154 LIST_ENTRY *StorageList;
155 FORMSET_STORAGE *Storage;
156
157 StorageList = GetFirstNode (&FormSet->StorageListHead);
158
159 while (!IsNull (&FormSet->StorageListHead, StorageList)) {
160 Storage = FORMSET_STORAGE_FROM_LINK (StorageList);
161
162 if (VarStoreId == Storage->VarStoreId) {
163 return Storage;
164 }
165
166 StorageList = GetNextNode (&FormSet->StorageListHead, StorageList);
167 }
168
169 return NULL;
170 }
171
172 /**
173 Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>
174 or a <ConfigResp> string.
175
176 @param FormSet The Form Set.
177 @param ConfigString The Configuration String which is defined by UEFI HII.
178
179 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
180 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
181 **/
182 FORMSET_STORAGE *
183 GetStorageFromConfigString (
184 IN CONST FORM_BROWSER_FORMSET *FormSet,
185 IN CONST EFI_STRING ConfigString
186 )
187 {
188 LIST_ENTRY *StorageList;
189 FORMSET_STORAGE *Storage;
190 CHAR16 *Name;
191
192 StorageList = GetFirstNode (&FormSet->StorageListHead);
193
194 while (!IsNull (&FormSet->StorageListHead, StorageList)) {
195 Storage = FORMSET_STORAGE_FROM_LINK (StorageList);
196
197 if ((Storage->VarStoreId == FormSet->DefaultVarStoreId) && (FormSet->OriginalDefaultVarStoreName != NULL)) {
198 Name = FormSet->OriginalDefaultVarStoreName;
199 } else {
200 Name = Storage->Name;
201 }
202
203 if (HiiIsConfigHdrMatch (ConfigString, &Storage->Guid, Name)) {
204 return Storage;
205 }
206
207 StorageList = GetNextNode (&FormSet->StorageListHead, StorageList);
208 }
209
210 return NULL;
211 }
212
213 /**
214 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
215 by a module using Framework HII Protocol Interfaces.
216
217 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
218 that Setup Utility can load the Buffer Storage using this protocol.
219
220 @param Packages The Package List.
221 @param ThunkContext The Thunk Context.
222
223 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
224 @retval EFI_OUT_RESOURCE There is not enough memory.
225
226 **/
227 EFI_STATUS
228 InstallDefaultConfigAccessProtocol (
229 IN CONST EFI_HII_PACKAGES *Packages,
230 IN OUT HII_THUNK_CONTEXT *ThunkContext
231 )
232 {
233 EFI_STATUS Status;
234 CONFIG_ACCESS_PRIVATE *ConfigAccessInstance;
235 HII_VENDOR_DEVICE_PATH *HiiVendorPath;
236
237 ASSERT (ThunkContext->IfrPackageCount != 0);
238
239 ConfigAccessInstance = AllocateCopyPool (
240 sizeof (CONFIG_ACCESS_PRIVATE),
241 &gConfigAccessPrivateTempate
242 );
243 ASSERT (ConfigAccessInstance != NULL);
244
245 //
246 // Use memory address as unique ID to distinguish from different device paths
247 // This function may be called multi times by the framework HII driver.
248 //
249 HiiVendorPath = AllocateCopyPool (
250 sizeof (HII_VENDOR_DEVICE_PATH),
251 &mUefiHiiVendorDevicePath
252 );
253 ASSERT (HiiVendorPath != NULL);
254
255 HiiVendorPath->Node.UniqueId = (UINT64) ((UINTN) HiiVendorPath);
256
257 Status = gBS->InstallMultipleProtocolInterfaces (
258 &ThunkContext->UefiHiiDriverHandle,
259 &gEfiDevicePathProtocolGuid,
260 HiiVendorPath,
261 &gEfiHiiConfigAccessProtocolGuid,
262 &ConfigAccessInstance->ConfigAccessProtocol,
263 NULL
264 );
265 ASSERT_EFI_ERROR (Status);
266
267 ConfigAccessInstance->ThunkContext = ThunkContext;
268
269 return EFI_SUCCESS;
270 }
271
272 /**
273 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
274 by a module using Framework HII Protocol Interfaces.
275
276 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
277
278 @param ThunkContext The Thunk Context.
279
280 **/
281 VOID
282 UninstallDefaultConfigAccessProtocol (
283 IN HII_THUNK_CONTEXT *ThunkContext
284 )
285 {
286 EFI_STATUS Status;
287 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
288 HII_VENDOR_DEVICE_PATH *HiiVendorPath;
289
290 Status = gBS->HandleProtocol (
291 ThunkContext->UefiHiiDriverHandle,
292 &gEfiHiiConfigAccessProtocolGuid,
293 (VOID **) &ConfigAccess
294 );
295 ASSERT_EFI_ERROR (Status);
296
297 Status = gBS->HandleProtocol (
298 ThunkContext->UefiHiiDriverHandle,
299 &gEfiDevicePathProtocolGuid,
300 (VOID **) &HiiVendorPath
301 );
302 ASSERT_EFI_ERROR (Status);
303
304 Status = gBS->UninstallMultipleProtocolInterfaces (
305 ThunkContext->UefiHiiDriverHandle,
306 &gEfiDevicePathProtocolGuid,
307 HiiVendorPath,
308 &gEfiHiiConfigAccessProtocolGuid,
309 ConfigAccess,
310 NULL
311 );
312 ASSERT_EFI_ERROR (Status);
313
314 }
315
316
317 /**
318 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
319
320 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
321 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
322 @param Data The data read.
323 @param DataSize The size of data.
324
325 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
326 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
327 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
328 **/
329 EFI_STATUS
330 CallFormCallBack (
331 IN FORMSET_STORAGE *BufferStorage,
332 IN EFI_FORM_CALLBACK_PROTOCOL *FwFormCallBack,
333 OUT VOID **Data,
334 OUT UINTN *DataSize
335 )
336 {
337 EFI_STATUS Status;
338
339 *DataSize = 0;
340 *Data = NULL;
341
342 Status = FwFormCallBack->NvRead (
343 FwFormCallBack,
344 BufferStorage->Name,
345 &BufferStorage->Guid,
346 NULL,
347 DataSize,
348 *Data
349 );
350 if (Status == EFI_BUFFER_TOO_SMALL) {
351 if (BufferStorage->Size != *DataSize) {
352 ASSERT (FALSE);
353 return EFI_INVALID_PARAMETER;
354 }
355
356 *Data = AllocateZeroPool (*DataSize);
357 if (Data == NULL) {
358 return EFI_OUT_OF_RESOURCES;
359 }
360
361 FwFormCallBack->NvRead (
362 FwFormCallBack,
363 BufferStorage->Name,
364 &BufferStorage->Guid,
365 NULL,
366 DataSize,
367 *Data
368 );
369 }
370
371 return Status;
372 }
373
374
375 /**
376 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
377
378 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
379 @param Data The data read.
380 @param DataSize The size of data.
381
382 If the UEFI Variable Get Service return the size information of the data
383 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
384 then ASSERT.
385
386 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
387 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
388 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
389 **/
390
391 EFI_STATUS
392 GetUefiVariable (
393 IN FORMSET_STORAGE *BufferStorage,
394 OUT VOID **Data,
395 OUT UINTN *DataSize
396 )
397 {
398 EFI_STATUS Status;
399
400 *DataSize = 0;
401 *Data = NULL;
402 Status = gRT->GetVariable (
403 BufferStorage->Name,
404 &BufferStorage->Guid,
405 NULL,
406 DataSize,
407 *Data
408 );
409 if (Status == EFI_BUFFER_TOO_SMALL) {
410
411 if (BufferStorage->Size != *DataSize) {
412 ASSERT (FALSE);
413 return EFI_INVALID_PARAMETER;
414 }
415
416 *Data = AllocateZeroPool (*DataSize);
417 if (Data == NULL) {
418 return EFI_OUT_OF_RESOURCES;
419 }
420
421 Status = gRT->GetVariable (
422 BufferStorage->Name,
423 &BufferStorage->Guid,
424 NULL,
425 DataSize,
426 *Data
427 );
428 }
429
430 return Status;
431 }
432
433 /**
434
435 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
436 so that data can be read from the data storage such as UEFI Variable or module's
437 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
438
439 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
440 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
441 includes the routing information as well as the configurable name / value pairs. It is
442 invalid for this string to be in <MultiConfigRequest> format.
443
444 @param Progress On return, points to a character in the Request string. Points to the string's null
445 terminator if request was successful. Points to the most recent '&' before the first
446 failing name / value pair (or the beginning of the string if the failure is in the first
447 name / value pair) if the request was not successful
448 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
449 values filled in for the names in the Request string. String to be allocated by the called
450 function.
451
452 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
453 @retval EFI_SUCCESS The setting is retrived successfully.
454 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
455 **/
456 EFI_STATUS
457 EFIAPI
458 ThunkExtractConfig (
459 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
460 IN CONST EFI_STRING Request,
461 OUT EFI_STRING *Progress,
462 OUT EFI_STRING *Results
463 )
464 {
465 EFI_STATUS Status;
466 CONFIG_ACCESS_PRIVATE *ConfigAccess;
467 FORMSET_STORAGE *BufferStorage;
468 VOID *Data;
469 UINTN DataSize;
470
471 if (Request == NULL) {
472 return EFI_NOT_FOUND;
473 }
474
475 Data = NULL;
476 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
477
478 BufferStorage = GetStorageFromConfigString (ConfigAccess->ThunkContext->FormSet, Request);
479
480 if (BufferStorage == NULL) {
481 *Progress = (EFI_STRING) Request;
482 return EFI_NOT_FOUND;
483 }
484
485 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
486 //
487 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
488 //
489 if (ConfigAccess->FormCallbackProtocol == NULL ||
490 ConfigAccess->FormCallbackProtocol->NvRead == NULL) {
491 Status = GetUefiVariable (
492 BufferStorage,
493 &Data,
494 &DataSize
495 );
496 } else {
497 Status = CallFormCallBack (
498 BufferStorage,
499 ConfigAccess->FormCallbackProtocol,
500 &Data,
501 &DataSize
502 );
503 }
504 } else {
505 //
506 // Use the NvMapOverride.
507 //
508 DataSize = BufferStorage->Size;
509 Data = AllocateCopyPool (DataSize, ConfigAccess->ThunkContext->NvMapOverride);
510
511 if (Data != NULL) {
512 Status = EFI_SUCCESS;
513 } else {
514 Status = EFI_OUT_OF_RESOURCES;
515 }
516 }
517
518 if (!EFI_ERROR (Status)) {
519 Status = mHiiConfigRoutingProtocol->BlockToConfig (
520 mHiiConfigRoutingProtocol,
521 Request,
522 Data,
523 DataSize,
524 Results,
525 Progress
526 );
527 }
528
529 if (Data != NULL) {
530 FreePool (Data);
531 }
532 return Status;
533 }
534
535 /**
536 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
537 so that data can be written to the data storage such as UEFI Variable or module's
538 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
539
540 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
541 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
542 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
543 failing name / value pair (or the beginning of the string if the failure is in the first
544 name / value pair) or the terminating NULL if all was successful.
545
546 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
547 @retval EFI_SUCCESS The setting is saved successfully.
548 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
549 **/
550 EFI_STATUS
551 EFIAPI
552 ThunkRouteConfig (
553 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
554 IN CONST EFI_STRING Configuration,
555 OUT EFI_STRING *Progress
556 )
557 {
558 EFI_STATUS Status;
559 CONFIG_ACCESS_PRIVATE *ConfigAccess;
560 FORMSET_STORAGE *BufferStorage;
561 VOID *Data;
562 UINTN DataSize;
563 UINTN DataSize2;
564 UINTN LastModifiedByteIndex;
565 BOOLEAN ResetRequired;
566 BOOLEAN DataAllocated;
567
568 if (Configuration == NULL) {
569 return EFI_INVALID_PARAMETER;
570 }
571
572 Data = NULL;
573 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
574
575 BufferStorage = GetStorageFromConfigString (ConfigAccess->ThunkContext->FormSet, Configuration);
576
577 if (BufferStorage == NULL) {
578 *Progress = Configuration;
579 return EFI_NOT_FOUND;
580 }
581
582 DataSize2 = BufferStorage->Size;
583 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
584 DataAllocated = TRUE;
585 if (ConfigAccess->FormCallbackProtocol == NULL ||
586 ConfigAccess->FormCallbackProtocol->NvRead == NULL) {
587 Status = GetUefiVariable (
588 BufferStorage,
589 &Data,
590 &DataSize
591 );
592 } else {
593 Status = CallFormCallBack (
594 BufferStorage,
595 ConfigAccess->FormCallbackProtocol,
596 &Data,
597 &DataSize
598 );
599 }
600 } else {
601 //
602 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
603 //
604 Status = EFI_SUCCESS;
605 Data = ConfigAccess->ThunkContext->NvMapOverride;
606 DataSize = DataSize2;
607 DataAllocated = FALSE;
608 }
609 if (EFI_ERROR (Status) || (DataSize2 != DataSize)) {
610 if (Data == NULL) {
611 Data = AllocateZeroPool (DataSize2);
612 }
613 }
614
615 Status = mHiiConfigRoutingProtocol->ConfigToBlock (
616 mHiiConfigRoutingProtocol,
617 Configuration,
618 Data,
619 &LastModifiedByteIndex,
620 Progress
621 );
622 if (EFI_ERROR (Status)) {
623 goto Done;
624 }
625
626 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
627 if (ConfigAccess->FormCallbackProtocol == NULL ||
628 ConfigAccess->FormCallbackProtocol->NvWrite == NULL) {
629 Status = gRT->SetVariable (
630 BufferStorage->Name,
631 &BufferStorage->Guid,
632 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
633 DataSize2,
634 Data
635 );
636 } else {
637 Status = ConfigAccess->FormCallbackProtocol->NvWrite (
638 ConfigAccess->FormCallbackProtocol,
639 BufferStorage->Name,
640 &BufferStorage->Guid,
641 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
642 DataSize2,
643 Data,
644 &ResetRequired
645 );
646
647 }
648 }
649
650 Done:
651 if (DataAllocated && (Data != NULL)) {
652 FreePool (Data);
653 }
654
655 return Status;
656 }
657
658 /**
659 Build the FRAMEWORK_EFI_IFR_DATA_ARRAY which will be used to pass to
660 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of FRAMEWORK_EFI_IFR_DATA_ARRAY
661 for details.
662
663 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
664
665 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
666 @param QuestionId The Question ID.
667 @param Type The Question Type.
668 @param Value The Question Value.
669 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
670
671 @return A pointer to FRAMEWORK_EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
672 **/
673 FRAMEWORK_EFI_IFR_DATA_ARRAY *
674 CreateIfrDataArray (
675 IN CONFIG_ACCESS_PRIVATE *ConfigAccess,
676 IN EFI_QUESTION_ID QuestionId,
677 IN UINT8 Type,
678 IN EFI_IFR_TYPE_VALUE *Value,
679 OUT BOOLEAN *NvMapAllocated
680 )
681 {
682 FRAMEWORK_EFI_IFR_DATA_ARRAY *IfrDataArray;
683 FRAMEWORK_EFI_IFR_DATA_ENTRY *IfrDataEntry;
684 UINTN BrowserDataSize;
685 FORMSET_STORAGE *BufferStorage;
686 UINTN Size;
687 EFI_STRING String;
688
689 *NvMapAllocated = FALSE;
690
691 String = NULL;
692
693 switch (Type) {
694 case EFI_IFR_TYPE_NUM_SIZE_8:
695 case EFI_IFR_TYPE_NUM_SIZE_16:
696 case EFI_IFR_TYPE_NUM_SIZE_32:
697 case EFI_IFR_TYPE_NUM_SIZE_64:
698 case EFI_IFR_TYPE_BOOLEAN:
699 Size = sizeof (*Value);
700 break;
701
702 case EFI_IFR_TYPE_STRING:
703 if (Value->string == 0) {
704 Size = 0;
705 } else {
706 String = HiiGetString (ConfigAccess->ThunkContext->UefiHiiHandle, Value->string, NULL);
707 ASSERT (String != NULL);
708
709 Size = StrSize (String);
710 }
711 break;
712
713 default:
714 ASSERT (FALSE);
715 Size = 0;
716 break;
717 }
718
719 IfrDataArray = AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY) + Size);
720 ASSERT (IfrDataArray != NULL);
721
722 BufferStorage = GetStorageFromQuestionId (ConfigAccess->ThunkContext->FormSet, QuestionId);
723
724 if (BufferStorage == NULL) {
725 //
726 // The QuestionId is not associated with a Buffer Storage.
727 // Try to get the first Buffer Storage then.
728 //
729 BufferStorage = GetFirstStorageOfFormSet (ConfigAccess->ThunkContext->FormSet);
730 }
731
732 if (BufferStorage != NULL) {
733 BrowserDataSize = BufferStorage->Size;
734
735 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
736 *NvMapAllocated = TRUE;
737 IfrDataArray->NvRamMap = AllocateZeroPool (BrowserDataSize);
738 } else {
739 *NvMapAllocated = FALSE;
740 IfrDataArray->NvRamMap = ConfigAccess->ThunkContext->NvMapOverride;
741 }
742
743 ASSERT (HiiGetBrowserData (&BufferStorage->Guid, BufferStorage->Name, BrowserDataSize, (UINT8 *) IfrDataArray->NvRamMap));
744 IfrDataEntry = (FRAMEWORK_EFI_IFR_DATA_ENTRY *) (IfrDataArray + 1);
745
746 switch (Type) {
747 case EFI_IFR_TYPE_NUM_SIZE_8:
748 case EFI_IFR_TYPE_NUM_SIZE_16:
749 case EFI_IFR_TYPE_NUM_SIZE_32:
750 case EFI_IFR_TYPE_NUM_SIZE_64:
751 case EFI_IFR_TYPE_BOOLEAN:
752 CopyMem (&IfrDataEntry->Data, &(Value->u8), sizeof (*Value));
753 break;
754
755 case EFI_IFR_TYPE_STRING:
756 if (Size != 0) {
757 ASSERT (String != NULL);
758 StrCpy ((CHAR16 *) &IfrDataEntry->Data, String);
759 FreePool (String);
760 }
761 break;
762 default:
763 ASSERT (FALSE);
764 break;
765 }
766
767 //
768 // Need to fiil in the information for the rest of field for FRAMEWORK_EFI_IFR_DATA_ENTRY.
769 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
770 //
771 //UINT8 OpCode; // Likely a string, numeric, or one-of
772 //UINT8 Length; // Length of the FRAMEWORK_EFI_IFR_DATA_ENTRY packet
773 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
774 //VOID *Data; // The data in the form based on the op-code type - this is not a pointer to the data, the data follows immediately
775 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
776 // If the OpCode is a String type - Data is a CHAR16[x] type
777 // If the OpCode is a Checkbox type - Data is a UINT8 value
778 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
779 }
780
781 return IfrDataArray;
782 }
783
784 /**
785 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
786 needs to be informed when data changed in NvMapOverride. This function will invoke
787 SetBrowserData () to set internal data of Form Browser.
788
789 @param ConfigAccess The Config Access Private Context.
790 @param QuestionId The Question Id that invokes the callback.
791
792
793 **/
794 VOID
795 SyncBrowserDataForNvMapOverride (
796 IN CONST CONFIG_ACCESS_PRIVATE *ConfigAccess,
797 IN EFI_QUESTION_ID QuestionId
798 )
799 {
800 FORMSET_STORAGE *BufferStorage;
801 BOOLEAN CheckFlag;
802 UINTN BrowserDataSize;
803
804 if (ConfigAccess->ThunkContext->NvMapOverride != NULL) {
805
806 BufferStorage = GetStorageFromQuestionId (ConfigAccess->ThunkContext->FormSet, QuestionId);
807
808 if (BufferStorage == NULL) {
809 //
810 // QuestionId is a statement without Storage.
811 // 1) It is a Goto.
812 //
813 //
814 BufferStorage = GetFirstStorageOfFormSet (ConfigAccess->ThunkContext->FormSet);
815 }
816
817 //
818 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
819 //
820 ASSERT (BufferStorage != NULL);
821
822 BrowserDataSize = BufferStorage->Size;
823
824 CheckFlag = HiiSetBrowserData (&BufferStorage->Guid, BufferStorage->Name, BrowserDataSize, ConfigAccess->ThunkContext->NvMapOverride, NULL);
825 ASSERT (CheckFlag);
826 }
827
828 }
829
830 /**
831 Free up resource allocated for a FRAMEWORK_EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
832
833 @param Array The FRAMEWORK_EFI_IFR_DATA_ARRAY allocated.
834 @param NvMapAllocated If the NvRamMap is allocated for FRAMEWORK_EFI_IFR_DATA_ARRAY.
835
836 **/
837 VOID
838 DestroyIfrDataArray (
839 IN FRAMEWORK_EFI_IFR_DATA_ARRAY *Array,
840 IN BOOLEAN NvMapAllocated
841 )
842 {
843 if (Array != NULL) {
844 if (NvMapAllocated) {
845 FreePool (Array->NvRamMap);
846 }
847
848 FreePool (Array);
849 }
850 }
851
852 /**
853 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
854 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
855 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
856 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
857 for detailed information.
858
859 @param ThunkContext The Thunk Context.
860 @param QuestionId The Question Id.
861 @param Type The Question Type.
862 @param Value The One Of Option's value.
863
864 @return The ONE_OF_OPTION_MAP_ENTRY found.
865 @retval NULL If no entry is found.
866 **/
867 ONE_OF_OPTION_MAP_ENTRY *
868 GetOneOfOptionMapEntry (
869 IN HII_THUNK_CONTEXT *ThunkContext,
870 IN EFI_QUESTION_ID QuestionId,
871 IN UINT8 Type,
872 IN EFI_IFR_TYPE_VALUE *Value
873 )
874 {
875 LIST_ENTRY *Link;
876 LIST_ENTRY *Link2;
877 ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;
878 ONE_OF_OPTION_MAP *OneOfOptionMap;
879 FORM_BROWSER_FORMSET *FormSet;
880
881 FormSet = ThunkContext->FormSet;
882
883 Link = GetFirstNode (&FormSet->OneOfOptionMapListHead);
884
885 while (!IsNull (&FormSet->OneOfOptionMapListHead, Link)) {
886 OneOfOptionMap = ONE_OF_OPTION_MAP_FROM_LINK(Link);
887 if (OneOfOptionMap->QuestionId == QuestionId) {
888 ASSERT (OneOfOptionMap->ValueType == Type);
889
890 Link2 = GetFirstNode (&OneOfOptionMap->OneOfOptionMapEntryListHead);
891
892 while (!IsNull (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2)) {
893 OneOfOptionMapEntry = ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2);
894
895 if (CompareMem (Value, &OneOfOptionMapEntry->Value, sizeof (EFI_IFR_TYPE_VALUE)) == 0) {
896 return OneOfOptionMapEntry;
897 }
898
899 Link2 = GetNextNode (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2);
900 }
901 }
902
903 Link = GetNextNode (&FormSet->OneOfOptionMapListHead, Link);
904 }
905
906
907 return NULL;
908 }
909
910 /**
911 Functions which are registered to receive notification of
912 database events have this prototype. The actual event is encoded
913 in NotifyType. The following table describes how PackageType,
914 PackageGuid, Handle, and Package are used for each of the
915 notification types.
916
917 If any Pakcage List in database is updated, mHiiPackageListUpdated
918 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
919 will force the UEFI Setup Browser to save the uncommitted data. This
920 is needed as Framework's Callback function may dynamically update
921 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
922 the Package List's IFR and display it. UEFI Config Access's implementation
923 is required to save the modified (SetBrowserData or directly save the data
924 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
925 we will enforce the rule in ThunkCallback (). The side effect of force saving
926 of NV data is the NV flag in browser may not flag a update as data has already
927 been saved to NV storage.
928
929 @param PackageType Package type of the notification.
930
931 @param PackageGuid If PackageType is
932 EFI_HII_PACKAGE_TYPE_GUID, then this is
933 the pointer to the GUID from the Guid
934 field of EFI_HII_PACKAGE_GUID_HEADER.
935 Otherwise, it must be NULL.
936
937 @param Package Points to the package referred to by the
938 notification Handle The handle of the package
939 list which contains the specified package.
940
941 @param Handle The HII handle.
942
943 @param NotifyType The type of change concerning the
944 database. See
945 EFI_HII_DATABASE_NOTIFY_TYPE.
946
947 **/
948 EFI_STATUS
949 EFIAPI
950 FormUpdateNotify (
951 IN UINT8 PackageType,
952 IN CONST EFI_GUID *PackageGuid,
953 IN CONST EFI_HII_PACKAGE_HEADER *Package,
954 IN EFI_HII_HANDLE Handle,
955 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
956 )
957 {
958 mHiiPackageListUpdated = TRUE;
959
960 return EFI_SUCCESS;
961 }
962
963 /**
964 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
965 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
966
967 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
968 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
969 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
970 type of data to expect. The format of the data tends to vary based on the opcode that
971 generated the callback.
972 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
973 EFI_IFR_ONE_OF_OPTION.
974 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
975 by Type. Type EFI_IFR_TYPE_VALUE is defined in
976 EFI_IFR_ONE_OF_OPTION.
977 @param ActionRequest On return, points to the action requested by the callback function. Type
978 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
979 Browser Protocol.
980
981 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
982 focuse to be INTERRACTIVE.
983 @retval EFI_SUCCESS The callback complete successfully.
984 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
985
986 **/
987 EFI_STATUS
988 EFIAPI
989 ThunkCallback (
990 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
991 IN EFI_BROWSER_ACTION Action,
992 IN EFI_QUESTION_ID QuestionId,
993 IN UINT8 Type,
994 IN EFI_IFR_TYPE_VALUE *Value,
995 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
996 )
997 {
998 EFI_STATUS Status;
999 CONFIG_ACCESS_PRIVATE *ConfigAccess;
1000 EFI_FORM_CALLBACK_PROTOCOL *FormCallbackProtocol;
1001 EFI_HII_CALLBACK_PACKET *Packet;
1002 FRAMEWORK_EFI_IFR_DATA_ARRAY *Data;
1003 FRAMEWORK_EFI_IFR_DATA_ENTRY *DataEntry;
1004 UINT16 KeyValue;
1005 ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;
1006 EFI_HANDLE NotifyHandle;
1007 EFI_INPUT_KEY Key;
1008 BOOLEAN NvMapAllocated;
1009
1010 ASSERT (This != NULL);
1011 ASSERT (Value != NULL);
1012 ASSERT (ActionRequest != NULL);
1013
1014 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1015
1016 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
1017
1018 FormCallbackProtocol = ConfigAccess->FormCallbackProtocol;
1019 if (FormCallbackProtocol == NULL) {
1020 ASSERT (FALSE);
1021 return EFI_UNSUPPORTED;
1022 }
1023
1024 //
1025 // Check if the QuestionId match a OneOfOption.
1026 //
1027 OneOfOptionMapEntry = GetOneOfOptionMapEntry (ConfigAccess->ThunkContext, QuestionId, Type, Value);
1028
1029 if (OneOfOptionMapEntry == NULL) {
1030 //
1031 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1032 //
1033 KeyValue = QuestionId;
1034 } else {
1035 //
1036 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1037 //
1038 KeyValue = OneOfOptionMapEntry->FwKey;
1039 }
1040
1041 //
1042 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
1043 //
1044 Data = CreateIfrDataArray (ConfigAccess, QuestionId, Type, Value, &NvMapAllocated);
1045
1046 Status = mHiiDatabase->RegisterPackageNotify (
1047 mHiiDatabase,
1048 EFI_HII_PACKAGE_FORMS,
1049 NULL,
1050 FormUpdateNotify,
1051 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
1052 &NotifyHandle
1053 );
1054 //
1055 //Call the Framework Callback function.
1056 //
1057 Packet = NULL;
1058 Status = FormCallbackProtocol->Callback (
1059 FormCallbackProtocol,
1060 KeyValue,
1061 Data,
1062 &Packet
1063 );
1064 SyncBrowserDataForNvMapOverride (ConfigAccess, QuestionId);
1065
1066 //
1067 // Callback require browser to perform action
1068 //
1069 if (EFI_ERROR (Status)) {
1070 if (Packet != NULL) {
1071 do {
1072 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, Packet->String, NULL);
1073 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1074 }
1075 //
1076 // Error Code in Status is discarded.
1077 //
1078 } else {
1079 if (Packet != NULL) {
1080 if (Packet->DataArray.EntryCount == 1 && Packet->DataArray.NvRamMap == NULL) {
1081 DataEntry = (FRAMEWORK_EFI_IFR_DATA_ENTRY *) ((UINT8 *) Packet + sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY));
1082 if ((DataEntry->Flags & EXIT_REQUIRED) == EXIT_REQUIRED) {
1083 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
1084 }
1085
1086 if ((DataEntry->Flags & SAVE_REQUIRED) == SAVE_REQUIRED) {
1087 Status = ConfigAccess->ConfigAccessProtocol.RouteConfig (
1088 &ConfigAccess->ConfigAccessProtocol,
1089 NULL,
1090 NULL
1091 );
1092 }
1093 }
1094 FreePool (Packet);
1095 }
1096 }
1097
1098 //
1099 // Unregister notify for Form package update
1100 //
1101 Status = mHiiDatabase->UnregisterPackageNotify (
1102 mHiiDatabase,
1103 NotifyHandle
1104 );
1105 //
1106 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1107 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1108 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1109 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1110 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1111 // the form and load all the variable storages.
1112 //
1113 if (*ActionRequest == EFI_BROWSER_ACTION_REQUEST_NONE && mHiiPackageListUpdated) {
1114 mHiiPackageListUpdated= FALSE;
1115 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
1116 } else {
1117 if (ConfigAccess->ThunkContext->FormSet->SubClass == EFI_FRONT_PAGE_SUBCLASS ||
1118 ConfigAccess->ThunkContext->FormSet->SubClass == EFI_SINGLE_USE_SUBCLASS) {
1119 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
1120 }
1121 }
1122
1123
1124 //
1125 // Clean up.
1126 //
1127 DestroyIfrDataArray (Data, NvMapAllocated);
1128
1129 return Status;
1130 }
1131