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