]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/PlatformPei/Platform.c
86084e466acff13fa3885179211d01e63e9e7c9b
[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, 0x01C },
38 { EfiRuntimeServicesData, 0x050 },
39 { EfiRuntimeServicesCode, 0x020 },
40 { EfiBootServicesCode, 0x0F0 },
41 { EfiBootServicesData, 0xA00 },
42 { EfiMaxMemoryType, 0x000 }
43 };
44
45
46 VOID
47 AddIoMemoryBaseSizeHob (
48 EFI_PHYSICAL_ADDRESS MemoryBase,
49 UINT64 MemorySize
50 )
51 {
52 STATIC EFI_RESOURCE_ATTRIBUTE_TYPE Attributes =
53 (
54 EFI_RESOURCE_ATTRIBUTE_PRESENT |
55 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
56 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
57 EFI_RESOURCE_ATTRIBUTE_TESTED
58 );
59
60 BuildResourceDescriptorHob (
61 EFI_RESOURCE_MEMORY_MAPPED_IO,
62 Attributes,
63 MemoryBase,
64 MemorySize
65 );
66 }
67
68
69 VOID
70 AddIoMemoryRangeHob (
71 EFI_PHYSICAL_ADDRESS MemoryBase,
72 EFI_PHYSICAL_ADDRESS MemoryLimit
73 )
74 {
75 AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
76 }
77
78
79 VOID
80 AddMemoryBaseSizeHob (
81 EFI_PHYSICAL_ADDRESS MemoryBase,
82 UINT64 MemorySize
83 )
84 {
85 STATIC EFI_RESOURCE_ATTRIBUTE_TYPE Attributes =
86 (
87 EFI_RESOURCE_ATTRIBUTE_PRESENT |
88 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
89 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
90 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
91 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
92 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
93 EFI_RESOURCE_ATTRIBUTE_TESTED
94 );
95
96 BuildResourceDescriptorHob (
97 EFI_RESOURCE_SYSTEM_MEMORY,
98 Attributes,
99 MemoryBase,
100 MemorySize
101 );
102 }
103
104
105 VOID
106 AddMemoryRangeHob (
107 EFI_PHYSICAL_ADDRESS MemoryBase,
108 EFI_PHYSICAL_ADDRESS MemoryLimit
109 )
110 {
111 AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
112 }
113
114
115 VOID
116 MemMapInitialization (
117 )
118 {
119 //
120 // Create Memory Type Information HOB
121 //
122 BuildGuidDataHob (
123 &gEfiMemoryTypeInformationGuid,
124 mDefaultMemoryTypeInformation,
125 sizeof(mDefaultMemoryTypeInformation)
126 );
127
128 //
129 // Local APIC range
130 //
131 AddIoMemoryBaseSizeHob (0xFEC80000, 0x80000);
132
133 //
134 // I/O APIC range
135 //
136 AddIoMemoryBaseSizeHob (0xFEC00000, 0x80000);
137
138 //
139 // Video memory + Legacy BIOS region
140 //
141 AddIoMemoryRangeHob (0x0A0000, 0x100000);
142 }
143
144
145 VOID
146 MiscInitialization (
147 )
148 {
149 //
150 // Disable A20 Mask
151 //
152 IoWrite8 (0x92, (UINT8) (IoRead8 (0x92) | 0x02));
153
154 //
155 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
156 //
157 BuildCpuHob (36, 16);
158 }
159
160
161 VOID
162 ReserveEmuVariableNvStore (
163 )
164 {
165 EFI_PHYSICAL_ADDRESS VariableStore;
166
167 //
168 // Allocate storage for NV variables early on so it will be
169 // at a consistent address. Since VM memory is preserved
170 // across reboots, this allows the NV variable storage to survive
171 // a VM reboot.
172 //
173 VariableStore =
174 (EFI_PHYSICAL_ADDRESS)(UINTN)
175 AllocateRuntimePool (
176 2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)
177 );
178 DEBUG ((EFI_D_INFO,
179 "Reserved variable store memory: 0x%lX; size: %dkb\n",
180 VariableStore,
181 (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024
182 ));
183 PcdSet64 (PcdEmuVariableNvStoreReserved, VariableStore);
184 }
185
186
187 /**
188 Perform Platform PEI initialization.
189
190 @param FileHandle Handle of the file being invoked.
191 @param PeiServices Describes the list of possible PEI Services.
192
193 @return EFI_SUCCESS The PEIM initialized successfully.
194
195 **/
196 EFI_STATUS
197 EFIAPI
198 InitializePlatform (
199 IN EFI_PEI_FILE_HANDLE FileHandle,
200 IN CONST EFI_PEI_SERVICES **PeiServices
201 )
202 {
203 DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));
204
205 MemDetect ();
206
207 ReserveEmuVariableNvStore ();
208
209 PeiFvInitialization ();
210
211 MemMapInitialization ();
212
213 MiscInitialization ();
214
215 return EFI_SUCCESS;
216 }
217