]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c
OvmfPkg: Fix VS2015 warning C4459 in XenBusDxe
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPlatformLib / 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
a36d531f
MC
27\r
28/**\r
29 Return the current Boot Mode\r
30\r
31 This function returns the boot reason on the platform\r
32\r
33 @return Return the current Boot Mode of the platform\r
34\r
35**/\r
36EFI_BOOT_MODE\r
37ArmPlatformGetBootMode (\r
38 VOID\r
39 )\r
40{\r
41 return BOOT_WITH_FULL_CONFIGURATION;\r
42}\r
43\r
44/**\r
45 This function is called by PrePeiCore, in the SEC phase.\r
46**/\r
47RETURN_STATUS\r
48ArmPlatformInitialize (\r
49 IN UINTN MpId\r
50 )\r
51{\r
52 //\r
53 // We are relying on ArmPlatformInitializeSystemMemory () being called from\r
54 // InitializeMemory (), which only occurs if the following feature is disabled\r
55 //\r
56 ASSERT (!FeaturePcdGet (PcdSystemMemoryInitializeInSec));\r
57 return RETURN_SUCCESS;\r
58}\r
59\r
60/**\r
61 Initialize the system (or sometimes called permanent) memory\r
62\r
63 This memory is generally represented by the DRAM.\r
64\r
65 This function is called from InitializeMemory() in MemoryInitPeim, in the PEI\r
66 phase.\r
67**/\r
68VOID\r
69ArmPlatformInitializeSystemMemory (\r
70 VOID\r
71 )\r
72{\r
73 VOID *DeviceTreeBase;\r
74 INT32 Node, Prev;\r
75 UINT64 NewBase;\r
76 UINT64 NewSize;\r
a36d531f 77 CONST CHAR8 *Type;\r
a36d531f
MC
78 INT32 Len;\r
79 CONST UINT64 *RegProp;\r
a36d531f
MC
80\r
81 NewBase = 0;\r
82 NewSize = 0;\r
83\r
ada518b7 84 DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);\r
a36d531f
MC
85 ASSERT (DeviceTreeBase != NULL);\r
86\r
87 //\r
88 // Make sure we have a valid device tree blob\r
89 //\r
90 ASSERT (fdt_check_header (DeviceTreeBase) == 0);\r
91\r
92 //\r
93 // Look for a memory node\r
94 //\r
337d450e 95 for (Prev = 0;; Prev = Node) {\r
a36d531f
MC
96 Node = fdt_next_node (DeviceTreeBase, Prev, NULL);\r
97 if (Node < 0) {\r
98 break;\r
99 }\r
100\r
101 //\r
102 // Check for memory node\r
103 //\r
104 Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);\r
105 if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {\r
106 //\r
107 // Get the 'reg' property of this node. For now, we will assume\r
108 // two 8 byte quantities for base and size, respectively.\r
109 //\r
110 RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);\r
111 if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {\r
112\r
113 NewBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));\r
114 NewSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));\r
115\r
116 //\r
117 // Make sure the start of DRAM matches our expectation\r
118 //\r
119 ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);\r
120 PcdSet64 (PcdSystemMemorySize, NewSize);\r
121\r
122 DEBUG ((EFI_D_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",\r
123 __FUNCTION__, NewBase, NewBase + NewSize - 1));\r
124 } else {\r
125 DEBUG ((EFI_D_ERROR, "%a: Failed to parse FDT memory node\n",\r
126 __FUNCTION__));\r
127 }\r
337d450e 128 break;\r
a36d531f
MC
129 }\r
130 }\r
131\r
132 //\r
133 // We need to make sure that the machine we are running on has at least\r
134 // 128 MB of memory configured, and is currently executing this binary from\r
135 // NOR flash. This prevents a device tree image in DRAM from getting\r
136 // clobbered when our caller installs permanent PEI RAM, before we have a\r
137 // chance of marking its location as reserved or copy it to a freshly\r
138 // allocated block in the permanent PEI RAM in the platform PEIM.\r
139 //\r
140 ASSERT (NewSize >= SIZE_128MB);\r
141 ASSERT (\r
bb5420bb 142 (((UINT64)PcdGet64 (PcdFdBaseAddress) +\r
a36d531f 143 (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||\r
bb5420bb 144 ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));\r
a36d531f
MC
145}\r
146\r
147VOID\r
148ArmPlatformGetPlatformPpiList (\r
149 OUT UINTN *PpiListSize,\r
150 OUT EFI_PEI_PPI_DESCRIPTOR **PpiList\r
151 )\r
152{\r
153 *PpiListSize = 0;\r
154 *PpiList = NULL;\r
155}\r