]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformSetupDxe/PlatformSetupDxe.c
Vlv2TbltDevicePkg: Sync the branch changes to Trunk,
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformSetupDxe / PlatformSetupDxe.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13
14 Module Name:
15
16 **/
17
18 #include "PlatformSetupDxe.h"
19 #include "Guid/SetupVariable.h"
20 #include <Protocol/FormBrowserEx2.h>
21
22
23 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
24 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
25
26 typedef struct {
27 UINTN Signature;
28 EFI_HANDLE DriverHandle;
29 EFI_HII_HANDLE RegisteredHandle;
30 SYSTEM_CONFIGURATION FakeNvData;
31 SYSTEM_CONFIGURATION BackupNvData;
32 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
33 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
34 } EFI_CALLBACK_INFO;
35
36 #pragma pack(1)
37
38 //
39 // HII specific Vendor Device Path definition.
40 //
41 typedef struct {
42 VENDOR_DEVICE_PATH VendorDevicePath;
43 EFI_DEVICE_PATH_PROTOCOL End;
44 } HII_VENDOR_DEVICE_PATH;
45
46 #pragma pack()
47
48 //
49 // uni string and Vfr Binary data.
50 //
51 extern UINT8 VfrBin[];
52 extern UINT8 PlatformSetupDxeStrings[];
53
54 EFI_HANDLE mImageHandle;
55
56 //
57 // module global data
58 //
59 #define EFI_NORMAL_SETUP_GUID \
60 { 0xec87d643, 0xeba4, 0x4bb5, 0xa1, 0xe5, 0x3f, 0x3e, 0x36, 0xb2, 0xd, 0xa9 }
61
62 EFI_GUID mNormalSetupGuid = EFI_NORMAL_SETUP_GUID;
63
64 EFI_GUID mSystemConfigGuid = SYSTEM_CONFIGURATION_GUID;
65 CHAR16 mVariableName[] = L"Setup";
66 CHAR16 mSetupName[] = L"Setup";
67 EFI_CALLBACK_INFO *mCallbackInfo;
68 BOOLEAN GlobalReset=FALSE;
69
70 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = {
71 {
72 {
73 HARDWARE_DEVICE_PATH,
74 HW_VENDOR_DP,
75 {
76 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
77 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
78 }
79 },
80 EFI_CALLER_ID_GUID
81 },
82 {
83 END_DEVICE_PATH_TYPE,
84 END_ENTIRE_DEVICE_PATH_SUBTYPE,
85 {
86 (UINT8) (END_DEVICE_PATH_LENGTH),
87 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
88 }
89 }
90 };
91
92 /**
93 This function allows a caller to extract the current configuration for one
94 or more named elements from the target driver.
95
96 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
97 @param Request A null-terminated Unicode string in <ConfigRequest> format.
98 @param Progress On return, points to a character in the Request string.
99 Points to the string's null terminator if request was successful.
100 Points to the most recent '&' before the first failing name/value
101 pair (or the beginning of the string if the failure is in the
102 first name/value pair) if the request was not successful.
103 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
104 has all values filled in for the names in the Request string.
105 String to be allocated by the called function.
106
107 @retval EFI_SUCCESS The Results is filled with the requested values.
108 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
109 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
110 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
111
112 **/
113
114 VOID
115 CheckSystemConfigLoad(SYSTEM_CONFIGURATION *SystemConfigPtr);
116
117 VOID
118 CheckSystemConfigSave(SYSTEM_CONFIGURATION *SystemConfigPtr);
119
120 VOID
121 ConfirmSecureBootTest();
122
123 VOID
124 LoadLpssDefaultValues (
125 IN EFI_CALLBACK_INFO *Private
126 )
127 {
128 //
129 // Load LPSS and SCC defalut configurations for Android
130 //
131 Private->FakeNvData.LpsseMMCEnabled = FALSE;
132 Private->FakeNvData.LpssSdioEnabled = TRUE;
133 Private->FakeNvData.LpssSdcardEnabled = TRUE;
134 Private->FakeNvData.LpssSdCardSDR25Enabled = FALSE;
135 Private->FakeNvData.LpssSdCardDDR50Enabled = TRUE;
136 Private->FakeNvData.LpssMipiHsi = FALSE;
137 Private->FakeNvData.LpsseMMC45Enabled = TRUE;
138 Private->FakeNvData.LpsseMMC45DDR50Enabled = TRUE;
139 Private->FakeNvData.LpsseMMC45HS200Enabled = FALSE;
140 Private->FakeNvData.LpsseMMC45RetuneTimerValue = 8;
141 Private->FakeNvData.eMMCBootMode = 1; // Auto Detect
142
143 Private->FakeNvData.GOPEnable = TRUE;
144 Private->FakeNvData.SecureBoot = TRUE;
145 Private->FakeNvData.UsbAutoMode = TRUE;
146 Private->FakeNvData.UsbXhciSupport = TRUE;
147 Private->FakeNvData.PchUsb30Mode = TRUE;
148 Private->FakeNvData.LegacyUSBBooting = FALSE;
149 Private->FakeNvData.PchUsb20 = FALSE;
150 }
151
152
153 EFI_STATUS
154 EFIAPI
155 SystemConfigExtractConfig (
156 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
157 IN CONST EFI_STRING Request,
158 OUT EFI_STRING *Progress,
159 OUT EFI_STRING *Results
160 )
161 {
162 EFI_STATUS Status;
163 EFI_CALLBACK_INFO *Private;
164 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
165 EFI_STRING ConfigRequestHdr;
166 EFI_STRING ConfigRequest;
167 BOOLEAN AllocatedRequest;
168 UINTN Size;
169 UINTN BufferSize;
170 VOID *SystemConfigPtr;
171
172
173 if (Progress == NULL || Results == NULL) {
174 return EFI_INVALID_PARAMETER;
175 }
176
177 *Progress = Request;
178 if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mSystemConfigGuid, mVariableName)) {
179 return EFI_NOT_FOUND;
180 }
181
182 ConfigRequestHdr = NULL;
183 ConfigRequest = NULL;
184 Size = 0;
185 AllocatedRequest = FALSE;
186
187 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
188
189 SetupInfo();
190
191 HiiConfigRouting = Private->HiiConfigRouting;
192 ConfigRequest = Request;
193 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
194 //
195 // Request has no request element, construct full request string.
196 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
197 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
198 //
199 ConfigRequestHdr = HiiConstructConfigHdr (&mSystemConfigGuid, mVariableName, Private->DriverHandle);
200 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
201 ConfigRequest = AllocateZeroPool (Size);
202 ASSERT (ConfigRequest != NULL);
203 AllocatedRequest = TRUE;
204 BufferSize = sizeof (SYSTEM_CONFIGURATION);
205 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
206 FreePool (ConfigRequestHdr);
207 }
208 SystemConfigPtr = GetVariable(mSetupName, &mNormalSetupGuid);
209
210
211 if (SystemConfigPtr == NULL) {
212 ZeroMem(&Private->FakeNvData, sizeof(SYSTEM_CONFIGURATION));
213 ZeroMem(&Private->BackupNvData, sizeof(SYSTEM_CONFIGURATION));
214 } else {
215 CheckSystemConfigLoad(SystemConfigPtr);
216 CopyMem(&Private->FakeNvData, SystemConfigPtr, sizeof(SYSTEM_CONFIGURATION));
217 CopyMem(&Private->BackupNvData, SystemConfigPtr, sizeof(SYSTEM_CONFIGURATION));
218 FreePool(SystemConfigPtr);
219 }
220
221 //
222 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
223 //
224 Status = HiiConfigRouting->BlockToConfig (
225 HiiConfigRouting,
226 ConfigRequest,
227 (UINT8 *) &Private->FakeNvData,
228 sizeof (SYSTEM_CONFIGURATION),
229 Results,
230 Progress
231 );
232
233 //
234 // Free the allocated config request string.
235 //
236 if (AllocatedRequest) {
237 FreePool (ConfigRequest);
238 ConfigRequest = NULL;
239 }
240
241 //
242 // Set Progress string to the original request string.
243 //
244 if (Request == NULL) {
245 *Progress = NULL;
246 } else if (StrStr (Request, L"OFFSET") == NULL) {
247 *Progress = Request + StrLen (Request);
248 }
249
250 return Status;
251 }
252
253 /**
254 This function processes the results of changes in configuration.
255
256 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
257 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
258 @param Progress A pointer to a string filled in with the offset of the most
259 recent '&' before the first failing name/value pair (or the
260 beginning of the string if the failure is in the first
261 name/value pair) or the terminating NULL if all was successful.
262
263 @retval EFI_SUCCESS The Results is processed successfully.
264 @retval EFI_INVALID_PARAMETER Configuration is NULL.
265 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
266
267 **/
268 EFI_STATUS
269 EFIAPI
270 SystemConfigRouteConfig (
271 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
272 IN CONST EFI_STRING Configuration,
273 OUT EFI_STRING *Progress
274 )
275 {
276 EFI_CALLBACK_INFO *Private;
277 SYSTEM_CONFIGURATION *FakeNvData;
278
279 if (Configuration == NULL || Progress == NULL) {
280 return EFI_INVALID_PARAMETER;
281 }
282 *Progress = Configuration;
283
284 if (!HiiIsConfigHdrMatch (Configuration, &mSystemConfigGuid, mVariableName)) {
285 return EFI_NOT_FOUND;
286 }
287
288 *Progress = Configuration + StrLen (Configuration);
289 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
290 FakeNvData = &Private->FakeNvData;
291 if (!HiiGetBrowserData (&mSystemConfigGuid, mVariableName, sizeof (SYSTEM_CONFIGURATION), (UINT8 *) FakeNvData)) {
292 //
293 // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.
294 //
295 return EFI_SUCCESS;
296 }
297
298 if (Private->FakeNvData.ReservedO != Private->BackupNvData.ReservedO) {
299 Private->BackupNvData.ReservedO = Private->FakeNvData.ReservedO;
300 LoadLpssDefaultValues (Private);
301
302 //
303 // Pass changed uncommitted data back to Form Browser
304 //
305 HiiSetBrowserData (&mSystemConfigGuid, mVariableName, sizeof (SYSTEM_CONFIGURATION), (UINT8 *) FakeNvData, NULL);
306 }
307
308 gRT->SetVariable(
309 mSetupName,
310 &mNormalSetupGuid,
311 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
312 sizeof(SYSTEM_CONFIGURATION),
313 &Private->FakeNvData
314 );
315
316 CheckSystemConfigSave(&Private->FakeNvData);
317 return EFI_SUCCESS;
318 }
319
320 /**
321 This is the function that is called to provide results data to the driver. This data
322 consists of a unique key which is used to identify what data is either being passed back
323 or being asked for.
324
325 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
326 @param Action A null-terminated Unicode string in <ConfigRequest> format.
327 @param KeyValue A unique Goto OpCode callback value which record user's selection.
328 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
329 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
330 KeyValue == 0x1235 : user select 'Pci device filter' in first page
331 KeyValue == 0x1500 : user select 'order ... priority' item in second page
332 KeyValue == 0x1800 : user select 'commint changes' in third page
333 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
334 @param Type The type of value for the question.
335 @param Value A pointer to the data being sent to the original exporting driver.
336 @param ActionRequest On return, points to the action requested by the callback function.
337
338 @retval EFI_SUCCESS Always returned.
339
340 **/
341 EFI_STATUS
342 EFIAPI
343 SystemConfigCallback (
344 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
345 IN EFI_BROWSER_ACTION Action,
346 IN EFI_QUESTION_ID KeyValue,
347 IN UINT8 Type,
348 IN EFI_IFR_TYPE_VALUE *Value,
349 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
350 )
351 {
352 EFI_CALLBACK_INFO *Private;
353 SYSTEM_CONFIGURATION *FakeNvData;
354 SYSTEM_CONFIGURATION *SetupData;
355 UINTN SizeOfNvStore;
356 EFI_INPUT_KEY Key;
357 CHAR16 *StringBuffer1;
358 CHAR16 *StringBuffer2;
359 CHAR16 *StringBuffer3;
360 EFI_STATUS Status;
361 UINTN DataSize;
362 UINT8 OsSelection;
363 EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL *FormBrowserEx2;
364
365 StringBuffer1 = AllocateZeroPool (200 * sizeof (CHAR16));
366 ASSERT (StringBuffer1 != NULL);
367 StringBuffer2 = AllocateZeroPool (200 * sizeof (CHAR16));
368 ASSERT (StringBuffer2 != NULL);
369 StringBuffer3 = AllocateZeroPool (200 * sizeof (CHAR16));
370 ASSERT (StringBuffer3 != NULL);
371
372 switch (Action) {
373 case EFI_BROWSER_ACTION_CHANGING:
374 {
375 if (KeyValue == 0x1235) {
376 StrCpy (StringBuffer1, L"Will you disable PTT ? ");
377 StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
378
379 //
380 // Popup a menu to notice user
381 //
382 do {
383 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
384 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
385
386 //
387 // If the user hits the YES Response key,
388 //
389 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
390
391 }
392 } else if (KeyValue == 0x1236) {
393 StrCpy (StringBuffer1, L"Will you revoke trust ? ");
394 StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
395
396 //
397 // Popup a menu to notice user
398 //
399 do {
400 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
401 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
402
403 //
404 // If the user hits the YES Response key,
405 //
406 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
407
408 }
409 } else if (KeyValue == 0x1239) {
410 if (Value->u8 == 0x00) {
411 StrCpy (StringBuffer1, L"WARNING: SOC may be damaged due to high temperature");
412 StrCpy (StringBuffer2, L"when DPTF is disabled and IGD turbo is enabled.");
413 StrCpy (StringBuffer3, L"Press Enter/ESC to continue...");
414
415 //
416 // Popup a menu to notice user
417 //
418 do {
419 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, StringBuffer3, NULL);
420 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
421 }
422 } else if (KeyValue == 0x1240) { // secure erase feature of eMMC
423 //
424 // Popup a menu to notice user
425 //
426 StrCpy (StringBuffer1, L"WARNING: All your data on the eMMC will be lost");
427 StrCpy (StringBuffer2, L"Do you really want to enable secure erase on eMMC?");
428 StrCpy (StringBuffer3, L" Enter (YES) / Esc (NO) ");
429
430 do {
431 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, StringBuffer3,NULL);
432 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
433
434 //
435 // If the user hits the ESC Response key,
436 //
437 if (Key.ScanCode == SCAN_ESC) {
438 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
439 FakeNvData = &Private->FakeNvData;
440
441 Status = HiiGetBrowserData (
442 &mSystemConfigGuid,
443 mVariableName,
444 sizeof (SYSTEM_CONFIGURATION),
445 (UINT8 *) FakeNvData
446 );
447 if (!EFI_ERROR (Status)) {
448 FakeNvData->SecureErase = 0;
449 HiiSetBrowserData (
450 &mSystemConfigGuid,
451 mVariableName,
452 sizeof (SYSTEM_CONFIGURATION),
453 (UINT8 *) FakeNvData,
454 NULL
455 );
456 }
457 break;
458 }
459
460 //
461 // If the user hits the YES Response key
462 //
463 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
464 //
465 // Save change
466 //
467 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
468 FakeNvData = &Private->FakeNvData;
469
470 Status = HiiGetBrowserData (
471 &mSystemConfigGuid,
472 mVariableName,
473 sizeof (SYSTEM_CONFIGURATION),
474 (UINT8 *) FakeNvData
475 );
476 if (!EFI_ERROR (Status)) {
477 Status = gRT->SetVariable (
478 L"Setup",
479 &mNormalSetupGuid,
480 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
481 sizeof(SYSTEM_CONFIGURATION),
482 &Private->FakeNvData
483 );
484 }
485
486 //
487 // Reset system
488 //
489 gRT->ResetSystem(
490 EfiResetCold,
491 EFI_SUCCESS,
492 0,
493 NULL
494 );
495
496 }
497
498
499 }
500 else if (KeyValue == 0xF001) {
501 //
502 // Popup a menu to notice user
503 //
504 StrCpy (StringBuffer1, L"Do you want to Commit Changes and Exit?");
505 StrCpy (StringBuffer2, L" Enter (YES) / Esc (NO) ");
506
507 do {
508 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
509 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
510
511 //
512 // If the user hits the YES Response key
513 //
514 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
515 //
516 // Save change
517 //
518 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
519 FakeNvData = &Private->FakeNvData;
520
521 Status = HiiGetBrowserData (
522 &mSystemConfigGuid,
523 mVariableName,
524 sizeof (SYSTEM_CONFIGURATION),
525 (UINT8 *) FakeNvData
526 );
527 if (!EFI_ERROR (Status)) {
528 Status = gRT->SetVariable (
529 L"Setup",
530 &mNormalSetupGuid,
531 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
532 sizeof(SYSTEM_CONFIGURATION),
533 &Private->FakeNvData
534 );
535 }
536
537 //
538 // Update Secure Boot configuration changes
539 //
540 CheckSystemConfigSave(FakeNvData);
541
542 //
543 // Reset system
544 //
545 if (GlobalReset == TRUE) {
546 //
547 // Issue full reset
548 //
549 IoWrite8 (
550 (UINTN) 0XCF9,
551 (UINT8) 0x02
552 );
553
554 IoWrite8 (
555 (UINTN) 0xCF9,
556 (UINT8) 0x0E
557 );
558 } else {
559 gRT->ResetSystem(
560 EfiResetCold,
561 EFI_SUCCESS,
562 0,
563 NULL
564 );
565 }
566 }
567 } else if (KeyValue == 0xF002) {
568 //
569 // Popup a menu to notice user
570 //
571 StrCpy (StringBuffer1, L"Do you want to Discard Changes and Exit?");
572 StrCpy (StringBuffer2, L" Enter (YES) / Esc (NO) ");
573
574 do {
575 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
576 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
577
578 //
579 // If the user hits the YES Response key
580 //
581 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
582 //
583 // Reset system
584 //
585 gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
586 }
587 } else if (KeyValue == 0xF003) {
588 //
589 // Popup a menu to notice user
590 //
591 StrCpy (StringBuffer1, L"Do you want to load setup defaults and Exit?");
592 StrCpy (StringBuffer2, L" Enter (YES) / Esc (NO) ");
593
594 do {
595 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
596 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
597
598 //
599 // If the user hits the YES Response key
600 //
601 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
602
603 Status = gBS->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid, NULL, (VOID **) &FormBrowserEx2);
604 FormBrowserEx2->ExecuteAction(BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD);
605
606 FakeNvData = AllocateZeroPool (sizeof(SYSTEM_CONFIGURATION));
607
608 if (FakeNvData == NULL) {
609 return EFI_OUT_OF_RESOURCES;
610 }
611
612 Status = HiiGetBrowserData (
613 &mSystemConfigGuid,
614 mVariableName,
615 sizeof (SYSTEM_CONFIGURATION),
616 (UINT8 *) FakeNvData
617 );
618
619 if (!EFI_ERROR (Status)) {
620 Status = gRT->SetVariable (
621 L"Setup",
622 &mNormalSetupGuid,
623 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
624 sizeof(SYSTEM_CONFIGURATION),
625 FakeNvData
626 );
627 }
628
629 FreePool (FakeNvData);
630
631 DataSize = sizeof(OsSelection);
632 Status = gRT->GetVariable(
633 L"OsSelection",
634 &gOsSelectionVariableGuid,
635 NULL,
636 &DataSize,
637 &OsSelection
638 );
639
640 if (EFI_ERROR(Status) || (OsSelection != FakeNvData->ReservedO)) {
641 OsSelection = FakeNvData->ReservedO;
642 Status = gRT->SetVariable (
643 L"OsSelection",
644 &gOsSelectionVariableGuid,
645 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
646 sizeof(OsSelection),
647 &OsSelection
648 );
649 }
650
651 //
652 // Reset system
653 //
654 gRT->ResetSystem(
655 EfiResetCold,
656 EFI_SUCCESS,
657 0,
658 NULL
659 );
660 }
661 } else if ((KeyValue == 0x123A) || (KeyValue == 0x123B) || (KeyValue == 0x123C)) {
662 StrCpy (StringBuffer1, L"WARNING: Enable or disable USB Controllers will ");
663 StrCpy (StringBuffer2, L"make global reset to restart system.");
664 StrCpy (StringBuffer3, L"Press Enter/ESC to continue...");
665 //
666 // Popup a menu to notice user
667 //
668 do {
669 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, StringBuffer3, NULL);
670 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
671
672 FakeNvData = AllocateZeroPool (sizeof(SYSTEM_CONFIGURATION));
673 Status = HiiGetBrowserData (
674 &mSystemConfigGuid,
675 mVariableName,
676 sizeof (SYSTEM_CONFIGURATION),
677 (UINT8 *) FakeNvData
678 );
679 //
680 // Get variable data
681 //
682 SizeOfNvStore = sizeof(SYSTEM_CONFIGURATION);
683 SetupData = AllocateZeroPool (sizeof(SYSTEM_CONFIGURATION));
684 Status = gRT->GetVariable(
685 L"Setup",
686 &mNormalSetupGuid,
687 NULL,
688 &SizeOfNvStore,
689 SetupData
690 );
691 if ((SetupData->UsbAutoMode != FakeNvData->UsbAutoMode) ||
692 (SetupData->UsbXhciSupport != FakeNvData->UsbXhciSupport) ||
693 (SetupData->PchUsb20 != FakeNvData->PchUsb20)) {
694 GlobalReset = TRUE;
695 } else {
696 GlobalReset = FALSE;
697 }
698
699 }
700 }
701 break;
702
703 default:
704 break;
705 }
706
707 FreePool (StringBuffer1);
708 FreePool (StringBuffer2);
709 FreePool (StringBuffer3);
710
711 //
712 // Workaround for Load Default for "DPTF Enable"
713 //
714 if (Action == EFI_BROWSER_ACTION_DEFAULT_STANDARD) {
715 if (KeyValue == 0x1239) {
716 return EFI_NOT_FOUND;
717 }
718 }
719
720 if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
721 //
722 // Do nothing for UEFI OPEN/CLOSE Action
723 //
724 return EFI_SUCCESS;
725 }
726
727 Private = EFI_CALLBACK_INFO_FROM_THIS (This);
728 FakeNvData = &Private->FakeNvData;
729 if (!HiiGetBrowserData (&mSystemConfigGuid, mVariableName, sizeof (SYSTEM_CONFIGURATION), (UINT8 *) FakeNvData)) {
730 return EFI_NOT_FOUND;
731 }
732
733 if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) && (Private->FakeNvData.ReservedO != Private->BackupNvData.ReservedO)) {
734 Private->BackupNvData.ReservedO = Private->FakeNvData.ReservedO;
735 LoadLpssDefaultValues (Private);
736 }
737
738 //
739 // When user selected the secure erase, set it to disable
740 //
741 if((KeyValue == 0x1240) && (Action == EFI_BROWSER_ACTION_CHANGED)) {
742 FakeNvData->SecureErase = 0;
743 }
744
745 if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_CHANGED)) {
746 //
747 // If function 0 is disabled, function 1 ~ 7 also required to be disabled.
748 //
749 if (Private->FakeNvData.LpssDma0Enabled == 0) {
750 Private->FakeNvData.LpssHsuart0Enabled = 0;
751 Private->FakeNvData.LpssHsuart1Enabled = 0;
752 Private->FakeNvData.LpssPwm0Enabled = 0;
753 Private->FakeNvData.LpssPwm1Enabled = 0;
754 Private->FakeNvData.LpssSpiEnabled = 0;
755 }
756
757
758 //
759 // If function 0 is disabled, function 1 ~ 7 also required to be disabled.
760 //
761 if (Private->FakeNvData.LpssDma1Enabled == 0) {
762 Private->FakeNvData.LpssI2C0Enabled = 0;
763 Private->FakeNvData.LpssI2C1Enabled = 0;
764 Private->FakeNvData.LpssI2C2Enabled = 0;
765 Private->FakeNvData.LpssI2C3Enabled = 0;
766 Private->FakeNvData.LpssI2C4Enabled = 0;
767 Private->FakeNvData.LpssI2C5Enabled = 0;
768 Private->FakeNvData.LpssI2C6Enabled = 0;
769 }
770 }
771
772
773 //
774 // Pass changed uncommitted data back to Form Browser
775 //
776 HiiSetBrowserData (&mSystemConfigGuid, mVariableName, sizeof (SYSTEM_CONFIGURATION), (UINT8 *) FakeNvData, NULL);
777
778 return EFI_SUCCESS;
779 }
780
781
782 /**
783 The driver Entry Point. The funciton will export a disk device class formset and
784 its callback function to hii database.
785
786 @param ImageHandle The firmware allocated handle for the EFI image.
787 @param SystemTable A pointer to the EFI System Table.
788
789 @retval EFI_SUCCESS The entry point is executed successfully.
790 @retval other Some error occurs when executing this entry point.
791
792 **/
793 EFI_STATUS
794 EFIAPI
795 PlatformSetupDxeInit (
796 IN EFI_HANDLE ImageHandle,
797 IN EFI_SYSTEM_TABLE *SystemTable
798 )
799 {
800 EFI_STATUS Status;
801 EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
802
803 mImageHandle = ImageHandle;
804
805 //
806 // There should only be one Form Configuration protocol
807 //
808 Status = gBS->LocateProtocol (
809 &gEfiFormBrowser2ProtocolGuid,
810 NULL,
811 (VOID **) &FormBrowser2
812 );
813 if (EFI_ERROR (Status)) {
814 return Status;
815 }
816
817 mCallbackInfo = AllocateZeroPool (sizeof (EFI_CALLBACK_INFO));
818 if (mCallbackInfo == NULL) {
819 return EFI_BAD_BUFFER_SIZE;
820 }
821
822 mCallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;
823 mCallbackInfo->ConfigAccess.ExtractConfig = SystemConfigExtractConfig;
824 mCallbackInfo->ConfigAccess.RouteConfig = SystemConfigRouteConfig;
825 mCallbackInfo->ConfigAccess.Callback = SystemConfigCallback;
826
827 //
828 // Install Device Path Protocol and Config Access protocol to driver handle
829 // Install Platform Driver Override Protocol to driver handle
830 //
831 Status = gBS->InstallMultipleProtocolInterfaces (
832 &mCallbackInfo->DriverHandle,
833 &gEfiDevicePathProtocolGuid,
834 &mHiiVendorDevicePath,
835 &gEfiHiiConfigAccessProtocolGuid,
836 &mCallbackInfo->ConfigAccess,
837 NULL
838 );
839 if (EFI_ERROR (Status)) {
840 goto Finish;
841 }
842
843 //
844 // Publish our HII data
845 //
846 mCallbackInfo->RegisteredHandle = HiiAddPackages (
847 &mSystemConfigGuid,
848 mCallbackInfo->DriverHandle,
849 VfrBin,
850 PlatformSetupDxeStrings,
851 NULL
852 );
853 if (mCallbackInfo->RegisteredHandle == NULL) {
854 Status = EFI_OUT_OF_RESOURCES;
855 goto Finish;
856 }
857
858 mHiiHandle = mCallbackInfo->RegisteredHandle;
859
860 //
861 // Locate ConfigRouting protocol
862 //
863 Status = gBS->LocateProtocol (
864 &gEfiHiiConfigRoutingProtocolGuid,
865 NULL,
866 (VOID **) &mCallbackInfo->HiiConfigRouting
867 );
868 if (EFI_ERROR (Status)) {
869 goto Finish;
870 }
871
872 //
873 // Clear all the globle variable
874 //
875 return EFI_SUCCESS;
876
877 Finish:
878 if (mCallbackInfo->DriverHandle != NULL) {
879 gBS->UninstallMultipleProtocolInterfaces (
880 mCallbackInfo->DriverHandle,
881 &gEfiDevicePathProtocolGuid,
882 &mHiiVendorDevicePath,
883 &gEfiHiiConfigAccessProtocolGuid,
884 &mCallbackInfo->ConfigAccess,
885 NULL
886 );
887 }
888
889 if (mCallbackInfo->RegisteredHandle != NULL) {
890 HiiRemovePackages (mCallbackInfo->RegisteredHandle);
891 }
892
893 if (mCallbackInfo != NULL) {
894 FreePool (mCallbackInfo);
895 }
896
897 return Status;
898 }
899
900 /**
901 Unload its installed protocol.
902
903 @param[in] ImageHandle Handle that identifies the image to be unloaded.
904
905 @retval EFI_SUCCESS The image has been unloaded.
906 **/
907 EFI_STATUS
908 EFIAPI
909 PlatformSetupDxeUnload (
910 IN EFI_HANDLE ImageHandle
911 )
912 {
913 if (mCallbackInfo != NULL) {
914 if (mCallbackInfo->DriverHandle != NULL) {
915 gBS->UninstallMultipleProtocolInterfaces (
916 mCallbackInfo->DriverHandle,
917 &gEfiDevicePathProtocolGuid,
918 &mHiiVendorDevicePath,
919 &gEfiHiiConfigAccessProtocolGuid,
920 &mCallbackInfo->ConfigAccess,
921 NULL
922 );
923 }
924
925 if (mCallbackInfo->RegisteredHandle != NULL) {
926 HiiRemovePackages (mCallbackInfo->RegisteredHandle);
927 }
928
929 FreePool (mCallbackInfo);
930 }
931
932 return EFI_SUCCESS;
933 }
934