]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/PlatformPei/MemTypeInfo.c
OvmfPkg/PlatformPei: don't track BS Code/Data in default MemTypeInfo HOB
[mirror_edk2.git] / OvmfPkg / PlatformPei / MemTypeInfo.c
CommitLineData
d42fdd6f
LE
1/** @file\r
2 Produce a default memory type information HOB unless we can determine, from\r
3 the existence of the "MemoryTypeInformation" variable, that the DXE IPL PEIM\r
4 will produce the HOB.\r
5\r
6 Copyright (C) 2017-2020, Red Hat, Inc.\r
7\r
8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
9**/\r
10\r
11#include <Guid/MemoryTypeInformation.h>\r
12#include <Library/BaseLib.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/HobLib.h>\r
15#include <Library/PcdLib.h>\r
16#include <Library/PeiServicesLib.h>\r
17#include <Ppi/ReadOnlyVariable2.h>\r
18#include <Uefi/UefiMultiPhase.h>\r
19\r
20#include "Platform.h"\r
21\r
912718d8
LE
22//\r
23// The NumberOfPages values below are ad-hoc. They are updated sporadically at\r
24// best (please refer to git-blame for past updates). The values capture a set\r
25// of BIN hints that made sense at a particular time, for some (now likely\r
26// unknown) workloads / boot paths.\r
27//\r
d42fdd6f
LE
28STATIC EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {\r
29 { EfiACPIMemoryNVS, 0x004 },\r
30 { EfiACPIReclaimMemory, 0x008 },\r
31 { EfiReservedMemoryType, 0x004 },\r
32 { EfiRuntimeServicesData, 0x024 },\r
33 { EfiRuntimeServicesCode, 0x030 },\r
d42fdd6f
LE
34 { EfiMaxMemoryType, 0x000 }\r
35};\r
36\r
37STATIC\r
38VOID\r
39BuildMemTypeInfoHob (\r
40 VOID\r
41 )\r
42{\r
43 BuildGuidDataHob (\r
44 &gEfiMemoryTypeInformationGuid,\r
45 mDefaultMemoryTypeInformation,\r
46 sizeof mDefaultMemoryTypeInformation\r
47 );\r
48 DEBUG ((DEBUG_INFO, "%a: default memory type information HOB built\n",\r
49 __FUNCTION__));\r
50}\r
51\r
52/**\r
53 Notification function called when EFI_PEI_READ_ONLY_VARIABLE2_PPI becomes\r
54 available.\r
55\r
56 @param[in] PeiServices Indirect reference to the PEI Services Table.\r
57 @param[in] NotifyDescriptor Address of the notification descriptor data\r
58 structure.\r
59 @param[in] Ppi Address of the PPI that was installed.\r
60\r
61 @return Status of the notification. The status code returned from this\r
62 function is ignored.\r
63**/\r
64STATIC\r
65EFI_STATUS\r
66EFIAPI\r
67OnReadOnlyVariable2Available (\r
68 IN EFI_PEI_SERVICES **PeiServices,\r
69 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
70 IN VOID *Ppi\r
71 )\r
72{\r
73 EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariable2;\r
74 UINTN DataSize;\r
75 EFI_STATUS Status;\r
76\r
77 DEBUG ((DEBUG_VERBOSE, "%a\n", __FUNCTION__));\r
78\r
79 //\r
80 // Check if the "MemoryTypeInformation" variable exists, in the\r
81 // gEfiMemoryTypeInformationGuid namespace.\r
82 //\r
83 ReadOnlyVariable2 = Ppi;\r
84 DataSize = 0;\r
85 Status = ReadOnlyVariable2->GetVariable (\r
86 ReadOnlyVariable2,\r
87 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
88 &gEfiMemoryTypeInformationGuid,\r
89 NULL,\r
90 &DataSize,\r
91 NULL\r
92 );\r
93 switch (Status) {\r
94 case EFI_BUFFER_TOO_SMALL:\r
95 //\r
96 // The variable exists; the DXE IPL PEIM will build the HOB from it.\r
97 //\r
98 break;\r
99 case EFI_NOT_FOUND:\r
100 //\r
101 // The variable does not exist; install the default memory type information\r
102 // HOB.\r
103 //\r
104 BuildMemTypeInfoHob ();\r
105 break;\r
106 default:\r
107 DEBUG ((DEBUG_ERROR, "%a: unexpected: GetVariable(): %r\n", __FUNCTION__,\r
108 Status));\r
109 ASSERT (FALSE);\r
110 CpuDeadLoop ();\r
111 break;\r
112 }\r
113\r
114 return EFI_SUCCESS;\r
115}\r
116\r
117//\r
118// Notification object for registering the callback, for when\r
119// EFI_PEI_READ_ONLY_VARIABLE2_PPI becomes available.\r
120//\r
121STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mReadOnlyVariable2Notify = {\r
122 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH |\r
123 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), // Flags\r
124 &gEfiPeiReadOnlyVariable2PpiGuid, // Guid\r
125 OnReadOnlyVariable2Available // Notify\r
126};\r
127\r
128VOID\r
129MemTypeInfoInitialization (\r
130 VOID\r
131 )\r
132{\r
133 EFI_STATUS Status;\r
134\r
135 if (!FeaturePcdGet (PcdSmmSmramRequire)) {\r
136 //\r
137 // EFI_PEI_READ_ONLY_VARIABLE2_PPI will never be available; install\r
138 // the default memory type information HOB right away.\r
139 //\r
140 BuildMemTypeInfoHob ();\r
141 return;\r
142 }\r
143\r
144 Status = PeiServicesNotifyPpi (&mReadOnlyVariable2Notify);\r
145 if (EFI_ERROR (Status)) {\r
146 DEBUG ((DEBUG_ERROR, "%a: failed to set up R/O Variable 2 callback: %r\n",\r
147 __FUNCTION__, Status));\r
148 ASSERT (FALSE);\r
149 CpuDeadLoop ();\r
150 }\r
151}\r