1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef QCOM_HIDMA_H
17#define QCOM_HIDMA_H
18
19#include <linux/kfifo.h>
20#include <linux/interrupt.h>
21#include <linux/dmaengine.h>
22
23#define TRE_SIZE 32
24#define TRE_CFG_IDX 0
25#define TRE_LEN_IDX 1
26#define TRE_SRC_LOW_IDX 2
27#define TRE_SRC_HI_IDX 3
28#define TRE_DEST_LOW_IDX 4
29#define TRE_DEST_HI_IDX 5
30
31struct hidma_tx_status {
32 u8 err_info;
33 u8 err_code;
34};
35
36struct hidma_tre {
37 atomic_t allocated;
38 bool queued;
39 u16 status;
40 u32 chidx;
41 u32 dma_sig;
42 const char *dev_name;
43 void (*callback)(void *data);
44 void *data;
45 struct hidma_lldev *lldev;
46 u32 tre_local[TRE_SIZE / sizeof(u32) + 1];
47 u32 tre_index;
48 u32 int_flags;
49};
50
51struct hidma_lldev {
52 bool initialized;
53 u8 trch_state;
54 u8 evch_state;
55 u8 chidx;
56 u32 nr_tres;
57 spinlock_t lock;
58 struct hidma_tre *trepool;
59 struct device *dev;
60 void __iomem *trca;
61 void __iomem *evca;
62 struct hidma_tre
63 **pending_tre_list;
64 struct hidma_tx_status
65 *tx_status_list;
66 s32 pending_tre_count;
67
68 void *tre_ring;
69 dma_addr_t tre_ring_handle;
70 u32 tre_ring_size;
71 u32 tre_processed_off;
72
73 void *evre_ring;
74 dma_addr_t evre_ring_handle;
75 u32 evre_ring_size;
76 u32 evre_processed_off;
77
78 u32 tre_write_offset;
79 struct tasklet_struct task;
80 DECLARE_KFIFO_PTR(handoff_fifo,
81 struct hidma_tre *);
82};
83
84struct hidma_desc {
85 struct dma_async_tx_descriptor desc;
86
87 struct list_head node;
88 u32 tre_ch;
89};
90
91struct hidma_chan {
92 bool paused;
93 bool allocated;
94 char dbg_name[16];
95 u32 dma_sig;
96
97
98
99
100
101
102 struct dentry *debugfs;
103 struct dentry *stats;
104 struct hidma_dev *dmadev;
105 struct hidma_desc *running;
106
107 struct dma_chan chan;
108 struct list_head free;
109 struct list_head prepared;
110 struct list_head active;
111 struct list_head completed;
112
113
114 spinlock_t lock;
115};
116
117struct hidma_dev {
118 int irq;
119 int chidx;
120 u32 nr_descriptors;
121
122 struct hidma_lldev *lldev;
123 void __iomem *dev_trca;
124 struct resource *trca_resource;
125 void __iomem *dev_evca;
126 struct resource *evca_resource;
127
128
129 spinlock_t lock;
130 struct dma_device ddev;
131
132 struct dentry *debugfs;
133 struct dentry *stats;
134
135
136 struct tasklet_struct task;
137};
138
139int hidma_ll_request(struct hidma_lldev *llhndl, u32 dev_id,
140 const char *dev_name,
141 void (*callback)(void *data), void *data, u32 *tre_ch);
142
143void hidma_ll_free(struct hidma_lldev *llhndl, u32 tre_ch);
144enum dma_status hidma_ll_status(struct hidma_lldev *llhndl, u32 tre_ch);
145bool hidma_ll_isenabled(struct hidma_lldev *llhndl);
146void hidma_ll_queue_request(struct hidma_lldev *llhndl, u32 tre_ch);
147void hidma_ll_start(struct hidma_lldev *llhndl);
148int hidma_ll_pause(struct hidma_lldev *llhndl);
149int hidma_ll_resume(struct hidma_lldev *llhndl);
150void hidma_ll_set_transfer_params(struct hidma_lldev *llhndl, u32 tre_ch,
151 dma_addr_t src, dma_addr_t dest, u32 len, u32 flags);
152int hidma_ll_setup(struct hidma_lldev *lldev);
153struct hidma_lldev *hidma_ll_init(struct device *dev, u32 max_channels,
154 void __iomem *trca, void __iomem *evca,
155 u8 chidx);
156int hidma_ll_uninit(struct hidma_lldev *llhndl);
157irqreturn_t hidma_ll_inthandler(int irq, void *arg);
158void hidma_cleanup_pending_tre(struct hidma_lldev *llhndl, u8 err_info,
159 u8 err_code);
160#endif
161