]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkPlatformPkg/Library/PlatformSecLib/PlatformSecLib.c
QuarkPlatformPkg: Add new package for Galileo boards
[mirror_edk2.git] / QuarkPlatformPkg / Library / PlatformSecLib / PlatformSecLib.c
1 /** @file
2 Platform SEC Library for Quark.
3
4 Copyright (c) 2013-2015 Intel Corporation.
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14
15 **/
16
17 #include <PiPei.h>
18
19 #include <Ppi/SecPlatformInformation.h>
20 #include <Ppi/TemporaryRamSupport.h>
21 #include <Library/PcdLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/HobLib.h>
26 #include <Library/MtrrLib.h>
27
28 /**
29
30 Entry point to the C language phase of SEC. After the SEC assembly
31 code has initialized some temporary memory and set up the stack,
32 the control is transferred to this function.
33
34 @param SizeOfRam Size of the temporary memory available for use.
35 @param TempRamBase Base address of temporary ram
36 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
37
38 **/
39 VOID
40 EFIAPI
41 SecStartup (
42 IN UINT32 SizeOfRam,
43 IN UINT32 TempRamBase,
44 IN VOID *BootFirmwareVolume
45 );
46
47 /**
48 Auto-generated function that calls the library constructors for all of the module's
49 dependent libraries. This function must be called by the SEC Core once a stack has
50 been established.
51
52 **/
53 VOID
54 EFIAPI
55 ProcessLibraryConstructorList (
56 VOID
57 );
58
59 /**
60
61 Entry point to the C language phase of PlatformSecLib. After the SEC assembly
62 code has initialized some temporary memory and set up the stack, control is
63 transferred to this function.
64
65 **/
66 VOID
67 EFIAPI
68 PlatformSecLibStartup (
69 VOID
70 )
71 {
72 //
73 // Process all library constructor functions linked to SecCore.
74 // This function must be called before any library functions are called
75 //
76 ProcessLibraryConstructorList ();
77
78 //
79 // Set write back cache attribute for SPI FLASH
80 //
81 MtrrSetMemoryAttribute (
82 PcdGet32 (PcdFlashAreaBaseAddress),
83 PcdGet32 (PcdFlashAreaSize),
84 CacheWriteBack
85 );
86
87 //
88 // Set write back cache attribute for 512KB Embedded SRAM
89 //
90 MtrrSetMemoryAttribute (
91 PcdGet32 (PcdEsramStage1Base),
92 SIZE_512KB,
93 CacheWriteBack
94 );
95
96 //
97 // Pass control to SecCore module passing in the size of the temporary RAM in
98 // Embedded SRAM, the base address of the temporary RAM in Embedded SRAM, and
99 // the base address of the boot firmware volume. The top 32KB of the 512 KB
100 // embedded SRAM are used as temporary RAM.
101 //
102 SecStartup (
103 SIZE_32KB,
104 PcdGet32 (PcdEsramStage1Base) + SIZE_512KB - SIZE_32KB,
105 (VOID *)(UINTN)PcdGet32 (PcdFlashFvRecoveryBase)
106 );
107 }
108
109 /**
110 A developer supplied function to perform platform specific operations.
111
112 It's a developer supplied function to perform any operations appropriate to a
113 given platform. It's invoked just before passing control to PEI core by SEC
114 core. Platform developer may modify the SecCoreData and PPI list that is
115 passed to PEI Core.
116
117 @param SecCoreData The same parameter as passing to PEI core. It
118 could be overridden by this function.
119 @param PpiList The default PPI list passed from generic SEC
120 part.
121
122 @return The final PPI list that platform wishes to passed to PEI core.
123
124 **/
125 EFI_PEI_PPI_DESCRIPTOR *
126 EFIAPI
127 SecPlatformMain (
128 IN OUT EFI_SEC_PEI_HAND_OFF *SecCoreData,
129 IN EFI_PEI_PPI_DESCRIPTOR *PpiList
130 )
131 {
132 return NULL;
133 }
134
135 /**
136 This interface conveys state information out of the Security (SEC) phase into PEI.
137
138 @param PeiServices Pointer to the PEI Services Table.
139 @param StructureSize Pointer to the variable describing size of the input buffer.
140 @param PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
141
142 @retval EFI_SUCCESS The data was successfully returned.
143 @retval EFI_BUFFER_TOO_SMALL The buffer was too small.
144
145 **/
146 EFI_STATUS
147 EFIAPI
148 SecPlatformInformation (
149 IN CONST EFI_PEI_SERVICES **PeiServices,
150 IN OUT UINT64 *StructureSize,
151 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
152 )
153 {
154 UINT32 *BIST;
155 UINT32 Size;
156 UINT32 Count;
157 EFI_HOB_GUID_TYPE *GuidHob;
158 UINT32 *TopOfStack;
159
160 //
161 // Top of the stack is the top of the 512KB Embedded SRAM region
162 //
163 TopOfStack = (UINT32 *)(UINTN)(PcdGet32 (PcdEsramStage1Base) + SIZE_512KB);
164
165 GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid);
166 if (GuidHob != NULL) {
167 Size = GET_GUID_HOB_DATA_SIZE (GuidHob);
168 BIST = GET_GUID_HOB_DATA (GuidHob);
169 } else {
170 //
171 // The entries of BIST information, together with the number of them,
172 // reside in the bottom of stack, left untouched by normal stack operation.
173 // This routine copies the BIST information to the buffer pointed by
174 // PlatformInformationRecord for output.
175 //
176 Count = *(TopOfStack - 1);
177 Size = Count * sizeof (IA32_HANDOFF_STATUS);
178 BIST = (UINT32 *) ((UINT32) TopOfStack - sizeof (UINT32) - Size);
179
180 //
181 // Copy Data from Stack to Hob to avoid data is lost after memory is ready.
182 //
183 BuildGuidDataHob (
184 &gEfiSecPlatformInformationPpiGuid,
185 BIST,
186 (UINTN)Size
187 );
188 GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid);
189 Size = GET_GUID_HOB_DATA_SIZE (GuidHob);
190 BIST = GET_GUID_HOB_DATA (GuidHob);
191 }
192
193 if ((*StructureSize) < (UINT64) Size) {
194 *StructureSize = Size;
195 return EFI_BUFFER_TOO_SMALL;
196 }
197
198 *StructureSize = Size;
199 CopyMem (PlatformInformationRecord, BIST, Size);
200
201 return EFI_SUCCESS;
202 }
203
204 /**
205 This interface disables temporary memory in SEC Phase.
206 **/
207 VOID
208 EFIAPI
209 SecPlatformDisableTemporaryMemory (
210 VOID
211 )
212 {
213 }