summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/PiSmmCpuDxeSmm
diff options
context:
space:
mode:
authorDun Tan <dun.tan@intel.com>2023-05-15 17:59:56 +0800
committerRay Ni <ray.ni@intel.com>2023-06-30 11:07:40 +0530
commit7132df94aca29caf62b88beb049cd9c169c45c09 (patch)
tree1bd1985f4f003fd5d7881a59e8b006f1a38fc356 /UefiCpuPkg/PiSmmCpuDxeSmm
parentb4dde1ae6a8a573c84a70d197a4a341f7d5bfb3d (diff)
downloadedk2-7132df94aca29caf62b88beb049cd9c169c45c09.tar.gz
edk2-7132df94aca29caf62b88beb049cd9c169c45c09.tar.bz2
edk2-7132df94aca29caf62b88beb049cd9c169c45c09.zip
UefiCpuPkg: Sort mSmmCpuSmramRanges in FindSmramInfo
Sort mSmmCpuSmramRanges after get the SMRAM info in FindSmramInfo() function. Signed-off-by: Dun Tan <dun.tan@intel.com> Cc: Eric Dong <eric.dong@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'UefiCpuPkg/PiSmmCpuDxeSmm')
-rw-r--r--UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
index 7a3ed3022d..3c69c5b7a2 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -1220,6 +1220,32 @@ PiCpuSmmEntry (
}
/**
+ 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.
@@ -1240,6 +1266,7 @@ FindSmramInfo (
UINTN Index;
UINT64 MaxSize;
BOOLEAN Found;
+ EFI_SMRAM_DESCRIPTOR SmramDescriptor;
//
// Get SMM Access Protocol
@@ -1263,6 +1290,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
//
CurrentSmramRange = NULL;