X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FDriverSampleDxe%2FDriverSample.c;fp=MdeModulePkg%2FUniversal%2FDriverSampleDxe%2FDriverSample.c;h=62ba52e9402b577b7e135aa04930d2fa7ff059a9;hp=f98797225b639b3eeea26ae167cb5e5afae9a866;hb=1436aea4d5707e672672a11bda72be2c63c936c3;hpb=7c7184e201a90a1d2376e615e55e3f4074731468 diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index f98797225b..62ba52e940 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -7,19 +7,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #include "DriverSample.h" #define DISPLAY_ONLY_MY_ITEM 0x0002 -CHAR16 VariableName[] = L"MyIfrNVData"; -CHAR16 MyEfiVar[] = L"MyEfiVar"; -CHAR16 MyEfiBitVar[] = L"MyEfiBitVar"; -CHAR16 MyEfiUnionVar[] = L"MyEfiUnionVar"; +CHAR16 VariableName[] = L"MyIfrNVData"; +CHAR16 MyEfiVar[] = L"MyEfiVar"; +CHAR16 MyEfiBitVar[] = L"MyEfiBitVar"; +CHAR16 MyEfiUnionVar[] = L"MyEfiUnionVar"; -EFI_HANDLE DriverHandle[2] = {NULL, NULL}; -DRIVER_SAMPLE_PRIVATE_DATA *mPrivateData = NULL; -EFI_EVENT mEvent; +EFI_HANDLE DriverHandle[2] = { NULL, NULL }; +DRIVER_SAMPLE_PRIVATE_DATA *mPrivateData = NULL; +EFI_EVENT mEvent; HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = { { @@ -27,8 +26,8 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, { - (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + (UINT8)(sizeof (VENDOR_DEVICE_PATH)), + (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, DRIVER_SAMPLE_FORMSET_GUID @@ -37,8 +36,8 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { - (UINT8) (END_DEVICE_PATH_LENGTH), - (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) + (UINT8)(END_DEVICE_PATH_LENGTH), + (UINT8)((END_DEVICE_PATH_LENGTH) >> 8) } } }; @@ -49,8 +48,8 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, { - (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + (UINT8)(sizeof (VENDOR_DEVICE_PATH)), + (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, DRIVER_SAMPLE_INVENTORY_GUID @@ -59,8 +58,8 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { - (UINT8) (END_DEVICE_PATH_LENGTH), - (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) + (UINT8)(END_DEVICE_PATH_LENGTH), + (UINT8)((END_DEVICE_PATH_LENGTH) >> 8) } } }; @@ -76,34 +75,33 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = { **/ VOID SetArrayData ( - IN VOID *Array, - IN UINT8 Type, - IN UINTN Index, - IN UINT64 Value + IN VOID *Array, + IN UINT8 Type, + IN UINTN Index, + IN UINT64 Value ) { - ASSERT (Array != NULL); switch (Type) { - case EFI_IFR_TYPE_NUM_SIZE_8: - *(((UINT8 *) Array) + Index) = (UINT8) Value; - break; + case EFI_IFR_TYPE_NUM_SIZE_8: + *(((UINT8 *)Array) + Index) = (UINT8)Value; + break; - case EFI_IFR_TYPE_NUM_SIZE_16: - *(((UINT16 *) Array) + Index) = (UINT16) Value; - break; + case EFI_IFR_TYPE_NUM_SIZE_16: + *(((UINT16 *)Array) + Index) = (UINT16)Value; + break; - case EFI_IFR_TYPE_NUM_SIZE_32: - *(((UINT32 *) Array) + Index) = (UINT32) Value; - break; + case EFI_IFR_TYPE_NUM_SIZE_32: + *(((UINT32 *)Array) + Index) = (UINT32)Value; + break; - case EFI_IFR_TYPE_NUM_SIZE_64: - *(((UINT64 *) Array) + Index) = (UINT64) Value; - break; + case EFI_IFR_TYPE_NUM_SIZE_64: + *(((UINT64 *)Array) + Index) = (UINT64)Value; + break; - default: - break; + default: + break; } } @@ -116,8 +114,8 @@ SetArrayData ( **/ EFI_STATUS EFIAPI -NotificationFunction( - IN EFI_KEY_DATA *KeyData +NotificationFunction ( + IN EFI_KEY_DATA *KeyData ) { gBS->SignalEvent (mEvent); @@ -133,27 +131,27 @@ NotificationFunction( **/ EFI_STATUS EFIAPI -InternalStartMonitor( +InternalStartMonitor ( VOID ) { - EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx; - EFI_KEY_DATA KeyData; - EFI_STATUS Status; - EFI_HANDLE *Handles; - UINTN HandleCount; - UINTN HandleIndex; - VOID *NotifyHandle; + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx; + EFI_KEY_DATA KeyData; + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN HandleCount; + UINTN HandleIndex; + VOID *NotifyHandle; Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiSimpleTextInputExProtocolGuid, - NULL, - &HandleCount, - &Handles - ); + ByProtocol, + &gEfiSimpleTextInputExProtocolGuid, + NULL, + &HandleCount, + &Handles + ); for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { - Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx); + Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **)&SimpleEx); ASSERT_EFI_ERROR (Status); KeyData.KeyState.KeyToggleState = 0; @@ -161,21 +159,23 @@ InternalStartMonitor( KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED; KeyData.Key.UnicodeChar = L'c'; - Status = SimpleEx->RegisterKeyNotify( - SimpleEx, - &KeyData, - NotificationFunction, - &NotifyHandle); + Status = SimpleEx->RegisterKeyNotify ( + SimpleEx, + &KeyData, + NotificationFunction, + &NotifyHandle + ); if (EFI_ERROR (Status)) { break; } - KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED; - Status = SimpleEx->RegisterKeyNotify( - SimpleEx, - &KeyData, - NotificationFunction, - &NotifyHandle); + KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED; + Status = SimpleEx->RegisterKeyNotify ( + SimpleEx, + &KeyData, + NotificationFunction, + &NotifyHandle + ); if (EFI_ERROR (Status)) { break; } @@ -192,27 +192,27 @@ InternalStartMonitor( **/ EFI_STATUS EFIAPI -InternalStopMonitor( +InternalStopMonitor ( VOID ) { - EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx; - EFI_STATUS Status; - EFI_HANDLE *Handles; - EFI_KEY_DATA KeyData; - UINTN HandleCount; - UINTN HandleIndex; - VOID *NotifyHandle; + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx; + EFI_STATUS Status; + EFI_HANDLE *Handles; + EFI_KEY_DATA KeyData; + UINTN HandleCount; + UINTN HandleIndex; + VOID *NotifyHandle; Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiSimpleTextInputExProtocolGuid, - NULL, - &HandleCount, - &Handles - ); + ByProtocol, + &gEfiSimpleTextInputExProtocolGuid, + NULL, + &HandleCount, + &Handles + ); for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { - Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx); + Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **)&SimpleEx); ASSERT_EFI_ERROR (Status); KeyData.KeyState.KeyToggleState = 0; @@ -220,25 +220,28 @@ InternalStopMonitor( KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED; KeyData.Key.UnicodeChar = L'c'; - Status = SimpleEx->RegisterKeyNotify( - SimpleEx, - &KeyData, - NotificationFunction, - &NotifyHandle); + Status = SimpleEx->RegisterKeyNotify ( + SimpleEx, + &KeyData, + NotificationFunction, + &NotifyHandle + ); if (!EFI_ERROR (Status)) { Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle); } - KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED; - Status = SimpleEx->RegisterKeyNotify( - SimpleEx, - &KeyData, - NotificationFunction, - &NotifyHandle); + KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED; + Status = SimpleEx->RegisterKeyNotify ( + SimpleEx, + &KeyData, + NotificationFunction, + &NotifyHandle + ); if (!EFI_ERROR (Status)) { Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle); } } + return EFI_SUCCESS; } @@ -253,20 +256,20 @@ InternalStopMonitor( **/ EFI_STATUS LoadNameValueNames ( - IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData + IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData ) { - UINTN Index; + UINTN Index; // // Get Name/Value name string of current language // for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) { PrivateData->NameValueName[Index] = HiiGetString ( - PrivateData->HiiHandle[0], - PrivateData->NameStringId[Index], - NULL - ); + PrivateData->HiiHandle[0], + PrivateData->NameStringId[Index], + NULL + ); if (PrivateData->NameValueName[Index] == NULL) { return EFI_NOT_FOUND; } @@ -275,7 +278,6 @@ LoadNameValueNames ( return EFI_SUCCESS; } - /** Get the value of in format, i.e. the value of OFFSET or WIDTH or VALUE. @@ -297,21 +299,21 @@ LoadNameValueNames ( **/ EFI_STATUS GetValueOfNumber ( - IN EFI_STRING StringPtr, - OUT UINT8 **Number, - OUT UINTN *Len + IN EFI_STRING StringPtr, + OUT UINT8 **Number, + OUT UINTN *Len ) { - EFI_STRING TmpPtr; - UINTN Length; - EFI_STRING Str; - UINT8 *Buf; - EFI_STATUS Status; - UINT8 DigitUint8; - UINTN Index; - CHAR16 TemStr[2]; - - if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) { + EFI_STRING TmpPtr; + UINTN Length; + EFI_STRING Str; + UINT8 *Buf; + EFI_STATUS Status; + UINT8 DigitUint8; + UINTN Index; + CHAR16 TemStr[2]; + + if ((StringPtr == NULL) || (*StringPtr == L'\0') || (Number == NULL) || (Len == NULL)) { return EFI_INVALID_PARAMETER; } @@ -321,19 +323,21 @@ GetValueOfNumber ( while (*StringPtr != L'\0' && *StringPtr != L'&') { StringPtr++; } + *Len = StringPtr - TmpPtr; Length = *Len + 1; - Str = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16)); + Str = (EFI_STRING)AllocateZeroPool (Length * sizeof (CHAR16)); if (Str == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Exit; } + CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16)); *(Str + *Len) = L'\0'; Length = (Length + 1) / 2; - Buf = (UINT8 *) AllocateZeroPool (Length); + Buf = (UINT8 *)AllocateZeroPool (Length); if (Buf == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Exit; @@ -341,13 +345,13 @@ GetValueOfNumber ( Length = *Len; ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0; Index < Length; Index ++) { - TemStr[0] = Str[Length - Index - 1]; - DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + for (Index = 0; Index < Length; Index++) { + TemStr[0] = Str[Length - Index - 1]; + DigitUint8 = (UINT8)StrHexToUint64 (TemStr); if ((Index & 1) == 0) { - Buf [Index/2] = DigitUint8; + Buf[Index/2] = DigitUint8; } else { - Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]); + Buf[Index/2] = (UINT8)((DigitUint8 << 4) + Buf[Index/2]); } } @@ -375,21 +379,21 @@ Exit: **/ EFI_STRING CreateAltCfgString ( - IN EFI_STRING Result, - IN EFI_STRING ConfigHdr, - IN UINTN Offset, - IN UINTN Width + IN EFI_STRING Result, + IN EFI_STRING ConfigHdr, + IN UINTN Offset, + IN UINTN Width ) { - EFI_STRING StringPtr; - EFI_STRING TmpStr; - UINTN NewLen; + EFI_STRING StringPtr; + EFI_STRING TmpStr; + UINTN NewLen; NewLen = StrLen (Result); // // String Len = ConfigResp + AltConfig + AltConfig + 1("\0") // - NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16); + NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16); StringPtr = AllocateZeroPool (NewLen); if (StringPtr == NULL) { return NULL; @@ -403,12 +407,12 @@ CreateAltCfgString ( } UnicodeSPrint ( - StringPtr, - (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), - L"&%s&ALTCFG=%04x", - ConfigHdr, - EFI_HII_DEFAULT_CLASS_STANDARD - ); + StringPtr, + (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), + L"&%s&ALTCFG=%04x", + ConfigHdr, + EFI_HII_DEFAULT_CLASS_STANDARD + ); StringPtr += StrLen (StringPtr); UnicodeSPrint ( @@ -422,12 +426,12 @@ CreateAltCfgString ( StringPtr += StrLen (StringPtr); UnicodeSPrint ( - StringPtr, - (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), - L"&%s&ALTCFG=%04x", - ConfigHdr, - EFI_HII_DEFAULT_CLASS_MANUFACTURING - ); + StringPtr, + (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), + L"&%s&ALTCFG=%04x", + ConfigHdr, + EFI_HII_DEFAULT_CLASS_MANUFACTURING + ); StringPtr += StrLen (StringPtr); UnicodeSPrint ( @@ -453,24 +457,24 @@ CreateAltCfgString ( **/ VOID AppendAltCfgString ( - IN OUT EFI_STRING *RequestResult, - IN EFI_STRING ConfigRequestHdr + IN OUT EFI_STRING *RequestResult, + IN EFI_STRING ConfigRequestHdr ) { - EFI_STRING StringPtr; - UINTN Length; - UINT8 *TmpBuffer; - UINTN Offset; - UINTN Width; - UINTN BlockSize; - UINTN ValueOffset; - UINTN ValueWidth; - EFI_STATUS Status; - - TmpBuffer = NULL; - StringPtr = *RequestResult; - StringPtr = StrStr (StringPtr, L"OFFSET"); - BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); + EFI_STRING StringPtr; + UINTN Length; + UINT8 *TmpBuffer; + UINTN Offset; + UINTN Width; + UINTN BlockSize; + UINTN ValueOffset; + UINTN ValueWidth; + EFI_STATUS Status; + + TmpBuffer = NULL; + StringPtr = *RequestResult; + StringPtr = StrStr (StringPtr, L"OFFSET"); + BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); ValueOffset = OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, GetDefaultValueFromAccess); ValueWidth = sizeof (((DRIVER_SAMPLE_CONFIGURATION *)0)->GetDefaultValueFromAccess); @@ -487,18 +491,20 @@ AppendAltCfgString ( if (EFI_ERROR (Status)) { return; } + Offset = 0; CopyMem ( - &Offset, - TmpBuffer, - (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN) - ); + &Offset, + TmpBuffer, + (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN) + ); FreePool (TmpBuffer); StringPtr += Length; if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) { return; } + StringPtr += StrLen (L"&WIDTH="); // @@ -508,18 +514,20 @@ AppendAltCfgString ( if (EFI_ERROR (Status)) { return; } + Width = 0; CopyMem ( - &Width, - TmpBuffer, - (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN) - ); + &Width, + TmpBuffer, + (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN) + ); FreePool (TmpBuffer); StringPtr += Length; if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) { return; } + StringPtr += StrLen (L"&VALUE="); // @@ -529,12 +537,13 @@ AppendAltCfgString ( if (EFI_ERROR (Status)) { return; } + StringPtr += Length; // // Skip the character "&" before "OFFSET". // - StringPtr ++; + StringPtr++; // // Calculate Value and convert it to hex string. @@ -543,8 +552,8 @@ AppendAltCfgString ( return; } - if (Offset <= ValueOffset && Offset + Width >= ValueOffset + ValueWidth) { - *RequestResult = CreateAltCfgString(*RequestResult, ConfigRequestHdr, ValueOffset, ValueWidth); + if ((Offset <= ValueOffset) && (Offset + Width >= ValueOffset + ValueWidth)) { + *RequestResult = CreateAltCfgString (*RequestResult, ConfigRequestHdr, ValueOffset, ValueWidth); return; } } @@ -579,10 +588,10 @@ AppendAltCfgString ( EFI_STATUS EFIAPI ExtractConfig ( - IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, - IN CONST EFI_STRING Request, - OUT EFI_STRING *Progress, - OUT EFI_STRING *Results + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Request, + OUT EFI_STRING *Progress, + OUT EFI_STRING *Results ) { EFI_STATUS Status; @@ -598,19 +607,20 @@ ExtractConfig ( CHAR16 *StrPointer; BOOLEAN AllocatedRequest; - if (Progress == NULL || Results == NULL) { + if ((Progress == NULL) || (Results == NULL)) { return EFI_INVALID_PARAMETER; } + // // Initialize the local variables. // - ConfigRequestHdr = NULL; - ConfigRequest = NULL; - Size = 0; - *Progress = Request; - AllocatedRequest = FALSE; + ConfigRequestHdr = NULL; + ConfigRequest = NULL; + Size = 0; + *Progress = Request; + AllocatedRequest = FALSE; - PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); + PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); HiiConfigRouting = PrivateData->HiiConfigRouting; // @@ -618,13 +628,13 @@ ExtractConfig ( // Try to get the current setting from variable. // BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); - Status = gRT->GetVariable ( - VariableName, - &gDriverSampleFormSetGuid, - NULL, - &BufferSize, - &PrivateData->Configuration - ); + Status = gRT->GetVariable ( + VariableName, + &gDriverSampleFormSetGuid, + NULL, + &BufferSize, + &PrivateData->Configuration + ); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } @@ -639,8 +649,8 @@ ExtractConfig ( // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator // ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]); - Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); - ConfigRequest = AllocateZeroPool (Size); + Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (Size); ASSERT (ConfigRequest != NULL); AllocatedRequest = TRUE; UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); @@ -654,17 +664,20 @@ ExtractConfig ( if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) { return EFI_NOT_FOUND; } + // // Check whether request for EFI Varstore. EFI varstore get data // through hii database, not support in this path. // - if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiVar)) { + if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiVar)) { return EFI_UNSUPPORTED; } - if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiBitVar)) { + + if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiBitVar)) { return EFI_UNSUPPORTED; } - if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiUnionVar)) { + + if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiUnionVar)) { return EFI_UNSUPPORTED; } @@ -683,9 +696,10 @@ ExtractConfig ( if (StrPointer == NULL) { return EFI_INVALID_PARAMETER; } + if (StrStr (StrPointer, L"&") == NULL) { - Size = (StrLen (Request) + 32 + 1) * sizeof (CHAR16); - ConfigRequest = AllocateZeroPool (Size); + Size = (StrLen (Request) + 32 + 1) * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (Size); ASSERT (ConfigRequest != NULL); AllocatedRequest = TRUE; UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", Request, (UINT64)BufferSize); @@ -711,9 +725,9 @@ ExtractConfig ( // ::=&Name0=11&Name1=1234&Name2=0041004200430044 // BufferSize = (StrLen (ConfigRequest) + - 1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 + - 1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 + - 1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16); + 1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 + + 1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 + + 1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16); *Results = AllocateZeroPool (BufferSize); ASSERT (*Results != NULL); StrCpyS (*Results, BufferSize / sizeof (CHAR16), ConfigRequest); @@ -723,7 +737,7 @@ ExtractConfig ( // Append value of NameValueVar0, type is UINT8 // if ((Value = StrStr (*Results, PrivateData->NameValueName[0])) != NULL) { - Value += StrLen (PrivateData->NameValueName[0]); + Value += StrLen (PrivateData->NameValueName[0]); ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar0) * 2) + 1); CopyMem (Value + ValueStrLen, Value, StrSize (Value)); @@ -744,7 +758,7 @@ ExtractConfig ( // Append value of NameValueVar1, type is UINT16 // if ((Value = StrStr (*Results, PrivateData->NameValueName[1])) != NULL) { - Value += StrLen (PrivateData->NameValueName[1]); + Value += StrLen (PrivateData->NameValueName[1]); ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar1) * 2) + 1); CopyMem (Value + ValueStrLen, Value, StrSize (Value)); @@ -765,7 +779,7 @@ ExtractConfig ( // Append value of NameValueVar2, type is CHAR16 * // if ((Value = StrStr (*Results, PrivateData->NameValueName[2])) != NULL) { - Value += StrLen (PrivateData->NameValueName[2]); + Value += StrLen (PrivateData->NameValueName[2]); ValueStrLen = StrLen (PrivateData->Configuration.NameValueVar2) * 4 + 1; CopyMem (Value + ValueStrLen, Value, StrSize (Value)); @@ -773,8 +787,8 @@ ExtractConfig ( // // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044" // - StrPointer = (CHAR16 *) PrivateData->Configuration.NameValueVar2; - for (; *StrPointer != L'\0'; StrPointer++) { + StrPointer = (CHAR16 *)PrivateData->Configuration.NameValueVar2; + for ( ; *StrPointer != L'\0'; StrPointer++) { UnicodeValueToStringS ( Value, BufferSize - ((UINTN)Value - (UINTN)*Results), @@ -792,16 +806,16 @@ ExtractConfig ( // Convert buffer data to by helper function BlockToConfig() // Status = HiiConfigRouting->BlockToConfig ( - HiiConfigRouting, - ConfigRequest, - (UINT8 *) &PrivateData->Configuration, - BufferSize, - Results, - Progress - ); + HiiConfigRouting, + ConfigRequest, + (UINT8 *)&PrivateData->Configuration, + BufferSize, + Results, + Progress + ); if (!EFI_ERROR (Status)) { ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]); - AppendAltCfgString(Results, ConfigRequestHdr); + AppendAltCfgString (Results, ConfigRequestHdr); } } @@ -815,6 +829,7 @@ ExtractConfig ( if (ConfigRequestHdr != NULL) { FreePool (ConfigRequestHdr); } + // // Set Progress string to the original request string. // @@ -827,7 +842,6 @@ ExtractConfig ( return Status; } - /** This function processes the results of changes in configuration. @@ -849,9 +863,9 @@ ExtractConfig ( EFI_STATUS EFIAPI RouteConfig ( - IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, - IN CONST EFI_STRING Configuration, - OUT EFI_STRING *Progress + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Configuration, + OUT EFI_STRING *Progress ) { EFI_STATUS Status; @@ -866,13 +880,13 @@ RouteConfig ( UINTN Index; CHAR16 *StrBuffer; - if (Configuration == NULL || Progress == NULL) { + if ((Configuration == NULL) || (Progress == NULL)) { return EFI_INVALID_PARAMETER; } - PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); + PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); HiiConfigRouting = PrivateData->HiiConfigRouting; - *Progress = Configuration; + *Progress = Configuration; // // Check routing data in . @@ -886,13 +900,15 @@ RouteConfig ( // Check whether request for EFI Varstore. EFI varstore get data // through hii database, not support in this path. // - if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) { + if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) { return EFI_UNSUPPORTED; } - if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiBitVar)) { + + if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiBitVar)) { return EFI_UNSUPPORTED; } - if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiUnionVar)) { + + if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiUnionVar)) { return EFI_UNSUPPORTED; } @@ -900,13 +916,13 @@ RouteConfig ( // Get Buffer Storage data from EFI variable // BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); - Status = gRT->GetVariable ( - VariableName, - &gDriverSampleFormSetGuid, - NULL, - &BufferSize, - &PrivateData->Configuration - ); + Status = gRT->GetVariable ( + VariableName, + &gDriverSampleFormSetGuid, + NULL, + &BufferSize, + &PrivateData->Configuration + ); if (EFI_ERROR (Status)) { return Status; } @@ -939,18 +955,19 @@ RouteConfig ( if (StrPtr == NULL) { StrPtr = Value + StrLen (Value); } + // // Convert Value to Buffer data // - DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar0; + DataBuffer = (UINT8 *)&PrivateData->Configuration.NameValueVar0; ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) { - TemStr[0] = *StrPtr; - DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + for (Index = 0, StrPtr--; StrPtr >= Value; StrPtr--, Index++) { + TemStr[0] = *StrPtr; + DigitUint8 = (UINT8)StrHexToUint64 (TemStr); if ((Index & 1) == 0) { - DataBuffer [Index/2] = DigitUint8; + DataBuffer[Index/2] = DigitUint8; } else { - DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]); + DataBuffer[Index/2] = (UINT8)((UINT8)(DigitUint8 << 4) + DataBuffer[Index/2]); } } } @@ -971,18 +988,19 @@ RouteConfig ( if (StrPtr == NULL) { StrPtr = Value + StrLen (Value); } + // // Convert Value to Buffer data // - DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar1; + DataBuffer = (UINT8 *)&PrivateData->Configuration.NameValueVar1; ZeroMem (TemStr, sizeof (TemStr)); - for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) { - TemStr[0] = *StrPtr; - DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + for (Index = 0, StrPtr--; StrPtr >= Value; StrPtr--, Index++) { + TemStr[0] = *StrPtr; + DigitUint8 = (UINT8)StrHexToUint64 (TemStr); if ((Index & 1) == 0) { - DataBuffer [Index/2] = DigitUint8; + DataBuffer[Index/2] = DigitUint8; } else { - DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]); + DataBuffer[Index/2] = (UINT8)((UINT8)(DigitUint8 << 4) + DataBuffer[Index/2]); } } } @@ -1003,29 +1021,31 @@ RouteConfig ( if (StrPtr == NULL) { StrPtr = Value + StrLen (Value); } + // // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD" // - StrBuffer = (CHAR16 *) PrivateData->Configuration.NameValueVar2; + StrBuffer = (CHAR16 *)PrivateData->Configuration.NameValueVar2; ZeroMem (TemStr, sizeof (TemStr)); while (Value < StrPtr) { StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value, 4); - *(StrBuffer++) = (CHAR16) StrHexToUint64 (TemStr); - Value += 4; + *(StrBuffer++) = (CHAR16)StrHexToUint64 (TemStr); + Value += 4; } + *StrBuffer = L'\0'; } // // Store Buffer Storage back to EFI variable // - Status = gRT->SetVariable( - VariableName, - &gDriverSampleFormSetGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, - sizeof (DRIVER_SAMPLE_CONFIGURATION), - &PrivateData->Configuration - ); + Status = gRT->SetVariable ( + VariableName, + &gDriverSampleFormSetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (DRIVER_SAMPLE_CONFIGURATION), + &PrivateData->Configuration + ); return Status; } @@ -1034,13 +1054,13 @@ RouteConfig ( // Convert to buffer data by helper function ConfigToBlock() // BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); - Status = HiiConfigRouting->ConfigToBlock ( - HiiConfigRouting, - Configuration, - (UINT8 *) &PrivateData->Configuration, - &BufferSize, - Progress - ); + Status = HiiConfigRouting->ConfigToBlock ( + HiiConfigRouting, + Configuration, + (UINT8 *)&PrivateData->Configuration, + &BufferSize, + Progress + ); if (EFI_ERROR (Status)) { return Status; } @@ -1048,7 +1068,7 @@ RouteConfig ( // // Store Buffer Storage back to EFI variable // - Status = gRT->SetVariable( + Status = gRT->SetVariable ( VariableName, &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, @@ -1059,7 +1079,6 @@ RouteConfig ( return Status; } - /** This function processes the results of changes in configuration. @@ -1085,49 +1104,49 @@ RouteConfig ( EFI_STATUS EFIAPI DriverCallback ( - IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, - IN EFI_BROWSER_ACTION Action, - IN EFI_QUESTION_ID QuestionId, - IN UINT8 Type, - IN EFI_IFR_TYPE_VALUE *Value, - OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN EFI_BROWSER_ACTION Action, + IN EFI_QUESTION_ID QuestionId, + IN UINT8 Type, + IN EFI_IFR_TYPE_VALUE *Value, + OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest ) { - DRIVER_SAMPLE_PRIVATE_DATA *PrivateData; - EFI_STATUS Status; - VOID *StartOpCodeHandle; - VOID *OptionsOpCodeHandle; - EFI_IFR_GUID_LABEL *StartLabel; - VOID *EndOpCodeHandle; - EFI_IFR_GUID_LABEL *EndLabel; - EFI_INPUT_KEY Key; - DRIVER_SAMPLE_CONFIGURATION *Configuration; - MY_EFI_VARSTORE_DATA *EfiData; - EFI_FORM_ID FormId; - EFI_STRING Progress; - EFI_STRING Results; - UINT32 ProgressErr; - CHAR16 *TmpStr; - UINTN Index; - UINT64 BufferValue; - EFI_HII_POPUP_SELECTION UserSelection; + DRIVER_SAMPLE_PRIVATE_DATA *PrivateData; + EFI_STATUS Status; + VOID *StartOpCodeHandle; + VOID *OptionsOpCodeHandle; + EFI_IFR_GUID_LABEL *StartLabel; + VOID *EndOpCodeHandle; + EFI_IFR_GUID_LABEL *EndLabel; + EFI_INPUT_KEY Key; + DRIVER_SAMPLE_CONFIGURATION *Configuration; + MY_EFI_VARSTORE_DATA *EfiData; + EFI_FORM_ID FormId; + EFI_STRING Progress; + EFI_STRING Results; + UINT32 ProgressErr; + CHAR16 *TmpStr; + UINTN Index; + UINT64 BufferValue; + EFI_HII_POPUP_SELECTION UserSelection; UserSelection = 0xFF; - if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))|| - (ActionRequest == NULL)) { + if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) || + (ActionRequest == NULL)) + { return EFI_INVALID_PARAMETER; } - - FormId = 0; + FormId = 0; ProgressErr = 0; - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; BufferValue = 3; PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); switch (Action) { - case EFI_BROWSER_ACTION_FORM_OPEN: + case EFI_BROWSER_ACTION_FORM_OPEN: { if (QuestionId == 0x1234) { // @@ -1146,18 +1165,18 @@ DriverCallback ( // // Create Hii Extend Label OpCode as the start opcode // - StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; StartLabel->Number = LABEL_UPDATE2; HiiCreateActionOpCode ( StartOpCodeHandle, // Container for dynamic created opcodes 0x1238, // Question ID - STRING_TOKEN(STR_SAVE_TEXT), // Prompt text - STRING_TOKEN(STR_SAVE_TEXT), // Help text + STRING_TOKEN (STR_SAVE_TEXT), // Prompt text + STRING_TOKEN (STR_SAVE_TEXT), // Help text EFI_IFR_FLAG_CALLBACK, // Question flag 0 // Action String ID - ); + ); HiiUpdateForm ( PrivateData->HiiHandle[0], // HII handle @@ -1174,10 +1193,11 @@ DriverCallback ( Status = InternalStartMonitor (); ASSERT_EFI_ERROR (Status); } + + break; } - break; - case EFI_BROWSER_ACTION_FORM_CLOSE: + case EFI_BROWSER_ACTION_FORM_CLOSE: { if (QuestionId == 0x5678) { // @@ -1201,467 +1221,482 @@ DriverCallback ( Status = InternalStopMonitor (); ASSERT_EFI_ERROR (Status); } + + break; } - break; - case EFI_BROWSER_ACTION_RETRIEVE: + case EFI_BROWSER_ACTION_RETRIEVE: { switch (QuestionId ) { - case 0x1248: - if (Type != EFI_IFR_TYPE_REF) { - return EFI_INVALID_PARAMETER; - } - Value->ref.FormId = 0x3; - break; + case 0x1248: + if (Type != EFI_IFR_TYPE_REF) { + return EFI_INVALID_PARAMETER; + } - case 0x5678: - case 0x1247: - // - // We will reach here once the Question is refreshed - // + Value->ref.FormId = 0x3; + break; - // - // Initialize the container for dynamic opcodes - // - StartOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (StartOpCodeHandle != NULL); + case 0x5678: + case 0x1247: + // + // We will reach here once the Question is refreshed + // - // - // 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; - if (QuestionId == 0x5678) { - StartLabel->Number = LABEL_UPDATE2; - FormId = 0x03; - PrivateData->Configuration.DynamicRefresh++; - } else if (QuestionId == 0x1247 ) { - StartLabel->Number = LABEL_UPDATE3; - FormId = 0x06; - PrivateData->Configuration.RefreshGuidCount++; - } + // + // Initialize the container for dynamic opcodes + // + StartOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (StartOpCodeHandle != NULL); - HiiCreateActionOpCode ( - StartOpCodeHandle, // Container for dynamic created opcodes - 0x1237, // Question ID - STRING_TOKEN(STR_EXIT_TEXT), // Prompt text - STRING_TOKEN(STR_EXIT_TEXT), // Help text - EFI_IFR_FLAG_CALLBACK, // Question flag - 0 // Action String ID - ); + // + // 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; + if (QuestionId == 0x5678) { + StartLabel->Number = LABEL_UPDATE2; + FormId = 0x03; + PrivateData->Configuration.DynamicRefresh++; + } else if (QuestionId == 0x1247 ) { + StartLabel->Number = LABEL_UPDATE3; + FormId = 0x06; + PrivateData->Configuration.RefreshGuidCount++; + } - HiiUpdateForm ( - PrivateData->HiiHandle[0], // HII handle - &gDriverSampleFormSetGuid, // Formset GUID - FormId, // Form ID - StartOpCodeHandle, // Label for where to insert opcodes - NULL // Insert data - ); + HiiCreateActionOpCode ( + StartOpCodeHandle, // Container for dynamic created opcodes + 0x1237, // Question ID + STRING_TOKEN (STR_EXIT_TEXT), // Prompt text + STRING_TOKEN (STR_EXIT_TEXT), // Help text + EFI_IFR_FLAG_CALLBACK, // Question flag + 0 // Action String ID + ); - HiiFreeOpCodeHandle (StartOpCodeHandle); + HiiUpdateForm ( + PrivateData->HiiHandle[0], // HII handle + &gDriverSampleFormSetGuid, // Formset GUID + FormId, // Form ID + StartOpCodeHandle, // Label for where to insert opcodes + NULL // Insert data + ); + + HiiFreeOpCodeHandle (StartOpCodeHandle); - // - // Refresh the Question value - // - Status = gRT->SetVariable( - VariableName, - &gDriverSampleFormSetGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, - sizeof (DRIVER_SAMPLE_CONFIGURATION), - &PrivateData->Configuration - ); - - if (QuestionId == 0x5678) { // - // Update uncommitted data of Browser + // Refresh the Question value // - EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA)); - ASSERT (EfiData != NULL); - if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *) EfiData)) { - EfiData->Field8 = 111; - HiiSetBrowserData ( - &gDriverSampleFormSetGuid, - MyEfiVar, - sizeof (MY_EFI_VARSTORE_DATA), - (UINT8 *) EfiData, - NULL - ); + Status = gRT->SetVariable ( + VariableName, + &gDriverSampleFormSetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (DRIVER_SAMPLE_CONFIGURATION), + &PrivateData->Configuration + ); + + if (QuestionId == 0x5678) { + // + // Update uncommitted data of Browser + // + EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA)); + ASSERT (EfiData != NULL); + if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *)EfiData)) { + EfiData->Field8 = 111; + HiiSetBrowserData ( + &gDriverSampleFormSetGuid, + MyEfiVar, + sizeof (MY_EFI_VARSTORE_DATA), + (UINT8 *)EfiData, + NULL + ); + } + + FreePool (EfiData); } - FreePool (EfiData); - } - break; + + break; } + + break; } - break; - case EFI_BROWSER_ACTION_DEFAULT_STANDARD: + case EFI_BROWSER_ACTION_DEFAULT_STANDARD: { switch (QuestionId) { - case 0x1240: - Value->u8 = DEFAULT_CLASS_STANDARD_VALUE; - break; + case 0x1240: + Value->u8 = DEFAULT_CLASS_STANDARD_VALUE; + break; - case 0x1252: - for (Index = 0; Index < 3; Index ++) { - SetArrayData (Value, EFI_IFR_TYPE_NUM_SIZE_8, Index, BufferValue--); - } - break; + case 0x1252: + for (Index = 0; Index < 3; Index++) { + SetArrayData (Value, EFI_IFR_TYPE_NUM_SIZE_8, Index, BufferValue--); + } - case 0x6666: - Value->u8 = 12; - break; + break; - default: - Status = EFI_UNSUPPORTED; - break; + case 0x6666: + Value->u8 = 12; + break; + + default: + Status = EFI_UNSUPPORTED; + break; } + + break; } - break; - case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING: + case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING: { switch (QuestionId) { - case 0x1240: - Value->u8 = DEFAULT_CLASS_MANUFACTURING_VALUE; - break; + case 0x1240: + Value->u8 = DEFAULT_CLASS_MANUFACTURING_VALUE; + break; - case 0x6666: - Value->u8 = 13; - break; + case 0x6666: + Value->u8 = 13; + break; - default: - Status = EFI_UNSUPPORTED; - break; + default: + Status = EFI_UNSUPPORTED; + break; } + + break; } - break; - case EFI_BROWSER_ACTION_CHANGING: - { - switch (QuestionId) { - case 0x1249: - { - if (Type != EFI_IFR_TYPE_REF) { - return EFI_INVALID_PARAMETER; + case EFI_BROWSER_ACTION_CHANGING: + { + switch (QuestionId) { + case 0x1249: + { + if (Type != EFI_IFR_TYPE_REF) { + return EFI_INVALID_PARAMETER; + } + + Value->ref.FormId = 0x1234; + break; } + case 0x1234: + // + // Initialize the container for dynamic opcodes + // + StartOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (StartOpCodeHandle != NULL); - Value->ref.FormId = 0x1234; - } - break; - case 0x1234: - // - // Initialize the container for dynamic opcodes - // - StartOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (StartOpCodeHandle != NULL); + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != 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_UPDATE1; - // - // 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_UPDATE1; + // + // 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; + + HiiCreateActionOpCode ( + StartOpCodeHandle, // Container for dynamic created opcodes + 0x1237, // Question ID + STRING_TOKEN (STR_EXIT_TEXT), // Prompt text + STRING_TOKEN (STR_EXIT_TEXT), // Help text + EFI_IFR_FLAG_CALLBACK, // Question flag + 0 // Action String ID + ); - // - // 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; - - HiiCreateActionOpCode ( - StartOpCodeHandle, // Container for dynamic created opcodes - 0x1237, // Question ID - STRING_TOKEN(STR_EXIT_TEXT), // Prompt text - STRING_TOKEN(STR_EXIT_TEXT), // Help text - EFI_IFR_FLAG_CALLBACK, // Question flag - 0 // Action String ID - ); + // + // Create Option OpCode + // + OptionsOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (OptionsOpCodeHandle != NULL); + + HiiCreateOneOfOptionOpCode ( + OptionsOpCodeHandle, + STRING_TOKEN (STR_BOOT_OPTION1), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 1 + ); - // - // Create Option OpCode - // - OptionsOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (OptionsOpCodeHandle != NULL); - - HiiCreateOneOfOptionOpCode ( - OptionsOpCodeHandle, - STRING_TOKEN (STR_BOOT_OPTION1), - 0, - EFI_IFR_NUMERIC_SIZE_1, - 1 - ); + HiiCreateOneOfOptionOpCode ( + OptionsOpCodeHandle, + STRING_TOKEN (STR_BOOT_OPTION2), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 2 + ); - HiiCreateOneOfOptionOpCode ( - OptionsOpCodeHandle, - STRING_TOKEN (STR_BOOT_OPTION2), - 0, - EFI_IFR_NUMERIC_SIZE_1, - 2 - ); + // + // Prepare initial value for the dynamic created oneof Question + // + PrivateData->Configuration.DynamicOneof = 2; + Status = gRT->SetVariable ( + VariableName, + &gDriverSampleFormSetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (DRIVER_SAMPLE_CONFIGURATION), + &PrivateData->Configuration + ); - // - // Prepare initial value for the dynamic created oneof Question - // - PrivateData->Configuration.DynamicOneof = 2; - Status = gRT->SetVariable( - VariableName, - &gDriverSampleFormSetGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, - sizeof (DRIVER_SAMPLE_CONFIGURATION), - &PrivateData->Configuration - ); + // + // Set initial vlaue of dynamic created oneof Question in Form Browser + // + Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION)); + ASSERT (Configuration != NULL); + if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *)Configuration)) { + Configuration->DynamicOneof = 2; + + // + // Update uncommitted data of Browser + // + HiiSetBrowserData ( + &gDriverSampleFormSetGuid, + VariableName, + sizeof (DRIVER_SAMPLE_CONFIGURATION), + (UINT8 *)Configuration, + NULL + ); + } - // - // Set initial vlaue of dynamic created oneof Question in Form Browser - // - Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION)); - ASSERT (Configuration != NULL); - if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) { - Configuration->DynamicOneof = 2; + FreePool (Configuration); + + HiiCreateOneOfOpCode ( + StartOpCodeHandle, // Container for dynamic created opcodes + 0x8001, // Question ID (or call it "key") + CONFIGURATION_VARSTORE_ID, // VarStore ID + (UINT16)DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage + STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text + STRING_TOKEN (STR_ONE_OF_HELP), // Question help text + EFI_IFR_FLAG_CALLBACK, // Question flag + EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value + OptionsOpCodeHandle, // Option Opcode list + NULL // Default Opcode is NULl + ); - // - // Update uncommitted data of Browser - // - HiiSetBrowserData ( - &gDriverSampleFormSetGuid, - VariableName, - sizeof (DRIVER_SAMPLE_CONFIGURATION), - (UINT8 *) Configuration, - NULL - ); - } - FreePool (Configuration); - - HiiCreateOneOfOpCode ( - StartOpCodeHandle, // Container for dynamic created opcodes - 0x8001, // Question ID (or call it "key") - CONFIGURATION_VARSTORE_ID, // VarStore ID - (UINT16) DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage - STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text - STRING_TOKEN (STR_ONE_OF_HELP), // Question help text - EFI_IFR_FLAG_CALLBACK, // Question flag - EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value - OptionsOpCodeHandle, // Option Opcode list - NULL // Default Opcode is NULl - ); + HiiCreateOrderedListOpCode ( + StartOpCodeHandle, // Container for dynamic created opcodes + 0x8002, // Question ID + CONFIGURATION_VARSTORE_ID, // VarStore ID + (UINT16)DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage + STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text + STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text + EFI_IFR_FLAG_RESET_REQUIRED, // Question flag + 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET + EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value + 5, // Maximum container + OptionsOpCodeHandle, // Option Opcode list + NULL // Default Opcode is NULl + ); - HiiCreateOrderedListOpCode ( - StartOpCodeHandle, // Container for dynamic created opcodes - 0x8002, // Question ID - CONFIGURATION_VARSTORE_ID, // VarStore ID - (UINT16) DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage - STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text - STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text - EFI_IFR_FLAG_RESET_REQUIRED, // Question flag - 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET - EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value - 5, // Maximum container - OptionsOpCodeHandle, // Option Opcode list - NULL // Default Opcode is NULl - ); + HiiCreateTextOpCode ( + StartOpCodeHandle, + STRING_TOKEN (STR_TEXT_SAMPLE_HELP), + STRING_TOKEN (STR_TEXT_SAMPLE_HELP), + STRING_TOKEN (STR_TEXT_SAMPLE_STRING) + ); - HiiCreateTextOpCode ( - StartOpCodeHandle, - STRING_TOKEN(STR_TEXT_SAMPLE_HELP), - STRING_TOKEN(STR_TEXT_SAMPLE_HELP), - STRING_TOKEN(STR_TEXT_SAMPLE_STRING) - ); + HiiCreateDateOpCode ( + StartOpCodeHandle, + 0x8004, + 0x0, + 0x0, + STRING_TOKEN (STR_DATE_SAMPLE_HELP), + STRING_TOKEN (STR_DATE_SAMPLE_HELP), + 0, + QF_DATE_STORAGE_TIME, + NULL + ); - HiiCreateDateOpCode ( - StartOpCodeHandle, - 0x8004, - 0x0, - 0x0, - STRING_TOKEN(STR_DATE_SAMPLE_HELP), - STRING_TOKEN(STR_DATE_SAMPLE_HELP), - 0, - QF_DATE_STORAGE_TIME, - NULL - ); + HiiCreateTimeOpCode ( + StartOpCodeHandle, + 0x8005, + 0x0, + 0x0, + STRING_TOKEN (STR_TIME_SAMPLE_HELP), + STRING_TOKEN (STR_TIME_SAMPLE_HELP), + 0, + QF_TIME_STORAGE_TIME, + NULL + ); - HiiCreateTimeOpCode ( - StartOpCodeHandle, - 0x8005, - 0x0, - 0x0, - STRING_TOKEN(STR_TIME_SAMPLE_HELP), - STRING_TOKEN(STR_TIME_SAMPLE_HELP), - 0, - QF_TIME_STORAGE_TIME, - NULL - ); + HiiCreateGotoOpCode ( + StartOpCodeHandle, // Container for dynamic created opcodes + 1, // Target Form ID + STRING_TOKEN (STR_GOTO_FORM1), // Prompt text + STRING_TOKEN (STR_GOTO_HELP), // Help text + 0, // Question flag + 0x8003 // Question ID + ); - HiiCreateGotoOpCode ( - StartOpCodeHandle, // Container for dynamic created opcodes - 1, // Target Form ID - STRING_TOKEN (STR_GOTO_FORM1), // Prompt text - STRING_TOKEN (STR_GOTO_HELP), // Help text - 0, // Question flag - 0x8003 // Question ID - ); + HiiUpdateForm ( + PrivateData->HiiHandle[0], // HII handle + &gDriverSampleFormSetGuid, // Formset GUID + 0x1234, // Form ID + StartOpCodeHandle, // Label for where to insert opcodes + EndOpCodeHandle // Replace data + ); - HiiUpdateForm ( - PrivateData->HiiHandle[0], // HII handle - &gDriverSampleFormSetGuid, // Formset GUID - 0x1234, // Form ID - StartOpCodeHandle, // Label for where to insert opcodes - EndOpCodeHandle // Replace data - ); + HiiFreeOpCodeHandle (StartOpCodeHandle); + HiiFreeOpCodeHandle (OptionsOpCodeHandle); + HiiFreeOpCodeHandle (EndOpCodeHandle); + break; - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (OptionsOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); - break; + default: + break; + } - default: break; } - } - break; - case EFI_BROWSER_ACTION_CHANGED: - switch (QuestionId) { - case 0x1237: - // - // User press "Exit now", request Browser to exit - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT; - break; + case EFI_BROWSER_ACTION_CHANGED: + switch (QuestionId) { + case 0x1237: + // + // User press "Exit now", request Browser to exit + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT; + break; - case 0x1238: - // - // User press "Save now", request Browser to save the uncommitted data. - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; - break; + case 0x1238: + // + // User press "Save now", request Browser to save the uncommitted data. + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; + break; - case 0x1241: - case 0x1246: - // - // User press "Submit current form and Exit now", request Browser to submit current form and exit - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT; - break; + case 0x1241: + case 0x1246: + // + // User press "Submit current form and Exit now", request Browser to submit current form and exit + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT; + break; - case 0x1242: - // - // User press "Discard current form now", request Browser to discard the uncommitted data. - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD; - break; + case 0x1242: + // + // User press "Discard current form now", request Browser to discard the uncommitted data. + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD; + break; - case 0x1243: - // - // User press "Submit current form now", request Browser to save the uncommitted data. - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; - break; + case 0x1243: + // + // User press "Submit current form now", request Browser to save the uncommitted data. + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + break; - case 0x1244: - case 0x1245: - // - // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit. - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT; - break; + case 0x1244: + case 0x1245: + // + // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit. + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT; + break; - case 0x1231: - // - // 1. Check to see whether system support keyword. - // - Status = PrivateData->HiiKeywordHandler->GetData (PrivateData->HiiKeywordHandler, - L"NAMESPACE=x-UEFI-ns", - L"KEYWORD=iSCSIBootEnable", - &Progress, - &ProgressErr, - &Results - ); - if (EFI_ERROR (Status)) { - do { - CreatePopUp ( - EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, - &Key, - L"", - L"This system not support this keyword!", - L"Press ENTER to continue ...", - L"", - NULL - ); - } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + case 0x1231: + // + // 1. Check to see whether system support keyword. + // + Status = PrivateData->HiiKeywordHandler->GetData ( + PrivateData->HiiKeywordHandler, + L"NAMESPACE=x-UEFI-ns", + L"KEYWORD=iSCSIBootEnable", + &Progress, + &ProgressErr, + &Results + ); + if (EFI_ERROR (Status)) { + do { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"", + L"This system not support this keyword!", + L"Press ENTER to continue ...", + L"", + NULL + ); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); - Status = EFI_SUCCESS; - break; - } + Status = EFI_SUCCESS; + break; + } - // - // 2. If system support this keyword, just try to change value. - // + // + // 2. If system support this keyword, just try to change value. + // - // - // Change value from '0' to '1' or from '1' to '0' - // - TmpStr = StrStr (Results, L"&VALUE="); - ASSERT (TmpStr != NULL); - TmpStr += StrLen (L"&VALUE="); - TmpStr++; - if (*TmpStr == L'0') { - *TmpStr = L'1'; - } else { - *TmpStr = L'0'; - } + // + // Change value from '0' to '1' or from '1' to '0' + // + TmpStr = StrStr (Results, L"&VALUE="); + ASSERT (TmpStr != NULL); + TmpStr += StrLen (L"&VALUE="); + TmpStr++; + if (*TmpStr == L'0') { + *TmpStr = L'1'; + } else { + *TmpStr = L'0'; + } - // - // 3. Call the keyword handler protocol to change the value. - // - Status = PrivateData->HiiKeywordHandler->SetData (PrivateData->HiiKeywordHandler, - Results, - &Progress, - &ProgressErr - ); - if (EFI_ERROR (Status)) { - do { - CreatePopUp ( - EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, - &Key, - L"", - L"Set keyword to the system failed!", - L"Press ENTER to continue ...", - L"", - NULL - ); - } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + // + // 3. Call the keyword handler protocol to change the value. + // + Status = PrivateData->HiiKeywordHandler->SetData ( + PrivateData->HiiKeywordHandler, + Results, + &Progress, + &ProgressErr + ); + if (EFI_ERROR (Status)) { + do { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"", + L"Set keyword to the system failed!", + L"Press ENTER to continue ...", + L"", + NULL + ); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + + Status = EFI_SUCCESS; + break; + } - Status = EFI_SUCCESS; break; - } - break; - - case 0x1330: - Status = mPrivateData->HiiPopup->CreatePopup ( - mPrivateData->HiiPopup, - EfiHiiPopupStyleInfo, - EfiHiiPopupTypeYesNo, - mPrivateData->HiiHandle[0], - STRING_TOKEN (STR_POPUP_STRING), - &UserSelection - ); - if (!EFI_ERROR (Status)) { - if (UserSelection == EfiHiiPopupSelectionYes) { - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT; + + case 0x1330: + Status = mPrivateData->HiiPopup->CreatePopup ( + mPrivateData->HiiPopup, + EfiHiiPopupStyleInfo, + EfiHiiPopupTypeYesNo, + mPrivateData->HiiHandle[0], + STRING_TOKEN (STR_POPUP_STRING), + &UserSelection + ); + if (!EFI_ERROR (Status)) { + if (UserSelection == EfiHiiPopupSelectionYes) { + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT; + } } - } - break; - default: + break; + + default: + break; + } + break; - } - break; - case EFI_BROWSER_ACTION_SUBMITTED: + case EFI_BROWSER_ACTION_SUBMITTED: { if (QuestionId == 0x1250) { // @@ -1680,12 +1715,13 @@ DriverCallback ( ); } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN)); } + + break; } - break; - default: - Status = EFI_UNSUPPORTED; - break; + default: + Status = EFI_UNSUPPORTED; + break; } return Status; @@ -1703,30 +1739,30 @@ DriverCallback ( EFI_STATUS EFIAPI DriverSampleInit ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - EFI_HII_HANDLE HiiHandle[2]; - EFI_SCREEN_DESCRIPTOR Screen; - EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - EFI_HII_STRING_PROTOCOL *HiiString; - EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; - EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; - EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler; - EFI_HII_POPUP_PROTOCOL *PopupHandler; - CHAR16 *NewString; - UINTN BufferSize; - DRIVER_SAMPLE_CONFIGURATION *Configuration; - BOOLEAN ActionFlag; - EFI_STRING ConfigRequestHdr; - EFI_STRING NameRequestHdr; - MY_EFI_VARSTORE_DATA *VarStoreConfig; - MY_EFI_BITS_VARSTORE_DATA *BitsVarStoreConfig; - MY_EFI_UNION_DATA *UnionConfig; - EFI_INPUT_KEY HotKey; - EDKII_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx; + EFI_STATUS Status; + EFI_HII_HANDLE HiiHandle[2]; + EFI_SCREEN_DESCRIPTOR Screen; + EFI_HII_DATABASE_PROTOCOL *HiiDatabase; + EFI_HII_STRING_PROTOCOL *HiiString; + EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler; + EFI_HII_POPUP_PROTOCOL *PopupHandler; + CHAR16 *NewString; + UINTN BufferSize; + DRIVER_SAMPLE_CONFIGURATION *Configuration; + BOOLEAN ActionFlag; + EFI_STRING ConfigRequestHdr; + EFI_STRING NameRequestHdr; + MY_EFI_VARSTORE_DATA *VarStoreConfig; + MY_EFI_BITS_VARSTORE_DATA *BitsVarStoreConfig; + MY_EFI_UNION_DATA *UnionConfig; + EFI_INPUT_KEY HotKey; + EDKII_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx; // // Initialize the local variables. @@ -1741,8 +1777,8 @@ DriverSampleInit ( ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR)); gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow); - Screen.TopRow = 3; - Screen.BottomRow = Screen.BottomRow - 3; + Screen.TopRow = 3; + Screen.BottomRow = Screen.BottomRow - 3; // // Initialize driver private data @@ -1755,61 +1791,67 @@ DriverSampleInit ( mPrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE; mPrivateData->ConfigAccess.ExtractConfig = ExtractConfig; - mPrivateData->ConfigAccess.RouteConfig = RouteConfig; - mPrivateData->ConfigAccess.Callback = DriverCallback; + mPrivateData->ConfigAccess.RouteConfig = RouteConfig; + mPrivateData->ConfigAccess.Callback = DriverCallback; // // Locate Hii Database protocol // - Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase); + Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase); if (EFI_ERROR (Status)) { return Status; } + mPrivateData->HiiDatabase = HiiDatabase; // // Locate HiiString protocol // - Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString); + Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **)&HiiString); if (EFI_ERROR (Status)) { return Status; } + mPrivateData->HiiString = HiiString; // // Locate Formbrowser2 protocol // - Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2); + Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **)&FormBrowser2); if (EFI_ERROR (Status)) { return Status; } + mPrivateData->FormBrowser2 = FormBrowser2; // // Locate ConfigRouting protocol // - Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting); + Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&HiiConfigRouting); if (EFI_ERROR (Status)) { return Status; } + mPrivateData->HiiConfigRouting = HiiConfigRouting; // // Locate keyword handler protocol // - Status = gBS->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid, NULL, (VOID **) &HiiKeywordHandler); + Status = gBS->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid, NULL, (VOID **)&HiiKeywordHandler); if (EFI_ERROR (Status)) { return Status; } + mPrivateData->HiiKeywordHandler = HiiKeywordHandler; // // Locate HiiPopup protocol // - Status = gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid, NULL, (VOID **) &PopupHandler); + Status = gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid, NULL, (VOID **)&PopupHandler); if (EFI_ERROR (Status)) { return Status; } + mPrivateData->HiiPopup = PopupHandler; Status = gBS->InstallMultipleProtocolInterfaces ( @@ -1872,11 +1914,12 @@ DriverSampleInit ( // // Update the device path string. // - NewString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0, FALSE, FALSE); + NewString = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *)&mHiiVendorDevicePath0, FALSE, FALSE); if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) { DriverSampleUnload (ImageHandle); return EFI_OUT_OF_RESOURCES; } + if (NewString != NULL) { FreePool (NewString); } @@ -1917,12 +1960,12 @@ DriverSampleInit ( ASSERT (NameRequestHdr != NULL); BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); - Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration); + Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration); if (EFI_ERROR (Status)) { // // Store zero data Buffer Storage to EFI variable // - Status = gRT->SetVariable( + Status = gRT->SetVariable ( VariableName, &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, @@ -1933,6 +1976,7 @@ DriverSampleInit ( DriverSampleUnload (ImageHandle); return Status; } + // // EFI variable for NV config doesn't exit, we should build this variable // based on default values stored in IFR @@ -1964,6 +2008,7 @@ DriverSampleInit ( return EFI_INVALID_PARAMETER; } } + FreePool (ConfigRequestHdr); // @@ -1976,12 +2021,12 @@ DriverSampleInit ( ASSERT (ConfigRequestHdr != NULL); BufferSize = sizeof (MY_EFI_VARSTORE_DATA); - Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig); + Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig); if (EFI_ERROR (Status)) { // // Store zero data to EFI variable Storage. // - Status = gRT->SetVariable( + Status = gRT->SetVariable ( MyEfiVar, &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, @@ -1992,6 +2037,7 @@ DriverSampleInit ( DriverSampleUnload (ImageHandle); return Status; } + // // EFI variable for NV config doesn't exit, we should build this variable // based on default values stored in IFR @@ -2011,6 +2057,7 @@ DriverSampleInit ( return EFI_INVALID_PARAMETER; } } + FreePool (ConfigRequestHdr); // @@ -2023,12 +2070,12 @@ DriverSampleInit ( ASSERT (ConfigRequestHdr != NULL); BufferSize = sizeof (MY_EFI_BITS_VARSTORE_DATA); - Status = gRT->GetVariable (MyEfiBitVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, BitsVarStoreConfig); + Status = gRT->GetVariable (MyEfiBitVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, BitsVarStoreConfig); if (EFI_ERROR (Status)) { // // Store zero data to EFI variable Storage. // - Status = gRT->SetVariable( + Status = gRT->SetVariable ( MyEfiBitVar, &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, @@ -2039,6 +2086,7 @@ DriverSampleInit ( DriverSampleUnload (ImageHandle); return Status; } + // // EFI variable for NV config doesn't exit, we should build this variable // based on default values stored in IFR @@ -2058,9 +2106,10 @@ DriverSampleInit ( return EFI_INVALID_PARAMETER; } } + FreePool (ConfigRequestHdr); - // + // // Initialize Union efi varstore configuration data // UnionConfig = &mPrivateData->UnionConfig; @@ -2070,12 +2119,12 @@ DriverSampleInit ( ASSERT (ConfigRequestHdr != NULL); BufferSize = sizeof (MY_EFI_UNION_DATA); - Status = gRT->GetVariable (MyEfiUnionVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, UnionConfig); + Status = gRT->GetVariable (MyEfiUnionVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, UnionConfig); if (EFI_ERROR (Status)) { // // Store zero data to EFI variable Storage. // - Status = gRT->SetVariable( + Status = gRT->SetVariable ( MyEfiUnionVar, &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, @@ -2086,6 +2135,7 @@ DriverSampleInit ( DriverSampleUnload (ImageHandle); return Status; } + // // EFI variable for NV config doesn't exit, we should build this variable // based on default values stored in IFR @@ -2105,22 +2155,23 @@ DriverSampleInit ( return EFI_INVALID_PARAMETER; } } + FreePool (ConfigRequestHdr); Status = gBS->CreateEventEx ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - EfiEventEmptyFunction, - NULL, - &gEfiIfrRefreshIdOpGuid, - &mEvent - ); + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + EfiEventEmptyFunction, + NULL, + &gEfiIfrRefreshIdOpGuid, + &mEvent + ); ASSERT_EFI_ERROR (Status); // // Example of how to use BrowserEx protocol to register HotKey. // - Status = gBS->LocateProtocol (&gEdkiiFormBrowserExProtocolGuid, NULL, (VOID **) &FormBrowserEx); + Status = gBS->LocateProtocol (&gEdkiiFormBrowserExProtocolGuid, NULL, (VOID **)&FormBrowserEx); if (!EFI_ERROR (Status)) { // // First unregister the default hot key F9 and F10. @@ -2128,18 +2179,18 @@ DriverSampleInit ( HotKey.UnicodeChar = CHAR_NULL; HotKey.ScanCode = SCAN_F9; FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL); - HotKey.ScanCode = SCAN_F10; + HotKey.ScanCode = SCAN_F10; FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL); // // Register the default HotKey F9 and F10 again. // - HotKey.ScanCode = SCAN_F10; - NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL); + HotKey.ScanCode = SCAN_F10; + NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL); ASSERT (NewString != NULL); FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString); - HotKey.ScanCode = SCAN_F9; - NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL); + HotKey.ScanCode = SCAN_F9; + NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL); ASSERT (NewString != NULL); FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString); } @@ -2189,30 +2240,30 @@ DriverSampleUnload ( IN EFI_HANDLE ImageHandle ) { - UINTN Index; + UINTN Index; ASSERT (mPrivateData != NULL); if (DriverHandle[0] != NULL) { gBS->UninstallMultipleProtocolInterfaces ( - DriverHandle[0], - &gEfiDevicePathProtocolGuid, - &mHiiVendorDevicePath0, - &gEfiHiiConfigAccessProtocolGuid, - &mPrivateData->ConfigAccess, - NULL + DriverHandle[0], + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath0, + &gEfiHiiConfigAccessProtocolGuid, + &mPrivateData->ConfigAccess, + NULL ); DriverHandle[0] = NULL; } if (DriverHandle[1] != NULL) { gBS->UninstallMultipleProtocolInterfaces ( - DriverHandle[1], - &gEfiDevicePathProtocolGuid, - &mHiiVendorDevicePath1, - &gEfiHiiConfigAccessProtocolGuid, - &mPrivateData->ConfigAccess, - NULL + DriverHandle[1], + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath1, + &gEfiHiiConfigAccessProtocolGuid, + &mPrivateData->ConfigAccess, + NULL ); DriverHandle[1] = NULL; } @@ -2230,6 +2281,7 @@ DriverSampleUnload ( FreePool (mPrivateData->NameValueName[Index]); } } + FreePool (mPrivateData); mPrivateData = NULL;