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