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