1 // SPDX-License-Identifier: MIT
3 * Copyright(c) 2020 Intel Corporation.
5 #include <linux/workqueue.h>
7 #include "intel_pxp_irq.h"
8 #include "intel_pxp_session.h"
9 #include "gt/intel_gt_irq.h"
10 #include "gt/intel_gt_regs.h"
11 #include "gt/intel_gt_types.h"
14 #include "intel_runtime_pm.h"
17 * intel_pxp_irq_handler - Handles PXP interrupts.
18 * @pxp: pointer to pxp struct
19 * @iir: interrupt vector
21 void intel_pxp_irq_handler(struct intel_pxp *pxp, u16 iir)
23 struct intel_gt *gt = pxp_to_gt(pxp);
25 if (GEM_WARN_ON(!intel_pxp_is_enabled(pxp)))
28 lockdep_assert_held(>->irq_lock);
33 if (iir & (GEN12_DISPLAY_PXP_STATE_TERMINATED_INTERRUPT |
34 GEN12_DISPLAY_APP_TERMINATED_PER_FW_REQ_INTERRUPT)) {
35 /* immediately mark PXP as inactive on termination */
36 intel_pxp_mark_termination_in_progress(pxp);
37 pxp->session_events |= PXP_TERMINATION_REQUEST | PXP_INVAL_REQUIRED;
40 if (iir & GEN12_DISPLAY_STATE_RESET_COMPLETE_INTERRUPT)
41 pxp->session_events |= PXP_TERMINATION_COMPLETE;
43 if (pxp->session_events)
44 queue_work(system_unbound_wq, &pxp->session_work);
47 static inline void __pxp_set_interrupts(struct intel_gt *gt, u32 interrupts)
49 struct intel_uncore *uncore = gt->uncore;
50 const u32 mask = interrupts << 16;
52 intel_uncore_write(uncore, GEN11_CRYPTO_RSVD_INTR_ENABLE, mask);
53 intel_uncore_write(uncore, GEN11_CRYPTO_RSVD_INTR_MASK, ~mask);
56 static inline void pxp_irq_reset(struct intel_gt *gt)
58 spin_lock_irq(>->irq_lock);
59 gen11_gt_reset_one_iir(gt, 0, GEN11_KCR);
60 spin_unlock_irq(>->irq_lock);
63 void intel_pxp_irq_enable(struct intel_pxp *pxp)
65 struct intel_gt *gt = pxp_to_gt(pxp);
67 spin_lock_irq(>->irq_lock);
69 if (!pxp->irq_enabled)
70 WARN_ON_ONCE(gen11_gt_reset_one_iir(gt, 0, GEN11_KCR));
72 __pxp_set_interrupts(gt, GEN12_PXP_INTERRUPTS);
73 pxp->irq_enabled = true;
75 spin_unlock_irq(>->irq_lock);
78 void intel_pxp_irq_disable(struct intel_pxp *pxp)
80 struct intel_gt *gt = pxp_to_gt(pxp);
83 * We always need to submit a global termination when we re-enable the
84 * interrupts, so there is no need to make sure that the session state
85 * makes sense at the end of this function. Just make sure this is not
86 * called in a path were the driver consider the session as valid and
87 * doesn't call a termination on restart.
89 GEM_WARN_ON(intel_pxp_is_active(pxp));
91 spin_lock_irq(>->irq_lock);
93 pxp->irq_enabled = false;
94 __pxp_set_interrupts(gt, 0);
96 spin_unlock_irq(>->irq_lock);
97 intel_synchronize_irq(gt->i915);
101 flush_work(&pxp->session_work);