Blame view

crypto/async_tx/async_memcpy.c 2.58 KB
a61127c21   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
9bc89cd82   Dan Williams   async_tx: add the...
2
3
4
5
6
7
8
9
10
11
  /*
   * copy 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>
9bc89cd82   Dan Williams   async_tx: add the...
12
13
14
   */
  #include <linux/kernel.h>
  #include <linux/highmem.h>
4bb33cc89   Paul Gortmaker   crypto: add modul...
15
  #include <linux/module.h>
9bc89cd82   Dan Williams   async_tx: add the...
16
17
18
19
20
21
22
23
  #include <linux/mm.h>
  #include <linux/dma-mapping.h>
  #include <linux/async_tx.h>
  
  /**
   * async_memcpy - attempt to copy memory with a dma engine.
   * @dest: destination page
   * @src: src page
a08abd8ca   Dan Williams   async_tx: structi...
24
25
   * @dest_offset: offset into 'dest' to start transaction
   * @src_offset: offset into 'src' to start transaction
9bc89cd82   Dan Williams   async_tx: add the...
26
   * @len: length in bytes
a08abd8ca   Dan Williams   async_tx: structi...
27
28
29
   * @submit: submission / completion modifiers
   *
   * honored flags: ASYNC_TX_ACK
9bc89cd82   Dan Williams   async_tx: add the...
30
31
32
   */
  struct dma_async_tx_descriptor *
  async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
a08abd8ca   Dan Williams   async_tx: structi...
33
34
  	     unsigned int src_offset, size_t len,
  	     struct async_submit_ctl *submit)
9bc89cd82   Dan Williams   async_tx: add the...
35
  {
a08abd8ca   Dan Williams   async_tx: structi...
36
  	struct dma_chan *chan = async_tx_find_channel(submit, DMA_MEMCPY,
47437b2c9   Dan Williams   async_tx: allow a...
37
  						      &dest, 1, &src, 1, len);
9bc89cd82   Dan Williams   async_tx: add the...
38
  	struct dma_device *device = chan ? chan->device : NULL;
0036731c8   Dan Williams   async_tx: kill tx...
39
  	struct dma_async_tx_descriptor *tx = NULL;
897164629   Dan Williams   async_memcpy: con...
40
  	struct dmaengine_unmap_data *unmap = NULL;
9bc89cd82   Dan Williams   async_tx: add the...
41

897164629   Dan Williams   async_memcpy: con...
42
  	if (device)
b02bab6b0   NeilBrown   async_tx: use GFP...
43
  		unmap = dmaengine_get_unmap_data(device->dev, 2, GFP_NOWAIT);
897164629   Dan Williams   async_memcpy: con...
44
45
  
  	if (unmap && is_dma_copy_aligned(device, src_offset, dest_offset, len)) {
0776ae7b8   Bartlomiej Zolnierkiewicz   dmaengine: remove...
46
  		unsigned long dma_prep_flags = 0;
9bc89cd82   Dan Williams   async_tx: add the...
47

0403e3827   Dan Williams   dmaengine: add fe...
48
49
50
51
  		if (submit->cb_fn)
  			dma_prep_flags |= DMA_PREP_INTERRUPT;
  		if (submit->flags & ASYNC_TX_FENCE)
  			dma_prep_flags |= DMA_PREP_FENCE;
897164629   Dan Williams   async_memcpy: con...
52
53
54
55
56
57
58
59
60
61
62
63
  
  		unmap->to_cnt = 1;
  		unmap->addr[0] = dma_map_page(device->dev, src, src_offset, len,
  					      DMA_TO_DEVICE);
  		unmap->from_cnt = 1;
  		unmap->addr[1] = dma_map_page(device->dev, dest, dest_offset, len,
  					      DMA_FROM_DEVICE);
  		unmap->len = len;
  
  		tx = device->device_prep_dma_memcpy(chan, unmap->addr[1],
  						    unmap->addr[0], len,
  						    dma_prep_flags);
0036731c8   Dan Williams   async_tx: kill tx...
64
  	}
9bc89cd82   Dan Williams   async_tx: add the...
65

0036731c8   Dan Williams   async_tx: kill tx...
66
  	if (tx) {
3280ab3e8   Dan Williams   async_tx: checkpa...
67
68
  		pr_debug("%s: (async) len: %zu
  ", __func__, len);
897164629   Dan Williams   async_memcpy: con...
69
70
  
  		dma_set_unmap(tx, unmap);
a08abd8ca   Dan Williams   async_tx: structi...
71
  		async_tx_submit(chan, tx, submit);
0036731c8   Dan Williams   async_tx: kill tx...
72
  	} else {
9bc89cd82   Dan Williams   async_tx: add the...
73
  		void *dest_buf, *src_buf;
3280ab3e8   Dan Williams   async_tx: checkpa...
74
75
  		pr_debug("%s: (sync) len: %zu
  ", __func__, len);
9bc89cd82   Dan Williams   async_tx: add the...
76
77
  
  		/* wait for any prerequisite operations */
a08abd8ca   Dan Williams   async_tx: structi...
78
  		async_tx_quiesce(&submit->depend_tx);
9bc89cd82   Dan Williams   async_tx: add the...
79

f0dfc0b0b   Cong Wang   crypto: remove th...
80
81
  		dest_buf = kmap_atomic(dest) + dest_offset;
  		src_buf = kmap_atomic(src) + src_offset;
9bc89cd82   Dan Williams   async_tx: add the...
82
83
  
  		memcpy(dest_buf, src_buf, len);
f0dfc0b0b   Cong Wang   crypto: remove th...
84
85
  		kunmap_atomic(src_buf);
  		kunmap_atomic(dest_buf);
9bc89cd82   Dan Williams   async_tx: add the...
86

a08abd8ca   Dan Williams   async_tx: structi...
87
  		async_tx_sync_epilog(submit);
9bc89cd82   Dan Williams   async_tx: add the...
88
  	}
897164629   Dan Williams   async_memcpy: con...
89
  	dmaengine_unmap_put(unmap);
9bc89cd82   Dan Williams   async_tx: add the...
90
91
92
  	return tx;
  }
  EXPORT_SYMBOL_GPL(async_memcpy);
9bc89cd82   Dan Williams   async_tx: add the...
93
94
95
  MODULE_AUTHOR("Intel Corporation");
  MODULE_DESCRIPTION("asynchronous memcpy api");
  MODULE_LICENSE("GPL");