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