blob: 7dfc7e07982f9af66fb3014b5e1ba4f26e64cacb [file] [log] [blame]
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +01001/*
2 * Copyright © 2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +010025#include "intel_uc.h"
Sagar Arun Kamblea2695742017-11-16 19:02:41 +053026#include "intel_guc_submission.h"
Michal Wajdeczkoddf79d82017-10-04 18:13:42 +000027#include "i915_drv.h"
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +010028
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +010029/* Reset GuC providing us with fresh state for both GuC and HuC.
30 */
31static int __intel_uc_reset_hw(struct drm_i915_private *dev_priv)
32{
33 int ret;
34 u32 guc_status;
35
Michel Thierrycb20a3c2017-10-30 11:56:14 -070036 ret = intel_reset_guc(dev_priv);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +010037 if (ret) {
Michel Thierrycb20a3c2017-10-30 11:56:14 -070038 DRM_ERROR("Failed to reset GuC, ret = %d\n", ret);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +010039 return ret;
40 }
41
42 guc_status = I915_READ(GUC_STATUS);
43 WARN(!(guc_status & GS_MIA_IN_RESET),
44 "GuC status: 0x%x, MIA core expected to be in reset\n",
45 guc_status);
46
47 return ret;
48}
49
Michal Wajdeczko121981f2017-12-06 13:53:15 +000050static int __get_platform_enable_guc(struct drm_i915_private *dev_priv)
51{
52 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
53 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
54 int enable_guc = 0;
55
56 /* Default is to enable GuC/HuC if we know their firmwares */
57 if (intel_uc_fw_is_selected(guc_fw))
58 enable_guc |= ENABLE_GUC_SUBMISSION;
59 if (intel_uc_fw_is_selected(huc_fw))
60 enable_guc |= ENABLE_GUC_LOAD_HUC;
61
62 /* Any platform specific fine-tuning can be done here */
63
64 return enable_guc;
65}
66
67/**
68 * intel_uc_sanitize_options - sanitize uC related modparam options
69 * @dev_priv: device private
70 *
71 * In case of "enable_guc" option this function will attempt to modify
72 * it only if it was initially set to "auto(-1)". Default value for this
73 * modparam varies between platforms and it is hardcoded in driver code.
74 * Any other modparam value is only monitored against availability of the
75 * related hardware or firmware definitions.
76 */
Arkadiusz Hilerd2be9f22017-03-14 15:28:10 +010077void intel_uc_sanitize_options(struct drm_i915_private *dev_priv)
78{
Michal Wajdeczko121981f2017-12-06 13:53:15 +000079 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
80 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
Arkadiusz Hilerb551f612017-03-14 15:28:13 +010081
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +000082 /* A negative value means "use platform default" */
Michal Wajdeczko121981f2017-12-06 13:53:15 +000083 if (i915_modparams.enable_guc < 0)
84 i915_modparams.enable_guc = __get_platform_enable_guc(dev_priv);
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +000085
Michal Wajdeczko121981f2017-12-06 13:53:15 +000086 DRM_DEBUG_DRIVER("enable_guc=%d (submission:%s huc:%s)\n",
87 i915_modparams.enable_guc,
88 yesno(intel_uc_is_using_guc_submission()),
89 yesno(intel_uc_is_using_huc()));
90
91 /* Verify GuC firmware availability */
92 if (intel_uc_is_using_guc() && !intel_uc_fw_is_selected(guc_fw)) {
93 DRM_WARN("Incompatible option detected: enable_guc=%d, %s!\n",
94 i915_modparams.enable_guc,
95 !HAS_GUC(dev_priv) ? "no GuC hardware" :
96 "no GuC firmware");
Arkadiusz Hilerb551f612017-03-14 15:28:13 +010097 }
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +000098
Michal Wajdeczko121981f2017-12-06 13:53:15 +000099 /* Verify HuC firmware availability */
100 if (intel_uc_is_using_huc() && !intel_uc_fw_is_selected(huc_fw)) {
101 DRM_WARN("Incompatible option detected: enable_guc=%d, %s!\n",
102 i915_modparams.enable_guc,
103 !HAS_HUC(dev_priv) ? "no HuC hardware" :
104 "no HuC firmware");
105 }
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +0000106
Michal Wajdeczko121981f2017-12-06 13:53:15 +0000107 /* Make sure that sanitization was done */
108 GEM_BUG_ON(i915_modparams.enable_guc < 0);
Arkadiusz Hilerd2be9f22017-03-14 15:28:10 +0100109}
110
Michal Wajdeczko3af7a9c2017-10-04 15:33:27 +0000111void intel_uc_init_early(struct drm_i915_private *dev_priv)
112{
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000113 intel_guc_init_early(&dev_priv->guc);
Michal Wajdeczko2fe2d4e2017-12-06 13:53:10 +0000114 intel_huc_init_early(&dev_priv->huc);
Michal Wajdeczko3af7a9c2017-10-04 15:33:27 +0000115}
116
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100117void intel_uc_init_fw(struct drm_i915_private *dev_priv)
118{
Michal Wajdeczkoa655aeb2017-12-06 13:53:13 +0000119 if (!USES_GUC(dev_priv))
120 return;
121
Michal Wajdeczkoa16b4312017-10-04 15:33:25 +0000122 intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw);
123 intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw);
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100124}
125
Oscar Mateo3950bf32017-03-22 10:39:46 -0700126void intel_uc_fini_fw(struct drm_i915_private *dev_priv)
127{
Michal Wajdeczkoa655aeb2017-12-06 13:53:13 +0000128 if (!USES_GUC(dev_priv))
129 return;
130
Michal Wajdeczkoa16b4312017-10-04 15:33:25 +0000131 intel_uc_fw_fini(&dev_priv->guc.fw);
132 intel_uc_fw_fini(&dev_priv->huc.fw);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700133}
134
Sagar Arun Kamble1fc556f2017-10-04 15:33:24 +0000135/**
136 * intel_uc_init_mmio - setup uC MMIO access
137 *
138 * @dev_priv: device private
139 *
140 * Setup minimal state necessary for MMIO accesses later in the
141 * initialization sequence.
142 */
143void intel_uc_init_mmio(struct drm_i915_private *dev_priv)
144{
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000145 intel_guc_init_send_regs(&dev_priv->guc);
Sagar Arun Kamble1fc556f2017-10-04 15:33:24 +0000146}
147
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -0700148static void guc_capture_load_err_log(struct intel_guc *guc)
149{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +0000150 if (!guc->log.vma || i915_modparams.guc_log_level < 0)
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -0700151 return;
152
153 if (!guc->load_err_log)
154 guc->load_err_log = i915_gem_object_get(guc->log.vma->obj);
155
156 return;
157}
158
159static void guc_free_load_err_log(struct intel_guc *guc)
160{
161 if (guc->load_err_log)
162 i915_gem_object_put(guc->load_err_log);
163}
164
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000165static int guc_enable_communication(struct intel_guc *guc)
166{
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000167 struct drm_i915_private *dev_priv = guc_to_i915(guc);
168
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000169 if (HAS_GUC_CT(dev_priv))
170 return intel_guc_enable_ct(guc);
171
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000172 guc->send = intel_guc_send_mmio;
173 return 0;
174}
175
176static void guc_disable_communication(struct intel_guc *guc)
177{
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000178 struct drm_i915_private *dev_priv = guc_to_i915(guc);
179
180 if (HAS_GUC_CT(dev_priv))
181 intel_guc_disable_ct(guc);
182
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000183 guc->send = intel_guc_send_nop;
184}
185
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100186int intel_uc_init_hw(struct drm_i915_private *dev_priv)
187{
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000188 struct intel_guc *guc = &dev_priv->guc;
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100189 int ret, attempts;
190
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000191 if (!USES_GUC(dev_priv))
Oscar Mateob8991402017-03-28 09:53:47 -0700192 return 0;
193
Michal Wajdeczko121981f2017-12-06 13:53:15 +0000194 if (!HAS_GUC(dev_priv)) {
195 ret = -ENODEV;
196 goto err_out;
197 }
198
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000199 guc_disable_communication(guc);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100200 gen9_reset_guc_interrupts(dev_priv);
201
202 /* We need to notify the guc whenever we change the GGTT */
203 i915_ggtt_enable_guc(dev_priv);
204
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000205 if (USES_GUC_SUBMISSION(dev_priv)) {
Oscar Mateo397fce82017-03-22 10:39:52 -0700206 /*
207 * This is stuff we need to have available at fw load time
208 * if we are planning to enable submission later
209 */
Sagar Arun Kambledb14d0c52017-11-16 19:02:39 +0530210 ret = intel_guc_submission_init(guc);
Oscar Mateo397fce82017-03-22 10:39:52 -0700211 if (ret)
212 goto err_guc;
213 }
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100214
daniele.ceraolospurio@intel.com13f6c712017-04-06 17:18:52 -0700215 /* init WOPCM */
216 I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
217 I915_WRITE(DMA_GUC_WOPCM_OFFSET,
218 GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
219
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100220 /* WaEnableuKernelHeaderValidFix:skl */
221 /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
222 if (IS_GEN9(dev_priv))
223 attempts = 3;
224 else
225 attempts = 1;
226
227 while (attempts--) {
228 /*
229 * Always reset the GuC just before (re)loading, so
230 * that the state and timing are fairly predictable
231 */
232 ret = __intel_uc_reset_hw(dev_priv);
233 if (ret)
234 goto err_submission;
235
236 intel_huc_init_hw(&dev_priv->huc);
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000237 intel_guc_init_params(guc);
Michal Wajdeczkoe8668bb2017-10-16 14:47:14 +0000238 ret = intel_guc_fw_upload(guc);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100239 if (ret == 0 || ret != -EAGAIN)
240 break;
241
242 DRM_DEBUG_DRIVER("GuC fw load failed: %d; will reset and "
243 "retry %d more time(s)\n", ret, attempts);
244 }
245
246 /* Did we succeded or run out of retries? */
247 if (ret)
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -0700248 goto err_log_capture;
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100249
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000250 ret = guc_enable_communication(guc);
251 if (ret)
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -0700252 goto err_log_capture;
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000253
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +0530254 intel_huc_auth(&dev_priv->huc);
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000255 if (USES_GUC_SUBMISSION(dev_priv)) {
Michal Wajdeczko4f044a82017-09-19 19:38:44 +0000256 if (i915_modparams.guc_log_level >= 0)
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100257 gen9_enable_guc_interrupts(dev_priv);
258
Sagar Arun Kambledb14d0c52017-11-16 19:02:39 +0530259 ret = intel_guc_submission_enable(guc);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100260 if (ret)
Oscar Mateo3950bf32017-03-22 10:39:46 -0700261 goto err_interrupts;
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100262 }
263
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000264 dev_info(dev_priv->drm.dev, "GuC firmware version %u.%u\n",
Michal Wajdeczko86ffc312017-10-16 14:47:17 +0000265 guc->fw.major_ver_found, guc->fw.minor_ver_found);
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000266 dev_info(dev_priv->drm.dev, "GuC submission %s\n",
267 enableddisabled(USES_GUC_SUBMISSION(dev_priv)));
Michal Wajdeczko86ffc312017-10-16 14:47:17 +0000268
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100269 return 0;
270
271 /*
272 * We've failed to load the firmware :(
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100273 */
Oscar Mateo3950bf32017-03-22 10:39:46 -0700274err_interrupts:
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000275 guc_disable_communication(guc);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700276 gen9_disable_guc_interrupts(dev_priv);
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -0700277err_log_capture:
278 guc_capture_load_err_log(guc);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100279err_submission:
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000280 if (USES_GUC_SUBMISSION(dev_priv))
Sagar Arun Kambledb14d0c52017-11-16 19:02:39 +0530281 intel_guc_submission_fini(guc);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700282err_guc:
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100283 i915_ggtt_disable_guc(dev_priv);
Michal Wajdeczko121981f2017-12-06 13:53:15 +0000284err_out:
285 /*
286 * Note that there is no fallback as either user explicitly asked for
287 * the GuC or driver default option was to run with the GuC enabled.
288 */
289 if (GEM_WARN_ON(ret == -EIO))
290 ret = -EINVAL;
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100291
Michal Wajdeczko121981f2017-12-06 13:53:15 +0000292 dev_err(dev_priv->drm.dev, "GuC initialization failed %d\n", ret);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100293 return ret;
294}
295
Oscar Mateo3950bf32017-03-22 10:39:46 -0700296void intel_uc_fini_hw(struct drm_i915_private *dev_priv)
297{
Sagar Arun Kambledb14d0c52017-11-16 19:02:39 +0530298 struct intel_guc *guc = &dev_priv->guc;
299
300 guc_free_load_err_log(guc);
Michel Thierryc4a89522017-06-05 10:12:51 -0700301
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000302 if (!USES_GUC(dev_priv))
Oscar Mateob8991402017-03-28 09:53:47 -0700303 return;
304
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000305 if (USES_GUC_SUBMISSION(dev_priv))
Sagar Arun Kambledb14d0c52017-11-16 19:02:39 +0530306 intel_guc_submission_disable(guc);
Michal Wajdeczko2f640852017-05-26 11:13:24 +0000307
Sagar Arun Kambledb14d0c52017-11-16 19:02:39 +0530308 guc_disable_communication(guc);
Michal Wajdeczko2f640852017-05-26 11:13:24 +0000309
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000310 if (USES_GUC_SUBMISSION(dev_priv)) {
Oscar Mateo3950bf32017-03-22 10:39:46 -0700311 gen9_disable_guc_interrupts(dev_priv);
Sagar Arun Kambledb14d0c52017-11-16 19:02:39 +0530312 intel_guc_submission_fini(guc);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700313 }
Michal Wajdeczko2f640852017-05-26 11:13:24 +0000314
Oscar Mateo3950bf32017-03-22 10:39:46 -0700315 i915_ggtt_disable_guc(dev_priv);
316}