summaryrefslogtreecommitdiff
path: root/ReferenceCode/Haswell/Txt/TxtInit/Pei/TxtPeiLib.h
blob: 28c1303fbaacfc03c20855fa5bfa2e916d4e9736 (plain)
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
/** @file
  This file contains function definitions that can determine
  the TXT capabilities of a platform during PEI and perform
  certain specific platform tasks that are required for TXT
  during PEI.

@copyright
  Copyright (c) 1999 - 2013 Intel Corporation. All rights reserved
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

  This file contains an 'Intel Peripheral Driver' and uniquely
  identified as "Intel Reference Module" and is
  licensed for Intel CPUs and chipsets under the terms of your
  license agreement with Intel or your vendor.  This file may
  be modified by the user, subject to additional terms of the
  license agreement

**/
#ifndef _TXT_PEI_LIB_H_
#define _TXT_PEI_LIB_H_


///
/// External include files do NOT need to be explicitly specified in real EDKII
/// environment
///
#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000)
#include "EdkIIGluePeim.h"
#include "Txt.h"
#include "CpuAccess.h"
#include "BootGuardLibrary.h"

#include EFI_PPI_DEPENDENCY (Variable)
#include EFI_PPI_DEPENDENCY (Stall)
#include EFI_PPI_DEFINITION (TxtMemoryUnlocked)
#include EFI_GUID_DEFINITION (TxtInfoHob)
#include EFI_PPI_PRODUCER (CpuPlatformPolicy)
#endif
#include EFI_PPI_CONSUMER (TpmInitialized)

#define RESET_PORT                    0x0CF9
#define FULL_RESET_VALUE              0xE

#define PCI_BUS_NUMBER_PCH_LPC        0
#define PCI_DEVICE_NUMBER_PCH_LPC     31
#define PCI_FUNCTION_NUMBER_PCH_LPC   0
#define R_PCH_LPC_ACPI_BASE           0x40

#define APIC_SPURIOUS_VECTOR_REGISTER 0xF0
#define DEST_FIELD                    (0 << 18)
#define ALL_EXCLUDING_SELF            BIT19 + BIT18
#define SIPI                          BIT10 + BIT9
#define INIT                          BIT10 + BIT8
#define LEVEL_ASSERT                  BIT14
#define LEVEL_DEASSERT                (0 << 14)
#define DELIVERY_STATUS               BIT13
#define BASE_ADDR_MASK                0xFFFFF000
///
/// #define EFI_MSR_EXT_XAPIC_LVT_THERM         0x833
///
#define EFI_MSR_EXT_XAPIC_SVR 0x80F
#define AP_STARTUP_SIZE       0x1000
#define AP_STARTUP_ADDR       0x1000
#define AP_STARTUP_STKOFF     AP_STARTUP_ADDR + 0xFF0

#define BFV                   0       ///< Boot Firmware Voume
#define PCI_CMD               0x0004  ///< PCI Command Register
#define BM_BIT                0x4     ///< Bus Master bit
#define PCI_SCC               0x000A  ///< Sub Class Code Register
#define PCI_HDR               0x000E  ///< Header Type Register
#define MF_BIT                0x80    ///< Multi-function bit
///
///    Machne                        check architecture MSR registers
///
#define MCG_CAP     0x179
#define MCG_STATUS  0x17A
#define MCG_CTL     0x17B
#define MC0_CTL     0x400
#define MC0_STATUS  0x401
#define MC0_ADDR    0x402
#define MC0_MISC    0x403

