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
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.
16 Library Routines to create IFR on-the-fly
24 IN CHAR16
*FormSetTitle
,
28 IN OUT VOID
**FormBuffer
,
29 IN OUT VOID
**StringBuffer
39 FormSetTitle - Title of formset
41 Guid - Guid of formset
43 Class - Class of formset
45 SubClass - Sub class of formset
47 FormBuffer - Pointer of the formset created
49 StringBuffer - Pointer of FormSetTitile string created
53 EFI_OUT_OF_RESOURCES - No enough buffer to allocate
55 EFI_SUCCESS - Formset successfully created
60 EFI_HII_IFR_PACK IfrPack
;
61 EFI_IFR_FORM_SET FormSet
;
62 EFI_IFR_END_FORM_SET EndFormSet
;
64 CHAR16 CurrentLanguage
[4];
65 STRING_REF StringToken
;
68 // Pre-allocate a buffer sufficient for us to work from.
70 FormBuffer
= AllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE
);
71 if (FormBuffer
== NULL
) {
72 return EFI_OUT_OF_RESOURCES
;
76 // Pre-allocate a buffer sufficient for us to work from.
78 StringBuffer
= AllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE
);
79 if (StringBuffer
== NULL
) {
80 gBS
->FreePool (FormBuffer
);
81 return EFI_OUT_OF_RESOURCES
;
85 // Obtain current language value
87 GetCurrentLanguage (CurrentLanguage
);
90 // Add the FormSetTitle to the string buffer and get the StringToken
92 Status
= AddString (*StringBuffer
, CurrentLanguage
, FormSetTitle
, &StringToken
);
94 if (EFI_ERROR (Status
)) {
99 // Initialize the Ifr Package header data
101 IfrPack
.Header
.Length
= sizeof (EFI_HII_PACK_HEADER
) + sizeof (EFI_IFR_FORM_SET
) + sizeof (EFI_IFR_END_FORM_SET
);
102 IfrPack
.Header
.Type
= EFI_HII_IFR
;
105 // Initialize FormSet with the appropriate information
107 FormSet
.Header
.OpCode
= EFI_IFR_FORM_SET_OP
;
108 FormSet
.Header
.Length
= sizeof (EFI_IFR_FORM_SET
);
109 FormSet
.FormSetTitle
= StringToken
;
110 FormSet
.Class
= Class
;
111 FormSet
.SubClass
= SubClass
;
112 CopyMem (&FormSet
.Guid
, Guid
, sizeof (EFI_GUID
));
115 // Initialize the end formset data
117 EndFormSet
.Header
.Length
= sizeof (EFI_IFR_END_FORM_SET
);
118 EndFormSet
.Header
.OpCode
= EFI_IFR_END_FORM_SET_OP
;
120 Destination
= (UINT8
*) *FormBuffer
;
123 // Copy the formset/endformset data to the form buffer
125 CopyMem (Destination
, &IfrPack
, sizeof (EFI_HII_PACK_HEADER
));
127 Destination
= Destination
+ sizeof (EFI_HII_PACK_HEADER
);
129 CopyMem (Destination
, &FormSet
, sizeof (EFI_IFR_FORM_SET
));
131 Destination
= Destination
+ sizeof (EFI_IFR_FORM_SET
);
133 CopyMem (Destination
, &EndFormSet
, sizeof (EFI_IFR_END_FORM_SET
));
140 IN CHAR16
*FormTitle
,
142 IN OUT VOID
*FormBuffer
,
143 IN OUT VOID
*StringBuffer
153 FormTitle - Title of the form
155 FormId - Id of the form
157 FormBuffer - Pointer of the form created
159 StringBuffer - Pointer of FormTitil string created
163 EFI_SUCCESS - Form successfully created
169 EFI_IFR_END_FORM EndForm
;
170 CHAR16 CurrentLanguage
[4];
171 STRING_REF StringToken
;
174 // Obtain current language value
176 GetCurrentLanguage (CurrentLanguage
);
178 Status
= AddString (StringBuffer
, CurrentLanguage
, FormTitle
, &StringToken
);
180 if (EFI_ERROR (Status
)) {
184 Form
.Header
.OpCode
= EFI_IFR_FORM_OP
;
185 Form
.Header
.Length
= sizeof (EFI_IFR_FORM
);
186 Form
.FormId
= FormId
;
187 Form
.FormTitle
= StringToken
;
189 Status
= AddOpCode (FormBuffer
, &Form
);
191 if (EFI_ERROR (Status
)) {
195 EndForm
.Header
.OpCode
= EFI_IFR_END_FORM_OP
;
196 EndForm
.Header
.Length
= sizeof (EFI_IFR_END_FORM
);
198 Status
= AddOpCode (FormBuffer
, &EndForm
);
200 if (EFI_ERROR (Status
)) {
211 IN OUT VOID
*FormBuffer
,
212 IN OUT VOID
*StringBuffer
222 SubTitle - Sub title to be created
224 FormBuffer - Where this subtitle to add to
226 StringBuffer - String buffer created for subtitle
230 EFI_SUCCESS - Subtitle successfully created
235 EFI_IFR_SUBTITLE Subtitle
;
236 CHAR16 CurrentLanguage
[4];
237 STRING_REF StringToken
;
240 // Obtain current language value
242 GetCurrentLanguage (CurrentLanguage
);
244 Status
= AddString (StringBuffer
, CurrentLanguage
, SubTitle
, &StringToken
);
246 if (EFI_ERROR (Status
)) {
250 Subtitle
.Header
.OpCode
= EFI_IFR_SUBTITLE_OP
;
251 Subtitle
.Header
.Length
= sizeof (EFI_IFR_SUBTITLE
);
252 Subtitle
.SubTitle
= StringToken
;
254 Status
= AddOpCode (FormBuffer
, &Subtitle
);
256 if (EFI_ERROR (Status
)) {
271 IN OUT VOID
*FormBuffer
,
272 IN OUT VOID
*StringBuffer
278 Create a line of text
282 String - First string of the text
284 String2 - Second string of the text
286 String3 - Help string of the text
288 Flags - Flag of the text
290 Key - Key of the text
292 FormBuffer - The form where this text adds to
294 StringBuffer - String buffer created for String, String2 and String3
298 EFI_SUCCESS - Text successfully created
304 CHAR16 CurrentLanguage
[4];
305 STRING_REF StringToken
;
308 // Obtain current language value
310 GetCurrentLanguage (CurrentLanguage
);
313 // Add first string, get first string's token
315 Status
= AddString (StringBuffer
, CurrentLanguage
, String
, &StringToken
);
317 if (EFI_ERROR (Status
)) {
321 Text
.Header
.OpCode
= EFI_IFR_TEXT_OP
;
322 Text
.Header
.Length
= sizeof (EFI_IFR_TEXT
);
323 Text
.Text
= StringToken
;
326 // Add second string, get first string's token
328 Status
= AddString (StringBuffer
, CurrentLanguage
, String2
, &StringToken
);
330 if (EFI_ERROR (Status
)) {
334 Text
.TextTwo
= StringToken
;
336 Text
.Flags
= (UINT8
) (Flags
| EFI_IFR_FLAG_CREATED
);
340 // Add second string, get first string's token
342 Status
= AddString (StringBuffer
, CurrentLanguage
, String3
, &StringToken
);
344 if (EFI_ERROR (Status
)) {
348 Text
.Help
= StringToken
;
350 Status
= AddOpCode (FormBuffer
, &Text
);
352 if (EFI_ERROR (Status
)) {
364 IN OUT VOID
*FormBuffer
,
365 IN OUT VOID
*StringBuffer
375 FormId - Form ID of the hyperlink
377 Prompt - Prompt of the hyperlink
379 FormBuffer - The form where this hyperlink adds to
381 StringBuffer - String buffer created for Prompt
385 EFI_SUCCESS - Hyperlink successfully created
390 EFI_IFR_REF Hyperlink
;
391 CHAR16 CurrentLanguage
[4];
392 STRING_REF StringToken
;
395 // Obtain current language value
397 GetCurrentLanguage (CurrentLanguage
);
399 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
401 if (EFI_ERROR (Status
)) {
405 Hyperlink
.Header
.OpCode
= EFI_IFR_REF_OP
;
406 Hyperlink
.Header
.Length
= sizeof (EFI_IFR_REF
);
407 Hyperlink
.FormId
= FormId
;
408 Hyperlink
.Prompt
= StringToken
;
410 Status
= AddOpCode (FormBuffer
, &Hyperlink
);
412 if (EFI_ERROR (Status
)) {
422 IN UINT16 QuestionId
,
426 IN IFR_OPTION
*OptionsList
,
427 IN UINTN OptionCount
,
428 IN OUT VOID
*FormBuffer
,
429 IN OUT VOID
*StringBuffer
435 Create a one-of question with a set of options to choose from. The
436 OptionsList is a pointer to a null-terminated list of option descriptions.
440 QuestionId - Question ID of the one-of box
442 DataWidth - DataWidth of the one-of box
444 Prompt - Prompt of the one-of box
446 Help - Help of the one-of box
448 OptionsList - Each string in it is an option of the one-of box
450 OptionCount - Option string count
452 FormBuffer - The form where this one-of box adds to
454 StringBuffer - String buffer created for Prompt, Help and Option strings
458 EFI_DEVICE_ERROR - DataWidth > 2
460 EFI_SUCCESS - One-Of box successfully created.
466 EFI_IFR_ONE_OF OneOf
;
467 EFI_IFR_ONE_OF_OPTION OneOfOption
;
468 EFI_IFR_END_ONE_OF EndOneOf
;
469 CHAR16 CurrentLanguage
[4];
470 STRING_REF StringToken
;
473 // We do not create op-code storage widths for one-of in excess of 16 bits for now
476 return EFI_DEVICE_ERROR
;
480 // Obtain current language value
482 GetCurrentLanguage (CurrentLanguage
);
485 // Add first string, get first string's token
487 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
489 if (EFI_ERROR (Status
)) {
493 OneOf
.Header
.OpCode
= EFI_IFR_ONE_OF_OP
;
494 OneOf
.Header
.Length
= sizeof (EFI_IFR_ONE_OF
);
495 OneOf
.QuestionId
= QuestionId
;
496 OneOf
.Width
= DataWidth
;
497 OneOf
.Prompt
= StringToken
;
500 // Add second string, get first string's token
502 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
504 if (EFI_ERROR (Status
)) {
508 OneOf
.Help
= StringToken
;
510 Status
= AddOpCode (FormBuffer
, &OneOf
);
512 if (EFI_ERROR (Status
)) {
516 for (Index
= 0; Index
< OptionCount
; Index
++) {
517 OneOfOption
.Header
.OpCode
= EFI_IFR_ONE_OF_OPTION_OP
;
518 OneOfOption
.Header
.Length
= sizeof (EFI_IFR_ONE_OF_OPTION
);
521 // Add string and get token back
523 Status
= AddString (StringBuffer
, CurrentLanguage
, OptionsList
[Index
].OptionString
, &StringToken
);
525 OneOfOption
.Option
= StringToken
;
526 OneOfOption
.Value
= OptionsList
[Index
].Value
;
527 OneOfOption
.Flags
= (UINT8
) (OptionsList
[Index
].Flags
| EFI_IFR_FLAG_CREATED
);
528 OneOfOption
.Key
= OptionsList
[Index
].Key
;
530 Status
= AddOpCode (FormBuffer
, &OneOfOption
);
532 if (EFI_ERROR (Status
)) {
537 EndOneOf
.Header
.Length
= sizeof (EFI_IFR_END_ONE_OF
);
538 EndOneOf
.Header
.OpCode
= EFI_IFR_END_ONE_OF_OP
;
540 Status
= AddOpCode (FormBuffer
, &EndOneOf
);
542 if (EFI_ERROR (Status
)) {
551 IN UINT16 QuestionId
,
555 IN IFR_OPTION
*OptionsList
,
556 IN UINTN OptionCount
,
557 IN OUT VOID
*FormBuffer
,
558 IN OUT VOID
*StringBuffer
564 Create a one-of question with a set of options to choose from. The
565 OptionsList is a pointer to a null-terminated list of option descriptions.
569 QuestionId - Question ID of the ordered list
571 MaxEntries - MaxEntries of the ordered list
573 Prompt - Prompt of the ordered list
575 Help - Help of the ordered list
577 OptionsList - Each string in it is an option of the ordered list
579 OptionCount - Option string count
581 FormBuffer - The form where this ordered list adds to
583 StringBuffer - String buffer created for Prompt, Help and Option strings
587 EFI_SUCCESS - Ordered list successfully created.
593 EFI_IFR_ORDERED_LIST OrderedList
;
594 EFI_IFR_ONE_OF_OPTION OrderedListOption
;
595 EFI_IFR_END_ONE_OF EndOrderedList
;
596 CHAR16 CurrentLanguage
[4];
597 STRING_REF StringToken
;
600 // Obtain current language value
602 GetCurrentLanguage (CurrentLanguage
);
605 // Add first string, get first string's token
607 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
609 if (EFI_ERROR (Status
)) {
613 OrderedList
.Header
.OpCode
= EFI_IFR_ORDERED_LIST_OP
;
614 OrderedList
.Header
.Length
= sizeof (EFI_IFR_ORDERED_LIST
);
615 OrderedList
.QuestionId
= QuestionId
;
616 OrderedList
.MaxEntries
= MaxEntries
;
617 OrderedList
.Prompt
= StringToken
;
620 // Add second string, get first string's token
622 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
624 if (EFI_ERROR (Status
)) {
628 OrderedList
.Help
= StringToken
;
630 Status
= AddOpCode (FormBuffer
, &OrderedList
);
632 if (EFI_ERROR (Status
)) {
636 for (Index
= 0; Index
< OptionCount
; Index
++) {
637 OrderedListOption
.Header
.OpCode
= EFI_IFR_ONE_OF_OPTION_OP
;
638 OrderedListOption
.Header
.Length
= sizeof (EFI_IFR_ONE_OF_OPTION
);
641 // Add string and get token back
643 Status
= AddString (StringBuffer
, CurrentLanguage
, OptionsList
[Index
].OptionString
, &StringToken
);
645 OrderedListOption
.Option
= StringToken
;
646 OrderedListOption
.Value
= OptionsList
[Index
].Value
;
647 OrderedListOption
.Flags
= (UINT8
) (OptionsList
[Index
].Flags
| EFI_IFR_FLAG_CREATED
);
648 OrderedListOption
.Key
= OptionsList
[Index
].Key
;
650 Status
= AddOpCode (FormBuffer
, &OrderedListOption
);
652 if (EFI_ERROR (Status
)) {
657 EndOrderedList
.Header
.Length
= sizeof (EFI_IFR_END_ONE_OF
);
658 EndOrderedList
.Header
.OpCode
= EFI_IFR_END_ONE_OF_OP
;
660 Status
= AddOpCode (FormBuffer
, &EndOrderedList
);
662 if (EFI_ERROR (Status
)) {
672 IN UINT16 QuestionId
,
677 IN OUT VOID
*FormBuffer
,
678 IN OUT VOID
*StringBuffer
688 QuestionId - Question ID of the check box
690 DataWidth - DataWidth of the check box
692 Prompt - Prompt of the check box
694 Help - Help of the check box
696 Flags - Flags of the check box
698 FormBuffer - The form where this check box adds to
700 StringBuffer - String buffer created for Prompt and Help.
704 EFI_DEVICE_ERROR - DataWidth > 1
706 EFI_SUCCESS - Check box successfully created
711 EFI_IFR_CHECKBOX CheckBox
;
712 CHAR16 CurrentLanguage
[4];
713 STRING_REF StringToken
;
716 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
719 return EFI_DEVICE_ERROR
;
723 // Obtain current language value
725 GetCurrentLanguage (CurrentLanguage
);
728 // Add first string, get first string's token
730 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
732 if (EFI_ERROR (Status
)) {
736 CheckBox
.Header
.OpCode
= EFI_IFR_CHECKBOX_OP
;
737 CheckBox
.Header
.Length
= sizeof (EFI_IFR_CHECKBOX
);
738 CheckBox
.QuestionId
= QuestionId
;
739 CheckBox
.Width
= DataWidth
;
740 CheckBox
.Prompt
= StringToken
;
743 // Add second string, get first string's token
745 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
747 if (EFI_ERROR (Status
)) {
751 CheckBox
.Help
= StringToken
;
752 CheckBox
.Flags
= (UINT8
) (Flags
| EFI_IFR_FLAG_CREATED
);
754 Status
= AddOpCode (FormBuffer
, &CheckBox
);
756 if (EFI_ERROR (Status
)) {
766 IN UINT16 QuestionId
,
776 IN OUT VOID
*FormBuffer
,
777 IN OUT VOID
*StringBuffer
787 QuestionId - Question ID of the numeric
789 DataWidth - DataWidth of the numeric
791 Prompt - Prompt of the numeric
793 Help - Help of the numeric
795 Minimum - Minumun boundary of the numeric
797 Maximum - Maximum boundary of the numeric
799 Step - Step of the numeric
801 Default - Default value
803 Flags - Flags of the numeric
805 Key - Key of the numeric
807 FormBuffer - The form where this numeric adds to
809 StringBuffer - String buffer created for Prompt and Help.
813 EFI_DEVICE_ERROR - DataWidth > 2
815 EFI_SUCCESS - Numeric is successfully created
820 EFI_IFR_NUMERIC Numeric
;
821 CHAR16 CurrentLanguage
[4];
822 STRING_REF StringToken
;
825 // We do not create op-code storage widths for numerics in excess of 16 bits for now
828 return EFI_DEVICE_ERROR
;
832 // Obtain current language value
834 GetCurrentLanguage (CurrentLanguage
);
837 // Add first string, get first string's token
839 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
841 if (EFI_ERROR (Status
)) {
845 Numeric
.Header
.OpCode
= EFI_IFR_NUMERIC_OP
;
846 Numeric
.Header
.Length
= sizeof (EFI_IFR_NUMERIC
);
847 Numeric
.QuestionId
= QuestionId
;
848 Numeric
.Width
= DataWidth
;
849 Numeric
.Prompt
= StringToken
;
852 // Add second string, get first string's token
854 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
856 if (EFI_ERROR (Status
)) {
860 Numeric
.Help
= StringToken
;
861 Numeric
.Minimum
= Minimum
;
862 Numeric
.Maximum
= Maximum
;
864 Numeric
.Default
= Default
;
865 Numeric
.Flags
= (UINT8
) (Flags
| EFI_IFR_FLAG_CREATED
);
868 Status
= AddOpCode (FormBuffer
, &Numeric
);
870 if (EFI_ERROR (Status
)) {
880 IN UINT16 QuestionId
,
888 IN OUT VOID
*FormBuffer
,
889 IN OUT VOID
*StringBuffer
899 QuestionId - Question ID of the string
901 DataWidth - DataWidth of the string
903 Prompt - Prompt of the string
905 Help - Help of the string
907 MinSize - Min size boundary of the string
909 MaxSize - Max size boundary of the string
911 Flags - Flags of the string
913 Key - Key of the string
915 FormBuffer - The form where this string adds to
917 StringBuffer - String buffer created for Prompt and Help.
921 EFI_SUCCESS - String successfully created.
926 EFI_IFR_STRING String
;
927 CHAR16 CurrentLanguage
[4];
928 STRING_REF StringToken
;
931 // Obtain current language value
933 GetCurrentLanguage (CurrentLanguage
);
936 // Add first string, get first string's token
938 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
940 if (EFI_ERROR (Status
)) {
944 String
.Header
.OpCode
= EFI_IFR_STRING_OP
;
945 String
.Header
.Length
= sizeof (EFI_IFR_STRING
);
946 String
.QuestionId
= QuestionId
;
947 String
.Width
= DataWidth
;
948 String
.Prompt
= StringToken
;
951 // Add second string, get first string's token
953 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
955 if (EFI_ERROR (Status
)) {
959 String
.Help
= StringToken
;
960 String
.MinSize
= MinSize
;
961 String
.MaxSize
= MaxSize
;
962 String
.Flags
= (UINT8
) (Flags
| EFI_IFR_FLAG_CREATED
);
965 Status
= AddOpCode (FormBuffer
, &String
);
967 if (EFI_ERROR (Status
)) {