async_memset.c 2.6 KB
Newer Older
D
Dan Williams 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * memory fill offload engine support
 *
 * Copyright © 2006, Intel Corporation.
 *
 *      Dan Williams <dan.j.williams@intel.com>
 *
 *      with architecture considerations by:
 *      Neil Brown <neilb@suse.de>
 *      Jeff Garzik <jeff@garzik.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
#include <linux/kernel.h>
#include <linux/interrupt.h>
28
#include <linux/module.h>
D
Dan Williams 已提交
29 30 31 32 33 34 35 36 37 38
#include <linux/mm.h>
#include <linux/dma-mapping.h>
#include <linux/async_tx.h>

/**
 * async_memset - attempt to fill memory with a dma engine.
 * @dest: destination page
 * @val: fill value
 * @offset: offset in pages to start transaction
 * @len: length in bytes
39 40
 *
 * honored flags: ASYNC_TX_ACK
D
Dan Williams 已提交
41 42
 */
struct dma_async_tx_descriptor *
43 44
async_memset(struct page *dest, int val, unsigned int offset, size_t len,
	     struct async_submit_ctl *submit)
D
Dan Williams 已提交
45
{
46
	struct dma_chan *chan = async_tx_find_channel(submit, DMA_MEMSET,
47
						      &dest, 1, NULL, 0, len);
D
Dan Williams 已提交
48
	struct dma_device *device = chan ? chan->device : NULL;
49
	struct dma_async_tx_descriptor *tx = NULL;
D
Dan Williams 已提交
50

51
	if (device && is_dma_fill_aligned(device, offset, 0, len)) {
52
		dma_addr_t dma_dest;
D
Dan Williams 已提交
53
		unsigned long dma_prep_flags = 0;
D
Dan Williams 已提交
54

D
Dan Williams 已提交
55 56 57 58
		if (submit->cb_fn)
			dma_prep_flags |= DMA_PREP_INTERRUPT;
		if (submit->flags & ASYNC_TX_FENCE)
			dma_prep_flags |= DMA_PREP_FENCE;
59
		dma_dest = dma_map_page(device->dev, dest, offset, len,
60
					DMA_FROM_DEVICE);
D
Dan Williams 已提交
61

62
		tx = device->device_prep_dma_memset(chan, dma_dest, val, len,
63
						    dma_prep_flags);
64 65 66
	}

	if (tx) {
67
		pr_debug("%s: (async) len: %zu\n", __func__, len);
68
		async_tx_submit(chan, tx, submit);
D
Dan Williams 已提交
69 70
	} else { /* run the memset synchronously */
		void *dest_buf;
71
		pr_debug("%s: (sync) len: %zu\n", __func__, len);
D
Dan Williams 已提交
72

73
		dest_buf = page_address(dest) + offset;
D
Dan Williams 已提交
74 75

		/* wait for any prerequisite operations */
76
		async_tx_quiesce(&submit->depend_tx);
D
Dan Williams 已提交
77 78 79

		memset(dest_buf, val, len);

80
		async_tx_sync_epilog(submit);
D
Dan Williams 已提交
81 82 83 84 85 86 87 88 89
	}

	return tx;
}
EXPORT_SYMBOL_GPL(async_memset);

MODULE_AUTHOR("Intel Corporation");
MODULE_DESCRIPTION("asynchronous memset api");
MODULE_LICENSE("GPL");