git: 1236b04bb704 - main - arm64: gic: disable the ITS if it's enabled prior to configuration

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sat, 19 Mar 2022 03:47:20 UTC
The branch main has been updated by kevans:

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

commit 1236b04bb7045e541b2343543e356273db20ee56
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2022-03-19 03:03:44 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2022-03-19 03:03:44 +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.
    Differential Revision:  https://reviews.freebsd.org/D34546
---
 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 2388aeb55f8c..7b06a44f35b3 100644
--- a/sys/arm64/arm64/gicv3_its.c
+++ b/sys/arm64/arm64/gicv3_its.c
@@ -825,7 +825,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);
 
@@ -865,6 +865,18 @@ gicv3_its_attach(device_t dev)
 		sc->sc_ds = DOMAINSET_RR();
 	}
 
+	/*
+	 * 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)
@@ -890,8 +902,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);