From nobody Thu Nov 14 05:45:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43310+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562252324; cv=none; d=zoho.com; s=zohoarc; b=ChuKXyJpRVnRaNmGdw5n5BpKrWeSGxiYXHWb4HSHSL7OQV69DeqV2g4dTiYALV4m8tbdXuOqfWbmCTlH4s0F24Cwlz7hpvPqUprNy+ODSezacKay9CbSsjOCh76cwJSyFf2V4uPXTa9eEHNLiTmTs/qocSkKdUD5lI3aEfDtTh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562252324; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=OdUmkOK1rfgSWk4ou79IU8RsihyDvfC7Ann2X54Kb2E=; b=imCXp6Fxb8QhoCvYd1xwdFVuPZVGvig7KlBgttULr55KR8seeYDR4F1tj0Q/ooUmc/wcwsWNebmBReliyQj1YLx681ZYf7JfUH9CgriqK+AyV3ov7mOj/0T+rfT4XLALuXylJj+HcCJbB1QQ9aba8hlcrl5xjqTJAur8AA+fOTk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43310+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562252324368347.58918049491274; Thu, 4 Jul 2019 07:58:44 -0700 (PDT) Return-Path: X-Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by groups.io with SMTP; Thu, 04 Jul 2019 07:58:43 -0700 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43310+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 73yEZcPULXsZFaDPY+6Co1nvmOwpN90C543zUv5oiB1SMwS6akCsyL7yPX6qbRJHTrxzrahnQc KlN6v5wF9Uw25xj/O76Q+fS/Sg/quPF8VgSDBmUabu3Ov0QsayZNW9NOXSw5V7dukFmCPkAN9V s6dTiZYUWg1bOmrET3KYqyPZtEwCqHoaxSV4UPv8aDEeN7x0VHKFGME3qPjlpUUbpnWyxDOK1+ QRwz5Ztk3ojLY/+2D/aOjr/D5kSYvhli9p/PpOusmT3VKXDsdUy+fOgP/hI/q+c8+ny+HfjO9b Bbw= X-SBRS: 2.7 X-MesageID: 2589159 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,451,1557201600"; d="scan'208";a="2589159" From: "Anthony PERARD" To: CC: , Ard Biesheuvel , Jordan Justen , Laszlo Ersek , Julien Grall , Anthony PERARD Subject: [edk2-devel] [PATCH v3 33/35] OvmfPkg: Introduce XenIoPvhDxe to initialize Grant Tables Date: Thu, 4 Jul 2019 15:42:31 +0100 Message-ID: <20190704144233.27968-34-anthony.perard@citrix.com> In-Reply-To: <20190704144233.27968-1-anthony.perard@citrix.com> References: <20190704144233.27968-1-anthony.perard@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562252323; bh=g/kOaxObqf/VEPy6DAafa2Ic3qVZwIayazBN4H6mvsA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=P1ufY+XKtJ3SEReg2JY6/QADF4HJAkj9OVGKmXAQKfNQQ3vkYxqeD6XMFZPZJ+oj9NE cnz8VLVrJamaJfalN41FUicahVJJ/owhvWTvd/NtUF5Mv/k1cL1aqJ0b0TmumYsHcTmF2 RJ2Va0qZI/4YnbvEXOGM0txOTIRvmmpS1Lg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" XenIoPvhDxe use XenIoMmioLib to reserve some space to be use by the Grant Tables. The call is only done if it is necessary, we simply detect if the guest is PVH, as in this case there is currently no PCI bus, and no PCI Xen platform device which would start the XenIoPciDxe and allocate the space for the Grant Tables. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1689 Signed-off-by: Anthony PERARD --- Notes: v3: - downgrade type to DXE_DRIVER - use SPDX - rework InitializeXenIoPvhDxe, and handle errors properly. - Free the reserved allocation in ExitBootServices even if the XenIo protocol could successfully been uninstalled. =20 v2: - do allocation in EntryPoint like the other user of XenIoMmioLib. - allocate memory instead of hardcoded addr. - cleanup, add copyright - detect if we are running in PVH mode OvmfPkg/OvmfXen.dsc | 2 + OvmfPkg/OvmfXen.fdf | 1 + OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf | 34 +++++++++ OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c | 108 ++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf create mode 100644 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 487bada64d..af92ce3ed2 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -196,6 +196,7 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf + XenIoMmioLib|OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf =20 Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeT= cg2PhysicalPresenceLib.inf =20 @@ -583,6 +584,7 @@ [Components] NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf !endif } + OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf OvmfPkg/XenBusDxe/XenBusDxe.inf OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf index 5c1a925d6a..517a492f14 100644 --- a/OvmfPkg/OvmfXen.fdf +++ b/OvmfPkg/OvmfXen.fdf @@ -309,6 +309,7 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Metronome/Metronome.inf INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDx= e.inf =20 +INF OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf INF OvmfPkg/XenBusDxe/XenBusDxe.inf INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf diff --git a/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf b/OvmfPkg/XenIoPvhDxe/XenI= oPvhDxe.inf new file mode 100644 index 0000000000..a093d48fde --- /dev/null +++ b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf @@ -0,0 +1,34 @@ +## @file +# Driver for the XenIo protocol +# +# Copyright (c) 2019, Citrix Systems, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D XenIoPvhDxe + FILE_GUID =3D 7a567cc4-0e75-4d7a-a305-c3db109b53ad + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializeXenIoPvhDxe + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[Sources] + XenIoPvhDxe.c + +[LibraryClasses] + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiDriverEntryPoint + XenIoMmioLib + XenPlatformLib + +[Depex] + TRUE diff --git a/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c b/OvmfPkg/XenIoPvhDxe/XenIoP= vhDxe.c new file mode 100644 index 0000000000..88a394bf91 --- /dev/null +++ b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c @@ -0,0 +1,108 @@ +/** @file + + Driver for the XenIo protocol + + This driver simply allocate space for the grant tables. + + Copyright (c) 2019, Citrix Systems, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +typedef struct { + EFI_HANDLE XenIoHandle; + EFI_EVENT ExitBootEvent; + VOID *Allocation; +} XEN_IO_PVH_STATE; + +// +// Value should be the same as NR_GRANT_FRAMES in XenBusDxe +// +#define XEN_GRANT_FRAMES 4 + +STATIC +VOID +EFIAPI +XenIoPvhDxeNotifyExitBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + XEN_IO_PVH_STATE *State; + EFI_STATUS Status; + + State =3D Context; + + gBS->CloseEvent(&State->ExitBootEvent); + Status =3D XenIoMmioUninstall(State->XenIoHandle); + if (Status =3D=3D EFI_SUCCESS) { + // + // Only free the reserved space for grant table if no driver is using = it. + // + FreePages (State->Allocation, XEN_GRANT_FRAMES); + } + FreePool (State); +} + +EFI_STATUS +EFIAPI +InitializeXenIoPvhDxe ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + VOID *Allocation; + EFI_STATUS Status; + XEN_IO_PVH_STATE *State; + + State =3D NULL; + Allocation =3D NULL; + + if (! XenPvhDetected ()) { + return EFI_UNSUPPORTED; + } + + State =3D AllocatePool (sizeof (*State)); + if (State =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Error; + } + + Allocation =3D AllocateReservedPages (XEN_GRANT_FRAMES); + if (Allocation =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Error; + } + + State->XenIoHandle =3D NULL; + Status =3D XenIoMmioInstall (&State->XenIoHandle, (UINTN) Allocation); + if (EFI_ERROR (Status)) { + goto Error; + } + + State->Allocation =3D Allocation; + Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, + XenIoPvhDxeNotifyExitBoot, State, &State->ExitBootEvent); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; + +Error: + if (State !=3D NULL && State->XenIoHandle !=3D NULL) { + XenIoMmioUninstall(State->XenIoHandle); + } + if (Allocation !=3D NULL) { + FreePages (Allocation, XEN_GRANT_FRAMES); + } + if (State !=3D NULL) { + FreePool (State); + } + return Status; +} --=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 (#43310): https://edk2.groups.io/g/devel/message/43310 Mute This Topic: https://groups.io/mt/32308734/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-