blob: fc7ddd789f73490cde49eee78800a296a801c0a7 [file] [log] [blame]
Max Shvetsov103e0562021-02-04 16:58:31 +00001/*
Shruti Gupta38133fa2023-04-19 17:00:38 +01002 * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
Max Shvetsov103e0562021-02-04 16:58:31 +00003 *
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
Olivier Deprez569be402022-07-08 10:24:39 +020017#include <lib/extensions/sve.h>
18
Max Shvetsov103e0562021-02-04 16:58:31 +000019/* Hypervisor ID at physical FFA instance */
20#define HYP_ID (0)
Daniel Boulby198deda2021-03-03 11:35:25 +000021/* SPMC ID */
22#define SPMC_ID U(0x8000)
Max Shvetsov103e0562021-02-04 16:58:31 +000023
Olivier Deprez6967c242021-04-09 09:24:08 +020024/* ID for the first Secure Partition. */
25#define SPM_VM_ID_FIRST SP_ID(1)
26
Manish Pandeyf7aafef2021-03-03 11:31:47 +000027/* INTID for the managed exit virtual interrupt. */
28#define MANAGED_EXIT_INTERRUPT_ID U(4)
29
J-Alves4439ece2021-11-05 11:52:54 +000030/* INTID for the notification pending interrupt. */
31#define NOTIFICATION_PENDING_INTERRUPT_INTID 5
32
Raghu Krishnamurthy9e267a02022-08-11 21:25:26 -070033/* Interrupt used for testing extended SPI handling. */
34#define IRQ_ESPI_TEST_INTID 5000
35
Manish Pandey58971b62020-09-21 21:10:38 +010036/** IRQ/FIQ pin used for signaling a virtual interrupt. */
37enum interrupt_pin {
38 INTERRUPT_TYPE_IRQ,
39 INTERRUPT_TYPE_FIQ,
40};
41
Max Shvetsov103e0562021-02-04 16:58:31 +000042/*
43 * The bit 15 of the FF-A ID indicates whether the partition is executing
44 * in the normal world, in case it is a Virtual Machine (VM); or in the
45 * secure world, in case it is a Secure Partition (SP).
46 *
47 * If bit 15 is set partition is an SP; if bit 15 is clear partition is
48 * a VM.
49 */
50#define SP_ID_MASK U(1 << 15)
51#define SP_ID(x) ((x) | SP_ID_MASK)
J-Alvesd5d87152021-10-29 11:48:37 +010052#define VM_ID(x) (x & ~SP_ID_MASK)
Max Shvetsov103e0562021-02-04 16:58:31 +000053#define IS_SP_ID(x) ((x & SP_ID_MASK) != 0U)
54
Daniel Boulby4a2888a2022-05-31 16:07:36 +010055#define NULL_UUID (const struct ffa_uuid) { .uuid = {0} }
56
Max Shvetsov103e0562021-02-04 16:58:31 +000057struct ffa_features_test {
58 const char *test_name;
59 unsigned int feature;
60 unsigned int expected_ret;
Karl Meakin31b81772023-03-14 15:38:17 +000061 unsigned int param;
Daniel Boulby198deda2021-03-03 11:35:25 +000062 unsigned int version_added;
Max Shvetsov103e0562021-02-04 16:58:31 +000063};
Max Shvetsov103e0562021-02-04 16:58:31 +000064
65struct mailbox_buffers {
66 void *recv;
67 void *send;
68};
69
70#define CONFIGURE_MAILBOX(mb_name, buffers_size) \
71 do { \
72 /* Declare RX/TX buffers at virtual FF-A instance */ \
73 static struct { \
74 uint8_t rx[buffers_size]; \
75 uint8_t tx[buffers_size]; \
76 } __aligned(PAGE_SIZE) mb_buffers; \
77 mb_name.recv = (void *)mb_buffers.rx; \
78 mb_name.send = (void *)mb_buffers.tx; \
79 } while (false)
80
81#define CONFIGURE_AND_MAP_MAILBOX(mb_name, buffers_size, smc_ret) \
82 do { \
83 CONFIGURE_MAILBOX(mb_name, buffers_size); \
84 smc_ret = ffa_rxtx_map( \
85 (uintptr_t)mb_name.send, \
J-Alves43887ec2021-02-22 12:21:44 +000086 (uintptr_t)mb_name.recv, \
Max Shvetsov103e0562021-02-04 16:58:31 +000087 buffers_size / PAGE_SIZE \
88 ); \
89 } while (false)
90
J-Alves43887ec2021-02-22 12:21:44 +000091/**
92 * Helpers to evaluate returns of FF-A calls.
93 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010094bool is_ffa_call_error(struct ffa_value val);
95bool is_expected_ffa_error(struct ffa_value ret, int32_t error_code);
96bool is_ffa_direct_response(struct ffa_value ret);
97bool is_expected_ffa_return(struct ffa_value ret, uint32_t func_id);
98bool is_expected_cactus_response(struct ffa_value ret, uint32_t expected_resp,
J-Alves227065a2021-03-11 10:01:36 +000099 uint32_t arg);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100100void dump_ffa_value(struct ffa_value ret);
J-Alves43887ec2021-02-22 12:21:44 +0000101
Max Shvetsov103e0562021-02-04 16:58:31 +0000102bool check_spmc_execution_level(void);
103
Olivier Deprez881b1992020-12-01 15:34:34 +0100104unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_target);
105
J-Alvesbe1519a2021-02-19 14:33:54 +0000106/**
107 * Helper to conduct a memory retrieve. This is to be called by the receiver
108 * of a memory share operation.
109 */
110bool memory_retrieve(struct mailbox_buffers *mb,
111 struct ffa_memory_region **retrieved, uint64_t handle,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000112 ffa_id_t sender, ffa_id_t receiver,
J-Alvesafffe3a2023-09-22 17:14:52 +0100113 ffa_memory_region_flags_t flags, uint32_t mem_func);
J-Alvesbe1519a2021-02-19 14:33:54 +0000114
115/**
116 * Helper to conduct a memory relinquish. The caller is usually the receiver,
117 * after it being done with the memory shared, identified by the 'handle'.
118 */
119bool memory_relinquish(struct ffa_mem_relinquish *m, uint64_t handle,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000120 ffa_id_t id);
J-Alvesbe1519a2021-02-19 14:33:54 +0000121
122ffa_memory_handle_t memory_send(
123 struct ffa_memory_region *memory_region, uint32_t mem_func,
Daniel Boulbyce386b12022-03-29 18:36:36 +0100124 uint32_t fragment_length, uint32_t total_length, struct ffa_value *ret);
J-Alvesbe1519a2021-02-19 14:33:54 +0000125
126ffa_memory_handle_t memory_init_and_send(
127 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000128 ffa_id_t sender, ffa_id_t receiver,
J-Alvesbe1519a2021-02-19 14:33:54 +0000129 const struct ffa_memory_region_constituent* constituents,
Daniel Boulbyce386b12022-03-29 18:36:36 +0100130 uint32_t constituents_count, uint32_t mem_func, struct ffa_value *ret);
J-Alvesbe1519a2021-02-19 14:33:54 +0000131
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000132bool ffa_partition_info_helper(struct mailbox_buffers *mb,
133 const struct ffa_uuid uuid,
134 const struct ffa_partition_info *expected,
135 const uint16_t expected_size);
nabkah01eb95d1a2022-11-06 15:18:06 +0000136bool enable_trusted_wdog_interrupt(ffa_id_t source, ffa_id_t dest);
137bool disable_trusted_wdog_interrupt(ffa_id_t source, ffa_id_t dest);
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000138
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700139bool ffa_partition_info_regs_helper(const struct ffa_uuid uuid,
140 const struct ffa_partition_info *expected,
141 const uint16_t expected_size);
Karl Meakin367ff542023-11-01 15:05:37 +0000142
143struct ffa_memory_access ffa_memory_access_init_permissions_from_mem_func(
144 ffa_id_t receiver_id,
145 uint32_t mem_func);
146
Max Shvetsov103e0562021-02-04 16:58:31 +0000147#endif /* SPM_COMMON_H */