blob: ad0e9adba8ec628a8ea1d3147efbe53ddf7bd61e [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"
Karl Meakin07a69ab2025-02-07 14:53:19 +000012#include "hf/mm.h"
Karl Meakin64cadf52024-07-24 17:42:57 +010013#include "hf/vm.h"
14
Karl Meakin3d32eef2024-11-25 16:40:09 +000015/** Check validity of the FF-A memory send function attempt. */
Karl Meakin117c8082024-12-04 16:03:28 +000016bool ffa_memory_is_send_valid(ffa_id_t receiver, ffa_id_t sender,
17 uint32_t share_func, bool multiple_borrower);
Karl Meakin64cadf52024-07-24 17:42:57 +010018
Karl Meakin117c8082024-12-04 16:03:28 +000019enum ffa_memory_handle_allocator ffa_memory_get_handle_allocator(void);
Karl Meakin1a760e72024-07-25 18:58:37 +010020
Karl Meakin64cadf52024-07-24 17:42:57 +010021/**
22 * Encodes memory handle according to section 5.10.2 of the FF-A v1.0 spec.
23 */
Karl Meakin117c8082024-12-04 16:03:28 +000024static inline ffa_memory_handle_t ffa_memory_make_handle(uint64_t index)
Karl Meakin1a760e72024-07-25 18:58:37 +010025{
Karl Meakin117c8082024-12-04 16:03:28 +000026 return ffa_memory_handle_make(index, ffa_memory_get_handle_allocator());
Karl Meakin1a760e72024-07-25 18:58:37 +010027}
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 Meakin117c8082024-12-04 16:03:28 +000033static inline bool ffa_memory_is_handle_allocated_by_current_world(
Karl Meakin1a760e72024-07-25 18:58:37 +010034 ffa_memory_handle_t handle)
35{
36 return ffa_memory_handle_allocator(handle) ==
Karl Meakin117c8082024-12-04 16:03:28 +000037 ffa_memory_get_handle_allocator();
Karl Meakin1a760e72024-07-25 18:58:37 +010038}
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 */
Karl Meakin07a69ab2025-02-07 14:53:19 +000045mm_mode_t ffa_memory_get_other_world_mode(void);
Karl Meakin64cadf52024-07-24 17:42:57 +010046
Karl Meakin117c8082024-12-04 16:03:28 +000047bool ffa_memory_is_mem_perm_get_valid(const struct vcpu *current);
48bool ffa_memory_is_mem_perm_set_valid(const struct vcpu *current);
Karl Meakin64cadf52024-07-24 17:42:57 +010049
50/*
51 * Handles FF-A memory share calls with recipients from the other world.
52 */
Karl Meakin117c8082024-12-04 16:03:28 +000053struct ffa_value ffa_memory_other_world_mem_send(
Karl Meakin64cadf52024-07-24 17:42:57 +010054 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 Meakin117c8082024-12-04 16:03:28 +000062struct ffa_value ffa_memory_other_world_mem_reclaim(
Karl Meakin64cadf52024-07-24 17:42:57 +010063 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 Meakin117c8082024-12-04 16:03:28 +000070struct ffa_value ffa_memory_other_world_mem_send_continue(
Karl Meakin64cadf52024-07-24 17:42:57 +010071 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 */
Karl Meakin117c8082024-12-04 16:03:28 +000077ffa_memory_attributes_t ffa_memory_add_security_bit_from_mode(
Karl Meakin07a69ab2025-02-07 14:53:19 +000078 ffa_memory_attributes_t attributes, mm_mode_t mode);