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
;
41 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
43 ASSERT_EFI_ERROR (Status
);
46 // Check for memory node and add the memory spaces except the lowest one
48 for (FindNodeStatus
= FdtClient
->FindMemoryNodeReg (FdtClient
, &Node
,
49 (CONST VOID
**) &Reg
, &AddressCells
,
50 &SizeCells
, &RegSize
);
51 !EFI_ERROR (FindNodeStatus
);
52 FindNodeStatus
= FdtClient
->FindNextMemoryNodeReg (FdtClient
, Node
,
53 &Node
, (CONST VOID
**) &Reg
, &AddressCells
,
54 &SizeCells
, &RegSize
)) {
55 ASSERT (AddressCells
<= 2);
56 ASSERT (SizeCells
<= 2);
59 CurBase
= SwapBytes32 (*Reg
++);
60 if (AddressCells
> 1) {
61 CurBase
= (CurBase
<< 32) | SwapBytes32 (*Reg
++);
63 CurSize
= SwapBytes32 (*Reg
++);
65 CurSize
= (CurSize
<< 32) | SwapBytes32 (*Reg
++);
67 RegSize
-= (AddressCells
+ SizeCells
) * sizeof (UINT32
);
69 if (PcdGet64 (PcdSystemMemoryBase
) != CurBase
) {
70 Status
= gDS
->AddMemorySpace (EfiGcdMemoryTypeSystemMemory
, CurBase
,
71 CurSize
, EFI_MEMORY_WB
);
73 if (EFI_ERROR (Status
)) {
75 "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",
76 __FUNCTION__
, CurBase
, CurBase
+ CurSize
- 1, Status
));
80 Status
= gDS
->SetMemorySpaceAttributes (CurBase
, CurSize
,
83 if (EFI_ERROR (Status
)) {
85 "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",
86 __FUNCTION__
, CurBase
, CurBase
+ CurSize
- 1, Status
));
88 DEBUG ((EFI_D_INFO
, "%a: Add System RAM @ 0x%lx - 0x%lx\n",
89 __FUNCTION__
, CurBase
, CurBase
+ CurSize
- 1));