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"
25 #include "DeviceManager.h"
27 STATIC UINT16 mTokenCount
;
28 EFI_FRONTPAGE_CALLBACK_INFO FPCallbackInfo
;
29 extern UINTN gCallbackKey
;
30 extern EFI_FORM_BROWSER_PROTOCOL
*gBrowser
;
31 extern EFI_GUID gBdsStringPackGuid
;
32 extern BOOLEAN gConnectAllHappened
;
34 STRING_REF gStringTokenTable
[] = {
46 DeviceManagerCallbackRoutine (
47 IN EFI_FORM_CALLBACK_PROTOCOL
*This
,
49 IN EFI_IFR_DATA_ARRAY
*DataArray
,
50 OUT EFI_HII_CALLBACK_PACKET
**Packet
56 This is the function that is called to provide results data to the driver. This data
57 consists of a unique key which is used to identify what data is either being passed back
62 KeyValue - A unique value which is sent to the original exporting driver so that it
63 can identify the type of data to expect. The format of the data tends to
64 vary based on the op-code that geerated the callback.
66 Data - A pointer to the data being sent to the original exporting driver.
73 // The KeyValue corresponds in this case to the handle which was requested to be displayed
75 EFI_FRONTPAGE_CALLBACK_INFO
*CallbackInfo
;
77 CallbackInfo
= EFI_FP_CALLBACK_DATA_FROM_THIS (This
);
80 CallbackInfo
->Data
.VideoBIOS
= (UINT8
) (UINTN
) (((EFI_IFR_DATA_ENTRY
*)(DataArray
+ 1))->Data
);
83 &gEfiGenericPlatformVariableGuid
,
84 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
86 &CallbackInfo
->Data
.VideoBIOS
94 gCallbackKey
= KeyValue
;
99 InitializeDeviceManager (
106 Initialize HII information for the FrontPage
116 EFI_HII_PACKAGES
*PackageList
;
117 EFI_HII_UPDATE_DATA
*UpdateData
;
120 // Allocate space for creation of UpdateData Buffer
122 UpdateData
= AllocateZeroPool (0x1000);
123 ASSERT (UpdateData
!= NULL
);
125 PackageList
= PreparePackages (1, &gBdsStringPackGuid
, DeviceManagerVfrBin
);
126 Status
= Hii
->NewPack (Hii
, PackageList
, &FPCallbackInfo
.DevMgrHiiHandle
);
127 FreePool (PackageList
);
130 // This example does not implement worker functions for the NV accessor functions. Only a callback evaluator
132 FPCallbackInfo
.Signature
= EFI_FP_CALLBACK_DATA_SIGNATURE
;
133 FPCallbackInfo
.DevMgrCallback
.NvRead
= NULL
;
134 FPCallbackInfo
.DevMgrCallback
.NvWrite
= NULL
;
135 FPCallbackInfo
.DevMgrCallback
.Callback
= DeviceManagerCallbackRoutine
;
138 // Install protocol interface
140 FPCallbackInfo
.CallbackHandle
= NULL
;
142 Status
= gBS
->InstallProtocolInterface (
143 &FPCallbackInfo
.CallbackHandle
,
144 &gEfiFormCallbackProtocolGuid
,
145 EFI_NATIVE_INTERFACE
,
146 &FPCallbackInfo
.DevMgrCallback
149 ASSERT_EFI_ERROR (Status
);
152 // Flag update pending in FormSet
154 UpdateData
->FormSetUpdate
= TRUE
;
156 // Register CallbackHandle data for FormSet
158 UpdateData
->FormCallbackHandle
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) FPCallbackInfo
.CallbackHandle
;
160 // Simply registering the callback handle
162 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) 0x0000, TRUE
, UpdateData
);
164 FreePool (UpdateData
);
176 Call the browser and display the device manager
183 EFI_SUCCESS - Operation is successful.
184 EFI_INVALID_PARAMETER - If the inputs to SendForm function is not valid.
191 EFI_HII_HANDLE Index
;
193 EFI_IFR_FORM_SET
*FormSetData
;
196 EFI_HII_UPDATE_DATA
*UpdateData
;
198 STRING_REF TokenHelp
;
199 IFR_OPTION
*IfrOptionList
;
201 UINTN VideoOptionSize
;
202 EFI_HII_HANDLE
*HiiHandles
;
203 UINT16 HandleBufferLength
;
204 BOOLEAN BootDeviceMngrMenuResetRequired
;
206 IfrOptionList
= NULL
;
209 HandleBufferLength
= 0;
212 // Connect all prior to entering the platform setup menu.
214 if (!gConnectAllHappened
) {
215 BdsLibConnectAllDriversToAllControllers ();
216 gConnectAllHappened
= TRUE
;
219 // Allocate space for creation of UpdateData Buffer
221 UpdateData
= AllocateZeroPool (0x1000);
222 ASSERT (UpdateData
!= NULL
);
224 Status
= EFI_SUCCESS
;
228 if (mTokenCount
== 0) {
229 Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &mTokenCount
, L
" ");
233 TokenHelp
= (UINT16
) (Token
+ 1);
238 for (Index
= 0, Count
= 1; Count
< 0x10000; Count
<<= 1, Index
++) {
240 // We will strip off all previous menu entries
242 UpdateData
->DataCount
= 0xFF;
245 // Erase entries on this label
247 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, FALSE
, UpdateData
);
250 // Did we reach the end of the Token Table?
252 if (gStringTokenTable
[Index
] == 0xFFFF) {
256 CreateSubTitleOpCode (gStringTokenTable
[Index
], &UpdateData
->Data
);
258 // Add a single menu item - in this case a subtitle for the device type
260 UpdateData
->DataCount
= 1;
263 // Add default title for this label
265 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, TRUE
, UpdateData
);
268 // Add a space and an exit string. Remember since we add things at the label and push other things beyond the
269 // label down, we add this in reverse order
271 CreateSubTitleOpCode (STRING_TOKEN (STR_EXIT_STRING
), &UpdateData
->Data
);
272 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, TRUE
, UpdateData
);
273 CreateSubTitleOpCode (STR_EMPTY_STRING
, &UpdateData
->Data
);
274 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) Count
, TRUE
, UpdateData
);
277 // Get all the Hii handles
279 Status
= BdsLibGetHiiHandles (Hii
, &HandleBufferLength
, &HiiHandles
);
280 ASSERT_EFI_ERROR (Status
);
282 for (Index
= 1, BufferSize
= 0; Index
< HandleBufferLength
; Index
++) {
284 // Am not initializing Buffer since the first thing checked is the size
285 // this way I can get the real buffersize in the smallest code size
287 Status
= Hii
->GetForms (Hii
, Index
, 0, &BufferSize
, Buffer
);
289 if (Status
!= EFI_NOT_FOUND
) {
291 // BufferSize should have the real size of the forms now
293 Buffer
= AllocateZeroPool (BufferSize
);
294 ASSERT (Buffer
!= NULL
);
297 // Am not initializing Buffer since the first thing checked is the size
298 // this way I can get the real buffersize in the smallest code size
300 Status
= Hii
->GetForms (Hii
, Index
, 0, &BufferSize
, Buffer
);
303 // Skip EFI_HII_PACK_HEADER, advance to EFI_IFR_FORM_SET data.
305 FormSetData
= (EFI_IFR_FORM_SET
*) (Buffer
+ sizeof (EFI_HII_PACK_HEADER
));
308 // If this formset belongs in the device manager, add it to the menu
310 if (FormSetData
->Class
!= EFI_NON_DEVICE_CLASS
) {
312 StringLength
= 0x1000;
313 String
= AllocateZeroPool (StringLength
);
314 ASSERT (String
!= NULL
);
316 Status
= Hii
->GetString (Hii
, Index
, FormSetData
->FormSetTitle
, TRUE
, NULL
, &StringLength
, String
);
317 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &Token
, String
);
320 // If token value exceeded real token value - we need to add a new token values
322 if (Status
== EFI_INVALID_PARAMETER
) {
325 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &Token
, String
);
328 StringLength
= 0x1000;
329 if (FormSetData
->Help
== 0) {
332 Status
= Hii
->GetString (Hii
, Index
, FormSetData
->Help
, TRUE
, NULL
, &StringLength
, String
);
333 if (StringLength
== 0x02) {
336 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &TokenHelp
, String
);
337 if (Status
== EFI_INVALID_PARAMETER
) {
339 Status
= Hii
->NewString (Hii
, NULL
, FPCallbackInfo
.DevMgrHiiHandle
, &TokenHelp
, String
);
347 0x1000, // Device Manager Page
348 Token
, // Description String Token
349 TokenHelp
, // Description Help String Token
350 EFI_IFR_FLAG_INTERACTIVE
| EFI_IFR_FLAG_NV_ACCESS
, // Flag designating callback is active
351 (UINT16
) Index
, // Callback key value
352 &UpdateData
->Data
// Buffer to fill with op-code
356 // In the off-chance that we have lots of extra tokens allocated to the DeviceManager
357 // this ensures we are fairly re-using the tokens instead of constantly growing the token
358 // storage for this one handle. If we incremented the token value beyond what it normally
359 // would use, we will fall back into the error path which seeds the token value with a 0
360 // so that we can correctly add a token value.
362 if (TokenHelp
== 0) {
364 // Since we didn't add help, only advance Token by 1
368 Token
= (UINT16
) (Token
+ 2);
369 TokenHelp
= (UINT16
) (TokenHelp
+ 2);
372 // This for loop basically will take the Class value which is a bitmask and
373 // update the form for every active bit. There will be a label at each bit
374 // location. So if someone had a device which a class of EFI_DISK_DEVICE_CLASS |
375 // EFI_ON_BOARD_DEVICE_CLASS, this routine will unwind that mask and drop the menu entry
376 // on each corresponding label.
378 for (Count
= 1; Count
< 0x10000; Count
<<= 1) {
380 // This is an active bit, so update the form
382 if (FormSetData
->Class
& Count
) {
385 FPCallbackInfo
.DevMgrHiiHandle
,
386 (EFI_FORM_LABEL
) (FormSetData
->Class
& Count
),
396 // Reset Buffer pointer to original location
402 // Add oneof for video BIOS selection
404 VideoOption
= BdsLibGetVariableAndSize (
406 &gEfiGenericPlatformVariableGuid
,
409 if (NULL
== VideoOption
) {
410 FPCallbackInfo
.Data
.VideoBIOS
= 0;
412 FPCallbackInfo
.Data
.VideoBIOS
= VideoOption
[0];
413 FreePool (VideoOption
);
416 ASSERT (FPCallbackInfo
.Data
.VideoBIOS
<= 1);
418 IfrOptionList
= AllocatePool (2 * sizeof (IFR_OPTION
));
419 if (IfrOptionList
!= NULL
) {
420 IfrOptionList
[0].Flags
= EFI_IFR_FLAG_INTERACTIVE
;
421 IfrOptionList
[0].Key
= SET_VIDEO_BIOS_TYPE_QUESTION_ID
+ 0x2000;
422 IfrOptionList
[0].StringToken
= STRING_TOKEN (STR_ONE_OF_PCI
);
423 IfrOptionList
[0].Value
= 0;
424 IfrOptionList
[0].OptionString
= NULL
;
425 IfrOptionList
[1].Flags
= EFI_IFR_FLAG_INTERACTIVE
;
426 IfrOptionList
[1].Key
= SET_VIDEO_BIOS_TYPE_QUESTION_ID
+ 0x2000;
427 IfrOptionList
[1].StringToken
= STRING_TOKEN (STR_ONE_OF_AGP
);
428 IfrOptionList
[1].Value
= 1;
429 IfrOptionList
[1].OptionString
= NULL
;
430 IfrOptionList
[FPCallbackInfo
.Data
.VideoBIOS
].Flags
|= EFI_IFR_FLAG_DEFAULT
;
433 SET_VIDEO_BIOS_TYPE_QUESTION_ID
,
435 STRING_TOKEN (STR_ONE_OF_VBIOS
),
436 STRING_TOKEN (STR_ONE_OF_VBIOS_HELP
),
442 UpdateData
->DataCount
= 4;
443 Hii
->UpdateForm (Hii
, FPCallbackInfo
.DevMgrHiiHandle
, (EFI_FORM_LABEL
) EFI_VBIOS_CLASS
, TRUE
, UpdateData
);
444 FreePool (IfrOptionList
);
447 BootDeviceMngrMenuResetRequired
= FALSE
;
448 Status
= gBrowser
->SendForm (
450 TRUE
, // Use the database
451 &FPCallbackInfo
.DevMgrHiiHandle
, // The HII Handle
454 FPCallbackInfo
.CallbackHandle
,
455 (UINT8
*) &FPCallbackInfo
.Data
,
457 &BootDeviceMngrMenuResetRequired
460 if (BootDeviceMngrMenuResetRequired
) {
461 EnableResetRequired ();
464 Hii
->ResetStrings (Hii
, FPCallbackInfo
.DevMgrHiiHandle
);
467 // We will have returned from processing a callback - user either hit ESC to exit, or selected
468 // a target to display
470 if (gCallbackKey
!= 0 && gCallbackKey
< 0x2000) {
471 BootDeviceMngrMenuResetRequired
= FALSE
;
472 Status
= gBrowser
->SendForm (
474 TRUE
, // Use the database
475 (EFI_HII_HANDLE
*) &gCallbackKey
, // The HII Handle
478 NULL
, // This is the handle that the interface to the callback was installed on
481 &BootDeviceMngrMenuResetRequired
484 if (BootDeviceMngrMenuResetRequired
) {
485 EnableResetRequired ();
488 // Force return to Device Manager
493 if (gCallbackKey
>= 0x2000) {
497 FreePool (UpdateData
);
498 FreePool (HiiHandles
);