]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/PrePi/PrePi.c
f6abe2f2016bd654726f36d0b4a1ae9c22b89f5e
[mirror_edk2.git] / ArmVirtPkg / PrePi / PrePi.c
1 /** @file
2 *
3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
4 *
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
9 *
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 *
13 **/
14
15 #include <PiPei.h>
16 #include <Pi/PiBootMode.h>
17
18 #include <Library/PrePiLib.h>
19 #include <Library/PrintLib.h>
20 #include <Library/PrePiHobListPointerLib.h>
21 #include <Library/TimerLib.h>
22 #include <Library/PerformanceLib.h>
23 #include <Library/CacheMaintenanceLib.h>
24
25 #include <Ppi/GuidedSectionExtraction.h>
26 #include <Ppi/ArmMpCoreInfo.h>
27
28 #include "PrePi.h"
29
30 VOID
31 EFIAPI
32 ProcessLibraryConstructorList (
33 VOID
34 );
35
36 VOID
37 PrePiMain (
38 IN UINTN UefiMemoryBase,
39 IN UINTN StacksBase,
40 IN UINT64 StartTimeStamp
41 )
42 {
43 EFI_HOB_HANDOFF_INFO_TABLE* HobList;
44 EFI_STATUS Status;
45 CHAR8 Buffer[100];
46 UINTN CharCount;
47 UINTN StacksSize;
48
49 // Initialize the architecture specific bits
50 ArchInitialize ();
51
52 // Declare the PI/UEFI memory region
53 HobList = HobConstructor (
54 (VOID*)UefiMemoryBase,
55 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
56 (VOID*)UefiMemoryBase,
57 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks
58 );
59 PrePeiSetHobList (HobList);
60
61 //
62 // Ensure that the loaded image is invalidated in the caches, so that any
63 // modifications we made with the caches and MMU off (such as the applied
64 // relocations) don't become invisible once we turn them on.
65 //
66 InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));
67
68 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
69 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
70 ASSERT_EFI_ERROR (Status);
71
72 // Initialize the Serial Port
73 SerialPortInitialize ();
74 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",
75 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
76 SerialPortWrite ((UINT8 *) Buffer, CharCount);
77
78 // Create the Stacks HOB (reserve the memory for all stacks)
79 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
80 BuildStackHob (StacksBase, StacksSize);
81
82 //TODO: Call CpuPei as a library
83 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
84
85 // Set the Boot Mode
86 SetBootMode (BOOT_WITH_FULL_CONFIGURATION);
87
88 // Initialize Platform HOBs (CpuHob and FvHob)
89 Status = PlatformPeim ();
90 ASSERT_EFI_ERROR (Status);
91
92 // Now, the HOB List has been initialized, we can register performance information
93 PERF_START (NULL, "PEI", NULL, StartTimeStamp);
94
95 // SEC phase needs to run library constructors by hand.
96 ProcessLibraryConstructorList ();
97
98 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
99 Status = DecompressFirstFv ();
100 ASSERT_EFI_ERROR (Status);
101
102 // Load the DXE Core and transfer control to it
103 Status = LoadDxeCoreFromFv (NULL, 0);
104 ASSERT_EFI_ERROR (Status);
105 }
106
107 VOID
108 CEntryPoint (
109 IN UINTN MpId,
110 IN UINTN UefiMemoryBase,
111 IN UINTN StacksBase
112 )
113 {
114 UINT64 StartTimeStamp;
115
116 if (PerformanceMeasurementEnabled ()) {
117 // Initialize the Timer Library to setup the Timer HW controller
118 TimerConstructor ();
119 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
120 StartTimeStamp = GetPerformanceCounter ();
121 } else {
122 StartTimeStamp = 0;
123 }
124
125 // Data Cache enabled on Primary core when MMU is enabled.
126 ArmDisableDataCache ();
127 // Invalidate instruction cache
128 ArmInvalidateInstructionCache ();
129 // Enable Instruction Caches on all cores.
130 ArmEnableInstructionCache ();
131
132 PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);
133
134 // DXE Core should always load and never return
135 ASSERT (FALSE);
136 }