Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +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 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "hf/ffa.h" |
| 12 | #include "hf/vm.h" |
| 13 | |
Karl Meakin | 3d32eef | 2024-11-25 16:40:09 +0000 | [diff] [blame] | 14 | /** Check validity of the FF-A memory send function attempt. */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 15 | bool ffa_memory_is_send_valid(ffa_id_t receiver, ffa_id_t sender, |
| 16 | uint32_t share_func, bool multiple_borrower); |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 17 | |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 18 | enum ffa_memory_handle_allocator ffa_memory_get_handle_allocator(void); |
Karl Meakin | 1a760e7 | 2024-07-25 18:58:37 +0100 | [diff] [blame] | 19 | |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 20 | /** |
| 21 | * Encodes memory handle according to section 5.10.2 of the FF-A v1.0 spec. |
| 22 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 23 | static inline ffa_memory_handle_t ffa_memory_make_handle(uint64_t index) |
Karl Meakin | 1a760e7 | 2024-07-25 18:58:37 +0100 | [diff] [blame] | 24 | { |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 25 | return ffa_memory_handle_make(index, ffa_memory_get_handle_allocator()); |
Karl Meakin | 1a760e7 | 2024-07-25 18:58:37 +0100 | [diff] [blame] | 26 | } |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Checks whether given handle was allocated by current world, according to |
| 30 | * handle encoding rules. |
| 31 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 32 | static inline bool ffa_memory_is_handle_allocated_by_current_world( |
Karl Meakin | 1a760e7 | 2024-07-25 18:58:37 +0100 | [diff] [blame] | 33 | ffa_memory_handle_t handle) |
| 34 | { |
| 35 | return ffa_memory_handle_allocator(handle) == |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 36 | ffa_memory_get_handle_allocator(); |
Karl Meakin | 1a760e7 | 2024-07-25 18:58:37 +0100 | [diff] [blame] | 37 | } |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * For non-secure memory, retrieve the NS mode if the partition manager supports |
| 41 | * it. The SPMC will return MM_MODE_NS, and the hypervisor 0 as it only deals |
| 42 | * with NS accesses by default. |
| 43 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 44 | uint32_t ffa_memory_get_other_world_mode(void); |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 45 | |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 46 | bool ffa_memory_is_mem_perm_get_valid(const struct vcpu *current); |
| 47 | bool ffa_memory_is_mem_perm_set_valid(const struct vcpu *current); |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Handles FF-A memory share calls with recipients from the other world. |
| 51 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 52 | struct ffa_value ffa_memory_other_world_mem_send( |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 53 | struct vm *from, uint32_t share_func, |
| 54 | struct ffa_memory_region **memory_region, uint32_t length, |
| 55 | uint32_t fragment_length, struct mpool *page_pool); |
| 56 | |
| 57 | /** |
| 58 | * Handles the memory reclaim if a memory handle from the other world is |
| 59 | * provided. |
| 60 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 61 | struct ffa_value ffa_memory_other_world_mem_reclaim( |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 62 | struct vm *to, ffa_memory_handle_t handle, |
| 63 | ffa_memory_region_flags_t flags, struct mpool *page_pool); |
| 64 | |
| 65 | /** |
| 66 | * Handles the continuation of the memory send operation in case the memory |
| 67 | * region descriptor contains multiple segments. |
| 68 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 69 | struct ffa_value ffa_memory_other_world_mem_send_continue( |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 70 | struct vm *from, void *fragment, uint32_t fragment_length, |
| 71 | ffa_memory_handle_t handle, struct mpool *page_pool); |
| 72 | |
Karl Meakin | 3d32eef | 2024-11-25 16:40:09 +0000 | [diff] [blame] | 73 | /* |
| 74 | * Set the security bit in `attributes` if specified by `mode`. |
| 75 | */ |
Karl Meakin | 117c808 | 2024-12-04 16:03:28 +0000 | [diff] [blame^] | 76 | ffa_memory_attributes_t ffa_memory_add_security_bit_from_mode( |
Karl Meakin | 64cadf5 | 2024-07-24 17:42:57 +0100 | [diff] [blame] | 77 | ffa_memory_attributes_t attributes, uint32_t mode); |