blob: b4eaa2fb04cebf00b93b3415051fc431a155faa0 [file] [log] [blame]
johpow0150ccb552020-11-10 19:22:13 -06001/*
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +00002 * Copyright (c) 2021-2023, ARM Limited and Contributors. All rights reserved.
johpow0150ccb552020-11-10 19:22:13 -06003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdbool.h>
8#include <stdio.h>
9
10#include <arch.h>
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000011#include <arch_features.h>
johpow0150ccb552020-11-10 19:22:13 -060012#include <arch_helpers.h>
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000013#include <debug.h>
johpow0150ccb552020-11-10 19:22:13 -060014#include <lib/extensions/sme.h>
15
johpow0150ccb552020-11-10 19:22:13 -060016/*
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000017 * 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 *
johpow0150ccb552020-11-10 19:22:13 -060021 * Parameters
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000022 * 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.
johpow0150ccb552020-11-10 19:22:13 -060025 */
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000026void sme_smstart(smestart_instruction_type_t smstart_type)
johpow0150ccb552020-11-10 19:22:13 -060027{
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000028 u_register_t svcr = 0ULL;
johpow0150ccb552020-11-10 19:22:13 -060029
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000030 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;
johpow0150ccb552020-11-10 19:22:13 -060046 }
johpow0150ccb552020-11-10 19:22:13 -060047 write_svcr(read_svcr() | svcr);
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000048
49 isb();
johpow0150ccb552020-11-10 19:22:13 -060050}
51
52/*
53 * sme_smstop
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000054 * This function exits streaming mode and disables ZA array storage access
55 * independently or together based on the type of instruction variant.
56 *
johpow0150ccb552020-11-10 19:22:13 -060057 * Parameters
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000058 * 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.
johpow0150ccb552020-11-10 19:22:13 -060061 */
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000062void sme_smstop(smestop_instruction_type_t smstop_type)
johpow0150ccb552020-11-10 19:22:13 -060063{
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000064 u_register_t svcr = 0ULL;
johpow0150ccb552020-11-10 19:22:13 -060065
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000066 switch (smstop_type) {
67 case SMSTOP:
68 svcr = (~SVCR_SM_BIT) & (~SVCR_ZA_BIT);
69 break;
70
71 case SMSTOP_SM:
johpow0150ccb552020-11-10 19:22:13 -060072 svcr = ~SVCR_SM_BIT;
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000073 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;
johpow0150ccb552020-11-10 19:22:13 -060082 }
johpow0150ccb552020-11-10 19:22:13 -060083 write_svcr(read_svcr() & svcr);
johpow0150ccb552020-11-10 19:22:13 -060084
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000085 isb();
86}