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.
18 #include "v3d_trace.h"
20 #define V3D_CORE_IRQS ((u32)(V3D_INT_OUTOMEM | \
26 #define V3D_HUB_IRQS ((u32)(V3D_HUB_INT_MMU_WRV | \
27 V3D_HUB_INT_MMU_PTI | \
28 V3D_HUB_INT_MMU_CAP | \
32 v3d_hub_irq(int irq, void *arg);
35 v3d_overflow_mem_work(struct work_struct *work)
38 container_of(work, struct v3d_dev, overflow_mem_work);
39 struct drm_device *dev = &v3d->drm;
40 struct v3d_bo *bo = v3d_bo_create(dev, NULL /* XXX: GMP */, 256 * 1024);
41 struct drm_gem_object *obj;
42 unsigned long irqflags;
45 DRM_ERROR("Couldn't allocate binner overflow mem\n");
50 /* We lost a race, and our work task came in after the bin job
51 * completed and exited. This can happen because the HW
52 * signals OOM before it's fully OOM, so the binner might just
55 * If we lose the race and our work task comes in after a new
56 * bin job got scheduled, that's fine. We'll just give them
57 * some binner pool anyway.
59 spin_lock_irqsave(&v3d->job_lock, irqflags);
61 spin_unlock_irqrestore(&v3d->job_lock, irqflags);
65 drm_gem_object_get(obj);
66 list_add_tail(&bo->unref_head, &v3d->bin_job->render->unref_list);
67 spin_unlock_irqrestore(&v3d->job_lock, irqflags);
69 V3D_CORE_WRITE(0, V3D_PTB_BPOA, bo->node.start << PAGE_SHIFT);
70 V3D_CORE_WRITE(0, V3D_PTB_BPOS, obj->size);
73 drm_gem_object_put_unlocked(obj);
77 v3d_irq(int irq, void *arg)
79 struct v3d_dev *v3d = arg;
81 irqreturn_t status = IRQ_NONE;
83 intsts = V3D_CORE_READ(0, V3D_CTL_INT_STS);
85 /* Acknowledge the interrupts we're handling here. */
86 V3D_CORE_WRITE(0, V3D_CTL_INT_CLR, intsts);
88 if (intsts & V3D_INT_OUTOMEM) {
89 /* Note that the OOM status is edge signaled, so the
90 * interrupt won't happen again until the we actually
91 * add more memory. Also, as of V3D 4.1, FLDONE won't
92 * be reported until any OOM state has been cleared.
94 schedule_work(&v3d->overflow_mem_work);
98 if (intsts & V3D_INT_FLDONE) {
99 struct v3d_fence *fence =
100 to_v3d_fence(v3d->bin_job->base.irq_fence);
102 trace_v3d_bcl_irq(&v3d->drm, fence->seqno);
103 dma_fence_signal(&fence->base);
104 status = IRQ_HANDLED;
107 if (intsts & V3D_INT_FRDONE) {
108 struct v3d_fence *fence =
109 to_v3d_fence(v3d->render_job->base.irq_fence);
111 trace_v3d_rcl_irq(&v3d->drm, fence->seqno);
112 dma_fence_signal(&fence->base);
113 status = IRQ_HANDLED;
116 if (intsts & V3D_INT_CSDDONE) {
117 struct v3d_fence *fence =
118 to_v3d_fence(v3d->csd_job->base.irq_fence);
120 trace_v3d_csd_irq(&v3d->drm, fence->seqno);
121 dma_fence_signal(&fence->base);
122 status = IRQ_HANDLED;
125 /* We shouldn't be triggering these if we have GMP in
126 * always-allowed mode.
128 if (intsts & V3D_INT_GMPV)
129 dev_err(v3d->dev, "GMP violation\n");
131 /* V3D 4.2 wires the hub and core IRQs together, so if we &
132 * didn't see the common one then check hub for MMU IRQs.
134 if (v3d->single_irq_line && status == IRQ_NONE)
135 return v3d_hub_irq(irq, arg);
141 v3d_hub_irq(int irq, void *arg)
143 struct v3d_dev *v3d = arg;
145 irqreturn_t status = IRQ_NONE;
147 intsts = V3D_READ(V3D_HUB_INT_STS);
149 /* Acknowledge the interrupts we're handling here. */
150 V3D_WRITE(V3D_HUB_INT_CLR, intsts);
152 if (intsts & V3D_HUB_INT_TFUC) {
153 struct v3d_fence *fence =
154 to_v3d_fence(v3d->tfu_job->base.irq_fence);
156 trace_v3d_tfu_irq(&v3d->drm, fence->seqno);
157 dma_fence_signal(&fence->base);
158 status = IRQ_HANDLED;
161 if (intsts & (V3D_HUB_INT_MMU_WRV |
162 V3D_HUB_INT_MMU_PTI |
163 V3D_HUB_INT_MMU_CAP)) {
164 u32 axi_id = V3D_READ(V3D_MMU_VIO_ID);
165 u64 vio_addr = ((u64)V3D_READ(V3D_MMU_VIO_ADDR) <<
166 (v3d->va_width - 32));
167 static const char *const v3d41_axi_ids[] = {
177 const char *client = "?";
179 V3D_WRITE(V3D_MMU_CTL,
180 V3D_READ(V3D_MMU_CTL) & (V3D_MMU_CTL_CAP_EXCEEDED |
181 V3D_MMU_CTL_PT_INVALID |
182 V3D_MMU_CTL_WRITE_VIOLATION));
184 if (v3d->ver >= 41) {
185 axi_id = axi_id >> 5;
186 if (axi_id < ARRAY_SIZE(v3d41_axi_ids))
187 client = v3d41_axi_ids[axi_id];
190 dev_err(v3d->dev, "MMU error from client %s (%d) at 0x%llx%s%s%s\n",
191 client, axi_id, (long long)vio_addr,
192 ((intsts & V3D_HUB_INT_MMU_WRV) ?
193 ", write violation" : ""),
194 ((intsts & V3D_HUB_INT_MMU_PTI) ?
195 ", pte invalid" : ""),
196 ((intsts & V3D_HUB_INT_MMU_CAP) ?
197 ", cap exceeded" : ""));
198 status = IRQ_HANDLED;
205 v3d_irq_init(struct v3d_dev *v3d)
209 INIT_WORK(&v3d->overflow_mem_work, v3d_overflow_mem_work);
211 /* Clear any pending interrupts someone might have left around
214 for (core = 0; core < v3d->cores; core++)
215 V3D_CORE_WRITE(core, V3D_CTL_INT_CLR, V3D_CORE_IRQS);
216 V3D_WRITE(V3D_HUB_INT_CLR, V3D_HUB_IRQS);
218 irq1 = platform_get_irq(v3d->pdev, 1);
219 if (irq1 == -EPROBE_DEFER)
222 ret = devm_request_irq(v3d->dev, irq1,
223 v3d_irq, IRQF_SHARED,
227 ret = devm_request_irq(v3d->dev, platform_get_irq(v3d->pdev, 0),
228 v3d_hub_irq, IRQF_SHARED,
233 v3d->single_irq_line = true;
235 ret = devm_request_irq(v3d->dev, platform_get_irq(v3d->pdev, 0),
236 v3d_irq, IRQF_SHARED,
246 if (ret != -EPROBE_DEFER)
247 dev_err(v3d->dev, "IRQ setup failed: %d\n", ret);
252 v3d_irq_enable(struct v3d_dev *v3d)
256 /* Enable our set of interrupts, masking out any others. */
257 for (core = 0; core < v3d->cores; core++) {
258 V3D_CORE_WRITE(core, V3D_CTL_INT_MSK_SET, ~V3D_CORE_IRQS);
259 V3D_CORE_WRITE(core, V3D_CTL_INT_MSK_CLR, V3D_CORE_IRQS);
262 V3D_WRITE(V3D_HUB_INT_MSK_SET, ~V3D_HUB_IRQS);
263 V3D_WRITE(V3D_HUB_INT_MSK_CLR, V3D_HUB_IRQS);
267 v3d_irq_disable(struct v3d_dev *v3d)
271 /* Disable all interrupts. */
272 for (core = 0; core < v3d->cores; core++)
273 V3D_CORE_WRITE(core, V3D_CTL_INT_MSK_SET, ~0);
274 V3D_WRITE(V3D_HUB_INT_MSK_SET, ~0);
276 /* Clear any pending interrupts we might have left. */
277 for (core = 0; core < v3d->cores; core++)
278 V3D_CORE_WRITE(core, V3D_CTL_INT_CLR, V3D_CORE_IRQS);
279 V3D_WRITE(V3D_HUB_INT_CLR, V3D_HUB_IRQS);
281 cancel_work_sync(&v3d->overflow_mem_work);
284 /** Reinitializes interrupt registers when a GPU reset is performed. */
285 void v3d_irq_reset(struct v3d_dev *v3d)