blob: 62d876f340c7de3848c2dfe1c4305c5b046dce33 [file] [log] [blame]
Karl Meakin64cadf52024-07-24 17:42:57 +01001/*
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 Meakin3d32eef2024-11-25 16:40:09 +000014/** Check validity of the FF-A memory send function attempt. */
Karl Meakin64cadf52024-07-24 17:42:57 +010015bool plat_ffa_is_memory_send_valid(ffa_id_t receiver, ffa_id_t sender,
16 uint32_t share_func, bool multiple_borrower);
17
Karl Meakin1a760e72024-07-25 18:58:37 +010018enum ffa_memory_handle_allocator plat_ffa_memory_handle_allocator(void);
19
Karl Meakin64cadf52024-07-24 17:42:57 +010020/**
21 * Encodes memory handle according to section 5.10.2 of the FF-A v1.0 spec.
22 */
Karl Meakin1a760e72024-07-25 18:58:37 +010023static inline ffa_memory_handle_t plat_ffa_memory_handle_make(uint64_t index)
24{
25 return ffa_memory_handle_make(index,
26 plat_ffa_memory_handle_allocator());
27}
Karl Meakin64cadf52024-07-24 17:42:57 +010028
29/**
30 * Checks whether given handle was allocated by current world, according to
31 * handle encoding rules.
32 */
Karl Meakin1a760e72024-07-25 18:58:37 +010033static inline bool plat_ffa_memory_handle_allocated_by_current_world(
34 ffa_memory_handle_t handle)
35{
36 return ffa_memory_handle_allocator(handle) ==
37 plat_ffa_memory_handle_allocator();
38}
Karl Meakin64cadf52024-07-24 17:42:57 +010039
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 */
45uint32_t plat_ffa_other_world_mode(void);
46
47bool plat_ffa_is_mem_perm_get_valid(const struct vcpu *current);
48bool plat_ffa_is_mem_perm_set_valid(const struct vcpu *current);
49
50/*
51 * Handles FF-A memory share calls with recipients from the other world.
52 */
53struct ffa_value plat_ffa_other_world_mem_send(
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 */
62struct ffa_value plat_ffa_other_world_mem_reclaim(
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 */
70struct ffa_value plat_ffa_other_world_mem_send_continue(
71 struct vm *from, void *fragment, uint32_t fragment_length,
72 ffa_memory_handle_t handle, struct mpool *page_pool);
73
Karl Meakin3d32eef2024-11-25 16:40:09 +000074/*
75 * Set the security bit in `attributes` if specified by `mode`.
76 */
77ffa_memory_attributes_t plat_ffa_memory_add_security_bit_from_mode(
Karl Meakin64cadf52024-07-24 17:42:57 +010078 ffa_memory_attributes_t attributes, uint32_t mode);