• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 *  High memory node enumeration DXE driver for ARM Virtual Machines
3 *
4 *  Copyright (c) 2015-2016, Linaro Ltd. All rights reserved.
5 *
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
10 *
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
13 *  IMPLIED.
14 *
15 **/
16 
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>
22 
23 #include <Protocol/FdtClient.h>
24 
25 EFI_STATUS
26 EFIAPI
InitializeHighMemDxe(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)27 InitializeHighMemDxe (
28   IN EFI_HANDLE           ImageHandle,
29   IN EFI_SYSTEM_TABLE     *SystemTable
30   )
31 {
32   FDT_CLIENT_PROTOCOL   *FdtClient;
33   EFI_STATUS            Status, FindNodeStatus;
34   INT32                 Node;
35   CONST UINT32          *Reg;
36   UINT32                RegSize;
37   UINTN                 AddressCells, SizeCells;
38   UINT64                CurBase;
39   UINT64                CurSize;
40 
41   Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
42                   (VOID **)&FdtClient);
43   ASSERT_EFI_ERROR (Status);
44 
45   //
46   // Check for memory node and add the memory spaces except the lowest one
47   //
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);
57 
58     while (RegSize > 0) {
59       CurBase = SwapBytes32 (*Reg++);
60       if (AddressCells > 1) {
61         CurBase = (CurBase << 32) | SwapBytes32 (*Reg++);
62       }
63       CurSize = SwapBytes32 (*Reg++);
64       if (SizeCells > 1) {
65         CurSize = (CurSize << 32) | SwapBytes32 (*Reg++);
66       }
67       RegSize -= (AddressCells + SizeCells) * sizeof (UINT32);
68 
69       if (PcdGet64 (PcdSystemMemoryBase) != CurBase) {
70         Status = gDS->AddMemorySpace (EfiGcdMemoryTypeSystemMemory, CurBase,
71                         CurSize, EFI_MEMORY_WB);
72 
73         if (EFI_ERROR (Status)) {
74           DEBUG ((EFI_D_ERROR,
75             "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",
76             __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));
77           continue;
78         }
79 
80         Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize,
81                         EFI_MEMORY_WB);
82 
83         if (EFI_ERROR (Status)) {
84           DEBUG ((EFI_D_ERROR,
85             "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",
86             __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));
87         } else {
88           DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n",
89             __FUNCTION__, CurBase, CurBase + CurSize - 1));
90         }
91       }
92     }
93   }
94 
95   return EFI_SUCCESS;
96 }
97