typedef struct _ACM_HEADER {
  UINT32 ModuleType; ///< Module type
  UINT32 HeaderLen;  ///< 4 4 Header length (in multiples of four bytes)
  /// (161 for version 0.0)
  ///
  UINT32 HeaderVersion; ///< 8 4 Module format version
  UINT32 ModuleID;      ///< 12 4 Module release identifier
  UINT32 ModuleVendor;  ///< 16 4 Module vendor identifier
  UINT32 Date;          ///< 20 4 Creation date (BCD format:
  /// year.month.day)
  ///
  UINT32 Size;            ///< 24 4 Module size (in multiples of four bytes)
  UINT32 Reserved1;       ///< 28 4 Reserved for future extensions
  UINT32 CodeControl;     ///< 32 4 Authenticated code control flags
  UINT32 ErrorEntryPoint; ///< 36 4 Error response entry point offset (bytes)
  UINT32 GDTLimit;        ///< 40 4 GDT limit (defines last byte of GDT)
  UINT32 GDTBasePtr;      ///< 44 4 GDT base pointer offset (bytes)
  UINT32 SegSel;          ///< 48 4 Segment selector initializer
  UINT32 EntryPoint;      ///< 52 4 Authenticated code entry point offset (bytes)
  UINT32 Reserved2;       ///< 56 64 Reserved for future extensions
  UINT32 KeySize;         ///< 120 4 Module public key size less the exponent
  /// (in multiples of four bytes
  /// - 64 for version 0.0)
  ///
  UINT32 ScratchSize; ///< 124 4 Scratch field size (in multiples of four bytes)
  /// (2 * KeySize + 15 for version 0.0)
  ///
  UINT8 RSAPubKey[65 * 4]; ///< 128 KeySize * 4 + 4 Module public key
  UINT8 RSASig[256];       ///< 388 256 PKCS #1.5 RSA Signature.
} ACM_HEADER;

typedef struct _TXT_PEI_LIB_CONTEXT {
  EFI_PEI_SERVICES **PeiServices;
  PEI_CPU_IO_PPI   *CpuIoPpi;
  PEI_PCI_CFG_PPI  *PciCfgPpi;
  PEI_STALL_PPI    *PeiStall;
  ACM_HEADER       *BiosAcmBase;
  UINT32           BiosAcmSize;
  VOID             *ApStartup;
  UINT32           *McuStart;
  UINT32           Ia32ApicBase;
  TXT_INFO_HOB     *Hob;
} TXT_PEI_LIB_CONTEXT;

#pragma pack(1)
typedef union _MSR_REGISTER {
  UINT64 Qword;

  struct _DWORDS {
    UINT32 Low;
    UINT32 High;
  } Dwords;

  struct _BYTES {
    UINT8 FirstByte;
    UINT8 SecondByte;
    UINT8 ThirdByte;
    UINT8 FouthByte;
    UINT8 FifthByte;
    UINT8 SixthByte;
    UINT8 SeventhByte;
    UINT8 EighthByte;
  } Bytes;

} MSR_REGISTER;


#pragma pack()

#define PLATFORM_ID_SHIFT 50
#define PLATFORM_ID_MASK  7   ///< Bits 52:50
typedef struct _MCU {
  UINT32 headerVer;     ///< MCU Header Version ( = 00000001h )
  UINT32 revision;      ///< MCU Revision
  UINT32 date;          ///< MCU Date
  UINT32 signature;     ///< MCU Processor Signature
  UINT32 checksum;      ///< MCU Main checksum
  UINT32 loaderRev;     ///< MCU Loader Revision
  UINT32 procFlags;     ///< MCU Processor Flags (Platform ID)
  UINT32 dataSize;      ///< MCU Data Size
  UINT32 totalSize;     ///< MCU Total Size
  UINT32 reserved[3];
} MCU;

typedef struct _EST {
  UINT32 count;         ///< EST Count
  UINT32 checksum;      ///< EST Checksum
  UINT32 reserved[3];
} EST;

typedef struct _PSS {
  UINT32 signature;     ///< PSS Processor Signature
  UINT32 procFlags;     ///< PSS Processor Flags (Platform ID)
  UINT32 checksum;      ///< PSS Checksum
} PSS;

/**
  Returns CPU count

  @retval Number of CPUs
**/
UINT32
GetCpuCount (
  VOID
  );

/**
  Execute SCLEAN through BIOS ACM
**/
VOID
LaunchBiosAcmSclean (
  VOID
  );

/**
  Issue a global reset through PCH and PORTCF9
**/
VOID
DoGlobalReset (
  VOID
  );

/**
  Issue a cpu-only reset through PCH and PORTCF9
**/
VOID
DoCpuReset (
  VOID
  );

