(TEST) MemoryInitPeiLib: auto get memory size from fdt
This commit is contained in:
parent
3e996e0dd7
commit
0055a479a9
@ -158,32 +158,6 @@ static ARM_MEMORY_REGION_DESCRIPTOR_EX gDeviceMemoryDescriptorEx[] = {
|
|||||||
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED, AddMem,
|
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED, AddMem,
|
||||||
EfiRuntimeServicesData},
|
EfiRuntimeServicesData},
|
||||||
|
|
||||||
#ifdef MEMORY_4G
|
|
||||||
{0xA0000000, 0xDDFA0000, EFI_RESOURCE_SYSTEM_MEMORY,
|
|
||||||
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,
|
|
||||||
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK, AddMem, EfiConventionalMemory},
|
|
||||||
#else
|
|
||||||
#ifdef MEMORY_8G
|
|
||||||
{0xA0000000, 0xE0000000, EFI_RESOURCE_SYSTEM_MEMORY,
|
|
||||||
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,
|
|
||||||
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK, AddMem, EfiConventionalMemory},
|
|
||||||
{0x180000000, 0xFC8A0000, EFI_RESOURCE_SYSTEM_MEMORY,
|
|
||||||
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,
|
|
||||||
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK, AddMem, EfiConventionalMemory},
|
|
||||||
#else
|
|
||||||
#ifdef MEMORY_10G
|
|
||||||
{0xA0000000, 0x254AC0000, EFI_RESOURCE_SYSTEM_MEMORY,
|
|
||||||
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,
|
|
||||||
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK, AddMem, EfiConventionalMemory},
|
|
||||||
#else
|
|
||||||
{0xA0000000, 0x15AE00000, EFI_RESOURCE_SYSTEM_MEMORY,
|
|
||||||
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,
|
|
||||||
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK, AddMem, EfiConventionalMemory},
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Other */
|
/* Other */
|
||||||
|
|
||||||
/* AOP_SS_MSG_RAM */
|
/* AOP_SS_MSG_RAM */
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <Library/HobLib.h>
|
#include <Library/HobLib.h>
|
||||||
#include <Library/MemoryAllocationLib.h>
|
#include <Library/MemoryAllocationLib.h>
|
||||||
#include <Library/PcdLib.h>
|
#include <Library/PcdLib.h>
|
||||||
|
#include <Library/FdtParserLib.h>
|
||||||
|
|
||||||
// This varies by device
|
// This varies by device
|
||||||
#include <Configuration/DeviceMemoryMap.h>
|
#include <Configuration/DeviceMemoryMap.h>
|
||||||
@ -84,12 +85,19 @@ MemoryPeim(IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, IN UINT64 UefiMemorySize)
|
|||||||
ARM_MEMORY_REGION_DESCRIPTOR
|
ARM_MEMORY_REGION_DESCRIPTOR
|
||||||
MemoryDescriptor[MAX_ARM_MEMORY_REGION_DESCRIPTOR_COUNT];
|
MemoryDescriptor[MAX_ARM_MEMORY_REGION_DESCRIPTOR_COUNT];
|
||||||
UINTN Index = 0;
|
UINTN Index = 0;
|
||||||
|
UINTN Node = 0;
|
||||||
|
UINTN MemoryBase = 0;
|
||||||
|
UINTN MemorySize = 0;
|
||||||
|
UINTN MemoryTotal = 0;
|
||||||
|
fdt *Fdt;
|
||||||
|
|
||||||
// Ensure PcdSystemMemorySize has been set
|
Fdt = GetFdt();
|
||||||
ASSERT(PcdGet64(PcdSystemMemorySize) != 0);
|
ASSERT(Fdt != NULL);
|
||||||
|
|
||||||
// Run through each memory descriptor
|
// Run through each memory descriptor
|
||||||
while (MemoryDescriptorEx->Length != 0) {
|
while (MemoryDescriptorEx->Length != 0) {
|
||||||
|
if (MemoryDescriptorEx->MemoryType == EfiConventionalMemory)
|
||||||
|
MemoryTotal += MemoryDescriptorEx->Length;
|
||||||
switch (MemoryDescriptorEx->HobOption) {
|
switch (MemoryDescriptorEx->HobOption) {
|
||||||
case AddMem:
|
case AddMem:
|
||||||
case AddDev:
|
case AddDev:
|
||||||
@ -112,6 +120,33 @@ MemoryPeim(IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, IN UINT64 UefiMemorySize)
|
|||||||
MemoryDescriptorEx++;
|
MemoryDescriptorEx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (fdt_get_memory(Fdt, (int)Node, (uint64_t*)&MemoryBase, (uint64_t*)&MemorySize)) {
|
||||||
|
MemoryTotal += MemorySize;
|
||||||
|
DEBUG((
|
||||||
|
EFI_D_INFO,
|
||||||
|
"FDT Memory %-2d: 0x%016llx - 0x%016llx (0x%016llx)\n",
|
||||||
|
Node, MemoryBase, (MemoryBase + MemorySize), MemorySize
|
||||||
|
));
|
||||||
|
ASSERT(Index < MAX_ARM_MEMORY_REGION_DESCRIPTOR_COUNT);
|
||||||
|
MemoryDescriptor[Index].PhysicalBase = MemoryBase;
|
||||||
|
MemoryDescriptor[Index].VirtualBase = MemoryBase;
|
||||||
|
MemoryDescriptor[Index].Length = MemorySize;
|
||||||
|
MemoryDescriptor[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
|
||||||
|
BuildResourceDescriptorHob(
|
||||||
|
EFI_RESOURCE_SYSTEM_MEMORY,
|
||||||
|
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,
|
||||||
|
MemoryBase,
|
||||||
|
MemorySize
|
||||||
|
);
|
||||||
|
BuildMemoryAllocationHob(
|
||||||
|
MemoryBase,
|
||||||
|
MemorySize,
|
||||||
|
EfiConventionalMemory
|
||||||
|
);
|
||||||
|
Index++;
|
||||||
|
Node++;
|
||||||
|
}
|
||||||
|
|
||||||
// Last one (terminator)
|
// Last one (terminator)
|
||||||
ASSERT(Index < MAX_ARM_MEMORY_REGION_DESCRIPTOR_COUNT);
|
ASSERT(Index < MAX_ARM_MEMORY_REGION_DESCRIPTOR_COUNT);
|
||||||
MemoryDescriptor[Index].PhysicalBase = 0;
|
MemoryDescriptor[Index].PhysicalBase = 0;
|
||||||
@ -119,6 +154,8 @@ MemoryPeim(IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, IN UINT64 UefiMemorySize)
|
|||||||
MemoryDescriptor[Index].Length = 0;
|
MemoryDescriptor[Index].Length = 0;
|
||||||
MemoryDescriptor[Index].Attributes = 0;
|
MemoryDescriptor[Index].Attributes = 0;
|
||||||
|
|
||||||
|
DEBUG((EFI_D_INFO, "Memory Total: 0x%016lx (%d GiB)\n", MemoryTotal, MemoryTotal / (1024 * 1024 * 1024)));
|
||||||
|
|
||||||
// Build Memory Allocation Hob
|
// Build Memory Allocation Hob
|
||||||
DEBUG((EFI_D_INFO, "Configure MMU In \n"));
|
DEBUG((EFI_D_INFO, "Configure MMU In \n"));
|
||||||
InitMmu(MemoryDescriptor);
|
InitMmu(MemoryDescriptor);
|
||||||
|
@ -30,10 +30,12 @@
|
|||||||
ArmPkg/ArmPkg.dec
|
ArmPkg/ArmPkg.dec
|
||||||
ArmPlatformPkg/ArmPlatformPkg.dec
|
ArmPlatformPkg/ArmPlatformPkg.dec
|
||||||
sdm845Pkg/sdm845Pkg.dec
|
sdm845Pkg/sdm845Pkg.dec
|
||||||
|
SimpleInit.dec
|
||||||
|
|
||||||
[LibraryClasses]
|
[LibraryClasses]
|
||||||
DebugLib
|
DebugLib
|
||||||
HobLib
|
HobLib
|
||||||
|
SimpleInitLib
|
||||||
ArmMmuLib
|
ArmMmuLib
|
||||||
ArmPlatformLib
|
ArmPlatformLib
|
||||||
|
|
||||||
@ -46,6 +48,7 @@
|
|||||||
[FixedPcd]
|
[FixedPcd]
|
||||||
gArmTokenSpaceGuid.PcdSystemMemoryBase
|
gArmTokenSpaceGuid.PcdSystemMemoryBase
|
||||||
gArmTokenSpaceGuid.PcdSystemMemorySize
|
gArmTokenSpaceGuid.PcdSystemMemorySize
|
||||||
|
gsdm845PkgTokenSpaceGuid.DeviceTreeStore
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
TRUE
|
TRUE
|
||||||
|
Loading…
Reference in New Issue
Block a user