blob: 9885f760f2efc6940f625554fb0b5f762a609343 [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 */
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080078const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
Alex Dai33a732f2015-08-12 15:43:36 +010079{
80 switch (status) {
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080081 case INTEL_UC_FIRMWARE_FAIL:
Alex Dai33a732f2015-08-12 15:43:36 +010082 return "FAIL";
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080083 case INTEL_UC_FIRMWARE_NONE:
Alex Dai33a732f2015-08-12 15:43:36 +010084 return "NONE";
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080085 case INTEL_UC_FIRMWARE_PENDING:
Alex Dai33a732f2015-08-12 15:43:36 +010086 return "PENDING";
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080087 case INTEL_UC_FIRMWARE_SUCCESS:
Alex Dai33a732f2015-08-12 15:43:36 +010088 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{
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800275 struct intel_uc_fw *guc_fw = &dev_priv->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
Anusha Srivatsabd1328582017-01-18 08:05:53 -0800331u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
Peter Antoine74aa1562016-05-17 15:12:45 +0100332{
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{
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800347 struct intel_uc_fw *guc_fw = &dev_priv->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
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800351 ret = i915_gem_object_set_to_gtt_domain(guc_fw->obj, false);
Alex Dai33a732f2015-08-12 15:43:36 +0100352 if (ret) {
353 DRM_DEBUG_DRIVER("set-domain failed %d\n", ret);
354 return ret;
355 }
356
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800357 vma = i915_gem_object_ggtt_pin(guc_fw->obj, NULL, 0, 0,
Michał Winiarski83796f22017-01-11 16:17:39 +0100358 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 */
Anusha Srivatsabd1328582017-01-18 08:05:53 -0800367 I915_WRITE(GUC_WOPCM_SIZE, intel_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{
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800445 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
446 const char *fw_path = guc_fw->path;
Dave Gordonfce91f22016-05-20 11:42:42 +0100447 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,
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800451 intel_uc_fw_status_repr(guc_fw->fetch_status),
452 intel_uc_fw_status_repr(guc_fw->load_status));
Dave Gordonfce91f22016-05-20 11:42:42 +0100453
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? */
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800470 if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) {
Dave Gordonfce91f22016-05-20 11:42:42 +0100471 err = -EIO;
472 goto fail;
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800473 } else if (guc_fw->load_status == INTEL_UC_FIRMWARE_FAIL) {
Dave Gordonfce91f22016-05-20 11:42:42 +0100474 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
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800484 guc_fw->load_status = INTEL_UC_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",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800487 intel_uc_fw_status_repr(guc_fw->fetch_status),
488 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Dai33a732f2015-08-12 15:43:36 +0100489
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
Anusha Srivatsabd1328582017-01-18 08:05:53 -0800509 intel_huc_load(dev_priv);
Dave Gordond7617012016-04-04 18:50:57 +0100510 err = guc_ucode_xfer(dev_priv);
511 if (!err)
512 break;
513
514 if (--retries == 0)
515 goto fail;
516
Dave Gordonfce91f22016-05-20 11:42:42 +0100517 DRM_INFO("GuC fw load failed: %d; will reset and "
518 "retry %d more time(s)\n", err, retries);
Arun Siluvery6b332fa2016-04-04 18:50:56 +0100519 }
Alex Dai33a732f2015-08-12 15:43:36 +0100520
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800521 guc_fw->load_status = INTEL_UC_FIRMWARE_SUCCESS;
Alex Dai33a732f2015-08-12 15:43:36 +0100522
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800523 intel_guc_auth_huc(dev_priv);
524
Dave Gordon44a28b12015-08-12 15:43:41 +0100525 if (i915.enable_guc_submission) {
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530526 if (i915.guc_log_level >= 0)
527 gen9_enable_guc_interrupts(dev_priv);
528
Dave Gordonbeffa512016-06-10 18:29:26 +0100529 err = i915_guc_submission_enable(dev_priv);
Dave Gordon44a28b12015-08-12 15:43:41 +0100530 if (err)
531 goto fail;
Dave Gordon0c5664e2016-09-12 21:19:36 +0100532 guc_interrupts_capture(dev_priv);
Dave Gordon44a28b12015-08-12 15:43:41 +0100533 }
534
Tvrtko Ursulinfb51ff42017-02-07 08:50:25 +0000535 DRM_INFO("GuC %s (firmware %s [version %u.%u])\n",
536 i915.enable_guc_submission ? "submission enabled" : "loaded",
537 guc_fw->path,
538 guc_fw->major_ver_found, guc_fw->minor_ver_found);
539
Alex Dai33a732f2015-08-12 15:43:36 +0100540 return 0;
541
542fail:
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800543 if (guc_fw->load_status == INTEL_UC_FIRMWARE_PENDING)
544 guc_fw->load_status = INTEL_UC_FIRMWARE_FAIL;
Alex Dai33a732f2015-08-12 15:43:36 +0100545
Dave Gordon0c5664e2016-09-12 21:19:36 +0100546 guc_interrupts_release(dev_priv);
Dave Gordonbeffa512016-06-10 18:29:26 +0100547 i915_guc_submission_disable(dev_priv);
548 i915_guc_submission_fini(dev_priv);
Chris Wilson7c3f86b2017-01-12 11:00:49 +0000549 i915_ggtt_disable_guc(dev_priv);
Dave Gordon44a28b12015-08-12 15:43:41 +0100550
Dave Gordonfce91f22016-05-20 11:42:42 +0100551 /*
552 * We've failed to load the firmware :(
553 *
554 * Decide whether to disable GuC submission and fall back to
555 * execlist mode, and whether to hide the error by returning
556 * zero or to return -EIO, which the caller will treat as a
557 * nonfatal error (i.e. it doesn't prevent driver load, but
558 * marks the GPU as wedged until reset).
559 */
560 if (i915.enable_guc_loading > 1) {
561 ret = -EIO;
562 } else if (i915.enable_guc_submission > 1) {
563 ret = -EIO;
564 } else {
565 ret = 0;
566 }
567
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000568 if (err == 0 && !HAS_GUC_UCODE(dev_priv))
Dave Gordon4e50f792016-06-10 17:21:25 +0100569 ; /* Don't mention the GuC! */
570 else if (err == 0)
Dave Gordonfce91f22016-05-20 11:42:42 +0100571 DRM_INFO("GuC firmware load skipped\n");
Dave Gordon4e50f792016-06-10 17:21:25 +0100572 else if (ret != -EIO)
Dave Gordonfc32de92016-08-18 18:17:24 +0100573 DRM_NOTE("GuC firmware load failed: %d\n", err);
Dave Gordon4e50f792016-06-10 17:21:25 +0100574 else
Dave Gordonfc32de92016-08-18 18:17:24 +0100575 DRM_WARN("GuC firmware load failed: %d\n", err);
Dave Gordonfce91f22016-05-20 11:42:42 +0100576
577 if (i915.enable_guc_submission) {
578 if (fw_path == NULL)
579 DRM_INFO("GuC submission without firmware not supported\n");
580 if (ret == 0)
Dave Gordonfc32de92016-08-18 18:17:24 +0100581 DRM_NOTE("Falling back from GuC submission to execlist mode\n");
Dave Gordonfce91f22016-05-20 11:42:42 +0100582 else
583 DRM_ERROR("GuC init failed: %d\n", ret);
584 }
585 i915.enable_guc_submission = 0;
586
587 return ret;
Alex Dai33a732f2015-08-12 15:43:36 +0100588}
589
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800590void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
591 struct intel_uc_fw *uc_fw)
Alex Dai33a732f2015-08-12 15:43:36 +0100592{
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000593 struct pci_dev *pdev = dev_priv->drm.pdev;
Alex Dai33a732f2015-08-12 15:43:36 +0100594 struct drm_i915_gem_object *obj;
Jérémy Lefaure3aaa8ab2016-11-28 18:43:19 -0500595 const struct firmware *fw = NULL;
Anusha Srivatsafbbad732017-01-13 17:17:05 -0800596 struct uc_css_header *css;
Alex Daifeda33e2015-10-19 16:10:54 -0700597 size_t size;
Alex Dai33a732f2015-08-12 15:43:36 +0100598 int err;
599
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800600 DRM_DEBUG_DRIVER("before requesting firmware: uC fw fetch status %s\n",
601 intel_uc_fw_status_repr(uc_fw->fetch_status));
Alex Dai33a732f2015-08-12 15:43:36 +0100602
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800603 err = request_firmware(&fw, uc_fw->path, &pdev->dev);
Alex Dai33a732f2015-08-12 15:43:36 +0100604 if (err)
605 goto fail;
606 if (!fw)
607 goto fail;
608
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800609 DRM_DEBUG_DRIVER("fetch uC fw from %s succeeded, fw %p\n",
610 uc_fw->path, fw);
Alex Dai33a732f2015-08-12 15:43:36 +0100611
Alex Daifeda33e2015-10-19 16:10:54 -0700612 /* Check the size of the blob before examining buffer contents */
Anusha Srivatsafbbad732017-01-13 17:17:05 -0800613 if (fw->size < sizeof(struct uc_css_header)) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100614 DRM_NOTE("Firmware header is missing\n");
Alex Dai33a732f2015-08-12 15:43:36 +0100615 goto fail;
Alex Daifeda33e2015-10-19 16:10:54 -0700616 }
617
Anusha Srivatsafbbad732017-01-13 17:17:05 -0800618 css = (struct uc_css_header *)fw->data;
Alex Daifeda33e2015-10-19 16:10:54 -0700619
620 /* Firmware bits always start from header */
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800621 uc_fw->header_offset = 0;
622 uc_fw->header_size = (css->header_size_dw - css->modulus_size_dw -
Alex Daifeda33e2015-10-19 16:10:54 -0700623 css->key_size_dw - css->exponent_size_dw) * sizeof(u32);
624
Anusha Srivatsafbbad732017-01-13 17:17:05 -0800625 if (uc_fw->header_size != sizeof(struct uc_css_header)) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100626 DRM_NOTE("CSS header definition mismatch\n");
Alex Daifeda33e2015-10-19 16:10:54 -0700627 goto fail;
628 }
629
630 /* then, uCode */
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800631 uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
632 uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);
Alex Daifeda33e2015-10-19 16:10:54 -0700633
634 /* now RSA */
635 if (css->key_size_dw != UOS_RSA_SCRATCH_MAX_COUNT) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100636 DRM_NOTE("RSA key size is bad\n");
Alex Daifeda33e2015-10-19 16:10:54 -0700637 goto fail;
638 }
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800639 uc_fw->rsa_offset = uc_fw->ucode_offset + uc_fw->ucode_size;
640 uc_fw->rsa_size = css->key_size_dw * sizeof(u32);
Alex Daifeda33e2015-10-19 16:10:54 -0700641
642 /* At least, it should have header, uCode and RSA. Size of all three. */
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800643 size = uc_fw->header_size + uc_fw->ucode_size + uc_fw->rsa_size;
Alex Daifeda33e2015-10-19 16:10:54 -0700644 if (fw->size < size) {
Dave Gordonfc32de92016-08-18 18:17:24 +0100645 DRM_NOTE("Missing firmware components\n");
Alex Daifeda33e2015-10-19 16:10:54 -0700646 goto fail;
647 }
648
Alex Dai33a732f2015-08-12 15:43:36 +0100649 /*
650 * The GuC firmware image has the version number embedded at a well-known
651 * offset within the firmware blob; note that major / minor version are
652 * TWO bytes each (i.e. u16), although all pointers and offsets are defined
653 * in terms of bytes (u8).
654 */
Anusha Srivatsafbbad732017-01-13 17:17:05 -0800655 switch (uc_fw->fw) {
656 case INTEL_UC_FW_TYPE_GUC:
657 /* Header and uCode will be loaded to WOPCM. Size of the two. */
658 size = uc_fw->header_size + uc_fw->ucode_size;
659
660 /* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */
Anusha Srivatsabd1328582017-01-18 08:05:53 -0800661 if (size > intel_guc_wopcm_size(dev_priv)) {
Anusha Srivatsafbbad732017-01-13 17:17:05 -0800662 DRM_ERROR("Firmware is too large to fit in WOPCM\n");
663 goto fail;
664 }
665 uc_fw->major_ver_found = css->guc.sw_version >> 16;
666 uc_fw->minor_ver_found = css->guc.sw_version & 0xFFFF;
667 break;
668
669 case INTEL_UC_FW_TYPE_HUC:
670 uc_fw->major_ver_found = css->huc.sw_version >> 16;
671 uc_fw->minor_ver_found = css->huc.sw_version & 0xFFFF;
672 break;
673
674 default:
675 DRM_ERROR("Unknown firmware type %d\n", uc_fw->fw);
676 err = -ENOEXEC;
677 goto fail;
678 }
Alex Dai33a732f2015-08-12 15:43:36 +0100679
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800680 if (uc_fw->major_ver_found != uc_fw->major_ver_wanted ||
681 uc_fw->minor_ver_found < uc_fw->minor_ver_wanted) {
682 DRM_NOTE("uC firmware version %d.%d, required %d.%d\n",
683 uc_fw->major_ver_found, uc_fw->minor_ver_found,
684 uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted);
Alex Dai33a732f2015-08-12 15:43:36 +0100685 err = -ENOEXEC;
686 goto fail;
687 }
688
689 DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800690 uc_fw->major_ver_found, uc_fw->minor_ver_found,
691 uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted);
Alex Dai33a732f2015-08-12 15:43:36 +0100692
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000693 mutex_lock(&dev_priv->drm.struct_mutex);
Tvrtko Ursulin12d79d72016-12-01 14:16:37 +0000694 obj = i915_gem_object_create_from_data(dev_priv, fw->data, fw->size);
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000695 mutex_unlock(&dev_priv->drm.struct_mutex);
Alex Dai33a732f2015-08-12 15:43:36 +0100696 if (IS_ERR_OR_NULL(obj)) {
697 err = obj ? PTR_ERR(obj) : -ENOMEM;
698 goto fail;
699 }
700
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800701 uc_fw->obj = obj;
702 uc_fw->size = fw->size;
Alex Dai33a732f2015-08-12 15:43:36 +0100703
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800704 DRM_DEBUG_DRIVER("uC fw fetch status SUCCESS, obj %p\n",
705 uc_fw->obj);
Alex Dai33a732f2015-08-12 15:43:36 +0100706
707 release_firmware(fw);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800708 uc_fw->fetch_status = INTEL_UC_FIRMWARE_SUCCESS;
Alex Dai33a732f2015-08-12 15:43:36 +0100709 return;
710
711fail:
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800712 DRM_WARN("Failed to fetch valid uC firmware from %s (error %d)\n",
713 uc_fw->path, err);
714 DRM_DEBUG_DRIVER("uC fw fetch status FAIL; err %d, fw %p, obj %p\n",
715 err, fw, uc_fw->obj);
Alex Dai33a732f2015-08-12 15:43:36 +0100716
Chris Wilson65300b12017-02-14 13:34:20 +0000717 obj = fetch_and_zero(&uc_fw->obj);
Alex Dai33a732f2015-08-12 15:43:36 +0100718 if (obj)
Chris Wilsonf8c417c2016-07-20 13:31:53 +0100719 i915_gem_object_put(obj);
Alex Dai33a732f2015-08-12 15:43:36 +0100720
721 release_firmware(fw); /* OK even if fw is NULL */
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800722 uc_fw->fetch_status = INTEL_UC_FIRMWARE_FAIL;
Alex Dai33a732f2015-08-12 15:43:36 +0100723}
724
725/**
Dave Gordonf09d6752016-05-13 15:36:29 +0100726 * intel_guc_init() - define parameters and fetch firmware
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000727 * @dev_priv: i915 device private
Alex Dai33a732f2015-08-12 15:43:36 +0100728 *
729 * Called early during driver load, but after GEM is initialised.
Alex Dai33a732f2015-08-12 15:43:36 +0100730 *
731 * The firmware will be transferred to the GuC's memory later,
Dave Gordonf09d6752016-05-13 15:36:29 +0100732 * when intel_guc_setup() is called.
Alex Dai33a732f2015-08-12 15:43:36 +0100733 */
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000734void intel_guc_init(struct drm_i915_private *dev_priv)
Alex Dai33a732f2015-08-12 15:43:36 +0100735{
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800736 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Dai33a732f2015-08-12 15:43:36 +0100737 const char *fw_path;
738
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000739 if (!HAS_GUC(dev_priv)) {
Anusha Srivatsa21e33022016-10-14 16:47:05 -0700740 i915.enable_guc_loading = 0;
741 i915.enable_guc_submission = 0;
742 } else {
743 /* A negative value means "use platform default" */
744 if (i915.enable_guc_loading < 0)
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000745 i915.enable_guc_loading = HAS_GUC_UCODE(dev_priv);
Anusha Srivatsa21e33022016-10-14 16:47:05 -0700746 if (i915.enable_guc_submission < 0)
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000747 i915.enable_guc_submission = HAS_GUC_SCHED(dev_priv);
Anusha Srivatsa21e33022016-10-14 16:47:05 -0700748 }
Alex Dai33a732f2015-08-12 15:43:36 +0100749
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +0000750 if (!HAS_GUC_UCODE(dev_priv)) {
Alex Dai33a732f2015-08-12 15:43:36 +0100751 fw_path = NULL;
Tvrtko Ursulind9486e62016-10-13 11:03:03 +0100752 } else if (IS_SKYLAKE(dev_priv)) {
Alex Dai33a732f2015-08-12 15:43:36 +0100753 fw_path = I915_SKL_GUC_UCODE;
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800754 guc_fw->major_ver_wanted = SKL_FW_MAJOR;
755 guc_fw->minor_ver_wanted = SKL_FW_MINOR;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100756 } else if (IS_BROXTON(dev_priv)) {
Nick Hoath57bf5c82016-05-06 11:42:53 +0100757 fw_path = I915_BXT_GUC_UCODE;
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800758 guc_fw->major_ver_wanted = BXT_FW_MAJOR;
759 guc_fw->minor_ver_wanted = BXT_FW_MINOR;
Tvrtko Ursulin08537232016-10-13 11:03:02 +0100760 } else if (IS_KABYLAKE(dev_priv)) {
Peter Antoineff64cc12016-06-30 09:37:52 -0700761 fw_path = I915_KBL_GUC_UCODE;
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800762 guc_fw->major_ver_wanted = KBL_FW_MAJOR;
763 guc_fw->minor_ver_wanted = KBL_FW_MINOR;
Alex Dai33a732f2015-08-12 15:43:36 +0100764 } else {
Alex Dai33a732f2015-08-12 15:43:36 +0100765 fw_path = ""; /* unknown device */
766 }
767
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800768 guc_fw->path = fw_path;
769 guc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
770 guc_fw->load_status = INTEL_UC_FIRMWARE_NONE;
Alex Dai33a732f2015-08-12 15:43:36 +0100771
Dave Gordonfce91f22016-05-20 11:42:42 +0100772 /* Early (and silent) return if GuC loading is disabled */
773 if (!i915.enable_guc_loading)
774 return;
Alex Dai33a732f2015-08-12 15:43:36 +0100775 if (fw_path == NULL)
776 return;
Dave Gordonfce91f22016-05-20 11:42:42 +0100777 if (*fw_path == '\0')
Alex Dai33a732f2015-08-12 15:43:36 +0100778 return;
Alex Dai33a732f2015-08-12 15:43:36 +0100779
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800780 guc_fw->fetch_status = INTEL_UC_FIRMWARE_PENDING;
Alex Dai33a732f2015-08-12 15:43:36 +0100781 DRM_DEBUG_DRIVER("GuC firmware pending, path %s\n", fw_path);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800782 intel_uc_fw_fetch(dev_priv, guc_fw);
Alex Dai33a732f2015-08-12 15:43:36 +0100783 /* status must now be FAIL or SUCCESS */
784}
785
786/**
Dave Gordonf09d6752016-05-13 15:36:29 +0100787 * intel_guc_fini() - clean up all allocated resources
Tvrtko Ursulinb6ea8b42016-12-02 08:43:53 +0000788 * @dev_priv: i915 device private
Alex Dai33a732f2015-08-12 15:43:36 +0100789 */
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000790void intel_guc_fini(struct drm_i915_private *dev_priv)
Alex Dai33a732f2015-08-12 15:43:36 +0100791{
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800792 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Chris Wilson65300b12017-02-14 13:34:20 +0000793 struct drm_i915_gem_object *obj;
Alex Dai33a732f2015-08-12 15:43:36 +0100794
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000795 mutex_lock(&dev_priv->drm.struct_mutex);
Dave Gordon0c5664e2016-09-12 21:19:36 +0100796 guc_interrupts_release(dev_priv);
Dave Gordonbeffa512016-06-10 18:29:26 +0100797 i915_guc_submission_disable(dev_priv);
798 i915_guc_submission_fini(dev_priv);
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000799 mutex_unlock(&dev_priv->drm.struct_mutex);
Alex Dai33a732f2015-08-12 15:43:36 +0100800
Chris Wilson65300b12017-02-14 13:34:20 +0000801 obj = fetch_and_zero(&guc_fw->obj);
802 if (obj)
803 i915_gem_object_put(obj);
804
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800805 guc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
Alex Dai33a732f2015-08-12 15:43:36 +0100806}