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