]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Sec/SecMain.c
OVMF ResetVector: Modify interface with SEC module
[mirror_edk2.git] / OvmfPkg / Sec / SecMain.c
CommitLineData
49ba9447 1/** @file
2 Main SEC phase code. Transitions to PEI.
3
4 Copyright (c) 2008 - 2009, Intel Corporation
5
6 All rights reserved. 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#include <PiPei.h>
17#include <Library/BaseLib.h>
18#include <Library/DebugLib.h>
19#include <Library/BaseMemoryLib.h>
20#include <Library/PeiServicesLib.h>
21#include <Ppi/TemporaryRamSupport.h>
22#include <Library/PcdLib.h>
284af948 23#include <Library/UefiCpuLib.h>
49ba9447 24
25#include "SecMain.h"
26
27EFI_STATUS
28EFIAPI
29TemporaryRamMigration (
30 IN CONST EFI_PEI_SERVICES **PeiServices,
31 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
32 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
33 IN UINTN CopySize
34 );
35
36STATIC TEMPORARY_RAM_SUPPORT_PPI mTempRamSupportPpi = {
37 (TEMPORARY_RAM_MIGRATION) TemporaryRamMigration
38};
39
40STATIC EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable[] = {
41 {
42 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
43 &gEfiTemporaryRamSupportPpiGuid,
44 &mTempRamSupportPpi
45 },
46};
47
48
49VOID
50InitializeIdtPtr (
51 IN VOID* IdtPtr
52 )
53{
54 IA32_DESCRIPTOR IdtDescriptor;
55
56 IdtDescriptor.Base = (UINTN)IdtPtr;
57 IdtDescriptor.Limit = (UINT16) 0;
58 AsmWriteIdtr (&IdtDescriptor);
59}
60
61VOID
62EFIAPI
63SecCoreStartupWithStack (
64 IN VOID *BootFirmwareVolumePtr,
65 IN VOID *SecCoreEntryPoint,
66 IN VOID *PeiCoreEntryPoint,
67 IN VOID *TopOfCurrentStack
68 )
69{
70 EFI_SEC_PEI_HAND_OFF *SecCoreData;
71 UINT8 *BottomOfTempRam;
72 UINT8 *TopOfTempRam;
73 UINTN SizeOfTempRam;
74 VOID *IdtPtr;
75
284af948 76 //
77 // Initialize floating point operating environment
78 // to be compliant with UEFI spec.
79 //
80 InitializeFloatingPointUnits ();
81
49ba9447 82 DEBUG ((EFI_D_ERROR,
83 "SecCoreStartupWithStack(0x%x, 0x%x, 0x%x, 0x%x)\n",
84 (UINT32)(UINTN)BootFirmwareVolumePtr,
85 (UINT32)(UINTN)SecCoreEntryPoint,
86 (UINT32)(UINTN)PeiCoreEntryPoint,
87 (UINT32)(UINTN)TopOfCurrentStack));
88
89
90 BottomOfTempRam = (UINT8*)(UINTN) INITIAL_TOP_OF_STACK;
91 SizeOfTempRam = (UINTN) SIZE_64KB;
92 TopOfTempRam = BottomOfTempRam + SizeOfTempRam;
93
94 //
95 // |-------------|
96 // | SecCoreData | 4k
97 // |-------------|
98 // | Heap | 28k
99 // |-------------|
100 // | Stack | 32k
101 // |-------------| <---- INITIAL_TOP_OF_STACK
102 //
103
104 //
105 // Bind this information into the SEC hand-off state
106 //
107 SecCoreData = (EFI_SEC_PEI_HAND_OFF*)((UINTN) TopOfTempRam - SIZE_4KB);
108 SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);
109
110 SecCoreData->BootFirmwareVolumeBase = (VOID*)(UINTN) PcdGet32 (PcdOvmfFlashFvRecoveryBase);
111 SecCoreData->BootFirmwareVolumeSize = PcdGet32 (PcdOvmfFlashFvRecoverySize);
112
113 SecCoreData->TemporaryRamBase = (VOID*) BottomOfTempRam;
114 SecCoreData->TemporaryRamSize = SizeOfTempRam;
115
116 SecCoreData->PeiTemporaryRamSize = 28 * SIZE_1KB;
117 SecCoreData->PeiTemporaryRamBase = (VOID*)((UINTN)SecCoreData - SecCoreData->PeiTemporaryRamSize);
118
119 SecCoreData->StackBase = SecCoreData->TemporaryRamBase;
120 SecCoreData->StackSize = (UINTN)SecCoreData->PeiTemporaryRamBase - (UINTN)SecCoreData->TemporaryRamBase;
121
122 //
123 // Initialize the IDT Pointer, since IA32 & X64 architectures
124 // use it to store the PEI Services pointer.
125 //
126 IdtPtr = (VOID*)((UINT8*)SecCoreData + sizeof (*SecCoreData) + sizeof (UINTN));
127 IdtPtr = ALIGN_POINTER(IdtPtr, 16);
128 InitializeIdtPtr (IdtPtr);
129
130 //
131 // Transfer control to the PEI Core
132 //
133 PeiSwitchStacks (
134 (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint,
135 SecCoreData,
136 (VOID *) (UINTN) ((EFI_PEI_PPI_DESCRIPTOR *) &mPrivateDispatchTable),
137 NULL,
138 TopOfCurrentStack,
139 (VOID *)((UINTN)SecCoreData->StackBase + SecCoreData->StackSize)
140 );
141
142 //
143 // If we get here, then the PEI Core returned. This is an error
144 //
145 ASSERT (FALSE);
146 CpuDeadLoop ();
147}
148
149EFI_STATUS
150EFIAPI
151TemporaryRamMigration (
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 DEBUG ((EFI_D_ERROR, "TemporaryRamMigration(0x%x, 0x%x, 0x%x)\n", (UINTN)TemporaryMemoryBase, (UINTN)PermanentMemoryBase, CopySize));
159
160 //
161 // Migrate the whole temporary memory to permenent memory.
162 //
163 CopyMem((VOID*)(UINTN)PermanentMemoryBase, (VOID*)(UINTN)TemporaryMemoryBase, CopySize);
164
165 //
166 // SecSwitchStack function must be invoked after the memory migration
167 // immediatly, also we need fixup the stack change caused by new call into
168 // permenent memory.
169 //
170 SecSwitchStack (
171 (UINTN) TemporaryMemoryBase,
172 (UINTN) PermanentMemoryBase,
173 CopySize
174 );
175
176 return EFI_SUCCESS;
177}
178