]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkIfrSupportLib/IfrOpCodeCreation.c
Correct comments
[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 EFIAPI
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
44 return EFI_SUCCESS;
45 }
46
47 /**
48 Create a Text opcode independent of string creation.
49
50 This is used primarily by users who need to create just one particular valid op-code and the string
51 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
52 location to pre-defined forms in HII)
53
54 @param StringToken First string token of the text
55 @param StringTokenTwo Second string token of the text
56 @param StringTokenThree Help string token of the text
57 @param Flags Flag of the text
58 @param Key Key of the text
59 @param FormBuffer Output of text as a form
60
61 @retval EFI_SUCCESS Text created to be a form
62 **/
63 EFI_STATUS
64 EFIAPI
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
93 This is used primarily by users who need to create just one particular valid op-code and the string
94 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
95 location to pre-defined forms in HII)
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
104 @retval EFI_SUCCESS Hyperlink created to be a form
105 **/
106 EFI_STATUS
107 EFIAPI
108 CreateGotoOpCode (
109 IN UINT16 FormId,
110 IN STRING_REF StringToken,
111 IN STRING_REF StringTokenTwo,
112 IN UINT8 Flags,
113 IN UINT16 Key,
114 IN OUT VOID *FormBuffer
115 )
116 {
117 FRAMEWORK_EFI_IFR_REF Hyperlink;
118
119 Hyperlink.Header.OpCode = FRAMEWORK_EFI_IFR_REF_OP;
120 Hyperlink.Header.Length = sizeof (FRAMEWORK_EFI_IFR_REF);
121 Hyperlink.FormId = FormId;
122 Hyperlink.Prompt = StringToken;
123 Hyperlink.Help = StringTokenTwo;
124 Hyperlink.Key = Key;
125 Hyperlink.Flags = Flags;
126
127 CopyMem (FormBuffer, &Hyperlink, sizeof (FRAMEWORK_EFI_IFR_REF));
128
129 return EFI_SUCCESS;
130 }
131
132 /**
133 Create a one-of opcode with a set of option op-codes to choose from 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 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
139 has been filled in since this routine will not generate StringToken values.
140
141 @param QuestionId Question ID of the one-of box
142 @param DataWidth DataWidth of the one-of box
143 @param PromptToken Prompt string token of the one-of box
144 @param HelpToken Help string token of the one-of box
145 @param OptionsList Each string in it is an option of the one-of box
146 @param OptionCount Option string count
147 @param FormBuffer Output of One-Of box as a form
148
149
150 @retval EFI_SUCCESS One-Of box created to be a form
151 @retval EFI_DEVICE_ERROR DataWidth > 2
152 **/
153 EFI_STATUS
154 EFIAPI
155 CreateOneOfOpCode (
156 IN UINT16 QuestionId,
157 IN UINT8 DataWidth,
158 IN STRING_REF PromptToken,
159 IN STRING_REF HelpToken,
160 IN IFR_OPTION *OptionsList,
161 IN UINTN OptionCount,
162 IN OUT VOID *FormBuffer
163 )
164 {
165 UINTN Index;
166 FRAMEWORK_EFI_IFR_ONE_OF OneOf;
167 FRAMEWORK_EFI_IFR_ONE_OF_OPTION OneOfOption;
168 FRAMEWORK_EFI_IFR_END_ONE_OF EndOneOf;
169 UINT8 *LocalBuffer;
170
171 //
172 // We do not create op-code storage widths for one-of in excess of 16 bits for now
173 //
174 if (DataWidth > 2) {
175 return EFI_DEVICE_ERROR;
176 }
177
178 OneOf.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OP;
179 OneOf.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF);
180 OneOf.QuestionId = QuestionId;
181 OneOf.Width = DataWidth;
182 OneOf.Prompt = PromptToken;
183 OneOf.Help = HelpToken;
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 EFIAPI
235 CreateOrderedListOpCode (
236 IN UINT16 QuestionId,
237 IN UINT8 MaxEntries,
238 IN STRING_REF PromptToken,
239 IN STRING_REF HelpToken,
240 IN IFR_OPTION *OptionsList,
241 IN UINTN OptionCount,
242 IN OUT VOID *FormBuffer
243 )
244 {
245 UINTN Index;
246 FRAMEWORK_EFI_IFR_ORDERED_LIST OrderedList;
247 FRAMEWORK_EFI_IFR_ONE_OF_OPTION OrderedListOption;
248 FRAMEWORK_EFI_IFR_END_ONE_OF EndOrderedList;
249 UINT8 *LocalBuffer;
250
251 OrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_ORDERED_LIST_OP;
252 OrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST);
253 OrderedList.QuestionId = QuestionId;
254 OrderedList.MaxEntries = MaxEntries;
255 OrderedList.Prompt = PromptToken;
256 OrderedList.Help = HelpToken;
257 LocalBuffer = (UINT8 *) FormBuffer;
258
259 CopyMem (LocalBuffer, &OrderedList, sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST));
260
261 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST));
262
263 for (Index = 0; Index < OptionCount; Index++) {
264 OrderedListOption.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP;
265 OrderedListOption.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION);
266
267 OrderedListOption.Option = OptionsList[Index].StringToken;
268 OrderedListOption.Value = OptionsList[Index].Value;
269 OrderedListOption.Flags = OptionsList[Index].Flags;
270 OrderedListOption.Key = OptionsList[Index].Key;
271
272 CopyMem (LocalBuffer, &OrderedListOption, sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
273
274 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION));
275 }
276
277 EndOrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF);
278 EndOrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_END_ONE_OF_OP;
279
280 CopyMem (LocalBuffer, &EndOrderedList, sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
281
282 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF));
283
284 return EFI_SUCCESS;
285 }
286
287 /**
288 Create a checkbox opcode independent of string creation.
289 This is used primarily by users who need to create just one particular valid op-code and the string
290 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
291 location to pre-defined forms in HII)
292
293 @param QuestionId Question ID of the check box
294 @param DataWidth DataWidth of the check box
295 @param PromptToken Prompt string token of the check box
296 @param HelpToken Help string token of the check box
297 @param Flags Flags of the check box
298 @param Key Key of the check box
299 @param FormBuffer Output of the check box as a form
300
301 @retval EFI_SUCCESS Checkbox created to be a form
302 @retval EFI_DEVICE_ERROR DataWidth > 1
303 **/
304 EFI_STATUS
305 EFIAPI
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 FRAMEWORK_EFI_IFR_CHECKBOX CheckBox;
317
318 //
319 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
320 //
321 if (DataWidth > 1) {
322 return EFI_DEVICE_ERROR;
323 }
324
325 CheckBox.Header.OpCode = FRAMEWORK_EFI_IFR_CHECKBOX_OP;
326 CheckBox.Header.Length = sizeof (FRAMEWORK_EFI_IFR_CHECKBOX);
327 CheckBox.QuestionId = QuestionId;
328 CheckBox.Width = DataWidth;
329 CheckBox.Prompt = PromptToken;
330 CheckBox.Help = HelpToken;
331 CheckBox.Flags = Flags;
332 CheckBox.Key = Key;
333
334 CopyMem (FormBuffer, &CheckBox, sizeof (FRAMEWORK_EFI_IFR_CHECKBOX));
335
336 return EFI_SUCCESS;
337 }
338
339 /**
340 Create a numeric opcode independent of string creation.
341 This is used primarily by users who need to create just one particular valid op-code and the string
342 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
343 location to pre-defined forms in HII)
344
345 @param QuestionId Question ID of the numeric
346 @param DataWidth DataWidth of the numeric
347 @param PromptToken Prompt string token of the numeric
348 @param HelpToken Help string token of the numeric
349 @param Minimum Minumun boundary of the numeric
350 @param Maximum Maximum boundary of the numeric
351 @param Step Step of the numeric
352 @param Default Default value of the numeric
353 @param Flags Flags of the numeric
354 @param Key Key of the numeric
355 @param FormBuffer Output of the numeric as a form
356
357
358 @retval EFI_SUCCESS The numeric created to be a form.
359 @retval EFI_DEVICE_ERROR DataWidth > 2
360 **/
361 EFI_STATUS
362 EFIAPI
363 CreateNumericOpCode (
364 IN UINT16 QuestionId,
365 IN UINT8 DataWidth,
366 IN STRING_REF PromptToken,
367 IN STRING_REF HelpToken,
368 IN UINT16 Minimum,
369 IN UINT16 Maximum,
370 IN UINT16 Step,
371 IN UINT16 Default,
372 IN UINT8 Flags,
373 IN UINT16 Key,
374 IN OUT VOID *FormBuffer
375 )
376 {
377 FRAMEWORK_EFI_IFR_NUMERIC Numeric;
378
379 //
380 // We do not create op-code storage widths for numerics in excess of 16 bits for now
381 //
382 if (DataWidth > 2) {
383 return EFI_DEVICE_ERROR;
384 }
385
386 Numeric.Header.OpCode = FRAMEWORK_EFI_IFR_NUMERIC_OP;
387 Numeric.Header.Length = sizeof (FRAMEWORK_EFI_IFR_NUMERIC);
388 Numeric.QuestionId = QuestionId;
389 Numeric.Width = DataWidth;
390 Numeric.Prompt = PromptToken;
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 EFIAPI
424 CreateStringOpCode (
425 IN UINT16 QuestionId,
426 IN UINT8 DataWidth,
427 IN STRING_REF PromptToken,
428 IN STRING_REF HelpToken,
429 IN UINT8 MinSize,
430 IN UINT8 MaxSize,
431 IN UINT8 Flags,
432 IN UINT16 Key,
433 IN OUT VOID *FormBuffer
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 String.Help = HelpToken;
444 String.MinSize = MinSize;
445 String.MaxSize = MaxSize;
446 String.Flags = Flags;
447 String.Key = Key;
448
449 CopyMem (FormBuffer, &String, sizeof (FRAMEWORK_EFI_IFR_STRING));
450
451 return EFI_SUCCESS;
452 }
453
454 /**
455 Create a banner opcode. This is primarily used by the FrontPage implementation from BDS.
456
457 @param Title Title of the banner
458 @param LineNumber LineNumber of the banner
459 @param Alignment Alignment of the banner
460 @param FormBuffer Output of banner as a form
461
462 @retval EFI_SUCCESS Banner created to be a form.
463 **/
464 EFI_STATUS
465 EFIAPI
466 CreateBannerOpCode (
467 IN UINT16 Title,
468 IN UINT16 LineNumber,
469 IN UINT8 Alignment,
470 IN OUT VOID *FormBuffer
471 )
472 {
473 FRAMEWORK_EFI_IFR_BANNER Banner;
474
475 Banner.Header.OpCode = FRAMEWORK_EFI_IFR_BANNER_OP;
476 Banner.Header.Length = sizeof (FRAMEWORK_EFI_IFR_BANNER);
477 CopyMem (&Banner.Title, &Title, sizeof (UINT16));
478 CopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16));
479 Banner.Alignment = Alignment;
480
481 CopyMem (FormBuffer, &Banner, sizeof (FRAMEWORK_EFI_IFR_BANNER));
482
483 return EFI_SUCCESS;
484 }
485
486