]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c
ArmVirtPkg: remove ArmPlatformSysConfigLib dependency
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPlatformLib / Virt.c
1 /** @file
2 *
3 * Copyright (c) 2011-2013, ARM Limited. All rights reserved.
4 * Copyright (c) 2014, Linaro Limited. All rights reserved.
5 * Copyright (c) 2014, Red Hat, Inc.
6 *
7 *
8 * This program and the accompanying materials
9 * are licensed and made available under the terms and conditions of the BSD License
10 * which accompanies this distribution. The full text of the license may be found at
11 * http://opensource.org/licenses/bsd-license.php
12 *
13 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 *
16 **/
17
18 #include <Library/IoLib.h>
19 #include <Library/ArmPlatformLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/PcdLib.h>
22 #include <libfdt.h>
23 #include <Pi/PiBootMode.h>
24 #include <Uefi/UefiBaseType.h>
25 #include <Uefi/UefiMultiPhase.h>
26
27 /**
28 Return the current Boot Mode
29
30 This function returns the boot reason on the platform
31
32 @return Return the current Boot Mode of the platform
33
34 **/
35 EFI_BOOT_MODE
36 ArmPlatformGetBootMode (
37 VOID
38 )
39 {
40 return BOOT_WITH_FULL_CONFIGURATION;
41 }
42
43 /**
44 This function is called by PrePeiCore, in the SEC phase.
45 **/
46 RETURN_STATUS
47 ArmPlatformInitialize (
48 IN UINTN MpId
49 )
50 {
51 //
52 // We are relying on ArmPlatformInitializeSystemMemory () being called from
53 // InitializeMemory (), which only occurs if the following feature is disabled
54 //
55 ASSERT (!FeaturePcdGet (PcdSystemMemoryInitializeInSec));
56 return RETURN_SUCCESS;
57 }
58
59 /**
60 Initialize the system (or sometimes called permanent) memory
61
62 This memory is generally represented by the DRAM.
63
64 This function is called from InitializeMemory() in MemoryInitPeim, in the PEI
65 phase.
66 **/
67 VOID
68 ArmPlatformInitializeSystemMemory (
69 VOID
70 )
71 {
72 VOID *DeviceTreeBase;
73 INT32 Node, Prev;
74 UINT64 NewBase, CurBase;
75 UINT64 NewSize, CurSize;
76 CONST CHAR8 *Type;
77 INT32 Len;
78 CONST UINT64 *RegProp;
79 RETURN_STATUS PcdStatus;
80
81 NewBase = 0;
82 NewSize = 0;
83
84 DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
85 ASSERT (DeviceTreeBase != NULL);
86
87 //
88 // Make sure we have a valid device tree blob
89 //
90 ASSERT (fdt_check_header (DeviceTreeBase) == 0);
91
92 //
93 // Look for the lowest memory node
94 //
95 for (Prev = 0;; Prev = Node) {
96 Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
97 if (Node < 0) {
98 break;
99 }
100
101 //
102 // Check for memory node
103 //
104 Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
105 if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {
106 //
107 // Get the 'reg' property of this node. For now, we will assume
108 // two 8 byte quantities for base and size, respectively.
109 //
110 RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
111 if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {
112
113 CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
114 CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));
115
116 DEBUG ((EFI_D_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",
117 __FUNCTION__, CurBase, CurBase + CurSize - 1));
118
119 if (NewBase > CurBase || NewBase == 0) {
120 NewBase = CurBase;
121 NewSize = CurSize;
122 }
123 } else {
124 DEBUG ((EFI_D_ERROR, "%a: Failed to parse FDT memory node\n",
125 __FUNCTION__));
126 }
127 }
128 }
129
130 //
131 // Make sure the start of DRAM matches our expectation
132 //
133 ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);
134 PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);
135 ASSERT_RETURN_ERROR (PcdStatus);
136
137 //
138 // We need to make sure that the machine we are running on has at least
139 // 128 MB of memory configured, and is currently executing this binary from
140 // NOR flash. This prevents a device tree image in DRAM from getting
141 // clobbered when our caller installs permanent PEI RAM, before we have a
142 // chance of marking its location as reserved or copy it to a freshly
143 // allocated block in the permanent PEI RAM in the platform PEIM.
144 //
145 ASSERT (NewSize >= SIZE_128MB);
146 ASSERT (
147 (((UINT64)PcdGet64 (PcdFdBaseAddress) +
148 (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||
149 ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));
150 }
151
152 VOID
153 ArmPlatformGetPlatformPpiList (
154 OUT UINTN *PpiListSize,
155 OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
156 )
157 {
158 *PpiListSize = 0;
159 *PpiList = NULL;
160 }