Set RTC initial time to be BIOS Release time.
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformDxe / PlatformDxe.h
1 /*++
2
3 Copyright (c) 2004 - 2015, 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
15 Module Name:
16
17 PlatformDxe.h
18
19 Abstract:
20
21 Header file for Platform Initialization Driver.
22
23
24
25 ++*/
26
27 #ifndef _PLATFORM_DRIVER_H
28 #define _PLATFORM_DRIVER_H
29
30 #include <PiDxe.h>
31 #include <Library/BaseLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/PcdLib.h>
36 #include <Library/HobLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/BaseMemoryLib.h>
40 #include <Library/UefiRuntimeServicesTableLib.h>
41 #include <Library/IoLib.h>
42 #include <Library/ReportStatusCodeLib.h>
43 #include <Library/HobLib.h>
44 #include <Library/EfiRegTableLib.h>
45 #include <Library/Tpm2CommandLib.h>
46 #include <Library/Tpm2DeviceLib.h>
47 #include <Library/BaseCryptLib.h>
48 #include <Library/BiosIdLib.h>
49 #include <Protocol/GlobalNvsArea.h>
50 #include <Protocol/PciRootBridgeIo.h>
51 #include <Protocol/IsaAcpi.h>
52 #include <Framework/FrameworkInternalFormRepresentation.h>
53 #include <Protocol/FrameworkHii.h>
54 #include <Protocol/FrameworkFormCallback.h>
55 #include <Protocol/CpuIo.h>
56 #include <Protocol/BootScriptSave.h>
57 #include <Framework/BootScript.h>
58 #include <Guid/GlobalVariable.h>
59 #include <Guid/BoardFeatures.h>
60 #include <Guid/DataHubRecords.h>
61 #include <Protocol/DataHub.h>
62 #include <Protocol/PciIo.h>
63 #include <Protocol/Speaker.h>
64 #include <Protocol/ExitPmAuth.h>
65 #include <IndustryStandard/Pci22.h>
66 #include <Guid/SetupVariable.h>
67 #include <Guid/PlatformInfo.h>
68 #include "Configuration.h"
69 #define _EFI_H_ //skip efi.h
70 #include "PchAccess.h"
71 #include "VlvAccess.h"
72 #include "BoardIdDecode.h"
73 #include "PlatformBaseAddresses.h"
74 #include "SetupMode.h"
75 #include "PlatformBootMode.h"
76 #include "CpuType.h"
77
78 #define PCAT_RTC_ADDRESS_REGISTER 0x74
79 #define PCAT_RTC_DATA_REGISTER 0x75
80
81 #define RTC_ADDRESS_SECOND_ALARM 0x01
82 #define RTC_ADDRESS_MINUTE_ALARM 0x03
83 #define RTC_ADDRESS_HOUR_ALARM 0x05
84
85 #define RTC_ADDRESS_REGISTER_A 0x0A
86 #define RTC_ADDRESS_REGISTER_B 0x0B
87 #define RTC_ADDRESS_REGISTER_C 0x0C
88 #define RTC_ADDRESS_REGISTER_D 0x0D
89
90 #define B_RTC_ALARM_INT_ENABLE 0x20
91 #define B_RTC_ALARM_INT_STATUS 0x20
92
93 #define B_RTC_DATE_ALARM_MASK 0x3F
94
95 //
96 // Default CPU Alternate Duty Cycle (255=100%, 0=0%)
97 //
98 #define DEF_CPU_ALT_DUTY_CYCLE 0xFF
99
100 #define MAX_ONBOARD_SATA_DEVICE 2
101
102 #define DXE_DEVICE_ENABLED 1
103 #define DXE_DEVICE_DISABLED 0
104
105 #define AZALIA_MAX_LOOP_TIME 0x10000
106
107 //
108 // Platform driver GUID
109 //
110 #define EFI_PLATFORM_DRIVER_GUID \
111 { 0x056E7324, 0xA718, 0x465b, 0x9A, 0x84, 0x22, 0x8F, 0x06, 0x64, 0x2B, 0x4F }
112
113 #define PASSWORD_MAX_SIZE 20
114 #define PLATFORM_NORMAL_MODE 0x01
115 #define PLATFORM_SAFE_MODE 0x02
116 #define PLATFORM_RECOVERY_MODE 0x04
117 #define PLATFORM_MANUFACTURING_MODE 0x08
118 #define PLATFORM_BACK_TO_BIOS_MODE 0x10
119
120 #define EFI_OEM_SPECIFIC 0x8000
121 #define EFI_CU_PLATFORM_DXE_INIT (EFI_OEM_SPECIFIC | 0x00000011)
122 #define EFI_CU_PLATFORM_DXE_STEP1 (EFI_OEM_SPECIFIC | 0x00000012)
123 #define EFI_CU_PLATFORM_DXE_STEP2 (EFI_OEM_SPECIFIC | 0x00000013)
124 #define EFI_CU_PLATFORM_DXE_STEP3 (EFI_OEM_SPECIFIC | 0x00000014)
125 #define EFI_CU_PLATFORM_DXE_STEP4 (EFI_OEM_SPECIFIC | 0x00000015)
126 #define EFI_CU_PLATFORM_DXE_INIT_DONE (EFI_OEM_SPECIFIC | 0x00000016)
127
128
129 #define EFI_SECTION_STRING 0x1C
130 #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
131 #define PREFIX_BLANK 0x04
132
133 #pragma pack(1)
134
135 typedef UINT64 EFI_BOARD_FEATURES;
136
137 //
138 //BUGBUG: should remove these EDK hii definition once Hii transtion is done
139 //
140 typedef UINT16 STRING_REF;
141 typedef UINT16 EFI_FORM_LABEL;
142
143 typedef enum {
144 EfiUserPassword,
145 EfiAdminPassword
146 } EFI_PASSWORD_TYPE;
147
148 typedef struct {
149 CHAR16 TempPassword[PASSWORD_MAX_SIZE];
150 CHAR16 EncodedPassword[PASSWORD_MAX_SIZE];
151 VOID *PasswordLocation;
152 EFI_PASSWORD_TYPE PasswordType;
153 } EFI_PASSWORD_DATA;
154
155 typedef struct {
156 CHAR8 AaNumber[7];
157 UINT8 BoardId;
158 EFI_BOARD_FEATURES Features;
159 UINT16 SubsystemDeviceId;
160 UINT16 AudioSubsystemDeviceId;
161 UINT64 AcpiOemTableId;
162 } BOARD_ID_DECODE;
163
164 typedef
165 EFI_STATUS
166 (EFIAPI *EFI_FORM_ROUTINE) (
167 SYSTEM_CONFIGURATION *SetupBuffer
168 );
169
170 typedef struct{
171 UINT16 DeviceNumber;
172 UINT16 FunctionNumber;
173 }PCI_DEVICE_FUNC_INFO;
174
175 typedef struct{
176 CHAR16 PortNumber[4];
177 STRING_REF SataDeviceInfoStringId;
178 }SATA_DEVICE_STRING_INFO;
179
180 typedef struct {
181 UINT16 Signature;
182 UINT8 Size;
183 UINT32 EntryPoint;
184 UINT8 Reserve[17];
185 UINT16 PciDataOff;
186 UINT16 ExpansionOff;
187 } PNP_OPTION_ROM_HEADER;
188
189 typedef struct {
190 UINT32 Signature;
191 UINT8 Revision;
192 UINT8 Length;
193 UINT16 NextHeader;
194 UINT8 Reserve;
195 UINT8 CheckSum;
196 UINT32 DeviceId;
197 UINT16 ManufactureStrOff;
198 UINT16 ProductStrOff;
199 } PNP_EXPANSION_HEADER;
200
201 typedef struct {
202 BOOLEAN Enable;
203 UINT8 VerbTableNum;
204 UINT16 CodecSSID;
205 EFI_PHYSICAL_ADDRESS HDABar;
206 EFI_PHYSICAL_ADDRESS UpperHDABar;
207 UINT8 SDIPresent;
208 BOOLEAN Pme;
209 BOOLEAN LegacyFrontPanelAudio;
210 BOOLEAN HighDefinitionFrontPanelAudio;
211 } EFI_AZALIA_S3;
212
213 //
214 //following structs are from R8. Remove them once R8->R9 transition is done
215 //
216 typedef struct {
217 CHAR16 *OptionString; // Passed in string to generate a token for in a truly dynamic form creation
218 STRING_REF StringToken; // This is used when creating a single op-code without generating a StringToken (have one already)
219 UINT16 Value;
220 UINT8 Flags;
221 UINT16 Key;
222 } IFR_OPTION;
223
224
225
226 typedef struct {
227 UINT8 Number;
228 UINT32 HorizontalResolution;
229 UINT32 VerticalResolution;
230 } PANEL_RESOLUTION;
231
232 #pragma pack()
233
234 //
235 // Prototypes
236 //
237 EFI_STATUS
238 EFIAPI
239 EfiMain (
240 IN EFI_HANDLE ImageHandle,
241 IN EFI_SYSTEM_TABLE *SystemTable
242 );
243
244 EFI_STATUS
245 ProcessEventLog (
246 );
247
248 EFI_STATUS
249 FindDataRecords (
250 );
251
252 EFI_STATUS
253 ProcessPasswords(
254 );
255
256 VOID
257 MemorySetup(
258 );
259
260
261 UINTN
262 EfiValueToString (
263 IN OUT CHAR16 *Buffer,
264 IN INT64 Value,
265 IN UINTN Flags,
266 IN UINTN Width
267 );
268
269 VOID
270 EFIAPI
271 ReadyToBootFunction (
272 EFI_EVENT Event,
273 VOID *Context
274 );
275
276 VOID
277 InstallHiiDataAndGetSettings(
278 IN EFI_HII_STRING_PACK *StringPack,
279 //
280 ... // 0 or more of => IN EFI_HII_IFR_PACK *IfrPack,
281 // Terminate list with NULL
282 //
283 );
284
285 EFI_STATUS
286 ReadOrInitSetupVariable(
287 IN UINTN RequiredVariableSize,
288 IN UINTN RequiredPasswordSize,
289 IN VOID *DefaultData,
290 IN VOID *MfgDefaultData,
291 OUT VOID *SetupVariableData,
292 OUT VOID *SystemPassword
293 );
294
295 VOID
296 EfiLogicalOrMem(
297 IN VOID *Destination,
298 IN VOID *Source,
299 IN UINTN Length
300 );
301
302 EFI_STATUS
303 GetStringFromToken (
304 IN EFI_GUID *ProducerGuid,
305 IN STRING_REF Token,
306 OUT CHAR16 **String
307 );
308
309 UINT32
310 ConvertBase2ToRaw (
311 IN EFI_EXP_BASE2_DATA *Data);
312
313 UINT32
314 ConvertBase10ToRaw (
315 IN EFI_EXP_BASE10_DATA *Data);
316
317 CHAR16 *
318 GetStringById (
319 IN STRING_REF Id,
320 EFI_HII_HANDLE StringPackHandle
321 );
322
323 VOID
324 EFIAPI
325 SetupDataFilter (
326 IN EFI_EVENT Event,
327 IN VOID* Context
328 );
329
330 VOID
331 EFIAPI
332 IdeDataFilter (
333 IN EFI_EVENT Event,
334 IN VOID* Context
335 );
336
337 VOID
338 EFIAPI
339 UpdateAhciRaidDiskInfo (
340 IN EFI_EVENT Event,
341 IN VOID* Context
342 );
343
344 VOID
345 EFIAPI
346 EventLogFilter (
347 IN EFI_EVENT Event,
348 IN VOID* Context
349 );
350
351 VOID
352 SwapEntries (
353 IN CHAR8 *Data
354 );
355
356 VOID
357 AsciiToUnicode (
358 IN CHAR8 *AsciiString,
359 IN CHAR16 *UnicodeString
360 );
361
362 UINT16
363 ConfigModeStateGet();
364
365 VOID
366 SetSkus();
367
368 VOID
369 CPUSetupItems();
370
371 EFI_STATUS
372 SecurityDriverCallback (
373 IN EFI_FORM_CALLBACK_PROTOCOL *This,
374 IN UINT16 KeyValue,
375 IN EFI_IFR_DATA_ARRAY *Data,
376 OUT EFI_HII_CALLBACK_PACKET **Packet
377 );
378
379 VOID
380 SetPasswordState (
381 );
382
383 VOID
384 EncodePassword (
385 IN CHAR16 *Password
386 );
387
388 VOID
389 EFIAPI
390 PciBusEvent (
391 IN EFI_EVENT Event,
392 IN VOID* Context
393 );
394 VOID
395 AsfInitialize(
396 );
397
398 VOID
399 InitializeAsf (
400 );
401
402 UINT8
403 ReadCmosBank1Byte (
404 IN EFI_CPU_IO_PROTOCOL *CpuIo,
405 IN UINT8 Index
406 );
407
408 VOID
409 WriteCmosBank1Byte (
410 IN EFI_CPU_IO_PROTOCOL *CpuIo,
411 IN UINT8 Index,
412 IN UINT8 Data
413 );
414
415 VOID
416 InitializeBoardId (
417 );
418
419 EFI_STATUS
420 InstallBootCallbackRoutine(
421 );
422
423 EFI_STATUS
424 InstallConfigurationCallbackRoutine(
425 );
426
427 EFI_STATUS
428 InstallPerformanceCallbackRoutine(
429 );
430
431 EFI_STATUS
432 InstallSecurityCallbackRoutine (
433 );
434
435 EFI_STATUS
436 InstallMainCallbackRoutine (
437 );
438
439 EFI_STATUS
440 MemoryConfigurationUpdate (
441 UINT16 *Key,
442 EFI_FORM_LABEL *Label,
443 UINT16 *OpcodeCount,
444 UINT8 **OpcodeData,
445 EFI_FORM_ROUTINE *Routine
446 );
447
448 EFI_STATUS
449 MemoryConfigurationCallbackRoutine (
450 SYSTEM_CONFIGURATION *SetupBuffer
451 );
452
453 EFI_STATUS
454 MemoryConfigurationCalculateSpeed(
455 SYSTEM_CONFIGURATION *SetupBuffer
456 );
457
458 VOID
459 UpdateMemoryString(
460 IN STRING_REF TokenToUpdate,
461 IN CHAR16 *NewString
462 );
463
464 VOID
465 InitFeaturePolicy (
466 IN EFI_PLATFORM_INFO_HOB *PlatformInfo
467 );
468
469 VOID
470 InitializeSetupVarHide (
471 );
472
473 VOID
474 PreparePCIePCISlotInformation(
475 VOID
476 );
477
478
479 EFI_STATUS
480 BootConfigurationUpdate (
481 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
482 );
483
484 EFI_STATUS
485 InitializeBootConfiguration(
486 VOID
487 );
488
489 UINT16
490 GetStringSize(
491 IN CHAR16 *ThisString
492 );
493
494 UINT16
495 GetDriveCount (
496 IN STRING_REF *BootMap
497 );
498
499 CHAR16 *
500 GetBootString (
501 IN STRING_REF Id,
502 OUT UINTN *Length
503 );
504
505 EFI_STATUS
506 BootCfgCreateTwoOptionOneOf(
507 IN UINT16 QuestionId,
508 IN EFI_FORM_LABEL Label,
509 IN STRING_REF OptionPrompt,
510 IN STRING_REF OptionHelp,
511 IN STRING_REF OptionOneString,
512 IN STRING_REF OptionTwoString,
513 IN UINT8 OptionOneFlags,
514 IN UINT8 OptionTwoFlags,
515 IN UINT16 KeyValueOne,
516 IN UINT16 KeyValueTwo
517 );
518
519 EFI_STATUS
520 ReplaceOpcodeWithText(
521 IN STRING_REF OptionPrompt,
522 IN STRING_REF OptionHelp,
523 IN STRING_REF OptionOneString,
524 IN EFI_FORM_LABEL Label
525 );
526
527 EFI_STATUS
528 CreateDriveBootOrderOpcode(
529 IN VOID *Data,
530 IN STRING_REF *BootMap,
531 IN EFI_FORM_LABEL Label,
532 IN UINT16 QuestionId,
533 IN STRING_REF OptionOneString,
534 IN STRING_REF OptionTwoString
535 );
536
537 VOID
538 SetHyperBootCfgFlags(
539 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
540 );
541
542 VOID
543 GetHyperBootCfgFlags(
544 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
545 );
546
547 VOID
548 PrepareBootCfgForHyperBoot(
549 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
550 );
551
552 BOOLEAN
553 BootCfgChanged(
554 IN SYSTEM_CONFIGURATION *SystemConfiguration
555 );
556
557 EFI_STATUS
558 InsertOpcodeAtIndex(
559 IN SYSTEM_CONFIGURATION *SystemConfiguration,
560 IN OUT IFR_OPTION *OptionList,
561 IN IFR_OPTION IfrOption,
562 IN UINT16 OptionCount
563 );
564
565 VOID
566 ConfigureBootOrderStrings(
567 IN SYSTEM_CONFIGURATION *SystemConfiguration
568 );
569
570 VOID
571 InitializeAllBootStrings(
572 VOID
573 );
574
575 VOID
576 SaveUsbCfgSettings(
577 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
578 );
579
580 VOID
581 RestoreUsbCfgSettings(
582 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
583 );
584
585 EFI_STATUS
586 UpdateBootDevicePriority(
587 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
588 );
589
590 EFI_STATUS
591 DisableHyperBoot(
592 IN OUT SYSTEM_CONFIGURATION *SystemConfiguration
593 );
594
595 BOOLEAN
596 CheckForUserPassword(
597 VOID
598 );
599
600 EFI_STATUS
601 EFIAPI
602 HyperBootPasswordCallback(
603 IN OUT VOID* Data
604 );
605
606 EFI_STATUS
607 EFIAPI
608 HyperBootF9Callback (
609 IN VOID* Data
610 );
611
612 EFI_STATUS
613 InstallHiiEvents(
614 VOID
615 );
616
617 EFI_STATUS
618 EFIAPI
619 ProgramToneFrequency (
620 IN EFI_SPEAKER_IF_PROTOCOL *This,
621 IN UINT16 Frequency
622 );
623
624 EFI_STATUS
625 EFIAPI
626 GenerateBeepTone (
627 IN EFI_SPEAKER_IF_PROTOCOL *This,
628 IN UINTN NumberOfBeeps,
629 IN UINTN BeepDuration,
630 IN UINTN TimeInterval
631 );
632
633 EFI_STATUS
634 InitializeObservableProtocol();
635
636 EFI_STATUS
637 PciBusDriverHook();
638
639 VOID
640 EFIAPI
641 AdjustDefaultRtcTimeCallback (
642 IN EFI_EVENT Event,
643 IN VOID *Context
644 );
645
646 typedef struct _GOP_DISPLAY_BRIGHTNESS_PROTOCOL GOP_DISPLAY_BRIGHTNESS_PROTOCOL;
647
648 typedef
649 EFI_STATUS
650 (EFIAPI *GET_MAXIMUM_BRIGHTNESS_LEVEL) (
651 IN GOP_DISPLAY_BRIGHTNESS_PROTOCOL *This,
652 OUT UINT32 *MaxBrightnessLevel
653 );
654
655
656 typedef
657 EFI_STATUS
658 (EFIAPI *GET_CURRENT_BRIGHTNESS_LEVEL) (
659 IN GOP_DISPLAY_BRIGHTNESS_PROTOCOL *This,
660 OUT UINT32 *MaxBrightnessLevel
661 );
662
663 typedef
664 EFI_STATUS
665 (EFIAPI *SET_BRIGHTNESS_LEVEL) (
666 IN GOP_DISPLAY_BRIGHTNESS_PROTOCOL *This,
667 IN UINT32 BrightnessLevel
668 );
669
670 struct _GOP_DISPLAY_BRIGHTNESS_PROTOCOL {
671 UINT32 Revision;
672 GET_MAXIMUM_BRIGHTNESS_LEVEL GetMaxBrightnessLevel;
673 GET_CURRENT_BRIGHTNESS_LEVEL GetCurrentBrightnessLevel;
674 SET_BRIGHTNESS_LEVEL SetBrightnessLevel;
675 };
676
677 //
678 // Global externs
679 //
680 extern UINT8 MaintenanceBin[];
681 extern UINT8 MainBin[];
682 extern UINT8 ConfigurationBin[];
683 extern UINT8 MemoryConfigurationBin[];
684 extern UINT8 PerformanceBin[];
685 extern UINT8 SecurityBin[];
686 extern UINT8 BootBin[];
687 extern UINT8 PowerBin[];
688 extern UINT8 SystemSetupBin[];
689
690 extern VOID *mDxePlatformStringPack;
691 extern EFI_HII_PROTOCOL *mHii;
692 extern SYSTEM_CONFIGURATION mSystemConfiguration;
693 extern FRAMEWORK_EFI_HII_HANDLE mMaintenanceHiiHandle;
694 extern FRAMEWORK_EFI_HII_HANDLE mMainHiiHandle;
695 extern FRAMEWORK_EFI_HII_HANDLE mConfigurationHiiHandle;
696 extern FRAMEWORK_EFI_HII_HANDLE mPerformanceHiiHandle;
697 extern FRAMEWORK_EFI_HII_HANDLE mPowerHiiHandle;
698 extern FRAMEWORK_EFI_HII_HANDLE mBootHiiHandle;
699 extern FRAMEWORK_EFI_HII_HANDLE mSecurityHiiHandle;
700
701 extern SYSTEM_PASSWORDS mSystemPassword;
702 extern EFI_PASSWORD_DATA mAdminPassword;
703 extern EFI_PASSWORD_DATA mUserPassword;
704
705 extern EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *mPciRootBridgeIo;
706
707 //
708 //extern EFI_REG_TABLE mSubsystemIdRegs[];
709 //
710 extern UINT32 mSubsystemVidDid;
711 extern UINT32 mSubsystemAudioVidDid;
712
713 extern UINT8 mBoardIdIndex;
714 extern BOOLEAN mFoundAANum;
715 extern EFI_BOARD_FEATURES mBoardFeatures;
716 extern UINT16 mSubsystemDeviceId;
717 extern UINT16 mSubsystemAudioDeviceId;
718 extern BOARD_ID_DECODE mBoardIdDecodeTable[];
719 extern UINTN mBoardIdDecodeTableSize;
720
721 extern UINT8 mSmbusRsvdAddresses[];
722 extern UINT8 mNumberSmbusAddress;
723 extern BOOLEAN mMfgMode;
724 extern UINT32 mPlatformBootMode;
725 extern CHAR8 BoardAaNumber[];
726
727 extern EFI_GUID gEfiGlobalNvsAreaProtocolGuid;
728 #endif