git: 9526031cd560 - main - Create macros for the Arm timer IRQ indexes

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Wed, 21 Sep 2022 09:59:59 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=9526031cd5606fe590ef69224d0db1af1603dcfe

commit 9526031cd5606fe590ef69224d0db1af1603dcfe
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-09-14 16:29:29 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-09-21 09:59:08 +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
---
 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 ebaadd5f38a8..aabcfd138012 100644
--- a/sys/arm/arm/generic_timer.c
+++ b/sys/arm/arm/generic_timer.c
@@ -78,6 +78,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)
@@ -93,8 +99,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;
@@ -104,10 +110,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 }
 };
 
@@ -412,9 +418,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);
@@ -480,17 +489,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;
@@ -509,7 +518,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)