]>
Commit | Line | Data |
---|---|---|
a6f164a7 | 1 | /** @file\r |
6d8ced29 LG |
2 | This file also installs UEFI PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r |
3 | \r | |
4 | The main code offers a UI interface in device manager to let user configure\r | |
a6f164a7 | 5 | platform override protocol to override the default algorithm for matching\r |
6 | drivers to controllers.\r | |
7 | \r | |
8 | The main flow:\r | |
6d8ced29 LG |
9 | 1. It dynamicly locate all controller device path.\r |
10 | 2. It dynamicly locate all drivers which support binding protocol.\r | |
11 | 3. It export and dynamicly update two menu to let user select the\r | |
a6f164a7 | 12 | mapping between drivers to controllers.\r |
6d8ced29 | 13 | 4. It save all the mapping info in NV variables which will be consumed\r |
a6f164a7 | 14 | by platform override protocol driver to publish the platform override protocol.\r |
15 | \r | |
083f7c69 | 16 | Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 17 | This program and the accompanying materials\r |
e5618791 LG |
18 | are licensed and made available under the terms and conditions of the BSD License\r |
19 | which accompanies this distribution. The full text of the license may be found at\r | |
20 | http://opensource.org/licenses/bsd-license.php\r | |
21 | \r | |
22 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
23 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
24 | \r | |
a6f164a7 | 25 | **/\r |
26 | \r | |
6d8ced29 | 27 | #include "InternalPlatDriOverrideDxe.h"\r |
a6f164a7 | 28 | #include "PlatOverMngr.h"\r |
29 | \r | |
68dbca6c LG |
30 | #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')\r |
31 | #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)\r | |
32 | \r | |
33 | typedef struct {\r | |
34 | UINTN Signature;\r | |
35 | EFI_HANDLE DriverHandle;\r | |
36 | EFI_HII_HANDLE RegisteredHandle;\r | |
37 | PLAT_OVER_MNGR_DATA FakeNvData;\r | |
38 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r | |
39 | EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;\r | |
6d8ced29 | 40 | EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL PlatformDriverOverride;\r |
68dbca6c LG |
41 | } EFI_CALLBACK_INFO;\r |
42 | \r | |
f6f910dd | 43 | #pragma pack(1)\r |
44 | \r | |
45 | ///\r | |
46 | /// HII specific Vendor Device Path definition.\r | |
47 | ///\r | |
48 | typedef struct {\r | |
49 | VENDOR_DEVICE_PATH VendorDevicePath;\r | |
50 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
51 | } HII_VENDOR_DEVICE_PATH;\r | |
52 | \r | |
53 | #pragma pack()\r | |
54 | \r | |
68dbca6c LG |
55 | //\r |
56 | // uni string and Vfr Binary data.\r | |
57 | //\r | |
58 | extern UINT8 VfrBin[];\r | |
6d8ced29 | 59 | extern UINT8 PlatDriOverrideDxeStrings[];\r |
68dbca6c LG |
60 | \r |
61 | //\r | |
62 | // module global data\r | |
63 | //\r | |
7e3bcccb | 64 | CHAR16 mVariableName[] = L"Data";\r |
68dbca6c | 65 | LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);\r |
6d8ced29 LG |
66 | BOOLEAN mEnvironmentVariableRead = FALSE;\r |
67 | EFI_HANDLE mCallerImageHandle = NULL;\r | |
68dbca6c LG |
68 | \r |
69 | EFI_HANDLE *mDevicePathHandleBuffer;\r | |
70 | EFI_HANDLE *mDriverImageHandleBuffer;\r | |
71 | \r | |
db0bd81c | 72 | INTN mSelectedCtrIndex;\r |
68dbca6c | 73 | EFI_STRING_ID mControllerToken[MAX_CHOICE_NUM];\r |
fe1e36e5 | 74 | UINTN mDriverImageHandleCount;\r |
75 | EFI_STRING_ID mDriverImageToken[MAX_CHOICE_NUM];\r | |
76 | EFI_STRING_ID mDriverImageFilePathToken[MAX_CHOICE_NUM];\r | |
77 | EFI_LOADED_IMAGE_PROTOCOL *mDriverImageProtocol[MAX_CHOICE_NUM];\r | |
78 | EFI_DEVICE_PATH_PROTOCOL *mControllerDevicePathProtocol[MAX_CHOICE_NUM];\r | |
79 | UINTN mSelectedDriverImageNum;\r | |
80 | UINTN mLastSavedDriverImageNum;\r | |
fe1e36e5 | 81 | UINT16 mCurrentPage;\r |
7e3bcccb | 82 | EFI_CALLBACK_INFO *mCallbackInfo;\r |
a6f164a7 | 83 | \r |
f6f910dd | 84 | HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = {\r |
85 | {\r | |
86 | {\r | |
87 | HARDWARE_DEVICE_PATH,\r | |
88 | HW_VENDOR_DP,\r | |
89 | {\r | |
90 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
91 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
92 | }\r | |
93 | },\r | |
c8ad2d7a | 94 | PLAT_OVER_MNGR_GUID\r |
f6f910dd | 95 | },\r |
96 | {\r | |
97 | END_DEVICE_PATH_TYPE,\r | |
98 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
99 | { \r | |
100 | (UINT8) (END_DEVICE_PATH_LENGTH),\r | |
101 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r | |
102 | }\r | |
103 | }\r | |
104 | };\r | |
105 | \r | |
87fbccbe | 106 | /**\r |
107 | Converting a given device to an unicode string. \r | |
108 | \r | |
109 | This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol\r | |
110 | does not installed, then return unknown device path L"?" directly.\r | |
111 | \r | |
112 | @param DevPath Given device path instance\r | |
113 | \r | |
114 | @return Converted string from given device path.\r | |
115 | @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.\r | |
116 | **/\r | |
117 | CHAR16 *\r | |
118 | DevicePathToStr (\r | |
119 | IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r | |
6d8ced29 LG |
120 | )\r |
121 | {\r | |
122 | EFI_STATUS Status;\r | |
123 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r | |
124 | CHAR16 *ToText;\r | |
125 | \r | |
126 | if (DevPath == NULL) {\r | |
127 | return L"";\r | |
128 | }\r | |
129 | \r | |
130 | Status = gBS->LocateProtocol (\r | |
131 | &gEfiDevicePathToTextProtocolGuid,\r | |
132 | NULL,\r | |
133 | (VOID **) &DevPathToText\r | |
134 | );\r | |
135 | if (!EFI_ERROR (Status)) {\r | |
136 | ToText = DevPathToText->ConvertDevicePathToText (\r | |
137 | DevPath,\r | |
138 | FALSE,\r | |
139 | TRUE\r | |
140 | );\r | |
141 | ASSERT (ToText != NULL);\r | |
142 | return ToText;\r | |
143 | }\r | |
144 | \r | |
145 | return L"?";\r | |
146 | }\r | |
87fbccbe | 147 | \r |
a6f164a7 | 148 | /**\r |
f6a65182 | 149 | Worker function to get the driver name by ComponentName or ComponentName2 protocol \r |
150 | according to the driver binding handle.\r | |
a6f164a7 | 151 | \r |
f6a65182 | 152 | @param DriverBindingHandle The Handle of DriverBinding.\r |
153 | @param ProtocolGuid The pointer to Component Name (2) protocol GUID.\r | |
154 | @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.\r | |
a6f164a7 | 155 | \r |
f6a65182 | 156 | @retval !NULL Pointer into the image name if the image name is found,\r |
157 | @retval NULL Pointer to NULL if the image name is not found.\r | |
a6f164a7 | 158 | \r |
159 | **/\r | |
f6a65182 | 160 | CHAR16 *\r |
161 | GetComponentNameWorker (\r | |
162 | IN EFI_HANDLE DriverBindingHandle,\r | |
163 | IN EFI_GUID *ProtocolGuid,\r | |
164 | IN CONST CHAR16 *VariableName\r | |
a6f164a7 | 165 | )\r |
166 | {\r | |
f6a65182 | 167 | EFI_STATUS Status;\r |
168 | EFI_COMPONENT_NAME_PROTOCOL *ComponentName;\r | |
169 | CHAR16 *DriverName;\r | |
170 | CHAR8 *Language;\r | |
171 | CHAR8 *BestLanguage;\r | |
a6f164a7 | 172 | \r |
f6a65182 | 173 | Status = gBS->OpenProtocol (\r |
174 | DriverBindingHandle,\r | |
175 | ProtocolGuid,\r | |
176 | (VOID *) &ComponentName,\r | |
177 | NULL,\r | |
178 | NULL,\r | |
179 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
180 | );\r | |
181 | if (EFI_ERROR (Status)) {\r | |
68dbca6c | 182 | return NULL;\r |
a6f164a7 | 183 | }\r |
f6a65182 | 184 | \r |
a6f164a7 | 185 | //\r |
f6a65182 | 186 | // Find the best matching language.\r |
a6f164a7 | 187 | //\r |
f6a65182 | 188 | Language = GetEfiGlobalVariable (VariableName);\r |
189 | BestLanguage = GetBestLanguage (\r | |
190 | ComponentName->SupportedLanguages,\r | |
191 | (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid),\r | |
192 | Language,\r | |
193 | NULL\r | |
194 | );\r | |
195 | \r | |
196 | DriverName = NULL;\r | |
197 | if (BestLanguage != NULL) {\r | |
198 | ComponentName->GetDriverName (\r | |
199 | ComponentName,\r | |
200 | BestLanguage,\r | |
201 | &DriverName\r | |
202 | );\r | |
203 | FreePool (BestLanguage);\r | |
a6f164a7 | 204 | }\r |
f6a65182 | 205 | \r |
206 | if (Language != NULL) {\r | |
207 | FreePool (Language);\r | |
208 | }\r | |
209 | \r | |
210 | return DriverName;\r | |
a6f164a7 | 211 | }\r |
212 | \r | |
f6a65182 | 213 | \r |
a6f164a7 | 214 | /**\r |
68dbca6c LG |
215 | Get the driver name by ComponentName or ComponentName2 protocol \r |
216 | according to the driver binding handle\r | |
a6f164a7 | 217 | \r |
218 | @param DriverBindingHandle The Handle of DriverBinding.\r | |
219 | \r | |
220 | @retval !NULL Pointer into the image name if the image name is found,\r | |
221 | @retval NULL Pointer to NULL if the image name is not found.\r | |
222 | \r | |
223 | **/\r | |
224 | CHAR16 *\r | |
225 | GetComponentName (\r | |
226 | IN EFI_HANDLE DriverBindingHandle\r | |
227 | )\r | |
228 | {\r | |
f6a65182 | 229 | CHAR16 *DriverName;\r |
68dbca6c | 230 | \r |
f6a65182 | 231 | //\r |
232 | // Try RFC 4646 Component Name 2 protocol first.\r | |
233 | //\r | |
234 | DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentName2ProtocolGuid, L"PlatformLang");\r | |
235 | if (DriverName == NULL) {\r | |
236 | //\r | |
237 | // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol. \r | |
238 | //\r | |
239 | DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentNameProtocolGuid, L"Lang");\r | |
a6f164a7 | 240 | }\r |
241 | \r | |
242 | return DriverName;\r | |
243 | }\r | |
244 | \r | |
245 | /**\r | |
68dbca6c | 246 | Get the image name from EFI UI section.\r |
f6a65182 | 247 | Get FV protocol by its loaded image protocol to abstract EFI UI section.\r |
a6f164a7 | 248 | \r |
68dbca6c | 249 | @param Image Pointer to the loaded image protocol\r |
a6f164a7 | 250 | \r |
68dbca6c LG |
251 | @retval !NULL Pointer to the image name if the image name is found,\r |
252 | @retval NULL NULL if the image name is not found.\r | |
a6f164a7 | 253 | \r |
254 | **/\r | |
255 | CHAR16 *\r | |
256 | GetImageName (\r | |
cebc8d48 | 257 | IN EFI_LOADED_IMAGE_PROTOCOL *Image\r |
a6f164a7 | 258 | )\r |
259 | {\r | |
260 | EFI_STATUS Status;\r | |
a6f164a7 | 261 | EFI_DEVICE_PATH_PROTOCOL *DevPathNode;\r |
1232b214 | 262 | EFI_DEVICE_PATH_PROTOCOL *AlignedDevPathNode;\r |
a6f164a7 | 263 | MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;\r |
264 | VOID *Buffer;\r | |
265 | UINTN BufferSize;\r | |
266 | UINT32 AuthenticationStatus;\r | |
267 | EFI_GUID *NameGuid;\r | |
cebc8d48 | 268 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv2;\r |
a6f164a7 | 269 | \r |
cebc8d48 | 270 | Fv2 = NULL;\r |
a6f164a7 | 271 | Buffer = NULL;\r |
272 | BufferSize = 0;\r | |
273 | \r | |
274 | if (Image->FilePath == NULL) {\r | |
275 | return NULL;\r | |
276 | }\r | |
1232b214 | 277 | DevPathNode = Image->FilePath;\r |
a6f164a7 | 278 | \r |
a6f164a7 | 279 | while (!IsDevicePathEnd (DevPathNode)) {\r |
1232b214 | 280 | //\r |
281 | // Make sure device path node is aligned when accessing it's FV Name Guid field.\r | |
282 | //\r | |
283 | AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength(DevPathNode), DevPathNode);\r | |
284 | \r | |
a6f164a7 | 285 | //\r |
286 | // Find the Fv File path\r | |
287 | //\r | |
1232b214 | 288 | NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)AlignedDevPathNode);\r |
a6f164a7 | 289 | if (NameGuid != NULL) {\r |
1232b214 | 290 | FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) AlignedDevPathNode;\r |
a6f164a7 | 291 | Status = gBS->HandleProtocol (\r |
292 | Image->DeviceHandle,\r | |
293 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
cebc8d48 | 294 | (VOID **) &Fv2\r |
a6f164a7 | 295 | );\r |
68dbca6c LG |
296 | //\r |
297 | // Locate Image EFI UI section to get the image name.\r | |
298 | //\r | |
a6f164a7 | 299 | if (!EFI_ERROR (Status)) {\r |
cebc8d48 LG |
300 | Status = Fv2->ReadSection (\r |
301 | Fv2,\r | |
a6f164a7 | 302 | &FvFilePath->FvFileName,\r |
303 | EFI_SECTION_USER_INTERFACE,\r | |
304 | 0,\r | |
305 | &Buffer,\r | |
306 | &BufferSize,\r | |
307 | &AuthenticationStatus\r | |
308 | );\r | |
309 | if (!EFI_ERROR (Status)) {\r | |
1232b214 | 310 | FreePool (AlignedDevPathNode);\r |
a6f164a7 | 311 | break;\r |
312 | }\r | |
313 | Buffer = NULL;\r | |
314 | }\r | |
315 | }\r | |
1232b214 | 316 | \r |
317 | FreePool (AlignedDevPathNode);\r | |
318 | \r | |
a6f164a7 | 319 | //\r |
320 | // Next device path node\r | |
321 | //\r | |
322 | DevPathNode = NextDevicePathNode (DevPathNode);\r | |
323 | }\r | |
324 | \r | |
a6f164a7 | 325 | return Buffer;\r |
326 | }\r | |
327 | \r | |
328 | /**\r | |
329 | Prepare the first page to let user select the device controller which need to\r | |
68dbca6c LG |
330 | add mapping drivers if user select 'Refresh' in first page.\r |
331 | During first page, user will see all currnet controller device path in system,\r | |
332 | select any device path will go to second page to select its overrides drivers.\r | |
a6f164a7 | 333 | \r |
334 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
335 | @param KeyValue The callback key value of device controller item in first page.\r | |
336 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r | |
337 | \r | |
338 | @retval EFI_SUCCESS Always returned.\r | |
339 | \r | |
340 | **/\r | |
341 | EFI_STATUS\r | |
342 | UpdateDeviceSelectPage (\r | |
343 | IN EFI_CALLBACK_INFO *Private,\r | |
344 | IN UINT16 KeyValue,\r | |
345 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
346 | )\r | |
347 | {\r | |
a6f164a7 | 348 | EFI_STATUS Status;\r |
a6f164a7 | 349 | UINTN Index;\r |
350 | UINTN DevicePathHandleCount;\r | |
351 | CHAR16 *NewString;\r | |
352 | EFI_STRING_ID NewStringToken;\r | |
353 | CHAR16 *ControllerName;\r | |
354 | EFI_DEVICE_PATH_PROTOCOL *ControllerDevicePath;\r | |
355 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
356 | EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;\r | |
357 | UINTN Len;\r | |
7e3bcccb LG |
358 | VOID *StartOpCodeHandle;\r |
359 | VOID *EndOpCodeHandle;\r | |
360 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
361 | EFI_IFR_GUID_LABEL *EndLabel; \r | |
362 | \r | |
a6f164a7 | 363 | //\r |
7e3bcccb | 364 | // Set current page form ID.\r |
68dbca6c LG |
365 | //\r |
366 | mCurrentPage = FORM_ID_DEVICE; \r | |
367 | \r | |
a6f164a7 | 368 | //\r |
369 | // Initial the mapping database in memory\r | |
370 | //\r | |
371 | FreeMappingDatabase (&mMappingDataBase);\r | |
7e3bcccb LG |
372 | InitOverridesMapping (&mMappingDataBase);\r |
373 | \r | |
374 | //\r | |
375 | // Init OpCode Handle\r | |
376 | //\r | |
377 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
378 | ASSERT (StartOpCodeHandle != NULL);\r | |
a6f164a7 | 379 | \r |
7e3bcccb LG |
380 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r |
381 | ASSERT (EndOpCodeHandle != NULL);\r | |
382 | \r | |
383 | //\r | |
384 | // Create Hii Extend Label OpCode as the start opcode\r | |
a6f164a7 | 385 | //\r |
7e3bcccb LG |
386 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r |
387 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
388 | StartLabel->Number = FORM_ID_DEVICE;\r | |
389 | \r | |
a6f164a7 | 390 | //\r |
7e3bcccb LG |
391 | // Create Hii Extend Label OpCode as the end opcode\r |
392 | //\r | |
393 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
394 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
395 | EndLabel->Number = LABEL_END;\r | |
396 | \r | |
a6f164a7 | 397 | //\r |
398 | // Clear first page form\r | |
399 | //\r | |
7e3bcccb | 400 | HiiUpdateForm (\r |
a6f164a7 | 401 | Private->RegisteredHandle,\r |
c8ad2d7a | 402 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 403 | FORM_ID_DEVICE,\r |
7e3bcccb LG |
404 | StartOpCodeHandle, // Label FORM_ID_DEVICE\r |
405 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 406 | );\r |
407 | \r | |
408 | //\r | |
409 | // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,\r | |
68dbca6c | 410 | // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement\r |
a6f164a7 | 411 | //\r |
412 | NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH);\r | |
cb7d01c0 | 413 | NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH), NULL);\r |
a6f164a7 | 414 | ASSERT (NewString != NULL);\r |
cb7d01c0 | 415 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) {\r |
416 | ASSERT (FALSE);\r | |
417 | }\r | |
68dbca6c | 418 | FreePool (NewString);\r |
a6f164a7 | 419 | \r |
420 | NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH_HELP);\r | |
cb7d01c0 | 421 | NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH_HELP), NULL);\r |
a6f164a7 | 422 | ASSERT (NewString != NULL);\r |
cb7d01c0 | 423 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) {\r |
424 | ASSERT (FALSE);\r | |
425 | }\r | |
68dbca6c LG |
426 | FreePool (NewString);\r |
427 | \r | |
a6f164a7 | 428 | //\r |
429 | // created needed controller device item in first page\r | |
430 | //\r | |
431 | DevicePathHandleCount = 0;\r | |
432 | Status = gBS->LocateHandleBuffer (\r | |
433 | ByProtocol,\r | |
434 | &gEfiDevicePathProtocolGuid,\r | |
435 | NULL,\r | |
436 | &DevicePathHandleCount,\r | |
437 | &mDevicePathHandleBuffer\r | |
438 | );\r | |
439 | if (EFI_ERROR (Status) || (DevicePathHandleCount == 0)) {\r | |
440 | return EFI_SUCCESS;\r | |
441 | }\r | |
442 | \r | |
443 | for (Index = 0; Index < DevicePathHandleCount; Index++) {\r | |
444 | if (FakeNvData->PciDeviceFilter == 0x01) {\r | |
445 | //\r | |
446 | // Only care PCI device which contain efi driver in its option rom.\r | |
447 | //\r | |
448 | \r | |
449 | //\r | |
450 | // Check whether it is a pci device\r | |
451 | //\r | |
452 | ControllerDevicePath = NULL;\r | |
453 | Status = gBS->OpenProtocol (\r | |
454 | mDevicePathHandleBuffer[Index],\r | |
455 | &gEfiPciIoProtocolGuid,\r | |
456 | (VOID **) &PciIo,\r | |
457 | NULL,\r | |
458 | NULL,\r | |
459 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
460 | );\r | |
461 | if (EFI_ERROR (Status)) {\r | |
462 | continue;\r | |
463 | }\r | |
464 | //\r | |
465 | // Check whether it contain efi driver in its option rom\r | |
466 | //\r | |
467 | Status = gBS->HandleProtocol(\r | |
468 | mDevicePathHandleBuffer[Index],\r | |
469 | &gEfiBusSpecificDriverOverrideProtocolGuid,\r | |
470 | (VOID **) &BusSpecificDriverOverride\r | |
471 | );\r | |
472 | if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {\r | |
473 | continue;\r | |
474 | }\r | |
475 | }\r | |
476 | \r | |
477 | ControllerDevicePath = NULL;\r | |
478 | Status = gBS->OpenProtocol (\r | |
479 | mDevicePathHandleBuffer[Index],\r | |
480 | &gEfiDevicePathProtocolGuid,\r | |
481 | (VOID **) &ControllerDevicePath,\r | |
482 | NULL,\r | |
483 | NULL,\r | |
484 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
485 | );\r | |
486 | ASSERT_EFI_ERROR (Status);\r | |
487 | //\r | |
488 | // Save the device path protocol interface\r | |
489 | //\r | |
490 | mControllerDevicePathProtocol[Index] = ControllerDevicePath;\r | |
491 | \r | |
492 | //\r | |
493 | // Get the driver name\r | |
494 | //\r | |
495 | ControllerName = DevicePathToStr (ControllerDevicePath);\r | |
496 | \r | |
497 | //\r | |
498 | // Export the driver name string and create item in set options page\r | |
499 | //\r | |
500 | Len = StrSize (ControllerName);\r | |
501 | NewString = AllocateZeroPool (Len + StrSize (L"--"));\r | |
77980854 | 502 | ASSERT (NewString != NULL);\r |
a6f164a7 | 503 | if (EFI_ERROR (CheckMapping (ControllerDevicePath,NULL, &mMappingDataBase, NULL, NULL))) {\r |
504 | StrCat (NewString, L"--");\r | |
505 | } else {\r | |
506 | StrCat (NewString, L"**");\r | |
507 | }\r | |
508 | StrCat (NewString, ControllerName);\r | |
509 | \r | |
cb7d01c0 | 510 | NewStringToken = HiiSetString (Private->RegisteredHandle, mControllerToken[Index], NewString, NULL);\r |
511 | ASSERT (NewStringToken != 0);\r | |
68dbca6c | 512 | FreePool (NewString);\r |
a6f164a7 | 513 | //\r |
514 | // Save the device path string toke for next access use\r | |
515 | //\r | |
516 | mControllerToken[Index] = NewStringToken;\r | |
7e3bcccb LG |
517 | \r |
518 | HiiCreateGotoOpCode (\r | |
519 | StartOpCodeHandle,\r | |
a6f164a7 | 520 | FORM_ID_DRIVER,\r |
521 | NewStringToken,\r | |
522 | STRING_TOKEN (STR_GOTO_HELP_DRIVER),\r | |
523 | EFI_IFR_FLAG_CALLBACK,\r | |
7e3bcccb | 524 | (UINT16) (Index + KEY_VALUE_DEVICE_OFFSET)\r |
a6f164a7 | 525 | );\r |
526 | }\r | |
527 | \r | |
528 | //\r | |
529 | // Update first page form\r | |
530 | //\r | |
7e3bcccb | 531 | HiiUpdateForm (\r |
a6f164a7 | 532 | Private->RegisteredHandle,\r |
c8ad2d7a | 533 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 534 | FORM_ID_DEVICE,\r |
7e3bcccb LG |
535 | StartOpCodeHandle, // Label FORM_ID_DEVICE\r |
536 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 537 | );\r |
538 | \r | |
7e3bcccb LG |
539 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r |
540 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
541 | \r | |
a6f164a7 | 542 | return EFI_SUCCESS;\r |
543 | }\r | |
544 | \r | |
68dbca6c LG |
545 | /**\r |
546 | Get the first Driver Binding handle which has the specific image handle.\r | |
547 | \r | |
548 | @param ImageHandle The Image handle\r | |
549 | \r | |
550 | @return Handle to Driver binding\r | |
551 | @retval NULL The paramter is not valid or the driver binding handle is not found.\r | |
552 | \r | |
553 | **/\r | |
554 | EFI_HANDLE\r | |
555 | GetDriverBindingHandleFromImageHandle (\r | |
556 | IN EFI_HANDLE ImageHandle\r | |
557 | )\r | |
558 | {\r | |
559 | EFI_STATUS Status;\r | |
560 | UINTN Index;\r | |
561 | UINTN DriverBindingHandleCount;\r | |
562 | EFI_HANDLE *DriverBindingHandleBuffer;\r | |
563 | EFI_DRIVER_BINDING_PROTOCOL *DriverBindingInterface;\r | |
564 | EFI_HANDLE DriverBindingHandle;\r | |
565 | \r | |
566 | DriverBindingHandle = NULL;\r | |
567 | \r | |
568 | if (ImageHandle == NULL) {\r | |
569 | return NULL;\r | |
570 | }\r | |
571 | //\r | |
572 | // Get all drivers which support driver binding protocol\r | |
573 | //\r | |
574 | DriverBindingHandleCount = 0;\r | |
575 | Status = gBS->LocateHandleBuffer (\r | |
576 | ByProtocol,\r | |
577 | &gEfiDriverBindingProtocolGuid,\r | |
578 | NULL,\r | |
579 | &DriverBindingHandleCount,\r | |
580 | &DriverBindingHandleBuffer\r | |
581 | );\r | |
582 | if (EFI_ERROR (Status) || (DriverBindingHandleCount == 0)) {\r | |
583 | return NULL;\r | |
584 | }\r | |
e5618791 LG |
585 | \r |
586 | //\r | |
587 | // Get the first Driver Binding handle which has the specific image handle.\r | |
588 | //\r | |
68dbca6c LG |
589 | for (Index = 0; Index < DriverBindingHandleCount; Index++) {\r |
590 | DriverBindingInterface = NULL;\r | |
591 | Status = gBS->OpenProtocol (\r | |
592 | DriverBindingHandleBuffer[Index],\r | |
593 | &gEfiDriverBindingProtocolGuid,\r | |
594 | (VOID **) &DriverBindingInterface,\r | |
595 | NULL,\r | |
596 | NULL,\r | |
597 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
598 | );\r | |
599 | if (EFI_ERROR (Status)) {\r | |
600 | continue;\r | |
601 | }\r | |
602 | \r | |
603 | if (DriverBindingInterface->ImageHandle == ImageHandle) {\r | |
604 | DriverBindingHandle = DriverBindingHandleBuffer[Index];\r | |
605 | break;\r | |
606 | }\r | |
607 | }\r | |
608 | \r | |
68dbca6c LG |
609 | FreePool (DriverBindingHandleBuffer);\r |
610 | return DriverBindingHandle;\r | |
611 | }\r | |
612 | \r | |
a6f164a7 | 613 | /**\r |
614 | Prepare to let user select the drivers which need mapping with the device controller\r | |
615 | selected in first page.\r | |
616 | \r | |
617 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
618 | @param KeyValue The callback key value of device controller item in first page.\r | |
9872985b | 619 | KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.\r |
a6f164a7 | 620 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r |
621 | \r | |
622 | @retval EFI_SUCCESS Always returned.\r | |
623 | \r | |
624 | **/\r | |
625 | EFI_STATUS\r | |
626 | UpdateBindingDriverSelectPage (\r | |
627 | IN EFI_CALLBACK_INFO *Private,\r | |
628 | IN UINT16 KeyValue,\r | |
629 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
630 | )\r | |
631 | {\r | |
a6f164a7 | 632 | EFI_STATUS Status;\r |
633 | UINTN Index;\r | |
a6f164a7 | 634 | CHAR16 *NewString;\r |
635 | EFI_STRING_ID NewStringToken;\r | |
636 | EFI_STRING_ID NewStringHelpToken;\r | |
637 | UINTN DriverImageHandleCount;\r | |
a6f164a7 | 638 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r |
639 | CHAR16 *DriverName;\r | |
640 | BOOLEAN FreeDriverName;\r | |
a6f164a7 | 641 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;\r |
642 | EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;\r | |
643 | EFI_HANDLE DriverBindingHandle;\r | |
7e3bcccb LG |
644 | VOID *StartOpCodeHandle;\r |
645 | VOID *EndOpCodeHandle;\r | |
646 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
647 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
68dbca6c | 648 | \r |
a6f164a7 | 649 | //\r |
650 | // If user select a controller item in the first page the following code will be run.\r | |
651 | // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown\r | |
652 | //\r | |
653 | //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols\r | |
654 | // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.\r | |
655 | // 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.\r | |
656 | //\r | |
657 | \r | |
658 | mCurrentPage = FORM_ID_DRIVER;\r | |
659 | //\r | |
660 | // Switch the item callback key value to its NO. in mDevicePathHandleBuffer\r | |
661 | //\r | |
68dbca6c | 662 | mSelectedCtrIndex = KeyValue - KEY_VALUE_DEVICE_OFFSET;\r |
e35eb8af | 663 | ASSERT (mSelectedCtrIndex >= 0 && mSelectedCtrIndex < MAX_CHOICE_NUM);\r |
db0bd81c | 664 | \r |
a6f164a7 | 665 | mLastSavedDriverImageNum = 0;\r |
7e3bcccb | 666 | \r |
a6f164a7 | 667 | //\r |
7e3bcccb | 668 | // Init OpCode Handle\r |
a6f164a7 | 669 | //\r |
7e3bcccb LG |
670 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r |
671 | ASSERT (StartOpCodeHandle != NULL);\r | |
672 | \r | |
673 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
674 | ASSERT (EndOpCodeHandle != NULL);\r | |
675 | \r | |
676 | //\r | |
677 | // Create Hii Extend Label OpCode as the start opcode\r | |
678 | //\r | |
679 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
680 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
681 | StartLabel->Number = FORM_ID_DRIVER;\r | |
682 | \r | |
683 | //\r | |
684 | // Create Hii Extend Label OpCode as the end opcode\r | |
685 | //\r | |
686 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
687 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
688 | EndLabel->Number = LABEL_END;\r | |
689 | \r | |
a6f164a7 | 690 | //\r |
691 | // Clear second page form\r | |
692 | //\r | |
7e3bcccb | 693 | HiiUpdateForm (\r |
a6f164a7 | 694 | Private->RegisteredHandle,\r |
c8ad2d7a | 695 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 696 | FORM_ID_DRIVER,\r |
7e3bcccb LG |
697 | StartOpCodeHandle,\r |
698 | EndOpCodeHandle\r | |
a6f164a7 | 699 | );\r |
700 | \r | |
701 | //\r | |
702 | // Show all driver which support loaded image protocol in second page\r | |
703 | //\r | |
704 | DriverImageHandleCount = 0;\r | |
705 | Status = gBS->LocateHandleBuffer (\r | |
706 | ByProtocol,\r | |
707 | &gEfiLoadedImageProtocolGuid,\r | |
708 | NULL,\r | |
709 | &DriverImageHandleCount,\r | |
710 | &mDriverImageHandleBuffer\r | |
711 | );\r | |
712 | if (EFI_ERROR (Status) || (DriverImageHandleCount == 0)) {\r | |
713 | return EFI_NOT_FOUND;\r | |
714 | }\r | |
715 | \r | |
716 | mDriverImageHandleCount = DriverImageHandleCount;\r | |
717 | for (Index = 0; Index < DriverImageHandleCount; Index++) {\r | |
718 | //\r | |
719 | // Step1: Get the driver image total file path for help string and the driver name.\r | |
720 | //\r | |
721 | \r | |
722 | //\r | |
723 | // Find driver's Loaded Image protocol\r | |
724 | //\r | |
725 | LoadedImage =NULL;\r | |
726 | \r | |
727 | Status = gBS->OpenProtocol (\r | |
728 | mDriverImageHandleBuffer[Index],\r | |
729 | &gEfiLoadedImageProtocolGuid,\r | |
730 | (VOID **) &LoadedImage,\r | |
731 | NULL,\r | |
732 | NULL,\r | |
733 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
734 | );\r | |
735 | if (EFI_ERROR (Status)) {\r | |
736 | FakeNvData->DriSelection[Index] = 0x00;\r | |
737 | continue;\r | |
738 | }\r | |
739 | mDriverImageProtocol[Index] = LoadedImage;\r | |
740 | //\r | |
741 | // Find its related driver binding protocol\r | |
742 | //\r | |
68dbca6c LG |
743 | DriverBindingHandle = GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer[Index]);\r |
744 | if (DriverBindingHandle == NULL) {\r | |
a6f164a7 | 745 | FakeNvData->DriSelection[Index] = 0x00;\r |
746 | continue;\r | |
747 | }\r | |
748 | \r | |
749 | //\r | |
750 | // Get the EFI Loaded Image Device Path Protocol\r | |
751 | //\r | |
752 | LoadedImageDevicePath = NULL;\r | |
753 | Status = gBS->HandleProtocol (\r | |
754 | mDriverImageHandleBuffer[Index],\r | |
755 | &gEfiLoadedImageDevicePathProtocolGuid,\r | |
756 | (VOID **) &LoadedImageDevicePath\r | |
757 | );\r | |
758 | if (LoadedImageDevicePath == NULL) {\r | |
759 | FakeNvData->DriSelection[Index] = 0x00;\r | |
760 | continue;\r | |
761 | }\r | |
762 | \r | |
763 | if (FakeNvData->PciDeviceFilter == 0x01) {\r | |
764 | //\r | |
765 | // only care the driver which is in a Pci device option rom,\r | |
766 | // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom\r | |
767 | //\r | |
768 | if (!EFI_ERROR (Status)) {\r | |
769 | Status = gBS->HandleProtocol(\r | |
770 | LoadedImage->DeviceHandle,\r | |
771 | &gEfiBusSpecificDriverOverrideProtocolGuid,\r | |
772 | (VOID **) &BusSpecificDriverOverride\r | |
773 | );\r | |
774 | if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {\r | |
775 | FakeNvData->DriSelection[Index] = 0x00;\r | |
776 | continue;\r | |
777 | }\r | |
778 | } else {\r | |
779 | FakeNvData->DriSelection[Index] = 0x00;\r | |
780 | continue;\r | |
781 | }\r | |
782 | }\r | |
783 | \r | |
784 | //\r | |
785 | // For driver name, try to get its component name, if fail, get its image name,\r | |
786 | // if also fail, give a default name.\r | |
787 | //\r | |
788 | FreeDriverName = FALSE;\r | |
789 | DriverName = GetComponentName (DriverBindingHandle);\r | |
790 | if (DriverName == NULL) {\r | |
791 | //\r | |
792 | // get its image name\r | |
793 | //\r | |
794 | DriverName = GetImageName (LoadedImage);\r | |
795 | }\r | |
796 | if (DriverName == NULL) {\r | |
797 | //\r | |
798 | // give a default name\r | |
799 | //\r | |
cb7d01c0 | 800 | DriverName = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME), NULL);\r |
a6f164a7 | 801 | ASSERT (DriverName != NULL);\r |
802 | FreeDriverName = TRUE; // the DriverName string need to free pool\r | |
803 | }\r | |
804 | \r | |
805 | \r | |
806 | //\r | |
807 | // Step2 Export the driver name string and create check box item in second page\r | |
808 | //\r | |
809 | \r | |
810 | //\r | |
811 | // First create the driver image name\r | |
812 | //\r | |
813 | NewString = AllocateZeroPool (StrSize (DriverName));\r | |
77980854 | 814 | ASSERT (NewString != NULL); \r |
a6f164a7 | 815 | if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol[mSelectedCtrIndex], LoadedImageDevicePath, &mMappingDataBase, NULL, NULL))) {\r |
816 | FakeNvData->DriSelection[Index] = 0x00;\r | |
817 | } else {\r | |
818 | FakeNvData->DriSelection[Index] = 0x01;\r | |
819 | mLastSavedDriverImageNum++;\r | |
820 | }\r | |
821 | StrCat (NewString, DriverName);\r | |
cb7d01c0 | 822 | NewStringToken = HiiSetString (Private->RegisteredHandle, mDriverImageToken[Index], NewString, NULL);\r |
823 | ASSERT (NewStringToken != 0);\r | |
a6f164a7 | 824 | mDriverImageToken[Index] = NewStringToken;\r |
68dbca6c | 825 | FreePool (NewString);\r |
a6f164a7 | 826 | if (FreeDriverName) {\r |
68dbca6c | 827 | FreePool (DriverName);\r |
a6f164a7 | 828 | }\r |
829 | \r | |
830 | //\r | |
831 | // Second create the driver image device path as item help string\r | |
832 | //\r | |
833 | DriverName = DevicePathToStr (LoadedImageDevicePath);\r | |
834 | \r | |
835 | NewString = AllocateZeroPool (StrSize (DriverName));\r | |
80882266 | 836 | ASSERT (NewString != NULL); \r |
a6f164a7 | 837 | StrCat (NewString, DriverName);\r |
cb7d01c0 | 838 | NewStringHelpToken = HiiSetString (Private->RegisteredHandle, mDriverImageFilePathToken[Index], NewString, NULL);\r |
839 | ASSERT (NewStringHelpToken != 0);\r | |
a6f164a7 | 840 | mDriverImageFilePathToken[Index] = NewStringHelpToken;\r |
68dbca6c LG |
841 | FreePool (NewString);\r |
842 | FreePool (DriverName);\r | |
a6f164a7 | 843 | \r |
7e3bcccb LG |
844 | HiiCreateCheckBoxOpCode (\r |
845 | StartOpCodeHandle,\r | |
a6f164a7 | 846 | (UINT16) (DRIVER_SELECTION_QUESTION_ID + Index),\r |
847 | VARSTORE_ID_PLAT_OVER_MNGR,\r | |
848 | (UINT16) (DRIVER_SELECTION_VAR_OFFSET + Index),\r | |
849 | NewStringToken,\r | |
850 | NewStringHelpToken,\r | |
851 | 0,\r | |
852 | 0,\r | |
7e3bcccb | 853 | NULL\r |
a6f164a7 | 854 | );\r |
855 | }\r | |
856 | \r | |
857 | //\r | |
858 | // Update second page form\r | |
859 | //\r | |
7e3bcccb | 860 | HiiUpdateForm (\r |
a6f164a7 | 861 | Private->RegisteredHandle,\r |
c8ad2d7a | 862 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 863 | FORM_ID_DRIVER,\r |
7e3bcccb LG |
864 | StartOpCodeHandle, // Label FORM_ID_DRIVER\r |
865 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 866 | );\r |
867 | \r | |
7e3bcccb LG |
868 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r |
869 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
a6f164a7 | 870 | return EFI_SUCCESS;\r |
871 | }\r | |
872 | \r | |
873 | /**\r | |
874 | Prepare to let user select the priority order of the drivers which are\r | |
875 | selected in second page.\r | |
876 | \r | |
877 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
878 | @param KeyValue The callback key value of device controller item in first page.\r | |
879 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r | |
880 | \r | |
881 | @retval EFI_SUCCESS Always returned.\r | |
882 | \r | |
883 | **/\r | |
884 | EFI_STATUS\r | |
885 | UpdatePrioritySelectPage (\r | |
886 | IN EFI_CALLBACK_INFO *Private,\r | |
887 | IN UINT16 KeyValue,\r | |
888 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
889 | )\r | |
890 | {\r | |
a6f164a7 | 891 | UINTN Index;\r |
a6f164a7 | 892 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;\r |
a6f164a7 | 893 | UINTN SelectedDriverImageNum;\r |
894 | UINT32 DriverImageNO;\r | |
895 | UINTN MinNO;\r | |
896 | UINTN Index1;\r | |
897 | UINTN TempNO[100];\r | |
7e3bcccb LG |
898 | UINTN OrderNO[100];\r |
899 | VOID *StartOpCodeHandle;\r | |
900 | VOID *EndOpCodeHandle;\r | |
901 | VOID *OptionsOpCodeHandle;\r | |
902 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
903 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
a6f164a7 | 904 | \r |
905 | //\r | |
906 | // Following code will be run if user select 'order ... priority' item in second page\r | |
907 | // Prepare third page. In third page, user will order the drivers priority which are selected in second page\r | |
908 | //\r | |
909 | mCurrentPage = FORM_ID_ORDER;\r | |
910 | \r | |
7e3bcccb LG |
911 | //\r |
912 | // Init OpCode Handle\r | |
913 | //\r | |
914 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
915 | ASSERT (StartOpCodeHandle != NULL);\r | |
916 | \r | |
917 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
918 | ASSERT (EndOpCodeHandle != NULL);\r | |
919 | \r | |
920 | //\r | |
921 | // Create Hii Extend Label OpCode as the start opcode\r | |
922 | //\r | |
923 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
924 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
925 | StartLabel->Number = FORM_ID_ORDER;\r | |
926 | \r | |
927 | //\r | |
928 | // Create Hii Extend Label OpCode as the end opcode\r | |
929 | //\r | |
930 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
931 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
932 | EndLabel->Number = LABEL_END;\r | |
933 | \r | |
a6f164a7 | 934 | //\r |
935 | // Clear third page form\r | |
936 | //\r | |
7e3bcccb | 937 | HiiUpdateForm (\r |
a6f164a7 | 938 | Private->RegisteredHandle,\r |
c8ad2d7a | 939 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 940 | FORM_ID_ORDER,\r |
7e3bcccb LG |
941 | StartOpCodeHandle,\r |
942 | EndOpCodeHandle\r | |
a6f164a7 | 943 | );\r |
944 | \r | |
945 | //\r | |
946 | // Check how many drivers have been selected\r | |
947 | //\r | |
948 | SelectedDriverImageNum = 0;\r | |
949 | for (Index = 0; Index < mDriverImageHandleCount; Index++) {\r | |
950 | if (FakeNvData->DriSelection[Index] != 0) {\r | |
951 | SelectedDriverImageNum ++;\r | |
952 | }\r | |
953 | }\r | |
954 | \r | |
955 | mSelectedDriverImageNum = SelectedDriverImageNum;\r | |
956 | if (SelectedDriverImageNum == 0) {\r | |
957 | return EFI_SUCCESS;\r | |
958 | }\r | |
7e3bcccb LG |
959 | \r |
960 | OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
961 | ASSERT (OptionsOpCodeHandle != NULL);\r | |
962 | \r | |
a6f164a7 | 963 | //\r |
964 | // Create order list for those selected drivers\r | |
965 | //\r | |
966 | SelectedDriverImageNum = 0;\r | |
967 | for (Index = 0; Index < mDriverImageHandleCount; Index++) {\r | |
968 | if (FakeNvData->DriSelection[Index] != 0) {\r | |
a6f164a7 | 969 | //\r |
970 | // Use the NO. in driver binding buffer as value, will use it later\r | |
971 | //\r | |
7e3bcccb LG |
972 | HiiCreateOneOfOptionOpCode (\r |
973 | OptionsOpCodeHandle,\r | |
974 | mDriverImageToken[Index],\r | |
975 | 0,\r | |
976 | EFI_IFR_NUMERIC_SIZE_1,\r | |
977 | Index + 1\r | |
978 | );\r | |
a6f164a7 | 979 | \r |
980 | //\r | |
981 | // Get the EFI Loaded Image Device Path Protocol\r | |
982 | //\r | |
983 | LoadedImageDevicePath = NULL;\r | |
984 | gBS->HandleProtocol (\r | |
985 | mDriverImageHandleBuffer[Index],\r | |
986 | &gEfiLoadedImageDevicePathProtocolGuid,\r | |
987 | (VOID **) &LoadedImageDevicePath\r | |
988 | );\r | |
989 | ASSERT (LoadedImageDevicePath != NULL);\r | |
990 | \r | |
991 | //\r | |
992 | // Check the driver DriverImage's order number in mapping database\r | |
993 | //\r | |
994 | DriverImageNO = 0;\r | |
995 | CheckMapping (\r | |
996 | mControllerDevicePathProtocol[mSelectedCtrIndex],\r | |
997 | LoadedImageDevicePath,\r | |
998 | &mMappingDataBase,\r | |
999 | NULL,\r | |
1000 | &DriverImageNO\r | |
1001 | );\r | |
1002 | if (DriverImageNO == 0) {\r | |
1003 | DriverImageNO = (UINT32) mLastSavedDriverImageNum + 1;\r | |
1004 | mLastSavedDriverImageNum++;\r | |
1005 | }\r | |
1006 | TempNO[SelectedDriverImageNum] = DriverImageNO;\r | |
7e3bcccb | 1007 | OrderNO[SelectedDriverImageNum] = Index + 1;\r |
a6f164a7 | 1008 | SelectedDriverImageNum ++;\r |
1009 | }\r | |
1010 | }\r | |
1011 | \r | |
1012 | ASSERT (SelectedDriverImageNum == mSelectedDriverImageNum);\r | |
1013 | //\r | |
1014 | // NvRamMap Must be clear firstly\r | |
1015 | //\r | |
68dbca6c | 1016 | ZeroMem (FakeNvData->DriOrder, sizeof (FakeNvData->DriOrder));\r |
a6f164a7 | 1017 | \r |
1018 | //\r | |
1019 | // Order the selected drivers according to the info already in mapping database\r | |
1020 | // the less order number in mapping database the less order number in NvRamMap\r | |
1021 | //\r | |
1022 | for (Index=0; Index < SelectedDriverImageNum; Index++) {\r | |
1023 | //\r | |
1024 | // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array\r | |
1025 | //\r | |
1026 | MinNO = 0;\r | |
1027 | for (Index1=0; Index1 < SelectedDriverImageNum; Index1++) {\r | |
1028 | if (TempNO[Index1] < TempNO[MinNO]) {\r | |
1029 | MinNO = Index1;\r | |
1030 | }\r | |
1031 | }\r | |
1032 | //\r | |
1033 | // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer\r | |
1034 | //\r | |
7e3bcccb | 1035 | FakeNvData->DriOrder[Index] = (UINT8) OrderNO[MinNO];\r |
68dbca6c | 1036 | TempNO[MinNO] = MAX_CHOICE_NUM + 1;\r |
a6f164a7 | 1037 | }\r |
7e3bcccb LG |
1038 | \r |
1039 | //\r | |
1040 | // Create Order List OpCode\r | |
1041 | //\r | |
1042 | HiiCreateOrderedListOpCode (\r | |
1043 | StartOpCodeHandle,\r | |
a6f164a7 | 1044 | (UINT16) DRIVER_ORDER_QUESTION_ID,\r |
1045 | VARSTORE_ID_PLAT_OVER_MNGR,\r | |
1046 | (UINT16) DRIVER_ORDER_VAR_OFFSET,\r | |
1047 | mControllerToken[mSelectedCtrIndex],\r | |
1048 | mControllerToken[mSelectedCtrIndex],\r | |
1049 | EFI_IFR_FLAG_RESET_REQUIRED,\r | |
1050 | 0,\r | |
1051 | EFI_IFR_NUMERIC_SIZE_1,\r | |
40b96d40 | 1052 | (UINT8) MAX_CHOICE_NUM,\r |
7e3bcccb LG |
1053 | OptionsOpCodeHandle,\r |
1054 | NULL\r | |
a6f164a7 | 1055 | );\r |
1056 | \r | |
1057 | //\r | |
1058 | // Update third page form\r | |
1059 | //\r | |
7e3bcccb | 1060 | HiiUpdateForm (\r |
a6f164a7 | 1061 | Private->RegisteredHandle,\r |
c8ad2d7a | 1062 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 1063 | FORM_ID_ORDER,\r |
7e3bcccb LG |
1064 | StartOpCodeHandle, // Label FORM_ID_ORDER\r |
1065 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 1066 | );\r |
1067 | \r | |
7e3bcccb LG |
1068 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r |
1069 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
1070 | HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r | |
1071 | \r | |
a6f164a7 | 1072 | return EFI_SUCCESS;\r |
1073 | }\r | |
1074 | \r | |
1075 | /**\r | |
1076 | Save the save the mapping database to NV variable.\r | |
1077 | \r | |
1078 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
1079 | @param KeyValue The callback key value of device controller item in first page.\r | |
1080 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r | |
1081 | \r | |
1082 | @retval EFI_SUCCESS Always returned.\r | |
1083 | \r | |
1084 | **/\r | |
1085 | EFI_STATUS\r | |
1086 | CommintChanges (\r | |
1087 | IN EFI_CALLBACK_INFO *Private,\r | |
1088 | IN UINT16 KeyValue,\r | |
1089 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
1090 | )\r | |
1091 | {\r | |
1092 | EFI_STATUS Status;\r | |
1093 | UINTN Index;\r | |
1094 | UINTN SelectedDriverImageNum;\r | |
1095 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;\r | |
1096 | //\r | |
1097 | // Following code will be run if user select 'commint changes' in third page\r | |
1098 | // user enter 'Commit Changes' to save the mapping database\r | |
1099 | //\r | |
1100 | DeleteDriverImage (mControllerDevicePathProtocol[mSelectedCtrIndex], NULL, &mMappingDataBase);\r | |
1101 | for (SelectedDriverImageNum = 0; SelectedDriverImageNum < mSelectedDriverImageNum; SelectedDriverImageNum++) {\r | |
1102 | //\r | |
1103 | // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer\r | |
1104 | //\r | |
1105 | Index = FakeNvData->DriOrder[SelectedDriverImageNum] - 1;\r | |
1106 | \r | |
1107 | //\r | |
1108 | // Get the EFI Loaded Image Device Path Protocol\r | |
1109 | //\r | |
1110 | LoadedImageDevicePath = NULL;\r | |
1111 | Status = gBS->HandleProtocol (\r | |
1112 | mDriverImageHandleBuffer[Index],\r | |
1113 | &gEfiLoadedImageDevicePathProtocolGuid,\r | |
1114 | (VOID **) &LoadedImageDevicePath\r | |
1115 | );\r | |
1116 | ASSERT (LoadedImageDevicePath != NULL);\r | |
1117 | \r | |
1118 | InsertDriverImage (\r | |
1119 | mControllerDevicePathProtocol[mSelectedCtrIndex],\r | |
1120 | LoadedImageDevicePath,\r | |
1121 | &mMappingDataBase,\r | |
1122 | (UINT32)SelectedDriverImageNum + 1\r | |
1123 | );\r | |
1124 | }\r | |
1125 | Status = SaveOverridesMapping (&mMappingDataBase);\r | |
1126 | \r | |
1127 | return Status;\r | |
1128 | }\r | |
1129 | \r | |
1130 | /**\r | |
1131 | This function allows a caller to extract the current configuration for one\r | |
1132 | or more named elements from the target driver.\r | |
1133 | \r | |
1134 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
1135 | @param Request A null-terminated Unicode string in <ConfigRequest> format.\r | |
1136 | @param Progress On return, points to a character in the Request string.\r | |
1137 | Points to the string's null terminator if request was successful.\r | |
1138 | Points to the most recent '&' before the first failing name/value\r | |
1139 | pair (or the beginning of the string if the failure is in the\r | |
1140 | first name/value pair) if the request was not successful.\r | |
1141 | @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r | |
1142 | has all values filled in for the names in the Request string.\r | |
1143 | String to be allocated by the called function.\r | |
1144 | \r | |
1145 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
1146 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
e35eb8af | 1147 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r |
a6f164a7 | 1148 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r |
1149 | \r | |
1150 | **/\r | |
1151 | EFI_STATUS\r | |
1152 | EFIAPI\r | |
1153 | PlatOverMngrExtractConfig (\r | |
68dbca6c | 1154 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
a6f164a7 | 1155 | IN CONST EFI_STRING Request,\r |
1156 | OUT EFI_STRING *Progress,\r | |
1157 | OUT EFI_STRING *Results\r | |
1158 | )\r | |
1159 | {\r | |
1160 | EFI_STATUS Status;\r | |
1161 | EFI_CALLBACK_INFO *Private;\r | |
1162 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r | |
59aefb7e LG |
1163 | EFI_STRING ConfigRequestHdr;\r |
1164 | EFI_STRING ConfigRequest;\r | |
1165 | BOOLEAN AllocatedRequest;\r | |
1166 | UINTN Size;\r | |
1167 | UINTN BufferSize;\r | |
8d00a0f1 | 1168 | \r |
59aefb7e | 1169 | if (Progress == NULL || Results == NULL) {\r |
ae79d2f9 LG |
1170 | return EFI_INVALID_PARAMETER;\r |
1171 | }\r | |
59aefb7e LG |
1172 | \r |
1173 | *Progress = Request;\r | |
c8ad2d7a | 1174 | if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gPlatformOverridesManagerGuid, mVariableName)) {\r |
59aefb7e LG |
1175 | return EFI_NOT_FOUND;\r |
1176 | }\r | |
1177 | \r | |
1178 | ConfigRequestHdr = NULL;\r | |
1179 | ConfigRequest = NULL;\r | |
1180 | Size = 0;\r | |
1181 | AllocatedRequest = FALSE;\r | |
1182 | \r | |
ae79d2f9 | 1183 | Private = EFI_CALLBACK_INFO_FROM_THIS (This);\r |
a6f164a7 | 1184 | HiiConfigRouting = Private->HiiConfigRouting;\r |
59aefb7e LG |
1185 | ConfigRequest = Request;\r |
1186 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r | |
1187 | //\r | |
1188 | // Request has no request element, construct full request string.\r | |
1189 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r | |
1190 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
1191 | //\r | |
c8ad2d7a | 1192 | ConfigRequestHdr = HiiConstructConfigHdr (&gPlatformOverridesManagerGuid, mVariableName, Private->DriverHandle);\r |
59aefb7e LG |
1193 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r |
1194 | ConfigRequest = AllocateZeroPool (Size);\r | |
1195 | ASSERT (ConfigRequest != NULL);\r | |
1196 | AllocatedRequest = TRUE;\r | |
1197 | BufferSize = sizeof (PLAT_OVER_MNGR_DATA);\r | |
1198 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r | |
1199 | FreePool (ConfigRequestHdr);\r | |
1200 | }\r | |
a6f164a7 | 1201 | \r |
1202 | //\r | |
1203 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r | |
1204 | //\r | |
1205 | Status = HiiConfigRouting->BlockToConfig (\r | |
1206 | HiiConfigRouting,\r | |
59aefb7e | 1207 | ConfigRequest,\r |
a6f164a7 | 1208 | (UINT8 *) &Private->FakeNvData,\r |
1209 | sizeof (PLAT_OVER_MNGR_DATA),\r | |
1210 | Results,\r | |
1211 | Progress\r | |
1212 | );\r | |
59aefb7e LG |
1213 | \r |
1214 | //\r | |
1215 | // Free the allocated config request string.\r | |
1216 | //\r | |
1217 | if (AllocatedRequest) {\r | |
1218 | FreePool (ConfigRequest);\r | |
1219 | ConfigRequest = NULL;\r | |
1220 | }\r | |
1221 | //\r | |
1222 | // Set Progress string to the original request string.\r | |
1223 | //\r | |
1224 | if (Request == NULL) {\r | |
1225 | *Progress = NULL;\r | |
1226 | } else if (StrStr (Request, L"OFFSET") == NULL) {\r | |
1227 | *Progress = Request + StrLen (Request);\r | |
1228 | }\r | |
1229 | \r | |
a6f164a7 | 1230 | return Status;\r |
1231 | }\r | |
1232 | \r | |
1233 | /**\r | |
1234 | This function processes the results of changes in configuration.\r | |
1235 | \r | |
cebc8d48 LG |
1236 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r |
1237 | @param Configuration A null-terminated Unicode string in <ConfigRequest> format.\r | |
1238 | @param Progress A pointer to a string filled in with the offset of the most\r | |
1239 | recent '&' before the first failing name/value pair (or the\r | |
1240 | beginning of the string if the failure is in the first\r | |
1241 | name/value pair) or the terminating NULL if all was successful.\r | |
a6f164a7 | 1242 | \r |
1243 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
1244 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
1245 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
1246 | \r | |
1247 | **/\r | |
1248 | EFI_STATUS\r | |
1249 | EFIAPI\r | |
1250 | PlatOverMngrRouteConfig (\r | |
1251 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
1252 | IN CONST EFI_STRING Configuration,\r | |
1253 | OUT EFI_STRING *Progress\r | |
1254 | )\r | |
1255 | {\r | |
1256 | EFI_CALLBACK_INFO *Private;\r | |
a6f164a7 | 1257 | UINT16 KeyValue;\r |
a6f164a7 | 1258 | PLAT_OVER_MNGR_DATA *FakeNvData;\r |
1259 | \r | |
ae79d2f9 LG |
1260 | if (Configuration == NULL || Progress == NULL) {\r |
1261 | return EFI_INVALID_PARAMETER;\r | |
1262 | }\r | |
1263 | *Progress = Configuration;\r | |
1264 | \r | |
c8ad2d7a | 1265 | if (!HiiIsConfigHdrMatch (Configuration, &gPlatformOverridesManagerGuid, mVariableName)) {\r |
ae79d2f9 LG |
1266 | return EFI_NOT_FOUND;\r |
1267 | }\r | |
de482998 LG |
1268 | \r |
1269 | *Progress = Configuration + StrLen (Configuration);\r | |
7e3bcccb | 1270 | Private = EFI_CALLBACK_INFO_FROM_THIS (This);\r |
1d451ff9 | 1271 | FakeNvData = &Private->FakeNvData;\r |
c8ad2d7a | 1272 | if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid, mVariableName, sizeof (PLAT_OVER_MNGR_DATA), (UINT8 *) FakeNvData)) {\r |
de482998 LG |
1273 | //\r |
1274 | // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.\r | |
1275 | //\r | |
1276 | return EFI_SUCCESS;\r | |
a6f164a7 | 1277 | }\r |
1278 | \r | |
1279 | if (mCurrentPage == FORM_ID_DRIVER) {\r | |
1280 | KeyValue = KEY_VALUE_DRIVER_GOTO_ORDER;\r | |
1281 | UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);\r | |
1282 | KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r | |
1283 | CommintChanges (Private, KeyValue, FakeNvData);\r | |
1284 | //\r | |
1285 | // Since UpdatePrioritySelectPage will change mCurrentPage,\r | |
1286 | // should ensure the mCurrentPage still indicate the second page here\r | |
1287 | //\r | |
1288 | mCurrentPage = FORM_ID_DRIVER;\r | |
1289 | }\r | |
1290 | \r | |
1291 | if (mCurrentPage == FORM_ID_ORDER) {\r | |
1292 | KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r | |
1293 | CommintChanges (Private, KeyValue, FakeNvData);\r | |
1294 | }\r | |
7e3bcccb | 1295 | \r |
a6f164a7 | 1296 | return EFI_SUCCESS;\r |
1297 | }\r | |
1298 | \r | |
1299 | /**\r | |
1300 | This is the function that is called to provide results data to the driver. This data\r | |
1301 | consists of a unique key which is used to identify what data is either being passed back\r | |
1302 | or being asked for.\r | |
1303 | \r | |
1304 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
1305 | @param Action A null-terminated Unicode string in <ConfigRequest> format.\r | |
1306 | @param KeyValue A unique Goto OpCode callback value which record user's selection.\r | |
1307 | 0x100 <= KeyValue <0x500 : user select a controller item in the first page;\r | |
1308 | KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page\r | |
1309 | KeyValue == 0x1235 : user select 'Pci device filter' in first page\r | |
1310 | KeyValue == 0x1500 : user select 'order ... priority' item in second page\r | |
1311 | KeyValue == 0x1800 : user select 'commint changes' in third page\r | |
1312 | KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page\r | |
1313 | @param Type The type of value for the question.\r | |
1314 | @param Value A pointer to the data being sent to the original exporting driver.\r | |
1315 | @param ActionRequest On return, points to the action requested by the callback function.\r | |
1316 | \r | |
1317 | @retval EFI_SUCCESS Always returned.\r | |
1318 | \r | |
1319 | **/\r | |
1320 | EFI_STATUS\r | |
1321 | EFIAPI\r | |
1322 | PlatOverMngrCallback (\r | |
1323 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
1324 | IN EFI_BROWSER_ACTION Action,\r | |
1325 | IN EFI_QUESTION_ID KeyValue,\r | |
1326 | IN UINT8 Type,\r | |
1327 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
1328 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
1329 | )\r | |
1330 | {\r | |
1331 | EFI_CALLBACK_INFO *Private;\r | |
1332 | EFI_STATUS Status;\r | |
1333 | EFI_STRING_ID NewStringToken;\r | |
a6f164a7 | 1334 | EFI_INPUT_KEY Key;\r |
7e3bcccb | 1335 | PLAT_OVER_MNGR_DATA *FakeNvData;\r |
5adb8db7 | 1336 | \r |
3a4e7a3e ED |
1337 | if ((Action != EFI_BROWSER_ACTION_CHANGING) && (Action != EFI_BROWSER_ACTION_CHANGED)) {\r |
1338 | //\r | |
1339 | // All other action return unsupported.\r | |
1340 | //\r | |
1341 | return EFI_UNSUPPORTED;\r | |
1342 | }\r | |
1343 | \r | |
1344 | Private = EFI_CALLBACK_INFO_FROM_THIS (This);\r | |
1345 | FakeNvData = &Private->FakeNvData;\r | |
1346 | if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid, mVariableName, sizeof (PLAT_OVER_MNGR_DATA), (UINT8 *) FakeNvData)) {\r | |
1347 | return EFI_NOT_FOUND;\r | |
1348 | }\r | |
1349 | \r | |
083f7c69 | 1350 | if (Action == EFI_BROWSER_ACTION_CHANGING) {\r |
3a4e7a3e ED |
1351 | if (Value == NULL) {\r |
1352 | return EFI_INVALID_PARAMETER;\r | |
cb7d01c0 | 1353 | }\r |
3a4e7a3e ED |
1354 | \r |
1355 | if (KeyValue == KEY_VALUE_DRIVER_GOTO_PREVIOUS) {\r | |
083f7c69 ED |
1356 | UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r |
1357 | //\r | |
1358 | // Update page title string\r | |
1359 | //\r | |
1360 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1361 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) {\r | |
1362 | ASSERT (FALSE);\r | |
1363 | }\r | |
a6f164a7 | 1364 | }\r |
083f7c69 ED |
1365 | \r |
1366 | if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) {\r | |
1367 | if (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS) {\r | |
1368 | KeyValue = (EFI_QUESTION_ID) (mSelectedCtrIndex + KEY_VALUE_DEVICE_OFFSET);\r | |
1369 | }\r | |
1370 | UpdateBindingDriverSelectPage (Private, KeyValue, FakeNvData);\r | |
1371 | //\r | |
1372 | // Update page title string\r | |
1373 | //\r | |
1374 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1375 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Second, Select drivers for the previous selected controller", NULL) == 0) {\r | |
1376 | ASSERT (FALSE);\r | |
1377 | }\r | |
cb7d01c0 | 1378 | }\r |
a6f164a7 | 1379 | \r |
083f7c69 ED |
1380 | if (KeyValue == KEY_VALUE_DRIVER_GOTO_ORDER) {\r |
1381 | UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);\r | |
1382 | //\r | |
1383 | // Update page title string\r | |
1384 | //\r | |
1385 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1386 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Finally, Set the priority order for the drivers and save them", NULL) == 0) {\r | |
1387 | ASSERT (FALSE);\r | |
1388 | }\r | |
cb7d01c0 | 1389 | }\r |
a6f164a7 | 1390 | \r |
083f7c69 ED |
1391 | if (KeyValue == KEY_VALUE_DEVICE_CLEAR) {\r |
1392 | //\r | |
1393 | // Deletes all environment variable(s) that contain the override mappings info\r | |
1394 | //\r | |
1395 | FreeMappingDatabase (&mMappingDataBase);\r | |
1396 | Status = SaveOverridesMapping (&mMappingDataBase);\r | |
1397 | UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r | |
1398 | }\r | |
3a4e7a3e ED |
1399 | } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r |
1400 | switch (KeyValue) {\r | |
1401 | case KEY_VALUE_DEVICE_REFRESH:\r | |
1402 | case KEY_VALUE_DEVICE_FILTER:\r | |
1403 | UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r | |
1404 | //\r | |
1405 | // Update page title string\r | |
1406 | //\r | |
1407 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1408 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) {\r | |
1409 | ASSERT (FALSE);\r | |
1410 | }\r | |
1411 | break;\r | |
1412 | \r | |
1413 | case KEY_VALUE_ORDER_SAVE_AND_EXIT:\r | |
1414 | Status = CommintChanges (Private, KeyValue, FakeNvData);\r | |
1415 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r | |
1416 | if (EFI_ERROR (Status)) {\r | |
1417 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Single Override Info too large, Saving Error!", NULL);\r | |
1418 | return EFI_DEVICE_ERROR;\r | |
1419 | }\r | |
1420 | break;\r | |
083f7c69 | 1421 | \r |
3a4e7a3e ED |
1422 | default:\r |
1423 | break;\r | |
1424 | }\r | |
1425 | }\r | |
083f7c69 | 1426 | \r |
a6f164a7 | 1427 | //\r |
3a4e7a3e | 1428 | // Pass changed uncommitted data back to Form Browser\r |
a6f164a7 | 1429 | //\r |
3a4e7a3e ED |
1430 | HiiSetBrowserData (&gPlatformOverridesManagerGuid, mVariableName, sizeof (PLAT_OVER_MNGR_DATA), (UINT8 *) FakeNvData, NULL);\r |
1431 | \r | |
1432 | return EFI_SUCCESS;\r | |
a6f164a7 | 1433 | }\r |
1434 | \r | |
6d8ced29 LG |
1435 | /**\r |
1436 | Retrieves the image handle of the platform override driver for a controller in the system.\r | |
1437 | \r | |
1438 | @param This A pointer to the\r | |
1439 | EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.\r | |
1440 | @param ControllerHandle The device handle of the controller to check if a\r | |
1441 | driver override exists.\r | |
1442 | @param DriverImageHandle On input, a pointer to the previous driver image\r | |
1443 | handle returned by GetDriver(). On output, a\r | |
1444 | pointer to the next driver image handle. Passing\r | |
1445 | in a NULL, will return the first driver image\r | |
1446 | handle for ControllerHandle.\r | |
1447 | \r | |
1448 | @retval EFI_SUCCESS The driver override for ControllerHandle was\r | |
1449 | returned in DriverImageHandle.\r | |
1450 | @retval EFI_NOT_FOUND A driver override for ControllerHandle was not\r | |
1451 | found.\r | |
284ee2e8 RN |
1452 | @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is NULL.\r |
1453 | DriverImageHandle is not a handle that was returned\r | |
1454 | on a previous call to GetDriver().\r | |
6d8ced29 LG |
1455 | \r |
1456 | **/\r | |
1457 | EFI_STATUS\r | |
1458 | EFIAPI\r | |
1459 | GetDriver (\r | |
1460 | IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r | |
1461 | IN EFI_HANDLE ControllerHandle,\r | |
1462 | IN OUT EFI_HANDLE *DriverImageHandle\r | |
1463 | )\r | |
1464 | {\r | |
1465 | EFI_STATUS Status;\r | |
1466 | \r | |
1467 | //\r | |
1468 | // Check that ControllerHandle is a valid handle\r | |
1469 | //\r | |
1470 | if (ControllerHandle == NULL) {\r | |
1471 | return EFI_INVALID_PARAMETER;\r | |
1472 | }\r | |
1473 | \r | |
1474 | //\r | |
1475 | // Read the environment variable(s) that contain the override mappings from Controller Device Path to\r | |
1476 | // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller\r | |
1477 | // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed\r | |
1478 | // once and finished in first call.\r | |
1479 | //\r | |
1480 | if (!mEnvironmentVariableRead) {\r | |
1481 | mEnvironmentVariableRead = TRUE;\r | |
1482 | \r | |
1483 | Status = InitOverridesMapping (&mMappingDataBase);\r | |
1484 | if (EFI_ERROR (Status)){\r | |
1485 | DEBUG ((DEBUG_ERROR, "The status to Get Platform Driver Override Variable is %r\n", Status));\r | |
1486 | InitializeListHead (&mMappingDataBase);\r | |
1487 | return EFI_NOT_FOUND;\r | |
1488 | }\r | |
1489 | }\r | |
1490 | \r | |
1491 | //\r | |
1492 | // if the environment variable does not exist, just return not found\r | |
1493 | //\r | |
1494 | if (IsListEmpty (&mMappingDataBase)) {\r | |
1495 | return EFI_NOT_FOUND;\r | |
1496 | }\r | |
1497 | \r | |
1498 | return GetDriverFromMapping (\r | |
1499 | ControllerHandle,\r | |
1500 | DriverImageHandle,\r | |
1501 | &mMappingDataBase,\r | |
1502 | mCallerImageHandle\r | |
1503 | );\r | |
1504 | }\r | |
1505 | \r | |
1506 | /**\r | |
1507 | Retrieves the device path of the platform override driver for a controller in the system.\r | |
1508 | This driver doesn't support this API.\r | |
1509 | \r | |
1510 | @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r | |
1511 | PROTOCOL instance. \r | |
1512 | @param ControllerHandle The device handle of the controller to check if a driver override\r | |
1513 | exists. \r | |
1514 | @param DriverImagePath On input, a pointer to the previous driver device path returned by\r | |
1515 | GetDriverPath(). On output, a pointer to the next driver\r | |
1516 | device path. Passing in a pointer to NULL, will return the first\r | |
1517 | driver device path for ControllerHandle.\r | |
1518 | \r | |
1519 | @retval EFI_UNSUPPORTED\r | |
1520 | **/\r | |
1521 | EFI_STATUS\r | |
1522 | EFIAPI\r | |
1523 | GetDriverPath (\r | |
1524 | IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r | |
1525 | IN EFI_HANDLE ControllerHandle,\r | |
1526 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DriverImagePath\r | |
1527 | )\r | |
1528 | {\r | |
1529 | return EFI_UNSUPPORTED;\r | |
1530 | }\r | |
1531 | \r | |
1532 | \r | |
1533 | /**\r | |
1534 | Used to associate a driver image handle with a device path that was returned on a prior call to the\r | |
1535 | GetDriverPath() service. This driver image handle will then be available through the \r | |
1536 | GetDriver() service. This driver doesn't support this API.\r | |
1537 | \r | |
1538 | @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r | |
1539 | PROTOCOL instance. \r | |
1540 | @param ControllerHandle The device handle of the controller. \r | |
1541 | @param DriverImagePath A pointer to the driver device path that was returned in a prior\r | |
1542 | call to GetDriverPath(). \r | |
1543 | @param DriverImageHandle The driver image handle that was returned by LoadImage()\r | |
1544 | when the driver specified by DriverImagePath was loaded \r | |
1545 | into memory. \r | |
1546 | \r | |
1547 | @retval EFI_UNSUPPORTED\r | |
1548 | **/\r | |
1549 | EFI_STATUS\r | |
1550 | EFIAPI\r | |
1551 | DriverLoaded (\r | |
1552 | IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r | |
1553 | IN EFI_HANDLE ControllerHandle,\r | |
1554 | IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath,\r | |
1555 | IN EFI_HANDLE DriverImageHandle\r | |
1556 | )\r | |
1557 | {\r | |
1558 | return EFI_UNSUPPORTED;\r | |
1559 | }\r | |
1560 | \r | |
a6f164a7 | 1561 | /**\r |
68dbca6c LG |
1562 | The driver Entry Point. The funciton will export a disk device class formset and\r |
1563 | its callback function to hii database.\r | |
a6f164a7 | 1564 | \r |
68dbca6c LG |
1565 | @param ImageHandle The firmware allocated handle for the EFI image.\r |
1566 | @param SystemTable A pointer to the EFI System Table.\r | |
a6f164a7 | 1567 | \r |
68dbca6c LG |
1568 | @retval EFI_SUCCESS The entry point is executed successfully.\r |
1569 | @retval other Some error occurs when executing this entry point.\r | |
a6f164a7 | 1570 | \r |
1571 | **/\r | |
68dbca6c LG |
1572 | EFI_STATUS\r |
1573 | EFIAPI\r | |
6d8ced29 | 1574 | PlatDriOverrideDxeInit (\r |
68dbca6c LG |
1575 | IN EFI_HANDLE ImageHandle,\r |
1576 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
a6f164a7 | 1577 | )\r |
1578 | {\r | |
68dbca6c | 1579 | EFI_STATUS Status;\r |
f6f910dd | 1580 | EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;\r |
6d8ced29 | 1581 | VOID *Instance;\r |
e5618791 | 1582 | \r |
68dbca6c LG |
1583 | //\r |
1584 | // There should only be one Form Configuration protocol\r | |
1585 | //\r | |
a6f164a7 | 1586 | Status = gBS->LocateProtocol (\r |
68dbca6c LG |
1587 | &gEfiFormBrowser2ProtocolGuid,\r |
1588 | NULL,\r | |
1589 | (VOID **) &FormBrowser2\r | |
1590 | );\r | |
1591 | if (EFI_ERROR (Status)) {\r | |
1592 | return Status;\r | |
1593 | }\r | |
1594 | \r | |
6d8ced29 LG |
1595 | //\r |
1596 | // According to UEFI spec, there can be at most a single instance\r | |
1597 | // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r | |
1598 | // So here we check the existence.\r | |
1599 | //\r | |
1600 | Status = gBS->LocateProtocol (\r | |
1601 | &gEfiPlatformDriverOverrideProtocolGuid,\r | |
1602 | NULL,\r | |
1603 | &Instance\r | |
1604 | );\r | |
1605 | //\r | |
1606 | // If there was no error, assume there is an installation and return error\r | |
1607 | //\r | |
1608 | if (!EFI_ERROR (Status)) {\r | |
1609 | return EFI_ALREADY_STARTED;\r | |
1610 | }\r | |
1611 | \r | |
1612 | mCallerImageHandle = ImageHandle;\r | |
7e3bcccb LG |
1613 | mCallbackInfo = AllocateZeroPool (sizeof (EFI_CALLBACK_INFO));\r |
1614 | if (mCallbackInfo == NULL) {\r | |
68dbca6c LG |
1615 | return EFI_BAD_BUFFER_SIZE;\r |
1616 | }\r | |
1617 | \r | |
7e3bcccb LG |
1618 | mCallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;\r |
1619 | mCallbackInfo->ConfigAccess.ExtractConfig = PlatOverMngrExtractConfig;\r | |
1620 | mCallbackInfo->ConfigAccess.RouteConfig = PlatOverMngrRouteConfig;\r | |
1621 | mCallbackInfo->ConfigAccess.Callback = PlatOverMngrCallback;\r | |
6d8ced29 LG |
1622 | mCallbackInfo->PlatformDriverOverride.GetDriver = GetDriver;\r |
1623 | mCallbackInfo->PlatformDriverOverride.GetDriverPath = GetDriverPath;\r | |
1624 | mCallbackInfo->PlatformDriverOverride.DriverLoaded = DriverLoaded;\r | |
68dbca6c | 1625 | //\r |
f6f910dd | 1626 | // Install Device Path Protocol and Config Access protocol to driver handle\r |
6d8ced29 | 1627 | // Install Platform Driver Override Protocol to driver handle\r |
68dbca6c | 1628 | //\r |
f6f910dd | 1629 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
7e3bcccb | 1630 | &mCallbackInfo->DriverHandle,\r |
f6f910dd | 1631 | &gEfiDevicePathProtocolGuid,\r |
1632 | &mHiiVendorDevicePath,\r | |
68dbca6c | 1633 | &gEfiHiiConfigAccessProtocolGuid,\r |
7e3bcccb | 1634 | &mCallbackInfo->ConfigAccess,\r |
6d8ced29 LG |
1635 | &gEfiPlatformDriverOverrideProtocolGuid,\r |
1636 | &mCallbackInfo->PlatformDriverOverride,\r | |
f6f910dd | 1637 | NULL\r |
68dbca6c LG |
1638 | );\r |
1639 | if (EFI_ERROR (Status)) {\r | |
e5618791 | 1640 | goto Finish;\r |
68dbca6c LG |
1641 | }\r |
1642 | \r | |
1643 | //\r | |
1644 | // Publish our HII data\r | |
1645 | //\r | |
cb7d01c0 | 1646 | mCallbackInfo->RegisteredHandle = HiiAddPackages (\r |
c8ad2d7a | 1647 | &gPlatformOverridesManagerGuid,\r |
cb7d01c0 | 1648 | mCallbackInfo->DriverHandle,\r |
1649 | VfrBin,\r | |
6d8ced29 | 1650 | PlatDriOverrideDxeStrings,\r |
cb7d01c0 | 1651 | NULL\r |
1652 | );\r | |
1653 | if (mCallbackInfo->RegisteredHandle == NULL) {\r | |
1654 | Status = EFI_OUT_OF_RESOURCES;\r | |
e5618791 LG |
1655 | goto Finish;\r |
1656 | }\r | |
1657 | \r | |
68dbca6c LG |
1658 | //\r |
1659 | // Locate ConfigRouting protocol\r | |
1660 | //\r | |
1661 | Status = gBS->LocateProtocol (\r | |
1662 | &gEfiHiiConfigRoutingProtocolGuid,\r | |
a6f164a7 | 1663 | NULL,\r |
7e3bcccb | 1664 | (VOID **) &mCallbackInfo->HiiConfigRouting\r |
a6f164a7 | 1665 | );\r |
68dbca6c | 1666 | if (EFI_ERROR (Status)) {\r |
e5618791 | 1667 | goto Finish;\r |
68dbca6c LG |
1668 | }\r |
1669 | \r | |
1670 | //\r | |
1671 | // Clear all the globle variable\r | |
1672 | //\r | |
1673 | mDriverImageHandleCount = 0;\r | |
1674 | mCurrentPage = 0;\r | |
1675 | ZeroMem (mDriverImageToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r | |
1676 | ZeroMem (mDriverImageFilePathToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r | |
1677 | ZeroMem (mControllerToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r | |
1678 | ZeroMem (mDriverImageProtocol, MAX_CHOICE_NUM * sizeof (EFI_LOADED_IMAGE_PROTOCOL *));\r | |
6d8ced29 LG |
1679 | \r |
1680 | return EFI_SUCCESS;\r | |
e5618791 LG |
1681 | \r |
1682 | Finish:\r | |
f0c855b2 | 1683 | PlatDriOverrideDxeUnload (ImageHandle);\r |
e5618791 LG |
1684 | \r |
1685 | return Status;\r | |
a6f164a7 | 1686 | }\r |
87fbccbe | 1687 | \r |
1688 | /**\r | |
6d8ced29 LG |
1689 | Unload its installed protocol.\r |
1690 | \r | |
1691 | @param[in] ImageHandle Handle that identifies the image to be unloaded.\r | |
1692 | \r | |
1693 | @retval EFI_SUCCESS The image has been unloaded.\r | |
87fbccbe | 1694 | **/\r |
6d8ced29 LG |
1695 | EFI_STATUS\r |
1696 | EFIAPI\r | |
1697 | PlatDriOverrideDxeUnload (\r | |
1698 | IN EFI_HANDLE ImageHandle\r | |
87fbccbe | 1699 | )\r |
1700 | {\r | |
f0c855b2 | 1701 | ASSERT (mCallbackInfo != NULL);\r |
1702 | \r | |
6d8ced29 LG |
1703 | if (mCallbackInfo->DriverHandle != NULL) {\r |
1704 | gBS->UninstallMultipleProtocolInterfaces (\r | |
1705 | mCallbackInfo->DriverHandle,\r | |
1706 | &gEfiDevicePathProtocolGuid,\r | |
1707 | &mHiiVendorDevicePath,\r | |
1708 | &gEfiHiiConfigAccessProtocolGuid,\r | |
1709 | &mCallbackInfo->ConfigAccess,\r | |
1710 | &gEfiPlatformDriverOverrideProtocolGuid,\r | |
1711 | &mCallbackInfo->PlatformDriverOverride,\r | |
1712 | NULL\r | |
1713 | );\r | |
87fbccbe | 1714 | }\r |
6d8ced29 LG |
1715 | \r |
1716 | if (mCallbackInfo->RegisteredHandle != NULL) {\r | |
1717 | HiiRemovePackages (mCallbackInfo->RegisteredHandle);\r | |
87fbccbe | 1718 | }\r |
1719 | \r | |
f0c855b2 | 1720 | FreePool (mCallbackInfo);\r |
6d8ced29 LG |
1721 | \r |
1722 | return EFI_SUCCESS;\r | |
87fbccbe | 1723 | }\r |