]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePeiCore/PrePeiCore.c
ARM Packages: Removed trailing spaces
[mirror_edk2.git] / ArmPlatformPkg / PrePeiCore / PrePeiCore.c
CommitLineData
1d5d0ae9 1/** @file\r
2* Main file supporting the transition to PEI Core in Normal World for Versatile Express\r
3*\r
6d0ca257 4* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
1d5d0ae9 5*\r
6dafb303
OM
6* This program and the accompanying materials\r
7* are licensed and made available under the terms and conditions of the BSD License\r
8* which accompanies this distribution. The full text of the license may be found at\r
9* http://opensource.org/licenses/bsd-license.php\r
10*\r
11* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
1d5d0ae9 13*\r
14**/\r
15\r
1d5d0ae9 16#include <Library/BaseLib.h>\r
a6caee65 17#include <Library/DebugAgentLib.h>\r
1d5d0ae9 18#include <Library/ArmLib.h>\r
8fc38a3f 19\r
20#include <Ppi/ArmGlobalVariable.h>\r
1d5d0ae9 21\r
f598bf12 22#include "PrePeiCore.h"\r
1d5d0ae9 23\r
93d451c6 24EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = { PrePeiCoreTemporaryRamSupport };\r
8fc38a3f 25ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi = { PrePeiCoreGetGlobalVariableMemory };\r
1d5d0ae9 26\r
8fc38a3f 27EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {\r
1d5d0ae9 28 {\r
8fc38a3f 29 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
1d5d0ae9 30 &gEfiTemporaryRamSupportPpiGuid,\r
93d451c6 31 &mTemporaryRamSupportPpi\r
8fc38a3f 32 },\r
33 {\r
77de7e53 34 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
8fc38a3f 35 &gArmGlobalVariablePpiGuid,\r
36 &mGlobalVariablePpi\r
1d5d0ae9 37 }\r
38};\r
39\r
77de7e53 40VOID\r
41CreatePpiList (\r
42 OUT UINTN *PpiListSize,\r
43 OUT EFI_PEI_PPI_DESCRIPTOR **PpiList\r
44 )\r
45{\r
46 EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;\r
47 UINTN PlatformPpiListSize;\r
48 UINTN ListBase;\r
49 EFI_PEI_PPI_DESCRIPTOR *LastPpi;\r
50\r
51 // Get the Platform PPIs\r
52 PlatformPpiListSize = 0;\r
53 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);\r
54\r
55 // Copy the Common and Platform PPis in Temporrary Memory\r
56 ListBase = PcdGet32 (PcdCPUCoresStackBase);\r
57 CopyMem ((VOID*)ListBase, gCommonPpiTable, sizeof(gCommonPpiTable));\r
58 CopyMem ((VOID*)(ListBase + sizeof(gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);\r
59\r
60 // Set the Terminate flag on the last PPI entry\r
61 LastPpi = (EFI_PEI_PPI_DESCRIPTOR*)ListBase + ((sizeof(gCommonPpiTable) + PlatformPpiListSize) / sizeof(EFI_PEI_PPI_DESCRIPTOR)) - 1;\r
62 LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
63\r
64 *PpiList = (EFI_PEI_PPI_DESCRIPTOR*)ListBase;\r
65 *PpiListSize = sizeof(gCommonPpiTable) + PlatformPpiListSize;\r
66}\r
67\r
1d5d0ae9 68VOID\r
69CEntryPoint (\r
0787bc61 70 IN UINTN MpId,\r
1d5d0ae9 71 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint\r
72 )\r
73{\r
6dafb303
OM
74 // Data Cache enabled on Primary core when MMU is enabled.\r
75 ArmDisableDataCache ();\r
76 // Invalidate Data cache\r
77 ArmInvalidateDataCache ();\r
78 // Invalidate instruction cache\r
a9d7090f 79 ArmInvalidateInstructionCache ();\r
6dafb303 80 // Enable Instruction Caches on all cores.\r
f598bf12 81 ArmEnableInstructionCache ();\r
1d5d0ae9 82\r
83 //\r
84 // Note: Doesn't have to Enable CPU interface in non-secure world,\r
85 // as Non-secure interface is already enabled in Secure world.\r
86 //\r
87\r
a9d7090f 88 // Write VBAR - The Exception Vector table must be aligned to its requirement\r
6d0ca257
OM
89 // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure\r
90 // 'Align=4K' is defined into your FDF for this module.\r
91 ASSERT (((UINTN)PeiVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0);\r
a9d7090f 92 ArmWriteVBar ((UINTN)PeiVectorTable);\r
1d5d0ae9 93\r
94 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.\r
95\r
77de7e53 96 // If not primary Jump to Secondary Main\r
bebda7ce 97 if (ArmPlatformIsPrimaryCore (MpId)) {\r
a6caee65 98 // Initialize the Debug Agent for Source Level Debugging\r
99 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
100 SaveAndSetDebugTimerInterrupt (TRUE);\r
101\r
f437141a 102 // Initialize the platform specific controllers\r
103 ArmPlatformInitialize (MpId);\r
104\r
a6caee65 105 // Goto primary Main.\r
f598bf12 106 PrimaryMain (PeiCoreEntryPoint);\r
1d5d0ae9 107 } else {\r
0787bc61 108 SecondaryMain (MpId);\r
1d5d0ae9 109 }\r
110\r
111 // PEI Core should always load and never return\r
112 ASSERT (FALSE);\r
113}\r
114\r
115EFI_STATUS\r
116EFIAPI\r
93d451c6 117PrePeiCoreTemporaryRamSupport (\r
1d5d0ae9 118 IN CONST EFI_PEI_SERVICES **PeiServices,\r
119 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
120 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
121 IN UINTN CopySize\r
122 )\r
123{\r
93d451c6 124 VOID *OldHeap;\r
125 VOID *NewHeap;\r
126 VOID *OldStack;\r
127 VOID *NewStack;\r
128\r
129 OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;\r
130 NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));\r
131\r
132 OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));\r
133 NewStack = (VOID*)(UINTN)PermanentMemoryBase;\r
134\r
135 //\r
136 // Migrate the temporary memory stack to permanent memory stack.\r
1d5d0ae9 137 //\r
93d451c6 138 CopyMem (NewStack, OldStack, CopySize >> 1);\r
139\r
140 //\r
141 // Migrate the temporary memory heap to permanent memory heap.\r
f598bf12 142 //\r
93d451c6 143 CopyMem (NewHeap, OldHeap, CopySize >> 1);\r
3402aac7 144\r
93d451c6 145 SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);\r
1d5d0ae9 146\r
93d451c6 147 return EFI_SUCCESS;\r
148}\r
1d5d0ae9 149\r
8fc38a3f 150EFI_STATUS\r
151PrePeiCoreGetGlobalVariableMemory (\r
152 OUT EFI_PHYSICAL_ADDRESS *GlobalVariableBase\r
153 )\r
154{\r
155 ASSERT (GlobalVariableBase != NULL);\r
156\r
157 *GlobalVariableBase = (UINTN)PcdGet32 (PcdCPUCoresStackBase) +\r
158 (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) -\r
159 (UINTN)PcdGet32 (PcdPeiGlobalVariableSize);\r
160\r
1d5d0ae9 161 return EFI_SUCCESS;\r
162}\r
163\r