PlatformSetupDxe.c 26 KB

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