| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * helper functions for physically contiguous capture buffers |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * Based on videobuf-vmalloc.c, |
|---|
| 10 | 11 | * (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 |
|---|
| 15 | 12 | */ |
|---|
| 16 | 13 | |
|---|
| 17 | 14 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 39 | 36 | |
|---|
| 40 | 37 | static int __videobuf_dc_alloc(struct device *dev, |
|---|
| 41 | 38 | struct videobuf_dma_contig_memory *mem, |
|---|
| 42 | | - unsigned long size, gfp_t flags) |
|---|
| 39 | + unsigned long size) |
|---|
| 43 | 40 | { |
|---|
| 44 | 41 | 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); |
|---|
| 48 | 44 | if (!mem->vaddr) { |
|---|
| 49 | 45 | dev_err(dev, "memory alloc size %ld failed\n", mem->size); |
|---|
| 50 | 46 | return -ENOMEM; |
|---|
| .. | .. |
|---|
| 172 | 168 | mem->size = PAGE_ALIGN(vb->size + offset); |
|---|
| 173 | 169 | ret = -EINVAL; |
|---|
| 174 | 170 | |
|---|
| 175 | | - down_read(&mm->mmap_sem); |
|---|
| 171 | + mmap_read_lock(mm); |
|---|
| 176 | 172 | |
|---|
| 177 | 173 | vma = find_vma(mm, untagged_baddr); |
|---|
| 178 | 174 | if (!vma) |
|---|
| .. | .. |
|---|
| 204 | 200 | } |
|---|
| 205 | 201 | |
|---|
| 206 | 202 | out_up: |
|---|
| 207 | | - up_read(¤t->mm->mmap_sem); |
|---|
| 203 | + mmap_read_unlock(current->mm); |
|---|
| 208 | 204 | |
|---|
| 209 | 205 | return ret; |
|---|
| 210 | 206 | } |
|---|
| .. | .. |
|---|
| 249 | 245 | |
|---|
| 250 | 246 | /* All handling should be done by __videobuf_mmap_mapper() */ |
|---|
| 251 | 247 | 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"); |
|---|
| 253 | 249 | return -EINVAL; |
|---|
| 254 | 250 | } |
|---|
| 255 | 251 | break; |
|---|
| .. | .. |
|---|
| 261 | 257 | return videobuf_dma_contig_user_get(mem, vb); |
|---|
| 262 | 258 | |
|---|
| 263 | 259 | /* 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))) |
|---|
| 266 | 261 | return -ENOMEM; |
|---|
| 267 | 262 | break; |
|---|
| 268 | 263 | case V4L2_MEMORY_OVERLAY: |
|---|
| .. | .. |
|---|
| 281 | 276 | struct videobuf_dma_contig_memory *mem; |
|---|
| 282 | 277 | struct videobuf_mapping *map; |
|---|
| 283 | 278 | int retval; |
|---|
| 284 | | - unsigned long size; |
|---|
| 285 | 279 | |
|---|
| 286 | 280 | dev_dbg(q->dev, "%s\n", __func__); |
|---|
| 287 | 281 | |
|---|
| .. | .. |
|---|
| 299 | 293 | BUG_ON(!mem); |
|---|
| 300 | 294 | MAGIC_CHECK(mem->magic, MAGIC_DC_MEM); |
|---|
| 301 | 295 | |
|---|
| 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))) |
|---|
| 304 | 297 | 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); |
|---|
| 309 | 298 | |
|---|
| 310 | 299 | /* the "vm_pgoff" is just used in v4l2 to find the |
|---|
| 311 | 300 | * corresponding buffer data structure which is allocated |
|---|
| 312 | 301 | * earlier and it does not mean the offset from the physical |
|---|
| 313 | 302 | * 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(). |
|---|
| 315 | 304 | */ |
|---|
| 316 | 305 | 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); |
|---|
| 319 | 308 | if (retval) { |
|---|
| 320 | 309 | dev_err(q->dev, "mmap: remap failed with error %d. ", |
|---|
| 321 | 310 | retval); |
|---|