]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/PlatformPei/Platform.c
OVMF: Support greater than 2GB of memory
[mirror_edk2.git] / OvmfPkg / PlatformPei / Platform.c
1 /**@file
2 Platform PEI driver
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 //
16 // The package level header files this module uses
17 //
18 #include <PiPei.h>
19
20 //
21 // The Library classes this module consumes
22 //
23 #include <Library/DebugLib.h>
24 #include <Library/HobLib.h>
25 #include <Library/IoLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/PcdLib.h>
28 #include <Library/PciLib.h>
29 #include <Library/PeimEntryPoint.h>
30 #include <Library/ResourcePublicationLib.h>
31 #include <Guid/MemoryTypeInformation.h>
32
33 #include "Platform.h"
34
35 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
36 { EfiACPIMemoryNVS, 0x004 },
37 { EfiACPIReclaimMemory, 0x008 },
38 { EfiReservedMemoryType, 0x004 },
39 { EfiRuntimeServicesData, 0x024 },
40 { EfiRuntimeServicesCode, 0x030 },
41 { EfiBootServicesCode, 0x180 },
42 { EfiBootServicesData, 0xF00 },
43 { EfiMaxMemoryType, 0x000 }
44 };
45
46
47 VOID
48 AddIoMemoryBaseSizeHob (
49 EFI_PHYSICAL_ADDRESS MemoryBase,
50 UINT64 MemorySize
51 )
52 {
53 BuildResourceDescriptorHob (
54 EFI_RESOURCE_MEMORY_MAPPED_IO,
55 EFI_RESOURCE_ATTRIBUTE_PRESENT |
56 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
57 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
58 EFI_RESOURCE_ATTRIBUTE_TESTED,
59 MemoryBase,
60 MemorySize
61 );
62 }
63
64
65 VOID
66 AddIoMemoryRangeHob (
67 EFI_PHYSICAL_ADDRESS MemoryBase,
68 EFI_PHYSICAL_ADDRESS MemoryLimit
69 )
70 {
71 AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
72 }
73
74
75 VOID
76 AddMemoryBaseSizeHob (
77 EFI_PHYSICAL_ADDRESS MemoryBase,
78 UINT64 MemorySize
79 )
80 {
81 BuildResourceDescriptorHob (
82 EFI_RESOURCE_SYSTEM_MEMORY,
83 EFI_RESOURCE_ATTRIBUTE_PRESENT |
84 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
85 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
86 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
87 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
88 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
89 EFI_RESOURCE_ATTRIBUTE_TESTED,
90 MemoryBase,
91 MemorySize
92 );
93 }
94
95
96 VOID
97 AddMemoryRangeHob (
98 EFI_PHYSICAL_ADDRESS MemoryBase,
99 EFI_PHYSICAL_ADDRESS MemoryLimit
100 )
101 {
102 AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
103 }
104
105 VOID
106 MemMapInitialization (
107 EFI_PHYSICAL_ADDRESS TopOfMemory
108 )
109 {
110 //
111 // Create Memory Type Information HOB
112 //
113 BuildGuidDataHob (
114 &gEfiMemoryTypeInformationGuid,
115 mDefaultMemoryTypeInformation,
116 sizeof(mDefaultMemoryTypeInformation)
117 );
118
119 //
120 // Add PCI IO Port space available for PCI resource allocations.
121 //
122 BuildResourceDescriptorHob (
123 EFI_RESOURCE_IO,
124 EFI_RESOURCE_ATTRIBUTE_PRESENT |
125 EFI_RESOURCE_ATTRIBUTE_INITIALIZED,
126 0x1000,
127 0xF000
128 );
129
130 //
131 // Add PCI MMIO space available to PCI resource allocations
132 //
133 if (TopOfMemory < BASE_2GB) {
134 AddIoMemoryBaseSizeHob (BASE_2GB, 0xFEC00000 - BASE_2GB);
135 } else {
136 AddIoMemoryBaseSizeHob (TopOfMemory, 0xFEC00000 - TopOfMemory);
137 }
138
139 //
140 // Local APIC range
141 //
142 AddIoMemoryBaseSizeHob (0xFEC80000, SIZE_512KB);
143
144 //
145 // I/O APIC range
146 //
147 AddIoMemoryBaseSizeHob (0xFEC00000, SIZE_512KB);
148
149 //
150 // Video memory + Legacy BIOS region
151 //
152 AddIoMemoryRangeHob (0x0A0000, BASE_1MB);
153 }
154
155
156 VOID
157 MiscInitialization (
158 )
159 {
160 //
161 // Disable A20 Mask
162 //
163 IoOr8 (0x92, BIT1);
164
165 //
166 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
167 //
168 BuildCpuHob (36, 16);
169 }
170
171
172 VOID
173 ReserveEmuVariableNvStore (
174 )
175 {
176 EFI_PHYSICAL_ADDRESS VariableStore;
177
178 //
179 // Allocate storage for NV variables early on so it will be
180 // at a consistent address. Since VM memory is preserved
181 // across reboots, this allows the NV variable storage to survive
182 // a VM reboot.
183 //
184 VariableStore =
185 (EFI_PHYSICAL_ADDRESS)(UINTN)
186 AllocateRuntimePool (
187 2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)
188 );
189 DEBUG ((EFI_D_INFO,
190 "Reserved variable store memory: 0x%lX; size: %dkb\n",
191 VariableStore,
192 (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024
193 ));
194 PcdSet64 (PcdEmuVariableNvStoreReserved, VariableStore);
195 }
196
197
198 /**
199 Perform Platform PEI initialization.
200
201 @param FileHandle Handle of the file being invoked.
202 @param PeiServices Describes the list of possible PEI Services.
203
204 @return EFI_SUCCESS The PEIM initialized successfully.
205
206 **/
207 EFI_STATUS
208 EFIAPI
209 InitializePlatform (
210 IN EFI_PEI_FILE_HANDLE FileHandle,
211 IN CONST EFI_PEI_SERVICES **PeiServices
212 )
213 {
214 EFI_PHYSICAL_ADDRESS TopOfMemory;
215
216 DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));
217
218 TopOfMemory = MemDetect ();
219
220 ReserveEmuVariableNvStore ();
221
222 PeiFvInitialization ();
223
224 MemMapInitialization (TopOfMemory);
225
226 MiscInitialization ();
227
228 return EFI_SUCCESS;
229 }