From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.40435.1670305277713945636 for ; Mon, 05 Dec 2022 21:41:17 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=OCeTsd2+; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: zhiguang.liu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670305277; x=1701841277; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=h2rTEXWY/qOtCQlrmEfhS1tYOK6dIWdRRrZMja13BgA=; b=OCeTsd2+PcMpVl6ihALJgtp7FMUrkF4eUhSDKVvjnWRE8T5taBvFJY+E HHWmxNKgrQmJwGlWAeXa0sNiUeqyp6el7lNIqbwvM6vbbbFwqPW7jLJXX LYzDWx26rPhRnAWk5kNGoY/K5MxhScENGnh7JgiH6+GYihSeNlAE4aOiZ GY4tl4IOzvcV0IzHA5Hy2tTppgbCrErJgpSnkYo9nFwMhrBtODcILwmtB fgq02aa8uuoX+Wy1G+QH9OhfxfSiqy03XXoLB832uQmu7vsXkdETspuBQ aZ+bemsCUMAaJ6fUIGINR0X8J0jS+cwyBhIyHp8WVHn39NVQnZHg8rLuW w==; X-IronPort-AV: E=McAfee;i="6500,9779,10552"; a="296232565" X-IronPort-AV: E=Sophos;i="5.96,220,1665471600"; d="scan'208";a="296232565" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2022 21:41:17 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10552"; a="714671237" X-IronPort-AV: E=Sophos;i="5.96,220,1665471600"; d="scan'208";a="714671237" Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2022 21:41:15 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Andrew Fish , Ray Ni Subject: [PATCH 1/2] EmulatorPkg: Add persistent memory in EmuThunkPpi Date: Tue, 6 Dec 2022 13:40:52 +0800 Message-Id: <20221206054052.9910-1-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The persistent memory is for PEIM to use, and won't lose during cold or warm reset. PcdPersistentMemorySize is only used by WinHost.c, other modules can check the persistent memory size using the field PersistentMemorySize. Cc: Andrew Fish Cc: Ray Ni Signed-off-by: Zhiguang Liu --- EmulatorPkg/EmulatorPkg.dec | 3 ++- EmulatorPkg/Include/Ppi/EmuThunk.h | 4 +++- EmulatorPkg/Unix/Host/Host.c | 13 +++++++++++-- EmulatorPkg/Unix/Host/Host.inf | 3 ++- EmulatorPkg/Win/Host/WinHost.c | 11 ++++++++++- EmulatorPkg/Win/Host/WinHost.inf | 2 +- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/EmulatorPkg/EmulatorPkg.dec b/EmulatorPkg/EmulatorPkg.dec index b9c70b63b3..fe81652b04 100644 --- a/EmulatorPkg/EmulatorPkg.dec +++ b/EmulatorPkg/EmulatorPkg.dec @@ -2,7 +2,7 @@ # # This is the Emu Emulation Environment Platform # -# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.
# Portions copyright (c) 2011, Apple Inc. All rights reserved. # (C) Copyright 2020 Hewlett Packard Enterprise Development LP
# @@ -86,6 +86,7 @@ # The user ID and password are fixed as below. gEmulatorPkgTokenSpaceGuid.PcdRedfishServieUserId|"admin"|VOID*|0x00001022 gEmulatorPkgTokenSpaceGuid.PcdRedfishServiePassword|"pwd123456"|VOID*|0x00001023 + gEmulatorPkgTokenSpaceGuid.PcdPersistentMemorySize|0x4000000|UINT32|0x00001024 [PcdsFixedAtBuild, PcdsPatchableInModule] gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006 diff --git a/EmulatorPkg/Include/Ppi/EmuThunk.h b/EmulatorPkg/Include/Ppi/EmuThunk.h index c0e2bc6b98..cf29cf824c 100644 --- a/EmulatorPkg/Include/Ppi/EmuThunk.h +++ b/EmulatorPkg/Include/Ppi/EmuThunk.h @@ -2,7 +2,7 @@ Emulator Thunk to abstract OS services from pure EFI code Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.
- + Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -107,6 +107,8 @@ typedef struct { EMU_PEI_AUTOSCAN MemoryAutoScan; EMU_PEI_FD_INFORMATION FirmwareDevices; EMU_PEI_THUNK_INTERFACE Thunk; + UINTN PersistentMemorySize; + UINT8 PersistentMemory[0]; } EMU_THUNK_PPI; extern EFI_GUID gEmuThunkPpiGuid; diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c index 38c01c84af..8d0be5b54b 100644 --- a/EmulatorPkg/Unix/Host/Host.c +++ b/EmulatorPkg/Unix/Host/Host.c @@ -1,6 +1,6 @@ /*++ @file -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.
Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -102,6 +102,7 @@ main ( CHAR16 *FirmwareVolumesStr; UINTN *StackPointer; FILE *GdbTempFile; + EMU_THUNK_PPI *SecEmuThunkPpi; // // Xcode does not support sourcing gdb scripts directly, so the Xcode XML @@ -137,7 +138,15 @@ main ( // // PPIs pased into PEI_CORE // - AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi); + SecEmuThunkPpi = AllocateZeroPool (sizeof (EMU_THUNK_PPI) + FixedPcdGet32 (PcdPersistentMemorySize)); + if (SecEmuThunkPpi == NULL) { + printf ("ERROR : Can not allocate memory for SecEmuThunkPpi. Exiting.\n"); + exit (1); + } + + CopyMem (SecEmuThunkPpi, &mSecEmuThunkPpi, sizeof (EMU_THUNK_PPI)); + SecEmuThunkPpi->PersistentMemorySize = FixedPcdGet32 (PcdPersistentMemorySize); + AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, SecEmuThunkPpi); SecInitThunkProtocol (); diff --git a/EmulatorPkg/Unix/Host/Host.inf b/EmulatorPkg/Unix/Host/Host.inf index c479d2b7d0..f5ebbed683 100644 --- a/EmulatorPkg/Unix/Host/Host.inf +++ b/EmulatorPkg/Unix/Host/Host.inf @@ -2,7 +2,7 @@ # Entry Point of Emu Emulator # # Main executable file of Unix Emulator that loads PEI core after initialization finished. -# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.
# Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -106,6 +106,7 @@ gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage + gEmulatorPkgTokenSpaceGuid.PcdPersistentMemorySize [FeaturePcd] gEmulatorPkgTokenSpaceGuid.PcdEmulatorLazyLoadSymbols diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c index 096292f95a..3b2fde297d 100644 --- a/EmulatorPkg/Win/Host/WinHost.c +++ b/EmulatorPkg/Win/Host/WinHost.c @@ -436,6 +436,7 @@ Returns: UINTN SystemAffinityMask; INT32 LowBit; UINTN ResetJumpCode; + EMU_THUNK_PPI *SecEmuThunkPpi; // // Enable the privilege so that RTC driver can successfully run SetTime() @@ -477,7 +478,15 @@ Returns: // // PPIs pased into PEI_CORE // - AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi); + SecEmuThunkPpi = AllocateZeroPool (sizeof (EMU_THUNK_PPI) + FixedPcdGet32 (PcdPersistentMemorySize)); + if (SecEmuThunkPpi == NULL) { + SecPrint ("ERROR : Can not allocate memory for SecEmuThunkPpi. Exiting.\n"); + exit (1); + } + + CopyMem (SecEmuThunkPpi, &mSecEmuThunkPpi, sizeof (EMU_THUNK_PPI)); + SecEmuThunkPpi->PersistentMemorySize = FixedPcdGet32 (PcdPersistentMemorySize); + AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, SecEmuThunkPpi); AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiPeiReset2PpiGuid, &mEmuReset2Ppi); // diff --git a/EmulatorPkg/Win/Host/WinHost.inf b/EmulatorPkg/Win/Host/WinHost.inf index b61901fae2..4dac6e033e 100644 --- a/EmulatorPkg/Win/Host/WinHost.inf +++ b/EmulatorPkg/Win/Host/WinHost.inf @@ -74,7 +74,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack - + gEmulatorPkgTokenSpaceGuid.PcdPersistentMemorySize gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareVolume gEmulatorPkgTokenSpaceGuid.PcdEmuMemorySize -- 2.31.1.windows.1