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