• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Android coprocessor DMA library
3  *
4  * Copyright 2018 Google Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 #ifndef __ABC_PCIE_DMA_H
11 #define __ABC_PCIE_DMA_H
12 
13 
14 #include <linux/ioctl.h>
15 #include <linux/types.h>
16 
17 #define ABC_PCIE_DMA_IOC_MAGIC 'U'
18 
19 enum dma_buf_type {
20 	DMA_BUFFER_USER = 0,
21 	DMA_BUFFER_DMA_BUF
22 };
23 
24 /* abc_dma_data_direction must match values in <linux/dma-direction.h> */
25 enum abc_dma_data_direction {
26 	ABC_DMA_TO_DEVICE = 1,
27 	ABC_DMA_FROM_DEVICE = 2,
28 };
29 
30 struct abc_pcie_dma_desc_legacy {
31 	enum dma_buf_type local_buf_type; /* local buffer type (DMA/user) */
32 	union {
33 		void *local_buf; /* local buffer address */
34 		int local_dma_buf_fd; /* local DMA buffer file descriptor */
35 	};
36 	__u32 local_buf_size; /* local buffer size */
37 
38 	/* TODO(alexperez):  Remove support for specifying an arbitrary AB
39 	 * physical address once bringup is done. b/113105230
40 	 *
41 	 * local buffer type (DMA/AB physical)
42 	 */
43 	enum dma_buf_type remote_buf_type;
44 	union {
45 		__u64 remote_buf; /* remote buffer address */
46 		int remote_dma_buf_fd; /* remote DMA buffer file descriptor */
47 	};
48 	enum abc_dma_data_direction dir; /* direction of the DMA transfer */
49 	__u8 chan; /* dma channel to be used */
50 };
51 
52 struct abc_pcie_dma_desc {
53 	enum dma_buf_type local_buf_type; /* local buffer type (DMA/user) */
54 	union {
55 		void *local_buf; /* local buffer address */
56 		int local_dma_buf_fd; /* local DMA buffer file descriptor */
57 	};
58 	__u64 local_dma_buf_off; /* offset within dma buf to xfer from/to */
59 
60 	enum dma_buf_type remote_buf_type;
61 	union {
62 		__u64 remote_buf; /* remote buffer virtual address */
63 		int remote_dma_buf_fd; /* remote DMA buffer file descriptor */
64 	};
65 	__u64 remote_dma_buf_off; /* offset within dma buf to xfer from/to */
66 
67 	__u64 size; /* number of bytes to transfer */
68 	enum abc_dma_data_direction dir; /* direction of the DMA transfer */
69 };
70 
71 struct abc_pcie_dma_desc_async {
72 	struct abc_pcie_dma_desc dma_desc;
73 	__u64 id; /* Transaction id after returning from create ioctl */
74 };
75 
76 struct abc_pcie_dma_desc_start {
77 	__u64 id;
78 	__u32 start_id; /* ID of start if multiply re-started (out) */
79 };
80 
81 struct abc_pcie_dma_desc_wait {
82 	__u64 id;
83 	int timeout; /* In usecs, 0:zero wait, < 0: infinite */
84 	int error; /* Error code if transfer state is error (out) */
85 	__u32 start_id; /* ID of start if multiply re-started (out) */
86 };
87 
88 #define ABC_PCIE_DMA_IOC_POST_DMA_XFER_LEGACY				\
89 	_IOW(ABC_PCIE_DMA_IOC_MAGIC, 1, struct abc_pcie_dma_desc_legacy *)
90 
91 #define ABC_PCIE_DMA_IOC_POST_DMA_XFER_SYNC				\
92 	_IOW(ABC_PCIE_DMA_IOC_MAGIC, 2, struct abc_pcie_dma_desc)
93 
94 #define ABC_PCIE_DMA_IOC_POST_DMA_XFER_CREATE				\
95 	_IOWR(ABC_PCIE_DMA_IOC_MAGIC, 3, struct abc_pcie_dma_desc_async)
96 
97 #define ABC_PCIE_DMA_IOC_POST_DMA_XFER_START				\
98 	_IOWR(ABC_PCIE_DMA_IOC_MAGIC, 4, struct abc_pcie_dma_desc_start)
99 
100 #define ABC_PCIE_DMA_IOC_POST_DMA_XFER_WAIT				\
101 	_IOWR(ABC_PCIE_DMA_IOC_MAGIC, 5, struct abc_pcie_dma_desc_wait)
102 
103 #define ABC_PCIE_DMA_IOC_POST_DMA_XFER_CLEAN				\
104 	_IOW(ABC_PCIE_DMA_IOC_MAGIC, 6, __u64)
105 
106 
107 #endif /* __ABC_PCIE_DMA_H */
108