public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Kun Qin" <kuqin12@gmail.com>
To: devel@edk2.groups.io
Cc: Leif Lindholm <quic_llindhol@quicinc.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>
Subject: [edk2-devel] [PATCH v1 2/3] ArmPkg: ArmGicLib: Added GIC v3 and v4 support to ArmGicSendSgiTo
Date: Mon, 24 Jul 2023 13:15:21 -0700	[thread overview]
Message-ID: <20230724201523.852-3-kuqin12@gmail.com> (raw)
In-Reply-To: <20230724201523.852-1-kuqin12@gmail.com>

From: Kun Qin <kuqin@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4466

This change extended the existing function `ArmGicSendSgiTo` of ArmGicLib
to format the incoming parameters to comply with GICv3 and GICv4 spec,
and signal software generated interrupts to non secure group 1 at EL1.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Signed-off-by: Kun Qin <kuqin@microsoft.com>
---
 ArmPkg/Drivers/ArmGic/ArmGicLib.c  | 52 +++++++++++++++++---
 ArmPkg/Include/Library/ArmGicLib.h | 22 +++++++++
 2 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
index 7f4bb248fc72..830d822d2c05 100644
--- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
+++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
@@ -146,12 +146,52 @@ ArmGicSendSgiTo (
   IN  UINT8  SgiId
   )
 {
-  MmioWrite32 (
-    GicDistributorBase + ARM_GIC_ICDSGIR,
-    ((TargetListFilter & 0x3) << 24) |
-    ((CPUTargetList & 0xFF) << 16)   |
-    (SgiId & 0xF)
-    );
+  ARM_GIC_ARCH_REVISION  Revision;
+  UINT32                 ApplicableTargets;
+  UINT32                 AFF3;
+  UINT32                 AFF2;
+  UINT32                 AFF1;
+  UINT32                 AFF0;
+  UINT32                 Irm;
+  UINT64                 SGIValue;
+
+  Revision = ArmGicGetSupportedArchRevision ();
+  if (Revision == ARM_GIC_ARCH_REVISION_2) {
+    MmioWrite32 (
+      GicDistributorBase + ARM_GIC_ICDSGIR,
+      ((TargetListFilter & 0x3) << 24) |
+      ((CPUTargetList & 0xFF) << 16)   |
+      (SgiId & 0xF)
+      );
+  } else {
+    // Below routine is adopted from gicv3_raise_secure_g0_sgi in TF-A
+
+    /* Extract affinity fields from target */
+    AFF0 = GET_MPIDR_AFF0 (CPUTargetList);
+    AFF1 = GET_MPIDR_AFF1 (CPUTargetList);
+    AFF2 = GET_MPIDR_AFF2 (CPUTargetList);
+    AFF3 = GET_MPIDR_AFF3 (CPUTargetList);
+
+    /*
+     * Make target list from affinity 0, and ensure GICv3 SGI can target
+     * this PE.
+     */
+    ApplicableTargets = (1 << AFF0);
+
+    /*
+     * Evaluate the filter to see if this is for the target or all others
+     */
+    Irm = (TargetListFilter == ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE) ? SGIR_IRM_TO_OTHERS : SGIR_IRM_TO_AFF;
+
+    /* Raise SGI to PE specified by its affinity */
+    SGIValue = GICV3_SGIR_VALUE (AFF3, AFF2, AFF1, SgiId, Irm, ApplicableTargets);
+
+    /*
+     * Ensure that any shared variable updates depending on out of band
+     * interrupt trigger are observed before raising SGI.
+     */
+    ArmGicV3SendNsG1Sgi (SGIValue);
+  }
 }
 
 /*
diff --git a/ArmPkg/Include/Library/ArmGicLib.h b/ArmPkg/Include/Library/ArmGicLib.h
index 773b27954522..28d58f187d4f 100644
--- a/ArmPkg/Include/Library/ArmGicLib.h
+++ b/ArmPkg/Include/Library/ArmGicLib.h
@@ -110,6 +110,28 @@
 // Bit Mask for
 #define ARM_GIC_ICCIAR_ACKINTID  0x3FF
 
+/* ICC SGI macros */
+#define SGIR_TGT_MASK     ((UINT64)0xffff)
+#define SGIR_AFF1_SHIFT   16
+#define SGIR_INTID_SHIFT  24
+#define SGIR_INTID_MASK   ((UINT64)0xf)
+#define SGIR_AFF2_SHIFT   32
+#define SGIR_IRM_SHIFT    40
+#define SGIR_IRM_MASK     ((UINT64)0x1)
+#define SGIR_AFF3_SHIFT   48
+#define SGIR_AFF_MASK     ((UINT64)0xff)
+
+#define SGIR_IRM_TO_AFF     0
+#define SGIR_IRM_TO_OTHERS  1
+
+#define GICV3_SGIR_VALUE(_aff3, _aff2, _aff1, _intid, _irm, _tgt) \
+  ((((UINT64) (_aff3) & SGIR_AFF_MASK) << SGIR_AFF3_SHIFT) | \
+   (((UINT64) (_irm) & SGIR_IRM_MASK) << SGIR_IRM_SHIFT) | \
+   (((UINT64) (_aff2) & SGIR_AFF_MASK) << SGIR_AFF2_SHIFT) | \
+   (((_intid) & SGIR_INTID_MASK) << SGIR_INTID_SHIFT) | \
+   (((_aff1) & SGIR_AFF_MASK) << SGIR_AFF1_SHIFT) | \
+   ((_tgt) & SGIR_TGT_MASK))
+
 UINT32
 EFIAPI
 ArmGicGetInterfaceIdentification (
-- 
2.41.0.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107189): https://edk2.groups.io/g/devel/message/107189
Mute This Topic: https://groups.io/mt/100337223/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-07-24 20:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-24 20:15 [edk2-devel] [PATCH v1 0/3] Add support for handling SGI and pending interrupts Kun Qin
2023-07-24 20:15 ` [edk2-devel] [PATCH v1 1/3] ArmPkg: ArmGic: Added support to send SGI to NS G1 EL1 Kun Qin
2023-07-24 20:15 ` Kun Qin [this message]
2023-07-24 20:15 ` [edk2-devel] [PATCH v1 3/3] ArmPkg: ArmGic: Added functionalities to manipulate pending interrupts Kun Qin
2023-07-26  8:45 ` [edk2-devel] [PATCH v1 0/3] Add support for handling SGI and " Ard Biesheuvel
2023-07-26 18:45   ` Kun Qin
2023-08-03 15:33     ` Ard Biesheuvel
2023-08-03 17:02       ` Leif Lindholm
2023-08-03 18:15         ` Kun Qin

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=20230724201523.852-3-kuqin12@gmail.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