]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
Retire Extended HII library class.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / DeviceMngr / DeviceManager.c
1 /** @file
2 The platform device manager reference implementation
3
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
9
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.
12
13 **/
14
15 #include "DeviceManager.h"
16
17 DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {
18 DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,
19 NULL,
20 NULL,
21 {
22 FakeExtractConfig,
23 FakeRouteConfig,
24 DeviceManagerCallback
25 }
26 };
27
28 EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;
29
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 }
37 };
38
39 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {
40 {
41 {
42 HARDWARE_DEVICE_PATH,
43 HW_VENDOR_DP,
44 {
45 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
46 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
47 }
48 },
49 //
50 // {102579A0-3686-466e-ACD8-80C087044F4A}
51 //
52 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
53 },
54 {
55 END_DEVICE_PATH_TYPE,
56 END_ENTIRE_DEVICE_PATH_SUBTYPE,
57 {
58 (UINT8) (END_DEVICE_PATH_LENGTH),
59 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
60 }
61 }
62 };
63
64 #define MENU_ITEM_NUM \
65 (sizeof (mDeviceManagerMenuItemTable) / sizeof (DEVICE_MANAGER_MENU_ITEM))
66
67 /**
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.
71
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.
79
80 @retval EFI_SUCCESS The callback successfully handled the action.
81 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
82
83 **/
84 EFI_STATUS
85 EFIAPI
86 DeviceManagerCallback (
87 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
88 IN EFI_BROWSER_ACTION Action,
89 IN EFI_QUESTION_ID QuestionId,
90 IN UINT8 Type,
91 IN EFI_IFR_TYPE_VALUE *Value,
92 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
93 )
94 {
95 if ((Value == NULL) || (ActionRequest == NULL)) {
96 return EFI_INVALID_PARAMETER;
97 }
98
99
100 gCallbackKey = QuestionId;
101
102 //
103 // Request to exit SendForm(), so as to switch to selected form
104 //
105 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
106
107
108 return EFI_SUCCESS;
109 }
110
111 /**
112
113 This function registers HII packages to HII database.
114
115 @retval EFI_SUCCESS This function complete successfully.
116 @return Other value if failed to register HII packages.
117
118 **/
119 EFI_STATUS
120 InitializeDeviceManager (
121 VOID
122 )
123 {
124 EFI_STATUS Status;
125 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
126
127 //
128 // Install Device Path Protocol and Config Access protocol to driver handle
129 //
130 Status = gBS->InstallMultipleProtocolInterfaces (
131 &gDeviceManagerPrivate.DriverHandle,
132 &gEfiDevicePathProtocolGuid,
133 &mDeviceManagerHiiVendorDevicePath,
134 &gEfiHiiConfigAccessProtocolGuid,
135 &gDeviceManagerPrivate.ConfigAccess,
136 NULL
137 );
138 ASSERT_EFI_ERROR (Status);
139
140 //
141 // Publish our HII data
142 //
143 PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings);
144 ASSERT (PackageList != NULL);
145
146 Status = gHiiDatabase->NewPackageList (
147 gHiiDatabase,
148 PackageList,
149 gDeviceManagerPrivate.DriverHandle,
150 &gDeviceManagerPrivate.HiiHandle
151 );
152 FreePool (PackageList);
153
154 return Status;
155 }
156
157 /**
158 Call the browser and display the device manager to allow user
159 to configure the platform.
160
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.
163
164 @retval EFI_SUCCESS Operation is successful.
165 @return Other values if failed to clean up the dynamic content from HII
166 database.
167
168 **/
169 EFI_STATUS
170 CallDeviceManager (
171 VOID
172 )
173 {
174 EFI_STATUS Status;
175 UINTN Count;
176 UINTN Index;
177 CHAR16 *String;
178 UINTN StringLength;
179 EFI_HII_UPDATE_DATA UpdateData[MENU_ITEM_NUM];
180 EFI_STRING_ID Token;
181 EFI_STRING_ID TokenHelp;
182 EFI_HII_HANDLE *HiiHandles;
183 UINTN HandleBufferLength;
184 UINTN NumberOfHiiHandles;
185 EFI_HII_HANDLE HiiHandle;
186 UINT16 FormSetClass;
187 EFI_STRING_ID FormSetTitle;
188 EFI_STRING_ID FormSetHelp;
189 EFI_BROWSER_ACTION_REQUEST ActionRequest;
190 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
191
192 HiiHandles = NULL;
193 HandleBufferLength = 0;
194
195 Status = EFI_SUCCESS;
196 gCallbackKey = 0;
197
198 //
199 // Connect all prior to entering the platform setup menu.
200 //
201 if (!gConnectAllHappened) {
202 BdsLibConnectAllDriversToAllControllers ();
203 gConnectAllHappened = TRUE;
204 }
205
206 //
207 // Create Subtitle OpCodes
208 //
209 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
210 //
211 // Allocate space for creation of UpdateData Buffer
212 //
213 UpdateData[Index].BufferSize = 0x1000;
214 UpdateData[Index].Offset = 0;
215 UpdateData[Index].Data = AllocatePool (0x1000);
216 ASSERT (UpdateData[Index].Data != NULL);
217
218 CreateSubTitleOpCode (mDeviceManagerMenuItemTable[Index].StringId, 0, 0, 1, &UpdateData[Index]);
219 }
220
221 //
222 // Get all the Hii handles
223 //
224 Status = HiiLibGetHiiHandles (&HandleBufferLength, &HiiHandles);
225 ASSERT_EFI_ERROR (Status && (HiiHandles != NULL));
226
227 HiiHandle = gDeviceManagerPrivate.HiiHandle;
228
229 StringLength = 0x1000;
230 String = AllocateZeroPool (StringLength);
231 ASSERT (String != NULL);
232
233 //
234 // Search for formset of each class type
235 //
236 NumberOfHiiHandles = HandleBufferLength / sizeof (EFI_HII_HANDLE);
237 for (Index = 0; Index < NumberOfHiiHandles; Index++) {
238 IfrLibExtractClassFromHiiHandle (HiiHandles[Index], &FormSetClass, &FormSetTitle, &FormSetHelp);
239
240 if (FormSetClass == EFI_NON_DEVICE_CLASS) {
241 continue;
242 }
243
244 Token = 0;
245 *String = 0;
246 StringLength = 0x1000;
247 HiiLibGetString (HiiHandles[Index], FormSetTitle, String, &StringLength);
248 HiiLibNewString (HiiHandle, &Token, String);
249
250 TokenHelp = 0;
251 *String = 0;
252 StringLength = 0x1000;
253 HiiLibGetString (HiiHandles[Index], FormSetHelp, String, &StringLength);
254 HiiLibNewString (HiiHandle, &TokenHelp, String);
255
256 for (Count = 0; Count < MENU_ITEM_NUM; Count++) {
257 if (FormSetClass & mDeviceManagerMenuItemTable[Count].Class) {
258 CreateActionOpCode (
259 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
260 Token,
261 TokenHelp,
262 EFI_IFR_FLAG_CALLBACK,
263 0,
264 &UpdateData[Count]
265 );
266 }
267 }
268 }
269 FreePool (String);
270
271 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
272 //
273 // Add End Opcode for Subtitle
274 //
275 CreateEndOpCode (&UpdateData[Index]);
276
277 IfrLibUpdateForm (
278 HiiHandle,
279 &mDeviceManagerGuid,
280 DEVICE_MANAGER_FORM_ID,
281 mDeviceManagerMenuItemTable[Index].Class,
282 FALSE,
283 &UpdateData[Index]
284 );
285 }
286
287 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
288 Status = gFormBrowser2->SendForm (
289 gFormBrowser2,
290 &HiiHandle,
291 1,
292 NULL,
293 0,
294 NULL,
295 &ActionRequest
296 );
297 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
298 EnableResetRequired ();
299 }
300
301 //
302 // We will have returned from processing a callback - user either hit ESC to exit, or selected
303 // a target to display
304 //
305 if (gCallbackKey != 0) {
306 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
307 Status = gFormBrowser2->SendForm (
308 gFormBrowser2,
309 &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],
310 1,
311 NULL,
312 0,
313 NULL,
314 &ActionRequest
315 );
316
317 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
318 EnableResetRequired ();
319 }
320
321 //
322 // Force return to Device Manager
323 //
324 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
325 }
326
327 //
328 // Cleanup dynamic created strings in HII database by reinstall the packagelist
329 //
330 gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);
331 PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings);
332 ASSERT (PackageList != NULL);
333 Status = gHiiDatabase->NewPackageList (
334 gHiiDatabase,
335 PackageList,
336 gDeviceManagerPrivate.DriverHandle,
337 &gDeviceManagerPrivate.HiiHandle
338 );
339 FreePool (PackageList);
340
341 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
342 FreePool (UpdateData[Index].Data);
343 }
344 FreePool (HiiHandles);
345
346 return Status;
347 }