33 UINTN AddressCells, SizeCells;
39 Status =
gBS->LocateProtocol (
40 &gFdtClientProtocolGuid,
46 Status =
gBS->LocateProtocol (
47 &gEfiCpuArchProtocolGuid,
56 for (FindNodeStatus = FdtClient->FindMemoryNodeReg (
64 !EFI_ERROR (FindNodeStatus);
65 FindNodeStatus = FdtClient->FindNextMemoryNodeReg (
75 ASSERT (AddressCells <= 2);
76 ASSERT (SizeCells <= 2);
80 if (AddressCells > 1) {
89 RegSize -= (AddressCells + SizeCells) *
sizeof (UINT32);
91 Status =
gDS->GetMemorySpaceDescriptor (CurBase, &GcdDescriptor);
92 if (EFI_ERROR (Status)) {
95 "%a: Region 0x%lx - 0x%lx not found in the GCD memory space map\n",
104 Status =
gDS->AddMemorySpace (
111 if (EFI_ERROR (Status)) {
114 "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",
117 CurBase + CurSize - 1,
123 Status =
gDS->SetMemorySpaceAttributes (
128 if (EFI_ERROR (Status)) {
131 "%a: gDS->SetMemorySpaceAttributes() failed on region 0x%lx - 0x%lx (%r)\n",
134 CurBase + CurSize - 1,
150 Attributes = EFI_MEMORY_WB;
151 if ((
PcdGet64 (PcdDxeNxMemoryProtectionPolicy) &
154 Attributes |= EFI_MEMORY_XP;
157 Status = Cpu->SetMemoryAttributes (Cpu, CurBase, CurSize, Attributes);
159 if (EFI_ERROR (Status)) {
162 "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",
165 CurBase + CurSize - 1,
171 "%a: Add System RAM @ 0x%lx - 0x%lx\n",
174 CurBase + CurSize - 1
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet64(TokenName)
@ EfiGcdMemoryTypeNonExistent
@ EfiGcdMemoryTypeSystemMemory
EFI_GCD_MEMORY_TYPE GcdMemoryType