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