Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 1 | /* |
Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2021-2023, Arm Limited. All rights reserved. |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SVE_H |
| 8 | #define SVE_H |
| 9 | |
Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame^] | 10 | #include <arch.h> |
| 11 | |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 12 | #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 Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 15 | /* |
| 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 Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame^] | 22 | #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 Capella | c59184c | 2022-08-23 19:09:41 -0400 | [diff] [blame] | 30 | #ifndef __ASSEMBLY__ |
| 31 | |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 32 | typedef uint8_t sve_vector_t[SVE_VECTOR_LEN_BYTES]; |
| 33 | |
Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame^] | 34 | void sve_config_vq(uint8_t sve_vq); |
| 35 | uint32_t sve_probe_vl(uint8_t sve_max_vq); |
| 36 | |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 37 | #ifdef __aarch64__ |
| 38 | |
| 39 | /* Returns the SVE implemented VL in bytes (constrained by ZCR_EL3.LEN) */ |
| 40 | static 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 Capella | c59184c | 2022-08-23 19:09:41 -0400 | [diff] [blame] | 55 | #endif /* __ASSEMBLY__ */ |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 56 | #endif /* SVE_H */ |