]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/PlatformPei/Platform.c
Update OVMF Platform PEI to declare IO and MMIO resources.
[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 )
108 {
109 //
110 // Create Memory Type Information HOB
111 //
112 BuildGuidDataHob (
113 &gEfiMemoryTypeInformationGuid,
114 mDefaultMemoryTypeInformation,
115 sizeof(mDefaultMemoryTypeInformation)
116 );
117
118 //
119 // Add PCI IO Port space available for PCI resource allocations.
120 //
121 BuildResourceDescriptorHob (
122 EFI_RESOURCE_IO,
123 EFI_RESOURCE_ATTRIBUTE_PRESENT |
124 EFI_RESOURCE_ATTRIBUTE_INITIALIZED,
125 0x1000,
126 0xF000
127 );
128
129 //
130 // Add PCI MMIO space available to PCI resource allocations
131 //
132 AddIoMemoryBaseSizeHob (0x80000000, 0xFEC00000 - 0x80000000);
133
134 //
135 // Local APIC range
136 //
137 AddIoMemoryBaseSizeHob (0xFEC80000, 0x80000);
138
139 //
140 // I/O APIC range
141 //
142 AddIoMemoryBaseSizeHob (0xFEC00000, 0x80000);
143
144 //
145 // Video memory + Legacy BIOS region
146 //
147 AddIoMemoryRangeHob (0x0A0000, 0x100000);
148 }
149
150
151 VOID
152 MiscInitialization (
153 )
154 {
155 //
156 // Disable A20 Mask
157 //
158 IoWrite8 (0x92, (UINT8) (IoRead8 (0x92) | 0x02));
159
160 //
161 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
162 //
163 BuildCpuHob (36, 16);
164 }
165
166
167 VOID
168 ReserveEmuVariableNvStore (
169 )
170 {
171 EFI_PHYSICAL_ADDRESS VariableStore;
172
173 //
174 // Allocate storage for NV variables early on so it will be
175 // at a consistent address. Since VM memory is preserved
176 // across reboots, this allows the NV variable storage to survive
177 // a VM reboot.
178 //
179 VariableStore =
180 (EFI_PHYSICAL_ADDRESS)(UINTN)
181 AllocateRuntimePool (
182 2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)
183 );
184 DEBUG ((EFI_D_INFO,
185 "Reserved variable store memory: 0x%lX; size: %dkb\n",
186 VariableStore,
187 (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024
188 ));
189 PcdSet64 (PcdEmuVariableNvStoreReserved, VariableStore);
190 }
191
192
193 /**
194 Perform Platform PEI initialization.
195
196 @param FileHandle Handle of the file being invoked.
197 @param PeiServices Describes the list of possible PEI Services.
198
199 @return EFI_SUCCESS The PEIM initialized successfully.
200
201 **/
202 EFI_STATUS
203 EFIAPI
204 InitializePlatform (
205 IN EFI_PEI_FILE_HANDLE FileHandle,
206 IN CONST EFI_PEI_SERVICES **PeiServices
207 )
208 {
209 DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));
210
211 MemDetect ();
212
213 ReserveEmuVariableNvStore ();
214
215 PeiFvInitialization ();
216
217 MemMapInitialization ();
218
219 MiscInitialization ();
220
221 return EFI_SUCCESS;
222 }