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)
74 if (!HAS_GUC(dev_priv) || !intel_uc_is_using_guc())
75 guc_log_level = GUC_LOG_LEVEL_DISABLED;
76 else if (IS_ENABLED(CONFIG_DRM_I915_DEBUG) ||
77 IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
78 guc_log_level = GUC_LOG_LEVEL_MAX;
80 guc_log_level = GUC_LOG_LEVEL_NON_VERBOSE;
82 /* Any platform specific fine-tuning can be done here */
88 * sanitize_options_early - sanitize uC related modparam options
89 * @dev_priv: device private
91 * In case of "enable_guc" option this function will attempt to modify
92 * it only if it was initially set to "auto(-1)". Default value for this
93 * modparam varies between platforms and it is hardcoded in driver code.
94 * Any other modparam value is only monitored against availability of the
95 * related hardware or firmware definitions.
97 * In case of "guc_log_level" option this function will attempt to modify
98 * it only if it was initially set to "auto(-1)" or if initial value was
99 * "enable(1..4)" on platforms without the GuC. Default value for this
100 * modparam varies between platforms and is usually set to "disable(0)"
101 * unless GuC is enabled on given platform and the driver is compiled with
102 * debug config when this modparam will default to "enable(1..4)".
104 static void sanitize_options_early(struct drm_i915_private *dev_priv)
106 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
107 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
109 /* A negative value means "use platform default" */
110 if (i915_modparams.enable_guc < 0)
111 i915_modparams.enable_guc = __get_platform_enable_guc(dev_priv);
113 DRM_DEBUG_DRIVER("enable_guc=%d (submission:%s huc:%s)\n",
114 i915_modparams.enable_guc,
115 yesno(intel_uc_is_using_guc_submission()),
116 yesno(intel_uc_is_using_huc()));
118 /* Verify GuC firmware availability */
119 if (intel_uc_is_using_guc() && !intel_uc_fw_is_selected(guc_fw)) {
120 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
121 "enable_guc", i915_modparams.enable_guc,
122 !HAS_GUC(dev_priv) ? "no GuC hardware" :
126 /* Verify HuC firmware availability */
127 if (intel_uc_is_using_huc() && !intel_uc_fw_is_selected(huc_fw)) {
128 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
129 "enable_guc", i915_modparams.enable_guc,
130 !HAS_HUC(dev_priv) ? "no HuC hardware" :
134 /* A negative value means "use platform/config default" */
135 if (i915_modparams.guc_log_level < 0)
136 i915_modparams.guc_log_level =
137 __get_default_guc_log_level(dev_priv);
139 if (i915_modparams.guc_log_level > 0 && !intel_uc_is_using_guc()) {
140 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
141 "guc_log_level", i915_modparams.guc_log_level,
142 !HAS_GUC(dev_priv) ? "no GuC hardware" :
144 i915_modparams.guc_log_level = 0;
147 if (i915_modparams.guc_log_level > GUC_LOG_LEVEL_MAX) {
148 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",
149 "guc_log_level", i915_modparams.guc_log_level,
150 "verbosity too high");
151 i915_modparams.guc_log_level = GUC_LOG_LEVEL_MAX;
154 DRM_DEBUG_DRIVER("guc_log_level=%d (enabled:%s, verbose:%s, verbosity:%d)\n",
155 i915_modparams.guc_log_level,
156 yesno(i915_modparams.guc_log_level),
157 yesno(GUC_LOG_LEVEL_IS_VERBOSE(i915_modparams.guc_log_level)),
158 GUC_LOG_LEVEL_TO_VERBOSITY(i915_modparams.guc_log_level));
160 /* Make sure that sanitization was done */
161 GEM_BUG_ON(i915_modparams.enable_guc < 0);
162 GEM_BUG_ON(i915_modparams.guc_log_level < 0);
165 void intel_uc_init_early(struct drm_i915_private *i915)
167 struct intel_guc *guc = &i915->guc;
168 struct intel_huc *huc = &i915->huc;
170 intel_guc_init_early(guc);
171 intel_huc_init_early(huc);
173 sanitize_options_early(i915);
176 intel_uc_fw_fetch(i915, &guc->fw);
179 intel_uc_fw_fetch(i915, &huc->fw);
182 void intel_uc_cleanup_early(struct drm_i915_private *i915)
184 struct intel_guc *guc = &i915->guc;
185 struct intel_huc *huc = &i915->huc;
188 intel_uc_fw_fini(&huc->fw);
191 intel_uc_fw_fini(&guc->fw);
193 guc_free_load_err_log(guc);
197 * intel_uc_init_mmio - setup uC MMIO access
199 * @dev_priv: device private
201 * Setup minimal state necessary for MMIO accesses later in the
202 * initialization sequence.
204 void intel_uc_init_mmio(struct drm_i915_private *dev_priv)
206 intel_guc_init_send_regs(&dev_priv->guc);
209 static void guc_capture_load_err_log(struct intel_guc *guc)
211 if (!guc->log.vma || !i915_modparams.guc_log_level)
214 if (!guc->load_err_log)
215 guc->load_err_log = i915_gem_object_get(guc->log.vma->obj);
220 static void guc_free_load_err_log(struct intel_guc *guc)
222 if (guc->load_err_log)
223 i915_gem_object_put(guc->load_err_log);
226 static int guc_enable_communication(struct intel_guc *guc)
228 struct drm_i915_private *dev_priv = guc_to_i915(guc);
230 gen9_enable_guc_interrupts(dev_priv);
232 if (HAS_GUC_CT(dev_priv))
233 return intel_guc_ct_enable(&guc->ct);
235 guc->send = intel_guc_send_mmio;
236 guc->handler = intel_guc_to_host_event_handler_mmio;
240 static void guc_disable_communication(struct intel_guc *guc)
242 struct drm_i915_private *dev_priv = guc_to_i915(guc);
244 if (HAS_GUC_CT(dev_priv))
245 intel_guc_ct_disable(&guc->ct);
247 gen9_disable_guc_interrupts(dev_priv);
249 guc->send = intel_guc_send_nop;
250 guc->handler = intel_guc_to_host_event_handler_nop;
253 int intel_uc_init_misc(struct drm_i915_private *dev_priv)
255 struct intel_guc *guc = &dev_priv->guc;
258 if (!USES_GUC(dev_priv))
261 intel_guc_init_ggtt_pin_bias(guc);
263 ret = intel_guc_init_wq(guc);
270 void intel_uc_fini_misc(struct drm_i915_private *dev_priv)
272 struct intel_guc *guc = &dev_priv->guc;
274 if (!USES_GUC(dev_priv))
277 intel_guc_fini_wq(guc);
280 int intel_uc_init(struct drm_i915_private *dev_priv)
282 struct intel_guc *guc = &dev_priv->guc;
285 if (!USES_GUC(dev_priv))
288 if (!HAS_GUC(dev_priv))
291 ret = intel_guc_init(guc);
295 if (USES_GUC_SUBMISSION(dev_priv)) {
297 * This is stuff we need to have available at fw load time
298 * if we are planning to enable submission later
300 ret = intel_guc_submission_init(guc);
310 void intel_uc_fini(struct drm_i915_private *dev_priv)
312 struct intel_guc *guc = &dev_priv->guc;
314 if (!USES_GUC(dev_priv))
317 GEM_BUG_ON(!HAS_GUC(dev_priv));
319 if (USES_GUC_SUBMISSION(dev_priv))
320 intel_guc_submission_fini(guc);
325 void intel_uc_sanitize(struct drm_i915_private *i915)
327 struct intel_guc *guc = &i915->guc;
328 struct intel_huc *huc = &i915->huc;
333 GEM_BUG_ON(!HAS_GUC(i915));
335 guc_disable_communication(guc);
337 intel_huc_sanitize(huc);
338 intel_guc_sanitize(guc);
340 __intel_uc_reset_hw(i915);
343 int intel_uc_init_hw(struct drm_i915_private *dev_priv)
345 struct intel_guc *guc = &dev_priv->guc;
346 struct intel_huc *huc = &dev_priv->huc;
349 if (!USES_GUC(dev_priv))
352 GEM_BUG_ON(!HAS_GUC(dev_priv));
354 gen9_reset_guc_interrupts(dev_priv);
356 /* WaEnableuKernelHeaderValidFix:skl */
357 /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
358 if (IS_GEN9(dev_priv))
365 * Always reset the GuC just before (re)loading, so
366 * that the state and timing are fairly predictable
368 ret = __intel_uc_reset_hw(dev_priv);
372 if (USES_HUC(dev_priv)) {
373 ret = intel_huc_fw_upload(huc);
378 intel_guc_init_params(guc);
379 ret = intel_guc_fw_upload(guc);
380 if (ret == 0 || ret != -EAGAIN)
383 DRM_DEBUG_DRIVER("GuC fw load failed: %d; will reset and "
384 "retry %d more time(s)\n", ret, attempts);
387 /* Did we succeded or run out of retries? */
389 goto err_log_capture;
391 ret = guc_enable_communication(guc);
393 goto err_log_capture;
395 if (USES_HUC(dev_priv)) {
396 ret = intel_huc_auth(huc);
398 goto err_communication;
401 if (USES_GUC_SUBMISSION(dev_priv)) {
402 ret = intel_guc_submission_enable(guc);
404 goto err_communication;
407 dev_info(dev_priv->drm.dev, "GuC firmware version %u.%u\n",
408 guc->fw.major_ver_found, guc->fw.minor_ver_found);
409 dev_info(dev_priv->drm.dev, "GuC submission %s\n",
410 enableddisabled(USES_GUC_SUBMISSION(dev_priv)));
411 dev_info(dev_priv->drm.dev, "HuC %s\n",
412 enableddisabled(USES_HUC(dev_priv)));
417 * We've failed to load the firmware :(
420 guc_disable_communication(guc);
422 guc_capture_load_err_log(guc);
425 * Note that there is no fallback as either user explicitly asked for
426 * the GuC or driver default option was to run with the GuC enabled.
428 if (GEM_WARN_ON(ret == -EIO))
431 dev_err(dev_priv->drm.dev, "GuC initialization failed %d\n", ret);
435 void intel_uc_fini_hw(struct drm_i915_private *dev_priv)
437 struct intel_guc *guc = &dev_priv->guc;
439 if (!USES_GUC(dev_priv))
442 GEM_BUG_ON(!HAS_GUC(dev_priv));
444 if (USES_GUC_SUBMISSION(dev_priv))
445 intel_guc_submission_disable(guc);
447 guc_disable_communication(guc);
450 int intel_uc_suspend(struct drm_i915_private *i915)
452 struct intel_guc *guc = &i915->guc;
458 if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
461 err = intel_guc_suspend(guc);
463 DRM_DEBUG_DRIVER("Failed to suspend GuC, err=%d", err);
467 gen9_disable_guc_interrupts(i915);
472 int intel_uc_resume(struct drm_i915_private *i915)
474 struct intel_guc *guc = &i915->guc;
480 if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
483 gen9_enable_guc_interrupts(i915);
485 err = intel_guc_resume(guc);
487 DRM_DEBUG_DRIVER("Failed to resume GuC, err=%d", err);