Skip to content

Commit ad239f8

Browse files
author
Jocelyn Falempe
committed
drm/i915/pxp: implement function for sending tee stream command
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2041690 Upstream Status: git://anongit.freedesktop.org/drm/drm commit 9058f9d Author: Vitaly Lubart <vitaly.lubart@intel.com> AuthorDate: Tue Sep 27 17:41:38 2022 -0700 Commit: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> CommitDate: Mon Oct 3 11:29:14 2022 -0700 Command to be sent via the stream interface are written to a local memory page, whose address is then provided to the GSC. The interface supports providing a full sg with multiple pages for both input and output messages, but since for now we only aim to support short and synchronous messages we can use a single page for both input and output. Note that the mei interface expects an sg of 4k pages, while our lmem pages are 64k. If we ever need to support more than 4k we'll need to convert. Added a TODO comment to the code to record this. Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Cc: Alan Previn <alan.previn.teres.alexis@intel.com> Reviewed-by: Alan Previn <alan.previn.teres.alexis@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220928004145.745803-9-daniele.ceraolospurio@intel.com Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
1 parent 50ef4f9 commit ad239f8

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

drivers/gpu/drm/i915/pxp/intel_pxp_tee.c

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <drm/i915_pxp_tee_interface.h>
99
#include <drm/i915_component.h>
1010

11+
#include "gem/i915_gem_lmem.h"
12+
1113
#include "i915_drv.h"
1214
#include "intel_pxp.h"
1315
#include "intel_pxp_session.h"
@@ -69,6 +71,47 @@ static int intel_pxp_tee_io_message(struct intel_pxp *pxp,
6971
return ret;
7072
}
7173

74+
int intel_pxp_tee_stream_message(struct intel_pxp *pxp,
75+
u8 client_id, u32 fence_id,
76+
void *msg_in, size_t msg_in_len,
77+
void *msg_out, size_t msg_out_len)
78+
{
79+
/* TODO: for bigger objects we need to use a sg of 4k pages */
80+
const size_t max_msg_size = PAGE_SIZE;
81+
struct drm_i915_private *i915 = pxp_to_gt(pxp)->i915;
82+
struct i915_pxp_component *pxp_component = pxp->pxp_component;
83+
unsigned int offset = 0;
84+
struct scatterlist *sg;
85+
int ret;
86+
87+
if (msg_in_len > max_msg_size || msg_out_len > max_msg_size)
88+
return -ENOSPC;
89+
90+
mutex_lock(&pxp->tee_mutex);
91+
92+
if (unlikely(!pxp_component || !pxp_component->ops->gsc_command)) {
93+
ret = -ENODEV;
94+
goto unlock;
95+
}
96+
97+
GEM_BUG_ON(!pxp->stream_cmd.obj);
98+
99+
sg = i915_gem_object_get_sg_dma(pxp->stream_cmd.obj, 0, &offset);
100+
101+
memcpy(pxp->stream_cmd.vaddr, msg_in, msg_in_len);
102+
103+
ret = pxp_component->ops->gsc_command(pxp_component->tee_dev, client_id,
104+
fence_id, sg, msg_in_len, sg);
105+
if (ret < 0)
106+
drm_err(&i915->drm, "Failed to send PXP TEE gsc command\n");
107+
else
108+
memcpy(msg_out, pxp->stream_cmd.vaddr, msg_out_len);
109+
110+
unlock:
111+
mutex_unlock(&pxp->tee_mutex);
112+
return ret;
113+
}
114+
72115
/**
73116
* i915_pxp_tee_component_bind - bind function to pass the function pointers to pxp_tee
74117
* @i915_kdev: pointer to i915 kernel device
@@ -126,6 +169,66 @@ static const struct component_ops i915_pxp_tee_component_ops = {
126169
.unbind = i915_pxp_tee_component_unbind,
127170
};
128171

172+
static int alloc_streaming_command(struct intel_pxp *pxp)
173+
{
174+
struct drm_i915_private *i915 = pxp_to_gt(pxp)->i915;
175+
struct drm_i915_gem_object *obj = NULL;
176+
void *cmd;
177+
int err;
178+
179+
pxp->stream_cmd.obj = NULL;
180+
pxp->stream_cmd.vaddr = NULL;
181+
182+
if (!IS_DGFX(i915))
183+
return 0;
184+
185+
/* allocate lmem object of one page for PXP command memory and store it */
186+
obj = i915_gem_object_create_lmem(i915, PAGE_SIZE, I915_BO_ALLOC_CONTIGUOUS);
187+
if (IS_ERR(obj)) {
188+
drm_err(&i915->drm, "Failed to allocate pxp streaming command!\n");
189+
return PTR_ERR(obj);
190+
}
191+
192+
err = i915_gem_object_pin_pages_unlocked(obj);
193+
if (err) {
194+
drm_err(&i915->drm, "Failed to pin gsc message page!\n");
195+
goto out_put;
196+
}
197+
198+
/* map the lmem into the virtual memory pointer */
199+
cmd = i915_gem_object_pin_map_unlocked(obj, i915_coherent_map_type(i915, obj, true));
200+
if (IS_ERR(cmd)) {
201+
drm_err(&i915->drm, "Failed to map gsc message page!\n");
202+
err = PTR_ERR(cmd);
203+
goto out_unpin;
204+
}
205+
206+
memset(cmd, 0, obj->base.size);
207+
208+
pxp->stream_cmd.obj = obj;
209+
pxp->stream_cmd.vaddr = cmd;
210+
211+
return 0;
212+
213+
out_unpin:
214+
i915_gem_object_unpin_pages(obj);
215+
out_put:
216+
i915_gem_object_put(obj);
217+
return err;
218+
}
219+
220+
static void free_streaming_command(struct intel_pxp *pxp)
221+
{
222+
struct drm_i915_gem_object *obj = fetch_and_zero(&pxp->stream_cmd.obj);
223+
224+
if (!obj)
225+
return;
226+
227+
i915_gem_object_unpin_map(obj);
228+
i915_gem_object_unpin_pages(obj);
229+
i915_gem_object_put(obj);
230+
}
231+
129232
int intel_pxp_tee_component_init(struct intel_pxp *pxp)
130233
{
131234
int ret;
@@ -134,16 +237,24 @@ int intel_pxp_tee_component_init(struct intel_pxp *pxp)
134237

135238
mutex_init(&pxp->tee_mutex);
136239

240+
ret = alloc_streaming_command(pxp);
241+
if (ret)
242+
return ret;
243+
137244
ret = component_add_typed(i915->drm.dev, &i915_pxp_tee_component_ops,
138245
I915_COMPONENT_PXP);
139246
if (ret < 0) {
140247
drm_err(&i915->drm, "Failed to add PXP component (%d)\n", ret);
141-
return ret;
248+
goto out_free;
142249
}
143250

144251
pxp->pxp_component_added = true;
145252

146253
return 0;
254+
255+
out_free:
256+
free_streaming_command(pxp);
257+
return ret;
147258
}
148259

