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 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
71 return EFI_INVALID_PARAMETER
;
75 gCallbackKey
= QuestionId
;
78 // Request to exit SendForm(), so as to switch to selected form
80 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
88 This function registers HII packages to HII database.
90 @retval EFI_SUCCESS This function complete successfully.
91 @return Other value if failed to register HII packages.
95 InitializeDeviceManager (
100 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
103 // Create driver handle used by HII database
105 Status
= HiiLibCreateHiiDriverHandle (&gDeviceManagerPrivate
.DriverHandle
);
106 if (EFI_ERROR (Status
)) {
111 // Install Config Access protocol to driver handle
113 Status
= gBS
->InstallProtocolInterface (
114 &gDeviceManagerPrivate
.DriverHandle
,
115 &gEfiHiiConfigAccessProtocolGuid
,
116 EFI_NATIVE_INTERFACE
,
117 &gDeviceManagerPrivate
.ConfigAccess
119 ASSERT_EFI_ERROR (Status
);
122 // Publish our HII data
124 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
125 ASSERT (PackageList
!= NULL
);
127 Status
= gHiiDatabase
->NewPackageList (
130 gDeviceManagerPrivate
.DriverHandle
,
131 &gDeviceManagerPrivate
.HiiHandle
133 FreePool (PackageList
);
139 Call the browser and display the device manager to allow user
140 to configure the platform.
142 This function create the dynamic content for device manager. It includes
143 section header for all class of devices, one-of opcode to set VBIOS.
145 @retval EFI_SUCCESS Operation is successful.
146 @return Other values if failed to clean up the dynamic content from HII
160 EFI_HII_UPDATE_DATA UpdateData
[MENU_ITEM_NUM
];
162 EFI_STRING_ID TokenHelp
;
163 EFI_HII_HANDLE
*HiiHandles
;
164 UINTN HandleBufferLength
;
165 UINTN NumberOfHiiHandles
;
166 EFI_HII_HANDLE HiiHandle
;
168 EFI_STRING_ID FormSetTitle
;
169 EFI_STRING_ID FormSetHelp
;
170 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
171 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
174 HandleBufferLength
= 0;
176 Status
= EFI_SUCCESS
;
180 // Connect all prior to entering the platform setup menu.
182 if (!gConnectAllHappened
) {
183 BdsLibConnectAllDriversToAllControllers ();
184 gConnectAllHappened
= TRUE
;
188 // Create Subtitle OpCodes
190 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
192 // Allocate space for creation of UpdateData Buffer
194 UpdateData
[Index
].BufferSize
= 0x1000;
195 UpdateData
[Index
].Offset
= 0;
196 UpdateData
[Index
].Data
= AllocatePool (0x1000);
197 ASSERT (UpdateData
[Index
].Data
!= NULL
);
199 CreateSubTitleOpCode (mDeviceManagerMenuItemTable
[Index
].StringId
, 0, 0, 1, &UpdateData
[Index
]);
203 // Get all the Hii handles
205 Status
= HiiLibGetHiiHandles (&HandleBufferLength
, &HiiHandles
);
206 ASSERT_EFI_ERROR (Status
&& (HiiHandles
!= NULL
));
208 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
210 StringLength
= 0x1000;
211 String
= AllocateZeroPool (StringLength
);
212 ASSERT (String
!= NULL
);
215 // Search for formset of each class type
217 NumberOfHiiHandles
= HandleBufferLength
/ sizeof (EFI_HII_HANDLE
);
218 for (Index
= 0; Index
< NumberOfHiiHandles
; Index
++) {
219 IfrLibExtractClassFromHiiHandle (HiiHandles
[Index
], &FormSetClass
, &FormSetTitle
, &FormSetHelp
);
221 if (FormSetClass
== EFI_NON_DEVICE_CLASS
) {
227 StringLength
= 0x1000;
228 HiiLibGetString (HiiHandles
[Index
], FormSetTitle
, String
, &StringLength
);
229 HiiLibNewString (HiiHandle
, &Token
, String
);
233 StringLength
= 0x1000;
234 HiiLibGetString (HiiHandles
[Index
], FormSetHelp
, String
, &StringLength
);
235 HiiLibNewString (HiiHandle
, &TokenHelp
, String
);
237 for (Count
= 0; Count
< MENU_ITEM_NUM
; Count
++) {
238 if (FormSetClass
& mDeviceManagerMenuItemTable
[Count
].Class
) {
240 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
),
243 EFI_IFR_FLAG_CALLBACK
,
252 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
254 // Add End Opcode for Subtitle
256 CreateEndOpCode (&UpdateData
[Index
]);
261 DEVICE_MANAGER_FORM_ID
,
262 mDeviceManagerMenuItemTable
[Index
].Class
,
271 DEVICE_MANAGER_FORM_ID
,
277 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
278 Status
= gFormBrowser2
->SendForm (
287 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
288 EnableResetRequired ();
292 // We will have returned from processing a callback - user either hit ESC to exit, or selected
293 // a target to display
295 if (gCallbackKey
!= 0) {
296 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
297 Status
= gFormBrowser2
->SendForm (
299 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
307 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
308 EnableResetRequired ();
312 // Force return to Device Manager
314 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
318 // Cleanup dynamic created strings in HII database by reinstall the packagelist
320 gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
321 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
322 ASSERT (PackageList
!= NULL
);
323 Status
= gHiiDatabase
->NewPackageList (
326 gDeviceManagerPrivate
.DriverHandle
,
327 &gDeviceManagerPrivate
.HiiHandle
329 FreePool (PackageList
);
331 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
332 FreePool (UpdateData
[Index
].Data
);
334 FreePool (HiiHandles
);