From nobody Mon Feb 9 11:30:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96305+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96305+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1668180449; cv=none; d=zohomail.com; s=zohoarc; b=UNVeoTprEzTV1Z+or4AXGnkDXdsS++m8nSkFAnMVzZZ4ZQfV1fi+CxUDW5ZcBj+Vc9A+V7aydG/abroHd1ijgAvB48fBkaxMRBA1hVtcg3ZuB6t3kjejlLhGtTyPl2NLrbsDazdotcRdDlSjoduQM3iPT2uIveutPeL/Jw2pYWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668180449; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gnhTY7nswY9Ov4u0+PV10XGl1J57rBhVNkqRfyLTw/g=; b=L7ZNoIbAqDKa2YszWoYsTPCY6wZe6hnNk8gk7zoOh1ovnmooWDjMF0SrHu1d0mt+CUYTqFN+ksU1adWlfJPeOmSjOsThyFlUoEJCI8WOoNwH5zLGhFhBUREHDPAOti1rQGLqriNPM44WC5ZWf1KkY6v3Pyv/hLb7yVEn3qLFB08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96305+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1668180449811869.0367613693724; Fri, 11 Nov 2022 07:27:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4gQJYY1788612xf6msUP9Qy3; Fri, 11 Nov 2022 07:27:29 -0800 X-Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by mx.groups.io with SMTP id smtpd.web09.6694.1668180445341896668 for ; Fri, 11 Nov 2022 07:27:28 -0800 X-SBRS: None X-MesageID: 87190452 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:VqKAO6oGWVQiAzgaNGXECQeoWxNeBmIiZRIvgKrLsJaIsI4StFCzt garIBnUOPaCY2T1fN1zYN+290sPuJKHxtZmSFFr/C5gQilE8JuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpAFc+E0/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKm06W1wUmAWP6gR5gaHziBNVfrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXADAXSwukuODs+5iqTOhTt94oCfS6FapK7xmMzRmBZRonaZXKQqGM7t5ExjYgwMtJGJ4yZ eJAN2ApNk6ZJUQSZBFHU/rSn8/x7pX7WzRetFKSo7tx+2XJxRZ9+LPsLMDUapqBQsA9ckOw9 j2frjylX0ty2Nq3kjuB73+gtuv0pCLhVawiG7yX7e9RuQjGroAUIEJPDgbqyRWjsWa3Qd5Va FAV8ywppq8o+WSoQ8P7Uhn+p2SL1jYfQdNAHukS8gyByqPIpQ2eAwAsTDlbZNUg8stwRyExy lKPt9LvGTFr9raSTBq1+rqKoDeaNCQWdykNfygZVRBD4t6LiIMygw3CSJByGamdj9vpFDW2y DePxAA8mrESgMgjx6i9u1fdjFqRSoPhF1BvoF+NByT8s10/NNXNi5GUBUbz7exlN6GmTAO6l mkCmvev9usrMMCkvXnYKAkSJ42B6/GAOTzapFdgGZg96jigk0KekZBsDCJWfxkwbJtdEdP9S AqK4F4KuscPVJe/RfUvC79dHfjG2kQJ+T7NcvnPJuRDbZFqHONs1HE/PBXAt4wBfaVFrE3eB Xt5WZzyZZr5If49pNZTewv6+e5D+8zG7TmPLa0XNjz+uVdeDVbMIVv/DHOAb/oi8ISPqxjP/ tBUOqOikksBALSmP3KPq95IdTjmyETX4riv9aRqmhOreFI6SAnN9deNqV/eR2CVt/sMzbqZl p1MckRZ1ED+lRX6xfaiMxhehXKGdcgXkE/XygR8Zwr2gCJyPNrHAWV2X8JfQITLPddLlZZcJ 8Tpse3aahiTYlwrIwggUKQ= IronPort-HdrOrdr: A9a23:ApqLOKH5R1LlMQPSpLqE7seALOsnbusQ8zAXP0AYc3Nom6uj5q eTdZUgpGbJYVkqOU3I9ersBEDEewK/yXcX2/h0AV7BZmnbUQKTRekIh7cKgQeQfhEWntQts5 uIGJIRNDSfNzRHZL7BkWqFL+o= X-IronPort-AV: E=Sophos;i="5.96,156,1665460800"; d="scan'208";a="87190452" From: "Anthony PERARD via groups.io" To: CC: Jiewen Yao , Julien Grall , Jordan Justen , Ard Biesheuvel , Gerd Hoffmann , Anthony PERARD Subject: [edk2-devel] [PATCH 3/3] OvmfPkg/OvmfXen: Introduce Xen's ResetSystemLib, to use xen hypercall Date: Fri, 11 Nov 2022 15:27:14 +0000 Message-ID: <20221111152714.61331-4-anthony.perard@citrix.com> In-Reply-To: <20221111152714.61331-1-anthony.perard@citrix.com> References: <20221111152714.61331-1-anthony.perard@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,anthony.perard@citrix.com X-Gm-Message-State: yUX7JxP3X1uw1wRnudX3Ga9nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1668180449; bh=gnhTY7nswY9Ov4u0+PV10XGl1J57rBhVNkqRfyLTw/g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=NmcwGzhZ8Ch70YlKhYomqNAm1jEqQParGYGdRqF1fFnqIGs7pqH682yT4PP4iJaadMY QMJfUaWvfbYvZoi5haqXFhns/RpLTyPw3l2c7cTIzISyVAcTlfaQBzQ3Sb9j+kT5w7s8K q9RtOx0rhqfqe0kdw2rqQn3mPKh65ysGtK0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1668180450813100010 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD When booting OvmfXen, the ACPI interface for shutdown/reset might not be available, instead use the hypercall interface. While it's probably possible to use the hypercall in all cases, we keep using the same interface while it still possible. That is ACPI on HVM guest, and fallback to hypercall on PVH guest. Signed-off-by: Anthony PERARD --- OvmfPkg/OvmfXen.dsc | 10 +++---- ...ystemLib.inf =3D> BaseResetSystemLibXen.inf} | 9 ++++--- ...SystemLib.inf =3D> DxeResetSystemLibXen.inf} | 11 +++++--- ...ResetShutdown.c =3D> BaseResetShutdownXen.c} | 19 +++++++++++--- ...eResetShutdown.c =3D> DxeResetShutdownXen.c} | 26 ++++++++++++------- 5 files changed, 49 insertions(+), 26 deletions(-) copy OvmfPkg/Library/ResetSystemLib/{BaseResetSystemLib.inf =3D> BaseReset= SystemLibXen.inf} (73%) copy OvmfPkg/Library/ResetSystemLib/{DxeResetSystemLib.inf =3D> DxeResetSy= stemLibXen.inf} (73%) copy OvmfPkg/Library/ResetSystemLib/{BaseResetShutdown.c =3D> BaseResetShu= tdownXen.c} (72%) copy OvmfPkg/Library/ResetSystemLib/{DxeResetShutdown.c =3D> DxeResetShutd= ownXen.c} (72%) diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 8df173a0ee84..18f7c0d76643 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -118,7 +118,7 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf @@ -302,7 +302,7 @@ [LibraryClasses.common.DXE_CORE] =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf @@ -316,7 +316,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] =20 [LibraryClasses.common.UEFI_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf @@ -326,7 +326,7 @@ [LibraryClasses.common.UEFI_DRIVER] =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf @@ -345,7 +345,7 @@ [LibraryClasses.common.DXE_DRIVER] =20 [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf b/OvmfPk= g/Library/ResetSystemLib/BaseResetSystemLibXen.inf similarity index 73% copy from OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf copy to OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf index 35d317f1e0b3..8d75dd565365 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf @@ -1,7 +1,9 @@ ## @file -# Base library instance for ResetSystem library class for OVMF +# Base library instance for ResetSystem library class for Xen # # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2022, Citrix Systems, Inc. +# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -9,7 +11,7 @@ [Defines] INF_VERSION =3D 0x00010005 BASE_NAME =3D BaseResetSystemLib - FILE_GUID =3D 66564872-21d4-4d2a-a68b-1e844f980820 + FILE_GUID =3D 9ef32aa1-9e82-4fb1-9c49-0eff538601f8 MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D ResetSystemLib|SEC PEI_CORE PEIM DXE_= CORE @@ -22,7 +24,7 @@ [Defines] # =20 [Sources] - BaseResetShutdown.c + BaseResetShutdownXen.c ResetSystemLib.c =20 [Packages] @@ -36,3 +38,4 @@ [LibraryClasses] IoLib PciLib TimerLib + XenHypercallLib diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf b/OvmfPkg= /Library/ResetSystemLib/DxeResetSystemLibXen.inf similarity index 73% copy from OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf copy to OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf index a9b4ce90000a..ccee69e6e1fa 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf @@ -1,16 +1,18 @@ ## @file -# DXE library instance for ResetSystem library class for OVMF +# DXE library instance for ResetSystem library class for Xen # # Copyright (C) 2020, Red Hat, Inc. # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2022, Citrix Systems, Inc. +# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## =20 [Defines] INF_VERSION =3D 1.29 - BASE_NAME =3D DxeResetSystemLib - FILE_GUID =3D bc7835ea-4094-41fe-b770-bad9e6c479b2 + BASE_NAME =3D DxeResetSystemLibXen + FILE_GUID =3D a5ac25e6-4dc5-4fd9-92cd-74e46bd2e72a MODULE_TYPE =3D DXE_DRIVER VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D ResetSystemLib|DXE_DRIVER DXE_RUNTIME= _DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION @@ -24,7 +26,7 @@ [Defines] # =20 [Sources] - DxeResetShutdown.c + DxeResetShutdownXen.c ResetSystemLib.c =20 [Packages] @@ -38,6 +40,7 @@ [LibraryClasses] IoLib PcdLib TimerLib + XenHypercallLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c b/OvmfPkg/L= ibrary/ResetSystemLib/BaseResetShutdownXen.c similarity index 72% copy from OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c copy to OvmfPkg/Library/ResetSystemLib/BaseResetShutdownXen.c index c21d3c89cf95..f45d9125feb4 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetShutdownXen.c @@ -3,6 +3,8 @@ =20 Copyright (C) 2020, Red Hat, Inc. Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2022, Citrix Systems, Inc. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 @@ -13,6 +15,7 @@ #include // IoOr16() #include // PciRead16() #include // ResetShutdown() +#include #include // OVMF_HOSTBRIDGE_DID =20 /** @@ -40,12 +43,20 @@ ResetShutdown ( case INTEL_Q35_MCH_DEVICE_ID: AcpiPmBaseAddress =3D ICH9_PMBASE_VALUE; break; - case CLOUDHV_DEVICE_ID: - IoWrite8 (CLOUDHV_ACPI_SHUTDOWN_IO_ADDRESS, 5 << 2 | 1 << 5); - CpuDeadLoop (); default: - ASSERT (FALSE); + { + // + // Fallback to using hypercall. + // Necessary for PVH guest, but should work for HVM guest. + // + INTN ReturnCode; + XEN_SCHED_SHUTDOWN ShutdownOp =3D { + .Reason =3D XEN_SHED_SHUTDOWN_POWEROFF, + }; + ReturnCode =3D XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, ShutdownOp= ); + ASSERT (ReturnCode =3D=3D 0); CpuDeadLoop (); + } } =20 IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, 0); diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c b/OvmfPkg/Li= brary/ResetSystemLib/DxeResetShutdownXen.c similarity index 72% copy from OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c copy to OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c index 31f01b82e4ee..f7f32765cfc9 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c @@ -8,15 +8,16 @@ =20 #include // BIT13 =20 +#include #include // CpuDeadLoop() #include // ASSERT() #include // IoOr16() #include // PcdGet16() #include // ResetShutdown() +#include #include // PIIX4_PMBA_VALUE =20 STATIC UINT16 mAcpiPmBaseAddress; -STATIC UINT16 mAcpiHwReducedSleepCtl; =20 EFI_STATUS EFIAPI @@ -35,13 +36,13 @@ DxeResetInit ( case INTEL_Q35_MCH_DEVICE_ID: mAcpiPmBaseAddress =3D ICH9_PMBASE_VALUE; break; - case CLOUDHV_DEVICE_ID: - mAcpiHwReducedSleepCtl =3D CLOUDHV_ACPI_SHUTDOWN_IO_ADDRESS; - break; default: - ASSERT (FALSE); - CpuDeadLoop (); - return EFI_UNSUPPORTED; + // + // Fallback to using hypercall. + // Necessary for PVH guest, but should work for HVM guest. + // + mAcpiPmBaseAddress =3D 0xffff; + break; } =20 return EFI_SUCCESS; @@ -60,11 +61,16 @@ ResetShutdown ( VOID ) { - if (mAcpiHwReducedSleepCtl) { - IoWrite8 (mAcpiHwReducedSleepCtl, 5 << 2 | 1 << 5); - } else { + if (mAcpiPmBaseAddress !=3D 0xffff) { IoBitFieldWrite16 (mAcpiPmBaseAddress + 4, 10, 13, 0); IoOr16 (mAcpiPmBaseAddress + 4, BIT13); + } else { + INTN ReturnCode; + XEN_SCHED_SHUTDOWN ShutdownOp =3D { + .Reason =3D XEN_SHED_SHUTDOWN_POWEROFF, + }; + ReturnCode =3D XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, &ShutdownOp); + ASSERT (ReturnCode =3D=3D 0); } =20 CpuDeadLoop (); --=20 Anthony PERARD -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96305): https://edk2.groups.io/g/devel/message/96305 Mute This Topic: https://groups.io/mt/94960819/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-