]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/PlatformDxe/Platform.c
OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones
[mirror_edk2.git] / OvmfPkg / PlatformDxe / Platform.c
index 49189141bbbbe04351f56e97111c1d6b0aeada41..f2e51960ce8b7c1d00fe76764598e1f55fd5cea8 100644 (file)
@@ -5,13 +5,7 @@
   Copyright (C) 2014, Red Hat, Inc.\r
   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials are licensed and made available\r
-  under the terms and conditions of the BSD License which accompanies this\r
-  distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
-  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
 #include <Library/BaseLib.h>\r
@@ -234,7 +228,7 @@ ExtractConfig (
   MAIN_FORM_STATE MainFormState;\r
   EFI_STATUS      Status;\r
 \r
-  DEBUG ((EFI_D_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));\r
+  DEBUG ((DEBUG_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));\r
 \r
   Status = PlatformConfigToFormState (&MainFormState);\r
   if (EFI_ERROR (Status)) {\r
@@ -249,15 +243,71 @@ ExtractConfig (
                                 (VOID *) &MainFormState, sizeof MainFormState,\r
                                 Results, Progress);\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "%a: BlockToConfig(): %r, Progress=\"%s\"\n",\r
+    DEBUG ((DEBUG_ERROR, "%a: BlockToConfig(): %r, Progress=\"%s\"\n",\r
       __FUNCTION__, Status, (Status == EFI_DEVICE_ERROR) ? NULL : *Progress));\r
   } else {\r
-    DEBUG ((EFI_D_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));\r
+    DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));\r
   }\r
   return Status;\r
 }\r
 \r
 \r
+/**\r
+  Interpret the binary form state and save it as persistent platform\r
+  configuration.\r
+\r
+  @param[in] MainFormState  Binary form/widget state to verify and save.\r
+\r
+  @retval EFI_SUCCESS  Platform configuration saved.\r
+  @return              Error codes from underlying functions.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+FormStateToPlatformConfig (\r
+  IN CONST MAIN_FORM_STATE *MainFormState\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  PLATFORM_CONFIG PlatformConfig;\r
+  CONST GOP_MODE  *GopMode;\r
+\r
+  //\r
+  // There's nothing to do with the textual CurrentPreferredResolution field.\r
+  // We verify and translate the selection in the drop-down list.\r
+  //\r
+  if (MainFormState->NextPreferredResolution >= mNumGopModes) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  GopMode = mGopModes + MainFormState->NextPreferredResolution;\r
+\r
+  ZeroMem (&PlatformConfig, sizeof PlatformConfig);\r
+  PlatformConfig.HorizontalResolution = GopMode->X;\r
+  PlatformConfig.VerticalResolution   = GopMode->Y;\r
+\r
+  Status = PlatformConfigSave (&PlatformConfig);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  This function is called by the HII machinery when it wants the driver to\r
+  interpret and persist the form state.\r
+\r
+  See the precise documentation in the UEFI spec.\r
+\r
+  @param[in]  This           The Config Access Protocol instance.\r
+\r
+  @param[in]  Configuration  A <ConfigResp> format UCS-2 string describing the\r
+                             form state.\r
+\r
+  @param[out] Progress       A pointer into Configuration on output,\r
+                             identifying the element where processing failed.\r
+\r
+  @retval EFI_SUCCESS  Configuration verified, state permanent.\r
+\r
+  @return              Status codes from underlying functions.\r
+**/\r
 STATIC\r
 EFI_STATUS\r
 EFIAPI\r
