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