blob: c59272b955e74a4409b77ff22c7ce326cc98e373 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
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>
9#include <rsi-memory.h>
10#include <smc-rsi.h>
11#include <status.h>
12
13bool 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;
18 enum ripas ripas = (enum ripas)rec->regs[3];
19
20 if (ripas > RMI_RAM) {
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
41 rec->set_ripas.start = start;
42 rec->set_ripas.end = end;
43 rec->set_ripas.addr = start;
44 rec->set_ripas.ripas = ripas;
45
46 rec_exit->exit_reason = RMI_EXIT_RIPAS_CHANGE;
47 rec_exit->ripas_base = start;
48 rec_exit->ripas_size = size;
49 rec_exit->ripas_value = (unsigned int)ripas;
50
51 return false;
52}
53
54rsi_status_t handle_rsi_ipa_state_get(struct rec *rec, unsigned long ipa,
55 enum ripas *ripas_ptr)
56{
57 bool s2tte_destroyed;
58
59 if (!GRANULE_ALIGNED(ipa)) {
60 return RSI_ERROR_INPUT;
61 }
62
63 if (!addr_in_rec_par(rec, ipa)) {
64 return RSI_ERROR_INPUT;
65 }
66
67 realm_ipa_get_ripas(rec, ipa, ripas_ptr, &s2tte_destroyed);
68 if (s2tte_destroyed == true) {
69 /* TODO: handle destroyed state appropriately */
70 return RSI_ERROR_INPUT;
71 }
72
73 return RSI_SUCCESS;
74}