blob: e82da08eeb10ab1fb034a93d850b5474214e7241 [file] [log] [blame]
Jayanth Dodderi Chidanand95d5d272023-01-16 17:58:47 +00001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdio.h>
8#include <stdlib.h>
9
10#include <arch_features.h>
11#include <arch_helpers.h>
12#include <lib/extensions/sme.h>
13#include <test_helpers.h>
14#include <tftf_lib.h>
15
16#ifdef __aarch64__
17
18#define SME2_ARRAYSIZE (512/64)
19#define SME2_INPUT_DATA (0x1fffffffffffffff)
20
21/* Global buffers */
Olivier Depreza61927e2023-06-01 17:16:00 +020022static __aligned(16) uint64_t sme2_input_buffer[SME2_ARRAYSIZE] = {0};
23static __aligned(16) uint64_t sme2_output_buffer[SME2_ARRAYSIZE] = {0};
Jayanth Dodderi Chidanand95d5d272023-01-16 17:58:47 +000024
25/*
26 * clear_ZT0: ZERO all bytes of the ZT0 register.
27 *
28 */
29static void clear_ZT0(void)
30{
31 /**
32 * Due to the lack of support from the toolchain, instruction
33 * opcodes are used here.
34 * TODO: Further, once the toolchain adds support for SME features
35 * this could be replaced with the instruction ZERO {ZT0}.
36 */
37 asm volatile(".inst 0xc0480001" : : : );
38}
39
40#endif /* __aarch64__ */
41
42/*
43 * test_sme2_support: Test SME2 support when the extension is enabled.
44 *
45 * Execute some SME2 instructions. These should not be trapped to EL3,
46 * as TF-A is responsible for enabling SME2 for Non-secure world.
47 *
48 */
49test_result_t test_sme2_support(void)
50{
51 /* SME2 is an AArch64-only feature.*/
52 SKIP_TEST_IF_AARCH32();
53
54#ifdef __aarch64__
55 /* Skip the test if SME2 is not supported. */
56 SKIP_TEST_IF_SME2_NOT_SUPPORTED();
57
Jayanth Dodderi Chidanand95d5d272023-01-16 17:58:47 +000058 /*
59 * FEAT_SME2 adds a 512 BIT architectural register ZT0 to support
60 * the lookup-table feature.
61 * System register SMCR_ELx defines a bit SMCR_ELx.EZT0 bit [30] to
Arunachalam Ganapathy92f18682023-09-02 01:41:28 +010062 * enable/disable access to this register. SMCR_EL2_RESET_VAL enables
63 * this bit by default.
Jayanth Dodderi Chidanand95d5d272023-01-16 17:58:47 +000064 *
65 * Instructions to access ZT0 register are being tested to ensure
Arunachalam Ganapathy92f18682023-09-02 01:41:28 +010066 * SMCR_EL3.EZT0 bit is set by EL3 firmware so that EL2 access are not
67 * trapped.
Jayanth Dodderi Chidanand95d5d272023-01-16 17:58:47 +000068 */
69
70 /* Make sure we can acesss SME2 ZT0 storage, PSTATE.ZA = 1*/
71 VERBOSE("Enabling SME ZA storage and ZT0 storage.\n");
72
73 sme_smstart(SMSTART_ZA);
74
75 /*
76 * LDR (ZT0) : Load ZT0 register.
77 * Load the 64-byte ZT0 register from the memory address
78 * provided in the 64-bit scalar base register.
79 */
80 for (int i = 0; i < SME2_ARRAYSIZE; i++) {
81 sme2_input_buffer[i] = SME2_INPUT_DATA;
82 }
83 sme2_load_zt0_instruction(sme2_input_buffer);
84
85 /*
86 * STR (ZT0) : Store ZT0 register.
87 * Store the 64-byte ZT0 register to the memory address
88 * provided in the 64-bit scalar base register
89 */
90
91 sme2_store_zt0_instruction(sme2_output_buffer);
92
93 /**
94 * compare the input and output buffer to verify the operations of
95 * LDR and STR instructions with ZT0 register.
96 */
97 for (int i = 0; i < SME2_ARRAYSIZE; i++) {
98 if (sme2_input_buffer[i] != sme2_output_buffer[i]) {
99 return TEST_RESULT_FAIL;
100 }
101 }
102
103 /* ZER0 (ZT0) */
104 clear_ZT0();
105
106 /* Finally disable the acesss to SME2 ZT0 storage, PSTATE.ZA = 0*/
107 VERBOSE("Disabling SME ZA storage and ZT0 storage.\n");
108
109 sme_smstop(SMSTOP_ZA);
110
111 return TEST_RESULT_SUCCESS;
112#endif /* __aarch64__ */
113}