1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (C) 2014-2018 Broadcom */
5 * DOC: Interrupt management for the V3D engine
7 * When we take a bin, render, TFU done, or CSD done interrupt, we
8 * need to signal the fence for that job so that the scheduler can
9 * queue up the next one and unblock any waiters.
11 * When we take the binner out of memory interrupt, we need to
12 * allocate some new memory and pass it to the binner so that the
13 * current job can make progress.
16 #include <linux/platform_device.h>
17 #include <linux/sched/clock.h>
21 #include "v3d_trace.h"
23 #define V3D_CORE_IRQS(ver) ((u32)(V3D_INT_OUTOMEM | \
26 V3D_INT_CSDDONE(ver) | \
27 (ver < 71 ? V3D_INT_GMPV : 0)))
29 #define V3D_HUB_IRQS(ver) ((u32)(V3D_HUB_INT_MMU_WRV | \
30 V3D_HUB_INT_MMU_PTI | \
31 V3D_HUB_INT_MMU_CAP | \
33 (ver >= 71 ? V3D_V7_HUB_INT_GMPV : 0)))
36 v3d_hub_irq(int irq, void *arg);
39 v3d_overflow_mem_work(struct work_struct *work)
42 container_of(work, struct v3d_dev, overflow_mem_work);
43 struct drm_device *dev = &v3d->drm;
44 struct v3d_bo *bo = v3d_bo_create(dev, NULL /* XXX: GMP */, 256 * 1024);
45 struct drm_gem_object *obj;
46 unsigned long irqflags;
49 DRM_ERROR("Couldn't allocate binner overflow mem\n");
54 /* We lost a race, and our work task came in after the bin job
55 * completed and exited. This can happen because the HW
56 * signals OOM before it's fully OOM, so the binner might just
59 * If we lose the race and our work task comes in after a new
60 * bin job got scheduled, that's fine. We'll just give them
61 * some binner pool anyway.
63 spin_lock_irqsave(&v3d->job_lock, irqflags);
65 spin_unlock_irqrestore(&v3d->job_lock, irqflags);
69 drm_gem_object_get(obj);
70 list_add_tail(&bo->unref_head, &v3d->bin_job->render->unref_list);
71 spin_unlock_irqrestore(&v3d->job_lock, irqflags);
73 v3d_mmu_flush_all(v3d);
75 V3D_CORE_WRITE(0, V3D_PTB_BPOA, bo->node.start << V3D_MMU_PAGE_SHIFT);
76 V3D_CORE_WRITE(0, V3D_PTB_BPOS, obj->size);
79 drm_gem_object_put(obj);
83 v3d_irq(int irq, void *arg)
85 struct v3d_dev *v3d = arg;
87 irqreturn_t status = IRQ_NONE;
89 intsts = V3D_CORE_READ(0, V3D_CTL_INT_STS);
91 /* Acknowledge the interrupts we're handling here. */
92 V3D_CORE_WRITE(0, V3D_CTL_INT_CLR, intsts);
94 if (intsts & V3D_INT_OUTOMEM) {
95 /* Note that the OOM status is edge signaled, so the
96 * interrupt won't happen again until the we actually
97 * add more memory. Also, as of V3D 4.1, FLDONE won't
98 * be reported until any OOM state has been cleared.
100 schedule_work(&v3d->overflow_mem_work);
101 status = IRQ_HANDLED;
104 if (intsts & V3D_INT_FLDONE) {
105 struct v3d_fence *fence =
106 to_v3d_fence(v3d->bin_job->base.irq_fence);
108 v3d_job_update_stats(&v3d->bin_job->base, V3D_BIN);
109 trace_v3d_bcl_irq(&v3d->drm, fence->seqno);
110 dma_fence_signal(&fence->base);
112 status = IRQ_HANDLED;
115 if (intsts & V3D_INT_FRDONE) {
116 struct v3d_fence *fence =
117 to_v3d_fence(v3d->render_job->base.irq_fence);
119 v3d_job_update_stats(&v3d->render_job->base, V3D_RENDER);
120 trace_v3d_rcl_irq(&v3d->drm, fence->seqno);
121 dma_fence_signal(&fence->base);
122 v3d->render_job = NULL;
123 status = IRQ_HANDLED;
126 if (intsts & V3D_INT_CSDDONE(v3d->ver)) {
127 struct v3d_fence *fence =
128 to_v3d_fence(v3d->csd_job->base.irq_fence);
130 v3d_job_update_stats(&v3d->csd_job->base, V3D_CSD);
131 trace_v3d_csd_irq(&v3d->drm, fence->seqno);
132 dma_fence_signal(&fence->base);
134 status = IRQ_HANDLED;
137 /* We shouldn't be triggering these if we have GMP in
138 * always-allowed mode.
140 if (v3d->ver < 71 && (intsts & V3D_INT_GMPV))
141 dev_err(v3d->drm.dev, "GMP violation\n");
143 /* V3D 4.2 wires the hub and core IRQs together, so if we &
144 * didn't see the common one then check hub for MMU IRQs.
146 if (v3d->single_irq_line && status == IRQ_NONE)
147 return v3d_hub_irq(irq, arg);
153 v3d_hub_irq(int irq, void *arg)
155 struct v3d_dev *v3d = arg;
157 irqreturn_t status = IRQ_NONE;
159 intsts = V3D_READ(V3D_HUB_INT_STS);
161 /* Acknowledge the interrupts we're handling here. */
162 V3D_WRITE(V3D_HUB_INT_CLR, intsts);
164 if (intsts & V3D_HUB_INT_TFUC) {
165 struct v3d_fence *fence =
166 to_v3d_fence(v3d->tfu_job->base.irq_fence);
168 v3d_job_update_stats(&v3d->tfu_job->base, V3D_TFU);
169 trace_v3d_tfu_irq(&v3d->drm, fence->seqno);
170 dma_fence_signal(&fence->base);
172 status = IRQ_HANDLED;
175 if (intsts & (V3D_HUB_INT_MMU_WRV |
176 V3D_HUB_INT_MMU_PTI |
177 V3D_HUB_INT_MMU_CAP)) {
178 u32 axi_id = V3D_READ(V3D_MMU_VIO_ID);
179 u64 vio_addr = ((u64)V3D_READ(V3D_MMU_VIO_ADDR) <<
180 (v3d->va_width - 32));
181 static const char *const v3d41_axi_ids[] = {
191 const char *client = "?";
193 V3D_WRITE(V3D_MMU_CTL, V3D_READ(V3D_MMU_CTL));
195 if (v3d->ver >= 41) {
196 axi_id = axi_id >> 5;
197 if (axi_id < ARRAY_SIZE(v3d41_axi_ids))
198 client = v3d41_axi_ids[axi_id];
201 dev_err(v3d->drm.dev, "MMU error from client %s (%d) at 0x%llx%s%s%s\n",
202 client, axi_id, (long long)vio_addr,
203 ((intsts & V3D_HUB_INT_MMU_WRV) ?
204 ", write violation" : ""),
205 ((intsts & V3D_HUB_INT_MMU_PTI) ?
206 ", pte invalid" : ""),
207 ((intsts & V3D_HUB_INT_MMU_CAP) ?
208 ", cap exceeded" : ""));
209 status = IRQ_HANDLED;
212 if (v3d->ver >= 71 && (intsts & V3D_V7_HUB_INT_GMPV)) {
213 dev_err(v3d->drm.dev, "GMP Violation\n");
214 status = IRQ_HANDLED;
221 v3d_irq_init(struct v3d_dev *v3d)
225 INIT_WORK(&v3d->overflow_mem_work, v3d_overflow_mem_work);
227 /* Clear any pending interrupts someone might have left around
230 for (core = 0; core < v3d->cores; core++)
231 V3D_CORE_WRITE(core, V3D_CTL_INT_CLR, V3D_CORE_IRQS(v3d->ver));
232 V3D_WRITE(V3D_HUB_INT_CLR, V3D_HUB_IRQS(v3d->ver));
234 irq1 = platform_get_irq_optional(v3d_to_pdev(v3d), 1);
235 if (irq1 == -EPROBE_DEFER)
238 ret = devm_request_irq(v3d->drm.dev, irq1,
239 v3d_irq, IRQF_SHARED,
243 ret = devm_request_irq(v3d->drm.dev,
244 platform_get_irq(v3d_to_pdev(v3d), 0),
245 v3d_hub_irq, IRQF_SHARED,
250 v3d->single_irq_line = true;
252 ret = devm_request_irq(v3d->drm.dev,
253 platform_get_irq(v3d_to_pdev(v3d), 0),
254 v3d_irq, IRQF_SHARED,
264 if (ret != -EPROBE_DEFER)
265 dev_err(v3d->drm.dev, "IRQ setup failed: %d\n", ret);
270 v3d_irq_enable(struct v3d_dev *v3d)
274 /* Enable our set of interrupts, masking out any others. */
275 for (core = 0; core < v3d->cores; core++) {
276 V3D_CORE_WRITE(core, V3D_CTL_INT_MSK_SET, ~V3D_CORE_IRQS(v3d->ver));
277 V3D_CORE_WRITE(core, V3D_CTL_INT_MSK_CLR, V3D_CORE_IRQS(v3d->ver));
280 V3D_WRITE(V3D_HUB_INT_MSK_SET, ~V3D_HUB_IRQS(v3d->ver));
281 V3D_WRITE(V3D_HUB_INT_MSK_CLR, V3D_HUB_IRQS(v3d->ver));
285 v3d_irq_disable(struct v3d_dev *v3d)
289 /* Disable all interrupts. */
290 for (core = 0; core < v3d->cores; core++)
291 V3D_CORE_WRITE(core, V3D_CTL_INT_MSK_SET, ~0);
292 V3D_WRITE(V3D_HUB_INT_MSK_SET, ~0);
294 /* Clear any pending interrupts we might have left. */
295 for (core = 0; core < v3d->cores; core++)
296 V3D_CORE_WRITE(core, V3D_CTL_INT_CLR, V3D_CORE_IRQS(v3d->ver));
297 V3D_WRITE(V3D_HUB_INT_CLR, V3D_HUB_IRQS(v3d->ver));
299 cancel_work_sync(&v3d->overflow_mem_work);
302 /** Reinitializes interrupt registers when a GPU reset is performed. */
303 void v3d_irq_reset(struct v3d_dev *v3d)