hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/v4l2-core/videobuf-dma-contig.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * helper functions for physically contiguous capture buffers
34 *
....@@ -8,10 +9,6 @@
89 *
910 * Based on videobuf-vmalloc.c,
1011 * (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org>
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; either version 2
1512 */
1613
1714 #include <linux/init.h>
....@@ -39,12 +36,11 @@
3936
4037 static int __videobuf_dc_alloc(struct device *dev,
4138 struct videobuf_dma_contig_memory *mem,
42
- unsigned long size, gfp_t flags)
39
+ unsigned long size)
4340 {
4441 mem->size = size;
45
- mem->vaddr = dma_alloc_coherent(dev, mem->size,
46
- &mem->dma_handle, flags);
47
-
42
+ mem->vaddr = dma_alloc_coherent(dev, mem->size, &mem->dma_handle,
43
+ GFP_KERNEL);
4844 if (!mem->vaddr) {
4945 dev_err(dev, "memory alloc size %ld failed\n", mem->size);
5046 return -ENOMEM;
....@@ -172,7 +168,7 @@
172168 mem->size = PAGE_ALIGN(vb->size + offset);
173169 ret = -EINVAL;
174170
175
- down_read(&mm->mmap_sem);
171
+ mmap_read_lock(mm);
176172
177173 vma = find_vma(mm, untagged_baddr);
178174 if (!vma)
....@@ -204,7 +200,7 @@
204200 }
205201
206202 out_up:
207
- up_read(&current->mm->mmap_sem);
203
+ mmap_read_unlock(current->mm);
208204
209205 return ret;
210206 }
....@@ -249,7 +245,7 @@
249245
250246 /* All handling should be done by __videobuf_mmap_mapper() */
251247 if (!mem->vaddr) {
252
- dev_err(q->dev, "memory is not alloced/mmapped.\n");
248
+ dev_err(q->dev, "memory is not allocated/mmapped.\n");
253249 return -EINVAL;
254250 }
255251 break;
....@@ -261,8 +257,7 @@
261257 return videobuf_dma_contig_user_get(mem, vb);
262258
263259 /* allocate memory for the read() method */
264
- if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(vb->size),
265
- GFP_KERNEL))
260
+ if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(vb->size)))
266261 return -ENOMEM;
267262 break;
268263 case V4L2_MEMORY_OVERLAY:
....@@ -281,7 +276,6 @@
281276 struct videobuf_dma_contig_memory *mem;
282277 struct videobuf_mapping *map;
283278 int retval;
284
- unsigned long size;
285279
286280 dev_dbg(q->dev, "%s\n", __func__);
287281
....@@ -299,23 +293,18 @@
299293 BUG_ON(!mem);
300294 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
301295
302
- if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(buf->bsize),
303
- GFP_KERNEL | __GFP_COMP))
296
+ if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(buf->bsize)))
304297 goto error;
305
-
306
- /* Try to remap memory */
307
- size = vma->vm_end - vma->vm_start;
308
- vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
309298
310299 /* the "vm_pgoff" is just used in v4l2 to find the
311300 * corresponding buffer data structure which is allocated
312301 * earlier and it does not mean the offset from the physical
313302 * buffer start address as usual. So set it to 0 to pass
314
- * the sanity check in vm_iomap_memory().
303
+ * the sanity check in dma_mmap_coherent().
315304 */
316305 vma->vm_pgoff = 0;
317
-
318
- retval = vm_iomap_memory(vma, mem->dma_handle, size);
306
+ retval = dma_mmap_coherent(q->dev, vma, mem->vaddr, mem->dma_handle,
307
+ mem->size);
319308 if (retval) {
320309 dev_err(q->dev, "mmap: remap failed with error %d. ",
321310 retval);