blob: 4bcef5d2c01197503dd2ba722725363a95ea6f07 [file] [log] [blame]
Alex Dai33a732f2015-08-12 15:43:36 +01001/*
2 * Copyright © 2014 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 * Authors:
24 * Vinit Azad <vinit.azad@intel.com>
25 * Ben Widawsky <ben@bwidawsk.net>
26 * Dave Gordon <david.s.gordon@intel.com>
27 * Alex Dai <yu.dai@intel.com>
28 */
29#include <linux/firmware.h>
30#include "i915_drv.h"
Arkadiusz Hiler8c4f24f2016-11-25 18:59:33 +010031#include "intel_uc.h"
Alex Dai33a732f2015-08-12 15:43:36 +010032
33/**
Alex Daifeda33e2015-10-19 16:10:54 -070034 * DOC: GuC-specific firmware loader
Alex Dai33a732f2015-08-12 15:43:36 +010035 *
36 * intel_guc:
37 * Top level structure of guc. It handles firmware loading and manages client
38 * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
39 * ExecList submission.
40 *
41 * Firmware versioning:
42 * The firmware build process will generate a version header file with major and
43 * minor version defined. The versions are built into CSS header of firmware.
44 * i915 kernel driver set the minimal firmware version required per platform.
45 * The firmware installation package will install (symbolic link) proper version
46 * of firmware.
47 *
48 * GuC address space:
49 * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
50 * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
51 * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
52 * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
53 *
Alex Dai33a732f2015-08-12 15:43:36 +010054 */
55
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +010056#define SKL_FW_MAJOR 6
57#define SKL_FW_MINOR 1
58
59#define BXT_FW_MAJOR 8
60#define BXT_FW_MINOR 7
61
62#define KBL_FW_MAJOR 9
63#define KBL_FW_MINOR 14
64
65#define GUC_FW_PATH(platform, major, minor) \
66 "i915/" __stringify(platform) "_guc_ver" __stringify(major) "_" __stringify(minor) ".bin"
67
68#define I915_SKL_GUC_UCODE GUC_FW_PATH(skl, SKL_FW_MAJOR, SKL_FW_MINOR)
Alex Dai33a732f2015-08-12 15:43:36 +010069MODULE_FIRMWARE(I915_SKL_GUC_UCODE);
70
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +010071#define I915_BXT_GUC_UCODE GUC_FW_PATH(bxt, BXT_FW_MAJOR, BXT_FW_MINOR)
Nick Hoath57bf5c82016-05-06 11:42:53 +010072MODULE_FIRMWARE(I915_BXT_GUC_UCODE);
73
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +010074#define I915_KBL_GUC_UCODE GUC_FW_PATH(kbl, KBL_FW_MAJOR, KBL_FW_MINOR)
Peter Antoineff64cc12016-06-30 09:37:52 -070075MODULE_FIRMWARE(I915_KBL_GUC_UCODE);
76
Alex Dai33a732f2015-08-12 15:43:36 +010077/* User-friendly representation of an enum */
78const char *intel_guc_fw_status_repr(enum intel_guc_fw_status status)
79{
80 switch (status) {
81 case GUC_FIRMWARE_FAIL:
82 return "FAIL";
83 case GUC_FIRMWARE_NONE:
84 return "NONE";
85 case GUC_FIRMWARE_PENDING:
86 return "PENDING";
87 case GUC_FIRMWARE_SUCCESS:
88 return "SUCCESS";
89 default:
90 return "UNKNOWN!";
91 }
92};
93
Dave Gordon0c5664e2016-09-12 21:19:36 +010094static void guc_interrupts_release(struct drm_i915_private *dev_priv)
Dave Gordon4df001d2015-08-12 15:43:42 +010095{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +000096 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +053097 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +000098 int irqs;
Dave Gordon4df001d2015-08-12 15:43:42 +010099
Dave Gordonfa7545a2016-06-24 15:57:57 +0100100 /* tell all command streamers NOT to forward interrupts or vblank to GuC */
Dave Gordon4df001d2015-08-12 15:43:42 +0100101 irqs = _MASKED_FIELD(GFX_FORWARD_VBLANK_MASK, GFX_FORWARD_VBLANK_NEVER);
102 irqs |= _MASKED_BIT_DISABLE(GFX_INTERRUPT_STEERING);
Akash Goel3b3f1652016-10-13 22:44:48 +0530103 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000104 I915_WRITE(RING_MODE_GEN7(engine), irqs);
Dave Gordon4df001d2015-08-12 15:43:42 +0100105
Dave Gordon4df001d2015-08-12 15:43:42 +0100106 /* route all GT interrupts to the host */
107 I915_WRITE(GUC_BCS_RCS_IER, 0);
108 I915_WRITE(GUC_VCS2_VCS1_IER, 0);
109 I915_WRITE(GUC_WD_VECS_IER, 0);
110}
111
Dave Gordon0c5664e2016-09-12 21:19:36 +0100112static void guc_interrupts_capture(struct drm_i915_private *dev_priv)
Dave Gordon4df001d2015-08-12 15:43:42 +0100113{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000114 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530115 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000116 int irqs;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530117 u32 tmp;
Dave Gordon4df001d2015-08-12 15:43:42 +0100118
Dave Gordonfa7545a2016-06-24 15:57:57 +0100119 /* tell all command streamers to forward interrupts (but not vblank) to GuC */
120 irqs = _MASKED_BIT_ENABLE(GFX_INTERRUPT_STEERING);
Akash Goel3b3f1652016-10-13 22:44:48 +0530121 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000122 I915_WRITE(RING_MODE_GEN7(engine), irqs);
Dave Gordon4df001d2015-08-12 15:43:42 +0100123
Dave Gordon4df001d2015-08-12 15:43:42 +0100124 /* route USER_INTERRUPT to Host, all others are sent to GuC. */
125 irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
126 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT;
127 /* These three registers have the same bit definitions */
128 I915_WRITE(GUC_BCS_RCS_IER, ~irqs);
129 I915_WRITE(GUC_VCS2_VCS1_IER, ~irqs);
130 I915_WRITE(GUC_WD_VECS_IER, ~irqs);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530131
132 /*
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100133 * The REDIRECT_TO_GUC bit of the PMINTRMSK register directs all
134 * (unmasked) PM interrupts to the GuC. All other bits of this
135 * register *disable* generation of a specific interrupt.
136 *
137 * 'pm_intr_keep' indicates bits that are NOT to be set when
138 * writing to the PM interrupt mask register, i.e. interrupts
139 * that must not be disabled.
140 *
141 * If the GuC is handling these interrupts, then we must not let
142 * the PM code disable ANY interrupt that the GuC is expecting.
143 * So for each ENABLED (0) bit in this register, we must SET the
144 * bit in pm_intr_keep so that it's left enabled for the GuC.
145 *
146 * OTOH the REDIRECT_TO_GUC bit is initially SET in pm_intr_keep
147 * (so interrupts go to the DISPLAY unit at first); but here we
148 * need to CLEAR that bit, which will result in the register bit
149 * being left SET!
150 */
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530151 tmp = I915_READ(GEN6_PMINTRMSK);
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100152 if (tmp & GEN8_PMINTR_REDIRECT_TO_GUC) {
153 dev_priv->rps.pm_intr_keep |= ~tmp;
154 dev_priv->rps.pm_intr_keep &= ~GEN8_PMINTR_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530155 }
Dave Gordon4df001d2015-08-12 15:43:42 +0100156}
157
Alex Dai33a732f2015-08-12 15:43:36 +0100158static u32 get_gttype(struct drm_i915_private *dev_priv)
159{
160 /* XXX: GT type based on PCI device ID? field seems unused by fw */
161 return 0;
162}
163
164static u32 get_core_family(struct drm_i915_private *dev_priv)
165{
Dave Gordonfc32de92016-08-18 18:17:24 +0100166 u32 gen = INTEL_GEN(dev_priv);
167
168 switch (gen) {
Alex Dai33a732f2015-08-12 15:43:36 +0100169 case 9:
170 return GFXCORE_FAMILY_GEN9;
171
172 default:
Dave Gordonfc32de92016-08-18 18:17:24 +0100173 WARN(1, "GEN%d does not support GuC operation!\n", gen);
Alex Dai33a732f2015-08-12 15:43:36 +0100174 return GFXCORE_FAMILY_UNKNOWN;
175 }
176}
177
Dave Gordon0c5664e2016-09-12 21:19:36 +0100178/*
179 * Initialise the GuC parameter block before starting the firmware
180 * transfer. These parameters are read by the firmware on startup
181 * and cannot be changed thereafter.
182 */
183static void guc_params_init(struct drm_i915_private *dev_priv)
Alex Dai33a732f2015-08-12 15:43:36 +0100184{
185 struct intel_guc *guc = &dev_priv->guc;
186 u32 params[GUC_CTL_MAX_DWORDS];
187 int i;
188
189 memset(&params, 0, sizeof(params));
190
191 params[GUC_CTL_DEVICE_INFO] |=
192 (get_gttype(dev_priv) << GUC_CTL_GTTYPE_SHIFT) |
193 (get_core_family(dev_priv) << GUC_CTL_COREFAMILY_SHIFT);
194
195 /*
196 * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one
197 * second. This ARAR is calculated by:
198 * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10
199 */
200 params[GUC_CTL_ARAT_HIGH] = 0;
201 params[GUC_CTL_ARAT_LOW] = 100000000;
202
203 params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER;
204
205 params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER |
206 GUC_CTL_VCS2_ENABLED;
207
Akash Goeld6b40b42016-10-12 21:54:29 +0530208 params[GUC_CTL_LOG_PARAMS] = guc->log.flags;
Sagar Arun Kambleb1e37102016-10-12 21:54:27 +0530209
Alex Dai33a732f2015-08-12 15:43:36 +0100210 if (i915.guc_log_level >= 0) {
Alex Dai33a732f2015-08-12 15:43:36 +0100211 params[GUC_CTL_DEBUG] =
212 i915.guc_log_level << GUC_LOG_VERBOSITY_SHIFT;
Sagar Arun Kambleb1e37102016-10-12 21:54:27 +0530213 } else
214 params[GUC_CTL_DEBUG] = GUC_LOG_DISABLED;
Alex Dai33a732f2015-08-12 15:43:36 +0100215
Chris Wilson8b797af2016-08-15 10:48:51 +0100216 if (guc->ads_vma) {
Chris Wilson4741da92016-12-24 19:31:46 +0000217 u32 ads = guc_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT;
Alex Daib6a5cd72015-12-18 12:00:12 -0800218 params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
219 params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
220 }
221
Alex Daibac427f2015-08-12 15:43:39 +0100222 /* If GuC submission is enabled, set up additional parameters here */
223 if (i915.enable_guc_submission) {
Chris Wilson4741da92016-12-24 19:31:46 +0000224 u32 pgs = guc_ggtt_offset(dev_priv->guc.ctx_pool_vma);
Alex Daibac427f2015-08-12 15:43:39 +0100225 u32 ctx_in_16 = GUC_MAX_GPU_CONTEXTS / 16;
226
227 pgs >>= PAGE_SHIFT;
228 params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) |
229 (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT);
230
231 params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS;
232
233 /* Unmask this bit to enable the GuC's internal scheduler */
234 params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER;
235 }
236
Alex Dai33a732f2015-08-12 15:43:36 +0100237 I915_WRITE(SOFT_SCRATCH(0), 0);
238
239 for (i = 0; i < GUC_CTL_MAX_DWORDS; i++)
240 I915_WRITE(SOFT_SCRATCH(1 + i), params[i]);
241}
242
243/*
244 * Read the GuC status register (GUC_STATUS) and store it in the
245 * specified location; then return a boolean indicating whether
246 * the value matches either of two values representing completion
247 * of the GuC boot process.
248 *
Tvrtko Ursulin36894e82016-02-11 10:27:31 +0000249 * This is used for polling the GuC status in a wait_for()
Alex Dai33a732f2015-08-12 15:43:36 +0100250 * loop below.
251 */
252static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
253 u32 *status)
254{
255 u32 val = I915_READ(GUC_STATUS);
Alex Dai0d44d3f2015-09-22 13:48:40 -0700256 u32 uk_val = val & GS_UKERNEL_MASK;
Alex Dai33a732f2015-08-12 15:43:36 +0100257 *status = val;
Alex Dai0d44d3f2015-09-22 13:48:40 -0700258 return (uk_val == GS_UKERNEL_READY ||
259 ((val & GS_MIA_CORE_STATE) && uk_val == GS_UKERNEL_LAPIC_DONE));
Alex Dai33a732f2015-08-12 15:43:36 +0100260}
261
262/*
263 * Transfer the firmware image to RAM for execution by the microcontroller.
264 *
Alex Dai33a732f2015-08-12 15:43:36 +0100265 * Architecturally, the DMA engine is bidirectional, and can potentially even
266 * transfer between GTT locations. This functionality is left out of the API
267 * for now as there is no need for it.
268 *
269 * Note that GuC needs the CSS header plus uKernel code to be copied by the
270 * DMA engine in one operation, whereas the RSA signature is loaded via MMIO.
271 */
Chris Wilson058d88c2016-08-15 10:49:06 +0100272static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv,
273 struct i915_vma *vma)
Alex Dai33a732f2015-08-12 15:43:36 +0100274{
275 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
Alex Dai33a732f2015-08-12 15:43:36 +0100276 unsigned long offset;
Chris Wilson058d88c2016-08-15 10:49:06 +0100277 struct sg_table *sg = vma->pages;
Alex Daifeda33e2015-10-19 16:10:54 -0700278 u32 status, rsa[UOS_RSA_SCRATCH_MAX_COUNT];
Alex Dai33a732f2015-08-12 15:43:36 +0100279 int i, ret = 0;
280
Alex Daifeda33e2015-10-19 16:10:54 -0700281 /* where RSA signature starts */
282 offset = guc_fw->rsa_offset;
Alex Dai33a732f2015-08-12 15:43:36 +0100283
284 /* Copy RSA signature from the fw image to HW for verification */
Alex Daifeda33e2015-10-19 16:10:54 -0700285 sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, sizeof(rsa), offset);
286 for (i = 0; i < UOS_RSA_SCRATCH_MAX_COUNT; i++)
Ville Syrjäläab9cc552015-09-18 20:03:24 +0300287 I915_WRITE(UOS_RSA_SCRATCH(i), rsa[i]);
Alex Dai33a732f2015-08-12 15:43:36 +0100288
Alex Daifeda33e2015-10-19 16:10:54 -0700289 /* The header plus uCode will be copied to WOPCM via DMA, excluding any
290 * other components */
291 I915_WRITE(DMA_COPY_SIZE, guc_fw->header_size + guc_fw->ucode_size);
292
Alex Dai33a732f2015-08-12 15:43:36 +0100293 /* Set the source address for the new blob */
Chris Wilson4741da92016-12-24 19:31:46 +0000294 offset = guc_ggtt_offset(vma) + guc_fw->header_offset;
Alex Dai33a732f2015-08-12 15:43:36 +0100295 I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset));
296 I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF);
297
298 /*
299 * Set the DMA destination. Current uCode expects the code to be
300 * loaded at 8k; locations below this are used for the stack.
301 */
302 I915_WRITE(DMA_ADDR_1_LOW, 0x2000);
303 I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM);
304
305 /* Finally start the DMA */
306 I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(UOS_MOVE | START_DMA));
307
308 /*
Tvrtko Ursulin36894e82016-02-11 10:27:31 +0000309 * Wait for the DMA to complete & the GuC to start up.
Alex Dai33a732f2015-08-12 15:43:36 +0100310 * NB: Docs recommend not using the interrupt for completion.
311 * Measurements indicate this should take no more than 20ms, so a
312 * timeout here indicates that the GuC has failed and is unusable.
313 * (Higher levels of the driver will attempt to fall back to
314 * execlist mode if this happens.)
315 */
Tvrtko Ursulin36894e82016-02-11 10:27:31 +0000316 ret = wait_for(guc_ucode_response(dev_priv, &status), 100);
Alex Dai33a732f2015-08-12 15:43:36 +0100317
318 DRM_DEBUG_DRIVER("DMA status 0x%x, GuC status 0x%x\n",
319 I915_READ(DMA_CTRL), status);
320
321 if ((status & GS_BOOTROM_MASK) == GS_BOOTROM_RSA_FAILED) {
322 DRM_ERROR("GuC firmware signature verification failed\n");
323 ret = -ENOEXEC;
324 }
325
326 DRM_DEBUG_DRIVER("returning %d\n", ret);
327
328 return ret;
329}
330
Peter Antoine74aa1562016-05-17 15:12:45 +0100331static u32 guc_wopcm_size(struct drm_i915_private *dev_priv)
332{
333 u32 wopcm_size = GUC_WOPCM_TOP;
334
335 /* On BXT, the top of WOPCM is reserved for RC6 context */
Michel Thierry254e0932017-01-09 16:51:35 +0200336 if (IS_GEN9_LP(dev_priv))
Peter Antoine74aa1562016-05-17 15:12:45 +0100337 wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
338
339 return wopcm_size;
340}
341
Alex Dai33a732f2015-08-12 15:43:36 +0100342/*
343 * Load the GuC firmware blob into the MinuteIA.
344 */
345static int guc_ucode_xfer(struct drm_i915_private *dev_priv)
346{
347 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
Chris Wilson058d88c2016-08-15 10:49:06 +0100348 struct i915_vma *vma;
Alex Dai33a732f2015-08-12 15:43:36 +0100349 int ret;
350
351 ret = i915_gem_object_set_to_gtt_domain(guc_fw->guc_fw_obj, false);
352 if (ret) {
353 DRM_DEBUG_DRIVER("set-domain failed %d\n", ret);
354 return ret;
355 }
356
Michał Winiarski83796f22017-01-11 16:17:39 +0100357 vma = i915_gem_object_ggtt_pin(guc_fw->guc_fw_obj, NULL, 0, 0,
358 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
Chris Wilson058d88c2016-08-15 10:49:06 +0100359 if (IS_ERR(vma)) {
360 DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma));
361 return PTR_ERR(vma);
Alex Dai33a732f2015-08-12 15:43:36 +0100362 }
363
Alex Dai33a732f2015-08-12 15:43:36 +0100364 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
365
366 /* init WOPCM */
Peter Antoine74aa1562016-05-17 15:12:45 +0100367 I915_WRITE(GUC_WOPCM_SIZE, guc_wopcm_size(dev_priv));
Alex Dai33a732f2015-08-12 15:43:36 +0100368 I915_WRITE(DMA_GUC_WOPCM_OFFSET, GUC_WOPCM_OFFSET_VALUE);
369
370 /* Enable MIA caching. GuC clock gating is disabled. */
371 I915_WRITE(GUC_SHIM_CONTROL, GUC_SHIM_CONTROL_VALUE);
372
Jani Nikulaa117f372016-09-16 16:59:44 +0300373 /* WaDisableMinuteIaClockGating:bxt */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100374 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
Nick Hoathb970b482015-09-08 10:31:53 +0100375 I915_WRITE(GUC_SHIM_CONTROL, (I915_READ(GUC_SHIM_CONTROL) &
376 ~GUC_ENABLE_MIA_CLOCK_GATING));
377 }
378
Jani Nikula4ff40a42016-09-26 15:07:51 +0300379 /* WaC6DisallowByGfxPause:bxt */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100380 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0))
Tim Gore65fe29e2016-07-20 11:00:25 +0100381 I915_WRITE(GEN6_GFXPAUSE, 0x30FFF);
Alex Dai33a732f2015-08-12 15:43:36 +0100382
Michel Thierry254e0932017-01-09 16:51:35 +0200383 if (IS_GEN9_LP(dev_priv))
Alex Dai33a732f2015-08-12 15:43:36 +0100384 I915_WRITE(GEN9LP_GT_PM_CONFIG, GT_DOORBELL_ENABLE);
385 else
386 I915_WRITE(GEN9_GT_PM_CONFIG, GT_DOORBELL_ENABLE);
387
Tvrtko Ursulin5db94012016-10-13 11:03:10 +0100388 if (IS_GEN9(dev_priv)) {
Alex Dai33a732f2015-08-12 15:43:36 +0100389 /* DOP Clock Gating Enable for GuC clocks */
390 I915_WRITE(GEN7_MISCCPCTL, (GEN8_DOP_CLOCK_GATE_GUC_ENABLE |
391 I915_READ(GEN7_MISCCPCTL)));
392
Dave Gordon0c5664e2016-09-12 21:19:36 +0100393 /* allows for 5us (in 10ns units) before GT can go to RC6 */
Alex Dai33a732f2015-08-12 15:43:36 +0100394 I915_WRITE(GUC_ARAT_C6DIS, 0x1FF);
395 }
396
Dave Gordon0c5664e2016-09-12 21:19:36 +0100397 guc_params_init(dev_priv);
Alex Dai33a732f2015-08-12 15:43:36 +0100398
Chris Wilson058d88c2016-08-15 10:49:06 +0100399 ret = guc_ucode_xfer_dma(dev_priv, vma);
Alex Dai33a732f2015-08-12 15:43:36 +0100400
401 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
402
403 /*
404 * We keep the object pages for reuse during resume. But we can unpin it
405 * now that DMA has completed, so it doesn't continue to take up space.
406 */
Chris Wilson058d88c2016-08-15 10:49:06 +0100407 i915_vma_unpin(vma);
Alex Dai33a732f2015-08-12 15:43:36 +0100408
409 return ret;
410}
411
Dave Gordon0c5664e2016-09-12 21:19:36 +0100412static int guc_hw_reset(struct drm_i915_private *dev_priv)
Arun Siluvery6b332fa2016-04-04 18:50:56 +0100413{
414 int ret;
415 u32 guc_status;
416
417 ret = intel_guc_reset(dev_priv);
418 if (ret) {
419 DRM_ERROR("GuC reset failed, ret = %d\n", ret);
420 return ret;
421 }
422
423 guc_status = I915_READ(GUC_STATUS);
424 WARN(!(guc_status & GS_MIA_IN_RESET),
425 "GuC status: 0x%x, MIA core expected to be in reset\n", guc_status);
426
427 return ret;
428}
429
Alex Dai33a732f2015-08-12 15:43:36 +0100430/**
Dave Gordonf09d6752016-05-13 15:36:29 +0100431 * intel_guc_setup() - finish preparing the GuC for activity
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000432 * @dev_priv: i915 device private
Alex Dai33a732f2015-08-12 15:43:36 +0100433 *
434 * Called from gem_init_hw() during driver loading and also after a GPU reset.
435 *
Dave Gordonf09d6752016-05-13 15:36:29 +0100436 * The main action required here it to load the GuC uCode into the device.
Alex Dai33a732f2015-08-12 15:43:36 +0100437 * The firmware image should have already been fetched into memory by the
Dave Gordonf09d6752016-05-13 15:36:29 +0100438 * earlier call to intel_guc_init(), so here we need only check that worked,
439 * and then transfer the image to the h/w.
Alex Dai33a732f2015-08-12 15:43:36 +0100440 *
441 * Return: non-zero code on error
442 */
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000443int intel_guc_setup(struct drm_i915_private *dev_priv)
Alex Dai33a732f2015-08-12 15:43:36 +0100444{
Alex Dai33a732f2015-08-12 15:43:36 +0100445 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
Dave Gordonfce91f22016-05-20 11:42:42 +0100446 const char *fw_path = guc_fw->guc_fw_path;
447 int retries, ret, err;
Alex Dai33a732f2015-08-12 15:43:36 +0100448
Dave Gordonfce91f22016-05-20 11:42:42 +0100449 DRM_DEBUG_DRIVER("GuC fw status: path %s, fetch %s, load %s\n",
450 fw_path,
451 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status),
452 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
453
454 /* Loading forbidden, or no firmware to load? */
455 if (!i915.enable_guc_loading) {
456 err = 0;
457 goto fail;
Dave Gordone556f7c2016-06-07 09:14:49 +0100458 } else if (fw_path == NULL) {
459 /* Device is known to have no uCode (e.g. no GuC) */
460 err = -ENXIO;
461 goto fail;
462 } else if (*fw_path == '\0') {
463 /* Device has a GuC but we don't know what f/w to load? */
Dave Gordonfc32de92016-08-18 18:17:24 +0100464 WARN(1, "No GuC firmware known for this platform!\n");
Dave Gordonfce91f22016-05-20 11:42:42 +0100465 err = -ENODEV;
466 goto fail;
467 }
468
469 /* Fetch failed, or already fetched but failed to load? */
470 if (guc_fw->guc_fw_fetch_status != GUC_FIRMWARE_SUCCESS) {
471 err = -EIO;
472 goto fail;
473 } else if (guc_fw->guc_fw_load_status == GUC_FIRMWARE_FAIL) {
474 err = -ENOEXEC;
475 goto fail;
476 }
477
Dave Gordon0c5664e2016-09-12 21:19:36 +0100478 guc_interrupts_release(dev_priv);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530479 gen9_reset_guc_interrupts(dev_priv);
Dave Gordonfce91f22016-05-20 11:42:42 +0100480
Chris Wilson7c3f86b2017-01-12 11:00:49 +0000481 /* We need to notify the guc whenever we change the GGTT */
482 i915_ggtt_enable_guc(dev_priv);
483
Dave Gordonfce91f22016-05-20 11:42:42 +0100484 guc_fw->guc_fw_load_status = GUC_FIRMWARE_PENDING;
Daniel Vetter9f9e5392015-10-23 11:10:59 +0200485
Alex Dai33a732f2015-08-12 15:43:36 +0100486 DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n",
487 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status),
488 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
489
Dave Gordonbeffa512016-06-10 18:29:26 +0100490 err = i915_guc_submission_init(dev_priv);
Alex Daibac427f2015-08-12 15:43:39 +0100491 if (err)
492 goto fail;
493
Arun Siluvery6b332fa2016-04-04 18:50:56 +0100494 /*
495 * WaEnableuKernelHeaderValidFix:skl,bxt
496 * For BXT, this is only upto B0 but below WA is required for later
497 * steppings also so this is extended as well.
498 */
499 /* WaEnableGuCBootHashCheckNotSet:skl,bxt */
Dave Gordond7617012016-04-04 18:50:57 +0100500 for (retries = 3; ; ) {
501 /*
502 * Always reset the GuC just before (re)loading, so
503 * that the state and timing are fairly predictable
504 */
Dave Gordon0c5664e2016-09-12 21:19:36 +0100505 err = guc_hw_reset(dev_priv);
Dave Gordonfc32de92016-08-18 18:17:24 +0100506 if (err)
Arun Siluvery6b332fa2016-04-04 18:50:56 +0100507 goto fail;
Dave Gordond7617012016-04-04 18:50:57 +0100508
509 err = guc_ucode_xfer(dev_priv);
510 if (!err)
511 break;
512
513 if (--retries == 0)
514 goto fail;
515
Dave Gordonfce91f22016-05-20 11:42:42 +0100516 DRM_INFO("GuC fw load failed: %d; will reset and "
517 "retry %d more time(s)\n", err, retries);
Arun Siluvery6b332fa2016-04-04 18:50:56 +0100518 }
Alex Dai33a732f2015-08-12 15:43:36 +0100519
520 guc_fw->guc_fw_load_status = GUC_FIRMWARE_SUCCESS;
521
522 DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n",
523 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status),
524 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
525
Dave Gordon44a28b12015-08-12 15:43:41 +0100526 if (i915.enable_guc_submission) {
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530527 if (i915.guc_log_level >= 0)
528 gen9_enable_guc_interrupts(dev_priv);
529
Dave Gordonbeffa512016-06-10 18:29:26 +0100530 err = i915_guc_submission_enable(dev_priv);
Dave Gordon44a28b12015-08-12 15:43:41 +0100531 if (err)
532 goto fail;
Dave Gordon0c5664e2016-09-12 21:19:36 +0100533 guc_interrupts_capture(dev_priv);
Dave Gordon44a28b12015-08-12 15:43:41 +0100534 }
535
Alex Dai33a732f2015-08-12 15:43:36 +0100536 return 0;
537
538fail:
539 if (guc_fw->guc_fw_load_status == GUC_FIRMWARE_PENDING)
540 guc_fw->guc_fw_load_status = GUC_FIRMWARE_FAIL;
541
Dave Gordon0c5664e2016-09-12 21:19:36 +0100542 guc_interrupts_release(dev_priv);
Dave Gordonbeffa512016-06-10 18:29:26 +0100543 i915_guc_submission_disable(dev_priv);
544 i915_guc_submission_fini(dev_priv);
Chris Wilson7c3f86b2017-01-12 11:00:49 +0000545 i915_ggtt_disable_guc(dev_priv);
Dave Gordon44a28b12015-08-12 15:43:41 +0100546
Dave Gordonfce91f22016-05-20 11:42:42 +0100547 /*
548 * We've failed to load the firmware :(
549 *
550 * Decide whether to disable GuC submission and fall back to
551 * execlist mode, and whether to hide the error by returning
552 * zero or to return -EIO, which the caller will treat as a
553 * nonfatal error (i.e. it doesn't prevent driver load, but
554 * marks the GPU as wedged until reset).
555 */
556 if (i915.enable_guc_loading > 1) {
557 ret = -EIO;
558 } else if (i915.enable_guc_submission > 1) {
559 ret = -EIO;
560 } else {
561 ret = 0;
562 }
563
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000564 if (err == 0 && !HAS_GUC_UCODE(dev_priv))
Dave Gordon4e50f792016-06-10 17:21:25 +0100565 ; /* Don't mention the GuC! */
566 else if (err == 0)
Dave Gordonfce91f22016-05-20 11:42:42 +0100567 DRM_INFO("GuC firmware load skipped\n");
Dave Gordon4e50f792016-06-10 17:21:25 +0100568 else if (ret != -EIO)
Dave Gordonfc32de92016-08-18 18:17:24 +0100569 DRM_NOTE("GuC firmware load failed: %d\n", err);
Dave Gordon4e50f792016-06-10 17:21:25 +0100570 else
Dave Gordonfc32de92016-08-18 18:17:24 +0100571 DRM_WARN("GuC firmware load failed: %d\n", err);
Dave Gordonfce91f22016-05-20 11:42:42 +0100572
573 if (i915.enable_guc_submission) {
574 if (fw_path == NULL)
575 DRM_INFO("GuC submission without firmware not supported\n");
576 if (ret == 0)
Dave Gordonfc32de92016-08-18 18:17:24 +0100577 DRM_NOTE("Falling back from GuC submission to execlist mode\n");
Dave Gordonfce91f22016-05-20 11:42:42 +0100578 else
579 DRM_ERROR("GuC init failed: %d\n", ret);
580 }
581 i915.enable_guc_submission = 0;
582
583 return ret;
Alex Dai33a732f2015-08-12 15:43:36 +0100584}
585
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000586static void guc_fw_fetch(struct drm_i915_private *dev_priv,
587 struct intel_guc_fw *guc_fw)
Alex Dai33a732f2015-08-12 15:43:36 +0100588{
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000589 struct pci_dev *pdev = dev_priv->drm.pdev;
Alex Dai33a732f2015-08-12 15:43:36 +0100590 struct drm_i915_gem_object *obj;
Jérémy Lefaure3aaa8ab2016-11-28 18:43:19 -0500591 const struct firmware *fw = NULL;
Alex Daifeda33e2015-10-19 16:10:54 -0700592 struct guc_css_header *css;
593 size_t size;
Alex Dai33a732f2015-08-12 15:43:36 +0100594 int err;
595
596 DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetch status %s\n",
597 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
598
David Weinehall52a05c32016-08-22 13:32:44 +0300599 err = request_firmware(&fw, guc_fw->guc_fw_path, &pdev->dev);
Alex Dai33a732f2015-08-12 15:43:36 +0100600 if (err)
601 goto fail;
602 if (!fw)
603 goto fail;
604
605 DRM_DEBUG_DRIVER("fetch GuC fw from %s succeeded, fw %p\n",
606 guc_fw->guc_fw_path, fw);
Alex Dai33a732f2015-08-12 15:43:36 +0100607
Alex Daifeda33e2015-10-19 16:10:54 -0700608 /* Check the size of the blob before examining buffer contents */
609 if (fw->size < sizeof(struct guc_css_header)) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100610 DRM_NOTE("Firmware header is missing\n");
Alex Dai33a732f2015-08-12 15:43:36 +0100611 goto fail;
Alex Daifeda33e2015-10-19 16:10:54 -0700612 }
613
614 css = (struct guc_css_header *)fw->data;
615
616 /* Firmware bits always start from header */
617 guc_fw->header_offset = 0;
618 guc_fw->header_size = (css->header_size_dw - css->modulus_size_dw -
619 css->key_size_dw - css->exponent_size_dw) * sizeof(u32);
620
621 if (guc_fw->header_size != sizeof(struct guc_css_header)) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100622 DRM_NOTE("CSS header definition mismatch\n");
Alex Daifeda33e2015-10-19 16:10:54 -0700623 goto fail;
624 }
625
626 /* then, uCode */
627 guc_fw->ucode_offset = guc_fw->header_offset + guc_fw->header_size;
628 guc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);
629
630 /* now RSA */
631 if (css->key_size_dw != UOS_RSA_SCRATCH_MAX_COUNT) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100632 DRM_NOTE("RSA key size is bad\n");
Alex Daifeda33e2015-10-19 16:10:54 -0700633 goto fail;
634 }
635 guc_fw->rsa_offset = guc_fw->ucode_offset + guc_fw->ucode_size;
636 guc_fw->rsa_size = css->key_size_dw * sizeof(u32);
637
638 /* At least, it should have header, uCode and RSA. Size of all three. */
639 size = guc_fw->header_size + guc_fw->ucode_size + guc_fw->rsa_size;
640 if (fw->size < size) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100641 DRM_NOTE("Missing firmware components\n");
Alex Daifeda33e2015-10-19 16:10:54 -0700642 goto fail;
643 }
644
645 /* Header and uCode will be loaded to WOPCM. Size of the two. */
646 size = guc_fw->header_size + guc_fw->ucode_size;
Tvrtko Ursulin12d79d72016-12-01 14:16:37 +0000647 if (size > guc_wopcm_size(dev_priv)) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100648 DRM_NOTE("Firmware is too large to fit in WOPCM\n");
Alex Daifeda33e2015-10-19 16:10:54 -0700649 goto fail;
650 }
Alex Dai33a732f2015-08-12 15:43:36 +0100651
652 /*
653 * The GuC firmware image has the version number embedded at a well-known
654 * offset within the firmware blob; note that major / minor version are
655 * TWO bytes each (i.e. u16), although all pointers and offsets are defined
656 * in terms of bytes (u8).
657 */
Alex Daifeda33e2015-10-19 16:10:54 -0700658 guc_fw->guc_fw_major_found = css->guc_sw_version >> 16;
659 guc_fw->guc_fw_minor_found = css->guc_sw_version & 0xFFFF;
Alex Dai33a732f2015-08-12 15:43:36 +0100660
661 if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted ||
662 guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100663 DRM_NOTE("GuC firmware version %d.%d, required %d.%d\n",
Alex Dai33a732f2015-08-12 15:43:36 +0100664 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found,
665 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
666 err = -ENOEXEC;
667 goto fail;
668 }
669
670 DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n",
671 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found,
672 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
673
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000674 mutex_lock(&dev_priv->drm.struct_mutex);
Tvrtko Ursulin12d79d72016-12-01 14:16:37 +0000675 obj = i915_gem_object_create_from_data(dev_priv, fw->data, fw->size);
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000676 mutex_unlock(&dev_priv->drm.struct_mutex);
Alex Dai33a732f2015-08-12 15:43:36 +0100677 if (IS_ERR_OR_NULL(obj)) {
678 err = obj ? PTR_ERR(obj) : -ENOMEM;
679 goto fail;
680 }
681
682 guc_fw->guc_fw_obj = obj;
683 guc_fw->guc_fw_size = fw->size;
684
685 DRM_DEBUG_DRIVER("GuC fw fetch status SUCCESS, obj %p\n",
686 guc_fw->guc_fw_obj);
687
688 release_firmware(fw);
689 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_SUCCESS;
690 return;
691
692fail:
Dave Gordonfc32de92016-08-18 18:17:24 +0100693 DRM_WARN("Failed to fetch valid GuC firmware from %s (error %d)\n",
694 guc_fw->guc_fw_path, err);
Alex Dai33a732f2015-08-12 15:43:36 +0100695 DRM_DEBUG_DRIVER("GuC fw fetch status FAIL; err %d, fw %p, obj %p\n",
696 err, fw, guc_fw->guc_fw_obj);
Alex Dai33a732f2015-08-12 15:43:36 +0100697
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000698 mutex_lock(&dev_priv->drm.struct_mutex);
Alex Dai33a732f2015-08-12 15:43:36 +0100699 obj = guc_fw->guc_fw_obj;
700 if (obj)
Chris Wilsonf8c417c2016-07-20 13:31:53 +0100701 i915_gem_object_put(obj);
Alex Dai33a732f2015-08-12 15:43:36 +0100702 guc_fw->guc_fw_obj = NULL;
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000703 mutex_unlock(&dev_priv->drm.struct_mutex);
Alex Dai33a732f2015-08-12 15:43:36 +0100704
705 release_firmware(fw); /* OK even if fw is NULL */
706 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_FAIL;
707}
708
709/**
Dave Gordonf09d6752016-05-13 15:36:29 +0100710 * intel_guc_init() - define parameters and fetch firmware
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000711 * @dev_priv: i915 device private
Alex Dai33a732f2015-08-12 15:43:36 +0100712 *
713 * Called early during driver load, but after GEM is initialised.
Alex Dai33a732f2015-08-12 15:43:36 +0100714 *
715 * The firmware will be transferred to the GuC's memory later,
Dave Gordonf09d6752016-05-13 15:36:29 +0100716 * when intel_guc_setup() is called.
Alex Dai33a732f2015-08-12 15:43:36 +0100717 */
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000718void intel_guc_init(struct drm_i915_private *dev_priv)
Alex Dai33a732f2015-08-12 15:43:36 +0100719{
Alex Dai33a732f2015-08-12 15:43:36 +0100720 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
721 const char *fw_path;
722
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000723 if (!HAS_GUC(dev_priv)) {
Anusha Srivatsa21e33022016-10-14 16:47:05 -0700724 i915.enable_guc_loading = 0;
725 i915.enable_guc_submission = 0;
726 } else {
727 /* A negative value means "use platform default" */
728 if (i915.enable_guc_loading < 0)
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000729 i915.enable_guc_loading = HAS_GUC_UCODE(dev_priv);
Anusha Srivatsa21e33022016-10-14 16:47:05 -0700730 if (i915.enable_guc_submission < 0)
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000731 i915.enable_guc_submission = HAS_GUC_SCHED(dev_priv);
Anusha Srivatsa21e33022016-10-14 16:47:05 -0700732 }
Alex Dai33a732f2015-08-12 15:43:36 +0100733
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000734 if (!HAS_GUC_UCODE(dev_priv)) {
Alex Dai33a732f2015-08-12 15:43:36 +0100735 fw_path = NULL;
Tvrtko Ursulind9486e62016-10-13 11:03:03 +0100736 } else if (IS_SKYLAKE(dev_priv)) {
Alex Dai33a732f2015-08-12 15:43:36 +0100737 fw_path = I915_SKL_GUC_UCODE;
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +0100738 guc_fw->guc_fw_major_wanted = SKL_FW_MAJOR;
739 guc_fw->guc_fw_minor_wanted = SKL_FW_MINOR;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100740 } else if (IS_BROXTON(dev_priv)) {
Nick Hoath57bf5c82016-05-06 11:42:53 +0100741 fw_path = I915_BXT_GUC_UCODE;
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +0100742 guc_fw->guc_fw_major_wanted = BXT_FW_MAJOR;
743 guc_fw->guc_fw_minor_wanted = BXT_FW_MINOR;
Tvrtko Ursulin08537232016-10-13 11:03:02 +0100744 } else if (IS_KABYLAKE(dev_priv)) {
Peter Antoineff64cc12016-06-30 09:37:52 -0700745 fw_path = I915_KBL_GUC_UCODE;
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +0100746 guc_fw->guc_fw_major_wanted = KBL_FW_MAJOR;
747 guc_fw->guc_fw_minor_wanted = KBL_FW_MINOR;
Alex Dai33a732f2015-08-12 15:43:36 +0100748 } else {
Alex Dai33a732f2015-08-12 15:43:36 +0100749 fw_path = ""; /* unknown device */
750 }
751
Alex Dai33a732f2015-08-12 15:43:36 +0100752 guc_fw->guc_fw_path = fw_path;
753 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_NONE;
754 guc_fw->guc_fw_load_status = GUC_FIRMWARE_NONE;
755
Dave Gordonfce91f22016-05-20 11:42:42 +0100756 /* Early (and silent) return if GuC loading is disabled */
757 if (!i915.enable_guc_loading)
758 return;
Alex Dai33a732f2015-08-12 15:43:36 +0100759 if (fw_path == NULL)
760 return;
Dave Gordonfce91f22016-05-20 11:42:42 +0100761 if (*fw_path == '\0')
Alex Dai33a732f2015-08-12 15:43:36 +0100762 return;
Alex Dai33a732f2015-08-12 15:43:36 +0100763
764 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_PENDING;
765 DRM_DEBUG_DRIVER("GuC firmware pending, path %s\n", fw_path);
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000766 guc_fw_fetch(dev_priv, guc_fw);
Alex Dai33a732f2015-08-12 15:43:36 +0100767 /* status must now be FAIL or SUCCESS */
768}
769
770/**
Dave Gordonf09d6752016-05-13 15:36:29 +0100771 * intel_guc_fini() - clean up all allocated resources
Tvrtko Ursulinb6ea8b42016-12-02 08:43:53 +0000772 * @dev_priv: i915 device private
Alex Dai33a732f2015-08-12 15:43:36 +0100773 */
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000774void intel_guc_fini(struct drm_i915_private *dev_priv)
Alex Dai33a732f2015-08-12 15:43:36 +0100775{
Alex Dai33a732f2015-08-12 15:43:36 +0100776 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
777
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000778 mutex_lock(&dev_priv->drm.struct_mutex);
Dave Gordon0c5664e2016-09-12 21:19:36 +0100779 guc_interrupts_release(dev_priv);
Dave Gordonbeffa512016-06-10 18:29:26 +0100780 i915_guc_submission_disable(dev_priv);
781 i915_guc_submission_fini(dev_priv);
Alex Daibac427f2015-08-12 15:43:39 +0100782
Alex Dai33a732f2015-08-12 15:43:36 +0100783 if (guc_fw->guc_fw_obj)
Chris Wilsonf8c417c2016-07-20 13:31:53 +0100784 i915_gem_object_put(guc_fw->guc_fw_obj);
Alex Dai33a732f2015-08-12 15:43:36 +0100785 guc_fw->guc_fw_obj = NULL;
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000786 mutex_unlock(&dev_priv->drm.struct_mutex);
Alex Dai33a732f2015-08-12 15:43:36 +0100787
788 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_NONE;
789}