PlatformSetupDxe.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. /** @file
  2. Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include "PlatformSetupDxe.h"
  6. #include "Guid/SetupVariable.h"
  7. #include <Protocol/FormBrowserEx2.h>
  8. #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
  9. #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
  10. typedef struct {
  11. UINTN Signature;
  12. EFI_HANDLE DriverHandle;
  13. EFI_HII_HANDLE RegisteredHandle;
  14. SYSTEM_CONFIGURATION FakeNvData;
  15. SYSTEM_CONFIGURATION BackupNvData;
  16. EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
  17. EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
  18. } EFI_CALLBACK_INFO;
  19. #pragma pack(1)
  20. //
  21. // HII specific Vendor Device Path definition.
  22. //
  23. typedef struct {
  24. VENDOR_DEVICE_PATH VendorDevicePath;
  25. EFI_DEVICE_PATH_PROTOCOL End;
  26. } HII_VENDOR_DEVICE_PATH;
  27. #pragma pack()
  28. //
  29. // uni string and Vfr Binary data.
  30. //
  31. extern UINT8 VfrBin[];
  32. extern UINT8 PlatformSetupDxeStrings[];
  33. EFI_HANDLE mImageHandle;
  34. //
  35. // module global data
  36. //
  37. #define EFI_NORMAL_SETUP_GUID \
  38. { 0xec87d643, 0xeba4, 0x4bb5, 0xa1, 0xe5, 0x3f, 0x3e, 0x36, 0xb2, 0xd, 0xa9 }
  39. EFI_GUID mNormalSetupGuid = EFI_NORMAL_SETUP_GUID;
  40. EFI_GUID mSystemConfigGuid = SYSTEM_CONFIGURATION_GUID;
  41. CHAR16 mVariableName[] = L"Setup";
  42. CHAR16 mSetupName[] = L"Setup";
  43. EFI_CALLBACK_INFO *mCallbackInfo;
  44. BOOLEAN GlobalReset=FALSE;
  45. HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = {
  46. {
  47. {
  48. HARDWARE_DEVICE_PATH,
  49. HW_VENDOR_DP,
  50. {
  51. (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
  52. (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
  53. }
  54. },
  55. EFI_CALLER_ID_GUID
  56. },
  57. {
  58. END_DEVICE_PATH_TYPE,
  59. END_ENTIRE_DEVICE_PATH_SUBTYPE,
  60. {
  61. (UINT8) (END_DEVICE_PATH_LENGTH),
  62. (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
  63. }
  64. }
  65. };
  66. /**
  67. This function allows a caller to extract the current configuration for one
  68. or more named elements from the target driver.
  69. @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  70. @param Request A null-terminated Unicode string in <ConfigRequest> format.
  71. @param Progress On return, points to a character in the Request string.
  72. Points to the string's null terminator if request was successful.
  73. Points to the most recent '&' before the first failing name/value
  74. pair (or the beginning of the string if the failure is in the
  75. first name/value pair) if the request was not successful.
  76. @param Results A null-terminated Unicode string in <ConfigAltResp> format which
  77. has all values filled in for the names in the Request string.
  78. String to be allocated by the called function.
  79. @retval EFI_SUCCESS The Results is filled with the requested values.
  80. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
  81. @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
  82. @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
  83. **/
  84. VOID
  85. CheckSystemConfigLoad(SYSTEM_CONFIGURATION *SystemConfigPtr);
  86. VOID
  87. CheckSystemConfigSave(SYSTEM_CONFIGURATION *SystemConfigPtr);
  88. VOID
  89. ConfirmSecureBootTest();
  90. VOID
  91. LoadLpssDefaultValues (
  92. IN EFI_CALLBACK_INFO *Private
  93. )
  94. {
  95. //
  96. // Load LPSS and SCC default configurations for Android
  97. //
  98. Private->FakeNvData.LpsseMMCEnabled = FALSE;
  99. Private->FakeNvData.LpssSdioEnabled = TRUE;
  100. Private->FakeNvData.LpssSdcardEnabled = TRUE;
  101. Private->FakeNvData.LpssSdCardSDR25Enabled = FALSE;
  102. Private->FakeNvData.LpssSdCardDDR50Enabled = TRUE;
  103. Private->FakeNvData.LpssMipiHsi = FALSE;
  104. Private->FakeNvData.LpsseMMC45Enabled = TRUE;
  105. Private->FakeNvData.LpsseMMC45DDR50Enabled = TRUE;
  106. Private->FakeNvData.LpsseMMC45HS200Enabled = FALSE;
  107. Private->FakeNvData.LpsseMMC45RetuneTimerValue = 8;
  108. Private->FakeNvData.eMMCBootMode = 1; // Auto Detect
  109. Private->FakeNvData.GOPEnable = TRUE;
  110. Private->FakeNvData.SecureBoot = TRUE;
  111. Private->FakeNvData.UsbAutoMode = TRUE;
  112. Private->FakeNvData.UsbXhciSupport = TRUE;
  113. Private->FakeNvData.PchUsb30Mode = TRUE;
  114. Private->FakeNvData.LegacyUSBBooting = FALSE;
  115. Private->FakeNvData.PchUsb20 = FALSE;
  116. }
  117. EFI_STATUS
  118. EFIAPI
  119. SystemConfigExtractConfig (
  120. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  121. IN CONST EFI_STRING Request,
  122. OUT EFI_STRING *Progress,
  123. OUT EFI_STRING *Results
  124. )
  125. {
  126. return EFI_UNSUPPORTED;
  127. }
  128. /**
  129. This function processes the results of changes in configuration.
  130. @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  131. @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
  132. @param Progress A pointer to a string filled in with the offset of the most
  133. recent '&' before the first failing name/value pair (or the
  134. beginning of the string if the failure is in the first
  135. name/value pair) or the terminating NULL if all was successful.
  136. @retval EFI_SUCCESS The Results is processed successfully.
  137. @retval EFI_INVALID_PARAMETER Configuration is NULL.
  138. @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
  139. **/
  140. EFI_STATUS
  141. EFIAPI
  142. SystemConfigRouteConfig (
  143. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  144. IN CONST EFI_STRING Configuration,
  145. OUT EFI_STRING *Progress
  146. )
  147. {
  148. return EFI_UNSUPPORTED;
  149. }
  150. /**
  151. This is the function that is called to provide results data to the driver. This data
  152. consists of a unique key which is used to identify what data is either being passed back
  153. or being asked for.
  154. @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  155. @param Action A null-terminated Unicode string in <ConfigRequest> format.
  156. @param KeyValue A unique Goto OpCode callback value which record user's selection.
  157. 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
  158. KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
  159. KeyValue == 0x1235 : user select 'Pci device filter' in first page
  160. KeyValue == 0x1500 : user select 'order ... priority' item in second page
  161. KeyValue == 0x1800 : user select 'commint changes' in third page
  162. KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
  163. @param Type The type of value for the question.
  164. @param Value A pointer to the data being sent to the original exporting driver.
  165. @param ActionRequest On return, points to the action requested by the callback function.
  166. @retval EFI_SUCCESS Always returned.
  167. **/
  168. EFI_STATUS
  169. EFIAPI
  170. SystemConfigCallback (
  171. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  172. IN EFI_BROWSER_ACTION Action,
  173. IN EFI_QUESTION_ID KeyValue,
  174. IN UINT8 Type,
  175. IN EFI_IFR_TYPE_VALUE *Value,
  176. OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
  177. )
  178. {
  179. EFI_CALLBACK_INFO *Private;
  180. SYSTEM_CONFIGURATION *FakeNvData;
  181. SYSTEM_CONFIGURATION *SetupData;
  182. UINTN SizeOfNvStore;
  183. EFI_INPUT_KEY Key;
  184. CHAR16 *StringBuffer1;
  185. CHAR16 *StringBuffer2;
  186. CHAR16 *StringBuffer3;
  187. EFI_STATUS Status;
  188. UINTN DataSize;
  189. UINT8 OsSelection;
  190. EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL *FormBrowserEx2;
  191. StringBuffer1 = AllocateZeroPool (200 * sizeof (CHAR16));
  192. ASSERT (StringBuffer1 != NULL);
  193. StringBuffer2 = AllocateZeroPool (200 * sizeof (CHAR16));
  194. ASSERT (StringBuffer2 != NULL);
  195. StringBuffer3 = AllocateZeroPool (200 * sizeof (CHAR16));
  196. ASSERT (StringBuffer3 != NULL);
  197. switch (Action) {
  198. case EFI_BROWSER_ACTION_CHANGING:
  199. {
  200. if (KeyValue == 0x1235) {
  201. StrCpy (StringBuffer1, L"Will you disable PTT ? ");
  202. StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
  203. //
  204. // Popup a menu to notice user
  205. //
  206. do {
  207. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
  208. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  209. //
  210. // If the user hits the YES Response key,
  211. //
  212. if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
  213. }
  214. } else if (KeyValue == 0x1236) {
  215. StrCpy (StringBuffer1, L"Will you revoke trust ? ");
  216. StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
  217. //
  218. // Popup a menu to notice user
  219. //
  220. do {
  221. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
  222. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  223. //
  224. // If the user hits the YES Response key,
  225. //
  226. if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
  227. }
  228. } else if (KeyValue == 0x1239) {
  229. if (Value->u8 == 0x00) {
  230. StrCpy (StringBuffer1, L"WARNING: SOC may be damaged due to high temperature");
  231. StrCpy (StringBuffer2, L"when DPTF is disabled and IGD turbo is enabled.");
  232. StrCpy (StringBuffer3, L"Press Enter/ESC to continue...");
  233. //
  234. // Popup a menu to notice user
  235. //
  236. do {
  237. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, StringBuffer3, NULL);
  238. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  239. }
  240. } else if (KeyValue == 0x1240) { // secure erase feature of eMMC
  241. //
  242. // Popup a menu to notice user
  243. //
  244. StrCpy (StringBuffer1, L"WARNING: All your data on the eMMC will be lost");
  245. StrCpy (StringBuffer2, L"Do you really want to enable secure erase on eMMC?");
  246. StrCpy (StringBuffer3, L" Enter (YES) / Esc (NO) ");
  247. do {
  248. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, StringBuffer3,NULL);
  249. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  250. //
  251. // If the user hits the ESC Response key,
  252. //
  253. if (Key.ScanCode == SCAN_ESC) {
  254. Private = EFI_CALLBACK_INFO_FROM_THIS (This);
  255. FakeNvData = &Private->FakeNvData;
  256. Status = HiiGetBrowserData (
  257. &mSystemConfigGuid,
  258. mVariableName,
  259. sizeof (SYSTEM_CONFIGURATION),
  260. (UINT8 *) FakeNvData
  261. );
  262. if (!EFI_ERROR (Status)) {
  263. FakeNvData->SecureErase = 0;
  264. HiiSetBrowserData (
  265. &mSystemConfigGuid,
  266. mVariableName,
  267. sizeof (SYSTEM_CONFIGURATION),
  268. (UINT8 *) FakeNvData,
  269. NULL
  270. );
  271. }
  272. break;
  273. }
  274. //
  275. // If the user hits the YES Response key
  276. //
  277. if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
  278. //
  279. // Save change
  280. //
  281. Private = EFI_CALLBACK_INFO_FROM_THIS (This);
  282. FakeNvData = &Private->FakeNvData;
  283. Status = HiiGetBrowserData (
  284. &mSystemConfigGuid,
  285. mVariableName,
  286. sizeof (SYSTEM_CONFIGURATION),
  287. (UINT8 *) FakeNvData
  288. );
  289. if (!EFI_ERROR (Status)) {
  290. Status = gRT->SetVariable (
  291. L"Setup",
  292. &mNormalSetupGuid,
  293. EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
  294. sizeof(SYSTEM_CONFIGURATION),
  295. &Private->FakeNvData
  296. );
  297. }
  298. //
  299. // Reset system
  300. //
  301. gRT->ResetSystem(
  302. EfiResetCold,
  303. EFI_SUCCESS,
  304. 0,
  305. NULL
  306. );
  307. }
  308. }
  309. else if (KeyValue == 0xF001) {
  310. //
  311. // Popup a menu to notice user
  312. //
  313. StrCpy (StringBuffer1, L"Do you want to Commit Changes and Exit?");
  314. StrCpy (StringBuffer2, L" Enter (YES) / Esc (NO) ");
  315. do {
  316. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
  317. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  318. //
  319. // If the user hits the YES Response key
  320. //
  321. if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
  322. //
  323. // Save change
  324. //
  325. Private = EFI_CALLBACK_INFO_FROM_THIS (This);
  326. FakeNvData = &Private->FakeNvData;
  327. Status = HiiGetBrowserData (
  328. &mSystemConfigGuid,
  329. mVariableName,
  330. sizeof (SYSTEM_CONFIGURATION),
  331. (UINT8 *) FakeNvData
  332. );
  333. if (!EFI_ERROR (Status)) {
  334. Status = gRT->SetVariable (
  335. L"Setup",
  336. &mNormalSetupGuid,
  337. EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
  338. sizeof(SYSTEM_CONFIGURATION),
  339. &Private->FakeNvData
  340. );
  341. }
  342. //
  343. // Update Secure Boot configuration changes
  344. //
  345. CheckSystemConfigSave(FakeNvData);
  346. //
  347. // Reset system
  348. //
  349. if (GlobalReset == TRUE) {
  350. //
  351. // Issue full reset
  352. //
  353. IoWrite8 (
  354. (UINTN) 0XCF9,
  355. (UINT8) 0x02
  356. );
  357. IoWrite8 (
  358. (UINTN) 0xCF9,
  359. (UINT8) 0x0E
  360. );
  361. } else {
  362. gRT->ResetSystem(
  363. EfiResetCold,
  364. EFI_SUCCESS,
  365. 0,
  366. NULL
  367. );
  368. }
  369. }
  370. } else if (KeyValue == 0xF002) {
  371. //
  372. // Popup a menu to notice user
  373. //
  374. StrCpy (StringBuffer1, L"Do you want to Discard Changes and Exit?");
  375. StrCpy (StringBuffer2, L" Enter (YES) / Esc (NO) ");
  376. do {
  377. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
  378. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  379. //
  380. // If the user hits the YES Response key
  381. //
  382. if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
  383. //
  384. // Reset system
  385. //
  386. gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
  387. }
  388. } else if (KeyValue == 0xF003) {
  389. //
  390. // Popup a menu to notice user
  391. //
  392. StrCpy (StringBuffer1, L"Do you want to load setup defaults and Exit?");
  393. StrCpy (StringBuffer2, L" Enter (YES) / Esc (NO) ");
  394. do {
  395. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
  396. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  397. //
  398. // If the user hits the YES Response key
  399. //
  400. if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
  401. Status = gBS->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid, NULL, (VOID **) &FormBrowserEx2);
  402. FormBrowserEx2->ExecuteAction(BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD);
  403. FakeNvData = AllocateZeroPool (sizeof(SYSTEM_CONFIGURATION));
  404. if (FakeNvData == NULL) {
  405. return EFI_OUT_OF_RESOURCES;
  406. }
  407. Status = HiiGetBrowserData (
  408. &mSystemConfigGuid,
  409. mVariableName,
  410. sizeof (SYSTEM_CONFIGURATION),
  411. (UINT8 *) FakeNvData
  412. );
  413. if (!EFI_ERROR (Status)) {
  414. Status = gRT->SetVariable (
  415. L"Setup",
  416. &mNormalSetupGuid,
  417. EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
  418. sizeof(SYSTEM_CONFIGURATION),
  419. FakeNvData
  420. );
  421. }
  422. DataSize = sizeof(OsSelection);
  423. Status = gRT->GetVariable(
  424. L"OsSelection",
  425. &gOsSelectionVariableGuid,
  426. NULL,
  427. &DataSize,
  428. &OsSelection
  429. );
  430. if (EFI_ERROR(Status) || (OsSelection != FakeNvData->ReservedO)) {
  431. OsSelection = FakeNvData->ReservedO;
  432. Status = gRT->SetVariable (
  433. L"OsSelection",
  434. &gOsSelectionVariableGuid,
  435. EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
  436. sizeof(OsSelection),
  437. &OsSelection
  438. );
  439. }
  440. FreePool (FakeNvData);
  441. //
  442. // Reset system
  443. //
  444. gRT->ResetSystem(
  445. EfiResetCold,
  446. EFI_SUCCESS,
  447. 0,
  448. NULL
  449. );
  450. }
  451. } else if ((KeyValue == 0x123A) || (KeyValue == 0x123B) || (KeyValue == 0x123C)) {
  452. StrCpy (StringBuffer1, L"WARNING: Enable or disable USB Controllers will ");
  453. StrCpy (StringBuffer2, L"make global reset to restart system.");
  454. StrCpy (StringBuffer3, L"Press Enter/ESC to continue...");
  455. //
  456. // Popup a menu to notice user
  457. //
  458. do {
  459. CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, StringBuffer3, NULL);
  460. } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  461. FakeNvData = AllocateZeroPool (sizeof(SYSTEM_CONFIGURATION));
  462. Status = HiiGetBrowserData (
  463. &mSystemConfigGuid,
  464. mVariableName,
  465. sizeof (SYSTEM_CONFIGURATION),
  466. (UINT8 *) FakeNvData
  467. );
  468. //
  469. // Get variable data
  470. //
  471. SizeOfNvStore = sizeof(SYSTEM_CONFIGURATION);
  472. SetupData = AllocateZeroPool (sizeof(SYSTEM_CONFIGURATION));
  473. Status = gRT->GetVariable(
  474. L"Setup",
  475. &mNormalSetupGuid,
  476. NULL,
  477. &SizeOfNvStore,
  478. SetupData
  479. );
  480. if ((SetupData->UsbAutoMode != FakeNvData->UsbAutoMode) ||
  481. (SetupData->UsbXhciSupport != FakeNvData->UsbXhciSupport) ||
  482. (SetupData->PchUsb20 != FakeNvData->PchUsb20)) {
  483. GlobalReset = TRUE;
  484. } else {
  485. GlobalReset = FALSE;
  486. }
  487. }
  488. }
  489. break;
  490. default:
  491. break;
  492. }
  493. FreePool (StringBuffer1);
  494. FreePool (StringBuffer2);
  495. FreePool (StringBuffer3);
  496. //
  497. // Workaround for Load Default for "DPTF Enable"
  498. //
  499. if (Action == EFI_BROWSER_ACTION_DEFAULT_STANDARD) {
  500. if (KeyValue == 0x1239) {
  501. return EFI_NOT_FOUND;
  502. }
  503. }
  504. if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
  505. //
  506. // Do nothing for UEFI OPEN/CLOSE Action
  507. //
  508. return EFI_SUCCESS;
  509. }
  510. Private = EFI_CALLBACK_INFO_FROM_THIS (This);
  511. FakeNvData = &Private->FakeNvData;
  512. if (!HiiGetBrowserData (&mSystemConfigGuid, mVariableName, sizeof (SYSTEM_CONFIGURATION), (UINT8 *) FakeNvData)) {
  513. return EFI_NOT_FOUND;
  514. }
  515. if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) && (Private->FakeNvData.ReservedO != Private->BackupNvData.ReservedO)) {
  516. Private->BackupNvData.ReservedO = Private->FakeNvData.ReservedO;
  517. LoadLpssDefaultValues (Private);
  518. }
  519. //
  520. // When user selected the secure erase, set it to disable
  521. //
  522. if((KeyValue == 0x1240) && (Action == EFI_BROWSER_ACTION_CHANGED)) {
  523. FakeNvData->SecureErase = 0;
  524. }
  525. if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_CHANGED)) {
  526. //
  527. // If function 0 is disabled, function 1 ~ 7 also required to be disabled.
  528. //
  529. if (Private->FakeNvData.LpssDma0Enabled == 0) {
  530. Private->FakeNvData.LpssHsuart0Enabled = 0;
  531. Private->FakeNvData.LpssHsuart1Enabled = 0;
  532. Private->FakeNvData.LpssPwm0Enabled = 0;
  533. Private->FakeNvData.LpssPwm1Enabled = 0;
  534. Private->FakeNvData.LpssSpiEnabled = 0;
  535. }
  536. //
  537. // If function 0 is disabled, function 1 ~ 7 also required to be disabled.
  538. //
  539. if (Private->FakeNvData.LpssDma1Enabled == 0) {
  540. Private->FakeNvData.LpssI2C0Enabled = 0;
  541. Private->FakeNvData.LpssI2C1Enabled = 0;
  542. Private->FakeNvData.LpssI2C2Enabled = 0;
  543. Private->FakeNvData.LpssI2C3Enabled = 0;
  544. Private->FakeNvData.LpssI2C4Enabled = 0;
  545. Private->FakeNvData.LpssI2C5Enabled = 0;
  546. Private->FakeNvData.LpssI2C6Enabled = 0;
  547. }
  548. }
  549. //
  550. // Pass changed uncommitted data back to Form Browser
  551. //
  552. HiiSetBrowserData (&mSystemConfigGuid, mVariableName, sizeof (SYSTEM_CONFIGURATION), (UINT8 *) FakeNvData, NULL);
  553. return EFI_SUCCESS;
  554. }
  555. /**
  556. The driver Entry Point. The function will export a disk device class formset and
  557. its callback function to hii database.
  558. @param ImageHandle The firmware allocated handle for the EFI image.
  559. @param SystemTable A pointer to the EFI System Table.
  560. @retval EFI_SUCCESS The entry point is executed successfully.
  561. @retval other Some error occurs when executing this entry point.
  562. **/
  563. EFI_STATUS
  564. EFIAPI
  565. PlatformSetupDxeInit (
  566. IN EFI_HANDLE ImageHandle,
  567. IN EFI_SYSTEM_TABLE *SystemTable
  568. )
  569. {
  570. EFI_STATUS Status;
  571. EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
  572. mImageHandle = ImageHandle;
  573. //
  574. // There should only be one Form Configuration protocol
  575. //
  576. Status = gBS->LocateProtocol (
  577. &gEfiFormBrowser2ProtocolGuid,
  578. NULL,
  579. (VOID **) &FormBrowser2
  580. );
  581. if (EFI_ERROR (Status)) {
  582. return Status;
  583. }
  584. mCallbackInfo = AllocateZeroPool (sizeof (EFI_CALLBACK_INFO));
  585. if (mCallbackInfo == NULL) {
  586. return EFI_BAD_BUFFER_SIZE;
  587. }
  588. mCallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;
  589. mCallbackInfo->ConfigAccess.ExtractConfig = SystemConfigExtractConfig;
  590. mCallbackInfo->ConfigAccess.RouteConfig = SystemConfigRouteConfig;
  591. mCallbackInfo->ConfigAccess.Callback = SystemConfigCallback;
  592. //
  593. // Install Device Path Protocol and Config Access protocol to driver handle
  594. // Install Platform Driver Override Protocol to driver handle
  595. //
  596. Status = gBS->InstallMultipleProtocolInterfaces (
  597. &mCallbackInfo->DriverHandle,
  598. &gEfiDevicePathProtocolGuid,
  599. &mHiiVendorDevicePath,
  600. &gEfiHiiConfigAccessProtocolGuid,
  601. &mCallbackInfo->ConfigAccess,
  602. NULL
  603. );
  604. if (EFI_ERROR (Status)) {
  605. goto Finish;
  606. }
  607. //
  608. // Publish our HII data
  609. //
  610. mCallbackInfo->RegisteredHandle = HiiAddPackages (
  611. &mSystemConfigGuid,
  612. mCallbackInfo->DriverHandle,
  613. VfrBin,
  614. PlatformSetupDxeStrings,
  615. NULL
  616. );
  617. if (mCallbackInfo->RegisteredHandle == NULL) {
  618. Status = EFI_OUT_OF_RESOURCES;
  619. goto Finish;
  620. }
  621. mHiiHandle = mCallbackInfo->RegisteredHandle;
  622. //
  623. // Locate ConfigRouting protocol
  624. //
  625. Status = gBS->LocateProtocol (
  626. &gEfiHiiConfigRoutingProtocolGuid,
  627. NULL,
  628. (VOID **) &mCallbackInfo->HiiConfigRouting
  629. );
  630. if (EFI_ERROR (Status)) {
  631. goto Finish;
  632. }
  633. //
  634. // Clear all the globle variable
  635. //
  636. return EFI_SUCCESS;
  637. Finish:
  638. if (mCallbackInfo->DriverHandle != NULL) {
  639. gBS->UninstallMultipleProtocolInterfaces (
  640. mCallbackInfo->DriverHandle,
  641. &gEfiDevicePathProtocolGuid,
  642. &mHiiVendorDevicePath,
  643. &gEfiHiiConfigAccessProtocolGuid,
  644. &mCallbackInfo->ConfigAccess,
  645. NULL
  646. );
  647. }
  648. if (mCallbackInfo->RegisteredHandle != NULL) {
  649. HiiRemovePackages (mCallbackInfo->RegisteredHandle);
  650. }
  651. if (mCallbackInfo != NULL) {
  652. FreePool (mCallbackInfo);
  653. }
  654. return Status;
  655. }
  656. /**
  657. Unload its installed protocol.
  658. @param[in] ImageHandle Handle that identifies the image to be unloaded.
  659. @retval EFI_SUCCESS The image has been unloaded.
  660. **/
  661. EFI_STATUS
  662. EFIAPI
  663. PlatformSetupDxeUnload (
  664. IN EFI_HANDLE ImageHandle
  665. )
  666. {
  667. if (mCallbackInfo != NULL) {
  668. if (mCallbackInfo->DriverHandle != NULL) {
  669. gBS->UninstallMultipleProtocolInterfaces (
  670. mCallbackInfo->DriverHandle,
  671. &gEfiDevicePathProtocolGuid,
  672. &mHiiVendorDevicePath,
  673. &gEfiHiiConfigAccessProtocolGuid,
  674. &mCallbackInfo->ConfigAccess,
  675. NULL
  676. );
  677. }
  678. if (mCallbackInfo->RegisteredHandle != NULL) {
  679. HiiRemovePackages (mCallbackInfo->RegisteredHandle);
  680. }
  681. FreePool (mCallbackInfo);
  682. }
  683. return EFI_SUCCESS;
  684. }