]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/ConfigAccess.c
Bug fixes for FrameworkHiiToUefiHiiThunk;
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / ConfigAccess.c
1 /**@file
2 This file contains functions related to Config Access Protocols installed by
3 by HII Thunk Modules which is used to thunk UEFI Config Access Callback to
4 Framework HII Callback.
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
19 BOOLEAN mHiiPackageListUpdated;
20
21 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate = {
22 CONFIG_ACCESS_PRIVATE_SIGNATURE,
23 {
24 ThunkExtractConfig,
25 ThunkRouteConfig,
26 ThunkCallback
27 }, //ConfigAccessProtocol
28 NULL, //FormCallbackProtocol
29 {NULL, NULL}, //ConfigAccessStorageListHead
30 NULL
31 };
32
33 /**
34 Find and return the pointer to Package Header of the Form package
35 in the Framework Package List. The Framework Package List is created
36 by a module calling the Framework HII interface.
37 The Framwork Package List contains package data
38 generated by Intel's UEFI VFR Compiler and String gather tool. The data format
39 of the package data is defined by TIANO_AUTOGEN_PACKAGES_HEADER.
40
41 If the package list contains other type of packages such as KEYBOARD_LAYOUT,
42 FONTS and IMAGES, the ASSERT. This is to make sure the caller is a
43 Framework Module which does not include packages introduced by UEFI Specification
44 or packages that is not supported by Thunk layer.
45
46 @param Packages The Framework Package List
47
48 @retval EFI_HII_PACKAGE_HEADER* Return the Package Header of Form Package.
49 @retval NULL If no Form Package is found.
50 **/
51 EFI_HII_PACKAGE_HEADER *
52 GetIfrFormSet (
53 IN CONST EFI_HII_PACKAGES *Packages
54 )
55 {
56 TIANO_AUTOGEN_PACKAGES_HEADER **TianoAutogenPackageHdrArray;
57 EFI_HII_PACKAGE_HEADER *IfrPackage;
58 UINTN Index;
59
60 ASSERT (Packages != NULL);
61
62 IfrPackage = NULL;
63
64 TianoAutogenPackageHdrArray = (TIANO_AUTOGEN_PACKAGES_HEADER **) (((UINT8 *) &Packages->GuidId) + sizeof (Packages->GuidId));
65 for (Index = 0; Index < Packages->NumberOfPackages; Index++) {
66 //
67 // BugBug: The current UEFI HII build tool generate a binary in the format defined in:
68 // TIANO_AUTOGEN_PACKAGES_HEADER. We assume that all packages generated in
69 // this binary is with same package type. So the returned IfrPackNum and StringPackNum
70 // may not be the exact number of valid package number in the binary generated
71 // by HII Build tool.
72 //
73 switch (TianoAutogenPackageHdrArray[Index]->PackageHeader.Type) {
74 case EFI_HII_PACKAGE_FORM:
75 return &TianoAutogenPackageHdrArray[Index]->PackageHeader;
76 break;
77
78 case EFI_HII_PACKAGE_STRINGS:
79 case EFI_HII_PACKAGE_SIMPLE_FONTS:
80 break;
81
82 //
83 // The following fonts are invalid for a module that using Framework to UEFI thunk layer.
84 //
85 case EFI_HII_PACKAGE_KEYBOARD_LAYOUT:
86 case EFI_HII_PACKAGE_FONTS:
87 case EFI_HII_PACKAGE_IMAGES:
88 default:
89 ASSERT (FALSE);
90 break;
91 }
92 }
93
94 return (EFI_HII_PACKAGE_HEADER *) NULL;
95 }
96
97 /**
98 This function scan EFI_IFR_VARSTORE_OP in the Form Package.
99 It create entries for these VARSTORE found and append the entry
100 to a Link List.
101
102 If FormSetPackage is not EFI_HII_PACKAGE_FORM, then ASSERT.
103 If there is no linear buffer storage in this formset, then ASSERT.
104
105 @param FormSetPackage The Form Package header.
106 @param BufferStorageListHead The link list for the VARSTORE found in the form package.
107
108 @retval EFI_SUCCESS The function scan the form set and find one or more VARSTOREs.
109 @retval EFI_OUT_OF_RESOURCES There is not enough memory to complete the function.
110 **/
111 EFI_STATUS
112 GetBufferStorage (
113 IN CONST EFI_HII_PACKAGE_HEADER *FormSetPackage,
114 OUT LIST_ENTRY *BufferStorageListHead
115 )
116 {
117 UINTN OpCodeOffset;
118 UINTN OpCodeLength;
119 UINT8 *OpCodeData;
120 UINT8 Operand;
121 EFI_IFR_VARSTORE *VarStoreOpCode;
122 BUFFER_STORAGE_ENTRY *BufferStorage;
123
124 ASSERT (FormSetPackage->Type == EFI_HII_PACKAGE_FORM);
125
126 OpCodeOffset = sizeof (EFI_HII_PACKAGE_HEADER);
127 //
128 // Scan all opcode for the FormSet Package for
129 // EFI_IFR_VARSTORE_OP opcode.
130 //
131 while (OpCodeOffset < FormSetPackage->Length) {
132 OpCodeData = (UINT8 *) FormSetPackage + OpCodeOffset;
133
134 OpCodeLength = ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
135 OpCodeOffset += OpCodeLength;
136 Operand = ((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode;
137
138 if (Operand == EFI_IFR_VARSTORE_OP) {
139 VarStoreOpCode = (EFI_IFR_VARSTORE *)OpCodeData;
140 BufferStorage = AllocateZeroPool (sizeof (*BufferStorage));
141 if (BufferStorage == NULL) {
142 return EFI_OUT_OF_RESOURCES;
143 }
144 //
145 // Record the attributes: GUID, Name, VarStoreId and Size.
146 //
147 CopyMem (&BufferStorage->Guid, &VarStoreOpCode->Guid, sizeof (EFI_GUID));
148
149 BufferStorage->Name = AllocateZeroPool (AsciiStrSize (VarStoreOpCode->Name) * 2);
150 AsciiStrToUnicodeStr (VarStoreOpCode->Name, BufferStorage->Name);
151
152 BufferStorage->VarStoreId = VarStoreOpCode->VarStoreId;
153
154 BufferStorage->Size = VarStoreOpCode->Size;
155 BufferStorage->Signature = BUFFER_STORAGE_ENTRY_SIGNATURE;
156
157 InsertTailList (BufferStorageListHead, &BufferStorage->Link);
158 }
159 }
160
161 return EFI_SUCCESS;
162 }
163
164
165 /**
166 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
167 by a module using Framework HII Protocol Interfaces.
168
169 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
170 that Setup Utility can load the Buffer Storage using this protocol.
171
172 @param Packages The framework package list.
173 @param ThunkContext The Thunk Layer Handle Mapping Database Entry.
174
175 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
176 @retval EFI_OUT_RESOURCE There is not enough memory.
177
178 **/
179 EFI_STATUS
180 InstallDefaultConfigAccessProtocol (
181 IN CONST EFI_HII_PACKAGES *Packages,
182 IN OUT HII_THUNK_CONTEXT *ThunkContext
183 )
184 {
185 EFI_HII_PACKAGE_HEADER *FormSetPackage;
186 EFI_STATUS Status;
187 CONFIG_ACCESS_PRIVATE *ConfigAccessInstance;
188
189 Status = HiiLibCreateHiiDriverHandle (&ThunkContext->UefiHiiDriverHandle);
190 ConfigAccessInstance = AllocateCopyPool (
191 sizeof (CONFIG_ACCESS_PRIVATE),
192 &gConfigAccessPrivateTempate
193 );
194 ASSERT (ConfigAccessInstance != NULL);
195
196 InitializeListHead (&ConfigAccessInstance->BufferStorageListHead);
197
198 //
199 // We assume there is only one formset package in each Forms Package
200 //
201 FormSetPackage = GetIfrFormSet (Packages);
202 ASSERT (FormSetPackage != NULL);
203
204 Status = GetBufferStorage (FormSetPackage, &ConfigAccessInstance->BufferStorageListHead);
205 if (EFI_ERROR (Status)) {
206 FreePool (ConfigAccessInstance);
207 ASSERT (FALSE);
208 return Status;
209 }
210
211 Status = gBS->InstallMultipleProtocolInterfaces (
212 &ThunkContext->UefiHiiDriverHandle,
213 &gEfiHiiConfigAccessProtocolGuid,
214 &ConfigAccessInstance->ConfigAccessProtocol,
215 NULL
216 );
217 //
218 //BUGBUG: Remove when done.
219 //
220 ASSERT_EFI_ERROR (Status);
221
222 if (EFI_ERROR (Status)) {
223 FreePool (ConfigAccessInstance);
224 return Status;
225 }
226
227 ConfigAccessInstance->ThunkContext = ThunkContext;
228
229 return EFI_SUCCESS;
230 }
231
232 VOID
233 DestroyBufferStorageList (
234 IN LIST_ENTRY *ListHead
235 )
236 {
237 LIST_ENTRY *Link;
238 BUFFER_STORAGE_ENTRY *Entry;
239
240 while (!IsListEmpty (ListHead)) {
241 Link = GetFirstNode (ListHead);
242
243 Entry = BUFFER_STORAGE_ENTRY_FROM_LINK(Link);
244
245 FreePool (Entry->Name);
246 Link = RemoveEntryList (Link);
247
248 FreePool (Entry);
249 }
250 }
251
252 VOID
253 UninstallDefaultConfigAccessProtocol (
254 IN HII_THUNK_CONTEXT *ThunkContext
255 )
256 {
257 EFI_STATUS Status;
258 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
259 CONFIG_ACCESS_PRIVATE *ConfigAccessInstance;
260
261 HiiLibDestroyHiiDriverHandle (ThunkContext->UefiHiiDriverHandle);
262
263 Status = gBS->HandleProtocol (
264 ThunkContext->UefiHiiDriverHandle,
265 &gEfiHiiConfigAccessProtocolGuid,
266 (VOID **) &ConfigAccess
267 );
268
269 ASSERT_EFI_ERROR (Status);
270
271 Status = gBS->UninstallProtocolInterface (
272 ThunkContext->UefiHiiDriverHandle,
273 &gEfiHiiConfigAccessProtocolGuid,
274 ConfigAccess
275 );
276 ASSERT_EFI_ERROR (Status);
277
278 ConfigAccessInstance = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (ConfigAccess);
279
280 DestroyBufferStorageList (&ConfigAccessInstance->BufferStorageListHead);
281
282 }
283
284
285 /**
286 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
287
288 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
289 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
290 @param Data The data read.
291 @param DataSize The size of data.
292
293 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
294 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
295 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
296 **/
297 EFI_STATUS
298 CallFormCallBack (
299 IN BUFFER_STORAGE_ENTRY *BufferStorage,
300 IN EFI_FORM_CALLBACK_PROTOCOL *FwFormCallBack,
301 OUT VOID **Data,
302 OUT UINTN *DataSize
303 )
304 {
305 EFI_STATUS Status;
306
307 *DataSize = 0;
308 *Data = NULL;
309
310 Status = FwFormCallBack->NvRead (
311 FwFormCallBack,
312 BufferStorage->Name,
313 &BufferStorage->Guid,
314 NULL,
315 DataSize,
316 *Data
317 );
318 if (Status == EFI_BUFFER_TOO_SMALL) {
319 if (BufferStorage->Size != *DataSize) {
320 ASSERT (FALSE);
321 return EFI_INVALID_PARAMETER;
322 }
323
324 *Data = AllocateZeroPool (*DataSize);
325 if (Data == NULL) {
326 return EFI_OUT_OF_RESOURCES;
327 }
328
329 FwFormCallBack->NvRead (
330 FwFormCallBack,
331 BufferStorage->Name,
332 &BufferStorage->Guid,
333 NULL,
334 DataSize,
335 *Data
336 );
337 }
338
339 return Status;
340 }
341
342
343 /**
344 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
345
346 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
347 @param Data The data read.
348 @param DataSize The size of data.
349
350 If the UEFI Variable Get Service return the size information of the data
351 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
352 then ASSERT.
353
354 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
355 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
356 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
357 **/
358
359 EFI_STATUS
360 GetUefiVariable (
361 IN BUFFER_STORAGE_ENTRY *BufferStorage,
362 OUT VOID **Data,
363 OUT UINTN *DataSize
364 )
365 {
366 EFI_STATUS Status;
367
368 *DataSize = 0;
369 *Data = NULL;
370 Status = gRT->GetVariable (
371 BufferStorage->Name,
372 &BufferStorage->Guid,
373 NULL,
374 DataSize,
375 *Data
376 );
377 if (Status == EFI_BUFFER_TOO_SMALL) {
378
379 if (BufferStorage->Size != *DataSize) {
380 ASSERT (FALSE);
381 return EFI_INVALID_PARAMETER;
382 }
383
384 *Data = AllocateZeroPool (*DataSize);
385 if (Data == NULL) {
386 return EFI_OUT_OF_RESOURCES;
387 }
388
389 Status = gRT->GetVariable (
390 BufferStorage->Name,
391 &BufferStorage->Guid,
392 NULL,
393 DataSize,
394 *Data
395 );
396 }
397
398 return Status;
399 }
400
401 /**
402
403 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
404 so that data can be read from the data storage such as UEFI Variable or module's
405 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
406
407 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
408 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
409 includes the routing information as well as the configurable name / value pairs. It is
410 invalid for this string to be in <MultiConfigRequest> format.
411
412 @param Progress On return, points to a character in the Request string. Points to the string's null
413 terminator if request was successful. Points to the most recent '&' before the first
414 failing name / value pair (or the beginning of the string if the failure is in the first
415 name / value pair) if the request was not successful
416 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
417 values filled in for the names in the Request string. String to be allocated by the called
418 function.
419
420 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
421 @retval EFI_SUCCESS The setting is retrived successfully.
422 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
423 **/
424 EFI_STATUS
425 EFIAPI
426 ThunkExtractConfig (
427 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
428 IN CONST EFI_STRING Request,
429 OUT EFI_STRING *Progress,
430 OUT EFI_STRING *Results
431 )
432 {
433 EFI_STATUS Status;
434 CONFIG_ACCESS_PRIVATE *ConfigAccess;
435 LIST_ENTRY *Link;
436 BUFFER_STORAGE_ENTRY *BufferStorage;
437 VOID *Data;
438 UINTN DataSize;
439
440 Data = NULL;
441 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
442
443 //
444 // For now, only one var varstore is supported so that we don't need to parse the Configuration string.
445 //
446 Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);
447 if (Link == NULL) {
448 ASSERT (FALSE);
449 return EFI_INVALID_PARAMETER;
450 }
451
452 BufferStorage = BUFFER_STORAGE_ENTRY_FROM_LINK (Link);
453
454 if (ConfigAccess->FormCallbackProtocol == NULL ||
455 ConfigAccess->FormCallbackProtocol->NvRead == NULL) {
456 Status = GetUefiVariable (
457 BufferStorage,
458 &Data,
459 &DataSize
460 );
461 } else {
462 Status = CallFormCallBack (
463 BufferStorage,
464 ConfigAccess->FormCallbackProtocol,
465 &Data,
466 &DataSize
467 );
468 }
469
470 if (!EFI_ERROR (Status)) {
471 Status = mHiiConfigRoutingProtocol->BlockToConfig (
472 mHiiConfigRoutingProtocol,
473 Request,
474 Data,
475 DataSize,
476 Results,
477 Progress
478 );
479 }
480
481 SafeFreePool (Data);
482 return Status;
483 }
484
485 /**
486
487 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
488 so that data can be written to the data storage such as UEFI Variable or module's
489 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
490
491 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
492 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
493 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
494 failing name / value pair (or the beginning of the string if the failure is in the first
495 name / value pair) or the terminating NULL if all was successful.
496
497 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
498 @retval EFI_SUCCESS The setting is saved successfully.
499 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
500 **/
501 EFI_STATUS
502 EFIAPI
503 ThunkRouteConfig (
504 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
505 IN CONST EFI_STRING Configuration,
506 OUT EFI_STRING *Progress
507 )
508 {
509 EFI_STATUS Status;
510 CONFIG_ACCESS_PRIVATE *ConfigAccess;
511 LIST_ENTRY *Link;
512 BUFFER_STORAGE_ENTRY *BufferStorage;
513 UINT8 *Data;
514 UINTN DataSize;
515 UINTN DataSize2;
516 UINTN LastModifiedByteIndex;
517 BOOLEAN ResetRequired;
518 BOOLEAN DataAllocated;
519
520 Data = NULL;
521 DataAllocated = TRUE;
522 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
523
524 //
525 // For now, only one var varstore is supported so that we don't need to parse the Configuration string.
526 //
527 Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);
528 if (Link == NULL) {
529 ASSERT (FALSE);
530 return EFI_INVALID_PARAMETER;
531 }
532
533 BufferStorage = BUFFER_STORAGE_ENTRY_FROM_LINK (Link);
534 DataSize2 = BufferStorage->Size;
535 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
536 if (ConfigAccess->FormCallbackProtocol == NULL ||
537 ConfigAccess->FormCallbackProtocol->NvRead == NULL) {
538 Status = GetUefiVariable (
539 BufferStorage,
540 &Data,
541 &DataSize
542 );
543 ASSERT (DataSize == DataSize2);
544
545 } else {
546 Status = CallFormCallBack (
547 BufferStorage,
548 ConfigAccess->FormCallbackProtocol,
549 &Data,
550 &DataSize
551 );
552 ASSERT (DataSize == DataSize2);
553
554 }
555 } else {
556 Status = EFI_SUCCESS;
557 Data = ConfigAccess->ThunkContext->NvMapOverride;
558 DataSize = DataSize2;
559 DataAllocated = FALSE;
560 }
561 if (EFI_ERROR (Status)) {
562 goto Done;
563 }
564
565 Status = mHiiConfigRoutingProtocol->ConfigToBlock (
566 mHiiConfigRoutingProtocol,
567 Configuration,
568 Data,
569 &LastModifiedByteIndex,
570 Progress
571 );
572 if (EFI_ERROR (Status)) {
573 goto Done;
574 }
575
576 if (ConfigAccess->FormCallbackProtocol == NULL ||
577 ConfigAccess->FormCallbackProtocol->NvWrite == NULL) {
578 Status = gRT->SetVariable (
579 BufferStorage->Name,
580 &BufferStorage->Guid,
581 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
582 DataSize,
583 Data
584 );
585 } else {
586 Status = ConfigAccess->FormCallbackProtocol->NvWrite (
587 ConfigAccess->FormCallbackProtocol,
588 BufferStorage->Name,
589 &BufferStorage->Guid,
590 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
591 DataSize,
592 Data,
593 &ResetRequired
594 );
595
596 }
597
598 Done:
599 if (DataAllocated && (Data != NULL)) {
600 FreePool (Data);
601 }
602
603 return Status;
604 }
605
606 FRAMEWORK_EFI_IFR_DATA_ARRAY *
607 CreateIfrDataArray (
608 IN CONFIG_ACCESS_PRIVATE *ConfigAccess,
609 IN EFI_QUESTION_ID QuestionId,
610 IN UINT8 Type,
611 IN EFI_IFR_TYPE_VALUE *Value,
612 OUT BOOLEAN *NvMapAllocated
613 )
614 {
615 FRAMEWORK_EFI_IFR_DATA_ARRAY *IfrDataArray;
616 FRAMEWORK_EFI_IFR_DATA_ENTRY *IfrDataEntry;
617 UINTN BrowserDataSize;
618 BUFFER_STORAGE_ENTRY *BufferStorageEntry;
619 LIST_ENTRY *Link;
620
621 IfrDataArray = AllocateZeroPool (0x100);
622 ASSERT (IfrDataArray != NULL);
623
624 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
625 Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);
626
627 ASSERT (!IsNull (&ConfigAccess->BufferStorageListHead, Link));
628
629 BufferStorageEntry = BUFFER_STORAGE_ENTRY_FROM_LINK(Link);
630
631 BrowserDataSize = BufferStorageEntry->Size;
632 *NvMapAllocated = TRUE;
633 IfrDataArray->NvRamMap = AllocateZeroPool (BrowserDataSize);
634 GetBrowserData (NULL, NULL, &BrowserDataSize, IfrDataArray->NvRamMap);
635 } else {
636 *NvMapAllocated = FALSE;
637 IfrDataArray->NvRamMap = ConfigAccess->ThunkContext->NvMapOverride;
638 }
639
640 IfrDataEntry = (FRAMEWORK_EFI_IFR_DATA_ENTRY *) (IfrDataArray + 1);
641
642 switch (Type) {
643 case EFI_IFR_TYPE_NUM_SIZE_8:
644 case EFI_IFR_TYPE_NUM_SIZE_16:
645 case EFI_IFR_TYPE_NUM_SIZE_32:
646 case EFI_IFR_TYPE_NUM_SIZE_64:
647 case EFI_IFR_TYPE_BOOLEAN:
648 CopyMem (&IfrDataEntry->Data, &(Value->u8), sizeof (*Value));
649 break;
650
651 default:
652 ASSERT (FALSE);
653 break;
654 }
655
656 return IfrDataArray;
657 }
658
659 VOID
660 DestroyIfrDataArray (
661 IN FRAMEWORK_EFI_IFR_DATA_ARRAY *Array,
662 IN BOOLEAN NvMapAllocated
663 )
664 {
665 if (NvMapAllocated) {
666 FreePool (Array->NvRamMap);
667 }
668
669 FreePool (Array);
670 }
671
672
673 ONE_OF_OPTION_MAP_ENTRY *
674 GetOneOfOptionMapEntry (
675 IN HII_THUNK_CONTEXT *ThunkContext,
676 IN EFI_QUESTION_ID QuestionId,
677 IN UINT8 Type,
678 IN EFI_IFR_TYPE_VALUE *Value
679 )
680 {
681 LIST_ENTRY *Link;
682 LIST_ENTRY *Link2;
683 ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;
684 ONE_OF_OPTION_MAP *OneOfOptionMap;
685
686 Link = GetFirstNode (&ThunkContext->OneOfOptionMapListHead);
687
688 while (!IsNull (&ThunkContext->OneOfOptionMapListHead, Link)) {
689 OneOfOptionMap = ONE_OF_OPTION_MAP_FROM_LINK(Link);
690 if (OneOfOptionMap->QuestionId == QuestionId) {
691 ASSERT (OneOfOptionMap->ValueType == Type);
692
693 Link2 = GetFirstNode (&OneOfOptionMap->OneOfOptionMapEntryListHead);
694
695 while (!IsNull (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2)) {
696 OneOfOptionMapEntry = ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2);
697
698 if (CompareMem (Value, &OneOfOptionMapEntry->Value, sizeof (EFI_IFR_TYPE_VALUE)) == 0) {
699 return OneOfOptionMapEntry;
700 }
701
702 Link2 = GetNextNode (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2);
703 }
704 }
705
706 Link = GetNextNode (&ThunkContext->OneOfOptionMapListHead, Link);
707 }
708
709
710 return NULL;
711 }
712
713 /**
714 Functions which are registered to receive notification of
715 database events have this prototype. The actual event is encoded
716 in NotifyType. The following table describes how PackageType,
717 PackageGuid, Handle, and Package are used for each of the
718 notification types.
719
720 @param PackageType Package type of the notification.
721
722 @param PackageGuid If PackageType is
723 EFI_HII_PACKAGE_TYPE_GUID, then this is
724 the pointer to the GUID from the Guid
725 field of EFI_HII_PACKAGE_GUID_HEADER.
726 Otherwise, it must be NULL.
727
728 @param Package Points to the package referred to by the
729 notification Handle The handle of the package
730 list which contains the specified package.
731
732 @param Handle The HII handle.
733
734 @param NotifyType The type of change concerning the
735 database. See
736 EFI_HII_DATABASE_NOTIFY_TYPE.
737
738 **/
739 EFI_STATUS
740 EFIAPI
741 FormUpdateNotify (
742 IN UINT8 PackageType,
743 IN CONST EFI_GUID *PackageGuid,
744 IN CONST EFI_HII_PACKAGE_HEADER *Package,
745 IN EFI_HII_HANDLE Handle,
746 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
747 )
748 {
749 mHiiPackageListUpdated = TRUE;
750
751 return EFI_SUCCESS;
752 }
753
754 /**
755 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
756 the framework HII module willl do no porting (except some porting works needed for callback for EFI_ONE_OF_OPTION opcode)
757 and still work with a UEFI HII SetupBrowser.
758
759 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
760 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
761 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
762 type of data to expect. The format of the data tends to vary based on the opcode that
763 generated the callback.
764 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
765 EFI_IFR_ONE_OF_OPTION.
766 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
767 by Type. Type EFI_IFR_TYPE_VALUE is defined in
768 EFI_IFR_ONE_OF_OPTION.
769 @param ActionRequest On return, points to the action requested by the callback function. Type
770 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
771 Browser Protocol.
772
773 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
774 focuse to be INTERRACTIVE.
775 @retval EFI_SUCCESS The callback complete successfully.
776 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
777
778 **/
779 EFI_STATUS
780 EFIAPI
781 ThunkCallback (
782 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
783 IN EFI_BROWSER_ACTION Action,
784 IN EFI_QUESTION_ID QuestionId,
785 IN UINT8 Type,
786 IN EFI_IFR_TYPE_VALUE *Value,
787 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
788 )
789 {
790 EFI_STATUS Status;
791 CONFIG_ACCESS_PRIVATE *ConfigAccess;
792 EFI_FORM_CALLBACK_PROTOCOL *FormCallbackProtocol;
793 EFI_HII_CALLBACK_PACKET *Packet;
794 FRAMEWORK_EFI_IFR_DATA_ARRAY *Data;
795 FRAMEWORK_EFI_IFR_DATA_ENTRY *DataEntry;
796 UINT16 KeyValue;
797 ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;
798 EFI_HANDLE NotifyHandle;
799 EFI_INPUT_KEY Key;
800 BOOLEAN NvMapAllocated;
801
802 ASSERT (This != NULL);
803 ASSERT (Value != NULL);
804 ASSERT (ActionRequest != NULL);
805
806 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
807
808 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
809
810 FormCallbackProtocol = ConfigAccess->FormCallbackProtocol;
811 if (FormCallbackProtocol == NULL) {
812 ASSERT (FALSE);
813 return EFI_UNSUPPORTED;
814 }
815
816 //
817 // Check if the QuestionId match a OneOfOption.
818 //
819 OneOfOptionMapEntry = GetOneOfOptionMapEntry (ConfigAccess->ThunkContext, QuestionId, Type, Value);
820
821 if (OneOfOptionMapEntry == NULL) {
822 //
823 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
824 //
825 KeyValue = QuestionId;
826 } else {
827 KeyValue = OneOfOptionMapEntry->FwKey;
828 }
829
830 //
831 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
832 //
833 Data = CreateIfrDataArray (ConfigAccess, QuestionId, Type, Value, &NvMapAllocated);
834
835 Status = mHiiDatabase->RegisterPackageNotify (
836 mHiiDatabase,
837 EFI_HII_PACKAGE_FORM,
838 NULL,
839 FormUpdateNotify,
840 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
841 &NotifyHandle
842 );
843 //
844 //
845 //
846 Packet = NULL;
847 Status = FormCallbackProtocol->Callback (
848 FormCallbackProtocol,
849 KeyValue,
850 Data,
851 &Packet
852 );
853
854 //
855 // Callback require browser to perform action
856 //
857 if (EFI_ERROR (Status)) {
858 if (Packet != NULL) {
859 //
860 // BUGBUG: need to restore the changing question to default value
861 //
862
863 do {
864 IfrLibCreatePopUp (1, &Key, Packet->String);
865
866 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
867
868 }
869
870 //
871 // Error Code in Status is discarded.
872 //
873 } else {
874 if (Packet != NULL) {
875 if (Packet->DataArray.EntryCount == 1 && Packet->DataArray.NvRamMap == NULL) {
876 DataEntry = (FRAMEWORK_EFI_IFR_DATA_ENTRY *) ((UINT8 *) Packet + sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY));
877 if ((DataEntry->Flags & EXIT_REQUIRED) == EXIT_REQUIRED) {
878 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
879 }
880
881 if ((DataEntry->Flags & SAVE_REQUIRED) == SAVE_REQUIRED) {
882 Status = ConfigAccess->ConfigAccessProtocol.RouteConfig (
883 &ConfigAccess->ConfigAccessProtocol,
884 NULL,
885 NULL
886 );
887 }
888 }
889 FreePool (Packet);
890 }
891 }
892
893 //
894 // Unregister notify for Form package update
895 //
896 Status = mHiiDatabase->UnregisterPackageNotify (
897 mHiiDatabase,
898 NotifyHandle
899 );
900 //
901 // UEFI SetupBrowser handles scenario differently with Framework SetupBrowser when call back function
902 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
903 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
904 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
905 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
906 // the form and load all the variable storages.
907 //
908 if (*ActionRequest == EFI_BROWSER_ACTION_REQUEST_NONE && mHiiPackageListUpdated) {
909 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
910 }
911
912 DestroyIfrDataArray (Data, NvMapAllocated);
913
914 return Status;
915 }
916