[PATCH v1 3/3] DynamicTablesPkg: Test for duplicate GT Block frame numbers


Krzysztof Koch
 

Check for duplicate frame numbers when populating the GT Block Timer
Frames inside the GTDT table generator.

Signed-off-by: Krzysztof Koch <krzysztof.koch@...>
---

Notes:
v1:
- Detect duplicate GT Frame Numbers in GTDT [Krzysztof]

DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c | 66 +++++++++++++++++++-
1 file changed, 64 insertions(+), 2 deletions(-)

diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
index 8d9ddcf9244b9f8b795edf7a53dd8a071bb121bc..d1ac9110cc5c8df8506b6db09cc362fdb0df8d76 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
@@ -179,6 +179,55 @@ AddGenericWatchdogList (
} // for
}

+/**
+ Function to test if two Generic Timer Block Frame Info structures have the
+ same frame number.
+
+ @param [in] Frame1 Pointer to the first GT Block Frame Info
+ structure.
+ @param [in] Frame2 Pointer to the second GT Block Frame Info
+ structure.
+ @param [in] Index1 Index of Frame1 in the shared GT Block Frame
+ Information List.
+ @param [in] Index2 Index of Frame2 in the shared GT Block Frame
+ Information List.
+
+ @retval TRUE Frame1 and Frame2 have the same frame number.
+ @return FALSE Frame1 and Frame2 have different frame numbers.
+
+**/
+BOOLEAN
+EFIAPI
+IsGtFrameNumberEqual (
+ IN CONST VOID * Frame1,
+ IN CONST VOID * Frame2,
+ IN UINTN Index1,
+ IN UINTN Index2
+ )
+{
+ UINT8 FrameNumber1;
+ UINT8 FrameNumber2;
+
+ ASSERT ((Frame1 != NULL) && (Frame2 != NULL));
+
+ FrameNumber1 = ((CM_ARM_GTBLOCK_TIMER_FRAME_INFO*)Frame1)->FrameNumber;
+ FrameNumber2 = ((CM_ARM_GTBLOCK_TIMER_FRAME_INFO*)Frame2)->FrameNumber;
+
+ if (FrameNumber1 == FrameNumber2) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: GTDT: GT Block Frame Info Structures %d and %d have the same " \
+ "frame number: 0x%x.\n",
+ Index1,
+ Index2,
+ FrameNumber1
+ ));
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/** Update the GT Block Timer Frame lists in the GTDT Table.

@param [in] GtBlockFrame Pointer to the GT Block Frames
@@ -187,8 +236,8 @@ AddGenericWatchdogList (
Information List.
@param [in] GTBlockFrameCount Number of GT Block Frames.

- @retval EFI_SUCCESS Table generated successfully.
- @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_SUCCESS Table generated successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
@@ -198,6 +247,8 @@ AddGTBlockTimerFrames (
IN UINT32 GTBlockFrameCount
)
{
+ BOOLEAN IsFrameNumberDuplicated;
+
ASSERT (GtBlockFrame != NULL);
ASSERT (GTBlockTimerFrameList != NULL);

@@ -211,6 +262,17 @@ AddGTBlockTimerFrames (
return EFI_INVALID_PARAMETER;
}

+ IsFrameNumberDuplicated = FindDuplicateValue (
+ GTBlockTimerFrameList,
+ GTBlockFrameCount,
+ sizeof (CM_ARM_GTBLOCK_TIMER_FRAME_INFO),
+ IsGtFrameNumberEqual
+ );
+ // Duplicate entry was found so timer frame numbers provided are invalid
+ if (IsFrameNumberDuplicated) {
+ return EFI_INVALID_PARAMETER;
+ }
+
while (GTBlockFrameCount-- != 0) {
DEBUG ((
DEBUG_INFO,
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'

Join devel@edk2.groups.io to automatically receive all group messages.