Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * |
| 4 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 5 | */ |
| 6 | |
| 7 | #include <realm.h> |
| 8 | #include <ripas.h> |
AlexeiFedorov | 5b186ad | 2023-04-26 14:43:18 +0100 | [diff] [blame] | 9 | #include <rsi-handler.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 10 | #include <smc-rsi.h> |
| 11 | #include <status.h> |
| 12 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 13 | void handle_rsi_ipa_state_set(struct rec *rec, |
| 14 | struct rmi_rec_exit *rec_exit, |
| 15 | struct rsi_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 16 | { |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame^] | 17 | unsigned long base = rec->regs[1]; |
| 18 | unsigned long top = base + rec->regs[2]; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 19 | enum ripas ripas_val = (enum ripas)rec->regs[3]; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 20 | |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame^] | 21 | if ((ripas_val > RIPAS_RAM) || |
| 22 | !GRANULE_ALIGNED(base) || !GRANULE_ALIGNED(top) || |
| 23 | (top <= base) || /* Size is zero, or range overflows */ |
| 24 | !region_in_rec_par(rec, base, top)) { |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 25 | res->action = UPDATE_REC_RETURN_TO_REALM; |
| 26 | res->smc_res.x[0] = RSI_ERROR_INPUT; |
| 27 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 28 | } |
| 29 | |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame^] | 30 | rec->set_ripas.base = base; |
| 31 | rec->set_ripas.top = top; |
| 32 | rec->set_ripas.addr = base; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 33 | rec->set_ripas.ripas_val = ripas_val; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 34 | |
| 35 | rec_exit->exit_reason = RMI_EXIT_RIPAS_CHANGE; |
AlexeiFedorov | ccce3ad | 2023-04-28 18:29:47 +0100 | [diff] [blame^] | 36 | rec_exit->ripas_base = base; |
| 37 | rec_exit->ripas_top = top; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 38 | rec_exit->ripas_value = (unsigned int)ripas_val; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 39 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 40 | res->action = UPDATE_REC_EXIT_TO_HOST; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 41 | } |
| 42 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 43 | void handle_rsi_ipa_state_get(struct rec *rec, |
| 44 | struct rsi_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 45 | { |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 46 | unsigned long ipa = rec->regs[1]; |
| 47 | unsigned long rtt_level; |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 48 | enum s2_walk_status ws; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 49 | enum ripas ripas_val; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 50 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 51 | res->action = UPDATE_REC_RETURN_TO_REALM; |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 52 | |
| 53 | if (!GRANULE_ALIGNED(ipa) || !addr_in_rec_par(rec, ipa)) { |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 54 | res->smc_res.x[0] = RSI_ERROR_INPUT; |
| 55 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 56 | } |
| 57 | |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 58 | ws = realm_ipa_get_ripas(rec, ipa, &ripas_val, &rtt_level); |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 59 | if (ws == WALK_SUCCESS) { |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 60 | res->smc_res.x[0] = RSI_SUCCESS; |
| 61 | res->smc_res.x[1] = ripas_val; |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 62 | } else { |
| 63 | /* Exit to Host */ |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 64 | res->action = STAGE_2_TRANSLATION_FAULT; |
| 65 | res->rtt_level = rtt_level; |
| 66 | res->smc_res.x[0] = RSI_ERROR_INPUT; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 67 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 68 | } |