blob: 994fbfe163e371c8e8783832188b3a77faf841ce [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>
11
Max Shvetsov959be332021-03-16 14:18:13 +000012#define fill_sve_helper(num) "ldr z"#num", [%0, #"#num", MUL VL];"
13#define read_sve_helper(num) "str z"#num", [%0, #"#num", MUL VL];"
14
Olivier Deprez569be402022-07-08 10:24:39 +020015/*
16 * Max. vector length permitted by the architecture:
17 * SVE: 2048 bits = 256 bytes
18 */
19#define SVE_VECTOR_LEN_BYTES 256
20#define SVE_NUM_VECTORS 32
21
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010022#define SVE_VQ_ARCH_MAX ((1 << ZCR_EL2_SVE_VL_WIDTH) - 1)
23
24/* convert SVE VL in bytes to VQ */
25#define SVE_VL_TO_VQ(vl_bytes) (((vl_bytes) >> 4U) - 1)
26
27/* convert SVE VQ to bits */
28#define SVE_VQ_TO_BITS(vq) (((vq) + 1U) << 7U)
29
Kathleen Capellac59184c2022-08-23 19:09:41 -040030#ifndef __ASSEMBLY__
31
Olivier Deprez569be402022-07-08 10:24:39 +020032typedef uint8_t sve_vector_t[SVE_VECTOR_LEN_BYTES];
33
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010034void sve_config_vq(uint8_t sve_vq);
35uint32_t sve_probe_vl(uint8_t sve_max_vq);
36
Olivier Deprez569be402022-07-08 10:24:39 +020037#ifdef __aarch64__
38
39/* Returns the SVE implemented VL in bytes (constrained by ZCR_EL3.LEN) */
40static inline uint64_t sve_vector_length_get(void)
41{
42 uint64_t vl;
43
44 __asm__ volatile(
45 ".arch_extension sve\n"
46 "rdvl %0, #1;"
47 ".arch_extension nosve\n"
48 : "=r" (vl)
49 );
50
51 return vl;
52}
53
54#endif /* __aarch64__ */
Kathleen Capellac59184c2022-08-23 19:09:41 -040055#endif /* __ASSEMBLY__ */
Olivier Deprez569be402022-07-08 10:24:39 +020056#endif /* SVE_H */