2 * Main file supporting the transition to PEI Core in Normal World for Versatile Express
4 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
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
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.
16 #include <Library/BaseLib.h>
17 #include <Library/DebugAgentLib.h>
18 #include <Library/ArmLib.h>
20 #include "PrePeiCore.h"
22 CONST EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi
= { PrePeiCoreTemporaryRamSupport
};
24 CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable
[] = {
26 EFI_PEI_PPI_DESCRIPTOR_PPI
,
27 &gEfiTemporaryRamSupportPpiGuid
,
28 (VOID
*) &mTemporaryRamSupportPpi
34 OUT UINTN
*PpiListSize
,
35 OUT EFI_PEI_PPI_DESCRIPTOR
**PpiList
38 EFI_PEI_PPI_DESCRIPTOR
*PlatformPpiList
;
39 UINTN PlatformPpiListSize
;
41 EFI_PEI_PPI_DESCRIPTOR
*LastPpi
;
43 // Get the Platform PPIs
44 PlatformPpiListSize
= 0;
45 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize
, &PlatformPpiList
);
47 // Copy the Common and Platform PPis in Temporrary Memory
48 ListBase
= PcdGet64 (PcdCPUCoresStackBase
);
49 CopyMem ((VOID
*)ListBase
, gCommonPpiTable
, sizeof(gCommonPpiTable
));
50 CopyMem ((VOID
*)(ListBase
+ sizeof(gCommonPpiTable
)), PlatformPpiList
, PlatformPpiListSize
);
52 // Set the Terminate flag on the last PPI entry
53 LastPpi
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
+ ((sizeof(gCommonPpiTable
) + PlatformPpiListSize
) / sizeof(EFI_PEI_PPI_DESCRIPTOR
)) - 1;
54 LastPpi
->Flags
|= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
56 *PpiList
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
;
57 *PpiListSize
= sizeof(gCommonPpiTable
) + PlatformPpiListSize
;
63 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
66 // Data Cache enabled on Primary core when MMU is enabled.
67 ArmDisableDataCache ();
68 // Invalidate Data cache
69 ArmInvalidateDataCache ();
70 // Invalidate instruction cache
71 ArmInvalidateInstructionCache ();
72 // Enable Instruction Caches on all cores.
73 ArmEnableInstructionCache ();
76 // Note: Doesn't have to Enable CPU interface in non-secure world,
77 // as Non-secure interface is already enabled in Secure world.
80 // Write VBAR - The Exception Vector table must be aligned to its requirement
81 // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure
82 // 'Align=4K' is defined into your FDF for this module.
83 ASSERT (((UINTN
)PeiVectorTable
& ARM_VECTOR_TABLE_ALIGNMENT
) == 0);
84 ArmWriteVBar ((UINTN
)PeiVectorTable
);
86 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
88 // If not primary Jump to Secondary Main
89 if (ArmPlatformIsPrimaryCore (MpId
)) {
90 // Initialize the Debug Agent for Source Level Debugging
91 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
92 SaveAndSetDebugTimerInterrupt (TRUE
);
94 // Initialize the platform specific controllers
95 ArmPlatformInitialize (MpId
);
98 PrimaryMain (PeiCoreEntryPoint
);
100 SecondaryMain (MpId
);
103 // PEI Core should always load and never return
109 PrePeiCoreTemporaryRamSupport (
110 IN CONST EFI_PEI_SERVICES
**PeiServices
,
111 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
112 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
122 HeapSize
= ALIGN_VALUE (CopySize
/ 2, CPU_STACK_ALIGNMENT
);
124 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
125 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ (CopySize
- HeapSize
));
127 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ HeapSize
);
128 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
131 // Migrate the temporary memory stack to permanent memory stack.
133 CopyMem (NewStack
, OldStack
, CopySize
- HeapSize
);
136 // Migrate the temporary memory heap to permanent memory heap.
138 CopyMem (NewHeap
, OldHeap
, HeapSize
);
140 SecSwitchStack ((UINTN
)NewStack
- (UINTN
)OldStack
);