OpalHii.c 41 KB

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