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