VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/Fv.c@ 85716

Last change on this file since 85716 was 82249, checked in by vboxsync, 5 years ago

EFI/Firmware: Relocate the DXE FV volume to the top of the RAM once the memory is initialized to not interfer with older OS X bootloaders which try to allocate memory in that area

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/** @file
2 Build FV related hobs for platform.
3
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include "PiPei.h"
10#include "Platform.h"
11#include <Library/DebugLib.h>
12#include <Library/HobLib.h>
13#include <Library/PeiServicesLib.h>
14#include <Library/PcdLib.h>
15
16#include <Library/BaseMemoryLib.h>
17
18/**
19 Publish PEI & DXE (Decompressed) Memory based FVs to let PEI
20 and DXE know about them.
21
22 @retval EFI_SUCCESS Platform PEI FVs were initialized successfully.
23
24**/
25EFI_STATUS
26PeiFvInitialization (
27 VOID
28 )
29{
30 BOOLEAN SecureS3Needed;
31#ifdef VBOX
32 EFI_PHYSICAL_ADDRESS PhysOvmfDxeMemFvBaseRelocated = 0;
33 VOID *OvmfDxeMemFvBaseRelocated;
34#endif
35
36 DEBUG ((EFI_D_INFO, "Platform PEI Firmware Volume Initialization\n"));
37
38#ifdef VBOX
39 /*
40 * Relocate the DXE firmware to the top of the RAM so it doesn't interfer with older OS X bootloaders
41 * trying to allocate memory in the area where MEMFD is currently residing.
42 */
43 PeiServicesAllocatePages (EfiRuntimeServicesCode,
44 EFI_SIZE_TO_PAGES(PcdGet32 (PcdOvmfDxeMemFvSize)),
45 &PhysOvmfDxeMemFvBaseRelocated);
46
47 OvmfDxeMemFvBaseRelocated = (VOID *)(UINTN)PhysOvmfDxeMemFvBaseRelocated;
48 CopyMem (OvmfDxeMemFvBaseRelocated, (VOID *)(UINTN)PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSize));
49
50 //
51 // Let DXE know about the DXE FV
52 //
53 BuildFvHob (PhysOvmfDxeMemFvBaseRelocated, PcdGet32 (PcdOvmfDxeMemFvSize));
54
55 SecureS3Needed = mS3Supported && FeaturePcdGet (PcdSmmSmramRequire);
56
57 //
58 // Create a memory allocation HOB for the DXE FV.
59 //
60 // If "secure" S3 is needed, then SEC will decompress both PEI and DXE
61 // firmware volumes at S3 resume too, hence we need to keep away the OS from
62 // DXEFV as well. Otherwise we only need to keep away DXE itself from the
63 // DXEFV area.
64 //
65 BuildMemoryAllocationHob (
66 PhysOvmfDxeMemFvBaseRelocated,
67 PcdGet32 (PcdOvmfDxeMemFvSize),
68 SecureS3Needed ? EfiACPIMemoryNVS : EfiBootServicesData
69 );
70
71 //
72 // Let PEI know about the DXE FV so it can find the DXE Core
73 //
74 PeiServicesInstallFvInfoPpi (
75 NULL,
76 (VOID *)(UINTN)OvmfDxeMemFvBaseRelocated,
77 PcdGet32 (PcdOvmfDxeMemFvSize),
78 NULL,
79 NULL
80 );
81#else
82
83 //
84 // Create a memory allocation HOB for the PEI FV.
85 //
86 // Allocate as ACPI NVS is S3 is supported
87 //
88 BuildMemoryAllocationHob (
89 PcdGet32 (PcdOvmfPeiMemFvBase),
90 PcdGet32 (PcdOvmfPeiMemFvSize),
91 mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData
92 );
93
94 //
95 // Let DXE know about the DXE FV
96 //
97 BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSize));
98
99 SecureS3Needed = mS3Supported && FeaturePcdGet (PcdSmmSmramRequire);
100
101 //
102 // Create a memory allocation HOB for the DXE FV.
103 //
104 // If "secure" S3 is needed, then SEC will decompress both PEI and DXE
105 // firmware volumes at S3 resume too, hence we need to keep away the OS from
106 // DXEFV as well. Otherwise we only need to keep away DXE itself from the
107 // DXEFV area.
108 //
109 BuildMemoryAllocationHob (
110 PcdGet32 (PcdOvmfDxeMemFvBase),
111 PcdGet32 (PcdOvmfDxeMemFvSize),
112 SecureS3Needed ? EfiACPIMemoryNVS : EfiBootServicesData
113 );
114
115 //
116 // Additionally, said decompression will use temporary memory above the end
117 // of DXEFV, so let's keep away the OS from there too.
118 //
119 if (SecureS3Needed) {
120 UINT32 DxeMemFvEnd;
121
122 DxeMemFvEnd = PcdGet32 (PcdOvmfDxeMemFvBase) +
123 PcdGet32 (PcdOvmfDxeMemFvSize);
124 BuildMemoryAllocationHob (
125 DxeMemFvEnd,
126 PcdGet32 (PcdOvmfDecompressionScratchEnd) - DxeMemFvEnd,
127 EfiACPIMemoryNVS
128 );
129 }
130
131 //
132 // Let PEI know about the DXE FV so it can find the DXE Core
133 //
134 PeiServicesInstallFvInfoPpi (
135 NULL,
136 (VOID *)(UINTN) PcdGet32 (PcdOvmfDxeMemFvBase),
137 PcdGet32 (PcdOvmfDxeMemFvSize),
138 NULL,
139 NULL
140 );
141#endif
142
143 return EFI_SUCCESS;
144}
145
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette