From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.17915.1684231210780691710 for ; Tue, 16 May 2023 03:00:40 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=eea5JPVQ; spf=pass (domain: intel.com, ip: 134.134.136.100, 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=1684231240; x=1715767240; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AvZOlazLQ91MXcDyL6y+UO4P10+FuWq6PPWCe83lLn8=; b=eea5JPVQhqsQutoeLxcrRK874RRJ6IqJDt+vCGVgv6xmUMzFOPGdotLX 8ItrQbz2wrM7Sdf+u51TT7HjNND7srbj5qEa3AULDDr0SyY21umxjMGi1 jFDnnZ8YMBcSXmZ/+i6UBqKpe6p/GvEmYvH8lv/pzg49Okk9MDimnydol ZdRiggtFHSD9/o1pJnBdovMByAH5GelYc8FGy8gul4yv7l/hO/mtIsWb6 aNkIulELNiW2z5UFcThtQYFxpSijHVtfxfrP2RRs/kuee8M93nVgcGz4I JqOwnJsc3K8S357QXDMU2eaxTiR9+FsC3CK2M768tmW0OExaWgih/hIZ0 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10711"; a="417093374" X-IronPort-AV: E=Sophos;i="5.99,278,1677571200"; d="scan'208";a="417093374" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2023 03:00:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10711"; a="791019699" X-IronPort-AV: E=Sophos;i="5.99,278,1677571200"; d="scan'208";a="791019699" Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.158]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2023 03:00:38 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [Patch V4 12/15] UefiCpuPkg: Sort mSmmCpuSmramRanges in FindSmramInfo Date: Tue, 16 May 2023 17:59:29 +0800 Message-Id: <20230516095932.1525-13-dun.tan@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20230516095932.1525-1-dun.tan@intel.com> References: <20230516095932.1525-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 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c index c0e368ea94..d69e976269 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; + VOID *Buffer; // // Get SMM Access Protocol @@ -1240,6 +1267,14 @@ FindSmramInfo ( mSmmCpuSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR); + // + // Sort the mSmmCpuSmramRanges + // + Buffer = AllocateZeroPool (sizeof (EFI_SMRAM_DESCRIPTOR)); + ASSERT (Buffer != NULL); + QuickSort (mSmmCpuSmramRanges, mSmmCpuSmramRangeCount, sizeof (EFI_SMRAM_DESCRIPTOR), (BASE_SORT_COMPARE)CpuSmramRangeCompare, Buffer); + FreePool (Buffer); + // // Find the largest SMRAM range between 1MB and 4GB that is at least 256K - 4K in size // -- 2.31.1.windows.1