xref: /openbmc/u-boot/include/dma.h (revision ae485b54)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * (C) Copyright 2015
4  *     Texas Instruments Incorporated, <www.ti.com>
5  */
6 
7 #ifndef _DMA_H_
8 #define _DMA_H_
9 
10 /*
11  * enum dma_direction - dma transfer direction indicator
12  * @DMA_MEM_TO_MEM: Memcpy mode
13  * @DMA_MEM_TO_DEV: From Memory to Device
14  * @DMA_DEV_TO_MEM: From Device to Memory
15  * @DMA_DEV_TO_DEV: From Device to Device
16  */
17 enum dma_direction {
18 	DMA_MEM_TO_MEM,
19 	DMA_MEM_TO_DEV,
20 	DMA_DEV_TO_MEM,
21 	DMA_DEV_TO_DEV,
22 };
23 
24 #define DMA_SUPPORTS_MEM_TO_MEM	BIT(0)
25 #define DMA_SUPPORTS_MEM_TO_DEV	BIT(1)
26 #define DMA_SUPPORTS_DEV_TO_MEM	BIT(2)
27 #define DMA_SUPPORTS_DEV_TO_DEV	BIT(3)
28 
29 /*
30  * struct dma_ops - Driver model DMA operations
31  *
32  * The uclass interface is implemented by all DMA devices which use
33  * driver model.
34  */
35 struct dma_ops {
36 	/*
37 	 * Get the current timer count
38 	 *
39 	 * @dev: The DMA device
40 	 * @direction: direction of data transfer should be one from
41 		       enum dma_direction
42 	 * @dst: Destination pointer
43 	 * @src: Source pointer
44 	 * @len: Length of the data to be copied.
45 	 * @return: 0 if OK, -ve on error
46 	 */
47 	int (*transfer)(struct udevice *dev, int direction, void *dst,
48 			void *src, size_t len);
49 };
50 
51 /*
52  * struct dma_dev_priv - information about a device used by the uclass
53  *
54  * @supported: mode of transfers that DMA can support, should be
55  *	       one/multiple of DMA_SUPPORTS_*
56  */
57 struct dma_dev_priv {
58 	u32 supported;
59 };
60 
61 /*
62  * dma_get_device - get a DMA device which supports transfer
63  * type of transfer_type
64  *
65  * @transfer_type - transfer type should be one/multiple of
66  *		    DMA_SUPPORTS_*
67  * @devp - udevice pointer to return the found device
68  * @return - will return on success and devp will hold the
69  *	     pointer to the device
70  */
71 int dma_get_device(u32 transfer_type, struct udevice **devp);
72 
73 /*
74  * dma_memcpy - try to use DMA to do a mem copy which will be
75  *		much faster than CPU mem copy
76  *
77  * @dst - destination pointer
78  * @src - souce pointer
79  * @len - data length to be copied
80  * @return - on successful transfer returns no of bytes
81 	     transferred and on failure return error code.
82  */
83 int dma_memcpy(void *dst, void *src, size_t len);
84 
85 #endif	/* _DMA_H_ */
86