]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c
Add missing protocol header files
[mirror_edk2.git] / MdeModulePkg / Application / PlatOverMngr / PlatOverMngr.c
1 /** @file
2
3 A UI application to offer a UI interface in device manager to let user configure
4 platform override protocol to override the default algorithm for matching
5 drivers to controllers.
6
7 The main flow:
8 1. The UI application dynamicly locate all controller device path.
9 2. The UI application dynamicly locate all drivers which support binding protocol.
10 3. The UI application export and dynamicly update two menu to let user select the
11 mapping between drivers to controllers.
12 4. The UI application save all the mapping info in NV variables which will be consumed
13 by platform override protocol driver to publish the platform override protocol.
14
15 Copyright (c) 2007 - 2008, Intel Corporation
16 All rights reserved. This program and the accompanying materials
17 are licensed and made available under the terms and conditions of the BSD License
18 which accompanies this distribution. The full text of the license may be found at
19 http://opensource.org/licenses/bsd-license.php
20
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23
24 **/
25
26 #include <PiDxe.h>
27
28 #include <Protocol/HiiConfigAccess.h>
29 #include <Protocol/HiiConfigRouting.h>
30 #include <Protocol/HiiDatabase.h>
31 #include <Protocol/FormBrowser2.h>
32 #include <Protocol/LoadedImage.h>
33 #include <Protocol/FirmwareVolume2.h>
34 #include <Protocol/PciIo.h>
35 #include <Protocol/BusSpecificDriverOverride.h>
36 #include <Protocol/ComponentName2.h>
37 #include <Protocol/ComponentName.h>
38 #include <Protocol/DriverBinding.h>
39 #include <Protocol/DevicePathToText.h>
40 #include <Protocol/DevicePath.h>
41
42 #include <Guid/GlobalVariable.h>
43
44 #include <Library/BaseLib.h>
45 #include <Library/DebugLib.h>
46 #include <Library/UefiLib.h>
47 #include <Library/UefiApplicationEntryPoint.h>
48 #include <Library/UefiBootServicesTableLib.h>
49 #include <Library/PlatformDriverOverrideLib.h>
50 #include <Library/HiiLib.h>
51 #include <Library/IfrSupportLib.h>
52 #include <Library/ExtendedHiiLib.h>
53 #include <Library/ExtendedIfrSupportLib.h>
54 #include <Library/BaseMemoryLib.h>
55 #include <Library/MemoryAllocationLib.h>
56 #include <Library/UefiRuntimeServicesTableLib.h>
57 #include <Library/DevicePathLib.h>
58 #include "PlatOverMngr.h"
59
60 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
61 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
62
63 typedef struct {
64 UINTN Signature;
65 EFI_HANDLE DriverHandle;
66 EFI_HII_HANDLE RegisteredHandle;
67 PLAT_OVER_MNGR_DATA FakeNvData;
68 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
69 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
70 } EFI_CALLBACK_INFO;
71
72 //
73 // uni string and Vfr Binary data.
74 //
75 extern UINT8 VfrBin[];
76 extern UINT8 PlatOverMngrStrings[];
77
78 //
79 // module global data
80 //
81 EFI_GUID mPlatformOverridesManagerGuid = PLAT_OVER_MNGR_GUID;
82 LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);
83
84 EFI_HANDLE *mDevicePathHandleBuffer;
85 EFI_HANDLE *mDriverImageHandleBuffer;
86
87 INTN mSelectedCtrIndex;
88 EFI_STRING_ID mControllerToken[MAX_CHOICE_NUM];
89 UINTN mDriverImageHandleCount;
90 EFI_STRING_ID mDriverImageToken[MAX_CHOICE_NUM];
91 EFI_STRING_ID mDriverImageFilePathToken[MAX_CHOICE_NUM];
92 EFI_LOADED_IMAGE_PROTOCOL *mDriverImageProtocol[MAX_CHOICE_NUM];
93 EFI_DEVICE_PATH_PROTOCOL *mControllerDevicePathProtocol[MAX_CHOICE_NUM];
94 UINTN mSelectedDriverImageNum;
95 UINTN mLastSavedDriverImageNum;
96 CHAR8 mLanguage[RFC_3066_ENTRY_SIZE];
97 UINT16 mCurrentPage;
98
99 /**
100 Converting a given device to an unicode string.
101
102 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
103 does not installed, then return unknown device path L"?" directly.
104
105 @param DevPath Given device path instance
106
107 @return Converted string from given device path.
108 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
109 **/
110 CHAR16 *
111 DevicePathToStr (
112 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
113 );
114
115 /**
116 Do string convertion for the ComponentName supported language. It do
117 the convertion just for english language code from RFC 3066 to ISO 639-2.
118 Then it will check whether the converted language is in the supported language list.
119 If not supported, NULL is returned.
120 If Language is not english, NULL is returned.
121
122 @param SupportedLanguages Pointer to ComponentName supported language string list. ISO 639-2 language
123 @param Language The language string. RFC 3066 language
124
125 @return English language string (ISO 639-2)
126 @return NULL if the conertion is not successful.
127
128 **/
129 CHAR8 *
130 ConvertComponentNameSupportLanguage (
131 IN CHAR8 *SupportedLanguages,
132 IN CHAR8 *Language
133 )
134 {
135 CHAR8 *LangCode;
136 LangCode = NULL;
137
138 //
139 // Check the input language is English
140 //
141 if (AsciiStrnCmp (Language, "en-", 3) != 0) {
142 return NULL;
143 }
144
145 //
146 // Check SupportedLanguages format
147 //
148 if (AsciiStrStr (SupportedLanguages, "en-") != NULL) {
149 //
150 // Create RFC 3066 language
151 //
152 LangCode = AllocateZeroPool(AsciiStrSize (Language));
153 AsciiStrCpy (LangCode, Language);
154 } else if (AsciiStrStr (SupportedLanguages, "en") != NULL) {
155 //
156 // Create ISO 639-2 Language
157 //
158 LangCode = AllocateZeroPool(4);
159 AsciiStrCpy (LangCode, "eng");
160 }
161
162 return LangCode;
163 }
164
165 /**
166 Get the driver name by ComponentName or ComponentName2 protocol
167 according to the driver binding handle
168
169 @param DriverBindingHandle The Handle of DriverBinding.
170
171 @retval !NULL Pointer into the image name if the image name is found,
172 @retval NULL Pointer to NULL if the image name is not found.
173
174 **/
175 CHAR16 *
176 GetComponentName (
177 IN EFI_HANDLE DriverBindingHandle
178 )
179 {
180 EFI_STATUS Status;
181 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
182 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
183 CHAR8 *SupportedLanguage;
184 CHAR16 *DriverName;
185
186 ComponentName = NULL;
187 ComponentName2 = NULL;
188 Status = gBS->OpenProtocol (
189 DriverBindingHandle,
190 &gEfiComponentName2ProtocolGuid,
191 (VOID **) &ComponentName2,
192 NULL,
193 NULL,
194 EFI_OPEN_PROTOCOL_GET_PROTOCOL
195 );
196 if (EFI_ERROR(Status)) {
197 Status = gBS->OpenProtocol (
198 DriverBindingHandle,
199 &gEfiComponentNameProtocolGuid,
200 (VOID **) &ComponentName,
201 NULL,
202 NULL,
203 EFI_OPEN_PROTOCOL_GET_PROTOCOL
204 );
205 }
206
207 Status = EFI_SUCCESS;
208 DriverName = NULL;
209 if (ComponentName != NULL) {
210 if (ComponentName->GetDriverName != NULL) {
211 SupportedLanguage = ConvertComponentNameSupportLanguage (ComponentName->SupportedLanguages, mLanguage);
212 if (SupportedLanguage != NULL) {
213 Status = ComponentName->GetDriverName (
214 ComponentName,
215 SupportedLanguage,
216 &DriverName
217 );
218 FreePool (SupportedLanguage);
219 }
220 }
221 } else if (ComponentName2 != NULL) {
222 if (ComponentName2->GetDriverName != NULL) {
223 Status = ComponentName2->GetDriverName (
224 ComponentName2,
225 mLanguage,
226 &DriverName
227 );
228 }
229 }
230
231 if (EFI_ERROR (Status)) {
232 return NULL;
233 }
234
235 return DriverName;
236 }
237
238 /**
239 Get the image name from EFI UI section.
240 Get FV protocol by its loaded image protoocl to abastract EFI UI section.
241
242 @param Image Pointer to the loaded image protocol
243
244 @retval !NULL Pointer to the image name if the image name is found,
245 @retval NULL NULL if the image name is not found.
246
247 **/
248 CHAR16 *
249 GetImageName (
250 IN EFI_LOADED_IMAGE_PROTOCOL *Image
251 )
252 {
253 EFI_STATUS Status;
254 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
255 EFI_DEVICE_PATH_PROTOCOL *AlignedDevPathNode;
256 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
257 VOID *Buffer;
258 UINTN BufferSize;
259 UINT32 AuthenticationStatus;
260 EFI_GUID *NameGuid;
261 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv2;
262
263 Fv2 = NULL;
264 Buffer = NULL;
265 BufferSize = 0;
266
267 if (Image->FilePath == NULL) {
268 return NULL;
269 }
270 DevPathNode = Image->FilePath;
271
272 while (!IsDevicePathEnd (DevPathNode)) {
273 //
274 // Make sure device path node is aligned when accessing it's FV Name Guid field.
275 //
276 AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength(DevPathNode), DevPathNode);
277
278 //
279 // Find the Fv File path
280 //
281 NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)AlignedDevPathNode);
282 if (NameGuid != NULL) {
283 FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) AlignedDevPathNode;
284 Status = gBS->HandleProtocol (
285 Image->DeviceHandle,
286 &gEfiFirmwareVolume2ProtocolGuid,
287 (VOID **) &Fv2
288 );
289 //
290 // Locate Image EFI UI section to get the image name.
291 //
292 if (!EFI_ERROR (Status)) {
293 Status = Fv2->ReadSection (
294 Fv2,
295 &FvFilePath->FvFileName,
296 EFI_SECTION_USER_INTERFACE,
297 0,
298 &Buffer,
299 &BufferSize,
300 &AuthenticationStatus
301 );
302 if (!EFI_ERROR (Status)) {
303 FreePool (AlignedDevPathNode);
304 break;
305 }
306 Buffer = NULL;
307 }
308 }
309
310 FreePool (AlignedDevPathNode);
311
312 //
313 // Next device path node
314 //
315 DevPathNode = NextDevicePathNode (DevPathNode);
316 }
317
318 return Buffer;
319 }
320
321 /**
322 Prepare the first page to let user select the device controller which need to
323 add mapping drivers if user select 'Refresh' in first page.
324 During first page, user will see all currnet controller device path in system,
325 select any device path will go to second page to select its overrides drivers.
326
327 @param Private Pointer to EFI_CALLBACK_INFO.
328 @param KeyValue The callback key value of device controller item in first page.
329 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
330
331 @retval EFI_SUCCESS Always returned.
332
333 **/
334 EFI_STATUS
335 UpdateDeviceSelectPage (
336 IN EFI_CALLBACK_INFO *Private,
337 IN UINT16 KeyValue,
338 IN PLAT_OVER_MNGR_DATA *FakeNvData
339 )
340 {
341 EFI_HII_UPDATE_DATA UpdateData;
342 EFI_STATUS Status;
343 UINTN LangSize;
344 UINTN Index;
345 UINTN DevicePathHandleCount;
346 CHAR16 *NewString;
347 EFI_STRING_ID NewStringToken;
348 CHAR16 *ControllerName;
349 EFI_DEVICE_PATH_PROTOCOL *ControllerDevicePath;
350 EFI_PCI_IO_PROTOCOL *PciIo;
351 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;
352 UINTN Len;
353
354 //
355 // set current page form ID.
356 //
357 mCurrentPage = FORM_ID_DEVICE;
358
359 //
360 // Get Platform supported Language (RFC_3066 format)
361 //
362 LangSize = RFC_3066_ENTRY_SIZE;
363 Status = gRT->GetVariable (
364 L"PlatformLang",
365 &gEfiGlobalVariableGuid,
366 NULL,
367 &LangSize,
368 mLanguage
369 );
370 ASSERT_EFI_ERROR (Status);
371
372 //
373 // Initial the mapping database in memory
374 //
375 FreeMappingDatabase (&mMappingDataBase);
376 Status = InitOverridesMapping (&mMappingDataBase);
377
378 //
379 // Clear all the content in the first page
380 //
381 UpdateData.BufferSize = UPDATE_DATA_SIZE;
382 UpdateData.Offset = 0;
383 UpdateData.Data = AllocateZeroPool (UPDATE_DATA_SIZE);
384 ASSERT (UpdateData.Data != NULL);
385 //
386 // Clear first page form
387 //
388 IfrLibUpdateForm (
389 Private->RegisteredHandle,
390 &mPlatformOverridesManagerGuid,
391 FORM_ID_DEVICE,
392 FORM_ID_DEVICE,
393 FALSE,
394 &UpdateData
395 );
396
397 //
398 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
399 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
400 //
401 NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH);
402 HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH), &NewString);
403 ASSERT (NewString != NULL);
404 Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString);
405 ASSERT_EFI_ERROR (Status);
406 FreePool (NewString);
407
408 NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH_HELP);
409 HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH_HELP), &NewString);
410 ASSERT (NewString != NULL);
411 Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString);
412 ASSERT_EFI_ERROR (Status);
413 FreePool (NewString);
414
415 //
416 // created needed controller device item in first page
417 //
418 DevicePathHandleCount = 0;
419 Status = gBS->LocateHandleBuffer (
420 ByProtocol,
421 &gEfiDevicePathProtocolGuid,
422 NULL,
423 &DevicePathHandleCount,
424 &mDevicePathHandleBuffer
425 );
426 if (EFI_ERROR (Status) || (DevicePathHandleCount == 0)) {
427 return EFI_SUCCESS;
428 }
429
430 for (Index = 0; Index < DevicePathHandleCount; Index++) {
431 if (FakeNvData->PciDeviceFilter == 0x01) {
432 //
433 // Only care PCI device which contain efi driver in its option rom.
434 //
435
436 //
437 // Check whether it is a pci device
438 //
439 ControllerDevicePath = NULL;
440 Status = gBS->OpenProtocol (
441 mDevicePathHandleBuffer[Index],
442 &gEfiPciIoProtocolGuid,
443 (VOID **) &PciIo,
444 NULL,
445 NULL,
446 EFI_OPEN_PROTOCOL_GET_PROTOCOL
447 );
448 if (EFI_ERROR (Status)) {
449 continue;
450 }
451 //
452 // Check whether it contain efi driver in its option rom
453 //
454 Status = gBS->HandleProtocol(
455 mDevicePathHandleBuffer[Index],
456 &gEfiBusSpecificDriverOverrideProtocolGuid,
457 (VOID **) &BusSpecificDriverOverride
458 );
459 if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {
460 continue;
461 }
462 }
463
464 ControllerDevicePath = NULL;
465 Status = gBS->OpenProtocol (
466 mDevicePathHandleBuffer[Index],
467 &gEfiDevicePathProtocolGuid,
468 (VOID **) &ControllerDevicePath,
469 NULL,
470 NULL,
471 EFI_OPEN_PROTOCOL_GET_PROTOCOL
472 );
473 ASSERT_EFI_ERROR (Status);
474 //
475 // Save the device path protocol interface
476 //
477 mControllerDevicePathProtocol[Index] = ControllerDevicePath;
478
479 //
480 // Get the driver name
481 //
482 ControllerName = DevicePathToStr (ControllerDevicePath);
483
484 //
485 // Export the driver name string and create item in set options page
486 //
487 Len = StrSize (ControllerName);
488 NewString = AllocateZeroPool (Len + StrSize (L"--"));
489 ASSERT (NewString != NULL);
490 if (EFI_ERROR (CheckMapping (ControllerDevicePath,NULL, &mMappingDataBase, NULL, NULL))) {
491 StrCat (NewString, L"--");
492 } else {
493 StrCat (NewString, L"**");
494 }
495 StrCat (NewString, ControllerName);
496
497 NewStringToken = mControllerToken[Index];
498 if (NewStringToken == 0) {
499 Status = HiiLibNewString (Private->RegisteredHandle, &NewStringToken, NewString);
500 } else {
501 Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString);
502 }
503 ASSERT_EFI_ERROR (Status);
504 FreePool (NewString);
505 //
506 // Save the device path string toke for next access use
507 //
508 mControllerToken[Index] = NewStringToken;
509
510 CreateGotoOpCode (
511 FORM_ID_DRIVER,
512 NewStringToken,
513 STRING_TOKEN (STR_GOTO_HELP_DRIVER),
514 EFI_IFR_FLAG_CALLBACK,
515 (UINT16) (Index + KEY_VALUE_DEVICE_OFFSET),
516 &UpdateData
517 );
518 }
519
520 //
521 // Update first page form
522 //
523 IfrLibUpdateForm (
524 Private->RegisteredHandle,
525 &mPlatformOverridesManagerGuid,
526 FORM_ID_DEVICE,
527 FORM_ID_DEVICE,
528 FALSE,
529 &UpdateData
530 );
531
532 FreePool (UpdateData.Data);
533 return EFI_SUCCESS;
534 }
535
536 /**
537 Get the first Driver Binding handle which has the specific image handle.
538
539 @param ImageHandle The Image handle
540
541 @return Handle to Driver binding
542 @retval NULL The paramter is not valid or the driver binding handle is not found.
543
544 **/
545 EFI_HANDLE
546 GetDriverBindingHandleFromImageHandle (
547 IN EFI_HANDLE ImageHandle
548 )
549 {
550 EFI_STATUS Status;
551 UINTN Index;
552 UINTN DriverBindingHandleCount;
553 EFI_HANDLE *DriverBindingHandleBuffer;
554 EFI_DRIVER_BINDING_PROTOCOL *DriverBindingInterface;
555 EFI_HANDLE DriverBindingHandle;
556
557 DriverBindingHandle = NULL;
558
559 if (ImageHandle == NULL) {
560 return NULL;
561 }
562 //
563 // Get all drivers which support driver binding protocol
564 //
565 DriverBindingHandleCount = 0;
566 Status = gBS->LocateHandleBuffer (
567 ByProtocol,
568 &gEfiDriverBindingProtocolGuid,
569 NULL,
570 &DriverBindingHandleCount,
571 &DriverBindingHandleBuffer
572 );
573 if (EFI_ERROR (Status) || (DriverBindingHandleCount == 0)) {
574 return NULL;
575 }
576
577 //
578 // Get the first Driver Binding handle which has the specific image handle.
579 //
580 for (Index = 0; Index < DriverBindingHandleCount; Index++) {
581 DriverBindingInterface = NULL;
582 Status = gBS->OpenProtocol (
583 DriverBindingHandleBuffer[Index],
584 &gEfiDriverBindingProtocolGuid,
585 (VOID **) &DriverBindingInterface,
586 NULL,
587 NULL,
588 EFI_OPEN_PROTOCOL_GET_PROTOCOL
589 );
590 if (EFI_ERROR (Status)) {
591 continue;
592 }
593
594 if (DriverBindingInterface->ImageHandle == ImageHandle) {
595 DriverBindingHandle = DriverBindingHandleBuffer[Index];
596 break;
597 }
598 }
599
600 FreePool (DriverBindingHandleBuffer);
601 return DriverBindingHandle;
602 }
603
604 /**
605 Prepare to let user select the drivers which need mapping with the device controller
606 selected in first page.
607
608 @param Private Pointer to EFI_CALLBACK_INFO.
609 @param KeyValue The callback key value of device controller item in first page.
610 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
611 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
612
613 @retval EFI_SUCCESS Always returned.
614
615 **/
616 EFI_STATUS
617 UpdateBindingDriverSelectPage (
618 IN EFI_CALLBACK_INFO *Private,
619 IN UINT16 KeyValue,
620 IN PLAT_OVER_MNGR_DATA *FakeNvData
621 )
622 {
623 EFI_HII_UPDATE_DATA UpdateData;
624 EFI_STATUS Status;
625 UINTN Index;
626 CHAR16 *NewString;
627 EFI_STRING_ID NewStringToken;
628 EFI_STRING_ID NewStringHelpToken;
629 UINTN DriverImageHandleCount;
630 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
631 CHAR16 *DriverName;
632 BOOLEAN FreeDriverName;
633 EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
634 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;
635 EFI_HANDLE DriverBindingHandle;
636
637 //
638 // If user select a controller item in the first page the following code will be run.
639 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
640 //
641 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
642 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
643 // then use the Component Name Protocol on the same handle as the first matching Driver Binding Protocol to look up the name of the driver.
644 //
645
646 mCurrentPage = FORM_ID_DRIVER;
647 //
648 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
649 //
650 mSelectedCtrIndex = KeyValue - KEY_VALUE_DEVICE_OFFSET;
651 ASSERT (mSelectedCtrIndex > 0 && mSelectedCtrIndex < MAX_CHOICE_NUM);
652
653 mLastSavedDriverImageNum = 0;
654 //
655 // Clear all the content in dynamic page
656 //
657 UpdateData.BufferSize = UPDATE_DATA_SIZE;
658 UpdateData.Offset = 0;
659 UpdateData.Data = AllocateZeroPool (UPDATE_DATA_SIZE);
660 ASSERT (UpdateData.Data != NULL);
661 //
662 // Clear second page form
663 //
664 IfrLibUpdateForm (
665 Private->RegisteredHandle,
666 &mPlatformOverridesManagerGuid,
667 FORM_ID_DRIVER,
668 FORM_ID_DRIVER,
669 FALSE,
670 &UpdateData
671 );
672
673 //
674 // Show all driver which support loaded image protocol in second page
675 //
676 DriverImageHandleCount = 0;
677 Status = gBS->LocateHandleBuffer (
678 ByProtocol,
679 &gEfiLoadedImageProtocolGuid,
680 NULL,
681 &DriverImageHandleCount,
682 &mDriverImageHandleBuffer
683 );
684 if (EFI_ERROR (Status) || (DriverImageHandleCount == 0)) {
685 return EFI_NOT_FOUND;
686 }
687
688 mDriverImageHandleCount = DriverImageHandleCount;
689 for (Index = 0; Index < DriverImageHandleCount; Index++) {
690 //
691 // Step1: Get the driver image total file path for help string and the driver name.
692 //
693
694 //
695 // Find driver's Loaded Image protocol
696 //
697 LoadedImage =NULL;
698
699 Status = gBS->OpenProtocol (
700 mDriverImageHandleBuffer[Index],
701 &gEfiLoadedImageProtocolGuid,
702 (VOID **) &LoadedImage,
703 NULL,
704 NULL,
705 EFI_OPEN_PROTOCOL_GET_PROTOCOL
706 );
707 if (EFI_ERROR (Status)) {
708 FakeNvData->DriSelection[Index] = 0x00;
709 continue;
710 }
711 mDriverImageProtocol[Index] = LoadedImage;
712 //
713 // Find its related driver binding protocol
714 //
715 DriverBindingHandle = GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer[Index]);
716 if (DriverBindingHandle == NULL) {
717 FakeNvData->DriSelection[Index] = 0x00;
718 continue;
719 }
720
721 //
722 // Get the EFI Loaded Image Device Path Protocol
723 //
724 LoadedImageDevicePath = NULL;
725 Status = gBS->HandleProtocol (
726 mDriverImageHandleBuffer[Index],
727 &gEfiLoadedImageDevicePathProtocolGuid,
728 (VOID **) &LoadedImageDevicePath
729 );
730 if (LoadedImageDevicePath == NULL) {
731 FakeNvData->DriSelection[Index] = 0x00;
732 continue;
733 }
734
735 if (FakeNvData->PciDeviceFilter == 0x01) {
736 //
737 // only care the driver which is in a Pci device option rom,
738 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
739 //
740 if (!EFI_ERROR (Status)) {
741 Status = gBS->HandleProtocol(
742 LoadedImage->DeviceHandle,
743 &gEfiBusSpecificDriverOverrideProtocolGuid,
744 (VOID **) &BusSpecificDriverOverride
745 );
746 if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {
747 FakeNvData->DriSelection[Index] = 0x00;
748 continue;
749 }
750 } else {
751 FakeNvData->DriSelection[Index] = 0x00;
752 continue;
753 }
754 }
755
756 //
757 // For driver name, try to get its component name, if fail, get its image name,
758 // if also fail, give a default name.
759 //
760 FreeDriverName = FALSE;
761 DriverName = GetComponentName (DriverBindingHandle);
762 if (DriverName == NULL) {
763 //
764 // get its image name
765 //
766 DriverName = GetImageName (LoadedImage);
767 }
768 if (DriverName == NULL) {
769 //
770 // give a default name
771 //
772 HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME), &DriverName);
773 ASSERT (DriverName != NULL);
774 FreeDriverName = TRUE; // the DriverName string need to free pool
775 }
776
777
778 //
779 // Step2 Export the driver name string and create check box item in second page
780 //
781
782 //
783 // First create the driver image name
784 //
785 NewString = AllocateZeroPool (StrSize (DriverName));
786 ASSERT (NewString != NULL);
787 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol[mSelectedCtrIndex], LoadedImageDevicePath, &mMappingDataBase, NULL, NULL))) {
788 FakeNvData->DriSelection[Index] = 0x00;
789 } else {
790 FakeNvData->DriSelection[Index] = 0x01;
791 mLastSavedDriverImageNum++;
792 }
793 StrCat (NewString, DriverName);
794 NewStringToken = mDriverImageToken[Index];
795 if (NewStringToken == 0) {
796 Status = HiiLibNewString (Private->RegisteredHandle, &NewStringToken, NewString);
797 } else {
798 Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString);
799 }
800 mDriverImageToken[Index] = NewStringToken;
801 ASSERT_EFI_ERROR (Status);
802 FreePool (NewString);
803 if (FreeDriverName) {
804 FreePool (DriverName);
805 }
806
807 //
808 // Second create the driver image device path as item help string
809 //
810 DriverName = DevicePathToStr (LoadedImageDevicePath);
811
812 NewString = AllocateZeroPool (StrSize (DriverName));
813 ASSERT (NewString != NULL);
814 StrCat (NewString, DriverName);
815 NewStringHelpToken = mDriverImageFilePathToken[Index];
816 if (NewStringHelpToken == 0) {
817 Status = HiiLibNewString (Private->RegisteredHandle, &NewStringHelpToken, NewString);
818 } else {
819 Status = HiiLibSetString (Private->RegisteredHandle, NewStringHelpToken, NewString);
820 }
821 mDriverImageFilePathToken[Index] = NewStringHelpToken;
822 ASSERT_EFI_ERROR (Status);
823 FreePool (NewString);
824 FreePool (DriverName);
825
826 CreateCheckBoxOpCode (
827 (UINT16) (DRIVER_SELECTION_QUESTION_ID + Index),
828 VARSTORE_ID_PLAT_OVER_MNGR,
829 (UINT16) (DRIVER_SELECTION_VAR_OFFSET + Index),
830 NewStringToken,
831 NewStringHelpToken,
832 0,
833 0,
834 &UpdateData
835 );
836 }
837
838 //
839 // Update second page form
840 //
841 IfrLibUpdateForm (
842 Private->RegisteredHandle,
843 &mPlatformOverridesManagerGuid,
844 FORM_ID_DRIVER,
845 FORM_ID_DRIVER,
846 FALSE,
847 &UpdateData
848 );
849
850 FreePool (UpdateData.Data);
851 return EFI_SUCCESS;
852 }
853
854 /**
855 Prepare to let user select the priority order of the drivers which are
856 selected in second page.
857
858 @param Private Pointer to EFI_CALLBACK_INFO.
859 @param KeyValue The callback key value of device controller item in first page.
860 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
861
862 @retval EFI_SUCCESS Always returned.
863
864 **/
865 EFI_STATUS
866 UpdatePrioritySelectPage (
867 IN EFI_CALLBACK_INFO *Private,
868 IN UINT16 KeyValue,
869 IN PLAT_OVER_MNGR_DATA *FakeNvData
870 )
871 {
872 EFI_HII_UPDATE_DATA UpdateData;
873 UINTN Index;
874 EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
875 IFR_OPTION *IfrOptionList;
876 UINTN SelectedDriverImageNum;
877 UINT32 DriverImageNO;
878 UINTN MinNO;
879 UINTN Index1;
880 UINTN TempNO[100];
881
882 //
883 // Following code will be run if user select 'order ... priority' item in second page
884 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
885 //
886 mCurrentPage = FORM_ID_ORDER;
887
888 UpdateData.BufferSize = UPDATE_DATA_SIZE;
889 UpdateData.Offset = 0;
890 UpdateData.Data = AllocateZeroPool (UPDATE_DATA_SIZE);
891 ASSERT (UpdateData.Data != NULL);
892 //
893 // Clear third page form
894 //
895 IfrLibUpdateForm (
896 Private->RegisteredHandle,
897 &mPlatformOverridesManagerGuid,
898 FORM_ID_ORDER,
899 FORM_ID_ORDER,
900 FALSE,
901 &UpdateData
902 );
903
904 //
905 // Check how many drivers have been selected
906 //
907 SelectedDriverImageNum = 0;
908 for (Index = 0; Index < mDriverImageHandleCount; Index++) {
909 if (FakeNvData->DriSelection[Index] != 0) {
910 SelectedDriverImageNum ++;
911 }
912 }
913
914 mSelectedDriverImageNum = SelectedDriverImageNum;
915 if (SelectedDriverImageNum == 0) {
916 return EFI_SUCCESS;
917 }
918
919 IfrOptionList = AllocateZeroPool (sizeof (IFR_OPTION) * mSelectedDriverImageNum);
920 ASSERT (IfrOptionList != NULL);
921 //
922 // Create order list for those selected drivers
923 //
924 SelectedDriverImageNum = 0;
925 for (Index = 0; Index < mDriverImageHandleCount; Index++) {
926 if (FakeNvData->DriSelection[Index] != 0) {
927 IfrOptionList[SelectedDriverImageNum].StringToken = mDriverImageToken[Index];
928 //
929 // Use the NO. in driver binding buffer as value, will use it later
930 //
931 IfrOptionList[SelectedDriverImageNum].Value.u8 = (UINT8) (Index + 1);
932 IfrOptionList[SelectedDriverImageNum].Flags = 0;
933
934 //
935 // Get the EFI Loaded Image Device Path Protocol
936 //
937 LoadedImageDevicePath = NULL;
938 gBS->HandleProtocol (
939 mDriverImageHandleBuffer[Index],
940 &gEfiLoadedImageDevicePathProtocolGuid,
941 (VOID **) &LoadedImageDevicePath
942 );
943 ASSERT (LoadedImageDevicePath != NULL);
944
945 //
946 // Check the driver DriverImage's order number in mapping database
947 //
948 DriverImageNO = 0;
949 CheckMapping (
950 mControllerDevicePathProtocol[mSelectedCtrIndex],
951 LoadedImageDevicePath,
952 &mMappingDataBase,
953 NULL,
954 &DriverImageNO
955 );
956 if (DriverImageNO == 0) {
957 DriverImageNO = (UINT32) mLastSavedDriverImageNum + 1;
958 mLastSavedDriverImageNum++;
959 }
960 TempNO[SelectedDriverImageNum] = DriverImageNO;
961 SelectedDriverImageNum ++;
962 }
963 }
964
965 ASSERT (SelectedDriverImageNum == mSelectedDriverImageNum);
966 //
967 // NvRamMap Must be clear firstly
968 //
969 ZeroMem (FakeNvData->DriOrder, sizeof (FakeNvData->DriOrder));
970
971 //
972 // Order the selected drivers according to the info already in mapping database
973 // the less order number in mapping database the less order number in NvRamMap
974 //
975 for (Index=0; Index < SelectedDriverImageNum; Index++) {
976 //
977 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
978 //
979 MinNO = 0;
980 for (Index1=0; Index1 < SelectedDriverImageNum; Index1++) {
981 if (TempNO[Index1] < TempNO[MinNO]) {
982 MinNO = Index1;
983 }
984 }
985 //
986 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
987 //
988 FakeNvData->DriOrder[Index] =IfrOptionList[MinNO].Value.u8;
989 TempNO[MinNO] = MAX_CHOICE_NUM + 1;
990 }
991
992 CreateOrderedListOpCode (
993 (UINT16) DRIVER_ORDER_QUESTION_ID,
994 VARSTORE_ID_PLAT_OVER_MNGR,
995 (UINT16) DRIVER_ORDER_VAR_OFFSET,
996 mControllerToken[mSelectedCtrIndex],
997 mControllerToken[mSelectedCtrIndex],
998 EFI_IFR_FLAG_RESET_REQUIRED,
999 0,
1000 EFI_IFR_NUMERIC_SIZE_1,
1001 (UINT8) MAX_CHOICE_NUM,
1002 IfrOptionList,
1003 SelectedDriverImageNum,
1004 &UpdateData
1005 );
1006
1007 //
1008 // Update third page form
1009 //
1010 IfrLibUpdateForm (
1011 Private->RegisteredHandle,
1012 &mPlatformOverridesManagerGuid,
1013 FORM_ID_ORDER,
1014 FORM_ID_ORDER,
1015 FALSE,
1016 &UpdateData
1017 );
1018
1019 FreePool (IfrOptionList);
1020 FreePool (UpdateData.Data);
1021 return EFI_SUCCESS;
1022 }
1023
1024 /**
1025 Save the save the mapping database to NV variable.
1026
1027 @param Private Pointer to EFI_CALLBACK_INFO.
1028 @param KeyValue The callback key value of device controller item in first page.
1029 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1030
1031 @retval EFI_SUCCESS Always returned.
1032
1033 **/
1034 EFI_STATUS
1035 CommintChanges (
1036 IN EFI_CALLBACK_INFO *Private,
1037 IN UINT16 KeyValue,
1038 IN PLAT_OVER_MNGR_DATA *FakeNvData
1039 )
1040 {
1041 EFI_STATUS Status;
1042 UINTN Index;
1043 UINTN SelectedDriverImageNum;
1044 EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
1045 //
1046 // Following code will be run if user select 'commint changes' in third page
1047 // user enter 'Commit Changes' to save the mapping database
1048 //
1049 DeleteDriverImage (mControllerDevicePathProtocol[mSelectedCtrIndex], NULL, &mMappingDataBase);
1050 for (SelectedDriverImageNum = 0; SelectedDriverImageNum < mSelectedDriverImageNum; SelectedDriverImageNum++) {
1051 //
1052 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1053 //
1054 Index = FakeNvData->DriOrder[SelectedDriverImageNum] - 1;
1055
1056 //
1057 // Get the EFI Loaded Image Device Path Protocol
1058 //
1059 LoadedImageDevicePath = NULL;
1060 Status = gBS->HandleProtocol (
1061 mDriverImageHandleBuffer[Index],
1062 &gEfiLoadedImageDevicePathProtocolGuid,
1063 (VOID **) &LoadedImageDevicePath
1064 );
1065 ASSERT (LoadedImageDevicePath != NULL);
1066
1067 InsertDriverImage (
1068 mControllerDevicePathProtocol[mSelectedCtrIndex],
1069 LoadedImageDevicePath,
1070 &mMappingDataBase,
1071 (UINT32)SelectedDriverImageNum + 1
1072 );
1073 }
1074 Status = SaveOverridesMapping (&mMappingDataBase);
1075
1076 return Status;
1077 }
1078
1079 /**
1080 This function allows a caller to extract the current configuration for one
1081 or more named elements from the target driver.
1082
1083 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1084 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1085 @param Progress On return, points to a character in the Request string.
1086 Points to the string's null terminator if request was successful.
1087 Points to the most recent '&' before the first failing name/value
1088 pair (or the beginning of the string if the failure is in the
1089 first name/value pair) if the request was not successful.
1090 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1091 has all values filled in for the names in the Request string.
1092 String to be allocated by the called function.
1093
1094 @retval EFI_SUCCESS The Results is filled with the requested values.
1095 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1096 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1097 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1098
1099 **/
1100 EFI_STATUS
1101 EFIAPI
1102 PlatOverMngrExtractConfig (
1103 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1104 IN CONST EFI_STRING Request,
1105 OUT EFI_STRING *Progress,
1106 OUT EFI_STRING *Results
1107 )
1108 {
1109 EFI_STATUS Status;
1110 EFI_CALLBACK_INFO *Private;
1111 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
1112
1113 if (Request == NULL) {
1114 return EFI_NOT_FOUND;
1115 }
1116
1117 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
1118 HiiConfigRouting = Private->HiiConfigRouting;
1119
1120 //
1121 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1122 //
1123 Status = HiiConfigRouting->BlockToConfig (
1124 HiiConfigRouting,
1125 Request,
1126 (UINT8 *) &Private->FakeNvData,
1127 sizeof (PLAT_OVER_MNGR_DATA),
1128 Results,
1129 Progress
1130 );
1131 return Status;
1132 }
1133
1134 /**
1135 This function processes the results of changes in configuration.
1136
1137 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1138 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1139 @param Progress A pointer to a string filled in with the offset of the most
1140 recent '&' before the first failing name/value pair (or the
1141 beginning of the string if the failure is in the first
1142 name/value pair) or the terminating NULL if all was successful.
1143
1144 @retval EFI_SUCCESS The Results is processed successfully.
1145 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1146 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1147
1148 **/
1149 EFI_STATUS
1150 EFIAPI
1151 PlatOverMngrRouteConfig (
1152 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1153 IN CONST EFI_STRING Configuration,
1154 OUT EFI_STRING *Progress
1155 )
1156 {
1157 EFI_CALLBACK_INFO *Private;
1158 EFI_STATUS Status;
1159 UINT16 KeyValue;
1160 UINTN BufferSize;
1161 PLAT_OVER_MNGR_DATA *FakeNvData;
1162
1163 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
1164
1165 FakeNvData = &Private->FakeNvData;
1166 BufferSize = sizeof (PLAT_OVER_MNGR_DATA);
1167 Status = GetBrowserData (NULL, NULL, &BufferSize, (UINT8 *) FakeNvData);
1168 if (EFI_ERROR (Status)) {
1169 return Status;
1170 }
1171
1172 if (mCurrentPage == FORM_ID_DRIVER) {
1173 KeyValue = KEY_VALUE_DRIVER_GOTO_ORDER;
1174 UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);
1175 KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;
1176 CommintChanges (Private, KeyValue, FakeNvData);
1177 //
1178 // Since UpdatePrioritySelectPage will change mCurrentPage,
1179 // should ensure the mCurrentPage still indicate the second page here
1180 //
1181 mCurrentPage = FORM_ID_DRIVER;
1182 }
1183
1184 if (mCurrentPage == FORM_ID_ORDER) {
1185 KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;
1186 CommintChanges (Private, KeyValue, FakeNvData);
1187 }
1188 return EFI_SUCCESS;
1189 }
1190
1191 /**
1192 This is the function that is called to provide results data to the driver. This data
1193 consists of a unique key which is used to identify what data is either being passed back
1194 or being asked for.
1195
1196 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1197 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1198 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1199 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1200 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1201 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1202 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1203 KeyValue == 0x1800 : user select 'commint changes' in third page
1204 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1205 @param Type The type of value for the question.
1206 @param Value A pointer to the data being sent to the original exporting driver.
1207 @param ActionRequest On return, points to the action requested by the callback function.
1208
1209 @retval EFI_SUCCESS Always returned.
1210
1211 **/
1212 EFI_STATUS
1213 EFIAPI
1214 PlatOverMngrCallback (
1215 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1216 IN EFI_BROWSER_ACTION Action,
1217 IN EFI_QUESTION_ID KeyValue,
1218 IN UINT8 Type,
1219 IN EFI_IFR_TYPE_VALUE *Value,
1220 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
1221 )
1222 {
1223 EFI_CALLBACK_INFO *Private;
1224 EFI_STATUS Status;
1225 EFI_STRING_ID NewStringToken;
1226 UINTN BufferSize;
1227 PLAT_OVER_MNGR_DATA *FakeNvData;
1228 EFI_INPUT_KEY Key;
1229
1230 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
1231
1232 FakeNvData = &Private->FakeNvData;
1233 BufferSize = sizeof (PLAT_OVER_MNGR_DATA);
1234 Status = GetBrowserData (NULL, NULL, &BufferSize, (UINT8 *) FakeNvData);
1235 if (EFI_ERROR (Status)) {
1236 return Status;
1237 }
1238
1239 if (KeyValue == KEY_VALUE_DEVICE_REFRESH ||
1240 KeyValue == KEY_VALUE_DEVICE_FILTER ||
1241 KeyValue == KEY_VALUE_DRIVER_GOTO_PREVIOUS
1242 ) {
1243 UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);
1244 //
1245 // Update page title string
1246 //
1247 NewStringToken = STRING_TOKEN (STR_TITLE);
1248 Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path");
1249 ASSERT_EFI_ERROR (Status);
1250 }
1251
1252 if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) {
1253 if (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS) {
1254 KeyValue = (EFI_QUESTION_ID) (mSelectedCtrIndex + KEY_VALUE_DEVICE_OFFSET);
1255 }
1256 UpdateBindingDriverSelectPage (Private, KeyValue, FakeNvData);
1257 //
1258 // Update page title string
1259 //
1260 NewStringToken = STRING_TOKEN (STR_TITLE);
1261 Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"Second, Select drivers for the previous selected controller");
1262 ASSERT_EFI_ERROR (Status);
1263 }
1264
1265 if (KeyValue == KEY_VALUE_DRIVER_GOTO_ORDER) {
1266 UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);
1267 //
1268 // Update page title string
1269 //
1270 NewStringToken = STRING_TOKEN (STR_TITLE);
1271 Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"Finally, Set the priority order for the drivers and save them");
1272 ASSERT_EFI_ERROR (Status);
1273 }
1274
1275 if (KeyValue == KEY_VALUE_ORDER_SAVE_AND_EXIT) {
1276 Status = CommintChanges (Private, KeyValue, FakeNvData);
1277 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
1278 if (EFI_ERROR (Status)) {
1279 IfrLibCreatePopUp (1, &Key, L"Single Override Info too large, Saving Error!");
1280 return EFI_DEVICE_ERROR;
1281 }
1282 }
1283
1284 if (KeyValue == KEY_VALUE_DEVICE_CLEAR) {
1285 //
1286 // Deletes all environment variable(s) that contain the override mappings info
1287 //
1288 FreeMappingDatabase (&mMappingDataBase);
1289 Status = SaveOverridesMapping (&mMappingDataBase);
1290 UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);
1291 }
1292 //
1293 // Pass changed uncommitted data back to Form Browser
1294 //
1295 BufferSize = sizeof (PLAT_OVER_MNGR_DATA);
1296 Status = SetBrowserData (NULL, NULL, BufferSize, (UINT8 *) FakeNvData, NULL);
1297
1298 return EFI_SUCCESS;
1299 }
1300
1301 /**
1302 The driver Entry Point. The funciton will export a disk device class formset and
1303 its callback function to hii database.
1304
1305 @param ImageHandle The firmware allocated handle for the EFI image.
1306 @param SystemTable A pointer to the EFI System Table.
1307
1308 @retval EFI_SUCCESS The entry point is executed successfully.
1309 @retval other Some error occurs when executing this entry point.
1310
1311 **/
1312 EFI_STATUS
1313 EFIAPI
1314 PlatOverMngrInit (
1315 IN EFI_HANDLE ImageHandle,
1316 IN EFI_SYSTEM_TABLE *SystemTable
1317 )
1318 {
1319 EFI_STATUS Status;
1320 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
1321 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
1322 EFI_CALLBACK_INFO *CallbackInfo;
1323 EFI_HANDLE DriverHandle;
1324 EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
1325
1326 //
1327 // There should only be one HII protocol
1328 //
1329 Status = gBS->LocateProtocol (
1330 &gEfiHiiDatabaseProtocolGuid,
1331 NULL,
1332 (VOID **) &HiiDatabase
1333 );
1334 if (EFI_ERROR (Status)) {
1335 return Status;
1336 }
1337
1338 //
1339 // There should only be one Form Configuration protocol
1340 //
1341 Status = gBS->LocateProtocol (
1342 &gEfiFormBrowser2ProtocolGuid,
1343 NULL,
1344 (VOID **) &FormBrowser2
1345 );
1346 if (EFI_ERROR (Status)) {
1347 return Status;
1348 }
1349
1350 CallbackInfo = AllocateZeroPool (sizeof (EFI_CALLBACK_INFO));
1351 if (CallbackInfo == NULL) {
1352 return EFI_BAD_BUFFER_SIZE;
1353 }
1354
1355 CallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;
1356 CallbackInfo->ConfigAccess.ExtractConfig = PlatOverMngrExtractConfig;
1357 CallbackInfo->ConfigAccess.RouteConfig = PlatOverMngrRouteConfig;
1358 CallbackInfo->ConfigAccess.Callback = PlatOverMngrCallback;
1359
1360 //
1361 // Create driver handle used by HII database
1362 //
1363 Status = HiiLibCreateHiiDriverHandle (&DriverHandle);
1364 if (EFI_ERROR (Status)) {
1365 goto Finish;
1366 }
1367 CallbackInfo->DriverHandle = DriverHandle;
1368
1369 //
1370 // Install Config Access protocol to driver handle
1371 //
1372 Status = gBS->InstallProtocolInterface (
1373 &DriverHandle,
1374 &gEfiHiiConfigAccessProtocolGuid,
1375 EFI_NATIVE_INTERFACE,
1376 &CallbackInfo->ConfigAccess
1377 );
1378 if (EFI_ERROR (Status)) {
1379 goto Finish;
1380 }
1381
1382 //
1383 // Publish our HII data
1384 //
1385 PackageList = HiiLibPreparePackageList (
1386 2,
1387 &mPlatformOverridesManagerGuid,
1388 VfrBin,
1389 PlatOverMngrStrings
1390 );
1391 ASSERT (PackageList != NULL);
1392
1393 Status = HiiDatabase->NewPackageList (
1394 HiiDatabase,
1395 PackageList,
1396 DriverHandle,
1397 &CallbackInfo->RegisteredHandle
1398 );
1399 FreePool (PackageList);
1400
1401 if (EFI_ERROR (Status)) {
1402 goto Finish;
1403 }
1404
1405 //
1406 // Locate ConfigRouting protocol
1407 //
1408 Status = gBS->LocateProtocol (
1409 &gEfiHiiConfigRoutingProtocolGuid,
1410 NULL,
1411 (VOID **) &CallbackInfo->HiiConfigRouting
1412 );
1413 if (EFI_ERROR (Status)) {
1414 goto Finish;
1415 }
1416
1417 //
1418 // Clear all the globle variable
1419 //
1420 mDriverImageHandleCount = 0;
1421 mCurrentPage = 0;
1422 ZeroMem (mDriverImageToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));
1423 ZeroMem (mDriverImageFilePathToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));
1424 ZeroMem (mControllerToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));
1425 ZeroMem (mDriverImageProtocol, MAX_CHOICE_NUM * sizeof (EFI_LOADED_IMAGE_PROTOCOL *));
1426
1427 //
1428 // Show the page
1429 //
1430 Status = FormBrowser2->SendForm (
1431 FormBrowser2,
1432 &CallbackInfo->RegisteredHandle,
1433 1,
1434 NULL,
1435 0,
1436 NULL,
1437 NULL
1438 );
1439 if (EFI_ERROR (Status)) {
1440 goto Finish;
1441 }
1442
1443 Status = HiiDatabase->RemovePackageList (HiiDatabase, CallbackInfo->RegisteredHandle);
1444 if (EFI_ERROR (Status)) {
1445 goto Finish;
1446 }
1447
1448 return EFI_SUCCESS;
1449
1450 Finish:
1451 if (CallbackInfo->DriverHandle != NULL) {
1452 HiiLibDestroyHiiDriverHandle (CallbackInfo->DriverHandle);
1453 }
1454 if (CallbackInfo != NULL) {
1455 FreePool (CallbackInfo);
1456 }
1457
1458 return Status;
1459 }
1460
1461 /**
1462 Converting a given device to an unicode string.
1463
1464 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
1465 does not installed, then return unknown device path L"?" directly.
1466
1467 @param DevPath Given device path instance
1468
1469 @return Converted string from given device path.
1470 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
1471 **/
1472 CHAR16 *
1473 DevicePathToStr (
1474 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
1475 )
1476 {
1477 EFI_STATUS Status;
1478 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
1479 CHAR16 *ToText;
1480
1481 if (DevPath == NULL) {
1482 return L"";
1483 }
1484
1485 Status = gBS->LocateProtocol (
1486 &gEfiDevicePathToTextProtocolGuid,
1487 NULL,
1488 (VOID **) &DevPathToText
1489 );
1490 if (!EFI_ERROR (Status)) {
1491 ToText = DevPathToText->ConvertDevicePathToText (
1492 DevPath,
1493 FALSE,
1494 TRUE
1495 );
1496 ASSERT (ToText != NULL);
1497 return ToText;
1498 }
1499
1500 return L"?";
1501 }