Skip to content

Commit c62e490

Browse files
author
Jocelyn Falempe
committed
drm/i915/dg2: setup HuC loading via GSC
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2041690 Upstream Status: git://anongit.freedesktop.org/drm/drm commit 087b681 Author: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> AuthorDate: Tue Sep 27 17:41:40 2022 -0700 Commit: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> CommitDate: Mon Oct 3 11:29:16 2022 -0700 The GSC will perform both the load and the authentication, so we just need to check the auth bit after the GSC has replied. Since we require the PXP module to load the HuC, the earliest we can trigger the load is during the pxp_bind operation. Note that GSC-loaded HuC survives GT reset, so we need to just mark it as ready when we re-init the GT HW. V2: move setting of HuC fw error state to the failure path of the HuC auth function, so it covers both the legacy and new auth flows V4: 1. Fix typo in the commit message 2. style fix in intel_huc_wait_for_auth_complete() Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Reviewed-by: Alan Previn <alan.previn.teres.alexis@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220928004145.745803-11-daniele.ceraolospurio@intel.com Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
1 parent ecff121 commit c62e490

File tree

5 files changed

+77
-15
lines changed

5 files changed

+77
-15
lines changed

drivers/gpu/drm/i915/gt/uc/intel_huc.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ void intel_huc_fini(struct intel_huc *huc)
125125
intel_uc_fw_fini(&huc->fw);
126126
}
127127

128+
int intel_huc_wait_for_auth_complete(struct intel_huc *huc)
129+
{
130+
struct intel_gt *gt = huc_to_gt(huc);
131+
int ret;
132+
133+
ret = __intel_wait_for_register(gt->uncore,
134+
huc->status.reg,
135+
huc->status.mask,
136+
huc->status.value,
137+
2, 50, NULL);
138+
139+
if (ret) {
140+
drm_err(&gt->i915->drm, "HuC: Firmware not verified %d\n", ret);
141+
intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_LOAD_FAIL);
142+
return ret;
143+
}
144+
145+
intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_RUNNING);
146+
drm_info(&gt->i915->drm, "HuC authenticated\n");
147+
return 0;
148+
}
149+
128150
/**
129151
* intel_huc_auth() - Authenticate HuC uCode
130152
* @huc: intel_huc structure
@@ -161,27 +183,18 @@ int intel_huc_auth(struct intel_huc *huc)
161183
}
162184

163185
/* Check authentication status, it should be done by now */
164-
ret = __intel_wait_for_register(gt->uncore,
165-
huc->status.reg,
166-
huc->status.mask,
167-
huc->status.value,
168-
2, 50, NULL);
169-
if (ret) {
170-
DRM_ERROR("HuC: Firmware not verified %d\n", ret);
186+
ret = intel_huc_wait_for_auth_complete(huc);
187+
if (ret)
171188
goto fail;
172-
}
173189

174-
intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_RUNNING);
175-
drm_info(&gt->i915->drm, "HuC authenticated\n");
176190
return 0;
177191

178192
fail:
179193
i915_probe_error(gt->i915, "HuC: Authentication failed %d\n", ret);
180-
intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_LOAD_FAIL);
181194
return ret;
182195
}
183196

184-
static bool huc_is_authenticated(struct intel_huc *huc)
197+
bool intel_huc_is_authenticated(struct intel_huc *huc)
185198
{
186199
struct intel_gt *gt = huc_to_gt(huc);
187200
intel_wakeref_t wakeref;
@@ -223,15 +236,15 @@ int intel_huc_check_status(struct intel_huc *huc)
223236
break;
224237
}
225238

226-
return huc_is_authenticated(huc);
239+
return intel_huc_is_authenticated(huc);
227240
}
228241

229242
void intel_huc_update_auth_status(struct intel_huc *huc)
230243
{
231244
if (!intel_uc_fw_is_loadable(&huc->fw))
232245
return;
233246

234-
if (huc_is_authenticated(huc))
247+
if (intel_huc_is_authenticated(huc))
235248
intel_uc_fw_change_status(&huc->fw,
236249
INTEL_UC_FIRMWARE_RUNNING);
237250
}

