blob: d17029c57433c23c9d05d23514094ba8e5be290a [file] [log] [blame]
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +01001/*
2 * Copyright © 2016 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 */
24
25#include "i915_drv.h"
26#include "intel_uc.h"
Arkadiusz Hiler4c0fed72017-03-14 15:28:08 +010027#include <linux/firmware.h>
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +010028
Michal Wajdeczko00bbb722017-03-30 11:21:13 +000029/* Cleans up uC firmware by releasing the firmware GEM obj.
30 */
31static void __intel_uc_fw_fini(struct intel_uc_fw *uc_fw)
32{
33 struct drm_i915_gem_object *obj;
34
35 obj = fetch_and_zero(&uc_fw->obj);
36 if (obj)
37 i915_gem_object_put(obj);
38
39 uc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
40}
41
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +010042/* Reset GuC providing us with fresh state for both GuC and HuC.
43 */
44static int __intel_uc_reset_hw(struct drm_i915_private *dev_priv)
45{
46 int ret;
47 u32 guc_status;
48
49 ret = intel_guc_reset(dev_priv);
50 if (ret) {
51 DRM_ERROR("GuC reset failed, ret = %d\n", ret);
52 return ret;
53 }
54
55 guc_status = I915_READ(GUC_STATUS);
56 WARN(!(guc_status & GS_MIA_IN_RESET),
57 "GuC status: 0x%x, MIA core expected to be in reset\n",
58 guc_status);
59
60 return ret;
61}
62
Arkadiusz Hilerd2be9f22017-03-14 15:28:10 +010063void intel_uc_sanitize_options(struct drm_i915_private *dev_priv)
64{
65 if (!HAS_GUC(dev_priv)) {
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +000066 if (i915.enable_guc_loading > 0 ||
67 i915.enable_guc_submission > 0)
68 DRM_INFO("Ignoring GuC options, no hardware\n");
Arkadiusz Hilerd2be9f22017-03-14 15:28:10 +010069
70 i915.enable_guc_loading = 0;
71 i915.enable_guc_submission = 0;
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +000072 return;
Arkadiusz Hilerd2be9f22017-03-14 15:28:10 +010073 }
Arkadiusz Hilerb551f612017-03-14 15:28:13 +010074
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +000075 /* A negative value means "use platform default" */
76 if (i915.enable_guc_loading < 0)
77 i915.enable_guc_loading = HAS_GUC_UCODE(dev_priv);
78
79 /* Verify firmware version */
Arkadiusz Hilerb551f612017-03-14 15:28:13 +010080 if (i915.enable_guc_loading) {
81 if (HAS_HUC_UCODE(dev_priv))
82 intel_huc_select_fw(&dev_priv->huc);
83
84 if (intel_guc_select_fw(&dev_priv->guc))
85 i915.enable_guc_loading = 0;
86 }
Michal Wajdeczkod4a70a12017-03-15 13:37:41 +000087
88 /* Can't enable guc submission without guc loaded */
89 if (!i915.enable_guc_loading)
90 i915.enable_guc_submission = 0;
91
92 /* A negative value means "use platform default" */
93 if (i915.enable_guc_submission < 0)
94 i915.enable_guc_submission = HAS_GUC_SCHED(dev_priv);
Arkadiusz Hilerd2be9f22017-03-14 15:28:10 +010095}
96
Michal Wajdeczkoa03aac42017-05-10 12:59:26 +000097static void guc_write_irq_trigger(struct intel_guc *guc)
98{
99 struct drm_i915_private *dev_priv = guc_to_i915(guc);
100
101 I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER);
102}
103
Arkadiusz Hiler413e8fd2016-11-25 18:59:36 +0100104void intel_uc_init_early(struct drm_i915_private *dev_priv)
105{
Oscar Mateo5e7cd372017-03-22 10:39:49 -0700106 struct intel_guc *guc = &dev_priv->guc;
107
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000108 intel_guc_ct_init_early(&guc->ct);
109
Oscar Mateo5e7cd372017-03-22 10:39:49 -0700110 mutex_init(&guc->send_mutex);
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000111 guc->send = intel_guc_send_nop;
Michal Wajdeczkoa03aac42017-05-10 12:59:26 +0000112 guc->notify = guc_write_irq_trigger;
Arkadiusz Hiler413e8fd2016-11-25 18:59:36 +0100113}
114
Michal Wajdeczko9d98af0b2017-03-27 09:45:10 +0000115static void fetch_uc_fw(struct drm_i915_private *dev_priv,
116 struct intel_uc_fw *uc_fw)
117{
118 struct pci_dev *pdev = dev_priv->drm.pdev;
119 struct drm_i915_gem_object *obj;
120 const struct firmware *fw = NULL;
121 struct uc_css_header *css;
122 size_t size;
123 int err;
124
Michal Wajdeczkob57f7f72017-03-30 11:21:15 +0000125 if (!uc_fw->path)
126 return;
127
Michal Wajdeczko9d98af0b2017-03-27 09:45:10 +0000128 uc_fw->fetch_status = INTEL_UC_FIRMWARE_PENDING;
129
130 DRM_DEBUG_DRIVER("before requesting firmware: uC fw fetch status %s\n",
131 intel_uc_fw_status_repr(uc_fw->fetch_status));
132
133 err = request_firmware(&fw, uc_fw->path, &pdev->dev);
134 if (err)
135 goto fail;
136 if (!fw)
137 goto fail;
138
139 DRM_DEBUG_DRIVER("fetch uC fw from %s succeeded, fw %p\n",
140 uc_fw->path, fw);
141
142 /* Check the size of the blob before examining buffer contents */
143 if (fw->size < sizeof(struct uc_css_header)) {
144 DRM_NOTE("Firmware header is missing\n");
145 goto fail;
146 }
147
148 css = (struct uc_css_header *)fw->data;
149
150 /* Firmware bits always start from header */
151 uc_fw->header_offset = 0;
152 uc_fw->header_size = (css->header_size_dw - css->modulus_size_dw -
153 css->key_size_dw - css->exponent_size_dw) * sizeof(u32);
154
155 if (uc_fw->header_size != sizeof(struct uc_css_header)) {
156 DRM_NOTE("CSS header definition mismatch\n");
157 goto fail;
158 }
159
160 /* then, uCode */
161 uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
162 uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);
163
164 /* now RSA */
165 if (css->key_size_dw != UOS_RSA_SCRATCH_MAX_COUNT) {
166 DRM_NOTE("RSA key size is bad\n");
167 goto fail;
168 }
169 uc_fw->rsa_offset = uc_fw->ucode_offset + uc_fw->ucode_size;
170 uc_fw->rsa_size = css->key_size_dw * sizeof(u32);
171
172 /* At least, it should have header, uCode and RSA. Size of all three. */
173 size = uc_fw->header_size + uc_fw->ucode_size + uc_fw->rsa_size;
174 if (fw->size < size) {
175 DRM_NOTE("Missing firmware components\n");
176 goto fail;
177 }
178
179 /*
180 * The GuC firmware image has the version number embedded at a
181 * well-known offset within the firmware blob; note that major / minor
182 * version are TWO bytes each (i.e. u16), although all pointers and
183 * offsets are defined in terms of bytes (u8).
184 */
185 switch (uc_fw->type) {
186 case INTEL_UC_FW_TYPE_GUC:
187 /* Header and uCode will be loaded to WOPCM. Size of the two. */
188 size = uc_fw->header_size + uc_fw->ucode_size;
189
190 /* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */
191 if (size > intel_guc_wopcm_size(dev_priv)) {
192 DRM_ERROR("Firmware is too large to fit in WOPCM\n");
193 goto fail;
194 }
195 uc_fw->major_ver_found = css->guc.sw_version >> 16;
196 uc_fw->minor_ver_found = css->guc.sw_version & 0xFFFF;
197 break;
198
199 case INTEL_UC_FW_TYPE_HUC:
200 uc_fw->major_ver_found = css->huc.sw_version >> 16;
201 uc_fw->minor_ver_found = css->huc.sw_version & 0xFFFF;
202 break;
203
204 default:
205 DRM_ERROR("Unknown firmware type %d\n", uc_fw->type);
206 err = -ENOEXEC;
207 goto fail;
208 }
209
210 if (uc_fw->major_ver_wanted == 0 && uc_fw->minor_ver_wanted == 0) {
Michal Wajdeczko5e065f12017-03-30 11:21:12 +0000211 DRM_NOTE("Skipping %s firmware version check\n",
212 intel_uc_fw_type_repr(uc_fw->type));
Michal Wajdeczko9d98af0b2017-03-27 09:45:10 +0000213 } else if (uc_fw->major_ver_found != uc_fw->major_ver_wanted ||
214 uc_fw->minor_ver_found < uc_fw->minor_ver_wanted) {
Michal Wajdeczko5e065f12017-03-30 11:21:12 +0000215 DRM_NOTE("%s firmware version %d.%d, required %d.%d\n",
216 intel_uc_fw_type_repr(uc_fw->type),
Michal Wajdeczko9d98af0b2017-03-27 09:45:10 +0000217 uc_fw->major_ver_found, uc_fw->minor_ver_found,
218 uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted);
219 err = -ENOEXEC;
220 goto fail;
221 }
222
223 DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n",
224 uc_fw->major_ver_found, uc_fw->minor_ver_found,
225 uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted);
226
227 obj = i915_gem_object_create_from_data(dev_priv, fw->data, fw->size);
228 if (IS_ERR(obj)) {
229 err = PTR_ERR(obj);
230 goto fail;
231 }
232
233 uc_fw->obj = obj;
234 uc_fw->size = fw->size;
235
236 DRM_DEBUG_DRIVER("uC fw fetch status SUCCESS, obj %p\n",
237 uc_fw->obj);
238
239 release_firmware(fw);
240 uc_fw->fetch_status = INTEL_UC_FIRMWARE_SUCCESS;
241 return;
242
243fail:
244 DRM_WARN("Failed to fetch valid uC firmware from %s (error %d)\n",
245 uc_fw->path, err);
246 DRM_DEBUG_DRIVER("uC fw fetch status FAIL; err %d, fw %p, obj %p\n",
247 err, fw, uc_fw->obj);
248
249 release_firmware(fw); /* OK even if fw is NULL */
250 uc_fw->fetch_status = INTEL_UC_FIRMWARE_FAIL;
251}
252
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100253void intel_uc_init_fw(struct drm_i915_private *dev_priv)
254{
Michal Wajdeczkob57f7f72017-03-30 11:21:15 +0000255 fetch_uc_fw(dev_priv, &dev_priv->huc.fw);
256 fetch_uc_fw(dev_priv, &dev_priv->guc.fw);
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100257}
258
Oscar Mateo3950bf32017-03-22 10:39:46 -0700259void intel_uc_fini_fw(struct drm_i915_private *dev_priv)
260{
Michal Wajdeczko00bbb722017-03-30 11:21:13 +0000261 __intel_uc_fw_fini(&dev_priv->guc.fw);
262 __intel_uc_fw_fini(&dev_priv->huc.fw);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700263}
264
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000265static inline i915_reg_t guc_send_reg(struct intel_guc *guc, u32 i)
266{
267 GEM_BUG_ON(!guc->send_regs.base);
268 GEM_BUG_ON(!guc->send_regs.count);
269 GEM_BUG_ON(i >= guc->send_regs.count);
270
271 return _MMIO(guc->send_regs.base + 4 * i);
272}
273
274static void guc_init_send_regs(struct intel_guc *guc)
275{
276 struct drm_i915_private *dev_priv = guc_to_i915(guc);
277 enum forcewake_domains fw_domains = 0;
278 unsigned int i;
279
280 guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0));
281 guc->send_regs.count = SOFT_SCRATCH_COUNT - 1;
282
283 for (i = 0; i < guc->send_regs.count; i++) {
284 fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
285 guc_send_reg(guc, i),
286 FW_REG_READ | FW_REG_WRITE);
287 }
288 guc->send_regs.fw_domains = fw_domains;
289}
290
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000291static int guc_enable_communication(struct intel_guc *guc)
292{
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000293 struct drm_i915_private *dev_priv = guc_to_i915(guc);
294
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000295 guc_init_send_regs(guc);
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000296
297 if (HAS_GUC_CT(dev_priv))
298 return intel_guc_enable_ct(guc);
299
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000300 guc->send = intel_guc_send_mmio;
301 return 0;
302}
303
304static void guc_disable_communication(struct intel_guc *guc)
305{
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000306 struct drm_i915_private *dev_priv = guc_to_i915(guc);
307
308 if (HAS_GUC_CT(dev_priv))
309 intel_guc_disable_ct(guc);
310
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000311 guc->send = intel_guc_send_nop;
312}
313
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100314int intel_uc_init_hw(struct drm_i915_private *dev_priv)
315{
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000316 struct intel_guc *guc = &dev_priv->guc;
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100317 int ret, attempts;
318
Oscar Mateob8991402017-03-28 09:53:47 -0700319 if (!i915.enable_guc_loading)
320 return 0;
321
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000322 guc_disable_communication(guc);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100323 gen9_reset_guc_interrupts(dev_priv);
324
325 /* We need to notify the guc whenever we change the GGTT */
326 i915_ggtt_enable_guc(dev_priv);
327
Oscar Mateo397fce82017-03-22 10:39:52 -0700328 if (i915.enable_guc_submission) {
329 /*
330 * This is stuff we need to have available at fw load time
331 * if we are planning to enable submission later
332 */
333 ret = i915_guc_submission_init(dev_priv);
334 if (ret)
335 goto err_guc;
336 }
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100337
daniele.ceraolospurio@intel.com13f6c712017-04-06 17:18:52 -0700338 /* init WOPCM */
339 I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
340 I915_WRITE(DMA_GUC_WOPCM_OFFSET,
341 GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
342
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100343 /* WaEnableuKernelHeaderValidFix:skl */
344 /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
345 if (IS_GEN9(dev_priv))
346 attempts = 3;
347 else
348 attempts = 1;
349
350 while (attempts--) {
351 /*
352 * Always reset the GuC just before (re)loading, so
353 * that the state and timing are fairly predictable
354 */
355 ret = __intel_uc_reset_hw(dev_priv);
356 if (ret)
357 goto err_submission;
358
359 intel_huc_init_hw(&dev_priv->huc);
360 ret = intel_guc_init_hw(&dev_priv->guc);
361 if (ret == 0 || ret != -EAGAIN)
362 break;
363
364 DRM_DEBUG_DRIVER("GuC fw load failed: %d; will reset and "
365 "retry %d more time(s)\n", ret, attempts);
366 }
367
368 /* Did we succeded or run out of retries? */
369 if (ret)
370 goto err_submission;
371
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000372 ret = guc_enable_communication(guc);
373 if (ret)
374 goto err_submission;
375
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100376 intel_guc_auth_huc(dev_priv);
377 if (i915.enable_guc_submission) {
378 if (i915.guc_log_level >= 0)
379 gen9_enable_guc_interrupts(dev_priv);
380
381 ret = i915_guc_submission_enable(dev_priv);
382 if (ret)
Oscar Mateo3950bf32017-03-22 10:39:46 -0700383 goto err_interrupts;
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100384 }
385
386 return 0;
387
388 /*
389 * We've failed to load the firmware :(
390 *
391 * Decide whether to disable GuC submission and fall back to
392 * execlist mode, and whether to hide the error by returning
393 * zero or to return -EIO, which the caller will treat as a
394 * nonfatal error (i.e. it doesn't prevent driver load, but
395 * marks the GPU as wedged until reset).
396 */
Oscar Mateo3950bf32017-03-22 10:39:46 -0700397err_interrupts:
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000398 guc_disable_communication(guc);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700399 gen9_disable_guc_interrupts(dev_priv);
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100400err_submission:
Oscar Mateo397fce82017-03-22 10:39:52 -0700401 if (i915.enable_guc_submission)
402 i915_guc_submission_fini(dev_priv);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700403err_guc:
Arkadiusz Hiler6cd5a722017-03-14 15:28:11 +0100404 i915_ggtt_disable_guc(dev_priv);
405
406 DRM_ERROR("GuC init failed\n");
407 if (i915.enable_guc_loading > 1 || i915.enable_guc_submission > 1)
408 ret = -EIO;
409 else
410 ret = 0;
411
412 if (i915.enable_guc_submission) {
413 i915.enable_guc_submission = 0;
414 DRM_NOTE("Falling back from GuC submission to execlist mode\n");
415 }
416
417 return ret;
418}
419
Oscar Mateo3950bf32017-03-22 10:39:46 -0700420void intel_uc_fini_hw(struct drm_i915_private *dev_priv)
421{
Oscar Mateob8991402017-03-28 09:53:47 -0700422 if (!i915.enable_guc_loading)
423 return;
424
Michal Wajdeczko2f640852017-05-26 11:13:24 +0000425 if (i915.enable_guc_submission)
Oscar Mateo3950bf32017-03-22 10:39:46 -0700426 i915_guc_submission_disable(dev_priv);
Michal Wajdeczko2f640852017-05-26 11:13:24 +0000427
428 guc_disable_communication(&dev_priv->guc);
429
430 if (i915.enable_guc_submission) {
Oscar Mateo3950bf32017-03-22 10:39:46 -0700431 gen9_disable_guc_interrupts(dev_priv);
Oscar Mateo397fce82017-03-22 10:39:52 -0700432 i915_guc_submission_fini(dev_priv);
Oscar Mateo3950bf32017-03-22 10:39:46 -0700433 }
Michal Wajdeczko2f640852017-05-26 11:13:24 +0000434
Oscar Mateo3950bf32017-03-22 10:39:46 -0700435 i915_ggtt_disable_guc(dev_priv);
436}
437
Michal Wajdeczko789a6252017-05-02 10:32:42 +0000438int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len)
439{
440 WARN(1, "Unexpected send: action=%#x\n", *action);
441 return -ENODEV;
442}
443
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100444/*
Oscar Mateo5e7cd372017-03-22 10:39:49 -0700445 * This function implements the MMIO based host to GuC interface.
446 */
447int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len)
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100448{
449 struct drm_i915_private *dev_priv = guc_to_i915(guc);
450 u32 status;
451 int i;
452 int ret;
453
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000454 GEM_BUG_ON(!len);
455 GEM_BUG_ON(len > guc->send_regs.count);
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100456
Michal Wajdeczkof8a58d62017-05-26 11:13:25 +0000457 /* If CT is available, we expect to use MMIO only during init/fini */
458 GEM_BUG_ON(HAS_GUC_CT(dev_priv) &&
459 *action != INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER &&
460 *action != INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER);
461
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100462 mutex_lock(&guc->send_mutex);
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000463 intel_uncore_forcewake_get(dev_priv, guc->send_regs.fw_domains);
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100464
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100465 for (i = 0; i < len; i++)
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000466 I915_WRITE(guc_send_reg(guc, i), action[i]);
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100467
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000468 POSTING_READ(guc_send_reg(guc, i - 1));
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100469
Michal Wajdeczkoa03aac42017-05-10 12:59:26 +0000470 intel_guc_notify(guc);
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100471
472 /*
Michal Wajdeczkobea4e4a2017-04-07 16:01:45 +0000473 * No GuC command should ever take longer than 10ms.
474 * Fast commands should still complete in 10us.
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100475 */
Michal Wajdeczkobea4e4a2017-04-07 16:01:45 +0000476 ret = __intel_wait_for_register_fw(dev_priv,
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000477 guc_send_reg(guc, 0),
Michal Wajdeczkobea4e4a2017-04-07 16:01:45 +0000478 INTEL_GUC_RECV_MASK,
479 INTEL_GUC_RECV_MASK,
480 10, 10, &status);
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100481 if (status != INTEL_GUC_STATUS_SUCCESS) {
482 /*
483 * Either the GuC explicitly returned an error (which
484 * we convert to -EIO here) or no response at all was
485 * received within the timeout limit (-ETIMEDOUT)
486 */
487 if (ret != -ETIMEDOUT)
488 ret = -EIO;
489
490 DRM_WARN("INTEL_GUC_SEND: Action 0x%X failed;"
491 " ret=%d status=0x%08X response=0x%08X\n",
492 action[0], ret, status, I915_READ(SOFT_SCRATCH(15)));
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100493 }
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100494
Michal Wajdeczkoa0c1fe22017-05-10 12:59:27 +0000495 intel_uncore_forcewake_put(dev_priv, guc->send_regs.fw_domains);
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +0100496 mutex_unlock(&guc->send_mutex);
497
498 return ret;
499}
500
501int intel_guc_sample_forcewake(struct intel_guc *guc)
502{
503 struct drm_i915_private *dev_priv = guc_to_i915(guc);
504 u32 action[2];
505
506 action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE;
507 /* WaRsDisableCoarsePowerGating:skl,bxt */
508 if (!intel_enable_rc6() || NEEDS_WaRsDisableCoarsePowerGating(dev_priv))
509 action[1] = 0;
510 else
511 /* bit 0 and 1 are for Render and Media domain separately */
512 action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA;
513
514 return intel_guc_send(guc, action, ARRAY_SIZE(action));
515}