/** Dynamic create Hii information for Device Manager. @param NextShowFormId The FormId which need to be show. **/ VOID CreateDeviceManagerForm( IN EFI_FORM_ID NextShowFormId ) { UINTN Index; EFI_STRING String; EFI_STRING_ID Token; EFI_STRING_ID TokenHelp; EFI_HII_HANDLE *HiiHandles; EFI_HII_HANDLE HiiHandle; EFI_GUID FormSetGuid; VOID *StartOpCodeHandle; VOID *EndOpCodeHandle; EFI_IFR_GUID_LABEL *StartLabel; EFI_IFR_GUID_LABEL *EndLabel; BOOLEAN AddNetworkMenu; UINTN AddItemCount; UINTN NewStringLen; EFI_STRING NewStringTitle; CHAR16 *DevicePathStr; EFI_STRING_ID DevicePathId; EFI_IFR_FORM_SET *Buffer; UINTN BufferSize; UINT8 ClassGuidNum; EFI_GUID *ClassGuid; UINTN TempSize; UINT8 *Ptr; EFI_STATUS Status; TempSize =0; BufferSize = 0; Buffer = NULL; HiiHandle = gDeviceManagerPrivate.HiiHandle; AddNetworkMenu = FALSE; AddItemCount = 0; // // If need show the Network device list form, clear the old save list first. // if ((NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) { mMacDeviceList.CurListLen = 0; } // // Update the network device form titile. // if (NextShowFormId == 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 // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); EndOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (EndOpCodeHandle != NULL); // // Create Hii Extend Label OpCode as the start opcode // StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; // // According to the next show Form id(mNextShowFormId) to decide which form need to update. // StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + NextShowFormId); // // Create Hii Extend Label OpCode as the end opcode // EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; EndLabel->Number = LABEL_END; // // Get all the Hii handles // HiiHandles = HiiGetHiiHandles (NULL); ASSERT (HiiHandles != NULL); // // Search for formset of each class type // for (Index = 0; HiiHandles[Index] != NULL; Index++) { Status = HiiGetFormSetFromHiiHandle(HiiHandles[Index], &Buffer,&BufferSize); if (EFI_ERROR (Status)){ continue; } Ptr = (UINT8 *)Buffer; while(TempSize < BufferSize) { TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length; if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){ Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length; continue; } ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3); ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET)); while (ClassGuidNum-- > 0) { if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, ClassGuid)== 0) { ClassGuid ++; continue; } String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL); if (String == NULL) { String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); ASSERT (String != NULL); } Token = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL); if (String == NULL) { String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); ASSERT (String != NULL); } TokenHelp = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); FormSetGuid = ((EFI_IFR_FORM_SET *)Ptr)->Guid; // // Network device process // if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId,&AddItemCount)) { if (NextShowFormId == DEVICE_MANAGER_FORM_ID) { // // Only show one menu item "Network Config" in the device manger form. // if (!AddNetworkMenu) { AddNetworkMenu = TRUE; HiiCreateGotoOpCode ( StartOpCodeHandle, NETWORK_DEVICE_LIST_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 (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) { // // In network device list form, same mac address device only show one menu. // while (AddItemCount > 0) { HiiCreateGotoOpCode ( StartOpCodeHandle, NETWORK_DEVICE_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 (NextShowFormId == NETWORK_DEVICE_FORM_ID) { // // In network device form, only the selected mac address device need to be show. // DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]); DevicePathId = 0; if (DevicePathStr != NULL){ DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); FreePool(DevicePathStr); } HiiCreateGotoExOpCode ( StartOpCodeHandle, 0, Token, TokenHelp, 0, (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET), 0, &FormSetGuid, DevicePathId ); } } else { // // Not network device process, only need to show at device manger form. // if (NextShowFormId == DEVICE_MANAGER_FORM_ID) { DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]); DevicePathId = 0; if (DevicePathStr != NULL){ DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); FreePool(DevicePathStr); } HiiCreateGotoExOpCode ( StartOpCodeHandle, 0, Token, TokenHelp, 0, (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET), 0, &FormSetGuid, DevicePathId ); } } break; } Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length; } FreePool(Buffer); Buffer = NULL; TempSize = 0; BufferSize = 0; } HiiUpdateForm ( HiiHandle, &mDeviceManagerGuid, NextShowFormId, StartOpCodeHandle, EndOpCodeHandle ); HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); FreePool (HiiHandles); }
/** Search the drivers in the system which need to show in the front page and insert the menu to the front page. @param HiiHandle The hii handle for the Uiapp driver. @param ClassGuid The class guid for the driver which is the target. @param SpecialHandlerFn The pointer to the specail handler function, if any. @param StartOpCodeHandle The opcode handle to save the new opcode. @retval EFI_SUCCESS Search the driver success **/ EFI_STATUS UiListThirdPartyDrivers ( IN EFI_HII_HANDLE HiiHandle, IN EFI_GUID *ClassGuid, IN DRIVER_SPECIAL_HANDLER SpecialHandlerFn, IN VOID *StartOpCodeHandle ) { UINTN Index; EFI_STRING String; EFI_STRING_ID Token; EFI_STRING_ID TokenHelp; EFI_HII_HANDLE *HiiHandles; CHAR16 *DevicePathStr; UINTN Count; UINTN CurrentSize; UI_HII_DRIVER_INSTANCE *DriverListPtr; EFI_STRING NewName; BOOLEAN EmptyLineAfter; if (gHiiDriverList != NULL) { FreePool (gHiiDriverList); } HiiHandles = HiiGetHiiHandles (NULL); ASSERT (HiiHandles != NULL); gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE)); ASSERT (gHiiDriverList != NULL); DriverListPtr = gHiiDriverList; CurrentSize = UI_HII_DRIVER_LIST_SIZE; for (Index = 0, Count = 0; HiiHandles[Index] != NULL; Index++) { if (!RequiredDriver (HiiHandles[Index], ClassGuid, &Token, &TokenHelp, &gHiiDriverList[Count].FormSetGuid)) { continue; } String = HiiGetString (HiiHandles[Index], Token, NULL); if (String == NULL) { String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); ASSERT (String != NULL); } else if (SpecialHandlerFn != NULL) { // // Check whether need to rename the driver name. // EmptyLineAfter = FALSE; if (SpecialHandlerFn (String, &NewName, &EmptyLineAfter)) { FreePool (String); String = NewName; DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter; } } DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); String = HiiGetString (HiiHandles[Index], TokenHelp, NULL); if (String == NULL) { String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); ASSERT (String != NULL); } DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]); if (DevicePathStr != NULL){ DriverListPtr[Count].DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); FreePool (DevicePathStr); } else { DriverListPtr[Count].DevicePathId = 0; } Count++; if (Count >= CurrentSize) { DriverListPtr = ReallocatePool ( CurrentSize * sizeof (UI_HII_DRIVER_INSTANCE), (Count + UI_HII_DRIVER_LIST_SIZE) * sizeof (UI_HII_DRIVER_INSTANCE), gHiiDriverList ); ASSERT (DriverListPtr != NULL); gHiiDriverList = DriverListPtr; CurrentSize += UI_HII_DRIVER_LIST_SIZE; } } FreePool (HiiHandles); Index = 0; while (gHiiDriverList[Index].PromptId != 0) { HiiCreateGotoExOpCode ( StartOpCodeHandle, 0, gHiiDriverList[Index].PromptId, gHiiDriverList[Index].HelpId, 0, (EFI_QUESTION_ID) (Index + FRONT_PAGE_KEY_DRIVER), 0, &gHiiDriverList[Index].FormSetGuid, gHiiDriverList[Index].DevicePathId ); if (gHiiDriverList[Index].EmptyLineAfter) { UiCreateEmptyLine (HiiHandle, StartOpCodeHandle); } Index ++; } return EFI_SUCCESS; }
/** Update the form to include the driver health instances. @param ConfigureOnly Only include the configure required driver health instances when TRUE, include all the driver health instances otherwise. **/ VOID DriverHealthManagerUpdateForm ( BOOLEAN ConfigureOnly ) { EFI_STATUS Status; EFI_IFR_GUID_LABEL *StartLabel; EFI_IFR_GUID_LABEL *EndLabel; VOID *StartOpCodeHandle; VOID *EndOpCodeHandle; UINTN Index; EFI_STRING_ID Prompt; EFI_STRING_ID Help; CHAR16 String[512]; UINTN StringCount; EFI_STRING TmpString; EFI_STRING DriverName; EFI_STRING ControllerName; UINTN MessageIndex; EFI_HANDLE DriverHandle; EFI_STRING_ID DevicePath; EFI_GUID FormsetGuid; EfiBootManagerFreeDriverHealthInfo (mDriverHealthManagerHealthInfo, mDriverHealthManagerHealthInfoCount); mDriverHealthManagerHealthInfo = EfiBootManagerGetDriverHealthInfo (&mDriverHealthManagerHealthInfoCount); // // Allocate space for creation of UpdateData Buffer // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); EndOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (EndOpCodeHandle != NULL); // // Create Hii Extend Label OpCode as the start opcode // StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; StartLabel->Number = LABEL_BEGIN; // // Create Hii Extend Label OpCode as the end opcode // EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; EndLabel->Number = LABEL_END; for (Index = 0; Index < mDriverHealthManagerHealthInfoCount; Index++) { if (ConfigureOnly && mDriverHealthManagerHealthInfo[Index].HealthStatus != EfiDriverHealthStatusConfigurationRequired) { continue; } DriverName = DriverHealthManagerGetDriverName (mDriverHealthManagerHealthInfo[Index].DriverHealthHandle); ASSERT (DriverName != NULL); if (mDriverHealthManagerHealthInfo[Index].ControllerHandle == NULL) { // // The ControllerHandle is set to NULL and the HealthStatus is set to EfiDriverHealthStatusHealthy // if all the controllers managed by the driver are in healthy state. // ASSERT (mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusHealthy); UnicodeSPrint (String, sizeof (String), L"%s", DriverName); } else { ControllerName = DriverHealthManagerGetControllerName ( mDriverHealthManagerHealthInfo[Index].DriverHealthHandle, mDriverHealthManagerHealthInfo[Index].ControllerHandle, mDriverHealthManagerHealthInfo[Index].ChildHandle ); ASSERT (ControllerName != NULL); UnicodeSPrint (String, sizeof (String), L"%s %s", DriverName, ControllerName); FreePool (ControllerName); } FreePool (DriverName); Prompt = HiiSetString (mDriverHealthManagerHiiHandle, 0, String, NULL); switch(mDriverHealthManagerHealthInfo[Index].HealthStatus) { case EfiDriverHealthStatusRepairRequired: TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_REPAIR_REQUIRED), NULL); break; case EfiDriverHealthStatusConfigurationRequired: TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_CONFIGURATION_REQUIRED), NULL); break; case EfiDriverHealthStatusFailed: TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_FAILED), NULL); break; case EfiDriverHealthStatusReconnectRequired: TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_RECONNECT_REQUIRED), NULL); break; case EfiDriverHealthStatusRebootRequired: TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_REBOOT_REQUIRED), NULL); break; default: ASSERT (mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusHealthy); TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_HEALTHY), NULL); break; } StringCount = UnicodeSPrint (String, sizeof (String), L"%s\n", TmpString); FreePool (TmpString); // // Add the message of the Module itself provided as the help. // if (mDriverHealthManagerHealthInfo[Index].MessageList != NULL) { for (MessageIndex = 0; mDriverHealthManagerHealthInfo[Index].MessageList[MessageIndex].HiiHandle != NULL; MessageIndex++) { TmpString = HiiGetString ( mDriverHealthManagerHealthInfo[Index].MessageList[MessageIndex].HiiHandle, mDriverHealthManagerHealthInfo[Index].MessageList[MessageIndex].StringId, NULL ); StringCount += UnicodeSPrint (String + StringCount, sizeof (String) - sizeof (String[0]) * StringCount, L"\n%s", TmpString); FreePool (TmpString); } } Help = HiiSetString (mDriverHealthManagerHiiHandle, 0, String, NULL); switch (mDriverHealthManagerHealthInfo[Index].HealthStatus) { case EfiDriverHealthStatusConfigurationRequired: Status = mDriverHealthManagerDatabase->GetPackageListHandle ( mDriverHealthManagerDatabase, mDriverHealthManagerHealthInfo[Index].HiiHandle, &DriverHandle ); ASSERT_EFI_ERROR (Status); TmpString = ConvertDevicePathToText (DevicePathFromHandle (DriverHandle), FALSE, TRUE); DevicePath = HiiSetString (mDriverHealthManagerHiiHandle, 0, TmpString, NULL); FreePool (TmpString); Status = DriverHealthManagerGetFormsetId (mDriverHealthManagerHealthInfo[Index].HiiHandle, &FormsetGuid); ASSERT_EFI_ERROR (Status); HiiCreateGotoExOpCode ( StartOpCodeHandle, 0, Prompt, Help, 0, 0, 0, &FormsetGuid, DevicePath ); break; case EfiDriverHealthStatusRepairRequired: case EfiDriverHealthStatusReconnectRequired: case EfiDriverHealthStatusRebootRequired: HiiCreateActionOpCode ( StartOpCodeHandle, (EFI_QUESTION_ID) (Index + QUESTION_ID_DRIVER_HEALTH_BASE), Prompt, Help, EFI_IFR_FLAG_CALLBACK, 0 ); break; default: ASSERT (mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusHealthy || mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusFailed); HiiCreateTextOpCode ( StartOpCodeHandle, Prompt, Help, 0 ); break; } } Status = HiiUpdateForm ( mDriverHealthManagerHiiHandle, ConfigureOnly ? PcdGetPtr (PcdDriverHealthConfigureForm) : &mDriverHealthManagerForm, DRIVER_HEALTH_FORM_ID, StartOpCodeHandle, EndOpCodeHandle ); ASSERT_EFI_ERROR (Status); HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); }
/** Create dynamic code for BMM. @param BmmCallbackInfo The BMM context data. **/ VOID InitializeDrivers( IN BMM_CALLBACK_DATA *BmmCallbackInfo ) { EFI_HII_HANDLE HiiHandle; VOID *StartOpCodeHandle; VOID *EndOpCodeHandle; EFI_IFR_GUID_LABEL *StartLabel; EFI_IFR_GUID_LABEL *EndLabel; UINTN Index; EFI_STRING_ID FormSetTitle; EFI_STRING_ID FormSetHelp; EFI_STRING String; EFI_STRING_ID Token; EFI_STRING_ID TokenHelp; EFI_HII_HANDLE *HiiHandles; UINTN SkipCount; EFI_GUID FormSetGuid; CHAR16 *DevicePathStr; EFI_STRING_ID DevicePathId; HiiHandle = BmmCallbackInfo->BmmHiiHandle; // // Allocate space for creation of UpdateData Buffer // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); EndOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (EndOpCodeHandle != NULL); // // Create Hii Extend Label OpCode as the start opcode // StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; StartLabel->Number = LABEL_BMM_PLATFORM_INFORMATION; // // Create Hii Extend Label OpCode as the end opcode // EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; EndLabel->Number = LABEL_END; // // Get all the Hii handles // HiiHandles = HiiGetHiiHandles (NULL); ASSERT (HiiHandles != NULL); // // Search for formset of each class type // SkipCount = 0; for (Index = 0; HiiHandles[Index] != NULL; Index++) { if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiIfrBootMaintenanceGuid, SkipCount, &FormSetTitle, &FormSetHelp, &FormSetGuid)) { SkipCount = 0; continue; } String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL); if (String == NULL) { String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL); ASSERT (String != NULL); } Token = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL); if (String == NULL) { String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL); ASSERT (String != NULL); } TokenHelp = HiiSetString (HiiHandle, 0, String, NULL); FreePool (String); DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]); DevicePathId = 0; if (DevicePathStr != NULL){ DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); FreePool (DevicePathStr); } HiiCreateGotoExOpCode ( StartOpCodeHandle, 0, Token, TokenHelp, 0, (EFI_QUESTION_ID) (Index + FRONT_PAGE_KEY_OFFSET), 0, &FormSetGuid, DevicePathId ); // //One packagelist may has more than one form package, //Index-- means keep current HiiHandle and still extract from the packagelist, //SkipCount++ means skip the formset which was found before in the same form package. // SkipCount++; Index--; } HiiUpdateForm ( HiiHandle, &mBootMaintGuid, FORM_MAIN_ID, StartOpCodeHandle, EndOpCodeHandle ); HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); FreePool (HiiHandles); }