From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.7188.1646227973092336980 for ; Wed, 02 Mar 2022 05:32:53 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=eHki9bMs; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1646227973; x=1677763973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6L0d7Yyrmw8N+UZLPJJV2pBPZzqj7iTelftda8evHpg=; b=eHki9bMsltutzCtaLBJcHaPg239GmqfcVwRQnLEgwUg+KUTt/d2Rm56r HxwizWv3TBBSB7zFZSHEpTi509tdjNnlH1f6Bsen0cOxhp7ia7sBbU8ZM P1b4X4wSzqYalBoU1ym/8iE0e9WTcgDH8rRfHsOYLQQJc7obI0rAOfZYC p4syoSSwBBdsTQ1bR2sVaC2flZii29Dnf0Kxir9o/SAxpG4GJEU2drwuA hr5jHlWrgtRPRlMk6VYLF6jFzMRRNj8DL7E5+Aakag+tmoQu/e7OBLtz6 atZqDRlznOpfeOzwNMGd6PN+r9Lp6lqvQPFtjbRSaDzSUJmr8jX2qijN4 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10273"; a="253130664" X-IronPort-AV: E=Sophos;i="5.90,149,1643702400"; d="scan'208";a="253130664" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 05:32:43 -0800 X-IronPort-AV: E=Sophos;i="5.90,149,1643702400"; d="scan'208";a="535389541" Received: from spearce-mobl1.amr.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.27.130]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 05:32:41 -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 v6 7/8] OvmfPkg: CloudHv: Rely on PVH memmap instead of CMOS Date: Wed, 2 Mar 2022 14:31:36 +0100 Message-Id: <72270dff2f01a8cb955d6c8eb0bdd1fb9f156ffe.1646227817.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. Acked-by: Gerd Hoffmann 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.