]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/OpcodeCreation.c
Support Framework IFR SELECT OP code.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / OpcodeCreation.c
index 7a14b9c68ae9dbbcd0192e39863c61371f1efafe..0692c2a5994c5174e42e5bf947066028a8e09030 100644 (file)
@@ -2,7 +2,7 @@
 Implement Functions to convert IFR Opcode in format defined in Framework HII specification to\r
 format defined in UEFI HII Specification.\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2010, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -26,7 +26,7 @@ typedef struct {
   UINT8 UefiIfrOp;\r
 } IFR_OPCODE_MAP;\r
   \r
-IFR_OPCODE_MAP mQuestionOpcodeMap [] = {\r
+IFR_OPCODE_MAP QuestionOpcodeMap[] = {\r
   { FRAMEWORK_EFI_IFR_ONE_OF_OP,        EFI_IFR_ONE_OF_OP},\r
   { FRAMEWORK_EFI_IFR_CHECKBOX_OP,      EFI_IFR_CHECKBOX_OP},\r
   { FRAMEWORK_EFI_IFR_NUMERIC_OP,       EFI_IFR_NUMERIC_OP},\r
@@ -51,9 +51,9 @@ QuestionOpFwToUefi (
 {\r
   UINTN       Index;\r
 \r
-  for (Index = 0; Index < sizeof (mQuestionOpcodeMap) / sizeof (mQuestionOpcodeMap[0]); Index++) {\r
-    if (FwOp == mQuestionOpcodeMap[Index].FrameworkIfrOp) {\r
-      *UefiOp = mQuestionOpcodeMap[Index].UefiIfrOp;\r
+  for (Index = 0; Index < sizeof (QuestionOpcodeMap) / sizeof (QuestionOpcodeMap[0]); Index++) {\r
+    if (FwOp == QuestionOpcodeMap[Index].FrameworkIfrOp) {\r
+      *UefiOp = QuestionOpcodeMap[Index].UefiIfrOp;\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -63,13 +63,15 @@ QuestionOpFwToUefi (
 }\r
 \r
 /**\r
-  Translate a Framework Question Opcode to UEFI Question Opcode.\r
+  Translate a Framework Question ID to UEFI Question ID.\r
 \r
-  @param FwOp     Framework Opcode.\r
-  @param UefiOp   UEFI Opcode.\r
+  @param FormSet   FormSet context\r
+  @param FwOpCode  Framework Opcode\r
+  @param FwQId     Framework Question Id\r
+  @param UefiQId   UEFI Question ID.\r
 \r
-  @retval     EFI_SUCCESS     The UEFI opcode is found and returned.\r
-  @retval     EFI_NOT_FOUND   The UEFI opcode is not found.\r
+  @retval     EFI_SUCCESS     The UEFI Question Id is found and returned.\r
+  @retval     EFI_NOT_FOUND   The UEFI Question Id is not found.\r
 **/\r
 EFI_STATUS\r
 FwQIdToUefiQId (\r
@@ -150,6 +152,9 @@ FwQIdToUefiQId (
 \r
   If FwQuestionId is not 0, then it is used as the Framework Question ID.\r
 \r
+  @param FwQuestionId \r
+  @param FormSet      \r
+\r
   @return The Framework Question ID.\r
 **/\r
 EFI_QUESTION_ID\r
@@ -169,8 +174,8 @@ AssignQuestionId (
 /**\r
   Create UEFI HII Text Opcode from a Framework HII Text Opcode.\r
 \r
-  @param FwOpcode              The input Framework Opcode.\r
   @param UefiUpdateDataHandle  The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
+  @param FwOpcode              The input Framework Opcode.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -207,8 +212,8 @@ F2UCreateTextOpCode (
 /**\r
   Create UEFI HII Reference Opcode from a Framework HII Reference Opcode.\r
 \r
-  @param FwOpcode              The input Framework Opcode.\r
   @param UefiUpdateDataHandle  The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
+  @param FwOpcode              The input Framework Opcode.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -245,9 +250,9 @@ F2UCreateReferenceOpCode (
 /**\r
   Create UEFI HII "One Of Option" Opcode from a Framework HII "One Of Option" Opcode.\r
 \r
+  @param UefiUpdateDataHandle  The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param FwOpcode              The input Framework Opcode.\r
   @param Width                 The size of the One Of Option. 1 bytes or 2 bytes.\r
-  @param UefiUpdateDataHandle  The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -300,10 +305,10 @@ F2UCreateOneOfOptionOpCode (
   to a UEFI Question ID. This information is used to invoke the Framework HII Browser Callback\r
   function. The opcode is appened to UefiUpdateDataHandle.\r
 \r
+  @param    UefiUpdateDataHandle  The UEFI Update Data buffer.\r
   @param    QuestionId            The UEFI Question ID.\r
   @param    OptionValue           The value of the "One Of Option".\r
   @param    KeyValue              The Framework "One Of Option" callback key.\r
-  @param    UefiUpdateDataHandle  The UEFI Update Data buffer.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -336,9 +341,9 @@ CreateGuidOptionKeyOpCode (
 /**\r
   Create UEFI HII "One Of" Opcode from a Framework HII "One Of" Opcode.\r
 \r
+  @param UefiUpdateDataHandle     The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param ThunkContext             The HII Thunk Context.\r
   @param FwOpcode                 The input Framework Opcode.\r
-  @param UefiUpdateDataHandle     The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param NextFwOpcode             Returns the position of the next Framework Opcode after EFI_IFR_END_ONE_OF_OP of\r
                                   the "One Of Option".\r
   @param OpcodeCount              The number of Opcode for the complete Framework "One Of" Opcode.\r
@@ -398,7 +403,7 @@ F2UCreateOneOfOpCode (
 \r
     }\r
 \r
-    if (FwOneOfOp->Flags & EFI_IFR_FLAG_RESET_REQUIRED) {\r
+    if ((FwOneOfOp->Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {\r
       UOpcode.Question.Flags |= EFI_IFR_FLAG_RESET_REQUIRED;\r
     }\r
 \r
@@ -456,9 +461,9 @@ F2UCreateOneOfOpCode (
 /**\r
   Create UEFI HII "Ordered List" Opcode from a Framework HII "Ordered List" Opcode.\r
 \r
+  @param UefiUpdateDataHandle The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param ThunkContext         The HII Thunk Context.\r
   @param FwOpcode             The input Framework Opcode.\r
-  @param UefiUpdateDataHandle The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param NextFwOpcode         Returns the position of the next Framework Opcode after EFI_IFR_END_ONE_OF_OP of\r
                               the "Ordered List".\r
   @param OpcodeCount          The number of Opcode for the complete Framework "Ordered List" Opcode.\r
@@ -517,7 +522,7 @@ F2UCreateOrderedListOpCode (
       }\r
     }\r
 \r
-    if (FwOneOfOp->Flags & EFI_IFR_FLAG_RESET_REQUIRED) {\r
+    if ((FwOneOfOp->Flags & EFI_IFR_FLAG_RESET_REQUIRED) ==  EFI_IFR_FLAG_RESET_REQUIRED) {\r
       UOpcode.Question.Flags |= EFI_IFR_FLAG_RESET_REQUIRED;\r
     }\r
 \r
@@ -562,9 +567,9 @@ F2UCreateOrderedListOpCode (
 /**\r
   Create UEFI HII CheckBox Opcode from a Framework HII Checkbox Opcode.\r
 \r
+  @param UefiUpdateDataHandle  The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param ThunkContext          The HII Thunk Context.\r
   @param FwOpcode              The input Framework Opcode.\r
-  @param UefiUpdateDataHandle  The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -627,9 +632,9 @@ F2UCreateCheckBoxOpCode (
 /**\r
   Create UEFI HII Numeric Opcode from a Framework HII Numeric Opcode.\r
 \r
+  @param UefiUpdateDataHandle    The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param ThunkContext            The HII Thunk Context.\r
   @param FwOpcode                The input Framework Opcode.\r
-  @param UefiUpdateDataHandle    The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -749,9 +754,9 @@ F2UCreateNumericOpCode (
 /**\r
   Create UEFI HII String Opcode from a Framework HII String Opcode.\r
 \r
+  @param UefiUpdateDataHandle     The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
   @param ThunkContext             The HII Thunk Context.\r
   @param FwOpcode                 The input Framework Opcode.\r
-  @param UefiUpdateDataHandle     The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -802,8 +807,8 @@ F2UCreateStringOpCode (
 /**\r
   Create UEFI HII Banner Opcode from a Framework HII Banner Opcode.\r
 \r
-  @param FwOpcode                 The input Framework Opcode.\r
   @param UefiUpdateDataHandle     The newly created UEFI HII opcode is appended to UefiUpdateDataHandle.\r
+  @param FwOpcode                 The input Framework Opcode.\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
   @retval Other  A pointer to the created opcode.\r
@@ -837,7 +842,7 @@ F2UCreateBannerOpCode (
 \r
   @param ThunkContext         The HII Thunk Context.\r
   @param FwUpdateData         The Framework Update Data.\r
-  @param UefiUpdateData       The UEFI Update Data.\r
+  @param UefiOpCodeHandle     The UEFI opcode hanlde.\r
 \r
   @retval EFI_SUCCESS       The UEFI Update Data is created successfully.\r
   @retval EFI_UNSUPPORTED   There is unsupported opcode in FwUpdateData.\r
@@ -855,9 +860,19 @@ FwUpdateDataToUefiUpdateData (
   UINTN                                Index;\r
   UINTN                                DataCount;\r
   UINT8                                *OpCodeBuffer;\r
+  LIST_ENTRY                           *StorageList;\r
+  FORMSET_STORAGE                      *Storage;\r
+  FORM_BROWSER_FORMSET                 *FormSet;\r
+  CHAR16                               *DefaultVarStoreName;\r
+  UINT16                               DefaultVarStoreId;\r
+  EFI_IFR_VARSTORE_SELECT              *SelectVarOp;\r
 \r
   FwOpCode = (FRAMEWORK_EFI_IFR_OP_HEADER *) &FwUpdateData->Data;\r
 \r
+  FormSet = ThunkContext->FormSet;\r
+  DefaultVarStoreId   = FormSet->DefaultVarStoreId;\r
+  DefaultVarStoreName = FormSet->OriginalDefaultVarStoreName;\r
+\r
   for (Index = 0; Index < FwUpdateData->DataCount; Index += DataCount) {\r
     switch (FwOpCode->OpCode) {\r
       case FRAMEWORK_EFI_IFR_SUBTITLE_OP:\r
@@ -921,6 +936,31 @@ FwUpdateDataToUefiUpdateData (
         OpCodeBuffer = F2UCreateNumericOpCode (UefiOpCodeHandle, ThunkContext, (FRAMEWORK_EFI_IFR_NUMERIC *) FwOpCode);\r
         DataCount = 1;\r
         break;\r
+      \r
+      case EFI_IFR_VARSTORE_SELECT_OP:\r
+        OpCodeBuffer = (UINT8 *) FwOpCode;\r
+        SelectVarOp  = (EFI_IFR_VARSTORE_SELECT *) FwOpCode;\r
+        //\r
+        // Check whether the selected VarId is in StorageList.\r
+        //\r
+        StorageList = GetFirstNode (&FormSet->StorageListHead);\r
+        while (!IsNull (&FormSet->StorageListHead, StorageList)) {\r
+          Storage = FORMSET_STORAGE_FROM_LINK (StorageList);\r
+          if (Storage->VarStoreId == SelectVarOp->VarId) {\r
+            break;\r
+          }\r
+          StorageList = GetNextNode (&FormSet->StorageListHead, StorageList);\r
+        }\r
+        ASSERT (!IsNull (&FormSet->StorageListHead, StorageList));\r
+        //\r
+        // Change VarStoreId to the selected VarId.\r
+        //\r
+        FormSet->DefaultVarStoreId = SelectVarOp->VarId;\r
+        if (SelectVarOp->VarId == DefaultVarStoreId)  {\r
+          FormSet->OriginalDefaultVarStoreName = DefaultVarStoreName;\r
+        }\r
+        DataCount = 1;\r
+        break;\r
 \r
       default:\r
         ASSERT (FALSE);\r
@@ -934,6 +974,11 @@ FwUpdateDataToUefiUpdateData (
     FwOpCode = (FRAMEWORK_EFI_IFR_OP_HEADER *)((UINT8 *) FwOpCode + FwOpCode->Length);\r
   }\r
 \r
+  //\r
+  // Revert FromSet default varstore ID.\r
+  //\r
+  FormSet->DefaultVarStoreId           = DefaultVarStoreId;\r
+  FormSet->OriginalDefaultVarStoreName = DefaultVarStoreName;\r
   return EFI_SUCCESS;\r
 }\r
 \r