]>
Commit | Line | Data |
---|---|---|
112e584b SZ |
1 | /** @file\r |
2 | Implementation of the HII for the Opal UEFI Driver.\r | |
3 | \r | |
31587395 | 4 | Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>\r |
289b714b | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
112e584b SZ |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "OpalHii.h"\r | |
40d32e79 ED |
10 | //\r |
11 | // Character definitions\r | |
12 | //\r | |
13 | #define UPPER_LOWER_CASE_OFFSET 0x20\r | |
112e584b SZ |
14 | \r |
15 | //\r | |
16 | // This is the generated IFR binary Data for each formset defined in VFR.\r | |
17 | // This Data array is ready to be used as input of HiiAddPackages() to\r | |
18 | // create a packagelist (which contains Form packages, String packages, etc).\r | |
19 | //\r | |
20 | extern UINT8 OpalPasswordFormBin[];\r | |
21 | \r | |
22 | //\r | |
23 | // This is the generated String package Data for all .UNI files.\r | |
24 | // This Data array is ready to be used as input of HiiAddPackages() to\r | |
25 | // create a packagelist (which contains Form packages, String packages, etc).\r | |
26 | //\r | |
27 | extern UINT8 OpalPasswordDxeStrings[];\r | |
28 | \r | |
29 | CHAR16 OpalPasswordStorageName[] = L"OpalHiiConfig";\r | |
30 | \r | |
31 | EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol;\r | |
32 | \r | |
33 | //\r | |
34 | // Handle to the list of HII packages (forms and strings) for this driver\r | |
35 | //\r | |
36 | EFI_HII_HANDLE gHiiPackageListHandle = NULL;\r | |
37 | \r | |
38 | //\r | |
39 | // Package List GUID containing all form and string packages\r | |
40 | //\r | |
41 | const EFI_GUID gHiiPackageListGuid = PACKAGE_LIST_GUID;\r | |
42 | const EFI_GUID gHiiSetupVariableGuid = SETUP_VARIABLE_GUID;\r | |
43 | \r | |
44 | //\r | |
45 | // Structure that contains state of the HII\r | |
46 | // This structure is updated by Hii.cpp and its contents\r | |
47 | // is rendered in the HII.\r | |
48 | //\r | |
49 | OPAL_HII_CONFIGURATION gHiiConfiguration;\r | |
50 | \r | |
51 | //\r | |
52 | // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL\r | |
53 | //\r | |
54 | HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath = {\r | |
55 | {\r | |
56 | {\r | |
57 | HARDWARE_DEVICE_PATH,\r | |
58 | HW_VENDOR_DP,\r | |
59 | {\r | |
60 | (UINT8)(sizeof(VENDOR_DEVICE_PATH)),\r | |
61 | (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8)\r | |
62 | }\r | |
63 | },\r | |
64 | OPAL_PASSWORD_CONFIG_GUID\r | |
65 | },\r | |
66 | {\r | |
67 | END_DEVICE_PATH_TYPE,\r | |
68 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
69 | {\r | |
70 | (UINT8)(END_DEVICE_PATH_LENGTH),\r | |
71 | (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)\r | |
72 | }\r | |
73 | }\r | |
74 | };\r | |
75 | \r | |
76 | /**\r | |
77 | Get saved OPAL request.\r | |
78 | \r | |
79 | @param[in] OpalDisk The disk needs to get the saved OPAL request.\r | |
80 | @param[out] OpalRequest OPAL request got.\r | |
81 | \r | |
82 | **/\r | |
83 | VOID\r | |
84 | GetSavedOpalRequest (\r | |
85 | IN OPAL_DISK *OpalDisk,\r | |
86 | OUT OPAL_REQUEST *OpalRequest\r | |
87 | )\r | |
88 | {\r | |
89 | EFI_STATUS Status;\r | |
90 | OPAL_REQUEST_VARIABLE *TempVariable;\r | |
91 | OPAL_REQUEST_VARIABLE *Variable;\r | |
92 | UINTN VariableSize;\r | |
93 | EFI_DEVICE_PATH_PROTOCOL *DevicePathInVariable;\r | |
94 | UINTN DevicePathSizeInVariable;\r | |
95 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
96 | UINTN DevicePathSize;\r | |
97 | \r | |
98 | DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));\r | |
99 | \r | |
100 | Variable = NULL;\r | |
101 | VariableSize = 0;\r | |
102 | \r | |
103 | Status = GetVariable2 (\r | |
104 | OPAL_REQUEST_VARIABLE_NAME,\r | |
105 | &gHiiSetupVariableGuid,\r | |
106 | (VOID **) &Variable,\r | |
107 | &VariableSize\r | |
108 | );\r | |
109 | if (EFI_ERROR (Status) || (Variable == NULL)) {\r | |
110 | return;\r | |
111 | }\r | |
112 | \r | |
113 | TempVariable = Variable;\r | |
114 | while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&\r | |
115 | (VariableSize >= TempVariable->Length) &&\r | |
116 | (TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE))) {\r | |
117 | DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) TempVariable + sizeof (OPAL_REQUEST_VARIABLE));\r | |
118 | DevicePathSizeInVariable = GetDevicePathSize (DevicePathInVariable);\r | |
119 | DevicePath = OpalDisk->OpalDevicePath;\r | |
120 | DevicePathSize = GetDevicePathSize (DevicePath);\r | |
121 | if ((DevicePathSize == DevicePathSizeInVariable) &&\r | |
122 | (CompareMem (DevicePath, DevicePathInVariable, DevicePathSize) == 0)) {\r | |
123 | //\r | |
124 | // Found the node for the OPAL device.\r | |
125 | // Get the OPAL request.\r | |
126 | //\r | |
127 | CopyMem (OpalRequest, &TempVariable->OpalRequest, sizeof (OPAL_REQUEST));\r | |
128 | DEBUG ((\r | |
129 | DEBUG_INFO,\r | |
130 | "OpalRequest got: 0x%x\n",\r | |
131 | *OpalRequest\r | |
132 | ));\r | |
133 | break;\r | |
134 | }\r | |
135 | VariableSize -= TempVariable->Length;\r | |
136 | TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) TempVariable + TempVariable->Length);\r | |
137 | }\r | |
138 | \r | |
139 | FreePool (Variable);\r | |
140 | \r | |
141 | DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | Save OPAL request.\r | |
146 | \r | |
147 | @param[in] OpalDisk The disk has OPAL request to save.\r | |
148 | @param[in] OpalRequest OPAL request to save.\r | |
149 | \r | |
150 | **/\r | |
151 | VOID\r | |
152 | SaveOpalRequest (\r | |
153 | IN OPAL_DISK *OpalDisk,\r | |
154 | IN OPAL_REQUEST OpalRequest\r | |
155 | )\r | |
156 | {\r | |
157 | EFI_STATUS Status;\r | |
158 | OPAL_REQUEST_VARIABLE *TempVariable;\r | |
159 | UINTN TempVariableSize;\r | |
160 | OPAL_REQUEST_VARIABLE *Variable;\r | |
161 | UINTN VariableSize;\r | |
162 | OPAL_REQUEST_VARIABLE *NewVariable;\r | |
163 | UINTN NewVariableSize;\r | |
164 | EFI_DEVICE_PATH_PROTOCOL *DevicePathInVariable;\r | |
165 | UINTN DevicePathSizeInVariable;\r | |
166 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
167 | UINTN DevicePathSize;\r | |
168 | \r | |
169 | DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));\r | |
170 | \r | |
171 | DEBUG ((\r | |
172 | DEBUG_INFO,\r | |
173 | "OpalRequest to save: 0x%x\n",\r | |
174 | OpalRequest\r | |
175 | ));\r | |
176 | \r | |
177 | Variable = NULL;\r | |
178 | VariableSize = 0;\r | |
179 | NewVariable = NULL;\r | |
180 | NewVariableSize = 0;\r | |
181 | \r | |
182 | Status = GetVariable2 (\r | |
183 | OPAL_REQUEST_VARIABLE_NAME,\r | |
184 | &gHiiSetupVariableGuid,\r | |
185 | (VOID **) &Variable,\r | |
186 | &VariableSize\r | |
187 | );\r | |
188 | if (!EFI_ERROR (Status) && (Variable != NULL)) {\r | |
189 | TempVariable = Variable;\r | |
190 | TempVariableSize = VariableSize;\r | |
191 | while ((TempVariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&\r | |
192 | (TempVariableSize >= TempVariable->Length) &&\r | |
193 | (TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE))) {\r | |
194 | DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) TempVariable + sizeof (OPAL_REQUEST_VARIABLE));\r | |
195 | DevicePathSizeInVariable = GetDevicePathSize (DevicePathInVariable);\r | |
196 | DevicePath = OpalDisk->OpalDevicePath;\r | |
197 | DevicePathSize = GetDevicePathSize (DevicePath);\r | |
198 | if ((DevicePathSize == DevicePathSizeInVariable) &&\r | |
199 | (CompareMem (DevicePath, DevicePathInVariable, DevicePathSize) == 0)) {\r | |
200 | //\r | |
201 | // Found the node for the OPAL device.\r | |
202 | // Update the OPAL request.\r | |
203 | //\r | |
204 | CopyMem (&TempVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));\r | |
205 | NewVariable = Variable;\r | |
206 | NewVariableSize = VariableSize;\r | |
207 | break;\r | |
208 | }\r | |
209 | TempVariableSize -= TempVariable->Length;\r | |
210 | TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) TempVariable + TempVariable->Length);\r | |
211 | }\r | |
212 | if (NewVariable == NULL) {\r | |
213 | //\r | |
214 | // The node for the OPAL device is not found.\r | |
215 | // Create node for the OPAL device.\r | |
216 | //\r | |
217 | DevicePath = OpalDisk->OpalDevicePath;\r | |
218 | DevicePathSize = GetDevicePathSize (DevicePath);\r | |
219 | NewVariableSize = VariableSize + sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;\r | |
220 | NewVariable = AllocatePool (NewVariableSize);\r | |
221 | ASSERT (NewVariable != NULL);\r | |
222 | CopyMem (NewVariable, Variable, VariableSize);\r | |
223 | TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) NewVariable + VariableSize);\r | |
224 | TempVariable->Length = (UINT32) (sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);\r | |
225 | CopyMem (&TempVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));\r | |
226 | DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) TempVariable + sizeof (OPAL_REQUEST_VARIABLE));\r | |
227 | CopyMem (DevicePathInVariable, DevicePath, DevicePathSize);\r | |
228 | }\r | |
229 | } else {\r | |
230 | DevicePath = OpalDisk->OpalDevicePath;\r | |
231 | DevicePathSize = GetDevicePathSize (DevicePath);\r | |
232 | NewVariableSize = sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;\r | |
233 | NewVariable = AllocatePool (NewVariableSize);\r | |
234 | ASSERT (NewVariable != NULL);\r | |
235 | NewVariable->Length = (UINT32) (sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);\r | |
236 | CopyMem (&NewVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));\r | |
237 | DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) NewVariable + sizeof (OPAL_REQUEST_VARIABLE));\r | |
238 | CopyMem (DevicePathInVariable, DevicePath, DevicePathSize);\r | |
239 | }\r | |
240 | Status = gRT->SetVariable (\r | |
241 | OPAL_REQUEST_VARIABLE_NAME,\r | |
242 | (EFI_GUID *) &gHiiSetupVariableGuid,\r | |
243 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
244 | NewVariableSize,\r | |
245 | NewVariable\r | |
246 | );\r | |
247 | if (EFI_ERROR (Status)) {\r | |
248 | DEBUG ((DEBUG_INFO, "OpalRequest variable set failed (%r)\n", Status));\r | |
249 | }\r | |
250 | if (NewVariable != Variable) {\r | |
251 | FreePool (NewVariable);\r | |
252 | }\r | |
253 | if (Variable != NULL) {\r | |
254 | FreePool (Variable);\r | |
255 | }\r | |
256 | \r | |
257 | DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));\r | |
258 | }\r | |
259 | \r | |
260 | /**\r | |
261 | Sets the current system state of global config variables.\r | |
262 | \r | |
263 | **/\r | |
264 | VOID\r | |
265 | HiiSetCurrentConfiguration(\r | |
266 | VOID\r | |
267 | )\r | |
268 | {\r | |
269 | UINT32 PpStorageFlag;\r | |
270 | EFI_STRING NewString;\r | |
271 | \r | |
272 | gHiiConfiguration.NumDisks = GetDeviceCount();\r | |
273 | \r | |
274 | //\r | |
275 | // Update the BlockSID status string.\r | |
276 | //\r | |
277 | PpStorageFlag = Tcg2PhysicalPresenceLibGetManagementFlags ();\r | |
278 | \r | |
279 | if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID) != 0) {\r | |
280 | NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_ENABLED), NULL);\r | |
281 | if (NewString == NULL) {\r | |
282 | DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));\r | |
283 | return;\r | |
284 | }\r | |
285 | } else {\r | |
286 | NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISABLED), NULL);\r | |
287 | if (NewString == NULL) {\r | |
288 | DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));\r | |
289 | return;\r | |
290 | }\r | |
291 | }\r | |
292 | HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS1), NewString, NULL);\r | |
293 | FreePool (NewString);\r | |
294 | \r | |
295 | if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) != 0) {\r | |
296 | NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_TRUE), NULL);\r | |
297 | if (NewString == NULL) {\r | |
298 | DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));\r | |
299 | return;\r | |
300 | }\r | |
301 | } else {\r | |
302 | NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_FALSE), NULL);\r | |
303 | if (NewString == NULL) {\r | |
304 | DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));\r | |
305 | return;\r | |
306 | }\r | |
307 | }\r | |
308 | HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS2), NewString, NULL);\r | |
309 | FreePool (NewString);\r | |
310 | \r | |
311 | if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) != 0) {\r | |
312 | NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_TRUE), NULL);\r | |
313 | if (NewString == NULL) {\r | |
314 | DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));\r | |
315 | return;\r | |
316 | }\r | |
317 | } else {\r | |
318 | NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_FALSE), NULL);\r | |
319 | if (NewString == NULL) {\r | |
320 | DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));\r | |
321 | return;\r | |
322 | }\r | |
323 | }\r | |
324 | HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS3), NewString, NULL);\r | |
325 | FreePool (NewString);\r | |
326 | }\r | |
327 | \r | |
328 | /**\r | |
329 | Install the HII related resources.\r | |
330 | \r | |
331 | @retval EFI_SUCCESS Install all the resources success.\r | |
332 | @retval other Error occur when install the resources.\r | |
333 | **/\r | |
334 | EFI_STATUS\r | |
335 | HiiInstall(\r | |
336 | VOID\r | |
337 | )\r | |
338 | {\r | |
339 | EFI_STATUS Status;\r | |
340 | EFI_HANDLE DriverHandle;\r | |
341 | \r | |
342 | //\r | |
343 | // Clear the global configuration.\r | |
344 | //\r | |
345 | ZeroMem(&gHiiConfiguration, sizeof(gHiiConfiguration));\r | |
346 | \r | |
347 | //\r | |
348 | // Obtain the driver handle that the BIOS assigned us\r | |
349 | //\r | |
350 | DriverHandle = HiiGetDriverImageHandleCB();\r | |
351 | \r | |
352 | //\r | |
353 | // Populate the config access protocol with the three functions we are publishing\r | |
354 | //\r | |
355 | gHiiConfigAccessProtocol.ExtractConfig = ExtractConfig;\r | |
356 | gHiiConfigAccessProtocol.RouteConfig = RouteConfig;\r | |
357 | gHiiConfigAccessProtocol.Callback = DriverCallback;\r | |
358 | \r | |
359 | //\r | |
360 | // Associate the required protocols with our driver handle\r | |
361 | //\r | |
362 | Status = gBS->InstallMultipleProtocolInterfaces(\r | |
363 | &DriverHandle,\r | |
364 | &gEfiHiiConfigAccessProtocolGuid,\r | |
365 | &gHiiConfigAccessProtocol, // HII callback\r | |
366 | &gEfiDevicePathProtocolGuid,\r | |
367 | &gHiiVendorDevicePath, // required for HII callback allow all disks to be shown in same hii\r | |
368 | NULL\r | |
369 | );\r | |
370 | \r | |
371 | if (EFI_ERROR(Status)) {\r | |
372 | return Status;\r | |
373 | }\r | |
374 | \r | |
375 | return OpalHiiAddPackages();\r | |
376 | }\r | |
377 | \r | |
378 | /**\r | |
379 | Install the HII form and string packages.\r | |
380 | \r | |
381 | @retval EFI_SUCCESS Install all the resources success.\r | |
382 | @retval EFI_OUT_OF_RESOURCES Out of resource error.\r | |
383 | **/\r | |
384 | EFI_STATUS\r | |
385 | OpalHiiAddPackages(\r | |
386 | VOID\r | |
387 | )\r | |
388 | {\r | |
389 | EFI_HANDLE DriverHandle;\r | |
112e584b SZ |
390 | \r |
391 | DriverHandle = HiiGetDriverImageHandleCB();\r | |
392 | \r | |
393 | //\r | |
394 | // Publish the HII form and HII string packages\r | |
395 | //\r | |
396 | gHiiPackageListHandle = HiiAddPackages(\r | |
397 | &gHiiPackageListGuid,\r | |
398 | DriverHandle,\r | |
399 | OpalPasswordDxeStrings,\r | |
400 | OpalPasswordFormBin,\r | |
401 | (VOID*)NULL\r | |
402 | );\r | |
403 | \r | |
404 | //\r | |
405 | // Make sure the packages installed successfully\r | |
406 | //\r | |
407 | if (gHiiPackageListHandle == NULL) {\r | |
408 | DEBUG ((DEBUG_INFO, "OpalHiiAddPackages failed\n"));\r | |
409 | return EFI_OUT_OF_RESOURCES;\r | |
410 | }\r | |
411 | \r | |
112e584b SZ |
412 | return EFI_SUCCESS;\r |
413 | }\r | |
414 | \r | |
415 | /**\r | |
416 | Uninstall the HII capability.\r | |
417 | \r | |
418 | @retval EFI_SUCCESS Uninstall all the resources success.\r | |
419 | @retval others Other errors occur when unistall the hii resource.\r | |
420 | **/\r | |
421 | EFI_STATUS\r | |
422 | HiiUninstall(\r | |
423 | VOID\r | |
424 | )\r | |
425 | {\r | |
426 | EFI_STATUS Status;\r | |
427 | \r | |
428 | //\r | |
429 | // Remove the packages we've provided to the BIOS\r | |
430 | //\r | |
431 | HiiRemovePackages(gHiiPackageListHandle);\r | |
432 | \r | |
433 | //\r | |
434 | // Remove the protocols from our driver handle\r | |
435 | //\r | |
436 | Status = gBS->UninstallMultipleProtocolInterfaces(\r | |
437 | HiiGetDriverImageHandleCB(),\r | |
438 | &gEfiHiiConfigAccessProtocolGuid,\r | |
439 | &gHiiConfigAccessProtocol, // HII callback\r | |
440 | &gEfiDevicePathProtocolGuid,\r | |
441 | &gHiiVendorDevicePath, // required for HII callback\r | |
442 | NULL\r | |
443 | );\r | |
444 | if (EFI_ERROR(Status)) {\r | |
445 | DEBUG ((DEBUG_INFO, "Cannot uninstall Hii Protocols: %r\n", Status));\r | |
446 | }\r | |
447 | \r | |
448 | return Status;\r | |
449 | }\r | |
450 | \r | |
451 | /**\r | |
452 | Updates the main menu form.\r | |
453 | \r | |
454 | @retval EFI_SUCCESS update the main form success.\r | |
455 | **/\r | |
456 | EFI_STATUS\r | |
457 | HiiPopulateMainMenuForm (\r | |
458 | VOID\r | |
459 | )\r | |
460 | {\r | |
461 | UINT8 Index;\r | |
462 | CHAR8 *DiskName;\r | |
463 | EFI_STRING_ID DiskNameId;\r | |
464 | OPAL_DISK *OpalDisk;\r | |
465 | \r | |
466 | HiiSetCurrentConfiguration();\r | |
467 | \r | |
468 | gHiiConfiguration.SupportedDisks = 0;\r | |
469 | \r | |
470 | for (Index = 0; Index < gHiiConfiguration.NumDisks; Index++) {\r | |
471 | OpalDisk = HiiGetOpalDiskCB (Index);\r | |
472 | if ((OpalDisk != NULL) && OpalFeatureSupported (&OpalDisk->SupportedAttributes)) {\r | |
473 | gHiiConfiguration.SupportedDisks |= (1 << Index);\r | |
474 | DiskNameId = GetDiskNameStringId (Index);\r | |
475 | DiskName = HiiDiskGetNameCB (Index);\r | |
476 | if ((DiskName == NULL) || (DiskNameId == 0)) {\r | |
477 | return EFI_UNSUPPORTED;\r | |
478 | }\r | |
479 | HiiSetFormString(DiskNameId, DiskName);\r | |
480 | }\r | |
481 | }\r | |
482 | \r | |
483 | OpalHiiSetBrowserData ();\r | |
484 | return EFI_SUCCESS;\r | |
485 | }\r | |
486 | \r | |
487 | /**\r | |
488 | Get disk name string id.\r | |
489 | \r | |
490 | @param DiskIndex The input disk index info.\r | |
491 | \r | |
492 | @retval The disk name string id.\r | |
493 | \r | |
494 | **/\r | |
495 | EFI_STRING_ID\r | |
496 | GetDiskNameStringId(\r | |
497 | UINT8 DiskIndex\r | |
498 | )\r | |
499 | {\r | |
500 | switch (DiskIndex) {\r | |
501 | case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0);\r | |
502 | case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1);\r | |
503 | case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2);\r | |
504 | case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3);\r | |
505 | case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4);\r | |
506 | case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5);\r | |
507 | }\r | |
508 | return 0;\r | |
509 | }\r | |
510 | \r | |
40d32e79 ED |
511 | /**\r |
512 | Confirm whether user truly want to do the revert action.\r | |
513 | \r | |
514 | @param OpalDisk The device which need to do the revert action.\r | |
515 | \r | |
516 | @retval EFI_SUCCESS Confirmed user want to do the revert action.\r | |
517 | **/\r | |
518 | EFI_STATUS\r | |
519 | HiiConfirmRevertAction (\r | |
520 | IN OPAL_DISK *OpalDisk\r | |
521 | \r | |
522 | )\r | |
523 | {\r | |
524 | CHAR16 Unicode[512];\r | |
525 | EFI_INPUT_KEY Key;\r | |
526 | CHAR16 ApproveResponse;\r | |
527 | CHAR16 RejectResponse;\r | |
528 | \r | |
529 | //\r | |
530 | // When the estimate cost time bigger than MAX_ACCEPTABLE_REVERTING_TIME, pop up dialog to let user confirm\r | |
531 | // the revert action.\r | |
532 | //\r | |
533 | if (OpalDisk->EstimateTimeCost < MAX_ACCEPTABLE_REVERTING_TIME) {\r | |
534 | return EFI_SUCCESS;\r | |
535 | }\r | |
536 | \r | |
537 | ApproveResponse = L'Y';\r | |
538 | RejectResponse = L'N';\r | |
539 | \r | |
540 | UnicodeSPrint(Unicode, StrSize(L"WARNING: Revert device needs about ####### seconds"), L"WARNING: Revert device needs about %d seconds", OpalDisk->EstimateTimeCost);\r | |
541 | \r | |
542 | do {\r | |
543 | CreatePopUp(\r | |
544 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
545 | &Key,\r | |
546 | Unicode,\r | |
547 | L" System should not be powered off until revert completion ",\r | |
548 | L" ",\r | |
549 | L" Press 'Y/y' to continue, press 'N/n' to cancal ",\r | |
550 | NULL\r | |
551 | );\r | |
552 | } while (\r | |
553 | ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (ApproveResponse | UPPER_LOWER_CASE_OFFSET)) &&\r | |
554 | ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (RejectResponse | UPPER_LOWER_CASE_OFFSET))\r | |
555 | );\r | |
556 | \r | |
557 | if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (RejectResponse | UPPER_LOWER_CASE_OFFSET)) {\r | |
558 | return EFI_ABORTED;\r | |
559 | }\r | |
560 | \r | |
561 | return EFI_SUCCESS;\r | |
562 | }\r | |
563 | \r | |
112e584b SZ |
564 | /**\r |
565 | This function processes the results of changes in configuration.\r | |
566 | \r | |
567 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
568 | @param Action Specifies the type of action taken by the browser.\r | |
569 | @param QuestionId A unique value which is sent to the original\r | |
570 | exporting driver so that it can identify the type\r | |
571 | of data to expect.\r | |
572 | @param Type The type of value for the question.\r | |
573 | @param Value A pointer to the data being sent to the original\r | |
574 | exporting driver.\r | |
575 | @param ActionRequest On return, points to the action requested by the\r | |
576 | callback function.\r | |
577 | \r | |
578 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
579 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r | |
580 | variable and its data.\r | |
581 | @retval EFI_DEVICE_ERROR The variable could not be saved.\r | |
582 | @retval EFI_UNSUPPORTED The specified Action is not supported by the\r | |
583 | callback.\r | |
584 | \r | |
585 | **/\r | |
586 | EFI_STATUS\r | |
587 | EFIAPI\r | |
588 | DriverCallback(\r | |
589 | CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
590 | EFI_BROWSER_ACTION Action,\r | |
591 | EFI_QUESTION_ID QuestionId,\r | |
592 | UINT8 Type,\r | |
593 | EFI_IFR_TYPE_VALUE *Value,\r | |
594 | EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
595 | )\r | |
596 | {\r | |
597 | HII_KEY HiiKey;\r | |
598 | UINT8 HiiKeyId;\r | |
599 | UINT32 PpRequest;\r | |
600 | OPAL_DISK *OpalDisk;\r | |
601 | \r | |
602 | if (ActionRequest != NULL) {\r | |
603 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r | |
604 | } else {\r | |
605 | return EFI_INVALID_PARAMETER;\r | |
606 | }\r | |
607 | \r | |
608 | //\r | |
609 | // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.\r | |
610 | //\r | |
611 | if ((QuestionId & HII_KEY_FLAG) == 0) {\r | |
612 | return EFI_SUCCESS;\r | |
613 | }\r | |
614 | \r | |
615 | HiiKey.Raw = QuestionId;\r | |
616 | HiiKeyId = (UINT8) HiiKey.KeyBits.Id;\r | |
617 | \r | |
618 | if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r | |
619 | switch (HiiKeyId) {\r | |
620 | case HII_KEY_ID_VAR_SUPPORTED_DISKS:\r | |
621 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));\r | |
622 | return HiiPopulateMainMenuForm ();\r | |
623 | \r | |
624 | case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS:\r | |
625 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS\n"));\r | |
626 | return HiiPopulateDiskInfoForm();\r | |
627 | }\r | |
628 | } else if (Action == EFI_BROWSER_ACTION_CHANGING) {\r | |
629 | switch (HiiKeyId) {\r | |
630 | case HII_KEY_ID_GOTO_DISK_INFO:\r | |
631 | return HiiSelectDisk((UINT8)HiiKey.KeyBits.Index);\r | |
40d32e79 ED |
632 | \r |
633 | case HII_KEY_ID_REVERT:\r | |
634 | case HII_KEY_ID_PSID_REVERT:\r | |
635 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
636 | if (OpalDisk != NULL) {\r | |
637 | return HiiConfirmRevertAction (OpalDisk);\r | |
638 | } else {\r | |
639 | ASSERT (FALSE);\r | |
640 | return EFI_SUCCESS;\r | |
641 | }\r | |
642 | \r | |
112e584b SZ |
643 | }\r |
644 | } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r | |
645 | switch (HiiKeyId) {\r | |
646 | case HII_KEY_ID_BLOCKSID:\r | |
647 | switch (Value->u8) {\r | |
648 | case 0:\r | |
649 | PpRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION;\r | |
650 | break;\r | |
651 | \r | |
652 | case 1:\r | |
653 | PpRequest = TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID;\r | |
654 | break;\r | |
655 | \r | |
656 | case 2:\r | |
657 | PpRequest = TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID;\r | |
658 | break;\r | |
659 | \r | |
660 | case 3:\r | |
661 | PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE;\r | |
662 | break;\r | |
663 | \r | |
664 | case 4:\r | |
665 | PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE;\r | |
666 | break;\r | |
667 | \r | |
668 | case 5:\r | |
669 | PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE;\r | |
670 | break;\r | |
671 | \r | |
672 | case 6:\r | |
673 | PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE;\r | |
674 | break;\r | |
675 | \r | |
676 | default:\r | |
677 | PpRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION;\r | |
678 | DEBUG ((DEBUG_ERROR, "Invalid value input!\n"));\r | |
679 | break;\r | |
680 | }\r | |
681 | HiiSetBlockSidAction(PpRequest);\r | |
682 | \r | |
683 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
684 | return EFI_SUCCESS;\r | |
685 | \r | |
686 | case HII_KEY_ID_SET_ADMIN_PWD:\r | |
687 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_SET_ADMIN_PWD\n"));\r | |
688 | gHiiConfiguration.OpalRequest.SetAdminPwd = Value->b;\r | |
689 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
690 | if (OpalDisk != NULL) {\r | |
691 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
692 | }\r | |
693 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
694 | return EFI_SUCCESS;\r | |
695 | \r | |
696 | case HII_KEY_ID_SET_USER_PWD:\r | |
697 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_SET_USER_PWD\n"));\r | |
698 | gHiiConfiguration.OpalRequest.SetUserPwd = Value->b;\r | |
699 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
700 | if (OpalDisk != NULL) {\r | |
701 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
702 | }\r | |
703 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
704 | return EFI_SUCCESS;\r | |
705 | \r | |
706 | case HII_KEY_ID_SECURE_ERASE:\r | |
707 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_SECURE_ERASE\n"));\r | |
708 | gHiiConfiguration.OpalRequest.SecureErase = Value->b;\r | |
709 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
710 | if (OpalDisk != NULL) {\r | |
711 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
712 | }\r | |
713 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
714 | return EFI_SUCCESS;\r | |
b3548d32 | 715 | \r |
112e584b SZ |
716 | case HII_KEY_ID_REVERT:\r |
717 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_REVERT\n"));\r | |
718 | gHiiConfiguration.OpalRequest.Revert = Value->b;\r | |
719 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
720 | if (OpalDisk != NULL) {\r | |
721 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
722 | }\r | |
723 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
724 | return EFI_SUCCESS;\r | |
725 | case HII_KEY_ID_KEEP_USER_DATA:\r | |
726 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_KEEP_USER_DATA\n"));\r | |
727 | gHiiConfiguration.OpalRequest.KeepUserData = Value->b;\r | |
728 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
729 | if (OpalDisk != NULL) {\r | |
730 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
731 | }\r | |
732 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
733 | return EFI_SUCCESS;\r | |
734 | \r | |
735 | case HII_KEY_ID_PSID_REVERT:\r | |
736 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_PSID_REVERT\n"));\r | |
737 | gHiiConfiguration.OpalRequest.PsidRevert = Value->b;\r | |
738 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
739 | if (OpalDisk != NULL) {\r | |
740 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
741 | }\r | |
742 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
743 | return EFI_SUCCESS;\r | |
744 | \r | |
745 | case HII_KEY_ID_DISABLE_USER:\r | |
746 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_DISABLE_USER\n"));\r | |
747 | gHiiConfiguration.OpalRequest.DisableUser = Value->b;\r | |
748 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
749 | if (OpalDisk != NULL) {\r | |
750 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
751 | }\r | |
752 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
753 | return EFI_SUCCESS;\r | |
754 | \r | |
755 | case HII_KEY_ID_ENABLE_FEATURE:\r | |
756 | DEBUG ((DEBUG_INFO, "HII_KEY_ID_ENABLE_FEATURE\n"));\r | |
757 | gHiiConfiguration.OpalRequest.EnableFeature = Value->b;\r | |
758 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
759 | if (OpalDisk != NULL) {\r | |
760 | SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);\r | |
761 | }\r | |
762 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
763 | return EFI_SUCCESS;\r | |
764 | \r | |
765 | default:\r | |
766 | break;\r | |
767 | }\r | |
768 | }\r | |
769 | \r | |
770 | return EFI_UNSUPPORTED;\r | |
771 | }\r | |
772 | \r | |
773 | /**\r | |
774 | Update the global Disk index info.\r | |
775 | \r | |
776 | @param Index The input disk index info.\r | |
777 | \r | |
778 | @retval EFI_SUCCESS Update the disk index info success.\r | |
779 | \r | |
780 | **/\r | |
781 | EFI_STATUS\r | |
782 | HiiSelectDisk(\r | |
783 | UINT8 Index\r | |
784 | )\r | |
785 | {\r | |
786 | OpalHiiGetBrowserData();\r | |
787 | gHiiConfiguration.SelectedDiskIndex = Index;\r | |
788 | OpalHiiSetBrowserData ();\r | |
789 | \r | |
790 | return EFI_SUCCESS;\r | |
791 | }\r | |
792 | \r | |
793 | /**\r | |
794 | Draws the disk info form.\r | |
795 | \r | |
796 | @retval EFI_SUCCESS Draw the disk info success.\r | |
797 | \r | |
798 | **/\r | |
799 | EFI_STATUS\r | |
800 | HiiPopulateDiskInfoForm(\r | |
801 | VOID\r | |
802 | )\r | |
803 | {\r | |
804 | OPAL_DISK* OpalDisk;\r | |
805 | OPAL_DISK_ACTIONS AvailActions;\r | |
806 | TCG_RESULT Ret;\r | |
807 | CHAR8 *DiskName;\r | |
808 | \r | |
809 | OpalHiiGetBrowserData();\r | |
810 | \r | |
811 | DiskName = HiiDiskGetNameCB (gHiiConfiguration.SelectedDiskIndex);\r | |
812 | if (DiskName == NULL) {\r | |
813 | return EFI_UNSUPPORTED;\r | |
814 | }\r | |
815 | HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME), DiskName);\r | |
816 | \r | |
817 | gHiiConfiguration.SelectedDiskAvailableActions = HII_ACTION_NONE;\r | |
818 | ZeroMem (&gHiiConfiguration.OpalRequest, sizeof (OPAL_REQUEST));\r | |
819 | gHiiConfiguration.KeepUserDataForced = FALSE;\r | |
820 | \r | |
821 | OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);\r | |
822 | \r | |
823 | if (OpalDisk != NULL) {\r | |
824 | OpalDiskUpdateStatus (OpalDisk);\r | |
825 | Ret = OpalSupportGetAvailableActions(&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature, OpalDisk->Owner, &AvailActions);\r | |
826 | if (Ret == TcgResultSuccess) {\r | |
827 | //\r | |
828 | // Update actions, always allow PSID Revert\r | |
829 | //\r | |
830 | gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.PsidRevert == 1) ? HII_ACTION_PSID_REVERT : HII_ACTION_NONE;\r | |
831 | \r | |
832 | //\r | |
833 | // Always allow unlock to handle device migration\r | |
834 | //\r | |
835 | gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Unlock == 1) ? HII_ACTION_UNLOCK : HII_ACTION_NONE;\r | |
836 | \r | |
837 | if (!OpalFeatureEnabled (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {\r | |
838 | if (OpalDisk->Owner == OpalOwnershipNobody) {\r | |
839 | gHiiConfiguration.SelectedDiskAvailableActions |= HII_ACTION_ENABLE_FEATURE;\r | |
840 | \r | |
841 | //\r | |
842 | // Update strings\r | |
843 | //\r | |
844 | HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default");\r | |
845 | } else {\r | |
846 | DEBUG ((DEBUG_INFO, "Feature disabled but ownership != nobody\n"));\r | |
847 | }\r | |
848 | } else {\r | |
849 | gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Revert == 1) ? HII_ACTION_REVERT : HII_ACTION_NONE;\r | |
850 | gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.AdminPass == 1) ? HII_ACTION_SET_ADMIN_PWD : HII_ACTION_NONE;\r | |
851 | gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.UserPass == 1) ? HII_ACTION_SET_USER_PWD : HII_ACTION_NONE;\r | |
852 | gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.SecureErase == 1) ? HII_ACTION_SECURE_ERASE : HII_ACTION_NONE;\r | |
853 | gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.DisableUser == 1) ? HII_ACTION_DISABLE_USER : HII_ACTION_NONE;\r | |
854 | \r | |
855 | HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default and Disable");\r | |
856 | \r | |
857 | //\r | |
858 | // Determine revert options for disk\r | |
859 | // Default initialize keep user Data to be true\r | |
860 | //\r | |
861 | gHiiConfiguration.OpalRequest.KeepUserData = 1;\r | |
862 | if (AvailActions.RevertKeepDataForced) {\r | |
863 | gHiiConfiguration.KeepUserDataForced = TRUE;\r | |
864 | }\r | |
865 | }\r | |
866 | }\r | |
867 | \r | |
868 | GetSavedOpalRequest (OpalDisk, &gHiiConfiguration.OpalRequest);\r | |
869 | }\r | |
870 | \r | |
871 | //\r | |
872 | // Pass the current configuration to the BIOS\r | |
873 | //\r | |
874 | OpalHiiSetBrowserData ();\r | |
875 | \r | |
876 | return EFI_SUCCESS;\r | |
877 | }\r | |
878 | \r | |
879 | /**\r | |
880 | Send BlockSid request through TPM physical presence module.\r | |
881 | \r | |
882 | @param PpRequest TPM physical presence operation request.\r | |
883 | \r | |
884 | @retval EFI_SUCCESS Do the required action success.\r | |
885 | @retval Others Other error occur.\r | |
886 | \r | |
887 | **/\r | |
888 | EFI_STATUS\r | |
889 | HiiSetBlockSidAction (\r | |
890 | IN UINT32 PpRequest\r | |
891 | )\r | |
892 | {\r | |
893 | UINT32 ReturnCode;\r | |
894 | EFI_STATUS Status;\r | |
895 | \r | |
896 | ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest, 0);\r | |
897 | if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r | |
898 | Status = EFI_SUCCESS;\r | |
899 | } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r | |
900 | Status = EFI_OUT_OF_RESOURCES;\r | |
901 | } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r | |
902 | Status = EFI_UNSUPPORTED;\r | |
903 | } else {\r | |
904 | Status = EFI_DEVICE_ERROR;\r | |
905 | }\r | |
906 | \r | |
907 | return Status;\r | |
908 | }\r | |
909 | \r | |
910 | /**\r | |
911 | This function processes the results of changes in configuration.\r | |
912 | \r | |
913 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
914 | @param Configuration A null-terminated Unicode string in <ConfigResp>\r | |
915 | format.\r | |
916 | @param Progress A pointer to a string filled in with the offset of\r | |
917 | the most recent '&' before the first failing\r | |
918 | name/value pair (or the beginning of the string if\r | |
919 | the failure is in the first name/value pair) or\r | |
920 | the terminating NULL if all was successful.\r | |
921 | \r | |
922 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
923 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
924 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r | |
925 | driver.\r | |
926 | \r | |
927 | **/\r | |
928 | EFI_STATUS\r | |
929 | EFIAPI\r | |
930 | RouteConfig(\r | |
931 | CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
932 | CONST EFI_STRING Configuration,\r | |
933 | EFI_STRING *Progress\r | |
934 | )\r | |
935 | {\r | |
936 | if (Configuration == NULL || Progress == NULL) {\r | |
937 | return (EFI_INVALID_PARAMETER);\r | |
938 | }\r | |
939 | \r | |
940 | *Progress = Configuration;\r | |
941 | if (!HiiIsConfigHdrMatch (Configuration, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {\r | |
942 | return EFI_NOT_FOUND;\r | |
943 | }\r | |
944 | \r | |
945 | *Progress = Configuration + StrLen (Configuration);\r | |
946 | \r | |
947 | return EFI_SUCCESS;\r | |
948 | }\r | |
949 | \r | |
950 | /**\r | |
951 | This function allows a caller to extract the current configuration for one\r | |
952 | or more named elements from the target driver.\r | |
953 | \r | |
954 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
955 | @param Request A null-terminated Unicode string in\r | |
956 | <ConfigRequest> format.\r | |
957 | @param Progress On return, points to a character in the Request\r | |
958 | string. Points to the string's null terminator if\r | |
959 | request was successful. Points to the most recent\r | |
960 | '&' before the first failing name/value pair (or\r | |
961 | the beginning of the string if the failure is in\r | |
962 | the first name/value pair) if the request was not\r | |
963 | successful.\r | |
964 | @param Results A null-terminated Unicode string in\r | |
965 | <ConfigAltResp> format which has all values filled\r | |
966 | in for the names in the Request string. String to\r | |
967 | be allocated by the called function.\r | |
968 | \r | |
969 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
970 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
971 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r | |
972 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r | |
973 | driver.\r | |
974 | \r | |
975 | **/\r | |
976 | EFI_STATUS\r | |
977 | EFIAPI\r | |
978 | ExtractConfig(\r | |
979 | CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
980 | CONST EFI_STRING Request,\r | |
981 | EFI_STRING *Progress,\r | |
982 | EFI_STRING *Results\r | |
983 | )\r | |
984 | {\r | |
985 | EFI_STATUS Status;\r | |
986 | EFI_STRING ConfigRequest;\r | |
987 | EFI_STRING ConfigRequestHdr;\r | |
988 | UINTN BufferSize;\r | |
989 | UINTN Size;\r | |
990 | BOOLEAN AllocatedRequest;\r | |
991 | EFI_HANDLE DriverHandle;\r | |
992 | \r | |
993 | //\r | |
994 | // Check for valid parameters\r | |
995 | //\r | |
996 | if (Progress == NULL || Results == NULL) {\r | |
997 | return (EFI_INVALID_PARAMETER);\r | |
998 | }\r | |
999 | \r | |
1000 | *Progress = Request;\r | |
1001 | if ((Request != NULL) &&\r | |
1002 | !HiiIsConfigHdrMatch (Request, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {\r | |
1003 | return EFI_NOT_FOUND;\r | |
1004 | }\r | |
1005 | \r | |
1006 | AllocatedRequest = FALSE;\r | |
1007 | BufferSize = sizeof (OPAL_HII_CONFIGURATION);\r | |
1008 | ConfigRequest = Request;\r | |
1009 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r | |
1010 | //\r | |
1011 | // Request has no request element, construct full request string.\r | |
1012 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r | |
1013 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
1014 | //\r | |
1015 | DriverHandle = HiiGetDriverImageHandleCB();\r | |
1016 | ConfigRequestHdr = HiiConstructConfigHdr (&gHiiSetupVariableGuid, OpalPasswordStorageName, DriverHandle);\r | |
1017 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r | |
1018 | ConfigRequest = AllocateZeroPool (Size);\r | |
1019 | if (ConfigRequest == NULL) {\r | |
1020 | return EFI_OUT_OF_RESOURCES;\r | |
1021 | }\r | |
1022 | AllocatedRequest = TRUE;\r | |
1023 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r | |
1024 | FreePool (ConfigRequestHdr);\r | |
1025 | }\r | |
1026 | \r | |
1027 | //\r | |
1028 | // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )\r | |
1029 | //\r | |
1030 | Status = gHiiConfigRouting->BlockToConfig(\r | |
1031 | gHiiConfigRouting,\r | |
1032 | ConfigRequest,\r | |
1033 | (UINT8*)&gHiiConfiguration,\r | |
1034 | sizeof(OPAL_HII_CONFIGURATION),\r | |
1035 | Results,\r | |
1036 | Progress\r | |
1037 | );\r | |
1038 | \r | |
1039 | //\r | |
1040 | // Free the allocated config request string.\r | |
1041 | //\r | |
1042 | if (AllocatedRequest) {\r | |
1043 | FreePool (ConfigRequest);\r | |
1044 | ConfigRequest = NULL;\r | |
1045 | }\r | |
1046 | \r | |
1047 | //\r | |
1048 | // Set Progress string to the original request string.\r | |
1049 | //\r | |
1050 | if (Request == NULL) {\r | |
1051 | *Progress = NULL;\r | |
1052 | } else if (StrStr (Request, L"OFFSET") == NULL) {\r | |
1053 | *Progress = Request + StrLen (Request);\r | |
1054 | }\r | |
1055 | \r | |
1056 | return (Status);\r | |
1057 | }\r | |
1058 | \r | |
1059 | \r | |
1060 | /**\r | |
1061 | \r | |
1062 | Pass the current system state to the bios via the hii_G_Configuration.\r | |
1063 | \r | |
1064 | **/\r | |
1065 | VOID\r | |
1066 | OpalHiiSetBrowserData (\r | |
1067 | VOID\r | |
1068 | )\r | |
1069 | {\r | |
1070 | HiiSetBrowserData(\r | |
1071 | &gHiiSetupVariableGuid,\r | |
1072 | (CHAR16*)L"OpalHiiConfig",\r | |
1073 | sizeof(gHiiConfiguration),\r | |
1074 | (UINT8*)&gHiiConfiguration,\r | |
1075 | NULL\r | |
1076 | );\r | |
1077 | }\r | |
1078 | \r | |
1079 | \r | |
1080 | /**\r | |
1081 | \r | |
1082 | Populate the hii_g_Configuraton with the browser Data.\r | |
1083 | \r | |
1084 | **/\r | |
1085 | VOID\r | |
1086 | OpalHiiGetBrowserData (\r | |
1087 | VOID\r | |
1088 | )\r | |
1089 | {\r | |
1090 | HiiGetBrowserData(\r | |
1091 | &gHiiSetupVariableGuid,\r | |
1092 | (CHAR16*)L"OpalHiiConfig",\r | |
1093 | sizeof(gHiiConfiguration),\r | |
1094 | (UINT8*)&gHiiConfiguration\r | |
1095 | );\r | |
1096 | }\r | |
1097 | \r | |
1098 | /**\r | |
1099 | Set a string Value in a form.\r | |
1100 | \r | |
1101 | @param DestStringId The stringid which need to update.\r | |
1102 | @param SrcAsciiStr The string nned to update.\r | |
1103 | \r | |
1104 | @retval EFI_SUCCESS Do the required action success.\r | |
1105 | @retval Others Other error occur.\r | |
1106 | \r | |
1107 | **/\r | |
1108 | EFI_STATUS\r | |
1109 | HiiSetFormString(\r | |
1110 | EFI_STRING_ID DestStringId,\r | |
1111 | CHAR8 *SrcAsciiStr\r | |
1112 | )\r | |
1113 | {\r | |
1114 | UINT32 Len;\r | |
1115 | UINT32 UniSize;\r | |
1116 | CHAR16* UniStr;\r | |
1117 | \r | |
1118 | //\r | |
1119 | // Determine the Length of the sting\r | |
1120 | //\r | |
1121 | Len = ( UINT32 )AsciiStrLen( SrcAsciiStr );\r | |
1122 | \r | |
1123 | //\r | |
1124 | // Allocate space for the unicode string, including terminator\r | |
1125 | //\r | |
1126 | UniSize = (Len + 1) * sizeof(CHAR16);\r | |
1127 | UniStr = (CHAR16*)AllocateZeroPool(UniSize);\r | |
1128 | \r | |
1129 | //\r | |
1130 | // Copy into unicode string, then copy into string id\r | |
1131 | //\r | |
1132 | AsciiStrToUnicodeStrS ( SrcAsciiStr, UniStr, Len + 1);\r | |
1133 | \r | |
1134 | //\r | |
1135 | // Update the string in the form\r | |
1136 | //\r | |
1137 | if (HiiSetString(gHiiPackageListHandle, DestStringId, UniStr, NULL) == 0) {\r | |
1138 | DEBUG ((DEBUG_INFO, "HiiSetFormString( ) failed\n"));\r | |
1139 | FreePool(UniStr);\r | |
1140 | return (EFI_OUT_OF_RESOURCES);\r | |
1141 | }\r | |
1142 | \r | |
1143 | //\r | |
1144 | // Free the memory\r | |
1145 | //\r | |
1146 | FreePool(UniStr);\r | |
1147 | \r | |
1148 | return (EFI_SUCCESS);\r | |
1149 | }\r | |
1150 | \r | |
1151 | /**\r | |
1152 | Initialize the Opal disk base on the hardware info get from device.\r | |
1153 | \r | |
1154 | @param Dev The Opal device.\r | |
1155 | \r | |
1156 | @retval EFI_SUCESS Initialize the device success.\r | |
1157 | @retval EFI_DEVICE_ERROR Get info from device failed.\r | |
1158 | \r | |
1159 | **/\r | |
1160 | EFI_STATUS\r | |
1161 | OpalDiskInitialize (\r | |
1162 | IN OPAL_DRIVER_DEVICE *Dev\r | |
1163 | )\r | |
1164 | {\r | |
1165 | TCG_RESULT TcgResult;\r | |
1166 | OPAL_SESSION Session;\r | |
40d32e79 ED |
1167 | UINT8 ActiveDataRemovalMechanism;\r |
1168 | UINT32 RemovalMechanishLists[ResearvedMechanism];\r | |
112e584b SZ |
1169 | \r |
1170 | ZeroMem(&Dev->OpalDisk, sizeof(OPAL_DISK));\r | |
1171 | Dev->OpalDisk.Sscp = Dev->Sscp;\r | |
1172 | Dev->OpalDisk.MediaId = Dev->MediaId;\r | |
1173 | Dev->OpalDisk.OpalDevicePath = Dev->OpalDevicePath;\r | |
1174 | \r | |
1175 | ZeroMem(&Session, sizeof(Session));\r | |
1176 | Session.Sscp = Dev->Sscp;\r | |
1177 | Session.MediaId = Dev->MediaId;\r | |
1178 | \r | |
1179 | TcgResult = OpalGetSupportedAttributesInfo (&Session, &Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.OpalBaseComId);\r | |
1180 | if (TcgResult != TcgResultSuccess) {\r | |
1181 | return EFI_DEVICE_ERROR;\r | |
1182 | }\r | |
1183 | Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r | |
1184 | \r | |
1185 | TcgResult = OpalUtilGetMsid (&Session, Dev->OpalDisk.Msid, OPAL_MSID_LENGHT, &Dev->OpalDisk.MsidLength);\r | |
1186 | if (TcgResult != TcgResultSuccess) {\r | |
1187 | return EFI_DEVICE_ERROR;\r | |
1188 | }\r | |
1189 | \r | |
40d32e79 ED |
1190 | if (Dev->OpalDisk.SupportedAttributes.DataRemoval) {\r |
1191 | TcgResult = OpalUtilGetDataRemovalMechanismLists (&Session, RemovalMechanishLists);\r | |
1192 | if (TcgResult != TcgResultSuccess) {\r | |
1193 | return EFI_DEVICE_ERROR;\r | |
1194 | }\r | |
1195 | \r | |
1196 | TcgResult = OpalUtilGetActiveDataRemovalMechanism (&Session, Dev->OpalDisk.Msid, Dev->OpalDisk.MsidLength, &ActiveDataRemovalMechanism);\r | |
1197 | if (TcgResult != TcgResultSuccess) {\r | |
1198 | return EFI_DEVICE_ERROR;\r | |
1199 | }\r | |
1200 | \r | |
1201 | Dev->OpalDisk.EstimateTimeCost = RemovalMechanishLists[ActiveDataRemovalMechanism];\r | |
1202 | }\r | |
1203 | \r | |
112e584b SZ |
1204 | return OpalDiskUpdateStatus (&Dev->OpalDisk);\r |
1205 | }\r | |
1206 | \r | |
1207 | /**\r | |
1208 | Update the device info.\r | |
1209 | \r | |
1210 | @param OpalDisk The Opal device.\r | |
1211 | \r | |
1212 | @retval EFI_SUCESS Initialize the device success.\r | |
1213 | @retval EFI_DEVICE_ERROR Get info from device failed.\r | |
1214 | @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.\r | |
1215 | \r | |
1216 | **/\r | |
1217 | EFI_STATUS\r | |
1218 | OpalDiskUpdateStatus (\r | |
1219 | OPAL_DISK *OpalDisk\r | |
1220 | )\r | |
1221 | {\r | |
1222 | TCG_RESULT TcgResult;\r | |
1223 | OPAL_SESSION Session;\r | |
1224 | \r | |
1225 | ZeroMem(&Session, sizeof(Session));\r | |
1226 | Session.Sscp = OpalDisk->Sscp;\r | |
1227 | Session.MediaId = OpalDisk->MediaId;\r | |
1228 | Session.OpalBaseComId = OpalDisk->OpalBaseComId;\r | |
1229 | \r | |
1230 | TcgResult = OpalGetLockingInfo(&Session, &OpalDisk->LockingFeature);\r | |
1231 | if (TcgResult != TcgResultSuccess) {\r | |
1232 | return EFI_DEVICE_ERROR;\r | |
1233 | }\r | |
1234 | \r | |
1235 | if (OpalDisk->MsidLength == 0) {\r | |
1236 | return EFI_INVALID_PARAMETER;\r | |
1237 | } else {\r | |
1238 | //\r | |
1239 | // Base on the Msid info to get the ownership, so Msid info must get first.\r | |
1240 | //\r | |
1241 | OpalDisk->Owner = OpalUtilDetermineOwnership(&Session, OpalDisk->Msid, OpalDisk->MsidLength);\r | |
1242 | }\r | |
1243 | \r | |
1244 | return EFI_SUCCESS;\r | |
1245 | }\r | |
1246 | \r |