From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: citrix.com, ip: 216.71.145.153, mailfrom: anthony.perard@citrix.com) 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 Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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: [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> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190704144233.27968-1-anthony.perard@citrix.com> References: <20190704144233.27968-1-anthony.perard@citrix.com> MIME-Version: 1.0 Return-Path: anthony.perard@citrix.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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=20=20=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=0D XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf=0D XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf=0D + XenIoMmioLib|OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf=0D =0D Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeT= cg2PhysicalPresenceLib.inf=0D =0D @@ -583,6 +584,7 @@ [Components] NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf=0D !endif=0D }=0D + OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf=0D OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf=0D OvmfPkg/XenBusDxe/XenBusDxe.inf=0D OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf=0D 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=0D INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDx= e.inf=0D =0D +INF OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf=0D INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf=0D INF OvmfPkg/XenBusDxe/XenBusDxe.inf=0D INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf=0D 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=0D +# Driver for the XenIo protocol=0D +#=0D +# Copyright (c) 2019, Citrix Systems, Inc.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D XenIoPvhDxe=0D + FILE_GUID =3D 7a567cc4-0e75-4d7a-a305-c3db109b53ad=0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D InitializeXenIoPvhDxe=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[Sources]=0D + XenIoPvhDxe.c=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + MemoryAllocationLib=0D + UefiBootServicesTableLib=0D + UefiDriverEntryPoint=0D + XenIoMmioLib=0D + XenPlatformLib=0D +=0D +[Depex]=0D + TRUE=0D 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=0D +=0D + Driver for the XenIo protocol=0D +=0D + This driver simply allocate space for the grant tables.=0D +=0D + Copyright (c) 2019, Citrix Systems, Inc.=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +typedef struct {=0D + EFI_HANDLE XenIoHandle;=0D + EFI_EVENT ExitBootEvent;=0D + VOID *Allocation;=0D +} XEN_IO_PVH_STATE;=0D +=0D +//=0D +// Value should be the same as NR_GRANT_FRAMES in XenBusDxe=0D +//=0D +#define XEN_GRANT_FRAMES 4=0D +=0D +STATIC=0D +VOID=0D +EFIAPI=0D +XenIoPvhDxeNotifyExitBoot (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + XEN_IO_PVH_STATE *State;=0D + EFI_STATUS Status;=0D +=0D + State =3D Context;=0D +=0D + gBS->CloseEvent(&State->ExitBootEvent);=0D + Status =3D XenIoMmioUninstall(State->XenIoHandle);=0D + if (Status =3D=3D EFI_SUCCESS) {=0D + //=0D + // Only free the reserved space for grant table if no driver is using = it.=0D + //=0D + FreePages (State->Allocation, XEN_GRANT_FRAMES);=0D + }=0D + FreePool (State);=0D +}=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +InitializeXenIoPvhDxe (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + VOID *Allocation;=0D + EFI_STATUS Status;=0D + XEN_IO_PVH_STATE *State;=0D +=0D + State =3D NULL;=0D + Allocation =3D NULL;=0D +=0D + if (! XenPvhDetected ()) {=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + State =3D AllocatePool (sizeof (*State));=0D + if (State =3D=3D NULL) {=0D + Status =3D EFI_OUT_OF_RESOURCES;=0D + goto Error;=0D + }=0D +=0D + Allocation =3D AllocateReservedPages (XEN_GRANT_FRAMES);=0D + if (Allocation =3D=3D NULL) {=0D + Status =3D EFI_OUT_OF_RESOURCES;=0D + goto Error;=0D + }=0D +=0D + State->XenIoHandle =3D NULL;=0D + Status =3D XenIoMmioInstall (&State->XenIoHandle, (UINTN) Allocation);=0D + if (EFI_ERROR (Status)) {=0D + goto Error;=0D + }=0D +=0D + State->Allocation =3D Allocation;=0D + Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK= ,=0D + XenIoPvhDxeNotifyExitBoot, State, &State->ExitBootEvent)= ;=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return EFI_SUCCESS;=0D +=0D +Error:=0D + if (State !=3D NULL && State->XenIoHandle !=3D NULL) {=0D + XenIoMmioUninstall(State->XenIoHandle);=0D + }=0D + if (Allocation !=3D NULL) {=0D + FreePages (Allocation, XEN_GRANT_FRAMES);=0D + }=0D + if (State !=3D NULL) {=0D + FreePool (State);=0D + }=0D + return Status;=0D +}=0D --=20 Anthony PERARD