1
2
3
4
5
6
7
8
9
10#ifndef VIRT_DMA_H
11#define VIRT_DMA_H
12
13#include <linux/dmaengine.h>
14#include <linux/interrupt.h>
15
16#include "dmaengine.h"
17
18struct virt_dma_desc {
19 struct dma_async_tx_descriptor tx;
20
21 struct list_head node;
22};
23
24struct virt_dma_chan {
25 struct dma_chan chan;
26 struct tasklet_struct task;
27 void (*desc_free)(struct virt_dma_desc *);
28
29 spinlock_t lock;
30
31
32 struct list_head desc_submitted;
33 struct list_head desc_issued;
34 struct list_head desc_completed;
35
36 struct virt_dma_desc *cyclic;
37};
38
39static inline struct virt_dma_chan *to_virt_chan(struct dma_chan *chan)
40{
41 return container_of(chan, struct virt_dma_chan, chan);
42}
43
44void vchan_dma_desc_free_list(struct virt_dma_chan *vc, struct list_head *head);
45void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev);
46struct virt_dma_desc *vchan_find_desc(struct virt_dma_chan *, dma_cookie_t);
47
48
49
50
51
52
53
54static inline struct dma_async_tx_descriptor *vchan_tx_prep(struct virt_dma_chan *vc,
55 struct virt_dma_desc *vd, unsigned long tx_flags)
56{
57 extern dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *);
58
59 dma_async_tx_descriptor_init(&vd->tx, &vc->chan);
60 vd->tx.flags = tx_flags;
61 vd->tx.tx_submit = vchan_tx_submit;
62
63 return &vd->tx;
64}
65
66
67
68
69
70
71
72static inline bool vchan_issue_pending(struct virt_dma_chan *vc)
73{
74 list_splice_tail_init(&vc->desc_submitted, &vc->desc_issued);
75 return !list_empty(&vc->desc_issued);
76}
77
78
79
80
81
82
83
84static inline void vchan_cookie_complete(struct virt_dma_desc *vd)
85{
86 struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
87
88 dma_cookie_complete(&vd->tx);
89 dev_vdbg(vc->chan.device->dev, "txd %p[%x]: marked complete\n",
90 vd, vd->tx.cookie);
91 list_add_tail(&vd->node, &vc->desc_completed);
92
93 tasklet_schedule(&vc->task);
94}
95
96
97
98
99
100static inline void vchan_cyclic_callback(struct virt_dma_desc *vd)
101{
102 struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
103
104 vc->cyclic = vd;
105 tasklet_schedule(&vc->task);
106}
107
108
109
110
111
112
113
114static inline struct virt_dma_desc *vchan_next_desc(struct virt_dma_chan *vc)
115{
116 if (list_empty(&vc->desc_issued))
117 return NULL;
118
119 return list_first_entry(&vc->desc_issued, struct virt_dma_desc, node);
120}
121
122
123
124
125
126
127
128
129
130
131
132static inline void vchan_get_all_descriptors(struct virt_dma_chan *vc,
133 struct list_head *head)
134{
135 list_splice_tail_init(&vc->desc_submitted, head);
136 list_splice_tail_init(&vc->desc_issued, head);
137 list_splice_tail_init(&vc->desc_completed, head);
138}
139
140static inline void vchan_free_chan_resources(struct virt_dma_chan *vc)
141{
142 unsigned long flags;
143 LIST_HEAD(head);
144
145 spin_lock_irqsave(&vc->lock, flags);
146 vchan_get_all_descriptors(vc, &head);
147 spin_unlock_irqrestore(&vc->lock, flags);
148
149 vchan_dma_desc_free_list(vc, &head);
150}
151
152#endif
153