]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
Refine all R9 call back function to return EFI_UNSUPPORTED for all unsupported call...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / DeviceMngr / DeviceManager.c
CommitLineData
5c08e117 1/** @file\r
2 The platform device manager reference implementation\r
3\r
2fde83b1 4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
180a5a35 5This program and the accompanying materials\r
5c08e117 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "DeviceManager.h"\r
16\r
17DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {\r
18 DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,\r
19 NULL,\r
20 NULL,\r
ab4da126 21 NULL,\r
22 NULL,\r
5c08e117 23 {\r
24 FakeExtractConfig,\r
25 FakeRouteConfig,\r
26 DeviceManagerCallback\r
ab4da126 27 },\r
28 {\r
29 FakeExtractConfig,\r
30 FakeRouteConfig,\r
31 DriverHealthCallback\r
5c08e117 32 }\r
33};\r
34\r
3c4b1122
ED
35#define MAX_MAC_ADDRESS_NODE_LIST_LEN 10\r
36\r
5c08e117 37EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;\r
ab4da126 38EFI_GUID mDriverHealthGuid = DRIVER_HEALTH_FORMSET_GUID;\r
5c08e117 39\r
3c4b1122
ED
40//\r
41// Which Mac Address string is select\r
42// it will decide what menu need to show in the NETWORK_DEVICE_FORM_ID form.\r
43//\r
44EFI_STRING mSelectedMacAddrString;\r
45\r
46//\r
47// Which form Id need to be show.\r
48//\r
49EFI_FORM_ID mNextShowFormId = DEVICE_MANAGER_FORM_ID; \r
50\r
51//\r
52// The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID\r
53//\r
54MAC_ADDRESS_NODE_LIST mMacDeviceList;\r
55\r
5c08e117 56DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable[] = {\r
57 { STRING_TOKEN (STR_DISK_DEVICE), EFI_DISK_DEVICE_CLASS },\r
58 { STRING_TOKEN (STR_VIDEO_DEVICE), EFI_VIDEO_DEVICE_CLASS },\r
59 { STRING_TOKEN (STR_NETWORK_DEVICE), EFI_NETWORK_DEVICE_CLASS },\r
60 { STRING_TOKEN (STR_INPUT_DEVICE), EFI_INPUT_DEVICE_CLASS },\r
61 { STRING_TOKEN (STR_ON_BOARD_DEVICE), EFI_ON_BOARD_DEVICE_CLASS },\r
62 { STRING_TOKEN (STR_OTHER_DEVICE), EFI_OTHER_DEVICE_CLASS }\r
63};\r
64\r
f6f910dd 65HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {\r
66 {\r
67 {\r
68 HARDWARE_DEVICE_PATH,\r
69 HW_VENDOR_DP,\r
70 {\r
71 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
72 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
73 }\r
74 },\r
75 //\r
76 // {102579A0-3686-466e-ACD8-80C087044F4A}\r
77 //\r
78 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }\r
79 },\r
80 {\r
81 END_DEVICE_PATH_TYPE,\r
82 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
83 { \r
84 (UINT8) (END_DEVICE_PATH_LENGTH),\r
85 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
86 }\r
87 }\r
88};\r
89\r
61910435
LG
90HII_VENDOR_DEVICE_PATH mDriverHealthHiiVendorDevicePath = {\r
91 {\r
92 {\r
93 HARDWARE_DEVICE_PATH,\r
94 HW_VENDOR_DP,\r
95 {\r
96 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
97 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
98 }\r
99 },\r
100 //\r
101 // {D8F76651-1675-4986-BED4-3824B2F1F4C8}\r
102 //\r
103 { 0xd8f76651, 0x1675, 0x4986, { 0xbe, 0xd4, 0x38, 0x24, 0xb2, 0xf1, 0xf4, 0xc8 } }\r
104 },\r
105 {\r
106 END_DEVICE_PATH_TYPE,\r
107 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
108 { \r
109 (UINT8) (END_DEVICE_PATH_LENGTH),\r
110 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
111 }\r
112 }\r
113};\r
114\r
5c08e117 115/**\r
ab4da126 116 This function is invoked if user selected a interactive opcode from Device Manager's\r
5c08e117 117 Formset. The decision by user is saved to gCallbackKey for later processing. If\r
118 user set VBIOS, the new value is saved to EFI variable.\r
119\r
120 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
121 @param Action Specifies the type of action taken by the browser.\r
122 @param QuestionId A unique value which is sent to the original exporting driver\r
123 so that it can identify the type of data to expect.\r
124 @param Type The type of value for the question.\r
125 @param Value A pointer to the data being sent to the original exporting driver.\r
126 @param ActionRequest On return, points to the action requested by the callback function.\r
127\r
128 @retval EFI_SUCCESS The callback successfully handled the action.\r
129 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r
130\r
131**/\r
132EFI_STATUS\r
133EFIAPI\r
134DeviceManagerCallback (\r
135 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
136 IN EFI_BROWSER_ACTION Action,\r
137 IN EFI_QUESTION_ID QuestionId,\r
138 IN UINT8 Type,\r
139 IN EFI_IFR_TYPE_VALUE *Value,\r
140 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
141 )\r
142{\r
3c4b1122
ED
143 UINTN CurIndex;\r
144 \r
4548fc2a
LG
145 if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
146 //\r
147 // Do nothing for UEFI OPEN/CLOSE Action\r
148 //\r
149 return EFI_SUCCESS;\r
150 }\r
151\r
5c08e117 152 if ((Value == NULL) || (ActionRequest == NULL)) {\r
153 return EFI_INVALID_PARAMETER;\r
154 }\r
155\r
6aa22a17 156 gCallbackKey = QuestionId;\r
5c08e117 157\r
3c4b1122
ED
158 if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {\r
159 //\r
160 // If user select the mac address, need to record mac address string to support next form show.\r
161 //\r
162 for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) {\r
163 if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) {\r
164 mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL);\r
165 }\r
166 }\r
167 }\r
168 \r
6aa22a17 169 //\r
170 // Request to exit SendForm(), so as to switch to selected form\r
171 //\r
172 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
5c08e117 173\r
5c08e117 174 return EFI_SUCCESS;\r
175}\r
176\r
177/**\r
178\r
179 This function registers HII packages to HII database.\r
180\r
cb7d01c0 181 @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully.\r
182 @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered.\r
5c08e117 183\r
184**/\r
185EFI_STATUS\r
186InitializeDeviceManager (\r
187 VOID\r
188 )\r
189{\r
190 EFI_STATUS Status;\r
5c08e117 191\r
192 //\r
f6f910dd 193 // Install Device Path Protocol and Config Access protocol to driver handle\r
5c08e117 194 //\r
f6f910dd 195 Status = gBS->InstallMultipleProtocolInterfaces (\r
5c08e117 196 &gDeviceManagerPrivate.DriverHandle,\r
f6f910dd 197 &gEfiDevicePathProtocolGuid,\r
198 &mDeviceManagerHiiVendorDevicePath,\r
5c08e117 199 &gEfiHiiConfigAccessProtocolGuid,\r
f6f910dd 200 &gDeviceManagerPrivate.ConfigAccess,\r
201 NULL\r
5c08e117 202 );\r
203 ASSERT_EFI_ERROR (Status);\r
204\r
ab4da126 205 Status = gBS->InstallMultipleProtocolInterfaces (\r
206 &gDeviceManagerPrivate.DriverHealthHandle,\r
61910435
LG
207 &gEfiDevicePathProtocolGuid,\r
208 &mDriverHealthHiiVendorDevicePath,\r
ab4da126 209 &gEfiHiiConfigAccessProtocolGuid,\r
210 &gDeviceManagerPrivate.DriverHealthConfigAccess,\r
211 NULL\r
212 );\r
213 ASSERT_EFI_ERROR (Status);\r
214\r
3c4b1122
ED
215 mMacDeviceList.CurListLen = 0;\r
216 mMacDeviceList.MaxListLen = 0;\r
217\r
5c08e117 218 return Status;\r
219}\r
220\r
75bf9d0e
LG
221/**\r
222 Extract the displayed formset for given HII handle and class guid.\r
223\r
224 @param Handle The HII handle.\r
225 @param SetupClassGuid The class guid specifies which form set will be displayed.\r
226 @param FormSetTitle Formset title string.\r
227 @param FormSetHelp Formset help string.\r
228\r
229 @retval TRUE The formset for given HII handle will be displayed.\r
230 @return FALSE The formset for given HII handle will not be displayed.\r
231\r
232**/\r
233BOOLEAN\r
234ExtractDisplayedHiiFormFromHiiHandle (\r
235 IN EFI_HII_HANDLE Handle,\r
236 IN EFI_GUID *SetupClassGuid,\r
237 OUT EFI_STRING_ID *FormSetTitle,\r
238 OUT EFI_STRING_ID *FormSetHelp\r
239 )\r
240{\r
241 EFI_STATUS Status;\r
242 UINTN BufferSize;\r
243 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r
244 UINT8 *Package;\r
245 UINT8 *OpCodeData;\r
246 UINT32 Offset;\r
247 UINT32 Offset2;\r
248 UINT32 PackageListLength;\r
249 EFI_HII_PACKAGE_HEADER PackageHeader;\r
250 EFI_GUID *ClassGuid;\r
251 UINT8 ClassGuidNum;\r
252\r
253 ASSERT (Handle != NULL);\r
254 ASSERT (SetupClassGuid != NULL); \r
255 ASSERT (FormSetTitle != NULL);\r
256 ASSERT (FormSetHelp != NULL);\r
257\r
258 *FormSetTitle = 0;\r
259 *FormSetHelp = 0;\r
260 ClassGuidNum = 0;\r
261 ClassGuid = NULL;\r
262\r
263 //\r
264 // Get HII PackageList\r
265 //\r
266 BufferSize = 0;\r
267 HiiPackageList = NULL;\r
268 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
269 //\r
270 // Handle is a invalid handle. Check if Handle is corrupted.\r
271 //\r
272 ASSERT (Status != EFI_NOT_FOUND);\r
273 //\r
274 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.\r
275 //\r
276 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
277 \r
278 HiiPackageList = AllocatePool (BufferSize);\r
279 ASSERT (HiiPackageList != NULL);\r
280\r
281 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
282 if (EFI_ERROR (Status)) {\r
283 return FALSE;\r
284 }\r
285\r
286 //\r
287 // Get Form package from this HII package List\r
288 //\r
289 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
290 Offset2 = 0;\r
291 PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);\r
292\r
293 while (Offset < PackageListLength) {\r
294 Package = ((UINT8 *) HiiPackageList) + Offset;\r
295 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
296\r
297 if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {\r
298 //\r
299 // Search FormSet Opcode in this Form Package\r
300 //\r
301 Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);\r
302 while (Offset2 < PackageHeader.Length) {\r
303 OpCodeData = Package + Offset2;\r
304\r
305 if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {\r
158bb28a
LG
306 if (((EFI_IFR_OP_HEADER *) OpCodeData)->Length > OFFSET_OF (EFI_IFR_FORM_SET, Flags)) {\r
307 //\r
308 // Find FormSet OpCode\r
309 //\r
5e24f37a 310 ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *) OpCodeData)->Flags & 0x3);\r
158bb28a
LG
311 ClassGuid = (EFI_GUID *) (VOID *)(OpCodeData + sizeof (EFI_IFR_FORM_SET));\r
312 while (ClassGuidNum-- > 0) {\r
313 if (CompareGuid (SetupClassGuid, ClassGuid)) {\r
314 CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));\r
315 CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));\r
316 FreePool (HiiPackageList);\r
317 return TRUE;\r
318 }\r
32e9da0c 319 ClassGuid ++;\r
75bf9d0e 320 }\r
158bb28a
LG
321 } else {\r
322 CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));\r
323 CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));\r
324 FreePool (HiiPackageList);\r
325 return TRUE;\r
75bf9d0e
LG
326 }\r
327 }\r
328 \r
329 //\r
330 // Go to next opcode\r
331 //\r
332 Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
333 }\r
334 }\r
335 \r
336 //\r
337 // Go to next package\r
338 //\r
339 Offset += PackageHeader.Length;\r
340 }\r
341\r
342 FreePool (HiiPackageList);\r
343\r
344 return FALSE;\r
345}\r
346\r
3c4b1122
ED
347/**\r
348 Get the mac address string from the device path.\r
349 if the device path has the vlan, get the vanid also.\r
350 \r
351 @param MacAddressNode Device path begin with mac address \r
352 @param PBuffer Output string buffer contain mac address.\r
353\r
354**/\r
355BOOLEAN \r
356GetMacAddressString(\r
357 IN MAC_ADDR_DEVICE_PATH *MacAddressNode,\r
358 OUT CHAR16 **PBuffer\r
359 )\r
360{\r
361 UINTN HwAddressSize;\r
362 UINTN Index;\r
363 UINT8 *HwAddress;\r
364 EFI_DEVICE_PATH_PROTOCOL *Node;\r
365 UINT16 VlanId;\r
366 CHAR16 *String;\r
367 UINTN BufferLen;\r
368\r
369 VlanId = 0;\r
370 String = NULL;\r
371 ASSERT(MacAddressNode != NULL);\r
372\r
373 HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r
374 if (MacAddressNode->IfType == 0x01 || MacAddressNode->IfType == 0x00) {\r
375 HwAddressSize = 6;\r
376 }\r
377\r
378 //\r
379 // The output format is MAC:XX:XX:XX:...\XXXX\r
380 // The size is the Number size + ":" size + Vlan size(\XXXX) + End\r
381 //\r
382 BufferLen = (4 + 2 * HwAddressSize + (HwAddressSize - 1) + 5 + 1) * sizeof (CHAR16);\r
383 String = AllocateZeroPool (BufferLen);\r
384 if (String == NULL) {\r
385 return FALSE;\r
386 }\r
387\r
388 *PBuffer = String;\r
389 StrCpy(String, L"MAC:");\r
390 String += 4;\r
391 \r
392 //\r
393 // Convert the MAC address into a unicode string.\r
394 //\r
395 HwAddress = &MacAddressNode->MacAddress.Addr[0];\r
396 for (Index = 0; Index < HwAddressSize; Index++) {\r
397 String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);\r
398 if (Index < HwAddressSize - 1) {\r
399 *String++ = L':';\r
400 }\r
401 }\r
402 \r
403 //\r
404 // If VLAN is configured, it will need extra 5 characters like "\0005".\r
405 // Plus one unicode character for the null-terminator.\r
406 //\r
407 Node = (EFI_DEVICE_PATH_PROTOCOL *)MacAddressNode;\r
408 while (!IsDevicePathEnd (Node)) {\r
409 if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) {\r
410 VlanId = ((VLAN_DEVICE_PATH *) Node)->VlanId;\r
411 }\r
412 Node = NextDevicePathNode (Node);\r
413 }\r
414\r
415 if (VlanId != 0) {\r
416 *String++ = L'\\';\r
417 String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);\r
418 }\r
419\r
420 //\r
421 // Null terminate the Unicode string\r
422 //\r
423 *String = L'\0';\r
424\r
425 return TRUE;\r
426}\r
427\r
428/**\r
429 Save question id and prompt id to the mac device list.\r
430 If the same mac address has saved yet, no need to add more.\r
431\r
3c4b1122
ED
432 @param MacAddrString Mac address string.\r
433\r
434 @retval EFI_SUCCESS Add the item is successful.\r
435 @return Other values if failed to Add the item.\r
436**/\r
437BOOLEAN \r
438AddIdToMacDeviceList (\r
439 IN EFI_STRING MacAddrString\r
440 )\r
441{\r
442 MENU_INFO_ITEM *TempDeviceList;\r
443 UINTN Index;\r
444 EFI_STRING StoredString;\r
445 EFI_STRING_ID PromptId;\r
446 EFI_HII_HANDLE HiiHandle;\r
447\r
448 HiiHandle = gDeviceManagerPrivate.HiiHandle;\r
449 TempDeviceList = NULL;\r
450\r
451 for (Index = 0; Index < mMacDeviceList.CurListLen; Index ++) {\r
452 StoredString = HiiGetString (HiiHandle, mMacDeviceList.NodeList[Index].PromptId, NULL);\r
453 if (StoredString == NULL) {\r
454 return FALSE;\r
455 }\r
456\r
457 //\r
458 // Already has save the same mac address to the list.\r
459 //\r
460 if (StrCmp (MacAddrString, StoredString) == 0) {\r
461 return FALSE;\r
462 }\r
463 }\r
464\r
465 PromptId = HiiSetString(HiiHandle, 0, MacAddrString, NULL);\r
466 //\r
467 // If not in the list, save it.\r
468 //\r
469 if (mMacDeviceList.MaxListLen > mMacDeviceList.CurListLen + 1) {\r
470 mMacDeviceList.NodeList[mMacDeviceList.CurListLen].PromptId = PromptId;\r
471 mMacDeviceList.NodeList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r
472 } else {\r
473 mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;\r
474 if (mMacDeviceList.CurListLen != 0) {\r
475 TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);\r
476 } else {\r
477 TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);\r
478 }\r
479 \r
480 if (TempDeviceList == NULL) {\r
481 return FALSE;\r
482 }\r
483 TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId; \r
484 TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r
485 \r
486 if (mMacDeviceList.CurListLen > 0) {\r
487 FreePool(mMacDeviceList.NodeList);\r
488 }\r
489 \r
490 mMacDeviceList.NodeList = TempDeviceList;\r
491 }\r
492 mMacDeviceList.CurListLen ++;\r
493\r
494 return TRUE;\r
495}\r
496\r
497/**\r
498 Check the devcie path, try to find whether it has mac address path.\r
499\r
500 In this function, first need to check whether this path has mac address path.\r
501 second, when the mac address device path has find, also need to deicide whether\r
502 need to add this mac address relate info to the menu.\r
503\r
504 @param *Node Input device which need to be check.\r
505 @param *NeedAddItem Whether need to add the menu in the network device list.\r
506 \r
507 @retval TRUE Has mac address device path.\r
508 @retval FALSE NOT Has mac address device path. \r
509\r
510**/\r
511BOOLEAN\r
512IsMacAddressDevicePath (\r
513 IN VOID *Node,\r
514 OUT BOOLEAN *NeedAddItem\r
515 )\r
516{\r
517 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
518 CHAR16 *Buffer;\r
519 BOOLEAN ReturnVal;\r
520 \r
521 ASSERT (Node != NULL);\r
522 *NeedAddItem = FALSE;\r
523 ReturnVal = FALSE;\r
524 Buffer = NULL;\r
525\r
526 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
527\r
528 //\r
529 // find the partition device path node\r
530 //\r
531 while (!IsDevicePathEnd (DevicePath)) {\r
532 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r
533 (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) {\r
534 ReturnVal = TRUE;\r
535 \r
536 if (DEVICE_MANAGER_FORM_ID == mNextShowFormId) {\r
537 *NeedAddItem = TRUE;\r
538 break;\r
539 } \r
540 \r
541 if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) {\r
542 break;\r
543 }\r
544\r
545 if (NETWORK_DEVICE_FORM_ID == mNextShowFormId) {\r
546 if (StrCmp (Buffer, mSelectedMacAddrString) == 0) {\r
547 *NeedAddItem = TRUE;\r
548 }\r
549 break;\r
550 }\r
551\r
552 if (NETWORK_DEVICE_LIST_FORM_ID == mNextShowFormId) {\r
553 //\r
554 // Same handle may has two network child handle, so the questionid \r
555 // has the offset of SAME_HANDLE_KEY_OFFSET.\r
556 //\r
557 if (AddIdToMacDeviceList (Buffer)) {\r
558 *NeedAddItem = TRUE;\r
559 }\r
560 break;\r
561 }\r
562 } \r
563 DevicePath = NextDevicePathNode (DevicePath);\r
564 }\r
565\r
566 if (Buffer != NULL) {\r
567 FreePool (Buffer);\r
568 }\r
569\r
570 return ReturnVal;\r
571}\r
572\r
573/**\r
574 Check to see if the device path is for the network device.\r
575\r
576 @param Handle The HII handle which include the mac address device path.\r
577 @param ItemCount The new add Mac address item count.\r
578\r
579 @retval TRUE Need to add new item in the menu.\r
580 @return FALSE Do not need to add the menu about the network.\r
581\r
582**/\r
583BOOLEAN \r
584IsNeedAddNetworkMenu (\r
585 IN EFI_HII_HANDLE Handle,\r
586 OUT UINTN *ItemCount\r
587 )\r
588{\r
589 EFI_STATUS Status;\r
590 UINTN EntryCount;\r
591 UINTN Index; \r
592 EFI_HII_HANDLE HiiDeviceManagerHandle;\r
593 EFI_HANDLE DriverHandle;\r
594 EFI_HANDLE ControllerHandle;\r
595 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
596 EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r
597 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
598 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
599 BOOLEAN IsNeedAdd;\r
600\r
601 HiiDeviceManagerHandle = gDeviceManagerPrivate.HiiHandle;\r
602 IsNeedAdd = FALSE;\r
603 OpenInfoBuffer = NULL;\r
604 if ((Handle == NULL) || (ItemCount == NULL)) {\r
605 return FALSE;\r
606 }\r
607 *ItemCount = 0;\r
608\r
609 Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r
610 if (EFI_ERROR (Status)) {\r
611 return FALSE;\r
612 }\r
613 //\r
614 // Get the device path by the got Driver handle .\r
615 //\r
616 Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath);\r
617 if (EFI_ERROR (Status)) {\r
618 return FALSE;\r
619 }\r
620 TmpDevicePath = DevicePath;\r
621\r
622 // \r
623 // Check whether this device path include mac address device path.\r
624 // If this path has mac address path, get the value whether need \r
625 // add this info to the menu and return.\r
626 // Else check more about the child handle devcie path.\r
627 //\r
628 if (IsMacAddressDevicePath(TmpDevicePath, &IsNeedAdd)) {\r
629 if ((NETWORK_DEVICE_LIST_FORM_ID == mNextShowFormId) && IsNeedAdd) {\r
630 (*ItemCount) = 1;\r
631 }\r
632 return IsNeedAdd;\r
633 }\r
634\r
635 //\r
636 // Search whether this path is the controller path, not he child handle path.\r
637 // And the child handle has the network devcie connected.\r
638 //\r
639 TmpDevicePath = DevicePath;\r
640 Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle);\r
641 if (EFI_ERROR (Status)) {\r
642 return FALSE;\r
643 }\r
644\r
645 if (!IsDevicePathEnd (TmpDevicePath)) {\r
646 return FALSE; \r
647 }\r
648\r
649 //\r
650 // Retrieve the list of agents that are consuming the specific protocol\r
651 // on ControllerHandle.\r
652 // The buffer point by OpenInfoBuffer need be free at this function.\r
653 //\r
654 Status = gBS->OpenProtocolInformation (\r
655 ControllerHandle,\r
656 &gEfiPciIoProtocolGuid,\r
657 &OpenInfoBuffer,\r
658 &EntryCount\r
659 );\r
660 if (EFI_ERROR (Status)) {\r
661 return FALSE;\r
662 }\r
663\r
664 //\r
665 // Inspect if ChildHandle is one of the agents.\r
666 //\r
667 Status = EFI_UNSUPPORTED;\r
668 for (Index = 0; Index < EntryCount; Index++) {\r
669 //\r
670 // Query all the children created by the controller handle's driver\r
671 //\r
672 if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
673 Status = gBS->OpenProtocol (\r
674 OpenInfoBuffer[Index].ControllerHandle,\r
675 &gEfiDevicePathProtocolGuid,\r
676 (VOID **) &ChildDevicePath,\r
677 NULL,\r
678 NULL,\r
679 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
680 );\r
681 if (EFI_ERROR (Status)) {\r
682 continue;\r
683 }\r
684\r
685 // \r
686 // Check whether this device path include mac address device path.\r
687 //\r
688 if (!IsMacAddressDevicePath(ChildDevicePath, &IsNeedAdd)) {\r
689 //\r
690 // If this path not has mac address path, check the other.\r
691 //\r
692 continue;\r
693 } else {\r
694 //\r
695 // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.\r
696 //\r
697 if ((NETWORK_DEVICE_LIST_FORM_ID == mNextShowFormId)) {\r
698 if (IsNeedAdd) {\r
699 (*ItemCount) += 1;\r
700 }\r
701 continue;\r
702 } else {\r
703 //\r
704 // If need to update other form, return whether need to add to the menu.\r
705 // \r
706 goto Done;\r
707 }\r
708 }\r
709 }\r
710 }\r
711\r
712Done:\r
713 if (OpenInfoBuffer != NULL) {\r
714 FreePool (OpenInfoBuffer); \r
715 }\r
716 return IsNeedAdd; \r
717}\r
718\r
5c08e117 719/**\r
720 Call the browser and display the device manager to allow user\r
721 to configure the platform.\r
722\r
723 This function create the dynamic content for device manager. It includes\r
724 section header for all class of devices, one-of opcode to set VBIOS.\r
725 \r
726 @retval EFI_SUCCESS Operation is successful.\r
727 @return Other values if failed to clean up the dynamic content from HII\r
728 database.\r
729\r
730**/\r
731EFI_STATUS\r
732CallDeviceManager (\r
733 VOID\r
734 )\r
735{\r
736 EFI_STATUS Status;\r
5c08e117 737 UINTN Index;\r
cb7d01c0 738 EFI_STRING String;\r
5c08e117 739 EFI_STRING_ID Token;\r
740 EFI_STRING_ID TokenHelp;\r
5c08e117 741 EFI_HII_HANDLE *HiiHandles;\r
5c08e117 742 EFI_HII_HANDLE HiiHandle;\r
5c08e117 743 EFI_STRING_ID FormSetTitle;\r
744 EFI_STRING_ID FormSetHelp;\r
745 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
75bf9d0e
LG
746 VOID *StartOpCodeHandle;\r
747 VOID *EndOpCodeHandle;\r
748 EFI_IFR_GUID_LABEL *StartLabel;\r
749 EFI_IFR_GUID_LABEL *EndLabel;\r
ab4da126 750 UINTN NumHandles;\r
751 EFI_HANDLE *DriverHealthHandles;\r
3c4b1122
ED
752 BOOLEAN AddNetworkMenu;\r
753 UINTN AddItemCount;\r
754 UINTN NewStringLen;\r
755 EFI_STRING NewStringTitle;\r
5c08e117 756\r
75bf9d0e 757 HiiHandles = NULL;\r
5c08e117 758 Status = EFI_SUCCESS;\r
759 gCallbackKey = 0;\r
ab4da126 760 NumHandles = 0;\r
761 DriverHealthHandles = NULL;\r
3c4b1122
ED
762 AddNetworkMenu = FALSE;\r
763 AddItemCount = 0;\r
5c08e117 764\r
765 //\r
766 // Connect all prior to entering the platform setup menu.\r
767 //\r
768 if (!gConnectAllHappened) {\r
769 BdsLibConnectAllDriversToAllControllers ();\r
770 gConnectAllHappened = TRUE;\r
771 }\r
7119d96a 772\r
773 HiiHandle = gDeviceManagerPrivate.HiiHandle;\r
774 if (HiiHandle == NULL) {\r
775 //\r
776 // Publish our HII data.\r
777 //\r
778 HiiHandle = HiiAddPackages (\r
779 &mDeviceManagerGuid,\r
780 gDeviceManagerPrivate.DriverHandle,\r
781 DeviceManagerVfrBin,\r
782 BdsDxeStrings,\r
783 NULL\r
784 );\r
785 if (HiiHandle == NULL) {\r
786 return EFI_OUT_OF_RESOURCES;\r
787 }\r
788\r
789 gDeviceManagerPrivate.HiiHandle = HiiHandle;\r
790 }\r
791\r
5c08e117 792 //\r
3c4b1122
ED
793 // If need show the Network device list form, clear the old save list first.\r
794 //\r
795 if ((mNextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) {\r
796 mMacDeviceList.CurListLen = 0;\r
797 }\r
798\r
5c08e117 799 //\r
3c4b1122
ED
800 // Update the network device form titile.\r
801 //\r
802 if (mNextShowFormId == NETWORK_DEVICE_FORM_ID) {\r
803 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NULL);\r
d0460875 804 NewStringLen = StrLen(mSelectedMacAddrString) * 2;\r
d3b4af2b 805 NewStringLen += (StrLen(String) + 2) * 2;\r
3c4b1122
ED
806 NewStringTitle = AllocatePool (NewStringLen);\r
807 UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);\r
808 HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL); \r
809 FreePool (String);\r
810 FreePool (NewStringTitle);\r
811 }\r
812\r
75bf9d0e
LG
813 //\r
814 // Allocate space for creation of UpdateData Buffer\r
815 //\r
816 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
817 ASSERT (StartOpCodeHandle != NULL);\r
5c08e117 818\r
75bf9d0e
LG
819 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
820 ASSERT (EndOpCodeHandle != NULL);\r
821\r
822 //\r
823 // Create Hii Extend Label OpCode as the start opcode\r
824 //\r
825 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
826 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
3c4b1122
ED
827 //\r
828 // According to the next show Form id(mNextShowFormId) to decide which form need to update.\r
829 //\r
d3b4af2b 830 StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + mNextShowFormId);\r
75bf9d0e
LG
831\r
832 //\r
833 // Create Hii Extend Label OpCode as the end opcode\r
834 //\r
835 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
836 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
837 EndLabel->Number = LABEL_END;\r
838\r
5c08e117 839 //\r
840 // Get all the Hii handles\r
841 //\r
cb7d01c0 842 HiiHandles = HiiGetHiiHandles (NULL);\r
843 ASSERT (HiiHandles != NULL);\r
5c08e117 844\r
5c08e117 845 //\r
846 // Search for formset of each class type\r
847 //\r
cb7d01c0 848 for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
3c4b1122
ED
849 //\r
850 // The QuestionId in the form which will call the driver form has this asssumption.\r
851 // QuestionId = Handle Index + NETWORK_DEVICE_LIST_KEY_OFFSET;\r
852 // Different QuestionId at least has the section of NETWORK_DEVICE_LIST_KEY_OFFSET.\r
853 //\r
854 ASSERT(Index < MAX_KEY_SECTION_LEN);\r
855\r
75bf9d0e 856 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, &FormSetTitle, &FormSetHelp)) {\r
5c08e117 857 continue;\r
858 }\r
859\r
cb7d01c0 860 String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);\r
0e8e994d 861 if (String == NULL) {\r
862 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);\r
863 ASSERT (String != NULL);\r
864 }\r
cb7d01c0 865 Token = HiiSetString (HiiHandle, 0, String, NULL);\r
866 FreePool (String);\r
5c08e117 867\r
cb7d01c0 868 String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL);\r
0e8e994d 869 if (String == NULL) {\r
870 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);\r
871 ASSERT (String != NULL);\r
872 }\r
cb7d01c0 873 TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);\r
874 FreePool (String);\r
5c08e117 875\r
3c4b1122
ED
876 //\r
877 // Network device process\r
878 // \r
879 if (IsNeedAddNetworkMenu (HiiHandles[Index], &AddItemCount)) {\r
880 if (mNextShowFormId == DEVICE_MANAGER_FORM_ID) {\r
881 //\r
882 // Only show one menu item "Network Config" in the device manger form.\r
883 //\r
884 if (!AddNetworkMenu) {\r
885 AddNetworkMenu = TRUE;\r
c1e2b152 886 HiiCreateGotoOpCode (\r
3c4b1122 887 StartOpCodeHandle,\r
c1e2b152 888 DEVICE_MANAGER_FORM_ID,\r
3c4b1122
ED
889 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE),\r
890 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP),\r
891 EFI_IFR_FLAG_CALLBACK,\r
c1e2b152 892 (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID\r
3c4b1122
ED
893 );\r
894 }\r
895 } else if (mNextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) {\r
896 //\r
897 // In network device list form, same mac address device only show one menu.\r
898 //\r
899 while (AddItemCount > 0) {\r
c1e2b152 900 HiiCreateGotoOpCode (\r
3c4b1122 901 StartOpCodeHandle,\r
c1e2b152 902 NETWORK_DEVICE_LIST_FORM_ID,\r
3c4b1122
ED
903 mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId,\r
904 STRING_TOKEN (STR_NETWORK_DEVICE_HELP),\r
905 EFI_IFR_FLAG_CALLBACK,\r
c1e2b152 906 mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId\r
3c4b1122
ED
907 );\r
908 AddItemCount -= 1;\r
909 }\r
910 } else if (mNextShowFormId == NETWORK_DEVICE_FORM_ID) {\r
911 //\r
912 // In network device form, only the selected mac address device need to be show.\r
913 //\r
c1e2b152 914 HiiCreateGotoOpCode (\r
3c4b1122 915 StartOpCodeHandle,\r
c1e2b152 916 NETWORK_DEVICE_FORM_ID,\r
3c4b1122
ED
917 Token,\r
918 TokenHelp,\r
919 EFI_IFR_FLAG_CALLBACK,\r
c1e2b152 920 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET)\r
3c4b1122
ED
921 );\r
922 }\r
923 } else {\r
924 //\r
925 // \r
926 // Not network device process, only need to show at device manger form.\r
927 //\r
928 if (mNextShowFormId == DEVICE_MANAGER_FORM_ID) {\r
c1e2b152 929 HiiCreateGotoOpCode (\r
3c4b1122 930 StartOpCodeHandle,\r
c1e2b152 931 DEVICE_MANAGER_FORM_ID,\r
3c4b1122
ED
932 Token,\r
933 TokenHelp,\r
934 EFI_IFR_FLAG_CALLBACK,\r
c1e2b152 935 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET)\r
3c4b1122
ED
936 );\r
937 }\r
938 }\r
5c08e117 939 }\r
940\r
ab4da126 941 Status = gBS->LocateHandleBuffer (\r
942 ByProtocol,\r
943 &gEfiDriverHealthProtocolGuid,\r
944 NULL,\r
945 &NumHandles,\r
946 &DriverHealthHandles\r
947 );\r
479e19a6 948\r
ab4da126 949 //\r
479e19a6 950 // If there are no drivers installed driver health protocol, do not create driver health entry in UI\r
ab4da126 951 //\r
479e19a6 952 if (NumHandles != 0) {\r
953 //\r
954 // If driver health protocol is installed, create Driver Health subtitle and entry\r
955 //\r
956 HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE), 0, 0, 0);\r
c1e2b152
ED
957 HiiCreateGotoOpCode (\r
958 StartOpCodeHandle,\r
959 DRIVER_HEALTH_FORM_ID,\r
479e19a6 960 STRING_TOKEN(STR_DRIVER_HEALTH_ALL_HEALTHY), // Prompt text\r
961 STRING_TOKEN(STR_DRIVER_HEALTH_STATUS_HELP), // Help text\r
c1e2b152
ED
962 EFI_IFR_FLAG_CALLBACK,\r
963 DEVICE_MANAGER_KEY_DRIVER_HEALTH // Question ID\r
964 );\r
479e19a6 965\r
ab4da126 966 //\r
967 // Check All Driver health status\r
968 //\r
969 if (!PlaformHealthStatusCheck ()) {\r
970 //\r
971 // At least one driver in the platform are not in healthy status\r
972 //\r
973 HiiSetString (HiiHandle, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY), GetStringById (STRING_TOKEN (STR_DRIVER_NOT_HEALTH)), NULL);\r
974 } else {\r
975 //\r
976 // For the string of STR_DRIVER_HEALTH_ALL_HEALTHY previously has been updated and we need to update it while re-entry.\r
977 //\r
978 HiiSetString (HiiHandle, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY), GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY)), NULL);\r
979 }\r
980 }\r
981\r
75bf9d0e
LG
982 HiiUpdateForm (\r
983 HiiHandle,\r
984 &mDeviceManagerGuid,\r
3c4b1122 985 mNextShowFormId,\r
75bf9d0e
LG
986 StartOpCodeHandle,\r
987 EndOpCodeHandle\r
988 );\r
989\r
5c08e117 990 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
991 Status = gFormBrowser2->SendForm (\r
992 gFormBrowser2,\r
993 &HiiHandle,\r
994 1,\r
75bf9d0e 995 &mDeviceManagerGuid,\r
3c4b1122 996 mNextShowFormId,\r
5c08e117 997 NULL,\r
998 &ActionRequest\r
999 );\r
1000 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
1001 EnableResetRequired ();\r
1002 }\r
1003\r
1004 //\r
3c4b1122 1005 // We will have returned from processing a callback, selected\r
5c08e117 1006 // a target to display\r
1007 //\r
3c4b1122 1008 if ((gCallbackKey >= DEVICE_KEY_OFFSET)) {\r
5c08e117 1009 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
1010 Status = gFormBrowser2->SendForm (\r
1011 gFormBrowser2,\r
1012 &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],\r
1013 1,\r
1014 NULL,\r
1015 0,\r
1016 NULL,\r
1017 &ActionRequest\r
1018 );\r
1019\r
1020 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
1021 EnableResetRequired ();\r
1022 }\r
1023\r
1024 //\r
1025 // Force return to Device Manager\r
1026 //\r
1027 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
3c4b1122 1028 goto Done;\r
5c08e117 1029 }\r
1030\r
ab4da126 1031 //\r
1032 // Driver Health item chose. \r
1033 //\r
1034 if (gCallbackKey == DEVICE_MANAGER_KEY_DRIVER_HEALTH) {\r
1035 CallDriverHealth ();\r
bd2057a8 1036 //\r
1037 // Force return to Device Manager\r
1038 //\r
1039 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
3c4b1122
ED
1040 goto Done;\r
1041 }\r
1042\r
1043 //\r
1044 // Enter from device manager and into the network device list.\r
1045 //\r
1046 if (gCallbackKey == QUESTION_NETWORK_DEVICE_ID) {\r
1047 mNextShowFormId = NETWORK_DEVICE_LIST_FORM_ID;\r
1048 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
1049 goto Done;\r
1050 }\r
1051\r
1052 //\r
1053 // In this case, go from the network device list to the specify device.\r
1054 //\r
1055 if ((gCallbackKey < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET ) && (gCallbackKey >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {\r
1056 mNextShowFormId = NETWORK_DEVICE_FORM_ID;\r
1057 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
1058 goto Done;\r
1059 }\r
1060\r
1061 //\r
1062 // Select the ESC, the gCallbackKey == 0.\r
1063 //\r
1064 if(mNextShowFormId - 1 < DEVICE_MANAGER_FORM_ID) {\r
1065 mNextShowFormId = DEVICE_MANAGER_FORM_ID;\r
1066 } else {\r
d3b4af2b 1067 mNextShowFormId = (UINT16) (mNextShowFormId - 1);\r
3c4b1122 1068 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
ab4da126 1069 }\r
1070\r
3c4b1122 1071Done:\r
5c08e117 1072 //\r
7119d96a 1073 // Remove our packagelist from HII database.\r
5c08e117 1074 //\r
cb7d01c0 1075 HiiRemovePackages (HiiHandle);\r
7119d96a 1076 gDeviceManagerPrivate.HiiHandle = NULL;\r
5c08e117 1077\r
75bf9d0e
LG
1078 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1079 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
5c08e117 1080 FreePool (HiiHandles);\r
1081\r
1082 return Status;\r
1083}\r
ab4da126 1084\r
1085/**\r
1086 This function is invoked if user selected a interactive opcode from Driver Health's\r
1087 Formset. The decision by user is saved to gCallbackKey for later processing.\r
1088\r
1089 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
1090 @param Action Specifies the type of action taken by the browser.\r
1091 @param QuestionId A unique value which is sent to the original exporting driver\r
1092 so that it can identify the type of data to expect.\r
1093 @param Type The type of value for the question.\r
1094 @param Value A pointer to the data being sent to the original exporting driver.\r
1095 @param ActionRequest On return, points to the action requested by the callback function.\r
1096\r
1097 @retval EFI_SUCCESS The callback successfully handled the action.\r
1098 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r
1099\r
1100**/\r
1101EFI_STATUS\r
1102EFIAPI\r
1103DriverHealthCallback (\r
1104 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
1105 IN EFI_BROWSER_ACTION Action,\r
1106 IN EFI_QUESTION_ID QuestionId,\r
1107 IN UINT8 Type,\r
1108 IN EFI_IFR_TYPE_VALUE *Value,\r
1109 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
1110 )\r
1111{\r
4548fc2a
LG
1112 if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
1113 //\r
1114 // Do nothing for UEFI OPEN/CLOSE Action\r
1115 //\r
1116 return EFI_SUCCESS;\r
1117 }\r
1118\r
ab4da126 1119 if ((Value == NULL) || (ActionRequest == NULL)) {\r
1120 return EFI_INVALID_PARAMETER;\r
1121 }\r
1122\r
1123 gCallbackKey = QuestionId;\r
1124\r
1125 //\r
1126 // Request to exit SendForm(), so as to switch to selected form\r
1127 //\r
1128 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
1129\r
1130 return EFI_SUCCESS;\r
1131}\r
1132\r
1133/**\r
1134 Collect and display the platform's driver health relative information, allow user to do interactive \r
1135 operation while the platform is unhealthy.\r
1136\r
1137 This function display a form which divided into two parts. The one list all modules which has installed \r
1138 driver health protocol. The list usually contain driver name, controller name, and it's health info.\r
1139 While the driver name can't be retrieved, will use device path as backup. The other part of the form provide\r
1140 a choice to the user to repair all platform.\r
1141\r
1142**/\r
1143VOID\r
1144CallDriverHealth (\r
1145 VOID\r
1146 )\r
1147{\r
1148 EFI_STATUS Status; \r
1149 EFI_HII_HANDLE HiiHandle;\r
1150 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
1151 EFI_IFR_GUID_LABEL *StartLabel;\r
1152 EFI_IFR_GUID_LABEL *StartLabelRepair;\r
1153 EFI_IFR_GUID_LABEL *EndLabel;\r
1154 EFI_IFR_GUID_LABEL *EndLabelRepair;\r
1155 VOID *StartOpCodeHandle;\r
1156 VOID *EndOpCodeHandle;\r
1157 VOID *StartOpCodeHandleRepair;\r
1158 VOID *EndOpCodeHandleRepair;\r
1159 UINTN Index;\r
1160 EFI_STRING_ID Token;\r
1161 EFI_STRING_ID TokenHelp;\r
1162 EFI_STRING String;\r
1163 EFI_STRING TmpString;\r
1164 EFI_STRING DriverName;\r
1165 EFI_STRING ControllerName;\r
1166 LIST_ENTRY DriverHealthList;\r
1167 DRIVER_HEALTH_INFO *DriverHealthInfo;\r
1168 LIST_ENTRY *Link;\r
1169 EFI_DEVICE_PATH_PROTOCOL *DriverDevicePath;\r
1170 UINTN Length;\r
2fde83b1 1171 BOOLEAN RebootRequired;\r
ab4da126 1172\r
ab4da126 1173 Index = 0;\r
1174 Length = 0;\r
1175 DriverHealthInfo = NULL; \r
1176 DriverDevicePath = NULL;\r
1177 InitializeListHead (&DriverHealthList);\r
1178\r
7119d96a 1179 HiiHandle = gDeviceManagerPrivate.DriverHealthHiiHandle;\r
1180 if (HiiHandle == NULL) {\r
1181 //\r
1182 // Publish Driver Health HII data.\r
1183 //\r
1184 HiiHandle = HiiAddPackages (\r
1185 &mDeviceManagerGuid,\r
1186 gDeviceManagerPrivate.DriverHealthHandle,\r
1187 DriverHealthVfrBin,\r
1188 BdsDxeStrings,\r
1189 NULL\r
1190 );\r
1191 if (HiiHandle == NULL) {\r
1192 return;\r
1193 }\r
1194\r
1195 gDeviceManagerPrivate.DriverHealthHiiHandle = HiiHandle;\r
1196 }\r
1197\r
ab4da126 1198 //\r
1199 // Allocate space for creation of UpdateData Buffer\r
1200 //\r
1201 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1202 ASSERT (StartOpCodeHandle != NULL);\r
1203\r
1204 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1205 ASSERT (EndOpCodeHandle != NULL);\r
1206\r
1207 StartOpCodeHandleRepair = HiiAllocateOpCodeHandle ();\r
1208 ASSERT (StartOpCodeHandleRepair != NULL);\r
1209\r
1210 EndOpCodeHandleRepair = HiiAllocateOpCodeHandle ();\r
1211 ASSERT (EndOpCodeHandleRepair != NULL);\r
1212\r
1213 //\r
1214 // Create Hii Extend Label OpCode as the start opcode\r
1215 //\r
1216 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1217 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1218 StartLabel->Number = LABEL_DRIVER_HEALTH;\r
1219\r
1220 //\r
1221 // Create Hii Extend Label OpCode as the start opcode\r
1222 //\r
1223 StartLabelRepair = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandleRepair, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1224 StartLabelRepair->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1225 StartLabelRepair->Number = LABEL_DRIVER_HEALTH_REAPIR_ALL;\r
1226\r
1227 //\r
1228 // Create Hii Extend Label OpCode as the end opcode\r
1229 //\r
1230 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1231 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1232 EndLabel->Number = LABEL_DRIVER_HEALTH_END;\r
1233\r
1234 //\r
1235 // Create Hii Extend Label OpCode as the end opcode\r
1236 //\r
1237 EndLabelRepair = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandleRepair, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1238 EndLabelRepair->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1239 EndLabelRepair->Number = LABEL_DRIVER_HEALTH_REAPIR_ALL_END;\r
1240\r
1241 HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DH_STATUS_LIST), 0, 0, 1);\r
1242\r
1243 Status = GetAllControllersHealthStatus (&DriverHealthList);\r
1244 ASSERT (Status != EFI_OUT_OF_RESOURCES);\r
1245\r
1246 Link = GetFirstNode (&DriverHealthList);\r
1247\r
1248 while (!IsNull (&DriverHealthList, Link)) { \r
1249 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);\r
1250 \r
1251 //\r
1252 // Assume no line strings is longer than 512 bytes.\r
1253 //\r
1254 String = (EFI_STRING) AllocateZeroPool (0x200);\r
1255 ASSERT (String != NULL);\r
1256\r
1257 Status = DriverHealthGetDriverName (DriverHealthInfo->DriverHandle, &DriverName);\r
1258 if (EFI_ERROR (Status)) {\r
1259 //\r
1260 // Can not get the Driver name, so use the Device path\r
1261 //\r
1262 DriverDevicePath = DevicePathFromHandle (DriverHealthInfo->DriverHandle);\r
1263 DriverName = DevicePathToStr (DriverDevicePath);\r
1264 }\r
1265 //\r
1266 // Add the Driver name & Controller name into FormSetTitle string\r
1267 // \r
1268 StrnCat (String, DriverName, StrLen (DriverName));\r
1269\r
1270\r
1271 Status = DriverHealthGetControllerName (\r
1272 DriverHealthInfo->DriverHandle, \r
1273 DriverHealthInfo->ControllerHandle, \r
1274 DriverHealthInfo->ChildHandle, \r
1275 &ControllerName\r
1276 );\r
1277\r
1278 if (!EFI_ERROR (Status)) {\r
1279 //\r
1280 // Can not get the Controller name, just let it empty.\r
1281 //\r
1282 StrnCat (String, L" ", StrLen (L" "));\r
1283 StrnCat (String, ControllerName, StrLen (ControllerName)); \r
1284 }\r
1285 \r
1286 //\r
1287 // Add the message of the Module itself provided after the string item.\r
1288 //\r
1289 if ((DriverHealthInfo->MessageList != NULL) && (DriverHealthInfo->MessageList->StringId != 0)) {\r
1290 StrnCat (String, L" ", StrLen (L" "));\r
1291 TmpString = HiiGetString (\r
1292 DriverHealthInfo->MessageList->HiiHandle, \r
1293 DriverHealthInfo->MessageList->StringId, \r
1294 NULL\r
1295 );\r
ab4da126 1296 } else {\r
1297 //\r
1298 // Update the string will be displayed base on the driver's health status\r
1299 //\r
1300 switch(DriverHealthInfo->HealthStatus) {\r
1301 case EfiDriverHealthStatusRepairRequired:\r
2fde83b1 1302 TmpString = GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED));\r
ab4da126 1303 break;\r
1304 case EfiDriverHealthStatusConfigurationRequired:\r
2fde83b1 1305 TmpString = GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED));\r
ab4da126 1306 break;\r
1307 case EfiDriverHealthStatusFailed:\r
2fde83b1 1308 TmpString = GetStringById (STRING_TOKEN (STR_OPERATION_FAILED));\r
ab4da126 1309 break;\r
1310 case EfiDriverHealthStatusReconnectRequired:\r
2fde83b1 1311 TmpString = GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED));\r
ab4da126 1312 break;\r
1313 case EfiDriverHealthStatusRebootRequired:\r
2fde83b1 1314 TmpString = GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED));\r
ab4da126 1315 break;\r
1316 default:\r
2fde83b1 1317 TmpString = GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY));\r
ab4da126 1318 break;\r
1319 }\r
1320 }\r
1321\r
b70a580b
RN
1322 ASSERT (TmpString != NULL);\r
1323 StrCat (String, TmpString);\r
1324 FreePool (TmpString);\r
1325\r
ab4da126 1326 Token = HiiSetString (HiiHandle, 0, String, NULL);\r
1327 FreePool (String);\r
1328\r
1329 TokenHelp = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_SINGLE_HELP)), NULL);\r
1330\r
1331 HiiCreateActionOpCode (\r
1332 StartOpCodeHandle,\r
1333 (EFI_QUESTION_ID) (Index + DRIVER_HEALTH_KEY_OFFSET),\r
1334 Token,\r
1335 TokenHelp,\r
1336 EFI_IFR_FLAG_CALLBACK,\r
1337 0\r
1338 );\r
1339 Index++;\r
1340 Link = GetNextNode (&DriverHealthList, Link);\r
1341 }\r
1342 \r
1343 //\r
1344 // Add End Opcode for Subtitle\r
1345 // \r
1346 HiiCreateEndOpCode (StartOpCodeHandle);\r
1347\r
1348 HiiCreateSubTitleOpCode (StartOpCodeHandleRepair, STRING_TOKEN (STR_DRIVER_HEALTH_REPAIR_ALL), 0, 0, 1);\r
1349 TokenHelp = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP)), NULL); \r
1350\r
1351 if (PlaformHealthStatusCheck ()) {\r
1352 //\r
1353 // No action need to do for the platform\r
1354 //\r
1355 Token = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY)), NULL);\r
1356 HiiCreateActionOpCode (\r
1357 StartOpCodeHandleRepair,\r
1358 0,\r
1359 Token,\r
1360 TokenHelp,\r
1361 EFI_IFR_FLAG_READ_ONLY,\r
1362 0\r
1363 );\r
1364 } else {\r
1365 //\r
1366 // Create ActionOpCode only while the platform need to do health related operation.\r
1367 //\r
1368 Token = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_TITLE)), NULL);\r
1369 HiiCreateActionOpCode (\r
1370 StartOpCodeHandleRepair,\r
1371 (EFI_QUESTION_ID) DRIVER_HEALTH_REPAIR_ALL_KEY,\r
1372 Token,\r
1373 TokenHelp,\r
1374 EFI_IFR_FLAG_CALLBACK,\r
1375 0\r
1376 );\r
1377 }\r
1378\r
1379 HiiCreateEndOpCode (StartOpCodeHandleRepair);\r
1380\r
1381 Status = HiiUpdateForm (\r
1382 HiiHandle,\r
1383 &mDriverHealthGuid,\r
1384 DRIVER_HEALTH_FORM_ID,\r
1385 StartOpCodeHandle,\r
1386 EndOpCodeHandle\r
1387 );\r
1388 ASSERT (Status != EFI_NOT_FOUND);\r
1389 ASSERT (Status != EFI_BUFFER_TOO_SMALL);\r
1390\r
1391 Status = HiiUpdateForm (\r
1392 HiiHandle,\r
1393 &mDriverHealthGuid,\r
1394 DRIVER_HEALTH_FORM_ID,\r
1395 StartOpCodeHandleRepair,\r
1396 EndOpCodeHandleRepair\r
1397 );\r
1398 ASSERT (Status != EFI_NOT_FOUND);\r
1399 ASSERT (Status != EFI_BUFFER_TOO_SMALL);\r
1400\r
1401 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
1402 Status = gFormBrowser2->SendForm (\r
1403 gFormBrowser2,\r
1404 &HiiHandle,\r
1405 1,\r
1406 &mDriverHealthGuid,\r
1407 DRIVER_HEALTH_FORM_ID,\r
1408 NULL,\r
1409 &ActionRequest\r
1410 );\r
1411 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
1412 EnableResetRequired ();\r
1413 }\r
1414\r
1415 //\r
1416 // We will have returned from processing a callback - user either hit ESC to exit, or selected\r
1417 // a target to display.\r
1418 // Process the diver health status states here.\r
1419 // \r
bd2057a8 1420 if (gCallbackKey >= DRIVER_HEALTH_KEY_OFFSET && gCallbackKey != DRIVER_HEALTH_REPAIR_ALL_KEY) {\r
ab4da126 1421 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
1422\r
1423 Link = GetFirstNode (&DriverHealthList);\r
1424 Index = 0;\r
1425\r
1426 while (!IsNull (&DriverHealthList, Link)) {\r
1427 //\r
1428 // Got the item relative node in the List\r
1429 //\r
1430 if (Index == (gCallbackKey - DRIVER_HEALTH_KEY_OFFSET)) { \r
1431 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);\r
1432 //\r
1433 // Process the driver's healthy status for the specify module\r
1434 //\r
2fde83b1 1435 RebootRequired = FALSE;\r
ab4da126 1436 ProcessSingleControllerHealth (\r
1437 DriverHealthInfo->DriverHealth,\r
1438 DriverHealthInfo->ControllerHandle, \r
1439 DriverHealthInfo->ChildHandle,\r
1440 DriverHealthInfo->HealthStatus,\r
1441 &(DriverHealthInfo->MessageList),\r
2fde83b1
RN
1442 DriverHealthInfo->HiiHandle,\r
1443 &RebootRequired\r
1444 );\r
1445 if (RebootRequired) {\r
1446 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
1447 }\r
1448 break;\r
ab4da126 1449 }\r
1450 Index++;\r
1451 Link = GetNextNode (&DriverHealthList, Link);\r
1452 }\r
1453\r
1454 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
1455 EnableResetRequired ();\r
1456 }\r
1457 \r
1458 //\r
1459 // Force return to the form of Driver Health in Device Manager \r
1460 //\r
1461 gCallbackKey = DRIVER_HEALTH_RETURN_KEY;\r
1462 }\r
1463\r
1464 //\r
1465 // Repair the whole platform\r
1466 //\r
1467 if (gCallbackKey == DRIVER_HEALTH_REPAIR_ALL_KEY) {\r
1468 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
1469 \r
1470 PlatformRepairAll (&DriverHealthList);\r
1471\r
1472 gCallbackKey = DRIVER_HEALTH_RETURN_KEY;\r
1473 }\r
1474 \r
1475 //\r
7119d96a 1476 // Remove driver health packagelist from HII database.\r
ab4da126 1477 //\r
ab4da126 1478 HiiRemovePackages (HiiHandle);\r
7119d96a 1479 gDeviceManagerPrivate.DriverHealthHiiHandle = NULL;\r
ab4da126 1480\r
ab4da126 1481 //\r
1482 // Free driver health info list\r
1483 //\r
1484 while (!IsListEmpty (&DriverHealthList)) {\r
1485\r
1486 Link = GetFirstNode(&DriverHealthList);\r
1487 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);\r
1488 RemoveEntryList (Link);\r
1489\r
1490 if (DriverHealthInfo->MessageList != NULL) {\r
1491 FreePool(DriverHealthInfo->MessageList);\r
1492 FreePool (DriverHealthInfo);\r
1493 } \r
1494 }\r
1495\r
1496 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1497 HiiFreeOpCodeHandle (EndOpCodeHandle); \r
1498 HiiFreeOpCodeHandle (StartOpCodeHandleRepair);\r
1499 HiiFreeOpCodeHandle (EndOpCodeHandleRepair); \r
1500\r
1501 if (gCallbackKey == DRIVER_HEALTH_RETURN_KEY) {\r
bd2057a8 1502 //\r
1503 // Force return to Driver Health Form\r
1504 //\r
ab4da126 1505 gCallbackKey = DEVICE_MANAGER_KEY_DRIVER_HEALTH;\r
1506 CallDriverHealth ();\r
1507 }\r
ab4da126 1508}\r
1509\r
1510\r
8e8ae2da 1511/**\r
ab4da126 1512 Check the Driver Health status of a single controller and try to process it if not healthy.\r
1513\r
1514 This function called by CheckAllControllersHealthStatus () function in order to process a specify\r
1515 contoller's health state.\r
1516\r
8e8ae2da 1517 @param DriverHealthList A Pointer to the list contain all of the platform driver health information. \r
1518 @param DriverHandle The handle of driver.\r
ab4da126 1519 @param ControllerHandle The class guid specifies which form set will be displayed.\r
1520 @param ChildHandle The handle of the child controller to retrieve the health \r
8e8ae2da 1521 status on. This is an optional parameter that may be NULL. \r
1522 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.\r
ab4da126 1523 @param HealthStatus The health status of the controller.\r
ab4da126 1524\r
1525 @retval EFI_INVALID_PARAMETER HealthStatus or DriverHealth is NULL.\r
1526 @retval HealthStatus The Health status of specify controller.\r
1527 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.\r
1528 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.\r
1529 @retval EFI_SUCCESS The Health related operation has been taken successfully.\r
1530\r
8e8ae2da 1531**/\r
ab4da126 1532EFI_STATUS\r
1533EFIAPI\r
1534GetSingleControllerHealthStatus (\r
1535 IN OUT LIST_ENTRY *DriverHealthList,\r
1536 IN EFI_HANDLE DriverHandle,\r
1537 IN EFI_HANDLE ControllerHandle, OPTIONAL\r
1538 IN EFI_HANDLE ChildHandle, OPTIONAL\r
1539 IN EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth,\r
1540 IN EFI_DRIVER_HEALTH_STATUS *HealthStatus\r
1541 )\r
1542{\r
1543 EFI_STATUS Status;\r
1544 EFI_DRIVER_HEALTH_HII_MESSAGE *MessageList;\r
1545 EFI_HII_HANDLE FormHiiHandle;\r
1546 DRIVER_HEALTH_INFO *DriverHealthInfo;\r
1547\r
1548 if (HealthStatus == NULL) {\r
1549 //\r
1550 // If HealthStatus is NULL, then return EFI_INVALID_PARAMETER\r
1551 //\r
1552 return EFI_INVALID_PARAMETER;\r
1553 }\r
1554\r
1555 //\r
1556 // Assume the HealthStatus is healthy\r
1557 //\r
1558 *HealthStatus = EfiDriverHealthStatusHealthy;\r
1559\r
1560 if (DriverHealth == NULL) {\r
1561 //\r
1562 // If DriverHealth is NULL, then return EFI_INVALID_PARAMETER\r
1563 //\r
1564 return EFI_INVALID_PARAMETER;\r
1565 }\r
1566\r
1567 if (ControllerHandle == NULL) {\r
1568 //\r
1569 // If ControllerHandle is NULL, the return the cumulative health status of the driver\r
1570 //\r
1571 Status = DriverHealth->GetHealthStatus (DriverHealth, NULL, NULL, HealthStatus, NULL, NULL);\r
1572 if (*HealthStatus == EfiDriverHealthStatusHealthy) {\r
1573 //\r
1574 // Add the driver health related information into the list\r
1575 //\r
1576 DriverHealthInfo = AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO));\r
1577 if (DriverHealthInfo == NULL) {\r
1578 return EFI_OUT_OF_RESOURCES;\r
1579 }\r
1580\r
1581 DriverHealthInfo->Signature = DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE;\r
1582 DriverHealthInfo->DriverHandle = DriverHandle;\r
1583 DriverHealthInfo->ControllerHandle = NULL;\r
1584 DriverHealthInfo->ChildHandle = NULL;\r
1585 DriverHealthInfo->HiiHandle = NULL;\r
1586 DriverHealthInfo->DriverHealth = DriverHealth;\r
1587 DriverHealthInfo->MessageList = NULL;\r
1588 DriverHealthInfo->HealthStatus = *HealthStatus;\r
1589\r
1590 InsertTailList (DriverHealthList, &DriverHealthInfo->Link);\r
1591 }\r
1592 return Status;\r
1593 }\r
1594\r
1595 MessageList = NULL;\r
1596 FormHiiHandle = NULL;\r
1597\r
1598 //\r
1599 // Collect the health status with the optional HII message list\r
1600 //\r
1601 Status = DriverHealth->GetHealthStatus (DriverHealth, ControllerHandle, ChildHandle, HealthStatus, &MessageList, &FormHiiHandle);\r
1602\r
1603 if (EFI_ERROR (Status)) {\r
1604 //\r
1605 // If the health status could not be retrieved, then return immediately\r
1606 //\r
1607 return Status;\r
1608 }\r
1609\r
1610 //\r
1611 // Add the driver health related information into the list\r
1612 //\r
1613 DriverHealthInfo = AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO));\r
1614 if (DriverHealthInfo == NULL) {\r
1615 return EFI_OUT_OF_RESOURCES;\r
1616 }\r
1617\r
1618 DriverHealthInfo->Signature = DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE; \r
1619 DriverHealthInfo->DriverHandle = DriverHandle;\r
1620 DriverHealthInfo->ControllerHandle = ControllerHandle;\r
1621 DriverHealthInfo->ChildHandle = ChildHandle;\r
1622 DriverHealthInfo->HiiHandle = FormHiiHandle;\r
1623 DriverHealthInfo->DriverHealth = DriverHealth;\r
1624 DriverHealthInfo->MessageList = MessageList;\r
1625 DriverHealthInfo->HealthStatus = *HealthStatus;\r
1626\r
1627 InsertTailList (DriverHealthList, &DriverHealthInfo->Link);\r
1628\r
1629 return EFI_SUCCESS;\r
1630}\r
1631\r
1632/**\r
1633 Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database, \r
1634 and queries each EFI Driver Health Protocol to determine if one or more of the controllers \r
1635 managed by each EFI Driver Health Protocol instance are not healthy. \r
1636\r
1637 @param DriverHealthList A Pointer to the list contain all of the platform driver health\r
1638 information. \r
1639\r
1640 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.\r
1641 @retval EFI_SUCCESS All the controllers in the platform are healthy.\r
1642 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.\r
1643\r
1644**/\r
1645EFI_STATUS\r
1646GetAllControllersHealthStatus (\r
1647 IN OUT LIST_ENTRY *DriverHealthList\r
1648 )\r
1649{\r
1650 EFI_STATUS Status; \r
1651 UINTN NumHandles;\r
1652 EFI_HANDLE *DriverHealthHandles;\r
1653 EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth;\r
1654 EFI_DRIVER_HEALTH_STATUS HealthStatus;\r
1655 UINTN DriverHealthIndex;\r
1656 EFI_HANDLE *Handles;\r
1657 UINTN HandleCount;\r
1658 UINTN ControllerIndex;\r
1659 UINTN ChildIndex;\r
1660 \r
1661 //\r
1662 // Initialize local variables\r
1663 //\r
1664 Handles = NULL;\r
1665 DriverHealthHandles = NULL;\r
1666 NumHandles = 0;\r
1667 HandleCount = 0;\r
1668\r
1669 HealthStatus = EfiDriverHealthStatusHealthy;\r
1670\r
1671 Status = gBS->LocateHandleBuffer (\r
1672 ByProtocol,\r
1673 &gEfiDriverHealthProtocolGuid,\r
1674 NULL,\r
1675 &NumHandles,\r
1676 &DriverHealthHandles\r
1677 );\r
1678\r
1679 if (Status == EFI_NOT_FOUND || NumHandles == 0) {\r
1680 //\r
1681 // If there are no Driver Health Protocols handles, then return EFI_NOT_FOUND\r
1682 //\r
1683 return EFI_NOT_FOUND;\r
1684 }\r
1685\r
1686 if (EFI_ERROR (Status) || DriverHealthHandles == NULL) {\r
1687 //\r
1688 // If the list of Driver Health Protocol handles can not be retrieved, then \r
1689 // return EFI_OUT_OF_RESOURCES\r
1690 //\r
1691 return EFI_OUT_OF_RESOURCES;\r
1692 }\r
1693\r
1694 //\r
1695 // Check the health status of all controllers in the platform\r
1696 // Start by looping through all the Driver Health Protocol handles in the handle database\r
1697 //\r
1698 for (DriverHealthIndex = 0; DriverHealthIndex < NumHandles; DriverHealthIndex++) {\r
1699 //\r
1700 // Skip NULL Driver Health Protocol handles\r
1701 //\r
1702 if (DriverHealthHandles[DriverHealthIndex] == NULL) {\r
1703 continue;\r
1704 }\r
1705\r
1706 //\r
1707 // Retrieve the Driver Health Protocol from DriverHandle\r
1708 //\r
1709 Status = gBS->HandleProtocol ( \r
1710 DriverHealthHandles[DriverHealthIndex],\r
1711 &gEfiDriverHealthProtocolGuid,\r
1712 (VOID **)&DriverHealth\r
1713 );\r
1714 if (EFI_ERROR (Status)) {\r
1715 //\r
1716 // If the Driver Health Protocol can not be retrieved, then skip to the next\r
1717 // Driver Health Protocol handle\r
1718 //\r
1719 continue;\r
1720 }\r
1721\r
1722 //\r
1723 // Check the health of all the controllers managed by a Driver Health Protocol handle\r
1724 //\r
1725 Status = GetSingleControllerHealthStatus (DriverHealthList, DriverHealthHandles[DriverHealthIndex], NULL, NULL, DriverHealth, &HealthStatus);\r
1726\r
1727 //\r
1728 // If Status is an error code, then the health information could not be retrieved, so assume healthy\r
1729 // and skip to the next Driver Health Protocol handle\r
1730 //\r
1731 if (EFI_ERROR (Status)) {\r
1732 continue;\r
1733 }\r
1734\r
1735 //\r
1736 // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next \r
1737 // Driver Health Protocol handle\r
1738 //\r
1739 if (HealthStatus == EfiDriverHealthStatusHealthy) {\r
1740 continue;\r
1741 }\r
1742\r
1743 //\r
1744 // See if the list of all handles in the handle database has been retrieved\r
1745 //\r
1746 //\r
1747 if (Handles == NULL) {\r
1748 //\r
1749 // Retrieve the list of all handles from the handle database\r
1750 //\r
1751 Status = gBS->LocateHandleBuffer (\r
1752 AllHandles,\r
1753 NULL,\r
1754 NULL,\r
1755 &HandleCount,\r
1756 &Handles\r
1757 );\r
1758 if (EFI_ERROR (Status) || Handles == NULL) {\r
1759 //\r
1760 // If all the handles in the handle database can not be retrieved, then \r
1761 // return EFI_OUT_OF_RESOURCES\r
1762 //\r
1763 Status = EFI_OUT_OF_RESOURCES;\r
1764 goto Done;\r
1765 }\r
1766 }\r
1767 //\r
1768 // Loop through all the controller handles in the handle database\r
1769 //\r
1770 for (ControllerIndex = 0; ControllerIndex < HandleCount; ControllerIndex++) {\r
1771 //\r
1772 // Skip NULL controller handles\r
1773 //\r
1774 if (Handles[ControllerIndex] == NULL) {\r
1775 continue;\r
1776 }\r
1777\r
1778 Status = GetSingleControllerHealthStatus (DriverHealthList, DriverHealthHandles[DriverHealthIndex], Handles[ControllerIndex], NULL, DriverHealth, &HealthStatus);\r
1779 if (EFI_ERROR (Status)) {\r
1780 //\r
1781 // If Status is an error code, then the health information could not be retrieved, so assume healthy\r
1782 //\r
1783 HealthStatus = EfiDriverHealthStatusHealthy;\r
1784 }\r
1785\r
1786 //\r
1787 // If CheckHealthSingleController() returned an error on a terminal state, then do not check the health of child controllers\r
1788 //\r
1789 if (EFI_ERROR (Status)) {\r
1790 continue;\r
1791 }\r
1792\r
1793 //\r
1794 // Loop through all the child handles in the handle database\r
1795 //\r
1796 for (ChildIndex = 0; ChildIndex < HandleCount; ChildIndex++) {\r
1797 //\r
1798 // Skip NULL child handles\r
1799 //\r
1800 if (Handles[ChildIndex] == NULL) {\r
1801 continue;\r
1802 }\r
1803\r
1804 Status = GetSingleControllerHealthStatus (DriverHealthList, DriverHealthHandles[DriverHealthIndex], Handles[ControllerIndex], Handles[ChildIndex], DriverHealth, &HealthStatus);\r
1805 if (EFI_ERROR (Status)) {\r
1806 //\r
1807 // If Status is an error code, then the health information could not be retrieved, so assume healthy\r
1808 //\r
1809 HealthStatus = EfiDriverHealthStatusHealthy;\r
1810 }\r
1811\r
1812 //\r
1813 // If CheckHealthSingleController() returned an error on a terminal state, then skip to the next child\r
1814 //\r
1815 if (EFI_ERROR (Status)) {\r
1816 continue;\r
1817 }\r
1818 }\r
1819 }\r
1820 }\r
1821\r
1822 Status = EFI_SUCCESS;\r
1823\r
1824Done:\r
1825 if (Handles != NULL) {\r
1826 gBS->FreePool (Handles);\r
1827 }\r
1828 if (DriverHealthHandles != NULL) {\r
1829 gBS->FreePool (DriverHealthHandles);\r
1830 }\r
1831\r
1832 return Status;\r
1833}\r
1834\r
1835\r
8e8ae2da 1836/**\r
ab4da126 1837 Check the healthy status of the platform, this function will return immediately while found one driver \r
1838 in the platform are not healthy.\r
1839\r
1840 @retval FALSE at least one driver in the platform are not healthy.\r
1841 @retval TRUE No controller install Driver Health Protocol,\r
1842 or all controllers in the platform are in healthy status.\r
8e8ae2da 1843**/\r
ab4da126 1844BOOLEAN\r
1845PlaformHealthStatusCheck (\r
1846 VOID\r
1847 )\r
1848{\r
1849 EFI_DRIVER_HEALTH_STATUS HealthStatus;\r
1850 EFI_STATUS Status;\r
1851 UINTN Index;\r
1852 UINTN NoHandles;\r
1853 EFI_HANDLE *DriverHealthHandles;\r
1854 EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth;\r
1855 BOOLEAN AllHealthy;\r
1856\r
1857 //\r
1858 // Initialize local variables\r
1859 //\r
1860 DriverHealthHandles = NULL;\r
1861 DriverHealth = NULL;\r
1862\r
1863 HealthStatus = EfiDriverHealthStatusHealthy;\r
1864\r
1865 Status = gBS->LocateHandleBuffer (\r
1866 ByProtocol,\r
1867 &gEfiDriverHealthProtocolGuid,\r
1868 NULL,\r
1869 &NoHandles,\r
1870 &DriverHealthHandles\r
1871 );\r
1872 //\r
1873 // There are no handles match the search for Driver Health Protocol has been installed.\r
1874 //\r
1875 if (Status == EFI_NOT_FOUND) {\r
1876 return TRUE;\r
1877 }\r
1878 //\r
1879 // Assume all modules are healthy.\r
1880 // \r
1881 AllHealthy = TRUE;\r
1882\r
1883 //\r
1884 // Found one or more Handles.\r
1885 //\r
1886 if (!EFI_ERROR (Status)) { \r
1887 for (Index = 0; Index < NoHandles; Index++) {\r
1888 Status = gBS->HandleProtocol (\r
1889 DriverHealthHandles[Index],\r
1890 &gEfiDriverHealthProtocolGuid,\r
1891 (VOID **) &DriverHealth\r
1892 );\r
1893 if (!EFI_ERROR (Status)) {\r
1894 Status = DriverHealth->GetHealthStatus (\r
1895 DriverHealth,\r
1896 NULL,\r
1897 NULL,\r
1898 &HealthStatus,\r
1899 NULL,\r
1900 NULL\r
1901 );\r
1902 }\r
1903 //\r
1904 // Get the healthy status of the module\r
1905 //\r
1906 if (!EFI_ERROR (Status)) {\r
1907 if (HealthStatus != EfiDriverHealthStatusHealthy) {\r
1908 //\r
1909 // Return immediately one driver's status not in healthy.\r
1910 //\r
1911 return FALSE; \r
1912 }\r
1913 }\r
1914 }\r
1915 }\r
1916 return AllHealthy;\r
1917}\r
1918\r
1919/**\r
1920 Processes a single controller using the EFI Driver Health Protocol associated with \r
1921 that controller. This algorithm continues to query the GetHealthStatus() service until\r
1922 one of the legal terminal states of the EFI Driver Health Protocol is reached. This may \r
1923 require the processing of HII Messages, HII Form, and invocation of repair operations.\r
1924\r
1925 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.\r
1926 @param ControllerHandle The class guid specifies which form set will be displayed.\r
1927 @param ChildHandle The handle of the child controller to retrieve the health \r
1928 status on. This is an optional parameter that may be NULL. \r
1929 @param HealthStatus The health status of the controller.\r
1930 @param MessageList An array of warning or error messages associated \r
1931 with the controller specified by ControllerHandle and \r
1932 ChildHandle. This is an optional parameter that may be NULL.\r
1933 @param FormHiiHandle The HII handle for an HII form associated with the \r
1934 controller specified by ControllerHandle and ChildHandle.\r
2fde83b1 1935 @param RebootRequired Indicate whether a reboot is required to repair the controller.\r
ab4da126 1936**/\r
1937VOID\r
1938ProcessSingleControllerHealth (\r
2fde83b1
RN
1939 IN EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth,\r
1940 IN EFI_HANDLE ControllerHandle, OPTIONAL\r
1941 IN EFI_HANDLE ChildHandle, OPTIONAL\r
1942 IN EFI_DRIVER_HEALTH_STATUS HealthStatus,\r
1943 IN EFI_DRIVER_HEALTH_HII_MESSAGE **MessageList, OPTIONAL\r
1944 IN EFI_HII_HANDLE FormHiiHandle,\r
1945 IN OUT BOOLEAN *RebootRequired\r
ab4da126 1946 )\r
1947{\r
1948 EFI_STATUS Status;\r
1949 EFI_DRIVER_HEALTH_STATUS LocalHealthStatus;\r
1950 \r
1951 LocalHealthStatus = HealthStatus;\r
1952 //\r
1953 // If the module need to be repaired or reconfiguration, will process it until\r
1954 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair \r
1955 // will be in (Health, Failed, Configuration Required).\r
1956 //\r
2fde83b1
RN
1957 while(LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired ||\r
1958 LocalHealthStatus == EfiDriverHealthStatusRepairRequired) {\r
ab4da126 1959\r
1960 if (LocalHealthStatus == EfiDriverHealthStatusRepairRequired) {\r
1961 Status = DriverHealth->Repair (\r
1962 DriverHealth,\r
1963 ControllerHandle,\r
1964 ChildHandle,\r
1965 (EFI_DRIVER_HEALTH_REPAIR_PROGRESS_NOTIFY) RepairNotify\r
1966 );\r
1967 }\r
1968 //\r
1969 // Via a form of the driver need to do configuration provided to process of status in \r
1970 // EfiDriverHealthStatusConfigurationRequired. The status after configuration should be in\r
1971 // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required). \r
1972 //\r
1973 if (LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired) {\r
2fde83b1
RN
1974 if (FormHiiHandle != NULL) {\r
1975 Status = gFormBrowser2->SendForm (\r
1976 gFormBrowser2,\r
1977 &FormHiiHandle,\r
1978 1,\r
1979 &gEfiHiiDriverHealthFormsetGuid,\r
1980 0,\r
1981 NULL,\r
1982 NULL\r
1983 );\r
1984 ASSERT( !EFI_ERROR (Status));\r
1985 } else {\r
1986 //\r
1987 // Exit the loop in case no FormHiiHandle is supplied to prevent dead-loop\r
1988 //\r
1989 break;\r
1990 }\r
ab4da126 1991 }\r
1992\r
1993 Status = DriverHealth->GetHealthStatus (\r
1994 DriverHealth,\r
1995 ControllerHandle,\r
1996 ChildHandle,\r
1997 &LocalHealthStatus,\r
1998 NULL,\r
1999 &FormHiiHandle\r
2000 );\r
2fde83b1 2001 ASSERT_EFI_ERROR (Status);\r
ab4da126 2002\r
2fde83b1 2003 if (*MessageList != NULL) {\r
ab4da126 2004 ProcessMessages (*MessageList);\r
2fde83b1 2005 } \r
ab4da126 2006 }\r
2007 \r
2008 //\r
2009 // Health status in {Healthy, Failed} may also have Messages need to process\r
2010 //\r
2011 if (LocalHealthStatus == EfiDriverHealthStatusHealthy || LocalHealthStatus == EfiDriverHealthStatusFailed) {\r
2012 if (*MessageList != NULL) {\r
2013 ProcessMessages (*MessageList);\r
2014 }\r
2015 }\r
2016 //\r
2017 // Check for RebootRequired or ReconnectRequired\r
2018 //\r
2019 if (LocalHealthStatus == EfiDriverHealthStatusRebootRequired) {\r
2fde83b1 2020 *RebootRequired = TRUE;\r
ab4da126 2021 }\r
2022 \r
2023 //\r
2024 // Do reconnect if need.\r
2025 //\r
2026 if (LocalHealthStatus == EfiDriverHealthStatusReconnectRequired) {\r
2027 Status = gBS->DisconnectController (ControllerHandle, NULL, NULL);\r
2028 if (EFI_ERROR (Status)) {\r
2fde83b1
RN
2029 //\r
2030 // Disconnect failed. Need to promote reconnect to a reboot.\r
2031 //\r
2032 *RebootRequired = TRUE;\r
2033 } else {\r
2034 gBS->ConnectController (ControllerHandle, NULL, NULL, TRUE);\r
ab4da126 2035 }\r
ab4da126 2036 }\r
2037}\r
2038\r
2039\r
2040/**\r
2041 Platform specific notification function for controller repair operations.\r
2042\r
2043 If the driver for a controller support the Driver Health Protocol and the\r
2044 current state of the controller is EfiDriverHealthStatusRepairRequired then\r
2045 when the Repair() service of the Driver Health Protocol is called, this \r
2046 platform specific notification function can display the progress of the repair\r
2047 operation. Some platforms may choose to not display anything, other may choose\r
2048 to show the percentage complete on text consoles, and other may choose to render\r
2049 a progress bar on text and graphical consoles.\r
2050\r
2051 This function displays the percentage of the repair operation that has been\r
2052 completed on text consoles. The percentage is Value / Limit * 100%.\r
2053 \r
2054 @param Value Value in the range 0..Limit the the repair has completed..\r
2055 @param Limit The maximum value of Value\r
2056\r
2057**/\r
2058VOID\r
2059RepairNotify (\r
2060 IN UINTN Value,\r
2061 IN UINTN Limit\r
2062 )\r
2063{\r
2064 UINTN Percent;\r
2065\r
2066 if (Limit == 0) {\r
2067 Print(L"Repair Progress Undefined\n\r");\r
2068 } else {\r
2069 Percent = Value * 100 / Limit;\r
2070 Print(L"Repair Progress = %3d%%\n\r", Percent);\r
2071 }\r
2072}\r
2073\r
2074/**\r
2075 Processes a set of messages returned by the GetHealthStatus ()\r
2076 service of the EFI Driver Health Protocol\r
2077\r
2078 @param MessageList The MessageList point to messages need to processed. \r
2079\r
2080**/\r
2081VOID\r
2082ProcessMessages (\r
2083 IN EFI_DRIVER_HEALTH_HII_MESSAGE *MessageList\r
2084 )\r
2085{\r
2086 UINTN MessageIndex;\r
2087 EFI_STRING MessageString;\r
2088\r
2089 for (MessageIndex = 0;\r
2090 MessageList[MessageIndex].HiiHandle != NULL;\r
2091 MessageIndex++) {\r
2092\r
2093 MessageString = HiiGetString (\r
2094 MessageList[MessageIndex].HiiHandle,\r
2095 MessageList[MessageIndex].StringId,\r
2096 NULL\r
2097 );\r
2098 if (MessageString != NULL) {\r
2099 //\r
2100 // User can customize the output. Just simply print out the MessageString like below. \r
2101 // Also can use the HiiHandle to display message on the front page.\r
2102 // \r
2103 // Print(L"%s\n",MessageString);\r
2104 // gBS->Stall (100000);\r
2105 }\r
2106 }\r
2107\r
2108}\r
2109\r
8e8ae2da 2110/**\r
ab4da126 2111 Repair the whole platform.\r
2112\r
2113 This function is the main entry for user choose "Repair All" in the front page.\r
2114 It will try to do recovery job till all the driver health protocol installed modules \r
2115 reach a terminal state.\r
2116\r
2117 @param DriverHealthList A Pointer to the list contain all of the platform driver health\r
2118 information.\r
2119\r
8e8ae2da 2120**/\r
ab4da126 2121VOID\r
2122PlatformRepairAll (\r
2123 IN LIST_ENTRY *DriverHealthList\r
2124 )\r
2125{ \r
2126 DRIVER_HEALTH_INFO *DriverHealthInfo;\r
2127 LIST_ENTRY *Link;\r
2fde83b1 2128 BOOLEAN RebootRequired;\r
ab4da126 2129\r
2130 ASSERT (DriverHealthList != NULL);\r
2131\r
2fde83b1 2132 RebootRequired = FALSE;\r
ab4da126 2133\r
2fde83b1
RN
2134 for ( Link = GetFirstNode (DriverHealthList)\r
2135 ; !IsNull (DriverHealthList, Link)\r
2136 ; Link = GetNextNode (DriverHealthList, Link)\r
2137 ) {\r
ab4da126 2138 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);\r
2139 //\r
2140 // Do driver health status operation by each link node\r
2141 //\r
2142 ASSERT (DriverHealthInfo != NULL);\r
2143\r
2144 ProcessSingleControllerHealth ( \r
2fde83b1
RN
2145 DriverHealthInfo->DriverHealth,\r
2146 DriverHealthInfo->ControllerHandle,\r
2147 DriverHealthInfo->ChildHandle,\r
2148 DriverHealthInfo->HealthStatus,\r
2149 &(DriverHealthInfo->MessageList),\r
2150 DriverHealthInfo->HiiHandle,\r
2151 &RebootRequired\r
2152 );\r
2153 }\r
ab4da126 2154\r
2fde83b1
RN
2155 if (RebootRequired) {\r
2156 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
ab4da126 2157 }\r
2158}\r
2159\r
2160/**\r
2161\r
2162 Select the best matching language according to front page policy for best user experience. \r
2163 \r
2164 This function supports both ISO 639-2 and RFC 4646 language codes, but language \r
2165 code types may not be mixed in a single call to this function. \r
2166\r
2167 @param SupportedLanguages A pointer to a Null-terminated ASCII string that\r
2168 contains a set of language codes in the format \r
2169 specified by Iso639Language.\r
2170 @param Iso639Language If TRUE, then all language codes are assumed to be\r
2171 in ISO 639-2 format. If FALSE, then all language\r
2172 codes are assumed to be in RFC 4646 language format.\r
2173\r
2174 @retval NULL The best matching language could not be found in SupportedLanguages.\r
2175 @retval NULL There are not enough resources available to return the best matching \r
2176 language.\r
2177 @retval Other A pointer to a Null-terminated ASCII string that is the best matching \r
2178 language in SupportedLanguages.\r
2179**/\r
2180CHAR8 *\r
2181DriverHealthSelectBestLanguage (\r
2182 IN CHAR8 *SupportedLanguages,\r
2183 IN BOOLEAN Iso639Language\r
2184 )\r
2185{\r
2186 CHAR8 *LanguageVariable;\r
2187 CHAR8 *BestLanguage;\r
2188\r
2189 LanguageVariable = GetEfiGlobalVariable (Iso639Language ? L"Lang" : L"PlatformLang");\r
2190\r
2191 BestLanguage = GetBestLanguage(\r
2192 SupportedLanguages,\r
2193 Iso639Language,\r
2194 (LanguageVariable != NULL) ? LanguageVariable : "",\r
2195 Iso639Language ? "eng" : "en-US",\r
2196 NULL\r
2197 );\r
2198 if (LanguageVariable != NULL) {\r
2199 FreePool (LanguageVariable);\r
2200 }\r
2201\r
2202 return BestLanguage;\r
2203}\r
2204\r
2205\r
2206\r
2207/**\r
2208\r
2209 This is an internal worker function to get the Component Name (2) protocol interface\r
2210 and the language it supports.\r
2211\r
2212 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.\r
2213 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.\r
2214 @param ComponentName A pointer to the Component Name (2) protocol interface.\r
2215 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the \r
2216 located Component Name (2) instance.\r
2217\r
8e8ae2da 2218 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find\r
ab4da126 2219 the best matching language it support.\r
8e8ae2da 2220 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.\r
2221 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding\r
ab4da126 2222 the supported language.\r
2223\r
2224**/\r
2225EFI_STATUS\r
2226GetComponentNameWorker (\r
2227 IN EFI_GUID *ProtocolGuid,\r
2228 IN EFI_HANDLE DriverBindingHandle,\r
2229 OUT EFI_COMPONENT_NAME_PROTOCOL **ComponentName,\r
2230 OUT CHAR8 **SupportedLanguage\r
2231 )\r
2232{\r
2233 EFI_STATUS Status;\r
2234\r
2235 //\r
2236 // Locate Component Name (2) protocol on the driver binging handle.\r
2237 //\r
2238 Status = gBS->OpenProtocol (\r
2239 DriverBindingHandle,\r
2240 ProtocolGuid,\r
2241 (VOID **) ComponentName,\r
2242 NULL,\r
2243 NULL,\r
2244 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
2245 );\r
2246 if (EFI_ERROR (Status)) {\r
2247 return Status;\r
2248 }\r
2249\r
2250 //\r
2251 // Apply shell policy to select the best language.\r
2252 //\r
2253 *SupportedLanguage = DriverHealthSelectBestLanguage (\r
2254 (*ComponentName)->SupportedLanguages,\r
2255 (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid)\r
2256 );\r
2257 if (*SupportedLanguage == NULL) {\r
2258 Status = EFI_UNSUPPORTED;\r
2259 }\r
2260\r
2261 return Status;\r
2262}\r
2263\r
2264/**\r
2265\r
2266 This is an internal worker function to get driver name from Component Name (2) protocol interface.\r
2267\r
2268\r
2269 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.\r
2270 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.\r
2271 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name\r
2272 of the driver specified by This.\r
2273\r
2274 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol\r
2275 interface.\r
2276 @retval Other The driver name cannot be retrieved from Component Name (2) protocol\r
2277 interface.\r
2278\r
2279**/\r
2280EFI_STATUS\r
2281GetDriverNameWorker (\r
2282 IN EFI_GUID *ProtocolGuid,\r
2283 IN EFI_HANDLE DriverBindingHandle,\r
2284 OUT CHAR16 **DriverName\r
2285 )\r
2286{\r
2287 EFI_STATUS Status;\r
2288 CHAR8 *BestLanguage;\r
2289 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;\r
2290\r
2291 //\r
2292 // Retrieve Component Name (2) protocol instance on the driver binding handle and \r
2293 // find the best language this instance supports. \r
2294 //\r
2295 Status = GetComponentNameWorker (\r
2296 ProtocolGuid,\r
2297 DriverBindingHandle,\r
2298 &ComponentName,\r
2299 &BestLanguage\r
2300 );\r
2301 if (EFI_ERROR (Status)) {\r
2302 return Status;\r
2303 }\r
2304 \r
2305 //\r
2306 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.\r
2307 //\r
2308 Status = ComponentName->GetDriverName (\r
2309 ComponentName,\r
2310 BestLanguage,\r
2311 DriverName\r
2312 );\r
2313 FreePool (BestLanguage);\r
2314 \r
2315 return Status;\r
2316}\r
2317\r
2318/**\r
2319\r
2320 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface\r
2321 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.\r
2322 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward\r
2323 compatibility support. \r
2324\r
2325 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.\r
2326 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name\r
2327 of the driver specified by This.\r
2328\r
2329 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol\r
2330 interface.\r
2331 @retval Other The driver name cannot be retrieved from Component Name (2) protocol\r
2332 interface.\r
2333\r
2334**/\r
2335EFI_STATUS\r
2336DriverHealthGetDriverName (\r
2337 IN EFI_HANDLE DriverBindingHandle,\r
2338 OUT CHAR16 **DriverName\r
2339 )\r
2340{\r
2341 EFI_STATUS Status;\r
2342\r
2343 //\r
2344 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.\r
2345 //\r
2346 Status = GetDriverNameWorker (&gEfiComponentName2ProtocolGuid, DriverBindingHandle, DriverName);\r
2347 if (EFI_ERROR (Status)) {\r
2348 //\r
2349 // If it fails to get the driver name from Component Name protocol interface, we should fall back on\r
2350 // EFI 1.1 Component Name protocol interface.\r
2351 //\r
2352 Status = GetDriverNameWorker (&gEfiComponentNameProtocolGuid, DriverBindingHandle, DriverName);\r
2353 }\r
2354\r
2355 return Status;\r
2356}\r
2357\r
2358\r
2359\r
2360/**\r
2361 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface\r
2362 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.\r
2363 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward\r
2364 compatibility support. \r
2365\r
2366 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.\r
2367 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.\r
2368 @param ControllerHandle The handle of a controller that the driver specified by This is managing.\r
2369 This handle specifies the controller whose name is to be returned.\r
2370 @param ChildHandle The handle of the child controller to retrieve the name of. This is an\r
2371 optional parameter that may be NULL. It will be NULL for device drivers.\r
2372 It will also be NULL for bus drivers that attempt to retrieve the name\r
2373 of the bus controller. It will not be NULL for a bus driver that attempts\r
2374 to retrieve the name of a child controller.\r
2375 @param ControllerName A pointer to the Unicode string to return. This Unicode string\r
2376 is the name of the controller specified by ControllerHandle and ChildHandle.\r
2377\r
2378 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol\r
2379 interface.\r
2380 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.\r
2381\r
2382**/\r
2383EFI_STATUS\r
2384GetControllerNameWorker (\r
2385 IN EFI_GUID *ProtocolGuid,\r
2386 IN EFI_HANDLE DriverBindingHandle,\r
2387 IN EFI_HANDLE ControllerHandle,\r
2388 IN EFI_HANDLE ChildHandle,\r
2389 OUT CHAR16 **ControllerName\r
2390 )\r
2391{\r
2392 EFI_STATUS Status;\r
2393 CHAR8 *BestLanguage;\r
2394 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;\r
2395\r
2396 //\r
2397 // Retrieve Component Name (2) protocol instance on the driver binding handle and \r
2398 // find the best language this instance supports. \r
2399 //\r
2400 Status = GetComponentNameWorker (\r
2401 ProtocolGuid,\r
2402 DriverBindingHandle,\r
2403 &ComponentName,\r
2404 &BestLanguage\r
2405 );\r
2406 if (EFI_ERROR (Status)) {\r
2407 return Status;\r
2408 }\r
2409\r
2410 //\r
2411 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.\r
2412 //\r
2413 Status = ComponentName->GetControllerName (\r
2414 ComponentName,\r
2415 ControllerHandle,\r
2416 ChildHandle,\r
2417 BestLanguage,\r
2418 ControllerName\r
2419 );\r
2420 FreePool (BestLanguage);\r
2421\r
2422 return Status;\r
2423}\r
2424\r
2425/**\r
2426\r
2427 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface\r
2428 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name. \r
2429 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward\r
2430 compatibility support. \r
2431\r
2432 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.\r
2433 @param ControllerHandle The handle of a controller that the driver specified by This is managing.\r
2434 This handle specifies the controller whose name is to be returned.\r
2435 @param ChildHandle The handle of the child controller to retrieve the name of. This is an\r
2436 optional parameter that may be NULL. It will be NULL for device drivers.\r
2437 It will also be NULL for bus drivers that attempt to retrieve the name\r
2438 of the bus controller. It will not be NULL for a bus driver that attempts\r
2439 to retrieve the name of a child controller.\r
ab4da126 2440 @param ControllerName A pointer to the Unicode string to return. This Unicode string\r
2441 is the name of the controller specified by ControllerHandle and ChildHandle.\r
2442\r
2443 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol\r
2444 interface.\r
2445 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.\r
2446\r
2447**/\r
2448EFI_STATUS\r
2449DriverHealthGetControllerName (\r
2450 IN EFI_HANDLE DriverBindingHandle,\r
2451 IN EFI_HANDLE ControllerHandle,\r
2452 IN EFI_HANDLE ChildHandle,\r
2453 OUT CHAR16 **ControllerName\r
2454 )\r
2455{\r
2456 EFI_STATUS Status;\r
2457\r
2458 //\r
2459 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.\r
2460 //\r
2461 Status = GetControllerNameWorker (\r
2462 &gEfiComponentName2ProtocolGuid,\r
2463 DriverBindingHandle,\r
2464 ControllerHandle,\r
2465 ChildHandle,\r
2466 ControllerName\r
2467 );\r
2468 if (EFI_ERROR (Status)) {\r
2469 //\r
2470 // If it fails to get the controller name from Component Name protocol interface, we should fall back on\r
2471 // EFI 1.1 Component Name protocol interface.\r
2472 //\r
2473 Status = GetControllerNameWorker (\r
2474 &gEfiComponentNameProtocolGuid,\r
2475 DriverBindingHandle,\r
2476 ControllerHandle,\r
2477 ChildHandle,\r
2478 ControllerName\r
2479 );\r
2480 }\r
2481\r
2482 return Status;\r
2483}\r