X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FDriverSampleDxe%2FDriverSample.c;h=204c043ff45e9617935f68aadb8ef9f9e1f72079;hp=9751242fd2a29c68b52a542fc748c4bf671fd706;hb=9bd22b08d1a9b0b4c2fd325a928b58acd176d9d1;hpb=46cc3885e68cc19981a4756e1a2d40d35f2eb92f diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index 9751242fd2..204c043ff4 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -2,7 +2,7 @@ This is an example of how a driver might export data to the HII protocol to be later utilized by the Setup Protocol -Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2014, 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 @@ -18,12 +18,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define DISPLAY_ONLY_MY_ITEM 0x0002 -EFI_GUID mFormSetGuid = FORMSET_GUID; -EFI_GUID mInventoryGuid = INVENTORY_GUID; - CHAR16 VariableName[] = L"MyIfrNVData"; +CHAR16 MyEfiVar[] = L"MyEfiVar"; EFI_HANDLE DriverHandle[2] = {NULL, NULL}; DRIVER_SAMPLE_PRIVATE_DATA *PrivateData = NULL; +EFI_EVENT mEvent; HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = { { @@ -35,10 +34,7 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = { (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, - // - // {C153B68D-EBFC-488e-B110-662867745B87} - // - { 0xc153b68d, 0xebfc, 0x488e, { 0xb1, 0x10, 0x66, 0x28, 0x67, 0x74, 0x5b, 0x87 } } + DRIVER_SAMPLE_FORMSET_GUID }, { END_DEVICE_PATH_TYPE, @@ -60,10 +56,7 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = { (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, - // - // {06F37F07-0C48-40e9-8436-0A08A0BB76B0} - // - { 0x6f37f07, 0xc48, 0x40e9, { 0x84, 0x36, 0xa, 0x8, 0xa0, 0xbb, 0x76, 0xb0 } } + DRIVER_SAMPLE_INVENTORY_GUID }, { END_DEVICE_PATH_TYPE, @@ -75,6 +68,158 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = { } }; +/** + Add empty function for event process function. + + @param Event The Event need to be process + @param Context The context of the event. + +**/ +VOID +EFIAPI +DriverSampleInternalEmptyFunction ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ +} + +/** + Notification function for keystrokes. + + @param[in] KeyData The key that was pressed. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +NotificationFunction( + IN EFI_KEY_DATA *KeyData + ) +{ + gBS->SignalEvent (mEvent); + + return EFI_SUCCESS; +} + +/** + Function to start monitoring for CTRL-C using SimpleTextInputEx. + + @retval EFI_SUCCESS The feature is enabled. + @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available. +**/ +EFI_STATUS +EFIAPI +InternalStartMonitor( + VOID + ) +{ + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx; + EFI_KEY_DATA KeyData; + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN HandleCount; + UINTN HandleIndex; + EFI_HANDLE NotifyHandle; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiSimpleTextInputExProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { + Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx); + ASSERT_EFI_ERROR (Status); + + KeyData.KeyState.KeyToggleState = 0; + KeyData.Key.ScanCode = 0; + KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED; + KeyData.Key.UnicodeChar = L'c'; + + 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); + if (EFI_ERROR (Status)) { + break; + } + } + + return EFI_SUCCESS; +} + +/** + Function to stop monitoring for CTRL-C using SimpleTextInputEx. + + @retval EFI_SUCCESS The feature is enabled. + @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available. +**/ +EFI_STATUS +EFIAPI +InternalStopMonitor( + VOID + ) +{ + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx; + EFI_STATUS Status; + EFI_HANDLE *Handles; + EFI_KEY_DATA KeyData; + UINTN HandleCount; + UINTN HandleIndex; + EFI_HANDLE NotifyHandle; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiSimpleTextInputExProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { + Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx); + ASSERT_EFI_ERROR (Status); + + KeyData.KeyState.KeyToggleState = 0; + KeyData.Key.ScanCode = 0; + KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED; + KeyData.Key.UnicodeChar = L'c'; + + 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); + if (!EFI_ERROR (Status)) { + Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle); + } + } + return EFI_SUCCESS; +} + + /** Encode the password using a simple algorithm. @@ -138,7 +283,7 @@ ValidatePassword ( BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); Status = gRT->GetVariable ( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, NULL, &BufferSize, &PrivateData->Configuration @@ -231,7 +376,7 @@ SetPassword ( BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); Status = gRT->GetVariable ( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, NULL, &BufferSize, &PrivateData->Configuration @@ -243,7 +388,7 @@ SetPassword ( // // Get user input password // - Password = &PrivateData->Configuration.WhatIsThePassword2[0]; + Password = PrivateData->Configuration.WhatIsThePassword2; PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2); ZeroMem (Password, PasswordSize); @@ -263,7 +408,7 @@ SetPassword ( // Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION)); ASSERT (Configuration != NULL); - if (HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) { + if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) { // // Update password's clear text in the screen // @@ -273,7 +418,7 @@ SetPassword ( // Update uncommitted data of Browser // HiiSetBrowserData ( - &mFormSetGuid, + &gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration, @@ -293,7 +438,7 @@ SetPassword ( EncodePassword (Password, StrLen (Password) * 2); Status = gRT->SetVariable( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (DRIVER_SAMPLE_CONFIGURATION), &PrivateData->Configuration @@ -517,7 +662,6 @@ AppendAltCfgString ( ) { EFI_STRING StringPtr; - EFI_STRING TmpPtr; UINTN Length; UINT8 *TmpBuffer; UINTN Offset; @@ -527,6 +671,7 @@ AppendAltCfgString ( UINTN ValueWidth; EFI_STATUS Status; + TmpBuffer = NULL; StringPtr = *RequestResult; StringPtr = StrStr (StringPtr, L"OFFSET"); BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); @@ -538,11 +683,6 @@ AppendAltCfgString ( } while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) { - // - // Back up the header of one - // - TmpPtr = StringPtr; - StringPtr += StrLen (L"OFFSET="); // // Get Offset @@ -587,7 +727,7 @@ AppendAltCfgString ( StringPtr += StrLen (L"&VALUE="); // - // Get Width + // Get Value // Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length); if (EFI_ERROR (Status)) { @@ -679,7 +819,7 @@ ExtractConfig ( BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); Status = gRT->GetVariable ( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, NULL, &BufferSize, &PrivateData->Configuration @@ -697,7 +837,7 @@ ExtractConfig ( // Allocate and fill a buffer large enough to hold the template // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator // - ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]); + ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]); Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (Size); ASSERT (ConfigRequest != NULL); @@ -710,10 +850,17 @@ ExtractConfig ( // Check routing data in . // Note: if only one Storage is used, then this checking could be skipped. // - if (!HiiIsConfigHdrMatch (Request, &mFormSetGuid, NULL)) { + 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)) { + return EFI_UNSUPPORTED; + } + // // Set Request to the unified request string. // ConfigRequest = Request; @@ -834,7 +981,7 @@ ExtractConfig ( Progress ); if (!EFI_ERROR (Status)) { - ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]); + ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]); AppendAltCfgString(Results, ConfigRequestHdr); } } @@ -912,17 +1059,25 @@ RouteConfig ( // Check routing data in . // Note: if only one Storage is used, then this checking could be skipped. // - if (!HiiIsConfigHdrMatch (Configuration, &mFormSetGuid, NULL)) { + if (!HiiIsConfigHdrMatch (Configuration, &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(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) { + return EFI_UNSUPPORTED; + } + // // Get Buffer Storage data from EFI variable // BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); Status = gRT->GetVariable ( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, NULL, &BufferSize, &PrivateData->Configuration @@ -1041,7 +1196,7 @@ RouteConfig ( // Status = gRT->SetVariable( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (DRIVER_SAMPLE_CONFIGURATION), &PrivateData->Configuration @@ -1070,7 +1225,7 @@ RouteConfig ( // Status = gRT->SetVariable( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (DRIVER_SAMPLE_CONFIGURATION), &PrivateData->Configuration @@ -1115,7 +1270,6 @@ DriverCallback ( { DRIVER_SAMPLE_PRIVATE_DATA *PrivateData; EFI_STATUS Status; - UINT8 MyVar; VOID *StartOpCodeHandle; VOID *OptionsOpCodeHandle; EFI_IFR_GUID_LABEL *StartLabel; @@ -1123,7 +1277,8 @@ DriverCallback ( EFI_IFR_GUID_LABEL *EndLabel; EFI_INPUT_KEY Key; DRIVER_SAMPLE_CONFIGURATION *Configuration; - UINTN MyVarSize; + MY_EFI_VARSTORE_DATA *EfiData; + EFI_FORM_ID FormId; if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))|| (ActionRequest == NULL)) { @@ -1131,6 +1286,7 @@ DriverCallback ( } + FormId = 0; Status = EFI_SUCCESS; PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); @@ -1169,7 +1325,7 @@ DriverCallback ( HiiUpdateForm ( PrivateData->HiiHandle[0], // HII handle - &mFormSetGuid, // Formset GUID + &gDriverSampleFormSetGuid, // Formset GUID 0x3, // Form ID StartOpCodeHandle, // Label for where to insert opcodes NULL // Insert data @@ -1177,6 +1333,11 @@ DriverCallback ( HiiFreeOpCodeHandle (StartOpCodeHandle); } + + if (QuestionId == 0x1247) { + Status = InternalStartMonitor (); + ASSERT_EFI_ERROR (Status); + } } break; @@ -1199,26 +1360,24 @@ DriverCallback ( ); } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN)); } + + if (QuestionId == 0x1247) { + Status = InternalStopMonitor (); + ASSERT_EFI_ERROR (Status); + } } break; case EFI_BROWSER_ACTION_RETRIEVE: { - if (QuestionId == 0x1111) { - // - // EfiVarstore question takes sample action (print value as debug information) - // after read/write question. - // - MyVarSize = 1; - Status = gRT->GetVariable( - L"MyVar", - &mFormSetGuid, - NULL, - &MyVarSize, - &MyVar - ); - ASSERT_EFI_ERROR (Status); - DEBUG ((DEBUG_INFO, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar, MyVarSize)); + if (QuestionId == 0x1248) { + { + if (Type != EFI_IFR_TYPE_REF) { + return EFI_INVALID_PARAMETER; + } + + Value->ref.FormId = 0x3; + } } } break; @@ -1254,6 +1413,15 @@ DriverCallback ( 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 @@ -1315,7 +1483,7 @@ DriverCallback ( PrivateData->Configuration.DynamicOneof = 2; Status = gRT->SetVariable( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (DRIVER_SAMPLE_CONFIGURATION), &PrivateData->Configuration @@ -1326,14 +1494,14 @@ DriverCallback ( // Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION)); ASSERT (Configuration != NULL); - if (HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) { + if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) { Configuration->DynamicOneof = 2; // // Update uncommitted data of Browser // HiiSetBrowserData ( - &mFormSetGuid, + &gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration, @@ -1412,7 +1580,7 @@ DriverCallback ( HiiUpdateForm ( PrivateData->HiiHandle[0], // HII handle - &mFormSetGuid, // Formset GUID + &gDriverSampleFormSetGuid, // Formset GUID 0x1234, // Form ID StartOpCodeHandle, // Label for where to insert opcodes EndOpCodeHandle // Replace data @@ -1424,6 +1592,7 @@ DriverCallback ( break; case 0x5678: + case 0x1247: // // We will reach here once the Question is refreshed // @@ -1439,7 +1608,15 @@ DriverCallback ( // 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; + 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++; + } HiiCreateActionOpCode ( StartOpCodeHandle, // Container for dynamic created opcodes @@ -1452,8 +1629,8 @@ DriverCallback ( HiiUpdateForm ( PrivateData->HiiHandle[0], // HII handle - &mFormSetGuid, // Formset GUID - 0x3, // Form ID + &gDriverSampleFormSetGuid, // Formset GUID + FormId, // Form ID StartOpCodeHandle, // Label for where to insert opcodes NULL // Insert data ); @@ -1463,42 +1640,32 @@ DriverCallback ( // // Refresh the Question value // - PrivateData->Configuration.DynamicRefresh++; Status = gRT->SetVariable( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (DRIVER_SAMPLE_CONFIGURATION), &PrivateData->Configuration ); - // - // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause - // the first statement in Form 3 be suppressed - // - MyVarSize = 1; - MyVar = 111; - Status = gRT->SetVariable( - L"MyVar", - &mFormSetGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, - MyVarSize, - &MyVar - ); - break; - - 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; + 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); + } break; case 0x2000: @@ -1535,27 +1702,63 @@ DriverCallback ( break; - case 0x1111: - // - // EfiVarstore question takes sample action (print value as debug information) - // after read/write question. - // - MyVarSize = 1; - Status = gRT->GetVariable( - L"MyVar", - &mFormSetGuid, - NULL, - &MyVarSize, - &MyVar - ); - ASSERT_EFI_ERROR (Status); - DEBUG ((DEBUG_INFO, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar, MyVarSize)); 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 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 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 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; + + default: + break; + } + break; + default: Status = EFI_UNSUPPORTED; break; @@ -1592,11 +1795,17 @@ DriverSampleInit ( DRIVER_SAMPLE_CONFIGURATION *Configuration; BOOLEAN ActionFlag; EFI_STRING ConfigRequestHdr; + EFI_STRING NameRequestHdr; + MY_EFI_VARSTORE_DATA *VarStoreConfig; + EFI_INPUT_KEY HotKey; + EFI_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx; // // Initialize the local variables. // ConfigRequestHdr = NULL; + NewString = NULL; + // // Initialize screen dimensions for SendForm(). // Remove 3 characters from top and bottom @@ -1674,7 +1883,7 @@ DriverSampleInit ( // Publish our HII data // HiiHandle[0] = HiiAddPackages ( - &mFormSetGuid, + &gDriverSampleFormSetGuid, DriverHandle[0], DriverSampleStrings, VfrBin, @@ -1700,7 +1909,7 @@ DriverSampleInit ( PrivateData->DriverHandle[1] = DriverHandle[1]; HiiHandle[1] = HiiAddPackages ( - &mInventoryGuid, + &gDriverSampleInventoryGuid, DriverHandle[1], DriverSampleStrings, InventoryBin, @@ -1713,6 +1922,18 @@ DriverSampleInit ( PrivateData->HiiHandle[1] = HiiHandle[1]; + // + // Update the device path string. + // + 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); + } + // // Very simple example of how one would update a string that is already // in the HII database @@ -1742,39 +1963,145 @@ DriverSampleInit ( // // Try to read NV config EFI variable first // - ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, DriverHandle[0]); + ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]); ASSERT (ConfigRequestHdr != NULL); + NameRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, NULL, DriverHandle[0]); + ASSERT (NameRequestHdr != NULL); + BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION); - Status = gRT->GetVariable (VariableName, &mFormSetGuid, 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( VariableName, - &mFormSetGuid, + &gDriverSampleFormSetGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (DRIVER_SAMPLE_CONFIGURATION), Configuration ); - ASSERT (Status == EFI_SUCCESS); + if (EFI_ERROR (Status)) { + DriverSampleUnload (ImageHandle); + return Status; + } // // EFI variable for NV config doesn't exit, we should build this variable // based on default values stored in IFR // + ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD); + if (!ActionFlag) { + DriverSampleUnload (ImageHandle); + return EFI_INVALID_PARAMETER; + } + ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD); - ASSERT (ActionFlag); + if (!ActionFlag) { + DriverSampleUnload (ImageHandle); + return EFI_INVALID_PARAMETER; + } } else { // // EFI variable does exist and Validate Current Setting // + ActionFlag = HiiValidateSettings (NameRequestHdr); + if (!ActionFlag) { + DriverSampleUnload (ImageHandle); + return EFI_INVALID_PARAMETER; + } + ActionFlag = HiiValidateSettings (ConfigRequestHdr); - ASSERT (ActionFlag); + if (!ActionFlag) { + DriverSampleUnload (ImageHandle); + return EFI_INVALID_PARAMETER; + } } + FreePool (ConfigRequestHdr); + // + // Initialize efi varstore configuration data + // + VarStoreConfig = &PrivateData->VarStoreConfig; + ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA)); + + ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]); + ASSERT (ConfigRequestHdr != NULL); + + BufferSize = sizeof (MY_EFI_VARSTORE_DATA); + Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig); + if (EFI_ERROR (Status)) { + // + // Store zero data to EFI variable Storage. + // + Status = gRT->SetVariable( + MyEfiVar, + &gDriverSampleFormSetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (MY_EFI_VARSTORE_DATA), + VarStoreConfig + ); + if (EFI_ERROR (Status)) { + DriverSampleUnload (ImageHandle); + return Status; + } + // + // EFI variable for NV config doesn't exit, we should build this variable + // based on default values stored in IFR + // + ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD); + if (!ActionFlag) { + DriverSampleUnload (ImageHandle); + return EFI_INVALID_PARAMETER; + } + } else { + // + // EFI variable does exist and Validate Current Setting + // + ActionFlag = HiiValidateSettings (ConfigRequestHdr); + if (!ActionFlag) { + DriverSampleUnload (ImageHandle); + return EFI_INVALID_PARAMETER; + } + } FreePool (ConfigRequestHdr); + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + DriverSampleInternalEmptyFunction, + NULL, + &gEfiIfrRefreshIdOpGuid, + &mEvent + ); + ASSERT_EFI_ERROR (Status); + + // + // Example of how to use BrowserEx protocol to register HotKey. + // + Status = gBS->LocateProtocol (&gEfiFormBrowserExProtocolGuid, NULL, (VOID **) &FormBrowserEx); + if (!EFI_ERROR (Status)) { + // + // First unregister the default hot key F9 and F10. + // + HotKey.UnicodeChar = CHAR_NULL; + HotKey.ScanCode = SCAN_F9; + FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL); + HotKey.ScanCode = SCAN_F10; + FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL); + + // + // Register the default HotKey F9 and F10 again. + // + HotKey.ScanCode = SCAN_F10; + NewString = HiiGetString (PrivateData->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 (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL); + ASSERT (NewString != NULL); + FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString); + } // // In default, this driver is built into Flash device image, @@ -1863,5 +2190,7 @@ DriverSampleUnload ( FreePool (PrivateData); PrivateData = NULL; + gBS->CloseEvent (mEvent); + return EFI_SUCCESS; }