]>
Commit | Line | Data |
---|---|---|
68312710 SZ |
1 | /** @file\r |
2 | * High memory node enumeration DXE driver for ARM Virtual Machines\r | |
3 | *\r | |
490acf89 | 4 | * Copyright (c) 2015-2016, Linaro Ltd. All rights reserved.\r |
68312710 SZ |
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 | |
68312710 | 18 | #include <Library/DebugLib.h>\r |
68312710 | 19 | #include <Library/DxeServicesTableLib.h>\r |
490acf89 AB |
20 | #include <Library/PcdLib.h>\r |
21 | #include <Library/UefiBootServicesTableLib.h>\r | |
22 | \r | |
23 | #include <Protocol/FdtClient.h>\r | |
68312710 SZ |
24 | \r |
25 | EFI_STATUS\r | |
26 | EFIAPI\r | |
27 | InitializeHighMemDxe (\r | |
28 | IN EFI_HANDLE ImageHandle,\r | |
29 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
30 | )\r | |
31 | {\r | |
490acf89 AB |
32 | FDT_CLIENT_PROTOCOL *FdtClient;\r |
33 | EFI_STATUS Status, FindNodeStatus;\r | |
34 | INT32 Node;\r | |
35 | CONST UINT32 *Reg;\r | |
36 | UINT32 RegSize;\r | |
37 | UINTN AddressCells, SizeCells;\r | |
38 | UINT64 CurBase;\r | |
39 | UINT64 CurSize;\r | |
413edd47 | 40 | UINT64 Attributes;\r |
68312710 | 41 | \r |
490acf89 AB |
42 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r |
43 | (VOID **)&FdtClient);\r | |
44 | ASSERT_EFI_ERROR (Status);\r | |
68312710 SZ |
45 | \r |
46 | //\r | |
490acf89 | 47 | // Check for memory node and add the memory spaces except the lowest one\r |
68312710 | 48 | //\r |
490acf89 AB |
49 | for (FindNodeStatus = FdtClient->FindMemoryNodeReg (FdtClient, &Node,\r |
50 | (CONST VOID **) &Reg, &AddressCells,\r | |
51 | &SizeCells, &RegSize);\r | |
52 | !EFI_ERROR (FindNodeStatus);\r | |
53 | FindNodeStatus = FdtClient->FindNextMemoryNodeReg (FdtClient, Node,\r | |
54 | &Node, (CONST VOID **) &Reg, &AddressCells,\r | |
55 | &SizeCells, &RegSize)) {\r | |
56 | ASSERT (AddressCells <= 2);\r | |
57 | ASSERT (SizeCells <= 2);\r | |
68312710 | 58 | \r |
490acf89 AB |
59 | while (RegSize > 0) {\r |
60 | CurBase = SwapBytes32 (*Reg++);\r | |
61 | if (AddressCells > 1) {\r | |
62 | CurBase = (CurBase << 32) | SwapBytes32 (*Reg++);\r | |
63 | }\r | |
64 | CurSize = SwapBytes32 (*Reg++);\r | |
65 | if (SizeCells > 1) {\r | |
66 | CurSize = (CurSize << 32) | SwapBytes32 (*Reg++);\r | |
67 | }\r | |
68 | RegSize -= (AddressCells + SizeCells) * sizeof (UINT32);\r | |
68312710 | 69 | \r |
490acf89 AB |
70 | if (PcdGet64 (PcdSystemMemoryBase) != CurBase) {\r |
71 | Status = gDS->AddMemorySpace (EfiGcdMemoryTypeSystemMemory, CurBase,\r | |
72 | CurSize, EFI_MEMORY_WB);\r | |
68312710 | 73 | \r |
490acf89 AB |
74 | if (EFI_ERROR (Status)) {\r |
75 | DEBUG ((EFI_D_ERROR,\r | |
76 | "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",\r | |
77 | __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r | |
78 | continue;\r | |
79 | }\r | |
68312710 | 80 | \r |
413edd47 AB |
81 | //\r |
82 | // Take care not to strip any permission attributes that will have been\r | |
83 | // set by DxeCore on the region we just added if a strict permission\r | |
84 | // policy is in effect for EfiConventionalMemory regions.\r | |
85 | // Unfortunately, we cannot interrogate the GCD memory space map for\r | |
86 | // those permissions, since they are not recorded there (for historical\r | |
87 | // reasons), so check the policy directly.\r | |
88 | //\r | |
89 | Attributes = EFI_MEMORY_WB;\r | |
90 | if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) &\r | |
91 | (1U << (UINT32)EfiConventionalMemory)) != 0) {\r | |
92 | Attributes |= EFI_MEMORY_XP;\r | |
93 | }\r | |
94 | \r | |
95 | Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize, Attributes);\r | |
68312710 | 96 | \r |
490acf89 AB |
97 | if (EFI_ERROR (Status)) {\r |
98 | DEBUG ((EFI_D_ERROR,\r | |
99 | "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",\r | |
100 | __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r | |
101 | } else {\r | |
102 | DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n",\r | |
103 | __FUNCTION__, CurBase, CurBase + CurSize - 1));\r | |
68312710 SZ |
104 | }\r |
105 | }\r | |
106 | }\r | |
107 | }\r | |
108 | \r | |
109 | return EFI_SUCCESS;\r | |
110 | }\r |