/*1* memory fill offload engine support2*3* Copyright © 2006, Intel Corporation.4*5* Dan Williams <[email protected]>6*7* with architecture considerations by:8* Neil Brown <[email protected]>9* Jeff Garzik <[email protected]>10*11* This program is free software; you can redistribute it and/or modify it12* under the terms and conditions of the GNU General Public License,13* version 2, as published by the Free Software Foundation.14*15* This program is distributed in the hope it will be useful, but WITHOUT16* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or17* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for18* more details.19*20* You should have received a copy of the GNU General Public License along with21* this program; if not, write to the Free Software Foundation, Inc.,22* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.23*24*/25#include <linux/kernel.h>26#include <linux/interrupt.h>27#include <linux/mm.h>28#include <linux/dma-mapping.h>29#include <linux/async_tx.h>3031/**32* async_memset - attempt to fill memory with a dma engine.33* @dest: destination page34* @val: fill value35* @offset: offset in pages to start transaction36* @len: length in bytes37*38* honored flags: ASYNC_TX_ACK39*/40struct dma_async_tx_descriptor *41async_memset(struct page *dest, int val, unsigned int offset, size_t len,42struct async_submit_ctl *submit)43{44struct dma_chan *chan = async_tx_find_channel(submit, DMA_MEMSET,45&dest, 1, NULL, 0, len);46struct dma_device *device = chan ? chan->device : NULL;47struct dma_async_tx_descriptor *tx = NULL;4849if (device && is_dma_fill_aligned(device, offset, 0, len)) {50dma_addr_t dma_dest;51unsigned long dma_prep_flags = 0;5253if (submit->cb_fn)54dma_prep_flags |= DMA_PREP_INTERRUPT;55if (submit->flags & ASYNC_TX_FENCE)56dma_prep_flags |= DMA_PREP_FENCE;57dma_dest = dma_map_page(device->dev, dest, offset, len,58DMA_FROM_DEVICE);5960tx = device->device_prep_dma_memset(chan, dma_dest, val, len,61dma_prep_flags);62}6364if (tx) {65pr_debug("%s: (async) len: %zu\n", __func__, len);66async_tx_submit(chan, tx, submit);67} else { /* run the memset synchronously */68void *dest_buf;69pr_debug("%s: (sync) len: %zu\n", __func__, len);7071dest_buf = page_address(dest) + offset;7273/* wait for any prerequisite operations */74async_tx_quiesce(&submit->depend_tx);7576memset(dest_buf, val, len);7778async_tx_sync_epilog(submit);79}8081return tx;82}83EXPORT_SYMBOL_GPL(async_memset);8485MODULE_AUTHOR("Intel Corporation");86MODULE_DESCRIPTION("asynchronous memset api");87MODULE_LICENSE("GPL");888990