summaryrefslogtreecommitdiff
path: root/Core/EM/TCG2/Common/xTcgPei.c
blob: 506f9be1e256e2344ae4df437bc0e1c50bb402a0 (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**     5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093            **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
//*************************************************************************
// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/xTcgPei.c 1     4/21/14 2:16p Fredericko $
//
// $Revision: 1 $
//
// $Date: 4/21/14 2:16p $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/xTcgPei.c $
// 
// 1     4/21/14 2:16p Fredericko
// 
// 1     10/08/13 12:02p Fredericko
// Initial Check-In for Tpm-Next module
// 
// 2     10/03/13 1:54p Fredericko
// 
// 1     7/10/13 5:51p Fredericko
// [TAG]  		EIP120969
// [Category]  	New Feature
// [Description]  	TCG (TPM20)
// 
// 36    9/19/12 10:34a Fredericko
// [TAG]  		EIP90807
// [Category]  	Improvement
// [Description]  	MonotonicCounter variable guid changed.
// [Files]  		xTcgPei.c, AmiTcgPlatformPeiAfterMem.c
// 
// 35    3/19/12 6:27p Fredericko
// [TAG]  		EIP82769
// [Description]  	Firmware updates disable the TPM when Firmware update
// is done
// [Files]  		TcgDxe.c, xTcgDxe.c, xTcgPei.c
// 
// 34    12/12/11 3:17p Fredericko
// [TAG]  		EIP76865
// [Category]  	Improvement
// [Description]  	Dual Support for TCM and TPM. System could hang in TXT
// if txt is enabled in setup
// [Files]  		
// AmiTcgPlatfompeilib.c, AmiTcgPlatformPpi.cif,  AmiTcgPlatformPpi.h,
// AmiTcgPlatformProtocol.cif,  AmiTcgPlatformProtocol.h,
// EMpTcmPei.c, TcgDxe.cif, TcgPei.cif, TcgPeiAfterMem.cif,
// TcgPeiAfterMem.mak, TcgTcmPeiAfterMem.c, xTcgDxe.c, xTcgPei.c, 
// xTcgPeiAfterMem.c 
// 
// 33    9/27/11 10:21p Fredericko
// [TAG]  		EIP67286
// [Category]  	Improvement
// [Description]  	changes for Tcg Setup policy
// [Files]  		Tcg.sdl
// TcgPei.cif
// TcgPei.mak
// xtcgPei.c
// xTcgPeiAfterMem.c
// TcgPeiAfterMem.mak
// TcgDxe.cif
// TcgDxe.mak
// xTcgDxe.c
// AmiTcgPlatformPeilib.c
// AmiTcgPlatformDxelib.c
// 
// 32    4/27/11 3:01p Fredericko
// removed VFR compile directive
// 
// 31    3/29/11 12:57p Fredericko
// 
// 30    3/28/11 2:14p Fredericko
// [TAG]        EIP 54642
// [Category] Improvement
// [Description] 1. Checkin Files related to TCG function override 
// 2. Include TCM and TPM auto detection
// [Files] Affects all TCG files
// 
// 29    5/19/10 5:53p Fredericko
// Included File Header
// Included File Revision History
// Updated AMI Function Headers
// Code Beautification
// EIP 37653
//
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:  xTcgPei.c
//
// Description:
//        Contians entry point function for TcgPei Subcomponent
//
//<AMI_FHDR_END>
//*************************************************************************
#include <Efi.h>
#include <Pei.h>
#include <TcgCommon.h>
#include <AmiPeiLib.h>
#include <TcgMisc.h>
#include <ppi\AmiTcgPlatformPpi.h>
#include "PPI\TcgService\TcgService.h"
#include "PPI\TpmDevice\TpmDevice.h"
#include "PPI\CpuIo.h"
#include "PPI\LoadFile.h"
#include "TcgPlatformSetupPeiPolicy.h"
#include "Tpm20Includes\Tpm20.h"
#include "Tpm20CRBLib.h"



EFI_GUID        gTcgPpiGuid = PEI_TCG_PPI_GUID;
EFI_GUID        gPlatformGuid = AMI_TCG_PLATFORM_PPI_GUID;

EFI_STATUS
EFIAPI TpmPeiEntry (
    IN EFI_FFS_FILE_HEADER *FfsHeader,
    IN EFI_PEI_SERVICES    **PeiServices );

EFI_STATUS
EFIAPI TcmPeiEntry (
    IN EFI_FFS_FILE_HEADER *FfsHeader,
    IN EFI_PEI_SERVICES    **PeiServices );


EFI_STATUS
EFIAPI TcgPeiEntry (
    IN EFI_FFS_FILE_HEADER *FfsHeader,
    IN EFI_PEI_SERVICES    **PeiServices );

EFI_STATUS
EFIAPI TcgTcmPeiEntry (
    IN EFI_FFS_FILE_HEADER *FfsHeader,
    IN EFI_PEI_SERVICES    **PeiServices );

EFI_STATUS TcgPeiBuildHobGuid(
    IN EFI_PEI_SERVICES **PeiServices,
    IN EFI_GUID         *Guid,
    IN UINTN            DataLength,
    OUT VOID            **Hob );

EFI_STATUS
EFIAPI Tpm20CrbEntry(
    IN EFI_FFS_FILE_HEADER *FfsHeader,
    IN EFI_PEI_SERVICES    **PeiServices );

UINT8 GetPlatformSupportType()
{
   return (AutoSupportType());
}

static AMI_TCG_PLATFORM_PPI PlatformTypePpi = {
    GetPlatformSupportType
};


static EFI_PEI_PPI_DESCRIPTOR mPlatformPpiList[] = {
    {
        EFI_PEI_PPI_DESCRIPTOR_PPI
        | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
        &gPlatformGuid,
        &PlatformTypePpi
    }
};


//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure:   CommonTcgPeiEntryPoint
//
// Description: Entry point for Tcg PEI component
//
//
// Input:       IN      EFI_FFS_FILE_HEADER       *FfsHeader
//              IN      EFI_PEI_SERVICES          **PeiServices,
//
// Output:      EFI_STATUS
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
EFIAPI CommonTcgPeiEntryPoint(
    IN EFI_FFS_FILE_HEADER *FfsHeader,
    IN EFI_PEI_SERVICES    **PeiServices )
{
    EFI_STATUS                     Status;
    VOID                           *Context = NULL;
    BOOLEAN                        DeviceType = FALSE;
    TCG_PLATFORM_SETUP_INTERFACE   *TcgPeiPolicy = NULL;
    EFI_GUID                        gTcgPeiPolicyGuid =\
                                        TCG_PLATFORM_SETUP_PEI_POLICY_GUID;
    TCG_CONFIGURATION              ConfigFlags;
    CHAR16                         Monotonic[] = L"MonotonicCounter";
#if defined(CORE_COMBINED_VERSION) && (CORE_COMBINED_VERSION > 262797)
    EFI_GUID                       Guid        = AMI_GLOBAL_VARIABLE_GUID;
#else
    EFI_GUID                       Guid        = EFI_GLOBAL_VARIABLE;
#endif
    EFI_GUID                       TcgGuid     = AMI_TCG_RESETVAR_HOB_GUID;
    UINTN                          Size        = sizeof(UINT32);
    UINT32                         Counter;
    EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
    EFI_HOB_GUID_TYPE               *Hob;
    BOOLEAN                         ResetAllTcgVar = FALSE;
    EFI_GUID                        gTcgReadOnlyVariablePpiGuid
                                        = EFI_TCG_PEI_READ_ONLY_VARIABLE_PPI_GUID;


    Status = (*PeiServices)->InstallPpi( PeiServices, &mPlatformPpiList[0] );
    if ( EFI_ERROR( Status ))
    {
        return EFI_UNLOAD_IMAGE;
    }

    Status = (*PeiServices)->LocatePpi(
                PeiServices,
                &gTcgPeiPolicyGuid,
                0, NULL,
                &TcgPeiPolicy);

    if(EFI_ERROR(Status) || TcgPeiPolicy == NULL )return Status;
    
    Status = (*PeiServices)->LocatePpi(
        PeiServices,
        &gTcgReadOnlyVariablePpiGuid,
        0, NULL,
        &ReadOnlyVariable
        );

    if(EFI_ERROR(Status) || ReadOnlyVariable == NULL )return Status;

    Status = ReadOnlyVariable->GetVariable( PeiServices, Monotonic, &Guid,
                                            NULL, &Size, &Counter );

    if ( EFI_ERROR( Status ))
    {

        ResetAllTcgVar = TRUE;
        Status         = TcgPeiBuildHobGuid(
            PeiServices,
            &TcgGuid,
            sizeof (BOOLEAN),
            &Hob );
    
        Hob++;
        (*PeiServices)->CopyMem( Hob, &ResetAllTcgVar, sizeof (ResetAllTcgVar));
    }

    if(!AutoSupportType()){
       Status = TpmPeiEntry( FfsHeader, PeiServices );
       PEI_TRACE((-1, PeiServices, "TpmPeiEntry results = %r \n", Status)); 
       if ( EFI_ERROR( Status )){ 
             return Status; 
       }
    }else{
       Status = TcmPeiEntry( FfsHeader, PeiServices );
       if ( EFI_ERROR( Status )){
       return Status;}
    }

    PEI_TRACE((-1, PeiServices, "before getTcgPeiPolicy\n")); 
    Status = TcgPeiPolicy->getTcgPeiPolicy(PeiServices, &ConfigFlags);

    PEI_TRACE((-1, PeiServices, "getTcgPeiPolicy results = %r \n", Status)); 

    if ( ConfigFlags.TpmSupport == 0x00  || EFI_ERROR( Status ))
    {
        PEI_TRACE((-1, PeiServices, "ConfigFlags.TpmSupport == 0x00  || EFI_ERROR( Status )\n")); 
        return EFI_SUCCESS;
    }


    PEI_TRACE((-1, PeiServices, "TcgPeiEntry processing\n")); 
    if(!AutoSupportType()){
       Status = TcgPeiEntry( FfsHeader, PeiServices );
       PEI_TRACE((-1, PeiServices, "TcgPeiEntry result = %r\n", Status)); 
       if(EFI_ERROR(Status)){
            PEI_TRACE((-1, PeiServices, "Tpm20CrbEntry Execution\n", Status));
            Tpm20CrbEntry(FfsHeader, PeiServices );
       }
    }else{
       Status = TcgTcmPeiEntry( FfsHeader, PeiServices );
    }

    return Status;
}

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**     5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093            **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
//**********************************************************************