Skip to main content

islet_rmm/rsi/
constraint.rs

1use crate::config::SMCCC_1_3_SVE_HINT;
2use crate::event::{Command, Context};
3use crate::rmi::constraint::Constraint; // TODO: we might need rsi's own constraint struct in the future
4use crate::rsi;
5
6fn pick(cmd: Command) -> Option<Constraint> {
7    let constraint = match cmd {
8        // XXX: Constraints for RSI and PSCI are not correctly enforced now.
9        //      Note that arg and ret values in Context are not used in RSI where
10        //      set_reg and get_reg are instead used.
11        rsi::ABI_VERSION => Constraint::new(rsi::ABI_VERSION, 2, 3),
12        rsi::FEATURES => Constraint::new(rsi::FEATURES, 2, 2),
13        rsi::MEASUREMENT_READ => Constraint::new(rsi::MEASUREMENT_READ, 2, 9),
14        rsi::MEASUREMENT_EXTEND => Constraint::new(rsi::MEASUREMENT_EXTEND, 11, 1),
15        rsi::ATTEST_TOKEN_INIT => Constraint::new(rsi::ATTEST_TOKEN_INIT, 9, 2),
16        rsi::ATTEST_TOKEN_CONTINUE => Constraint::new(rsi::ATTEST_TOKEN_CONTINUE, 4, 2),
17        rsi::REALM_CONFIG => Constraint::new(rsi::REALM_CONFIG, 2, 1),
18        rsi::IPA_STATE_SET => Constraint::new(rsi::IPA_STATE_SET, 5, 3),
19        rsi::IPA_STATE_GET => Constraint::new(rsi::IPA_STATE_GET, 3, 3),
20        rsi::HOST_CALL => Constraint::new(rsi::HOST_CALL, 2, 1),
21        // PSCI
22        // XXX: Setting 0 in ret_num currently causes a problem, while PSCI_CPU_SUSPEND,
23        //      PSCI_CPU_OFF, PSCI_SYSTEM_OFF, and PSCI_SYSTEM_RESET have no output values.
24        rsi::PSCI_VERSION => Constraint::new(rsi::PSCI_VERSION, 1, 1),
25        rsi::PSCI_CPU_SUSPEND => Constraint::new(rsi::PSCI_CPU_SUSPEND, 4, 1),
26        rsi::PSCI_CPU_OFF => Constraint::new(rsi::PSCI_CPU_OFF, 1, 1),
27        rsi::PSCI_CPU_ON => Constraint::new(rsi::PSCI_CPU_ON, 4, 1),
28        rsi::PSCI_AFFINITY_INFO => Constraint::new(rsi::PSCI_AFFINITY_INFO, 3, 1),
29        rsi::PSCI_SYSTEM_OFF => Constraint::new(rsi::PSCI_SYSTEM_OFF, 1, 1),
30        rsi::PSCI_SYSTEM_RESET => Constraint::new(rsi::PSCI_SYSTEM_RESET, 1, 1),
31
32        rsi::PSCI_FEATURES => Constraint::new(rsi::PSCI_FEATURES, 2, 1),
33        // XXX: SMCCC_VERSION is not defined in the spec, so remove it if it is not used now
34        rsi::SMCCC_VERSION => Constraint::new(rsi::SMCCC_VERSION, 2, 1),
35        // XXX: REALM_SEALING_KEY do not exist in the spec
36        rsi::ISLET_REALM_SEALING_KEY => Constraint::new(rsi::ISLET_REALM_SEALING_KEY, 2, 5),
37        _ => return None,
38    };
39    Some(constraint)
40}
41
42pub fn validate(cmd: Command) -> Context {
43    let fid = cmd & !SMCCC_1_3_SVE_HINT;
44    let mut ctx = Context::new(fid);
45    if cmd & SMCCC_1_3_SVE_HINT != 0 {
46        ctx.sve_hint = true;
47    }
48    if let Some(c) = pick(fid) {
49        ctx.resize_ret(c.ret_num);
50    } else {
51        // rmm.handle_rsi takes care of unregistered command.
52        // Just limit the array size here.
53        ctx.resize_ret(1);
54    }
55    ctx
56}