blob: 58569d511e873592fc2a5e1cefcbf02333d54f36 [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
J-Alves79c08f12021-10-27 15:15:16 +010010#include <plat/common/platform.h>
11
Max Shvetsov103e0562021-02-04 16:58:31 +000012#include <stdint.h>
13#include <string.h>
14
J-Alves79c08f12021-10-27 15:15:16 +010015#include <ffa_helpers.h>
16
Max Shvetsov103e0562021-02-04 16:58:31 +000017/* Hypervisor ID at physical FFA instance */
18#define HYP_ID (0)
Daniel Boulby198deda2021-03-03 11:35:25 +000019/* SPMC ID */
20#define SPMC_ID U(0x8000)
Max Shvetsov103e0562021-02-04 16:58:31 +000021
Olivier Deprez6967c242021-04-09 09:24:08 +020022/* ID for the first Secure Partition. */
23#define SPM_VM_ID_FIRST SP_ID(1)
24
Manish Pandeyf7aafef2021-03-03 11:31:47 +000025/* INTID for the managed exit virtual interrupt. */
26#define MANAGED_EXIT_INTERRUPT_ID U(4)
27
J-Alves4439ece2021-11-05 11:52:54 +000028/* INTID for the notification pending interrupt. */
29#define NOTIFICATION_PENDING_INTERRUPT_INTID 5
30
Manish Pandey58971b62020-09-21 21:10:38 +010031/** IRQ/FIQ pin used for signaling a virtual interrupt. */
32enum interrupt_pin {
33 INTERRUPT_TYPE_IRQ,
34 INTERRUPT_TYPE_FIQ,
35};
36
Max Shvetsov103e0562021-02-04 16:58:31 +000037/*
38 * The bit 15 of the FF-A ID indicates whether the partition is executing
39 * in the normal world, in case it is a Virtual Machine (VM); or in the
40 * secure world, in case it is a Secure Partition (SP).
41 *
42 * If bit 15 is set partition is an SP; if bit 15 is clear partition is
43 * a VM.
44 */
45#define SP_ID_MASK U(1 << 15)
46#define SP_ID(x) ((x) | SP_ID_MASK)
J-Alvesd5d87152021-10-29 11:48:37 +010047#define VM_ID(x) (x & ~SP_ID_MASK)
Max Shvetsov103e0562021-02-04 16:58:31 +000048#define IS_SP_ID(x) ((x & SP_ID_MASK) != 0U)
49
50struct ffa_features_test {
51 const char *test_name;
52 unsigned int feature;
53 unsigned int expected_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000054 unsigned int version_added;
Max Shvetsov103e0562021-02-04 16:58:31 +000055};
Max Shvetsov103e0562021-02-04 16:58:31 +000056
57struct mailbox_buffers {
58 void *recv;
59 void *send;
60};
61
62#define CONFIGURE_MAILBOX(mb_name, buffers_size) \
63 do { \
64 /* Declare RX/TX buffers at virtual FF-A instance */ \
65 static struct { \
66 uint8_t rx[buffers_size]; \
67 uint8_t tx[buffers_size]; \
68 } __aligned(PAGE_SIZE) mb_buffers; \
69 mb_name.recv = (void *)mb_buffers.rx; \
70 mb_name.send = (void *)mb_buffers.tx; \
71 } while (false)
72
73#define CONFIGURE_AND_MAP_MAILBOX(mb_name, buffers_size, smc_ret) \
74 do { \
75 CONFIGURE_MAILBOX(mb_name, buffers_size); \
76 smc_ret = ffa_rxtx_map( \
77 (uintptr_t)mb_name.send, \
J-Alves43887ec2021-02-22 12:21:44 +000078 (uintptr_t)mb_name.recv, \
Max Shvetsov103e0562021-02-04 16:58:31 +000079 buffers_size / PAGE_SIZE \
80 ); \
81 } while (false)
82
J-Alves43887ec2021-02-22 12:21:44 +000083/**
84 * Helpers to evaluate returns of FF-A calls.
85 */
86bool is_ffa_call_error(smc_ret_values val);
J-Alves227065a2021-03-11 10:01:36 +000087bool is_expected_ffa_error(smc_ret_values ret, int32_t error_code);
J-Alves43887ec2021-02-22 12:21:44 +000088bool is_ffa_direct_response(smc_ret_values ret);
89bool is_expected_ffa_return(smc_ret_values ret, uint32_t func_id);
J-Alves227065a2021-03-11 10:01:36 +000090bool is_expected_cactus_response(smc_ret_values ret, uint32_t expected_resp,
91 uint32_t arg);
J-Alvescd1cefe2021-06-14 14:29:18 +010092void dump_smc_ret_values(smc_ret_values ret);
J-Alves43887ec2021-02-22 12:21:44 +000093
Olivier Deprez881b1992020-12-01 15:34:34 +010094/*
95 * Vector length:
96 * SIMD: 128 bits = 16 bytes
Max Shvetsov959be332021-03-16 14:18:13 +000097 * SVE: 512 bits = 64 bytes
Olivier Deprez881b1992020-12-01 15:34:34 +010098 */
99#define SIMD_VECTOR_LEN_BYTES 16
Max Shvetsov959be332021-03-16 14:18:13 +0000100#define SVE_VECTOR_LEN_BYTES 64
101
Olivier Deprez881b1992020-12-01 15:34:34 +0100102#define SIMD_NUM_VECTORS 32
Max Shvetsov959be332021-03-16 14:18:13 +0000103#define SVE_NUM_VECTORS 32
Olivier Deprez881b1992020-12-01 15:34:34 +0100104typedef uint8_t simd_vector_t[SIMD_VECTOR_LEN_BYTES];
Max Shvetsov959be332021-03-16 14:18:13 +0000105typedef uint8_t sve_vector_t[SVE_VECTOR_LEN_BYTES];
Olivier Deprez881b1992020-12-01 15:34:34 +0100106
107/*
Max Shvetsov959be332021-03-16 14:18:13 +0000108 * Fills SIMD/SVE registers with the content of the container v.
109 * Number of vectors is assumed to be SIMD/SVE_NUM_VECTORS.
Olivier Deprez881b1992020-12-01 15:34:34 +0100110 */
111void fill_simd_vector_regs(const simd_vector_t v[SIMD_NUM_VECTORS]);
Max Shvetsov959be332021-03-16 14:18:13 +0000112void fill_sve_vector_regs(const sve_vector_t v[SVE_NUM_VECTORS]);
Olivier Deprez881b1992020-12-01 15:34:34 +0100113
114/*
Max Shvetsov959be332021-03-16 14:18:13 +0000115 * Reads contents of SIMD/SVE registers into the provided container v.
116 * Number of vectors is assumed to be SIMD/SVE_NUM_VECTORS.
Olivier Deprez881b1992020-12-01 15:34:34 +0100117 */
118void read_simd_vector_regs(simd_vector_t v[SIMD_NUM_VECTORS]);
Max Shvetsov959be332021-03-16 14:18:13 +0000119void read_sve_vector_regs(sve_vector_t v[SVE_NUM_VECTORS]);
Olivier Deprez881b1992020-12-01 15:34:34 +0100120
Max Shvetsov103e0562021-02-04 16:58:31 +0000121bool check_spmc_execution_level(void);
122
Olivier Deprez881b1992020-12-01 15:34:34 +0100123unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_target);
124
J-Alvesbe1519a2021-02-19 14:33:54 +0000125/**
126 * Helper to conduct a memory retrieve. This is to be called by the receiver
127 * of a memory share operation.
128 */
129bool memory_retrieve(struct mailbox_buffers *mb,
130 struct ffa_memory_region **retrieved, uint64_t handle,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000131 ffa_id_t sender, ffa_id_t receiver,
J-Alvesbe1519a2021-02-19 14:33:54 +0000132 uint32_t mem_func);
133
134/**
135 * Helper to conduct a memory relinquish. The caller is usually the receiver,
136 * after it being done with the memory shared, identified by the 'handle'.
137 */
138bool memory_relinquish(struct ffa_mem_relinquish *m, uint64_t handle,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000139 ffa_id_t id);
J-Alvesbe1519a2021-02-19 14:33:54 +0000140
141ffa_memory_handle_t memory_send(
142 struct ffa_memory_region *memory_region, uint32_t mem_func,
143 uint32_t fragment_length, uint32_t total_length);
144
145ffa_memory_handle_t memory_init_and_send(
146 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000147 ffa_id_t sender, ffa_id_t receiver,
J-Alvesbe1519a2021-02-19 14:33:54 +0000148 const struct ffa_memory_region_constituent* constituents,
149 uint32_t constituents_count, uint32_t mem_func);
150
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000151bool ffa_partition_info_helper(struct mailbox_buffers *mb,
152 const struct ffa_uuid uuid,
153 const struct ffa_partition_info *expected,
154 const uint16_t expected_size);
155
Max Shvetsov103e0562021-02-04 16:58:31 +0000156#endif /* SPM_COMMON_H */