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