]>
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 | |
68312710 | 40 | \r |
490acf89 AB |
41 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r |
42 | (VOID **)&FdtClient);\r | |
43 | ASSERT_EFI_ERROR (Status);\r | |
68312710 SZ |
44 | \r |
45 | //\r | |
490acf89 | 46 | // Check for memory node and add the memory spaces except the lowest one\r |
68312710 | 47 | //\r |
490acf89 AB |
48 | for (FindNodeStatus = FdtClient->FindMemoryNodeReg (FdtClient, &Node,\r |
49 | (CONST VOID **) &Reg, &AddressCells,\r | |
50 | &SizeCells, &RegSize);\r | |
51 | !EFI_ERROR (FindNodeStatus);\r | |
52 | FindNodeStatus = FdtClient->FindNextMemoryNodeReg (FdtClient, Node,\r | |
53 | &Node, (CONST VOID **) &Reg, &AddressCells,\r | |
54 | &SizeCells, &RegSize)) {\r | |
55 | ASSERT (AddressCells <= 2);\r | |
56 | ASSERT (SizeCells <= 2);\r | |
68312710 | 57 | \r |
490acf89 AB |
58 | while (RegSize > 0) {\r |
59 | CurBase = SwapBytes32 (*Reg++);\r | |
60 | if (AddressCells > 1) {\r | |
61 | CurBase = (CurBase << 32) | SwapBytes32 (*Reg++);\r | |
62 | }\r | |
63 | CurSize = SwapBytes32 (*Reg++);\r | |
64 | if (SizeCells > 1) {\r | |
65 | CurSize = (CurSize << 32) | SwapBytes32 (*Reg++);\r | |
66 | }\r | |
67 | RegSize -= (AddressCells + SizeCells) * sizeof (UINT32);\r | |
68312710 | 68 | \r |
490acf89 AB |
69 | if (PcdGet64 (PcdSystemMemoryBase) != CurBase) {\r |
70 | Status = gDS->AddMemorySpace (EfiGcdMemoryTypeSystemMemory, CurBase,\r | |
71 | CurSize, EFI_MEMORY_WB);\r | |
68312710 | 72 | \r |
490acf89 AB |
73 | if (EFI_ERROR (Status)) {\r |
74 | DEBUG ((EFI_D_ERROR,\r | |
75 | "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",\r | |
76 | __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r | |
77 | continue;\r | |
78 | }\r | |
68312710 | 79 | \r |
490acf89 AB |
80 | Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize,\r |
81 | EFI_MEMORY_WB);\r | |
68312710 | 82 | \r |
490acf89 AB |
83 | if (EFI_ERROR (Status)) {\r |
84 | DEBUG ((EFI_D_ERROR,\r | |
85 | "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",\r | |
86 | __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r | |
87 | } else {\r | |
88 | DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n",\r | |
89 | __FUNCTION__, CurBase, CurBase + CurSize - 1));\r | |
68312710 SZ |
90 | }\r |
91 | }\r | |
92 | }\r | |
93 | }\r | |
94 | \r | |
95 | return EFI_SUCCESS;\r | |
96 | }\r |