blob: 60432a57504f757e308150729712588b49343267 [file] [log] [blame]
Max Shvetsov959be332021-03-16 14:18:13 +00001/*
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +01002 * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
Max Shvetsov959be332021-03-16 14:18:13 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef SVE_H
8#define SVE_H
9
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010010#include <arch.h>
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010011#include <stdlib.h> /* for rand() */
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010012
Max Shvetsov959be332021-03-16 14:18:13 +000013#define fill_sve_helper(num) "ldr z"#num", [%0, #"#num", MUL VL];"
14#define read_sve_helper(num) "str z"#num", [%0, #"#num", MUL VL];"
15
Olivier Deprez569be402022-07-08 10:24:39 +020016/*
17 * Max. vector length permitted by the architecture:
18 * SVE: 2048 bits = 256 bytes
19 */
20#define SVE_VECTOR_LEN_BYTES 256
21#define SVE_NUM_VECTORS 32
22
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +010023#define SVE_VQ_ARCH_MIN (0U)
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010024#define SVE_VQ_ARCH_MAX ((1 << ZCR_EL2_SVE_VL_WIDTH) - 1)
25
26/* convert SVE VL in bytes to VQ */
27#define SVE_VL_TO_VQ(vl_bytes) (((vl_bytes) >> 4U) - 1)
28
29/* convert SVE VQ to bits */
30#define SVE_VQ_TO_BITS(vq) (((vq) + 1U) << 7U)
31
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +010032/* convert SVE VQ to bytes */
33#define SVE_VQ_TO_BYTES(vq) (SVE_VQ_TO_BITS(vq) / 8)
34
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010035/* get a random SVE VQ b/w 0 to SVE_VQ_ARCH_MAX */
36#define SVE_GET_RANDOM_VQ (rand() % (SVE_VQ_ARCH_MAX + 1))
37
Kathleen Capellac59184c2022-08-23 19:09:41 -040038#ifndef __ASSEMBLY__
39
Olivier Deprez569be402022-07-08 10:24:39 +020040typedef uint8_t sve_vector_t[SVE_VECTOR_LEN_BYTES];
41
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010042void sve_config_vq(uint8_t sve_vq);
43uint32_t sve_probe_vl(uint8_t sve_max_vq);
Arunachalam Ganapathyd179ddc2023-04-12 10:41:42 +010044void sve_fill_vector_regs(const sve_vector_t v[SVE_NUM_VECTORS]);
45void sve_read_vector_regs(sve_vector_t v[SVE_NUM_VECTORS]);
46
47/* Assembly routines */
48bool sve_subtract_arrays_interleaved(int *dst_array, int *src_array1,
49 int *src_array2, int array_size,
50 bool (*world_switch_cb)(void));
51
52void sve_subtract_arrays(int *dst_array, int *src_array1, int *src_array2,
53 int array_size);
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010054
Olivier Deprez569be402022-07-08 10:24:39 +020055#ifdef __aarch64__
56
57/* Returns the SVE implemented VL in bytes (constrained by ZCR_EL3.LEN) */
58static inline uint64_t sve_vector_length_get(void)
59{
60 uint64_t vl;
61
62 __asm__ volatile(
63 ".arch_extension sve\n"
64 "rdvl %0, #1;"
65 ".arch_extension nosve\n"
66 : "=r" (vl)
67 );
68
69 return vl;
70}
71
72#endif /* __aarch64__ */
Kathleen Capellac59184c2022-08-23 19:09:41 -040073#endif /* __ASSEMBLY__ */
Olivier Deprez569be402022-07-08 10:24:39 +020074#endif /* SVE_H */