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 	 * @platform_cfg_is_bad: used to track if any prior arb session creation resulted
31 	 * in a failure that was caused by a platform configuration issue, meaning that
32 	 * failure will not get resolved without a change to the platform (not kernel)
33 	 * such as BIOS configuration, firwmware update, etc. This bool gets reflected when
34 	 * GET_PARAM:I915_PARAM_PXP_STATUS is called.
35 	 */
36 	bool platform_cfg_is_bad;
37 
38 	/**
39 	 * @kcr_base: base mmio offset for the KCR engine which is different on legacy platforms
40 	 * vs newer platforms where the KCR is inside the media-tile.
41 	 */
42 	u32 kcr_base;
43 
44 	/**
45 	 * @gsccs_res: resources for request submission for platforms that have a GSC engine.
46 	 */
47 	struct gsccs_session_resources {
48 		u64 host_session_handle; /* used by firmware to link commands to sessions */
49 		struct intel_context *ce; /* context for gsc command submission */
50 
51 		struct i915_vma *pkt_vma; /* GSC FW cmd packet vma */
52 		void *pkt_vaddr;  /* GSC FW cmd packet virt pointer */
53 
54 		struct i915_vma *bb_vma; /* HECI_PKT batch buffer vma */
55 		void *bb_vaddr; /* HECI_PKT batch buffer virt pointer */
56 	} gsccs_res;
57 
58 	/**
59 	 * @pxp_component: i915_pxp_component struct of the bound mei_pxp
60 	 * module. Only set and cleared inside component bind/unbind functions,
61 	 * which are protected by &tee_mutex.
62 	 */
63 	struct i915_pxp_component *pxp_component;
64 
65 	/**
66 	 * @dev_link: Enforce module relationship for power management ordering.
67 	 */
68 	struct device_link *dev_link;
69 	/**
70 	 * @pxp_component_added: track if the pxp component has been added.
71 	 * Set and cleared in tee init and fini functions respectively.
72 	 */
73 	bool pxp_component_added;
74 
75 	/** @ce: kernel-owned context used for PXP operations */
76 	struct intel_context *ce;
77 
78 	/** @arb_mutex: protects arb session start */
79 	struct mutex arb_mutex;
80 	/**
81 	 * @arb_is_valid: tracks arb session status.
82 	 * After a teardown, the arb session can still be in play on the HW
83 	 * even if the keys are gone, so we can't rely on the HW state of the
84 	 * session to know if it's valid and need to track the status in SW.
85 	 */
86 	bool arb_is_valid;
87 
88 	/**
89 	 * @key_instance: tracks which key instance we're on, so we can use it
90 	 * to determine if an object was created using the current key or a
91 	 * previous one.
92 	 */
93 	u32 key_instance;
94 
95 	/** @tee_mutex: protects the tee channel binding and messaging. */
96 	struct mutex tee_mutex;
97 
98 	/** @stream_cmd: LMEM obj used to send stream PXP commands to the GSC */
99 	struct {
100 		struct drm_i915_gem_object *obj; /* contains PXP command memory */
101 		void *vaddr; /* virtual memory for PXP command */
102 	} stream_cmd;
103 
104 	/**
105 	 * @hw_state_invalidated: if the HW perceives an attack on the integrity
106 	 * of the encryption it will invalidate the keys and expect SW to
107 	 * re-initialize the session. We keep track of this state to make sure
108 	 * we only re-start the arb session when required.
109 	 */
110 	bool hw_state_invalidated;
111 
112 	/** @irq_enabled: tracks the status of the kcr irqs */
113 	bool irq_enabled;
114 	/**
115 	 * @termination: tracks the status of a pending termination. Only
116 	 * re-initialized under gt->irq_lock and completed in &session_work.
117 	 */
118 	struct completion termination;
119 
120 	/** @session_work: worker that manages session events. */
121 	struct work_struct session_work;
122 	/** @session_events: pending session events, protected with gt->irq_lock. */
123 	u32 session_events;
124 #define PXP_TERMINATION_REQUEST  BIT(0)
125 #define PXP_TERMINATION_COMPLETE BIT(1)
126 #define PXP_INVAL_REQUIRED       BIT(2)
127 #define PXP_EVENT_TYPE_IRQ       BIT(3)
128 };
129 
130 #endif /* __INTEL_PXP_TYPES_H__ */
131