]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkIfrSupportLib/IfrOpCodeCreation.c
a467e099a731be5fb35306c131e44faf140968ec
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkIfrSupportLib / IfrOpCodeCreation.c
1 /** @file
2 Library Routines to create IFR independent of string data - assume tokens already exist
3 Primarily to be used for exporting op-codes at a label in pre-defined forms.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14
15 **/
16
17 #include "IfrSupportLibInternal.h"
18
19 /**
20 Create a SubTitle opcode independent of string creation
21 This is used primarily by users who need to create just one particular valid op-code and the string
22 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
23 location to pre-defined forms in HII)
24
25 @param StringToken StringToken of the subtitle
26 @param FormBuffer Output of subtitle as a form
27
28 @retval EFI_SUCCESS Subtitle created to be a form
29 **/
30 EFI_STATUS
31 CreateSubTitleOpCode (
32 IN STRING_REF StringToken,
33 IN OUT VOID *FormBuffer
34 )
35 {
36 FRAMEWORK_EFI_IFR_SUBTITLE Subtitle;
37
38 Subtitle.Header.OpCode = FRAMEWORK_EFI_IFR_SUBTITLE_OP;
39 Subtitle.Header.Length = sizeof (FRAMEWORK_EFI_IFR_SUBTITLE);
40 Subtitle.SubTitle = StringToken;
41
42 CopyMem (FormBuffer, &Subtitle, sizeof (FRAMEWORK_EFI_IFR_SUBTITLE));
43 return EFI_SUCCESS;
44 }
45
46 /**
47 Create a Text opcode independent of string creation
48 This is used primarily by users who need to create just one particular valid op-code and the string
49 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
50 location to pre-defined forms in HII)
51
52 @param StringToken - First string token of the text
53 @param StringTokenTwo - Second string token of the text
54 @param StringTokenThree - Help string token of the text
55 @param Flags - Flag of the text
56 @param Key - Key of the text
57 @param FormBuffer - Output of text as a form
58
59 @retval EFI_SUCCESS - Text created to be a form
60 **/
61 EFI_STATUS
62 CreateTextOpCode (
63 IN STRING_REF StringToken,
64 IN STRING_REF StringTokenTwo,
65 IN STRING_REF StringTokenThree,
66 IN UINT8 Flags,
67 IN UINT16 Key,
68 IN OUT VOID *FormBuffer
69 )
70 {
71 FRAMEWORK_EFI_IFR_TEXT Text;
72
73 Text.Header.OpCode = FRAMEWORK_EFI_IFR_TEXT_OP;
74 Text.Header.Length = sizeof (FRAMEWORK_EFI_IFR_TEXT);
75 Text.Text = StringToken;
76
77 Text.TextTwo = StringTokenTwo;
78 Text.Help = StringTokenThree;
79 Text.Flags = Flags;
80 Text.Key = Key;
81
82 CopyMem (FormBuffer, &Text, sizeof (FRAMEWORK_EFI_IFR_TEXT));
83
84 return EFI_SUCCESS;
85 }
86
87 /**
88 Create a hyperlink opcode independent of string creation
89 This is used primarily by users who need to create just one particular valid op-code and the string
90 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
91 location to pre-defined forms in HII)
92
93
94 @param FormId - Form ID of the hyperlink
95 @param StringToken - Prompt string token of the hyperlink
96 @param StringTokenTwo - Help string token of the hyperlink
97 @param Flags - Flags of the hyperlink
98 @param Key - Key of the hyperlink
99 @param FormBuffer - Output of hyperlink as a form
100 @retval EFI_SUCCESS - Hyperlink created to be a form
101 --*/
102 EFI_STATUS
103 CreateGotoOpCode (
104 IN UINT16 FormId,
105 IN STRING_REF StringToken,
106 IN STRING_REF StringTokenTwo,
107 IN UINT8 Flags,
108 IN UINT16 Key,
109 IN OUT VOID *FormBuffer
110 )
111
112 {
113 FRAMEWORK_EFI_IFR_REF Hyperlink;
114
115 Hyperlink.Header.OpCode = FRAMEWORK_EFI_IFR_REF_OP;
116 Hyperlink.Header.Length = sizeof (FRAMEWORK_EFI_IFR_REF);
117 Hyperlink.FormId = FormId;
118 Hyperlink.Prompt = StringToken;
119 Hyperlink.Help = StringTokenTwo;
120 Hyperlink.Key = Key;
121 Hyperlink.Flags = Flags;
122
123 CopyMem (FormBuffer, &Hyperlink, sizeof (FRAMEWORK_EFI_IFR_REF));
124
125 return EFI_SUCCESS;
126 }
127
128 /**
129 Create a one-of opcode with a set of option op-codes to choose from independent of string creation.
130 This is used primarily by users who need to create just one particular valid op-code and the string
131 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
132 location to pre-defined forms in HII)
133
134 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
135 has been filled in since this routine will not generate StringToken values.
136
137 @param QuestionId - Question ID of the one-of box
138 @param DataWidth - DataWidth of the one-of box
139 @param PromptToken - Prompt string token of the one-of box
140 @param HelpToken - Help string token of the one-of box
141 @param OptionsList - Each string in it is an option of the one-of box
142 @param OptionCount - Option string count
143 @param FormBuffer - Output of One-Of box as a form
144
145
146 @retval EFI_SUCCESS - One-Of box created to be a form
147 @retval EFI_DEVICE_ERROR - DataWidth > 2
148 **/
149 EFI_STATUS
150 CreateOneOfOpCode (
151 IN UINT16 QuestionId,
152 IN UINT8 DataWidth,
153 IN STRING_REF PromptToken,
154 IN STRING_REF HelpToken,
155 IN IFR_OPTION *OptionsList,
156 IN UINTN OptionCount,
157 IN OUT VOID *FormBuffer
158 )
159 {
160 UINTN Index;
161 FRAMEWORK_EFI_IFR_ONE_OF OneOf;
162 FRAMEWORK_EFI_IFR_ONE_OF_OPTION OneOfOption;
163 FRAMEWORK_EFI_IFR_END_ONE_OF EndOneOf;
164 UINT8 *LocalBuffer;
165
166 //
167 // We do not create op-code storage widths for one-of in excess of 16 bits for now
168 //
169 if (DataWidth > 2) {
170 return EFI_DEVICE_ERROR;
171 }
172
173 OneOf.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OP;
174 OneOf.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF);
175 OneOf.QuestionId = QuestionId;
176 OneOf.Width = DataWidth;
177 OneOf.Prompt = PromptToken;
178
179 OneOf.Help = HelpToken;
180
181 LocalBuffer = (UINT8 *) FormBuffer;
182
183 CopyMem (LocalBuffer, &OneOf, sizeof (FRAMEWORK_EFI_IFR_ONE_OF));
184
185 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ONE_OF));
186
187 for (Index = 0; Index < OptionCount; Index++) {
188 OneOfOption.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP;
189 OneOfOption.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION);
190
191 OneOfOption.Option = OptionsList[Index].StringToken;
192 OneOfOption.Value = OptionsList[Index].Value;
193 OneOfOption.Flags = OptionsList[Index].Flags;
194 OneOfOption.Key = OptionsList[Index].Key;
195
196 CopyMem (LocalBuffer, &OneOfOption, sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
197
198 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
199 }
200
201 EndOneOf.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF);
202 EndOneOf.Header.OpCode = FRAMEWORK_EFI_IFR_END_ONE_OF_OP;
203
204 CopyMem (LocalBuffer, &EndOneOf, sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
205
206 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
207
208 return EFI_SUCCESS;
209 }
210
211 /**
212 Create a ordered list opcode with a set of option op-codes to choose from independent of string creation.
213 This is used primarily by users who need to create just one particular valid op-code and the string
214 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
215 location to pre-defined forms in HII)
216
217 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
218 has been filled in since this routine will not generate StringToken values.
219
220 @param QuestionId - Question ID of the ordered list
221 @param MaxEntries - MaxEntries of the ordered list
222 @param PromptToken - Prompt string token of the ordered list
223 @param HelpToken - Help string token of the ordered list
224 @param OptionsList - Each string in it is an option of the ordered list
225 @param OptionCount - Option string count
226 @param FormBuffer - Output of ordered list as a form
227
228 @retval EFI_SUCCESS - Ordered list created to be a form
229 **/
230 EFI_STATUS
231 CreateOrderedListOpCode (
232 IN UINT16 QuestionId,
233 IN UINT8 MaxEntries,
234 IN STRING_REF PromptToken,
235 IN STRING_REF HelpToken,
236 IN IFR_OPTION *OptionsList,
237 IN UINTN OptionCount,
238 IN OUT VOID *FormBuffer
239 )
240 {
241 UINTN Index;
242 FRAMEWORK_EFI_IFR_ORDERED_LIST OrderedList;
243 FRAMEWORK_EFI_IFR_ONE_OF_OPTION OrderedListOption;
244 FRAMEWORK_EFI_IFR_END_ONE_OF EndOrderedList;
245 UINT8 *LocalBuffer;
246
247 OrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_ORDERED_LIST_OP;
248 OrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST);
249 OrderedList.QuestionId = QuestionId;
250 OrderedList.MaxEntries = MaxEntries;
251 OrderedList.Prompt = PromptToken;
252
253 OrderedList.Help = HelpToken;
254
255 LocalBuffer = (UINT8 *) FormBuffer;
256
257 CopyMem (LocalBuffer, &OrderedList, sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST));
258
259 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST));
260
261 for (Index = 0; Index < OptionCount; Index++) {
262 OrderedListOption.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP;
263 OrderedListOption.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION);
264
265 OrderedListOption.Option = OptionsList[Index].StringToken;
266 OrderedListOption.Value = OptionsList[Index].Value;
267 OrderedListOption.Flags = OptionsList[Index].Flags;
268 OrderedListOption.Key = OptionsList[Index].Key;
269
270 CopyMem (LocalBuffer, &OrderedListOption, sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
271
272 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
273 }
274
275 EndOrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF);
276 EndOrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_END_ONE_OF_OP;
277
278 CopyMem (LocalBuffer, &EndOrderedList, sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
279
280 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
281
282 return EFI_SUCCESS;
283 }
284
285 /**
286 Create a checkbox opcode independent of string creation
287 This is used primarily by users who need to create just one particular valid op-code and the string
288 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
289 location to pre-defined forms in HII)
290
291 @param QuestionId - Question ID of the check box
292 @param DataWidth - DataWidth of the check box
293 @param PromptToken - Prompt string token of the check box
294 @param HelpToken - Help string token of the check box
295 @param Flags - Flags of the check box
296 @param Key - Key of the check box
297 @param FormBuffer - Output of the check box as a form
298
299 @retval EFI_SUCCESS - Checkbox created to be a form
300 @retval EFI_DEVICE_ERROR - DataWidth > 1
301 **/
302 EFI_STATUS
303 CreateCheckBoxOpCode (
304 IN UINT16 QuestionId,
305 IN UINT8 DataWidth,
306 IN STRING_REF PromptToken,
307 IN STRING_REF HelpToken,
308 IN UINT8 Flags,
309 IN UINT16 Key,
310 IN OUT VOID *FormBuffer
311 )
312
313 {
314 FRAMEWORK_EFI_IFR_CHECKBOX CheckBox;
315
316 //
317 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
318 //
319 if (DataWidth > 1) {
320 return EFI_DEVICE_ERROR;
321 }
322
323 CheckBox.Header.OpCode = FRAMEWORK_EFI_IFR_CHECKBOX_OP;
324 CheckBox.Header.Length = sizeof (FRAMEWORK_EFI_IFR_CHECKBOX);
325 CheckBox.QuestionId = QuestionId;
326 CheckBox.Width = DataWidth;
327 CheckBox.Prompt = PromptToken;
328
329 CheckBox.Help = HelpToken;
330 CheckBox.Flags = Flags;
331 CheckBox.Key = Key;
332
333 CopyMem (FormBuffer, &CheckBox, sizeof (FRAMEWORK_EFI_IFR_CHECKBOX));
334
335 return EFI_SUCCESS;
336 }
337
338 /**
339 Create a numeric opcode independent of string creation
340 This is used primarily by users who need to create just one particular valid op-code and the string
341 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
342 location to pre-defined forms in HII)
343
344 @param QuestionId - Question ID of the numeric
345 @param DataWidth - DataWidth of the numeric
346 @param PromptToken - Prompt string token of the numeric
347 @param HelpToken - Help string token of the numeric
348 @param Minimum - Minumun boundary of the numeric
349 @param Maximum - Maximum boundary of the numeric
350 @param Step - Step of the numeric
351 @param Default - Default value of the numeric
352 @param Flags - Flags of the numeric
353 @param Key - Key of the numeric
354 @param FormBuffer - Output of the numeric as a form
355
356
357 @retval EFI_SUCCESS - The numeric created to be a form.
358 @retval EFI_DEVICE_ERROR - DataWidth > 2
359 **/
360 EFI_STATUS
361 CreateNumericOpCode (
362 IN UINT16 QuestionId,
363 IN UINT8 DataWidth,
364 IN STRING_REF PromptToken,
365 IN STRING_REF HelpToken,
366 IN UINT16 Minimum,
367 IN UINT16 Maximum,
368 IN UINT16 Step,
369 IN UINT16 Default,
370 IN UINT8 Flags,
371 IN UINT16 Key,
372 IN OUT VOID *FormBuffer
373 )
374
375 {
376 FRAMEWORK_EFI_IFR_NUMERIC Numeric;
377
378 //
379 // We do not create op-code storage widths for numerics in excess of 16 bits for now
380 //
381 if (DataWidth > 2) {
382 return EFI_DEVICE_ERROR;
383 }
384
385 Numeric.Header.OpCode = FRAMEWORK_EFI_IFR_NUMERIC_OP;
386 Numeric.Header.Length = sizeof (FRAMEWORK_EFI_IFR_NUMERIC);
387 Numeric.QuestionId = QuestionId;
388 Numeric.Width = DataWidth;
389 Numeric.Prompt = PromptToken;
390
391 Numeric.Help = HelpToken;
392 Numeric.Minimum = Minimum;
393 Numeric.Maximum = Maximum;
394 Numeric.Step = Step;
395 Numeric.Default = Default;
396 Numeric.Flags = Flags;
397 Numeric.Key = Key;
398
399 CopyMem (FormBuffer, &Numeric, sizeof (FRAMEWORK_EFI_IFR_NUMERIC));
400
401 return EFI_SUCCESS;
402 }
403
404 /**
405 Create a numeric opcode independent of string creation
406 This is used primarily by users who need to create just one particular valid op-code and the string
407 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
408 location to pre-defined forms in HII)
409
410 @param QuestionId Question ID of the string
411 @param DataWidth DataWidth of the string
412 @param PromptToken Prompt token of the string
413 @param HelpToken Help token of the string
414 @param MinSize Min size boundary of the string
415 @param MaxSize Max size boundary of the string
416 @param Flags Flags of the string
417 @param Key Key of the string
418 @param FormBuffer Output of the string as a form
419
420 @retval EFI_SUCCESS String created to be a form.
421 **/
422 EFI_STATUS
423 CreateStringOpCode (
424 IN UINT16 QuestionId,
425 IN UINT8 DataWidth,
426 IN STRING_REF PromptToken,
427 IN STRING_REF HelpToken,
428 IN UINT8 MinSize,
429 IN UINT8 MaxSize,
430 IN UINT8 Flags,
431 IN UINT16 Key,
432 IN OUT VOID *FormBuffer
433 )
434
435 {
436 FRAMEWORK_EFI_IFR_STRING String;
437
438 String.Header.OpCode = FRAMEWORK_EFI_IFR_STRING_OP;
439 String.Header.Length = sizeof (FRAMEWORK_EFI_IFR_STRING);
440 String.QuestionId = QuestionId;
441 String.Width = DataWidth;
442 String.Prompt = PromptToken;
443
444 String.Help = HelpToken;
445 String.MinSize = MinSize;
446 String.MaxSize = MaxSize;
447 String.Flags = Flags;
448 String.Key = Key;
449
450 CopyMem (FormBuffer, &String, sizeof (FRAMEWORK_EFI_IFR_STRING));
451
452 return EFI_SUCCESS;
453 }
454
455 /**
456 Create a banner opcode. This is primarily used by the FrontPage implementation from BDS.
457
458 @param Title - Title of the banner
459 @param LineNumber - LineNumber of the banner
460 @param Alignment - Alignment of the banner
461 @param FormBuffer - Output of banner as a form
462
463 @retval EFI_SUCCESS - Banner created to be a form.
464 **/
465 EFI_STATUS
466 CreateBannerOpCode (
467 IN UINT16 Title,
468 IN UINT16 LineNumber,
469 IN UINT8 Alignment,
470 IN OUT VOID *FormBuffer
471 )
472
473 {
474 FRAMEWORK_EFI_IFR_BANNER Banner;
475
476 Banner.Header.OpCode = FRAMEWORK_EFI_IFR_BANNER_OP;
477 Banner.Header.Length = sizeof (FRAMEWORK_EFI_IFR_BANNER);
478 CopyMem (&Banner.Title, &Title, sizeof (UINT16));
479 CopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16));
480 Banner.Alignment = Alignment;
481
482 CopyMem (FormBuffer, &Banner, sizeof (FRAMEWORK_EFI_IFR_BANNER));
483
484 return EFI_SUCCESS;
485 }
486
487