cregit-Linux how code gets into the kernel

Release 4.7 arch/blackfin/kernel/dma-mapping.c

/*
 * Dynamic DMA mapping support
 *
 * Copyright 2005-2009 Analog Devices Inc.
 *
 * Licensed under the GPL-2 or later
 */

#include <linux/types.h>
#include <linux/gfp.h>
#include <linux/string.h>
#include <linux/spinlock.h>
#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <linux/export.h>
#include <linux/bitmap.h>


static spinlock_t dma_page_lock;

static unsigned long *dma_page;

static unsigned int dma_pages;

static unsigned long dma_base;

static unsigned long dma_size;

static unsigned int dma_initialized;


static void dma_alloc_init(unsigned long start, unsigned long end) { spin_lock_init(&dma_page_lock); dma_initialized = 0; dma_page = (unsigned long *)__get_free_page(GFP_KERNEL); memset(dma_page, 0, PAGE_SIZE); dma_base = PAGE_ALIGN(start); dma_size = PAGE_ALIGN(end) - PAGE_ALIGN(start); dma_pages = dma_size >> PAGE_SHIFT; memset((void *)dma_base, 0, DMA_UNCACHED_REGION); dma_initialized = 1; printk(KERN_INFO "%s: dma_page @ 0x%p - %d pages at 0x%08lx\n", __func__, dma_page, dma_pages, dma_base); }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu9897.03%125.00%
harvey harrisonharvey harrison10.99%125.00%
barry songbarry song10.99%125.00%
michael hennerichmichael hennerich10.99%125.00%
Total101100.00%4100.00%


static inline unsigned int get_pages(size_t size) { return ((size - 1) >> PAGE_SHIFT) + 1; }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu24100.00%1100.00%
Total24100.00%1100.00%


static unsigned long __alloc_dma_pages(unsigned int pages) { unsigned long ret = 0, flags; unsigned long start; if (dma_initialized == 0) dma_alloc_init(_ramend - DMA_UNCACHED_REGION, _ramend); spin_lock_irqsave(&dma_page_lock, flags); start = bitmap_find_next_zero_area(dma_page, dma_pages, 0, pages, 0); if (start < dma_pages) { ret = dma_base + (start << PAGE_SHIFT); bitmap_set(dma_page, start, pages); } spin_unlock_irqrestore(&dma_page_lock, flags); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu6969.70%133.33%
akinobu mitaakinobu mita2626.26%133.33%
michael hennerichmichael hennerich44.04%133.33%
Total99100.00%3100.00%


static void __free_dma_pages(unsigned long addr, unsigned int pages) { unsigned long page = (addr - dma_base) >> PAGE_SHIFT; unsigned long flags; if ((page + pages) > dma_pages) { printk(KERN_ERR "%s: freeing outside range.\n", __func__); BUG(); } spin_lock_irqsave(&dma_page_lock, flags); bitmap_clear(dma_page, page, pages); spin_unlock_irqrestore(&dma_page_lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu6988.46%125.00%
akinobu mitaakinobu mita56.41%125.00%
michael hennerichmichael hennerich33.85%125.00%
harvey harrisonharvey harrison11.28%125.00%
Total78100.00%4100.00%


static void *bfin_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs) { void *ret; ret = (void *)__alloc_dma_pages(get_pages(size)); if (ret) { memset(ret, 0, size); *dma_handle = virt_to_phys(ret); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu6490.14%150.00%
christoph hellwigchristoph hellwig79.86%150.00%
Total71100.00%2100.00%


static void bfin_dma_free(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) { __free_dma_pages((unsigned long)vaddr, get_pages(size)); }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu3382.50%150.00%
christoph hellwigchristoph hellwig717.50%150.00%
Total40100.00%2100.00%

/* * Streaming DMA mappings */
void __dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir) { __dma_sync_inline(addr, size, dir); }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu1562.50%133.33%
barry songbarry song833.33%133.33%
sonic zhangsonic zhang14.17%133.33%
Total24100.00%3100.00%

EXPORT_SYMBOL(__dma_sync);
static int bfin_dma_map_sg(struct device *dev, struct scatterlist *sg_list, int nents, enum dma_data_direction direction, struct dma_attrs *attrs) { struct scatterlist *sg; int i; for_each_sg(sg_list, sg, nents, i) { sg->dma_address = (dma_addr_t) sg_virt(sg); __dma_sync(sg_dma_address(sg), sg_dma_len(sg), direction); } return nents; }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu4051.28%228.57%
sonic zhangsonic zhang2532.05%228.57%
christoph hellwigchristoph hellwig78.97%114.29%
barry songbarry song33.85%114.29%
jens axboejens axboe33.85%114.29%
Total78100.00%7100.00%


static void bfin_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg_list, int nelems, enum dma_data_direction direction) { struct scatterlist *sg; int i; for_each_sg(sg_list, sg, nelems, i) { sg->dma_address = (dma_addr_t) sg_virt(sg); __dma_sync(sg_dma_address(sg), sg_dma_len(sg), direction); } }

Contributors

PersonTokensPropCommitsCommitProp
barry songbarry song2941.43%125.00%
bryan wubryan wu2332.86%125.00%
sonic zhangsonic zhang1622.86%125.00%
christoph hellwigchristoph hellwig22.86%125.00%
Total70100.00%4100.00%


static dma_addr_t bfin_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs) { dma_addr_t handle = (dma_addr_t)(page_address(page) + offset); _dma_sync(handle, size, dir); return handle; }

Contributors

PersonTokensPropCommitsCommitProp
christoph hellwigchristoph hellwig59100.00%1100.00%
Total59100.00%1100.00%


static inline void bfin_dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { _dma_sync(handle, size, dir); }

Contributors

PersonTokensPropCommitsCommitProp
christoph hellwigchristoph hellwig31100.00%1100.00%
Total31100.00%1100.00%

struct dma_map_ops bfin_dma_ops = { .alloc = bfin_dma_alloc, .free = bfin_dma_free, .map_page = bfin_dma_map_page, .map_sg = bfin_dma_map_sg, .sync_single_for_device = bfin_dma_sync_single_for_device, .sync_sg_for_device = bfin_dma_sync_sg_for_device, }; EXPORT_SYMBOL(bfin_dma_ops);

Overall Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu48862.81%214.29%
christoph hellwigchristoph hellwig15019.31%17.14%
barry songbarry song445.66%17.14%
sonic zhangsonic zhang425.41%321.43%
akinobu mitaakinobu mita344.38%17.14%
michael hennerichmichael hennerich91.16%17.14%
paul gortmakerpaul gortmaker30.39%17.14%
jens axboejens axboe30.39%17.14%
harvey harrisonharvey harrison20.26%17.14%
robin getzrobin getz10.13%17.14%
adrian bunkadrian bunk10.13%17.14%
Total777100.00%14100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}