2 The platform device manager reference implementation
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.
47 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
48 @param Action Specifies the type of action taken by the browser.
49 @param QuestionId A unique value which is sent to the original exporting driver
50 so that it can identify the type of data to expect.
51 @param Type The type of value for the question.
52 @param Value A pointer to the data being sent to the original exporting driver.
53 @param ActionRequest On return, points to the action requested by the callback function.
55 @retval EFI_SUCCESS The callback successfully handled the action.
56 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
61 DeviceManagerCallback (
62 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
63 IN EFI_BROWSER_ACTION Action
,
64 IN EFI_QUESTION_ID QuestionId
,
66 IN EFI_IFR_TYPE_VALUE
*Value
,
67 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
70 DEVICE_MANAGER_CALLBACK_DATA
*PrivateData
;
72 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
73 return EFI_INVALID_PARAMETER
;
76 PrivateData
= DEVICE_MANAGER_CALLBACK_DATA_FROM_THIS (This
);
79 case DEVICE_MANAGER_KEY_VBIOS
:
80 PrivateData
->VideoBios
= Value
->u8
;
83 &gEfiGenericPlatformVariableGuid
,
84 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
86 &PrivateData
->VideoBios
90 // Tell browser not to ask for confirmation of changes,
91 // since we have already applied.
93 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
98 // The key corresponds the Handle Index which was requested to be displayed
100 gCallbackKey
= QuestionId
;
103 // Request to exit SendForm(), so as to switch to selected form
105 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
114 This function registers HII packages to HII database.
116 @retval EFI_SUCCESS This function complete successfully.
117 @return Other value if failed to register HII packages.
121 InitializeDeviceManager (
126 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
129 // Create driver handle used by HII database
131 Status
= HiiLibCreateHiiDriverHandle (&gDeviceManagerPrivate
.DriverHandle
);
132 if (EFI_ERROR (Status
)) {
137 // Install Config Access protocol to driver handle
139 Status
= gBS
->InstallProtocolInterface (
140 &gDeviceManagerPrivate
.DriverHandle
,
141 &gEfiHiiConfigAccessProtocolGuid
,
142 EFI_NATIVE_INTERFACE
,
143 &gDeviceManagerPrivate
.ConfigAccess
145 ASSERT_EFI_ERROR (Status
);
148 // Publish our HII data
150 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
151 ASSERT (PackageList
!= NULL
);
153 Status
= gHiiDatabase
->NewPackageList (
156 gDeviceManagerPrivate
.DriverHandle
,
157 &gDeviceManagerPrivate
.HiiHandle
159 FreePool (PackageList
);
165 Call the browser and display the device manager to allow user
166 to configure the platform.
168 This function create the dynamic content for device manager. It includes
169 section header for all class of devices, one-of opcode to set VBIOS.
171 @retval EFI_SUCCESS Operation is successful.
172 @return Other values if failed to clean up the dynamic content from HII
186 EFI_HII_UPDATE_DATA UpdateData
[MENU_ITEM_NUM
];
188 EFI_STRING_ID TokenHelp
;
189 IFR_OPTION
*IfrOptionList
;
191 UINTN VideoOptionSize
;
192 EFI_HII_HANDLE
*HiiHandles
;
193 UINTN HandleBufferLength
;
194 UINTN NumberOfHiiHandles
;
195 EFI_HII_HANDLE HiiHandle
;
197 EFI_STRING_ID FormSetTitle
;
198 EFI_STRING_ID FormSetHelp
;
199 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
200 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
202 IfrOptionList
= NULL
;
205 HandleBufferLength
= 0;
207 Status
= EFI_SUCCESS
;
211 // Connect all prior to entering the platform setup menu.
213 if (!gConnectAllHappened
) {
214 BdsLibConnectAllDriversToAllControllers ();
215 gConnectAllHappened
= TRUE
;
219 // Create Subtitle OpCodes
221 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
223 // Allocate space for creation of UpdateData Buffer
225 UpdateData
[Index
].BufferSize
= 0x1000;
226 UpdateData
[Index
].Offset
= 0;
227 UpdateData
[Index
].Data
= AllocatePool (0x1000);
228 ASSERT (UpdateData
[Index
].Data
!= NULL
);
230 CreateSubTitleOpCode (mDeviceManagerMenuItemTable
[Index
].StringId
, 0, 0, 1, &UpdateData
[Index
]);
234 // Get all the Hii handles
236 Status
= HiiLibGetHiiHandles (&HandleBufferLength
, &HiiHandles
);
237 ASSERT_EFI_ERROR (Status
&& (HiiHandles
!= NULL
));
239 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
241 StringLength
= 0x1000;
242 String
= AllocateZeroPool (StringLength
);
243 ASSERT (String
!= NULL
);
246 // Search for formset of each class type
248 NumberOfHiiHandles
= HandleBufferLength
/ sizeof (EFI_HII_HANDLE
);
249 for (Index
= 0; Index
< NumberOfHiiHandles
; Index
++) {
250 IfrLibExtractClassFromHiiHandle (HiiHandles
[Index
], &FormSetClass
, &FormSetTitle
, &FormSetHelp
);
252 if (FormSetClass
== EFI_NON_DEVICE_CLASS
) {
258 StringLength
= 0x1000;
259 HiiLibGetString (HiiHandles
[Index
], FormSetTitle
, String
, &StringLength
);
260 HiiLibNewString (HiiHandle
, &Token
, String
);
264 StringLength
= 0x1000;
265 HiiLibGetString (HiiHandles
[Index
], FormSetHelp
, String
, &StringLength
);
266 HiiLibNewString (HiiHandle
, &TokenHelp
, String
);
268 for (Count
= 0; Count
< MENU_ITEM_NUM
; Count
++) {
269 if (FormSetClass
& mDeviceManagerMenuItemTable
[Count
].Class
) {
271 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
),
274 EFI_IFR_FLAG_CALLBACK
,
283 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
285 // Add End Opcode for Subtitle
287 CreateEndOpCode (&UpdateData
[Index
]);
292 DEVICE_MANAGER_FORM_ID
,
293 mDeviceManagerMenuItemTable
[Index
].Class
,
300 // Add oneof for video BIOS selection
302 VideoOption
= BdsLibGetVariableAndSize (
304 &gEfiGenericPlatformVariableGuid
,
307 if (VideoOption
== NULL
) {
308 gDeviceManagerPrivate
.VideoBios
= 0;
310 gDeviceManagerPrivate
.VideoBios
= VideoOption
[0];
311 FreePool (VideoOption
);
314 ASSERT (gDeviceManagerPrivate
.VideoBios
<= 1);
316 IfrOptionList
= AllocatePool (2 * sizeof (IFR_OPTION
));
317 ASSERT (IfrOptionList
!= NULL
);
318 IfrOptionList
[0].Flags
= 0;
319 IfrOptionList
[0].StringToken
= STRING_TOKEN (STR_ONE_OF_PCI
);
320 IfrOptionList
[0].Value
.u8
= 0;
321 IfrOptionList
[1].Flags
= 0;
322 IfrOptionList
[1].StringToken
= STRING_TOKEN (STR_ONE_OF_AGP
);
323 IfrOptionList
[1].Value
.u8
= 1;
324 IfrOptionList
[gDeviceManagerPrivate
.VideoBios
].Flags
|= EFI_IFR_OPTION_DEFAULT
;
326 UpdateData
[0].Offset
= 0;
328 DEVICE_MANAGER_KEY_VBIOS
,
331 STRING_TOKEN (STR_ONE_OF_VBIOS
),
332 STRING_TOKEN (STR_ONE_OF_VBIOS_HELP
),
333 EFI_IFR_FLAG_CALLBACK
,
334 EFI_IFR_NUMERIC_SIZE_1
,
343 DEVICE_MANAGER_FORM_ID
,
349 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
350 Status
= gFormBrowser2
->SendForm (
359 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
360 EnableResetRequired ();
364 // We will have returned from processing a callback - user either hit ESC to exit, or selected
365 // a target to display
367 if (gCallbackKey
!= 0) {
368 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
369 Status
= gFormBrowser2
->SendForm (
371 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
379 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
380 EnableResetRequired ();
384 // Force return to Device Manager
386 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
390 // Cleanup dynamic created strings in HII database by reinstall the packagelist
392 gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
393 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
394 ASSERT (PackageList
!= NULL
);
395 Status
= gHiiDatabase
->NewPackageList (
398 gDeviceManagerPrivate
.DriverHandle
,
399 &gDeviceManagerPrivate
.HiiHandle
401 FreePool (PackageList
);
403 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
404 FreePool (UpdateData
[Index
].Data
);
406 FreePool (HiiHandles
);