blob: 2d6e51ae1dbc538d98dd9af16430c6c2da71681a [file] [log] [blame]
Max Shvetsov103e0562021-02-04 16:58:31 +00001/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef SPM_COMMON_H
8#define SPM_COMMON_H
9
10#include <ffa_helpers.h>
11#include <stdint.h>
12#include <string.h>
13
14/* Hypervisor ID at physical FFA instance */
15#define HYP_ID (0)
16
Olivier Deprez6967c242021-04-09 09:24:08 +020017/* ID for the first Secure Partition. */
18#define SPM_VM_ID_FIRST SP_ID(1)
19
Max Shvetsov103e0562021-02-04 16:58:31 +000020/*
21 * The bit 15 of the FF-A ID indicates whether the partition is executing
22 * in the normal world, in case it is a Virtual Machine (VM); or in the
23 * secure world, in case it is a Secure Partition (SP).
24 *
25 * If bit 15 is set partition is an SP; if bit 15 is clear partition is
26 * a VM.
27 */
28#define SP_ID_MASK U(1 << 15)
29#define SP_ID(x) ((x) | SP_ID_MASK)
30#define IS_SP_ID(x) ((x & SP_ID_MASK) != 0U)
31
32struct ffa_features_test {
33 const char *test_name;
34 unsigned int feature;
35 unsigned int expected_ret;
36};
Max Shvetsov103e0562021-02-04 16:58:31 +000037
38struct mailbox_buffers {
39 void *recv;
40 void *send;
41};
42
43#define CONFIGURE_MAILBOX(mb_name, buffers_size) \
44 do { \
45 /* Declare RX/TX buffers at virtual FF-A instance */ \
46 static struct { \
47 uint8_t rx[buffers_size]; \
48 uint8_t tx[buffers_size]; \
49 } __aligned(PAGE_SIZE) mb_buffers; \
50 mb_name.recv = (void *)mb_buffers.rx; \
51 mb_name.send = (void *)mb_buffers.tx; \
52 } while (false)
53
54#define CONFIGURE_AND_MAP_MAILBOX(mb_name, buffers_size, smc_ret) \
55 do { \
56 CONFIGURE_MAILBOX(mb_name, buffers_size); \
57 smc_ret = ffa_rxtx_map( \
58 (uintptr_t)mb_name.send, \
J-Alves43887ec2021-02-22 12:21:44 +000059 (uintptr_t)mb_name.recv, \
Max Shvetsov103e0562021-02-04 16:58:31 +000060 buffers_size / PAGE_SIZE \
61 ); \
62 } while (false)
63
J-Alves43887ec2021-02-22 12:21:44 +000064/**
65 * Helpers to evaluate returns of FF-A calls.
66 */
67bool is_ffa_call_error(smc_ret_values val);
68bool is_ffa_direct_response(smc_ret_values ret);
69bool is_expected_ffa_return(smc_ret_values ret, uint32_t func_id);
70
Olivier Deprez881b1992020-12-01 15:34:34 +010071/*
72 * Vector length:
73 * SIMD: 128 bits = 16 bytes
74 */
75#define SIMD_VECTOR_LEN_BYTES 16
76#define SIMD_NUM_VECTORS 32
77typedef uint8_t simd_vector_t[SIMD_VECTOR_LEN_BYTES];
78
79/*
80 * Fills SIMD registers with the content of the container v.
81 * Number of vectors is assumed to be SIMD_NUM_VECTORS.
82 */
83void fill_simd_vector_regs(const simd_vector_t v[SIMD_NUM_VECTORS]);
84
85/*
86 * Reads contents of SIMD registers into the provided container v.
87 * Number of vectors is assumed to be SIMD_NUM_VECTORS.
88 */
89void read_simd_vector_regs(simd_vector_t v[SIMD_NUM_VECTORS]);
90
Max Shvetsov103e0562021-02-04 16:58:31 +000091bool check_spmc_execution_level(void);
92
Olivier Deprez881b1992020-12-01 15:34:34 +010093unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_target);
94
J-Alvesbe1519a2021-02-19 14:33:54 +000095/**
96 * Helper to conduct a memory retrieve. This is to be called by the receiver
97 * of a memory share operation.
98 */
99bool memory_retrieve(struct mailbox_buffers *mb,
100 struct ffa_memory_region **retrieved, uint64_t handle,
101 ffa_vm_id_t sender, ffa_vm_id_t receiver,
102 uint32_t mem_func);
103
104/**
105 * Helper to conduct a memory relinquish. The caller is usually the receiver,
106 * after it being done with the memory shared, identified by the 'handle'.
107 */
108bool memory_relinquish(struct ffa_mem_relinquish *m, uint64_t handle,
109 ffa_vm_id_t id);
110
111ffa_memory_handle_t memory_send(
112 struct ffa_memory_region *memory_region, uint32_t mem_func,
113 uint32_t fragment_length, uint32_t total_length);
114
115ffa_memory_handle_t memory_init_and_send(
116 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
117 ffa_vm_id_t sender, ffa_vm_id_t receiver,
118 const struct ffa_memory_region_constituent* constituents,
119 uint32_t constituents_count, uint32_t mem_func);
120
Max Shvetsov103e0562021-02-04 16:58:31 +0000121#endif /* SPM_COMMON_H */