fix(sme): enable SME/SME2 during arch init

This change enables SME/SME2 for nonsecure use at EL2 for TFTF cases
during arch_setup. This removes dependency on testcases to explicitly
call sme_enable or sme2_enable to access SME or SME2 functionality.

This change also adds CPTR_EL2 register in suspend context. CPTR_EL2
register is saved/restored in CPU suspend entry/exit path.

Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Change-Id: I2c99fd49c48c1a9ff2110747714db858a78d3a32
diff --git a/tftf/tests/extensions/sme/test_sme.c b/tftf/tests/extensions/sme/test_sme.c
index 64391ab..6d85183 100644
--- a/tftf/tests/extensions/sme/test_sme.c
+++ b/tftf/tests/extensions/sme/test_sme.c
@@ -71,13 +71,11 @@
 	unsigned int requested_vector_len;
 	unsigned int len_max;
 	unsigned int __unused svl_max = 0U;
+	u_register_t saved_smcr;
 
 	/* Skip the test if SME is not supported. */
 	SKIP_TEST_IF_SME_NOT_SUPPORTED();
 
-	/* Enable SME for use at NS EL2. */
-	sme_enable();
-
 	/* Make sure TPIDR2_EL0 is accessible. */
 	write_tpidr2_el0(0);
 	if (read_tpidr2_el0() != 0) {
@@ -97,8 +95,12 @@
 	/* Entering Streaming SVE mode */
 	sme_smstart(SMSTART_SM);
 
+	saved_smcr = read_smcr_el2();
+
 	/* Write SMCR_EL2 with the LEN max to find implemented width. */
 	write_smcr_el2(SME_SMCR_LEN_MAX);
+	isb();
+
 	len_max = (unsigned int)read_smcr_el2();
 	VERBOSE("Maximum SMCR_EL2.LEN value: 0x%x\n", len_max);
 	VERBOSE("Enumerating supported vector lengths...\n");
@@ -108,6 +110,7 @@
 		reg &= ~(SMCR_ELX_LEN_MASK << SMCR_ELX_LEN_SHIFT);
 		reg |= (i << SMCR_ELX_LEN_SHIFT);
 		write_smcr_el2(reg);
+		isb();
 
 		/* Compute current and requested vector lengths in bits. */
 		current_vector_len = ((unsigned int)sme_rdvl_1() * 8U);
@@ -164,6 +167,9 @@
 		sme_try_illegal_instruction();
 	}
 
+	write_smcr_el2(saved_smcr);
+	isb();
+
 	return TEST_RESULT_SUCCESS;
 #endif /* __aarch64__ */
 }