Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 1 | /* |
| 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 Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 29 | #include "i915_drv.h" |
Arkadiusz Hiler | 8c4f24f | 2016-11-25 18:59:33 +0100 | [diff] [blame] | 30 | #include "intel_uc.h" |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 31 | |
| 32 | /** |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 33 | * DOC: GuC-specific firmware loader |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 34 | * |
| 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 Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 53 | */ |
| 54 | |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 55 | #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 Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 68 | MODULE_FIRMWARE(I915_SKL_GUC_UCODE); |
| 69 | |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 70 | #define I915_BXT_GUC_UCODE GUC_FW_PATH(bxt, BXT_FW_MAJOR, BXT_FW_MINOR) |
Nick Hoath | 57bf5c8 | 2016-05-06 11:42:53 +0100 | [diff] [blame] | 71 | MODULE_FIRMWARE(I915_BXT_GUC_UCODE); |
| 72 | |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 73 | #define I915_KBL_GUC_UCODE GUC_FW_PATH(kbl, KBL_FW_MAJOR, KBL_FW_MINOR) |
Peter Antoine | ff64cc1 | 2016-06-30 09:37:52 -0700 | [diff] [blame] | 74 | MODULE_FIRMWARE(I915_KBL_GUC_UCODE); |
| 75 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 76 | |
| 77 | static u32 get_gttype(struct drm_i915_private *dev_priv) |
| 78 | { |
| 79 | /* XXX: GT type based on PCI device ID? field seems unused by fw */ |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static u32 get_core_family(struct drm_i915_private *dev_priv) |
| 84 | { |
Dave Gordon | fc32de9 | 2016-08-18 18:17:24 +0100 | [diff] [blame] | 85 | u32 gen = INTEL_GEN(dev_priv); |
| 86 | |
| 87 | switch (gen) { |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 88 | case 9: |
Michal Wajdeczko | b53af8b | 2017-04-04 13:38:36 +0000 | [diff] [blame^] | 89 | return GUC_CORE_FAMILY_GEN9; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 90 | |
| 91 | default: |
Michal Wajdeczko | b53af8b | 2017-04-04 13:38:36 +0000 | [diff] [blame^] | 92 | MISSING_CASE(gen); |
| 93 | return GUC_CORE_FAMILY_UNKNOWN; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Dave Gordon | 0c5664e | 2016-09-12 21:19:36 +0100 | [diff] [blame] | 97 | /* |
| 98 | * Initialise the GuC parameter block before starting the firmware |
| 99 | * transfer. These parameters are read by the firmware on startup |
| 100 | * and cannot be changed thereafter. |
| 101 | */ |
| 102 | static void guc_params_init(struct drm_i915_private *dev_priv) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 103 | { |
| 104 | struct intel_guc *guc = &dev_priv->guc; |
| 105 | u32 params[GUC_CTL_MAX_DWORDS]; |
| 106 | int i; |
| 107 | |
| 108 | memset(¶ms, 0, sizeof(params)); |
| 109 | |
| 110 | params[GUC_CTL_DEVICE_INFO] |= |
| 111 | (get_gttype(dev_priv) << GUC_CTL_GTTYPE_SHIFT) | |
| 112 | (get_core_family(dev_priv) << GUC_CTL_COREFAMILY_SHIFT); |
| 113 | |
| 114 | /* |
| 115 | * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one |
| 116 | * second. This ARAR is calculated by: |
| 117 | * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10 |
| 118 | */ |
| 119 | params[GUC_CTL_ARAT_HIGH] = 0; |
| 120 | params[GUC_CTL_ARAT_LOW] = 100000000; |
| 121 | |
| 122 | params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER; |
| 123 | |
| 124 | params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER | |
| 125 | GUC_CTL_VCS2_ENABLED; |
| 126 | |
Akash Goel | d6b40b4 | 2016-10-12 21:54:29 +0530 | [diff] [blame] | 127 | params[GUC_CTL_LOG_PARAMS] = guc->log.flags; |
Sagar Arun Kamble | b1e3710 | 2016-10-12 21:54:27 +0530 | [diff] [blame] | 128 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 129 | if (i915.guc_log_level >= 0) { |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 130 | params[GUC_CTL_DEBUG] = |
| 131 | i915.guc_log_level << GUC_LOG_VERBOSITY_SHIFT; |
Sagar Arun Kamble | b1e3710 | 2016-10-12 21:54:27 +0530 | [diff] [blame] | 132 | } else |
| 133 | params[GUC_CTL_DEBUG] = GUC_LOG_DISABLED; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 134 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 135 | /* If GuC submission is enabled, set up additional parameters here */ |
| 136 | if (i915.enable_guc_submission) { |
Oscar Mateo | 0704df2 | 2017-03-22 10:39:47 -0700 | [diff] [blame] | 137 | u32 ads = guc_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT; |
Oscar Mateo | b09935a | 2017-03-22 10:39:53 -0700 | [diff] [blame] | 138 | u32 pgs = guc_ggtt_offset(dev_priv->guc.stage_desc_pool); |
| 139 | u32 ctx_in_16 = GUC_MAX_STAGE_DESCRIPTORS / 16; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 140 | |
Oscar Mateo | 0704df2 | 2017-03-22 10:39:47 -0700 | [diff] [blame] | 141 | params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT; |
| 142 | params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED; |
| 143 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 144 | pgs >>= PAGE_SHIFT; |
| 145 | params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) | |
| 146 | (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT); |
| 147 | |
| 148 | params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS; |
| 149 | |
| 150 | /* Unmask this bit to enable the GuC's internal scheduler */ |
| 151 | params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER; |
| 152 | } |
| 153 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 154 | I915_WRITE(SOFT_SCRATCH(0), 0); |
| 155 | |
| 156 | for (i = 0; i < GUC_CTL_MAX_DWORDS; i++) |
| 157 | I915_WRITE(SOFT_SCRATCH(1 + i), params[i]); |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Read the GuC status register (GUC_STATUS) and store it in the |
| 162 | * specified location; then return a boolean indicating whether |
| 163 | * the value matches either of two values representing completion |
| 164 | * of the GuC boot process. |
| 165 | * |
Tvrtko Ursulin | 36894e8 | 2016-02-11 10:27:31 +0000 | [diff] [blame] | 166 | * This is used for polling the GuC status in a wait_for() |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 167 | * loop below. |
| 168 | */ |
| 169 | static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, |
| 170 | u32 *status) |
| 171 | { |
| 172 | u32 val = I915_READ(GUC_STATUS); |
Alex Dai | 0d44d3f | 2015-09-22 13:48:40 -0700 | [diff] [blame] | 173 | u32 uk_val = val & GS_UKERNEL_MASK; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 174 | *status = val; |
Alex Dai | 0d44d3f | 2015-09-22 13:48:40 -0700 | [diff] [blame] | 175 | return (uk_val == GS_UKERNEL_READY || |
| 176 | ((val & GS_MIA_CORE_STATE) && uk_val == GS_UKERNEL_LAPIC_DONE)); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Transfer the firmware image to RAM for execution by the microcontroller. |
| 181 | * |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 182 | * Architecturally, the DMA engine is bidirectional, and can potentially even |
| 183 | * transfer between GTT locations. This functionality is left out of the API |
| 184 | * for now as there is no need for it. |
| 185 | * |
| 186 | * Note that GuC needs the CSS header plus uKernel code to be copied by the |
| 187 | * DMA engine in one operation, whereas the RSA signature is loaded via MMIO. |
| 188 | */ |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 189 | static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv, |
| 190 | struct i915_vma *vma) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 191 | { |
Anusha Srivatsa | db0a091 | 2017-01-13 17:17:04 -0800 | [diff] [blame] | 192 | struct intel_uc_fw *guc_fw = &dev_priv->guc.fw; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 193 | unsigned long offset; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 194 | struct sg_table *sg = vma->pages; |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 195 | u32 status, rsa[UOS_RSA_SCRATCH_MAX_COUNT]; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 196 | int i, ret = 0; |
| 197 | |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 198 | /* where RSA signature starts */ |
| 199 | offset = guc_fw->rsa_offset; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 200 | |
| 201 | /* Copy RSA signature from the fw image to HW for verification */ |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 202 | sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, sizeof(rsa), offset); |
| 203 | for (i = 0; i < UOS_RSA_SCRATCH_MAX_COUNT; i++) |
Ville Syrjälä | ab9cc55 | 2015-09-18 20:03:24 +0300 | [diff] [blame] | 204 | I915_WRITE(UOS_RSA_SCRATCH(i), rsa[i]); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 205 | |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 206 | /* The header plus uCode will be copied to WOPCM via DMA, excluding any |
| 207 | * other components */ |
| 208 | I915_WRITE(DMA_COPY_SIZE, guc_fw->header_size + guc_fw->ucode_size); |
| 209 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 210 | /* Set the source address for the new blob */ |
Chris Wilson | 4741da9 | 2016-12-24 19:31:46 +0000 | [diff] [blame] | 211 | offset = guc_ggtt_offset(vma) + guc_fw->header_offset; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 212 | I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset)); |
| 213 | I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF); |
| 214 | |
| 215 | /* |
| 216 | * Set the DMA destination. Current uCode expects the code to be |
| 217 | * loaded at 8k; locations below this are used for the stack. |
| 218 | */ |
| 219 | I915_WRITE(DMA_ADDR_1_LOW, 0x2000); |
| 220 | I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM); |
| 221 | |
| 222 | /* Finally start the DMA */ |
| 223 | I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(UOS_MOVE | START_DMA)); |
| 224 | |
| 225 | /* |
Tvrtko Ursulin | 36894e8 | 2016-02-11 10:27:31 +0000 | [diff] [blame] | 226 | * Wait for the DMA to complete & the GuC to start up. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 227 | * NB: Docs recommend not using the interrupt for completion. |
| 228 | * Measurements indicate this should take no more than 20ms, so a |
| 229 | * timeout here indicates that the GuC has failed and is unusable. |
| 230 | * (Higher levels of the driver will attempt to fall back to |
| 231 | * execlist mode if this happens.) |
| 232 | */ |
Tvrtko Ursulin | 36894e8 | 2016-02-11 10:27:31 +0000 | [diff] [blame] | 233 | ret = wait_for(guc_ucode_response(dev_priv, &status), 100); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 234 | |
| 235 | DRM_DEBUG_DRIVER("DMA status 0x%x, GuC status 0x%x\n", |
| 236 | I915_READ(DMA_CTRL), status); |
| 237 | |
| 238 | if ((status & GS_BOOTROM_MASK) == GS_BOOTROM_RSA_FAILED) { |
| 239 | DRM_ERROR("GuC firmware signature verification failed\n"); |
| 240 | ret = -ENOEXEC; |
| 241 | } |
| 242 | |
| 243 | DRM_DEBUG_DRIVER("returning %d\n", ret); |
| 244 | |
| 245 | return ret; |
| 246 | } |
| 247 | |
Anusha Srivatsa | bd132858 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 248 | u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv) |
Peter Antoine | 74aa156 | 2016-05-17 15:12:45 +0100 | [diff] [blame] | 249 | { |
| 250 | u32 wopcm_size = GUC_WOPCM_TOP; |
| 251 | |
| 252 | /* On BXT, the top of WOPCM is reserved for RC6 context */ |
Michel Thierry | 254e093 | 2017-01-09 16:51:35 +0200 | [diff] [blame] | 253 | if (IS_GEN9_LP(dev_priv)) |
Peter Antoine | 74aa156 | 2016-05-17 15:12:45 +0100 | [diff] [blame] | 254 | wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED; |
| 255 | |
| 256 | return wopcm_size; |
| 257 | } |
| 258 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 259 | /* |
| 260 | * Load the GuC firmware blob into the MinuteIA. |
| 261 | */ |
| 262 | static int guc_ucode_xfer(struct drm_i915_private *dev_priv) |
| 263 | { |
Anusha Srivatsa | db0a091 | 2017-01-13 17:17:04 -0800 | [diff] [blame] | 264 | struct intel_uc_fw *guc_fw = &dev_priv->guc.fw; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 265 | struct i915_vma *vma; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 266 | int ret; |
| 267 | |
Anusha Srivatsa | db0a091 | 2017-01-13 17:17:04 -0800 | [diff] [blame] | 268 | ret = i915_gem_object_set_to_gtt_domain(guc_fw->obj, false); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 269 | if (ret) { |
| 270 | DRM_DEBUG_DRIVER("set-domain failed %d\n", ret); |
| 271 | return ret; |
| 272 | } |
| 273 | |
Anusha Srivatsa | db0a091 | 2017-01-13 17:17:04 -0800 | [diff] [blame] | 274 | vma = i915_gem_object_ggtt_pin(guc_fw->obj, NULL, 0, 0, |
Michał Winiarski | 83796f2 | 2017-01-11 16:17:39 +0100 | [diff] [blame] | 275 | PIN_OFFSET_BIAS | GUC_WOPCM_TOP); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 276 | if (IS_ERR(vma)) { |
| 277 | DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma)); |
| 278 | return PTR_ERR(vma); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 281 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 282 | |
| 283 | /* init WOPCM */ |
Anusha Srivatsa | bd132858 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 284 | I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv)); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 285 | I915_WRITE(DMA_GUC_WOPCM_OFFSET, GUC_WOPCM_OFFSET_VALUE); |
| 286 | |
| 287 | /* Enable MIA caching. GuC clock gating is disabled. */ |
| 288 | I915_WRITE(GUC_SHIM_CONTROL, GUC_SHIM_CONTROL_VALUE); |
| 289 | |
Jani Nikula | a117f37 | 2016-09-16 16:59:44 +0300 | [diff] [blame] | 290 | /* WaDisableMinuteIaClockGating:bxt */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 291 | if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) { |
Nick Hoath | b970b48 | 2015-09-08 10:31:53 +0100 | [diff] [blame] | 292 | I915_WRITE(GUC_SHIM_CONTROL, (I915_READ(GUC_SHIM_CONTROL) & |
| 293 | ~GUC_ENABLE_MIA_CLOCK_GATING)); |
| 294 | } |
| 295 | |
Jani Nikula | 4ff40a4 | 2016-09-26 15:07:51 +0300 | [diff] [blame] | 296 | /* WaC6DisallowByGfxPause:bxt */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 297 | if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0)) |
Tim Gore | 65fe29e | 2016-07-20 11:00:25 +0100 | [diff] [blame] | 298 | I915_WRITE(GEN6_GFXPAUSE, 0x30FFF); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 299 | |
Michel Thierry | 254e093 | 2017-01-09 16:51:35 +0200 | [diff] [blame] | 300 | if (IS_GEN9_LP(dev_priv)) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 301 | I915_WRITE(GEN9LP_GT_PM_CONFIG, GT_DOORBELL_ENABLE); |
| 302 | else |
| 303 | I915_WRITE(GEN9_GT_PM_CONFIG, GT_DOORBELL_ENABLE); |
| 304 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 305 | if (IS_GEN9(dev_priv)) { |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 306 | /* DOP Clock Gating Enable for GuC clocks */ |
| 307 | I915_WRITE(GEN7_MISCCPCTL, (GEN8_DOP_CLOCK_GATE_GUC_ENABLE | |
| 308 | I915_READ(GEN7_MISCCPCTL))); |
| 309 | |
Dave Gordon | 0c5664e | 2016-09-12 21:19:36 +0100 | [diff] [blame] | 310 | /* allows for 5us (in 10ns units) before GT can go to RC6 */ |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 311 | I915_WRITE(GUC_ARAT_C6DIS, 0x1FF); |
| 312 | } |
| 313 | |
Dave Gordon | 0c5664e | 2016-09-12 21:19:36 +0100 | [diff] [blame] | 314 | guc_params_init(dev_priv); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 315 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 316 | ret = guc_ucode_xfer_dma(dev_priv, vma); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 317 | |
| 318 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 319 | |
| 320 | /* |
| 321 | * We keep the object pages for reuse during resume. But we can unpin it |
| 322 | * now that DMA has completed, so it doesn't continue to take up space. |
| 323 | */ |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 324 | i915_vma_unpin(vma); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 325 | |
| 326 | return ret; |
| 327 | } |
| 328 | |
| 329 | /** |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 330 | * intel_guc_init_hw() - finish preparing the GuC for activity |
| 331 | * @guc: intel_guc structure |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 332 | * |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 333 | * Called during driver loading and also after a GPU reset. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 334 | * |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 335 | * The main action required here it to load the GuC uCode into the device. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 336 | * The firmware image should have already been fetched into memory by the |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 337 | * earlier call to intel_guc_init(), so here we need only check that |
| 338 | * worked, and then transfer the image to the h/w. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 339 | * |
| 340 | * Return: non-zero code on error |
| 341 | */ |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 342 | int intel_guc_init_hw(struct intel_guc *guc) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 343 | { |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 344 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 345 | const char *fw_path = guc->fw.path; |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 346 | int ret; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 347 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 348 | DRM_DEBUG_DRIVER("GuC fw status: path %s, fetch %s, load %s\n", |
| 349 | fw_path, |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 350 | intel_uc_fw_status_repr(guc->fw.fetch_status), |
| 351 | intel_uc_fw_status_repr(guc->fw.load_status)); |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 352 | |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 353 | if (guc->fw.fetch_status != INTEL_UC_FIRMWARE_SUCCESS) |
| 354 | return -EIO; |
Chris Wilson | 7c3f86b | 2017-01-12 11:00:49 +0000 | [diff] [blame] | 355 | |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 356 | guc->fw.load_status = INTEL_UC_FIRMWARE_PENDING; |
Daniel Vetter | 9f9e539 | 2015-10-23 11:10:59 +0200 | [diff] [blame] | 357 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 358 | DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n", |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 359 | intel_uc_fw_status_repr(guc->fw.fetch_status), |
| 360 | intel_uc_fw_status_repr(guc->fw.load_status)); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 361 | |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 362 | ret = guc_ucode_xfer(dev_priv); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 363 | |
Arkadiusz Hiler | 6cd5a72 | 2017-03-14 15:28:11 +0100 | [diff] [blame] | 364 | if (ret) |
| 365 | return -EAGAIN; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 366 | |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 367 | guc->fw.load_status = INTEL_UC_FIRMWARE_SUCCESS; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 368 | |
Tvrtko Ursulin | fb51ff4 | 2017-02-07 08:50:25 +0000 | [diff] [blame] | 369 | DRM_INFO("GuC %s (firmware %s [version %u.%u])\n", |
| 370 | i915.enable_guc_submission ? "submission enabled" : "loaded", |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 371 | guc->fw.path, |
| 372 | guc->fw.major_ver_found, guc->fw.minor_ver_found); |
Tvrtko Ursulin | fb51ff4 | 2017-02-07 08:50:25 +0000 | [diff] [blame] | 373 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 374 | return 0; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 375 | } |
| 376 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 377 | /** |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 378 | * intel_guc_select_fw() - selects GuC firmware for loading |
Arkadiusz Hiler | 29ad6a3 | 2017-03-14 15:28:09 +0100 | [diff] [blame] | 379 | * @guc: intel_guc struct |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 380 | * |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 381 | * Return: zero when we know firmware, non-zero in other case |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 382 | */ |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 383 | int intel_guc_select_fw(struct intel_guc *guc) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 384 | { |
Arkadiusz Hiler | 29ad6a3 | 2017-03-14 15:28:09 +0100 | [diff] [blame] | 385 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Arkadiusz Hiler | 8fc2a4e | 2017-03-14 15:28:12 +0100 | [diff] [blame] | 386 | |
| 387 | guc->fw.path = NULL; |
| 388 | guc->fw.fetch_status = INTEL_UC_FIRMWARE_NONE; |
| 389 | guc->fw.load_status = INTEL_UC_FIRMWARE_NONE; |
Arkadiusz Hiler | 6833b82 | 2017-03-15 14:34:15 +0100 | [diff] [blame] | 390 | guc->fw.type = INTEL_UC_FW_TYPE_GUC; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 391 | |
Arkadiusz Hiler | b3420dd | 2017-03-14 15:28:14 +0100 | [diff] [blame] | 392 | if (i915.guc_firmware_path) { |
| 393 | guc->fw.path = i915.guc_firmware_path; |
| 394 | guc->fw.major_ver_wanted = 0; |
| 395 | guc->fw.minor_ver_wanted = 0; |
| 396 | } else if (IS_SKYLAKE(dev_priv)) { |
Arkadiusz Hiler | 8fc2a4e | 2017-03-14 15:28:12 +0100 | [diff] [blame] | 397 | guc->fw.path = I915_SKL_GUC_UCODE; |
Arkadiusz Hiler | 29ad6a3 | 2017-03-14 15:28:09 +0100 | [diff] [blame] | 398 | guc->fw.major_ver_wanted = SKL_FW_MAJOR; |
| 399 | guc->fw.minor_ver_wanted = SKL_FW_MINOR; |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 400 | } else if (IS_BROXTON(dev_priv)) { |
Arkadiusz Hiler | 8fc2a4e | 2017-03-14 15:28:12 +0100 | [diff] [blame] | 401 | guc->fw.path = I915_BXT_GUC_UCODE; |
Arkadiusz Hiler | 29ad6a3 | 2017-03-14 15:28:09 +0100 | [diff] [blame] | 402 | guc->fw.major_ver_wanted = BXT_FW_MAJOR; |
| 403 | guc->fw.minor_ver_wanted = BXT_FW_MINOR; |
Tvrtko Ursulin | 0853723 | 2016-10-13 11:03:02 +0100 | [diff] [blame] | 404 | } else if (IS_KABYLAKE(dev_priv)) { |
Arkadiusz Hiler | 8fc2a4e | 2017-03-14 15:28:12 +0100 | [diff] [blame] | 405 | guc->fw.path = I915_KBL_GUC_UCODE; |
Arkadiusz Hiler | 29ad6a3 | 2017-03-14 15:28:09 +0100 | [diff] [blame] | 406 | guc->fw.major_ver_wanted = KBL_FW_MAJOR; |
| 407 | guc->fw.minor_ver_wanted = KBL_FW_MINOR; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 408 | } else { |
Arkadiusz Hiler | 8fc2a4e | 2017-03-14 15:28:12 +0100 | [diff] [blame] | 409 | DRM_ERROR("No GuC firmware known for platform with GuC!\n"); |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 410 | return -ENOENT; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Arkadiusz Hiler | b551f61 | 2017-03-14 15:28:13 +0100 | [diff] [blame] | 413 | return 0; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 414 | } |