Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Gerd Hoffmann | 913965c | 2018-09-11 15:42:04 +0200 | [diff] [blame] | 2 | #include <linux/cred.h> |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 3 | #include <linux/device.h> |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 4 | #include <linux/dma-buf.h> |
| 5 | #include <linux/highmem.h> |
Gerd Hoffmann | 913965c | 2018-09-11 15:42:04 +0200 | [diff] [blame] | 6 | #include <linux/init.h> |
| 7 | #include <linux/kernel.h> |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 8 | #include <linux/memfd.h> |
Gerd Hoffmann | 913965c | 2018-09-11 15:42:04 +0200 | [diff] [blame] | 9 | #include <linux/miscdevice.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/shmem_fs.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/udmabuf.h> |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 14 | |
Gerd Hoffmann | dc4716d | 2018-09-11 15:42:10 +0200 | [diff] [blame] | 15 | static const u32 list_limit = 1024; /* udmabuf_create_list->count limit */ |
| 16 | static const size_t size_limit_mb = 64; /* total dmabuf size, in megabytes */ |
| 17 | |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 18 | struct udmabuf { |
Gerd Hoffmann | b35f57c | 2018-09-11 15:42:06 +0200 | [diff] [blame] | 19 | pgoff_t pagecount; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 20 | struct page **pages; |
Gurchetan Singh | 284562e | 2019-12-02 17:36:27 -0800 | [diff] [blame] | 21 | struct sg_table *sg; |
Gurchetan Singh | c1bbed6 | 2019-12-02 17:36:25 -0800 | [diff] [blame] | 22 | struct miscdevice *device; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 23 | }; |
| 24 | |
Souptick Joarder | 300133d | 2019-01-03 15:26:34 -0800 | [diff] [blame] | 25 | static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 26 | { |
| 27 | struct vm_area_struct *vma = vmf->vma; |
| 28 | struct udmabuf *ubuf = vma->vm_private_data; |
| 29 | |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 30 | vmf->page = ubuf->pages[vmf->pgoff]; |
| 31 | get_page(vmf->page); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | static const struct vm_operations_struct udmabuf_vm_ops = { |
| 36 | .fault = udmabuf_vm_fault, |
| 37 | }; |
| 38 | |
| 39 | static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) |
| 40 | { |
| 41 | struct udmabuf *ubuf = buf->priv; |
| 42 | |
| 43 | if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) |
| 44 | return -EINVAL; |
| 45 | |
| 46 | vma->vm_ops = &udmabuf_vm_ops; |
| 47 | vma->vm_private_data = ubuf; |
| 48 | return 0; |
| 49 | } |
| 50 | |
Gurchetan Singh | 17a7ce2 | 2019-12-02 17:36:26 -0800 | [diff] [blame] | 51 | static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf, |
| 52 | enum dma_data_direction direction) |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 53 | { |
Gurchetan Singh | 17a7ce2 | 2019-12-02 17:36:26 -0800 | [diff] [blame] | 54 | struct udmabuf *ubuf = buf->priv; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 55 | struct sg_table *sg; |
Gerd Hoffmann | a3e722d | 2018-09-11 15:42:05 +0200 | [diff] [blame] | 56 | int ret; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 57 | |
| 58 | sg = kzalloc(sizeof(*sg), GFP_KERNEL); |
| 59 | if (!sg) |
Gerd Hoffmann | a3e722d | 2018-09-11 15:42:05 +0200 | [diff] [blame] | 60 | return ERR_PTR(-ENOMEM); |
| 61 | ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount, |
| 62 | 0, ubuf->pagecount << PAGE_SHIFT, |
| 63 | GFP_KERNEL); |
| 64 | if (ret < 0) |
| 65 | goto err; |
Marek Szyprowski | 62296b3 | 2020-04-06 16:41:45 +0200 | [diff] [blame] | 66 | ret = dma_map_sgtable(dev, sg, direction, 0); |
| 67 | if (ret < 0) |
Gerd Hoffmann | a3e722d | 2018-09-11 15:42:05 +0200 | [diff] [blame] | 68 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 69 | return sg; |
| 70 | |
Gerd Hoffmann | a3e722d | 2018-09-11 15:42:05 +0200 | [diff] [blame] | 71 | err: |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 72 | sg_free_table(sg); |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 73 | kfree(sg); |
Gerd Hoffmann | a3e722d | 2018-09-11 15:42:05 +0200 | [diff] [blame] | 74 | return ERR_PTR(ret); |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Gurchetan Singh | 17a7ce2 | 2019-12-02 17:36:26 -0800 | [diff] [blame] | 77 | static void put_sg_table(struct device *dev, struct sg_table *sg, |
| 78 | enum dma_data_direction direction) |
| 79 | { |
Marek Szyprowski | 62296b3 | 2020-04-06 16:41:45 +0200 | [diff] [blame] | 80 | dma_unmap_sgtable(dev, sg, direction, 0); |
Gurchetan Singh | 17a7ce2 | 2019-12-02 17:36:26 -0800 | [diff] [blame] | 81 | sg_free_table(sg); |
| 82 | kfree(sg); |
| 83 | } |
| 84 | |
| 85 | static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, |
| 86 | enum dma_data_direction direction) |
| 87 | { |
| 88 | return get_sg_table(at->dev, at->dmabuf, direction); |
| 89 | } |
| 90 | |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 91 | static void unmap_udmabuf(struct dma_buf_attachment *at, |
| 92 | struct sg_table *sg, |
| 93 | enum dma_data_direction direction) |
| 94 | { |
Gurchetan Singh | 17a7ce2 | 2019-12-02 17:36:26 -0800 | [diff] [blame] | 95 | return put_sg_table(at->dev, sg, direction); |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static void release_udmabuf(struct dma_buf *buf) |
| 99 | { |
| 100 | struct udmabuf *ubuf = buf->priv; |
Gurchetan Singh | 284562e | 2019-12-02 17:36:27 -0800 | [diff] [blame] | 101 | struct device *dev = ubuf->device->this_device; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 102 | pgoff_t pg; |
| 103 | |
Gurchetan Singh | 284562e | 2019-12-02 17:36:27 -0800 | [diff] [blame] | 104 | if (ubuf->sg) |
| 105 | put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL); |
| 106 | |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 107 | for (pg = 0; pg < ubuf->pagecount; pg++) |
| 108 | put_page(ubuf->pages[pg]); |
| 109 | kfree(ubuf->pages); |
| 110 | kfree(ubuf); |
| 111 | } |
| 112 | |
Gurchetan Singh | 284562e | 2019-12-02 17:36:27 -0800 | [diff] [blame] | 113 | static int begin_cpu_udmabuf(struct dma_buf *buf, |
| 114 | enum dma_data_direction direction) |
| 115 | { |
| 116 | struct udmabuf *ubuf = buf->priv; |
| 117 | struct device *dev = ubuf->device->this_device; |
| 118 | |
| 119 | if (!ubuf->sg) { |
| 120 | ubuf->sg = get_sg_table(dev, buf, direction); |
| 121 | if (IS_ERR(ubuf->sg)) |
| 122 | return PTR_ERR(ubuf->sg); |
| 123 | } else { |
Gurchetan Singh | 1ffe095 | 2019-12-17 15:02:28 -0800 | [diff] [blame] | 124 | dma_sync_sg_for_cpu(dev, ubuf->sg->sgl, ubuf->sg->nents, |
| 125 | direction); |
Gurchetan Singh | 284562e | 2019-12-02 17:36:27 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | static int end_cpu_udmabuf(struct dma_buf *buf, |
| 132 | enum dma_data_direction direction) |
| 133 | { |
| 134 | struct udmabuf *ubuf = buf->priv; |
| 135 | struct device *dev = ubuf->device->this_device; |
| 136 | |
| 137 | if (!ubuf->sg) |
| 138 | return -EINVAL; |
| 139 | |
Gurchetan Singh | 1ffe095 | 2019-12-17 15:02:28 -0800 | [diff] [blame] | 140 | dma_sync_sg_for_device(dev, ubuf->sg->sgl, ubuf->sg->nents, direction); |
Gurchetan Singh | 284562e | 2019-12-02 17:36:27 -0800 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
Gerd Hoffmann | a348528 | 2018-09-11 15:42:07 +0200 | [diff] [blame] | 144 | static const struct dma_buf_ops udmabuf_ops = { |
Gurchetan Singh | bc7a71d | 2019-12-02 17:36:24 -0800 | [diff] [blame] | 145 | .cache_sgt_mapping = true, |
| 146 | .map_dma_buf = map_udmabuf, |
| 147 | .unmap_dma_buf = unmap_udmabuf, |
| 148 | .release = release_udmabuf, |
| 149 | .mmap = mmap_udmabuf, |
Gurchetan Singh | 284562e | 2019-12-02 17:36:27 -0800 | [diff] [blame] | 150 | .begin_cpu_access = begin_cpu_udmabuf, |
| 151 | .end_cpu_access = end_cpu_udmabuf, |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | #define SEALS_WANTED (F_SEAL_SHRINK) |
| 155 | #define SEALS_DENIED (F_SEAL_WRITE) |
| 156 | |
Gurchetan Singh | c1bbed6 | 2019-12-02 17:36:25 -0800 | [diff] [blame] | 157 | static long udmabuf_create(struct miscdevice *device, |
| 158 | struct udmabuf_create_list *head, |
| 159 | struct udmabuf_create_item *list) |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 160 | { |
| 161 | DEFINE_DMA_BUF_EXPORT_INFO(exp_info); |
| 162 | struct file *memfd = NULL; |
| 163 | struct udmabuf *ubuf; |
| 164 | struct dma_buf *buf; |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 165 | pgoff_t pgoff, pgcnt, pgidx, pgbuf = 0, pglimit; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 166 | struct page *page; |
| 167 | int seals, ret = -EINVAL; |
| 168 | u32 i, flags; |
| 169 | |
Gerd Hoffmann | 33f3542 | 2018-09-11 15:42:15 +0200 | [diff] [blame] | 170 | ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL); |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 171 | if (!ubuf) |
| 172 | return -ENOMEM; |
| 173 | |
Gerd Hoffmann | dc4716d | 2018-09-11 15:42:10 +0200 | [diff] [blame] | 174 | pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 175 | for (i = 0; i < head->count; i++) { |
| 176 | if (!IS_ALIGNED(list[i].offset, PAGE_SIZE)) |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 177 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 178 | if (!IS_ALIGNED(list[i].size, PAGE_SIZE)) |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 179 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 180 | ubuf->pagecount += list[i].size >> PAGE_SHIFT; |
Gerd Hoffmann | dc4716d | 2018-09-11 15:42:10 +0200 | [diff] [blame] | 181 | if (ubuf->pagecount > pglimit) |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 182 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 183 | } |
Gerd Hoffmann | 33f3542 | 2018-09-11 15:42:15 +0200 | [diff] [blame] | 184 | ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages), |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 185 | GFP_KERNEL); |
| 186 | if (!ubuf->pages) { |
| 187 | ret = -ENOMEM; |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 188 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | pgbuf = 0; |
| 192 | for (i = 0; i < head->count; i++) { |
Gerd Hoffmann | 7a1c67d | 2018-09-11 15:42:12 +0200 | [diff] [blame] | 193 | ret = -EBADFD; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 194 | memfd = fget(list[i].memfd); |
| 195 | if (!memfd) |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 196 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 197 | if (!shmem_mapping(file_inode(memfd)->i_mapping)) |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 198 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 199 | seals = memfd_fcntl(memfd, F_GET_SEALS, 0); |
Gerd Hoffmann | 7a1c67d | 2018-09-11 15:42:12 +0200 | [diff] [blame] | 200 | if (seals == -EINVAL) |
| 201 | goto err; |
| 202 | ret = -EINVAL; |
| 203 | if ((seals & SEALS_WANTED) != SEALS_WANTED || |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 204 | (seals & SEALS_DENIED) != 0) |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 205 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 206 | pgoff = list[i].offset >> PAGE_SHIFT; |
| 207 | pgcnt = list[i].size >> PAGE_SHIFT; |
| 208 | for (pgidx = 0; pgidx < pgcnt; pgidx++) { |
| 209 | page = shmem_read_mapping_page( |
| 210 | file_inode(memfd)->i_mapping, pgoff + pgidx); |
| 211 | if (IS_ERR(page)) { |
| 212 | ret = PTR_ERR(page); |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 213 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 214 | } |
| 215 | ubuf->pages[pgbuf++] = page; |
| 216 | } |
| 217 | fput(memfd); |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 218 | memfd = NULL; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 219 | } |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 220 | |
| 221 | exp_info.ops = &udmabuf_ops; |
| 222 | exp_info.size = ubuf->pagecount << PAGE_SHIFT; |
| 223 | exp_info.priv = ubuf; |
Gerd Hoffmann | 5c074ee | 2018-11-14 13:20:29 +0100 | [diff] [blame] | 224 | exp_info.flags = O_RDWR; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 225 | |
Gurchetan Singh | c1bbed6 | 2019-12-02 17:36:25 -0800 | [diff] [blame] | 226 | ubuf->device = device; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 227 | buf = dma_buf_export(&exp_info); |
| 228 | if (IS_ERR(buf)) { |
| 229 | ret = PTR_ERR(buf); |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 230 | goto err; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | flags = 0; |
| 234 | if (head->flags & UDMABUF_FLAGS_CLOEXEC) |
| 235 | flags |= O_CLOEXEC; |
| 236 | return dma_buf_fd(buf, flags); |
| 237 | |
Gerd Hoffmann | 0d17455 | 2018-09-11 15:42:11 +0200 | [diff] [blame] | 238 | err: |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 239 | while (pgbuf > 0) |
| 240 | put_page(ubuf->pages[--pgbuf]); |
Gustavo A. R. Silva | 683a0e6 | 2018-09-04 14:07:49 -0500 | [diff] [blame] | 241 | if (memfd) |
| 242 | fput(memfd); |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 243 | kfree(ubuf->pages); |
| 244 | kfree(ubuf); |
| 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | static long udmabuf_ioctl_create(struct file *filp, unsigned long arg) |
| 249 | { |
| 250 | struct udmabuf_create create; |
| 251 | struct udmabuf_create_list head; |
| 252 | struct udmabuf_create_item list; |
| 253 | |
| 254 | if (copy_from_user(&create, (void __user *)arg, |
Gerd Hoffmann | 33f3542 | 2018-09-11 15:42:15 +0200 | [diff] [blame] | 255 | sizeof(create))) |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 256 | return -EFAULT; |
| 257 | |
| 258 | head.flags = create.flags; |
| 259 | head.count = 1; |
| 260 | list.memfd = create.memfd; |
| 261 | list.offset = create.offset; |
| 262 | list.size = create.size; |
| 263 | |
Gurchetan Singh | c1bbed6 | 2019-12-02 17:36:25 -0800 | [diff] [blame] | 264 | return udmabuf_create(filp->private_data, &head, &list); |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static long udmabuf_ioctl_create_list(struct file *filp, unsigned long arg) |
| 268 | { |
| 269 | struct udmabuf_create_list head; |
| 270 | struct udmabuf_create_item *list; |
| 271 | int ret = -EINVAL; |
| 272 | u32 lsize; |
| 273 | |
| 274 | if (copy_from_user(&head, (void __user *)arg, sizeof(head))) |
| 275 | return -EFAULT; |
Gerd Hoffmann | dc4716d | 2018-09-11 15:42:10 +0200 | [diff] [blame] | 276 | if (head.count > list_limit) |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 277 | return -EINVAL; |
| 278 | lsize = sizeof(struct udmabuf_create_item) * head.count; |
| 279 | list = memdup_user((void __user *)(arg + sizeof(head)), lsize); |
| 280 | if (IS_ERR(list)) |
| 281 | return PTR_ERR(list); |
| 282 | |
Gurchetan Singh | c1bbed6 | 2019-12-02 17:36:25 -0800 | [diff] [blame] | 283 | ret = udmabuf_create(filp->private_data, &head, list); |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 284 | kfree(list); |
| 285 | return ret; |
| 286 | } |
| 287 | |
| 288 | static long udmabuf_ioctl(struct file *filp, unsigned int ioctl, |
| 289 | unsigned long arg) |
| 290 | { |
| 291 | long ret; |
| 292 | |
| 293 | switch (ioctl) { |
| 294 | case UDMABUF_CREATE: |
| 295 | ret = udmabuf_ioctl_create(filp, arg); |
| 296 | break; |
| 297 | case UDMABUF_CREATE_LIST: |
| 298 | ret = udmabuf_ioctl_create_list(filp, arg); |
| 299 | break; |
| 300 | default: |
Gerd Hoffmann | 52499d9c | 2018-09-11 15:42:13 +0200 | [diff] [blame] | 301 | ret = -ENOTTY; |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | static const struct file_operations udmabuf_fops = { |
| 308 | .owner = THIS_MODULE, |
| 309 | .unlocked_ioctl = udmabuf_ioctl, |
Kristian H. Kristensen | d4a197f | 2020-09-03 18:16:52 +0000 | [diff] [blame] | 310 | #ifdef CONFIG_COMPAT |
| 311 | .compat_ioctl = udmabuf_ioctl, |
| 312 | #endif |
Gerd Hoffmann | fbb0de7 | 2018-08-27 11:34:44 +0200 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | static struct miscdevice udmabuf_misc = { |
| 316 | .minor = MISC_DYNAMIC_MINOR, |
| 317 | .name = "udmabuf", |
| 318 | .fops = &udmabuf_fops, |
| 319 | }; |
| 320 | |
| 321 | static int __init udmabuf_dev_init(void) |
| 322 | { |
| 323 | return misc_register(&udmabuf_misc); |
| 324 | } |
| 325 | |
| 326 | static void __exit udmabuf_dev_exit(void) |
| 327 | { |
| 328 | misc_deregister(&udmabuf_misc); |
| 329 | } |
| 330 | |
| 331 | module_init(udmabuf_dev_init) |
| 332 | module_exit(udmabuf_dev_exit) |
| 333 | |
| 334 | MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>"); |
| 335 | MODULE_LICENSE("GPL v2"); |