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