]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePeiCore/PrePeiCore.c
ArmPlatformPkg: Renamed and Invoked earlier ArmPlatformNormalInitialize()
[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
4* Copyright (c) 2011, ARM Limited. All rights reserved.\r
5* \r
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
13*\r
14**/\r
15\r
1d5d0ae9 16#include <Library/BaseLib.h>\r
a6caee65 17#include <Library/DebugAgentLib.h>\r
f598bf12 18#include <Library/PrintLib.h>\r
1d5d0ae9 19#include <Library/ArmLib.h>\r
f598bf12 20#include <Library/SerialPortLib.h>\r
8fc38a3f 21\r
22#include <Ppi/ArmGlobalVariable.h>\r
1d5d0ae9 23\r
f598bf12 24#include "PrePeiCore.h"\r
1d5d0ae9 25\r
93d451c6 26EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = { PrePeiCoreTemporaryRamSupport };\r
8fc38a3f 27ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi = { PrePeiCoreGetGlobalVariableMemory };\r
1d5d0ae9 28\r
8fc38a3f 29EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {\r
1d5d0ae9 30 {\r
8fc38a3f 31 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
1d5d0ae9 32 &gEfiTemporaryRamSupportPpiGuid,\r
93d451c6 33 &mTemporaryRamSupportPpi\r
8fc38a3f 34 },\r
35 {\r
77de7e53 36 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
8fc38a3f 37 &gArmGlobalVariablePpiGuid,\r
38 &mGlobalVariablePpi\r
1d5d0ae9 39 }\r
40};\r
41\r
77de7e53 42VOID\r
43CreatePpiList (\r
44 OUT UINTN *PpiListSize,\r
45 OUT EFI_PEI_PPI_DESCRIPTOR **PpiList\r
46 )\r
47{\r
48 EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;\r
49 UINTN PlatformPpiListSize;\r
50 UINTN ListBase;\r
51 EFI_PEI_PPI_DESCRIPTOR *LastPpi;\r
52\r
53 // Get the Platform PPIs\r
54 PlatformPpiListSize = 0;\r
55 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);\r
56\r
57 // Copy the Common and Platform PPis in Temporrary Memory\r
58 ListBase = PcdGet32 (PcdCPUCoresStackBase);\r
59 CopyMem ((VOID*)ListBase, gCommonPpiTable, sizeof(gCommonPpiTable));\r
60 CopyMem ((VOID*)(ListBase + sizeof(gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);\r
61\r
62 // Set the Terminate flag on the last PPI entry\r
63 LastPpi = (EFI_PEI_PPI_DESCRIPTOR*)ListBase + ((sizeof(gCommonPpiTable) + PlatformPpiListSize) / sizeof(EFI_PEI_PPI_DESCRIPTOR)) - 1;\r
64 LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
65\r
66 *PpiList = (EFI_PEI_PPI_DESCRIPTOR*)ListBase;\r
67 *PpiListSize = sizeof(gCommonPpiTable) + PlatformPpiListSize;\r
68}\r
69\r
1d5d0ae9 70VOID\r
71CEntryPoint (\r
0787bc61 72 IN UINTN MpId,\r
1d5d0ae9 73 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint\r
74 )\r
75{\r
76 //Clean Data cache\r
77 ArmCleanInvalidateDataCache();\r
78\r
79 //Invalidate instruction cache\r
80 ArmInvalidateInstructionCache();\r
81\r
82 // Enable Instruction & Data caches\r
f598bf12 83 ArmEnableDataCache ();\r
84 ArmEnableInstructionCache ();\r
1d5d0ae9 85\r
86 //\r
87 // Note: Doesn't have to Enable CPU interface in non-secure world,\r
88 // as Non-secure interface is already enabled in Secure world.\r
89 //\r
90\r
91 // Write VBAR - The Vector table must be 32-byte aligned\r
92 ASSERT(((UINT32)PeiVectorTable & ((1 << 5)-1)) == 0);\r
93 ArmWriteVBar((UINT32)PeiVectorTable);\r
94\r
95 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.\r
96\r
77de7e53 97 // If not primary Jump to Secondary Main\r
0787bc61 98 if (IS_PRIMARY_CORE(MpId)) {\r
a6caee65 99 // Initialize the Debug Agent for Source Level Debugging\r
100 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
101 SaveAndSetDebugTimerInterrupt (TRUE);\r
102\r
f437141a 103 // Initialize the platform specific controllers\r
104 ArmPlatformInitialize (MpId);\r
105\r
a6caee65 106 // Goto primary Main.\r
f598bf12 107 PrimaryMain (PeiCoreEntryPoint);\r
1d5d0ae9 108 } else {\r
0787bc61 109 SecondaryMain (MpId);\r
1d5d0ae9 110 }\r
111\r
112 // PEI Core should always load and never return\r
113 ASSERT (FALSE);\r
114}\r
115\r
116EFI_STATUS\r
117EFIAPI\r
93d451c6 118PrePeiCoreTemporaryRamSupport (\r
1d5d0ae9 119 IN CONST EFI_PEI_SERVICES **PeiServices,\r
120 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
121 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
122 IN UINTN CopySize\r
123 )\r
124{\r
93d451c6 125 VOID *OldHeap;\r
126 VOID *NewHeap;\r
127 VOID *OldStack;\r
128 VOID *NewStack;\r
129\r
130 OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;\r
131 NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));\r
132\r
133 OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));\r
134 NewStack = (VOID*)(UINTN)PermanentMemoryBase;\r
135\r
136 //\r
137 // Migrate the temporary memory stack to permanent memory stack.\r
1d5d0ae9 138 //\r
93d451c6 139 CopyMem (NewStack, OldStack, CopySize >> 1);\r
140\r
141 //\r
142 // Migrate the temporary memory heap to permanent memory heap.\r
f598bf12 143 //\r
93d451c6 144 CopyMem (NewHeap, OldHeap, CopySize >> 1);\r
145 \r
146 SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);\r
1d5d0ae9 147\r
93d451c6 148 return EFI_SUCCESS;\r
149}\r
1d5d0ae9 150\r
8fc38a3f 151EFI_STATUS\r
152PrePeiCoreGetGlobalVariableMemory (\r
153 OUT EFI_PHYSICAL_ADDRESS *GlobalVariableBase\r
154 )\r
155{\r
156 ASSERT (GlobalVariableBase != NULL);\r
157\r
158 *GlobalVariableBase = (UINTN)PcdGet32 (PcdCPUCoresStackBase) +\r
159 (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) -\r
160 (UINTN)PcdGet32 (PcdPeiGlobalVariableSize);\r
161\r
1d5d0ae9 162 return EFI_SUCCESS;\r
163}\r
164\r
2637d1ef 165VOID\r
166PeiCommonExceptionEntry (\r
167 IN UINT32 Entry,\r
168 IN UINT32 LR\r
169 )\r
170{\r
171 CHAR8 Buffer[100];\r
172 UINTN CharCount;\r
173\r
1d5d0ae9 174 switch (Entry) {\r
175 case 0:\r
2637d1ef 176 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
1d5d0ae9 177 break;\r
178 case 1:\r
2637d1ef 179 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
1d5d0ae9 180 break;\r
181 case 2:\r
2637d1ef 182 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
1d5d0ae9 183 break;\r
184 case 3:\r
2637d1ef 185 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
1d5d0ae9 186 break;\r
187 case 4:\r
2637d1ef 188 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
1d5d0ae9 189 break;\r
190 case 5:\r
2637d1ef 191 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
1d5d0ae9 192 break;\r
193 case 6:\r
2637d1ef 194 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
1d5d0ae9 195 break;\r
196 case 7:\r
2637d1ef 197 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
1d5d0ae9 198 break;\r
199 default:\r
2637d1ef 200 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
1d5d0ae9 201 break;\r
202 }\r
2637d1ef 203 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
1d5d0ae9 204 while(1);\r
205}\r