1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
/** @file
The platform device manager reference implementation
Copyright (c) 2004 - 2008, Intel Corporation. <BR>
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "DeviceManager.h"
#include <Guid/HiiPlatformSetupFormset.h>
DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {
DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,
NULL,
NULL,
{
FakeExtractConfig,
FakeRouteConfig,
DeviceManagerCallback
}
};
EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;
DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable[] = {
{ STRING_TOKEN (STR_DISK_DEVICE), EFI_DISK_DEVICE_CLASS },
{ STRING_TOKEN (STR_VIDEO_DEVICE), EFI_VIDEO_DEVICE_CLASS },
{ STRING_TOKEN (STR_NETWORK_DEVICE), EFI_NETWORK_DEVICE_CLASS },
{ STRING_TOKEN (STR_INPUT_DEVICE), EFI_INPUT_DEVICE_CLASS },
{ STRING_TOKEN (STR_ON_BOARD_DEVICE), EFI_ON_BOARD_DEVICE_CLASS },
{ STRING_TOKEN (STR_OTHER_DEVICE), EFI_OTHER_DEVICE_CLASS }
};
HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {
{
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8) (sizeof (VENDOR_DEVICE_PATH)),
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
}
},
//
// {102579A0-3686-466e-ACD8-80C087044F4A}
//
{ 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
(UINT8) (END_DEVICE_PATH_LENGTH),
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
}
}
};
/**
This function is invoked if user selected a iteractive opcode from Device Manager's
Formset. The decision by user is saved to gCallbackKey for later processing. If
user set VBIOS, the new value is saved to EFI variable.
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
@param Action Specifies the type of action taken by the browser.
@param QuestionId A unique value which is sent to the original exporting driver
so that it can identify the type of data to expect.
@param Type The type of value for the question.
@param Value A pointer to the data being sent to the original exporting driver.
@param ActionRequest On return, points to the action requested by the callback function.
@retval EFI_SUCCESS The callback successfully handled the action.
@retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
**/
EFI_STATUS
EFIAPI
DeviceManagerCallback (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN EFI_BROWSER_ACTION Action,
IN EFI_QUESTION_ID QuestionId,
IN UINT8 Type,
IN EFI_IFR_TYPE_VALUE *Value,
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
)
{
if ((Value == NULL) || (ActionRequest == NULL)) {
return EFI_INVALID_PARAMETER;
}
gCallbackKey = QuestionId;
//
// Request to exit SendForm(), so as to switch to selected form
//
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
return EFI_SUCCESS;
}
/**
This function registers HII packages to HII database.
@retval EFI_SUCCESS HII packages for the Device Manager were registered successfully.
@retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered.
**/
EFI_STATUS
InitializeDeviceManager (
VOID
)
{
EFI_STATUS Status;
//
// Install Device Path Protocol and Config Access protocol to driver handle
//
Status = gBS->InstallMultipleProtocolInterfaces (
&gDeviceManagerPrivate.DriverHandle,
&gEfiDevicePathProtocolGuid,
&mDeviceManagerHiiVendorDevicePath,
&gEfiHiiConfigAccessProtocolGuid,
&gDeviceManagerPrivate.ConfigAccess,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Publish our HII data
//
gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
&mDeviceManagerGuid,
gDeviceManagerPrivate.DriverHandle,
DeviceManagerVfrBin,
BdsDxeStrings,
NULL
);
if (gDeviceManagerPrivate.HiiHandle == NULL) {
Status = EFI_OUT_OF_RESOURCES;
} else {
Status = EFI_SUCCESS;
}
return Status;
}
/**
Extract the displayed formset for given HII handle and class guid.
@param Handle The HII handle.
@param SetupClassGuid The class guid specifies which form set will be displayed.
@param FormSetTitle Formset title string.
@param FormSetHelp Formset help string.
@retval TRUE The formset for given HII handle will be displayed.
@return FALSE The formset for given HII handle will not be displayed.
**/
BOOLEAN
ExtractDisplayedHiiFormFromHiiHandle (
IN EFI_HII_HANDLE Handle,
IN EFI_GUID *SetupClassGuid,
OUT EFI_STRING_ID *FormSetTitle,
OUT EFI_STRING_ID *FormSetHelp
)
{
EFI_STATUS Status;
UINTN BufferSize;
EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
UINT8 *Package;
UINT8 *OpCodeData;
UINT32 Offset;
UINT32 Offset2;
UINT32 PackageListLength;
EFI_HII_PACKAGE_HEADER PackageHeader;
EFI_GUID *ClassGuid;
UINT8 ClassGuidNum;
ASSERT (Handle != NULL);
ASSERT (SetupClassGuid != NULL);
ASSERT (FormSetTitle != NULL);
ASSERT (FormSetHelp != NULL);
*FormSetTitle = 0;
*FormSetHelp = 0;
ClassGuidNum = 0;
ClassGuid = NULL;
//
// Get HII PackageList
//
BufferSize = 0;
HiiPackageList = NULL;
Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
//
// Handle is a invalid handle. Check if Handle is corrupted.
//
ASSERT (Status != EFI_NOT_FOUND);
//
// The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
//
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
HiiPackageList = AllocatePool (BufferSize);
ASSERT (HiiPackageList != NULL);
Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
if (EFI_ERROR (Status)) {
return FALSE;
}
//
// Get Form package from this HII package List
//
Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
Offset2 = 0;
PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);
while (Offset < PackageListLength) {
Package = ((UINT8 *) HiiPackageList) + Offset;
CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {
//
// Search FormSet Opcode in this Form Package
//
Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);
while (Offset2 < PackageHeader.Length) {
OpCodeData = Package + Offset2;
if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {
//
// Find FormSet OpCode
//
ClassGuidNum = ((EFI_IFR_FORM_SET *) OpCodeData)->Flags;
ClassGuid = (EFI_GUID *) (VOID *)(OpCodeData + sizeof (EFI_IFR_FORM_SET));
while (ClassGuidNum-- > 0) {
if (CompareGuid (SetupClassGuid, ClassGuid)) {
CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));
CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));
FreePool (HiiPackageList);
return TRUE;
}
}
}
//
// Go to next opcode
//
Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
}
}
//
// Go to next package
//
Offset += PackageHeader.Length;
}
FreePool (HiiPackageList);
return FALSE;
}
/**
Call the browser and display the device manager to allow user
to configure the platform.
This function create the dynamic content for device manager. It includes
section header for all class of devices, one-of opcode to set VBIOS.
@retval EFI_SUCCESS Operation is successful.
@return Other values if failed to clean up the dynamic content from HII
database.
**/
EFI_STATUS
CallDeviceManager (
VOID
)
{
EFI_STATUS Status;
UINTN Index;
EFI_STRING String;
EFI_STRING_ID Token;
EFI_STRING_ID TokenHelp;
EFI_HII_HANDLE *HiiHandles;
EFI_HII_HANDLE HiiHandle;
EFI_STRING_ID FormSetTitle;
EFI_STRING_ID FormSetHelp;
EFI_BROWSER_ACTION_REQUEST ActionRequest;
VOID *StartOpCodeHandle;
VOID *EndOpCodeHandle;
EFI_IFR_GUID_LABEL *StartLabel;
EFI_IFR_GUID_LABEL *EndLabel;
HiiHandles = NULL;
Status = EFI_SUCCESS;
gCallbackKey = 0;
//
// Connect all prior to entering the platform setup menu.
//
if (!gConnectAllHappened) {
BdsLibConnectAllDriversToAllControllers ();
gConnectAllHappened = TRUE;
}
//
// Create Subtitle OpCodes
//
//
// Allocate space for creation of UpdateData Buffer
//
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (StartOpCodeHandle != NULL);
EndOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (EndOpCodeHandle != NULL);
//
// Create Hii Extend Label OpCode as the start opcode
//
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
StartLabel->Number = LABEL_DEVICES_LIST;
//
// Create Hii Extend Label OpCode as the end opcode
//
EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
EndLabel->Number = LABEL_END;
HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DEVICES_LIST), 0, 0, 1);
//
// Get all the Hii handles
//
HiiHandles = HiiGetHiiHandles (NULL);
ASSERT (HiiHandles != NULL);
HiiHandle = gDeviceManagerPrivate.HiiHandle;
//
// Search for formset of each class type
//
for (Index = 0; HiiHandles[Index] != NULL; Index++) {
if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, &FormSetTitle, &FormSetHelp)) {
continue;
}
String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);
ASSERT (String != NULL);
Token = HiiSetString (HiiHandle, 0, String, NULL);
FreePool (String);
String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL);
ASSERT (String != NULL);
TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);
FreePool (String);
HiiCreateActionOpCode (
StartOpCodeHandle,
(EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
Token,
TokenHelp,
EFI_IFR_FLAG_CALLBACK,
0
);
}
//
// Add End Opcode for Subtitle
//
HiiCreateEndOpCode (StartOpCodeHandle);
HiiUpdateForm (
HiiHandle,
&mDeviceManagerGuid,
DEVICE_MANAGER_FORM_ID,
StartOpCodeHandle,
EndOpCodeHandle
);
ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
Status = gFormBrowser2->SendForm (
gFormBrowser2,
&HiiHandle,
1,
&mDeviceManagerGuid,
0,
NULL,
&ActionRequest
);
if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
EnableResetRequired ();
}
//
// We will have returned from processing a callback - user either hit ESC to exit, or selected
// a target to display
//
if (gCallbackKey != 0) {
ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
Status = gFormBrowser2->SendForm (
gFormBrowser2,
&HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],
1,
NULL,
0,
NULL,
&ActionRequest
);
if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
EnableResetRequired ();
}
//
// Force return to Device Manager
//
gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
}
//
// Cleanup dynamic created strings in HII database by reinstall the packagelist
//
HiiRemovePackages (HiiHandle);
gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
&mDeviceManagerGuid,
gDeviceManagerPrivate.DriverHandle,
DeviceManagerVfrBin,
BdsDxeStrings,
NULL
);
if (gDeviceManagerPrivate.HiiHandle == NULL) {
Status = EFI_OUT_OF_RESOURCES;
} else {
Status = EFI_SUCCESS;
}
HiiFreeOpCodeHandle (StartOpCodeHandle);
HiiFreeOpCodeHandle (EndOpCodeHandle);
FreePool (HiiHandles);
return Status;
}
|