Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 The Hafnium Authors. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
| 7 | */ |
| 8 | |
Karl Meakin | 902af08 | 2024-11-28 14:58:38 +0000 | [diff] [blame] | 9 | #include "hf/ffa/direct_messaging.h" |
Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 10 | |
| 11 | #include "hf/arch/other_world.h" |
| 12 | |
| 13 | #include "hf/vcpu.h" |
| 14 | #include "hf/vm.h" |
| 15 | |
| 16 | #include "hypervisor.h" |
| 17 | |
| 18 | /** |
| 19 | * Check validity of a FF-A direct message request. |
| 20 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame] | 21 | bool ffa_direct_msg_is_direct_request_valid(struct vcpu *current, |
| 22 | ffa_id_t sender_vm_id, |
| 23 | ffa_id_t receiver_vm_id) |
Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 24 | { |
| 25 | ffa_id_t current_vm_id = current->vm->id; |
| 26 | |
| 27 | /* |
| 28 | * The primary VM can send direct message request to |
| 29 | * any other VM (but itself) or SP, but can't spoof |
| 30 | * a different sender. |
| 31 | */ |
| 32 | return sender_vm_id != receiver_vm_id && |
| 33 | sender_vm_id == current_vm_id && vm_is_primary(current->vm); |
| 34 | } |
| 35 | |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame] | 36 | bool ffa_direct_msg_is_direct_request_supported(struct vm *sender_vm, |
| 37 | struct vm *receiver_vm, |
| 38 | uint32_t func) |
Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 39 | { |
| 40 | (void)sender_vm; |
| 41 | (void)receiver_vm; |
| 42 | (void)func; |
| 43 | |
| 44 | /* |
| 45 | * As Hypervisor is only meant to be used as a test artifact, allow |
| 46 | * direct messaging for all VMs. |
| 47 | */ |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Check validity of a FF-A direct message response. |
| 53 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame] | 54 | bool ffa_direct_msg_is_direct_response_valid(struct vcpu *current, |
| 55 | ffa_id_t sender_vm_id, |
| 56 | ffa_id_t receiver_vm_id) |
Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 57 | { |
| 58 | ffa_id_t current_vm_id = current->vm->id; |
| 59 | |
| 60 | /* |
| 61 | * Secondary VMs can send direct message responses to |
| 62 | * the PVM, but can't spoof a different sender. |
| 63 | */ |
| 64 | return sender_vm_id != receiver_vm_id && |
| 65 | sender_vm_id == current_vm_id && |
| 66 | receiver_vm_id == HF_PRIMARY_VM_ID; |
| 67 | } |
| 68 | |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame] | 69 | bool ffa_direct_msg_direct_request_forward(ffa_id_t receiver_vm_id, |
| 70 | struct ffa_value args, |
| 71 | struct ffa_value *ret) |
Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 72 | { |
| 73 | if (!plat_ffa_is_tee_enabled()) { |
| 74 | dlog_verbose("Not forwarding: ffa_tee_enabled is false\n"); |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * VM's requests should be forwarded to the SPMC, if receiver is an SP. |
| 80 | */ |
| 81 | if (vm_id_is_current_world(receiver_vm_id)) { |
| 82 | dlog_verbose( |
| 83 | "Not forwarding: receiver VM %#x is in the same " |
| 84 | "world\n", |
| 85 | receiver_vm_id); |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | switch (args.func) { |
| 90 | case FFA_MSG_SEND_DIRECT_REQ_32: |
| 91 | case FFA_MSG_SEND_DIRECT_REQ_64: |
| 92 | *ret = arch_other_world_call(args); |
| 93 | break; |
| 94 | case FFA_MSG_SEND_DIRECT_REQ2_64: |
| 95 | *ret = arch_other_world_call_ext(args); |
| 96 | break; |
| 97 | default: |
| 98 | panic("Invalid direct message function %#x\n", args.func); |
| 99 | break; |
| 100 | } |
| 101 | |
| 102 | return true; |
| 103 | } |
| 104 | |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame] | 105 | void ffa_direct_msg_wind_call_chain_ffa_direct_req( |
Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 106 | struct vcpu_locked current_locked, |
| 107 | struct vcpu_locked receiver_vcpu_locked, ffa_id_t sender_vm_id) |
| 108 | { |
| 109 | /* Calls chains not supported in the Hypervisor/VMs. */ |
| 110 | (void)current_locked; |
| 111 | (void)receiver_vcpu_locked; |
| 112 | (void)sender_vm_id; |
| 113 | } |
| 114 | |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame] | 115 | void ffa_direct_msg_unwind_call_chain_ffa_direct_resp( |
Karl Meakin | 07de26a | 2024-07-23 17:59:33 +0100 | [diff] [blame] | 116 | struct vcpu_locked current_locked, struct vcpu_locked next_locked) |
| 117 | { |
| 118 | /* Calls chains not supported in the Hypervisor/VMs. */ |
| 119 | (void)current_locked; |
| 120 | (void)next_locked; |
| 121 | } |
Karl Meakin | a115049 | 2025-01-31 13:22:08 +0000 | [diff] [blame^] | 122 | |
| 123 | bool plat_ffa_handle_framework_msg(struct ffa_value args, struct ffa_value *ret) |
| 124 | { |
| 125 | (void)args; |
| 126 | (void)ret; |
| 127 | |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | bool plat_ffa_is_spmd_lp_id(ffa_id_t vm_id) |
| 132 | { |
| 133 | (void)vm_id; |
| 134 | return false; |
| 135 | } |