/* SPDX-License-Identifier: GPL-2.0-only */


#ifndef _MEM_BUF_EXPORTER_H
#define _MEM_BUF_EXPORTER_H

#include <linux/dma-buf.h>
#include <linux/gunyah/gh_rm_drv.h>
#include <soc/qcom/secure_buffer.h>

int mem_buf_dma_buf_attach(struct dma_buf *dmabuf,
		      struct dma_buf_attachment *attachment);


struct mem_buf_vmperm;


struct mem_buf_dma_buf_ops {
	struct mem_buf_vmperm *(*lookup)(struct dma_buf *dmabuf);
	int (*attach)(struct dma_buf *dmabuf, struct dma_buf_attachment *a);
	struct dma_buf_ops dma_ops;
};

struct dma_buf *
mem_buf_dma_buf_export(struct dma_buf_export_info *exp_info,
			struct mem_buf_dma_buf_ops *ops);


#define MEM_BUF_WRAPPER_FLAG_STATIC_VM BIT(0)
#define MEM_BUF_WRAPPER_FLAG_LENDSHARE BIT(1)
#define MEM_BUF_WRAPPER_FLAG_ACCEPT BIT(2)
#define MEM_BUF_WRAPPER_FLAG_ERR BIT(3)


struct mem_buf_vmperm *mem_buf_vmperm_alloc(struct sg_table *sgt);


struct mem_buf_vmperm *mem_buf_vmperm_alloc_staticvm(struct sg_table *sgt, int *vmids, int *perms,
		u32 nr_acl_entries);


struct mem_buf_vmperm *mem_buf_vmperm_alloc_accept(struct sg_table *sgt,
	gh_memparcel_handle_t memparcel_hdl);



int mem_buf_vmperm_release(struct mem_buf_vmperm *vmperm);


void mem_buf_vmperm_pin(struct mem_buf_vmperm *vmperm);


void mem_buf_vmperm_unpin(struct mem_buf_vmperm *vmperm);


bool mem_buf_vmperm_can_cmo(struct mem_buf_vmperm *vmperm);


bool mem_buf_vmperm_can_mmap(struct mem_buf_vmperm *vmperm, struct vm_area_struct *vma);


bool mem_buf_vmperm_can_vmap(struct mem_buf_vmperm *vmperm);

#endif 
