X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=IntelFrameworkModulePkg%2FUniversal%2FBdsDxe%2FDeviceMngr%2FDeviceManager.c;h=6cb9d6b7ab07de5da771e4f26c430822a03a860e;hp=30be2b59b5a32a46beb003a7bf64b80ef7148dc1;hb=847240774030f9da79140a9d515a64ec817eb6eb;hpb=32e9da0c40cef1bc9a8e7701af0ae513a0e1b3fb diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c index 30be2b59b5..6cb9d6b7ab 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c @@ -1,8 +1,8 @@ /** @file The platform device manager reference implementation -Copyright (c) 2004 - 2010, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -32,8 +32,23 @@ DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = { } }; -EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID; -EFI_GUID mDriverHealthGuid = DRIVER_HEALTH_FORMSET_GUID; +#define MAX_MAC_ADDRESS_NODE_LIST_LEN 10 + +// +// Which Mac Address string is select +// it will decide what menu need to show in the NETWORK_DEVICE_FORM_ID form. +// +EFI_STRING mSelectedMacAddrString; + +// +// Which form Id need to be show. +// +EFI_FORM_ID mNextShowFormId = DEVICE_MANAGER_FORM_ID; + +// +// The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID +// +MAC_ADDRESS_NODE_LIST mMacDeviceList; DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable[] = { { STRING_TOKEN (STR_DISK_DEVICE), EFI_DISK_DEVICE_CLASS }, @@ -54,10 +69,7 @@ HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = { (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, - // - // {102579A0-3686-466e-ACD8-80C087044F4A} - // - { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } } + DEVICE_MANAGER_FORMSET_GUID }, { END_DEVICE_PATH_TYPE, @@ -79,10 +91,7 @@ HII_VENDOR_DEVICE_PATH mDriverHealthHiiVendorDevicePath = { (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, - // - // {D8F76651-1675-4986-BED4-3824B2F1F4C8} - // - { 0xd8f76651, 0x1675, 0x4986, { 0xbe, 0xd4, 0x38, 0x24, 0xb2, 0xf1, 0xf4, 0xc8 } } + DRIVER_HEALTH_FORMSET_GUID }, { END_DEVICE_PATH_TYPE, @@ -122,16 +131,30 @@ DeviceManagerCallback ( OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest ) { - if ((Value == NULL) || (ActionRequest == NULL)) { + UINTN CurIndex; + + if (Action != EFI_BROWSER_ACTION_CHANGING) { + // + // All other action return unsupported. + // + return EFI_UNSUPPORTED; + } + + if (Value == NULL) { return EFI_INVALID_PARAMETER; } gCallbackKey = QuestionId; - - // - // Request to exit SendForm(), so as to switch to selected form - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT; + if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) { + // + // If user select the mac address, need to record mac address string to support next form show. + // + for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) { + if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) { + mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL); + } + } + } return EFI_SUCCESS; } @@ -174,37 +197,8 @@ InitializeDeviceManager ( ); ASSERT_EFI_ERROR (Status); - // - // Publish our HII data - // - gDeviceManagerPrivate.HiiHandle = HiiAddPackages ( - &mDeviceManagerGuid, - gDeviceManagerPrivate.DriverHandle, - DeviceManagerVfrBin, - BdsDxeStrings, - NULL - ); - if (gDeviceManagerPrivate.HiiHandle == NULL) { - return EFI_OUT_OF_RESOURCES; - } else { - Status = EFI_SUCCESS; - } - - // - // Publish Driver Health HII data - // - gDeviceManagerPrivate.DriverHealthHiiHandle = HiiAddPackages ( - &mDeviceManagerGuid, - gDeviceManagerPrivate.DriverHealthHandle, - DriverHealthVfrBin, - BdsDxeStrings, - NULL - ); - if (gDeviceManagerPrivate.DriverHealthHiiHandle == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = EFI_SUCCESS; - } + mMacDeviceList.CurListLen = 0; + mMacDeviceList.MaxListLen = 0; return Status; } @@ -298,7 +292,7 @@ ExtractDisplayedHiiFormFromHiiHandle ( // // Find FormSet OpCode // - ClassGuidNum = ((EFI_IFR_FORM_SET *) OpCodeData)->Flags & 0x3; + ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *) OpCodeData)->Flags & 0x3); ClassGuid = (EFI_GUID *) (VOID *)(OpCodeData + sizeof (EFI_IFR_FORM_SET)); while (ClassGuidNum-- > 0) { if (CompareGuid (SetupClassGuid, ClassGuid)) { @@ -335,6 +329,376 @@ ExtractDisplayedHiiFormFromHiiHandle ( return FALSE; } +/** + Get the mac address string from the device path. + if the device path has the vlan, get the vanid also. + + @param MacAddressNode Device path begin with mac address + @param PBuffer Output string buffer contain mac address. + +**/ +BOOLEAN +GetMacAddressString( + IN MAC_ADDR_DEVICE_PATH *MacAddressNode, + OUT CHAR16 **PBuffer + ) +{ + UINTN HwAddressSize; + UINTN Index; + UINT8 *HwAddress; + EFI_DEVICE_PATH_PROTOCOL *Node; + UINT16 VlanId; + CHAR16 *String; + UINTN BufferLen; + + VlanId = 0; + String = NULL; + ASSERT(MacAddressNode != NULL); + + HwAddressSize = sizeof (EFI_MAC_ADDRESS); + if (MacAddressNode->IfType == 0x01 || MacAddressNode->IfType == 0x00) { + HwAddressSize = 6; + } + + // + // The output format is MAC:XX:XX:XX:...\XXXX + // The size is the Number size + ":" size + Vlan size(\XXXX) + End + // + BufferLen = (4 + 2 * HwAddressSize + (HwAddressSize - 1) + 5 + 1) * sizeof (CHAR16); + String = AllocateZeroPool (BufferLen); + if (String == NULL) { + return FALSE; + } + + *PBuffer = String; + StrCpy(String, L"MAC:"); + String += 4; + + // + // Convert the MAC address into a unicode string. + // + HwAddress = &MacAddressNode->MacAddress.Addr[0]; + for (Index = 0; Index < HwAddressSize; Index++) { + String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2); + if (Index < HwAddressSize - 1) { + *String++ = L':'; + } + } + + // + // If VLAN is configured, it will need extra 5 characters like "\0005". + // Plus one unicode character for the null-terminator. + // + Node = (EFI_DEVICE_PATH_PROTOCOL *)MacAddressNode; + while (!IsDevicePathEnd (Node)) { + if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) { + VlanId = ((VLAN_DEVICE_PATH *) Node)->VlanId; + } + Node = NextDevicePathNode (Node); + } + + if (VlanId != 0) { + *String++ = L'\\'; + String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4); + } + + // + // Null terminate the Unicode string + // + *String = L'\0'; + + return TRUE; +} + +/** + Save question id and prompt id to the mac device list. + If the same mac address has saved yet, no need to add more. + + @param MacAddrString Mac address string. + + @retval EFI_SUCCESS Add the item is successful. + @return Other values if failed to Add the item. +**/ +BOOLEAN +AddIdToMacDeviceList ( + IN EFI_STRING MacAddrString + ) +{ + MENU_INFO_ITEM *TempDeviceList; + UINTN Index; + EFI_STRING StoredString; + EFI_STRING_ID PromptId; + EFI_HII_HANDLE HiiHandle; + + HiiHandle = gDeviceManagerPrivate.HiiHandle; + TempDeviceList = NULL; + + for (Index = 0; Index < mMacDeviceList.CurListLen; Index ++) { + StoredString = HiiGetString (HiiHandle, mMacDeviceList.NodeList[Index].PromptId, NULL); + if (StoredString == NULL) { + return FALSE; + } + + // + // Already has save the same mac address to the list. + // + if (StrCmp (MacAddrString, StoredString) == 0) { + return FALSE; + } + } + + PromptId = HiiSetString(HiiHandle, 0, MacAddrString, NULL); + // + // If not in the list, save it. + // + if (mMacDeviceList.MaxListLen > mMacDeviceList.CurListLen + 1) { + mMacDeviceList.NodeList[mMacDeviceList.CurListLen].PromptId = PromptId; + mMacDeviceList.NodeList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET); + } else { + mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN; + if (mMacDeviceList.CurListLen != 0) { + TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList); + } else { + TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen); + } + + if (TempDeviceList == NULL) { + return FALSE; + } + TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId; + TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET); + + if (mMacDeviceList.CurListLen > 0) { + FreePool(mMacDeviceList.NodeList); + } + + mMacDeviceList.NodeList = TempDeviceList; + } + mMacDeviceList.CurListLen ++; + + return TRUE; +} + +/** + Check the devcie path, try to find whether it has mac address path. + + In this function, first need to check whether this path has mac address path. + second, when the mac address device path has find, also need to deicide whether + need to add this mac address relate info to the menu. + + @param *Node Input device which need to be check. + @param *NeedAddItem Whether need to add the menu in the network device list. + + @retval TRUE Has mac address device path. + @retval FALSE NOT Has mac address device path. + +**/ +BOOLEAN +IsMacAddressDevicePath ( + IN VOID *Node, + OUT BOOLEAN *NeedAddItem + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + CHAR16 *Buffer; + BOOLEAN ReturnVal; + + ASSERT (Node != NULL); + *NeedAddItem = FALSE; + ReturnVal = FALSE; + Buffer = NULL; + + DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node; + + // + // find the partition device path node + // + while (!IsDevicePathEnd (DevicePath)) { + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) { + ReturnVal = TRUE; + + if (DEVICE_MANAGER_FORM_ID == mNextShowFormId) { + *NeedAddItem = TRUE; + break; + } + + if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) { + break; + } + + if (NETWORK_DEVICE_FORM_ID == mNextShowFormId) { + if (StrCmp (Buffer, mSelectedMacAddrString) == 0) { + *NeedAddItem = TRUE; + } + break; + } + + if (NETWORK_DEVICE_LIST_FORM_ID == mNextShowFormId) { + // + // Same handle may has two network child handle, so the questionid + // has the offset of SAME_HANDLE_KEY_OFFSET. + // + if (AddIdToMacDeviceList (Buffer)) { + *NeedAddItem = TRUE; + } + break; + } + } + DevicePath = NextDevicePathNode (DevicePath); + } + + if (Buffer != NULL) { + FreePool (Buffer); + } + + return ReturnVal; +} + +/** + Check to see if the device path is for the network device. + + @param Handle The HII handle which include the mac address device path. + @param ItemCount The new add Mac address item count. + + @retval TRUE Need to add new item in the menu. + @return FALSE Do not need to add the menu about the network. + +**/ +BOOLEAN +IsNeedAddNetworkMenu ( + IN EFI_HII_HANDLE Handle, + OUT UINTN *ItemCount + ) +{ + EFI_STATUS Status; + UINTN EntryCount; + UINTN Index; + EFI_HANDLE DriverHandle; + EFI_HANDLE ControllerHandle; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath; + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; + BOOLEAN IsNeedAdd; + + IsNeedAdd = FALSE; + OpenInfoBuffer = NULL; + if ((Handle == NULL) || (ItemCount == NULL)) { + return FALSE; + } + *ItemCount = 0; + + Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle); + if (EFI_ERROR (Status)) { + return FALSE; + } + // + // Get the device path by the got Driver handle . + // + Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath); + if (EFI_ERROR (Status)) { + return FALSE; + } + TmpDevicePath = DevicePath; + + // + // Check whether this device path include mac address device path. + // If this path has mac address path, get the value whether need + // add this info to the menu and return. + // Else check more about the child handle devcie path. + // + if (IsMacAddressDevicePath(TmpDevicePath, &IsNeedAdd)) { + if ((NETWORK_DEVICE_LIST_FORM_ID == mNextShowFormId) && IsNeedAdd) { + (*ItemCount) = 1; + } + return IsNeedAdd; + } + + // + // Search whether this path is the controller path, not he child handle path. + // And the child handle has the network devcie connected. + // + TmpDevicePath = DevicePath; + Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle); + if (EFI_ERROR (Status)) { + return FALSE; + } + + if (!IsDevicePathEnd (TmpDevicePath)) { + return FALSE; + } + + // + // Retrieve the list of agents that are consuming the specific protocol + // on ControllerHandle. + // The buffer point by OpenInfoBuffer need be free at this function. + // + Status = gBS->OpenProtocolInformation ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + &OpenInfoBuffer, + &EntryCount + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + // + // Inspect if ChildHandle is one of the agents. + // + Status = EFI_UNSUPPORTED; + for (Index = 0; Index < EntryCount; Index++) { + // + // Query all the children created by the controller handle's driver + // + if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { + Status = gBS->OpenProtocol ( + OpenInfoBuffer[Index].ControllerHandle, + &gEfiDevicePathProtocolGuid, + (VOID **) &ChildDevicePath, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Check whether this device path include mac address device path. + // + if (!IsMacAddressDevicePath(ChildDevicePath, &IsNeedAdd)) { + // + // If this path not has mac address path, check the other. + // + continue; + } else { + // + // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more. + // + if ((NETWORK_DEVICE_LIST_FORM_ID == mNextShowFormId)) { + if (IsNeedAdd) { + (*ItemCount) += 1; + } + continue; + } else { + // + // If need to update other form, return whether need to add to the menu. + // + goto Done; + } + } + } + } + +Done: + if (OpenInfoBuffer != NULL) { + FreePool (OpenInfoBuffer); + } + return IsNeedAdd; +} + /** Call the browser and display the device manager to allow user to configure the platform. @@ -368,12 +732,18 @@ CallDeviceManager ( EFI_IFR_GUID_LABEL *EndLabel; UINTN NumHandles; EFI_HANDLE *DriverHealthHandles; + BOOLEAN AddNetworkMenu; + UINTN AddItemCount; + UINTN NewStringLen; + EFI_STRING NewStringTitle; HiiHandles = NULL; Status = EFI_SUCCESS; gCallbackKey = 0; NumHandles = 0; DriverHealthHandles = NULL; + AddNetworkMenu = FALSE; + AddItemCount = 0; // // Connect all prior to entering the platform setup menu. @@ -382,9 +752,47 @@ CallDeviceManager ( BdsLibConnectAllDriversToAllControllers (); gConnectAllHappened = TRUE; } + + HiiHandle = gDeviceManagerPrivate.HiiHandle; + if (HiiHandle == NULL) { + // + // Publish our HII data. + // + HiiHandle = HiiAddPackages ( + &gDeviceManagerFormSetGuid, + gDeviceManagerPrivate.DriverHandle, + DeviceManagerVfrBin, + BdsDxeStrings, + NULL + ); + if (HiiHandle == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + gDeviceManagerPrivate.HiiHandle = HiiHandle; + } + // - // Create Subtitle OpCodes + // If need show the Network device list form, clear the old save list first. // + if ((mNextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) { + mMacDeviceList.CurListLen = 0; + } + + // + // Update the network device form titile. + // + if (mNextShowFormId == NETWORK_DEVICE_FORM_ID) { + String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NULL); + NewStringLen = StrLen(mSelectedMacAddrString) * 2; + NewStringLen += (StrLen(String) + 2) * 2; + NewStringTitle = AllocatePool (NewStringLen); + UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString); + HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL); + FreePool (String); + FreePool (NewStringTitle); + } + // // Allocate space for creation of UpdateData Buffer // @@ -399,7 +807,10 @@ CallDeviceManager ( // StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - StartLabel->Number = LABEL_DEVICES_LIST; + // + // According to the next show Form id(mNextShowFormId) to decide which form need to update. + // + StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + mNextShowFormId); // // Create Hii Extend Label OpCode as the end opcode @@ -408,20 +819,23 @@ CallDeviceManager ( EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; EndLabel->Number = LABEL_END; - HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DEVICES_LIST), 0, 0, 1); - // // Get all the Hii handles // HiiHandles = HiiGetHiiHandles (NULL); ASSERT (HiiHandles != NULL); - HiiHandle = gDeviceManagerPrivate.HiiHandle; - // // Search for formset of each class type // for (Index = 0; HiiHandles[Index] != NULL; Index++) { + // + // The QuestionId in the form which will call the driver form has this asssumption. + // QuestionId = Handle Index + NETWORK_DEVICE_LIST_KEY_OFFSET; + // Different QuestionId at least has the section of NETWORK_DEVICE_LIST_KEY_OFFSET. + // + ASSERT(Index < MAX_KEY_SECTION_LEN); + if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, &FormSetTitle, &FormSetHelp)) { continue; } @@ -442,21 +856,71 @@ CallDeviceManager ( TokenHelp = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); - HiiCreateActionOpCode ( - StartOpCodeHandle, - (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET), - Token, - TokenHelp, - EFI_IFR_FLAG_CALLBACK, - 0 - ); + // + // Network device process + // + if (IsNeedAddNetworkMenu (HiiHandles[Index], &AddItemCount)) { + if (mNextShowFormId == DEVICE_MANAGER_FORM_ID) { + // + // Only show one menu item "Network Config" in the device manger form. + // + if (!AddNetworkMenu) { + AddNetworkMenu = TRUE; + HiiCreateGotoOpCode ( + StartOpCodeHandle, + INVALID_FORM_ID, + STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE), + STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP), + EFI_IFR_FLAG_CALLBACK, + (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID + ); + } + } else if (mNextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) { + // + // In network device list form, same mac address device only show one menu. + // + while (AddItemCount > 0) { + HiiCreateGotoOpCode ( + StartOpCodeHandle, + INVALID_FORM_ID, + mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId, + STRING_TOKEN (STR_NETWORK_DEVICE_HELP), + EFI_IFR_FLAG_CALLBACK, + mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId + ); + AddItemCount -= 1; + } + } else if (mNextShowFormId == NETWORK_DEVICE_FORM_ID) { + // + // In network device form, only the selected mac address device need to be show. + // + HiiCreateGotoOpCode ( + StartOpCodeHandle, + INVALID_FORM_ID, + Token, + TokenHelp, + EFI_IFR_FLAG_CALLBACK, + (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET) + ); + } + } else { + // + // + // Not network device process, only need to show at device manger form. + // + if (mNextShowFormId == DEVICE_MANAGER_FORM_ID) { + HiiCreateGotoOpCode ( + StartOpCodeHandle, + INVALID_FORM_ID, + Token, + TokenHelp, + EFI_IFR_FLAG_CALLBACK, + (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET) + ); + } + } } - // - // Add End Opcode for Subtitle - // - HiiCreateEndOpCode (StartOpCodeHandle); - Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiDriverHealthProtocolGuid, @@ -464,13 +928,24 @@ CallDeviceManager ( &NumHandles, &DriverHealthHandles ); + // - // If there are no drivers installed driver health protocol + // If there are no drivers installed driver health protocol, do not create driver health entry in UI // - if (NumHandles == 0) { - HiiSetString (HiiHandle, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE), GetStringById (STRING_TOKEN (STR_EMPTY_STRING)), NULL); - HiiSetString (HiiHandle, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY), GetStringById (STRING_TOKEN (STR_EMPTY_STRING)), NULL); - } else { + if (NumHandles != 0) { + // + // If driver health protocol is installed, create Driver Health subtitle and entry + // + HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE), 0, 0, 0); + HiiCreateGotoOpCode ( + StartOpCodeHandle, + DRIVER_HEALTH_FORM_ID, + STRING_TOKEN(STR_DRIVER_HEALTH_ALL_HEALTHY), // Prompt text + STRING_TOKEN(STR_DRIVER_HEALTH_STATUS_HELP), // Help text + EFI_IFR_FLAG_CALLBACK, + DEVICE_MANAGER_KEY_DRIVER_HEALTH // Question ID + ); + // // Check All Driver health status // @@ -489,8 +964,8 @@ CallDeviceManager ( HiiUpdateForm ( HiiHandle, - &mDeviceManagerGuid, - DEVICE_MANAGER_FORM_ID, + &gDeviceManagerFormSetGuid, + mNextShowFormId, StartOpCodeHandle, EndOpCodeHandle ); @@ -500,8 +975,8 @@ CallDeviceManager ( gFormBrowser2, &HiiHandle, 1, - &mDeviceManagerGuid, - 0, + &gDeviceManagerFormSetGuid, + mNextShowFormId, NULL, &ActionRequest ); @@ -510,10 +985,10 @@ CallDeviceManager ( } // - // We will have returned from processing a callback - user either hit ESC to exit, or selected + // We will have returned from processing a callback, selected // a target to display // - if ((gCallbackKey != 0) && (gCallbackKey != DEVICE_MANAGER_KEY_DRIVER_HEALTH)) { + if ((gCallbackKey >= DEVICE_KEY_OFFSET)) { ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; Status = gFormBrowser2->SendForm ( gFormBrowser2, @@ -533,6 +1008,7 @@ CallDeviceManager ( // Force return to Device Manager // gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER; + goto Done; } // @@ -544,26 +1020,44 @@ CallDeviceManager ( // Force return to Device Manager // gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER; + goto Done; } // - // Cleanup dynamic created strings in HII database by reinstall the packagelist + // Enter from device manager and into the network device list. // - HiiRemovePackages (HiiHandle); + if (gCallbackKey == QUESTION_NETWORK_DEVICE_ID) { + mNextShowFormId = NETWORK_DEVICE_LIST_FORM_ID; + gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER; + goto Done; + } + + // + // In this case, go from the network device list to the specify device. + // + if ((gCallbackKey < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET ) && (gCallbackKey >= NETWORK_DEVICE_LIST_KEY_OFFSET)) { + mNextShowFormId = NETWORK_DEVICE_FORM_ID; + gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER; + goto Done; + } - gDeviceManagerPrivate.HiiHandle = HiiAddPackages ( - &mDeviceManagerGuid, - gDeviceManagerPrivate.DriverHandle, - DeviceManagerVfrBin, - BdsDxeStrings, - NULL - ); - if (gDeviceManagerPrivate.HiiHandle == NULL) { - Status = EFI_OUT_OF_RESOURCES; + // + // Select the ESC, the gCallbackKey == 0. + // + if(mNextShowFormId - 1 < DEVICE_MANAGER_FORM_ID) { + mNextShowFormId = DEVICE_MANAGER_FORM_ID; } else { - Status = EFI_SUCCESS; + mNextShowFormId = (UINT16) (mNextShowFormId - 1); + gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER; } +Done: + // + // Remove our packagelist from HII database. + // + HiiRemovePackages (HiiHandle); + gDeviceManagerPrivate.HiiHandle = NULL; + HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); FreePool (HiiHandles); @@ -598,18 +1092,25 @@ DriverHealthCallback ( OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest ) { - if ((Value == NULL) || (ActionRequest == NULL)) { - return EFI_INVALID_PARAMETER; - } + if (Action == EFI_BROWSER_ACTION_CHANGED) { + if ((Value == NULL) || (ActionRequest == NULL)) { + return EFI_INVALID_PARAMETER; + } - gCallbackKey = QuestionId; + gCallbackKey = QuestionId; + + // + // Request to exit SendForm(), so as to switch to selected form + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT; + + return EFI_SUCCESS; + } // - // Request to exit SendForm(), so as to switch to selected form + // All other action return unsupported. // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT; - - return EFI_SUCCESS; + return EFI_UNSUPPORTED; } /** @@ -649,15 +1150,32 @@ CallDriverHealth ( DRIVER_HEALTH_INFO *DriverHealthInfo; LIST_ENTRY *Link; EFI_DEVICE_PATH_PROTOCOL *DriverDevicePath; - UINTN Length; + BOOLEAN RebootRequired; - HiiHandle = gDeviceManagerPrivate.DriverHealthHiiHandle; Index = 0; - Length = 0; DriverHealthInfo = NULL; DriverDevicePath = NULL; InitializeListHead (&DriverHealthList); + HiiHandle = gDeviceManagerPrivate.DriverHealthHiiHandle; + if (HiiHandle == NULL) { + // + // Publish Driver Health HII data. + // + HiiHandle = HiiAddPackages ( + &gDeviceManagerFormSetGuid, + gDeviceManagerPrivate.DriverHealthHandle, + DriverHealthVfrBin, + BdsDxeStrings, + NULL + ); + if (HiiHandle == NULL) { + return; + } + + gDeviceManagerPrivate.DriverHealthHiiHandle = HiiHandle; + } + // // Allocate space for creation of UpdateData Buffer // @@ -756,44 +1274,36 @@ CallDriverHealth ( DriverHealthInfo->MessageList->StringId, NULL ); - // - // Assert if can not retrieve the message string - // - ASSERT (TmpString != NULL); - StrnCat (String, TmpString, StrLen (TmpString)); - FreePool (TmpString); } else { // // Update the string will be displayed base on the driver's health status // switch(DriverHealthInfo->HealthStatus) { case EfiDriverHealthStatusRepairRequired: - Length = StrLen (GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED))); - StrnCat (String, GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED)), Length); + TmpString = GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED)); break; case EfiDriverHealthStatusConfigurationRequired: - Length = StrLen (GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED))); - StrnCat (String, GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED)), Length); + TmpString = GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED)); break; case EfiDriverHealthStatusFailed: - Length = StrLen (GetStringById (STRING_TOKEN (STR_OPERATION_FAILED))); - StrnCat (String, GetStringById (STRING_TOKEN (STR_OPERATION_FAILED)), Length); + TmpString = GetStringById (STRING_TOKEN (STR_OPERATION_FAILED)); break; case EfiDriverHealthStatusReconnectRequired: - Length = StrLen (GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED))); - StrnCat (String, GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED)), Length); + TmpString = GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED)); break; case EfiDriverHealthStatusRebootRequired: - Length = StrLen (GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED))); - StrnCat (String, GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED)), Length); + TmpString = GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED)); break; default: - Length = StrLen (GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY))); - StrnCat (String, GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY)), Length); + TmpString = GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY)); break; } } + ASSERT (TmpString != NULL); + StrCat (String, TmpString); + FreePool (TmpString); + Token = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); @@ -851,7 +1361,7 @@ CallDriverHealth ( Status = HiiUpdateForm ( HiiHandle, - &mDriverHealthGuid, + &gDriverHealthFormSetGuid, DRIVER_HEALTH_FORM_ID, StartOpCodeHandle, EndOpCodeHandle @@ -861,7 +1371,7 @@ CallDriverHealth ( Status = HiiUpdateForm ( HiiHandle, - &mDriverHealthGuid, + &gDriverHealthFormSetGuid, DRIVER_HEALTH_FORM_ID, StartOpCodeHandleRepair, EndOpCodeHandleRepair @@ -874,7 +1384,7 @@ CallDriverHealth ( gFormBrowser2, &HiiHandle, 1, - &mDriverHealthGuid, + &gDriverHealthFormSetGuid, DRIVER_HEALTH_FORM_ID, NULL, &ActionRequest @@ -903,15 +1413,20 @@ CallDriverHealth ( // // Process the driver's healthy status for the specify module // + RebootRequired = FALSE; ProcessSingleControllerHealth ( DriverHealthInfo->DriverHealth, DriverHealthInfo->ControllerHandle, DriverHealthInfo->ChildHandle, DriverHealthInfo->HealthStatus, &(DriverHealthInfo->MessageList), - DriverHealthInfo->HiiHandle - ); - break; + DriverHealthInfo->HiiHandle, + &RebootRequired + ); + if (RebootRequired) { + gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL); + } + break; } Index++; Link = GetNextNode (&DriverHealthList, Link); @@ -939,23 +1454,11 @@ CallDriverHealth ( } // - // Cleanup dynamic created strings in HII database by reinstall the packagelist + // Remove driver health packagelist from HII database. // - HiiRemovePackages (HiiHandle); + gDeviceManagerPrivate.DriverHealthHiiHandle = NULL; - gDeviceManagerPrivate.DriverHealthHiiHandle = HiiAddPackages ( - &mDriverHealthGuid, - gDeviceManagerPrivate.DriverHealthHandle, - DriverHealthVfrBin, - BdsDxeStrings, - NULL - ); - if (gDeviceManagerPrivate.DriverHealthHiiHandle == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = EFI_SUCCESS; - } // // Free driver health info list // @@ -1410,15 +1913,17 @@ PlaformHealthStatusCheck ( ChildHandle. This is an optional parameter that may be NULL. @param FormHiiHandle The HII handle for an HII form associated with the controller specified by ControllerHandle and ChildHandle. + @param RebootRequired Indicate whether a reboot is required to repair the controller. **/ VOID ProcessSingleControllerHealth ( - IN EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth, - IN EFI_HANDLE ControllerHandle, OPTIONAL - IN EFI_HANDLE ChildHandle, OPTIONAL - IN EFI_DRIVER_HEALTH_STATUS HealthStatus, - IN EFI_DRIVER_HEALTH_HII_MESSAGE **MessageList, OPTIONAL - IN EFI_HII_HANDLE FormHiiHandle + IN EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth, + IN EFI_HANDLE ControllerHandle, OPTIONAL + IN EFI_HANDLE ChildHandle, OPTIONAL + IN EFI_DRIVER_HEALTH_STATUS HealthStatus, + IN EFI_DRIVER_HEALTH_HII_MESSAGE **MessageList, OPTIONAL + IN EFI_HII_HANDLE FormHiiHandle, + IN OUT BOOLEAN *RebootRequired ) { EFI_STATUS Status; @@ -1430,8 +1935,8 @@ ProcessSingleControllerHealth ( // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair // will be in (Health, Failed, Configuration Required). // - while( LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired || - LocalHealthStatus == EfiDriverHealthStatusRepairRequired) { + while(LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired || + LocalHealthStatus == EfiDriverHealthStatusRepairRequired) { if (LocalHealthStatus == EfiDriverHealthStatusRepairRequired) { Status = DriverHealth->Repair ( @@ -1447,16 +1952,23 @@ ProcessSingleControllerHealth ( // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required). // if (LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired) { - Status = gFormBrowser2->SendForm ( - gFormBrowser2, - &FormHiiHandle, - 1, - &gEfiHiiDriverHealthFormsetGuid, - 0, - NULL, - NULL - ); - ASSERT( !EFI_ERROR (Status)); + if (FormHiiHandle != NULL) { + Status = gFormBrowser2->SendForm ( + gFormBrowser2, + &FormHiiHandle, + 1, + &gEfiHiiDriverHealthFormsetGuid, + 0, + NULL, + NULL + ); + ASSERT( !EFI_ERROR (Status)); + } else { + // + // Exit the loop in case no FormHiiHandle is supplied to prevent dead-loop + // + break; + } } Status = DriverHealth->GetHealthStatus ( @@ -1467,11 +1979,11 @@ ProcessSingleControllerHealth ( NULL, &FormHiiHandle ); - ASSERT_EFI_ERROR (Status); + ASSERT_EFI_ERROR (Status); - if (*MessageList != NULL) { + if (*MessageList != NULL) { ProcessMessages (*MessageList); - } + } } // @@ -1486,7 +1998,7 @@ ProcessSingleControllerHealth ( // Check for RebootRequired or ReconnectRequired // if (LocalHealthStatus == EfiDriverHealthStatusRebootRequired) { - gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL); + *RebootRequired = TRUE; } // @@ -1495,12 +2007,13 @@ ProcessSingleControllerHealth ( if (LocalHealthStatus == EfiDriverHealthStatusReconnectRequired) { Status = gBS->DisconnectController (ControllerHandle, NULL, NULL); if (EFI_ERROR (Status)) { - // - // Disconnect failed. Need to promote reconnect to a reboot. - // - gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL); + // + // Disconnect failed. Need to promote reconnect to a reboot. + // + *RebootRequired = TRUE; + } else { + gBS->ConnectController (ControllerHandle, NULL, NULL, TRUE); } - gBS->ConnectController (ControllerHandle, NULL, NULL, TRUE); } } @@ -1593,12 +2106,16 @@ PlatformRepairAll ( { DRIVER_HEALTH_INFO *DriverHealthInfo; LIST_ENTRY *Link; + BOOLEAN RebootRequired; ASSERT (DriverHealthList != NULL); - Link = GetFirstNode (DriverHealthList); + RebootRequired = FALSE; - while (!IsNull (DriverHealthList, Link)) { + for ( Link = GetFirstNode (DriverHealthList) + ; !IsNull (DriverHealthList, Link) + ; Link = GetNextNode (DriverHealthList, Link) + ) { DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link); // // Do driver health status operation by each link node @@ -1606,15 +2123,18 @@ PlatformRepairAll ( ASSERT (DriverHealthInfo != NULL); ProcessSingleControllerHealth ( - DriverHealthInfo->DriverHealth, - DriverHealthInfo->ControllerHandle, - DriverHealthInfo->ChildHandle, - DriverHealthInfo->HealthStatus, - &(DriverHealthInfo->MessageList), - DriverHealthInfo->HiiHandle - ); + DriverHealthInfo->DriverHealth, + DriverHealthInfo->ControllerHandle, + DriverHealthInfo->ChildHandle, + DriverHealthInfo->HealthStatus, + &(DriverHealthInfo->MessageList), + DriverHealthInfo->HiiHandle, + &RebootRequired + ); + } - Link = GetNextNode (DriverHealthList, Link); + if (RebootRequired) { + gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL); } }