2 Platform SEC Library for Quark.
4 Copyright (c) 2013-2015 Intel Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Ppi/SecPlatformInformation.h>
14 #include <Ppi/TemporaryRamSupport.h>
15 #include <Library/PcdLib.h>
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/HobLib.h>
20 #include <Library/MtrrLib.h>
24 Entry point to the C language phase of SEC. After the SEC assembly
25 code has initialized some temporary memory and set up the stack,
26 the control is transferred to this function.
28 @param SizeOfRam Size of the temporary memory available for use.
29 @param TempRamBase Base address of temporary ram
30 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
37 IN UINT32 TempRamBase
,
38 IN VOID
*BootFirmwareVolume
42 Auto-generated function that calls the library constructors for all of the module's
43 dependent libraries. This function must be called by the SEC Core once a stack has
49 ProcessLibraryConstructorList (
55 Entry point to the C language phase of PlatformSecLib. After the SEC assembly
56 code has initialized some temporary memory and set up the stack, control is
57 transferred to this function.
62 PlatformSecLibStartup (
67 // Process all library constructor functions linked to SecCore.
68 // This function must be called before any library functions are called
70 ProcessLibraryConstructorList ();
73 // Set write back cache attribute for SPI FLASH
75 MtrrSetMemoryAttribute (
76 PcdGet32 (PcdFlashAreaBaseAddress
),
77 PcdGet32 (PcdFlashAreaSize
),
82 // Set write back cache attribute for 512KB Embedded SRAM
84 MtrrSetMemoryAttribute (
85 PcdGet32 (PcdEsramStage1Base
),
91 // Pass control to SecCore module passing in the size of the temporary RAM in
92 // Embedded SRAM, the base address of the temporary RAM in Embedded SRAM, and
93 // the base address of the boot firmware volume. The top 32KB of the 512 KB
94 // embedded SRAM are used as temporary RAM.
98 PcdGet32 (PcdEsramStage1Base
) + SIZE_512KB
- SIZE_32KB
,
99 (VOID
*)(UINTN
)PcdGet32 (PcdFlashFvRecoveryBase
)
104 A developer supplied function to perform platform specific operations.
106 It's a developer supplied function to perform any operations appropriate to a
107 given platform. It's invoked just before passing control to PEI core by SEC
108 core. Platform developer may modify the SecCoreData and PPI list that is
111 @param SecCoreData The same parameter as passing to PEI core. It
112 could be overridden by this function.
113 @param PpiList The default PPI list passed from generic SEC
116 @return The final PPI list that platform wishes to passed to PEI core.
119 EFI_PEI_PPI_DESCRIPTOR
*
122 IN OUT EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
123 IN EFI_PEI_PPI_DESCRIPTOR
*PpiList
130 This interface conveys state information out of the Security (SEC) phase into PEI.
132 @param PeiServices Pointer to the PEI Services Table.
133 @param StructureSize Pointer to the variable describing size of the input buffer.
134 @param PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
136 @retval EFI_SUCCESS The data was successfully returned.
137 @retval EFI_BUFFER_TOO_SMALL The buffer was too small.
142 SecPlatformInformation (
143 IN CONST EFI_PEI_SERVICES
**PeiServices
,
144 IN OUT UINT64
*StructureSize
,
145 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD
*PlatformInformationRecord
151 EFI_HOB_GUID_TYPE
*GuidHob
;
155 // Top of the stack is the top of the 512KB Embedded SRAM region
157 TopOfStack
= (UINT32
*)(UINTN
)(PcdGet32 (PcdEsramStage1Base
) + SIZE_512KB
);
159 GuidHob
= GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid
);
160 if (GuidHob
!= NULL
) {
161 Size
= GET_GUID_HOB_DATA_SIZE (GuidHob
);
162 BIST
= GET_GUID_HOB_DATA (GuidHob
);
165 // The entries of BIST information, together with the number of them,
166 // reside in the bottom of stack, left untouched by normal stack operation.
167 // This routine copies the BIST information to the buffer pointed by
168 // PlatformInformationRecord for output.
170 Count
= *(TopOfStack
- 1);
171 Size
= Count
* sizeof (IA32_HANDOFF_STATUS
);
172 BIST
= (UINT32
*) ((UINT32
) TopOfStack
- sizeof (UINT32
) - Size
);
175 // Copy Data from Stack to Hob to avoid data is lost after memory is ready.
178 &gEfiSecPlatformInformationPpiGuid
,
182 GuidHob
= GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid
);
183 Size
= GET_GUID_HOB_DATA_SIZE (GuidHob
);
184 BIST
= GET_GUID_HOB_DATA (GuidHob
);
187 if ((*StructureSize
) < (UINT64
) Size
) {
188 *StructureSize
= Size
;
189 return EFI_BUFFER_TOO_SMALL
;
192 *StructureSize
= Size
;
193 CopyMem (PlatformInformationRecord
, BIST
, Size
);
199 This interface disables temporary memory in SEC Phase.
203 SecPlatformDisableTemporaryMemory (