blob: 02c1262353c911bfdde67df324394937b78b3bd6 [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
Manish Pandeyf7aafef2021-03-03 11:31:47 +000020/* INTID for the managed exit virtual interrupt. */
21#define MANAGED_EXIT_INTERRUPT_ID U(4)
22
Manish Pandey58971b62020-09-21 21:10:38 +010023/** IRQ/FIQ pin used for signaling a virtual interrupt. */
24enum interrupt_pin {
25 INTERRUPT_TYPE_IRQ,
26 INTERRUPT_TYPE_FIQ,
27};
28
Max Shvetsov103e0562021-02-04 16:58:31 +000029/*
30 * The bit 15 of the FF-A ID indicates whether the partition is executing
31 * in the normal world, in case it is a Virtual Machine (VM); or in the
32 * secure world, in case it is a Secure Partition (SP).
33 *
34 * If bit 15 is set partition is an SP; if bit 15 is clear partition is
35 * a VM.
36 */
37#define SP_ID_MASK U(1 << 15)
38#define SP_ID(x) ((x) | SP_ID_MASK)
39#define IS_SP_ID(x) ((x & SP_ID_MASK) != 0U)
40
41struct ffa_features_test {
42 const char *test_name;
43 unsigned int feature;
44 unsigned int expected_ret;
45};
Max Shvetsov103e0562021-02-04 16:58:31 +000046
47struct mailbox_buffers {
48 void *recv;
49 void *send;
50};
51
52#define CONFIGURE_MAILBOX(mb_name, buffers_size) \
53 do { \
54 /* Declare RX/TX buffers at virtual FF-A instance */ \
55 static struct { \
56 uint8_t rx[buffers_size]; \
57 uint8_t tx[buffers_size]; \
58 } __aligned(PAGE_SIZE) mb_buffers; \
59 mb_name.recv = (void *)mb_buffers.rx; \
60 mb_name.send = (void *)mb_buffers.tx; \
61 } while (false)
62
63#define CONFIGURE_AND_MAP_MAILBOX(mb_name, buffers_size, smc_ret) \
64 do { \
65 CONFIGURE_MAILBOX(mb_name, buffers_size); \
66 smc_ret = ffa_rxtx_map( \
67 (uintptr_t)mb_name.send, \
J-Alves43887ec2021-02-22 12:21:44 +000068 (uintptr_t)mb_name.recv, \
Max Shvetsov103e0562021-02-04 16:58:31 +000069 buffers_size / PAGE_SIZE \
70 ); \
71 } while (false)
72
J-Alves43887ec2021-02-22 12:21:44 +000073/**
74 * Helpers to evaluate returns of FF-A calls.
75 */
76bool is_ffa_call_error(smc_ret_values val);
77bool is_ffa_direct_response(smc_ret_values ret);
78bool is_expected_ffa_return(smc_ret_values ret, uint32_t func_id);
79
Olivier Deprez881b1992020-12-01 15:34:34 +010080/*
81 * Vector length:
82 * SIMD: 128 bits = 16 bytes
83 */
84#define SIMD_VECTOR_LEN_BYTES 16
85#define SIMD_NUM_VECTORS 32
86typedef uint8_t simd_vector_t[SIMD_VECTOR_LEN_BYTES];
87
88/*
89 * Fills SIMD registers with the content of the container v.
90 * Number of vectors is assumed to be SIMD_NUM_VECTORS.
91 */
92void fill_simd_vector_regs(const simd_vector_t v[SIMD_NUM_VECTORS]);
93
94/*
95 * Reads contents of SIMD registers into the provided container v.
96 * Number of vectors is assumed to be SIMD_NUM_VECTORS.
97 */
98void read_simd_vector_regs(simd_vector_t v[SIMD_NUM_VECTORS]);
99
Max Shvetsov103e0562021-02-04 16:58:31 +0000100bool check_spmc_execution_level(void);
101
Olivier Deprez881b1992020-12-01 15:34:34 +0100102unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_target);
103
J-Alvesbe1519a2021-02-19 14:33:54 +0000104/**
105 * Helper to conduct a memory retrieve. This is to be called by the receiver
106 * of a memory share operation.
107 */
108bool memory_retrieve(struct mailbox_buffers *mb,
109 struct ffa_memory_region **retrieved, uint64_t handle,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000110 ffa_id_t sender, ffa_id_t receiver,
J-Alvesbe1519a2021-02-19 14:33:54 +0000111 uint32_t mem_func);
112
113/**
114 * Helper to conduct a memory relinquish. The caller is usually the receiver,
115 * after it being done with the memory shared, identified by the 'handle'.
116 */
117bool memory_relinquish(struct ffa_mem_relinquish *m, uint64_t handle,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000118 ffa_id_t id);
J-Alvesbe1519a2021-02-19 14:33:54 +0000119
120ffa_memory_handle_t memory_send(
121 struct ffa_memory_region *memory_region, uint32_t mem_func,
122 uint32_t fragment_length, uint32_t total_length);
123
124ffa_memory_handle_t memory_init_and_send(
125 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000126 ffa_id_t sender, ffa_id_t receiver,
J-Alvesbe1519a2021-02-19 14:33:54 +0000127 const struct ffa_memory_region_constituent* constituents,
128 uint32_t constituents_count, uint32_t mem_func);
129
Max Shvetsov103e0562021-02-04 16:58:31 +0000130#endif /* SPM_COMMON_H */