3 This is an example of how a driver might export data to the HII protocol to be
4 later utilized by the Setup Protocol
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "DriverSample.h"
20 #define DISPLAY_ONLY_MY_ITEM 0x0001
22 #define STRING_PACK_GUID \
24 0x8160a85f, 0x934d, 0x468b, { 0xa2, 0x35, 0x72, 0x89, 0x59, 0x14, 0xf6, 0xfc } \
27 EFI_GUID mFormSetGuid
= FORMSET_GUID
;
28 EFI_GUID mStringPackGuid
= STRING_PACK_GUID
;
34 IN EFI_FORM_CALLBACK_PROTOCOL
*This
,
36 IN EFI_IFR_DATA_ARRAY
*Data
,
37 OUT EFI_HII_CALLBACK_PACKET
**Packet
43 This is the function that is called to provide results data to the driver. This data
44 consists of a unique key which is used to identify what data is either being passed back
49 KeyValue - A unique value which is sent to the original exporting driver so that it
50 can identify the type of data to expect. The format of the data tends to
51 vary based on the op-code that geerated the callback.
53 Data - A pointer to the data being sent to the original exporting driver.
59 EFI_CALLBACK_INFO
*Private
;
60 EFI_HII_UPDATE_DATA
*UpdateData
;
62 EFI_HII_CALLBACK_PACKET
*DataPacket
;
64 CHAR16 VariableName
[40];
65 STATIC UINT16 QuestionId
= 0;
66 IFR_OPTION
*OptionList
;
70 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
73 // This should tell me the first offset AFTER the end of the compiled NV map
74 // If op-code results are not going to be saved to NV locations ensure the QuestionId
75 // is beyond the end of the NVRAM mapping.
77 if (QuestionId
== 0) {
78 QuestionId
= sizeof (MyIfrNVData
);
81 ZeroMem (VariableName
, (sizeof (CHAR16
) * 40));
86 // Create a small boot order list
88 QuestionId
= (UINT16
) ((UINTN
) (&NVStruc
.BootOrder
) - (UINTN
) (&NVStruc
));
91 // Need some memory for OptionList. Allow for up to 8 options.
93 OptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * 8);
94 ASSERT (OptionList
!= NULL
);
97 // Allocate space for creation of Buffer
99 UpdateData
= AllocateZeroPool (0x1000);
100 ASSERT (UpdateData
!= NULL
);
103 // Remove all the op-codes starting with Label 0x2222 to next Label (second label is for convenience
104 // so we don't have to keep track of how many op-codes we added or subtracted. The rules for removal
105 // of op-codes are simply that the removal will always stop as soon as a label or the end of a form is
106 // encountered. Therefore, giving a large obnoxious count such as below takes care of other complexities.
108 UpdateData
->DataCount
= 0xFF;
111 // Delete set of op-codes
113 Private
->Hii
->UpdateForm (
115 Private
->RegisteredHandle
,
116 (EFI_FORM_LABEL
) 0x2222,
117 FALSE
, // If we aren't adding, we are deleting
124 for (Index
= 0; Index
< 3; Index
++) {
125 OptionList
[Index
].StringToken
= (UINT16
) (STR_BOOT_OPTION1
+ Index
);
126 OptionList
[Index
].Value
= (UINT16
) (Index
+ 1);
127 OptionList
[Index
].Flags
= RESET_REQUIRED
;
130 CreateOrderedListOpCode (
131 QuestionId
, // Question ID
133 (UINT16
) STRING_TOKEN (STR_BOOT_OPTIONS
), // Token value for the Prompt
134 (UINT16
) STRING_TOKEN (STR_NULL_STRING
), // Token value for the Help
137 &UpdateData
->Data
// Buffer location to place op-codes
141 // For one-of/ordered lists commands, they really consist of 2 op-codes (a header and a footer)
142 // Each option within a one-of/ordered list is also an op-code
143 // So this example has 5 op-codes it is adding since we have a one-of header + 3 options + one-of footer
145 UpdateData
->DataCount
= 0x5;
150 Private
->Hii
->UpdateForm (
152 Private
->RegisteredHandle
,
153 (EFI_FORM_LABEL
) 0x2222,
158 FreePool (UpdateData
);
159 FreePool (OptionList
);
164 // Create a large boot order list
166 QuestionId
= (UINT16
) ((UINTN
) (&NVStruc
.BootOrder
) - (UINTN
) (&NVStruc
));
169 // Need some memory for OptionList. Allow for up to 8 options.
171 OptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * 8);
172 ASSERT (OptionList
!= NULL
);
175 // Allocate space for creation of Buffer
177 UpdateData
= AllocateZeroPool (0x1000);
178 ASSERT (UpdateData
!= NULL
);
181 // Remove all the op-codes starting with Label 0x2222 to next Label (second label is for convenience
182 // so we don't have to keep track of how many op-codes we added or subtracted
184 UpdateData
->DataCount
= 0xFF;
187 // Delete one op-code
189 Private
->Hii
->UpdateForm (
191 Private
->RegisteredHandle
,
192 (EFI_FORM_LABEL
) 0x2222,
200 for (Index
= 0; Index
< 4; Index
++) {
201 OptionList
[Index
].StringToken
= (UINT16
) (STR_BOOT_OPTION1
+ Index
);
202 OptionList
[Index
].Value
= (UINT16
) (Index
+ 1);
203 OptionList
[Index
].Flags
= RESET_REQUIRED
;
206 CreateOrderedListOpCode (
207 QuestionId
, // Question ID
209 (UINT16
) STRING_TOKEN (STR_BOOT_OPTIONS
), // Token value for the Prompt
210 (UINT16
) STRING_TOKEN (STR_NULL_STRING
), // Token value for the Help
213 &UpdateData
->Data
// Buffer location to place op-codes
217 // For one-of commands, they really consist of 2 op-codes (a header and a footer)
218 // Each option within a one-of is also an op-code
219 // So this example has 6 op-codes it is adding since we have a one-of header + 4 options + one-of footer
221 UpdateData
->DataCount
= 0x6;
226 Private
->Hii
->UpdateForm (
228 Private
->RegisteredHandle
,
229 (EFI_FORM_LABEL
) 0x2222,
234 FreePool (UpdateData
);
235 FreePool (OptionList
);
240 // Allocate space for creation of Buffer
242 QuestionId
= (UINT16
) ((UINTN
) (&NVStruc
.DynamicCheck
) - (UINTN
) (&NVStruc
));
243 UpdateData
= AllocateZeroPool (0x1000);
244 ASSERT (UpdateData
!= NULL
);
246 Location
= (UINT8
*) &UpdateData
->Data
;
248 UpdateData
->FormSetUpdate
= TRUE
;
249 UpdateData
->FormCallbackHandle
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Private
->CallbackHandle
;
250 UpdateData
->FormUpdate
= FALSE
;
251 UpdateData
->FormTitle
= 0;
252 UpdateData
->DataCount
= 2;
256 STR_GOTO_FORM1
, // Token value for the Prompt
260 &UpdateData
->Data
// Buffer location to place op-codes
263 Location
= Location
+ ((EFI_IFR_OP_HEADER
*) &UpdateData
->Data
)->Length
;
265 CreateCheckBoxOpCode (
266 QuestionId
, // Question ID
267 1, // Data width (BOOLEAN = 1)
268 (UINT16
) STRING_TOKEN (STR_CHECK_DYNAMIC_PROMPT
), // Token value for the Prompt
269 (UINT16
) STRING_TOKEN (STR_CHECK_DYNAMIC_HELP
), // Token value for the Help
270 EFI_IFR_FLAG_INTERACTIVE
, // Flags
272 Location
// Buffer location to place op-codes
275 Private
->Hii
->UpdateForm (
277 Private
->RegisteredHandle
,
278 (EFI_FORM_LABEL
) 0x1234,
283 FreePool (UpdateData
);
289 // Allocate space for creation of Buffer
291 UpdateData
= AllocateZeroPool (0x1000);
292 ASSERT (UpdateData
!= NULL
);
295 // Initialize DataPacket with information intended to remove all
296 // previously created op-codes in the dynamic page
298 UpdateData
->FormSetUpdate
= FALSE
;
299 UpdateData
->FormCallbackHandle
= 0;
300 UpdateData
->FormUpdate
= FALSE
;
301 UpdateData
->FormTitle
= 0;
303 // Unlikely to be more than 0xff op-codes in the dynamic page to remove
305 UpdateData
->DataCount
= 0xff;
306 UpdateData
->Data
= NULL
;
309 // Remove all op-codes from dynamic page
311 Private
->Hii
->UpdateForm (
313 Private
->RegisteredHandle
,
314 (EFI_FORM_LABEL
) 0x1234, // Label 0x1234
315 FALSE
, // Remove Op-codes (will never remove form/endform)
316 UpdateData
// Significant value is UpdateData->DataCount
319 UpdateData
->FormSetUpdate
= FALSE
;
320 UpdateData
->FormCallbackHandle
= 0;
321 UpdateData
->FormUpdate
= FALSE
;
322 UpdateData
->FormTitle
= 0;
323 UpdateData
->DataCount
= 1;
327 STR_GOTO_FORM1
, // Token value for the Prompt
331 &UpdateData
->Data
// Buffer location to place op-codes
334 Private
->Hii
->UpdateForm (
336 Private
->RegisteredHandle
,
337 (EFI_FORM_LABEL
) 0x1234,
342 FreePool (UpdateData
);
347 // If I hit the checkbox, I enter this case statement...
350 // Since I am returning an error (for test purposes) I need to pass in the string for the error
351 // I will allocate space for the return value. If an error occurs (which is the case) I can simply return
352 // an error and fill in the string parameter, otherwise, I will return information in the DataArray structure.
353 // The browser will free this packet structure
355 *Packet
= AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET
) + sizeof (SAMPLE_STRING
) + 2);
356 ASSERT (*Packet
!= NULL
);
359 // Assign the buffer address to DataPacket
361 DataPacket
= *Packet
;
363 StrCpy (DataPacket
->String
, (CHAR16
*) SAMPLE_STRING
);
364 return EFI_DEVICE_ERROR
;
368 *Packet
= AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET
) + 2);
369 ASSERT (*Packet
!= NULL
);
372 // Assign the buffer address to DataPacket
374 DataPacket
= *Packet
;
376 DataPacket
->DataArray
.EntryCount
= 1;
377 DataPacket
->DataArray
.NvRamMap
= NULL
;
378 ((EFI_IFR_DATA_ENTRY
*) (&DataPacket
->DataArray
+ 1))->Flags
= EXIT_REQUIRED
;
383 UnicodeSPrint (VariableName
, 0x80, (CHAR16
*) L
"%d", VAR_EQ_TEST_NAME
);
388 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
396 UnicodeSPrint (VariableName
, 0x80, (CHAR16
*) L
"%d", VAR_EQ_TEST_NAME
);
401 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
409 UnicodeSPrint (VariableName
, 0x80, (CHAR16
*) L
"%d", VAR_EQ_TEST_NAME
);
414 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
430 IN EFI_HANDLE ImageHandle
,
431 IN EFI_SYSTEM_TABLE
*SystemTable
435 EFI_HII_PROTOCOL
*Hii
;
437 // EFI_FORM_BROWSER_PROTOCOL *FormConfig;
439 EFI_HII_PACKAGES
*PackageList
;
440 EFI_HII_HANDLE HiiHandle
;
441 STRING_REF TokenToUpdate
;
442 STRING_REF TokenToUpdate2
;
443 STRING_REF TokenToUpdate3
;
445 EFI_HII_UPDATE_DATA
*UpdateData
;
446 EFI_CALLBACK_INFO
*CallbackInfo
;
448 EFI_SCREEN_DESCRIPTOR Screen
;
450 ZeroMem (&Screen
, sizeof (EFI_SCREEN_DESCRIPTOR
));
452 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Screen
.RightColumn
, &Screen
.BottomRow
);
455 // Remove 3 characters from top and bottom
458 Screen
.BottomRow
= Screen
.BottomRow
- 3;
461 // There should only be one HII protocol
463 Status
= gBS
->LocateProtocol (
464 &gEfiHiiProtocolGuid
,
468 if (EFI_ERROR (Status
)) {
472 CallbackInfo
= AllocatePool (sizeof (EFI_CALLBACK_INFO
));
473 if (CallbackInfo
== NULL
) {
474 return EFI_OUT_OF_RESOURCES
;
477 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
478 CallbackInfo
->Hii
= Hii
;
481 // This example does not implement worker functions for the NV accessor functions. Only a callback evaluator
483 CallbackInfo
->DriverCallback
.NvRead
= NULL
;
484 CallbackInfo
->DriverCallback
.NvWrite
= NULL
;
485 CallbackInfo
->DriverCallback
.Callback
= DriverCallback
;
488 // Install protocol interface
491 Status
= gBS
->InstallProtocolInterface (
493 &gEfiFormCallbackProtocolGuid
,
494 EFI_NATIVE_INTERFACE
,
495 &CallbackInfo
->DriverCallback
498 ASSERT_EFI_ERROR (Status
);
500 CallbackInfo
->CallbackHandle
= Handle
;
502 PackageList
= PreparePackages (1, &mStringPackGuid
, DriverSampleDxeStrings
);
503 Status
= Hii
->NewPack (Hii
, PackageList
, &HiiHandle
);
504 FreePool (PackageList
);
506 PackageList
= PreparePackages (1, &mStringPackGuid
, InventoryBin
);
507 Status
= Hii
->NewPack (Hii
, PackageList
, &HiiHandle
);
508 FreePool (PackageList
);
510 PackageList
= PreparePackages (1, &mStringPackGuid
, VfrBin
);
511 Status
= Hii
->NewPack (Hii
, PackageList
, &HiiHandle
);
512 FreePool (PackageList
);
514 CallbackInfo
->RegisteredHandle
= HiiHandle
;
517 // Very simple example of how one would update a string that is already
518 // in the HII database
520 TokenToUpdate
= (STRING_REF
) STR_CPU_STRING2
;
521 NewString
= (CHAR16
*) L
"700 Mhz";
523 Hii
->NewString (Hii
, NULL
, HiiHandle
, &TokenToUpdate
, NewString
);
526 // Add a string - if 0 will be updated with new Token number
528 TokenToUpdate
= (STRING_REF
) 0;
531 // Add a string - if 0 will be updated with new Token number
533 TokenToUpdate2
= (STRING_REF
) 0;
536 // Add a string - if 0 will be updated with new Token number
538 TokenToUpdate3
= (STRING_REF
) 0;
540 Hii
->NewString (Hii
, NULL
, HiiHandle
, &TokenToUpdate
, (CHAR16
*) L
"Desired Speed");
541 Hii
->NewString (Hii
, NULL
, HiiHandle
, &TokenToUpdate2
, (CHAR16
*) L
"5 Thz");
542 Hii
->NewString (Hii
, NULL
, HiiHandle
, &TokenToUpdate3
, (CHAR16
*) L
"This is next year's desired speed - right?");
545 // Allocate space for creation of Buffer
547 UpdateData
= AllocateZeroPool (0x1000);
548 ASSERT (UpdateData
!= NULL
);
551 // Flag update pending in FormSet
553 UpdateData
->FormSetUpdate
= TRUE
;
555 // Register CallbackHandle data for FormSet
557 UpdateData
->FormCallbackHandle
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) CallbackInfo
->CallbackHandle
;
558 UpdateData
->FormUpdate
= FALSE
;
559 UpdateData
->FormTitle
= 0;
560 UpdateData
->DataCount
= 1;
562 CreateTextOpCode (TokenToUpdate
, TokenToUpdate2
, TokenToUpdate3
, 0, 0, &UpdateData
->Data
);
564 Hii
->UpdateForm (Hii
, HiiHandle
, (EFI_FORM_LABEL
) 100, TRUE
, UpdateData
);
566 FreePool (UpdateData
);
569 // Example of how to display only the item we sent to HII
571 if (DISPLAY_ONLY_MY_ITEM
== 0x0001) {
573 // Have the browser pull out our copy of the data, and only display our data
575 // Status = FormConfig->SendForm (FormConfig, TRUE, HiiHandle, NULL, NULL, NULL, &Screen, NULL);
579 // Have the browser pull out all the data in the HII Database and display it.
581 // Status = FormConfig->SendForm (FormConfig, TRUE, 0, NULL, NULL, NULL, NULL, NULL);
585 if (EFI_ERROR (Status
)) {