blob: ee00e147b3babf803ceb09ce704a641b8cab6c59 [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 Meakin117c8082024-12-04 16:03:28 +000015bool ffa_memory_is_send_valid(ffa_id_t receiver, ffa_id_t sender,
16 uint32_t share_func, bool multiple_borrower);
Karl Meakin64cadf52024-07-24 17:42:57 +010017
Karl Meakin117c8082024-12-04 16:03:28 +000018enum ffa_memory_handle_allocator ffa_memory_get_handle_allocator(void);
Karl Meakin1a760e72024-07-25 18:58:37 +010019
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 Meakin117c8082024-12-04 16:03:28 +000023static inline ffa_memory_handle_t ffa_memory_make_handle(uint64_t index)
Karl Meakin1a760e72024-07-25 18:58:37 +010024{
Karl Meakin117c8082024-12-04 16:03:28 +000025 return ffa_memory_handle_make(index, ffa_memory_get_handle_allocator());
Karl Meakin1a760e72024-07-25 18:58:37 +010026}
Karl Meakin64cadf52024-07-24 17:42:57 +010027
28/**
29 * Checks whether given handle was allocated by current world, according to
30 * handle encoding rules.
31 */
Karl Meakin117c8082024-12-04 16:03:28 +000032static inline bool ffa_memory_is_handle_allocated_by_current_world(
Karl Meakin1a760e72024-07-25 18:58:37 +010033 ffa_memory_handle_t handle)
34{
35 return ffa_memory_handle_allocator(handle) ==
Karl Meakin117c8082024-12-04 16:03:28 +000036 ffa_memory_get_handle_allocator();
Karl Meakin1a760e72024-07-25 18:58:37 +010037}
Karl Meakin64cadf52024-07-24 17:42:57 +010038
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 Meakin117c8082024-12-04 16:03:28 +000044uint32_t ffa_memory_get_other_world_mode(void);
Karl Meakin64cadf52024-07-24 17:42:57 +010045
Karl Meakin117c8082024-12-04 16:03:28 +000046bool ffa_memory_is_mem_perm_get_valid(const struct vcpu *current);
47bool ffa_memory_is_mem_perm_set_valid(const struct vcpu *current);
Karl Meakin64cadf52024-07-24 17:42:57 +010048
49/*
50 * Handles FF-A memory share calls with recipients from the other world.
51 */
Karl Meakin117c8082024-12-04 16:03:28 +000052struct ffa_value ffa_memory_other_world_mem_send(
Karl Meakin64cadf52024-07-24 17:42:57 +010053 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 Meakin117c8082024-12-04 16:03:28 +000061struct ffa_value ffa_memory_other_world_mem_reclaim(
Karl Meakin64cadf52024-07-24 17:42:57 +010062 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 Meakin117c8082024-12-04 16:03:28 +000069struct ffa_value ffa_memory_other_world_mem_send_continue(
Karl Meakin64cadf52024-07-24 17:42:57 +010070 struct vm *from, void *fragment, uint32_t fragment_length,
71 ffa_memory_handle_t handle, struct mpool *page_pool);
72
Karl Meakin3d32eef2024-11-25 16:40:09 +000073/*
74 * Set the security bit in `attributes` if specified by `mode`.
75 */
Karl Meakin117c8082024-12-04 16:03:28 +000076ffa_memory_attributes_t ffa_memory_add_security_bit_from_mode(
Karl Meakin64cadf52024-07-24 17:42:57 +010077 ffa_memory_attributes_t attributes, uint32_t mode);