]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePeiCore/PrePeiCore.c
ArmPlatformPkg/ArmPlatformLib: Added support for ArmPlatformIsPrimaryCore()
[mirror_edk2.git] / ArmPlatformPkg / PrePeiCore / PrePeiCore.c
1 /** @file
2 * Main file supporting the transition to PEI Core in Normal World for Versatile Express
3 *
4 * Copyright (c) 2011-2012, ARM Limited. All rights reserved.
5 *
6 * 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 <Library/BaseLib.h>
17 #include <Library/DebugAgentLib.h>
18 #include <Library/ArmLib.h>
19
20 #include <Ppi/ArmGlobalVariable.h>
21
22 #include "PrePeiCore.h"
23
24 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = { PrePeiCoreTemporaryRamSupport };
25 ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi = { PrePeiCoreGetGlobalVariableMemory };
26
27 EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {
28 {
29 EFI_PEI_PPI_DESCRIPTOR_PPI,
30 &gEfiTemporaryRamSupportPpiGuid,
31 &mTemporaryRamSupportPpi
32 },
33 {
34 EFI_PEI_PPI_DESCRIPTOR_PPI,
35 &gArmGlobalVariablePpiGuid,
36 &mGlobalVariablePpi
37 }
38 };
39
40 VOID
41 CreatePpiList (
42 OUT UINTN *PpiListSize,
43 OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
44 )
45 {
46 EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;
47 UINTN PlatformPpiListSize;
48 UINTN ListBase;
49 EFI_PEI_PPI_DESCRIPTOR *LastPpi;
50
51 // Get the Platform PPIs
52 PlatformPpiListSize = 0;
53 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);
54
55 // Copy the Common and Platform PPis in Temporrary Memory
56 ListBase = PcdGet32 (PcdCPUCoresStackBase);
57 CopyMem ((VOID*)ListBase, gCommonPpiTable, sizeof(gCommonPpiTable));
58 CopyMem ((VOID*)(ListBase + sizeof(gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);
59
60 // Set the Terminate flag on the last PPI entry
61 LastPpi = (EFI_PEI_PPI_DESCRIPTOR*)ListBase + ((sizeof(gCommonPpiTable) + PlatformPpiListSize) / sizeof(EFI_PEI_PPI_DESCRIPTOR)) - 1;
62 LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
63
64 *PpiList = (EFI_PEI_PPI_DESCRIPTOR*)ListBase;
65 *PpiListSize = sizeof(gCommonPpiTable) + PlatformPpiListSize;
66 }
67
68 VOID
69 CEntryPoint (
70 IN UINTN MpId,
71 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
72 )
73 {
74 //Clean Data cache
75 ArmCleanInvalidateDataCache ();
76
77 //Invalidate instruction cache
78 ArmInvalidateInstructionCache ();
79
80 // Enable Instruction & Data caches
81 ArmEnableDataCache ();
82 ArmEnableInstructionCache ();
83
84 //
85 // Note: Doesn't have to Enable CPU interface in non-secure world,
86 // as Non-secure interface is already enabled in Secure world.
87 //
88
89 // Write VBAR - The Exception Vector table must be aligned to its requirement
90 ASSERT (((UINTN)PeiVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0);
91 ArmWriteVBar ((UINTN)PeiVectorTable);
92
93 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
94
95 // If not primary Jump to Secondary Main
96 if (ArmPlatformIsPrimaryCore (MpId)) {
97 // Initialize the Debug Agent for Source Level Debugging
98 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
99 SaveAndSetDebugTimerInterrupt (TRUE);
100
101 // Initialize the platform specific controllers
102 ArmPlatformInitialize (MpId);
103
104 // Goto primary Main.
105 PrimaryMain (PeiCoreEntryPoint);
106 } else {
107 SecondaryMain (MpId);
108 }
109
110 // PEI Core should always load and never return
111 ASSERT (FALSE);
112 }
113
114 EFI_STATUS
115 EFIAPI
116 PrePeiCoreTemporaryRamSupport (
117 IN CONST EFI_PEI_SERVICES **PeiServices,
118 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
119 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
120 IN UINTN CopySize
121 )
122 {
123 VOID *OldHeap;
124 VOID *NewHeap;
125 VOID *OldStack;
126 VOID *NewStack;
127
128 OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;
129 NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));
130
131 OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));
132 NewStack = (VOID*)(UINTN)PermanentMemoryBase;
133
134 //
135 // Migrate the temporary memory stack to permanent memory stack.
136 //
137 CopyMem (NewStack, OldStack, CopySize >> 1);
138
139 //
140 // Migrate the temporary memory heap to permanent memory heap.
141 //
142 CopyMem (NewHeap, OldHeap, CopySize >> 1);
143
144 SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);
145
146 return EFI_SUCCESS;
147 }
148
149 EFI_STATUS
150 PrePeiCoreGetGlobalVariableMemory (
151 OUT EFI_PHYSICAL_ADDRESS *GlobalVariableBase
152 )
153 {
154 ASSERT (GlobalVariableBase != NULL);
155
156 *GlobalVariableBase = (UINTN)PcdGet32 (PcdCPUCoresStackBase) +
157 (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) -
158 (UINTN)PcdGet32 (PcdPeiGlobalVariableSize);
159
160 return EFI_SUCCESS;
161 }
162