1
2
3
4
5
6#include <linux/types.h>
7
8#include "gt/intel_gt.h"
9#include "intel_huc.h"
10#include "i915_drv.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40void intel_huc_init_early(struct intel_huc *huc)
41{
42 struct drm_i915_private *i915 = huc_to_gt(huc)->i915;
43
44 intel_huc_fw_init_early(huc);
45
46 if (INTEL_GEN(i915) >= 11) {
47 huc->status.reg = GEN11_HUC_KERNEL_LOAD_INFO;
48 huc->status.mask = HUC_LOAD_SUCCESSFUL;
49 huc->status.value = HUC_LOAD_SUCCESSFUL;
50 } else {
51 huc->status.reg = HUC_STATUS2;
52 huc->status.mask = HUC_FW_VERIFIED;
53 huc->status.value = HUC_FW_VERIFIED;
54 }
55}
56
57static int intel_huc_rsa_data_create(struct intel_huc *huc)
58{
59 struct intel_gt *gt = huc_to_gt(huc);
60 struct intel_guc *guc = >->uc.guc;
61 struct i915_vma *vma;
62 size_t copied;
63 void *vaddr;
64 int err;
65
66 err = i915_inject_probe_error(gt->i915, -ENXIO);
67 if (err)
68 return err;
69
70
71
72
73
74
75
76
77
78
79
80 GEM_BUG_ON(huc->fw.rsa_size > PAGE_SIZE);
81 vma = intel_guc_allocate_vma(guc, PAGE_SIZE);
82 if (IS_ERR(vma))
83 return PTR_ERR(vma);
84
85 vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB);
86 if (IS_ERR(vaddr)) {
87 i915_vma_unpin_and_release(&vma, 0);
88 return PTR_ERR(vaddr);
89 }
90
91 copied = intel_uc_fw_copy_rsa(&huc->fw, vaddr, vma->size);
92 GEM_BUG_ON(copied < huc->fw.rsa_size);
93
94 i915_gem_object_unpin_map(vma->obj);
95
96 huc->rsa_data = vma;
97
98 return 0;
99}
100
101static void intel_huc_rsa_data_destroy(struct intel_huc *huc)
102{
103 i915_vma_unpin_and_release(&huc->rsa_data, 0);
104}
105
106int intel_huc_init(struct intel_huc *huc)
107{
108 struct drm_i915_private *i915 = huc_to_gt(huc)->i915;
109 int err;
110
111 err = intel_uc_fw_init(&huc->fw);
112 if (err)
113 goto out;
114
115
116
117
118
119
120 err = intel_huc_rsa_data_create(huc);
121 if (err)
122 goto out_fini;
123
124 intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_LOADABLE);
125
126 return 0;
127
128out_fini:
129 intel_uc_fw_fini(&huc->fw);
130out:
131 i915_probe_error(i915, "failed with %d\n", err);
132 return err;
133}
134
135void intel_huc_fini(struct intel_huc *huc)
136{
137 if (!intel_uc_fw_is_loadable(&huc->fw))
138 return;
139
140 intel_huc_rsa_data_destroy(huc);
141 intel_uc_fw_fini(&huc->fw);
142}
143
144
145
146
147
148
149
150
151
152
153
154int intel_huc_auth(struct intel_huc *huc)
155{
156 struct intel_gt *gt = huc_to_gt(huc);
157 struct intel_guc *guc = >->uc.guc;
158 int ret;
159
160 GEM_BUG_ON(intel_huc_is_authenticated(huc));
161
162 if (!intel_uc_fw_is_loaded(&huc->fw))
163 return -ENOEXEC;
164
165 ret = i915_inject_probe_error(gt->i915, -ENXIO);
166 if (ret)
167 goto fail;
168
169 ret = intel_guc_auth_huc(guc,
170 intel_guc_ggtt_offset(guc, huc->rsa_data));
171 if (ret) {
172 DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
173 goto fail;
174 }
175
176
177 ret = __intel_wait_for_register(gt->uncore,
178 huc->status.reg,
179 huc->status.mask,
180 huc->status.value,
181 2, 50, NULL);
182 if (ret) {
183 DRM_ERROR("HuC: Firmware not verified %d\n", ret);
184 goto fail;
185 }
186
187 intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_RUNNING);
188 return 0;
189
190fail:
191 i915_probe_error(gt->i915, "HuC: Authentication failed %d\n", ret);
192 intel_uc_fw_change_status(&huc->fw, INTEL_UC_FIRMWARE_FAIL);
193 return ret;
194}
195
196
197
198
199
200
201
202
203
204
205
206
207int intel_huc_check_status(struct intel_huc *huc)
208{
209 struct intel_gt *gt = huc_to_gt(huc);
210 intel_wakeref_t wakeref;
211 u32 status = 0;
212
213 if (!intel_huc_is_supported(huc))
214 return -ENODEV;
215
216 with_intel_runtime_pm(gt->uncore->rpm, wakeref)
217 status = intel_uncore_read(gt->uncore, huc->status.reg);
218
219 return (status & huc->status.mask) == huc->status.value;
220}
221