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
+#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/DevicePathLib.h>\r
#include <Library/HiiLib.h>\r
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
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
\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
}\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
OUT EFI_STRING *Progress\r
)\r
{\r
- return EFI_SUCCESS;\r
+ MAIN_FORM_STATE MainFormState;\r
+ UINTN BlockSize;\r
+ EFI_STATUS Status;\r
+\r
+ DEBUG ((EFI_D_VERBOSE, "%a: Configuration=\"%s\"\n", __FUNCTION__,\r
+ Configuration));\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 ((EFI_D_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
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
)\r
{\r
+ DEBUG ((EFI_D_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
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ switch (QuestionId) {\r
+ case QUESTION_SAVE_EXIT:\r
+ *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
+ break;\r
+\r
+ case QUESTION_DISCARD_EXIT:\r
+ *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+\r
return EFI_SUCCESS;\r
}\r
\r
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
//\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