Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 1 | /* |
| 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 Hiler | 4c0fed7 | 2017-03-14 15:28:08 +0100 | [diff] [blame] | 27 | #include <linux/firmware.h> |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 28 | |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 29 | /* Reset GuC providing us with fresh state for both GuC and HuC. |
| 30 | */ |
| 31 | static int __intel_uc_reset_hw(struct drm_i915_private *dev_priv) |
| 32 | { |
| 33 | int ret; |
| 34 | u32 guc_status; |
| 35 | |
| 36 | ret = intel_guc_reset(dev_priv); |
| 37 | if (ret) { |
| 38 | DRM_ERROR("GuC reset failed, ret = %d\n", ret); |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | guc_status = I915_READ(GUC_STATUS); |
| 43 | WARN(!(guc_status & GS_MIA_IN_RESET), |
| 44 | "GuC status: 0x%x, MIA core expected to be in reset\n", |
| 45 | guc_status); |
| 46 | |
| 47 | return ret; |
| 48 | } |
| 49 | |
Arkadiusz Hiler | d2be9f2 | 2017-03-14 15:28:10 +0100 | [diff] [blame] | 50 | void intel_uc_sanitize_options(struct drm_i915_private *dev_priv) |
| 51 | { |
| 52 | if (!HAS_GUC(dev_priv)) { |
Michal Wajdeczko | d4a70a1 | 2017-03-15 13:37:41 +0000 | [diff] [blame] | 53 | if (i915.enable_guc_loading > 0 || |
| 54 | i915.enable_guc_submission > 0) |
| 55 | DRM_INFO("Ignoring GuC options, no hardware\n"); |
Arkadiusz Hiler | d2be9f2 | 2017-03-14 15:28:10 +0100 | [diff] [blame] | 56 | |
| 57 | i915.enable_guc_loading = 0; |
| 58 | i915.enable_guc_submission = 0; |
Michal Wajdeczko | d4a70a1 | 2017-03-15 13:37:41 +0000 | [diff] [blame] | 59 | return; |
Arkadiusz Hiler | d2be9f2 | 2017-03-14 15:28:10 +0100 | [diff] [blame] | 60 | } |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 61 | |
Michal Wajdeczko | d4a70a1 | 2017-03-15 13:37:41 +0000 | [diff] [blame] | 62 | /* A negative value means "use platform default" */ |
| 63 | if (i915.enable_guc_loading < 0) |
| 64 | i915.enable_guc_loading = HAS_GUC_UCODE(dev_priv); |
| 65 | |
| 66 | /* Verify firmware version */ |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 67 | if (i915.enable_guc_loading) { |
| 68 | if (HAS_HUC_UCODE(dev_priv)) |
| 69 | intel_huc_select_fw(&dev_priv->huc); |
| 70 | |
| 71 | if (intel_guc_select_fw(&dev_priv->guc)) |
| 72 | i915.enable_guc_loading = 0; |
| 73 | } |
Michal Wajdeczko | d4a70a1 | 2017-03-15 13:37:41 +0000 | [diff] [blame] | 74 | |
| 75 | /* Can't enable guc submission without guc loaded */ |
| 76 | if (!i915.enable_guc_loading) |
| 77 | i915.enable_guc_submission = 0; |
| 78 | |
| 79 | /* A negative value means "use platform default" */ |
| 80 | if (i915.enable_guc_submission < 0) |
| 81 | i915.enable_guc_submission = HAS_GUC_SCHED(dev_priv); |
Arkadiusz Hiler | d2be9f2 | 2017-03-14 15:28:10 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Arkadiusz Hiler | 413e8fd | 2016-11-25 18:59:36 +0100 | [diff] [blame] | 84 | void intel_uc_init_early(struct drm_i915_private *dev_priv) |
| 85 | { |
Oscar Mateo | 5e7cd37 | 2017-03-22 10:39:49 -0700 | [diff] [blame] | 86 | struct intel_guc *guc = &dev_priv->guc; |
| 87 | |
| 88 | mutex_init(&guc->send_mutex); |
| 89 | guc->send = intel_guc_send_mmio; |
Arkadiusz Hiler | 413e8fd | 2016-11-25 18:59:36 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Michal Wajdeczko | 9d98af0b | 2017-03-27 09:45:10 +0000 | [diff] [blame] | 92 | static void fetch_uc_fw(struct drm_i915_private *dev_priv, |
| 93 | struct intel_uc_fw *uc_fw) |
| 94 | { |
| 95 | struct pci_dev *pdev = dev_priv->drm.pdev; |
| 96 | struct drm_i915_gem_object *obj; |
| 97 | const struct firmware *fw = NULL; |
| 98 | struct uc_css_header *css; |
| 99 | size_t size; |
| 100 | int err; |
| 101 | |
| 102 | uc_fw->fetch_status = INTEL_UC_FIRMWARE_PENDING; |
| 103 | |
| 104 | DRM_DEBUG_DRIVER("before requesting firmware: uC fw fetch status %s\n", |
| 105 | intel_uc_fw_status_repr(uc_fw->fetch_status)); |
| 106 | |
| 107 | err = request_firmware(&fw, uc_fw->path, &pdev->dev); |
| 108 | if (err) |
| 109 | goto fail; |
| 110 | if (!fw) |
| 111 | goto fail; |
| 112 | |
| 113 | DRM_DEBUG_DRIVER("fetch uC fw from %s succeeded, fw %p\n", |
| 114 | uc_fw->path, fw); |
| 115 | |
| 116 | /* Check the size of the blob before examining buffer contents */ |
| 117 | if (fw->size < sizeof(struct uc_css_header)) { |
| 118 | DRM_NOTE("Firmware header is missing\n"); |
| 119 | goto fail; |
| 120 | } |
| 121 | |
| 122 | css = (struct uc_css_header *)fw->data; |
| 123 | |
| 124 | /* Firmware bits always start from header */ |
| 125 | uc_fw->header_offset = 0; |
| 126 | uc_fw->header_size = (css->header_size_dw - css->modulus_size_dw - |
| 127 | css->key_size_dw - css->exponent_size_dw) * sizeof(u32); |
| 128 | |
| 129 | if (uc_fw->header_size != sizeof(struct uc_css_header)) { |
| 130 | DRM_NOTE("CSS header definition mismatch\n"); |
| 131 | goto fail; |
| 132 | } |
| 133 | |
| 134 | /* then, uCode */ |
| 135 | uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size; |
| 136 | uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32); |
| 137 | |
| 138 | /* now RSA */ |
| 139 | if (css->key_size_dw != UOS_RSA_SCRATCH_MAX_COUNT) { |
| 140 | DRM_NOTE("RSA key size is bad\n"); |
| 141 | goto fail; |
| 142 | } |
| 143 | uc_fw->rsa_offset = uc_fw->ucode_offset + uc_fw->ucode_size; |
| 144 | uc_fw->rsa_size = css->key_size_dw * sizeof(u32); |
| 145 | |
| 146 | /* At least, it should have header, uCode and RSA. Size of all three. */ |
| 147 | size = uc_fw->header_size + uc_fw->ucode_size + uc_fw->rsa_size; |
| 148 | if (fw->size < size) { |
| 149 | DRM_NOTE("Missing firmware components\n"); |
| 150 | goto fail; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * The GuC firmware image has the version number embedded at a |
| 155 | * well-known offset within the firmware blob; note that major / minor |
| 156 | * version are TWO bytes each (i.e. u16), although all pointers and |
| 157 | * offsets are defined in terms of bytes (u8). |
| 158 | */ |
| 159 | switch (uc_fw->type) { |
| 160 | case INTEL_UC_FW_TYPE_GUC: |
| 161 | /* Header and uCode will be loaded to WOPCM. Size of the two. */ |
| 162 | size = uc_fw->header_size + uc_fw->ucode_size; |
| 163 | |
| 164 | /* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ |
| 165 | if (size > intel_guc_wopcm_size(dev_priv)) { |
| 166 | DRM_ERROR("Firmware is too large to fit in WOPCM\n"); |
| 167 | goto fail; |
| 168 | } |
| 169 | uc_fw->major_ver_found = css->guc.sw_version >> 16; |
| 170 | uc_fw->minor_ver_found = css->guc.sw_version & 0xFFFF; |
| 171 | break; |
| 172 | |
| 173 | case INTEL_UC_FW_TYPE_HUC: |
| 174 | uc_fw->major_ver_found = css->huc.sw_version >> 16; |
| 175 | uc_fw->minor_ver_found = css->huc.sw_version & 0xFFFF; |
| 176 | break; |
| 177 | |
| 178 | default: |
| 179 | DRM_ERROR("Unknown firmware type %d\n", uc_fw->type); |
| 180 | err = -ENOEXEC; |
| 181 | goto fail; |
| 182 | } |
| 183 | |
| 184 | if (uc_fw->major_ver_wanted == 0 && uc_fw->minor_ver_wanted == 0) { |
Michal Wajdeczko | 5e065f1 | 2017-03-30 11:21:12 +0000 | [diff] [blame^] | 185 | DRM_NOTE("Skipping %s firmware version check\n", |
| 186 | intel_uc_fw_type_repr(uc_fw->type)); |
Michal Wajdeczko | 9d98af0b | 2017-03-27 09:45:10 +0000 | [diff] [blame] | 187 | } else if (uc_fw->major_ver_found != uc_fw->major_ver_wanted || |
| 188 | uc_fw->minor_ver_found < uc_fw->minor_ver_wanted) { |
Michal Wajdeczko | 5e065f1 | 2017-03-30 11:21:12 +0000 | [diff] [blame^] | 189 | DRM_NOTE("%s firmware version %d.%d, required %d.%d\n", |
| 190 | intel_uc_fw_type_repr(uc_fw->type), |
Michal Wajdeczko | 9d98af0b | 2017-03-27 09:45:10 +0000 | [diff] [blame] | 191 | uc_fw->major_ver_found, uc_fw->minor_ver_found, |
| 192 | uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted); |
| 193 | err = -ENOEXEC; |
| 194 | goto fail; |
| 195 | } |
| 196 | |
| 197 | DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n", |
| 198 | uc_fw->major_ver_found, uc_fw->minor_ver_found, |
| 199 | uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted); |
| 200 | |
| 201 | obj = i915_gem_object_create_from_data(dev_priv, fw->data, fw->size); |
| 202 | if (IS_ERR(obj)) { |
| 203 | err = PTR_ERR(obj); |
| 204 | goto fail; |
| 205 | } |
| 206 | |
| 207 | uc_fw->obj = obj; |
| 208 | uc_fw->size = fw->size; |
| 209 | |
| 210 | DRM_DEBUG_DRIVER("uC fw fetch status SUCCESS, obj %p\n", |
| 211 | uc_fw->obj); |
| 212 | |
| 213 | release_firmware(fw); |
| 214 | uc_fw->fetch_status = INTEL_UC_FIRMWARE_SUCCESS; |
| 215 | return; |
| 216 | |
| 217 | fail: |
| 218 | DRM_WARN("Failed to fetch valid uC firmware from %s (error %d)\n", |
| 219 | uc_fw->path, err); |
| 220 | DRM_DEBUG_DRIVER("uC fw fetch status FAIL; err %d, fw %p, obj %p\n", |
| 221 | err, fw, uc_fw->obj); |
| 222 | |
| 223 | release_firmware(fw); /* OK even if fw is NULL */ |
| 224 | uc_fw->fetch_status = INTEL_UC_FIRMWARE_FAIL; |
| 225 | } |
| 226 | |
Arkadiusz Hiler | 29ad6a3 | 2017-03-14 15:28:09 +0100 | [diff] [blame] | 227 | void intel_uc_init_fw(struct drm_i915_private *dev_priv) |
| 228 | { |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 229 | if (dev_priv->huc.fw.path) |
Michal Wajdeczko | 9d98af0b | 2017-03-27 09:45:10 +0000 | [diff] [blame] | 230 | fetch_uc_fw(dev_priv, &dev_priv->huc.fw); |
Arkadiusz Hiler | d2be9f2 | 2017-03-14 15:28:10 +0100 | [diff] [blame] | 231 | |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 232 | if (dev_priv->guc.fw.path) |
Michal Wajdeczko | 9d98af0b | 2017-03-27 09:45:10 +0000 | [diff] [blame] | 233 | fetch_uc_fw(dev_priv, &dev_priv->guc.fw); |
Arkadiusz Hiler | 29ad6a3 | 2017-03-14 15:28:09 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 236 | void intel_uc_fini_fw(struct drm_i915_private *dev_priv) |
| 237 | { |
| 238 | struct intel_uc_fw *guc_fw = &dev_priv->guc.fw; |
| 239 | struct intel_uc_fw *huc_fw = &dev_priv->huc.fw; |
| 240 | struct drm_i915_gem_object *obj; |
| 241 | |
| 242 | obj = fetch_and_zero(&guc_fw->obj); |
| 243 | if (obj) |
| 244 | i915_gem_object_put(obj); |
| 245 | |
| 246 | guc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE; |
| 247 | |
| 248 | obj = fetch_and_zero(&huc_fw->obj); |
| 249 | if (obj) |
| 250 | i915_gem_object_put(obj); |
| 251 | |
| 252 | huc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE; |
| 253 | } |
| 254 | |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 255 | int intel_uc_init_hw(struct drm_i915_private *dev_priv) |
| 256 | { |
| 257 | int ret, attempts; |
| 258 | |
Oscar Mateo | b899140 | 2017-03-28 09:53:47 -0700 | [diff] [blame] | 259 | if (!i915.enable_guc_loading) |
| 260 | return 0; |
| 261 | |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 262 | gen9_reset_guc_interrupts(dev_priv); |
| 263 | |
| 264 | /* We need to notify the guc whenever we change the GGTT */ |
| 265 | i915_ggtt_enable_guc(dev_priv); |
| 266 | |
Oscar Mateo | 397fce8 | 2017-03-22 10:39:52 -0700 | [diff] [blame] | 267 | if (i915.enable_guc_submission) { |
| 268 | /* |
| 269 | * This is stuff we need to have available at fw load time |
| 270 | * if we are planning to enable submission later |
| 271 | */ |
| 272 | ret = i915_guc_submission_init(dev_priv); |
| 273 | if (ret) |
| 274 | goto err_guc; |
| 275 | } |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 276 | |
| 277 | /* WaEnableuKernelHeaderValidFix:skl */ |
| 278 | /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */ |
| 279 | if (IS_GEN9(dev_priv)) |
| 280 | attempts = 3; |
| 281 | else |
| 282 | attempts = 1; |
| 283 | |
| 284 | while (attempts--) { |
| 285 | /* |
| 286 | * Always reset the GuC just before (re)loading, so |
| 287 | * that the state and timing are fairly predictable |
| 288 | */ |
| 289 | ret = __intel_uc_reset_hw(dev_priv); |
| 290 | if (ret) |
| 291 | goto err_submission; |
| 292 | |
| 293 | intel_huc_init_hw(&dev_priv->huc); |
| 294 | ret = intel_guc_init_hw(&dev_priv->guc); |
| 295 | if (ret == 0 || ret != -EAGAIN) |
| 296 | break; |
| 297 | |
| 298 | DRM_DEBUG_DRIVER("GuC fw load failed: %d; will reset and " |
| 299 | "retry %d more time(s)\n", ret, attempts); |
| 300 | } |
| 301 | |
| 302 | /* Did we succeded or run out of retries? */ |
| 303 | if (ret) |
| 304 | goto err_submission; |
| 305 | |
| 306 | intel_guc_auth_huc(dev_priv); |
| 307 | if (i915.enable_guc_submission) { |
| 308 | if (i915.guc_log_level >= 0) |
| 309 | gen9_enable_guc_interrupts(dev_priv); |
| 310 | |
| 311 | ret = i915_guc_submission_enable(dev_priv); |
| 312 | if (ret) |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 313 | goto err_interrupts; |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | |
| 318 | /* |
| 319 | * We've failed to load the firmware :( |
| 320 | * |
| 321 | * Decide whether to disable GuC submission and fall back to |
| 322 | * execlist mode, and whether to hide the error by returning |
| 323 | * zero or to return -EIO, which the caller will treat as a |
| 324 | * nonfatal error (i.e. it doesn't prevent driver load, but |
| 325 | * marks the GPU as wedged until reset). |
| 326 | */ |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 327 | err_interrupts: |
| 328 | gen9_disable_guc_interrupts(dev_priv); |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 329 | err_submission: |
Oscar Mateo | 397fce8 | 2017-03-22 10:39:52 -0700 | [diff] [blame] | 330 | if (i915.enable_guc_submission) |
| 331 | i915_guc_submission_fini(dev_priv); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 332 | err_guc: |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 333 | i915_ggtt_disable_guc(dev_priv); |
| 334 | |
| 335 | DRM_ERROR("GuC init failed\n"); |
| 336 | if (i915.enable_guc_loading > 1 || i915.enable_guc_submission > 1) |
| 337 | ret = -EIO; |
| 338 | else |
| 339 | ret = 0; |
| 340 | |
| 341 | if (i915.enable_guc_submission) { |
| 342 | i915.enable_guc_submission = 0; |
| 343 | DRM_NOTE("Falling back from GuC submission to execlist mode\n"); |
| 344 | } |
| 345 | |
| 346 | return ret; |
| 347 | } |
| 348 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 349 | void intel_uc_fini_hw(struct drm_i915_private *dev_priv) |
| 350 | { |
Oscar Mateo | b899140 | 2017-03-28 09:53:47 -0700 | [diff] [blame] | 351 | if (!i915.enable_guc_loading) |
| 352 | return; |
| 353 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 354 | if (i915.enable_guc_submission) { |
| 355 | i915_guc_submission_disable(dev_priv); |
| 356 | gen9_disable_guc_interrupts(dev_priv); |
Oscar Mateo | 397fce8 | 2017-03-22 10:39:52 -0700 | [diff] [blame] | 357 | i915_guc_submission_fini(dev_priv); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 358 | } |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 359 | i915_ggtt_disable_guc(dev_priv); |
| 360 | } |
| 361 | |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 362 | /* |
| 363 | * Read GuC command/status register (SOFT_SCRATCH_0) |
| 364 | * Return true if it contains a response rather than a command |
| 365 | */ |
Oscar Mateo | 5e7cd37 | 2017-03-22 10:39:49 -0700 | [diff] [blame] | 366 | static bool guc_recv(struct intel_guc *guc, u32 *status) |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 367 | { |
Michal Wajdeczko | bae3fdc | 2016-12-20 11:55:31 +0000 | [diff] [blame] | 368 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 369 | |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 370 | u32 val = I915_READ(SOFT_SCRATCH(0)); |
| 371 | *status = val; |
| 372 | return INTEL_GUC_RECV_IS_RESPONSE(val); |
| 373 | } |
| 374 | |
Oscar Mateo | 5e7cd37 | 2017-03-22 10:39:49 -0700 | [diff] [blame] | 375 | /* |
| 376 | * This function implements the MMIO based host to GuC interface. |
| 377 | */ |
| 378 | int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len) |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 379 | { |
| 380 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 381 | u32 status; |
| 382 | int i; |
| 383 | int ret; |
| 384 | |
| 385 | if (WARN_ON(len < 1 || len > 15)) |
| 386 | return -EINVAL; |
| 387 | |
| 388 | mutex_lock(&guc->send_mutex); |
Daniele Ceraolo Spurio | 5d64c12 | 2017-03-24 07:48:39 -0700 | [diff] [blame] | 389 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_BLITTER); |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 390 | |
| 391 | dev_priv->guc.action_count += 1; |
| 392 | dev_priv->guc.action_cmd = action[0]; |
| 393 | |
| 394 | for (i = 0; i < len; i++) |
| 395 | I915_WRITE(SOFT_SCRATCH(i), action[i]); |
| 396 | |
| 397 | POSTING_READ(SOFT_SCRATCH(i - 1)); |
| 398 | |
| 399 | I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER); |
| 400 | |
| 401 | /* |
| 402 | * Fast commands should complete in less than 10us, so sample quickly |
| 403 | * up to that length of time, then switch to a slower sleep-wait loop. |
| 404 | * No inte_guc_send command should ever take longer than 10ms. |
| 405 | */ |
Oscar Mateo | 5e7cd37 | 2017-03-22 10:39:49 -0700 | [diff] [blame] | 406 | ret = wait_for_us(guc_recv(guc, &status), 10); |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 407 | if (ret) |
Oscar Mateo | 5e7cd37 | 2017-03-22 10:39:49 -0700 | [diff] [blame] | 408 | ret = wait_for(guc_recv(guc, &status), 10); |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 409 | if (status != INTEL_GUC_STATUS_SUCCESS) { |
| 410 | /* |
| 411 | * Either the GuC explicitly returned an error (which |
| 412 | * we convert to -EIO here) or no response at all was |
| 413 | * received within the timeout limit (-ETIMEDOUT) |
| 414 | */ |
| 415 | if (ret != -ETIMEDOUT) |
| 416 | ret = -EIO; |
| 417 | |
| 418 | DRM_WARN("INTEL_GUC_SEND: Action 0x%X failed;" |
| 419 | " ret=%d status=0x%08X response=0x%08X\n", |
| 420 | action[0], ret, status, I915_READ(SOFT_SCRATCH(15))); |
| 421 | |
| 422 | dev_priv->guc.action_fail += 1; |
| 423 | dev_priv->guc.action_err = ret; |
| 424 | } |
| 425 | dev_priv->guc.action_status = status; |
| 426 | |
Daniele Ceraolo Spurio | 5d64c12 | 2017-03-24 07:48:39 -0700 | [diff] [blame] | 427 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_BLITTER); |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 428 | mutex_unlock(&guc->send_mutex); |
| 429 | |
| 430 | return ret; |
| 431 | } |
| 432 | |
| 433 | int intel_guc_sample_forcewake(struct intel_guc *guc) |
| 434 | { |
| 435 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 436 | u32 action[2]; |
| 437 | |
| 438 | action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE; |
| 439 | /* WaRsDisableCoarsePowerGating:skl,bxt */ |
| 440 | if (!intel_enable_rc6() || NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
| 441 | action[1] = 0; |
| 442 | else |
| 443 | /* bit 0 and 1 are for Render and Media domain separately */ |
| 444 | action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA; |
| 445 | |
| 446 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 447 | } |