]>
Commit | Line | Data |
---|---|---|
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-2014, 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 | |
16 | #include <Library/BaseLib.h>\r | |
17 | #include <Library/DebugAgentLib.h>\r | |
18 | #include <Library/ArmLib.h>\r | |
19 | \r | |
20 | #include <Ppi/ArmGlobalVariable.h>\r | |
21 | \r | |
22 | #include "PrePeiCore.h"\r | |
23 | \r | |
24 | CONST EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = { PrePeiCoreTemporaryRamSupport };\r | |
25 | CONST ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi = { PrePeiCoreGetGlobalVariableMemory };\r | |
26 | \r | |
27 | CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {\r | |
28 | {\r | |
29 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r | |
30 | &gEfiTemporaryRamSupportPpiGuid,\r | |
31 | (VOID *) &mTemporaryRamSupportPpi\r | |
32 | },\r | |
33 | {\r | |
34 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r | |
35 | &gArmGlobalVariablePpiGuid,\r | |
36 | (VOID *) &mGlobalVariablePpi\r | |
37 | }\r | |
38 | };\r | |
39 | \r | |
40 | VOID\r | |
41 | CreatePpiList (\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 = PcdGet64 (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 | |
68 | VOID\r | |
69 | CEntryPoint (\r | |
70 | IN UINTN MpId,\r | |
71 | IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint\r | |
72 | )\r | |
73 | {\r | |
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 | |
79 | ArmInvalidateInstructionCache ();\r | |
80 | // Enable Instruction Caches on all cores.\r | |
81 | ArmEnableInstructionCache ();\r | |
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 | |
88 | // Write VBAR - The Exception Vector table must be aligned to its requirement\r | |
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 | |
92 | ArmWriteVBar ((UINTN)PeiVectorTable);\r | |
93 | \r | |
94 | //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.\r | |
95 | \r | |
96 | // If not primary Jump to Secondary Main\r | |
97 | if (ArmPlatformIsPrimaryCore (MpId)) {\r | |
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 | |
102 | // Initialize the platform specific controllers\r | |
103 | ArmPlatformInitialize (MpId);\r | |
104 | \r | |
105 | // Goto primary Main.\r | |
106 | PrimaryMain (PeiCoreEntryPoint);\r | |
107 | } else {\r | |
108 | SecondaryMain (MpId);\r | |
109 | }\r | |
110 | \r | |
111 | // PEI Core should always load and never return\r | |
112 | ASSERT (FALSE);\r | |
113 | }\r | |
114 | \r | |
115 | EFI_STATUS\r | |
116 | EFIAPI\r | |
117 | PrePeiCoreTemporaryRamSupport (\r | |
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 | |
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 | |
137 | //\r | |
138 | CopyMem (NewStack, OldStack, CopySize >> 1);\r | |
139 | \r | |
140 | //\r | |
141 | // Migrate the temporary memory heap to permanent memory heap.\r | |
142 | //\r | |
143 | CopyMem (NewHeap, OldHeap, CopySize >> 1);\r | |
144 | \r | |
145 | SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);\r | |
146 | \r | |
147 | return EFI_SUCCESS;\r | |
148 | }\r | |
149 | \r | |
150 | EFI_STATUS\r | |
151 | PrePeiCoreGetGlobalVariableMemory (\r | |
152 | OUT EFI_PHYSICAL_ADDRESS *GlobalVariableBase\r | |
153 | )\r | |
154 | {\r | |
155 | ASSERT (GlobalVariableBase != NULL);\r | |
156 | \r | |
157 | *GlobalVariableBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) +\r | |
158 | (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) -\r | |
159 | (UINTN)PcdGet32 (PcdPeiGlobalVariableSize);\r | |
160 | \r | |
161 | return EFI_SUCCESS;\r | |
162 | }\r | |
163 | \r |