From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.12672.1671419019722248805 for ; Sun, 18 Dec 2022 19:03:39 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=dDZ/l6+q; spf=pass (domain: intel.com, ip: 192.55.52.115, 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=1671419019; x=1702955019; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=hqiIkWLs9fcjV+7JpRT8+bqhsh5jabgZlR7JKmc1wgo=; b=dDZ/l6+qrIAObLCSk8AmhySijVIm2/6r/VlnUawa4ffMbF9Gn9Ajq2/R 9zSR8YmE+MrV/46/OKwUnHWCTRv+GiH0bJN1NW2YvEVJ2Mujkj2F6elTG G5Ji7D8or06o4KftWmIiwvO6IWXdOlH+uIYouRrl5xxNCQ1Qtyb+Nf/lG 3qalLIX/mUIctD7KtN6UvdhPzZSutcHFr7ClsB8mYC/4TAaBDOL3ioT11 nD6ElPnEonL0+GYsmOIjdYsfjiCUkhrlkhdE/f5hBF1fergqVW7GADEDn LFvExrbaflTCa4aefThkjZmdab5Bp5VccBFd8RwDJ22bg8pipWOMuxeKJ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10565"; a="319307369" X-IronPort-AV: E=Sophos;i="5.96,254,1665471600"; d="scan'208";a="319307369" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2022 19:03:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10565"; a="650402951" X-IronPort-AV: E=Sophos;i="5.96,254,1665471600"; d="scan'208";a="650402951" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga002.jf.intel.com with ESMTP; 18 Dec 2022 19:03:38 -0800 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Sun, 18 Dec 2022 19:03:38 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Sun, 18 Dec 2022 19:03:38 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.177) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Sun, 18 Dec 2022 19:03:37 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R2HSF0+HfiqjW1noSuX+l8MDA5IdTiN0xu1QjZaC7TYR5TmSQALhysdE+34Z61gDJn5NHmSjNkikm4a6B1A6Nb80ALel/pZCqApd+em5vPt0y9fJcjk6yj6N8c3OzPUVNTaUW3I/JQpSLmPjC7hY9Ry4pZVSIWODUMJrjQ1U49aKKKflM/tF/Mc7SzoQs2JGbKqLLm62uRmLe+Nh4JWp/TVI10aFGw94SbOi9bLQAB8N8W2DkP6n6v5hqxcCYKGcrK3ikwGTvB1353RlPrvHCJHeiajWTLs7PaXN/clT4kAehY7yGlPoiO7c/V68WBP17S2ysZMdYAAvbwVF02qM+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vO50EICtNBav8vjqhvFc7r6HPisJn2QCH+z17KMeRdw=; b=jkhHb37Gh0kxScWkUikiO+zeurKTINGfrP4A40QV0WMs2g2fgWOtKHqH3ghhClwOMqUMDnfC33IJlYpoH/8NLqTz3jwd3wxmFf/eMzQ09e4wT1OJEtJIMSf2Y3ZrVZG9QcXaB5qeRBx4gYmQABuAu+SJC4JkhO4I7KhcOvRW2cvz7mX5N3ygSW0xC+PiX3LMo3CMdPtb1QudweWzuUhwFPhsOzVqPPU44Ju48H8qgQrslJrj2U/TO3A+GFCpvzLwXZODuJ3COADDujyZKG54aPV5P0vFIrtvrW22tubrRKFe1uoyBXCLIX4QQ8WzNeVzsfSNmxtaI36tMwuQDzPYHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MWHPR11MB1631.namprd11.prod.outlook.com (2603:10b6:301:10::10) by SJ0PR11MB5630.namprd11.prod.outlook.com (2603:10b6:a03:3bb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Mon, 19 Dec 2022 03:03:35 +0000 Received: from MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::994e:d3c4:7608:3405]) by MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::994e:d3c4:7608:3405%4]) with mapi id 15.20.5924.016; Mon, 19 Dec 2022 03:03:35 +0000 From: "Ni, Ray" To: "Kuo, Ted" , "devel@edk2.groups.io" CC: "Liu, Zhiguang" , "Chiu, Chasel" , "Desimone, Nathaniel L" , "Zeng, Star" , "S, Ashraf Ali" , "Duggapu, Chinni B" Subject: Re: [edk2-devel][PATCH v2 1/2] UefiCpuPkg: Supporting S3 in 64bit PEI Thread-Topic: [edk2-devel][PATCH v2 1/2] UefiCpuPkg: Supporting S3 in 64bit PEI Thread-Index: AQHZEUyFZr99T/OllUOhKt4RAJWQdq50ijcw Date: Mon, 19 Dec 2022 03:03:35 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MWHPR11MB1631:EE_|SJ0PR11MB5630:EE_ x-ms-office365-filtering-correlation-id: eb62bb13-3f1c-45f2-8d10-08dae16d9ea5 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: OMnCHrdIAEYhEjw4HeDbh60uGQ/wPJC5bScB0lL7p8kZeKBoZqmq4XYJ4ThxDe+e+kutOsf1Bd+qct9QDzM4Ah3PmZ/tUG64Zwie1xJ1voLM7fPXFH+YWVVtnqBET1Fos8oIXwU9ReisX5mX3uTiJalOCmtpFnRF4F9mwHEDW0MeVgBvKsurrG0Qelo2NOU7CatVgxiUhVjEpcsHttQ4OKBpVQa3AvIIQPR9KmkOJCeJRzutkZKS2RrwVQb0kgI4f0jsSbWAw57FDDY8J7ffUmmgqb8SRc7UKxhxXEsaO/Ul+RFCA4Mhj5hdZQMOW6ptlnw7PvnIMzmBOOFmuAKpJCfiZqwMx73iY65SfMfplxIFpLb8ebybsF4QOCnSaWEWmyC/8fHWdaDd043MwR0NHUnRI1yyrss4WIhYusY+nENgt0mnSKMUNFM10PNn4mBq5BxOsj5TBNAHN8Qsi5AA2qx/n8RkaSn+QHasDHrlfLT/2PCzfp4QWHnMKnT0bkmfgNB/Cps5Y7j2R0gi7y2e35I/IS9iKll7zNDmE6j3h7ffHjSPMT8YZl3gs31hCm6UJ0QJhb6lN4UJwda4EESWrW/2rYhazd6IFUr9Uhaib91UM3jlJgyZk4jqpts416IqDDZgtZucsob7RoGG+6H9SIWMD6BSXjgUqET6z56EWM0t2EyMs142Uw3jpI4PbKJ/n0cJU76W6R/MjA6eUli2L8gtVjApr5kqEa9dedzer7E= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1631.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(39860400002)(376002)(366004)(136003)(396003)(451199015)(107886003)(53546011)(6506007)(966005)(478600001)(71200400001)(7696005)(82960400001)(9686003)(26005)(38100700002)(186003)(122000001)(110136005)(33656002)(41300700001)(30864003)(54906003)(19627235002)(55016003)(316002)(2906002)(66446008)(66946007)(66556008)(66476007)(64756008)(4326008)(8676002)(76116006)(38070700005)(8936002)(83380400001)(86362001)(52536014)(5660300002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?g3dCehBJuQGc/YIMqNGn6BiK/QrlYVqVMrWfVqvoO+YnQyYs1h2455cXD9FA?= =?us-ascii?Q?70zrbnYk+rilr9XdIRP7Tiqj733LR+2EMcXEDLfUNCmsL4nkHaAbmik3P7H1?= =?us-ascii?Q?0UekhAEYpXDy2rut411FWoGyDCOkBYX9PDUKfVk/YbLnDpZTs3qsD5NPFBIE?= =?us-ascii?Q?WEAI/Uls/54N9rupOe1C3kNbrtrOE4VUqM48BgB80UreDDadh09qS9f0V5Fu?= =?us-ascii?Q?s7QIV4r2q4bVq3UUxeuttjZGn3LMnnqWlq6pRp5KZP8LynZtSr7zIgIPxydH?= =?us-ascii?Q?mCntvHrlJOEs568SDvCuHkeTnPr+aCsWAkFcNP4PWAKDGhPCD+lcHDU9proo?= =?us-ascii?Q?ri8QrVpUL9L7d9CQSWY1OeqJYW4lEU895IX/787NZYUprU2mDOuDFTZlNdL3?= =?us-ascii?Q?At289ReHkV5Xm5uSzafUkpRa5qDL82rDXVC2fRUrRc69UmCFu0aoWAbaVnC2?= =?us-ascii?Q?uSCrdm0jQpUAyttsJ1lodt5Rj4WaBLEm+x53lZ4QKWaveqO/FF8YKE+/Xjzw?= =?us-ascii?Q?xpP6E4dwEdfqrW32Rirx0ZlzOlvwLdOyY7LFbDnHGDXrp7X2LFw2h22Xl358?= =?us-ascii?Q?RI6IYf15qTljL6oJDBCPUOEW9LZ4JivNYoezEbqLJNKhDy/DuChXnodlu/bK?= =?us-ascii?Q?xUE68shPfnwTS6ZyKHZat2Wud3IAyaRTigMUZhd43wup/kogXbh6TfT38sbv?= =?us-ascii?Q?iXVnhZvlvSJ66OHb4/oLs7TUywm0GffDjO/10jOeDjnOsgVR/xzR7nqv6KjP?= =?us-ascii?Q?YLqBmPMZz6m7ehJAAl2nVy8lCjXXzXxjA7F8k0adpq78GWnTNTGz/aqNp1wv?= =?us-ascii?Q?nfK3/bJvKL66KN+NkDgI7vLZ130G6tAHdEet+uGnStrtYWQhj5P2/CPcluIr?= =?us-ascii?Q?xppmORu1hJK/6nv3pgiuddoJD217JDgZlJ5u7l1SqWIuIOkGXJGAW+i4tXDa?= =?us-ascii?Q?6tfhuTUlLtB05pftewh8o2QxPfyFrdPqJ1NXrxvfwJHqQXJx3QMfKL6Vfd4a?= =?us-ascii?Q?bJRXfJ+7MhqSCY9g+lWe23+bwghrKZrIt9ddyVl93omzPlAO7IKuSCwPF1Q5?= =?us-ascii?Q?Yz/zSJ/qOlhwqjvpjBMWOy/PUetGmv+uZHlYlh+mxST0VTbXA6qlvSIVPYKE?= =?us-ascii?Q?TQTx2fmlaCX6T1tfUGizwS9Qt+jkRasmyGASRPoLumaGzi6J97njrHeCGPCA?= =?us-ascii?Q?eYuJS2RelIKHglsoIt7sWUi+iO3UAlPdkObRUbJ+IPlCCS7TMxvIyT/QYqcX?= =?us-ascii?Q?ElquXC/fot5TTYDNZ8RQOR707nA6hF8deQB/u8B9kl9ryf3FcNnkQtiElfKp?= =?us-ascii?Q?cKOzO/n8i+OKhAD6BUI0yvgDoI2KdPyscFnrejQ9WSFsuJZDU475wpOPcE16?= =?us-ascii?Q?PC2XG+5mATzXNfUJkkEIOqR0G3L0sigvRsP6hz2AVDGppOX+YFhC1TfwKCXA?= =?us-ascii?Q?ApPK2ne1nQ+Vm80+zhGujiUCOdYi7BO5sBVLdIoEWdj+4X3ui3koCteJ6cg5?= =?us-ascii?Q?e1ltVWAgLstGP7UTEGchUk5piDV+hjocI0pDBapCHu3gmjaPxSOxHJwQVDJD?= =?us-ascii?Q?zBvsVfleo8zW4gSxy1o=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1631.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb62bb13-3f1c-45f2-8d10-08dae16d9ea5 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2022 03:03:35.5524 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: lo+JaiIVpZte1Iic/RPGj/ZUmQyKW4matCgaLv6hJMF6HWNAVa/r2I+8QhQo0GY4xdbmoAUbeUgV9ww/ZxBQBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5630 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ted, Can you run uncrustify local? I still see TAB in the patch. > -----Original Message----- > From: Kuo, Ted > Sent: Friday, December 16, 2022 8:46 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Liu, Zhiguang ; C= hiu, Chasel ; Desimone, > Nathaniel L ; Zeng, Star ; S, Ashraf Ali ; > Duggapu, Chinni B > Subject: [edk2-devel][PATCH v2 1/2] UefiCpuPkg: Supporting S3 in 64bit PE= I >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D4195 > 1.Updated the GDT table in VTF0 to align with the one in S3Resume2Pei. > By doing so can simplify the changes to enable S3 in 64bit PEI. > 2.Use SwitchStack() between PEI and SMM in S3 resume path when both > are in the same execution mode. > 3.Transfer from PEI to OS waking vector by calling SwitchStack() when > both are in the same execution mode. > 4.Removed the debug assertion in S3Resume.c to support 64bit PEI. >=20 > Cc: Ray Ni > Cc: Zhiguang Liu > Cc: Chasel Chiu > Cc: Nate DeSimone > Cc: Star Zeng > Cc: Ashraf Ali S > Cc: Chinni B Duggapu > Signed-off-by: Ted Kuo > --- > UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 13 ++- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 1 + > .../ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 63 ++++++++---- > .../Universal/Acpi/S3Resume2Pei/S3Resume.c | 97 ++++++++++++------- > 4 files changed, 117 insertions(+), 57 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSm= m/CpuS3.c > index 9b45c442c9..fb4a44eab6 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c > @@ -1,7 +1,7 @@ > /** @file >=20 > Code for Processor S3 restoration >=20 >=20 >=20 > -Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -783,7 +783,11 @@ SmmRestoreCpu ( > SmmS3ResumeState =3D mSmmS3ResumeState; >=20 > ASSERT (SmmS3ResumeState !=3D NULL); >=20 >=20 >=20 > - if (SmmS3ResumeState->Signature =3D=3D SMM_S3_RESUME_SMM_64) { >=20 > + // >=20 > + // Setup 64bit IDT in 64bit SMM env when called from 32bit PEI. >=20 > + // Note: 64bit PEI and 32bit DXE is not a supported combination. >=20 > + // >=20 > + if ((SmmS3ResumeState->Signature =3D=3D SMM_S3_RESUME_SMM_64) && (Feat= urePcdGet > (PcdDxeIplSwitchToLongMode) =3D=3D TRUE)) { >=20 > // >=20 > // Save the IA32 IDT Descriptor >=20 > // >=20 > @@ -846,9 +850,10 @@ SmmRestoreCpu ( > DEBUG ((DEBUG_INFO, "SMM S3 Return Stack Pointer =3D %x\n", SmmS3R= esumeState->ReturnStackPointer)); >=20 >=20 >=20 > // >=20 > - // If SMM is in 32-bit mode, then use SwitchStack() to resume PEI Phas= e >=20 > + // If SMM is in 32-bit mode or PcdDxeIplSwitchToLongMode is FALSE, the= n use SwitchStack() to resume PEI Phase. >=20 > + // Note: 64bit PEI and 32bit DXE is not a supported combination. >=20 > // >=20 > - if (SmmS3ResumeState->Signature =3D=3D SMM_S3_RESUME_SMM_32) { >=20 > + if ((SmmS3ResumeState->Signature =3D=3D SMM_S3_RESUME_SMM_32) || (Feat= urePcdGet (PcdDxeIplSwitchToLongMode) > =3D=3D FALSE)) { >=20 > DEBUG ((DEBUG_INFO, "Call SwitchStack() to return to S3 Resume in PE= I Phase\n")); >=20 >=20 >=20 > SwitchStack ( >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > index deef00f9c6..b4b327f60c 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > @@ -124,6 +124,7 @@ > gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmProfileEnable ## CO= NSUMES >=20 > gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmProfileRingBuffer ## CO= NSUMES >=20 > gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmFeatureControlMsrLock ## CO= NSUMES >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CO= NSUMES >=20 >=20 >=20 > [Pcd] >=20 > gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SO= METIMES_CONSUMES >=20 > diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm > b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm > index 0e79a3984b..f59fc6ead4 100644 > --- a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm > +++ b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm > @@ -2,7 +2,7 @@ > ; @file >=20 > ; Transition from 16 bit real mode into 32 bit flat protected mode >=20 > ; >=20 > -; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
>=20 > +; Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.
>=20 > ; SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > ; >=20 > ;-----------------------------------------------------------------------= ------- >=20 > @@ -92,7 +92,7 @@ ALIGN 16 >=20 >=20 > GDT_BASE: >=20 > ; null descriptor >=20 > -NULL_SEL equ $-GDT_BASE >=20 > +NULL_SEL equ $-GDT_BASE ; Selector [0x0] >=20 > DW 0 ; limit 15:0 >=20 > DW 0 ; base 15:0 >=20 > DB 0 ; base 23:16 >=20 > @@ -100,42 +100,67 @@ NULL_SEL equ $-GDT_BASE > DB 0 ; limit 19:16, flags >=20 > DB 0 ; base 31:24 >=20 >=20 >=20 > +; Spare segment descriptor >=20 > +SPARE1_SEL equ $-GDT_BASE ; Selector [0x8] >=20 > + DW 0 ; limit 15:0 >=20 > + DW 0 ; base 15:0 >=20 > + DB 0 ; base 23:16 >=20 > + DB 0 ; sys flag, dpl, type >=20 > + DB 0 ; limit 19:16, flags >=20 > + DB 0 ; base 31:24 >=20 > + >=20 > +; linear code segment descriptor >=20 > +LINEAR_CODE_SEL equ $-GDT_BASE ; Selector [0x10] >=20 > + DW 0xffff ; limit 15:0 >=20 > + DW 0 ; base 15:0 >=20 > + DB 0 ; base 23:16 >=20 > + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)= ; 09Bh >=20 > + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_L= IMIT(0xf) ; 0CFh >=20 > + DB 0 ; base 31:24 >=20 > + >=20 > ; linear data segment descriptor >=20 > -LINEAR_SEL equ $-GDT_BASE >=20 > +LINEAR_SEL equ $-GDT_BASE ; Selector [0x18] >=20 > DW 0xffff ; limit 15:0 >=20 > DW 0 ; base 15:0 >=20 > DB 0 ; base 23:16 >=20 > - DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE) >=20 > - DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_L= IMIT(0xf) >=20 > + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)= ; 093h >=20 > + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_L= IMIT(0xf) ; 0CFh >=20 > DB 0 ; base 31:24 >=20 >=20 >=20 > -; linear code segment descriptor >=20 > -LINEAR_CODE_SEL equ $-GDT_BASE >=20 > +; Spare segment descriptor >=20 > +SPARE2_SEL equ $-GDT_BASE ; Selector [0x20] >=20 > + DW 0 ; limit 15:0 >=20 > + DW 0 ; base 15:0 >=20 > + DB 0 ; base 23:16 >=20 > + DB 0 ; sys flag, dpl, type >=20 > + DB 0 ; limit 19:16, flags >=20 > + DB 0 ; base 31:24 >=20 > + >=20 > +; linear code (16-bit) segment descriptor >=20 > +LINEAR_CODE16_SEL equ $-GDT_BASE ; Selector [0x28] >=20 > DW 0xffff ; limit 15:0 >=20 > DW 0 ; base 15:0 >=20 > DB 0 ; base 23:16 >=20 > - DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE) >=20 > - DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_L= IMIT(0xf) >=20 > + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)= ; 09Bh >=20 > + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_L= IMIT(0xf) ; 08Fh >=20 > DB 0 ; base 31:24 >=20 >=20 >=20 > -%ifdef ARCH_X64 >=20 > -; linear code (64-bit) segment descriptor >=20 > -LINEAR_CODE64_SEL equ $-GDT_BASE >=20 > +; linear data (16-bit) segment descriptor >=20 > +LINEAR_DATA16_SEL equ $-GDT_BASE ; Selector [0x30] >=20 > DW 0xffff ; limit 15:0 >=20 > DW 0 ; base 15:0 >=20 > DB 0 ; base 23:16 >=20 > - DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE) >=20 > - DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_L= IMIT(0xf) >=20 > + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)= ; 093h >=20 > + DB 0 >=20 > DB 0 ; base 31:24 >=20 > -%endif >=20 >=20 >=20 > -; linear code segment descriptor >=20 > -LINEAR_CODE16_SEL equ $-GDT_BASE >=20 > +; linear code (64-bit) segment descriptor >=20 > +LINEAR_CODE64_SEL equ $-GDT_BASE ; Selector [0x38] >=20 > DW 0xffff ; limit 15:0 >=20 > DW 0 ; base 15:0 >=20 > DB 0 ; base 23:16 >=20 > - DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE) >=20 > - DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_L= IMIT(0xf) >=20 > + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)= ; 09Bh >=20 > + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_L= IMIT(0xf) ; 0AFh >=20 > DB 0 ; base 31:24 >=20 >=20 >=20 > GDT_END: >=20 > diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c > b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c > index 8419a4e32a..ec6fdc2d4c 100644 > --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c > +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c > @@ -4,7 +4,7 @@ > This module will execute the boot script saved during last boot and af= ter that, >=20 > control is passed to OS waking up handler. >=20 >=20 >=20 > - Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>=20 > + Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.
>=20 > Copyright (c) 2017, AMD Incorporated. All rights reserved.
>=20 >=20 >=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -332,9 +332,8 @@ IsLongModeWakingVector ( > ((Facs->OspmFlags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) !=3D 0)) >=20 > { >=20 > // Both BIOS and OS wants 64bit vector >=20 > - if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { >=20 > - return TRUE; >=20 > - } >=20 > + ASSERT ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UI= NTN) =3D=3D sizeof (UINT64))); >=20 > + return TRUE; >=20 > } >=20 > } >=20 >=20 >=20 > @@ -521,8 +520,11 @@ S3ResumeBootOs ( > // >=20 > // X64 long mode waking vector >=20 > // >=20 > - DEBUG ((DEBUG_INFO, "Transfer to 64bit OS waking vector - %x\r\n",= (UINTN)Facs->XFirmwareWakingVector)); >=20 > + DEBUG ((DEBUG_INFO, "Transfer from PEI to 64bit OS waking vector -= %x\r\n", (UINTN)Facs- > >XFirmwareWakingVector)); >=20 > if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { >=20 > + // >=20 > + // 32bit PEI calls to 64bit OS S3 waking vector >=20 > + // >=20 > AsmEnablePaging64 ( >=20 > 0x38, >=20 > Facs->XFirmwareWakingVector, >=20 > @@ -531,29 +533,58 @@ S3ResumeBootOs ( > (UINT64)(UINTN)TempStackTop >=20 > ); >=20 > } else { >=20 > - // >=20 > - // Report Status code that no valid waking vector is found >=20 > - // >=20 > - REPORT_STATUS_CODE ( >=20 > - EFI_ERROR_CODE | EFI_ERROR_MAJOR, >=20 > - (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_OS_WAKE_ERROR) >=20 > - ); >=20 > - DEBUG ((DEBUG_ERROR, "Unsupported for 32bit DXE transfer to 64bi= t OS waking vector!\r\n")); >=20 > - ASSERT (FALSE); >=20 > - CpuDeadLoop (); >=20 > - return; >=20 > + if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { >=20 > + // >=20 > + // 64bit PEI calls to 64bit OS S3 waking vector >=20 > + // >=20 > + SwitchStack ( >=20 > + (SWITCH_STACK_ENTRY_POINT)(UINTN)Facs->XFirmwareWakingVector= , >=20 > + NULL, >=20 > + NULL, >=20 > + (VOID *)(UINTN)TempStackTop >=20 > + ); >=20 > + } else { >=20 > + // >=20 > + // Report Status code that no valid waking vector is found. >=20 > + // Note: 32bit PEI + 32bit DXE firmware calling to 64bit OS S3= waking vector is an invalid configuration. >=20 > + // >=20 > + REPORT_STATUS_CODE ( >=20 > + EFI_ERROR_CODE | EFI_ERROR_MAJOR, >=20 > + (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_OS_WAKE_ERROR) >=20 > + ); >=20 > + DEBUG ((DEBUG_ERROR, "Unsupported for 32bit DXE transfer to 64= bit OS waking vector!\r\n")); >=20 > + ASSERT (FALSE); >=20 > + CpuDeadLoop (); >=20 > + return; >=20 > + } >=20 > } >=20 > } else { >=20 > // >=20 > // IA32 protected mode waking vector (Page disabled) >=20 > // >=20 > DEBUG ((DEBUG_INFO, "Transfer to 32bit OS waking vector - %x\r\n",= (UINTN)Facs->XFirmwareWakingVector)); >=20 > - SwitchStack ( >=20 > - (SWITCH_STACK_ENTRY_POINT)(UINTN)Facs->XFirmwareWakingVector, >=20 > - NULL, >=20 > - NULL, >=20 > - (VOID *)(UINTN)TempStackTop >=20 > - ); >=20 > + if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { >=20 > + // >=20 > + // 64bit PEI calls to 32bit OS S3 waking vector >=20 > + // >=20 > + AsmDisablePaging64 ( >=20 > + 0x10, >=20 > + (UINT32)Facs->XFirmwareWakingVector, >=20 > + 0, >=20 > + 0, >=20 > + (UINT32)TempStackTop >=20 > + ); >=20 > + } else { >=20 > + // >=20 > + // 32bit PEI calls to 32bit OS S3 waking vector >=20 > + // >=20 > + SwitchStack ( >=20 > + (SWITCH_STACK_ENTRY_POINT)(UINTN)Facs->XFirmwareWakingVector, >=20 > + NULL, >=20 > + NULL, >=20 > + (VOID *)(UINTN)TempStackTop >=20 > + ); >=20 > + } >=20 > } >=20 > } else { >=20 > // >=20 > @@ -579,7 +610,7 @@ S3ResumeBootOs ( >=20 >=20 > /** >=20 > Restore S3 page table because we do not trust ACPINvs content. >=20 > - If BootScriptExector driver will not run in 64-bit mode, this function= will do nothing. >=20 > + If BootScriptExecutor driver will not run in 64-bit mode, this functio= n will do nothing. >=20 >=20 >=20 > @param S3NvsPageTableAddress PageTableAddress in ACPINvs >=20 > @param Build4GPageTableOnly If BIOS just build 4G page table only >=20 > @@ -590,7 +621,7 @@ RestoreS3PageTables ( > IN BOOLEAN Build4GPageTableOnly >=20 > ) >=20 > { >=20 > - if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { >=20 > + if ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UINTN) =3D= =3D sizeof (UINT64))) { >=20 > UINT32 RegEax; >=20 > UINT32 RegEdx; >=20 > UINT8 PhysicalAddressBits; >=20 > @@ -825,7 +856,7 @@ S3ResumeExecuteBootScript ( > SignalToSmmByCommunication (&gEdkiiS3SmmInitDoneGuid); >=20 > } >=20 >=20 >=20 > - if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { >=20 > + if ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UINTN) =3D= =3D sizeof (UINT64))) { >=20 > AsmWriteCr3 ((UINTN)AcpiS3Context->S3NvsPageTableAddress); >=20 > } >=20 >=20 >=20 > @@ -1021,7 +1052,7 @@ S3RestoreConfig2 ( > CpuDeadLoop (); >=20 > } >=20 >=20 >=20 > - if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { >=20 > + if ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UINTN) =3D= =3D sizeof (UINT64))) { >=20 > // >=20 > // Need reconstruct page table here, since we do not trust ACPINvs. >=20 > // >=20 > @@ -1039,13 +1070,6 @@ S3RestoreConfig2 ( > // >=20 > GuidHob =3D GetFirstGuidHob (&gEfiAcpiVariableGuid); >=20 > if (GuidHob !=3D NULL) { >=20 > - // >=20 > - // Below SwitchStack/AsmEnablePaging64 function has >=20 > - // assumption that it's in 32 bits mode now. >=20 > - // Add ASSERT code to indicate this assumption. >=20 > - // >=20 > - ASSERT (sizeof (UINTN) =3D=3D sizeof (UINT32)); >=20 > - >=20 > Status =3D PeiServicesLocatePpi ( >=20 > &gPeiSmmAccessPpiGuid, >=20 > 0, >=20 > @@ -1079,7 +1103,12 @@ S3RestoreConfig2 ( > DEBUG ((DEBUG_INFO, "SMM S3 Return Stack Pointer =3D %x\n", SmmS= 3ResumeState->ReturnStackPointer)); >=20 > DEBUG ((DEBUG_INFO, "SMM S3 Smst =3D %x\n", SmmS= 3ResumeState->Smst)); >=20 >=20 >=20 > - if (SmmS3ResumeState->Signature =3D=3D SMM_S3_RESUME_SMM_32) { >=20 > + // >=20 > + // Directly do the switch stack when PEI and SMM env run in the same= execution mode. >=20 > + // >=20 > + if (((SmmS3ResumeState->Signature =3D=3D SMM_S3_RESUME_SMM_32) && (s= izeof (UINTN) =3D=3D sizeof (UINT32))) || >=20 > + ((SmmS3ResumeState->Signature =3D=3D SMM_S3_RESUME_SMM_64) && (s= izeof (UINTN) =3D=3D sizeof (UINT64)))) >=20 > + { >=20 > SwitchStack ( >=20 > (SWITCH_STACK_ENTRY_POINT)(UINTN)SmmS3ResumeState->SmmS3ResumeEn= tryPoint, >=20 > (VOID *)AcpiS3Context, >=20 > -- > 2.35.3.windows.1