]> Git Repo - linux.git/commitdiff
Merge tag 'tag-for-linus-3.5' of git://git.linaro.org/people/sumitsemwal/linux-dma-buf
authorLinus Torvalds <[email protected]>
Fri, 25 May 2012 16:37:26 +0000 (09:37 -0700)
committerLinus Torvalds <[email protected]>
Fri, 25 May 2012 16:37:26 +0000 (09:37 -0700)
Pull dma-buf updates from Sumit Semwal:
 "Here's the first signed-tag pull request for dma-buf framework.  It
  includes the following key items:
   - mmap support
   - vmap support
   - related documentation updates

  These are needed by various drivers to allow mmap/vmap of dma-buf
  shared buffers.  Dave Airlie has some prime patches dependent on the
  vmap pull as well."

* tag 'tag-for-linus-3.5' of git://git.linaro.org/people/sumitsemwal/linux-dma-buf:
  dma-buf: add initial vmap documentation
  dma-buf: minor documentation fixes.
  dma-buf: add vmap interface
  dma-buf: mmap support

1  2 
drivers/base/dma-buf.c

diff --combined drivers/base/dma-buf.c
index 05c64c11bad20b0bad58d6a2985b7a4258bb74c1,20258e179211c667eb8152d715dec9a11d5bed89..24e88fe29ec19801f627e55b7b454fbbe8268181
@@@ -44,8 -44,26 +44,26 @@@ static int dma_buf_release(struct inod
        return 0;
  }
  
+ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
+ {
+       struct dma_buf *dmabuf;
+       if (!is_dma_buf_file(file))
+               return -EINVAL;
+       dmabuf = file->private_data;
+       /* check for overflowing the buffer's size */
+       if (vma->vm_pgoff + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) >
+           dmabuf->size >> PAGE_SHIFT)
+               return -EINVAL;
+       return dmabuf->ops->mmap(dmabuf, vma);
+ }
  static const struct file_operations dma_buf_fops = {
        .release        = dma_buf_release,
+       .mmap           = dma_buf_mmap_internal,
  };
  
  /*
@@@ -82,7 -100,8 +100,8 @@@ struct dma_buf *dma_buf_export(void *pr
                          || !ops->unmap_dma_buf
                          || !ops->release
                          || !ops->kmap_atomic
-                         || !ops->kmap)) {
+                         || !ops->kmap
+                         || !ops->mmap)) {
                return ERR_PTR(-EINVAL);
        }
  
@@@ -293,7 -312,7 +312,7 @@@ EXPORT_SYMBOL_GPL(dma_buf_unmap_attachm
   * cpu in the kernel context. Calls begin_cpu_access to allow exporter-specific
   * preparations. Coherency is only guaranteed in the specified range for the
   * specified access direction.
 - * @dma_buf:  [in]    buffer to prepare cpu access for.
 + * @dmabuf:   [in]    buffer to prepare cpu access for.
   * @start:    [in]    start of range for cpu access.
   * @len:      [in]    length of range for cpu access.
   * @direction:        [in]    length of range for cpu access.
@@@ -320,7 -339,7 +339,7 @@@ EXPORT_SYMBOL_GPL(dma_buf_begin_cpu_acc
   * cpu in the kernel context. Calls end_cpu_access to allow exporter-specific
   * actions. Coherency is only guaranteed in the specified range for the
   * specified access direction.
 - * @dma_buf:  [in]    buffer to complete cpu access for.
 + * @dmabuf:   [in]    buffer to complete cpu access for.
   * @start:    [in]    start of range for cpu access.
   * @len:      [in]    length of range for cpu access.
   * @direction:        [in]    length of range for cpu access.
@@@ -340,7 -359,7 +359,7 @@@ EXPORT_SYMBOL_GPL(dma_buf_end_cpu_acces
  /**
   * dma_buf_kmap_atomic - Map a page of the buffer object into kernel address
   * space. The same restrictions as for kmap_atomic and friends apply.
 - * @dma_buf:  [in]    buffer to map page from.
 + * @dmabuf:   [in]    buffer to map page from.
   * @page_num: [in]    page in PAGE_SIZE units to map.
   *
   * This call must always succeed, any necessary preparations that might fail
@@@ -356,7 -375,7 +375,7 @@@ EXPORT_SYMBOL_GPL(dma_buf_kmap_atomic)
  
  /**
   * dma_buf_kunmap_atomic - Unmap a page obtained by dma_buf_kmap_atomic.
 - * @dma_buf:  [in]    buffer to unmap page from.
 + * @dmabuf:   [in]    buffer to unmap page from.
   * @page_num: [in]    page in PAGE_SIZE units to unmap.
   * @vaddr:    [in]    kernel space pointer obtained from dma_buf_kmap_atomic.
   *
@@@ -375,7 -394,7 +394,7 @@@ EXPORT_SYMBOL_GPL(dma_buf_kunmap_atomic
  /**
   * dma_buf_kmap - Map a page of the buffer object into kernel address space. The
   * same restrictions as for kmap and friends apply.
 - * @dma_buf:  [in]    buffer to map page from.
 + * @dmabuf:   [in]    buffer to map page from.
   * @page_num: [in]    page in PAGE_SIZE units to map.
   *
   * This call must always succeed, any necessary preparations that might fail
@@@ -391,7 -410,7 +410,7 @@@ EXPORT_SYMBOL_GPL(dma_buf_kmap)
  
  /**
   * dma_buf_kunmap - Unmap a page obtained by dma_buf_kmap.
 - * @dma_buf:  [in]    buffer to unmap page from.
 + * @dmabuf:   [in]    buffer to unmap page from.
   * @page_num: [in]    page in PAGE_SIZE units to unmap.
   * @vaddr:    [in]    kernel space pointer obtained from dma_buf_kmap.
   *
@@@ -406,3 -425,81 +425,81 @@@ void dma_buf_kunmap(struct dma_buf *dma
                dmabuf->ops->kunmap(dmabuf, page_num, vaddr);
  }
  EXPORT_SYMBOL_GPL(dma_buf_kunmap);
+ /**
+  * dma_buf_mmap - Setup up a userspace mmap with the given vma
+  * @dmabuf:   [in]    buffer that should back the vma
+  * @vma:      [in]    vma for the mmap
+  * @pgoff:    [in]    offset in pages where this mmap should start within the
+  *                    dma-buf buffer.
+  *
+  * This function adjusts the passed in vma so that it points at the file of the
+  * dma_buf operation. It alsog adjusts the starting pgoff and does bounds
+  * checking on the size of the vma. Then it calls the exporters mmap function to
+  * set up the mapping.
+  *
+  * Can return negative error values, returns 0 on success.
+  */
+ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
+                unsigned long pgoff)
+ {
+       if (WARN_ON(!dmabuf || !vma))
+               return -EINVAL;
+       /* check for offset overflow */
+       if (pgoff + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) < pgoff)
+               return -EOVERFLOW;
+       /* check for overflowing the buffer's size */
+       if (pgoff + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) >
+           dmabuf->size >> PAGE_SHIFT)
+               return -EINVAL;
+       /* readjust the vma */
+       if (vma->vm_file)
+               fput(vma->vm_file);
+       vma->vm_file = dmabuf->file;
+       get_file(vma->vm_file);
+       vma->vm_pgoff = pgoff;
+       return dmabuf->ops->mmap(dmabuf, vma);
+ }
+ EXPORT_SYMBOL_GPL(dma_buf_mmap);
+ /**
+  * dma_buf_vmap - Create virtual mapping for the buffer object into kernel
+  * address space. Same restrictions as for vmap and friends apply.
+  * @dmabuf:   [in]    buffer to vmap
+  *
+  * This call may fail due to lack of virtual mapping address space.
+  * These calls are optional in drivers. The intended use for them
+  * is for mapping objects linear in kernel space for high use objects.
+  * Please attempt to use kmap/kunmap before thinking about these interfaces.
+  */
+ void *dma_buf_vmap(struct dma_buf *dmabuf)
+ {
+       if (WARN_ON(!dmabuf))
+               return NULL;
+       if (dmabuf->ops->vmap)
+               return dmabuf->ops->vmap(dmabuf);
+       return NULL;
+ }
+ EXPORT_SYMBOL_GPL(dma_buf_vmap);
+ /**
+  * dma_buf_vunmap - Unmap a vmap obtained by dma_buf_vmap.
+  * @dmabuf:   [in]    buffer to vunmap
+  */
+ void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr)
+ {
+       if (WARN_ON(!dmabuf))
+               return;
+       if (dmabuf->ops->vunmap)
+               dmabuf->ops->vunmap(dmabuf, vaddr);
+ }
+ EXPORT_SYMBOL_GPL(dma_buf_vunmap);
This page took 0.066617 seconds and 4 git commands to generate.