git: d7474d9b3104 - stable/13 - arm64: gic: disable the ITS if it's enabled prior to configuration

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sun, 18 Sep 2022 06:27:01 UTC
The branch stable/13 has been updated by kevans:

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

commit d7474d9b31049aa5bef7b780be2752f6d489ec86
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2022-03-19 03:03:44 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2022-09-18 06:26:38 +0000

    arm64: gic: disable the ITS if it's enabled prior to configuration
    
    The ITS is defined to be disabled on a warm reset, but we may be coming
    in via another kernel/hypervisor type setup where the ITS has been
    previously configured then relinquished to the next kernel in the chain.
    
    If it's enabled, the later configuration of GITS_BASER will almost
    certainly fail -- clear it to prevent that.
    
    Reviewed by:    andrew
    Sponsored by:   Ampere Computing
    Submitted by:   Klara, Inc.
    
    (cherry picked from commit 1236b04bb7045e541b2343543e356273db20ee56)
---
 sys/arm64/arm64/gicv3_its.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c
index 2af20e5d03fc..82fd57cb42e8 100644
--- a/sys/arm64/arm64/gicv3_its.c
+++ b/sys/arm64/arm64/gicv3_its.c
@@ -822,7 +822,7 @@ gicv3_its_attach(device_t dev)
 	struct gicv3_its_softc *sc;
 	int domain, err, i, rid;
 	uint64_t phys;
-	uint32_t iidr;
+	uint32_t ctlr, iidr;
 
 	sc = device_get_softc(dev);
 
@@ -855,6 +855,18 @@ gicv3_its_attach(device_t dev)
 		}
 	}
 
+	/*
+	 * GIT_CTLR_EN is mandated to reset to 0 on a Warm reset, but we may be
+	 * coming in via, for instance, a kexec/kboot style setup where a
+	 * previous kernel has configured then relinquished control.  Clear it
+	 * so that we can reconfigure GITS_BASER*.
+	 */
+	ctlr = gic_its_read_4(sc, GITS_CTLR);
+	if ((ctlr & GITS_CTLR_EN) != 0) {
+		ctlr &= ~GITS_CTLR_EN;
+		gic_its_write_4(sc, GITS_CTLR, ctlr);
+	}
+
 	/* Allocate the private tables */
 	err = gicv3_its_table_init(dev, sc);
 	if (err != 0)
@@ -887,8 +899,7 @@ gicv3_its_attach(device_t dev)
 			sc->sc_its_cols[cpu] = NULL;
 
 	/* Enable the ITS */
-	gic_its_write_4(sc, GITS_CTLR,
-	    gic_its_read_4(sc, GITS_CTLR) | GITS_CTLR_EN);
+	gic_its_write_4(sc, GITS_CTLR, ctlr | GITS_CTLR_EN);
 
 	/* Create the LPI configuration table */
 	gicv3_its_conftable_init(sc);