1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright(c) 2020, Intel Corporation. All rights reserved.
4  */
5 
6 #ifndef __INTEL_PXP_TYPES_H__
7 #define __INTEL_PXP_TYPES_H__
8 
9 #include <linux/completion.h>
10 #include <linux/mutex.h>
11 #include <linux/types.h>
12 #include <linux/workqueue.h>
13 
14 struct intel_context;
15 struct intel_gt;
16 struct i915_pxp_component;
17 struct drm_i915_private;
18 
19 /**
20  * struct intel_pxp - pxp state
21  */
22 struct intel_pxp {
23 	/**
24 	 * @ctrl_gt: poiner to the tile that owns the controls for PXP subsystem assets that
25 	 * the VDBOX, the KCR engine (and GSC CS depending on the platform)
26 	 */
27 	struct intel_gt *ctrl_gt;
28 
29 	/**
30 	 * @pxp_component: i915_pxp_component struct of the bound mei_pxp
31 	 * module. Only set and cleared inside component bind/unbind functions,
32 	 * which are protected by &tee_mutex.
33 	 */
34 	struct i915_pxp_component *pxp_component;
35 	/**
36 	 * @pxp_component_added: track if the pxp component has been added.
37 	 * Set and cleared in tee init and fini functions respectively.
38 	 */
39 	bool pxp_component_added;
40 
41 	/** @ce: kernel-owned context used for PXP operations */
42 	struct intel_context *ce;
43 
44 	/** @arb_mutex: protects arb session start */
45 	struct mutex arb_mutex;
46 	/**
47 	 * @arb_is_valid: tracks arb session status.
48 	 * After a teardown, the arb session can still be in play on the HW
49 	 * even if the keys are gone, so we can't rely on the HW state of the
50 	 * session to know if it's valid and need to track the status in SW.
51 	 */
52 	bool arb_is_valid;
53 
54 	/**
55 	 * @key_instance: tracks which key instance we're on, so we can use it
56 	 * to determine if an object was created using the current key or a
57 	 * previous one.
58 	 */
59 	u32 key_instance;
60 
61 	/** @tee_mutex: protects the tee channel binding and messaging. */
62 	struct mutex tee_mutex;
63 
64 	/** @stream_cmd: LMEM obj used to send stream PXP commands to the GSC */
65 	struct {
66 		struct drm_i915_gem_object *obj; /* contains PXP command memory */
67 		void *vaddr; /* virtual memory for PXP command */
68 	} stream_cmd;
69 
70 	/**
71 	 * @hw_state_invalidated: if the HW perceives an attack on the integrity
72 	 * of the encryption it will invalidate the keys and expect SW to
73 	 * re-initialize the session. We keep track of this state to make sure
74 	 * we only re-start the arb session when required.
75 	 */
76 	bool hw_state_invalidated;
77 
78 	/** @irq_enabled: tracks the status of the kcr irqs */
79 	bool irq_enabled;
80 	/**
81 	 * @termination: tracks the status of a pending termination. Only
82 	 * re-initialized under gt->irq_lock and completed in &session_work.
83 	 */
84 	struct completion termination;
85 
86 	/** @session_work: worker that manages session events. */
87 	struct work_struct session_work;
88 	/** @session_events: pending session events, protected with gt->irq_lock. */
89 	u32 session_events;
90 #define PXP_TERMINATION_REQUEST  BIT(0)
91 #define PXP_TERMINATION_COMPLETE BIT(1)
92 #define PXP_INVAL_REQUIRED       BIT(2)
93 };
94 
95 #endif /* __INTEL_PXP_TYPES_H__ */
96