Skip to content

Commit 02c19d8

Browse files
committed
firmware: arm_ffa: Add support for FFA_MSG_SEND2
The FFA_MSG_SEND2 can be used to transmit a partition message from the Tx buffer of the sender(the driver in this case) endpoint to the Rx buffer of the receiver endpoint. An invocation of the FFA_MSG_SEND2 transfers the ownership of the Tx buffer to the receiver endpoint(or any intermediate consumer). Completion of an FFA_MSG_SEND2 invocation transfers the ownership of the buffer back to the sender endpoint. The framework defines the FFA_MSG_SEND2 interface to transmit a partition message from the Tx buffer of the sender to the Rx buffer of a receiver and inform the scheduler that the receiver must be run. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sudeep Holla <[email protected]>
1 parent 3c258bf commit 02c19d8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

drivers/firmware/arm_ffa/driver.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,38 @@ static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, bool mode_32bit,
345345
return -EINVAL;
346346
}
347347

348+
static int ffa_msg_send2(u16 src_id, u16 dst_id, void *buf, size_t sz)
349+
{
350+
u32 src_dst_ids = PACK_TARGET_INFO(src_id, dst_id);
351+
struct ffa_indirect_msg_hdr *msg;
352+
ffa_value_t ret;
353+
int retval = 0;
354+
355+
if (sz > (RXTX_BUFFER_SIZE - sizeof(*msg)))
356+
return -ERANGE;
357+
358+
mutex_lock(&drv_info->tx_lock);
359+
360+
msg = drv_info->tx_buffer;
361+
msg->flags = 0;
362+
msg->res0 = 0;
363+
msg->offset = sizeof(*msg);
364+
msg->send_recv_id = src_dst_ids;
365+
msg->size = sz;
366+
memcpy(msg + msg->offset, buf, sz);
367+
368+
/* flags = 0, sender VMID = 0 works for both physical/virtual NS */
369+
invoke_ffa_fn((ffa_value_t){
370+
.a0 = FFA_MSG_SEND2, .a1 = 0, .a2 = 0
371+
}, &ret);
372+
373+
if (ret.a0 == FFA_ERROR)
374+
retval = ffa_to_linux_errno((int)ret.a2);
375+
376+
mutex_unlock(&drv_info->tx_lock);
377+
return retval;
378+
}
379+
348380
static int ffa_mem_first_frag(u32 func_id, phys_addr_t buf, u32 buf_sz,
349381
u32 frag_len, u32 len, u64 *handle)
350382
{
@@ -871,6 +903,11 @@ static int ffa_sync_send_receive(struct ffa_device *dev,
871903
dev->mode_32bit, data);
872904
}
873905

906+
static int ffa_indirect_msg_send(struct ffa_device *dev, void *buf, size_t sz)
907+
{
908+
return ffa_msg_send2(drv_info->vm_id, dev->vm_id, buf, sz);
909+
}
910+
874911
static int ffa_memory_share(struct ffa_mem_ops_args *args)
875912
{
876913
if (drv_info->mem_ops_native)
@@ -1146,6 +1183,7 @@ static const struct ffa_info_ops ffa_drv_info_ops = {
11461183
static const struct ffa_msg_ops ffa_drv_msg_ops = {
11471184
.mode_32bit_set = ffa_mode_32bit_set,
11481185
.sync_send_receive = ffa_sync_send_receive,
1186+
.indirect_send = ffa_indirect_msg_send,
11491187
};
11501188

11511189
static const struct ffa_mem_ops ffa_drv_mem_ops = {

include/linux/arm_ffa.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ struct ffa_send_direct_data {
254254
unsigned long data4; /* w7/x7 */
255255
};
256256

257+
struct ffa_indirect_msg_hdr {
258+
u32 flags;
259+
u32 res0;
260+
u32 offset;
261+
u32 send_recv_id;
262+
u32 size;
263+
};
264+
257265
struct ffa_mem_region_addr_range {
258266
/* The base IPA of the constituent memory region, aligned to 4 kiB */
259267
u64 address;
@@ -414,6 +422,7 @@ struct ffa_msg_ops {
414422
void (*mode_32bit_set)(struct ffa_device *dev);
415423
int (*sync_send_receive)(struct ffa_device *dev,
416424
struct ffa_send_direct_data *data);
425+
int (*indirect_send)(struct ffa_device *dev, void *buf, size_t sz);
417426
};
418427

419428
struct ffa_mem_ops {

0 commit comments

Comments
 (0)