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