public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Krzysztof Koch" <krzysztof.koch@arm.com>
To: <devel@edk2.groups.io>
Cc: <leif.lindholm@linaro.org>, <Sami.Mujawar@arm.com>,
	<Alexei.Fedorov@arm.com>, <Matteo.Carlini@arm.com>,
	<Stephanie.Hughes-Fitt@arm.com>, <nd@arm.com>
Subject: [PATCH v1 3/3] DynamicTablesPkg: Test for duplicate GT Block frame numbers
Date: Thu, 16 May 2019 11:11:33 +0100	[thread overview]
Message-ID: <20190516101133.34912-4-krzysztof.koch@arm.com> (raw)
In-Reply-To: <20190516101133.34912-1-krzysztof.koch@arm.com>

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

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

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)'



  parent reply	other threads:[~2019-05-16 10:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 10:11 [PATCH v1 0/3] Detect duplicate field values in ACPI tables Krzysztof Koch
2019-05-16 10:11 ` [PATCH v1 1/3] DynamicTablesPkg: Add code for finding duplicate values in arrays Krzysztof Koch
2019-05-16 10:11 ` [PATCH v1 2/3] DynamicTablesPkg: Test for duplicate UIDs in MADT generator Krzysztof Koch
2019-05-16 10:11 ` Krzysztof Koch [this message]
2019-06-03 10:56 ` [edk2-devel] [PATCH v1 0/3] Detect duplicate field values in ACPI tables Alexei.Fedorov
2019-06-10 19:46 ` Sami Mujawar
2019-06-10 19:53   ` Sami Mujawar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190516101133.34912-4-krzysztof.koch@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox