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