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, or TFU done interrupt, we need to
8 * signal the fence for that job so that the scheduler can queue up
9 * 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 | \
25 #define V3D_HUB_IRQS ((u32)(V3D_HUB_INT_MMU_WRV | \
26 V3D_HUB_INT_MMU_PTI | \
27 V3D_HUB_INT_MMU_CAP | \
31 v3d_overflow_mem_work(struct work_struct
*work
)
34 container_of(work
, struct v3d_dev
, overflow_mem_work
);
35 struct drm_device
*dev
= &v3d
->drm
;
36 struct v3d_bo
*bo
= v3d_bo_create(dev
, NULL
/* XXX: GMP */, 256 * 1024);
37 unsigned long irqflags
;
40 DRM_ERROR("Couldn't allocate binner overflow mem\n");
44 /* We lost a race, and our work task came in after the bin job
45 * completed and exited. This can happen because the HW
46 * signals OOM before it's fully OOM, so the binner might just
49 * If we lose the race and our work task comes in after a new
50 * bin job got scheduled, that's fine. We'll just give them
51 * some binner pool anyway.
53 spin_lock_irqsave(&v3d
->job_lock
, irqflags
);
55 spin_unlock_irqrestore(&v3d
->job_lock
, irqflags
);
59 drm_gem_object_get(&bo
->base
);
60 list_add_tail(&bo
->unref_head
, &v3d
->bin_job
->unref_list
);
61 spin_unlock_irqrestore(&v3d
->job_lock
, irqflags
);
63 V3D_CORE_WRITE(0, V3D_PTB_BPOA
, bo
->node
.start
<< PAGE_SHIFT
);
64 V3D_CORE_WRITE(0, V3D_PTB_BPOS
, bo
->base
.size
);
67 drm_gem_object_put_unlocked(&bo
->base
);
71 v3d_irq(int irq
, void *arg
)
73 struct v3d_dev
*v3d
= arg
;
75 irqreturn_t status
= IRQ_NONE
;
77 intsts
= V3D_CORE_READ(0, V3D_CTL_INT_STS
);
79 /* Acknowledge the interrupts we're handling here. */
80 V3D_CORE_WRITE(0, V3D_CTL_INT_CLR
, intsts
);
82 if (intsts
& V3D_INT_OUTOMEM
) {
83 /* Note that the OOM status is edge signaled, so the
84 * interrupt won't happen again until the we actually
87 schedule_work(&v3d
->overflow_mem_work
);
91 if (intsts
& V3D_INT_FLDONE
) {
92 struct v3d_fence
*fence
=
93 to_v3d_fence(v3d
->bin_job
->bin
.done_fence
);
95 trace_v3d_bcl_irq(&v3d
->drm
, fence
->seqno
);
96 dma_fence_signal(&fence
->base
);
100 if (intsts
& V3D_INT_FRDONE
) {
101 struct v3d_fence
*fence
=
102 to_v3d_fence(v3d
->render_job
->render
.done_fence
);
104 trace_v3d_rcl_irq(&v3d
->drm
, fence
->seqno
);
105 dma_fence_signal(&fence
->base
);
106 status
= IRQ_HANDLED
;
109 /* We shouldn't be triggering these if we have GMP in
110 * always-allowed mode.
112 if (intsts
& V3D_INT_GMPV
)
113 dev_err(v3d
->dev
, "GMP violation\n");
119 v3d_hub_irq(int irq
, void *arg
)
121 struct v3d_dev
*v3d
= arg
;
123 irqreturn_t status
= IRQ_NONE
;
125 intsts
= V3D_READ(V3D_HUB_INT_STS
);
127 /* Acknowledge the interrupts we're handling here. */
128 V3D_WRITE(V3D_HUB_INT_CLR
, intsts
);
130 if (intsts
& V3D_HUB_INT_TFUC
) {
131 struct v3d_fence
*fence
=
132 to_v3d_fence(v3d
->tfu_job
->done_fence
);
134 trace_v3d_tfu_irq(&v3d
->drm
, fence
->seqno
);
135 dma_fence_signal(&fence
->base
);
136 status
= IRQ_HANDLED
;
139 if (intsts
& (V3D_HUB_INT_MMU_WRV
|
140 V3D_HUB_INT_MMU_PTI
|
141 V3D_HUB_INT_MMU_CAP
)) {
142 u32 axi_id
= V3D_READ(V3D_MMU_VIO_ID
);
143 u64 vio_addr
= (u64
)V3D_READ(V3D_MMU_VIO_ADDR
) << 8;
145 dev_err(v3d
->dev
, "MMU error from client %d at 0x%08llx%s%s%s\n",
146 axi_id
, (long long)vio_addr
,
147 ((intsts
& V3D_HUB_INT_MMU_WRV
) ?
148 ", write violation" : ""),
149 ((intsts
& V3D_HUB_INT_MMU_PTI
) ?
150 ", pte invalid" : ""),
151 ((intsts
& V3D_HUB_INT_MMU_CAP
) ?
152 ", cap exceeded" : ""));
153 status
= IRQ_HANDLED
;
160 v3d_irq_init(struct v3d_dev
*v3d
)
164 INIT_WORK(&v3d
->overflow_mem_work
, v3d_overflow_mem_work
);
166 /* Clear any pending interrupts someone might have left around
169 for (core
= 0; core
< v3d
->cores
; core
++)
170 V3D_CORE_WRITE(core
, V3D_CTL_INT_CLR
, V3D_CORE_IRQS
);
171 V3D_WRITE(V3D_HUB_INT_CLR
, V3D_HUB_IRQS
);
173 ret
= devm_request_irq(v3d
->dev
, platform_get_irq(v3d
->pdev
, 0),
174 v3d_hub_irq
, IRQF_SHARED
,
176 ret
= devm_request_irq(v3d
->dev
, platform_get_irq(v3d
->pdev
, 1),
177 v3d_irq
, IRQF_SHARED
,
180 dev_err(v3d
->dev
, "IRQ setup failed: %d\n", ret
);
186 v3d_irq_enable(struct v3d_dev
*v3d
)
190 /* Enable our set of interrupts, masking out any others. */
191 for (core
= 0; core
< v3d
->cores
; core
++) {
192 V3D_CORE_WRITE(core
, V3D_CTL_INT_MSK_SET
, ~V3D_CORE_IRQS
);
193 V3D_CORE_WRITE(core
, V3D_CTL_INT_MSK_CLR
, V3D_CORE_IRQS
);
196 V3D_WRITE(V3D_HUB_INT_MSK_SET
, ~V3D_HUB_IRQS
);
197 V3D_WRITE(V3D_HUB_INT_MSK_CLR
, V3D_HUB_IRQS
);
201 v3d_irq_disable(struct v3d_dev
*v3d
)
205 /* Disable all interrupts. */
206 for (core
= 0; core
< v3d
->cores
; core
++)
207 V3D_CORE_WRITE(core
, V3D_CTL_INT_MSK_SET
, ~0);
208 V3D_WRITE(V3D_HUB_INT_MSK_SET
, ~0);
210 /* Clear any pending interrupts we might have left. */
211 for (core
= 0; core
< v3d
->cores
; core
++)
212 V3D_CORE_WRITE(core
, V3D_CTL_INT_CLR
, V3D_CORE_IRQS
);
213 V3D_WRITE(V3D_HUB_INT_CLR
, V3D_HUB_IRQS
);
215 cancel_work_sync(&v3d
->overflow_mem_work
);
218 /** Reinitializes interrupt registers when a GPU reset is performed. */
219 void v3d_irq_reset(struct v3d_dev
*v3d
)