--- /dev/null
+/** @file\r
+ Produce a default memory type information HOB unless we can determine, from\r
+ the existence of the "MemoryTypeInformation" variable, that the DXE IPL PEIM\r
+ will produce the HOB.\r
+\r
+ Copyright (C) 2017-2020, Red Hat, Inc.\r
+\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Guid/MemoryTypeInformation.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Ppi/ReadOnlyVariable2.h>\r
+#include <Uefi/UefiMultiPhase.h>\r
+\r
+#include "Platform.h"\r
+\r
+STATIC EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {\r
+ { EfiACPIMemoryNVS, 0x004 },\r
+ { EfiACPIReclaimMemory, 0x008 },\r
+ { EfiReservedMemoryType, 0x004 },\r
+ { EfiRuntimeServicesData, 0x024 },\r
+ { EfiRuntimeServicesCode, 0x030 },\r
+ { EfiBootServicesCode, 0x180 },\r
+ { EfiBootServicesData, 0xF00 },\r
+ { EfiMaxMemoryType, 0x000 }\r
+};\r
+\r
+STATIC\r
+VOID\r
+BuildMemTypeInfoHob (\r
+ VOID\r
+ )\r
+{\r
+ BuildGuidDataHob (\r
+ &gEfiMemoryTypeInformationGuid,\r
+ mDefaultMemoryTypeInformation,\r
+ sizeof mDefaultMemoryTypeInformation\r
+ );\r
+ DEBUG ((DEBUG_INFO, "%a: default memory type information HOB built\n",\r
+ __FUNCTION__));\r
+}\r
+\r
+/**\r
+ Notification function called when EFI_PEI_READ_ONLY_VARIABLE2_PPI becomes\r
+ available.\r
+\r
+ @param[in] PeiServices Indirect reference to the PEI Services Table.\r
+ @param[in] NotifyDescriptor Address of the notification descriptor data\r
+ structure.\r
+ @param[in] Ppi Address of the PPI that was installed.\r
+\r
+ @return Status of the notification. The status code returned from this\r
+ function is ignored.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+OnReadOnlyVariable2Available (\r
+ IN EFI_PEI_SERVICES **PeiServices,\r
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
+ IN VOID *Ppi\r
+ )\r
+{\r
+ EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariable2;\r
+ UINTN DataSize;\r
+ EFI_STATUS Status;\r
+\r
+ DEBUG ((DEBUG_VERBOSE, "%a\n", __FUNCTION__));\r
+\r
+ //\r
+ // Check if the "MemoryTypeInformation" variable exists, in the\r
+ // gEfiMemoryTypeInformationGuid namespace.\r
+ //\r
+ ReadOnlyVariable2 = Ppi;\r
+ DataSize = 0;\r
+ Status = ReadOnlyVariable2->GetVariable (\r
+ ReadOnlyVariable2,\r
+ EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
+ &gEfiMemoryTypeInformationGuid,\r
+ NULL,\r
+ &DataSize,\r
+ NULL\r
+ );\r
+ switch (Status) {\r
+ case EFI_BUFFER_TOO_SMALL:\r
+ //\r
+ // The variable exists; the DXE IPL PEIM will build the HOB from it.\r
+ //\r
+ break;\r
+ case EFI_NOT_FOUND:\r
+ //\r
+ // The variable does not exist; install the default memory type information\r
+ // HOB.\r
+ //\r
+ BuildMemTypeInfoHob ();\r
+ break;\r
+ default:\r
+ DEBUG ((DEBUG_ERROR, "%a: unexpected: GetVariable(): %r\n", __FUNCTION__,\r
+ Status));\r
+ ASSERT (FALSE);\r
+ CpuDeadLoop ();\r
+ break;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// Notification object for registering the callback, for when\r
+// EFI_PEI_READ_ONLY_VARIABLE2_PPI becomes available.\r
+//\r
+STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mReadOnlyVariable2Notify = {\r
+ (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH |\r
+ EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), // Flags\r
+ &gEfiPeiReadOnlyVariable2PpiGuid, // Guid\r
+ OnReadOnlyVariable2Available // Notify\r
+};\r
+\r
+VOID\r
+MemTypeInfoInitialization (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (!FeaturePcdGet (PcdSmmSmramRequire)) {\r
+ //\r
+ // EFI_PEI_READ_ONLY_VARIABLE2_PPI will never be available; install\r
+ // the default memory type information HOB right away.\r
+ //\r
+ BuildMemTypeInfoHob ();\r
+ return;\r
+ }\r
+\r
+ Status = PeiServicesNotifyPpi (&mReadOnlyVariable2Notify);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "%a: failed to set up R/O Variable 2 callback: %r\n",\r
+ __FUNCTION__, Status));\r
+ ASSERT (FALSE);\r
+ CpuDeadLoop ();\r
+ }\r
+}\r
#include <Library/QemuFwCfgLib.h>\r
#include <Library/QemuFwCfgS3Lib.h>\r
#include <Library/ResourcePublicationLib.h>\r
-#include <Guid/MemoryTypeInformation.h>\r
#include <Ppi/MasterBootMode.h>\r
#include <IndustryStandard/I440FxPiix4.h>\r
#include <IndustryStandard/Pci22.h>\r
#include "Platform.h"\r
#include "Cmos.h"\r
\r
-EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {\r
- { EfiACPIMemoryNVS, 0x004 },\r
- { EfiACPIReclaimMemory, 0x008 },\r
- { EfiReservedMemoryType, 0x004 },\r
- { EfiRuntimeServicesData, 0x024 },\r
- { EfiRuntimeServicesCode, 0x030 },\r
- { EfiBootServicesCode, 0x180 },\r
- { EfiBootServicesData, 0xF00 },\r
- { EfiMaxMemoryType, 0x000 }\r
-};\r
-\r
-\r
EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] = {\r
{\r
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
PciIoBase = 0xC000;\r
PciIoSize = 0x4000;\r
\r
- //\r
- // Create Memory Type Information HOB\r
- //\r
- BuildGuidDataHob (\r
- &gEfiMemoryTypeInformationGuid,\r
- mDefaultMemoryTypeInformation,\r
- sizeof(mDefaultMemoryTypeInformation)\r
- );\r
-\r
//\r
// Video memory + Legacy BIOS region\r
//\r
ReserveEmuVariableNvStore ();\r
}\r
PeiFvInitialization ();\r
+ MemTypeInfoInitialization ();\r
MemMapInitialization ();\r
NoexecDxeInitialization ();\r
}\r