• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Function and Macro defintions for IFR parsing. To get the default value from IFR package, the IFR
3   opcode needs to be parsed. Most of code is taken from MdeModulePkg\Universal\SetupBrowserDxe\IfrParse.c.
4   This parser is simplified from the origianl IfrParser.c in the following way:
5 
6   1) All data structure definition that have nothing to do with IFR Default value scanning (
7      required to implement Framework HII's GetDefaultImage ()) is removed.
8   2) Ignore the IFR opcode which is invalid for Form Package
9      generated using Framework VFR file.
10 
11   Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
12   This program and the accompanying materials
13   are licensed and made available under the terms and conditions of the BSD License
14   which accompanies this distribution.  The full text of the license may be found at
15   http://opensource.org/licenses/bsd-license.php
16 
17   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 **/
21 
22 #ifndef _HII_THUNK_UEFI_IFR_PARSER_
23 #define _HII_THUNK_UEFI_IFR_PARSER_
24 
25 
26 //
27 // IFR relative definition
28 //
29 #define EFI_HII_EXPRESSION_INCONSISTENT_IF   0
30 #define EFI_HII_EXPRESSION_NO_SUBMIT_IF      1
31 #define EFI_HII_EXPRESSION_GRAY_OUT_IF       2
32 #define EFI_HII_EXPRESSION_SUPPRESS_IF       3
33 #define EFI_HII_EXPRESSION_DISABLE_IF        4
34 #define EFI_HII_EXPRESSION_VALUE             5
35 #define EFI_HII_EXPRESSION_RULE              6
36 
37 #define EFI_HII_VARSTORE_BUFFER              0
38 #define EFI_HII_VARSTORE_NAME_VALUE          1
39 #define EFI_HII_VARSTORE_EFI_VARIABLE        2
40 
41 #define FORM_INCONSISTENT_VALIDATION         0
42 #define FORM_NO_SUBMIT_VALIDATION            1
43 
44 extern EFI_GUID  gTianoHiiIfrGuid;
45 
46 #define ONE_OF_OPTION_MAP_ENTRY_FROM_LINK(Record) CR(Record, ONE_OF_OPTION_MAP_ENTRY, Link, ONE_OF_OPTION_MAP_ENTRY_SIGNATURE)
47 #define ONE_OF_OPTION_MAP_ENTRY_SIGNATURE            SIGNATURE_32 ('O', 'O', 'M', 'E')
48 typedef struct {
49   UINT32              Signature;
50   LIST_ENTRY          Link;
51 
52   UINT16              FwKey;
53   EFI_IFR_TYPE_VALUE  Value;
54 
55 } ONE_OF_OPTION_MAP_ENTRY;
56 
57 
58 
59 #define ONE_OF_OPTION_MAP_FROM_LINK(Record) CR(Record, ONE_OF_OPTION_MAP, Link, ONE_OF_OPTION_MAP_SIGNATURE)
60 #define ONE_OF_OPTION_MAP_SIGNATURE            SIGNATURE_32 ('O', 'O', 'O', 'M')
61 typedef struct {
62   UINT32            Signature;
63   LIST_ENTRY        Link;
64 
65   UINT16            VarStoreId;
66 
67   UINT8             ValueType; //EFI_IFR_TYPE_NUM_*
68 
69   EFI_QUESTION_ID   QuestionId;
70 
71   LIST_ENTRY        OneOfOptionMapEntryListHead; //ONE_OF_OPTION_MAP_ENTRY
72 } ONE_OF_OPTION_MAP;
73 
74 
75 typedef struct {
76   UINT8               Type;
77   EFI_IFR_TYPE_VALUE  Value;
78 } EFI_HII_VALUE;
79 
80 #define NAME_VALUE_NODE_SIGNATURE  SIGNATURE_32 ('N', 'V', 'S', 'T')
81 
82 #define FORMSET_STORAGE_SIGNATURE  SIGNATURE_32 ('F', 'S', 'T', 'G')
83 
84 typedef struct {
85   UINTN            Signature;
86   LIST_ENTRY       Link;
87 
88   UINT8            Type;           // Storage type
89 
90   UINT16           VarStoreId;
91   EFI_GUID         Guid;
92 
93   CHAR16           *Name;          // For EFI_IFR_VARSTORE
94   UINT16           Size;
95 
96   UINT32           Attributes;     // For EFI_IFR_VARSTORE_EFI: EFI Variable attribute
97 
98 } FORMSET_STORAGE;
99 
100 #define FORMSET_STORAGE_FROM_LINK(a)  CR (a, FORMSET_STORAGE, Link, FORMSET_STORAGE_SIGNATURE)
101 
102 #if 0
103 
104 #define EXPRESSION_OPCODE_SIGNATURE  SIGNATURE_32 ('E', 'X', 'O', 'P')
105 
106 typedef struct {
107   UINTN             Signature;
108   LIST_ENTRY        Link;
109 
110   UINT8             Operand;
111 
112   UINT8             Format;      // For EFI_IFR_TO_STRING, EFI_IFR_FIND
113   UINT8             Flags;       // For EFI_IFR_SPAN
114   UINT8             RuleId;      // For EFI_IFR_RULE_REF
115 
116   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
117 
118   EFI_QUESTION_ID   QuestionId;  // For EFI_IFR_EQ_ID_ID, EFI_IFR_EQ_ID_VAL_LIST, EFI_IFR_QUESTION_REF1
119   EFI_QUESTION_ID   QuestionId2;
120 
121   UINT16            ListLength;  // For EFI_IFR_EQ_ID_VAL_LIST
122   UINT16            *ValueList;
123 
124   EFI_STRING_ID     DevicePath;  // For EFI_IFR_QUESTION_REF3_2, EFI_IFR_QUESTION_REF3_3
125   EFI_GUID          Guid;
126 } EXPRESSION_OPCODE;
127 
128 #define EXPRESSION_OPCODE_FROM_LINK(a)  CR (a, EXPRESSION_OPCODE, Link, EXPRESSION_OPCODE_SIGNATURE)
129 
130 #define FORM_EXPRESSION_SIGNATURE  SIGNATURE_32 ('F', 'E', 'X', 'P')
131 
132 typedef struct {
133   UINTN             Signature;
134   LIST_ENTRY        Link;
135 
136   UINT8             Type;            // Type for this expression
137 
138   UINT8             RuleId;          // For EFI_IFR_RULE only
139   EFI_STRING_ID     Error;           // For EFI_IFR_NO_SUBMIT_IF, EFI_IFR_INCONSISTENT_IF only
140 
141   EFI_HII_VALUE     Result;          // Expression evaluation result
142 
143   LIST_ENTRY        OpCodeListHead;  // OpCodes consist of this expression (EXPRESSION_OPCODE)
144 } FORM_EXPRESSION;
145 
146 #define FORM_EXPRESSION_FROM_LINK(a)  CR (a, FORM_EXPRESSION, Link, FORM_EXPRESSION_SIGNATURE)
147 #endif
148 
149 #define QUESTION_DEFAULT_SIGNATURE  SIGNATURE_32 ('Q', 'D', 'F', 'T')
150 
151 typedef struct {
152   UINTN               Signature;
153   LIST_ENTRY          Link;
154 
155   UINT16              DefaultId;
156   EFI_HII_VALUE       Value;              // Default value
157 
158 } QUESTION_DEFAULT;
159 
160 #define QUESTION_DEFAULT_FROM_LINK(a)  CR (a, QUESTION_DEFAULT, Link, QUESTION_DEFAULT_SIGNATURE)
161 
162 #define QUESTION_OPTION_SIGNATURE  SIGNATURE_32 ('Q', 'O', 'P', 'T')
163 
164 typedef struct {
165   UINTN               Signature;
166   LIST_ENTRY          Link;
167 
168   EFI_STRING_ID       Text;
169   UINT8               Flags;
170   EFI_HII_VALUE       Value;
171   EFI_IMAGE_ID        ImageId;
172 
173 } QUESTION_OPTION;
174 
175 #define QUESTION_OPTION_FROM_LINK(a)  CR (a, QUESTION_OPTION, Link, QUESTION_OPTION_SIGNATURE)
176 
177 typedef union {
178   EFI_STRING_ID       VarName;
179   UINT16              VarOffset;
180 } VAR_STORE_INFO;
181 
182 #define FORM_BROWSER_STATEMENT_SIGNATURE  SIGNATURE_32 ('F', 'S', 'T', 'A')
183 typedef struct {
184   UINTN                 Signature;
185   LIST_ENTRY            Link;
186 
187   UINT8                 Operand;          // The operand (first byte) of this Statement or Question
188 
189   //
190   // Statement Header
191   //
192   EFI_STRING_ID         Prompt;
193   EFI_STRING_ID         Help;
194   EFI_STRING_ID         TextTwo;          // For EFI_IFR_TEXT
195 
196   //
197   // Question Header
198   //
199   EFI_QUESTION_ID       QuestionId;       // The value of zero is reserved
200   EFI_VARSTORE_ID       VarStoreId;       // A value of zero indicates no variable storage
201   FORMSET_STORAGE       *Storage;
202   VAR_STORE_INFO        VarStoreInfo;
203 
204   UINT16                StorageWidth;
205   UINT8                 QuestionFlags;
206 
207   EFI_HII_VALUE         HiiValue;         // Edit copy for checkbox, numberic, oneof
208   UINT8                 *BufferValue;     // Edit copy for string, password, orderedlist
209 
210   //
211   // OpCode specific members
212   //
213   UINT8                 Flags;            // for EFI_IFR_CHECKBOX, EFI_IFR_DATE, EFI_IFR_NUMERIC, EFI_IFR_ONE_OF,
214                                           // EFI_IFR_ORDERED_LIST, EFI_IFR_STRING,EFI_IFR_SUBTITLE,EFI_IFR_TIME, EFI_IFR_BANNER
215   UINT8                 MaxContainers;    // for EFI_IFR_ORDERED_LIST
216 
217   UINT16                BannerLineNumber; // for EFI_IFR_BANNER, 1-based line number
218   EFI_STRING_ID         QuestionConfig;   // for EFI_IFR_ACTION, if 0 then no configuration string will be processed
219 
220   UINT64                Minimum;          // for EFI_IFR_ONE_OF/EFI_IFR_NUMERIC, it's Min/Max value
221   UINT64                Maximum;          // for EFI_IFR_STRING/EFI_IFR_PASSWORD, it's Min/Max length
222   UINT64                Step;
223 
224   EFI_DEFAULT_ID        DefaultId;        // for EFI_IFR_RESET_BUTTON
225   EFI_FORM_ID           RefFormId;        // for EFI_IFR_REF
226   EFI_QUESTION_ID       RefQuestionId;    // for EFI_IFR_REF2
227   EFI_GUID              RefFormSetId;     // for EFI_IFR_REF3
228   EFI_STRING_ID         RefDevicePath;    // for EFI_IFR_REF4
229 
230   //
231   // Get from IFR parsing
232   //
233   LIST_ENTRY            DefaultListHead;     // nested EFI_IFR_DEFAULT list (QUESTION_DEFAULT), provide default values
234   LIST_ENTRY            OptionListHead;      // nested EFI_IFR_ONE_OF_OPTION list (QUESTION_OPTION)
235 
236   EFI_IMAGE_ID          ImageId;             // nested EFI_IFR_IMAGE
237   UINT8                 RefreshInterval;     // nested EFI_IFR_REFRESH, refresh interval(in seconds) for Question value, 0 means no refresh
238   BOOLEAN               InSubtitle;          // nesting inside of EFI_IFR_SUBTITLE
239 
240 } FORM_BROWSER_STATEMENT;
241 
242 #define FORM_BROWSER_STATEMENT_FROM_LINK(a)  CR (a, FORM_BROWSER_STATEMENT, Link, FORM_BROWSER_STATEMENT_SIGNATURE)
243 
244 #define FORM_BROWSER_FORM_SIGNATURE  SIGNATURE_32 ('F', 'F', 'R', 'M')
245 
246 typedef struct {
247   UINTN             Signature;
248   LIST_ENTRY        Link;
249 
250   UINT16            FormId;
251   EFI_STRING_ID     FormTitle;
252 
253   EFI_IMAGE_ID      ImageId;
254 
255 #if 0
256   LIST_ENTRY        ExpressionListHead;   // List of Expressions (FORM_EXPRESSION)
257 #endif
258   LIST_ENTRY        StatementListHead;    // List of Statements and Questions (FORM_BROWSER_STATEMENT)
259 } FORM_BROWSER_FORM;
260 
261 #define FORM_BROWSER_FORM_FROM_LINK(a)  CR (a, FORM_BROWSER_FORM, Link, FORM_BROWSER_FORM_SIGNATURE)
262 
263 #define FORMSET_DEFAULTSTORE_SIGNATURE  SIGNATURE_32 ('F', 'D', 'F', 'S')
264 
265 typedef struct {
266   UINTN            Signature;
267   LIST_ENTRY       Link;
268 
269   UINT16           DefaultId;
270   EFI_STRING_ID    DefaultName;
271 } FORMSET_DEFAULTSTORE;
272 
273 #define FORMSET_DEFAULTSTORE_FROM_LINK(a)  CR (a, FORMSET_DEFAULTSTORE, Link, FORMSET_DEFAULTSTORE_SIGNATURE)
274 
275 typedef struct {
276   EFI_HII_HANDLE                  HiiHandle;
277 
278   UINTN                           IfrBinaryLength;
279   UINT8                           *IfrBinaryData;
280 
281   EFI_GUID                        Guid;
282   EFI_STRING_ID                   FormSetTitle;
283   EFI_STRING_ID                   Help;
284   UINT16                          Class;
285   UINT16                          SubClass;
286   EFI_IMAGE_ID                    ImageId;
287 
288   FORM_BROWSER_STATEMENT          *StatementBuffer;     // Buffer for all Statements and Questions
289 #if 0
290   EXPRESSION_OPCODE               *ExpressionBuffer;    // Buffer for all Expression OpCode
291 #endif
292 
293   LIST_ENTRY                      StorageListHead;      // Storage list (FORMSET_STORAGE)
294   LIST_ENTRY                      DefaultStoreListHead; // DefaultStore list (FORMSET_DEFAULTSTORE)
295   LIST_ENTRY                      FormListHead;         // Form list (FORM_BROWSER_FORM)
296 
297   LIST_ENTRY                      OneOfOptionMapListHead; //ONE_OF_OPTION_MAP
298 
299   UINT16                          MaxQuestionId;
300 
301   //
302   // Added for Framework HII Thunk.
303   // Default Variable Storage built from a Framework VFR file using UEFI VFR Compiler in Compatibility mode is determined
304   // by priority rules defined in GetFormsetDefaultVarstoreId (). See the function description for details.
305   //
306   EFI_VARSTORE_ID                 DefaultVarStoreId;
307   CHAR16                          *OriginalDefaultVarStoreName;
308 
309   UINTN                           NumberOfStatement;
310 
311 } FORM_BROWSER_FORMSET;
312 
313 
314 /**
315   Parse opcodes in the formset IFR binary.
316 
317   @param  FormSet                Pointer of the FormSet data structure.
318 
319   @retval EFI_SUCCESS            Opcode parse success.
320   @retval Other                  Opcode parse fail.
321 
322 **/
323 EFI_STATUS
324 ParseOpCodes (
325   IN FORM_BROWSER_FORMSET              *FormSet
326   );
327 
328 /**
329   Free resources allocated for a FormSet
330 
331   @param  FormSet                Pointer of the FormSet
332 
333   @return None.
334 
335 **/
336 VOID
337 DestroyFormSet (
338   IN OUT FORM_BROWSER_FORMSET  *FormSet
339   );
340 
341 #endif
342 
343