blob: 4029e2b5f258bf7feb682e27d20f6af05a5a93d7 [file] [log] [blame]
J-Alves126ab502022-09-29 11:37:33 +01001/*
2 * Copyright 2023 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/types.h"
13
14/**
15 * Bits[31:3] of partition properties must be zero for FF-A v1.0.
16 * This corresponds to table 8.25 "Partition information descriptor"
17 * in DEN0077A FF-A 1.0 REL specification.
18 */
19#define FFA_PARTITION_v1_0_RES_MASK (~(UINT32_C(0x7)))
20
21/**
22 * Create a struct for the "Partition information descriptor" defined for v1.0
23 * which can be returned to v1.0 endpoints.
24 * This corresponds to table 8.25 "Partition information descriptor"
25 * in DEN0077A FF-A 1.0 REL specification.
26 */
27struct ffa_partition_info_v1_0 {
28 ffa_vm_id_t vm_id;
29 ffa_vcpu_count_t vcpu_count;
30 ffa_partition_properties_t properties;
31};
32
33/**
34 * Information about a set of pages which are being shared. This corresponds to
35 * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory
36 * transaction descriptor". Note that it is also used for retrieve requests and
37 * responses.
38 */
39struct ffa_memory_region_v1_0 {
40 /**
41 * The ID of the VM which originally sent the memory region, i.e. the
42 * owner.
43 */
44 ffa_vm_id_t sender;
45 uint8_t attributes;
46 /** Reserved field, must be 0. */
47 uint8_t reserved_0;
48 /** Flags to control behaviour of the transaction. */
49 ffa_memory_region_flags_t flags;
50 ffa_memory_handle_t handle;
51 /**
52 * An implementation defined value associated with the receiver and the
53 * memory region.
54 */
55 uint64_t tag;
56 /** Reserved field, must be 0. */
57 uint32_t reserved_1;
58 /**
59 * The number of `ffa_memory_access` entries included in this
60 * transaction.
61 */
62 uint32_t receiver_count;
63 /**
64 * An array of `receiver_count` endpoint memory access descriptors.
65 * Each one specifies a memory region offset, an endpoint and the
66 * attributes with which this memory region should be mapped in that
67 * endpoint's page table.
68 */
69 struct ffa_memory_access receivers[];
70};
71
72/**
73 * Gets the `ffa_composite_memory_region` for the given receiver from an
74 * `ffa_memory_region`, or NULL if it is not valid.
75 */
76static inline struct ffa_composite_memory_region *
77ffa_memory_region_get_composite_v1_0(
78 struct ffa_memory_region_v1_0 *memory_region, uint32_t receiver_index)
79{
80 uint32_t offset = memory_region->receivers[receiver_index]
81 .composite_memory_region_offset;
82
83 if (offset == 0) {
84 return NULL;
85 }
86
87 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
88 offset);
89}
90
J-Alves2d8457f2022-10-05 11:06:41 +010091void ffa_memory_region_init_header_v1_0(
92 struct ffa_memory_region_v1_0 *memory_region, ffa_vm_id_t sender,
93 ffa_memory_attributes_t attributes, ffa_memory_region_flags_t flags,
94 ffa_memory_handle_t handle, uint32_t tag, uint32_t receiver_count);
95
J-Alves126ab502022-09-29 11:37:33 +010096uint32_t ffa_memory_region_init_v1_0(
97 struct ffa_memory_region_v1_0 *memory_region,
98 size_t memory_region_max_size, ffa_vm_id_t sender,
99 struct ffa_memory_access receivers[], uint32_t receiver_count,
100 const struct ffa_memory_region_constituent constituents[],
101 uint32_t constituent_count, uint32_t tag,
102 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
103 enum ffa_memory_cacheability cacheability,
104 enum ffa_memory_shareability shareability, uint32_t *total_length,
105 uint32_t *fragment_length);