]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/ConfigAccess.c
c537a47b1ce9c5c43277a6f9bfcb701191d91b17
[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->ThunkContext->NvMapOverride == NULL) {
455 if (ConfigAccess->FormCallbackProtocol == NULL ||
456 ConfigAccess->FormCallbackProtocol->NvRead == NULL) {
457 Status = GetUefiVariable (
458 BufferStorage,
459 &Data,
460 &DataSize
461 );
462 } else {
463 Status = CallFormCallBack (
464 BufferStorage,
465 ConfigAccess->FormCallbackProtocol,
466 &Data,
467 &DataSize
468 );
469 }
470 } else {
471 DataSize = BufferStorage->Size;
472 Data = AllocateCopyPool (DataSize, ConfigAccess->ThunkContext->NvMapOverride);
473
474 if (Data != NULL) {
475 Status = EFI_SUCCESS;
476 } else {
477 Status = EFI_OUT_OF_RESOURCES;
478 }
479 }
480
481 if (!EFI_ERROR (Status)) {
482 Status = mHiiConfigRoutingProtocol->BlockToConfig (
483 mHiiConfigRoutingProtocol,
484 Request,
485 Data,
486 DataSize,
487 Results,
488 Progress
489 );
490 }
491
492 SafeFreePool (Data);
493 return Status;
494 }
495
496 /**
497
498 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
499 so that data can be written to the data storage such as UEFI Variable or module's
500 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
501
502 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
503 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
504 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
505 failing name / value pair (or the beginning of the string if the failure is in the first
506 name / value pair) or the terminating NULL if all was successful.
507
508 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
509 @retval EFI_SUCCESS The setting is saved successfully.
510 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
511 **/
512 EFI_STATUS
513 EFIAPI
514 ThunkRouteConfig (
515 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
516 IN CONST EFI_STRING Configuration,
517 OUT EFI_STRING *Progress
518 )
519 {
520 EFI_STATUS Status;
521 CONFIG_ACCESS_PRIVATE *ConfigAccess;
522 LIST_ENTRY *Link;
523 BUFFER_STORAGE_ENTRY *BufferStorage;
524 UINT8 *Data;
525 UINTN DataSize;
526 UINTN DataSize2;
527 UINTN LastModifiedByteIndex;
528 BOOLEAN ResetRequired;
529 BOOLEAN DataAllocated;
530
531 Data = NULL;
532 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
533
534 //
535 // For now, only one var varstore is supported so that we don't need to parse the Configuration string.
536 //
537 Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);
538 if (Link == NULL) {
539 ASSERT (FALSE);
540 return EFI_INVALID_PARAMETER;
541 }
542
543 BufferStorage = BUFFER_STORAGE_ENTRY_FROM_LINK (Link);
544 DataSize2 = BufferStorage->Size;
545 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
546 DataAllocated = TRUE;
547 if (ConfigAccess->FormCallbackProtocol == NULL ||
548 ConfigAccess->FormCallbackProtocol->NvRead == NULL) {
549 Status = GetUefiVariable (
550 BufferStorage,
551 &Data,
552 &DataSize
553 );
554 } else {
555 Status = CallFormCallBack (
556 BufferStorage,
557 ConfigAccess->FormCallbackProtocol,
558 &Data,
559 &DataSize
560 );
561 }
562 } else {
563 //
564 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
565 //
566 Status = EFI_SUCCESS;
567 Data = ConfigAccess->ThunkContext->NvMapOverride;
568 DataSize = DataSize2;
569 DataAllocated = FALSE;
570 }
571 if (EFI_ERROR (Status) || (DataSize2 != DataSize)) {
572 if (Data == NULL) {
573 Data = AllocateZeroPool (DataSize2);
574 }
575 }
576
577 Status = mHiiConfigRoutingProtocol->ConfigToBlock (
578 mHiiConfigRoutingProtocol,
579 Configuration,
580 Data,
581 &LastModifiedByteIndex,
582 Progress
583 );
584 if (EFI_ERROR (Status)) {
585 goto Done;
586 }
587
588 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
589 if (ConfigAccess->FormCallbackProtocol == NULL ||
590 ConfigAccess->FormCallbackProtocol->NvWrite == NULL) {
591 Status = gRT->SetVariable (
592 BufferStorage->Name,
593 &BufferStorage->Guid,
594 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
595 DataSize2,
596 Data
597 );
598 } else {
599 Status = ConfigAccess->FormCallbackProtocol->NvWrite (
600 ConfigAccess->FormCallbackProtocol,
601 BufferStorage->Name,
602 &BufferStorage->Guid,
603 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
604 DataSize2,
605 Data,
606 &ResetRequired
607 );
608
609 }
610 }
611
612 Done:
613 if (DataAllocated && (Data != NULL)) {
614 FreePool (Data);
615 }
616
617 return Status;
618 }
619
620 FRAMEWORK_EFI_IFR_DATA_ARRAY *
621 CreateIfrDataArray (
622 IN CONFIG_ACCESS_PRIVATE *ConfigAccess,
623 IN EFI_QUESTION_ID QuestionId,
624 IN UINT8 Type,
625 IN EFI_IFR_TYPE_VALUE *Value,
626 OUT BOOLEAN *NvMapAllocated
627 )
628 {
629 FRAMEWORK_EFI_IFR_DATA_ARRAY *IfrDataArray;
630 FRAMEWORK_EFI_IFR_DATA_ENTRY *IfrDataEntry;
631 UINTN BrowserDataSize;
632 BUFFER_STORAGE_ENTRY *BufferStorageEntry;
633 LIST_ENTRY *Link;
634 EFI_STATUS Status;
635
636 IfrDataArray = AllocateZeroPool (0x100);
637 ASSERT (IfrDataArray != NULL);
638
639 Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);
640 ASSERT (!IsNull (&ConfigAccess->BufferStorageListHead, Link));
641
642 BufferStorageEntry = BUFFER_STORAGE_ENTRY_FROM_LINK(Link);
643 BrowserDataSize = BufferStorageEntry->Size;
644
645 if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {
646 *NvMapAllocated = TRUE;
647 IfrDataArray->NvRamMap = AllocateZeroPool (BrowserDataSize);
648 } else {
649 *NvMapAllocated = FALSE;
650 IfrDataArray->NvRamMap = ConfigAccess->ThunkContext->NvMapOverride;
651 }
652
653 Status = GetBrowserData (NULL, NULL, &BrowserDataSize, IfrDataArray->NvRamMap);
654 ASSERT_EFI_ERROR (Status);
655
656 IfrDataEntry = (FRAMEWORK_EFI_IFR_DATA_ENTRY *) (IfrDataArray + 1);
657
658 switch (Type) {
659 case EFI_IFR_TYPE_NUM_SIZE_8:
660 case EFI_IFR_TYPE_NUM_SIZE_16:
661 case EFI_IFR_TYPE_NUM_SIZE_32:
662 case EFI_IFR_TYPE_NUM_SIZE_64:
663 case EFI_IFR_TYPE_BOOLEAN:
664 CopyMem (&IfrDataEntry->Data, &(Value->u8), sizeof (*Value));
665 break;
666
667 default:
668 ASSERT (FALSE);
669 break;
670 }
671
672 return IfrDataArray;
673 }
674
675 VOID
676 SyncBrowserDataForNvMapOverride (
677 IN CONFIG_ACCESS_PRIVATE *ConfigAccess
678 )
679 {
680 BUFFER_STORAGE_ENTRY *BufferStorageEntry;
681 LIST_ENTRY *Link;
682 EFI_STATUS Status;
683 UINTN BrowserDataSize;
684
685 if (ConfigAccess->ThunkContext->NvMapOverride != NULL) {
686
687 Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);
688 ASSERT (!IsNull (&ConfigAccess->BufferStorageListHead, Link));
689
690 BufferStorageEntry = BUFFER_STORAGE_ENTRY_FROM_LINK(Link);
691 BrowserDataSize = BufferStorageEntry->Size;
692
693 Status = SetBrowserData (NULL, NULL, BrowserDataSize, ConfigAccess->ThunkContext->NvMapOverride, NULL);
694 ASSERT_EFI_ERROR (Status);
695 }
696
697 }
698
699 VOID
700 DestroyIfrDataArray (
701 IN FRAMEWORK_EFI_IFR_DATA_ARRAY *Array,
702 IN BOOLEAN NvMapAllocated
703 )
704 {
705 if (NvMapAllocated) {
706 FreePool (Array->NvRamMap);
707 }
708
709 FreePool (Array);
710 }
711
712
713 ONE_OF_OPTION_MAP_ENTRY *
714 GetOneOfOptionMapEntry (
715 IN HII_THUNK_CONTEXT *ThunkContext,
716 IN EFI_QUESTION_ID QuestionId,
717 IN UINT8 Type,
718 IN EFI_IFR_TYPE_VALUE *Value
719 )
720 {
721 LIST_ENTRY *Link;
722 LIST_ENTRY *Link2;
723 ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;
724 ONE_OF_OPTION_MAP *OneOfOptionMap;
725
726 Link = GetFirstNode (&ThunkContext->OneOfOptionMapListHead);
727
728 while (!IsNull (&ThunkContext->OneOfOptionMapListHead, Link)) {
729 OneOfOptionMap = ONE_OF_OPTION_MAP_FROM_LINK(Link);
730 if (OneOfOptionMap->QuestionId == QuestionId) {
731 ASSERT (OneOfOptionMap->ValueType == Type);
732
733 Link2 = GetFirstNode (&OneOfOptionMap->OneOfOptionMapEntryListHead);
734
735 while (!IsNull (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2)) {
736 OneOfOptionMapEntry = ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2);
737
738 if (CompareMem (Value, &OneOfOptionMapEntry->Value, sizeof (EFI_IFR_TYPE_VALUE)) == 0) {
739 return OneOfOptionMapEntry;
740 }
741
742 Link2 = GetNextNode (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2);
743 }
744 }
745
746 Link = GetNextNode (&ThunkContext->OneOfOptionMapListHead, Link);
747 }
748
749
750 return NULL;
751 }
752
753 /**
754 Functions which are registered to receive notification of
755 database events have this prototype. The actual event is encoded
756 in NotifyType. The following table describes how PackageType,
757 PackageGuid, Handle, and Package are used for each of the
758 notification types.
759
760 @param PackageType Package type of the notification.
761
762 @param PackageGuid If PackageType is
763 EFI_HII_PACKAGE_TYPE_GUID, then this is
764 the pointer to the GUID from the Guid
765 field of EFI_HII_PACKAGE_GUID_HEADER.
766 Otherwise, it must be NULL.
767
768 @param Package Points to the package referred to by the
769 notification Handle The handle of the package
770 list which contains the specified package.
771
772 @param Handle The HII handle.
773
774 @param NotifyType The type of change concerning the
775 database. See
776 EFI_HII_DATABASE_NOTIFY_TYPE.
777
778 **/
779 EFI_STATUS
780 EFIAPI
781 FormUpdateNotify (
782 IN UINT8 PackageType,
783 IN CONST EFI_GUID *PackageGuid,
784 IN CONST EFI_HII_PACKAGE_HEADER *Package,
785 IN EFI_HII_HANDLE Handle,
786 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
787 )
788 {
789 mHiiPackageListUpdated = TRUE;
790
791 return EFI_SUCCESS;
792 }
793
794 /**
795 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
796 the framework HII module willl do no porting (except some porting works needed for callback for EFI_ONE_OF_OPTION opcode)
797 and still work with a UEFI HII SetupBrowser.
798
799 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
800 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
801 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
802 type of data to expect. The format of the data tends to vary based on the opcode that
803 generated the callback.
804 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
805 EFI_IFR_ONE_OF_OPTION.
806 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
807 by Type. Type EFI_IFR_TYPE_VALUE is defined in
808 EFI_IFR_ONE_OF_OPTION.
809 @param ActionRequest On return, points to the action requested by the callback function. Type
810 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
811 Browser Protocol.
812
813 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
814 focuse to be INTERRACTIVE.
815 @retval EFI_SUCCESS The callback complete successfully.
816 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
817
818 **/
819 EFI_STATUS
820 EFIAPI
821 ThunkCallback (
822 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
823 IN EFI_BROWSER_ACTION Action,
824 IN EFI_QUESTION_ID QuestionId,
825 IN UINT8 Type,
826 IN EFI_IFR_TYPE_VALUE *Value,
827 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
828 )
829 {
830 EFI_STATUS Status;
831 CONFIG_ACCESS_PRIVATE *ConfigAccess;
832 EFI_FORM_CALLBACK_PROTOCOL *FormCallbackProtocol;
833 EFI_HII_CALLBACK_PACKET *Packet;
834 FRAMEWORK_EFI_IFR_DATA_ARRAY *Data;
835 FRAMEWORK_EFI_IFR_DATA_ENTRY *DataEntry;
836 UINT16 KeyValue;
837 ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;
838 EFI_HANDLE NotifyHandle;
839 EFI_INPUT_KEY Key;
840 BOOLEAN NvMapAllocated;
841
842 ASSERT (This != NULL);
843 ASSERT (Value != NULL);
844 ASSERT (ActionRequest != NULL);
845
846 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
847
848 ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);
849
850 FormCallbackProtocol = ConfigAccess->FormCallbackProtocol;
851 if (FormCallbackProtocol == NULL) {
852 ASSERT (FALSE);
853 return EFI_UNSUPPORTED;
854 }
855
856 //
857 // Check if the QuestionId match a OneOfOption.
858 //
859 OneOfOptionMapEntry = GetOneOfOptionMapEntry (ConfigAccess->ThunkContext, QuestionId, Type, Value);
860
861 if (OneOfOptionMapEntry == NULL) {
862 //
863 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
864 //
865 KeyValue = QuestionId;
866 } else {
867 KeyValue = OneOfOptionMapEntry->FwKey;
868 }
869
870 //
871 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
872 //
873 Data = CreateIfrDataArray (ConfigAccess, QuestionId, Type, Value, &NvMapAllocated);
874
875 Status = mHiiDatabase->RegisterPackageNotify (
876 mHiiDatabase,
877 EFI_HII_PACKAGE_FORM,
878 NULL,
879 FormUpdateNotify,
880 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
881 &NotifyHandle
882 );
883 //
884 //
885 //
886 Packet = NULL;
887 Status = FormCallbackProtocol->Callback (
888 FormCallbackProtocol,
889 KeyValue,
890 Data,
891 &Packet
892 );
893 SyncBrowserDataForNvMapOverride (ConfigAccess);
894
895 //
896 // Callback require browser to perform action
897 //
898 if (EFI_ERROR (Status)) {
899 if (Packet != NULL) {
900 //
901 // BUGBUG: need to restore the changing question to default value
902 //
903
904 do {
905 IfrLibCreatePopUp (1, &Key, Packet->String);
906
907 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
908
909 }
910
911 //
912 // Error Code in Status is discarded.
913 //
914 } else {
915 if (Packet != NULL) {
916 if (Packet->DataArray.EntryCount == 1 && Packet->DataArray.NvRamMap == NULL) {
917 DataEntry = (FRAMEWORK_EFI_IFR_DATA_ENTRY *) ((UINT8 *) Packet + sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY));
918 if ((DataEntry->Flags & EXIT_REQUIRED) == EXIT_REQUIRED) {
919 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
920 }
921
922 if ((DataEntry->Flags & SAVE_REQUIRED) == SAVE_REQUIRED) {
923 Status = ConfigAccess->ConfigAccessProtocol.RouteConfig (
924 &ConfigAccess->ConfigAccessProtocol,
925 NULL,
926 NULL
927 );
928 }
929 }
930 FreePool (Packet);
931 }
932 }
933
934 //
935 // Unregister notify for Form package update
936 //
937 Status = mHiiDatabase->UnregisterPackageNotify (
938 mHiiDatabase,
939 NotifyHandle
940 );
941 //
942 // UEFI SetupBrowser handles scenario differently with Framework SetupBrowser when call back function
943 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
944 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
945 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
946 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
947 // the form and load all the variable storages.
948 //
949 if (*ActionRequest == EFI_BROWSER_ACTION_REQUEST_NONE && mHiiPackageListUpdated) {
950 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
951 }
952
953 DestroyIfrDataArray (Data, NvMapAllocated);
954
955 return Status;
956 }
957