]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkIfrSupportLib/IfrOpCodeCreation.c
c85aba3a4ca28ce1eab57494b489e45ba9d2aed2
[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 #include "IfrSupportLibInternal.h"
17
18 /**
19 Create a SubTitle opcode independent of string creation.
20 This is used primarily by users who need to create just one particular valid op-code and the string
21 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
22 location to pre-defined forms in HII)
23
24 @param StringToken StringToken of the subtitle
25 @param FormBuffer Output of subtitle as a form
26
27 @retval EFI_SUCCESS Subtitle created to be a form
28 **/
29 EFI_STATUS
30 CreateSubTitleOpCode (
31 IN STRING_REF StringToken,
32 IN OUT VOID *FormBuffer
33 )
34 {
35 FRAMEWORK_EFI_IFR_SUBTITLE Subtitle;
36
37 Subtitle.Header.OpCode = FRAMEWORK_EFI_IFR_SUBTITLE_OP;
38 Subtitle.Header.Length = sizeof (FRAMEWORK_EFI_IFR_SUBTITLE);
39 Subtitle.SubTitle = StringToken;
40
41 CopyMem (FormBuffer, &Subtitle, sizeof (FRAMEWORK_EFI_IFR_SUBTITLE));
42 return EFI_SUCCESS;
43 }
44
45 /**
46 Create a Text opcode independent of string creation.
47
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
90 This is used primarily by users who need to create just one particular valid op-code and the string
91 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
92 location to pre-defined forms in HII)
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
101 @retval EFI_SUCCESS Hyperlink created to be a form
102 **/
103 EFI_STATUS
104 CreateGotoOpCode (
105 IN UINT16 FormId,
106 IN STRING_REF StringToken,
107 IN STRING_REF StringTokenTwo,
108 IN UINT8 Flags,
109 IN UINT16 Key,
110 IN OUT VOID *FormBuffer
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 OneOf.Help = HelpToken;
179 LocalBuffer = (UINT8 *) FormBuffer;
180
181 CopyMem (LocalBuffer, &OneOf, sizeof (FRAMEWORK_EFI_IFR_ONE_OF));
182
183 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ONE_OF));
184
185 for (Index = 0; Index < OptionCount; Index++) {
186 OneOfOption.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP;
187 OneOfOption.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION);
188
189 OneOfOption.Option = OptionsList[Index].StringToken;
190 OneOfOption.Value = OptionsList[Index].Value;
191 OneOfOption.Flags = OptionsList[Index].Flags;
192 OneOfOption.Key = OptionsList[Index].Key;
193
194 CopyMem (LocalBuffer, &OneOfOption, sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
195
196 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
197 }
198
199 EndOneOf.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF);
200 EndOneOf.Header.OpCode = FRAMEWORK_EFI_IFR_END_ONE_OF_OP;
201
202 CopyMem (LocalBuffer, &EndOneOf, sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
203
204 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
205
206 return EFI_SUCCESS;
207 }
208
209 /**
210 Create a ordered list opcode with a set of option op-codes to choose from independent of string creation.
211 This is used primarily by users who need to create just one particular valid op-code and the string
212 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
213 location to pre-defined forms in HII)
214
215 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
216 has been filled in since this routine will not generate StringToken values.
217
218 @param QuestionId Question ID of the ordered list
219 @param MaxEntries MaxEntries of the ordered list
220 @param PromptToken Prompt string token of the ordered list
221 @param HelpToken Help string token of the ordered list
222 @param OptionsList Each string in it is an option of the ordered list
223 @param OptionCount Option string count
224 @param FormBuffer Output of ordered list as a form
225
226 @retval EFI_SUCCESS Ordered list created to be a form
227 **/
228 EFI_STATUS
229 CreateOrderedListOpCode (
230 IN UINT16 QuestionId,
231 IN UINT8 MaxEntries,
232 IN STRING_REF PromptToken,
233 IN STRING_REF HelpToken,
234 IN IFR_OPTION *OptionsList,
235 IN UINTN OptionCount,
236 IN OUT VOID *FormBuffer
237 )
238 {
239 UINTN Index;
240 FRAMEWORK_EFI_IFR_ORDERED_LIST OrderedList;
241 FRAMEWORK_EFI_IFR_ONE_OF_OPTION OrderedListOption;
242 FRAMEWORK_EFI_IFR_END_ONE_OF EndOrderedList;
243 UINT8 *LocalBuffer;
244
245 OrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_ORDERED_LIST_OP;
246 OrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST);
247 OrderedList.QuestionId = QuestionId;
248 OrderedList.MaxEntries = MaxEntries;
249 OrderedList.Prompt = PromptToken;
250 OrderedList.Help = HelpToken;
251 LocalBuffer = (UINT8 *) FormBuffer;
252
253 CopyMem (LocalBuffer, &OrderedList, sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST));
254
255 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST));
256
257 for (Index = 0; Index < OptionCount; Index++) {
258 OrderedListOption.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP;
259 OrderedListOption.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION);
260
261 OrderedListOption.Option = OptionsList[Index].StringToken;
262 OrderedListOption.Value = OptionsList[Index].Value;
263 OrderedListOption.Flags = OptionsList[Index].Flags;
264 OrderedListOption.Key = OptionsList[Index].Key;
265
266 CopyMem (LocalBuffer, &OrderedListOption, sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
267
268 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
269 }
270
271 EndOrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF);
272 EndOrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_END_ONE_OF_OP;
273
274 CopyMem (LocalBuffer, &EndOrderedList, sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
275
276 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
277
278 return EFI_SUCCESS;
279 }
280
281 /**
282 Create a checkbox opcode independent of string creation.
283 This is used primarily by users who need to create just one particular valid op-code and the string
284 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
285 location to pre-defined forms in HII)
286
287 @param QuestionId Question ID of the check box
288 @param DataWidth DataWidth of the check box
289 @param PromptToken Prompt string token of the check box
290 @param HelpToken Help string token of the check box
291 @param Flags Flags of the check box
292 @param Key Key of the check box
293 @param FormBuffer Output of the check box as a form
294
295 @retval EFI_SUCCESS Checkbox created to be a form
296 @retval EFI_DEVICE_ERROR DataWidth > 1
297 **/
298 EFI_STATUS
299 CreateCheckBoxOpCode (
300 IN UINT16 QuestionId,
301 IN UINT8 DataWidth,
302 IN STRING_REF PromptToken,
303 IN STRING_REF HelpToken,
304 IN UINT8 Flags,
305 IN UINT16 Key,
306 IN OUT VOID *FormBuffer
307 )
308 {
309 FRAMEWORK_EFI_IFR_CHECKBOX CheckBox;
310
311 //
312 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
313 //
314 if (DataWidth > 1) {
315 return EFI_DEVICE_ERROR;
316 }
317
318 CheckBox.Header.OpCode = FRAMEWORK_EFI_IFR_CHECKBOX_OP;
319 CheckBox.Header.Length = sizeof (FRAMEWORK_EFI_IFR_CHECKBOX);
320 CheckBox.QuestionId = QuestionId;
321 CheckBox.Width = DataWidth;
322 CheckBox.Prompt = PromptToken;
323 CheckBox.Help = HelpToken;
324 CheckBox.Flags = Flags;
325 CheckBox.Key = Key;
326
327 CopyMem (FormBuffer, &CheckBox, sizeof (FRAMEWORK_EFI_IFR_CHECKBOX));
328
329 return EFI_SUCCESS;
330 }
331
332 /**
333 Create a numeric opcode independent of string creation.
334 This is used primarily by users who need to create just one particular valid op-code and the string
335 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
336 location to pre-defined forms in HII)
337
338 @param QuestionId Question ID of the numeric
339 @param DataWidth DataWidth of the numeric
340 @param PromptToken Prompt string token of the numeric
341 @param HelpToken Help string token of the numeric
342 @param Minimum Minumun boundary of the numeric
343 @param Maximum Maximum boundary of the numeric
344 @param Step Step of the numeric
345 @param Default Default value of the numeric
346 @param Flags Flags of the numeric
347 @param Key Key of the numeric
348 @param FormBuffer Output of the numeric as a form
349
350
351 @retval EFI_SUCCESS The numeric created to be a form.
352 @retval EFI_DEVICE_ERROR DataWidth > 2
353 **/
354 EFI_STATUS
355 CreateNumericOpCode (
356 IN UINT16 QuestionId,
357 IN UINT8 DataWidth,
358 IN STRING_REF PromptToken,
359 IN STRING_REF HelpToken,
360 IN UINT16 Minimum,
361 IN UINT16 Maximum,
362 IN UINT16 Step,
363 IN UINT16 Default,
364 IN UINT8 Flags,
365 IN UINT16 Key,
366 IN OUT VOID *FormBuffer
367 )
368 {
369 FRAMEWORK_EFI_IFR_NUMERIC Numeric;
370
371 //
372 // We do not create op-code storage widths for numerics in excess of 16 bits for now
373 //
374 if (DataWidth > 2) {
375 return EFI_DEVICE_ERROR;
376 }
377
378 Numeric.Header.OpCode = FRAMEWORK_EFI_IFR_NUMERIC_OP;
379 Numeric.Header.Length = sizeof (FRAMEWORK_EFI_IFR_NUMERIC);
380 Numeric.QuestionId = QuestionId;
381 Numeric.Width = DataWidth;
382 Numeric.Prompt = PromptToken;
383 Numeric.Help = HelpToken;
384 Numeric.Minimum = Minimum;
385 Numeric.Maximum = Maximum;
386 Numeric.Step = Step;
387 Numeric.Default = Default;
388 Numeric.Flags = Flags;
389 Numeric.Key = Key;
390
391 CopyMem (FormBuffer, &Numeric, sizeof (FRAMEWORK_EFI_IFR_NUMERIC));
392
393 return EFI_SUCCESS;
394 }
395
396 /**
397 Create a numeric opcode independent of string creation.
398 This is used primarily by users who need to create just one particular valid op-code and the string
399 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
400 location to pre-defined forms in HII)
401
402 @param QuestionId Question ID of the string
403 @param DataWidth DataWidth of the string
404 @param PromptToken Prompt token of the string
405 @param HelpToken Help token of the string
406 @param MinSize Min size boundary of the string
407 @param MaxSize Max size boundary of the string
408 @param Flags Flags of the string
409 @param Key Key of the string
410 @param FormBuffer Output of the string as a form
411
412 @retval EFI_SUCCESS String created to be a form.
413 **/
414 EFI_STATUS
415 CreateStringOpCode (
416 IN UINT16 QuestionId,
417 IN UINT8 DataWidth,
418 IN STRING_REF PromptToken,
419 IN STRING_REF HelpToken,
420 IN UINT8 MinSize,
421 IN UINT8 MaxSize,
422 IN UINT8 Flags,
423 IN UINT16 Key,
424 IN OUT VOID *FormBuffer
425 )
426 {
427 FRAMEWORK_EFI_IFR_STRING String;
428
429 String.Header.OpCode = FRAMEWORK_EFI_IFR_STRING_OP;
430 String.Header.Length = sizeof (FRAMEWORK_EFI_IFR_STRING);
431 String.QuestionId = QuestionId;
432 String.Width = DataWidth;
433 String.Prompt = PromptToken;
434 String.Help = HelpToken;
435 String.MinSize = MinSize;
436 String.MaxSize = MaxSize;
437 String.Flags = Flags;
438 String.Key = Key;
439
440 CopyMem (FormBuffer, &String, sizeof (FRAMEWORK_EFI_IFR_STRING));
441
442 return EFI_SUCCESS;
443 }
444
445 /**
446 Create a banner opcode. This is primarily used by the FrontPage implementation from BDS.
447
448 @param Title Title of the banner
449 @param LineNumber LineNumber of the banner
450 @param Alignment Alignment of the banner
451 @param FormBuffer Output of banner as a form
452
453 @retval EFI_SUCCESS Banner created to be a form.
454 **/
455 EFI_STATUS
456 CreateBannerOpCode (
457 IN UINT16 Title,
458 IN UINT16 LineNumber,
459 IN UINT8 Alignment,
460 IN OUT VOID *FormBuffer
461 )
462 {
463 FRAMEWORK_EFI_IFR_BANNER Banner;
464
465 Banner.Header.OpCode = FRAMEWORK_EFI_IFR_BANNER_OP;
466 Banner.Header.Length = sizeof (FRAMEWORK_EFI_IFR_BANNER);
467 CopyMem (&Banner.Title, &Title, sizeof (UINT16));
468 CopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16));
469 Banner.Alignment = Alignment;
470
471 CopyMem (FormBuffer, &Banner, sizeof (FRAMEWORK_EFI_IFR_BANNER));
472
473 return EFI_SUCCESS;
474 }
475
476