git: 85194e20d047 - stable/13 - Create macros for the Arm timer IRQ indexes

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 17 Oct 2022 10:39:09 UTC
The branch stable/13 has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=85194e20d047bdefd835478452c6f318f4875c08

commit 85194e20d047bdefd835478452c6f318f4875c08
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-09-14 16:29:29 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-10-17 08:41:54 +0000

    Create macros for the Arm timer IRQ indexes
    
    Rather than hard coding these values use a macro to document which
    interrupt is being used.
    
    Reviewed by:    emaste
    Obtained from:  https://github.com/FreeBSD-UPB/freebsd-src (earlier version)
    Sponsored by:   Innovate UK
    Sponsored by:   The FreeBSD Foundation
    Sponsored by:   University Politehnica of Bucharest
    Differential Revision: https://reviews.freebsd.org/D36600
    
    (cherry picked from commit 9526031cd5606fe590ef69224d0db1af1603dcfe)
---
 sys/arm/arm/generic_timer.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c
index e3c54c237967..e465d1afbb3d 100644
--- a/sys/arm/arm/generic_timer.c
+++ b/sys/arm/arm/generic_timer.c
@@ -74,6 +74,12 @@ __FBSDID("$FreeBSD$");
 #include <dev/acpica/acpivar.h>
 #endif
 
+#define	GT_PHYS_SECURE		0
+#define	GT_PHYS_NONSECURE	1
+#define	GT_VIRT			2
+#define	GT_HYP			3
+#define	GT_IRQ_COUNT		4
+
 #define	GT_CTRL_ENABLE		(1 << 0)
 #define	GT_CTRL_INT_MASK	(1 << 1)
 #define	GT_CTRL_INT_STAT	(1 << 2)
@@ -89,8 +95,8 @@ __FBSDID("$FreeBSD$");
 #define	GT_CNTKCTL_PL0PCTEN	(1 << 0) /* PL0 CNTPCT and CNTFRQ access */
 
 struct arm_tmr_softc {
-	struct resource		*res[4];
-	void			*ihl[4];
+	struct resource		*res[GT_IRQ_COUNT];
+	void			*ihl[GT_IRQ_COUNT];
 	uint64_t		(*get_cntxct)(bool);
 	uint32_t		clkfreq;
 	struct eventtimer	et;
@@ -100,10 +106,10 @@ struct arm_tmr_softc {
 static struct arm_tmr_softc *arm_tmr_sc = NULL;
 
 static struct resource_spec timer_spec[] = {
-	{ SYS_RES_IRQ,		0,	RF_ACTIVE },	/* Secure */
-	{ SYS_RES_IRQ,		1,	RF_ACTIVE },	/* Non-secure */
-	{ SYS_RES_IRQ,		2,	RF_ACTIVE | RF_OPTIONAL }, /* Virt */
-	{ SYS_RES_IRQ,		3,	RF_ACTIVE | RF_OPTIONAL	}, /* Hyp */
+	{ SYS_RES_IRQ,	GT_PHYS_SECURE,		RF_ACTIVE },
+	{ SYS_RES_IRQ,	GT_PHYS_NONSECURE,	RF_ACTIVE },
+	{ SYS_RES_IRQ,	GT_VIRT,		RF_ACTIVE | RF_OPTIONAL },
+	{ SYS_RES_IRQ,	GT_HYP,			RF_ACTIVE | RF_OPTIONAL	},
 	{ -1, 0 }
 };
 
@@ -366,9 +372,12 @@ arm_tmr_acpi_identify(driver_t *driver, device_t parent)
 		goto out;
 	}
 
-	arm_tmr_acpi_add_irq(parent, dev, 0, gtdt->SecureEl1Interrupt);
-	arm_tmr_acpi_add_irq(parent, dev, 1, gtdt->NonSecureEl1Interrupt);
-	arm_tmr_acpi_add_irq(parent, dev, 2, gtdt->VirtualTimerInterrupt);
+	arm_tmr_acpi_add_irq(parent, dev, GT_PHYS_SECURE,
+	    gtdt->SecureEl1Interrupt);
+	arm_tmr_acpi_add_irq(parent, dev, GT_PHYS_NONSECURE,
+	    gtdt->NonSecureEl1Interrupt);
+	arm_tmr_acpi_add_irq(parent, dev, GT_VIRT,
+	    gtdt->VirtualTimerInterrupt);
 
 out:
 	acpi_unmap_table(gtdt);
@@ -434,17 +443,17 @@ arm_tmr_attach(device_t dev)
 
 #ifdef __aarch64__
 	/* Use the virtual timer if we have one. */
-	if (sc->res[2] != NULL) {
+	if (sc->res[GT_VIRT] != NULL) {
 		sc->physical = false;
-		first_timer = 2;
-		last_timer = 2;
+		first_timer = GT_VIRT;
+		last_timer = GT_VIRT;
 	} else
 #endif
 	/* Otherwise set up the secure and non-secure physical timers. */
 	{
 		sc->physical = true;
-		first_timer = 0;
-		last_timer = 1;
+		first_timer = GT_PHYS_SECURE;
+		last_timer = GT_PHYS_NONSECURE;
 	}
 
 	arm_tmr_sc = sc;
@@ -463,7 +472,7 @@ arm_tmr_attach(device_t dev)
 	}
 
 	/* Disable the virtual timer until we are ready */
-	if (sc->res[2] != NULL)
+	if (sc->res[GT_VIRT] != NULL)
 		arm_tmr_disable(false);
 	/* And the physical */
 	if (sc->physical)