42 UINT64 FirMemNodeBase, FirMemNodeSize;
43 UINT64 CurBase, MemBase;
47 CONST UINT64 *RegProp;
48 RETURN_STATUS PcdStatus;
51 ZeroMem (CloudHvMemNode,
sizeof (CloudHvMemNode));
57 ResourceAttributes = (
58 EFI_RESOURCE_ATTRIBUTE_PRESENT |
59 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
60 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
61 EFI_RESOURCE_ATTRIBUTE_TESTED
63 DeviceTreeBase = (VOID *)(
UINTN)
PcdGet64 (PcdDeviceTreeInitialBaseAddress);
64 if (DeviceTreeBase ==
NULL) {
71 if (fdt_check_header (DeviceTreeBase) != 0) {
78 for (Prev = 0; ; Prev = Node) {
79 Node = fdt_next_node (DeviceTreeBase, Prev,
NULL);
87 Type = fdt_getprop (DeviceTreeBase, Node,
"device_type", &Len);
88 if ((Type != 0) && (
AsciiStrnCmp (Type,
"memory", Len) == 0)) {
93 RegProp = fdt_getprop (DeviceTreeBase, Node,
"reg", &Len);
94 if ((RegProp != 0) && (Len == (2 *
sizeof (UINT64)))) {
100 "%a: System RAM @ 0x%lx - 0x%lx\n",
103 CurBase + CurSize - 1
107 if (CurBase != MemBase) {
109 EFI_RESOURCE_SYSTEM_MEMORY,
115 FirMemNodeBase = CurBase;
116 FirMemNodeSize = CurSize;
119 CloudHvMemNode[Index].Base = CurBase;
120 CloudHvMemNode[Index].Size = CurSize;
123 if (Index >= CLOUDHV_MAX_MEM_NODE_NUM) {
126 "%a: memory node larger than %d will not be included into Memory System\n",
128 CLOUDHV_MAX_MEM_NODE_NUM
135 "%a: Failed to parse FDT memory node\n",
146 return EFI_NOT_FOUND;
149 PcdStatus =
PcdSet64S (PcdSystemMemorySize, FirMemNodeSize);
152 (((UINT64)
PcdGet64 (PcdFdBaseAddress) +
153 (UINT64)
PcdGet32 (PcdFdSize)) <= FirMemNodeBase) ||
154 ((UINT64)
PcdGet64 (PcdFdBaseAddress) >= (FirMemNodeBase + FirMemNodeSize))
179 UINT8 Index, MemNodeIndex;
181 ASSERT (VirtualMemoryMap !=
NULL);
185 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
188 if (VirtualMemoryTable ==
NULL) {
189 DEBUG ((DEBUG_ERROR,
"%a: Error: Failed AllocatePool()\n", __func__));
196 while ((MemNodeIndex < CLOUDHV_MAX_MEM_NODE_NUM) && (CloudHvMemNode[MemNodeIndex].Size != 0)) {
197 VirtualMemoryTable[Index].PhysicalBase = CloudHvMemNode[MemNodeIndex].Base;
198 VirtualMemoryTable[Index].VirtualBase = CloudHvMemNode[MemNodeIndex].Base;
199 VirtualMemoryTable[Index].Length = CloudHvMemNode[MemNodeIndex].Size;
200 VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
204 "%a: Dumping System DRAM Memory Node%d Map:\n"
205 "\tPhysicalBase: 0x%lX\n"
206 "\tVirtualBase: 0x%lX\n"
210 VirtualMemoryTable[Index].PhysicalBase,
211 VirtualMemoryTable[Index].VirtualBase,
212 VirtualMemoryTable[Index].Length
219 VirtualMemoryTable[Index].PhysicalBase = MACH_VIRT_PERIPH_BASE;
220 VirtualMemoryTable[Index].VirtualBase = MACH_VIRT_PERIPH_BASE;
221 VirtualMemoryTable[Index].Length = MACH_VIRT_PERIPH_SIZE;
222 VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
226 VirtualMemoryTable[Index].PhysicalBase =
PcdGet64 (PcdFvBaseAddress);
227 VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase;
228 VirtualMemoryTable[Index].Length =
FixedPcdGet32 (PcdFvSize);
229 VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
233 VirtualMemoryTable[Index].PhysicalBase = TOP_32BIT_DEVICE_BASE;
234 VirtualMemoryTable[Index].VirtualBase = TOP_32BIT_DEVICE_BASE;
235 VirtualMemoryTable[Index].Length = TOP_32BIT_DEVICE_SIZE;
236 VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
242 *VirtualMemoryMap = VirtualMemoryTable;
VOID EFIAPI BuildResourceDescriptorHob(IN EFI_RESOURCE_TYPE ResourceType, IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute, IN EFI_PHYSICAL_ADDRESS PhysicalStart, IN UINT64 NumberOfBytes)
UINT64 EFIAPI ReadUnaligned64(IN CONST UINT64 *Buffer)
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
RETURN_STATUS EFIAPI CloudHvVirtMemInfoPeiLibConstructor(VOID)
VOID ArmVirtGetMemoryMap(OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap)
#define ASSERT_RETURN_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet64(TokenName)
#define FixedPcdGet32(TokenName)
#define FixedPcdGet64(TokenName)
#define PcdGet32(TokenName)
#define PcdSet64S(TokenName, Value)
UINT32 EFI_RESOURCE_ATTRIBUTE_TYPE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)