git: 9eea5eb52a0e - stable/14 - gicv3: Don't allocate pend_base if we're already started

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 16 Apr 2024 21:42:46 UTC
The branch stable/14 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=9eea5eb52a0eb61c46da0721176eac2c0d820531

commit 9eea5eb52a0eb61c46da0721176eac2c0d820531
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-02-28 14:08:32 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-16 21:28:37 +0000

    gicv3: Don't allocate pend_base if we're already started
    
    If the gicv3 is already started, then don't allocate memory for the
    pend_base tables.
    
    Sponsored by:           Netflix
    Reviewed by:            andrew
    Differential Revision:  https://reviews.freebsd.org/D44034
    
    (cherry picked from commit ddd98f5a626df5de51fd5c2460592d9b95a49179)
---
 sys/arm64/arm64/gicv3_its.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c
index c9eff1e9f474..de65d130ce91 100644
--- a/sys/arm64/arm64/gicv3_its.c
+++ b/sys/arm64/arm64/gicv3_its.c
@@ -287,6 +287,7 @@ struct gicv3_its_softc {
 #define	ITS_FLAGS_CMDQ_FLUSH		0x00000001
 #define	ITS_FLAGS_LPI_CONF_FLUSH	0x00000002
 #define	ITS_FLAGS_ERRATA_CAVIUM_22375	0x00000004
+#define	ITS_FLAGS_LPI_PREALLOC		0x00000008
 	u_int sc_its_flags;
 	bool	trace_enable;
 	vm_page_t ma; /* fake msi page */
@@ -681,6 +682,7 @@ gicv3_its_conftable_init(struct gicv3_its_softc *sc)
 {
 	/* note: we assume the ITS children are serialized by the parent */
 	static void *conf_table;
+	int extra_flags = 0;
 	device_t gicv3;
 	uint32_t ctlr;
 
@@ -697,6 +699,7 @@ gicv3_its_conftable_init(struct gicv3_its_softc *sc)
 	gicv3 = device_get_parent(sc->dev);
 	ctlr = gic_r_read_4(gicv3, GICR_CTLR);
 	if ((ctlr & GICR_CTLR_LPI_ENABLE) != 0) {
+		extra_flags = ITS_FLAGS_LPI_PREALLOC;
 		panic("gicv3 already enabled, can't reprogram.");
 	} else {
 
@@ -709,6 +712,7 @@ gicv3_its_conftable_init(struct gicv3_its_softc *sc)
 		    LPI_CONFTAB_ALIGN, 0);
 	}
 	sc->sc_conf_base = conf_table;
+	sc->sc_its_flags |= extra_flags;
 
 	/* Set the default configuration */
 	memset(sc->sc_conf_base, GIC_PRIORITY_MAX | LPI_CONF_GROUP1,
@@ -721,19 +725,20 @@ gicv3_its_conftable_init(struct gicv3_its_softc *sc)
 static void
 gicv3_its_pendtables_init(struct gicv3_its_softc *sc)
 {
-	int i;
 
-	for (i = 0; i <= mp_maxid; i++) {
-		if (CPU_ISSET(i, &sc->sc_cpus) == 0)
-			continue;
+	if ((sc->sc_its_flags & ITS_FLAGS_LPI_PREALLOC) == 0) {
+		for (int i = 0; i <= mp_maxid; i++) {
+			if (CPU_ISSET(i, &sc->sc_cpus) == 0)
+				continue;
 
-		sc->sc_pend_base[i] = (vm_offset_t)contigmalloc(
-		    LPI_PENDTAB_SIZE, M_GICV3_ITS, M_WAITOK | M_ZERO,
-		    0, LPI_PENDTAB_MAX_ADDR, LPI_PENDTAB_ALIGN, 0);
+			sc->sc_pend_base[i] = (vm_offset_t)contigmalloc(
+			    LPI_PENDTAB_SIZE, M_GICV3_ITS, M_WAITOK | M_ZERO,
+			    0, LPI_PENDTAB_MAX_ADDR, LPI_PENDTAB_ALIGN, 0);
 
-		/* Flush so the ITS can see the memory */
-		cpu_dcache_wb_range((vm_offset_t)sc->sc_pend_base[i],
-		    LPI_PENDTAB_SIZE);
+			/* Flush so the ITS can see the memory */
+			cpu_dcache_wb_range((vm_offset_t)sc->sc_pend_base[i],
+			    LPI_PENDTAB_SIZE);
+		}
 	}
 }