git: 02eaed648f40 - stable/14 - gicv3: Change how we initialize its children.

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

URL: https://cgit.FreeBSD.org/src/commit/?id=02eaed648f401f2aceaa1cea3fb2ca2e949b47e4

commit 02eaed648f401f2aceaa1cea3fb2ca2e949b47e4
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-02-28 14:08:15 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-16 21:27:35 +0000

    gicv3: Change how we initialize its children.
    
    The current code is written such that all the attach routines can do so
    in parallel. However, newbus serializes children today, and is likely to
    do so in the future. Only allocate memory for the first time. Add an
    assertion that this memory is allocated for larger units.
    
    Sponsored by:           Netflix
    Reviewed by:            andrew
    Differential Revision:  https://reviews.freebsd.org/D44032
    
    (cherry picked from commit 15c8a610a80dfe1980e043174d0fcc8034868676)
---
 sys/arm64/arm64/gicv3_its.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c
index 777e20649f33..16ea48f49b7f 100644
--- a/sys/arm64/arm64/gicv3_its.c
+++ b/sys/arm64/arm64/gicv3_its.c
@@ -292,8 +292,6 @@ struct gicv3_its_softc {
 	vm_page_t ma; /* fake msi page */
 };
 
-static void *conf_base;
-
 typedef void (its_quirk_func_t)(device_t);
 static its_quirk_func_t its_quirk_cavium_22375;
 
@@ -681,20 +679,26 @@ gicv3_its_table_init(device_t dev, struct gicv3_its_softc *sc)
 static void
 gicv3_its_conftable_init(struct gicv3_its_softc *sc)
 {
-	void *conf_table;
-
-	conf_table = atomic_load_ptr(&conf_base);
-	if (conf_table == NULL) {
-		conf_table = contigmalloc(LPI_CONFTAB_SIZE,
-		    M_GICV3_ITS, M_WAITOK, 0, LPI_CONFTAB_MAX_ADDR,
-		    LPI_CONFTAB_ALIGN, 0);
+	/* note: we assume the ITS children are serialized by the parent */
+	static void *conf_table;
 
-		if (atomic_cmpset_ptr((uintptr_t *)&conf_base,
-		    (uintptr_t)NULL, (uintptr_t)conf_table) == 0) {
-			contigfree(conf_table, LPI_CONFTAB_SIZE, M_GICV3_ITS);
-			conf_table = atomic_load_ptr(&conf_base);
-		}
+	/*
+	 * The PROPBASER is a singleton in our parent. We only set it up the
+	 * first time through. conf_table is effectively global to all the units
+	 * and we rely on subr_bus to serialize probe/attach.
+	 */
+	if (conf_table != NULL) {
+		sc->sc_conf_base = conf_table;
+		return;
 	}
+
+        /*
+         * Just allocate contiguous pages. We'll configure the PROPBASER
+         * register later in its_init_cpu_lpi().
+         */
+	conf_table = contigmalloc(LPI_CONFTAB_SIZE,
+	    M_GICV3_ITS, M_WAITOK, 0, LPI_CONFTAB_MAX_ADDR,
+	    LPI_CONFTAB_ALIGN, 0);
 	sc->sc_conf_base = conf_table;
 
 	/* Set the default configuration */