2 * Copyright © 2016 Intel Corporation
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:
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
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
26 #include "intel_guc_submission.h"
27 #include "intel_guc.h"
30 static void guc_free_load_err_log(struct intel_guc *guc);
32 /* Reset GuC providing us with fresh state for both GuC and HuC.
34 static int __intel_uc_reset_hw(struct drm_i915_private *dev_priv)
39 ret = intel_reset_guc(dev_priv);
41 DRM_ERROR("Failed to reset GuC, ret = %d\n", ret);
45 guc_status = I915_READ(GUC_STATUS);
46 WARN(!(guc_status & GS_MIA_IN_RESET),
47 "GuC status: 0x%x, MIA core expected to be in reset\n",
53 static int __get_platform_enable_guc(struct drm_i915_private *dev_priv)
55 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
56 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
59 /* Default is to enable GuC/HuC if we know their firmwares */
60 if (intel_uc_fw_is_selected(guc_fw))
61 enable_guc |= ENABLE_GUC_SUBMISSION;
62 if (intel_uc_fw_is_selected(huc_fw))
63 enable_guc |= ENABLE_GUC_LOAD_HUC;
65 /* Any platform specific fine-tuning can be done here */
70 static int __get_default_guc_log_level(struct drm_i915_private *dev_priv)
72 int guc_log_level = 0; /* disabled */
74 /* Enable if we're running on platform with GuC and debug config */
75 if (HAS_GUC(dev_priv) && intel_uc_is_using_guc() &&
76 (IS_ENABLED(CONFIG_DRM_I915_DEBUG) ||
77 IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)))
78 guc_log_level = 1 + GUC_LOG_VERBOSITY_MAX;
80 /* Any platform specific fine-tuning can be done here */
86 * sanitize_options_early - sanitize uC related modparam options
87 * @dev_priv: device private
89 * In case of "enable_guc" option this function will attempt to modify
90 * it only if it was initially set to "auto(-1)". Default value for this
91 * modparam varies between platforms and it is hardcoded in driver code.
92 * Any other modparam value is only monitored against availability of the
93 * related hardware or firmware definitions.
95 * In case of "guc_log_level" option this function will attempt to modify
96 * it only if it was initially set to "auto(-1)" or if initial value was
97 * "enable(1..4)" on platforms without the GuC. Default value for this
98 * modparam varies between platforms and is usually set to "disable(0)"
99 * unless GuC is enabled on given platform and the driver is compiled with
100 * debug config when this modparam will default to "enable(1..4)".
102 static void sanitize_options_early(struct drm_i915_private *dev_priv)
104 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
105 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
107 /* A negative value means "use platform default" */
108 if (i915_modparams.enable_guc < 0)
109 i915_modparams.enable_guc = __get_platform_enable_guc(dev_priv);
111 DRM_DEBUG_DRIVER("enable_guc=%d (submission:%s huc:%s)\n",
112 i915_modparams.enable_guc,
113 yesno(intel_uc_is_using_guc_submission()),
114 yesno(intel_uc_is_using_huc()));
116 /* Verify GuC firmware availability */
117 if (intel_uc_is_using_guc() && !intel_uc_fw_is_selected(guc_fw)) {
118 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
119 "enable_guc", i915_modparams.enable_guc,
120 !HAS_GUC(dev_priv) ? "no GuC hardware" :
124 /* Verify HuC firmware availability */
125 if (intel_uc_is_using_huc() && !intel_uc_fw_is_selected(huc_fw)) {
126 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
127 "enable_guc", i915_modparams.enable_guc,
128 !HAS_HUC(dev_priv) ? "no HuC hardware" :
132 /* A negative value means "use platform/config default" */
133 if (i915_modparams.guc_log_level < 0)
134 i915_modparams.guc_log_level =
135 __get_default_guc_log_level(dev_priv);
137 if (i915_modparams.guc_log_level > 0 && !intel_uc_is_using_guc()) {
138 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
139 "guc_log_level", i915_modparams.guc_log_level,
140 !HAS_GUC(dev_priv) ? "no GuC hardware" :
142 i915_modparams.guc_log_level = 0;
145 if (i915_modparams.guc_log_level > 1 + GUC_LOG_VERBOSITY_MAX) {
146 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
147 "guc_log_level", i915_modparams.guc_log_level,
148 "verbosity too high");
149 i915_modparams.guc_log_level = 1 + GUC_LOG_VERBOSITY_MAX;
152 DRM_DEBUG_DRIVER("guc_log_level=%d (enabled:%s verbosity:%d)\n",
153 i915_modparams.guc_log_level,
154 yesno(i915_modparams.guc_log_level),
155 i915_modparams.guc_log_level - 1);
157 /* Make sure that sanitization was done */
158 GEM_BUG_ON(i915_modparams.enable_guc < 0);
159 GEM_BUG_ON(i915_modparams.guc_log_level < 0);
162 void intel_uc_init_early(struct drm_i915_private *dev_priv)
164 intel_guc_init_early(&dev_priv->guc);
165 intel_huc_init_early(&dev_priv->huc);
167 sanitize_options_early(dev_priv);
170 void intel_uc_init_fw(struct drm_i915_private *dev_priv)
172 if (!USES_GUC(dev_priv))
175 if (USES_HUC(dev_priv))
176 intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw);
178 intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw);
181 void intel_uc_fini_fw(struct drm_i915_private *dev_priv)
183 if (!USES_GUC(dev_priv))
186 intel_uc_fw_fini(&dev_priv->guc.fw);
188 if (USES_HUC(dev_priv))
189 intel_uc_fw_fini(&dev_priv->huc.fw);
191 guc_free_load_err_log(&dev_priv->guc);
195 * intel_uc_init_mmio - setup uC MMIO access
197 * @dev_priv: device private
199 * Setup minimal state necessary for MMIO accesses later in the
200 * initialization sequence.
202 void intel_uc_init_mmio(struct drm_i915_private *dev_priv)
204 intel_guc_init_send_regs(&dev_priv->guc);
207 static void guc_capture_load_err_log(struct intel_guc *guc)
209 if (!guc->log.vma || !i915_modparams.guc_log_level)
212 if (!guc->load_err_log)
213 guc->load_err_log = i915_gem_object_get(guc->log.vma->obj);
218 static void guc_free_load_err_log(struct intel_guc *guc)
220 if (guc->load_err_log)
221 i915_gem_object_put(guc->load_err_log);
224 int intel_uc_register(struct drm_i915_private *i915)
231 if (i915_modparams.guc_log_level)
232 ret = intel_guc_log_register(&i915->guc.log);
237 void intel_uc_unregister(struct drm_i915_private *i915)
242 if (i915_modparams.guc_log_level)
243 intel_guc_log_unregister(&i915->guc.log);
246 static int guc_enable_communication(struct intel_guc *guc)
248 struct drm_i915_private *dev_priv = guc_to_i915(guc);
250 if (HAS_GUC_CT(dev_priv))
251 return intel_guc_enable_ct(guc);
253 guc->send = intel_guc_send_mmio;
257 static void guc_disable_communication(struct intel_guc *guc)
259 struct drm_i915_private *dev_priv = guc_to_i915(guc);
261 if (HAS_GUC_CT(dev_priv))
262 intel_guc_disable_ct(guc);
264 guc->send = intel_guc_send_nop;
267 int intel_uc_init_misc(struct drm_i915_private *dev_priv)
269 struct intel_guc *guc = &dev_priv->guc;
272 if (!USES_GUC(dev_priv))
275 intel_guc_init_ggtt_pin_bias(guc);
277 ret = intel_guc_init_wq(guc);
284 void intel_uc_fini_misc(struct drm_i915_private *dev_priv)
286 struct intel_guc *guc = &dev_priv->guc;
288 if (!USES_GUC(dev_priv))
291 intel_guc_fini_wq(guc);
294 int intel_uc_init(struct drm_i915_private *dev_priv)
296 struct intel_guc *guc = &dev_priv->guc;
299 if (!USES_GUC(dev_priv))
302 if (!HAS_GUC(dev_priv))
305 ret = intel_guc_init(guc);
309 if (USES_GUC_SUBMISSION(dev_priv)) {
311 * This is stuff we need to have available at fw load time
312 * if we are planning to enable submission later
314 ret = intel_guc_submission_init(guc);
324 void intel_uc_fini(struct drm_i915_private *dev_priv)
326 struct intel_guc *guc = &dev_priv->guc;
328 if (!USES_GUC(dev_priv))
331 GEM_BUG_ON(!HAS_GUC(dev_priv));
333 if (USES_GUC_SUBMISSION(dev_priv))
334 intel_guc_submission_fini(guc);
339 void intel_uc_sanitize(struct drm_i915_private *i915)
341 struct intel_guc *guc = &i915->guc;
342 struct intel_huc *huc = &i915->huc;
347 GEM_BUG_ON(!HAS_GUC(i915));
349 guc_disable_communication(guc);
351 intel_huc_sanitize(huc);
352 intel_guc_sanitize(guc);
354 __intel_uc_reset_hw(i915);
357 int intel_uc_init_hw(struct drm_i915_private *dev_priv)
359 struct intel_guc *guc = &dev_priv->guc;
360 struct intel_huc *huc = &dev_priv->huc;
363 if (!USES_GUC(dev_priv))
366 GEM_BUG_ON(!HAS_GUC(dev_priv));
368 gen9_reset_guc_interrupts(dev_priv);
370 /* WaEnableuKernelHeaderValidFix:skl */
371 /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
372 if (IS_GEN9(dev_priv))
379 * Always reset the GuC just before (re)loading, so
380 * that the state and timing are fairly predictable
382 ret = __intel_uc_reset_hw(dev_priv);
386 if (USES_HUC(dev_priv)) {
387 ret = intel_huc_fw_upload(huc);
392 intel_guc_init_params(guc);
393 ret = intel_guc_fw_upload(guc);
394 if (ret == 0 || ret != -EAGAIN)
397 DRM_DEBUG_DRIVER("GuC fw load failed: %d; will reset and "
398 "retry %d more time(s)\n", ret, attempts);
401 /* Did we succeded or run out of retries? */
403 goto err_log_capture;
405 ret = guc_enable_communication(guc);
407 goto err_log_capture;
409 if (USES_HUC(dev_priv)) {
410 ret = intel_huc_auth(huc);
412 goto err_communication;
415 if (USES_GUC_SUBMISSION(dev_priv)) {
416 if (i915_modparams.guc_log_level)
417 gen9_enable_guc_interrupts(dev_priv);
419 ret = intel_guc_submission_enable(guc);
424 dev_info(dev_priv->drm.dev, "GuC firmware version %u.%u\n",
425 guc->fw.major_ver_found, guc->fw.minor_ver_found);
426 dev_info(dev_priv->drm.dev, "GuC submission %s\n",
427 enableddisabled(USES_GUC_SUBMISSION(dev_priv)));
428 dev_info(dev_priv->drm.dev, "HuC %s\n",
429 enableddisabled(USES_HUC(dev_priv)));
434 * We've failed to load the firmware :(
437 gen9_disable_guc_interrupts(dev_priv);
439 guc_disable_communication(guc);
441 guc_capture_load_err_log(guc);
444 * Note that there is no fallback as either user explicitly asked for
445 * the GuC or driver default option was to run with the GuC enabled.
447 if (GEM_WARN_ON(ret == -EIO))
450 dev_err(dev_priv->drm.dev, "GuC initialization failed %d\n", ret);
454 void intel_uc_fini_hw(struct drm_i915_private *dev_priv)
456 struct intel_guc *guc = &dev_priv->guc;
458 if (!USES_GUC(dev_priv))
461 GEM_BUG_ON(!HAS_GUC(dev_priv));
463 if (USES_GUC_SUBMISSION(dev_priv))
464 intel_guc_submission_disable(guc);
466 guc_disable_communication(guc);
468 if (USES_GUC_SUBMISSION(dev_priv))
469 gen9_disable_guc_interrupts(dev_priv);
472 int intel_uc_suspend(struct drm_i915_private *i915)
474 struct intel_guc *guc = &i915->guc;
480 if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
483 err = intel_guc_suspend(guc);
485 DRM_DEBUG_DRIVER("Failed to suspend GuC, err=%d", err);
489 gen9_disable_guc_interrupts(i915);
494 int intel_uc_resume(struct drm_i915_private *i915)
496 struct intel_guc *guc = &i915->guc;
502 if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
505 if (i915_modparams.guc_log_level)
506 gen9_enable_guc_interrupts(i915);
508 err = intel_guc_resume(guc);
510 DRM_DEBUG_DRIVER("Failed to resume GuC, err=%d", err);