blob: dbb113bace2170a2c6ee3568a40a21ac62c66cef [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
17/*
18 * The bit 15 of the FF-A ID indicates whether the partition is executing
19 * in the normal world, in case it is a Virtual Machine (VM); or in the
20 * secure world, in case it is a Secure Partition (SP).
21 *
22 * If bit 15 is set partition is an SP; if bit 15 is clear partition is
23 * a VM.
24 */
25#define SP_ID_MASK U(1 << 15)
26#define SP_ID(x) ((x) | SP_ID_MASK)
27#define IS_SP_ID(x) ((x & SP_ID_MASK) != 0U)
28
29struct ffa_features_test {
30 const char *test_name;
31 unsigned int feature;
32 unsigned int expected_ret;
33};
Max Shvetsov103e0562021-02-04 16:58:31 +000034
35struct mailbox_buffers {
36 void *recv;
37 void *send;
38};
39
40#define CONFIGURE_MAILBOX(mb_name, buffers_size) \
41 do { \
42 /* Declare RX/TX buffers at virtual FF-A instance */ \
43 static struct { \
44 uint8_t rx[buffers_size]; \
45 uint8_t tx[buffers_size]; \
46 } __aligned(PAGE_SIZE) mb_buffers; \
47 mb_name.recv = (void *)mb_buffers.rx; \
48 mb_name.send = (void *)mb_buffers.tx; \
49 } while (false)
50
51#define CONFIGURE_AND_MAP_MAILBOX(mb_name, buffers_size, smc_ret) \
52 do { \
53 CONFIGURE_MAILBOX(mb_name, buffers_size); \
54 smc_ret = ffa_rxtx_map( \
55 (uintptr_t)mb_name.send, \
J-Alves43887ec2021-02-22 12:21:44 +000056 (uintptr_t)mb_name.recv, \
Max Shvetsov103e0562021-02-04 16:58:31 +000057 buffers_size / PAGE_SIZE \
58 ); \
59 } while (false)
60
J-Alves43887ec2021-02-22 12:21:44 +000061/**
62 * Helpers to evaluate returns of FF-A calls.
63 */
64bool is_ffa_call_error(smc_ret_values val);
65bool is_ffa_direct_response(smc_ret_values ret);
66bool is_expected_ffa_return(smc_ret_values ret, uint32_t func_id);
67
Olivier Deprez881b1992020-12-01 15:34:34 +010068/*
69 * Vector length:
70 * SIMD: 128 bits = 16 bytes
71 */
72#define SIMD_VECTOR_LEN_BYTES 16
73#define SIMD_NUM_VECTORS 32
74typedef uint8_t simd_vector_t[SIMD_VECTOR_LEN_BYTES];
75
76/*
77 * Fills SIMD registers with the content of the container v.
78 * Number of vectors is assumed to be SIMD_NUM_VECTORS.
79 */
80void fill_simd_vector_regs(const simd_vector_t v[SIMD_NUM_VECTORS]);
81
82/*
83 * Reads contents of SIMD registers into the provided container v.
84 * Number of vectors is assumed to be SIMD_NUM_VECTORS.
85 */
86void read_simd_vector_regs(simd_vector_t v[SIMD_NUM_VECTORS]);
87
Max Shvetsov103e0562021-02-04 16:58:31 +000088bool check_spmc_execution_level(void);
89
Olivier Deprez881b1992020-12-01 15:34:34 +010090unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_target);
91
J-Alvesbe1519a2021-02-19 14:33:54 +000092/**
93 * Helper to conduct a memory retrieve. This is to be called by the receiver
94 * of a memory share operation.
95 */
96bool memory_retrieve(struct mailbox_buffers *mb,
97 struct ffa_memory_region **retrieved, uint64_t handle,
98 ffa_vm_id_t sender, ffa_vm_id_t receiver,
99 uint32_t mem_func);
100
101/**
102 * Helper to conduct a memory relinquish. The caller is usually the receiver,
103 * after it being done with the memory shared, identified by the 'handle'.
104 */
105bool memory_relinquish(struct ffa_mem_relinquish *m, uint64_t handle,
106 ffa_vm_id_t id);
107
108ffa_memory_handle_t memory_send(
109 struct ffa_memory_region *memory_region, uint32_t mem_func,
110 uint32_t fragment_length, uint32_t total_length);
111
112ffa_memory_handle_t memory_init_and_send(
113 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
114 ffa_vm_id_t sender, ffa_vm_id_t receiver,
115 const struct ffa_memory_region_constituent* constituents,
116 uint32_t constituents_count, uint32_t mem_func);
117
Max Shvetsov103e0562021-02-04 16:58:31 +0000118#endif /* SPM_COMMON_H */