treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / gt / intel_gt_irq.c
blobf796bdf1ed30e6f3aa631b29e82956ee003f0336
1 /*
2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
5 */
7 #include <linux/sched/clock.h>
9 #include "i915_drv.h"
10 #include "i915_irq.h"
11 #include "intel_gt.h"
12 #include "intel_gt_irq.h"
13 #include "intel_uncore.h"
14 #include "intel_rps.h"
16 static void guc_irq_handler(struct intel_guc *guc, u16 iir)
18 if (iir & GUC_INTR_GUC2HOST)
19 intel_guc_to_host_event_handler(guc);
22 static void
23 cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
25 bool tasklet = false;
27 if (iir & GT_CONTEXT_SWITCH_INTERRUPT)
28 tasklet = true;
30 if (iir & GT_RENDER_USER_INTERRUPT) {
31 intel_engine_signal_breadcrumbs(engine);
32 tasklet |= intel_engine_needs_breadcrumb_tasklet(engine);
35 if (tasklet)
36 tasklet_hi_schedule(&engine->execlists.tasklet);
39 static u32
40 gen11_gt_engine_identity(struct intel_gt *gt,
41 const unsigned int bank, const unsigned int bit)
43 void __iomem * const regs = gt->uncore->regs;
44 u32 timeout_ts;
45 u32 ident;
47 lockdep_assert_held(&gt->irq_lock);
49 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
52 * NB: Specs do not specify how long to spin wait,
53 * so we do ~100us as an educated guess.
55 timeout_ts = (local_clock() >> 10) + 100;
56 do {
57 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
58 } while (!(ident & GEN11_INTR_DATA_VALID) &&
59 !time_after32(local_clock() >> 10, timeout_ts));
61 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
62 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
63 bank, bit, ident);
64 return 0;
67 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
68 GEN11_INTR_DATA_VALID);
70 return ident;
73 static void
74 gen11_other_irq_handler(struct intel_gt *gt, const u8 instance,
75 const u16 iir)
77 if (instance == OTHER_GUC_INSTANCE)
78 return guc_irq_handler(&gt->uc.guc, iir);
80 if (instance == OTHER_GTPM_INSTANCE)
81 return gen11_rps_irq_handler(&gt->rps, iir);
83 WARN_ONCE(1, "unhandled other interrupt instance=0x%x, iir=0x%x\n",
84 instance, iir);
87 static void
88 gen11_engine_irq_handler(struct intel_gt *gt, const u8 class,
89 const u8 instance, const u16 iir)
91 struct intel_engine_cs *engine;
93 if (instance <= MAX_ENGINE_INSTANCE)
94 engine = gt->engine_class[class][instance];
95 else
96 engine = NULL;
98 if (likely(engine))
99 return cs_irq_handler(engine, iir);
101 WARN_ONCE(1, "unhandled engine interrupt class=0x%x, instance=0x%x\n",
102 class, instance);
105 static void
106 gen11_gt_identity_handler(struct intel_gt *gt, const u32 identity)
108 const u8 class = GEN11_INTR_ENGINE_CLASS(identity);
109 const u8 instance = GEN11_INTR_ENGINE_INSTANCE(identity);
110 const u16 intr = GEN11_INTR_ENGINE_INTR(identity);
112 if (unlikely(!intr))
113 return;
115 if (class <= COPY_ENGINE_CLASS)
116 return gen11_engine_irq_handler(gt, class, instance, intr);
118 if (class == OTHER_CLASS)
119 return gen11_other_irq_handler(gt, instance, intr);
121 WARN_ONCE(1, "unknown interrupt class=0x%x, instance=0x%x, intr=0x%x\n",
122 class, instance, intr);
125 static void
126 gen11_gt_bank_handler(struct intel_gt *gt, const unsigned int bank)
128 void __iomem * const regs = gt->uncore->regs;
129 unsigned long intr_dw;
130 unsigned int bit;
132 lockdep_assert_held(&gt->irq_lock);
134 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
136 for_each_set_bit(bit, &intr_dw, 32) {
137 const u32 ident = gen11_gt_engine_identity(gt, bank, bit);
139 gen11_gt_identity_handler(gt, ident);
142 /* Clear must be after shared has been served for engine */
143 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
146 void gen11_gt_irq_handler(struct intel_gt *gt, const u32 master_ctl)
148 unsigned int bank;
150 spin_lock(&gt->irq_lock);
152 for (bank = 0; bank < 2; bank++) {
153 if (master_ctl & GEN11_GT_DW_IRQ(bank))
154 gen11_gt_bank_handler(gt, bank);
157 spin_unlock(&gt->irq_lock);
160 bool gen11_gt_reset_one_iir(struct intel_gt *gt,
161 const unsigned int bank, const unsigned int bit)
163 void __iomem * const regs = gt->uncore->regs;
164 u32 dw;
166 lockdep_assert_held(&gt->irq_lock);
168 dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
169 if (dw & BIT(bit)) {
171 * According to the BSpec, DW_IIR bits cannot be cleared without
172 * first servicing the Selector & Shared IIR registers.
174 gen11_gt_engine_identity(gt, bank, bit);
177 * We locked GT INT DW by reading it. If we want to (try
178 * to) recover from this successfully, we need to clear
179 * our bit, otherwise we are locking the register for
180 * everybody.
182 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), BIT(bit));
184 return true;
187 return false;
190 void gen11_gt_irq_reset(struct intel_gt *gt)
192 struct intel_uncore *uncore = gt->uncore;
194 /* Disable RCS, BCS, VCS and VECS class engines. */
195 intel_uncore_write(uncore, GEN11_RENDER_COPY_INTR_ENABLE, 0);
196 intel_uncore_write(uncore, GEN11_VCS_VECS_INTR_ENABLE, 0);
198 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
199 intel_uncore_write(uncore, GEN11_RCS0_RSVD_INTR_MASK, ~0);
200 intel_uncore_write(uncore, GEN11_BCS_RSVD_INTR_MASK, ~0);
201 intel_uncore_write(uncore, GEN11_VCS0_VCS1_INTR_MASK, ~0);
202 intel_uncore_write(uncore, GEN11_VCS2_VCS3_INTR_MASK, ~0);
203 intel_uncore_write(uncore, GEN11_VECS0_VECS1_INTR_MASK, ~0);
205 intel_uncore_write(uncore, GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
206 intel_uncore_write(uncore, GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
207 intel_uncore_write(uncore, GEN11_GUC_SG_INTR_ENABLE, 0);
208 intel_uncore_write(uncore, GEN11_GUC_SG_INTR_MASK, ~0);
211 void gen11_gt_irq_postinstall(struct intel_gt *gt)
213 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
214 struct intel_uncore *uncore = gt->uncore;
215 const u32 dmask = irqs << 16 | irqs;
216 const u32 smask = irqs << 16;
218 BUILD_BUG_ON(irqs & 0xffff0000);
220 /* Enable RCS, BCS, VCS and VECS class interrupts. */
221 intel_uncore_write(uncore, GEN11_RENDER_COPY_INTR_ENABLE, dmask);
222 intel_uncore_write(uncore, GEN11_VCS_VECS_INTR_ENABLE, dmask);
224 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
225 intel_uncore_write(uncore, GEN11_RCS0_RSVD_INTR_MASK, ~smask);
226 intel_uncore_write(uncore, GEN11_BCS_RSVD_INTR_MASK, ~smask);
227 intel_uncore_write(uncore, GEN11_VCS0_VCS1_INTR_MASK, ~dmask);
228 intel_uncore_write(uncore, GEN11_VCS2_VCS3_INTR_MASK, ~dmask);
229 intel_uncore_write(uncore, GEN11_VECS0_VECS1_INTR_MASK, ~dmask);
232 * RPS interrupts will get enabled/disabled on demand when RPS itself
233 * is enabled/disabled.
235 gt->pm_ier = 0x0;
236 gt->pm_imr = ~gt->pm_ier;
237 intel_uncore_write(uncore, GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
238 intel_uncore_write(uncore, GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
240 /* Same thing for GuC interrupts */
241 intel_uncore_write(uncore, GEN11_GUC_SG_INTR_ENABLE, 0);
242 intel_uncore_write(uncore, GEN11_GUC_SG_INTR_MASK, ~0);
245 void gen5_gt_irq_handler(struct intel_gt *gt, u32 gt_iir)
247 if (gt_iir & GT_RENDER_USER_INTERRUPT)
248 intel_engine_signal_breadcrumbs(gt->engine_class[RENDER_CLASS][0]);
249 if (gt_iir & ILK_BSD_USER_INTERRUPT)
250 intel_engine_signal_breadcrumbs(gt->engine_class[VIDEO_DECODE_CLASS][0]);
253 static void gen7_parity_error_irq_handler(struct intel_gt *gt, u32 iir)
255 if (!HAS_L3_DPF(gt->i915))
256 return;
258 spin_lock(&gt->irq_lock);
259 gen5_gt_disable_irq(gt, GT_PARITY_ERROR(gt->i915));
260 spin_unlock(&gt->irq_lock);
262 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
263 gt->i915->l3_parity.which_slice |= 1 << 1;
265 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
266 gt->i915->l3_parity.which_slice |= 1 << 0;
268 schedule_work(&gt->i915->l3_parity.error_work);
271 void gen6_gt_irq_handler(struct intel_gt *gt, u32 gt_iir)
273 if (gt_iir & GT_RENDER_USER_INTERRUPT)
274 intel_engine_signal_breadcrumbs(gt->engine_class[RENDER_CLASS][0]);
275 if (gt_iir & GT_BSD_USER_INTERRUPT)
276 intel_engine_signal_breadcrumbs(gt->engine_class[VIDEO_DECODE_CLASS][0]);
277 if (gt_iir & GT_BLT_USER_INTERRUPT)
278 intel_engine_signal_breadcrumbs(gt->engine_class[COPY_ENGINE_CLASS][0]);
280 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
281 GT_BSD_CS_ERROR_INTERRUPT |
282 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
283 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
285 if (gt_iir & GT_PARITY_ERROR(gt->i915))
286 gen7_parity_error_irq_handler(gt, gt_iir);
289 void gen8_gt_irq_ack(struct intel_gt *gt, u32 master_ctl, u32 gt_iir[4])
291 void __iomem * const regs = gt->uncore->regs;
293 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
294 gt_iir[0] = raw_reg_read(regs, GEN8_GT_IIR(0));
295 if (likely(gt_iir[0]))
296 raw_reg_write(regs, GEN8_GT_IIR(0), gt_iir[0]);
299 if (master_ctl & (GEN8_GT_VCS0_IRQ | GEN8_GT_VCS1_IRQ)) {
300 gt_iir[1] = raw_reg_read(regs, GEN8_GT_IIR(1));
301 if (likely(gt_iir[1]))
302 raw_reg_write(regs, GEN8_GT_IIR(1), gt_iir[1]);
305 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
306 gt_iir[2] = raw_reg_read(regs, GEN8_GT_IIR(2));
307 if (likely(gt_iir[2]))
308 raw_reg_write(regs, GEN8_GT_IIR(2), gt_iir[2]);
311 if (master_ctl & GEN8_GT_VECS_IRQ) {
312 gt_iir[3] = raw_reg_read(regs, GEN8_GT_IIR(3));
313 if (likely(gt_iir[3]))
314 raw_reg_write(regs, GEN8_GT_IIR(3), gt_iir[3]);
318 void gen8_gt_irq_handler(struct intel_gt *gt, u32 master_ctl, u32 gt_iir[4])
320 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
321 cs_irq_handler(gt->engine_class[RENDER_CLASS][0],
322 gt_iir[0] >> GEN8_RCS_IRQ_SHIFT);
323 cs_irq_handler(gt->engine_class[COPY_ENGINE_CLASS][0],
324 gt_iir[0] >> GEN8_BCS_IRQ_SHIFT);
327 if (master_ctl & (GEN8_GT_VCS0_IRQ | GEN8_GT_VCS1_IRQ)) {
328 cs_irq_handler(gt->engine_class[VIDEO_DECODE_CLASS][0],
329 gt_iir[1] >> GEN8_VCS0_IRQ_SHIFT);
330 cs_irq_handler(gt->engine_class[VIDEO_DECODE_CLASS][1],
331 gt_iir[1] >> GEN8_VCS1_IRQ_SHIFT);
334 if (master_ctl & GEN8_GT_VECS_IRQ) {
335 cs_irq_handler(gt->engine_class[VIDEO_ENHANCEMENT_CLASS][0],
336 gt_iir[3] >> GEN8_VECS_IRQ_SHIFT);
339 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
340 gen6_rps_irq_handler(&gt->rps, gt_iir[2]);
341 guc_irq_handler(&gt->uc.guc, gt_iir[2] >> 16);
345 void gen8_gt_irq_reset(struct intel_gt *gt)
347 struct intel_uncore *uncore = gt->uncore;
349 GEN8_IRQ_RESET_NDX(uncore, GT, 0);
350 GEN8_IRQ_RESET_NDX(uncore, GT, 1);
351 GEN8_IRQ_RESET_NDX(uncore, GT, 2);
352 GEN8_IRQ_RESET_NDX(uncore, GT, 3);
355 void gen8_gt_irq_postinstall(struct intel_gt *gt)
357 struct intel_uncore *uncore = gt->uncore;
359 /* These are interrupts we'll toggle with the ring mask register */
360 u32 gt_interrupts[] = {
361 (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
362 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
363 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
364 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT),
366 (GT_RENDER_USER_INTERRUPT << GEN8_VCS0_IRQ_SHIFT |
367 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS0_IRQ_SHIFT |
368 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
369 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT),
373 (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
374 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT)
377 gt->pm_ier = 0x0;
378 gt->pm_imr = ~gt->pm_ier;
379 GEN8_IRQ_INIT_NDX(uncore, GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
380 GEN8_IRQ_INIT_NDX(uncore, GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
382 * RPS interrupts will get enabled/disabled on demand when RPS itself
383 * is enabled/disabled. Same wil be the case for GuC interrupts.
385 GEN8_IRQ_INIT_NDX(uncore, GT, 2, gt->pm_imr, gt->pm_ier);
386 GEN8_IRQ_INIT_NDX(uncore, GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
389 static void gen5_gt_update_irq(struct intel_gt *gt,
390 u32 interrupt_mask,
391 u32 enabled_irq_mask)
393 lockdep_assert_held(&gt->irq_lock);
395 GEM_BUG_ON(enabled_irq_mask & ~interrupt_mask);
397 gt->gt_imr &= ~interrupt_mask;
398 gt->gt_imr |= (~enabled_irq_mask & interrupt_mask);
399 intel_uncore_write(gt->uncore, GTIMR, gt->gt_imr);
402 void gen5_gt_enable_irq(struct intel_gt *gt, u32 mask)
404 gen5_gt_update_irq(gt, mask, mask);
405 intel_uncore_posting_read_fw(gt->uncore, GTIMR);
408 void gen5_gt_disable_irq(struct intel_gt *gt, u32 mask)
410 gen5_gt_update_irq(gt, mask, 0);
413 void gen5_gt_irq_reset(struct intel_gt *gt)
415 struct intel_uncore *uncore = gt->uncore;
417 GEN3_IRQ_RESET(uncore, GT);
418 if (INTEL_GEN(gt->i915) >= 6)
419 GEN3_IRQ_RESET(uncore, GEN6_PM);
422 void gen5_gt_irq_postinstall(struct intel_gt *gt)
424 struct intel_uncore *uncore = gt->uncore;
425 u32 pm_irqs = 0;
426 u32 gt_irqs = 0;
428 gt->gt_imr = ~0;
429 if (HAS_L3_DPF(gt->i915)) {
430 /* L3 parity interrupt is always unmasked. */
431 gt->gt_imr = ~GT_PARITY_ERROR(gt->i915);
432 gt_irqs |= GT_PARITY_ERROR(gt->i915);
435 gt_irqs |= GT_RENDER_USER_INTERRUPT;
436 if (IS_GEN(gt->i915, 5))
437 gt_irqs |= ILK_BSD_USER_INTERRUPT;
438 else
439 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
441 GEN3_IRQ_INIT(uncore, GT, gt->gt_imr, gt_irqs);
443 if (INTEL_GEN(gt->i915) >= 6) {
445 * RPS interrupts will get enabled/disabled on demand when RPS
446 * itself is enabled/disabled.
448 if (HAS_ENGINE(gt->i915, VECS0)) {
449 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
450 gt->pm_ier |= PM_VEBOX_USER_INTERRUPT;
453 gt->pm_imr = 0xffffffff;
454 GEN3_IRQ_INIT(uncore, GEN6_PM, gt->pm_imr, pm_irqs);