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