From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web09.1518.1668225663457832422 for ; Fri, 11 Nov 2022 20:01:04 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=fCgTQ7K/; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668225664; x=1699761664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kGvDHxoRZXhn868rObj9lzoA2tobh5Rsa80bAVqBfwU=; b=fCgTQ7K/fn73C5ZOgDhVG7+m7sYNcRm7gPJ6IwEms2min8XX6U2EWaBL QnK3ptjJY1YhfWdmKChJw+ps+Rv6U9ekSU/nNCPlgK+mgvAo7nSh3zs4q XVVkkPssPrbpUyTSjoOU2A8y23jl+2M589Atnic99jbpkdffLua9r2LDq hdgvUIGkIoUxHkX8KYY68PuozLCnG5C4JohK3yAlfiW4SnkK01G5FEUvn xmTmORWfC3Ufl8rl15evvsiHkMZi73ILts5aiFa3QRvt0JqQs/EKWpH11 NdVqJdVNPxsoFqoXXGj/lIf0bsFq8C2vAlpv/SGOUjS6z2dL6lIVxut54 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="373827653" X-IronPort-AV: E=Sophos;i="5.96,158,1665471600"; d="scan'208";a="373827653" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2022 20:01:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="588725581" X-IronPort-AV: E=Sophos;i="5.96,158,1665471600"; d="scan'208";a="588725581" Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.56.10]) by orsmga003.jf.intel.com with ESMTP; 11 Nov 2022 20:00:49 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Andrew Fish , Zhiguang Liu Subject: [PATCH 3/3] EmulatorPkg/WinHost: Add Reset2 PPI Date: Sat, 12 Nov 2022 12:00:42 +0800 Message-Id: <20221112040042.741-4-ray.ni@intel.com> X-Mailer: git-send-email 2.37.2.windows.2 In-Reply-To: <20221112040042.741-1-ray.ni@intel.com> References: <20221112040042.741-1-ray.ni@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable When shutdown is requested, WinHost exits. Otherwise, WinHost re-runs from SEC. Tested no extra memory consumption with multiple resets in PEI. Signed-off-by: Ray Ni Cc: Andrew Fish Cc: Zhiguang Liu --- EmulatorPkg/Win/Host/WinHost.c | 75 ++++++++++++++++++++++++++++---- EmulatorPkg/Win/Host/WinHost.h | 3 +- EmulatorPkg/Win/Host/WinHost.inf | 3 +- 3 files changed, 71 insertions(+), 10 deletions(-) diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c index 9b10290ff3..32b6922307 100644 --- a/EmulatorPkg/Win/Host/WinHost.c +++ b/EmulatorPkg/Win/Host/WinHost.c @@ -56,6 +56,14 @@ NT_FD_INFO *gFdInfo; UINTN gSystemMemoryCount =3D 0;=0D NT_SYSTEM_MEMORY *gSystemMemory;=0D =0D +BASE_LIBRARY_JUMP_BUFFER mResetJumpBuffer;=0D +CHAR8 *mResetTypeStr[] =3D {=0D + "EfiResetCold",=0D + "EfiResetWarm",=0D + "EfiResetShutdown",=0D + "EfiResetPlatformSpecific"=0D +};=0D +=0D /*++=0D =0D Routine Description:=0D @@ -196,6 +204,45 @@ SecPrint ( );=0D }=0D =0D +/**=0D + Resets the entire platform.=0D +=0D + @param[in] ResetType The type of reset to perform.=0D + @param[in] ResetStatus The status code for the reset.=0D + @param[in] DataSize The size, in bytes, of ResetData.=0D + @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm,= or EfiResetShutdown=0D + the data buffer starts with a Null-terminated = string, optionally=0D + followed by additional binary data. The string= is a description=0D + that the caller may use to further indicate th= e reason for the=0D + system reset.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +WinReset (=0D + IN EFI_RESET_TYPE ResetType,=0D + IN EFI_STATUS ResetStatus,=0D + IN UINTN DataSize,=0D + IN VOID *ResetData OPTIONAL=0D + )=0D +{=0D + ASSERT (ResetType <=3D EfiResetPlatformSpecific);=0D + SecPrint (" Emu ResetSystem is called: ResetType =3D %s\n", mResetTypeS= tr[ResetType]);=0D +=0D + if (ResetType =3D=3D EfiResetShutdown) {=0D + exit (0);=0D + } else {=0D + //=0D + // Jump back to SetJump with jump code =3D ResetType + 1=0D + //=0D + LongJump (&mResetJumpBuffer, ResetType + 1);=0D + }=0D +}=0D +=0D +EFI_PEI_RESET2_PPI mEmuReset2Ppi =3D {=0D + WinReset=0D +};=0D +=0D /*++=0D =0D Routine Description:=0D @@ -388,6 +435,7 @@ Returns: UINTN ProcessAffinityMask;=0D UINTN SystemAffinityMask;=0D INT32 LowBit;=0D + UINTN ResetJumpCode;=0D =0D //=0D // Enable the privilege so that RTC driver can successfully run SetTime(= )=0D @@ -430,6 +478,7 @@ Returns: // PPIs pased into PEI_CORE=0D //=0D AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThun= kPpi);=0D + AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiPeiReset2PpiGuid, &mEmuRes= et2Ppi);=0D =0D //=0D // Emulator Bus Driver Thunks=0D @@ -500,14 +549,6 @@ Returns: exit (1);=0D }=0D =0D - SetMem32 (TemporaryRam, TemporaryRamSize, PcdGet32 (PcdInitValueInTempSt= ack));=0D -=0D - SecPrint (=0D - " OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n\r",=0D - TemporaryRamSize / SIZE_1KB,=0D - TemporaryRam=0D - );=0D -=0D //=0D // If enabled use the magic page to communicate between modules=0D // This replaces the PI PeiServicesTable pointer mechanism that=0D @@ -591,6 +632,24 @@ Returns: SecPrint ("\n\r");=0D }=0D =0D + ResetJumpCode =3D SetJump (&mResetJumpBuffer);=0D +=0D + //=0D + // Do not clear memory content for warm reset.=0D + //=0D + if (ResetJumpCode !=3D EfiResetWarm + 1) {=0D + SecPrint (" OS Emulator clearing temp RAM and physical RAM (to be dis= covered later)......\n\r");=0D + SetMem32 (TemporaryRam, TemporaryRamSize, PcdGet32 (PcdInitValueInTemp= Stack));=0D + for (Index =3D 0; Index < gSystemMemoryCount; Index++) {=0D + SetMem32 ((VOID *)(UINTN)gSystemMemory[Index].Memory, gSystemMemory[= Index].Size, PcdGet32 (PcdInitValueInTempStack));=0D + }=0D + }=0D +=0D + SecPrint (=0D + " OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n\r",=0D + TemporaryRamSize / SIZE_1KB,=0D + TemporaryRam=0D + );=0D //=0D // Hand off to SEC Core=0D //=0D diff --git a/EmulatorPkg/Win/Host/WinHost.h b/EmulatorPkg/Win/Host/WinHost.h index 49d42d1ad8..a9a21007e3 100644 --- a/EmulatorPkg/Win/Host/WinHost.h +++ b/EmulatorPkg/Win/Host/WinHost.h @@ -1,6 +1,6 @@ /**@file=0D =0D -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.
=0D (C) Copyright 2020 Hewlett Packard Enterprise Development LP
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -26,6 +26,7 @@ Abstract: #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D =0D diff --git a/EmulatorPkg/Win/Host/WinHost.inf b/EmulatorPkg/Win/Host/WinHos= t.inf index 2030ac0847..b61901fae2 100644 --- a/EmulatorPkg/Win/Host/WinHost.inf +++ b/EmulatorPkg/Win/Host/WinHost.inf @@ -2,7 +2,7 @@ # Entry Point of Win Emulator=0D #=0D # Main executable file of Win Emulator that loads Sec core after initializ= ation finished.=0D -# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.
=0D # Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.
= =0D # (C) Copyright 2020 Hewlett Packard Enterprise Development LP
=0D #=0D @@ -58,6 +58,7 @@ =0D [Ppis]=0D gEmuThunkPpiGuid=0D + gEfiPeiReset2PpiGuid=0D =0D [Protocols]=0D gEmuIoThunkProtocolGuid=0D --=20 2.37.2.windows.2