blob: f264af9af72afeaf1fa782af2b07c815c3d873fa [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};
34unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_target);
35
36struct mailbox_buffers {
37 void *recv;
38 void *send;
39};
40
41#define CONFIGURE_MAILBOX(mb_name, buffers_size) \
42 do { \
43 /* Declare RX/TX buffers at virtual FF-A instance */ \
44 static struct { \
45 uint8_t rx[buffers_size]; \
46 uint8_t tx[buffers_size]; \
47 } __aligned(PAGE_SIZE) mb_buffers; \
48 mb_name.recv = (void *)mb_buffers.rx; \
49 mb_name.send = (void *)mb_buffers.tx; \
50 } while (false)
51
52#define CONFIGURE_AND_MAP_MAILBOX(mb_name, buffers_size, smc_ret) \
53 do { \
54 CONFIGURE_MAILBOX(mb_name, buffers_size); \
55 smc_ret = ffa_rxtx_map( \
56 (uintptr_t)mb_name.send, \
57 (uintptr_t)mb_name.recv, \
58 buffers_size / PAGE_SIZE \
59 ); \
60 } while (false)
61
62bool check_spmc_execution_level(void);
63
64#endif /* SPM_COMMON_H */