]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
d03214b5df669b992aecad376a2fa2e740cb5f88
[mirror_edk2.git] / ArmPlatformPkg / MemoryInitPei / MemoryInitPeiLib.c
1 /** @file
2 *
3 * Copyright (c) 2011-2015, 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/ArmMmuLib.h>
18 #include <Library/ArmPlatformLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/PcdLib.h>
23
24 VOID
25 BuildMemoryTypeInformationHob (
26 VOID
27 );
28
29 STATIC
30 VOID
31 InitMmu (
32 IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable
33 )
34 {
35
36 VOID *TranslationTableBase;
37 UINTN TranslationTableSize;
38 RETURN_STATUS Status;
39
40 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
41 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
42 Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);
43 if (EFI_ERROR (Status)) {
44 DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));
45 }
46 }
47
48 /*++
49
50 Routine Description:
51
52
53
54 Arguments:
55
56 FileHandle - Handle of the file being invoked.
57 PeiServices - Describes the list of possible PEI Services.
58
59 Returns:
60
61 Status - EFI_SUCCESS if the boot mode could be set
62
63 --*/
64 EFI_STATUS
65 EFIAPI
66 MemoryPeim (
67 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,
68 IN UINT64 UefiMemorySize
69 )
70 {
71 ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
72 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
73 EFI_PEI_HOB_POINTERS NextHob;
74 BOOLEAN Found;
75
76 // Get Virtual Memory Map from the Platform Library
77 ArmPlatformGetVirtualMemoryMap (&MemoryTable);
78
79 // Ensure PcdSystemMemorySize has been set
80 ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
81
82 //
83 // Now, the permanent memory has been installed, we can call AllocatePages()
84 //
85 ResourceAttributes = (
86 EFI_RESOURCE_ATTRIBUTE_PRESENT |
87 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
88 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
89 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
90 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
91 EFI_RESOURCE_ATTRIBUTE_TESTED
92 );
93
94 //
95 // Check if the resource for the main system memory has been declared
96 //
97 Found = FALSE;
98 NextHob.Raw = GetHobList ();
99 while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {
100 if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&
101 (PcdGet64 (PcdSystemMemoryBase) >= NextHob.ResourceDescriptor->PhysicalStart) &&
102 (NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength <= PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))
103 {
104 Found = TRUE;
105 break;
106 }
107 NextHob.Raw = GET_NEXT_HOB (NextHob);
108 }
109
110 if (!Found) {
111 // Reserved the memory space occupied by the firmware volume
112 BuildResourceDescriptorHob (
113 EFI_RESOURCE_SYSTEM_MEMORY,
114 ResourceAttributes,
115 PcdGet64 (PcdSystemMemoryBase),
116 PcdGet64 (PcdSystemMemorySize)
117 );
118 }
119
120 // Build Memory Allocation Hob
121 InitMmu (MemoryTable);
122
123 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
124 // Optional feature that helps prevent EFI memory map fragmentation.
125 BuildMemoryTypeInformationHob ();
126 }
127
128 return EFI_SUCCESS;
129 }