soc: qcom: mem-buf: Add support for consumers to import dma-bufs

Supplier virtual machines (VMs) support exporting dma-bufs to
a consumer VM. However, consumers do not support importing dma-bufs
into their VMs, so add an IOCTL command to import a dma-buf into
a consumer VM.

The client must provide a memory parcel handle that corresponds to a
dma-buf that has been shared with the consumer VM, as well as an
access control list that is used for validating the access control
rules for the buffer. Upon success, the client is given a dma-buf
fd, which they can use to map the buffer and access it from both
the CPU, and peripherals.

Change-Id: I548e004e73543421b932430fbd9f84ad76658ef8
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
This commit is contained in:
Isaac J. Manjarres 2020-05-21 13:53:48 -07:00
commit eb749ee5d9
5 changed files with 677 additions and 7 deletions

View file

@ -56,13 +56,13 @@ struct mem_buf_ion_data {
};
/**
* struct mem_buf_alloc_ioctl_arg: An request to allocate memory from another
* struct mem_buf_alloc_ioctl_arg: A request to allocate memory from another
* VM to other VMs.
* @size: The size of the allocation.
* @nr_acl_entries: The number of ACL entries in @acl_list.
* @acl_list: An array of structures, where each structure specifies a VMID
* and the access permissions that the VMID will have to the memory to be
* allocated.
* @nr_acl_entries: The number of ACL entries in @acl_list.
* @src_mem_type: The type of memory that the source VM should allocate from.
* This should be one of the mem_buf_mem_type enum values.
* @src_data: A pointer to data that the source VM should interpret when
@ -70,25 +70,25 @@ struct mem_buf_ion_data {
* @dst_mem_type: The type of memory that the destination VM should treat the
* incoming allocation from the source VM as. This should be one of the
* mem_buf_mem_type enum values.
* @dst_data: A pointer to data that the destination VM should interpret when
* adding the memory to the current VM.
* @mem_buf_fd: A file descriptor representing the memory that was allocated
* from the source VM and added to the current VM. Calling close() on this file
* descriptor will deallocate the memory from the current VM, and return it
* to the source VM.
* * @dst_data: A pointer to data that the destination VM should interpret when
* adding the memory to the current VM.
*
* All reserved fields must be zeroed out by the caller prior to invoking the
* allocation IOCTL command with this argument.
*/
struct mem_buf_alloc_ioctl_arg {
__u64 size;
__u32 nr_acl_entries;
__u64 acl_list;
__u32 nr_acl_entries;
__u32 src_mem_type;
__u64 src_data;
__u32 dst_mem_type;
__u64 dst_data;
__u32 mem_buf_fd;
__u64 dst_data;
__u64 reserved0;
__u64 reserved1;
__u64 reserved2;
@ -131,4 +131,32 @@ struct mem_buf_export_ioctl_arg {
#define MEM_BUF_IOC_EXPORT _IOWR(MEM_BUF_IOC_MAGIC, 1,\
struct mem_buf_export_ioctl_arg)
/**
* struct mem_buf_import_ioctl_arg: A request to import memory from another
* VM as a dma-buf
* @memparcel_hdl: The handle that corresponds to the memparcel we are
* importing.
* @nr_acl_entries: The number of ACL entries in @acl_list.
* @acl_list: An array of structures, where each structure specifies a VMID
* and the access permissions that the VMID should have for the memparcel.
* @dma_buf_import_fd: A dma-buf file descriptor that the client can use to
* access the buffer. This fd must be closed to release the memory.
*
* All reserved fields must be zeroed out by the caller prior to invoking the
* import IOCTL command with this argument.
*/
struct mem_buf_import_ioctl_arg {
__u32 memparcel_hdl;
__u32 nr_acl_entries;
__u64 acl_list;
__u32 dma_buf_import_fd;
__u32 reserved0;
__u64 reserved1;
__u64 reserved2;
__u64 reserved3;
};
#define MEM_BUF_IOC_IMPORT _IOWR(MEM_BUF_IOC_MAGIC, 2,\
struct mem_buf_import_ioctl_arg)
#endif /* _UAPI_LINUX_MEM_BUF_H */