blob: ed6c7c75b04f5b5f821058c6c867371bf320162d [file] [log] [blame]
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +01001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <arch.h>
7#include <arch_features.h>
8#include <arch_helpers.h>
9#include <assert.h>
10#include <debug.h>
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010011#include <stdlib.h>
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010012#include <lib/extensions/sve.h>
13
14#include <host_realm_sve.h>
15#include <host_shared_data.h>
16
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010017#define RL_SVE_OP_ARRAYSIZE 512U
18#define SVE_TEST_ITERATIONS 4U
19
20static int rl_sve_op_1[RL_SVE_OP_ARRAYSIZE];
21static int rl_sve_op_2[RL_SVE_OP_ARRAYSIZE];
22
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010023/* Returns the maximum supported VL. This test is called only by sve Realm */
24bool test_realm_sve_rdvl(void)
25{
26 host_shared_data_t *sd = realm_get_shared_structure();
27 struct sve_cmd_rdvl *output;
28
29 assert(is_armv8_2_sve_present());
30
31 output = (struct sve_cmd_rdvl *)sd->realm_cmd_output_buffer;
32 memset((void *)output, 0, sizeof(struct sve_cmd_rdvl));
33
34 sve_config_vq(SVE_VQ_ARCH_MAX);
35 output->rdvl = sve_vector_length_get();
36
37 return true;
38}
39
40/*
41 * Reads and returns the ID_AA64PFR0_EL1 and ID_AA64ZFR0_EL1 registers
42 * This test could be called from sve or non-sve Realm
43 */
44bool test_realm_sve_read_id_registers(void)
45{
46 host_shared_data_t *sd = realm_get_shared_structure();
47 struct sve_cmd_id_regs *output;
48
49 output = (struct sve_cmd_id_regs *)sd->realm_cmd_output_buffer;
50 memset((void *)output, 0, sizeof(struct sve_cmd_id_regs));
51
52 realm_printf("Realm: reading ID registers: ID_AA64PFR0_EL1, "
53 " ID_AA64ZFR0_EL1\n");
54 output->id_aa64pfr0_el1 = read_id_aa64pfr0_el1();
55 output->id_aa64zfr0_el1 = read_id_aa64zfr0_el1();
56
57 return true;
58}
59
60/*
61 * Probes all VLs and return the bitmap with the bit set for each corresponding
62 * valid VQ. This test is called only by sve Realm
63 */
64bool test_realm_sve_probe_vl(void)
65{
66 host_shared_data_t *sd = realm_get_shared_structure();
67 struct sve_cmd_probe_vl *output;
68
69 assert(is_armv8_2_sve_present());
70
71 output = (struct sve_cmd_probe_vl *)&sd->realm_cmd_output_buffer;
72 memset((void *)output, 0, sizeof(struct sve_cmd_probe_vl));
73
74 /* Probe all VLs */
75 output->vl_bitmap = sve_probe_vl(SVE_VQ_ARCH_MAX);
76
77 return true;
78}
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010079
80bool test_realm_sve_ops(void)
81{
82 int val, i;
83
84 assert(is_armv8_2_sve_present());
85
86 /* get at random value to do sve_subtract */
87 val = rand();
88 for (i = 0; i < RL_SVE_OP_ARRAYSIZE; i++) {
89 rl_sve_op_1[i] = val - i;
90 rl_sve_op_2[i] = 1;
91 }
92
93 for (i = 0; i < SVE_TEST_ITERATIONS; i++) {
94 /* Config Realm with random SVE length */
95 sve_config_vq(SVE_GET_RANDOM_VQ);
96
97 /* Perform SVE operations, without world switch */
98 sve_subtract_arrays(rl_sve_op_1, rl_sve_op_1, rl_sve_op_2,
99 RL_SVE_OP_ARRAYSIZE);
100 }
101
102 /* Check result of SVE operations. */
103 for (i = 0; i < RL_SVE_OP_ARRAYSIZE; i++) {
104 if (rl_sve_op_1[i] != (val - i - SVE_TEST_ITERATIONS)) {
105 realm_printf("Realm: SVE ops failed\n");
106 return false;
107 }
108 }
109
110 return true;
111}