cregit-Linux how code gets into the kernel

Release 4.11 drivers/base/dma-mapping.c

Directory: drivers/base
/*
 * drivers/base/dma-mapping.c - arch-independent dma-mapping routines
 *
 * Copyright (c) 2006  SUSE Linux Products GmbH
 * Copyright (c) 2006  Tejun Heo <teheo@suse.de>
 *
 * This file is released under the GPLv2.
 */

#include <linux/dma-mapping.h>
#include <linux/export.h>
#include <linux/gfp.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>

/*
 * Managed DMA API
 */

struct dma_devres {
	
size_t		size;
	
void		*vaddr;
	
dma_addr_t	dma_handle;
};


static void dmam_coherent_release(struct device *dev, void *res) { struct dma_devres *this = res; dma_free_coherent(dev, this->size, this->vaddr, this->dma_handle); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo39100.00%1100.00%
Total39100.00%1100.00%


static void dmam_noncoherent_release(struct device *dev, void *res) { struct dma_devres *this = res; dma_free_noncoherent(dev, this->size, this->vaddr, this->dma_handle); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo39100.00%1100.00%
Total39100.00%1100.00%


static int dmam_match(struct device *dev, void *res, void *match_data) { struct dma_devres *this = res, *match = match_data; if (this->vaddr == match->vaddr) { WARN_ON(this->size != match->size || this->dma_handle != match->dma_handle); return 1; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo68100.00%1100.00%
Total68100.00%1100.00%

/** * dmam_alloc_coherent - Managed dma_alloc_coherent() * @dev: Device to allocate coherent memory for * @size: Size of allocation * @dma_handle: Out argument for allocated DMA handle * @gfp: Allocation flags * * Managed dma_alloc_coherent(). Memory allocated using this function * will be automatically released on driver detach. * * RETURNS: * Pointer to allocated memory on success, NULL on failure. */
void *dmam_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp) { struct dma_devres *dr; void *vaddr; dr = devres_alloc(dmam_coherent_release, sizeof(*dr), gfp); if (!dr) return NULL; vaddr = dma_alloc_coherent(dev, size, dma_handle, gfp); if (!vaddr) { devres_free(dr); return NULL; } dr->vaddr = vaddr; dr->dma_handle = *dma_handle; dr->size = size; devres_add(dev, dr); return vaddr; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo110100.00%1100.00%
Total110100.00%1100.00%

EXPORT_SYMBOL(dmam_alloc_coherent); /** * dmam_free_coherent - Managed dma_free_coherent() * @dev: Device to free coherent memory for * @size: Size of allocation * @vaddr: Virtual address of the memory to free * @dma_handle: DMA handle of the memory to free * * Managed dma_free_coherent(). */
void dmam_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle) { struct dma_devres match_data = { size, vaddr, dma_handle }; dma_free_coherent(dev, size, vaddr, dma_handle); WARN_ON(devres_destroy(dev, dmam_coherent_release, dmam_match, &match_data)); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo58100.00%1100.00%
Total58100.00%1100.00%

EXPORT_SYMBOL(dmam_free_coherent); /** * dmam_alloc_non_coherent - Managed dma_alloc_noncoherent() * @dev: Device to allocate non_coherent memory for * @size: Size of allocation * @dma_handle: Out argument for allocated DMA handle * @gfp: Allocation flags * * Managed dma_alloc_noncoherent(). Memory allocated using this * function will be automatically released on driver detach. * * RETURNS: * Pointer to allocated memory on success, NULL on failure. */
void *dmam_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp) { struct dma_devres *dr; void *vaddr; dr = devres_alloc(dmam_noncoherent_release, sizeof(*dr), gfp); if (!dr) return NULL; vaddr = dma_alloc_noncoherent(dev, size, dma_handle, gfp); if (!vaddr) { devres_free(dr); return NULL; } dr->vaddr = vaddr; dr->dma_handle = *dma_handle; dr->size = size; devres_add(dev, dr); return vaddr; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo110100.00%1100.00%
Total110100.00%1100.00%

EXPORT_SYMBOL(dmam_alloc_noncoherent); /** * dmam_free_coherent - Managed dma_free_noncoherent() * @dev: Device to free noncoherent memory for * @size: Size of allocation * @vaddr: Virtual address of the memory to free * @dma_handle: DMA handle of the memory to free * * Managed dma_free_noncoherent(). */
void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle) { struct dma_devres match_data = { size, vaddr, dma_handle }; dma_free_noncoherent(dev, size, vaddr, dma_handle); WARN_ON(!devres_destroy(dev, dmam_noncoherent_release, dmam_match, &match_data)); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo59100.00%1100.00%
Total59100.00%1100.00%

EXPORT_SYMBOL(dmam_free_noncoherent); #ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
static void dmam_coherent_decl_release(struct device *dev, void *res) { dma_release_declared_memory(dev); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo20100.00%1100.00%
Total20100.00%1100.00%

/** * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory() * @dev: Device to declare coherent memory for * @phys_addr: Physical address of coherent memory to be declared * @device_addr: Device address of coherent memory to be declared * @size: Size of coherent memory to be declared * @flags: Flags * * Managed dma_declare_coherent_memory(). * * RETURNS: * 0 on success, -errno on failure. */
int dmam_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, dma_addr_t device_addr, size_t size, int flags) { void *res; int rc; res = devres_alloc(dmam_coherent_decl_release, 0, GFP_KERNEL); if (!res) return -ENOMEM; rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size, flags); if (rc) { devres_add(dev, res); rc = 0; } else { devres_free(res); rc = -ENOMEM; } return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo8183.51%133.33%
Vyacheslav V. Yurkov1313.40%133.33%
Björn Helgaas33.09%133.33%
Total97100.00%3100.00%

EXPORT_SYMBOL(dmam_declare_coherent_memory); /** * dmam_release_declared_memory - Managed dma_release_declared_memory(). * @dev: Device to release declared coherent memory for * * Managed dmam_release_declared_memory(). */
void dmam_release_declared_memory(struct device *dev) { WARN_ON(devres_destroy(dev, dmam_coherent_decl_release, NULL, NULL)); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo24100.00%1100.00%
Total24100.00%1100.00%

EXPORT_SYMBOL(dmam_release_declared_memory); #endif /* * Create scatter-list for the already allocated DMA buffer. */
int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr, dma_addr_t handle, size_t size) { struct page *page = virt_to_page(cpu_addr); int ret; ret = sg_alloc_table(sgt, 1, GFP_KERNEL); if (unlikely(ret)) return ret; sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Marek Szyprowski78100.00%1100.00%
Total78100.00%1100.00%

EXPORT_SYMBOL(dma_common_get_sgtable); /* * Create userspace mapping for the DMA-coherent memory. */
int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size) { int ret = -ENXIO; #if defined(CONFIG_MMU) && !defined(CONFIG_ARCH_NO_COHERENT_DMA_MMAP) unsigned long user_count = vma_pages(vma); unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; unsigned long pfn = page_to_pfn(virt_to_page(cpu_addr)); unsigned long off = vma->vm_pgoff; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) return ret; if (off < count && user_count <= (count - off)) { ret = remap_pfn_range(vma, vma->vm_start, pfn + off, user_count << PAGE_SHIFT, vma->vm_page_prot); } #endif /* CONFIG_MMU && !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */ return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Marek Szyprowski14390.51%133.33%
Christoph Hellwig127.59%133.33%
Muhammad Falak R Wani31.90%133.33%
Total158100.00%3100.00%

EXPORT_SYMBOL(dma_common_mmap); #ifdef CONFIG_MMU /* * remaps an array of PAGE_SIZE pages into another vm_area * Cannot be used in non-sleeping contexts */
void *dma_common_pages_remap(struct page **pages, size_t size, unsigned long vm_flags, pgprot_t prot, const void *caller) { struct vm_struct *area; area = get_vm_area_caller(size, vm_flags, caller); if (!area) return NULL; area->pages = pages; if (map_vm_area(area, prot, pages)) { vunmap(area->addr); return NULL; } return area->addr; }

Contributors

PersonTokensPropCommitsCommitProp
Laura Abbott85100.00%1100.00%
Total85100.00%1100.00%

/* * remaps an allocated contiguous region into another vm_area. * Cannot be used in non-sleeping contexts */
void *dma_common_contiguous_remap(struct page *page, size_t size, unsigned long vm_flags, pgprot_t prot, const void *caller) { int i; struct page **pages; void *ptr; unsigned long pfn; pages = kmalloc(sizeof(struct page *) << get_order(size), GFP_KERNEL); if (!pages) return NULL; for (i = 0, pfn = page_to_pfn(page); i < (size >> PAGE_SHIFT); i++) pages[i] = pfn_to_page(pfn + i); ptr = dma_common_pages_remap(pages, size, vm_flags, prot, caller); kfree(pages); return ptr; }

Contributors

PersonTokensPropCommitsCommitProp
Laura Abbott129100.00%1100.00%
Total129100.00%1100.00%

/* * unmaps a range previously mapped by dma_common_*_remap */
void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags) { struct vm_struct *area = find_vm_area(cpu_addr); if (!area || (area->flags & vm_flags) != vm_flags) { WARN(1, "trying to free invalid coherent area: %p\n", cpu_addr); return; } unmap_kernel_range((unsigned long)cpu_addr, PAGE_ALIGN(size)); vunmap(cpu_addr); }

Contributors

PersonTokensPropCommitsCommitProp
Laura Abbott6995.83%150.00%
Peng Fan34.17%150.00%
Total72100.00%2100.00%

#endif

Overall Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo66753.83%214.29%
Laura Abbott29523.81%17.14%
Marek Szyprowski23719.13%321.43%
Vyacheslav V. Yurkov131.05%17.14%
Christoph Hellwig131.05%214.29%
Björn Helgaas40.32%17.14%
Peng Fan30.24%17.14%
Paul Gortmaker30.24%17.14%
Muhammad Falak R Wani30.24%17.14%
Florian Fainelli10.08%17.14%
Total1239100.00%14100.00%
Directory: drivers/base
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.