Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | */ |
| 5 | |
| 6 | #include <arch.h> |
| 7 | #include <arch_helpers.h> |
| 8 | #include <assert.h> |
| 9 | #include <buffer.h> |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 10 | #include <cpuid.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 11 | #include <debug.h> |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 12 | #include <run.h> |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 13 | #include <simd.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 14 | #include <smc-handler.h> |
| 15 | #include <smc-rmi.h> |
| 16 | #include <smc.h> |
| 17 | #include <status.h> |
| 18 | #include <utils_def.h> |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 19 | #include <xlat_high_va.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 20 | |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 21 | /* Maximum number of supported arguments */ |
AlexeiFedorov | 93f5ec5 | 2023-08-31 14:26:53 +0100 | [diff] [blame] | 22 | #define MAX_NUM_ARGS 5U |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 23 | |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 24 | /* Maximum number of output values */ |
AlexeiFedorov | 93f5ec5 | 2023-08-31 14:26:53 +0100 | [diff] [blame] | 25 | #define MAX_NUM_OUTPUT_VALS 4U |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 26 | |
| 27 | #define RMI_STATUS_STRING(_id)[RMI_##_id] = #_id |
| 28 | |
AlexeiFedorov | 04418f4 | 2023-09-13 10:50:33 +0100 | [diff] [blame] | 29 | static const char * const rmi_status_string[] = { |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 30 | RMI_STATUS_STRING(SUCCESS), |
| 31 | RMI_STATUS_STRING(ERROR_INPUT), |
| 32 | RMI_STATUS_STRING(ERROR_REALM), |
| 33 | RMI_STATUS_STRING(ERROR_REC), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 34 | RMI_STATUS_STRING(ERROR_RTT), |
| 35 | RMI_STATUS_STRING(ERROR_DEVICE), |
| 36 | RMI_STATUS_STRING(ERROR_NOT_SUPPORTED), |
| 37 | RMI_STATUS_STRING(ERROR_RTT_AUX) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 38 | }; |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 39 | |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 40 | COMPILER_ASSERT(ARRAY_SIZE(rmi_status_string) == RMI_ERROR_COUNT_MAX); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * At this level (in handle_ns_smc) we distinguish the RMI calls only on: |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 44 | * - The number of input arguments [0..5], and whether |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 45 | * - The function returns up to three output values in addition |
| 46 | * to the return status code. |
| 47 | * Hence, the naming syntax is: |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 48 | * - `*_[0..5]` when no output values are returned, and |
| 49 | * - `*_[0..3]_o` when the function returns some output values. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 50 | */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 51 | typedef unsigned long (*handler_0)(void); |
| 52 | typedef unsigned long (*handler_1)(unsigned long arg0); |
| 53 | typedef unsigned long (*handler_2)(unsigned long arg0, unsigned long arg1); |
| 54 | typedef unsigned long (*handler_3)(unsigned long arg0, unsigned long arg1, |
| 55 | unsigned long arg2); |
| 56 | typedef unsigned long (*handler_4)(unsigned long arg0, unsigned long arg1, |
| 57 | unsigned long arg2, unsigned long arg3); |
| 58 | typedef unsigned long (*handler_5)(unsigned long arg0, unsigned long arg1, |
| 59 | unsigned long arg2, unsigned long arg3, |
| 60 | unsigned long arg4); |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 61 | typedef void (*handler_1_o)(unsigned long arg0, struct smc_result *res); |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 62 | typedef void (*handler_2_o)(unsigned long arg0, unsigned long arg1, |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 63 | struct smc_result *res); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 64 | typedef void (*handler_3_o)(unsigned long arg0, unsigned long arg1, |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 65 | unsigned long arg2, struct smc_result *res); |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 66 | typedef void (*handler_4_o)(unsigned long arg0, unsigned long arg1, |
| 67 | unsigned long arg2, unsigned long arg3, |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 68 | struct smc_result *res); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 69 | |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 70 | /* |
| 71 | * SMC RMI handler type encoding: |
| 72 | * [0:7] - number of arguments |
| 73 | * [8:15] - number of output values |
| 74 | */ |
Shruti Gupta | 9e966b8 | 2024-03-21 13:45:24 +0000 | [diff] [blame] | 75 | #define RMI_TYPE(_in, _out) (U(_in) | (U(_out) << 8U)) |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 76 | #define set_rmi_type(_in, _out) rmi_type_##_in##_out = RMI_TYPE(_in, _out) |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 77 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 78 | enum rmi_type { |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 79 | set_rmi_type(0, 0), /* 0 arguments, 0 output values */ |
| 80 | set_rmi_type(1, 0), /* 1 argument, 0 output values */ |
| 81 | set_rmi_type(2, 0), /* 2 arguments, 0 output values */ |
| 82 | set_rmi_type(3, 0), /* 3 arguments, 0 output values */ |
| 83 | set_rmi_type(4, 0), /* 4 arguments, 0 output values */ |
| 84 | set_rmi_type(5, 0), /* 5 arguments, 0 output values */ |
| 85 | set_rmi_type(1, 1), /* 1 argument, 1 output value */ |
AlexeiFedorov | 2cc6cee | 2023-10-09 16:19:05 +0100 | [diff] [blame] | 86 | set_rmi_type(1, 2), /* 1 argument, 2 output values */ |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 87 | set_rmi_type(2, 2), /* 2 arguments, 2 output values */ |
| 88 | set_rmi_type(3, 1), /* 3 arguments, 1 output value */ |
| 89 | set_rmi_type(3, 2), /* 3 arguments, 2 output values */ |
| 90 | set_rmi_type(3, 4), /* 3 arguments, 4 output values */ |
| 91 | set_rmi_type(4, 1) /* 4 arguments, 1 output value */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct smc_handler { |
| 95 | const char *fn_name; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 96 | union { |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 97 | handler_0 f_00; |
| 98 | handler_1 f_10; |
| 99 | handler_2 f_20; |
| 100 | handler_3 f_30; |
| 101 | handler_4 f_40; |
| 102 | handler_5 f_50; |
| 103 | handler_1_o f_11; |
AlexeiFedorov | 2cc6cee | 2023-10-09 16:19:05 +0100 | [diff] [blame] | 104 | handler_1_o f_12; |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 105 | handler_2_o f_22; |
| 106 | handler_3_o f_31; |
| 107 | handler_3_o f_32; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 108 | handler_3_o f_34; |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 109 | handler_4_o f_41; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 110 | void *fn_dummy; |
| 111 | }; |
Chuyue Luo | 819aa31 | 2023-11-03 10:41:27 +0000 | [diff] [blame] | 112 | enum rmi_type type; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 113 | bool log_exec; /* print handler execution */ |
| 114 | bool log_error; /* print in case of error status */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /* |
| 118 | * Get handler ID from FID |
| 119 | * Precondition: FID is an RMI call |
| 120 | */ |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 121 | #define RMI_HANDLER_ID(_id) SMC64_FID_OFFSET_FROM_RANGE_MIN(RMI, _id) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 122 | |
Arunachalam Ganapathy | 807dda8 | 2024-05-03 14:22:43 +0100 | [diff] [blame] | 123 | #define HANDLER(_id, _in, _out, _fn, _exec, _error)[RMI_HANDLER_ID(SMC_RMI_##_id)] = { \ |
AlexeiFedorov | 6a4314e | 2023-10-20 15:40:14 +0100 | [diff] [blame] | 124 | .fn_name = (#_id), \ |
| 125 | .type = (enum rmi_type)RMI_TYPE(_in, _out), \ |
| 126 | .f_##_in##_out = (_fn), \ |
| 127 | .log_exec = (_exec), \ |
| 128 | .log_error = (_error) \ |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 129 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * The 3rd value enables the execution log. |
| 133 | * The 4th value enables the error log. |
| 134 | */ |
| 135 | static const struct smc_handler smc_handlers[] = { |
AlexeiFedorov | 2cc6cee | 2023-10-09 16:19:05 +0100 | [diff] [blame] | 136 | HANDLER(VERSION, 1, 2, smc_version, true, true), |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 137 | HANDLER(GRANULE_DELEGATE, 1, 0, smc_granule_delegate, false, true), |
| 138 | HANDLER(GRANULE_UNDELEGATE, 1, 0, smc_granule_undelegate, false, true), |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 139 | HANDLER(DATA_CREATE, 5, 0, smc_data_create, false, false), |
| 140 | HANDLER(DATA_CREATE_UNKNOWN, 3, 0, smc_data_create_unknown, false, false), |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 141 | HANDLER(DATA_DESTROY, 2, 2, smc_data_destroy, false, true), |
Arunachalam Ganapathy | 8f6f626 | 2024-10-10 11:42:00 +0100 | [diff] [blame] | 142 | HANDLER(PDEV_AUX_COUNT, 1, 1, smc_pdev_aux_count, true, true), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 143 | HANDLER(REALM_ACTIVATE, 1, 0, smc_realm_activate, true, true), |
| 144 | HANDLER(REALM_CREATE, 2, 0, smc_realm_create, true, true), |
| 145 | HANDLER(REALM_DESTROY, 1, 0, smc_realm_destroy, true, true), |
| 146 | HANDLER(REC_CREATE, 3, 0, smc_rec_create, true, true), |
| 147 | HANDLER(REC_DESTROY, 1, 0, smc_rec_destroy, true, true), |
| 148 | HANDLER(REC_ENTER, 2, 0, smc_rec_enter, false, true), |
AlexeiFedorov | 5db2aaa | 2024-08-07 11:16:15 +0100 | [diff] [blame] | 149 | HANDLER(RTT_CREATE, 4, 0, smc_rtt_create, false, true), |
| 150 | HANDLER(RTT_DESTROY, 3, 2, smc_rtt_destroy, false, true), |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 151 | HANDLER(RTT_MAP_UNPROTECTED, 4, 0, smc_rtt_map_unprotected, false, false), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 152 | HANDLER(VDEV_AUX_COUNT, 0, 0, NULL, true, true), |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 153 | HANDLER(RTT_READ_ENTRY, 3, 4, smc_rtt_read_entry, false, true), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 154 | HANDLER(RTT_UNMAP_UNPROTECTED, 3, 1, smc_rtt_unmap_unprotected, false, false), |
Arunachalam Ganapathy | cf718fb | 2024-11-28 16:03:11 +0000 | [diff] [blame] | 155 | HANDLER(RTT_DEV_MEM_VALIDATE, 4, 1, NULL, false, true), |
AlexeiFedorov | 120d7d0 | 2023-08-02 16:51:48 +0100 | [diff] [blame] | 156 | HANDLER(PSCI_COMPLETE, 3, 0, smc_psci_complete, true, true), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 157 | HANDLER(FEATURES, 1, 1, smc_read_feature_register, true, true), |
| 158 | HANDLER(RTT_FOLD, 3, 1, smc_rtt_fold, false, false), |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 159 | HANDLER(REC_AUX_COUNT, 1, 1, smc_rec_aux_count, true, true), |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 160 | HANDLER(RTT_INIT_RIPAS, 3, 1, smc_rtt_init_ripas, false, true), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 161 | HANDLER(RTT_SET_RIPAS, 4, 1, smc_rtt_set_ripas, false, true), |
AlexeiFedorov | d2e9393 | 2025-01-13 17:24:37 +0000 | [diff] [blame] | 162 | HANDLER(DEV_MEM_MAP, 4, 0, smc_dev_mem_map, false, true), |
| 163 | HANDLER(DEV_MEM_UNMAP, 3, 2, smc_dev_mem_unmap, false, true), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 164 | HANDLER(PDEV_ABORT, 0, 0, NULL, true, true), |
| 165 | HANDLER(PDEV_COMMUNICATE, 2, 0, NULL, true, true), |
Soby Mathew | e7cf182 | 2025-04-24 07:51:33 +0100 | [diff] [blame] | 166 | HANDLER(PDEV_CREATE, 2, 0, smc_pdev_create, true, true), |
Arunachalam Ganapathy | db98da6 | 2024-10-09 12:06:57 +0100 | [diff] [blame] | 167 | HANDLER(PDEV_DESTROY, 1, 0, smc_pdev_destroy, true, true), |
Arunachalam Ganapathy | 294d102 | 2024-07-17 12:31:26 +0100 | [diff] [blame] | 168 | HANDLER(PDEV_GET_STATE, 1, 1, smc_pdev_get_state, true, true), |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 169 | HANDLER(PDEV_IDE_RESET, 0, 0, NULL, true, true), |
| 170 | HANDLER(PDEV_NOTIFY, 0, 0, NULL, true, true), |
| 171 | HANDLER(PDEV_SET_PUBKEY, 4, 0, NULL, true, true), |
| 172 | HANDLER(PDEV_STOP, 0, 0, NULL, true, true), |
| 173 | HANDLER(RTT_AUX_CREATE, 0, 0, NULL, true, true), |
| 174 | HANDLER(RTT_AUX_DESTROY, 0, 0, NULL, true, true), |
| 175 | HANDLER(RTT_AUX_FOLD, 0, 0, NULL, true, true), |
| 176 | HANDLER(RTT_AUX_MAP_PROTECTED, 0, 0, NULL, true, true), |
| 177 | HANDLER(RTT_AUX_MAP_UNPROTECTED, 0, 0, NULL, true, true), |
| 178 | HANDLER(RTT_AUX_UNMAP_PROTECTED, 0, 0, NULL, true, true), |
| 179 | HANDLER(RTT_AUX_UNMAP_UNPROTECTED, 0, 0, NULL, true, true), |
| 180 | HANDLER(VDEV_ABORT, 0, 0, NULL, true, true), |
| 181 | HANDLER(VDEV_COMMUNICATE, 0, 0, NULL, true, true), |
| 182 | HANDLER(VDEV_CREATE, 0, 0, NULL, true, true), |
| 183 | HANDLER(VDEV_DESTROY, 0, 0, NULL, true, true), |
| 184 | HANDLER(VDEV_GET_STATE, 0, 0, NULL, true, true), |
| 185 | HANDLER(VDEV_STOP, 0, 0, NULL, true, true), |
| 186 | HANDLER(RTT_SET_S2AP, 0, 0, NULL, true, true), |
| 187 | HANDLER(MEC_SET_SHARED, 0, 0, NULL, true, true), |
| 188 | HANDLER(MEC_SET_PRIVATE, 0, 0, NULL, true, true), |
| 189 | HANDLER(VDEV_COMPLETE, 0, 0, NULL, true, true) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
Soby Mathew | 1ceb008 | 2024-10-10 17:22:38 +0100 | [diff] [blame] | 192 | COMPILER_ASSERT(ARRAY_SIZE(smc_handlers) == SMC64_NUM_FIDS_IN_RANGE(RMI)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 193 | |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 194 | static inline bool rmi_handler_needs_fpu(unsigned int id) |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 195 | { |
| 196 | #ifdef RMM_FPU_USE_AT_REL2 |
Arunachalam Ganapathy | 807dda8 | 2024-05-03 14:22:43 +0100 | [diff] [blame] | 197 | if ((id == SMC_RMI_REALM_CREATE) || (id == SMC_RMI_DATA_CREATE) || |
| 198 | (id == SMC_RMI_REC_CREATE) || (id == SMC_RMI_RTT_INIT_RIPAS)) { |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 199 | return true; |
| 200 | } |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 201 | #else |
| 202 | (void)id; |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 203 | #endif |
| 204 | return false; |
| 205 | } |
| 206 | |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 207 | static void rmi_log_on_exit(unsigned int handler_id, |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 208 | unsigned long args[], |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 209 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 210 | { |
| 211 | const struct smc_handler *handler = &smc_handlers[handler_id]; |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 212 | unsigned int function_id = SMC64_RMI_FID(handler_id); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 213 | return_code_t rc; |
| 214 | |
| 215 | if (!handler->log_exec && !handler->log_error) { |
| 216 | return; |
| 217 | } |
| 218 | |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 219 | rc = unpack_return_code(res->x[0]); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 220 | |
| 221 | if ((handler->log_exec) || |
| 222 | (handler->log_error && (rc.status != RMI_SUCCESS))) { |
Shruti Gupta | 9e966b8 | 2024-03-21 13:45:24 +0000 | [diff] [blame] | 223 | unsigned int num; |
| 224 | |
AlexeiFedorov | d416f14 | 2025-05-15 13:53:30 +0100 | [diff] [blame] | 225 | /* |
| 226 | * Print function name. |
| 227 | * RSI handler function SMC_RSI_RDEV_GET_INTERFACE_REPORT has |
| 228 | * maximum name length of 33 chars excluding the null terminator. |
| 229 | */ |
| 230 | INFO("SMC_RMI_%-25s", handler->fn_name); |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 231 | |
| 232 | /* Print arguments */ |
AlexeiFedorov | 84cba4f | 2023-08-25 13:45:48 +0100 | [diff] [blame] | 233 | num = (unsigned int)handler->type & 0xFFU; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 234 | assert(num <= MAX_NUM_ARGS); |
| 235 | |
| 236 | for (unsigned int i = 0U; i < num; i++) { |
| 237 | INFO(" %lx", args[i]); |
| 238 | } |
| 239 | |
| 240 | /* Print status */ |
Arunachalam Ganapathy | f36187e | 2024-05-07 11:49:33 +0100 | [diff] [blame] | 241 | if (rc.status >= RMI_ERROR_COUNT_MAX) { |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 242 | INFO(" > %lx", res->x[0]); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 243 | } else { |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 244 | INFO(" > RMI_%s", rmi_status_string[rc.status]); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /* Check for index */ |
Arunachalam Ganapathy | 807dda8 | 2024-05-03 14:22:43 +0100 | [diff] [blame] | 248 | if (((function_id == SMC_RMI_REC_ENTER) && |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 249 | (rc.status == RMI_ERROR_REALM)) || |
| 250 | (rc.status == RMI_ERROR_RTT)) { |
| 251 | INFO(" %x", rc.index); |
AlexeiFedorov | 697445b | 2023-04-25 15:27:57 +0100 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | if ((rc.status == RMI_SUCCESS) || |
| 255 | ((rc.status == RMI_ERROR_RTT) && |
AlexeiFedorov | 33c1db7 | 2024-08-05 11:42:25 +0100 | [diff] [blame] | 256 | ((function_id == SMC_RMI_RTT_DESTROY) || |
| 257 | (function_id == SMC_RMI_DATA_DESTROY) || |
| 258 | (function_id == SMC_RMI_RTT_UNMAP_UNPROTECTED)))) { |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 259 | /* Print output values */ |
AlexeiFedorov | 84cba4f | 2023-08-25 13:45:48 +0100 | [diff] [blame] | 260 | num = ((unsigned int)handler->type >> 8) & 0xFFU; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 261 | assert(num <= MAX_NUM_OUTPUT_VALS); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 262 | |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 263 | for (unsigned int i = 1U; i <= num; i++) { |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 264 | INFO(" %lx", res->x[i]); |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 265 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 266 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 267 | INFO("\n"); |
| 268 | } |
| 269 | } |
| 270 | |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 271 | /* cppcheck-suppress misra-c2012-8.4 */ |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 272 | /* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */ |
AlexeiFedorov | b0de4d5 | 2023-10-10 11:46:16 +0100 | [diff] [blame] | 273 | /* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */ |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 274 | void handle_ns_smc(unsigned int function_id, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 275 | unsigned long arg0, |
| 276 | unsigned long arg1, |
| 277 | unsigned long arg2, |
| 278 | unsigned long arg3, |
| 279 | unsigned long arg4, |
| 280 | unsigned long arg5, |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 281 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 282 | { |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 283 | (void)arg5; |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 284 | unsigned int handler_id; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 285 | const struct smc_handler *handler = NULL; |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 286 | bool restore_ns_simd_state = false; |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 287 | struct simd_context *ns_simd_ctx; |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 288 | bool sve_hint = false; |
AlexeiFedorov | 7c38ef4 | 2023-11-28 11:39:19 +0000 | [diff] [blame] | 289 | unsigned long args[] __unused = {arg0, arg1, arg2, arg3, arg4}; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 290 | |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 291 | /* Save the SVE hint bit and clear it from the function ID */ |
| 292 | if ((function_id & SMC_SVE_HINT) != 0U) { |
| 293 | sve_hint = true; |
| 294 | function_id &= ~SMC_SVE_HINT; |
| 295 | } |
Arunachalam Ganapathy | 937b549 | 2023-02-28 11:17:52 +0000 | [diff] [blame] | 296 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 297 | if (IS_SMC64_RMI_FID(function_id)) { |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 298 | handler_id = RMI_HANDLER_ID(function_id); |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 299 | /* cppcheck-suppress misra-c2012-17.3 */ |
Soby Mathew | 1ceb008 | 2024-10-10 17:22:38 +0100 | [diff] [blame] | 300 | if (handler_id < ARRAY_SIZE(smc_handlers)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 301 | handler = &smc_handlers[handler_id]; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * Check if handler exists and 'fn_dummy' is not NULL |
| 307 | * for not implemented 'function_id' calls in SMC RMI range. |
| 308 | */ |
| 309 | if ((handler == NULL) || (handler->fn_dummy == NULL)) { |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 310 | VERBOSE("[%s] unknown function_id: %x\n", |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 311 | __func__, function_id); |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 312 | res->x[0] = SMC_UNKNOWN; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 313 | return; |
| 314 | } |
| 315 | |
AlexeiFedorov | 7c38ef4 | 2023-11-28 11:39:19 +0000 | [diff] [blame] | 316 | assert(check_cpu_slots_empty()); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 317 | |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 318 | /* Current CPU's SIMD state must not be saved when entering RMM */ |
| 319 | assert(simd_is_state_saved() == false); |
| 320 | |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 321 | /* Get current CPU's NS SIMD context */ |
| 322 | ns_simd_ctx = get_cpu_ns_simd_context(); |
| 323 | |
Arunachalam Ganapathy | ebfab6a | 2023-08-24 14:44:23 +0100 | [diff] [blame] | 324 | /* Set or clear SVE hint bit in the NS SIMD context */ |
| 325 | simd_update_smc_sve_hint(ns_simd_ctx, sve_hint); |
| 326 | |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 327 | /* If the handler needs FPU, actively save NS simd context. */ |
| 328 | if (rmi_handler_needs_fpu(function_id) == true) { |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 329 | simd_context_save(ns_simd_ctx); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 330 | restore_ns_simd_state = true; |
| 331 | } |
| 332 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 333 | switch (handler->type) { |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 334 | case rmi_type_00: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 335 | res->x[0] = handler->f_00(); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 336 | break; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 337 | case rmi_type_10: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 338 | res->x[0] = handler->f_10(arg0); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 339 | break; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 340 | case rmi_type_20: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 341 | res->x[0] = handler->f_20(arg0, arg1); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 342 | break; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 343 | case rmi_type_30: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 344 | res->x[0] = handler->f_30(arg0, arg1, arg2); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 345 | break; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 346 | case rmi_type_40: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 347 | res->x[0] = handler->f_40(arg0, arg1, arg2, arg3); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 348 | break; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 349 | case rmi_type_50: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 350 | res->x[0] = handler->f_50(arg0, arg1, arg2, arg3, arg4); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 351 | break; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 352 | case rmi_type_11: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 353 | handler->f_11(arg0, res); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 354 | break; |
AlexeiFedorov | 2cc6cee | 2023-10-09 16:19:05 +0100 | [diff] [blame] | 355 | case rmi_type_12: |
| 356 | handler->f_12(arg0, res); |
| 357 | break; |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 358 | case rmi_type_22: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 359 | handler->f_22(arg0, arg1, res); |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 360 | break; |
| 361 | case rmi_type_31: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 362 | handler->f_31(arg0, arg1, arg2, res); |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 363 | break; |
| 364 | case rmi_type_32: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 365 | handler->f_32(arg0, arg1, arg2, res); |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 366 | break; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 367 | case rmi_type_34: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 368 | handler->f_34(arg0, arg1, arg2, res); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 369 | break; |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 370 | case rmi_type_41: |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame] | 371 | handler->f_41(arg0, arg1, arg2, arg3, res); |
AlexeiFedorov | 892abce | 2023-04-06 16:32:12 +0100 | [diff] [blame] | 372 | break; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 373 | default: |
| 374 | assert(false); |
| 375 | } |
| 376 | |
AlexeiFedorov | 7c38ef4 | 2023-11-28 11:39:19 +0000 | [diff] [blame] | 377 | rmi_log_on_exit(handler_id, args, res); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 378 | |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 379 | /* If the handler uses FPU, restore the saved NS simd context. */ |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 380 | if (restore_ns_simd_state) { |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 381 | simd_context_restore(ns_simd_ctx); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /* Current CPU's SIMD state must not be saved when exiting RMM */ |
| 385 | assert(simd_is_state_saved() == false); |
AlexeiFedorov | 7c38ef4 | 2023-11-28 11:39:19 +0000 | [diff] [blame] | 386 | assert(check_cpu_slots_empty()); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 389 | /* |
| 390 | * Identifies an abort that the RMM may recover from. |
| 391 | */ |
| 392 | struct rmm_trap_element { |
| 393 | /* |
| 394 | * The PC at the time of abort. |
| 395 | */ |
| 396 | unsigned long aborted_pc; |
| 397 | /* |
| 398 | * New value of the PC. |
| 399 | */ |
| 400 | unsigned long new_pc; |
| 401 | }; |
| 402 | |
| 403 | #define RMM_TRAP_HANDLER(_aborted_pc, _new_pc) \ |
Chuyue Luo | d738668 | 2023-09-22 11:55:47 +0100 | [diff] [blame] | 404 | { .aborted_pc = (unsigned long)(&(_aborted_pc)), \ |
| 405 | .new_pc = (unsigned long)(&(_new_pc)) } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 406 | |
| 407 | /* |
| 408 | * The registered locations of load/store instructions that access NS memory. |
| 409 | */ |
| 410 | extern void *ns_read; |
| 411 | extern void *ns_write; |
| 412 | |
| 413 | /* |
| 414 | * The new value of the PC when the GPF occurs on a registered location. |
| 415 | */ |
| 416 | extern void *ns_access_ret_0; |
| 417 | |
AlexeiFedorov | 53518ba | 2023-08-22 14:46:26 +0100 | [diff] [blame] | 418 | static struct rmm_trap_element rmm_trap_list[] = { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 419 | RMM_TRAP_HANDLER(ns_read, ns_access_ret_0), |
| 420 | RMM_TRAP_HANDLER(ns_write, ns_access_ret_0), |
| 421 | }; |
| 422 | #define RMM_TRAP_LIST_SIZE (sizeof(rmm_trap_list)/sizeof(struct rmm_trap_element)) |
| 423 | |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 424 | /* Crash dump registers X0 - X29 */ |
| 425 | #define DUMP_REGS 30U |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 426 | |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 427 | typedef struct { |
| 428 | uint64_t x[DUMP_REGS]; |
| 429 | uint64_t lr; |
| 430 | } dump_regs_t; |
| 431 | |
| 432 | __dead2 static void fatal_abort(dump_regs_t *regs) |
| 433 | { |
| 434 | __unused uint64_t sp_el2; |
| 435 | __unused uint64_t sp_el0 = (uint64_t)regs + sizeof(dump_regs_t); |
| 436 | __unused uint64_t lr = regs->lr; |
| 437 | |
| 438 | ERROR("Unexpected exception on CPU #%u:\n", my_cpuid()); |
| 439 | |
| 440 | for (unsigned int i = 0U; i < DUMP_REGS; i += 2U) { |
| 441 | INFO("X%u:\t\t0x%016lx X%u:\t\t0x%016lx\n", |
| 442 | i, regs->x[i], i + 1U, regs->x[i + 1U]); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 443 | } |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 444 | |
| 445 | /* Demangle return address */ |
| 446 | xpaci(lr); |
| 447 | |
| 448 | /* Switch SPSEL to read SP_EL2 register */ |
| 449 | write_spsel(MODE_SP_ELX); |
| 450 | read_sp(sp_el2); |
| 451 | write_spsel(MODE_SP_EL0); |
| 452 | |
| 453 | INFO("LR:\t\t0x%016lx\n", lr); |
| 454 | INFO("SP_EL0:\t\t0x%016lx\n", sp_el0); |
| 455 | INFO("SP_EL2:\t\t0x%016lx%c (0x%016lx-0x%016lx)\n", sp_el2, |
| 456 | ((sp_el2 < CPU_STACK_VIRT) || |
| 457 | (sp_el2 >= RMM_CPU_STACK_END_VA)) ? '*' : ' ', |
| 458 | CPU_STACK_VIRT, (RMM_CPU_STACK_END_VA - 1UL)); |
| 459 | INFO("ESR_EL2:\t0x%016lx\n", read_esr_el2()); |
| 460 | INFO("ELR_EL2:\t0x%016lx\n", read_elr_el2()); |
| 461 | INFO("FAR_EL2:\t0x%016lx\n", read_far_el2()); |
| 462 | INFO("SPSR_EL2:\t0x%016lx\n", read_spsr_el2()); |
| 463 | INFO("HCR_EL2:\t0x%016lx E2H = %c\n", read_hcr_el2(), |
| 464 | ((read_hcr_el2() & HCR_E2H) == 0UL) ? '0' : '1'); |
| 465 | INFO("CPTR_EL2:\t0x%016lx\n", read_cptr_el2()); |
| 466 | INFO("MDCR_EL2:\t0x%016lx\n", read_mdcr_el2()); |
| 467 | INFO("SCTLR_EL2:\t0x%016lx\n", read_sctlr_el2()); |
| 468 | |
AlexeiFedorov | be9209c | 2024-02-27 15:16:00 +0000 | [diff] [blame] | 469 | /* The AArch64 AAPCS mandates the usage of x29 as Frame Pointer */ |
| 470 | backtrace((uintptr_t)regs->x[29]); |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 471 | panic(); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static bool is_el2_data_abort_gpf(unsigned long esr) |
| 475 | { |
AlexeiFedorov | 537bee0 | 2023-02-02 13:38:23 +0000 | [diff] [blame] | 476 | if (((esr & MASK(ESR_EL2_EC)) == ESR_EL2_EC_DATA_ABORT_SEL) && |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 477 | ((esr & MASK(ESR_EL2_ABORT_FSC)) == ESR_EL2_ABORT_FSC_GPF)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 478 | return true; |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 479 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 480 | return false; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * Handles the RMM's aborts. |
| 485 | * It compares the PC at the time of the abort with the registered addresses. |
| 486 | * If it finds a match, it returns the new value of the PC that the RMM should |
| 487 | * continue from. Other register values are preserved. |
| 488 | * If no match is found, it aborts the RMM. |
| 489 | */ |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 490 | /* cppcheck-suppress misra-c2012-8.4 */ |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 491 | /* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */ |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 492 | /* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */ |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 493 | unsigned long handle_rmm_trap(dump_regs_t *regs) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 494 | { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 495 | unsigned long esr = read_esr_el2(); |
| 496 | unsigned long elr = read_elr_el2(); |
| 497 | |
| 498 | /* |
| 499 | * Only the GPF data aborts are recoverable. |
| 500 | */ |
| 501 | if (!is_el2_data_abort_gpf(esr)) { |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 502 | fatal_abort(regs); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 503 | } |
| 504 | |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 505 | for (unsigned int i = 0U; i < RMM_TRAP_LIST_SIZE; i++) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 506 | if (rmm_trap_list[i].aborted_pc == elr) { |
| 507 | return rmm_trap_list[i].new_pc; |
| 508 | } |
| 509 | } |
| 510 | |
AlexeiFedorov | 4c7d485 | 2024-01-25 14:37:34 +0000 | [diff] [blame] | 511 | fatal_abort(regs); |
AlexeiFedorov | 6c11969 | 2023-04-21 12:31:15 +0100 | [diff] [blame] | 512 | return 0UL; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 513 | } |