X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=EdkNt32Pkg%2FLibrary%2FEdkGenericBdsLib%2FBdsMisc.c;h=e7add072e18c30da4dfc828356c74df5b92bafc3;hb=d02ea958732846b91381c9050a5f43d503953974;hp=576ae7237f721dd065cb7d383d1ef3d4da21ac55;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4;p=mirror_edk2.git diff --git a/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c b/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c index 576ae7237f..e7add072e1 100644 --- a/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c +++ b/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c @@ -19,6 +19,9 @@ Abstract: --*/ +#define MAX_STRING_LEN 200 +static BOOLEAN mFeaturerSwitch = TRUE; +static BOOLEAN mResetRequired = FALSE; extern UINT16 gPlatformBootTimeOutDefault; UINT16 @@ -648,6 +651,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) { + gBS->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, @@ -685,7 +777,6 @@ Returns: DevicePath = Multi; DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); - Size -= sizeof (EFI_DEVICE_PATH_PROTOCOL); // // Search for the match of 'Single' in 'Multi' @@ -695,17 +786,13 @@ Returns: // If the single device path is found in multiple device paths, // return success // - if (Size == 0) { - return FALSE; - } - if (CompareMem (Single, DevicePathInst, Size) == 0) { + gBS->FreePool (DevicePathInst); return TRUE; } gBS->FreePool (DevicePathInst); DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); - Size -= sizeof (EFI_DEVICE_PATH_PROTOCOL); } return FALSE; @@ -762,3 +849,271 @@ Returns: return Status; } + +// +// 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 +// user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection. +// + +VOID +EnableResetReminderFeature ( + VOID + ) +/*++ + +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. + +Arguments: + + VOID + +Returns: + + VOID + +--*/ +{ + mFeaturerSwitch = TRUE; +} + +VOID +DisableResetReminderFeature ( + VOID + ) +/*++ + +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 + +Returns: + + VOID + +--*/ +{ + mFeaturerSwitch = FALSE; +} + +VOID +EnableResetRequired ( + VOID + ) +/*++ + +Routine Description: + + Record the info that a reset is required. + A module boolean variable is used to record whether a reset is required. + +Arguments: + + VOID + +Returns: + + VOID + +--*/ +{ + mResetRequired = TRUE; +} + +VOID +DisableResetRequired ( + VOID + ) +/*++ + +Routine Description: + + Record the info that no reset is required. + A module boolean variable is used to record whether a reset is required. + +Arguments: + + VOID + +Returns: + + VOID + +--*/ +{ + mResetRequired = FALSE; +} + +BOOLEAN +IsResetReminderFeatureEnable ( + VOID + ) +/*++ + +Routine Description: + + Check whether platform policy enable the reset reminder feature. The default is enabled. + +Arguments: + + VOID + +Returns: + + VOID + +--*/ +{ + return mFeaturerSwitch; +} + +BOOLEAN +IsResetRequired ( + VOID + ) +/*++ + +Routine Description: + + Check if user changed any option setting which needs a system reset to be effective. + +Arguments: + + VOID + +Returns: + + VOID + +--*/ +{ + return mResetRequired; +} + +VOID +SetupResetReminder ( + VOID + ) +/*++ + +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 + according to the user selection. + +Arguments: + + VOID + +Returns: + + VOID + +--*/ +{ + EFI_STATUS Status; + EFI_FORM_BROWSER_PROTOCOL *Browser; + EFI_INPUT_KEY Key; + CHAR16 *StringBuffer1; + CHAR16 *StringBuffer2; + + + // + //check any reset required change is applied? if yes, reset system + // + if (IsResetReminderFeatureEnable ()) { + if (IsResetRequired ()) { + + Status = gBS->LocateProtocol ( + &gEfiFormBrowserProtocolGuid, + NULL, + &Browser + ); + + StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); + ASSERT (StringBuffer1 != NULL); + StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); + ASSERT (StringBuffer2 != NULL); + StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? "); + 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); + // + // If the user hits the YES Response key, reset + // + if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) { + 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; + +}