LCOV - code coverage report
Current view: top level - drivers/media/common/videobuf2 - videobuf2-memops.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 0 24 0.0 %
Date: 2020-09-30 20:25:40 Functions: 0 4 0.0 %
Branches: 0 6 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * videobuf2-memops.c - generic memory handling routines for videobuf2
       3                 :            :  *
       4                 :            :  * Copyright (C) 2010 Samsung Electronics
       5                 :            :  *
       6                 :            :  * Author: Pawel Osciak <pawel@osciak.com>
       7                 :            :  *         Marek Szyprowski <m.szyprowski@samsung.com>
       8                 :            :  *
       9                 :            :  * This program is free software; you can redistribute it and/or modify
      10                 :            :  * it under the terms of the GNU General Public License as published by
      11                 :            :  * the Free Software Foundation.
      12                 :            :  */
      13                 :            : 
      14                 :            : #include <linux/slab.h>
      15                 :            : #include <linux/module.h>
      16                 :            : #include <linux/dma-mapping.h>
      17                 :            : #include <linux/vmalloc.h>
      18                 :            : #include <linux/mm.h>
      19                 :            : #include <linux/sched.h>
      20                 :            : #include <linux/file.h>
      21                 :            : 
      22                 :            : #include <media/videobuf2-v4l2.h>
      23                 :            : #include <media/videobuf2-memops.h>
      24                 :            : 
      25                 :            : /**
      26                 :            :  * vb2_create_framevec() - map virtual addresses to pfns
      27                 :            :  * @start:      Virtual user address where we start mapping
      28                 :            :  * @length:     Length of a range to map
      29                 :            :  *
      30                 :            :  * This function allocates and fills in a vector with pfns corresponding to
      31                 :            :  * virtual address range passed in arguments. If pfns have corresponding pages,
      32                 :            :  * page references are also grabbed to pin pages in memory. The function
      33                 :            :  * returns pointer to the vector on success and error pointer in case of
      34                 :            :  * failure. Returned vector needs to be freed via vb2_destroy_pfnvec().
      35                 :            :  */
      36                 :          0 : struct frame_vector *vb2_create_framevec(unsigned long start,
      37                 :            :                                          unsigned long length)
      38                 :            : {
      39                 :            :         int ret;
      40                 :            :         unsigned long first, last;
      41                 :            :         unsigned long nr;
      42                 :            :         struct frame_vector *vec;
      43                 :            :         unsigned int flags = FOLL_FORCE | FOLL_WRITE;
      44                 :            : 
      45                 :          0 :         first = start >> PAGE_SHIFT;
      46                 :          0 :         last = (start + length - 1) >> PAGE_SHIFT;
      47                 :          0 :         nr = last - first + 1;
      48                 :          0 :         vec = frame_vector_create(nr);
      49         [ #  # ]:          0 :         if (!vec)
      50                 :            :                 return ERR_PTR(-ENOMEM);
      51                 :          0 :         ret = get_vaddr_frames(start & PAGE_MASK, nr, flags, vec);
      52         [ #  # ]:          0 :         if (ret < 0)
      53                 :            :                 goto out_destroy;
      54                 :            :         /* We accept only complete set of PFNs */
      55         [ #  # ]:          0 :         if (ret != nr) {
      56                 :            :                 ret = -EFAULT;
      57                 :            :                 goto out_release;
      58                 :            :         }
      59                 :            :         return vec;
      60                 :            : out_release:
      61                 :          0 :         put_vaddr_frames(vec);
      62                 :            : out_destroy:
      63                 :          0 :         frame_vector_destroy(vec);
      64                 :          0 :         return ERR_PTR(ret);
      65                 :            : }
      66                 :            : EXPORT_SYMBOL(vb2_create_framevec);
      67                 :            : 
      68                 :            : /**
      69                 :            :  * vb2_destroy_framevec() - release vector of mapped pfns
      70                 :            :  * @vec:        vector of pfns / pages to release
      71                 :            :  *
      72                 :            :  * This releases references to all pages in the vector @vec (if corresponding
      73                 :            :  * pfns are backed by pages) and frees the passed vector.
      74                 :            :  */
      75                 :          0 : void vb2_destroy_framevec(struct frame_vector *vec)
      76                 :            : {
      77                 :          0 :         put_vaddr_frames(vec);
      78                 :          0 :         frame_vector_destroy(vec);
      79                 :          0 : }
      80                 :            : EXPORT_SYMBOL(vb2_destroy_framevec);
      81                 :            : 
      82                 :            : /**
      83                 :            :  * vb2_common_vm_open() - increase refcount of the vma
      84                 :            :  * @vma:        virtual memory region for the mapping
      85                 :            :  *
      86                 :            :  * This function adds another user to the provided vma. It expects
      87                 :            :  * struct vb2_vmarea_handler pointer in vma->vm_private_data.
      88                 :            :  */
      89                 :          0 : static void vb2_common_vm_open(struct vm_area_struct *vma)
      90                 :            : {
      91                 :          0 :         struct vb2_vmarea_handler *h = vma->vm_private_data;
      92                 :            : 
      93                 :            :         pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
      94                 :            :                __func__, h, refcount_read(h->refcount), vma->vm_start,
      95                 :            :                vma->vm_end);
      96                 :            : 
      97                 :          0 :         refcount_inc(h->refcount);
      98                 :          0 : }
      99                 :            : 
     100                 :            : /**
     101                 :            :  * vb2_common_vm_close() - decrease refcount of the vma
     102                 :            :  * @vma:        virtual memory region for the mapping
     103                 :            :  *
     104                 :            :  * This function releases the user from the provided vma. It expects
     105                 :            :  * struct vb2_vmarea_handler pointer in vma->vm_private_data.
     106                 :            :  */
     107                 :          0 : static void vb2_common_vm_close(struct vm_area_struct *vma)
     108                 :            : {
     109                 :          0 :         struct vb2_vmarea_handler *h = vma->vm_private_data;
     110                 :            : 
     111                 :            :         pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
     112                 :            :                __func__, h, refcount_read(h->refcount), vma->vm_start,
     113                 :            :                vma->vm_end);
     114                 :            : 
     115                 :          0 :         h->put(h->arg);
     116                 :          0 : }
     117                 :            : 
     118                 :            : /*
     119                 :            :  * vb2_common_vm_ops - common vm_ops used for tracking refcount of mmapped
     120                 :            :  * video buffers
     121                 :            :  */
     122                 :            : const struct vm_operations_struct vb2_common_vm_ops = {
     123                 :            :         .open = vb2_common_vm_open,
     124                 :            :         .close = vb2_common_vm_close,
     125                 :            : };
     126                 :            : EXPORT_SYMBOL_GPL(vb2_common_vm_ops);
     127                 :            : 
     128                 :            : MODULE_DESCRIPTION("common memory handling routines for videobuf2");
     129                 :            : MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>");
     130                 :            : MODULE_LICENSE("GPL");

Generated by: LCOV version 1.14