/**
  Issue a HOST reset through PCH and PORTCF9
**/
VOID
DoHostReset (
  VOID
  );

/**
  Dispatch APs to execute *Function with parameter pointed by *Param

  @param[in] (*Function)  - Address of Function to be executed by APs
  @param[in] Param        - Function parameter to be passed to
**/
VOID
StartupAllAPs (
  VOID (*Function)(),
  UINT64 *Param
  );

/**
  Put All APs into Wait-for-SIPI state
**/
VOID
PutApsInWfs (
  VOID
  );

/**
  Restore MTRR registers

  @param[in] ApCfg - Point to the MTRR buffer
**/
VOID
RestoreMtrrProgramming (
  UINT64 *ApCfg
  );

/**
  Restore APs' registers

  @param[in] ApCfg - Point to APs' registers buffer
**/
VOID
RestoreApConfig (
  UINT64 *ApCfg
  );

/**
  Initializes values passed to AP

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure
**/
VOID
PrepareApParams (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  This routine initializes and collects all PPIs and data required
  by the routines in this file.

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure
  @param[in] mPS - A pointer to the PEI Service Table

  @exception EFI_UNSUPPORTED   - If any of the required PPIs or data are unavailable
  @retval EFI_SUCCESS       - In all cases not listed above
**/
EFI_STATUS
InitializeTxtPeiLib (
  TXT_PEI_LIB_CONTEXT *pctx,
  IN EFI_PEI_SERVICES **mPS
  );

/**
  Determines whether or not the current processor is TXT Capable.

  @retval TRUE          - If the current processor supports TXT
  @retval FALSE         - If the current processor does not support TXT
**/
BOOLEAN
IsTxtProcessor (
  VOID
  );

/**
  Determines whether or not the current chipset is TXT Capable.

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure

  @retval TRUE          - If the current chipset supports TXT
  @retval FALSE         - If the current chipset doesn't supports TXT
**/
BOOLEAN
IsTxtChipset (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Determines whether or not POISON bit is set in status register

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure

  @retval TRUE          - If the TXT_WAKE_ERROR bit is asserted.
  @retval FALSE         - If the TXT_WAKE_ERROR bit is unasserted.
**/
BOOLEAN
IsTxtResetSet (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Determines whether or not SECRETS.STS bit is set in E2STS status register

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure

  @retval TRUE          - If the LT.SECRETS.STS bit is asserted.
  @retval FALSE         - If the LT.SECRETS.STS bit is unasserted.
**/
BOOLEAN
IsTxtSecretsSet (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Determines whether or not the platform has executed an TXT launch by
  examining the TPM Establishment bit.

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure

  @retval TRUE          - If the TPM establishment bit is asserted.
  @retval FALSE         - If the TPM establishment bit is unasserted.
**/
BOOLEAN
IsEstablishmentBitAsserted (
  IN TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Determines whether or not the platform has encountered an error during
  a sleep or power-off state.

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure

  @retval TRUE          - If the TXT_WAKE_ERROR bit is asserted.
  @retval FALSE         - If the TXT_WAKE_ERROR bit is unasserted.
**/
BOOLEAN
IsTxtWakeError (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Determines whether or not the platform memory has been locked

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure

  @retval TRUE          - If memroy is locked
  @retval FALSE         - If memory is unlocked
**/
BOOLEAN
IsMemoryLocked (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure

  @retval TRUE          - If TXT is enabled by platform setting
  @retval FALSE         - If TXT is disabled by platform setting
**/
BOOLEAN
IsTxtEnabled (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Determines ACM is matched to chipset or not

  @param[in] pctx         - Point to TXT_PEI_LIB_CONTEXT structure
  @param[in] BiosAcmBase  - A pointer to BIOS ACM location

  @retval TRUE          - BIOS ACM is matched to chipset
  @retval FALSE         - BIOS ACM is NOT matched to chipset
**/
BOOLEAN
CheckTxtAcmMatch (
  TXT_PEI_LIB_CONTEXT *pctx,
  ACM_HEADER          *BiosAcmBase
  );

/**
  Clear Sleep Type register.

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure

  @retval EFI_SUCCESS   - Always
**/
EFI_STATUS
ClearSlpTyp (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Invokes the SCLEAN function from the TXT BIOS ACM.
  1. Clearing of sleep type is necessary because SCLEAN destroys memory
  context, so S3 after it is run and system is reset is impossible. We
  do it here since there is no any indication that can sustain reset
  for any other module to do it on our behalf.
  2. APs are initialized before calling of SCLEAN
  3. SCLEAN function is invoked.

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure

  @retval EFI_SUCCESS   - Always.
**/

EFI_STATUS
DoSclean (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Determines presence of TPM in system

  @param[in] pctx         - Point to TXT_PEI_LIB_CONTEXT structure

  @retval EFI_SUCCESS          - If the TPM is present.
  @retval EFI_NOT_FOUND        - If the TPM is not present.
**/
EFI_STATUS
IsTpmPresent (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Searches PEI firemare volume (FV_BB) for file containig BIOS ACM.

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure
  @param[in] pBIOSAC_BASE  - A pointer to pointer to variable to hold found address

  @retval EFI_SUCCESS   - If address has been found
  @retval EFI_NOT_FOUND     - If address has not been found
**/
EFI_STATUS
FindBiosAcmInVolume (
  TXT_PEI_LIB_CONTEXT *pctx,
  OUT UINT32          **pBIOSAC_BASE
  );

/**
  Searches PEI firmware volume (FV_BB) for file containig AP Startup code

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure
  @param[in] pAP_STARTUP  - A pointer to pointer to variable to hold address
  @param[in] address.

  @retval EFI_SUCCESS   - If address has been found
  @retval EFI_NOT_FOUND     - If address has not been found
**/
EFI_STATUS
FindApStartupInVolume (
  TXT_PEI_LIB_CONTEXT *pctx,
  OUT UINT32          **pAP_STARTUP
  );

/**
  Searches PEI firmware volume (FV_BB) for offset of currently loaded MCU patch

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure
  @param[in] pMCU          - A pointer to pointer to variable to hold found offset
  @param[in] address.

  @retval EFI_SUCCESS   - If address has been found
  @retval EFI_NOT_FOUND     - If address has not been found
**/
EFI_STATUS
FindMcuInVolume (
  TXT_PEI_LIB_CONTEXT *pctx,
  OUT UINT32          **pMCU
  );

/**
  Searches PEI firmware volume (FV_BB) for the file with specified GUID through pGuid

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure
  @param[in] pGuid         - A pointer GUID
  @param[in] pModule       - A pointer to pointer to variable to hold address

  @retval EFI_SUCCESS   - If address has been found
  @retval EFI ERROR     - If address has not been found
**/
EFI_STATUS
FindModuleInFlash (
  TXT_PEI_LIB_CONTEXT *pctx,
  EFI_GUID            *pGuid,
  OUT UINT32          **pModule
  );

/**
  Parses Hob list for TXT Info HOB

  @param[in] pctx          - A pointer to an initialized TXT PEI Context data structure

  @retval EFI_SUCCESS   - If TXT Info Hob is found
  @retval EFI_NOT_FOUND - If TXT Info Hob is not found
**/
EFI_STATUS
CreateTxtInfoHob (
  TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Unlock memory when security is set ant TxT is not enabled

  @param[in] pctx      - A pointer to an initialized TXT PEI Context data structure

  @retval EFI_SUCCESS     - Complete memory unlock
  @exception EFI_UNSUPPORTED - CPU doesn't support TxT.
**/
EFI_STATUS
UnlockMemory (
  IN TXT_PEI_LIB_CONTEXT *pctx
  );

/**
  Fix up pointers since they are located in real memory now.

  @param[in] PeiServices          General purpose services available to every PEIM.
  @param[in] NotifyDescriptor     The notification structure this PEIM registered on install.
  @param[in] Ppi                  The memory discovered PPI.  Not used.

  @retval EFI_SUCCESS             The function completed successfully.
**/
EFI_STATUS
DprUpdate (
  IN EFI_PEI_SERVICES          **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
  IN VOID                      *Ppi
  );

#endif