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