summaryrefslogtreecommitdiff
path: root/ReferenceCode/Haswell/SampleCode/SecCore/Sec/Ia32/CrcSecPpi.c
blob: 28cc105d344f2d11e61e3f1f214fc4d6cad52654 (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
/*++
  This file contains an 'Intel Peripheral Driver' 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                                             
--*/
/*++

Copyright (c)  1999 - 2008 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. 


Module Name:

  CrcSecPpi.c

Abstract:

  Install SecPlatformInformation PPI.

--*/

//#include "Tiano.h"
//#include "PeiCore.h"
//#include "FlashMap.h"
//#include "EfiFirmwareFileSystem.h"
//#include "EfiFirmwareVolumeHeader.h"

//#include EFI_PPI_DEFINITION (SecPlatformInformation)
#include "Tiano.h"
//#include <Core\Core_Pei\PeiCore.h>

//#include "Efi.h"
//#include "Pei.h"

#include "EfiCommonLib.h"
#include <Ppi\AmiEarlyBistPpi.h>
static EFI_GUID gAmiEarlyBistGuid = AMI_EARLY_BIST_PPI_GUID;

#include "SecPlatformInformation.h"

EFI_STATUS
SecPlatformInformation (
  IN EFI_PEI_SERVICES                    **PeiServices,
  IN OUT UINT64                          *StructureSize,
  IN OUT SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
  );

EFI_SEC_PLATFORM_INFORMATION_PPI  mSecPlatformInformationPpi = { SecPlatformInformation };

EFI_PEI_PPI_DESCRIPTOR            mPeiSecPlatformInformationPpi = {
  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
  &gEfiSecPlatformInformationPpiGuid,
  &mSecPlatformInformationPpi
};

EFI_STATUS
EFIAPI
SecPlatformInformation (
  IN EFI_PEI_SERVICES                    **PeiServices,
  IN OUT UINT64                          *StructureSize,
  IN OUT SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
  )
/*++

Routine Description:

  Implementation of the PlatformInformation service in 
  EFI_SEC_PLATFORM_INFORMATION_PPI.
  This function conveys state information out of the SEC phase into PEI.

Arguments:

  PeiServices               - Pointer to the PEI Services Table.
  StructureSize             - Pointer to the variable describing size of the input buffer.
  PlatformInformationRecord - Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
  
Returns:

  EFI_SUCCESS          - The data was successfully returned.
  EFI_BUFFER_TOO_SMALL - The buffer was too small.
  
--*/
{
    UINT32  *BIST;
    UINT32  Size;
    UINT32  Count;
    AMI_EARLY_BIST_PPI  *AmiEarlyPpi;
    EFI_STATUS Status;
    CPU_BIST PrivateBist;
    
	Status = (*PeiServices)->LocatePpi(
		PeiServices,
		&gAmiEarlyBistGuid,
		0, NULL,
		&AmiEarlyPpi
	); 
    //Force BIST no error if PPI not found
    if (Status != EFI_SUCCESS) {
        Size  = sizeof (UINT64);
        if ((*StructureSize) < (UINT64) Size) {
            *StructureSize = Size;
            return EFI_BUFFER_TOO_SMALL;
        }
        PrivateBist.ApicId = 0;
        PrivateBist.Bist = 0;
        BIST = (UINT32*)&PrivateBist;
    } else{   
        Count = AmiEarlyPpi->NumBists;
        Size  = Count * sizeof (UINT64);
        if ((*StructureSize) < (UINT64) Size) {
            *StructureSize = Size;
            return EFI_BUFFER_TOO_SMALL;
        }        
        BIST = (UINT32 *) (&(AmiEarlyPpi->CpuBist));
    }
    *StructureSize  = Size;
    EfiCommonLibCopyMem (PlatformInformationRecord, BIST, Size);
    
    return EFI_SUCCESS;
    
/*
  UINT32  *BIST;
  UINT32  Size;
  UINT32  Count;

  //
  // The entries of BIST information, together with the number of them,
  // reside in the bottom of stack, left untouched by normal stack operation.
  // This routine copies the BIST information to the buffer pointed by
  // PlatformInformationRecord for output.
  //
  Count = *(TopOfCar - 1);
  Size  = Count * sizeof (UINT64);

  if ((*StructureSize) < (UINT64) Size) {
    *StructureSize = Size;
    return EFI_BUFFER_TOO_SMALL;
  }

  *StructureSize  = Size;
  BIST            = (UINT32 *) ((UINT32) TopOfCar - sizeof (UINT32) - Size);

  EfiCommonLibCopyMem (PlatformInformationRecord, BIST, Size);

  return EFI_SUCCESS;
*/
}

//<AMI_PHDR_START>
//**********************************************************************
//
// Procedure:	CrcSecPlatformInformationPpi
//
// Description:	
//  Install SecPlatformInformation PPI that Intel Ivybridge CPU reference code needs.
//  (conveys state information out of the SEC phase into PEI)
//
// Input:
//	IN EFI_FFS_FILE_HEADER *FfsHeader - pointer to the header of the current firmware file system
//  IN EFI_PEI_SERVICES **PeiServices - pointer to the PeiServices Table
//
// Output:
//  EFI_SUCCESS
//
// Notes:	
//          
//**********************************************************************
//<AMI_PHDR_END>
//PeiInitialize eLink

EFI_STATUS EFIAPI CrcSecPlatformInformationPpi(
	IN EFI_FFS_FILE_HEADER *FfsHeader,
	IN EFI_PEI_SERVICES **PeiServices
){
	EFI_STATUS					Status;

	// Install the NB Init Policy PPI
	Status = (*PeiServices)->InstallPpi(PeiServices, &mPeiSecPlatformInformationPpi);

	return EFI_SUCCESS;
}


//	VOID
//	SecStartup (
//	  IN UINT32               SizeOfRam,
//	  IN UINT32               BootFirmwareVolume,
//	  IN PEI_MAIN_ENTRY_POINT PeiCoreEntryPoint
//	  )
/*++

Routine Description:

  Entry point to the C language phase of SEC. After the SEC assembly
  code has initialized some temporary memory and set up the stack,
  the control is transferred to this function.

Arguments:

  SizeOfRam          - Size of the temporary memory available for use.
  BootFirmwareVolume - Base address of the Boot Firmware Volume.
  PeiCoreEntryPoint  - Pointer to the entry point of the PEI core.
  
Returns:

  This function never returns

--*/
//	{
//	  EFI_PEI_STARTUP_DESCRIPTOR  PeiStartup;
//	
//	  PeiStartup.SizeOfCacheAsRam   = SizeOfRam;
//	  PeiStartup.BootFirmwareVolume = BootFirmwareVolume;
//	  PeiStartup.DispatchTable      = &mPeiSecPlatformInformationPpi;
//	
//	  //
//	  // Transfer the control to the PEI core
//	  //
//	  (*PeiCoreEntryPoint) (&PeiStartup);
//	
//	  //
//	  // Should not come here.
//	  //
//	  return ;
//	}