]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/SecCore/SecBist.c
UefiCpuPkg/SecCore: Abstract worker function GetBistFromHob()
[mirror_edk2.git] / UefiCpuPkg / SecCore / SecBist.c
1 /** @file
2 Get SEC platform information(2) PPI and reinstall it.
3
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "SecMain.h"
16
17 /**
18 Worker function to parse CPU BIST information from Guided HOB.
19
20 @param[out] StructureSize Pointer to the variable describing size of the input buffer.
21 @param[out] StructureBuffer Pointer to the buffer save CPU BIST information.
22
23 @retval EFI_SUCCESS The data was successfully returned.
24 @retval EFI_BUFFER_TOO_SMALL The buffer was too small.
25
26 **/
27 EFI_STATUS
28 GetBistFromHob (
29 IN OUT UINT64 *StructureSize,
30 IN OUT VOID *StructureBuffer
31 )
32 {
33 EFI_HOB_GUID_TYPE *GuidHob;
34 VOID *DataInHob;
35 UINTN DataSize;
36
37 GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);
38 if (GuidHob == NULL) {
39 *StructureSize = 0;
40 return EFI_SUCCESS;
41 }
42
43 DataInHob = GET_GUID_HOB_DATA (GuidHob);
44 DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
45
46 //
47 // return the information from BistHob
48 //
49 if ((*StructureSize) < (UINT64) DataSize) {
50 *StructureSize = (UINT64) DataSize;
51 return EFI_BUFFER_TOO_SMALL;
52 }
53
54 *StructureSize = (UINT64) DataSize;
55 CopyMem (StructureBuffer, DataInHob, DataSize);
56 return EFI_SUCCESS;
57 }
58
59 /**
60 Implementation of the PlatformInformation service in EFI_SEC_PLATFORM_INFORMATION_PPI.
61
62 @param[in] PeiServices Pointer to the PEI Services Table.
63 @param[out] StructureSize Pointer to the variable describing size of the input buffer.
64 @param[out PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
65
66 @retval EFI_SUCCESS The data was successfully returned.
67 @retval EFI_BUFFER_TOO_SMALL The buffer was too small.
68
69 **/
70 EFI_STATUS
71 EFIAPI
72 SecPlatformInformationBist (
73 IN CONST EFI_PEI_SERVICES **PeiServices,
74 IN OUT UINT64 *StructureSize,
75 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
76 )
77 {
78 return GetBistFromHob (StructureSize, PlatformInformationRecord);
79 }
80
81 /**
82 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.
83
84 @param[in] PeiServices The pointer to the PEI Services Table.
85 @param[out] StructureSize The pointer to the variable describing size of the input buffer.
86 @param[out] PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.
87
88 @retval EFI_SUCCESS The data was successfully returned.
89 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to
90 hold the record is returned in StructureSize.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 SecPlatformInformation2Bist (
96 IN CONST EFI_PEI_SERVICES **PeiServices,
97 IN OUT UINT64 *StructureSize,
98 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
99 )
100 {
101 return GetBistFromHob (StructureSize, PlatformInformationRecord2);
102 }
103
104 /**
105 Worker function to get CPUs' BIST by calling SecPlatformInformationPpi
106 or SecPlatformInformation2Ppi.
107
108 @param[in] PeiServices Pointer to PEI Services Table
109 @param[in] Guid PPI Guid
110 @param[out] PpiDescriptor Return a pointer to instance of the
111 EFI_PEI_PPI_DESCRIPTOR
112 @param[out] BistInformationData Pointer to BIST information data
113 @param[out] BistInformationSize Return the size in bytes of BIST information
114
115 @retval EFI_SUCCESS Retrieve of the BIST data successfully
116 @retval EFI_NOT_FOUND No sec platform information(2) ppi export
117 @retval EFI_DEVICE_ERROR Failed to get CPU Information
118
119 **/
120 EFI_STATUS
121 GetBistInfoFromPpi (
122 IN CONST EFI_PEI_SERVICES **PeiServices,
123 IN CONST EFI_GUID *Guid,
124 OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
125 OUT VOID **BistInformationData,
126 OUT UINT64 *BistInformationSize OPTIONAL
127 )
128 {
129 EFI_STATUS Status;
130 EFI_SEC_PLATFORM_INFORMATION2_PPI *SecPlatformInformation2Ppi;
131 EFI_SEC_PLATFORM_INFORMATION_RECORD2 *SecPlatformInformation2;
132 UINT64 InformationSize;
133
134 Status = PeiServicesLocatePpi (
135 Guid, // GUID
136 0, // INSTANCE
137 PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
138 (VOID **)&SecPlatformInformation2Ppi // PPI
139 );
140 if (Status == EFI_NOT_FOUND) {
141 return EFI_NOT_FOUND;
142 }
143
144 if (Status == EFI_SUCCESS) {
145 //
146 // Get the size of the sec platform information2(BSP/APs' BIST data)
147 //
148 InformationSize = 0;
149 SecPlatformInformation2 = NULL;
150 Status = SecPlatformInformation2Ppi->PlatformInformation2 (
151 PeiServices,
152 &InformationSize,
153 SecPlatformInformation2
154 );
155 if (Status == EFI_BUFFER_TOO_SMALL) {
156 Status = PeiServicesAllocatePool (
157 (UINTN) InformationSize,
158 (VOID **) &SecPlatformInformation2
159 );
160 if (Status == EFI_SUCCESS) {
161 //
162 // Retrieve BIST data
163 //
164 Status = SecPlatformInformation2Ppi->PlatformInformation2 (
165 PeiServices,
166 &InformationSize,
167 SecPlatformInformation2
168 );
169 if (Status == EFI_SUCCESS) {
170 *BistInformationData = SecPlatformInformation2;
171 if (BistInformationSize != NULL) {
172 *BistInformationSize = InformationSize;
173 }
174 return EFI_SUCCESS;
175 }
176 }
177 }
178 }
179
180 return EFI_DEVICE_ERROR;
181 }