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 This function complete successfully.
116 @return Other value if failed to register HII packages.
120 InitializeDeviceManager (
125 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
128 // Install Device Path Protocol and Config Access protocol to driver handle
130 Status
= gBS
->InstallMultipleProtocolInterfaces (
131 &gDeviceManagerPrivate
.DriverHandle
,
132 &gEfiDevicePathProtocolGuid
,
133 &mDeviceManagerHiiVendorDevicePath
,
134 &gEfiHiiConfigAccessProtocolGuid
,
135 &gDeviceManagerPrivate
.ConfigAccess
,
138 ASSERT_EFI_ERROR (Status
);
141 // Publish our HII data
143 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
144 ASSERT (PackageList
!= NULL
);
146 Status
= gHiiDatabase
->NewPackageList (
149 gDeviceManagerPrivate
.DriverHandle
,
150 &gDeviceManagerPrivate
.HiiHandle
152 FreePool (PackageList
);
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
179 EFI_HII_UPDATE_DATA UpdateData
[MENU_ITEM_NUM
];
181 EFI_STRING_ID TokenHelp
;
182 EFI_HII_HANDLE
*HiiHandles
;
183 UINTN HandleBufferLength
;
184 UINTN NumberOfHiiHandles
;
185 EFI_HII_HANDLE HiiHandle
;
187 EFI_STRING_ID FormSetTitle
;
188 EFI_STRING_ID FormSetHelp
;
189 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
190 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
193 HandleBufferLength
= 0;
195 Status
= EFI_SUCCESS
;
199 // Connect all prior to entering the platform setup menu.
201 if (!gConnectAllHappened
) {
202 BdsLibConnectAllDriversToAllControllers ();
203 gConnectAllHappened
= TRUE
;
207 // Create Subtitle OpCodes
209 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
211 // Allocate space for creation of UpdateData Buffer
213 UpdateData
[Index
].BufferSize
= 0x1000;
214 UpdateData
[Index
].Offset
= 0;
215 UpdateData
[Index
].Data
= AllocatePool (0x1000);
216 ASSERT (UpdateData
[Index
].Data
!= NULL
);
218 CreateSubTitleOpCode (mDeviceManagerMenuItemTable
[Index
].StringId
, 0, 0, 1, &UpdateData
[Index
]);
222 // Get all the Hii handles
224 Status
= HiiLibGetHiiHandles (&HandleBufferLength
, &HiiHandles
);
225 ASSERT_EFI_ERROR (Status
&& (HiiHandles
!= NULL
));
227 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
229 StringLength
= 0x1000;
230 String
= AllocateZeroPool (StringLength
);
231 ASSERT (String
!= NULL
);
234 // Search for formset of each class type
236 NumberOfHiiHandles
= HandleBufferLength
/ sizeof (EFI_HII_HANDLE
);
237 for (Index
= 0; Index
< NumberOfHiiHandles
; Index
++) {
238 IfrLibExtractClassFromHiiHandle (HiiHandles
[Index
], &FormSetClass
, &FormSetTitle
, &FormSetHelp
);
240 if (FormSetClass
== EFI_NON_DEVICE_CLASS
) {
246 StringLength
= 0x1000;
247 HiiLibGetString (HiiHandles
[Index
], FormSetTitle
, String
, &StringLength
);
248 HiiLibNewString (HiiHandle
, &Token
, String
);
252 StringLength
= 0x1000;
253 HiiLibGetString (HiiHandles
[Index
], FormSetHelp
, String
, &StringLength
);
254 HiiLibNewString (HiiHandle
, &TokenHelp
, String
);
256 for (Count
= 0; Count
< MENU_ITEM_NUM
; Count
++) {
257 if (FormSetClass
& mDeviceManagerMenuItemTable
[Count
].Class
) {
259 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
),
262 EFI_IFR_FLAG_CALLBACK
,
271 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
273 // Add End Opcode for Subtitle
275 CreateEndOpCode (&UpdateData
[Index
]);
280 DEVICE_MANAGER_FORM_ID
,
281 mDeviceManagerMenuItemTable
[Index
].Class
,
287 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
288 Status
= gFormBrowser2
->SendForm (
297 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
298 EnableResetRequired ();
302 // We will have returned from processing a callback - user either hit ESC to exit, or selected
303 // a target to display
305 if (gCallbackKey
!= 0) {
306 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
307 Status
= gFormBrowser2
->SendForm (
309 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
317 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
318 EnableResetRequired ();
322 // Force return to Device Manager
324 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
328 // Cleanup dynamic created strings in HII database by reinstall the packagelist
330 gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
331 PackageList
= HiiLibPreparePackageList (2, &mDeviceManagerGuid
, DeviceManagerVfrBin
, BdsDxeStrings
);
332 ASSERT (PackageList
!= NULL
);
333 Status
= gHiiDatabase
->NewPackageList (
336 gDeviceManagerPrivate
.DriverHandle
,
337 &gDeviceManagerPrivate
.HiiHandle
339 FreePool (PackageList
);
341 for (Index
= 0; Index
< MENU_ITEM_NUM
; Index
++) {
342 FreePool (UpdateData
[Index
].Data
);
344 FreePool (HiiHandles
);