]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c
ArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory
[mirror_edk2.git] / ArmVirtPkg / MemoryInitPei / MemoryInitPeim.c
1 /** @file
2
3 Copyright (c) 2011, ARM Limited. All rights reserved.
4 Copyright (c) 2022, Google LLC. All rights reserved.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiPei.h>
11 #include <Library/ArmPlatformLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/HobLib.h>
14 #include <Library/PeimEntryPoint.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Library/PcdLib.h>
17 #include <Guid/MemoryTypeInformation.h>
18
19 EFI_STATUS
20 EFIAPI
21 MemoryPeim (
22 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,
23 IN UINT64 UefiMemorySize
24 );
25
26 /**
27 Build the memory type information HOB that describes how many pages of each
28 type to preallocate when initializing the GCD memory map.
29 **/
30 VOID
31 EFIAPI
32 BuildMemoryTypeInformationHob (
33 VOID
34 )
35 {
36 EFI_MEMORY_TYPE_INFORMATION Info[10];
37
38 Info[0].Type = EfiACPIReclaimMemory;
39 Info[0].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);
40 Info[1].Type = EfiACPIMemoryNVS;
41 Info[1].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);
42 Info[2].Type = EfiReservedMemoryType;
43 Info[2].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType);
44 Info[3].Type = EfiRuntimeServicesData;
45 Info[3].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);
46 Info[4].Type = EfiRuntimeServicesCode;
47 Info[4].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);
48 Info[5].Type = EfiBootServicesCode;
49 Info[5].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiBootServicesCode);
50 Info[6].Type = EfiBootServicesData;
51 Info[6].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiBootServicesData);
52 Info[7].Type = EfiLoaderCode;
53 Info[7].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiLoaderCode);
54 Info[8].Type = EfiLoaderData;
55 Info[8].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiLoaderData);
56
57 // Terminator for the list
58 Info[9].Type = EfiMaxMemoryType;
59 Info[9].NumberOfPages = 0;
60
61 BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));
62 }
63
64 /**
65 Module entry point.
66
67 @param[in] FileHandle Handle of the file being invoked.
68 @param[in] PeiServices Describes the list of possible PEI Services.
69
70 @return EFI_SUCCESS unless the operation failed.
71 **/
72 EFI_STATUS
73 EFIAPI
74 InitializeMemory (
75 IN EFI_PEI_FILE_HANDLE FileHandle,
76 IN CONST EFI_PEI_SERVICES **PeiServices
77 )
78 {
79 UINTN UefiMemoryBase;
80 EFI_STATUS Status;
81
82 ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS);
83
84 //
85 // Put the permanent PEI memory in the first 128 MiB of DRAM so that
86 // it is covered by the statically configured ID map.
87 //
88 UefiMemoryBase = (UINTN)FixedPcdGet64 (PcdSystemMemoryBase) + SIZE_128MB
89 - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);
90
91 Status = PeiServicesInstallPeiMemory (
92 UefiMemoryBase,
93 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
94 );
95 ASSERT_EFI_ERROR (Status);
96
97 Status = MemoryPeim (
98 UefiMemoryBase,
99 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
100 );
101 ASSERT_EFI_ERROR (Status);
102
103 return Status;
104 }