intel_pxp_irq.c 2.6 KB
Newer Older
1 2 3 4 5
// SPDX-License-Identifier: MIT
/*
 * Copyright(c) 2020 Intel Corporation.
 */
#include <linux/workqueue.h>
6

7
#include "gt/intel_gt_irq.h"
8
#include "gt/intel_gt_regs.h"
9
#include "gt/intel_gt_types.h"
10

11 12
#include "i915_irq.h"
#include "i915_reg.h"
13 14 15 16 17

#include "intel_pxp.h"
#include "intel_pxp_irq.h"
#include "intel_pxp_session.h"
#include "intel_pxp_types.h"
18
#include "intel_runtime_pm.h"
19 20 21 22 23 24 25 26

/**
 * intel_pxp_irq_handler - Handles PXP interrupts.
 * @pxp: pointer to pxp struct
 * @iir: interrupt vector
 */
void intel_pxp_irq_handler(struct intel_pxp *pxp, u16 iir)
{
27
	struct intel_gt *gt;
28 29 30 31

	if (GEM_WARN_ON(!intel_pxp_is_enabled(pxp)))
		return;

32 33
	gt = pxp->ctrl_gt;

34
	lockdep_assert_held(gt->irq_lock);
35 36 37 38 39 40 41 42

	if (unlikely(!iir))
		return;

	if (iir & (GEN12_DISPLAY_PXP_STATE_TERMINATED_INTERRUPT |
		   GEN12_DISPLAY_APP_TERMINATED_PER_FW_REQ_INTERRUPT)) {
		/* immediately mark PXP as inactive on termination */
		intel_pxp_mark_termination_in_progress(pxp);
43
		pxp->session_events |= PXP_TERMINATION_REQUEST | PXP_INVAL_REQUIRED;
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
	}

	if (iir & GEN12_DISPLAY_STATE_RESET_COMPLETE_INTERRUPT)
		pxp->session_events |= PXP_TERMINATION_COMPLETE;

	if (pxp->session_events)
		queue_work(system_unbound_wq, &pxp->session_work);
}

static inline void __pxp_set_interrupts(struct intel_gt *gt, u32 interrupts)
{
	struct intel_uncore *uncore = gt->uncore;
	const u32 mask = interrupts << 16;

	intel_uncore_write(uncore, GEN11_CRYPTO_RSVD_INTR_ENABLE, mask);
	intel_uncore_write(uncore, GEN11_CRYPTO_RSVD_INTR_MASK,  ~mask);
}

static inline void pxp_irq_reset(struct intel_gt *gt)
{
64
	spin_lock_irq(gt->irq_lock);
65
	gen11_gt_reset_one_iir(gt, 0, GEN11_KCR);
66
	spin_unlock_irq(gt->irq_lock);
67 68 69 70
}

void intel_pxp_irq_enable(struct intel_pxp *pxp)
{
71
	struct intel_gt *gt = pxp->ctrl_gt;
72

73
	spin_lock_irq(gt->irq_lock);
74 75 76 77 78 79 80

	if (!pxp->irq_enabled)
		WARN_ON_ONCE(gen11_gt_reset_one_iir(gt, 0, GEN11_KCR));

	__pxp_set_interrupts(gt, GEN12_PXP_INTERRUPTS);
	pxp->irq_enabled = true;

81
	spin_unlock_irq(gt->irq_lock);
82 83 84 85
}

void intel_pxp_irq_disable(struct intel_pxp *pxp)
{
86
	struct intel_gt *gt = pxp->ctrl_gt;
87 88 89 90 91 92 93 94 95 96

	/*
	 * We always need to submit a global termination when we re-enable the
	 * interrupts, so there is no need to make sure that the session state
	 * makes sense at the end of this function. Just make sure this is not
	 * called in a path were the driver consider the session as valid and
	 * doesn't call a termination on restart.
	 */
	GEM_WARN_ON(intel_pxp_is_active(pxp));

97
	spin_lock_irq(gt->irq_lock);
98 99 100 101

	pxp->irq_enabled = false;
	__pxp_set_interrupts(gt, 0);

102
	spin_unlock_irq(gt->irq_lock);
103 104 105 106 107 108
	intel_synchronize_irq(gt->i915);

	pxp_irq_reset(gt);

	flush_work(&pxp->session_work);
}