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