File dmabuf.h

FileList > dmabuf > dmabuf.h

Go to the source code of this file

  • #include <linux/dma-mapping.h>
  • #include <linux/list_sort.h>
  • #include <linux/slab.h>
  • #include <linux/uaccess.h>
  • #include <linux/version.h>
  • #include "module.h"
  • #include <linux/dma-direct.h>
  • #include <linux/dma-map-ops.h>

Classes

Type Name
struct dmabuf
struct dmabuf_entry

Public Static Functions

Type Name
struct dmabuf * dmabuf_alloc (struct device * dev, size_t size)
int dmabuf_entry_cmp (void * priv, const struct list_head * a, const struct list_head * b)
void dmabuf_free (struct dmabuf * dmabuf)
loff_t dmabuf_llseek (struct dmabuf * dmabuf, struct file * file, loff_t loff, int whence)
int dmabuf_mmap (struct dmabuf * dmabuf, struct vm_area_struct * vma)
ssize_t dmabuf_read (struct dmabuf * dmabuf, char __user * user_buffer, size_t user_size, loff_t offset)
int dmabuf_report (struct dmabuf * dmabuf)
ssize_t dmabuf_write (struct dmabuf * dmabuf, const char __user * user_buffer, size_t user_size, loff_t offset)

Public Static Functions Documentation

function dmabuf_alloc

static struct dmabuf * dmabuf_alloc (
    struct device * dev,
    size_t size
) 

Allocate DMA buffer.

Use dma_alloc_coherent to allocate list of struct dmabuf_entry objects that back the requested size of the DMA buffer.

The list is sorted by dma_handle such that contiguous ranges can be combined when passing handle and size to the device.

dmabuf = kzalloc()
while(dmabuf->size < size) list_add(dma_alloc_coherent(), &dmabuf->entries)
list_sort(&dmabuf->entries, (a, b) { a->dma_handle < b->dma_handle })

Parameters:

  • dev - associated struct device pointer
  • size - required size of the buffer

Returns:

  • pointer to struct dmabuf

Return value:

  • -EINVAL - if size is 0 or not multiple of page size
  • -ENOMEM - out of memory (kzalloc or dma_alloc_coherent)

function dmabuf_entry_cmp

static int dmabuf_entry_cmp (
    void * priv,
    const struct list_head * a,
    const struct list_head * b
) 

function dmabuf_free

static void dmabuf_free (
    struct dmabuf * dmabuf
) 

function dmabuf_llseek

static loff_t dmabuf_llseek (
    struct dmabuf * dmabuf,
    struct file * file,
    loff_t loff,
    int whence
) 

function dmabuf_mmap

static int dmabuf_mmap (
    struct dmabuf * dmabuf,
    struct vm_area_struct * vma
) 

Map DMA buffer to user address space.

Use pgprot_noncached to set page protection and map each dmabuf_entry with remap_pfn_range.

vma->vm_page_prot = pgprot_dmacoherent()
for_each(entry : dmabuf->entries) remap_pfn_range(pfn(entry->dma_handle))

Parameters:

  • dmabuf - pointer to struct dmabuf
  • vma - pointer to struct vm_area_struct

Returns:

  • 0 on success

Return value:

  • -EINVAL - if out of range
  • - errors from remap_pfn_range

function dmabuf_read

static ssize_t dmabuf_read (
    struct dmabuf * dmabuf,
    char __user * user_buffer,
    size_t user_size,
    loff_t offset
) 

function dmabuf_report

static int dmabuf_report (
    struct dmabuf * dmabuf
) 

Report contiguous DMA handles.

Parameters:

  • dmabuf - pointer to struct dmabuf

Returns:

  • number of contiguous DMA handles

function dmabuf_write

static ssize_t dmabuf_write (
    struct dmabuf * dmabuf,
    const char __user * user_buffer,
    size_t user_size,
    loff_t offset
) 


The documentation for this class was generated from the following file midas_fe/mudaq-dkms/dmabuf/dmabuf.h