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