X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=EdkNt32Pkg%2FLibrary%2FEdkGenericBdsLib%2FBdsMisc.c;h=b8be94e74ddde08f9121b9b3bc4b84281d921bca;hb=e237e7ae9fc23f32a25040d49cc9a16f2a7f3b4c;hp=b88d05127a41870a55cdd6852897a3dc7f9d6dfb;hpb=4ef4e1eab529c7d23100643705ee0df0b027f12c;p=mirror_edk2.git diff --git a/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c b/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c index b88d05127a..b8be94e74d 100644 --- a/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c +++ b/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c @@ -1,13 +1,13 @@ /*++ -Copyright (c) 2006, 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 - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2006 - 2007, 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 + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: @@ -31,7 +31,7 @@ BdsLibGetTimeout ( /*++ Routine Description: - + Return the default value for system Timeout variable. Arguments: @@ -39,7 +39,7 @@ Arguments: None Returns: - + Timeout value. --*/ @@ -85,7 +85,7 @@ BdsLibLoadDrivers ( /*++ Routine Description: - + The function will go through the driver optoin link list, load and start every driver the driver optoin device path point to. @@ -94,7 +94,7 @@ Arguments: BdsDriverLists - The header of the current driver option link list Returns: - + None --*/ @@ -198,7 +198,7 @@ BdsLibRegisterNewOption ( /*++ Routine Description: - + This function will register the new boot#### or driver#### option base on the VariableName. The new registered boot#### or driver#### will be linked to BdsOptionList and also update to the VariableName. After the boot#### or @@ -207,18 +207,18 @@ Routine Description: Arguments: BdsOptionList - The header of the boot#### or driver#### link list - + DevicePath - The device path which the boot#### or driver#### option present - + String - The description of the boot#### or driver#### - + VariableName - Indicate if the boot#### or driver#### option Returns: - + EFI_SUCCESS - The boot#### or driver#### have been success registered - + EFI_STATUS - Return the status of gRT->SetVariable (). --*/ @@ -249,11 +249,13 @@ Returns: ZeroMem (OptionName, sizeof (OptionName)); TempOptionSize = 0; + TempOptionPtr = BdsLibGetVariableAndSize ( VariableName, &gEfiGlobalVariableGuid, &TempOptionSize ); + // // Compare with current option variable // @@ -290,8 +292,8 @@ Returns: // // Got the option, so just return // - gBS->FreePool (OptionPtr); - gBS->FreePool (TempOptionPtr); + FreePool (OptionPtr); + FreePool (TempOptionPtr); return EFI_SUCCESS; } else { // @@ -302,7 +304,7 @@ Returns: } } - gBS->FreePool (OptionPtr); + FreePool (OptionPtr); } OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String) + GetDevicePathSize (DevicePath); @@ -342,12 +344,12 @@ Returns: OptionPtr ); if (EFI_ERROR (Status) || UpdateBootDevicePath) { - gBS->FreePool (OptionPtr); - gBS->FreePool (TempOptionPtr); + FreePool (OptionPtr); + FreePool (TempOptionPtr); return Status; } - gBS->FreePool (OptionPtr); + FreePool (OptionPtr); // // Update the option order variable @@ -363,13 +365,15 @@ Returns: OptionOrderPtr ); if (EFI_ERROR (Status)) { - gBS->FreePool (TempOptionPtr); - gBS->FreePool (OptionOrderPtr); + FreePool (TempOptionPtr); + FreePool (OptionOrderPtr); return Status; } - gBS->FreePool (TempOptionPtr); - gBS->FreePool (OptionOrderPtr); + if (TempOptionPtr != NULL) { + FreePool (TempOptionPtr); + } + FreePool (OptionOrderPtr); return EFI_SUCCESS; } @@ -383,9 +387,9 @@ BdsLibVariableToOption ( Routine Description: - Build the boot#### or driver#### option from the VariableName, the + Build the boot#### or driver#### option from the VariableName, the build boot#### or driver#### will also be linked to BdsCommonOptionList - + Arguments: BdsCommonOptionList - The header of the boot#### or driver#### option link list @@ -482,12 +486,12 @@ Returns: // if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) { InsertTailList (BdsCommonOptionList, &Option->Link); - gBS->FreePool (Variable); + FreePool (Variable); return Option; } - gBS->FreePool (Variable); - gBS->FreePool (Option); + FreePool (Variable); + FreePool (Option); return NULL; } @@ -553,38 +557,7 @@ Returns: } - gBS->FreePool (OptionOrder); - - return EFI_SUCCESS; -} - -EFI_STATUS -BdsLibGetBootMode ( - OUT EFI_BOOT_MODE *BootMode - ) -/*++ - -Routine Description: - - Get boot mode by looking up configuration table and parsing HOB list - -Arguments: - - BootMode - Boot mode from PEI handoff HOB. - -Returns: - - EFI_SUCCESS - Successfully get boot mode - - EFI_NOT_FOUND - Can not find the current system boot mode - ---*/ -{ - EFI_HOB_HANDOFF_INFO_TABLE *HobList; - - HobList = GetHobList (); - ASSERT (HobList->Header.HobType == EFI_HOB_TYPE_HANDOFF); - *BootMode = HobList->BootMode; + FreePool (OptionOrder); return EFI_SUCCESS; } @@ -651,6 +624,95 @@ Returns: return Buffer; } +VOID +BdsLibSafeFreePool ( + IN VOID *Buffer + ) +/*++ + +Routine Description: + + Free pool safely. + +Arguments: + + Buffer - The allocated pool entry to free + +Returns: + + Pointer of the buffer allocated. + +--*/ +{ + if (Buffer != NULL) { + FreePool (Buffer); + Buffer = NULL; + } +} + +EFI_DEVICE_PATH_PROTOCOL * +BdsLibDelPartMatchInstance ( + IN EFI_DEVICE_PATH_PROTOCOL *Multi, + IN EFI_DEVICE_PATH_PROTOCOL *Single + ) +/*++ + +Routine Description: + + Delete the instance in Multi which matches partly with Single instance + +Arguments: + + Multi - A pointer to a multi-instance device path data structure. + + Single - A pointer to a single-instance device path data structure. + +Returns: + + This function will remove the device path instances in Multi which partly + match with the Single, and return the result device path. If there is no + remaining device path as a result, this function will return NULL. + +--*/ +{ + EFI_DEVICE_PATH_PROTOCOL *Instance; + EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; + UINTN InstanceSize; + UINTN SingleDpSize; + UINTN Size; + + NewDevicePath = NULL; + TempNewDevicePath = NULL; + + if (Multi == NULL || Single == NULL) { + return Multi; + } + + Instance = GetNextDevicePathInstance (&Multi, &InstanceSize); + SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH; + InstanceSize -= END_DEVICE_PATH_LENGTH; + + while (Instance != NULL) { + + Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize; + + if ((CompareMem (Instance, Single, Size) != 0)) { + // + // Append the device path instance which does not match with Single + // + TempNewDevicePath = NewDevicePath; + NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance); + BdsLibSafeFreePool(TempNewDevicePath); + } + BdsLibSafeFreePool(Instance); + Instance = GetNextDevicePathInstance (&Multi, &InstanceSize); + InstanceSize -= END_DEVICE_PATH_LENGTH; + } + + return NewDevicePath; +} + BOOLEAN BdsLibMatchDevicePaths ( IN EFI_DEVICE_PATH_PROTOCOL *Multi, @@ -672,9 +734,9 @@ Arguments: Returns: TRUE - If the Single is contained within Multi - + FALSE - The Single is not match within Multi - + --*/ { @@ -698,11 +760,11 @@ Returns: // return success // if (CompareMem (Single, DevicePathInst, Size) == 0) { - gBS->FreePool (DevicePathInst); + FreePool (DevicePathInst); return TRUE; } - gBS->FreePool (DevicePathInst); + FreePool (DevicePathInst); DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); } @@ -730,7 +792,7 @@ Arguments: Returns: EFI_SUCCESS - Success print out the string using ConOut. - + EFI_STATUS - Return the status of the ConOut->OutputString (). --*/ @@ -763,7 +825,7 @@ Returns: // // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature. -// Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if +// Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection. // @@ -774,7 +836,7 @@ EnableResetReminderFeature ( /*++ Routine Description: - + Enable the setup browser reset reminder feature. This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it. @@ -789,7 +851,7 @@ Returns: --*/ { mFeaturerSwitch = TRUE; -} +} VOID DisableResetReminderFeature ( @@ -798,10 +860,10 @@ DisableResetReminderFeature ( /*++ Routine Description: - + Disable the setup browser reset reminder feature. This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it. - + Arguments: VOID @@ -813,7 +875,7 @@ Returns: --*/ { mFeaturerSwitch = FALSE; -} +} VOID EnableResetRequired ( @@ -822,10 +884,10 @@ EnableResetRequired ( /*++ Routine Description: - + Record the info that a reset is required. - A module boolean variable is used to record whether a reset is required. - + A module boolean variable is used to record whether a reset is required. + Arguments: VOID @@ -837,7 +899,7 @@ Returns: --*/ { mResetRequired = TRUE; -} +} VOID DisableResetRequired ( @@ -848,7 +910,7 @@ DisableResetRequired ( Routine Description: Record the info that no reset is required. - A module boolean variable is used to record whether a reset is required. + A module boolean variable is used to record whether a reset is required. Arguments: @@ -861,7 +923,7 @@ Returns: --*/ { mResetRequired = FALSE; -} +} BOOLEAN IsResetReminderFeatureEnable ( @@ -870,7 +932,7 @@ IsResetReminderFeatureEnable ( /*++ Routine Description: - + Check whether platform policy enable the reset reminder feature. The default is enabled. Arguments: @@ -893,9 +955,9 @@ IsResetRequired ( /*++ Routine Description: - + Check if user changed any option setting which needs a system reset to be effective. - + Arguments: VOID @@ -916,9 +978,9 @@ SetupResetReminder ( /*++ Routine Description: - + Check whether a reset is needed, and finish the reset reminder feature. - If a reset is needed, Popup a menu to notice user, and finish the feature + If a reset is needed, Popup a menu to notice user, and finish the feature according to the user selection. Arguments: @@ -933,9 +995,9 @@ Returns: { EFI_STATUS Status; EFI_FORM_BROWSER_PROTOCOL *Browser; - EFI_INPUT_KEY Key; + EFI_INPUT_KEY Key; CHAR16 *StringBuffer1; - CHAR16 *StringBuffer2; + CHAR16 *StringBuffer2; // @@ -943,28 +1005,30 @@ Returns: // if (IsResetReminderFeatureEnable ()) { if (IsResetRequired ()) { - + Status = gBS->LocateProtocol ( &gEfiFormBrowserProtocolGuid, NULL, &Browser - ); - + ); + + ASSERT (Status != EFI_SUCCESS); + StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); ASSERT (StringBuffer1 != NULL); StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); - ASSERT (StringBuffer2 != NULL); + ASSERT (StringBuffer2 != NULL); StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? "); - StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)"); + StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)"); // // Popup a menu to notice user - // + // do { Browser->CreatePopUp (2, TRUE, 0, NULL, &Key, StringBuffer1, StringBuffer2); - } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN)); - - gBS->FreePool (StringBuffer1); - gBS->FreePool (StringBuffer2); + } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN)); + + FreePool (StringBuffer1); + FreePool (StringBuffer2); // // If the user hits the YES Response key, reset // @@ -972,6 +1036,59 @@ Returns: gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); } gST->ConOut->ClearScreen (gST->ConOut); - } - } -} + } + } +} + +EFI_STATUS +BdsLibGetHiiHandles ( + IN EFI_HII_PROTOCOL *Hii, + IN OUT UINT16 *HandleBufferLength, + OUT EFI_HII_HANDLE **HiiHandleBuffer + ) +/*++ + +Routine Description: + + Determines the handles that are currently active in the database. + It's the caller's responsibility to free handle buffer. + +Arguments: + + This - A pointer to the EFI_HII_PROTOCOL instance. + HandleBufferLength - On input, a pointer to the length of the handle buffer. On output, + the length of the handle buffer that is required for the handles found. + HiiHandleBuffer - Pointer to an array of EFI_HII_PROTOCOL instances returned. + +Returns: + + EFI_SUCCESS - Get an array of EFI_HII_PROTOCOL instances successfully. + EFI_INVALID_PARAMETER - Hii is NULL. + EFI_NOT_FOUND - Database not found. + +--*/ +{ + UINT16 TempBufferLength; + EFI_STATUS Status; + + TempBufferLength = 0; + + // + // Try to find the actual buffer size for HiiHandle Buffer. + // + Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer); + + if (Status == EFI_BUFFER_TOO_SMALL) { + *HiiHandleBuffer = AllocateZeroPool (TempBufferLength); + Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer); + // + // we should not fail here. + // + ASSERT_EFI_ERROR (Status); + } + + *HandleBufferLength = TempBufferLength; + + return Status; + +}