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> |
Arunachalam Ganapathy | c1136a8 | 2023-04-12 15:24:44 +0100 | [diff] [blame] | 11 | #include <stdlib.h> /* for rand() */ |
Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame] | 12 | |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 13 | #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 Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 16 | /* |
| 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 Ganapathy | 5270d01 | 2023-04-19 14:53:42 +0100 | [diff] [blame] | 23 | #define SVE_VQ_ARCH_MIN (0U) |
Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame] | 24 | #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 Ganapathy | 5270d01 | 2023-04-19 14:53:42 +0100 | [diff] [blame] | 32 | /* convert SVE VQ to bytes */ |
| 33 | #define SVE_VQ_TO_BYTES(vq) (SVE_VQ_TO_BITS(vq) / 8) |
| 34 | |
Arunachalam Ganapathy | c1136a8 | 2023-04-12 15:24:44 +0100 | [diff] [blame] | 35 | /* 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 Capella | c59184c | 2022-08-23 19:09:41 -0400 | [diff] [blame] | 38 | #ifndef __ASSEMBLY__ |
| 39 | |
Arunachalam Ganapathy | 0358997 | 2023-08-30 11:04:51 +0100 | [diff] [blame^] | 40 | typedef uint8_t sve_z_regs_t[SVE_NUM_VECTORS * SVE_VECTOR_LEN_BYTES] |
| 41 | __aligned(16); |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 42 | |
Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame] | 43 | void sve_config_vq(uint8_t sve_vq); |
| 44 | uint32_t sve_probe_vl(uint8_t sve_max_vq); |
Arunachalam Ganapathy | 0358997 | 2023-08-30 11:04:51 +0100 | [diff] [blame^] | 45 | |
| 46 | void sve_z_regs_write(const sve_z_regs_t *z_regs); |
| 47 | void sve_z_regs_read(sve_z_regs_t *z_regs); |
Arunachalam Ganapathy | d179ddc | 2023-04-12 10:41:42 +0100 | [diff] [blame] | 48 | |
| 49 | /* Assembly routines */ |
| 50 | bool sve_subtract_arrays_interleaved(int *dst_array, int *src_array1, |
| 51 | int *src_array2, int array_size, |
| 52 | bool (*world_switch_cb)(void)); |
| 53 | |
| 54 | void sve_subtract_arrays(int *dst_array, int *src_array1, int *src_array2, |
| 55 | int array_size); |
Arunachalam Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame] | 56 | |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 57 | #ifdef __aarch64__ |
| 58 | |
| 59 | /* Returns the SVE implemented VL in bytes (constrained by ZCR_EL3.LEN) */ |
Arunachalam Ganapathy | 0358997 | 2023-08-30 11:04:51 +0100 | [diff] [blame^] | 60 | static inline uint64_t sve_rdvl_1(void) |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 61 | { |
| 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 Capella | c59184c | 2022-08-23 19:09:41 -0400 | [diff] [blame] | 75 | #endif /* __ASSEMBLY__ */ |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame] | 76 | #endif /* SVE_H */ |