3 Parser for IFR binary encoding.
5 Copyright (c) 2011-2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Common/UefiInternalFormRepresentation.h>
15 #include <Common/MdeModuleHii.h>
18 // Scope for Browser action. It may be Form, FormSet or System level.
25 } BROWSER_SETTING_SCOPE
;
28 ///Old EFI_IFR_VARSTORE_EFI structure to complible with UEFI 2.3
30 typedef struct _EFI_IFR_VARSTORE_EFI_OLD
{
31 EFI_IFR_OP_HEADER Header
;
32 EFI_VARSTORE_ID VarStoreId
;
35 } EFI_IFR_VARSTORE_EFI_OLD
;
38 /// The languages used in HII DB
47 /// Define the structure for the parameters of Uqi and Uqi List
49 typedef struct _FORM_BROWSER_STATEMENT FORM_BROWSER_STATEMENT
;
69 FORM_BROWSER_STATEMENT
*Question
;
72 typedef struct _UQI_PARAM_LIST
{
73 struct _UQI_PARAM_LIST
*Next
;
82 // Incremental size of stack for expression
84 #define EXPRESSION_STACK_SIZE_INCREMENT 0x100
87 // IFR relative definition
89 #define EFI_HII_EXPRESSION_INCONSISTENT_IF 0
90 #define EFI_HII_EXPRESSION_NO_SUBMIT_IF 1
91 #define EFI_HII_EXPRESSION_GRAY_OUT_IF 2
92 #define EFI_HII_EXPRESSION_SUPPRESS_IF 3
93 #define EFI_HII_EXPRESSION_DISABLE_IF 4
94 #define EFI_HII_EXPRESSION_VALUE 5
95 #define EFI_HII_EXPRESSION_RULE 6
96 #define EFI_HII_EXPRESSION_READ 7
97 #define EFI_HII_EXPRESSION_WRITE 8
98 #define EFI_HII_EXPRESSION_WARNING_IF 9
100 #define EFI_HII_VARSTORE_BUFFER 0
101 #define EFI_HII_VARSTORE_NAME_VALUE 1
102 #define EFI_HII_VARSTORE_EFI_VARIABLE 2
103 #define EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER 3
105 #define FORM_INCONSISTENT_VALIDATION 0
106 #define FORM_NO_SUBMIT_VALIDATION 1
114 // Buffer Data and Length if Type is EFI_IFR_TYPE_BUFFER or EFI_IFR_TYPE_STRING
118 EFI_IFR_TYPE_VALUE Value
;
121 #define NAME_VALUE_NODE_SIGNATURE SIGNATURE_32 ('N', 'V', 'S', 'T')
131 #define NAME_VALUE_NODE_FROM_LINK(a) CR (a, NAME_VALUE_NODE, Link, NAME_VALUE_NODE_SIGNATURE)
133 #define FORMSET_STORAGE_SIGNATURE SIGNATURE_32 ('F', 'S', 'T', 'G')
139 UINT16 DefaultId
[MAX_PLATFORM_DEFAULT_ID_NUM
];
140 UINT64 PlatformId
[MAX_PLATFORM_DEFAULT_ID_NUM
];
141 UINT32 DefaultPlatformIdNum
;
144 BOOLEAN NewEfiVarstore
; //EfiVarStore for UEFI 2.31 or not
145 BOOLEAN Skip
; //Flag for sorting out the variables
147 UINT8 Type
; // Storage type
152 CHAR16
*Name
; // For EFI_IFR_VARSTORE
156 LIST_ENTRY NameValueListHead
; // List of NAME_VALUE_NODE
158 UINT32 Attributes
; // For EFI_IFR_VARSTORE_EFI: EFI Variable attribute
161 #define FORMSET_STORAGE_FROM_LINK(a) CR (a, FORMSET_STORAGE, Link, FORMSET_STORAGE_SIGNATURE)
164 EFI_STRING_ID VarName
;
168 #define EXPRESSION_OPCODE_SIGNATURE SIGNATURE_32 ('E', 'X', 'O', 'P')
176 UINT8 Format
; // For EFI_IFR_TO_STRING, EFI_IFR_FIND
177 UINT8 Flags
; // For EFI_IFR_SPAN
178 UINT8 RuleId
; // For EFI_IFR_RULE_REF
180 EFI_HII_VALUE Value
; // For EFI_IFR_EQ_ID_VAL, EFI_IFR_UINT64, EFI_IFR_UINT32, EFI_IFR_UINT16, EFI_IFR_UINT8, EFI_IFR_STRING_REF1
182 EFI_QUESTION_ID QuestionId
; // For EFI_IFR_EQ_ID_ID, EFI_IFR_EQ_ID_VAL_LIST, EFI_IFR_QUESTION_REF1
183 EFI_QUESTION_ID QuestionId2
;
185 UINT16 ListLength
; // For EFI_IFR_EQ_ID_VAL_LIST
188 EFI_STRING_ID DevicePath
; // For EFI_IFR_QUESTION_REF3_2, EFI_IFR_QUESTION_REF3_3
191 FORMSET_STORAGE
*VarStorage
; // For EFI_IFR_SET, EFI_IFR_GET
192 VAR_STORE_INFO VarStoreInfo
;// For EFI_IFR_SET, EFI_IFR_GET
193 UINT8 ValueType
; // For EFI_IFR_SET, EFI_IFR_GET
194 UINT8 ValueWidth
; // For EFI_IFR_SET, EFI_IFR_GET
195 CHAR16
*ValueName
; // For EFI_IFR_SET, EFI_IFR_GET
196 LIST_ENTRY MapExpressionList
; // nested expressions inside of Map opcode.
199 #define EXPRESSION_OPCODE_FROM_LINK(a) CR (a, EXPRESSION_OPCODE, Link, EXPRESSION_OPCODE_SIGNATURE)
201 #define FORM_EXPRESSION_SIGNATURE SIGNATURE_32 ('F', 'E', 'X', 'P')
207 UINT8 Type
; // Type for this expression
209 UINT8 RuleId
; // For EFI_IFR_RULE only
210 EFI_STRING_ID Error
; // For EFI_IFR_NO_SUBMIT_IF, EFI_IFR_INCONSISTENT_IF only
212 EFI_HII_VALUE Result
; // Expression evaluation result
213 UINT8 TimeOut
; // For EFI_IFR_WARNING_IF
215 LIST_ENTRY OpCodeListHead
; // OpCodes consist of this expression (EXPRESSION_OPCODE)
218 #define FORM_EXPRESSION_FROM_LINK(a) CR (a, FORM_EXPRESSION, Link, FORM_EXPRESSION_SIGNATURE)
220 #define QUESTION_DEFAULT_SIGNATURE SIGNATURE_32 ('Q', 'D', 'F', 'T')
227 EFI_HII_VALUE Value
; // Default value
229 FORM_EXPRESSION
*ValueExpression
; // Not-NULL indicates default value is provided by EFI_IFR_VALUE
232 #define QUESTION_DEFAULT_FROM_LINK(a) CR (a, QUESTION_DEFAULT, Link, QUESTION_DEFAULT_SIGNATURE)
234 #define QUESTION_OPTION_SIGNATURE SIGNATURE_32 ('Q', 'O', 'P', 'T')
244 FORM_EXPRESSION
*SuppressExpression
; // Non-NULL indicates nested inside of SuppressIf
247 #define QUESTION_OPTION_FROM_LINK(a) CR (a, QUESTION_OPTION, Link, QUESTION_OPTION_SIGNATURE)
249 #define FORM_BROWSER_STATEMENT_SIGNATURE SIGNATURE_32 ('F', 'S', 'T', 'A')
251 struct _FORM_BROWSER_STATEMENT
{
254 UINT8 Operand
; // The operand (first byte) of this Statement or Question
259 UINT8 Type
; // Storage type
260 BOOLEAN NewEfiVarstore
; //EfiVarStore for UEFI 2.31 or not
261 UINT32 Attributes
; // For EFI_IFR_VARSTORE_EFI: EFI Variable attribute
262 BOOLEAN QuestionReferToBitField
;// Whether the question is stored in a bit field.
266 EFI_STRING_ID Prompt
;
268 EFI_STRING_ID TextTwo
; // For EFI_IFR_TEXT
273 EFI_QUESTION_ID QuestionId
; // The value of zero is reserved
274 EFI_VARSTORE_ID VarStoreId
; // A value of zero indicates no variable storage
275 FORMSET_STORAGE
*Storage
;
276 VAR_STORE_INFO VarStoreInfo
;
278 UINT16 BitStorageWidth
;
281 CHAR16
*VariableName
; // Name/Value or EFI Variable name
283 EFI_HII_VALUE HiiValue
; // Edit copy for checkbox, numberic, oneof
284 UINT8
*BufferValue
; // Edit copy for string, password, orderedlist
285 UINT8 ValueType
; // Data type for orderedlist value array
288 // OpCode specific members
290 UINT8 Flags
; // for EFI_IFR_CHECKBOX, EFI_IFR_DATE, EFI_IFR_NUMERIC, EFI_IFR_ONE_OF,
291 // EFI_IFR_ORDERED_LIST, EFI_IFR_STRING,EFI_IFR_SUBTITLE,EFI_IFR_TIME, EFI_IFR_BANNER
292 UINT8 MaxContainers
; // for EFI_IFR_ORDERED_LIST
294 UINT16 BannerLineNumber
; // for EFI_IFR_BANNER, 1-based line number
296 UINT64 Minimum
; // for EFI_IFR_ONE_OF/EFI_IFR_NUMERIC, it's Min/Max value
297 UINT64 Maximum
; // for EFI_IFR_STRING/EFI_IFR_PASSWORD, it's Min/Max length
300 EFI_DEFAULT_ID DefaultId
; // for EFI_IFR_RESET_BUTTON
301 EFI_GUID RefreshGuid
; // for EFI_IFR_REFRESH_ID
304 // Get from IFR parsing
306 FORM_EXPRESSION
*ValueExpression
; // nested EFI_IFR_VALUE, provide Question value and indicate Question is ReadOnly
307 LIST_ENTRY DefaultListHead
; // nested EFI_IFR_DEFAULT list (QUESTION_DEFAULT), provide default values
308 LIST_ENTRY OptionListHead
; // nested EFI_IFR_ONE_OF_OPTION list (QUESTION_OPTION)
310 EFI_IMAGE_ID ImageId
; // nested EFI_IFR_IMAGE
311 UINT8 RefreshInterval
; // nested EFI_IFR_REFRESH, refresh interval(in seconds) for Question value, 0 means no refresh
312 BOOLEAN InSubtitle
; // nesting inside of EFI_IFR_SUBTITLE
314 LIST_ENTRY InconsistentListHead
;// nested inconsistent expression list (FORM_EXPRESSION)
315 LIST_ENTRY NoSubmitListHead
; // nested nosubmit expression list (FORM_EXPRESSION)
316 LIST_ENTRY WarningListHead
; // nested warning expression list (FORM_EXPRESSION)
317 FORM_EXPRESSION
*GrayOutExpression
; // nesting inside of GrayOutIf
318 FORM_EXPRESSION
*SuppressExpression
; // nesting inside of SuppressIf
319 FORM_EXPRESSION
*DisableExpression
; // nesting inside of DisableIf
321 FORM_EXPRESSION
*ReadExpression
; // nested EFI_IFR_READ, provide this question value by read expression.
322 FORM_EXPRESSION
*WriteExpression
; // nested EFI_IFR_WRITE, evaluate write expression after this question value is set.
325 #define FORM_BROWSER_STATEMENT_FROM_LINK(a) CR (a, FORM_BROWSER_STATEMENT, Link, FORM_BROWSER_STATEMENT_SIGNATURE)
327 #define FORM_BROWSER_FORM_SIGNATURE SIGNATURE_32 ('F', 'F', 'R', 'M')
328 #define STANDARD_MAP_FORM_TYPE 0x01
334 UINT16 FormId
; // FormId of normal form or formmap form.
335 EFI_STRING_ID FormTitle
; // FormTile of normal form, or FormMapMethod title of formmap form.
336 UINT16 FormType
; // Specific form type for the different form.
338 BOOLEAN ModalForm
; // Whether this is a modal form.
339 LIST_ENTRY ExpressionListHead
; // List of Expressions (FORM_EXPRESSION)
340 LIST_ENTRY StatementListHead
; // List of Statements and Questions (FORM_BROWSER_STATEMENT)
341 FORM_EXPRESSION
*SuppressExpression
; // nesting inside of SuppressIf
344 #define FORM_BROWSER_FORM_FROM_LINK(a) CR (a, FORM_BROWSER_FORM, Link, FORM_BROWSER_FORM_SIGNATURE)
346 #define FORMSET_DEFAULTSTORE_SIGNATURE SIGNATURE_32 ('F', 'D', 'F', 'S')
353 EFI_STRING_ID DefaultName
;
354 } FORMSET_DEFAULTSTORE
;
356 #define STRING_NUMBER 100
359 EFI_STRING_ID StringId
;
364 EFI_STRING_ID CachedIdNum
;
365 EFI_STRING_ID MaxIdNum
;
366 STRING_INFO
*StringInfoList
;
367 } FORMSET_STRING_LIST
;
369 #define FORMSET_DEFAULTSTORE_FROM_LINK(a) CR (a, FORMSET_DEFAULTSTORE, Link, FORMSET_DEFAULTSTORE_SIGNATURE)
371 #define FORM_BROWSER_FORMSET_SIGNATURE SIGNATURE_32 ('F', 'B', 'F', 'S')
379 UINTN IfrBinaryLength
;
380 UINT8
*IfrBinaryData
;
381 UINT8
*UnicodeBinary
;
384 EFI_STRING_ID FormSetTitle
;
386 UINT8 NumberOfClassGuid
;
387 EFI_GUID ClassGuid
[3]; // Up to three ClassGuid
388 UINT16 Class
; // Tiano extended Class code
389 UINT16 SubClass
; // Tiano extended Subclass code
391 FORM_BROWSER_STATEMENT
*StatementBuffer
; // Buffer for all Statements and Questions
392 EXPRESSION_OPCODE
*ExpressionBuffer
; // Buffer for all Expression OpCode
394 LIST_ENTRY
*StorageListHead
; // Storage list (FORMSET_STORAGE)
395 LIST_ENTRY DefaultStoreListHead
; // DefaultStore list (FORMSET_DEFAULTSTORE)
396 LIST_ENTRY FormListHead
; // Form list (FORM_BROWSER_FORM)
397 LIST_ENTRY ExpressionListHead
; // List of Expressions (FORM_EXPRESSION)
398 FORMSET_STRING_LIST EnUsStringList
; // Cache EN_US English list
399 FORMSET_STRING_LIST UqiStringList
; // Cache EN_US English list
400 } FORM_BROWSER_FORMSET
;
402 #define FORM_BROWSER_FORMSET_FROM_LINK(a) CR (a, FORM_BROWSER_FORMSET, Link, FORM_BROWSER_FORMSET_SIGNATURE)
405 /// Structure for multi-platform support
408 UINT16 DefaultId
[MAX_PLATFORM_DEFAULT_ID_NUM
];
410 UINT64 PlatformId
[MAX_PLATFORM_DEFAULT_ID_NUM
];
411 UINT16 PlatformIdNum
;
412 UINT16 KeyDefaultId
[MAX_PLATFORM_DEFAULT_ID_NUM
];
413 UINT64 KeyPlatformId
[MAX_PLATFORM_DEFAULT_ID_NUM
];
415 FORM_BROWSER_STATEMENT PlatformIdQuestion
;
416 FORM_BROWSER_STATEMENT
*Question
;
417 UINT16 PlatformIdWidth
;
419 BOOLEAN MultiPlatformOrNot
;
420 BOOLEAN ExistStorageFfsInBfv
;
421 BOOLEAN SizeOptimized
;
422 BOOLEAN SizeOptimizedParam
;
423 } MULTI_PLATFORM_PARAMETERS
;
426 Search the variable list according to the variable Guid and name, and return the pointer
429 @param HiiObjList The pointer to the Question
430 @param VarName The EFI variable name need to be updated to VarList
431 @param Offset The offset of the variable
432 @param StorageListHead The pointer to the LIST_ENTRY of Storage
433 @param Vaue The value in that value offset of the variable
434 @param VarList The dual pointer of Varlist
440 IN FORM_BROWSER_STATEMENT
*Question
,
443 IN LIST_ENTRY
*StorageListHead
,
444 IN OUT CHAR8
**Value
,
445 IN OUT FORMSET_STORAGE
**VarList
449 Get the string based on the StringId and HII Package List Handle.
451 @param Token The String's ID.
452 @param HiiHandle The package list in the HII database to search for
453 the specified string.
455 @return The output string.
460 IN EFI_STRING_ID Token
,
465 Free resources allocated for all Storage in an LIST_ENTRY.
467 @param FormSet Pointer of the FormSet
472 IN LIST_ENTRY
*StorageEntryListHead
477 Free resources allocated for a FormSet.
479 @param FormSet Pointer of the FormSet
484 IN FORM_BROWSER_FORMSET
*FormSet
489 Free resources allocated for all FormSet in an LIST_ENTRY.
491 @param FormSet Pointer of the FormSet
496 IN LIST_ENTRY
*FormSetEntryListHead
500 Parse opcodes in the formset IFR binary.
502 @param FormSet Pointer of the FormSet data structure.
504 @retval EFI_SUCCESS Opcode parse success.
505 @retval Other Opcode parse fail.
510 IN FORM_BROWSER_FORMSET
*FormSet
514 Set the value to the variable of platformId question.
516 @param PlatformId The form set.
518 @retval EFI_SUCCESS Set successfully.
522 AssignThePlatformId (
528 Reset Questions to their default value in a Form, Formset or System.
530 @param FormSet FormSet data structure.
531 @param Form Form data structure.
532 @param DefaultId The default Id
533 @param PlatformId The platform Id
534 @param SettingScope Setting Scope for Default action.
536 @retval EFI_SUCCESS The function completed successfully.
537 @retval EFI_UNSUPPORTED Unsupport SettingScope.
542 IN FORM_BROWSER_FORMSET
*FormSet
,
543 IN FORM_BROWSER_FORM
*Form
,
545 IN UINT64 PlatformId
,
546 IN BROWSER_SETTING_SCOPE SettingScope
551 Reset stack pointer to begin of the stack.
555 ResetCurrentExpressionStack (
561 Push current expression onto the Stack
563 @param Pointer Pointer to current expression.
565 @retval EFI_SUCCESS The value was pushed onto the stack.
566 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
570 PushCurrentExpression (
576 Pop current expression from the Stack
578 @param Pointer Pointer to current expression to be pop.
580 @retval EFI_SUCCESS The value was pushed onto the stack.
581 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
585 PopCurrentExpression (
590 Reset stack pointer to begin of the stack.
594 ResetMapExpressionListStack (
600 Push the list of map expression onto the Stack
602 @param Pointer Pointer to the list of map expression to be pushed.
604 @retval EFI_SUCCESS The value was pushed onto the stack.
605 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
609 PushMapExpressionList (
615 Pop the list of map expression from the Stack
617 @param Pointer Pointer to the list of map expression to be pop.
619 @retval EFI_SUCCESS The value was pushed onto the stack.
620 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
624 PopMapExpressionList (
629 Reset stack pointer to begin of the stack.
639 Push an Operand onto the Stack
641 @param Operand Operand to push.
643 @retval EFI_SUCCESS The value was pushed onto the stack.
644 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
655 Pop an Operand from the Stack
657 @param Operand Operand to pop.
659 @retval EFI_SUCCESS The value was pushed onto the stack.
660 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
671 Zero extend integer/boolean/date/time to UINT64 for comparing.
673 @param Value HII Value to be converted.
678 IN EFI_HII_VALUE
*Value
683 Compare two Hii value.
685 @param Value1 Expression value to compare on left-hand.
686 @param Value2 Expression value to compare on right-hand.
688 @retval EFI_INVALID_PARAMETER Could not perform compare on two values.
689 @retval 0 Two operators equal.
690 @return Positive value if Value1 is greater than Value2.
691 @retval Negative value if Value1 is less than Value2.
696 IN EFI_HII_VALUE
*Value1
,
697 IN EFI_HII_VALUE
*Value2
,
698 IN FORM_BROWSER_FORMSET
*FormSet
702 Evaluate the result of a HII expression.
704 If Expression is NULL, then ASSERT.
706 @param FormSet FormSet associated with this expression.
707 @param Form Form associated with this expression.
708 @param Expression Expression to be evaluated.
709 @param ConstantExpression The pointer to the flag of constant expression. If constant, will return TRUE.
711 @retval EFI_SUCCESS The expression evaluated successfuly
712 @retval EFI_NOT_FOUND The Question which referenced by a QuestionId
714 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
716 @retval EFI_ACCESS_DENIED The pop operation underflowed the stack
717 @retval EFI_INVALID_PARAMETER Syntax error with the Expression
722 IN FORM_BROWSER_FORMSET
*FormSet
,
723 IN FORM_BROWSER_FORM
*Form
,
724 IN OUT FORM_EXPRESSION
*Expression
,
725 IN OUT BOOLEAN
*ConstantExpression
729 Compare two Uqi parameters
731 @param UqiParm1 The pointer to the first Uqi parameter.
732 @param UqiParm2 The pointer to the second Uqi parameter.
734 @retval TRUE If these two Uqi parameters are the same, return TRUE;
735 @return FALSE Otherwise, return FALSE;
739 IN CONST UQI_HEADER
*UqiParm1
,
740 IN CONST UQI_HEADER
*UqiParm2
745 Print all ONE_OF ORDER_LIST NUMERIC STRING and CHECKBOX in all fromsets.
747 @param Formset The pointer to the entry of the fromset list
748 @param Formset The pointer to the entry of the storage list
750 @retval EFI_SUCCESS It was complete successfully
751 @return EFI_ABORTED An error occurred
754 PrintInfoInAllFormset (
755 IN LIST_ENTRY
*FormSetEntryListHead
,
756 IN LIST_ENTRY
*StorageEntryListHead
760 Get the question value with bit field from the buffer.
762 @param Question The question refer to bit field.
763 @param Buffer The buffer which the question value get from.
764 @param Value Retun the value.
768 GetBitsQuestionValue(
769 IN FORM_BROWSER_STATEMENT
*Question
,
775 Set the question value with bit field to the buffer.
777 @param Question The question refer to bit field.
778 @param Buffer The buffer which the question value set to.
779 @param Value The value need to set.
783 SetBitsQuestionValue (
784 IN FORM_BROWSER_STATEMENT
*Question
,