feat(sme): add sme helper routines and add streaming sve support
This patch adds a few helper routines to set the Streaming SVE vector
length (SVL) in the SMCR_EL2 register, to enable/disable FEAT_SME_FA64
and to get CPU's Streaming SVE mode status.
This patch also makes SVE compare routines compatible for both normal
SVE and streaming SVE mode.
Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Change-Id: I7294bb17a85de395a321e99241704066662c90e8
diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h
index d607029..13d7063 100644
--- a/include/lib/aarch64/arch.h
+++ b/include/lib/aarch64/arch.h
@@ -967,7 +967,13 @@
/* SMCR_ELx definitions */
#define SMCR_ELX_LEN_SHIFT U(0)
-#define SMCR_ELX_LEN_MASK U(0x1ff)
+#define SMCR_ELX_LEN_WIDTH U(4)
+/*
+ * SMCR_ELX_RAZ_LEN is defined to find the architecturally permitted SVL. This
+ * is a combination of RAZ and LEN bit fields.
+ */
+#define SMCR_ELX_RAZ_LEN_SHIFT UL(0)
+#define SMCR_ELX_RAZ_LEN_WIDTH UL(9)
#define SMCR_ELX_EZT0_BIT (U(1) << 30)
#define SMCR_ELX_FA64_BIT (U(1) << 31)
#define SMCR_EL2_RESET_VAL (SMCR_ELX_EZT0_BIT | SMCR_ELX_FA64_BIT)
diff --git a/include/lib/extensions/sme.h b/include/lib/extensions/sme.h
index 99372e4..4a7e9b7 100644
--- a/include/lib/extensions/sme.h
+++ b/include/lib/extensions/sme.h
@@ -7,9 +7,14 @@
#ifndef SME_H
#define SME_H
+#include <stdlib.h> /* for rand() */
+
#define MAX_VL (512)
#define MAX_VL_B (MAX_VL / 8)
-#define SME_SMCR_LEN_MAX U(0x1FF)
+#define SME_SVQ_ARCH_MAX (MASK(SMCR_ELX_LEN) >> SMCR_ELX_LEN_SHIFT)
+
+/* get a random Streaming SVE VQ b/w 0 to SME_SVQ_ARCH_MAX */
+#define SME_GET_RANDOM_SVQ (rand() % (SME_SVQ_ARCH_MAX + 1))
typedef enum {
SMSTART, /* enters streaming sve mode and enables SME ZA array */
@@ -34,5 +39,10 @@
void sme_ZA_to_vector(const uint64_t *output_vector);
void sme2_load_zt0_instruction(const uint64_t *inputbuf);
void sme2_store_zt0_instruction(const uint64_t *outputbuf);
+void sme_config_svq(uint32_t svq);
+void sme_enable_fa64(void);
+void sme_disable_fa64(void);
+bool sme_smstat_sm(void);
+bool sme_feat_fa64_enabled(void);
#endif /* SME_H */
diff --git a/include/lib/extensions/sve.h b/include/lib/extensions/sve.h
index 4458001..5670afc 100644
--- a/include/lib/extensions/sve.h
+++ b/include/lib/extensions/sve.h
@@ -9,6 +9,7 @@
#include <arch.h>
#include <stdlib.h> /* for rand() */
+#include <lib/extensions/sme.h>
#define fill_sve_helper(num) "ldr z"#num", [%0, #"#num", MUL VL];"
#define read_sve_helper(num) "str z"#num", [%0, #"#num", MUL VL];"