--- /dev/null
+/*++\r
+Copyright (c) 2006, 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
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+ IfrOpCodeCreation.c\r
+\r
+Abstract:\r
+\r
+ Library Routines to create IFR independent of string data - assume tokens already exist\r
+ Primarily to be used for exporting op-codes at a label in pre-defined forms.\r
+\r
+Revision History:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+EFI_STATUS\r
+CreateSubTitleOpCode (\r
+ IN STRING_REF StringToken,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a SubTitle opcode independent of string creation\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+ \r
+Arguments:\r
+ \r
+ StringToken - StringToken of the subtitle\r
+ \r
+ FormBuffer - Output of subtitle as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - Subtitle created to be a form\r
+\r
+--*/\r
+{\r
+ EFI_IFR_SUBTITLE Subtitle;\r
+\r
+ Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;\r
+ Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);\r
+ Subtitle.SubTitle = StringToken;\r
+\r
+ CopyMem (FormBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE));\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CreateTextOpCode (\r
+ IN STRING_REF StringToken,\r
+ IN STRING_REF StringTokenTwo,\r
+ IN STRING_REF StringTokenThree,\r
+ IN UINT8 Flags,\r
+ IN UINT16 Key,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a Text opcode independent of string creation\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+ \r
+Arguments:\r
+ \r
+ StringToken - First string token of the text\r
+ \r
+ StringTokenTwo - Second string token of the text\r
+ \r
+ StringTokenThree - Help string token of the text\r
+ \r
+ Flags - Flag of the text\r
+ \r
+ Key - Key of the text\r
+ \r
+ FormBuffer - Output of text as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - Text created to be a form\r
+\r
+--*/\r
+{\r
+ EFI_IFR_TEXT Text;\r
+\r
+ Text.Header.OpCode = EFI_IFR_TEXT_OP;\r
+ Text.Header.Length = sizeof (EFI_IFR_TEXT);\r
+ Text.Text = StringToken;\r
+\r
+ Text.TextTwo = StringTokenTwo;\r
+ Text.Help = StringTokenThree;\r
+ Text.Flags = Flags;\r
+ Text.Key = Key;\r
+\r
+ CopyMem (FormBuffer, &Text, sizeof (EFI_IFR_TEXT));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CreateGotoOpCode (\r
+ IN UINT16 FormId,\r
+ IN STRING_REF StringToken,\r
+ IN STRING_REF StringTokenTwo,\r
+ IN UINT8 Flags,\r
+ IN UINT16 Key,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a hyperlink opcode independent of string creation\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+ \r
+Arguments:\r
+ \r
+ FormId - Form ID of the hyperlink\r
+ \r
+ StringToken - Prompt string token of the hyperlink\r
+ \r
+ StringTokenTwo - Help string token of the hyperlink\r
+ \r
+ Flags - Flags of the hyperlink\r
+ \r
+ Key - Key of the hyperlink\r
+ \r
+ FormBuffer - Output of hyperlink as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - Hyperlink created to be a form\r
+\r
+--*/\r
+{\r
+ EFI_IFR_REF Hyperlink;\r
+\r
+ Hyperlink.Header.OpCode = EFI_IFR_REF_OP;\r
+ Hyperlink.Header.Length = sizeof (EFI_IFR_REF);\r
+ Hyperlink.FormId = FormId;\r
+ Hyperlink.Prompt = StringToken;\r
+ Hyperlink.Help = StringTokenTwo;\r
+ Hyperlink.Key = Key;\r
+ Hyperlink.Flags = Flags;\r
+\r
+ CopyMem (FormBuffer, &Hyperlink, sizeof (EFI_IFR_REF));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CreateOneOfOpCode (\r
+ IN UINT16 QuestionId,\r
+ IN UINT8 DataWidth,\r
+ IN STRING_REF PromptToken,\r
+ IN STRING_REF HelpToken,\r
+ IN IFR_OPTION *OptionsList,\r
+ IN UINTN OptionCount,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a one-of opcode with a set of option op-codes to choose from independent of string creation.\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+\r
+ OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken\r
+ has been filled in since this routine will not generate StringToken values.\r
+ \r
+Arguments:\r
+ \r
+ QuestionId - Question ID of the one-of box\r
+ \r
+ DataWidth - DataWidth of the one-of box\r
+ \r
+ PromptToken - Prompt string token of the one-of box\r
+ \r
+ HelpToken - Help string token of the one-of box\r
+ \r
+ OptionsList - Each string in it is an option of the one-of box\r
+ \r
+ OptionCount - Option string count\r
+ \r
+ FormBuffer - Output of One-Of box as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - One-Of box created to be a form\r
+ \r
+ EFI_DEVICE_ERROR - DataWidth > 2\r
+\r
+--*/\r
+{\r
+ UINTN Index;\r
+ EFI_IFR_ONE_OF OneOf;\r
+ EFI_IFR_ONE_OF_OPTION OneOfOption;\r
+ EFI_IFR_END_ONE_OF EndOneOf;\r
+ UINT8 *LocalBuffer;\r
+\r
+ //\r
+ // We do not create op-code storage widths for one-of in excess of 16 bits for now\r
+ //\r
+ if (DataWidth > 2) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;\r
+ OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);\r
+ OneOf.QuestionId = QuestionId;\r
+ OneOf.Width = DataWidth;\r
+ OneOf.Prompt = PromptToken;\r
+\r
+ OneOf.Help = HelpToken;\r
+\r
+ LocalBuffer = (UINT8 *) FormBuffer;\r
+\r
+ CopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF));\r
+\r
+ LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF));\r
+\r
+ for (Index = 0; Index < OptionCount; Index++) {\r
+ OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;\r
+ OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);\r
+\r
+ OneOfOption.Option = OptionsList[Index].StringToken;\r
+ OneOfOption.Value = OptionsList[Index].Value;\r
+ OneOfOption.Flags = OptionsList[Index].Flags;\r
+ OneOfOption.Key = OptionsList[Index].Key;\r
+\r
+ CopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION));\r
+\r
+ LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));\r
+ }\r
+\r
+ EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);\r
+ EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;\r
+\r
+ CopyMem (LocalBuffer, &EndOneOf, sizeof (EFI_IFR_END_ONE_OF));\r
+\r
+ LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+CreateOrderedListOpCode (\r
+ IN UINT16 QuestionId,\r
+ IN UINT8 MaxEntries,\r
+ IN STRING_REF PromptToken,\r
+ IN STRING_REF HelpToken,\r
+ IN IFR_OPTION *OptionsList,\r
+ IN UINTN OptionCount,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a ordered list opcode with a set of option op-codes to choose from independent of string creation.\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+\r
+ OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken\r
+ has been filled in since this routine will not generate StringToken values.\r
+ \r
+Arguments:\r
+ \r
+ QuestionId - Question ID of the ordered list\r
+ \r
+ MaxEntries - MaxEntries of the ordered list\r
+ \r
+ PromptToken - Prompt string token of the ordered list\r
+ \r
+ HelpToken - Help string token of the ordered list\r
+ \r
+ OptionsList - Each string in it is an option of the ordered list\r
+ \r
+ OptionCount - Option string count\r
+ \r
+ FormBuffer - Output of ordered list as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - Ordered list created to be a form\r
+\r
+--*/\r
+{\r
+ UINTN Index;\r
+ EFI_IFR_ORDERED_LIST OrderedList;\r
+ EFI_IFR_ONE_OF_OPTION OrderedListOption;\r
+ EFI_IFR_END_ONE_OF EndOrderedList;\r
+ UINT8 *LocalBuffer;\r
+\r
+ OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;\r
+ OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);\r
+ OrderedList.QuestionId = QuestionId;\r
+ OrderedList.MaxEntries = MaxEntries;\r
+ OrderedList.Prompt = PromptToken;\r
+\r
+ OrderedList.Help = HelpToken;\r
+\r
+ LocalBuffer = (UINT8 *) FormBuffer;\r
+\r
+ CopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST));\r
+\r
+ LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ORDERED_LIST));\r
+\r
+ for (Index = 0; Index < OptionCount; Index++) {\r
+ OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;\r
+ OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);\r
+\r
+ OrderedListOption.Option = OptionsList[Index].StringToken;\r
+ OrderedListOption.Value = OptionsList[Index].Value;\r
+ OrderedListOption.Flags = OptionsList[Index].Flags;\r
+ OrderedListOption.Key = OptionsList[Index].Key;\r
+\r
+ CopyMem (LocalBuffer, &OrderedListOption, sizeof (EFI_IFR_ONE_OF_OPTION));\r
+\r
+ LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));\r
+ }\r
+\r
+ EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);\r
+ EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;\r
+\r
+ CopyMem (LocalBuffer, &EndOrderedList, sizeof (EFI_IFR_END_ONE_OF));\r
+\r
+ LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+CreateCheckBoxOpCode (\r
+ IN UINT16 QuestionId,\r
+ IN UINT8 DataWidth,\r
+ IN STRING_REF PromptToken,\r
+ IN STRING_REF HelpToken,\r
+ IN UINT8 Flags,\r
+ IN UINT16 Key,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a checkbox opcode independent of string creation\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+ \r
+Arguments:\r
+ \r
+ QuestionId - Question ID of the check box\r
+ \r
+ DataWidth - DataWidth of the check box\r
+ \r
+ PromptToken - Prompt string token of the check box\r
+ \r
+ HelpToken - Help string token of the check box\r
+ \r
+ Flags - Flags of the check box\r
+ \r
+ Key - Key of the check box\r
+ \r
+ FormBuffer - Output of the check box as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - Checkbox created to be a form\r
+ \r
+ EFI_DEVICE_ERROR - DataWidth > 1\r
+\r
+--*/\r
+{\r
+ EFI_IFR_CHECKBOX CheckBox;\r
+\r
+ //\r
+ // We do not create op-code storage widths for checkbox in excess of 8 bits for now\r
+ //\r
+ if (DataWidth > 1) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;\r
+ CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX);\r
+ CheckBox.QuestionId = QuestionId;\r
+ CheckBox.Width = DataWidth;\r
+ CheckBox.Prompt = PromptToken;\r
+\r
+ CheckBox.Help = HelpToken;\r
+ CheckBox.Flags = Flags;\r
+ CheckBox.Key = Key;\r
+\r
+ CopyMem (FormBuffer, &CheckBox, sizeof (EFI_IFR_CHECKBOX));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CreateNumericOpCode (\r
+ IN UINT16 QuestionId,\r
+ IN UINT8 DataWidth,\r
+ IN STRING_REF PromptToken,\r
+ IN STRING_REF HelpToken,\r
+ IN UINT16 Minimum,\r
+ IN UINT16 Maximum,\r
+ IN UINT16 Step,\r
+ IN UINT16 Default,\r
+ IN UINT8 Flags,\r
+ IN UINT16 Key,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a numeric opcode independent of string creation\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+ \r
+Arguments:\r
+ \r
+ QuestionId - Question ID of the numeric\r
+ \r
+ DataWidth - DataWidth of the numeric\r
+ \r
+ PromptToken - Prompt string token of the numeric\r
+ \r
+ HelpToken - Help string token of the numeric\r
+ \r
+ Minimum - Minumun boundary of the numeric\r
+ \r
+ Maximum - Maximum boundary of the numeric\r
+ \r
+ Step - Step of the numeric\r
+ \r
+ Default - Default value of the numeric\r
+ \r
+ Flags - Flags of the numeric\r
+ \r
+ Key - Key of the numeric\r
+ \r
+ FormBuffer - Output of the numeric as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - The numeric created to be a form.\r
+ \r
+ EFI_DEVICE_ERROR - DataWidth > 2\r
+\r
+--*/\r
+{\r
+ EFI_IFR_NUMERIC Numeric;\r
+\r
+ //\r
+ // We do not create op-code storage widths for numerics in excess of 16 bits for now\r
+ //\r
+ if (DataWidth > 2) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;\r
+ Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);\r
+ Numeric.QuestionId = QuestionId;\r
+ Numeric.Width = DataWidth;\r
+ Numeric.Prompt = PromptToken;\r
+\r
+ Numeric.Help = HelpToken;\r
+ Numeric.Minimum = Minimum;\r
+ Numeric.Maximum = Maximum;\r
+ Numeric.Step = Step;\r
+ Numeric.Default = Default;\r
+ Numeric.Flags = Flags;\r
+ Numeric.Key = Key;\r
+\r
+ CopyMem (FormBuffer, &Numeric, sizeof (EFI_IFR_NUMERIC));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CreateStringOpCode (\r
+ IN UINT16 QuestionId,\r
+ IN UINT8 DataWidth,\r
+ IN STRING_REF PromptToken,\r
+ IN STRING_REF HelpToken,\r
+ IN UINT8 MinSize,\r
+ IN UINT8 MaxSize,\r
+ IN UINT8 Flags,\r
+ IN UINT16 Key,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a numeric opcode independent of string creation\r
+ This is used primarily by users who need to create just one particular valid op-code and the string\r
+ data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label\r
+ location to pre-defined forms in HII)\r
+ \r
+Arguments:\r
+ \r
+ QuestionId - Question ID of the string\r
+ \r
+ DataWidth - DataWidth of the string\r
+ \r
+ PromptToken - Prompt token of the string\r
+ \r
+ HelpToken - Help token of the string\r
+ \r
+ MinSize - Min size boundary of the string\r
+ \r
+ MaxSize - Max size boundary of the string\r
+ \r
+ Flags - Flags of the string\r
+ \r
+ Key - Key of the string\r
+ \r
+ FormBuffer - Output of the string as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - String created to be a form.\r
+\r
+--*/\r
+{\r
+ EFI_IFR_STRING String;\r
+\r
+ String.Header.OpCode = EFI_IFR_STRING_OP;\r
+ String.Header.Length = sizeof (EFI_IFR_STRING);\r
+ String.QuestionId = QuestionId;\r
+ String.Width = DataWidth;\r
+ String.Prompt = PromptToken;\r
+\r
+ String.Help = HelpToken;\r
+ String.MinSize = MinSize;\r
+ String.MaxSize = MaxSize;\r
+ String.Flags = Flags;\r
+ String.Key = Key;\r
+\r
+ CopyMem (FormBuffer, &String, sizeof (EFI_IFR_STRING));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CreateBannerOpCode (\r
+ IN UINT16 Title,\r
+ IN UINT16 LineNumber,\r
+ IN UINT8 Alignment,\r
+ IN OUT VOID *FormBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Create a banner opcode. This is primarily used by the FrontPage implementation from BDS.\r
+ \r
+Arguments:\r
+ \r
+ Title - Title of the banner\r
+ \r
+ LineNumber - LineNumber of the banner\r
+ \r
+ Alignment - Alignment of the banner\r
+ \r
+ FormBuffer - Output of banner as a form\r
+ \r
+Returns: \r
+\r
+ EFI_SUCCESS - Banner created to be a form.\r
+\r
+--*/\r
+{\r
+ EFI_IFR_BANNER Banner;\r
+\r
+ Banner.Header.OpCode = EFI_IFR_BANNER_OP;\r
+ Banner.Header.Length = sizeof (EFI_IFR_BANNER);\r
+ CopyMem (&Banner.Title, &Title, sizeof (UINT16));\r
+ CopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16));\r
+ Banner.Alignment = Alignment;\r
+\r
+ CopyMem (FormBuffer, &Banner, sizeof (EFI_IFR_BANNER));\r
+\r
+ return EFI_SUCCESS;\r
+}\r