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/list.h>
11 #include <linux/mutex.h>
12 #include <linux/spinlock.h>
13 #include <linux/types.h>
14 #include <linux/workqueue.h>
15 
16 struct intel_context;
17 struct i915_pxp_component;
18 
19 /**
20  * struct intel_pxp - pxp state
21  */
22 struct intel_pxp {
23 	/**
24 	 * @pxp_component: i915_pxp_component struct of the bound mei_pxp
25 	 * module. Only set and cleared inside component bind/unbind functions,
26 	 * which are protected by &tee_mutex.
27 	 */
28 	struct i915_pxp_component *pxp_component;
29 	/**
30 	 * @pxp_component_added: track if the pxp component has been added.
31 	 * Set and cleared in tee init and fini functions respectively.
32 	 */
33 	bool pxp_component_added;
34 
35 	/** @ce: kernel-owned context used for PXP operations */
36 	struct intel_context *ce;
37 
38 	/** @arb_mutex: protects arb session start */
39 	struct mutex arb_mutex;
40 	/**
41 	 * @arb_is_valid: tracks arb session status.
42 	 * After a teardown, the arb session can still be in play on the HW
43 	 * even if the keys are gone, so we can't rely on the HW state of the
44 	 * session to know if it's valid and need to track the status in SW.
45 	 */
46 	bool arb_is_valid;
47 
48 	/**
49 	 * @key_instance: tracks which key instance we're on, so we can use it
50 	 * to determine if an object was created using the current key or a
51 	 * previous one.
52 	 */
53 	u32 key_instance;
54 
55 	/** @tee_mutex: protects the tee channel binding and messaging. */
56 	struct mutex tee_mutex;
57 
58 	/**
59 	 * @hw_state_invalidated: if the HW perceives an attack on the integrity
60 	 * of the encryption it will invalidate the keys and expect SW to
61 	 * re-initialize the session. We keep track of this state to make sure
62 	 * we only re-start the arb session when required.
63 	 */
64 	bool hw_state_invalidated;
65 
66 	/** @irq_enabled: tracks the status of the kcr irqs */
67 	bool irq_enabled;
68 	/**
69 	 * @termination: tracks the status of a pending termination. Only
70 	 * re-initialized under gt->irq_lock and completed in &session_work.
71 	 */
72 	struct completion termination;
73 
74 	/** @session_work: worker that manages session events. */
75 	struct work_struct session_work;
76 	/** @session_events: pending session events, protected with gt->irq_lock. */
77 	u32 session_events;
78 #define PXP_TERMINATION_REQUEST  BIT(0)
79 #define PXP_TERMINATION_COMPLETE BIT(1)
80 #define PXP_INVAL_REQUIRED       BIT(2)
81 };
82 
83 #endif /* __INTEL_PXP_TYPES_H__ */
84