3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The platform device manager reference implement
22 // Include common header file for this module.
24 #include "CommonHeader.h"
26 #include "DeviceManager.h"
28 STATIC UINT16 mTokenCount
;
29 EFI_FRONTPAGE_CALLBACK_INFO FPCallbackInfo
;
30 extern UINTN gCallbackKey
;
31 extern EFI_FORM_BROWSER_PROTOCOL
*gBrowser
;
32 extern EFI_GUID gBdsStringPackGuid
;
33 extern BOOLEAN gConnectAllHappened
;
35 STRING_REF gStringTokenTable
[] = {
47 DeviceManagerCallbackRoutine (
48 IN EFI_FORM_CALLBACK_PROTOCOL
*This
,
50 IN EFI_IFR_DATA_ARRAY
*DataArray
,
51 OUT EFI_HII_CALLBACK_PACKET
**Packet
57 This is the function that is called to provide results data to the driver. This data
58 consists of a unique key which is used to identify what data is either being passed back
63 KeyValue - A unique value which is sent to the original exporting driver so that it
64 can identify the type of data to expect. The format of the data tends to
65 vary based on the op-code that geerated the callback.
67 Data - A pointer to the data being sent to the original exporting driver.
74 // The KeyValue corresponds in this case to the handle which was requested to be displayed
76 EFI_FRONTPAGE_CALLBACK_INFO
*CallbackInfo
;
78 CallbackInfo
= EFI_FP_CALLBACK_DATA_FROM_THIS (This
);
81 CallbackInfo
->Data
.VideoBIOS
= (UINT8
) (UINTN
) (((EFI_IFR_DATA_ENTRY
*)(DataArray
+ 1))->Data
);
84 &gEfiGenericPlatformVariableGuid
,
85 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
87 &CallbackInfo
->Data
.VideoBIOS
95 gCallbackKey
= KeyValue
;
100 InitializeDeviceManager (
107 Initialize HII information for the FrontPage
117 EFI_HII_PACKAGES
*PackageList
;
118 EFI_HII_UPDATE_DATA
*UpdateData
;
121 // Allocate space for creation of UpdateData Buffer
123 UpdateData
= AllocateZeroPool (0x1000);
124 ASSERT (UpdateData
!= NULL
);
126 PackageList
= PreparePackages (1, &gBdsStringPackGuid
, DeviceManagerVfrBin
);
127 Status
= Hii
->NewPack (Hii
, PackageList
, &FPCallbackInfo
.DevMgrHiiHandle
);
128 FreePool (PackageList
);
131 // This example does not implement worker functions for the NV accessor functions. Only a callback evaluator
133 FPCallbackInfo
.Signature
= EFI_FP_CALLBACK_DATA_SIGNATURE
;
134 FPCallbackInfo
.DevMgrCallback
.NvRead
= NULL
;
135 FPCallbackInfo
.DevMgrCallback
.NvWrite
= NULL
;
136 FPCallbackInfo
.DevMgrCallback
.Callback
= DeviceManagerCallbackRoutine
;
139 // Install protocol interface
141 FPCallbackInfo
.CallbackHandle
= NULL
;
143 Status
= gBS
->InstallProtocolInterface (
144 &FPCallbackInfo
.CallbackHandle
,
145 &gEfiFormCallbackProtocolGuid
,
146 EFI_NATIVE_INTERFACE
,
147 &FPCallbackInfo
.DevMgrCallback
150 ASSERT_EFI_ERROR (Status
);
153 // Flag update pending in FormSet
155 UpdateData
->FormSetUpdate
= TRUE
;
157 // Register CallbackHandle data for FormSet
159 UpdateData
->FormCallbackHandle
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) FPCallbackInfo
.CallbackHandle
;
161 // Simply registering the callback handle
163 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) 0x0000, TRUE
, UpdateData
);
165 FreePool (UpdateData
);
177 Call the browser and display the device manager
184 EFI_SUCCESS - Operation is successful.
185 EFI_INVALID_PARAMETER - If the inputs to SendForm function is not valid.
192 EFI_HII_HANDLE Index
;
194 EFI_IFR_FORM_SET
*FormSetData
;
197 EFI_HII_UPDATE_DATA
*UpdateData
;
199 STRING_REF TokenHelp
;
200 IFR_OPTION
*IfrOptionList
;
202 UINTN VideoOptionSize
;
203 EFI_HII_HANDLE
*HiiHandles
;
204 UINT16 HandleBufferLength
;
205 BOOLEAN BootDeviceMngrMenuResetRequired
;
207 IfrOptionList
= NULL
;
210 HandleBufferLength
= 0;
213 // Connect all prior to entering the platform setup menu.
215 if (!gConnectAllHappened
) {
216 BdsLibConnectAllDriversToAllControllers ();
217 gConnectAllHappened
= TRUE
;
220 // Allocate space for creation of UpdateData Buffer
222 UpdateData
= AllocateZeroPool (0x1000);
223 ASSERT (UpdateData
!= NULL
);
225 Status
= EFI_SUCCESS
;
229 if (mTokenCount
== 0) {
230 Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &mTokenCount
, L
" ");
234 TokenHelp
= (UINT16
) (Token
+ 1);
239 for (Index
= 0, Count
= 1; Count
< 0x10000; Count
<<= 1, Index
++) {
241 // We will strip off all previous menu entries
243 UpdateData
->DataCount
= 0xFF;
246 // Erase entries on this label
248 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, FALSE
, UpdateData
);
251 // Did we reach the end of the Token Table?
253 if (gStringTokenTable
[Index
] == 0xFFFF) {
257 CreateSubTitleOpCode (gStringTokenTable
[Index
], &UpdateData
->Data
);
259 // Add a single menu item - in this case a subtitle for the device type
261 UpdateData
->DataCount
= 1;
264 // Add default title for this label
266 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, TRUE
, UpdateData
);
269 // Add a space and an exit string. Remember since we add things at the label and push other things beyond the
270 // label down, we add this in reverse order
272 CreateSubTitleOpCode (STRING_TOKEN (STR_EXIT_STRING
), &UpdateData
->Data
);
273 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, TRUE
, UpdateData
);
274 CreateSubTitleOpCode (STR_EMPTY_STRING
, &UpdateData
->Data
);
275 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, TRUE
, UpdateData
);
278 // Get all the Hii handles
280 Status
= BdsLibGetHiiHandles (Hii
, &HandleBufferLength
, &HiiHandles
);
281 ASSERT_EFI_ERROR (Status
);
283 for (Index
= 1, BufferSize
= 0; Index
< HandleBufferLength
; Index
++) {
285 // Am not initializing Buffer since the first thing checked is the size
286 // this way I can get the real buffersize in the smallest code size
288 Status
= Hii
->GetForms (Hii
, Index
, 0, &BufferSize
, Buffer
);
290 if (Status
!= EFI_NOT_FOUND
) {
292 // BufferSize should have the real size of the forms now
294 Buffer
= AllocateZeroPool (BufferSize
);
295 ASSERT (Buffer
!= NULL
);
298 // Am not initializing Buffer since the first thing checked is the size
299 // this way I can get the real buffersize in the smallest code size
301 Status
= Hii
->GetForms (Hii
, Index
, 0, &BufferSize
, Buffer
);
304 // Skip EFI_HII_PACK_HEADER, advance to EFI_IFR_FORM_SET data.
306 FormSetData
= (EFI_IFR_FORM_SET
*) (Buffer
+ sizeof (EFI_HII_PACK_HEADER
));
309 // If this formset belongs in the device manager, add it to the menu
311 if (FormSetData
->Class
!= EFI_NON_DEVICE_CLASS
) {
313 StringLength
= 0x1000;
314 String
= AllocateZeroPool (StringLength
);
315 ASSERT (String
!= NULL
);
317 Status
= Hii
->GetString (Hii
, Index
, FormSetData
->FormSetTitle
, TRUE
, NULL
, &StringLength
, String
);
318 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &Token
, String
);
321 // If token value exceeded real token value - we need to add a new token values
323 if (Status
== EFI_INVALID_PARAMETER
) {
326 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &Token
, String
);
329 StringLength
= 0x1000;
330 if (FormSetData
->Help
== 0) {
333 Status
= Hii
->GetString (Hii
, Index
, FormSetData
->Help
, TRUE
, NULL
, &StringLength
, String
);
334 if (StringLength
== 0x02) {
337 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &TokenHelp
, String
);
338 if (Status
== EFI_INVALID_PARAMETER
) {
340 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &TokenHelp
, String
);
348 0x1000, // Device Manager Page
349 Token
, // Description String Token
350 TokenHelp
, // Description Help String Token
351 EFI_IFR_FLAG_INTERACTIVE
| EFI_IFR_FLAG_NV_ACCESS
, // Flag designating callback is active
352 (UINT16
) Index
, // Callback key value
353 &UpdateData
->Data
// Buffer to fill with op-code
357 // In the off-chance that we have lots of extra tokens allocated to the DeviceManager
358 // this ensures we are fairly re-using the tokens instead of constantly growing the token
359 // storage for this one handle. If we incremented the token value beyond what it normally
360 // would use, we will fall back into the error path which seeds the token value with a 0
361 // so that we can correctly add a token value.
363 if (TokenHelp
== 0) {
365 // Since we didn't add help, only advance Token by 1
369 Token
= (UINT16
) (Token
+ 2);
370 TokenHelp
= (UINT16
) (TokenHelp
+ 2);
373 // This for loop basically will take the Class value which is a bitmask and
374 // update the form for every active bit. There will be a label at each bit
375 // location. So if someone had a device which a class of EFI_DISK_DEVICE_CLASS |
376 // EFI_ON_BOARD_DEVICE_CLASS, this routine will unwind that mask and drop the menu entry
377 // on each corresponding label.
379 for (Count
= 1; Count
< 0x10000; Count
<<= 1) {
381 // This is an active bit, so update the form
383 if (FormSetData
->Class
& Count
) {
386 FPCallbackInfo
.DevMgrHiiHandle
,
387 (EFI_FORM_LABEL
) (FormSetData
->Class
& Count
),
397 // Reset Buffer pointer to original location
403 // Add oneof for video BIOS selection
405 VideoOption
= BdsLibGetVariableAndSize (
407 &gEfiGenericPlatformVariableGuid
,
410 if (NULL
== VideoOption
) {
411 FPCallbackInfo
.Data
.VideoBIOS
= 0;
413 FPCallbackInfo
.Data
.VideoBIOS
= VideoOption
[0];
414 FreePool (VideoOption
);
417 ASSERT (FPCallbackInfo
.Data
.VideoBIOS
<= 1);
419 IfrOptionList
= AllocatePool (2 * sizeof (IFR_OPTION
));
420 if (IfrOptionList
!= NULL
) {
421 IfrOptionList
[0].Flags
= EFI_IFR_FLAG_INTERACTIVE
;
422 IfrOptionList
[0].Key
= SET_VIDEO_BIOS_TYPE_QUESTION_ID
+ 0x2000;
423 IfrOptionList
[0].StringToken
= STRING_TOKEN (STR_ONE_OF_PCI
);
424 IfrOptionList
[0].Value
= 0;
425 IfrOptionList
[0].OptionString
= NULL
;
426 IfrOptionList
[1].Flags
= EFI_IFR_FLAG_INTERACTIVE
;
427 IfrOptionList
[1].Key
= SET_VIDEO_BIOS_TYPE_QUESTION_ID
+ 0x2000;
428 IfrOptionList
[1].StringToken
= STRING_TOKEN (STR_ONE_OF_AGP
);
429 IfrOptionList
[1].Value
= 1;
430 IfrOptionList
[1].OptionString
= NULL
;
431 IfrOptionList
[FPCallbackInfo
.Data
.VideoBIOS
].Flags
|= EFI_IFR_FLAG_DEFAULT
;
434 SET_VIDEO_BIOS_TYPE_QUESTION_ID
,
436 STRING_TOKEN (STR_ONE_OF_VBIOS
),
437 STRING_TOKEN (STR_ONE_OF_VBIOS_HELP
),
443 UpdateData
->DataCount
= 4;
444 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) EFI_VBIOS_CLASS
, TRUE
, UpdateData
);
445 FreePool (IfrOptionList
);
448 BootDeviceMngrMenuResetRequired
= FALSE
;
449 Status
= gBrowser
->SendForm (
451 TRUE
, // Use the database
452 &FPCallbackInfo
.DevMgrHiiHandle
, // The HII Handle
455 FPCallbackInfo
.CallbackHandle
,
456 (UINT8
*) &FPCallbackInfo
.Data
,
458 &BootDeviceMngrMenuResetRequired
461 if (BootDeviceMngrMenuResetRequired
) {
462 EnableResetRequired ();
465 Hii
->ResetStrings (Hii
, FPCallbackInfo
.DevMgrHiiHandle
);
468 // We will have returned from processing a callback - user either hit ESC to exit, or selected
469 // a target to display
471 if (gCallbackKey
!= 0 && gCallbackKey
< 0x2000) {
472 BootDeviceMngrMenuResetRequired
= FALSE
;
473 Status
= gBrowser
->SendForm (
475 TRUE
, // Use the database
476 (EFI_HII_HANDLE
*) &gCallbackKey
, // The HII Handle
479 NULL
, // This is the handle that the interface to the callback was installed on
482 &BootDeviceMngrMenuResetRequired
485 if (BootDeviceMngrMenuResetRequired
) {
486 EnableResetRequired ();
489 // Force return to Device Manager
494 if (gCallbackKey
>= 0x2000) {
498 FreePool (UpdateData
);
499 FreePool (HiiHandles
);