]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmVirtPkg/HighMemDxe/HighMemDxe.c
ArmVirtPkg: HighMemDxe: add memory space for the high memory nodes
[mirror_edk2.git] / ArmVirtPkg / HighMemDxe / HighMemDxe.c
... / ...
CommitLineData
1/** @file\r
2* High memory node enumeration DXE driver for ARM Virtual Machines\r
3*\r
4* Copyright (c) 2015, Linaro Ltd. All rights reserved.\r
5*\r
6* This program and the accompanying materials are licensed and made available\r
7* under the terms and conditions of the BSD License which accompanies this\r
8* distribution. The full text of the license may be found at\r
9* http://opensource.org/licenses/bsd-license.php\r
10*\r
11* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR\r
13* IMPLIED.\r
14*\r
15**/\r
16\r
17#include <Library/BaseLib.h>\r
18#include <Library/UefiDriverEntryPoint.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/HobLib.h>\r
22#include <libfdt.h>\r
23#include <Library/DxeServicesTableLib.h>\r
24\r
25EFI_STATUS\r
26EFIAPI\r
27InitializeHighMemDxe (\r
28 IN EFI_HANDLE ImageHandle,\r
29 IN EFI_SYSTEM_TABLE *SystemTable\r
30 )\r
31{\r
32 VOID *Hob;\r
33 VOID *DeviceTreeBase;\r
34 INT32 Node, Prev;\r
35 EFI_STATUS Status;\r
36 CONST CHAR8 *Type;\r
37 INT32 Len;\r
38 CONST VOID *RegProp;\r
39 UINT64 CurBase;\r
40 UINT64 CurSize;\r
41\r
42 Hob = GetFirstGuidHob(&gFdtHobGuid);\r
43 if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) {\r
44 return EFI_NOT_FOUND;\r
45 }\r
46 DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);\r
47\r
48 if (fdt_check_header (DeviceTreeBase) != 0) {\r
49 DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__,\r
50 DeviceTreeBase));\r
51 return EFI_NOT_FOUND;\r
52 }\r
53\r
54 DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, DeviceTreeBase));\r
55\r
56 //\r
57 // Check for memory node and add the memory spaces expect the lowest one\r
58 //\r
59 for (Prev = 0;; Prev = Node) {\r
60 Node = fdt_next_node (DeviceTreeBase, Prev, NULL);\r
61 if (Node < 0) {\r
62 break;\r
63 }\r
64\r
65 Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);\r
66 if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {\r
67 //\r
68 // Get the 'reg' property of this node. For now, we will assume\r
69 // two 8 byte quantities for base and size, respectively.\r
70 //\r
71 RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);\r
72 if (RegProp != NULL && Len == (2 * sizeof (UINT64))) {\r
73\r
74 CurBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);\r
75 CurSize = fdt64_to_cpu (((UINT64 *)RegProp)[1]);\r
76\r
77 if (FixedPcdGet64 (PcdSystemMemoryBase) != CurBase) {\r
78 Status = gDS->AddMemorySpace (\r
79 EfiGcdMemoryTypeSystemMemory,\r
80 CurBase, CurSize,\r
81 EFI_MEMORY_WB | EFI_MEMORY_WC |\r
82 EFI_MEMORY_WT | EFI_MEMORY_UC);\r
83\r
84 if (EFI_ERROR (Status)) {\r
85 DEBUG ((EFI_D_ERROR,\r
86 "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",\r
87 __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r
88 continue;\r
89 }\r
90\r
91 Status = gDS->SetMemorySpaceAttributes (\r
92 CurBase, CurSize,\r
93 EFI_MEMORY_WB);\r
94\r
95 if (EFI_ERROR (Status)) {\r
96 DEBUG ((EFI_D_ERROR,\r
97 "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",\r
98 __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r
99 } else {\r
100 DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n",\r
101 __FUNCTION__, CurBase, CurBase + CurSize - 1));\r
102 }\r
103 }\r
104 }\r
105 }\r
106 }\r
107\r
108 return EFI_SUCCESS;\r
109}\r