2 The platform device manager reference implement
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "DeviceManager.h"
17 DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate
= {
18 DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE
,
28 EFI_GUID mDeviceManagerGuid
= DEVICE_MANAGER_FORMSET_GUID
;
30 DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable
[] = {
31 { STRING_TOKEN (STR_DISK_DEVICE
), EFI_DISK_DEVICE_CLASS
},
32 { STRING_TOKEN (STR_VIDEO_DEVICE
), EFI_VIDEO_DEVICE_CLASS
},
33 { STRING_TOKEN (STR_NETWORK_DEVICE
), EFI_NETWORK_DEVICE_CLASS
},
34 { STRING_TOKEN (STR_INPUT_DEVICE
), EFI_INPUT_DEVICE_CLASS
},
35 { STRING_TOKEN (STR_ON_BOARD_DEVICE
), EFI_ON_BOARD_DEVICE_CLASS
},
36 { STRING_TOKEN (STR_OTHER_DEVICE
), EFI_OTHER_DEVICE_CLASS
}
39 #define MENU_ITEM_NUM \
40 (sizeof (mDeviceManagerMenuItemTable) / sizeof (DEVICE_MANAGER_MENU_ITEM))
43 This function is invoked if user selected a iteractive opcode from Device Manager's
44 Formset. The decision by user is saved to gCallbackKey for later processing. If
45 user set VBIOS, the new value is saved to EFI variable.
48 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
49 @param Action Specifies the type of action taken by the browser.
50 @param QuestionId A unique value which is sent to the original exporting driver
51 so that it can identify the type of data to expect.
52 @param Type The type of value for the question.
53 @param Value A pointer to the data being sent to the original exporting driver.
54 @param ActionRequest On return, points to the action requested by the callback function.
56 @retval EFI_SUCCESS The callback successfully handled the action.
57 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
62 DeviceManagerCallback (
63 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
64 IN EFI_BROWSER_ACTION Action
,
65 IN EFI_QUESTION_ID QuestionId
,
67 IN EFI_IFR_TYPE_VALUE
*Value
,
68 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
71 DEVICE_MANAGER_CALLBACK_DATA
*PrivateData
;
73 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
74 return EFI_INVALID_PARAMETER
;
77 PrivateData
= DEVICE_MANAGER_CALLBACK_DATA_FROM_THIS (This
);
80 case DEVICE_MANAGER_KEY_VBIOS
:
81 PrivateData
->VideoBios
= Value
->u8
;
84 &gEfiGenericPlatformVariableGuid
,
85 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
87 &PrivateData
->VideoBios
91 // Tell browser not to ask for confirmation of changes,
92 // since we have already applied.
94 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
99 // The key corresponds the Handle Index which was requested to be displayed
101 gCallbackKey
= QuestionId
;
104 // Request to exit SendForm(), so as to switch to selected form
106 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
115 This function registers HII packages to HII database.
117 @retval EFI_SUCCESS This function complete successfully.
118 @return Other value if failed to register HII packages.
122 InitializeDeviceManager (
127 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
130 // Create driver handle used by HII database
132 Status
= HiiLibCreateHiiDriverHandle (&gDeviceManagerPrivate
.DriverHandle
);
133 if (EFI_ERROR (Status
)) {
138 // Install Config Access protocol to driver handle
140 Status
= gBS
->InstallProtocolInterface (
141 &gDeviceManagerPrivate
.DriverHandle
,
142 &gEfiHiiConfigAccessProtocolGuid
,
143 EFI_NATIVE_INTERFACE
,
144 &gDeviceManagerPrivate
.ConfigAccess
146 ASSERT_EFI_ERROR (Status
);
149 // Publish our HII data
151 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
152 ASSERT (PackageList
!= NULL
);
154 Status
= gHiiDatabase
->NewPackageList (
157 gDeviceManagerPrivate
.DriverHandle
,
158 &gDeviceManagerPrivate
.HiiHandle
160 FreePool (PackageList
);
167 Call the browser and display the device manager to allow user
168 to configure the platform.
170 This function create the dynamic content for device manager. It includes
171 section header for all class of devices, one-of opcode to set VBIOS.
173 @retval EFI_SUCCESS Operation is successful.
174 @retval Other values if failed to clean up the dynamic content from HII
188 EFI_HII_UPDATE_DATA UpdateData
[MENU_ITEM_NUM
];
190 EFI_STRING_ID TokenHelp
;
191 IFR_OPTION
*IfrOptionList
;
193 UINTN VideoOptionSize
;
194 EFI_HII_HANDLE
*HiiHandles
;
195 UINTN HandleBufferLength
;
196 UINTN NumberOfHiiHandles
;
197 EFI_HII_HANDLE HiiHandle
;
199 EFI_STRING_ID FormSetTitle
;
200 EFI_STRING_ID FormSetHelp
;
201 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
202 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
204 IfrOptionList
= NULL
;
207 HandleBufferLength
= 0;
209 Status
= EFI_SUCCESS
;
213 // Connect all prior to entering the platform setup menu.
215 if (!gConnectAllHappened
) {
216 BdsLibConnectAllDriversToAllControllers ();
217 gConnectAllHappened
= TRUE
;
221 // Create Subtitle OpCodes
223 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
225 // Allocate space for creation of UpdateData Buffer
227 UpdateData
[Index
].BufferSize
= 0x1000;
228 UpdateData
[Index
].Offset
= 0;
229 UpdateData
[Index
].Data
= AllocatePool (0x1000);
230 ASSERT (UpdateData
[Index
].Data
!= NULL
);
232 CreateSubTitleOpCode (mDeviceManagerMenuItemTable
[Index
].StringId
, 0, 0, 1, &UpdateData
[Index
]);
236 // Get all the Hii handles
238 Status
= HiiLibGetHiiHandles (&HandleBufferLength
, &HiiHandles
);
239 ASSERT_EFI_ERROR (Status
);
241 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
243 StringLength
= 0x1000;
244 String
= AllocateZeroPool (StringLength
);
245 ASSERT (String
!= NULL
);
248 // Search for formset of each class type
250 NumberOfHiiHandles
= HandleBufferLength
/ sizeof (EFI_HII_HANDLE
);
251 for (Index
= 0; Index
< NumberOfHiiHandles
; Index
++) {
252 IfrLibExtractClassFromHiiHandle (HiiHandles
[Index
], &FormSetClass
, &FormSetTitle
, &FormSetHelp
);
254 if (FormSetClass
== EFI_NON_DEVICE_CLASS
) {
260 StringLength
= 0x1000;
261 HiiLibGetString (HiiHandles
[Index
], FormSetTitle
, String
, &StringLength
);
262 HiiLibNewString (HiiHandle
, &Token
, String
);
266 StringLength
= 0x1000;
267 HiiLibGetString (HiiHandles
[Index
], FormSetHelp
, String
, &StringLength
);
268 HiiLibNewString (HiiHandle
, &TokenHelp
, String
);
270 for (Count
= 0; Count
< MENU_ITEM_NUM
; Count
++) {
271 if (FormSetClass
& mDeviceManagerMenuItemTable
[Count
].Class
) {
273 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
),
276 EFI_IFR_FLAG_CALLBACK
,
285 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
287 // Add End Opcode for Subtitle
289 CreateEndOpCode (&UpdateData
[Index
]);
294 DEVICE_MANAGER_FORM_ID
,
295 mDeviceManagerMenuItemTable
[Index
].Class
,
302 // Add oneof for video BIOS selection
304 VideoOption
= BdsLibGetVariableAndSize (
306 &gEfiGenericPlatformVariableGuid
,
309 if (NULL
== VideoOption
) {
310 gDeviceManagerPrivate
.VideoBios
= 0;
312 gDeviceManagerPrivate
.VideoBios
= VideoOption
[0];
313 FreePool (VideoOption
);
316 ASSERT (gDeviceManagerPrivate
.VideoBios
<= 1);
318 IfrOptionList
= AllocatePool (2 * sizeof (IFR_OPTION
));
319 ASSERT (IfrOptionList
!= NULL
);
320 IfrOptionList
[0].Flags
= 0;
321 IfrOptionList
[0].StringToken
= STRING_TOKEN (STR_ONE_OF_PCI
);
322 IfrOptionList
[0].Value
.u8
= 0;
323 IfrOptionList
[1].Flags
= 0;
324 IfrOptionList
[1].StringToken
= STRING_TOKEN (STR_ONE_OF_AGP
);
325 IfrOptionList
[1].Value
.u8
= 1;
326 IfrOptionList
[gDeviceManagerPrivate
.VideoBios
].Flags
|= EFI_IFR_OPTION_DEFAULT
;
328 UpdateData
[0].Offset
= 0;
330 DEVICE_MANAGER_KEY_VBIOS
,
333 STRING_TOKEN (STR_ONE_OF_VBIOS
),
334 STRING_TOKEN (STR_ONE_OF_VBIOS_HELP
),
335 EFI_IFR_FLAG_CALLBACK
,
336 EFI_IFR_NUMERIC_SIZE_1
,
345 DEVICE_MANAGER_FORM_ID
,
351 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
352 Status
= gFormBrowser2
->SendForm (
361 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
362 EnableResetRequired ();
366 // We will have returned from processing a callback - user either hit ESC to exit, or selected
367 // a target to display
369 if (gCallbackKey
!= 0) {
370 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
371 Status
= gFormBrowser2
->SendForm (
373 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
381 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
382 EnableResetRequired ();
386 // Force return to Device Manager
388 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
392 // Cleanup dynamic created strings in HII database by reinstall the packagelist
394 gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
395 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
396 ASSERT (PackageList
!= NULL
);
397 Status
= gHiiDatabase
->NewPackageList (
400 gDeviceManagerPrivate
.DriverHandle
,
401 &gDeviceManagerPrivate
.HiiHandle
403 FreePool (PackageList
);
405 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
406 FreePool (UpdateData
[Index
].Data
);
408 FreePool (HiiHandles
);