]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/PlatformPei/Platform.c
Add initial version of Open Virtual Machine Firmware (OVMF) platform.
[mirror_edk2.git] / OvmfPkg / PlatformPei / Platform.c
1 /**@file
2 Platform PEI driver
3
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. 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/PciLib.h>
27 #include <Library/PeimEntryPoint.h>
28 #include <Library/ResourcePublicationLib.h>
29 #include <Guid/MemoryTypeInformation.h>
30
31 #include "Platform.h"
32
33 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
34 { EfiACPIMemoryNVS, 0x004 },
35 { EfiACPIReclaimMemory, 0x01C },
36 { EfiRuntimeServicesData, 0x050 },
37 { EfiRuntimeServicesCode, 0x020 },
38 { EfiBootServicesCode, 0x0F0 },
39 { EfiBootServicesData, 0xA00 },
40 { EfiMaxMemoryType, 0x000 }
41 };
42
43
44 VOID
45 AddIoMemoryBaseSizeHob (
46 EFI_PHYSICAL_ADDRESS MemoryBase,
47 UINT64 MemorySize
48 )
49 {
50 STATIC EFI_RESOURCE_ATTRIBUTE_TYPE Attributes =
51 (
52 EFI_RESOURCE_ATTRIBUTE_PRESENT |
53 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
54 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
55 EFI_RESOURCE_ATTRIBUTE_TESTED
56 );
57
58 BuildResourceDescriptorHob (
59 EFI_RESOURCE_MEMORY_MAPPED_IO,
60 Attributes,
61 MemoryBase,
62 MemorySize
63 );
64 }
65
66
67 VOID
68 AddIoMemoryRangeHob (
69 EFI_PHYSICAL_ADDRESS MemoryBase,
70 EFI_PHYSICAL_ADDRESS MemoryLimit
71 )
72 {
73 AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
74 }
75
76
77 VOID
78 AddMemoryBaseSizeHob (
79 EFI_PHYSICAL_ADDRESS MemoryBase,
80 UINT64 MemorySize
81 )
82 {
83 STATIC EFI_RESOURCE_ATTRIBUTE_TYPE Attributes =
84 (
85 EFI_RESOURCE_ATTRIBUTE_PRESENT |
86 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
87 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
88 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
89 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
90 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
91 EFI_RESOURCE_ATTRIBUTE_TESTED
92 );
93
94 BuildResourceDescriptorHob (
95 EFI_RESOURCE_SYSTEM_MEMORY,
96 Attributes,
97 MemoryBase,
98 MemorySize
99 );
100 }
101
102
103 VOID
104 AddMemoryRangeHob (
105 EFI_PHYSICAL_ADDRESS MemoryBase,
106 EFI_PHYSICAL_ADDRESS MemoryLimit
107 )
108 {
109 AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
110 }
111
112
113 VOID
114 MemMapInitialization (
115 )
116 {
117 //
118 // Create Memory Type Information HOB
119 //
120 BuildGuidDataHob (
121 &gEfiMemoryTypeInformationGuid,
122 mDefaultMemoryTypeInformation,
123 sizeof(mDefaultMemoryTypeInformation)
124 );
125
126 //
127 // Local APIC range
128 //
129 AddIoMemoryBaseSizeHob (0xFEC80000, 0x80000);
130
131 //
132 // I/O APIC range
133 //
134 AddIoMemoryBaseSizeHob (0xFEC00000, 0x80000);
135
136 //
137 // Video memory + Legacy BIOS region
138 //
139 AddMemoryRangeHob (0x0A0000, 0x0B0000);
140 AddIoMemoryRangeHob (0x0B0000, 0x100000);
141 }
142
143
144 VOID
145 MiscInitialization (
146 )
147 {
148 //
149 // Disable A20 Mask
150 //
151 IoWrite8 (0x92, (UINT8) (IoRead8 (0x92) | 0x02));
152
153 //
154 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
155 //
156 BuildCpuHob (36, 16);
157 }
158
159
160 /**
161 Perform Platform PEI initialization.
162
163 @param FileHandle Handle of the file being invoked.
164 @param PeiServices Describes the list of possible PEI Services.
165
166 @return EFI_SUCCESS The PEIM initialized successfully.
167
168 **/
169 EFI_STATUS
170 EFIAPI
171 InitializePlatform (
172 IN EFI_PEI_FILE_HANDLE FileHandle,
173 IN CONST EFI_PEI_SERVICES **PeiServices
174 )
175 {
176 DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));
177
178 MemDetect ();
179
180 PeiFvInitialization ();
181
182 MemMapInitialization ();
183
184 MiscInitialization ();
185
186 return EFI_SUCCESS;
187 }
188