Revision: 15369
          http://sourceforge.net/p/edk2/code/15369
Author:   jljusten
Date:     2014-03-22 07:13:31 +0000 (Sat, 22 Mar 2014)
Log Message:
-----------
OvmfPkg: PlatformDxe: add form widgets for video modes

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 <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/OvmfPkg/PlatformDxe/Platform.c
    trunk/edk2/OvmfPkg/PlatformDxe/Platform.h
    trunk/edk2/OvmfPkg/PlatformDxe/Platform.inf
    trunk/edk2/OvmfPkg/PlatformDxe/Platform.uni
    trunk/edk2/OvmfPkg/PlatformDxe/PlatformForms.vfr

Modified: trunk/edk2/OvmfPkg/PlatformDxe/Platform.c
===================================================================
--- trunk/edk2/OvmfPkg/PlatformDxe/Platform.c   2014-03-22 07:13:24 UTC (rev 
15368)
+++ trunk/edk2/OvmfPkg/PlatformDxe/Platform.c   2014-03-22 07:13:31 UTC (rev 
15369)
@@ -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 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 @@
   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 @@
 
 
 /**
+  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 @@
     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,

Modified: trunk/edk2/OvmfPkg/PlatformDxe/Platform.h
===================================================================
--- trunk/edk2/OvmfPkg/PlatformDxe/Platform.h   2014-03-22 07:13:24 UTC (rev 
15368)
+++ trunk/edk2/OvmfPkg/PlatformDxe/Platform.h   2014-03-22 07:13:31 UTC (rev 
15369)
@@ -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.

Modified: trunk/edk2/OvmfPkg/PlatformDxe/Platform.inf
===================================================================
--- trunk/edk2/OvmfPkg/PlatformDxe/Platform.inf 2014-03-22 07:13:24 UTC (rev 
15368)
+++ trunk/edk2/OvmfPkg/PlatformDxe/Platform.inf 2014-03-22 07:13:31 UTC (rev 
15369)
@@ -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

Modified: trunk/edk2/OvmfPkg/PlatformDxe/Platform.uni
===================================================================
--- trunk/edk2/OvmfPkg/PlatformDxe/Platform.uni 2014-03-22 07:13:24 UTC (rev 
15368)
+++ trunk/edk2/OvmfPkg/PlatformDxe/Platform.uni 2014-03-22 07:13:31 UTC (rev 
15369)
@@ -60,6 +60,14 @@
  ++++  \ No newline at end of file

Modified: trunk/edk2/OvmfPkg/PlatformDxe/PlatformForms.vfr
===================================================================
--- trunk/edk2/OvmfPkg/PlatformDxe/PlatformForms.vfr    2014-03-22 07:13:24 UTC 
(rev 15368)
+++ trunk/edk2/OvmfPkg/PlatformDxe/PlatformForms.vfr    2014-03-22 07:13:31 UTC 
(rev 15369)
@@ -38,6 +38,24 @@
   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;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to