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.web11.386.1686191344244208222 for ; Wed, 07 Jun 2023 19:29:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=R4rqj5eu; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: dun.tan@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686191349; x=1717727349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ed2BMfdXc8YCfvvvlsOm5M92zlRLdA8ng9RqSWbb4E0=; b=R4rqj5euXtpAofC9DyXGVQyeXMmYB/qlmYQQD+YkMebEjBFU/AyBt25g +ro9mT9U9FmWcMLmytaj+mXqytJBk15X131PDNa6zlxuTf6W+YdDtbEtN IdCAwINk7/7Ipo4p3NLSwGG4Phq2EyxZF78xFdEDXEoVdTrrBaT48bSPJ PJLYlWvCvADJ+a3qn19zq3wn75Z7aH5LYlhWQhDgOpqac9qEv2NQvq6AY ysB+HKibLEwFVwuwZt3BdxS6T+QvvICWfEByu+yKVGDdcghjr7OPRpQPC VIJBRdrtaYMbW7HCtAM6be9alpf3GbTUJeDVcxRC0GnLhbwy1kyF7OLxU A==; X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="357184422" X-IronPort-AV: E=Sophos;i="6.00,225,1681196400"; d="scan'208";a="357184422" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2023 19:29:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="774877911" X-IronPort-AV: E=Sophos;i="6.00,225,1681196400"; d="scan'208";a="774877911" Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.158]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2023 19:29:07 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [Patch V5 11/14] UefiCpuPkg: Sort mSmmCpuSmramRanges in FindSmramInfo Date: Thu, 8 Jun 2023 10:27:39 +0800 Message-Id: <20230608022742.1292-12-dun.tan@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20230608022742.1292-1-dun.tan@intel.com> References: <20230608022742.1292-1-dun.tan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sort mSmmCpuSmramRanges after get the SMRAM info in FindSmramInfo() function. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c index 2144d6ade8..2568ffd677 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -1197,6 +1197,32 @@ PiCpuSmmEntry ( return EFI_SUCCESS; } +/** + Function to compare 2 EFI_SMRAM_DESCRIPTOR based on CpuStart. + + @param[in] Buffer1 pointer to Device Path poiner to compare + @param[in] Buffer2 pointer to second DevicePath pointer to compare + + @retval 0 Buffer1 equal to Buffer2 + @retval <0 Buffer1 is less than Buffer2 + @retval >0 Buffer1 is greater than Buffer2 +**/ +INTN +EFIAPI +CpuSmramRangeCompare ( + IN CONST VOID *Buffer1, + IN CONST VOID *Buffer2 + ) +{ + if (((EFI_SMRAM_DESCRIPTOR *)Buffer1)->CpuStart > ((EFI_SMRAM_DESCRIPTOR *)Buffer2)->CpuStart) { + return 1; + } else if (((EFI_SMRAM_DESCRIPTOR *)Buffer1)->CpuStart < ((EFI_SMRAM_DESCRIPTOR *)Buffer2)->CpuStart) { + return -1; + } + + return 0; +} + /** Find out SMRAM information including SMRR base and SMRR size. @@ -1218,6 +1244,7 @@ FindSmramInfo ( UINTN Index; UINT64 MaxSize; BOOLEAN Found; + EFI_SMRAM_DESCRIPTOR SmramDescriptor; // // Get SMM Access Protocol @@ -1240,6 +1267,11 @@ FindSmramInfo ( mSmmCpuSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR); + // + // Sort the mSmmCpuSmramRanges + // + QuickSort (mSmmCpuSmramRanges, mSmmCpuSmramRangeCount, sizeof (EFI_SMRAM_DESCRIPTOR), (BASE_SORT_COMPARE)CpuSmramRangeCompare, &SmramDescriptor); + // // Find the largest SMRAM range between 1MB and 4GB that is at least 256K - 4K in size // -- 2.31.1.windows.1