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 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath
= {
45 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
46 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
50 // {102579A0-3686-466e-ACD8-80C087044F4A}
52 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
56 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
58 (UINT8
) (END_DEVICE_PATH_LENGTH
),
59 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
64 #define MENU_ITEM_NUM \
65 (sizeof (mDeviceManagerMenuItemTable) / sizeof (DEVICE_MANAGER_MENU_ITEM))
68 This function is invoked if user selected a iteractive opcode from Device Manager's
69 Formset. The decision by user is saved to gCallbackKey for later processing. If
70 user set VBIOS, the new value is saved to EFI variable.
72 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
73 @param Action Specifies the type of action taken by the browser.
74 @param QuestionId A unique value which is sent to the original exporting driver
75 so that it can identify the type of data to expect.
76 @param Type The type of value for the question.
77 @param Value A pointer to the data being sent to the original exporting driver.
78 @param ActionRequest On return, points to the action requested by the callback function.
80 @retval EFI_SUCCESS The callback successfully handled the action.
81 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
86 DeviceManagerCallback (
87 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
88 IN EFI_BROWSER_ACTION Action
,
89 IN EFI_QUESTION_ID QuestionId
,
91 IN EFI_IFR_TYPE_VALUE
*Value
,
92 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
95 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
96 return EFI_INVALID_PARAMETER
;
100 gCallbackKey
= QuestionId
;
103 // Request to exit SendForm(), so as to switch to selected form
105 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
113 This function registers HII packages to HII database.
115 @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully.
116 @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered.
120 InitializeDeviceManager (
127 // Install Device Path Protocol and Config Access protocol to driver handle
129 Status
= gBS
->InstallMultipleProtocolInterfaces (
130 &gDeviceManagerPrivate
.DriverHandle
,
131 &gEfiDevicePathProtocolGuid
,
132 &mDeviceManagerHiiVendorDevicePath
,
133 &gEfiHiiConfigAccessProtocolGuid
,
134 &gDeviceManagerPrivate
.ConfigAccess
,
137 ASSERT_EFI_ERROR (Status
);
140 // Publish our HII data
142 gDeviceManagerPrivate
.HiiHandle
= HiiAddPackages (
144 gDeviceManagerPrivate
.DriverHandle
,
149 if (gDeviceManagerPrivate
.HiiHandle
== NULL
) {
150 Status
= EFI_OUT_OF_RESOURCES
;
152 Status
= EFI_SUCCESS
;
158 Call the browser and display the device manager to allow user
159 to configure the platform.
161 This function create the dynamic content for device manager. It includes
162 section header for all class of devices, one-of opcode to set VBIOS.
164 @retval EFI_SUCCESS Operation is successful.
165 @return Other values if failed to clean up the dynamic content from HII
178 EFI_HII_UPDATE_DATA UpdateData
[MENU_ITEM_NUM
];
180 EFI_STRING_ID TokenHelp
;
181 EFI_HII_HANDLE
*HiiHandles
;
182 EFI_HII_HANDLE HiiHandle
;
184 EFI_STRING_ID FormSetTitle
;
185 EFI_STRING_ID FormSetHelp
;
186 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
190 Status
= EFI_SUCCESS
;
194 // Connect all prior to entering the platform setup menu.
196 if (!gConnectAllHappened
) {
197 BdsLibConnectAllDriversToAllControllers ();
198 gConnectAllHappened
= TRUE
;
202 // Create Subtitle OpCodes
204 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
206 // Allocate space for creation of UpdateData Buffer
208 UpdateData
[Index
].BufferSize
= 0x1000;
209 UpdateData
[Index
].Offset
= 0;
210 UpdateData
[Index
].Data
= AllocatePool (0x1000);
211 ASSERT (UpdateData
[Index
].Data
!= NULL
);
213 CreateSubTitleOpCode (mDeviceManagerMenuItemTable
[Index
].StringId
, 0, 0, 1, &UpdateData
[Index
]);
217 // Get all the Hii handles
219 HiiHandles
= HiiGetHiiHandles (NULL
);
220 ASSERT (HiiHandles
!= NULL
);
222 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
225 // Search for formset of each class type
227 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
228 IfrLibExtractClassFromHiiHandle (HiiHandles
[Index
], &FormSetClass
, &FormSetTitle
, &FormSetHelp
);
230 if (FormSetClass
== EFI_NON_DEVICE_CLASS
) {
234 String
= HiiGetString (HiiHandles
[Index
], FormSetTitle
, NULL
);
235 ASSERT (String
!= NULL
);
236 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
239 String
= HiiGetString (HiiHandles
[Index
], FormSetHelp
, NULL
);
240 ASSERT (String
!= NULL
);
241 TokenHelp
= HiiSetString (HiiHandle
, 0, String
, NULL
);
244 for (Count
= 0; Count
< MENU_ITEM_NUM
; Count
++) {
245 if (FormSetClass
& mDeviceManagerMenuItemTable
[Count
].Class
) {
247 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
),
250 EFI_IFR_FLAG_CALLBACK
,
258 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
260 // Add End Opcode for Subtitle
262 CreateEndOpCode (&UpdateData
[Index
]);
267 DEVICE_MANAGER_FORM_ID
,
268 mDeviceManagerMenuItemTable
[Index
].Class
,
274 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
275 Status
= gFormBrowser2
->SendForm (
284 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
285 EnableResetRequired ();
289 // We will have returned from processing a callback - user either hit ESC to exit, or selected
290 // a target to display
292 if (gCallbackKey
!= 0) {
293 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
294 Status
= gFormBrowser2
->SendForm (
296 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
304 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
305 EnableResetRequired ();
309 // Force return to Device Manager
311 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
315 // Cleanup dynamic created strings in HII database by reinstall the packagelist
317 HiiRemovePackages (HiiHandle
);
319 gDeviceManagerPrivate
.HiiHandle
= HiiAddPackages (
321 gDeviceManagerPrivate
.DriverHandle
,
326 if (gDeviceManagerPrivate
.HiiHandle
== NULL
) {
327 Status
= EFI_OUT_OF_RESOURCES
;
329 Status
= EFI_SUCCESS
;
332 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
333 FreePool (UpdateData
[Index
].Data
);
335 FreePool (HiiHandles
);