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