]>
Commit | Line | Data |
---|---|---|
3a6eaccf | 1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011, ARM Limited. All rights reserved.\r | |
4 | *\r | |
5 | * This program and the accompanying materials\r | |
6 | * are licensed and made available under the terms and conditions of the BSD License\r | |
7 | * which accompanies this distribution. The full text of the license may be found at\r | |
8 | * http://opensource.org/licenses/bsd-license.php\r | |
9 | *\r | |
10 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | *\r | |
13 | **/\r | |
14 | \r | |
15 | #include <PiPei.h>\r | |
16 | \r | |
17 | #include <Library/ArmPlatformLib.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/HobLib.h>\r | |
20 | #include <Library/MemoryAllocationLib.h>\r | |
21 | #include <Library/PcdLib.h>\r | |
22 | \r | |
3a6eaccf | 23 | VOID\r |
24 | BuildMemoryTypeInformationHob (\r | |
25 | VOID\r | |
26 | );\r | |
27 | \r | |
28 | VOID\r | |
29 | InitMmu (\r | |
30 | VOID\r | |
31 | )\r | |
32 | {\r | |
33 | ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r | |
34 | VOID *TranslationTableBase;\r | |
35 | UINTN TranslationTableSize;\r | |
36 | \r | |
37 | // Get Virtual Memory Map from the Platform Library\r | |
38 | ArmPlatformGetVirtualMemoryMap(&MemoryTable);\r | |
39 | \r | |
40 | //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r | |
41 | // DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r | |
42 | ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r | |
43 | }\r | |
44 | \r | |
45 | /*++\r | |
46 | \r | |
47 | Routine Description:\r | |
48 | \r | |
49 | \r | |
50 | \r | |
51 | Arguments:\r | |
52 | \r | |
53 | FileHandle - Handle of the file being invoked.\r | |
54 | PeiServices - Describes the list of possible PEI Services.\r | |
55 | \r | |
56 | Returns:\r | |
57 | \r | |
58 | Status - EFI_SUCCESS if the boot mode could be set\r | |
59 | \r | |
60 | --*/\r | |
61 | EFI_STATUS\r | |
62 | EFIAPI\r | |
63 | MemoryPeim (\r | |
64 | IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r | |
65 | IN UINT64 UefiMemorySize\r | |
66 | )\r | |
67 | {\r | |
d269095b | 68 | EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r |
69 | UINT64 ResourceLength;\r | |
70 | EFI_PEI_HOB_POINTERS NextHob;\r | |
71 | EFI_PHYSICAL_ADDRESS FdTop;\r | |
72 | EFI_PHYSICAL_ADDRESS SystemMemoryTop;\r | |
73 | EFI_PHYSICAL_ADDRESS ResourceTop;\r | |
74 | BOOLEAN Found;\r | |
3a6eaccf | 75 | \r |
76 | // Ensure PcdSystemMemorySize has been set\r | |
77 | ASSERT (PcdGet32 (PcdSystemMemorySize) != 0);\r | |
78 | \r | |
3a6eaccf | 79 | //\r |
80 | // Now, the permanent memory has been installed, we can call AllocatePages()\r | |
81 | //\r | |
d269095b | 82 | ResourceAttributes = (\r |
3a6eaccf | 83 | EFI_RESOURCE_ATTRIBUTE_PRESENT |\r |
84 | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r | |
85 | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r | |
86 | EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r | |
87 | EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r | |
88 | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r | |
89 | EFI_RESOURCE_ATTRIBUTE_TESTED\r | |
90 | );\r | |
91 | \r | |
d269095b | 92 | // Reserved the memory space occupied by the firmware volume\r |
3a6eaccf | 93 | BuildResourceDescriptorHob (\r |
94 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
d269095b | 95 | ResourceAttributes,\r |
3a6eaccf | 96 | PcdGet32 (PcdSystemMemoryBase),\r |
d269095b | 97 | PcdGet32 (PcdSystemMemorySize)\r |
3a6eaccf | 98 | );\r |
99 | \r | |
d269095b | 100 | SystemMemoryTop = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize);\r |
f92b93c9 | 101 | FdTop = PcdGet32(PcdFdBaseAddress) + PcdGet32(PcdFdSize);\r |
d269095b | 102 | \r |
103 | // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE\r | |
104 | // core to overwrite this area we must mark the region with the attribute non-present\r | |
f92b93c9 | 105 | if ((PcdGet32 (PcdFdBaseAddress) >= PcdGet32 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) {\r |
d269095b | 106 | Found = FALSE;\r |
107 | \r | |
108 | // Search for System Memory Hob that contains the firmware\r | |
109 | NextHob.Raw = GetHobList ();\r | |
110 | while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r | |
111 | if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&\r | |
f92b93c9 | 112 | (PcdGet32(PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) &&\r |
d269095b | 113 | (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength))\r |
114 | {\r | |
115 | ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute;\r | |
116 | ResourceLength = NextHob.ResourceDescriptor->ResourceLength;\r | |
117 | ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength;\r | |
118 | \r | |
f92b93c9 | 119 | if (PcdGet32(PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) {\r |
d269095b | 120 | if (SystemMemoryTop == FdTop) {\r |
121 | NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT;\r | |
122 | } else {\r | |
123 | // Create the System Memory HOB for the firmware with the non-present attribute\r | |
124 | BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r | |
125 | ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r | |
f92b93c9 | 126 | PcdGet32(PcdFdBaseAddress),\r |
127 | PcdGet32(PcdFdSize));\r | |
d269095b | 128 | \r |
129 | // Top of the FD is system memory available for UEFI\r | |
f92b93c9 | 130 | NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize);\r |
131 | NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize);\r | |
d269095b | 132 | }\r |
133 | } else {\r | |
134 | // Create the System Memory HOB for the firmware with the non-present attribute\r | |
135 | BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r | |
136 | ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r | |
f92b93c9 | 137 | PcdGet32(PcdFdBaseAddress),\r |
138 | PcdGet32(PcdFdSize));\r | |
d269095b | 139 | \r |
140 | // Update the HOB\r | |
f92b93c9 | 141 | NextHob.ResourceDescriptor->ResourceLength = PcdGet32(PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart;\r |
d269095b | 142 | \r |
143 | // If there is some memory available on the top of the FD then create a HOB\r | |
144 | if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) {\r | |
145 | // Create the System Memory HOB for the remaining region (top of the FD)\r | |
146 | BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r | |
147 | ResourceAttributes,\r | |
148 | FdTop,\r | |
149 | ResourceTop - FdTop);\r | |
150 | }\r | |
151 | }\r | |
152 | Found = TRUE;\r | |
153 | break;\r | |
154 | }\r | |
155 | NextHob.Raw = GET_NEXT_HOB (NextHob);\r | |
3a6eaccf | 156 | }\r |
d269095b | 157 | \r |
158 | ASSERT(Found);\r | |
3a6eaccf | 159 | }\r |
160 | \r | |
161 | // Build Memory Allocation Hob\r | |
162 | InitMmu ();\r | |
163 | \r | |
164 | if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r | |
165 | // Optional feature that helps prevent EFI memory map fragmentation.\r | |
166 | BuildMemoryTypeInformationHob ();\r | |
167 | }\r | |
168 | \r | |
169 | return EFI_SUCCESS;\r | |
170 | }\r |