johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 1 | /* |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021-2023, ARM Limited and Contributors. All rights reserved. |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdbool.h> |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include <arch.h> |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 11 | #include <arch_features.h> |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 12 | #include <arch_helpers.h> |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 13 | #include <debug.h> |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 14 | #include <lib/extensions/sme.h> |
| 15 | |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 16 | /* |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 17 | * Function: sme_smstart |
| 18 | * This function enables streaming mode and ZA array storage access |
| 19 | * independently or together based on the type of instruction variant. |
| 20 | * |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 21 | * Parameters |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 22 | * smstart_type: If SMSTART, streaming mode and ZA access is enabled. |
| 23 | * If SMSTART_SM, streaming mode enabled. |
| 24 | * If SMSTART_ZA enables SME ZA storage and, ZT0 storage access. |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 25 | */ |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 26 | void sme_smstart(smestart_instruction_type_t smstart_type) |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 27 | { |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 28 | u_register_t svcr = 0ULL; |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 29 | |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 30 | switch (smstart_type) { |
| 31 | case SMSTART: |
| 32 | svcr = (SVCR_SM_BIT | SVCR_ZA_BIT); |
| 33 | break; |
| 34 | |
| 35 | case SMSTART_SM: |
| 36 | svcr = SVCR_SM_BIT; |
| 37 | break; |
| 38 | |
| 39 | case SMSTART_ZA: |
| 40 | svcr = SVCR_ZA_BIT; |
| 41 | break; |
| 42 | |
| 43 | default: |
| 44 | ERROR("Illegal SMSTART Instruction Variant\n"); |
| 45 | break; |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 46 | } |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 47 | write_svcr(read_svcr() | svcr); |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 48 | |
| 49 | isb(); |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* |
| 53 | * sme_smstop |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 54 | * This function exits streaming mode and disables ZA array storage access |
| 55 | * independently or together based on the type of instruction variant. |
| 56 | * |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 57 | * Parameters |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 58 | * smstop_type: If SMSTOP, exits streaming mode and ZA access is disabled |
| 59 | * If SMSTOP_SM, exits streaming mode. |
| 60 | * If SMSTOP_ZA disables SME ZA storage and, ZT0 storage access. |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 61 | */ |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 62 | void sme_smstop(smestop_instruction_type_t smstop_type) |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 63 | { |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 64 | u_register_t svcr = 0ULL; |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 65 | |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 66 | switch (smstop_type) { |
| 67 | case SMSTOP: |
| 68 | svcr = (~SVCR_SM_BIT) & (~SVCR_ZA_BIT); |
| 69 | break; |
| 70 | |
| 71 | case SMSTOP_SM: |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 72 | svcr = ~SVCR_SM_BIT; |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 73 | break; |
| 74 | |
| 75 | case SMSTOP_ZA: |
| 76 | svcr = ~SVCR_ZA_BIT; |
| 77 | break; |
| 78 | |
| 79 | default: |
| 80 | ERROR("Illegal SMSTOP Instruction Variant\n"); |
| 81 | break; |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 82 | } |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 83 | write_svcr(read_svcr() & svcr); |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 84 | |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 85 | isb(); |
| 86 | } |