]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: PlatformDxe: connect ExtractConfig() to platform data
authorLaszlo Ersek <lersek@redhat.com>
Sat, 22 Mar 2014 07:14:03 +0000 (07:14 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 22 Mar 2014 07:14:03 +0000 (07:14 +0000)
Establish the full stack of conversions in retrieving the platform
configuration:

    MultiConfigAltResp       -- form engine / HII communication
            ^
            |
     [BlockToConfig]
            |
     MAIN_FORM_STATE         -- binary representation of form/widget state
            ^
            |
[PlatformConfigToFormState]
            |
     PLATFORM_CONFIG         -- accessible to DXE and UEFI drivers
            ^
            |
   [PlatformConfigLoad]
            |
  UEFI non-volatile variable -- accessible to external utilities

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15374 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/PlatformDxe/Platform.c

index b95326e2b5fe5d5eb6a1783fb3d7ab56da6964a1..49189141bbbbe04351f56e97111c1d6b0aeada41 100644 (file)
@@ -15,6 +15,7 @@
 **/\r
 \r
 #include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include <Library/HiiLib.h>\r
@@ -125,6 +126,79 @@ STATIC UINTN    mNumGopModes;
 STATIC GOP_MODE *mGopModes;\r
 \r
 \r
+/**\r
+  Load the persistent platform configuration and translate it to binary form\r
+  state.\r
+\r
+  If the platform configuration is missing, then the function fills in a\r
+  default state.\r
+\r
+  @param[out] MainFormState  Binary form/widget state after translation.\r
+\r
+  @retval EFI_SUCCESS  Form/widget state ready.\r
+  @return              Error codes from underlying functions.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformConfigToFormState (\r
+  OUT MAIN_FORM_STATE *MainFormState\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  PLATFORM_CONFIG PlatformConfig;\r
+  UINT64          OptionalElements;\r
+  UINTN           ModeNumber;\r
+\r
+  ZeroMem (MainFormState, sizeof *MainFormState);\r
+\r
+  Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);\r
+  switch (Status) {\r
+  case EFI_SUCCESS:\r
+    if (OptionalElements & PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION) {\r
+      //\r
+      // Format the preferred resolution as text.\r
+      //\r
+      UnicodeSPrintAsciiFormat (\r
+        (CHAR16 *) MainFormState->CurrentPreferredResolution,\r
+        sizeof MainFormState->CurrentPreferredResolution,\r
+        "%Ldx%Ld",\r
+        (INT64) PlatformConfig.HorizontalResolution,\r
+        (INT64) PlatformConfig.VerticalResolution);\r
+\r
+      //\r
+      // Try to locate it in the drop-down list too. This may not succeed, but\r
+      // that's fine.\r
+      //\r
+      for (ModeNumber = 0; ModeNumber < mNumGopModes; ++ModeNumber) {\r
+        if (mGopModes[ModeNumber].X == PlatformConfig.HorizontalResolution &&\r
+            mGopModes[ModeNumber].Y == PlatformConfig.VerticalResolution) {\r
+          MainFormState->NextPreferredResolution = (UINT32) ModeNumber;\r
+          break;\r
+        }\r
+      }\r
+\r
+      break;\r
+    }\r
+    //\r
+    // fall through otherwise\r
+    //\r
+\r
+  case EFI_NOT_FOUND:\r
+    UnicodeSPrintAsciiFormat (\r
+      (CHAR16 *) MainFormState->CurrentPreferredResolution,\r
+      sizeof MainFormState->CurrentPreferredResolution,\r
+      "Unset");\r
+    break;\r
+\r
+  default:\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
 /**\r
   This function is called by the HII machinery when it fetches the form state.\r
 \r
@@ -142,7 +216,9 @@ STATIC GOP_MODE *mGopModes;
                         all values filled in for the names in the Request\r
                         string.\r
 \r
-  @return  Status codes from gHiiConfigRouting->BlockToConfig().\r
+  @retval EFI_SUCCESS  Extraction of form state in <MultiConfigAltResp>\r
+                       encoding successful.\r
+  @return              Status codes from underlying functions.\r
 \r
 **/\r
 STATIC\r
@@ -160,9 +236,15 @@ ExtractConfig (
 \r
   DEBUG ((EFI_D_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));\r
 \r
-  StrnCpy ((CHAR16 *) MainFormState.CurrentPreferredResolution,\r
-           L"Unset", MAXSIZE_RES_CUR);\r
-  MainFormState.NextPreferredResolution = 0;\r
+  Status = PlatformConfigToFormState (&MainFormState);\r
+  if (EFI_ERROR (Status)) {\r
+    *Progress = Request;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Answer the textual request keying off the binary form state.\r
+  //\r
   Status = gHiiConfigRouting->BlockToConfig (gHiiConfigRouting, Request,\r
                                 (VOID *) &MainFormState, sizeof MainFormState,\r
                                 Results, Progress);\r