2 * High memory node enumeration DXE driver for ARM Virtual Machines
4 * Copyright (c) 2015-2016, Linaro Ltd. All rights reserved.
6 * This program and the accompanying materials are licensed and made available
7 * under the terms and conditions of the BSD License which accompanies this
8 * distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/DxeServicesTableLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
23 #include <Protocol/FdtClient.h>
27 InitializeHighMemDxe (
28 IN EFI_HANDLE ImageHandle
,
29 IN EFI_SYSTEM_TABLE
*SystemTable
32 FDT_CLIENT_PROTOCOL
*FdtClient
;
33 EFI_STATUS Status
, FindNodeStatus
;
37 UINTN AddressCells
, SizeCells
;
42 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
44 ASSERT_EFI_ERROR (Status
);
47 // Check for memory node and add the memory spaces except the lowest one
49 for (FindNodeStatus
= FdtClient
->FindMemoryNodeReg (FdtClient
, &Node
,
50 (CONST VOID
**) &Reg
, &AddressCells
,
51 &SizeCells
, &RegSize
);
52 !EFI_ERROR (FindNodeStatus
);
53 FindNodeStatus
= FdtClient
->FindNextMemoryNodeReg (FdtClient
, Node
,
54 &Node
, (CONST VOID
**) &Reg
, &AddressCells
,
55 &SizeCells
, &RegSize
)) {
56 ASSERT (AddressCells
<= 2);
57 ASSERT (SizeCells
<= 2);
60 CurBase
= SwapBytes32 (*Reg
++);
61 if (AddressCells
> 1) {
62 CurBase
= (CurBase
<< 32) | SwapBytes32 (*Reg
++);
64 CurSize
= SwapBytes32 (*Reg
++);
66 CurSize
= (CurSize
<< 32) | SwapBytes32 (*Reg
++);
68 RegSize
-= (AddressCells
+ SizeCells
) * sizeof (UINT32
);
70 if (PcdGet64 (PcdSystemMemoryBase
) != CurBase
) {
71 Status
= gDS
->AddMemorySpace (EfiGcdMemoryTypeSystemMemory
, CurBase
,
72 CurSize
, EFI_MEMORY_WB
);
74 if (EFI_ERROR (Status
)) {
76 "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",
77 __FUNCTION__
, CurBase
, CurBase
+ CurSize
- 1, Status
));
82 // Take care not to strip any permission attributes that will have been
83 // set by DxeCore on the region we just added if a strict permission
84 // policy is in effect for EfiConventionalMemory regions.
85 // Unfortunately, we cannot interrogate the GCD memory space map for
86 // those permissions, since they are not recorded there (for historical
87 // reasons), so check the policy directly.
89 Attributes
= EFI_MEMORY_WB
;
90 if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy
) &
91 (1U << (UINT32
)EfiConventionalMemory
)) != 0) {
92 Attributes
|= EFI_MEMORY_XP
;
95 Status
= gDS
->SetMemorySpaceAttributes (CurBase
, CurSize
, Attributes
);
97 if (EFI_ERROR (Status
)) {
99 "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",
100 __FUNCTION__
, CurBase
, CurBase
+ CurSize
- 1, Status
));
102 DEBUG ((EFI_D_INFO
, "%a: Add System RAM @ 0x%lx - 0x%lx\n",
103 __FUNCTION__
, CurBase
, CurBase
+ CurSize
- 1));