Ard Biesheuvel | f9a9d2d | 2015-02-28 20:26:20 +0000 | [diff] [blame] | 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 |
|
| 17 | #include <Library/PrePiLib.h>
|
| 18 | #include <Library/PrintLib.h>
|
| 19 | #include <Library/PeCoffGetEntryPointLib.h>
|
| 20 | #include <Library/PrePiHobListPointerLib.h>
|
| 21 | #include <Library/TimerLib.h>
|
| 22 | #include <Library/PerformanceLib.h>
|
Ard Biesheuvel | c9e5618 | 2015-04-14 11:56:56 +0000 | [diff] [blame] | 23 | #include <Library/CacheMaintenanceLib.h>
|
Ard Biesheuvel | f9a9d2d | 2015-02-28 20:26:20 +0000 | [diff] [blame] | 24 |
|
| 25 | #include <Ppi/GuidedSectionExtraction.h>
|
| 26 | #include <Ppi/ArmMpCoreInfo.h>
|
| 27 | #include <Guid/LzmaDecompress.h>
|
| 28 | #include <Guid/ArmGlobalVariableHob.h>
|
| 29 |
|
| 30 | #include "PrePi.h"
|
| 31 | #include "LzmaDecompress.h"
|
| 32 |
|
| 33 | // Not used when PrePi in run in XIP mode
|
| 34 | UINTN mGlobalVariableBase = 0;
|
| 35 |
|
| 36 | EFI_STATUS
|
| 37 | EFIAPI
|
| 38 | ExtractGuidedSectionLibConstructor (
|
| 39 | VOID
|
| 40 | );
|
| 41 |
|
| 42 | EFI_STATUS
|
| 43 | EFIAPI
|
| 44 | LzmaDecompressLibConstructor (
|
| 45 | VOID
|
| 46 | );
|
| 47 |
|
| 48 | VOID
|
| 49 | EFIAPI
|
| 50 | BuildGlobalVariableHob (
|
| 51 | IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,
|
| 52 | IN UINT32 GlobalVariableSize
|
| 53 | )
|
| 54 | {
|
| 55 | ARM_HOB_GLOBAL_VARIABLE *Hob;
|
| 56 |
|
| 57 | Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));
|
| 58 | ASSERT(Hob != NULL);
|
| 59 |
|
| 60 | CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);
|
| 61 | Hob->GlobalVariableBase = GlobalVariableBase;
|
| 62 | Hob->GlobalVariableSize = GlobalVariableSize;
|
| 63 | }
|
| 64 |
|
| 65 | EFI_STATUS
|
| 66 | GetPlatformPpi (
|
| 67 | IN EFI_GUID *PpiGuid,
|
| 68 | OUT VOID **Ppi
|
| 69 | )
|
| 70 | {
|
| 71 | UINTN PpiListSize;
|
| 72 | UINTN PpiListCount;
|
| 73 | EFI_PEI_PPI_DESCRIPTOR *PpiList;
|
| 74 | UINTN Index;
|
| 75 |
|
| 76 | PpiListSize = 0;
|
| 77 | ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);
|
| 78 | PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);
|
| 79 | for (Index = 0; Index < PpiListCount; Index++, PpiList++) {
|
| 80 | if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {
|
| 81 | *Ppi = PpiList->Ppi;
|
| 82 | return EFI_SUCCESS;
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | return EFI_NOT_FOUND;
|
| 87 | }
|
| 88 |
|
| 89 | VOID
|
| 90 | PrePiMain (
|
| 91 | IN UINTN UefiMemoryBase,
|
| 92 | IN UINTN StacksBase,
|
| 93 | IN UINTN GlobalVariableBase,
|
| 94 | IN UINT64 StartTimeStamp
|
| 95 | )
|
| 96 | {
|
| 97 | EFI_HOB_HANDOFF_INFO_TABLE* HobList;
|
| 98 | EFI_STATUS Status;
|
| 99 | CHAR8 Buffer[100];
|
| 100 | UINTN CharCount;
|
| 101 | UINTN StacksSize;
|
| 102 |
|
| 103 | // Initialize the architecture specific bits
|
| 104 | ArchInitialize ();
|
| 105 |
|
Ard Biesheuvel | f9a9d2d | 2015-02-28 20:26:20 +0000 | [diff] [blame] | 106 | // Declare the PI/UEFI memory region
|
| 107 | HobList = HobConstructor (
|
| 108 | (VOID*)UefiMemoryBase,
|
| 109 | FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
|
| 110 | (VOID*)UefiMemoryBase,
|
| 111 | (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks
|
| 112 | );
|
| 113 | PrePeiSetHobList (HobList);
|
| 114 |
|
Ard Biesheuvel | c9e5618 | 2015-04-14 11:56:56 +0000 | [diff] [blame] | 115 | //
|
| 116 | // Ensure that the loaded image is invalidated in the caches, so that any
|
| 117 | // modifications we made with the caches and MMU off (such as the applied
|
| 118 | // relocations) don't become invisible once we turn them on.
|
| 119 | //
|
| 120 | InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));
|
| 121 |
|
Ard Biesheuvel | f9a9d2d | 2015-02-28 20:26:20 +0000 | [diff] [blame] | 122 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
|
| 123 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
|
| 124 | ASSERT_EFI_ERROR (Status);
|
| 125 |
|
Ard Biesheuvel | c9e5618 | 2015-04-14 11:56:56 +0000 | [diff] [blame] | 126 | // Initialize the Serial Port
|
| 127 | SerialPortInitialize ();
|
| 128 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",
|
| 129 | (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
|
| 130 | SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
| 131 |
|
Ard Biesheuvel | f9a9d2d | 2015-02-28 20:26:20 +0000 | [diff] [blame] | 132 | // Create the Stacks HOB (reserve the memory for all stacks)
|
| 133 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
|
| 134 | BuildStackHob (StacksBase, StacksSize);
|
| 135 |
|
| 136 | // Declare the Global Variable HOB
|
| 137 | BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));
|
| 138 |
|
| 139 | //TODO: Call CpuPei as a library
|
| 140 | BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
|
| 141 |
|
| 142 | // Set the Boot Mode
|
| 143 | SetBootMode (ArmPlatformGetBootMode ());
|
| 144 |
|
| 145 | // Initialize Platform HOBs (CpuHob and FvHob)
|
| 146 | Status = PlatformPeim ();
|
| 147 | ASSERT_EFI_ERROR (Status);
|
| 148 |
|
| 149 | // Now, the HOB List has been initialized, we can register performance information
|
| 150 | PERF_START (NULL, "PEI", NULL, StartTimeStamp);
|
| 151 |
|
| 152 | // SEC phase needs to run library constructors by hand.
|
| 153 | ExtractGuidedSectionLibConstructor ();
|
| 154 | LzmaDecompressLibConstructor ();
|
| 155 |
|
| 156 | // Build HOBs to pass up our version of stuff the DXE Core needs to save space
|
| 157 | BuildPeCoffLoaderHob ();
|
| 158 | BuildExtractSectionHob (
|
| 159 | &gLzmaCustomDecompressGuid,
|
| 160 | LzmaGuidedSectionGetInfo,
|
| 161 | LzmaGuidedSectionExtraction
|
| 162 | );
|
| 163 |
|
| 164 | // Assume the FV that contains the SEC (our code) also contains a compressed FV.
|
| 165 | Status = DecompressFirstFv ();
|
| 166 | ASSERT_EFI_ERROR (Status);
|
| 167 |
|
| 168 | // Load the DXE Core and transfer control to it
|
| 169 | Status = LoadDxeCoreFromFv (NULL, 0);
|
| 170 | ASSERT_EFI_ERROR (Status);
|
| 171 | }
|
| 172 |
|
| 173 | VOID
|
| 174 | CEntryPoint (
|
| 175 | IN UINTN MpId,
|
| 176 | IN UINTN UefiMemoryBase,
|
| 177 | IN UINTN StacksBase,
|
| 178 | IN UINTN GlobalVariableBase
|
| 179 | )
|
| 180 | {
|
| 181 | UINT64 StartTimeStamp;
|
| 182 |
|
| 183 | // Initialize the platform specific controllers
|
| 184 | ArmPlatformInitialize (MpId);
|
| 185 |
|
| 186 | if (PerformanceMeasurementEnabled ()) {
|
| 187 | // Initialize the Timer Library to setup the Timer HW controller
|
| 188 | TimerConstructor ();
|
| 189 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized
|
| 190 | StartTimeStamp = GetPerformanceCounter ();
|
| 191 | } else {
|
| 192 | StartTimeStamp = 0;
|
| 193 | }
|
| 194 |
|
| 195 | // Data Cache enabled on Primary core when MMU is enabled.
|
| 196 | ArmDisableDataCache ();
|
| 197 | // Invalidate Data cache
|
| 198 | ArmInvalidateDataCache ();
|
| 199 | // Invalidate instruction cache
|
| 200 | ArmInvalidateInstructionCache ();
|
| 201 | // Enable Instruction Caches on all cores.
|
| 202 | ArmEnableInstructionCache ();
|
| 203 |
|
| 204 | // Define the Global Variable region
|
| 205 | mGlobalVariableBase = GlobalVariableBase;
|
| 206 |
|
| 207 | PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);
|
| 208 |
|
| 209 | // DXE Core should always load and never return
|
| 210 | ASSERT (FALSE);
|
| 211 | }
|