In this patch we populate the form with the two widgets related to video resolution: - A read-only string field displaying the preference for the next boot. - A drop-down list offering choices for changing the setting. This list is implemented with dynamically generated IFR opcodes.
(In general, the current preference may be missing, or it may be invalid for the available video RAM size. The list of possible new settings is filtered with the video RAM size.) Because the form now becomes able to receive input, we must also implement ExtractConfig(). This function tells the HII engine about the state of the widgets. For now we set up both widgets with static data only: - The current preference always says "Unset". The driver code is still isolated from the backend (the UEFI variable store). - The list of possible resolutions offers 800x600 only. We don't interrogate the GOP yet. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <ler...@redhat.com> --- Notes: - make dependency on HII Config Routing explicit (provided by HiiDatabaseDxe) OvmfPkg/PlatformDxe/Platform.inf | 4 + OvmfPkg/PlatformDxe/Platform.h | 4 + OvmfPkg/PlatformDxe/PlatformForms.vfr | 18 +++ OvmfPkg/PlatformDxe/Platform.c | 215 +++++++++++++++++++++++++++++++++- OvmfPkg/PlatformDxe/Platform.uni | Bin 1920 -> 2992 bytes 5 files changed, 240 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/PlatformDxe/Platform.inf b/OvmfPkg/PlatformDxe/Platform.inf index e3701d4..5997e34 100644 --- a/OvmfPkg/PlatformDxe/Platform.inf +++ b/OvmfPkg/PlatformDxe/Platform.inf @@ -36,12 +36,14 @@ OvmfPkg/OvmfPkg.dec [LibraryClasses] + BaseLib BaseMemoryLib DebugLib DevicePathLib HiiLib MemoryAllocationLib UefiBootServicesTableLib + UefiHiiServicesLib UefiLib UefiRuntimeServicesTableLib UefiDriverEntryPoint @@ -55,9 +57,11 @@ gEfiHiiConfigAccessProtocolGuid ## PRODUCES [Guids] + gEfiIfrTianoGuid gOvmfPlatformConfigGuid [Depex] + gEfiHiiConfigRoutingProtocolGuid AND gEfiHiiDatabaseProtocolGuid AND gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid diff --git a/OvmfPkg/PlatformDxe/Platform.h b/OvmfPkg/PlatformDxe/Platform.h index afa15db..6ce67ff 100644 --- a/OvmfPkg/PlatformDxe/Platform.h +++ b/OvmfPkg/PlatformDxe/Platform.h @@ -22,8 +22,12 @@ #define FORMSTATEID_MAIN_FORM 1 #define FORMID_MAIN_FORM 1 +#define QUESTION_RES_CUR 1 #define MAXSIZE_RES_CUR 16 +#define LABEL_RES_NEXT 1 +#define QUESTION_RES_NEXT 2 + // // This structure describes the form state. Its fields relate strictly to the // visual widgets on the form. diff --git a/OvmfPkg/PlatformDxe/PlatformForms.vfr b/OvmfPkg/PlatformDxe/PlatformForms.vfr index c526ffa..61935c3 100644 --- a/OvmfPkg/PlatformDxe/PlatformForms.vfr +++ b/OvmfPkg/PlatformDxe/PlatformForms.vfr @@ -38,6 +38,24 @@ formset form formid = FORMID_MAIN_FORM, title = STRING_TOKEN(STR_MAIN_FORM_TITLE); + + // + // Display the current preference in a read-only string field. + // + string + varid = MainFormState.CurrentPreferredResolution, + questionid = QUESTION_RES_CUR, + prompt = STRING_TOKEN(STR_RES_CUR), + help = STRING_TOKEN(STR_RES_CUR_HELP), + flags = READ_ONLY, + minsize = 0, + maxsize = MAXSIZE_RES_CUR, + endstring; + + // + // We'll dynamically generate a one-of-many selection at this label. + // + label LABEL_RES_NEXT; endform; endformset; diff --git a/OvmfPkg/PlatformDxe/Platform.c b/OvmfPkg/PlatformDxe/Platform.c index 16066a0..4b14162 100644 --- a/OvmfPkg/PlatformDxe/Platform.c +++ b/OvmfPkg/PlatformDxe/Platform.c @@ -14,13 +14,18 @@ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ +#include <Library/BaseLib.h> #include <Library/DebugLib.h> #include <Library/DevicePathLib.h> #include <Library/HiiLib.h> #include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiHiiServicesLib.h> #include <Protocol/DevicePath.h> #include <Protocol/HiiConfigAccess.h> +#include <Guid/MdeModuleHii.h> +#include <Guid/OvmfPlatformConfig.h> +#include "Platform.h" #include "PlatformConfig.h" // @@ -94,6 +99,26 @@ extern UINT8 PlatformDxeStrings[]; extern UINT8 PlatformFormsBin[]; +/** + This function is called by the HII machinery when it fetches the form state. + + See the precise documentation in the UEFI spec. + + @param[in] This The Config Access Protocol instance. + + @param[in] Request A <ConfigRequest> format UCS-2 string describing the + query. + + @param[out] Progress A pointer into Request on output, identifying the query + element where processing failed. + + @param[out] Results A <MultiConfigAltResp> format UCS-2 string that has + all values filled in for the names in the Request + string. + + @return Status codes from gHiiConfigRouting->BlockToConfig(). + +**/ STATIC EFI_STATUS EFIAPI @@ -104,7 +129,24 @@ ExtractConfig ( OUT EFI_STRING *Results ) { - return EFI_SUCCESS; + MAIN_FORM_STATE MainFormState; + EFI_STATUS Status; + + DEBUG ((EFI_D_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request)); + + StrnCpy ((CHAR16 *) MainFormState.CurrentPreferredResolution, + L"Unset", MAXSIZE_RES_CUR); + MainFormState.NextPreferredResolution = 0; + Status = gHiiConfigRouting->BlockToConfig (gHiiConfigRouting, Request, + (VOID *) &MainFormState, sizeof MainFormState, + Results, Progress); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a: BlockToConfig(): %r, Progress=\"%s\"\n", + __FUNCTION__, Status, (Status == EFI_DEVICE_ERROR) ? NULL : *Progress)); + } else { + DEBUG ((EFI_D_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results)); + } + return Status; } @@ -138,6 +180,168 @@ Callback ( /** + Create a set of "one-of-many" (ie. "drop down list") option IFR opcodes, + based on available GOP resolutions, to be placed under a "one-of-many" (ie. + "drop down list") opcode. + + @param[in] PackageList The package list with the formset and form for + which the drop down options are produced. Option + names are added as new strings to PackageList. + + @param[out] OpCodeBuffer On output, a dynamically allocated opcode buffer + with drop down list options corresponding to GOP + resolutions. The caller is responsible for freeing + OpCodeBuffer with HiiFreeOpCodeHandle() after use. + + @retval EFI_SUCESS Opcodes have been successfully produced. + + @return Status codes from underlying functions. PackageList may + have been extended with new strings. OpCodeBuffer is + unchanged. +**/ +STATIC +EFI_STATUS +EFIAPI +CreateResolutionOptions ( + IN EFI_HII_HANDLE *PackageList, + OUT VOID **OpCodeBuffer + ) +{ + EFI_STATUS Status; + VOID *OutputBuffer; + EFI_STRING_ID NewString; + VOID *OpCode; + + OutputBuffer = HiiAllocateOpCodeHandle (); + if (OutputBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + NewString = HiiSetString (PackageList, 0 /* new string */, L"800x600", + NULL /* for all languages */); + if (NewString == 0) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeOutputBuffer; + } + OpCode = HiiCreateOneOfOptionOpCode (OutputBuffer, NewString, + 0 /* Flags */, EFI_IFR_NUMERIC_SIZE_4, 0 /* Value */); + if (OpCode == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeOutputBuffer; + } + + *OpCodeBuffer = OutputBuffer; + return EFI_SUCCESS; + +FreeOutputBuffer: + HiiFreeOpCodeHandle (OutputBuffer); + + return Status; +} + + +/** + Populate the form identified by the (PackageList, FormSetGuid, FormId) + triplet. + + @retval EFI_SUCESS Form successfully updated. + @return Status codes from underlying functions. + +**/ +STATIC +EFI_STATUS +EFIAPI +PopulateForm ( + IN EFI_HII_HANDLE *PackageList, + IN EFI_GUID *FormSetGuid, + IN EFI_FORM_ID FormId + ) +{ + EFI_STATUS Status; + VOID *OpCodeBuffer; + VOID *OpCode; + EFI_IFR_GUID_LABEL *Anchor; + VOID *OpCodeBuffer2; + + // + // 1. Allocate an empty opcode buffer. + // + OpCodeBuffer = HiiAllocateOpCodeHandle (); + if (OpCodeBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // 2. Create a label opcode (which is a Tiano extension) inside the buffer. + // The label's number must match the "anchor" label in the form. + // + OpCode = HiiCreateGuidOpCode (OpCodeBuffer, &gEfiIfrTianoGuid, + NULL /* optional copy origin */, sizeof *Anchor); + if (OpCode == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeOpCodeBuffer; + } + Anchor = OpCode; + Anchor->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + Anchor->Number = LABEL_RES_NEXT; + + // + // 3. Create the opcodes inside the buffer that are to be inserted into the + // form. + // + // 3.1. Get a list of resolutions. + // + Status = CreateResolutionOptions (PackageList, &OpCodeBuffer2); + if (EFI_ERROR (Status)) { + goto FreeOpCodeBuffer; + } + + // + // 3.2. Create a one-of-many question with the above options. + // + OpCode = HiiCreateOneOfOpCode ( + OpCodeBuffer, // create opcode inside this + // opcode buffer, + QUESTION_RES_NEXT, // ID of question, + FORMSTATEID_MAIN_FORM, // identifies form state + // storage, + (UINT16) OFFSET_OF (MAIN_FORM_STATE, // value of question stored + NextPreferredResolution), // at this offset, + STRING_TOKEN (STR_RES_NEXT), // Prompt, + STRING_TOKEN (STR_RES_NEXT_HELP), // Help, + 0, // QuestionFlags, + EFI_IFR_NUMERIC_SIZE_4, // see sizeof + // NextPreferredResolution, + OpCodeBuffer2, // buffer with possible + // choices, + NULL // DEFAULT opcodes + ); + if (OpCode == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeOpCodeBuffer2; + } + + // + // 4. Update the form with the opcode buffer. + // + Status = HiiUpdateForm (PackageList, FormSetGuid, FormId, + OpCodeBuffer, // buffer with head anchor, and new contents to be + // inserted at it + NULL // buffer with tail anchor, for deleting old + // contents up to it + ); + +FreeOpCodeBuffer2: + HiiFreeOpCodeHandle (OpCodeBuffer2); + +FreeOpCodeBuffer: + HiiFreeOpCodeHandle (OpCodeBuffer); + + return Status; +} + + +/** Load and execute the platform configuration. @retval EFI_SUCCESS Configuration loaded and executed. @@ -227,8 +431,17 @@ PlatformInit ( goto UninstallProtocols; } + Status = PopulateForm (mInstalledPackages, &gOvmfPlatformConfigGuid, + FORMID_MAIN_FORM); + if (EFI_ERROR (Status)) { + goto RemovePackages; + } + return EFI_SUCCESS; +RemovePackages: + HiiRemovePackages (mInstalledPackages); + UninstallProtocols: gBS->UninstallMultipleProtocolInterfaces (ImageHandle, &gEfiDevicePathProtocolGuid, &mPkgDevicePath, diff --git a/OvmfPkg/PlatformDxe/Platform.uni b/OvmfPkg/PlatformDxe/Platform.uni index 9d41e446c6ebdb2b0f43646946d5c7774fe55449..6ce844a664aa914069069f08380c9f7997fd9642 100644 GIT binary patch delta 779 zcma)4O-sW-6r6)3Ae0_@(2KZ=2L(Sa9=u5{q6IA_R?w5AHEn}6(I!n*g!Dh;kMy63 zH;>NSbfwgQ9$xnC+kJ0lXEG^ISElcF_GPV>9Gv0`cc|eSPWEh7vWc~%<H+8sHZg>U zE@P;(dnh>EMF=s#2r+zS0jn-^g$B=Fbaujeh&cPS))z2()^XZGpEnhr3g!#q@A)BF zC{E7%&e-R&yHETMZ!7W_9(kWk&iMpCeA+o5?DMRiYKo6+?s0?=Z)-XuJ;GyUm$i@} ziuHscPxSdsIC#KJgxJ<(0um5FnHA_BkEc7VjM*P+KtnsxogOM7j~!HT$u(l}4PN$P zZIq204Z3oJ)|?-Qwf}q3ol!4zV{HM0-k%fg0!?yJ*`9rn-m-thU5AgAheuS}<IblC zuiU!~QFhFA-a(Nm7sD_x5C7XQ@l~9sKMyd!hbSFse`HmJ_o;q7yDA>IRNZA&tQQ{* Ppi#O&XhLkFgk>GygXfcY delta 12 TcmdlW-oU@1hMk3%fr|kE7&-!_ -- 1.8.3.1 ------------------------------------------------------------------------------ Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel