]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFspPkg/FspSecCore/SecMain.c
Eliminate duplicated file GUID.
[mirror_edk2.git] / IntelFspPkg / FspSecCore / SecMain.c
1 /** @file
2
3 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php.
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 #include "SecMain.h"
15 #include "SecFsp.h"
16
17 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi = {
18 SecTemporaryRamSupport
19 };
20
21 EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi[] = {
22 {
23 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
24 &gEfiTemporaryRamSupportPpiGuid,
25 &gSecTemporaryRamSupportPpi
26 }
27 };
28
29 //
30 // These are IDT entries pointing to 08:FFFFFFE4h.
31 //
32 UINT64 mIdtEntryTemplate = 0xffff8e000008ffe4ULL;
33
34 /**
35
36 Entry point to the C language phase of SEC. After the SEC assembly
37 code has initialized some temporary memory and set up the stack,
38 the control is transferred to this function.
39
40
41 @param[in] SizeOfRam Size of the temporary memory available for use.
42 @param[in] TempRamBase Base address of tempory ram
43 @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.
44 @param[in] PeiCoreEntry Pei Core entrypoint.
45
46 @return This function never returns.
47
48 **/
49 VOID
50 EFIAPI
51 SecStartup (
52 IN UINT32 SizeOfRam,
53 IN UINT32 TempRamBase,
54 IN VOID *BootFirmwareVolume,
55 IN UINTN PeiCoreEntry
56 )
57 {
58 EFI_SEC_PEI_HAND_OFF SecCoreData;
59 IA32_DESCRIPTOR IdtDescriptor;
60 SEC_IDT_TABLE IdtTableInStack;
61 UINT32 Index;
62 FSP_GLOBAL_DATA PeiFspData;
63 PEI_CORE_ENTRY PeiCore;
64 UINT64 ExceptionHandler;
65
66 //
67 // Process all libraries constructor function linked to SecCore.
68 //
69 ProcessLibraryConstructorList ();
70
71 //
72 // Initialize floating point operating environment
73 // to be compliant with UEFI spec.
74 //
75 InitializeFloatingPointUnits ();
76
77
78 // |-------------------|---->
79 // |Idt Table |
80 // |-------------------|
81 // |PeiService Pointer | PeiStackSize
82 // |-------------------|
83 // | |
84 // | Stack |
85 // |-------------------|---->
86 // | |
87 // | |
88 // | Heap | PeiTemporayRamSize
89 // | |
90 // | |
91 // |-------------------|----> TempRamBase
92 IdtTableInStack.PeiService = NULL;
93 ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate);
94 for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) {
95 CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&ExceptionHandler, sizeof (UINT64));
96 }
97
98 IdtDescriptor.Base = (UINTN) &IdtTableInStack.IdtTable;
99 IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1);
100
101 AsmWriteIdtr (&IdtDescriptor);
102
103 //
104 // Iniitalize the global FSP data region
105 //
106 FspGlobalDataInit (&PeiFspData, &BootFirmwareVolume);
107
108 //
109 // Update the base address and length of Pei temporary memory
110 //
111 SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
112 SecCoreData.BootFirmwareVolumeBase = BootFirmwareVolume;
113 SecCoreData.BootFirmwareVolumeSize = (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)BootFirmwareVolume)->FvLength;
114 SecCoreData.TemporaryRamBase = (VOID*)(UINTN) TempRamBase;
115 SecCoreData.TemporaryRamSize = SizeOfRam;
116 SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
117 SecCoreData.PeiTemporaryRamSize = SizeOfRam >> 1;
118 SecCoreData.StackBase = (VOID*)(UINTN)(TempRamBase + SecCoreData.PeiTemporaryRamSize);
119 SecCoreData.StackSize = SizeOfRam >> 1;
120
121 //
122 // Call PeiCore Entry
123 //
124 PeiCore = (PEI_CORE_ENTRY)(PeiCoreEntry);
125 PeiCore (&SecCoreData, mPeiSecPlatformInformationPpi);
126
127 //
128 // Should never be here
129 //
130 CpuDeadLoop ();
131 }
132
133 /**
134 This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
135 permanent memory.
136
137 @param[in] PeiServices Pointer to the PEI Services Table.
138 @param[in] TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the
139 Temporary RAM contents.
140 @param[in] PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the
141 Temporary RAM contents.
142 @param[in] CopySize Amount of memory to migrate from temporary to permanent memory.
143
144 @retval EFI_SUCCESS The data was successfully returned.
145 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
146 TemporaryMemoryBase > PermanentMemoryBase.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 SecTemporaryRamSupport (
152 IN CONST EFI_PEI_SERVICES **PeiServices,
153 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
154 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
155 IN UINTN CopySize
156 )
157 {
158 IA32_DESCRIPTOR IdtDescriptor;
159 VOID* OldHeap;
160 VOID* NewHeap;
161 VOID* OldStack;
162 VOID* NewStack;
163
164 OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;
165 NewHeap = (VOID*)((UINTN)PermanentMemoryBase + CopySize / 2);
166
167 OldStack = (VOID*)((UINTN)TemporaryMemoryBase + CopySize / 2);
168 NewStack = (VOID*)(UINTN)PermanentMemoryBase;
169
170 //
171 // Migrate Heap
172 //
173 CopyMem (NewHeap, OldHeap, CopySize / 2);
174
175 //
176 // Migrate Stack
177 //
178 CopyMem (NewStack, OldStack, CopySize / 2);
179
180
181 //
182 // We need *not* fix the return address because currently,
183 // The PeiCore is executed in flash.
184 //
185
186 //
187 // Rebase IDT table in permanent memory
188 //
189 AsmReadIdtr (&IdtDescriptor);
190 IdtDescriptor.Base = IdtDescriptor.Base - (UINTN)OldStack + (UINTN)NewStack;
191
192 AsmWriteIdtr (&IdtDescriptor);
193
194 //
195 // Fixed the FSP data pointer
196 //
197 FspDataPointerFixUp ((UINTN)NewStack - (UINTN)OldStack);
198
199 //
200 // SecSwitchStack function must be invoked after the memory migration
201 // immediatly, also we need fixup the stack change caused by new call into
202 // permenent memory.
203 //
204 SecSwitchStack (
205 (UINT32) (UINTN) OldStack,
206 (UINT32) (UINTN) NewStack
207 );
208
209 return EFI_SUCCESS;
210 }