1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48#include "vc4_drv.h"
49#include "vc4_regs.h"
50
51#define V3D_DRIVER_IRQS (V3D_INT_OUTOMEM | \
52 V3D_INT_FLDONE | \
53 V3D_INT_FRDONE)
54
55DECLARE_WAIT_QUEUE_HEAD(render_wait);
56
57static void
58vc4_overflow_mem_work(struct work_struct *work)
59{
60 struct vc4_dev *vc4 =
61 container_of(work, struct vc4_dev, overflow_mem_work);
62 struct vc4_bo *bo = vc4->bin_bo;
63 int bin_bo_slot;
64 struct vc4_exec_info *exec;
65 unsigned long irqflags;
66
67 bin_bo_slot = vc4_v3d_get_bin_slot(vc4);
68 if (bin_bo_slot < 0) {
69 DRM_ERROR("Couldn't allocate binner overflow mem\n");
70 return;
71 }
72
73 spin_lock_irqsave(&vc4->job_lock, irqflags);
74
75 if (vc4->bin_alloc_overflow) {
76
77
78
79
80
81
82 exec = vc4_first_bin_job(vc4);
83 if (!exec)
84 exec = vc4_last_render_job(vc4);
85 if (exec) {
86 exec->bin_slots |= vc4->bin_alloc_overflow;
87 } else {
88
89
90
91 vc4->bin_alloc_used &= ~vc4->bin_alloc_overflow;
92 }
93 }
94 vc4->bin_alloc_overflow = BIT(bin_bo_slot);
95
96 V3D_WRITE(V3D_BPOA, bo->base.paddr + bin_bo_slot * vc4->bin_alloc_size);
97 V3D_WRITE(V3D_BPOS, bo->base.base.size);
98 V3D_WRITE(V3D_INTCTL, V3D_INT_OUTOMEM);
99 V3D_WRITE(V3D_INTENA, V3D_INT_OUTOMEM);
100 spin_unlock_irqrestore(&vc4->job_lock, irqflags);
101}
102
103static void
104vc4_irq_finish_bin_job(struct drm_device *dev)
105{
106 struct vc4_dev *vc4 = to_vc4_dev(dev);
107 struct vc4_exec_info *next, *exec = vc4_first_bin_job(vc4);
108
109 if (!exec)
110 return;
111
112 vc4_move_job_to_render(dev, exec);
113 next = vc4_first_bin_job(vc4);
114
115
116
117
118
119 if (next && next->perfmon == exec->perfmon)
120 vc4_submit_next_bin_job(dev);
121}
122
123static void
124vc4_cancel_bin_job(struct drm_device *dev)
125{
126 struct vc4_dev *vc4 = to_vc4_dev(dev);
127 struct vc4_exec_info *exec = vc4_first_bin_job(vc4);
128
129 if (!exec)
130 return;
131
132
133 if (exec->perfmon)
134 vc4_perfmon_stop(vc4, exec->perfmon, false);
135
136 list_move_tail(&exec->head, &vc4->bin_job_list);
137 vc4_submit_next_bin_job(dev);
138}
139
140static void
141vc4_irq_finish_render_job(struct drm_device *dev)
142{
143 struct vc4_dev *vc4 = to_vc4_dev(dev);
144 struct vc4_exec_info *exec = vc4_first_render_job(vc4);
145 struct vc4_exec_info *nextbin, *nextrender;
146
147 if (!exec)
148 return;
149
150 vc4->finished_seqno++;
151 list_move_tail(&exec->head, &vc4->job_done_list);
152
153 nextbin = vc4_first_bin_job(vc4);
154 nextrender = vc4_first_render_job(vc4);
155
156
157
158
159 if (exec->perfmon && !nextrender &&
160 (!nextbin || nextbin->perfmon != exec->perfmon))
161 vc4_perfmon_stop(vc4, exec->perfmon, true);
162
163
164
165
166
167
168
169
170 if (nextrender)
171 vc4_submit_next_render_job(dev);
172 else if (nextbin && nextbin->perfmon != exec->perfmon)
173 vc4_submit_next_bin_job(dev);
174
175 if (exec->fence) {
176 dma_fence_signal_locked(exec->fence);
177 dma_fence_put(exec->fence);
178 exec->fence = NULL;
179 }
180
181 wake_up_all(&vc4->job_wait_queue);
182 schedule_work(&vc4->job_done_work);
183}
184
185irqreturn_t
186vc4_irq(int irq, void *arg)
187{
188 struct drm_device *dev = arg;
189 struct vc4_dev *vc4 = to_vc4_dev(dev);
190 uint32_t intctl;
191 irqreturn_t status = IRQ_NONE;
192
193 barrier();
194 intctl = V3D_READ(V3D_INTCTL);
195
196
197
198
199
200
201 V3D_WRITE(V3D_INTCTL, intctl);
202
203 if (intctl & V3D_INT_OUTOMEM) {
204
205 V3D_WRITE(V3D_INTDIS, V3D_INT_OUTOMEM);
206 schedule_work(&vc4->overflow_mem_work);
207 status = IRQ_HANDLED;
208 }
209
210 if (intctl & V3D_INT_FLDONE) {
211 spin_lock(&vc4->job_lock);
212 vc4_irq_finish_bin_job(dev);
213 spin_unlock(&vc4->job_lock);
214 status = IRQ_HANDLED;
215 }
216
217 if (intctl & V3D_INT_FRDONE) {
218 spin_lock(&vc4->job_lock);
219 vc4_irq_finish_render_job(dev);
220 spin_unlock(&vc4->job_lock);
221 status = IRQ_HANDLED;
222 }
223
224 return status;
225}
226
227void
228vc4_irq_preinstall(struct drm_device *dev)
229{
230 struct vc4_dev *vc4 = to_vc4_dev(dev);
231
232 init_waitqueue_head(&vc4->job_wait_queue);
233 INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
234
235
236
237
238 V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS);
239}
240
241int
242vc4_irq_postinstall(struct drm_device *dev)
243{
244 struct vc4_dev *vc4 = to_vc4_dev(dev);
245
246
247 V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
248
249 return 0;
250}
251
252void
253vc4_irq_uninstall(struct drm_device *dev)
254{
255 struct vc4_dev *vc4 = to_vc4_dev(dev);
256
257
258 V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS);
259
260
261 V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS);
262
263
264 disable_irq(dev->irq);
265
266 cancel_work_sync(&vc4->overflow_mem_work);
267}
268
269
270void vc4_irq_reset(struct drm_device *dev)
271{
272 struct vc4_dev *vc4 = to_vc4_dev(dev);
273 unsigned long irqflags;
274
275
276 V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS);
277
278
279
280
281
282
283
284 V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
285
286 spin_lock_irqsave(&vc4->job_lock, irqflags);
287 vc4_cancel_bin_job(dev);
288 vc4_irq_finish_render_job(dev);
289 spin_unlock_irqrestore(&vc4->job_lock, irqflags);
290}
291