blob: ed5678ebb7c0673973dd5d1b6e440a3b33c05dc5 [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
Arunachalam Ganapathy03589972023-08-30 11:04:51 +010040typedef uint8_t sve_z_regs_t[SVE_NUM_VECTORS * SVE_VECTOR_LEN_BYTES]
41 __aligned(16);
Olivier Deprez569be402022-07-08 10:24:39 +020042
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010043void sve_config_vq(uint8_t sve_vq);
44uint32_t sve_probe_vl(uint8_t sve_max_vq);
Arunachalam Ganapathy03589972023-08-30 11:04:51 +010045
46void sve_z_regs_write(const sve_z_regs_t *z_regs);
47void sve_z_regs_read(sve_z_regs_t *z_regs);
Arunachalam Ganapathyd179ddc2023-04-12 10:41:42 +010048
49/* Assembly routines */
50bool sve_subtract_arrays_interleaved(int *dst_array, int *src_array1,
51 int *src_array2, int array_size,
52 bool (*world_switch_cb)(void));
53
54void sve_subtract_arrays(int *dst_array, int *src_array1, int *src_array2,
55 int array_size);
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010056
Olivier Deprez569be402022-07-08 10:24:39 +020057#ifdef __aarch64__
58
59/* Returns the SVE implemented VL in bytes (constrained by ZCR_EL3.LEN) */
Arunachalam Ganapathy03589972023-08-30 11:04:51 +010060static inline uint64_t sve_rdvl_1(void)
Olivier Deprez569be402022-07-08 10:24:39 +020061{
62 uint64_t vl;
63
64 __asm__ volatile(
65 ".arch_extension sve\n"
66 "rdvl %0, #1;"
67 ".arch_extension nosve\n"
68 : "=r" (vl)
69 );
70
71 return vl;
72}
73
74#endif /* __aarch64__ */
Kathleen Capellac59184c2022-08-23 19:09:41 -040075#endif /* __ASSEMBLY__ */
Olivier Deprez569be402022-07-08 10:24:39 +020076#endif /* SVE_H */