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