git: d42fa41bc2ed - stable/13 - Make SMCCC usable by device drivers

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 15 May 2023 15:46:03 UTC
The branch stable/13 has been updated by andrew:

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

commit d42fa41bc2edfe0a6ffb49f79fcb2790a743ae4a
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-06-04 11:13:51 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2023-05-15 10:55:36 +0000

    Make SMCCC usable by device drivers
    
    To allow device drivers to call into SMCCC we need to initialise it
    earlier. As it depends on PSCI, and that is detected via ACPI or FDT
    move the call to smccc_init to the PSCI driver.
    
    Add a function for drivers to read the smccc version, or 0 if smccc
    is not present.
    
    (cherry picked from commit 0600af1ff16041f15633b2263a8ad9525eecd2f1)
    (cherry picked from commit 7ca55fcc541b375c83eaf75f0658b79f250c82fd)
---
 sys/dev/psci/psci.c  |  4 ++++
 sys/dev/psci/smccc.c | 11 ++++++++---
 sys/dev/psci/smccc.h |  2 ++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/sys/dev/psci/psci.c b/sys/dev/psci/psci.c
index d54ee62fb328..228850ac6895 100644
--- a/sys/dev/psci/psci.c
+++ b/sys/dev/psci/psci.c
@@ -348,6 +348,10 @@ psci_attach(device_t dev, psci_initfn_t psci_init, int default_version)
 	if (psci_init(dev, default_version))
 		return (ENXIO);
 
+#ifdef __aarch64__
+	smccc_init();
+#endif
+
 	psci_softc = sc;
 
 	return (0);
diff --git a/sys/dev/psci/smccc.c b/sys/dev/psci/smccc.c
index 54673d431d4c..64732d58e2d4 100644
--- a/sys/dev/psci/smccc.c
+++ b/sys/dev/psci/smccc.c
@@ -47,8 +47,8 @@ __FBSDID("$FreeBSD$");
 /* Assume 1.0 until we detect a later version */
 static uint32_t	smccc_version = SMCCC_VERSION_1_0;
 
-static void
-smccc_init(void *dummy)
+void
+smccc_init(void)
 {
 	int32_t features;
 	uint32_t ret;
@@ -67,7 +67,12 @@ smccc_init(void *dummy)
 		    SMCCC_VERSION_MINOR(smccc_version));
 	}
 }
-SYSINIT(smccc_start, SI_SUB_CONFIGURE, SI_ORDER_ANY, smccc_init, NULL);
+
+uint32_t
+smccc_get_version(void)
+{
+	return (smccc_version);
+}
 
 int32_t
 smccc_arch_features(uint32_t smccc_func_id)
diff --git a/sys/dev/psci/smccc.h b/sys/dev/psci/smccc.h
index 6bb4dbcf7076..4644ee1cc7b3 100644
--- a/sys/dev/psci/smccc.h
+++ b/sys/dev/psci/smccc.h
@@ -82,6 +82,8 @@ struct arm_smccc_res {
 #define	SMCCC_RET_NOT_SUPPORTED		-1
 #define	SMCCC_RET_NOT_REQUIRED		-2
 
+void smccc_init(void);
+uint32_t smccc_get_version(void);
 int32_t smccc_arch_features(uint32_t);
 int smccc_arch_workaround_1(void);
 int smccc_arch_workaround_2(int);