David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 1 | /* |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved. |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <stdbool.h> |
| 8 | |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 9 | #include <arch.h> |
| 10 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <lib/el3_runtime/pubsub.h> |
| 12 | #include <lib/extensions/sve.h> |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 13 | |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 14 | /* |
| 15 | * Converts SVE vector size restriction in bytes to LEN according to ZCR_EL3 documentation. |
| 16 | * VECTOR_SIZE = (LEN+1) * 128 |
| 17 | */ |
| 18 | #define CONVERT_SVE_LENGTH(x) (((x / 128) - 1)) |
| 19 | |
| 20 | static bool sve_supported(void) |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 21 | { |
| 22 | uint64_t features; |
| 23 | |
| 24 | features = read_id_aa64pfr0_el1() >> ID_AA64PFR0_SVE_SHIFT; |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 25 | return (features & ID_AA64PFR0_SVE_MASK) == 1U; |
Dimitris Papastamos | 5e8cd79 | 2018-02-19 14:52:19 +0000 | [diff] [blame] | 26 | } |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 27 | |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 28 | void sve_enable(cpu_context_t *context) |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 29 | { |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 30 | if (!sve_supported()) { |
Dimitris Papastamos | 5e8cd79 | 2018-02-19 14:52:19 +0000 | [diff] [blame] | 31 | return; |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 32 | } |
Dimitris Papastamos | 5e8cd79 | 2018-02-19 14:52:19 +0000 | [diff] [blame] | 33 | |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 34 | u_register_t cptr_el3 = read_cptr_el3(); |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 35 | |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 36 | /* Enable access to SVE functionality for all ELs. */ |
| 37 | cptr_el3 = (cptr_el3 | CPTR_EZ_BIT) & ~(TFP_BIT); |
| 38 | write_ctx_reg(get_el3state_ctx(context), CTX_CPTR_EL3, cptr_el3); |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 39 | |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 40 | /* Restrict maximum SVE vector length (SVE_VECTOR_LENGTH+1) * 128. */ |
| 41 | write_ctx_reg(get_el3state_ctx(context), CTX_ZCR_EL3, |
| 42 | (ZCR_EL3_LEN_MASK & CONVERT_SVE_LENGTH(512))); |
David Cunado | ce88eee | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 43 | } |