drivers/gpu/drm/i915/gt/uc/intel_huc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ void intel_huc_init_early(struct intel_huc *huc);
2626
int intel_huc_init(struct intel_huc *huc);
2727
void intel_huc_fini(struct intel_huc *huc);
2828
int intel_huc_auth(struct intel_huc *huc);
29+
int intel_huc_wait_for_auth_complete(struct intel_huc *huc);
2930
int intel_huc_check_status(struct intel_huc *huc);
3031
void intel_huc_update_auth_status(struct intel_huc *huc);
32+
bool intel_huc_is_authenticated(struct intel_huc *huc);
3133

3234
static inline int intel_huc_sanitize(struct intel_huc *huc)
3335
{

drivers/gpu/drm/i915/gt/uc/intel_huc_fw.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,43 @@
33
* Copyright © 2014-2019 Intel Corporation
44
*/
55

6+
#include "gt/intel_gsc.h"
67
#include "gt/intel_gt.h"
8+
#include "intel_huc.h"
79
#include "intel_huc_fw.h"
810
#include "i915_drv.h"
11+
#include "pxp/intel_pxp_huc.h"
12+
13+
int intel_huc_fw_load_and_auth_via_gsc(struct intel_huc *huc)
14+
{
15+
int ret;
16+
17+
if (!intel_huc_is_loaded_by_gsc(huc))
18+
return -ENODEV;
19+
20+
if (!intel_uc_fw_is_loadable(&huc->fw))
21+
return -ENOEXEC;
22+
23+
/*
24+
* If we abort a suspend, HuC might still be loaded when the mei
25+
* component gets re-bound and this function called again. If so, just
26+
* mark the HuC as loaded.
27+
*/
28+
if (intel_huc_is_authenticated(huc)) {
29+
intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_RUNNING);
30+
return 0;
31+
}
32+
33+
GEM_WARN_ON(intel_uc_fw_is_loaded(&huc->fw));
34+
35+
ret = intel_pxp_huc_load_and_auth(&huc_to_gt(huc)->pxp);
36+
if (ret)
37+
return ret;
38+
39+
intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_TRANSFERRED);
40+
41+
return intel_huc_wait_for_auth_complete(huc);
42+
}
943

1044
/**
1145
* intel_huc_fw_upload() - load HuC uCode to device via DMA transfer

drivers/gpu/drm/i915/gt/uc/intel_huc_fw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
struct intel_huc;
1010

11+
int intel_huc_fw_load_and_auth_via_gsc(struct intel_huc *huc);
1112
int intel_huc_fw_upload(struct intel_huc *huc);
1213

1314
#endif

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "intel_pxp_session.h"
1616
#include "intel_pxp_tee.h"
1717
#include "intel_pxp_tee_interface.h"
18+
#include "intel_pxp_huc.h"
1819

1920
static inline struct intel_pxp *i915_dev_to_pxp(struct device *i915_kdev)
2021
{
@@ -127,13 +128,24 @@ static int i915_pxp_tee_component_bind(struct device *i915_kdev,
127128
{
128129
struct drm_i915_private *i915 = kdev_to_i915(i915_kdev);
129130
struct intel_pxp *pxp = i915_dev_to_pxp(i915_kdev);
131+
struct intel_uc *uc = &pxp_to_gt(pxp)->uc;
130132
intel_wakeref_t wakeref;
133+
int ret = 0;
131134

132135
mutex_lock(&pxp->tee_mutex);
133136
pxp->pxp_component = data;
134137
pxp->pxp_component->tee_dev = tee_kdev;
135138
mutex_unlock(&pxp->tee_mutex);
136139

140+
if (intel_uc_uses_huc(uc) && intel_huc_is_loaded_by_gsc(&uc->huc)) {
141+
with_intel_runtime_pm(&i915->runtime_pm, wakeref) {
142+
/* load huc via pxp */
143+
ret = intel_huc_fw_load_and_auth_via_gsc(&uc->huc);
144+
if (ret < 0)
145+
drm_err(&i915->drm, "failed to load huc via gsc %d\n", ret);
146+
}
147+
}
148+
137149
/* if we are suspended, the HW will be re-initialized on resume */
138150
wakeref = intel_runtime_pm_get_if_in_use(&i915->runtime_pm);
139151
if (!wakeref)
@@ -145,7 +157,7 @@ static int i915_pxp_tee_component_bind(struct device *i915_kdev,
145157

146158
intel_runtime_pm_put(&i915->runtime_pm, wakeref);
147159

148-
return 0;
160+
return ret;
149161
}
150162

151163
static void i915_pxp_tee_component_unbind(struct device *i915_kdev,

0 commit comments

Comments
 (0)