blob: 5907ef9e521dda358f16ffd5b73f14ca85eecde0 [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 Ganapathy0bbdc2d2023-04-05 15:30:18 +010023#define SVE_VQ_ARCH_MAX ((1 << ZCR_EL2_SVE_VL_WIDTH) - 1)
24
25/* convert SVE VL in bytes to VQ */
26#define SVE_VL_TO_VQ(vl_bytes) (((vl_bytes) >> 4U) - 1)
27
28/* convert SVE VQ to bits */
29#define SVE_VQ_TO_BITS(vq) (((vq) + 1U) << 7U)
30
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010031/* get a random SVE VQ b/w 0 to SVE_VQ_ARCH_MAX */
32#define SVE_GET_RANDOM_VQ (rand() % (SVE_VQ_ARCH_MAX + 1))
33
Kathleen Capellac59184c2022-08-23 19:09:41 -040034#ifndef __ASSEMBLY__
35
Olivier Deprez569be402022-07-08 10:24:39 +020036typedef uint8_t sve_vector_t[SVE_VECTOR_LEN_BYTES];
37
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010038void sve_config_vq(uint8_t sve_vq);
39uint32_t sve_probe_vl(uint8_t sve_max_vq);
Arunachalam Ganapathyd179ddc2023-04-12 10:41:42 +010040void sve_fill_vector_regs(const sve_vector_t v[SVE_NUM_VECTORS]);
41void sve_read_vector_regs(sve_vector_t v[SVE_NUM_VECTORS]);
42
43/* Assembly routines */
44bool sve_subtract_arrays_interleaved(int *dst_array, int *src_array1,
45 int *src_array2, int array_size,
46 bool (*world_switch_cb)(void));
47
48void sve_subtract_arrays(int *dst_array, int *src_array1, int *src_array2,
49 int array_size);
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010050
Olivier Deprez569be402022-07-08 10:24:39 +020051#ifdef __aarch64__
52
53/* Returns the SVE implemented VL in bytes (constrained by ZCR_EL3.LEN) */
54static inline uint64_t sve_vector_length_get(void)
55{
56 uint64_t vl;
57
58 __asm__ volatile(
59 ".arch_extension sve\n"
60 "rdvl %0, #1;"
61 ".arch_extension nosve\n"
62 : "=r" (vl)
63 );
64
65 return vl;
66}
67
68#endif /* __aarch64__ */
Kathleen Capellac59184c2022-08-23 19:09:41 -040069#endif /* __ASSEMBLY__ */
Olivier Deprez569be402022-07-08 10:24:39 +020070#endif /* SVE_H */