blob: 62ebf5605f6e3deca7229172efda916d4b2f29e0 [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 */
Alex Dai33a732f2015-08-12 15:43:36 +010029#include "i915_drv.h"
Arkadiusz Hiler8c4f24f2016-11-25 18:59:33 +010030#include "intel_uc.h"
Alex Dai33a732f2015-08-12 15:43:36 +010031
32/**
Alex Daifeda33e2015-10-19 16:10:54 -070033 * DOC: GuC-specific firmware loader
Alex Dai33a732f2015-08-12 15:43:36 +010034 *
35 * intel_guc:
36 * Top level structure of guc. It handles firmware loading and manages client
37 * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
38 * ExecList submission.
39 *
40 * Firmware versioning:
41 * The firmware build process will generate a version header file with major and
42 * minor version defined. The versions are built into CSS header of firmware.
43 * i915 kernel driver set the minimal firmware version required per platform.
44 * The firmware installation package will install (symbolic link) proper version
45 * of firmware.
46 *
47 * GuC address space:
48 * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
49 * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
50 * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
51 * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
52 *
Alex Dai33a732f2015-08-12 15:43:36 +010053 */
54
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +010055#define SKL_FW_MAJOR 6
56#define SKL_FW_MINOR 1
57
58#define BXT_FW_MAJOR 8
59#define BXT_FW_MINOR 7
60
61#define KBL_FW_MAJOR 9
62#define KBL_FW_MINOR 14
63
64#define GUC_FW_PATH(platform, major, minor) \
65 "i915/" __stringify(platform) "_guc_ver" __stringify(major) "_" __stringify(minor) ".bin"
66
67#define I915_SKL_GUC_UCODE GUC_FW_PATH(skl, SKL_FW_MAJOR, SKL_FW_MINOR)
Alex Dai33a732f2015-08-12 15:43:36 +010068MODULE_FIRMWARE(I915_SKL_GUC_UCODE);
69
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +010070#define I915_BXT_GUC_UCODE GUC_FW_PATH(bxt, BXT_FW_MAJOR, BXT_FW_MINOR)
Nick Hoath57bf5c82016-05-06 11:42:53 +010071MODULE_FIRMWARE(I915_BXT_GUC_UCODE);
72
Tvrtko Ursulin5e334c12016-08-10 16:16:46 +010073#define I915_KBL_GUC_UCODE GUC_FW_PATH(kbl, KBL_FW_MAJOR, KBL_FW_MINOR)
Peter Antoineff64cc12016-06-30 09:37:52 -070074MODULE_FIRMWARE(I915_KBL_GUC_UCODE);
75
Alex Dai33a732f2015-08-12 15:43:36 +010076/* User-friendly representation of an enum */
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080077const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
Alex Dai33a732f2015-08-12 15:43:36 +010078{
79 switch (status) {
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080080 case INTEL_UC_FIRMWARE_FAIL:
Alex Dai33a732f2015-08-12 15:43:36 +010081 return "FAIL";
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080082 case INTEL_UC_FIRMWARE_NONE:
Alex Dai33a732f2015-08-12 15:43:36 +010083 return "NONE";
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080084 case INTEL_UC_FIRMWARE_PENDING:
Alex Dai33a732f2015-08-12 15:43:36 +010085 return "PENDING";
Anusha Srivatsadb0a0912017-01-13 17:17:04 -080086 case INTEL_UC_FIRMWARE_SUCCESS:
Alex Dai33a732f2015-08-12 15:43:36 +010087 return "SUCCESS";
88 default:
89 return "UNKNOWN!";
90 }
91};
92
93static u32 get_gttype(struct drm_i915_private *dev_priv)
94{
95 /* XXX: GT type based on PCI device ID? field seems unused by fw */
96 return 0;
97}
98
99static u32 get_core_family(struct drm_i915_private *dev_priv)
100{
Dave Gordonfc32de92016-08-18 18:17:24 +0100101 u32 gen = INTEL_GEN(dev_priv);
102
103 switch (gen) {
Alex Dai33a732f2015-08-12 15:43:36 +0100104 case 9:
105 return GFXCORE_FAMILY_GEN9;
106
107 default:
Dave Gordonfc32de92016-08-18 18:17:24 +0100108 WARN(1, "GEN%d does not support GuC operation!\n", gen);
Alex Dai33a732f2015-08-12 15:43:36 +0100109 return GFXCORE_FAMILY_UNKNOWN;
110 }
111}
112
Dave Gordon0c5664e2016-09-12 21:19:36 +0100113/*
114 * Initialise the GuC parameter block before starting the firmware
115 * transfer. These parameters are read by the firmware on startup
116 * and cannot be changed thereafter.
117 */
118static void guc_params_init(struct drm_i915_private *dev_priv)
Alex Dai33a732f2015-08-12 15:43:36 +0100119{
120 struct intel_guc *guc = &dev_priv->guc;
121 u32 params[GUC_CTL_MAX_DWORDS];
122 int i;
123
124 memset(&params, 0, sizeof(params));
125
126 params[GUC_CTL_DEVICE_INFO] |=
127 (get_gttype(dev_priv) << GUC_CTL_GTTYPE_SHIFT) |
128 (get_core_family(dev_priv) << GUC_CTL_COREFAMILY_SHIFT);
129
130 /*
131 * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one
132 * second. This ARAR is calculated by:
133 * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10
134 */
135 params[GUC_CTL_ARAT_HIGH] = 0;
136 params[GUC_CTL_ARAT_LOW] = 100000000;
137
138 params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER;
139
140 params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER |
141 GUC_CTL_VCS2_ENABLED;
142
Akash Goeld6b40b42016-10-12 21:54:29 +0530143 params[GUC_CTL_LOG_PARAMS] = guc->log.flags;
Sagar Arun Kambleb1e37102016-10-12 21:54:27 +0530144
Alex Dai33a732f2015-08-12 15:43:36 +0100145 if (i915.guc_log_level >= 0) {
Alex Dai33a732f2015-08-12 15:43:36 +0100146 params[GUC_CTL_DEBUG] =
147 i915.guc_log_level << GUC_LOG_VERBOSITY_SHIFT;
Sagar Arun Kambleb1e37102016-10-12 21:54:27 +0530148 } else
149 params[GUC_CTL_DEBUG] = GUC_LOG_DISABLED;
Alex Dai33a732f2015-08-12 15:43:36 +0100150
Alex Daibac427f2015-08-12 15:43:39 +0100151 /* If GuC submission is enabled, set up additional parameters here */
152 if (i915.enable_guc_submission) {
Oscar Mateo0704df22017-03-22 10:39:47 -0700153 u32 ads = guc_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT;
Oscar Mateo73b05532017-03-22 10:39:45 -0700154 u32 pgs = guc_ggtt_offset(dev_priv->guc.ctx_pool);
Alex Daibac427f2015-08-12 15:43:39 +0100155 u32 ctx_in_16 = GUC_MAX_GPU_CONTEXTS / 16;
156
Oscar Mateo0704df22017-03-22 10:39:47 -0700157 params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
158 params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
159
Alex Daibac427f2015-08-12 15:43:39 +0100160 pgs >>= PAGE_SHIFT;
161 params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) |
162 (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT);
163
164 params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS;
165
166 /* Unmask this bit to enable the GuC's internal scheduler */
167 params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER;
168 }
169
Alex Dai33a732f2015-08-12 15:43:36 +0100170 I915_WRITE(SOFT_SCRATCH(0), 0);
171
172 for (i = 0; i < GUC_CTL_MAX_DWORDS; i++)
173 I915_WRITE(SOFT_SCRATCH(1 + i), params[i]);
174}
175
176/*
177 * Read the GuC status register (GUC_STATUS) and store it in the
178 * specified location; then return a boolean indicating whether
179 * the value matches either of two values representing completion
180 * of the GuC boot process.
181 *
Tvrtko Ursulin36894e82016-02-11 10:27:31 +0000182 * This is used for polling the GuC status in a wait_for()
Alex Dai33a732f2015-08-12 15:43:36 +0100183 * loop below.
184 */
185static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
186 u32 *status)
187{
188 u32 val = I915_READ(GUC_STATUS);
Alex Dai0d44d3f2015-09-22 13:48:40 -0700189 u32 uk_val = val & GS_UKERNEL_MASK;
Alex Dai33a732f2015-08-12 15:43:36 +0100190 *status = val;
Alex Dai0d44d3f2015-09-22 13:48:40 -0700191 return (uk_val == GS_UKERNEL_READY ||
192 ((val & GS_MIA_CORE_STATE) && uk_val == GS_UKERNEL_LAPIC_DONE));
Alex Dai33a732f2015-08-12 15:43:36 +0100193}
194
195/*
196 * Transfer the firmware image to RAM for execution by the microcontroller.
197 *
Alex Dai33a732f2015-08-12 15:43:36 +0100198 * Architecturally, the DMA engine is bidirectional, and can potentially even
199 * transfer between GTT locations. This functionality is left out of the API
200 * for now as there is no need for it.
201 *
202 * Note that GuC needs the CSS header plus uKernel code to be copied by the
203 * DMA engine in one operation, whereas the RSA signature is loaded via MMIO.
204 */
Chris Wilson058d88c2016-08-15 10:49:06 +0100205static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv,
206 struct i915_vma *vma)
Alex Dai33a732f2015-08-12 15:43:36 +0100207{
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800208 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Dai33a732f2015-08-12 15:43:36 +0100209 unsigned long offset;
Chris Wilson058d88c2016-08-15 10:49:06 +0100210 struct sg_table *sg = vma->pages;
Alex Daifeda33e2015-10-19 16:10:54 -0700211 u32 status, rsa[UOS_RSA_SCRATCH_MAX_COUNT];
Alex Dai33a732f2015-08-12 15:43:36 +0100212 int i, ret = 0;
213
Alex Daifeda33e2015-10-19 16:10:54 -0700214 /* where RSA signature starts */
215 offset = guc_fw->rsa_offset;
Alex Dai33a732f2015-08-12 15:43:36 +0100216
217 /* Copy RSA signature from the fw image to HW for verification */
Alex Daifeda33e2015-10-19 16:10:54 -0700218 sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, sizeof(rsa), offset);
219 for (i = 0; i < UOS_RSA_SCRATCH_MAX_COUNT; i++)
Ville Syrjäläab9cc552015-09-18 20:03:24 +0300220 I915_WRITE(UOS_RSA_SCRATCH(i), rsa[i]);
Alex Dai33a732f2015-08-12 15:43:36 +0100221
Alex Daifeda33e2015-10-19 16:10:54 -0700222 /* The header plus uCode will be copied to WOPCM via DMA, excluding any
223 * other components */
224 I915_WRITE(DMA_COPY_SIZE, guc_fw->header_size + guc_fw->ucode_size);
225
Alex Dai33a732f2015-08-12 15:43:36 +0100226 /* Set the source address for the new blob */
Chris Wilson4741da92016-12-24 19:31:46 +0000227 offset = guc_ggtt_offset(vma) + guc_fw->header_offset;
Alex Dai33a732f2015-08-12 15:43:36 +0100228 I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset));
229 I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF);
230
231 /*
232 * Set the DMA destination. Current uCode expects the code to be
233 * loaded at 8k; locations below this are used for the stack.
234 */
235 I915_WRITE(DMA_ADDR_1_LOW, 0x2000);
236 I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM);
237
238 /* Finally start the DMA */
239 I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(UOS_MOVE | START_DMA));
240
241 /*
Tvrtko Ursulin36894e82016-02-11 10:27:31 +0000242 * Wait for the DMA to complete & the GuC to start up.
Alex Dai33a732f2015-08-12 15:43:36 +0100243 * NB: Docs recommend not using the interrupt for completion.
244 * Measurements indicate this should take no more than 20ms, so a
245 * timeout here indicates that the GuC has failed and is unusable.
246 * (Higher levels of the driver will attempt to fall back to
247 * execlist mode if this happens.)
248 */
Tvrtko Ursulin36894e82016-02-11 10:27:31 +0000249 ret = wait_for(guc_ucode_response(dev_priv, &status), 100);
Alex Dai33a732f2015-08-12 15:43:36 +0100250
251 DRM_DEBUG_DRIVER("DMA status 0x%x, GuC status 0x%x\n",
252 I915_READ(DMA_CTRL), status);
253
254 if ((status & GS_BOOTROM_MASK) == GS_BOOTROM_RSA_FAILED) {
255 DRM_ERROR("GuC firmware signature verification failed\n");
256 ret = -ENOEXEC;
257 }
258
259 DRM_DEBUG_DRIVER("returning %d\n", ret);
260
261 return ret;
262}
263
Anusha Srivatsabd1328582017-01-18 08:05:53 -0800264u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
Peter Antoine74aa1562016-05-17 15:12:45 +0100265{
266 u32 wopcm_size = GUC_WOPCM_TOP;
267
268 /* On BXT, the top of WOPCM is reserved for RC6 context */
Michel Thierry254e0932017-01-09 16:51:35 +0200269 if (IS_GEN9_LP(dev_priv))
Peter Antoine74aa1562016-05-17 15:12:45 +0100270 wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
271
272 return wopcm_size;
273}
274
Alex Dai33a732f2015-08-12 15:43:36 +0100275/*
276 * Load the GuC firmware blob into the MinuteIA.
277 */
278static int guc_ucode_xfer(struct drm_i915_private *dev_priv)
279{
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800280 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Chris Wilson058d88c2016-08-15 10:49:06 +0100281 struct i915_vma *vma;
Alex Dai33a732f2015-08-12 15:43:36 +0100282 int ret;
283
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800284 ret = i915_gem_object_set_to_gtt_domain(guc_fw->obj, false);
Alex Dai33a732f2015-08-12 15:43:36 +0100285 if (ret) {
286 DRM_DEBUG_DRIVER("set-domain failed %d\n", ret);
287 return ret;
288 }
289
Anusha Srivatsadb0a0912017-01-13 17:17:04 -0800290 vma = i915_gem_object_ggtt_pin(guc_fw->obj, NULL, 0, 0,
Michał Winiarski83796f22017-01-11 16:17:39 +0100291 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
Chris Wilson058d88c2016-08-15 10:49:06 +0100292 if (IS_ERR(vma)) {
293 DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma));
294 return PTR_ERR(vma);
Alex Dai33a732f2015-08-12 15:43:36 +0100295 }
296
Alex Dai33a732f2015-08-12 15:43:36 +0100297 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
298
299 /* init WOPCM */
Anusha Srivatsabd1328582017-01-18 08:05:53 -0800300 I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
Alex Dai33a732f2015-08-12 15:43:36 +0100301 I915_WRITE(DMA_GUC_WOPCM_OFFSET, GUC_WOPCM_OFFSET_VALUE);
302
303 /* Enable MIA caching. GuC clock gating is disabled. */
304 I915_WRITE(GUC_SHIM_CONTROL, GUC_SHIM_CONTROL_VALUE);
305
Jani Nikulaa117f372016-09-16 16:59:44 +0300306 /* WaDisableMinuteIaClockGating:bxt */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100307 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
Nick Hoathb970b482015-09-08 10:31:53 +0100308 I915_WRITE(GUC_SHIM_CONTROL, (I915_READ(GUC_SHIM_CONTROL) &
309 ~GUC_ENABLE_MIA_CLOCK_GATING));
310 }
311
Jani Nikula4ff40a42016-09-26 15:07:51 +0300312 /* WaC6DisallowByGfxPause:bxt */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100313 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0))
Tim Gore65fe29e2016-07-20 11:00:25 +0100314 I915_WRITE(GEN6_GFXPAUSE, 0x30FFF);
Alex Dai33a732f2015-08-12 15:43:36 +0100315
Michel Thierry254e0932017-01-09 16:51:35 +0200316 if (IS_GEN9_LP(dev_priv))
Alex Dai33a732f2015-08-12 15:43:36 +0100317 I915_WRITE(GEN9LP_GT_PM_CONFIG, GT_DOORBELL_ENABLE);
318 else
319 I915_WRITE(GEN9_GT_PM_CONFIG, GT_DOORBELL_ENABLE);
320
Tvrtko Ursulin5db94012016-10-13 11:03:10 +0100321 if (IS_GEN9(dev_priv)) {
Alex Dai33a732f2015-08-12 15:43:36 +0100322 /* DOP Clock Gating Enable for GuC clocks */
323 I915_WRITE(GEN7_MISCCPCTL, (GEN8_DOP_CLOCK_GATE_GUC_ENABLE |
324 I915_READ(GEN7_MISCCPCTL)));
325
Dave Gordon0c5664e2016-09-12 21:19:36 +0100326 /* allows for 5us (in 10ns units) before GT can go to RC6 */
Alex Dai33a732f2015-08-12 15:43:36 +0100327 I915_WRITE(GUC_ARAT_C6DIS, 0x1FF);
328 }
329
Dave Gordon0c5664e2016-09-12 21:19:36 +0100330 guc_params_init(dev_priv);
Alex Dai33a732f2015-08-12 15:43:36 +0100331
Chris Wilson058d88c2016-08-15 10:49:06 +0100332 ret = guc_ucode_xfer_dma(dev_priv, vma);
Alex Dai33a732f2015-08-12 15:43:36 +0100333
334 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
335
336 /*
337 * We keep the object pages for reuse during resume. But we can unpin it
338 * now that DMA has completed, so it doesn't continue to take up space.
339 */
Chris Wilson058d88c2016-08-15 10:49:06 +0100340 i915_vma_unpin(vma);
Alex Dai33a732f2015-08-12 15:43:36 +0100341
342 return ret;
343}
344
345/**
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100346 * intel_guc_init_hw() - finish preparing the GuC for activity
347 * @guc: intel_guc structure
Alex Dai33a732f2015-08-12 15:43:36 +0100348 *
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100349 * Called during driver loading and also after a GPU reset.
Alex Dai33a732f2015-08-12 15:43:36 +0100350 *
Dave Gordonf09d6752016-05-13 15:36:29 +0100351 * The main action required here it to load the GuC uCode into the device.
Alex Dai33a732f2015-08-12 15:43:36 +0100352 * The firmware image should have already been fetched into memory by the
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100353 * earlier call to intel_guc_init(), so here we need only check that
354 * worked, and then transfer the image to the h/w.
Alex Dai33a732f2015-08-12 15:43:36 +0100355 *
356 * Return: non-zero code on error
357 */
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100358int intel_guc_init_hw(struct intel_guc *guc)
Alex Dai33a732f2015-08-12 15:43:36 +0100359{
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100360 struct drm_i915_private *dev_priv = guc_to_i915(guc);
361 const char *fw_path = guc->fw.path;
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100362 int ret;
Alex Dai33a732f2015-08-12 15:43:36 +0100363
Dave Gordonfce91f22016-05-20 11:42:42 +0100364 DRM_DEBUG_DRIVER("GuC fw status: path %s, fetch %s, load %s\n",
365 fw_path,
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100366 intel_uc_fw_status_repr(guc->fw.fetch_status),
367 intel_uc_fw_status_repr(guc->fw.load_status));
Dave Gordonfce91f22016-05-20 11:42:42 +0100368
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100369 if (guc->fw.fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
370 return -EIO;
Chris Wilson7c3f86b2017-01-12 11:00:49 +0000371
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100372 guc->fw.load_status = INTEL_UC_FIRMWARE_PENDING;
Daniel Vetter9f9e5392015-10-23 11:10:59 +0200373
Alex Dai33a732f2015-08-12 15:43:36 +0100374 DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n",
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100375 intel_uc_fw_status_repr(guc->fw.fetch_status),
376 intel_uc_fw_status_repr(guc->fw.load_status));
Alex Dai33a732f2015-08-12 15:43:36 +0100377
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100378 ret = guc_ucode_xfer(dev_priv);
Alex Daibac427f2015-08-12 15:43:39 +0100379
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100380 if (ret)
381 return -EAGAIN;
Alex Dai33a732f2015-08-12 15:43:36 +0100382
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100383 guc->fw.load_status = INTEL_UC_FIRMWARE_SUCCESS;
Alex Dai33a732f2015-08-12 15:43:36 +0100384
Tvrtko Ursulinfb51ff42017-02-07 08:50:25 +0000385 DRM_INFO("GuC %s (firmware %s [version %u.%u])\n",
386 i915.enable_guc_submission ? "submission enabled" : "loaded",
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100387 guc->fw.path,
388 guc->fw.major_ver_found, guc->fw.minor_ver_found);
Tvrtko Ursulinfb51ff42017-02-07 08:50:25 +0000389
Alex Dai33a732f2015-08-12 15:43:36 +0100390 return 0;
Alex Dai33a732f2015-08-12 15:43:36 +0100391}
392
Alex Dai33a732f2015-08-12 15:43:36 +0100393/**
Arkadiusz Hilerb551f612017-03-14 15:28:13 +0100394 * intel_guc_select_fw() - selects GuC firmware for loading
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100395 * @guc: intel_guc struct
Alex Dai33a732f2015-08-12 15:43:36 +0100396 *
Arkadiusz Hilerb551f612017-03-14 15:28:13 +0100397 * Return: zero when we know firmware, non-zero in other case
Alex Dai33a732f2015-08-12 15:43:36 +0100398 */
Arkadiusz Hilerb551f612017-03-14 15:28:13 +0100399int intel_guc_select_fw(struct intel_guc *guc)
Alex Dai33a732f2015-08-12 15:43:36 +0100400{
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100401 struct drm_i915_private *dev_priv = guc_to_i915(guc);
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100402
403 guc->fw.path = NULL;
404 guc->fw.fetch_status = INTEL_UC_FIRMWARE_NONE;
405 guc->fw.load_status = INTEL_UC_FIRMWARE_NONE;
Arkadiusz Hiler6833b822017-03-15 14:34:15 +0100406 guc->fw.type = INTEL_UC_FW_TYPE_GUC;
Alex Dai33a732f2015-08-12 15:43:36 +0100407
Arkadiusz Hilerb3420dd2017-03-14 15:28:14 +0100408 if (i915.guc_firmware_path) {
409 guc->fw.path = i915.guc_firmware_path;
410 guc->fw.major_ver_wanted = 0;
411 guc->fw.minor_ver_wanted = 0;
412 } else if (IS_SKYLAKE(dev_priv)) {
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100413 guc->fw.path = I915_SKL_GUC_UCODE;
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100414 guc->fw.major_ver_wanted = SKL_FW_MAJOR;
415 guc->fw.minor_ver_wanted = SKL_FW_MINOR;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100416 } else if (IS_BROXTON(dev_priv)) {
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100417 guc->fw.path = I915_BXT_GUC_UCODE;
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100418 guc->fw.major_ver_wanted = BXT_FW_MAJOR;
419 guc->fw.minor_ver_wanted = BXT_FW_MINOR;
Tvrtko Ursulin08537232016-10-13 11:03:02 +0100420 } else if (IS_KABYLAKE(dev_priv)) {
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100421 guc->fw.path = I915_KBL_GUC_UCODE;
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100422 guc->fw.major_ver_wanted = KBL_FW_MAJOR;
423 guc->fw.minor_ver_wanted = KBL_FW_MINOR;
Alex Dai33a732f2015-08-12 15:43:36 +0100424 } else {
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100425 DRM_ERROR("No GuC firmware known for platform with GuC!\n");
Arkadiusz Hilerb551f612017-03-14 15:28:13 +0100426 return -ENOENT;
Alex Dai33a732f2015-08-12 15:43:36 +0100427 }
428
Arkadiusz Hilerb551f612017-03-14 15:28:13 +0100429 return 0;
Alex Dai33a732f2015-08-12 15:43:36 +0100430}