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>
---
 OvmfPkg/PlatformConfigDxe/PlatformConfig.inf      |   6 +
 OvmfPkg/PlatformConfigDxe/PlatformConfig.h        |   4 +
 OvmfPkg/PlatformConfigDxe/PlatformConfigForms.vfr |  18 ++
 OvmfPkg/PlatformConfigDxe/PlatformConfig.c        | 216 +++++++++++++++++++++-
 OvmfPkg/PlatformConfigDxe/PlatformConfig.uni      | Bin 1944 -> 3016 bytes
 5 files changed, 243 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/PlatformConfigDxe/PlatformConfig.inf 
b/OvmfPkg/PlatformConfigDxe/PlatformConfig.inf
index 7f04c23..c3834c9 100644
--- a/OvmfPkg/PlatformConfigDxe/PlatformConfig.inf
+++ b/OvmfPkg/PlatformConfigDxe/PlatformConfig.inf
@@ -34,15 +34,21 @@
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
+  BaseLib
   DebugLib
   DevicePathLib
   HiiLib
   UefiBootServicesTableLib
+  UefiHiiServicesLib
   UefiDriverEntryPoint
 
 [Protocols]
   gEfiDevicePathProtocolGuid      ## PRODUCES
   gEfiHiiConfigAccessProtocolGuid ## PRODUCES
 
+[Guids]
+  gEfiIfrTianoGuid
+  gOvmfPlatformConfigGuid
+
 [Depex]
   TRUE
diff --git a/OvmfPkg/PlatformConfigDxe/PlatformConfig.h 
b/OvmfPkg/PlatformConfigDxe/PlatformConfig.h
index 5d9874f..77c4ecb 100644
--- a/OvmfPkg/PlatformConfigDxe/PlatformConfig.h
+++ b/OvmfPkg/PlatformConfigDxe/PlatformConfig.h
@@ -21,8 +21,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/PlatformConfigDxe/PlatformConfigForms.vfr 
b/OvmfPkg/PlatformConfigDxe/PlatformConfigForms.vfr
index 5dc4843..efd4589 100644
--- a/OvmfPkg/PlatformConfigDxe/PlatformConfigForms.vfr
+++ b/OvmfPkg/PlatformConfigDxe/PlatformConfigForms.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/PlatformConfigDxe/PlatformConfig.c 
b/OvmfPkg/PlatformConfigDxe/PlatformConfig.c
index eb03dd8..49fefaf 100644
--- a/OvmfPkg/PlatformConfigDxe/PlatformConfig.c
+++ b/OvmfPkg/PlatformConfigDxe/PlatformConfig.c
@@ -13,12 +13,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 "PlatformConfig.h"
 
 //
 // The HiiAddPackages() library function requires that any controller (or
@@ -91,6 +97,26 @@ extern UINT8 PlatformConfigDxeStrings[];
 extern UINT8 PlatformConfigFormsBin[];
 
 
+/**
+  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
@@ -101,7 +127,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;
 }
 
 
@@ -135,6 +178,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;
+}
+
+
+/**
   Entry point for this driver.
 
   @param[in] ImageHandle  Image handle of this driver.
@@ -184,8 +389,17 @@ PlatformConfigInit (
     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/PlatformConfigDxe/PlatformConfig.uni 
b/OvmfPkg/PlatformConfigDxe/PlatformConfig.uni
index 
6890b5a4d22d9eb510572d25e835e10322d5cd05..7fc3fa0c7528b6beadeb882820ac80919ac5a97a
 100644
GIT binary patch
delta 767
zcma)3O-sW-5Pg?6C=>+`)q}Y9q#$1W0aAmA2aCiCdXluJHdqsBl2!%D+4FkvXZSPx
zFa8A&zL_+BU{ML1ot@d4_x8P~xtIF$qhsft#U&5BIKmlR9K(b8{OoIGt9gha0`$0s
z8lAK5@suFO02xw*j3Q=z#s)3cZZz6qK1OP1oR!))44YTC^EUdtX>dJdz99abACraQ
z<f3nneLlPU#P9O9A%Edf^vUFcPxQg3Q}DqiYx}uUykheOM+otb(#dp0z|017F+mLT
zBQAMj$p46g2aH6BH6;^~fB?#@NP7ZS*O?i!KUKhz_DDMeEW|8(XySl-!sHzS>o}|R
zQmGbQIYFCM{p>^4b^q^0Z$kZdHx$F(SC{QurIDYqCnH*y50u9yR5#!$r0%yo`&^>t
znEO}PM4Cc?619Bn-yVsV;x;|G<YNnKMcqU_k=+nJq~hu1s_5=hX`flKTf8d)OLeD+
LONa()nAP<T_S%e|

delta 12
TcmX>hK7)V56m}L~1}+8w8u9||

-- 
1.8.3.1



------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to