blob: 4458001d27b6fb37f8210956a4c2ae5748c75e49 [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
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010016#define fill_sve_p_helper(num) "ldr p"#num", [%0, #"#num", MUL VL];"
17#define read_sve_p_helper(num) "str p"#num", [%0, #"#num", MUL VL];"
18
Olivier Deprez569be402022-07-08 10:24:39 +020019/*
20 * Max. vector length permitted by the architecture:
21 * SVE: 2048 bits = 256 bytes
22 */
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010023#define SVE_VECTOR_LEN_BYTES (256U)
24#define SVE_NUM_VECTORS (32U)
25
26/* Max size of one predicate register is 1/8 of Z register */
27#define SVE_P_REG_LEN_BYTES (SVE_VECTOR_LEN_BYTES / 8U)
28#define SVE_NUM_P_REGS (16U)
29
30/* Max size of one FFR register is 1/8 of Z register */
31#define SVE_FFR_REG_LEN_BYTES (SVE_VECTOR_LEN_BYTES / 8U)
32#define SVE_NUM_FFR_REGS (1U)
Olivier Deprez569be402022-07-08 10:24:39 +020033
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +010034#define SVE_VQ_ARCH_MIN (0U)
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010035#define SVE_VQ_ARCH_MAX ((1U << ZCR_EL2_SVE_VL_WIDTH) - 1U)
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010036
37/* convert SVE VL in bytes to VQ */
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010038#define SVE_VL_TO_VQ(vl_bytes) (((vl_bytes) >> 4U) - 1U)
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010039
40/* convert SVE VQ to bits */
41#define SVE_VQ_TO_BITS(vq) (((vq) + 1U) << 7U)
42
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +010043/* convert SVE VQ to bytes */
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010044#define SVE_VQ_TO_BYTES(vq) (SVE_VQ_TO_BITS(vq) / 8U)
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +010045
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010046/* get a random SVE VQ b/w 0 to SVE_VQ_ARCH_MAX */
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010047#define SVE_GET_RANDOM_VQ (rand() % (SVE_VQ_ARCH_MAX + 1U))
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010048
Kathleen Capellac59184c2022-08-23 19:09:41 -040049#ifndef __ASSEMBLY__
50
Arunachalam Ganapathy03589972023-08-30 11:04:51 +010051typedef uint8_t sve_z_regs_t[SVE_NUM_VECTORS * SVE_VECTOR_LEN_BYTES]
52 __aligned(16);
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010053typedef uint8_t sve_p_regs_t[SVE_NUM_P_REGS * SVE_P_REG_LEN_BYTES]
54 __aligned(16);
55typedef uint8_t sve_ffr_regs_t[SVE_NUM_FFR_REGS * SVE_FFR_REG_LEN_BYTES]
56 __aligned(16);
Olivier Deprez569be402022-07-08 10:24:39 +020057
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010058void sve_config_vq(uint8_t sve_vq);
59uint32_t sve_probe_vl(uint8_t sve_max_vq);
Arunachalam Ganapathy03589972023-08-30 11:04:51 +010060
61void sve_z_regs_write(const sve_z_regs_t *z_regs);
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010062void sve_z_regs_write_rand(sve_z_regs_t *z_regs);
Arunachalam Ganapathy03589972023-08-30 11:04:51 +010063void sve_z_regs_read(sve_z_regs_t *z_regs);
Arunachalam Ganapathyfa05bd92023-08-30 14:36:53 +010064uint64_t sve_z_regs_compare(const sve_z_regs_t *s1, const sve_z_regs_t *s2);
65
66void sve_p_regs_write(const sve_p_regs_t *p_regs);
67void sve_p_regs_write_rand(sve_p_regs_t *p_regs);
68void sve_p_regs_read(sve_p_regs_t *p_regs);
69uint64_t sve_p_regs_compare(const sve_p_regs_t *s1, const sve_p_regs_t *s2);
70
71void sve_ffr_regs_write(const sve_ffr_regs_t *ffr_regs);
72void sve_ffr_regs_write_rand(sve_ffr_regs_t *ffr_regs);
73void sve_ffr_regs_read(sve_ffr_regs_t *ffr_regs);
74uint64_t sve_ffr_regs_compare(const sve_ffr_regs_t *s1,
75 const sve_ffr_regs_t *s2);
Arunachalam Ganapathyd179ddc2023-04-12 10:41:42 +010076
77/* Assembly routines */
78bool sve_subtract_arrays_interleaved(int *dst_array, int *src_array1,
79 int *src_array2, int array_size,
80 bool (*world_switch_cb)(void));
81
82void sve_subtract_arrays(int *dst_array, int *src_array1, int *src_array2,
83 int array_size);
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010084
Olivier Deprez569be402022-07-08 10:24:39 +020085#ifdef __aarch64__
86
87/* Returns the SVE implemented VL in bytes (constrained by ZCR_EL3.LEN) */
Arunachalam Ganapathy03589972023-08-30 11:04:51 +010088static inline uint64_t sve_rdvl_1(void)
Olivier Deprez569be402022-07-08 10:24:39 +020089{
90 uint64_t vl;
91
92 __asm__ volatile(
93 ".arch_extension sve\n"
94 "rdvl %0, #1;"
95 ".arch_extension nosve\n"
96 : "=r" (vl)
97 );
98
99 return vl;
100}
101
102#endif /* __aarch64__ */
Kathleen Capellac59184c2022-08-23 19:09:41 -0400103#endif /* __ASSEMBLY__ */
Olivier Deprez569be402022-07-08 10:24:39 +0200104#endif /* SVE_H */