blob: db9b1be995e69b186ffc675d74f2be155e797472 [file] [log] [blame]
Abdellatif El Khlifi39d383b2023-08-04 14:33:40 +01001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
4 *
5 * Authors:
6 * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
7 */
8
9#ifndef __ARM_FFA_H
10#define __ARM_FFA_H
11
12#include <linux/printk.h>
13
14/*
15 * This header is public. It can be used by clients to access
16 * data structures and definitions they need
17 */
18
19/*
20 * struct ffa_partition_info - Partition information descriptor
21 * @id: Partition ID
22 * @exec_ctxt: Execution context count
23 * @properties: Partition properties
24 *
25 * Data structure containing information about partitions instantiated in the system
26 * This structure is filled with the data queried by FFA_PARTITION_INFO_GET
27 */
28struct ffa_partition_info {
29 u16 id;
30 u16 exec_ctxt;
31/* partition supports receipt of direct requests */
32#define FFA_PARTITION_DIRECT_RECV BIT(0)
33/* partition can send direct requests. */
34#define FFA_PARTITION_DIRECT_SEND BIT(1)
35/* partition can send and receive indirect messages. */
36#define FFA_PARTITION_INDIRECT_MSG BIT(2)
37 u32 properties;
38};
39
40/*
41 * struct ffa_partition_uuid - 16 bytes UUID transmitted by FFA_PARTITION_INFO_GET
42 * @a1-4: 32-bit words access to the UUID data
43 *
44 */
45struct ffa_partition_uuid {
46 u32 a1; /* w1 */
47 u32 a2; /* w2 */
48 u32 a3; /* w3 */
49 u32 a4; /* w4 */
50};
51
52/**
53 * struct ffa_partition_desc - the secure partition descriptor
54 * @info: partition information
55 * @sp_uuid: the secure partition UUID
56 *
57 * Each partition has its descriptor containing the partitions information and the UUID
58 */
59struct ffa_partition_desc {
60 struct ffa_partition_info info;
61 struct ffa_partition_uuid sp_uuid;
62};
63
64/*
65 * struct ffa_send_direct_data - Data structure hosting the data
66 * used by FFA_MSG_SEND_DIRECT_{REQ,RESP}
67 * @data0-4: Data read/written from/to x3-x7 registers
68 *
69 * Data structure containing the data to be sent by FFA_MSG_SEND_DIRECT_REQ
70 * or read from FFA_MSG_SEND_DIRECT_RESP
71 */
72
73/* For use with FFA_MSG_SEND_DIRECT_{REQ,RESP} which pass data via registers */
74struct ffa_send_direct_data {
75 ulong data0; /* w3/x3 */
76 ulong data1; /* w4/x4 */
77 ulong data2; /* w5/x5 */
78 ulong data3; /* w6/x6 */
79 ulong data4; /* w7/x7 */
80};
81
82struct udevice;
83
84/**
85 * struct ffa_bus_ops - Operations for FF-A
86 * @partition_info_get: callback for the FFA_PARTITION_INFO_GET
87 * @sync_send_receive: callback for the FFA_MSG_SEND_DIRECT_REQ
88 * @rxtx_unmap: callback for the FFA_RXTX_UNMAP
89 *
90 * The data structure providing all the operations supported by the driver.
91 * This structure is EFI runtime resident.
92 */
93struct ffa_bus_ops {
94 int (*partition_info_get)(struct udevice *dev, const char *uuid_str,
95 u32 *sp_count, struct ffa_partition_desc **sp_descs);
96 int (*sync_send_receive)(struct udevice *dev, u16 dst_part_id,
97 struct ffa_send_direct_data *msg,
98 bool is_smc64);
99 int (*rxtx_unmap)(struct udevice *dev);
100};
101
102#define ffa_get_ops(dev) ((struct ffa_bus_ops *)(dev)->driver->ops)
103
104/**
105 * ffa_rxtx_unmap() - FFA_RXTX_UNMAP driver operation
106 * Please see ffa_unmap_rxtx_buffers_hdlr() description for more details.
107 */
108int ffa_rxtx_unmap(struct udevice *dev);
109
110/**
111 * ffa_unmap_rxtx_buffers_hdlr() - FFA_RXTX_UNMAP handler function
112 * @dev: The arm_ffa bus device
113 *
114 * This function implements FFA_RXTX_UNMAP FF-A function
115 * to unmap the RX/TX buffers
116 *
117 * Return:
118 *
119 * 0 on success. Otherwise, failure
120 */
121int ffa_unmap_rxtx_buffers_hdlr(struct udevice *dev);
122
123/**
124 * ffa_sync_send_receive() - FFA_MSG_SEND_DIRECT_{REQ,RESP} driver operation
125 * Please see ffa_msg_send_direct_req_hdlr() description for more details.
126 */
127int ffa_sync_send_receive(struct udevice *dev, u16 dst_part_id,
128 struct ffa_send_direct_data *msg, bool is_smc64);
129
130/**
131 * ffa_msg_send_direct_req_hdlr() - FFA_MSG_SEND_DIRECT_{REQ,RESP} handler function
132 * @dev: The arm_ffa bus device
133 * @dst_part_id: destination partition ID
134 * @msg: pointer to the message data preallocated by the client (in/out)
135 * @is_smc64: select 64-bit or 32-bit FF-A ABI
136 *
137 * This function implements FFA_MSG_SEND_DIRECT_{REQ,RESP}
138 * FF-A functions.
139 *
140 * FFA_MSG_SEND_DIRECT_REQ is used to send the data to the secure partition.
141 * The response from the secure partition is handled by reading the
142 * FFA_MSG_SEND_DIRECT_RESP arguments.
143 *
144 * The maximum size of the data that can be exchanged is 40 bytes which is
145 * sizeof(struct ffa_send_direct_data) as defined by the FF-A specification 1.0
146 * in the section relevant to FFA_MSG_SEND_DIRECT_{REQ,RESP}
147 *
148 * Return:
149 *
150 * 0 on success. Otherwise, failure
151 */
152int ffa_msg_send_direct_req_hdlr(struct udevice *dev, u16 dst_part_id,
153 struct ffa_send_direct_data *msg, bool is_smc64);
154
155/**
156 * ffa_partition_info_get() - FFA_PARTITION_INFO_GET driver operation
157 * Please see ffa_get_partitions_info_hdlr() description for more details.
158 */
159int ffa_partition_info_get(struct udevice *dev, const char *uuid_str,
160 u32 *sp_count, struct ffa_partition_desc **sp_descs);
161
162/**
163 * ffa_get_partitions_info_hdlr() - FFA_PARTITION_INFO_GET handler function
164 * @uuid_str: pointer to the UUID string
165 * @sp_count: address of the variable containing the number of partitions matching the UUID
166 * The variable is set by the driver
167 * @sp_descs: address of the descriptors of the partitions matching the UUID
168 * The address is set by the driver
169 *
170 * Return the number of partitions and their descriptors matching the UUID
171 *
172 * Query the secure partition data from uc_priv.
173 * If not found, invoke FFA_PARTITION_INFO_GET
174 * FF-A function to query the partition information from secure world.
175 *
176 * A client of the FF-A driver should know the UUID of the service it wants to
177 * access. It should use the UUID to request the FF-A driver to provide the
178 * partition(s) information of the service. The FF-A driver uses
179 * PARTITION_INFO_GET to obtain this information. This is implemented through
180 * ffa_get_partitions_info_hdlr() function.
181 * A new FFA_PARTITION_INFO_GET call is issued (first one performed through
182 * ffa_cache_partitions_info) allowing to retrieve the partition(s) information.
183 * They are not saved (already done). We only update the UUID in the cached area.
184 * This assumes that partitions data does not change in the secure world.
185 * Otherwise u-boot will have an outdated partition data. The benefit of caching
186 * the information in the FF-A driver is to accommodate discovery after
187 * ExitBootServices().
188 *
189 * Return:
190 *
191 * @sp_count: the number of partitions
192 * @sp_descs: address of the partitions descriptors
193 *
194 * On success 0 is returned. Otherwise, failure
195 */
196int ffa_get_partitions_info_hdlr(struct udevice *dev, const char *uuid_str,
197 u32 *sp_count, struct ffa_partition_desc **sp_descs);
198
199struct ffa_priv;
200
201/**
202 * ffa_set_smc_conduit() - Set the SMC conduit
203 * @dev: The FF-A bus device
204 *
205 * Selects the SMC conduit by setting the FF-A ABI invoke function.
206 *
207 * Return:
208 *
209 * 0 on success. Otherwise, failure
210 */
211int ffa_set_smc_conduit(struct udevice *dev);
212
213#endif