@@ -267,9 +317,46 @@ RouteConfig (
   OUT       EFI_STRING                      *Progress\r
 )\r
 {\r
-  DEBUG ((EFI_D_VERBOSE, "%a: Configuration=\"%s\"\n", __FUNCTION__,\r
+  MAIN_FORM_STATE MainFormState;\r
+  UINTN           BlockSize;\r
+  EFI_STATUS      Status;\r
+\r
+  DEBUG ((DEBUG_VERBOSE, "%a: Configuration=\"%s\"\n", __FUNCTION__,\r
     Configuration));\r
-  return EFI_SUCCESS;\r
+\r
+  //\r
+  // the "read" step in RMW\r
+  //\r
+  Status = PlatformConfigToFormState (&MainFormState);\r
+  if (EFI_ERROR (Status)) {\r
+    *Progress = Configuration;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // the "modify" step in RMW\r
+  //\r
+  // (Update the binary form state. This update may be partial, which is why in\r
+  // general we must pre-load the form state from the platform config.)\r
+  //\r
+  BlockSize = sizeof MainFormState;\r
+  Status = gHiiConfigRouting->ConfigToBlock (gHiiConfigRouting, Configuration,\r
+                                (VOID *) &MainFormState, &BlockSize, Progress);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "%a: ConfigToBlock(): %r, Progress=\"%s\"\n",\r
+      __FUNCTION__, Status,\r
+      (Status == EFI_BUFFER_TOO_SMALL) ? NULL : *Progress));\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // the "write" step in RMW\r
+  //\r
+  Status = FormStateToPlatformConfig (&MainFormState);\r
+  if (EFI_ERROR (Status)) {\r
+    *Progress = Configuration;\r
+  }\r
+  return Status;\r
 }\r
 \r
 \r
@@ -285,7 +372,7 @@ Callback (
   OUT    EFI_BROWSER_ACTION_REQUEST             *ActionRequest\r
   )\r
 {\r
-  DEBUG ((EFI_D_VERBOSE, "%a: Action=0x%Lx QuestionId=%d Type=%d\n",\r
+  DEBUG ((DEBUG_VERBOSE, "%a: Action=0x%Lx QuestionId=%d Type=%d\n",\r
     __FUNCTION__, (UINT64) Action, QuestionId, Type));\r
 \r
   if (Action != EFI_BROWSER_ACTION_CHANGED) {\r
@@ -399,7 +486,7 @@ STATIC
 EFI_STATUS\r
 EFIAPI\r
 CreateResolutionOptions (\r
-  IN  EFI_HII_HANDLE  *PackageList,\r
+  IN  EFI_HII_HANDLE  PackageList,\r
   OUT VOID            **OpCodeBuffer,\r
   IN  UINTN           NumGopModes,\r
   IN  GOP_MODE        *GopModes\r
@@ -460,7 +547,7 @@ STATIC
 EFI_STATUS\r
 EFIAPI\r
 PopulateForm (\r
-  IN  EFI_HII_HANDLE  *PackageList,\r
+  IN  EFI_HII_HANDLE  PackageList,\r
   IN  EFI_GUID        *FormSetGuid,\r
   IN  EFI_FORM_ID     FormId,\r
   IN  UINTN           NumGopModes,\r
@@ -570,10 +657,11 @@ ExecutePlatformConfig (
   EFI_STATUS      Status;\r
   PLATFORM_CONFIG PlatformConfig;\r
   UINT64          OptionalElements;\r
+  RETURN_STATUS   PcdStatus;\r
 \r
   Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG (((Status == EFI_NOT_FOUND) ? EFI_D_VERBOSE : EFI_D_ERROR,\r
+    DEBUG (((Status == EFI_NOT_FOUND) ? DEBUG_VERBOSE : DEBUG_ERROR,\r
       "%a: failed to load platform config: %r\n", __FUNCTION__, Status));\r
     return Status;\r
   }\r
@@ -582,10 +670,13 @@ ExecutePlatformConfig (
     //\r
     // Pass the preferred resolution to GraphicsConsoleDxe via dynamic PCDs.\r
     //\r
-    PcdSet32 (PcdVideoHorizontalResolution,\r
+    PcdStatus = PcdSet32S (PcdVideoHorizontalResolution,\r
       PlatformConfig.HorizontalResolution);\r
-    PcdSet32 (PcdVideoVerticalResolution,\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
+    PcdStatus = PcdSet32S (PcdVideoVerticalResolution,\r
       PlatformConfig.VerticalResolution);\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
   }\r
 \r
   return EFI_SUCCESS;\r