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