]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/IfrSupportLibFramework/IfrOpCodeCreation.c
Rename Frame*Lib to *LibFramework to improve the speed that a module could be found...
[mirror_edk2.git] / IntelFrameworkPkg / Library / IfrSupportLibFramework / IfrOpCodeCreation.c
1 /*++
2 Copyright (c) 2006, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module Name:
12 IfrOpCodeCreation.c
13
14 Abstract:
15
16 Library Routines to create IFR independent of string data - assume tokens already exist
17 Primarily to be used for exporting op-codes at a label in pre-defined forms.
18
19 Revision History:
20
21 --*/
22
23 //
24 // Include common header file for this module.
25 //
26 #include "CommonHeader.h"
27
28 EFI_STATUS
29 CreateSubTitleOpCode (
30 IN STRING_REF StringToken,
31 IN OUT VOID *FormBuffer
32 )
33 /*++
34
35 Routine Description:
36
37 Create a SubTitle opcode independent of string creation
38 This is used primarily by users who need to create just one particular valid op-code and the string
39 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
40 location to pre-defined forms in HII)
41
42 Arguments:
43
44 StringToken - StringToken of the subtitle
45
46 FormBuffer - Output of subtitle as a form
47
48 Returns:
49
50 EFI_SUCCESS - Subtitle created to be a form
51
52 --*/
53 {
54 EFI_IFR_SUBTITLE Subtitle;
55
56 Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;
57 Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);
58 Subtitle.SubTitle = StringToken;
59
60 CopyMem (FormBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE));
61 return EFI_SUCCESS;
62 }
63
64
65 EFI_STATUS
66 CreateTextOpCode (
67 IN STRING_REF StringToken,
68 IN STRING_REF StringTokenTwo,
69 IN STRING_REF StringTokenThree,
70 IN UINT8 Flags,
71 IN UINT16 Key,
72 IN OUT VOID *FormBuffer
73 )
74 /*++
75
76 Routine Description:
77
78 Create a Text opcode independent of string creation
79 This is used primarily by users who need to create just one particular valid op-code and the string
80 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
81 location to pre-defined forms in HII)
82
83 Arguments:
84
85 StringToken - First string token of the text
86
87 StringTokenTwo - Second string token of the text
88
89 StringTokenThree - Help string token of the text
90
91 Flags - Flag of the text
92
93 Key - Key of the text
94
95 FormBuffer - Output of text as a form
96
97 Returns:
98
99 EFI_SUCCESS - Text created to be a form
100
101 --*/
102 {
103 EFI_IFR_TEXT Text;
104
105 Text.Header.OpCode = EFI_IFR_TEXT_OP;
106 Text.Header.Length = sizeof (EFI_IFR_TEXT);
107 Text.Text = StringToken;
108
109 Text.TextTwo = StringTokenTwo;
110 Text.Help = StringTokenThree;
111 Text.Flags = Flags;
112 Text.Key = Key;
113
114 CopyMem (FormBuffer, &Text, sizeof (EFI_IFR_TEXT));
115
116 return EFI_SUCCESS;
117 }
118
119
120 EFI_STATUS
121 CreateGotoOpCode (
122 IN UINT16 FormId,
123 IN STRING_REF StringToken,
124 IN STRING_REF StringTokenTwo,
125 IN UINT8 Flags,
126 IN UINT16 Key,
127 IN OUT VOID *FormBuffer
128 )
129 /*++
130
131 Routine Description:
132
133 Create a hyperlink opcode independent of string creation
134 This is used primarily by users who need to create just one particular valid op-code and the string
135 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
136 location to pre-defined forms in HII)
137
138 Arguments:
139
140 FormId - Form ID of the hyperlink
141
142 StringToken - Prompt string token of the hyperlink
143
144 StringTokenTwo - Help string token of the hyperlink
145
146 Flags - Flags of the hyperlink
147
148 Key - Key of the hyperlink
149
150 FormBuffer - Output of hyperlink as a form
151
152 Returns:
153
154 EFI_SUCCESS - Hyperlink created to be a form
155
156 --*/
157 {
158 EFI_IFR_REF Hyperlink;
159
160 Hyperlink.Header.OpCode = EFI_IFR_REF_OP;
161 Hyperlink.Header.Length = sizeof (EFI_IFR_REF);
162 Hyperlink.FormId = FormId;
163 Hyperlink.Prompt = StringToken;
164 Hyperlink.Help = StringTokenTwo;
165 Hyperlink.Key = Key;
166 Hyperlink.Flags = Flags;
167
168 CopyMem (FormBuffer, &Hyperlink, sizeof (EFI_IFR_REF));
169
170 return EFI_SUCCESS;
171 }
172
173
174 EFI_STATUS
175 CreateOneOfOpCode (
176 IN UINT16 QuestionId,
177 IN UINT8 DataWidth,
178 IN STRING_REF PromptToken,
179 IN STRING_REF HelpToken,
180 IN IFR_OPTION *OptionsList,
181 IN UINTN OptionCount,
182 IN OUT VOID *FormBuffer
183 )
184 /*++
185
186 Routine Description:
187
188 Create a one-of opcode with a set of option op-codes to choose from independent of string creation.
189 This is used primarily by users who need to create just one particular valid op-code and the string
190 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
191 location to pre-defined forms in HII)
192
193 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
194 has been filled in since this routine will not generate StringToken values.
195
196 Arguments:
197
198 QuestionId - Question ID of the one-of box
199
200 DataWidth - DataWidth of the one-of box
201
202 PromptToken - Prompt string token of the one-of box
203
204 HelpToken - Help string token of the one-of box
205
206 OptionsList - Each string in it is an option of the one-of box
207
208 OptionCount - Option string count
209
210 FormBuffer - Output of One-Of box as a form
211
212 Returns:
213
214 EFI_SUCCESS - One-Of box created to be a form
215
216 EFI_DEVICE_ERROR - DataWidth > 2
217
218 --*/
219 {
220 UINTN Index;
221 EFI_IFR_ONE_OF OneOf;
222 EFI_IFR_ONE_OF_OPTION OneOfOption;
223 EFI_IFR_END_ONE_OF EndOneOf;
224 UINT8 *LocalBuffer;
225
226 //
227 // We do not create op-code storage widths for one-of in excess of 16 bits for now
228 //
229 if (DataWidth > 2) {
230 return EFI_DEVICE_ERROR;
231 }
232
233 OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;
234 OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);
235 OneOf.QuestionId = QuestionId;
236 OneOf.Width = DataWidth;
237 OneOf.Prompt = PromptToken;
238
239 OneOf.Help = HelpToken;
240
241 LocalBuffer = (UINT8 *) FormBuffer;
242
243 CopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF));
244
245 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF));
246
247 for (Index = 0; Index < OptionCount; Index++) {
248 OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
249 OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
250
251 OneOfOption.Option = OptionsList[Index].StringToken;
252 OneOfOption.Value = OptionsList[Index].Value;
253 OneOfOption.Flags = OptionsList[Index].Flags;
254 OneOfOption.Key = OptionsList[Index].Key;
255
256 CopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION));
257
258 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));
259 }
260
261 EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
262 EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
263
264 CopyMem (LocalBuffer, &EndOneOf, sizeof (EFI_IFR_END_ONE_OF));
265
266 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));
267
268 return EFI_SUCCESS;
269 }
270
271 EFI_STATUS
272 CreateOrderedListOpCode (
273 IN UINT16 QuestionId,
274 IN UINT8 MaxEntries,
275 IN STRING_REF PromptToken,
276 IN STRING_REF HelpToken,
277 IN IFR_OPTION *OptionsList,
278 IN UINTN OptionCount,
279 IN OUT VOID *FormBuffer
280 )
281 /*++
282
283 Routine Description:
284
285 Create a ordered list opcode with a set of option op-codes to choose from independent of string creation.
286 This is used primarily by users who need to create just one particular valid op-code and the string
287 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
288 location to pre-defined forms in HII)
289
290 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
291 has been filled in since this routine will not generate StringToken values.
292
293 Arguments:
294
295 QuestionId - Question ID of the ordered list
296
297 MaxEntries - MaxEntries of the ordered list
298
299 PromptToken - Prompt string token of the ordered list
300
301 HelpToken - Help string token of the ordered list
302
303 OptionsList - Each string in it is an option of the ordered list
304
305 OptionCount - Option string count
306
307 FormBuffer - Output of ordered list as a form
308
309 Returns:
310
311 EFI_SUCCESS - Ordered list created to be a form
312
313 --*/
314 {
315 UINTN Index;
316 EFI_IFR_ORDERED_LIST OrderedList;
317 EFI_IFR_ONE_OF_OPTION OrderedListOption;
318 EFI_IFR_END_ONE_OF EndOrderedList;
319 UINT8 *LocalBuffer;
320
321 OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;
322 OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);
323 OrderedList.QuestionId = QuestionId;
324 OrderedList.MaxEntries = MaxEntries;
325 OrderedList.Prompt = PromptToken;
326
327 OrderedList.Help = HelpToken;
328
329 LocalBuffer = (UINT8 *) FormBuffer;
330
331 CopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST));
332
333 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ORDERED_LIST));
334
335 for (Index = 0; Index < OptionCount; Index++) {
336 OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
337 OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
338
339 OrderedListOption.Option = OptionsList[Index].StringToken;
340 OrderedListOption.Value = OptionsList[Index].Value;
341 OrderedListOption.Flags = OptionsList[Index].Flags;
342 OrderedListOption.Key = OptionsList[Index].Key;
343
344 CopyMem (LocalBuffer, &OrderedListOption, sizeof (EFI_IFR_ONE_OF_OPTION));
345
346 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));
347 }
348
349 EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
350 EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
351
352 CopyMem (LocalBuffer, &EndOrderedList, sizeof (EFI_IFR_END_ONE_OF));
353
354 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));
355
356 return EFI_SUCCESS;
357 }
358
359 EFI_STATUS
360 CreateCheckBoxOpCode (
361 IN UINT16 QuestionId,
362 IN UINT8 DataWidth,
363 IN STRING_REF PromptToken,
364 IN STRING_REF HelpToken,
365 IN UINT8 Flags,
366 IN UINT16 Key,
367 IN OUT VOID *FormBuffer
368 )
369 /*++
370
371 Routine Description:
372
373 Create a checkbox opcode independent of string creation
374 This is used primarily by users who need to create just one particular valid op-code and the string
375 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
376 location to pre-defined forms in HII)
377
378 Arguments:
379
380 QuestionId - Question ID of the check box
381
382 DataWidth - DataWidth of the check box
383
384 PromptToken - Prompt string token of the check box
385
386 HelpToken - Help string token of the check box
387
388 Flags - Flags of the check box
389
390 Key - Key of the check box
391
392 FormBuffer - Output of the check box as a form
393
394 Returns:
395
396 EFI_SUCCESS - Checkbox created to be a form
397
398 EFI_DEVICE_ERROR - DataWidth > 1
399
400 --*/
401 {
402 EFI_IFR_CHECKBOX CheckBox;
403
404 //
405 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
406 //
407 if (DataWidth > 1) {
408 return EFI_DEVICE_ERROR;
409 }
410
411 CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;
412 CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX);
413 CheckBox.QuestionId = QuestionId;
414 CheckBox.Width = DataWidth;
415 CheckBox.Prompt = PromptToken;
416
417 CheckBox.Help = HelpToken;
418 CheckBox.Flags = Flags;
419 CheckBox.Key = Key;
420
421 CopyMem (FormBuffer, &CheckBox, sizeof (EFI_IFR_CHECKBOX));
422
423 return EFI_SUCCESS;
424 }
425
426
427 EFI_STATUS
428 CreateNumericOpCode (
429 IN UINT16 QuestionId,
430 IN UINT8 DataWidth,
431 IN STRING_REF PromptToken,
432 IN STRING_REF HelpToken,
433 IN UINT16 Minimum,
434 IN UINT16 Maximum,
435 IN UINT16 Step,
436 IN UINT16 Default,
437 IN UINT8 Flags,
438 IN UINT16 Key,
439 IN OUT VOID *FormBuffer
440 )
441 /*++
442
443 Routine Description:
444
445 Create a numeric opcode independent of string creation
446 This is used primarily by users who need to create just one particular valid op-code and the string
447 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
448 location to pre-defined forms in HII)
449
450 Arguments:
451
452 QuestionId - Question ID of the numeric
453
454 DataWidth - DataWidth of the numeric
455
456 PromptToken - Prompt string token of the numeric
457
458 HelpToken - Help string token of the numeric
459
460 Minimum - Minumun boundary of the numeric
461
462 Maximum - Maximum boundary of the numeric
463
464 Step - Step of the numeric
465
466 Default - Default value of the numeric
467
468 Flags - Flags of the numeric
469
470 Key - Key of the numeric
471
472 FormBuffer - Output of the numeric as a form
473
474 Returns:
475
476 EFI_SUCCESS - The numeric created to be a form.
477
478 EFI_DEVICE_ERROR - DataWidth > 2
479
480 --*/
481 {
482 EFI_IFR_NUMERIC Numeric;
483
484 //
485 // We do not create op-code storage widths for numerics in excess of 16 bits for now
486 //
487 if (DataWidth > 2) {
488 return EFI_DEVICE_ERROR;
489 }
490
491 Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;
492 Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);
493 Numeric.QuestionId = QuestionId;
494 Numeric.Width = DataWidth;
495 Numeric.Prompt = PromptToken;
496
497 Numeric.Help = HelpToken;
498 Numeric.Minimum = Minimum;
499 Numeric.Maximum = Maximum;
500 Numeric.Step = Step;
501 Numeric.Default = Default;
502 Numeric.Flags = Flags;
503 Numeric.Key = Key;
504
505 CopyMem (FormBuffer, &Numeric, sizeof (EFI_IFR_NUMERIC));
506
507 return EFI_SUCCESS;
508 }
509
510
511 EFI_STATUS
512 CreateStringOpCode (
513 IN UINT16 QuestionId,
514 IN UINT8 DataWidth,
515 IN STRING_REF PromptToken,
516 IN STRING_REF HelpToken,
517 IN UINT8 MinSize,
518 IN UINT8 MaxSize,
519 IN UINT8 Flags,
520 IN UINT16 Key,
521 IN OUT VOID *FormBuffer
522 )
523 /*++
524
525 Routine Description:
526
527 Create a numeric opcode independent of string creation
528 This is used primarily by users who need to create just one particular valid op-code and the string
529 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
530 location to pre-defined forms in HII)
531
532 Arguments:
533
534 QuestionId - Question ID of the string
535
536 DataWidth - DataWidth of the string
537
538 PromptToken - Prompt token of the string
539
540 HelpToken - Help token of the string
541
542 MinSize - Min size boundary of the string
543
544 MaxSize - Max size boundary of the string
545
546 Flags - Flags of the string
547
548 Key - Key of the string
549
550 FormBuffer - Output of the string as a form
551
552 Returns:
553
554 EFI_SUCCESS - String created to be a form.
555
556 --*/
557 {
558 EFI_IFR_STRING String;
559
560 String.Header.OpCode = EFI_IFR_STRING_OP;
561 String.Header.Length = sizeof (EFI_IFR_STRING);
562 String.QuestionId = QuestionId;
563 String.Width = DataWidth;
564 String.Prompt = PromptToken;
565
566 String.Help = HelpToken;
567 String.MinSize = MinSize;
568 String.MaxSize = MaxSize;
569 String.Flags = Flags;
570 String.Key = Key;
571
572 CopyMem (FormBuffer, &String, sizeof (EFI_IFR_STRING));
573
574 return EFI_SUCCESS;
575 }
576
577
578 EFI_STATUS
579 CreateBannerOpCode (
580 IN UINT16 Title,
581 IN UINT16 LineNumber,
582 IN UINT8 Alignment,
583 IN OUT VOID *FormBuffer
584 )
585 /*++
586
587 Routine Description:
588
589 Create a banner opcode. This is primarily used by the FrontPage implementation from BDS.
590
591 Arguments:
592
593 Title - Title of the banner
594
595 LineNumber - LineNumber of the banner
596
597 Alignment - Alignment of the banner
598
599 FormBuffer - Output of banner as a form
600
601 Returns:
602
603 EFI_SUCCESS - Banner created to be a form.
604
605 --*/
606 {
607 EFI_IFR_BANNER Banner;
608
609 Banner.Header.OpCode = EFI_IFR_BANNER_OP;
610 Banner.Header.Length = sizeof (EFI_IFR_BANNER);
611 CopyMem (&Banner.Title, &Title, sizeof (UINT16));
612 CopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16));
613 Banner.Alignment = Alignment;
614
615 CopyMem (FormBuffer, &Banner, sizeof (EFI_IFR_BANNER));
616
617 return EFI_SUCCESS;
618 }