1 /*
2  * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*
8  * @file	dma.h
9  * @brief	DMA primitives for libmetal.
10  */
11 
12 #ifndef __METAL_DMA__H__
13 #define __METAL_DMA__H__
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /** \defgroup dma DMA Interfaces
20  *  @{ */
21 
22 #include <stdint.h>
23 #include <metal/sys.h>
24 
25 #define METAL_DMA_DEV_R  1 /**< DMA direction, device read */
26 #define METAL_DMA_DEV_W  2 /**< DMA direction, device write */
27 #define METAL_DMA_DEV_WR 3 /**< DMA direction, device read/write */
28 
29 /**
30  * @brief scatter/gather list element structure
31  */
32 struct metal_sg {
33 	void *virt; /**< CPU virtual address */
34 	struct metal_io_region *io; /**< IO region */
35 	int len; /**< length */
36 };
37 
38 struct metal_device;
39 
40 /**
41  * @brief      Map memory for DMA transaction.
42  *             After the memory is DMA mapped, the memory should be
43  *             accessed by the DMA device but not the CPU.
44  *
45  * @param[in]  dev       DMA device
46  * @param[in]  dir       DMA direction
47  * @param[in]  sg_in     sg list of memory to map
48  * @param[in]  nents_in  number of sg list entries of memory to map
49  * @param[out] sg_out    sg list of mapped memory
50  * @return     number of mapped sg entries, -error on failure.
51  */
52 int metal_dma_map(struct metal_device *dev,
53 		  uint32_t dir,
54 		  struct metal_sg *sg_in,
55 		  int nents_in,
56 		  struct metal_sg *sg_out);
57 
58 /**
59  * @brief      Unmap DMA memory
60  *             After the memory is DMA unmapped, the memory should
61  *             be accessed by the CPU but not the DMA device.
62  *
63  * @param[in]  dev       DMA device
64  * @param[in]  dir       DMA direction
65  * @param[in]  sg        sg list of mapped DMA memory
66  * @param[in]  nents     number of sg list entries of DMA memory
67  */
68 void metal_dma_unmap(struct metal_device *dev,
69 		  uint32_t dir,
70 		  struct metal_sg *sg,
71 		  int nents);
72 
73 /** @} */
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* __METAL_DMA__H__ */
80