149260
void intel_pxp_tee_component_fini(struct intel_pxp *pxp)
@@ -155,6 +266,8 @@ void intel_pxp_tee_component_fini(struct intel_pxp *pxp)
155266

156267
component_del(i915->drm.dev, &i915_pxp_tee_component_ops);
157268
pxp->pxp_component_added = false;
269+
270+
free_streaming_command(pxp);
158271
}
159272

160273
int intel_pxp_tee_cmd_create_arb_session(struct intel_pxp *pxp,

drivers/gpu/drm/i915/pxp/intel_pxp_tee.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ void intel_pxp_tee_component_fini(struct intel_pxp *pxp);
1414
int intel_pxp_tee_cmd_create_arb_session(struct intel_pxp *pxp,
1515
int arb_session_id);
1616

17+
int intel_pxp_tee_stream_message(struct intel_pxp *pxp,
18+
u8 client_id, u32 fence_id,
19+
void *msg_in, size_t msg_in_len,
20+
void *msg_out, size_t msg_out_len);
21+
1722
#endif /* __INTEL_PXP_TEE_H__ */

drivers/gpu/drm/i915/pxp/intel_pxp_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ struct intel_pxp {
5353
/** @tee_mutex: protects the tee channel binding and messaging. */
5454
struct mutex tee_mutex;
5555

56+
/** @stream_cmd: LMEM obj used to send stream PXP commands to the GSC */
57+
struct {
58+
struct drm_i915_gem_object *obj; /* contains PXP command memory */
59+
void *vaddr; /* virtual memory for PXP command */
60+
} stream_cmd;
61+
5662
/**
5763
* @hw_state_invalidated: if the HW perceives an attack on the integrity
5864
* of the encryption it will invalidate the keys and expect SW to

0 commit comments

Comments
 (0)