#include <linux/device.h>
#include <linux/dma-buf.h>
#include <linux/highmem.h>
#include <linux/kernel.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/shmem_fs.h>
#include <linux/udmabuf.h>
static const u32 list_limit = 1024;
static const size_t size_limit_mb = 64;
static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
struct vm_area_struct *vma = vmf->vma;
struct udmabuf *ubuf = vma->vm_private_data;
vmf->page = ubuf->pages[vmf->pgoff];
static const struct vm_operations_struct udmabuf_vm_ops = {
.fault = udmabuf_vm_fault,
static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
struct udmabuf *ubuf = buf->priv;
if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
vma->vm_ops = &udmabuf_vm_ops;
vma->vm_private_data = ubuf;
static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
enum dma_data_direction direction)
struct udmabuf *ubuf = at->dmabuf->priv;
sg = kzalloc(sizeof(*sg), GFP_KERNEL);
ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount,
0, ubuf->pagecount << PAGE_SHIFT,