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 | { |
| 17 | unsigned long start = rec->regs[1]; |
| 18 | unsigned long size = rec->regs[2]; |
| 19 | unsigned long end = start + size; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 20 | enum ripas ripas_val = (enum ripas)rec->regs[3]; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 21 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 22 | if ((ripas_val > RIPAS_RAM) || |
| 23 | !GRANULE_ALIGNED(start) || !GRANULE_ALIGNED(size) || |
| 24 | (end <= start) || /* Size is zero, or range overflows */ |
| 25 | !region_in_rec_par(rec, start, end)) { |
| 26 | res->action = UPDATE_REC_RETURN_TO_REALM; |
| 27 | res->smc_res.x[0] = RSI_ERROR_INPUT; |
| 28 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 29 | } |
| 30 | |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 31 | rec->set_ripas.base = start; |
| 32 | rec->set_ripas.top = end; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 33 | rec->set_ripas.addr = start; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 34 | rec->set_ripas.ripas_val = ripas_val; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 35 | |
| 36 | rec_exit->exit_reason = RMI_EXIT_RIPAS_CHANGE; |
| 37 | rec_exit->ripas_base = start; |
| 38 | rec_exit->ripas_size = size; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 39 | rec_exit->ripas_value = (unsigned int)ripas_val; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 40 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 41 | res->action = UPDATE_REC_EXIT_TO_HOST; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 42 | } |
| 43 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 44 | void handle_rsi_ipa_state_get(struct rec *rec, |
| 45 | struct rsi_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 46 | { |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 47 | unsigned long ipa = rec->regs[1]; |
| 48 | unsigned long rtt_level; |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 49 | enum s2_walk_status ws; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 50 | enum ripas ripas_val; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 51 | |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 52 | res->action = UPDATE_REC_RETURN_TO_REALM; |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 53 | |
| 54 | if (!GRANULE_ALIGNED(ipa) || !addr_in_rec_par(rec, ipa)) { |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 55 | res->smc_res.x[0] = RSI_ERROR_INPUT; |
| 56 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 57 | } |
| 58 | |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 59 | ws = realm_ipa_get_ripas(rec, ipa, &ripas_val, &rtt_level); |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 60 | if (ws == WALK_SUCCESS) { |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 61 | res->smc_res.x[0] = RSI_SUCCESS; |
| 62 | res->smc_res.x[1] = ripas_val; |
Arunachalam Ganapathy | dbaa886 | 2022-11-03 13:56:18 +0000 | [diff] [blame] | 63 | } else { |
| 64 | /* Exit to Host */ |
AlexeiFedorov | 9784420 | 2023-04-27 15:17:35 +0100 | [diff] [blame] | 65 | res->action = STAGE_2_TRANSLATION_FAULT; |
| 66 | res->rtt_level = rtt_level; |
| 67 | res->smc_res.x[0] = RSI_ERROR_INPUT; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 68 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 69 | } |