summaryrefslogtreecommitdiff
path: root/Board/EM/TCG2/Common/AmiTcgPlatformPeiBeforeMem.c
blob: f76147e9b18e20264669b208909227a7b13a869a (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (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/AmiTcgPlatform/AmiTcgPlatformPei/AmiTcgPlatformPeiBeforeMem/AmiTcgPlatformPeiBeforeMem.c 1     4/21/14 2:17p Fredericko $
//
// $Revision: 1 $
//
// $Date: 4/21/14 2:17p $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/TCG2/Common/AmiTcgPlatform/AmiTcgPlatformPei/AmiTcgPlatformPeiBeforeMem/AmiTcgPlatformPeiBeforeMem.c $
// 
// 1     4/21/14 2:17p Fredericko
// 
// 1     10/08/13 12:04p Fredericko
// Initial Check-In for Tpm-Next module
// 
// 1     7/10/13 5:54p Fredericko
// [TAG]  		EIP120969
// [Category]  	New Feature
// [Description]  	TCG (TPM20)
// 
// 8     4/27/12 6:18p Fredericko
// 
// 7     1/17/12 11:24a Fredericko
// Install Tpm_Initialized Ppi in PEI
// 
// 6     10/24/11 12:27p Fredericko
// 
// 5     9/01/11 2:23p Fredericko
// [TAG]  		EIP66113
// [Category]  	Improvement
// [Description]  	Support LTsx on server platforms where startup commands
// are sent by the ACM binaries.
// [Files]  		AmiTcgPlatformPeiBoardBeforeMem.c
// AmiTcgPlatformPeiLib.c
// AmiTcgPlatformPei.h
// 
// 4     4/26/11 1:52p Fredericko
// Added support for function level override of specific functions. 
// 
// 3     4/01/11 9:34a Fredericko
// Updated function Header
// 
// 2     3/29/11 2:22p 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
//
//
// 
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:	AmiTcgPlatformPeiBeforeMem.c
//
// Description:	Function file for AmiTcgPlatformPeiBeforeMem
//
//<AMI_FHDR_END>
//*************************************************************************
#include <Efi.h>
#include <Pei.h>
#include <TcgCommon.h>
#include <AmiPeiLib.h>
#include <TcgMisc.h>
#include "PPI\TcgService\TcgTcmService.h"
#include "PPI\TcgService\TcgService.h"
#include "PPI\TpmDevice\TpmDevice.h"
#include "PPI\CpuIo.h"
#include "PPI\LoadFile.h"
#include <Ppi\ReadOnlyVariable.h>
#include "AmiTcgPlatformPei.h"


EFI_GUID  gAMITcgPlatformPpiBeforeMemguid =  AMI_TCG_PLATFORM_PPI_BEFORE_MEM_GUID;
EFI_GUID  gTpmInitializedguid = PEI_TPM_INITIALIZED_PPI_GUID;

static EFI_PEI_PPI_DESCRIPTOR Tpm_Initialized[] =
{ 
	{
		EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
		&gTpmInitializedguid, NULL 
	}
};


//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure:   MemoryAbsentEntry
//
// Description: This function performs TPM MA initialization
//
//
// Input:       IN      EFI_FFS_FILE_HEADER       *FfsHeader
//              IN      EFI_PEI_SERVICES          **PeiServices,
//
// Output:      EFI_STATUS
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
MemoryAbsentEntry(
    IN EFI_PEI_SERVICES    **PeiServices )
{
    EFI_STATUS              Status;
    EFI_BOOT_MODE           BootMode;
    void                    *TcgDrvBuffer = NULL;
    UINT16                  Pages         = 0;
    EFI_GUID                guid          = EFI_TCG_MADriver_GUID;
    EFI_HOB_GUID_TYPE       *MAHobType;
    MASTRUCT                MAHob;
    FAR32LOCALS             CommonLegX;
    EFI_GUID                gEfiTcgMADriverHobGuid = EFI_TCG_MADriver_HOB_GUID;
    AMI_TCG_PEI_FUNCTION_OVERRIDE_PPI       *PpiOverride;
    EFI_GUID                Overrideguid = AMI_MEMORY_ABSENT_OVERRIDE_GUID;
    EFI_GUID                SkipTpmStartupGuid = AMI_SKIP_TPM_STARTUP_GUID;
    BOOLEAN                 SkipTpmStartup = FALSE;

    Status = (*PeiServices)->LocatePpi(
                    PeiServices,
                    &SkipTpmStartupGuid,
                    0, NULL,
                    &PpiOverride);

    if(!EFI_ERROR(Status)) {
        SkipTpmStartup = TRUE;
    }

    Status = (*PeiServices)->LocatePpi(
                    PeiServices,
                    &Overrideguid,
                    0, NULL,
                    &PpiOverride);

    if(!EFI_ERROR(Status)){
        return (PpiOverride->Function(PeiServices));
    }

    Status = (*PeiServices)->GetBootMode( PeiServices, &BootMode );
    ASSERT_PEI_ERROR( PeiServices, Status );

#if (StartupCmd_SelfTest_State == 1)
        if(!AutoSupportType()){
            if (!SkipTpmStartup) {
              Status = TcgPeiTpmStartup( PeiServices, BootMode );
              ASSERT_PEI_ERROR( PeiServices, Status );
   	        }

            Status = ContinueTPMSelfTest( PeiServices );
            ASSERT_PEI_ERROR( PeiServices, Status );

            if(!EFI_ERROR(Status)){       
              	(*PeiServices)->InstallPpi(PeiServices, Tpm_Initialized);
            }

            if ((BootMode == BOOT_ON_S3_RESUME) || (BootMode == BOOT_IN_RECOVERY_MODE))
            {
                return Status;
            }
        }
#else
        if ((BootMode == BOOT_ON_S3_RESUME) || (BootMode == BOOT_IN_RECOVERY_MODE))
        {
          return Status;
        }
#endif

    if(AutoSupportType()){
        Status = FillDriverLocByFile(&CommonLegX.Offset,PeiServices,&guid,&TcgDrvBuffer,(UINTN*)&Pages);
        if(EFI_ERROR(Status))return EFI_NOT_FOUND;
        if ( CommonLegX.Offset == NULL )
        {
            return EFI_NOT_FOUND;
        }

        MAHob.Offset   = CommonLegX.Offset;
        MAHob.Selector = SEL_flatCS;
        MAHob.Codep    = ((MPDRIVER_LEGHEADER*)((UINT8*)(TcgDrvBuffer)))->CodeP;

        Status = TcgPeiBuildHobGuid(
            PeiServices,
            &gEfiTcgMADriverHobGuid,
            sizeof (MASTRUCT),
            &MAHobType );

        ASSERT_PEI_ERROR( PeiServices, Status );
        MAHobType++;

        (*PeiServices)->CopyMem( MAHobType, &MAHob, sizeof (MASTRUCT));
        return Status;
    }

    return EFI_SUCCESS;
}




static AMI_TCG_PLATFORM_PPI_BEFORE_MEM  mAmiTcgPlatformPPI = {
    MemoryAbsentEntry,
};


static EFI_PEI_PPI_DESCRIPTOR mAmiTcgPlatformPPIListBeforeMem[] = {
    {
        EFI_PEI_PPI_DESCRIPTOR_PPI
        | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
        &gAMITcgPlatformPpiBeforeMemguid,
        &mAmiTcgPlatformPPI
    }
};




//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure:   AmiTcgPlatformPEI_EntryBeforeMem
//
// Description: Installs AMIplatform PPI for initialization in PEI before 
//              memory is installed
//
// Input:        IN EFI_FFS_FILE_HEADER *FfsHeader,
//               IN EFI_PEI_SERVICES    **PeiServices
//
// Output:      EFI_STATUS
//
// Modified:
//
// Referrals:   
//
// Notes:       
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
EFIAPI AmiTcgPlatformPEI_EntryBeforeMem(
    IN EFI_FFS_FILE_HEADER *FfsHeader,
    IN EFI_PEI_SERVICES    **PeiServices 
){
    EFI_STATUS Status;

    Status = (*PeiServices)->InstallPpi( PeiServices, mAmiTcgPlatformPPIListBeforeMem );
    return Status;
}


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