From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=softfail (domain: citrix.com, ip: , mailfrom: anthony.perard@citrix.com) Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com []) by groups.io with SMTP; Thu, 04 Jul 2019 07:58:45 -0700 Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: G/tltgAy+zTctT9Gyaz7C/Upd5a9xKVJbugBhAUQ1ou0Jut389RqXAo5AZwj3HciKzwdP1UQ8U oGfJ/VorkmLT/NUgfTaaWaX+yk3BRpXVtzb3wTzYwipFBSP2BIx6/PpLGjD4xMVRiqNjt6hOlk cYg6O3dLcPIOrj+ZFhPZhZlK55b/CeXqpJRQ2y+EOFGW8hIPzZO1fc9L3lVLDRKIIrMWXN0P38 /bXrp4VrJoBq3W2dCfN2JQEFEAC4kSBCNTgi2SDddnRsBKbUQ5pa/5RjocEyA8ZDPq+866I5pL 4pw= X-SBRS: 2.7 X-MesageID: 2623863 X-Ironport-Server: esa5.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="2623863" From: "Anthony PERARD" To: CC: , Ard Biesheuvel , Jordan Justen , Laszlo Ersek , Julien Grall , Anthony PERARD Subject: [PATCH v3 23/35] OvmfPkg/XenPlatformPei: no hvmloader: get the E820 table via hypercall Date: Thu, 4 Jul 2019 15:42:21 +0100 Message-ID: <20190704144233.27968-24-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 When the Xen PVH entry point has been used, hvmloader hasn't run and hasn't prepared an E820 table. The only way left to get an E820 table is to ask Xen via an hypercall, the call can only be made once so keep the result cached for later. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1689 Signed-off-by: Anthony PERARD Acked-by: Laszlo Ersek --- Notes: v3: - fix commit message - add 'm' prefix to the global variables and make them static OvmfPkg/XenPlatformPei/Xen.c | 46 +++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c index 188e831c5c..cbfd8058fc 100644 --- a/OvmfPkg/XenPlatformPei/Xen.c +++ b/OvmfPkg/XenPlatformPei/Xen.c @@ -27,6 +27,7 @@ #include =0D #include =0D #include =0D +#include =0D =0D #include "Platform.h"=0D #include "Xen.h"=0D @@ -40,6 +41,8 @@ EFI_XEN_INFO mXenInfo; // Only the E820 table is used by OVMF.=0D //=0D EFI_XEN_OVMF_INFO *mXenHvmloaderInfo;=0D +STATIC EFI_E820_ENTRY64 mE820Entries[128];=0D +STATIC UINT32 mE820EntriesCount;=0D =0D /**=0D Returns E820 map provided by Xen=0D @@ -55,6 +58,12 @@ XenGetE820Map ( UINT32 *Count=0D )=0D {=0D + INTN ReturnCode;=0D + xen_memory_map_t Parameters;=0D + UINTN LoopIndex;=0D + UINTN Index;=0D + EFI_E820_ENTRY64 TmpEntry;=0D +=0D //=0D // Get E820 produced by hvmloader=0D //=0D @@ -66,7 +75,42 @@ XenGetE820Map ( return EFI_SUCCESS;=0D }=0D =0D - return EFI_NOT_FOUND;=0D + //=0D + // Otherwise, get the E820 table from the Xen hypervisor=0D + //=0D +=0D + if (mE820EntriesCount > 0) {=0D + *Entries =3D mE820Entries;=0D + *Count =3D mE820EntriesCount;=0D + return EFI_SUCCESS;=0D + }=0D +=0D + Parameters.nr_entries =3D 128;=0D + set_xen_guest_handle (Parameters.buffer, mE820Entries);=0D +=0D + // Returns a errno=0D + ReturnCode =3D XenHypercallMemoryOp (XENMEM_memory_map, &Parameters);=0D + ASSERT (ReturnCode =3D=3D 0);=0D +=0D + mE820EntriesCount =3D Parameters.nr_entries;=0D +=0D + //=0D + // Sort E820 entries=0D + //=0D + for (LoopIndex =3D 1; LoopIndex < mE820EntriesCount; LoopIndex++) {=0D + for (Index =3D LoopIndex; Index < mE820EntriesCount; Index++) {=0D + if (mE820Entries[Index - 1].BaseAddr > mE820Entries[Index].BaseAddr)= {=0D + TmpEntry =3D mE820Entries[Index];=0D + mE820Entries[Index] =3D mE820Entries[Index - 1];=0D + mE820Entries[Index - 1] =3D TmpEntry;=0D + }=0D + }=0D + }=0D +=0D + *Count =3D mE820EntriesCount;=0D + *Entries =3D mE820Entries;=0D +=0D + return EFI_SUCCESS;=0D }=0D =0D /**=0D --=20 Anthony PERARD