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.web08.10910.1645712926893824814 for ; Thu, 24 Feb 2022 06:29:02 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=XizzVBB3; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: sebastien.boeuf@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645712942; x=1677248942; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AWf1T0q4/6xgyavylygwBNp2ErLax49xv8yW5MS6dE0=; b=XizzVBB3iEgOd0/ie5lVBCazUJ07J4elSHCiVOKuOu1Hzlo2khKD7KXH hjbsyk3TresfRlo69U1EFRWo8IQC8BHvEB5MI+2Ejn2n3INrePnrL4klA PLyq5NlrlSSxT/YSVFcrnHBvRpyn3nik70Ah2Ipr4pxh+wQQg1JgdBY+l P1Gvri0mufjUBhW3JXcvNBBJ0VZtNDqVqZVHA6qPZV5a4/StwMr1HjGST C68oUNS+YAnoqcSJ/Da6DsVLS+BsSfHM4HVWyqwqqiKidV50TwaN4P7Q+ h+lxAYXfDoQHvMRkkntJ9/m2HhlvoJRGbpJ5jAjgdQ3zj1at0YJ/9uSXM Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10267"; a="252437865" X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="252437865" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2022 06:29:01 -0800 X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="506335014" Received: from kalebaul-mobl.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.24.105]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2022 06:29:00 -0800 From: "Boeuf, Sebastien" To: devel@edk2.groups.io Cc: jiewen.yao@intel.com, jordan.l.justen@intel.com, kraxel@redhat.com, sebastien.boeuf@intel.com Subject: [PATCH v3 6/7] OvmfPkg: CloudHv: Rely on PVH memmap instead of CMOS Date: Thu, 24 Feb 2022 15:28:25 +0100 Message-Id: <38f9fc7d5e5d3ff7ce80f8dd7b57b85f15e3fda6.1645712595.git.sebastien.boeuf@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Sebastien Boeuf Instead of using the CMOS, the CloudHv platform relies on the list of memmap entries provided through the PVH boot protocol to determine the last RAM address below 4G. Signed-off-by: Sebastien Boeuf --- OvmfPkg/PlatformPei/MemDetect.c | 73 +++++++++++++++++++++++++++++ OvmfPkg/PlatformPei/PlatformPei.inf | 2 + 2 files changed, 75 insertions(+) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 1bcb5a08bc..8ecc8257f9 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -17,6 +17,7 @@ Module Name: #include #include #include +#include #include #include = @@ -315,6 +316,73 @@ ScanOrAdd64BitE820Ram ( return EFI_SUCCESS; } = +/** + Returns PVH memmap + + @param Entries Pointer to PVH memmap + @param Count Number of entries + + @return EFI_STATUS +**/ +EFI_STATUS +GetPvhMemmapEntries ( + struct hvm_memmap_table_entry **Entries, + UINT32 *Count + ) +{ + UINT32 *PVHResetVectorData; + struct hvm_start_info *pvh_start_info; + + PVHResetVectorData =3D (VOID *)(UINTN)PcdGet32 (PcdXenPvhStartOfDayStruc= tPtr); + if (PVHResetVectorData =3D=3D 0) { + return EFI_NOT_FOUND; + } + + pvh_start_info =3D (struct hvm_start_info *)(UINTN)PVHResetVectorData[0]; + + *Entries =3D (struct hvm_memmap_table_entry *)(UINTN)pvh_start_info->mem= map_paddr; + *Count =3D pvh_start_info->memmap_entries; + + return EFI_SUCCESS; +} + +STATIC +UINT64 +GetHighestSystemMemoryAddressFromPvhMemmap ( + BOOLEAN Below4gb + ) +{ + struct hvm_memmap_table_entry *Memmap; + UINT32 MemmapEntriesCount; + struct hvm_memmap_table_entry *Entry; + EFI_STATUS Status; + UINT32 Loop; + UINT64 HighestAddress; + UINT64 EntryEnd; + + HighestAddress =3D 0; + + Status =3D GetPvhMemmapEntries (&Memmap, &MemmapEntriesCount); + ASSERT_EFI_ERROR (Status); + + for (Loop =3D 0; Loop < MemmapEntriesCount; Loop++) { + Entry =3D Memmap + Loop; + EntryEnd =3D Entry->addr + Entry->size; + + if ((Entry->type =3D=3D XEN_HVM_MEMMAP_TYPE_RAM) && + (EntryEnd > HighestAddress)) + { + if (Below4gb && (EntryEnd <=3D BASE_4GB)) { + HighestAddress =3D EntryEnd; + } else if (!Below4gb && (EntryEnd >=3D BASE_4GB)) { + HighestAddress =3D EntryEnd; + } + } + } + + return HighestAddress; +} + UINT32 GetSystemMemorySizeBelow4gb ( VOID @@ -325,6 +393,11 @@ GetSystemMemorySizeBelow4gb ( UINT8 Cmos0x34; UINT8 Cmos0x35; = + if (mHostBridgeDevId =3D=3D CLOUDHV_DEVICE_ID) { + // Get the information from PVH memmap + return (UINT32)GetHighestSystemMemoryAddressFromPvhMemmap (TRUE); + } + Status =3D ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); if ((Status =3D=3D EFI_SUCCESS) && (LowerMemorySize > 0)) { return (UINT32)LowerMemorySize; diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 8ef404168c..212aa7b047 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -91,6 +91,8 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase + gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr + gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize -- = 2.32.0 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, = 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.