]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
920a0506306851ee3ec2fab8d396a04eb7a83511
[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 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.
117
118 **/
119 EFI_STATUS
120 InitializeDeviceManager (
121 VOID
122 )
123 {
124 EFI_STATUS Status;
125
126 //
127 // Install Device Path Protocol and Config Access protocol to driver handle
128 //
129 Status = gBS->InstallMultipleProtocolInterfaces (
130 &gDeviceManagerPrivate.DriverHandle,
131 &gEfiDevicePathProtocolGuid,
132 &mDeviceManagerHiiVendorDevicePath,
133 &gEfiHiiConfigAccessProtocolGuid,
134 &gDeviceManagerPrivate.ConfigAccess,
135 NULL
136 );
137 ASSERT_EFI_ERROR (Status);
138
139 //
140 // Publish our HII data
141 //
142 gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
143 &mDeviceManagerGuid,
144 gDeviceManagerPrivate.DriverHandle,
145 DeviceManagerVfrBin,
146 BdsDxeStrings,
147 NULL
148 );
149 if (gDeviceManagerPrivate.HiiHandle == NULL) {
150 Status = EFI_OUT_OF_RESOURCES;
151 } else {
152 Status = EFI_SUCCESS;
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 EFI_STRING String;
178 EFI_HII_UPDATE_DATA UpdateData[MENU_ITEM_NUM];
179 EFI_STRING_ID Token;
180 EFI_STRING_ID TokenHelp;
181 EFI_HII_HANDLE *HiiHandles;
182 EFI_HII_HANDLE HiiHandle;
183 UINT16 FormSetClass;
184 EFI_STRING_ID FormSetTitle;
185 EFI_STRING_ID FormSetHelp;
186 EFI_BROWSER_ACTION_REQUEST ActionRequest;
187
188 HiiHandles = NULL;
189
190 Status = EFI_SUCCESS;
191 gCallbackKey = 0;
192
193 //
194 // Connect all prior to entering the platform setup menu.
195 //
196 if (!gConnectAllHappened) {
197 BdsLibConnectAllDriversToAllControllers ();
198 gConnectAllHappened = TRUE;
199 }
200
201 //
202 // Create Subtitle OpCodes
203 //
204 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
205 //
206 // Allocate space for creation of UpdateData Buffer
207 //
208 UpdateData[Index].BufferSize = 0x1000;
209 UpdateData[Index].Offset = 0;
210 UpdateData[Index].Data = AllocatePool (0x1000);
211 ASSERT (UpdateData[Index].Data != NULL);
212
213 CreateSubTitleOpCode (mDeviceManagerMenuItemTable[Index].StringId, 0, 0, 1, &UpdateData[Index]);
214 }
215
216 //
217 // Get all the Hii handles
218 //
219 HiiHandles = HiiGetHiiHandles (NULL);
220 ASSERT (HiiHandles != NULL);
221
222 HiiHandle = gDeviceManagerPrivate.HiiHandle;
223
224 //
225 // Search for formset of each class type
226 //
227 for (Index = 0; HiiHandles[Index] != NULL; Index++) {
228 IfrLibExtractClassFromHiiHandle (HiiHandles[Index], &FormSetClass, &FormSetTitle, &FormSetHelp);
229
230 if (FormSetClass == EFI_NON_DEVICE_CLASS) {
231 continue;
232 }
233
234 String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);
235 ASSERT (String != NULL);
236 Token = HiiSetString (HiiHandle, 0, String, NULL);
237 FreePool (String);
238
239 String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL);
240 ASSERT (String != NULL);
241 TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);
242 FreePool (String);
243
244 for (Count = 0; Count < MENU_ITEM_NUM; Count++) {
245 if (FormSetClass & mDeviceManagerMenuItemTable[Count].Class) {
246 CreateActionOpCode (
247 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
248 Token,
249 TokenHelp,
250 EFI_IFR_FLAG_CALLBACK,
251 0,
252 &UpdateData[Count]
253 );
254 }
255 }
256 }
257
258 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
259 //
260 // Add End Opcode for Subtitle
261 //
262 CreateEndOpCode (&UpdateData[Index]);
263
264 IfrLibUpdateForm (
265 HiiHandle,
266 &mDeviceManagerGuid,
267 DEVICE_MANAGER_FORM_ID,
268 mDeviceManagerMenuItemTable[Index].Class,
269 FALSE,
270 &UpdateData[Index]
271 );
272 }
273
274 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
275 Status = gFormBrowser2->SendForm (
276 gFormBrowser2,
277 &HiiHandle,
278 1,
279 NULL,
280 0,
281 NULL,
282 &ActionRequest
283 );
284 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
285 EnableResetRequired ();
286 }
287
288 //
289 // We will have returned from processing a callback - user either hit ESC to exit, or selected
290 // a target to display
291 //
292 if (gCallbackKey != 0) {
293 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
294 Status = gFormBrowser2->SendForm (
295 gFormBrowser2,
296 &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],
297 1,
298 NULL,
299 0,
300 NULL,
301 &ActionRequest
302 );
303
304 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
305 EnableResetRequired ();
306 }
307
308 //
309 // Force return to Device Manager
310 //
311 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
312 }
313
314 //
315 // Cleanup dynamic created strings in HII database by reinstall the packagelist
316 //
317 HiiRemovePackages (HiiHandle);
318
319 gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
320 &mDeviceManagerGuid,
321 gDeviceManagerPrivate.DriverHandle,
322 DeviceManagerVfrBin,
323 BdsDxeStrings,
324 NULL
325 );
326 if (gDeviceManagerPrivate.HiiHandle == NULL) {
327 Status = EFI_OUT_OF_RESOURCES;
328 } else {
329 Status = EFI_SUCCESS;
330 }
331
332 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
333 FreePool (UpdateData[Index].Data);
334 }
335 FreePool (HiiHandles);
336
337 return Status;
338 }