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 | */ |
| 29 | #include <linux/firmware.h> |
| 30 | #include "i915_drv.h" |
| 31 | #include "intel_guc.h" |
| 32 | |
| 33 | /** |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 34 | * DOC: GuC-specific firmware loader |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 35 | * |
| 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 | * |
| 54 | * Firmware log: |
| 55 | * Firmware log is enabled by setting i915.guc_log_level to non-negative level. |
| 56 | * Log data is printed out via reading debugfs i915_guc_log_dump. Reading from |
| 57 | * i915_guc_load_status will print out firmware loading status and scratch |
| 58 | * registers value. |
| 59 | * |
| 60 | */ |
| 61 | |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 62 | #define SKL_FW_MAJOR 6 |
| 63 | #define SKL_FW_MINOR 1 |
| 64 | |
| 65 | #define BXT_FW_MAJOR 8 |
| 66 | #define BXT_FW_MINOR 7 |
| 67 | |
| 68 | #define KBL_FW_MAJOR 9 |
| 69 | #define KBL_FW_MINOR 14 |
| 70 | |
| 71 | #define GUC_FW_PATH(platform, major, minor) \ |
| 72 | "i915/" __stringify(platform) "_guc_ver" __stringify(major) "_" __stringify(minor) ".bin" |
| 73 | |
| 74 | #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] | 75 | MODULE_FIRMWARE(I915_SKL_GUC_UCODE); |
| 76 | |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 77 | #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] | 78 | MODULE_FIRMWARE(I915_BXT_GUC_UCODE); |
| 79 | |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 80 | #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] | 81 | MODULE_FIRMWARE(I915_KBL_GUC_UCODE); |
| 82 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 83 | /* User-friendly representation of an enum */ |
| 84 | const char *intel_guc_fw_status_repr(enum intel_guc_fw_status status) |
| 85 | { |
| 86 | switch (status) { |
| 87 | case GUC_FIRMWARE_FAIL: |
| 88 | return "FAIL"; |
| 89 | case GUC_FIRMWARE_NONE: |
| 90 | return "NONE"; |
| 91 | case GUC_FIRMWARE_PENDING: |
| 92 | return "PENDING"; |
| 93 | case GUC_FIRMWARE_SUCCESS: |
| 94 | return "SUCCESS"; |
| 95 | default: |
| 96 | return "UNKNOWN!"; |
| 97 | } |
| 98 | }; |
| 99 | |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 100 | static void direct_interrupts_to_host(struct drm_i915_private *dev_priv) |
| 101 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 102 | struct intel_engine_cs *engine; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 103 | int irqs; |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 104 | |
Dave Gordon | fa7545a | 2016-06-24 15:57:57 +0100 | [diff] [blame] | 105 | /* tell all command streamers NOT to forward interrupts or vblank to GuC */ |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 106 | irqs = _MASKED_FIELD(GFX_FORWARD_VBLANK_MASK, GFX_FORWARD_VBLANK_NEVER); |
| 107 | irqs |= _MASKED_BIT_DISABLE(GFX_INTERRUPT_STEERING); |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 108 | for_each_engine(engine, dev_priv) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 109 | I915_WRITE(RING_MODE_GEN7(engine), irqs); |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 110 | |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 111 | /* route all GT interrupts to the host */ |
| 112 | I915_WRITE(GUC_BCS_RCS_IER, 0); |
| 113 | I915_WRITE(GUC_VCS2_VCS1_IER, 0); |
| 114 | I915_WRITE(GUC_WD_VECS_IER, 0); |
| 115 | } |
| 116 | |
| 117 | static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv) |
| 118 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 119 | struct intel_engine_cs *engine; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 120 | int irqs; |
Sagar Arun Kamble | 1800ad2 | 2016-05-31 13:58:27 +0530 | [diff] [blame] | 121 | u32 tmp; |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 122 | |
Dave Gordon | fa7545a | 2016-06-24 15:57:57 +0100 | [diff] [blame] | 123 | /* tell all command streamers to forward interrupts (but not vblank) to GuC */ |
| 124 | irqs = _MASKED_BIT_ENABLE(GFX_INTERRUPT_STEERING); |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 125 | for_each_engine(engine, dev_priv) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 126 | I915_WRITE(RING_MODE_GEN7(engine), irqs); |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 127 | |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 128 | /* route USER_INTERRUPT to Host, all others are sent to GuC. */ |
| 129 | irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | |
| 130 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT; |
| 131 | /* These three registers have the same bit definitions */ |
| 132 | I915_WRITE(GUC_BCS_RCS_IER, ~irqs); |
| 133 | I915_WRITE(GUC_VCS2_VCS1_IER, ~irqs); |
| 134 | I915_WRITE(GUC_WD_VECS_IER, ~irqs); |
Sagar Arun Kamble | 1800ad2 | 2016-05-31 13:58:27 +0530 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * If GuC has routed PM interrupts to itself, don't keep it. |
| 138 | * and keep other interrupts those are unmasked by GuC. |
| 139 | */ |
| 140 | tmp = I915_READ(GEN6_PMINTRMSK); |
| 141 | if (tmp & GEN8_PMINTR_REDIRECT_TO_NON_DISP) { |
| 142 | dev_priv->rps.pm_intr_keep |= ~(tmp & ~GEN8_PMINTR_REDIRECT_TO_NON_DISP); |
| 143 | dev_priv->rps.pm_intr_keep &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP; |
| 144 | } |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 147 | static u32 get_gttype(struct drm_i915_private *dev_priv) |
| 148 | { |
| 149 | /* XXX: GT type based on PCI device ID? field seems unused by fw */ |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static u32 get_core_family(struct drm_i915_private *dev_priv) |
| 154 | { |
| 155 | switch (INTEL_INFO(dev_priv)->gen) { |
| 156 | case 9: |
| 157 | return GFXCORE_FAMILY_GEN9; |
| 158 | |
| 159 | default: |
| 160 | DRM_ERROR("GUC: unsupported core family\n"); |
| 161 | return GFXCORE_FAMILY_UNKNOWN; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | static void set_guc_init_params(struct drm_i915_private *dev_priv) |
| 166 | { |
| 167 | struct intel_guc *guc = &dev_priv->guc; |
| 168 | u32 params[GUC_CTL_MAX_DWORDS]; |
| 169 | int i; |
| 170 | |
| 171 | memset(¶ms, 0, sizeof(params)); |
| 172 | |
| 173 | params[GUC_CTL_DEVICE_INFO] |= |
| 174 | (get_gttype(dev_priv) << GUC_CTL_GTTYPE_SHIFT) | |
| 175 | (get_core_family(dev_priv) << GUC_CTL_COREFAMILY_SHIFT); |
| 176 | |
| 177 | /* |
| 178 | * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one |
| 179 | * second. This ARAR is calculated by: |
| 180 | * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10 |
| 181 | */ |
| 182 | params[GUC_CTL_ARAT_HIGH] = 0; |
| 183 | params[GUC_CTL_ARAT_LOW] = 100000000; |
| 184 | |
| 185 | params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER; |
| 186 | |
| 187 | params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER | |
| 188 | GUC_CTL_VCS2_ENABLED; |
| 189 | |
| 190 | if (i915.guc_log_level >= 0) { |
| 191 | params[GUC_CTL_LOG_PARAMS] = guc->log_flags; |
| 192 | params[GUC_CTL_DEBUG] = |
| 193 | i915.guc_log_level << GUC_LOG_VERBOSITY_SHIFT; |
| 194 | } |
| 195 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 196 | if (guc->ads_vma) { |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 197 | u32 ads = i915_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT; |
Alex Dai | b6a5cd7 | 2015-12-18 12:00:12 -0800 | [diff] [blame] | 198 | params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT; |
| 199 | params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED; |
| 200 | } |
| 201 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 202 | /* If GuC submission is enabled, set up additional parameters here */ |
| 203 | if (i915.enable_guc_submission) { |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 204 | u32 pgs = i915_ggtt_offset(dev_priv->guc.ctx_pool_vma); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 205 | u32 ctx_in_16 = GUC_MAX_GPU_CONTEXTS / 16; |
| 206 | |
| 207 | pgs >>= PAGE_SHIFT; |
| 208 | params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) | |
| 209 | (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT); |
| 210 | |
| 211 | params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS; |
| 212 | |
| 213 | /* Unmask this bit to enable the GuC's internal scheduler */ |
| 214 | params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER; |
| 215 | } |
| 216 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 217 | I915_WRITE(SOFT_SCRATCH(0), 0); |
| 218 | |
| 219 | for (i = 0; i < GUC_CTL_MAX_DWORDS; i++) |
| 220 | I915_WRITE(SOFT_SCRATCH(1 + i), params[i]); |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Read the GuC status register (GUC_STATUS) and store it in the |
| 225 | * specified location; then return a boolean indicating whether |
| 226 | * the value matches either of two values representing completion |
| 227 | * of the GuC boot process. |
| 228 | * |
Tvrtko Ursulin | 36894e8 | 2016-02-11 10:27:31 +0000 | [diff] [blame] | 229 | * This is used for polling the GuC status in a wait_for() |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 230 | * loop below. |
| 231 | */ |
| 232 | static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, |
| 233 | u32 *status) |
| 234 | { |
| 235 | u32 val = I915_READ(GUC_STATUS); |
Alex Dai | 0d44d3f | 2015-09-22 13:48:40 -0700 | [diff] [blame] | 236 | u32 uk_val = val & GS_UKERNEL_MASK; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 237 | *status = val; |
Alex Dai | 0d44d3f | 2015-09-22 13:48:40 -0700 | [diff] [blame] | 238 | return (uk_val == GS_UKERNEL_READY || |
| 239 | ((val & GS_MIA_CORE_STATE) && uk_val == GS_UKERNEL_LAPIC_DONE)); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /* |
| 243 | * Transfer the firmware image to RAM for execution by the microcontroller. |
| 244 | * |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 245 | * Architecturally, the DMA engine is bidirectional, and can potentially even |
| 246 | * transfer between GTT locations. This functionality is left out of the API |
| 247 | * for now as there is no need for it. |
| 248 | * |
| 249 | * Note that GuC needs the CSS header plus uKernel code to be copied by the |
| 250 | * DMA engine in one operation, whereas the RSA signature is loaded via MMIO. |
| 251 | */ |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 252 | static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv, |
| 253 | struct i915_vma *vma) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 254 | { |
| 255 | struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 256 | unsigned long offset; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 257 | struct sg_table *sg = vma->pages; |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 258 | u32 status, rsa[UOS_RSA_SCRATCH_MAX_COUNT]; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 259 | int i, ret = 0; |
| 260 | |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 261 | /* where RSA signature starts */ |
| 262 | offset = guc_fw->rsa_offset; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 263 | |
| 264 | /* Copy RSA signature from the fw image to HW for verification */ |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 265 | sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, sizeof(rsa), offset); |
| 266 | for (i = 0; i < UOS_RSA_SCRATCH_MAX_COUNT; i++) |
Ville Syrjälä | ab9cc55 | 2015-09-18 20:03:24 +0300 | [diff] [blame] | 267 | I915_WRITE(UOS_RSA_SCRATCH(i), rsa[i]); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 268 | |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 269 | /* The header plus uCode will be copied to WOPCM via DMA, excluding any |
| 270 | * other components */ |
| 271 | I915_WRITE(DMA_COPY_SIZE, guc_fw->header_size + guc_fw->ucode_size); |
| 272 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 273 | /* Set the source address for the new blob */ |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 274 | offset = i915_ggtt_offset(vma) + guc_fw->header_offset; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 275 | I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset)); |
| 276 | I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF); |
| 277 | |
| 278 | /* |
| 279 | * Set the DMA destination. Current uCode expects the code to be |
| 280 | * loaded at 8k; locations below this are used for the stack. |
| 281 | */ |
| 282 | I915_WRITE(DMA_ADDR_1_LOW, 0x2000); |
| 283 | I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM); |
| 284 | |
| 285 | /* Finally start the DMA */ |
| 286 | I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(UOS_MOVE | START_DMA)); |
| 287 | |
| 288 | /* |
Tvrtko Ursulin | 36894e8 | 2016-02-11 10:27:31 +0000 | [diff] [blame] | 289 | * Wait for the DMA to complete & the GuC to start up. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 290 | * NB: Docs recommend not using the interrupt for completion. |
| 291 | * Measurements indicate this should take no more than 20ms, so a |
| 292 | * timeout here indicates that the GuC has failed and is unusable. |
| 293 | * (Higher levels of the driver will attempt to fall back to |
| 294 | * execlist mode if this happens.) |
| 295 | */ |
Tvrtko Ursulin | 36894e8 | 2016-02-11 10:27:31 +0000 | [diff] [blame] | 296 | ret = wait_for(guc_ucode_response(dev_priv, &status), 100); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 297 | |
| 298 | DRM_DEBUG_DRIVER("DMA status 0x%x, GuC status 0x%x\n", |
| 299 | I915_READ(DMA_CTRL), status); |
| 300 | |
| 301 | if ((status & GS_BOOTROM_MASK) == GS_BOOTROM_RSA_FAILED) { |
| 302 | DRM_ERROR("GuC firmware signature verification failed\n"); |
| 303 | ret = -ENOEXEC; |
| 304 | } |
| 305 | |
| 306 | DRM_DEBUG_DRIVER("returning %d\n", ret); |
| 307 | |
| 308 | return ret; |
| 309 | } |
| 310 | |
Peter Antoine | 74aa156ba | 2016-05-17 15:12:45 +0100 | [diff] [blame] | 311 | static u32 guc_wopcm_size(struct drm_i915_private *dev_priv) |
| 312 | { |
| 313 | u32 wopcm_size = GUC_WOPCM_TOP; |
| 314 | |
| 315 | /* On BXT, the top of WOPCM is reserved for RC6 context */ |
| 316 | if (IS_BROXTON(dev_priv)) |
| 317 | wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED; |
| 318 | |
| 319 | return wopcm_size; |
| 320 | } |
| 321 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 322 | /* |
| 323 | * Load the GuC firmware blob into the MinuteIA. |
| 324 | */ |
| 325 | static int guc_ucode_xfer(struct drm_i915_private *dev_priv) |
| 326 | { |
| 327 | struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 328 | struct drm_device *dev = &dev_priv->drm; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 329 | struct i915_vma *vma; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 330 | int ret; |
| 331 | |
| 332 | ret = i915_gem_object_set_to_gtt_domain(guc_fw->guc_fw_obj, false); |
| 333 | if (ret) { |
| 334 | DRM_DEBUG_DRIVER("set-domain failed %d\n", ret); |
| 335 | return ret; |
| 336 | } |
| 337 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 338 | vma = i915_gem_object_ggtt_pin(guc_fw->guc_fw_obj, NULL, 0, 0, 0); |
| 339 | if (IS_ERR(vma)) { |
| 340 | DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma)); |
| 341 | return PTR_ERR(vma); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* Invalidate GuC TLB to let GuC take the latest updates to GTT. */ |
| 345 | I915_WRITE(GEN8_GTCR, GEN8_GTCR_INVALIDATE); |
| 346 | |
| 347 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 348 | |
| 349 | /* init WOPCM */ |
Peter Antoine | 74aa156ba | 2016-05-17 15:12:45 +0100 | [diff] [blame] | 350 | I915_WRITE(GUC_WOPCM_SIZE, guc_wopcm_size(dev_priv)); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 351 | I915_WRITE(DMA_GUC_WOPCM_OFFSET, GUC_WOPCM_OFFSET_VALUE); |
| 352 | |
| 353 | /* Enable MIA caching. GuC clock gating is disabled. */ |
| 354 | I915_WRITE(GUC_SHIM_CONTROL, GUC_SHIM_CONTROL_VALUE); |
| 355 | |
Nick Hoath | b970b48 | 2015-09-08 10:31:53 +0100 | [diff] [blame] | 356 | /* WaDisableMinuteIaClockGating:skl,bxt */ |
Jani Nikula | e87a005 | 2015-10-20 15:22:02 +0300 | [diff] [blame] | 357 | if (IS_SKL_REVID(dev, 0, SKL_REVID_B0) || |
Tim Gore | cbdc12a | 2015-10-26 10:48:58 +0000 | [diff] [blame] | 358 | IS_BXT_REVID(dev, 0, BXT_REVID_A1)) { |
Nick Hoath | b970b48 | 2015-09-08 10:31:53 +0100 | [diff] [blame] | 359 | I915_WRITE(GUC_SHIM_CONTROL, (I915_READ(GUC_SHIM_CONTROL) & |
| 360 | ~GUC_ENABLE_MIA_CLOCK_GATING)); |
| 361 | } |
| 362 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 363 | /* WaC6DisallowByGfxPause*/ |
Tim Gore | 65fe29e | 2016-07-20 11:00:25 +0100 | [diff] [blame] | 364 | if (IS_SKL_REVID(dev, 0, SKL_REVID_C0) || |
| 365 | IS_BXT_REVID(dev, 0, BXT_REVID_B0)) |
| 366 | I915_WRITE(GEN6_GFXPAUSE, 0x30FFF); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 367 | |
| 368 | if (IS_BROXTON(dev)) |
| 369 | I915_WRITE(GEN9LP_GT_PM_CONFIG, GT_DOORBELL_ENABLE); |
| 370 | else |
| 371 | I915_WRITE(GEN9_GT_PM_CONFIG, GT_DOORBELL_ENABLE); |
| 372 | |
| 373 | if (IS_GEN9(dev)) { |
| 374 | /* DOP Clock Gating Enable for GuC clocks */ |
| 375 | I915_WRITE(GEN7_MISCCPCTL, (GEN8_DOP_CLOCK_GATE_GUC_ENABLE | |
| 376 | I915_READ(GEN7_MISCCPCTL))); |
| 377 | |
| 378 | /* allows for 5us before GT can go to RC6 */ |
| 379 | I915_WRITE(GUC_ARAT_C6DIS, 0x1FF); |
| 380 | } |
| 381 | |
| 382 | set_guc_init_params(dev_priv); |
| 383 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 384 | ret = guc_ucode_xfer_dma(dev_priv, vma); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 385 | |
| 386 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 387 | |
| 388 | /* |
| 389 | * We keep the object pages for reuse during resume. But we can unpin it |
| 390 | * now that DMA has completed, so it doesn't continue to take up space. |
| 391 | */ |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 392 | i915_vma_unpin(vma); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 393 | |
| 394 | return ret; |
| 395 | } |
| 396 | |
Arun Siluvery | 6b332fa | 2016-04-04 18:50:56 +0100 | [diff] [blame] | 397 | static int i915_reset_guc(struct drm_i915_private *dev_priv) |
| 398 | { |
| 399 | int ret; |
| 400 | u32 guc_status; |
| 401 | |
| 402 | ret = intel_guc_reset(dev_priv); |
| 403 | if (ret) { |
| 404 | DRM_ERROR("GuC reset failed, ret = %d\n", ret); |
| 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | guc_status = I915_READ(GUC_STATUS); |
| 409 | WARN(!(guc_status & GS_MIA_IN_RESET), |
| 410 | "GuC status: 0x%x, MIA core expected to be in reset\n", guc_status); |
| 411 | |
| 412 | return ret; |
| 413 | } |
| 414 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 415 | /** |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 416 | * intel_guc_setup() - finish preparing the GuC for activity |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 417 | * @dev: drm device |
| 418 | * |
| 419 | * Called from gem_init_hw() during driver loading and also after a GPU reset. |
| 420 | * |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 421 | * 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] | 422 | * The firmware image should have already been fetched into memory by the |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 423 | * earlier call to intel_guc_init(), so here we need only check that worked, |
| 424 | * and then transfer the image to the h/w. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 425 | * |
| 426 | * Return: non-zero code on error |
| 427 | */ |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 428 | int intel_guc_setup(struct drm_device *dev) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 429 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 430 | struct drm_i915_private *dev_priv = to_i915(dev); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 431 | struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 432 | const char *fw_path = guc_fw->guc_fw_path; |
| 433 | int retries, ret, err; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 434 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 435 | DRM_DEBUG_DRIVER("GuC fw status: path %s, fetch %s, load %s\n", |
| 436 | fw_path, |
| 437 | intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status), |
| 438 | intel_guc_fw_status_repr(guc_fw->guc_fw_load_status)); |
| 439 | |
| 440 | /* Loading forbidden, or no firmware to load? */ |
| 441 | if (!i915.enable_guc_loading) { |
| 442 | err = 0; |
| 443 | goto fail; |
Dave Gordon | e556f7c | 2016-06-07 09:14:49 +0100 | [diff] [blame] | 444 | } else if (fw_path == NULL) { |
| 445 | /* Device is known to have no uCode (e.g. no GuC) */ |
| 446 | err = -ENXIO; |
| 447 | goto fail; |
| 448 | } else if (*fw_path == '\0') { |
| 449 | /* Device has a GuC but we don't know what f/w to load? */ |
| 450 | DRM_INFO("No GuC firmware known for this platform\n"); |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 451 | err = -ENODEV; |
| 452 | goto fail; |
| 453 | } |
| 454 | |
| 455 | /* Fetch failed, or already fetched but failed to load? */ |
| 456 | if (guc_fw->guc_fw_fetch_status != GUC_FIRMWARE_SUCCESS) { |
| 457 | err = -EIO; |
| 458 | goto fail; |
| 459 | } else if (guc_fw->guc_fw_load_status == GUC_FIRMWARE_FAIL) { |
| 460 | err = -ENOEXEC; |
| 461 | goto fail; |
| 462 | } |
| 463 | |
| 464 | direct_interrupts_to_host(dev_priv); |
| 465 | |
| 466 | guc_fw->guc_fw_load_status = GUC_FIRMWARE_PENDING; |
Daniel Vetter | 9f9e539 | 2015-10-23 11:10:59 +0200 | [diff] [blame] | 467 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 468 | DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n", |
| 469 | intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status), |
| 470 | intel_guc_fw_status_repr(guc_fw->guc_fw_load_status)); |
| 471 | |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 472 | err = i915_guc_submission_init(dev_priv); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 473 | if (err) |
| 474 | goto fail; |
| 475 | |
Arun Siluvery | 6b332fa | 2016-04-04 18:50:56 +0100 | [diff] [blame] | 476 | /* |
| 477 | * WaEnableuKernelHeaderValidFix:skl,bxt |
| 478 | * For BXT, this is only upto B0 but below WA is required for later |
| 479 | * steppings also so this is extended as well. |
| 480 | */ |
| 481 | /* WaEnableGuCBootHashCheckNotSet:skl,bxt */ |
Dave Gordon | d761701 | 2016-04-04 18:50:57 +0100 | [diff] [blame] | 482 | for (retries = 3; ; ) { |
| 483 | /* |
| 484 | * Always reset the GuC just before (re)loading, so |
| 485 | * that the state and timing are fairly predictable |
| 486 | */ |
| 487 | err = i915_reset_guc(dev_priv); |
Arun Siluvery | 6b332fa | 2016-04-04 18:50:56 +0100 | [diff] [blame] | 488 | if (err) { |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 489 | DRM_ERROR("GuC reset failed: %d\n", err); |
Arun Siluvery | 6b332fa | 2016-04-04 18:50:56 +0100 | [diff] [blame] | 490 | goto fail; |
| 491 | } |
Dave Gordon | d761701 | 2016-04-04 18:50:57 +0100 | [diff] [blame] | 492 | |
| 493 | err = guc_ucode_xfer(dev_priv); |
| 494 | if (!err) |
| 495 | break; |
| 496 | |
| 497 | if (--retries == 0) |
| 498 | goto fail; |
| 499 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 500 | DRM_INFO("GuC fw load failed: %d; will reset and " |
| 501 | "retry %d more time(s)\n", err, retries); |
Arun Siluvery | 6b332fa | 2016-04-04 18:50:56 +0100 | [diff] [blame] | 502 | } |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 503 | |
| 504 | guc_fw->guc_fw_load_status = GUC_FIRMWARE_SUCCESS; |
| 505 | |
| 506 | DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n", |
| 507 | intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status), |
| 508 | intel_guc_fw_status_repr(guc_fw->guc_fw_load_status)); |
| 509 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 510 | if (i915.enable_guc_submission) { |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 511 | err = i915_guc_submission_enable(dev_priv); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 512 | if (err) |
| 513 | goto fail; |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 514 | direct_interrupts_to_guc(dev_priv); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 517 | return 0; |
| 518 | |
| 519 | fail: |
| 520 | if (guc_fw->guc_fw_load_status == GUC_FIRMWARE_PENDING) |
| 521 | guc_fw->guc_fw_load_status = GUC_FIRMWARE_FAIL; |
| 522 | |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 523 | direct_interrupts_to_host(dev_priv); |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 524 | i915_guc_submission_disable(dev_priv); |
| 525 | i915_guc_submission_fini(dev_priv); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 526 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 527 | /* |
| 528 | * We've failed to load the firmware :( |
| 529 | * |
| 530 | * Decide whether to disable GuC submission and fall back to |
| 531 | * execlist mode, and whether to hide the error by returning |
| 532 | * zero or to return -EIO, which the caller will treat as a |
| 533 | * nonfatal error (i.e. it doesn't prevent driver load, but |
| 534 | * marks the GPU as wedged until reset). |
| 535 | */ |
| 536 | if (i915.enable_guc_loading > 1) { |
| 537 | ret = -EIO; |
| 538 | } else if (i915.enable_guc_submission > 1) { |
| 539 | ret = -EIO; |
| 540 | } else { |
| 541 | ret = 0; |
| 542 | } |
| 543 | |
Dave Gordon | 4e50f79 | 2016-06-10 17:21:25 +0100 | [diff] [blame] | 544 | if (err == 0 && !HAS_GUC_UCODE(dev)) |
| 545 | ; /* Don't mention the GuC! */ |
| 546 | else if (err == 0) |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 547 | DRM_INFO("GuC firmware load skipped\n"); |
Dave Gordon | 4e50f79 | 2016-06-10 17:21:25 +0100 | [diff] [blame] | 548 | else if (ret != -EIO) |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 549 | DRM_INFO("GuC firmware load failed: %d\n", err); |
Dave Gordon | 4e50f79 | 2016-06-10 17:21:25 +0100 | [diff] [blame] | 550 | else |
| 551 | DRM_ERROR("GuC firmware load failed: %d\n", err); |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 552 | |
| 553 | if (i915.enable_guc_submission) { |
| 554 | if (fw_path == NULL) |
| 555 | DRM_INFO("GuC submission without firmware not supported\n"); |
| 556 | if (ret == 0) |
Dave Gordon | e556f7c | 2016-06-07 09:14:49 +0100 | [diff] [blame] | 557 | DRM_INFO("Falling back from GuC submission to execlist mode\n"); |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 558 | else |
| 559 | DRM_ERROR("GuC init failed: %d\n", ret); |
| 560 | } |
| 561 | i915.enable_guc_submission = 0; |
| 562 | |
| 563 | return ret; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) |
| 567 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame^] | 568 | struct pci_dev *pdev = dev->pdev; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 569 | struct drm_i915_gem_object *obj; |
| 570 | const struct firmware *fw; |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 571 | struct guc_css_header *css; |
| 572 | size_t size; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 573 | int err; |
| 574 | |
| 575 | DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetch status %s\n", |
| 576 | intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status)); |
| 577 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame^] | 578 | err = request_firmware(&fw, guc_fw->guc_fw_path, &pdev->dev); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 579 | if (err) |
| 580 | goto fail; |
| 581 | if (!fw) |
| 582 | goto fail; |
| 583 | |
| 584 | DRM_DEBUG_DRIVER("fetch GuC fw from %s succeeded, fw %p\n", |
| 585 | guc_fw->guc_fw_path, fw); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 586 | |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 587 | /* Check the size of the blob before examining buffer contents */ |
| 588 | if (fw->size < sizeof(struct guc_css_header)) { |
| 589 | DRM_ERROR("Firmware header is missing\n"); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 590 | goto fail; |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | css = (struct guc_css_header *)fw->data; |
| 594 | |
| 595 | /* Firmware bits always start from header */ |
| 596 | guc_fw->header_offset = 0; |
| 597 | guc_fw->header_size = (css->header_size_dw - css->modulus_size_dw - |
| 598 | css->key_size_dw - css->exponent_size_dw) * sizeof(u32); |
| 599 | |
| 600 | if (guc_fw->header_size != sizeof(struct guc_css_header)) { |
| 601 | DRM_ERROR("CSS header definition mismatch\n"); |
| 602 | goto fail; |
| 603 | } |
| 604 | |
| 605 | /* then, uCode */ |
| 606 | guc_fw->ucode_offset = guc_fw->header_offset + guc_fw->header_size; |
| 607 | guc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32); |
| 608 | |
| 609 | /* now RSA */ |
| 610 | if (css->key_size_dw != UOS_RSA_SCRATCH_MAX_COUNT) { |
| 611 | DRM_ERROR("RSA key size is bad\n"); |
| 612 | goto fail; |
| 613 | } |
| 614 | guc_fw->rsa_offset = guc_fw->ucode_offset + guc_fw->ucode_size; |
| 615 | guc_fw->rsa_size = css->key_size_dw * sizeof(u32); |
| 616 | |
| 617 | /* At least, it should have header, uCode and RSA. Size of all three. */ |
| 618 | size = guc_fw->header_size + guc_fw->ucode_size + guc_fw->rsa_size; |
| 619 | if (fw->size < size) { |
| 620 | DRM_ERROR("Missing firmware components\n"); |
| 621 | goto fail; |
| 622 | } |
| 623 | |
| 624 | /* Header and uCode will be loaded to WOPCM. Size of the two. */ |
| 625 | size = guc_fw->header_size + guc_fw->ucode_size; |
Dave Gordon | f19ec8c | 2016-07-04 11:34:37 +0100 | [diff] [blame] | 626 | if (size > guc_wopcm_size(to_i915(dev))) { |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 627 | DRM_ERROR("Firmware is too large to fit in WOPCM\n"); |
| 628 | goto fail; |
| 629 | } |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 630 | |
| 631 | /* |
| 632 | * The GuC firmware image has the version number embedded at a well-known |
| 633 | * offset within the firmware blob; note that major / minor version are |
| 634 | * TWO bytes each (i.e. u16), although all pointers and offsets are defined |
| 635 | * in terms of bytes (u8). |
| 636 | */ |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 637 | guc_fw->guc_fw_major_found = css->guc_sw_version >> 16; |
| 638 | guc_fw->guc_fw_minor_found = css->guc_sw_version & 0xFFFF; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 639 | |
| 640 | if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || |
| 641 | guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) { |
| 642 | DRM_ERROR("GuC firmware version %d.%d, required %d.%d\n", |
| 643 | guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found, |
| 644 | guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted); |
| 645 | err = -ENOEXEC; |
| 646 | goto fail; |
| 647 | } |
| 648 | |
| 649 | DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n", |
| 650 | guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found, |
| 651 | guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted); |
| 652 | |
Daniel Stone | bf248ca | 2015-11-03 21:42:31 +0000 | [diff] [blame] | 653 | mutex_lock(&dev->struct_mutex); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 654 | obj = i915_gem_object_create_from_data(dev, fw->data, fw->size); |
Daniel Stone | bf248ca | 2015-11-03 21:42:31 +0000 | [diff] [blame] | 655 | mutex_unlock(&dev->struct_mutex); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 656 | if (IS_ERR_OR_NULL(obj)) { |
| 657 | err = obj ? PTR_ERR(obj) : -ENOMEM; |
| 658 | goto fail; |
| 659 | } |
| 660 | |
| 661 | guc_fw->guc_fw_obj = obj; |
| 662 | guc_fw->guc_fw_size = fw->size; |
| 663 | |
| 664 | DRM_DEBUG_DRIVER("GuC fw fetch status SUCCESS, obj %p\n", |
| 665 | guc_fw->guc_fw_obj); |
| 666 | |
| 667 | release_firmware(fw); |
| 668 | guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_SUCCESS; |
| 669 | return; |
| 670 | |
| 671 | fail: |
| 672 | DRM_DEBUG_DRIVER("GuC fw fetch status FAIL; err %d, fw %p, obj %p\n", |
| 673 | err, fw, guc_fw->guc_fw_obj); |
| 674 | DRM_ERROR("Failed to fetch GuC firmware from %s (error %d)\n", |
| 675 | guc_fw->guc_fw_path, err); |
| 676 | |
Alex Dai | a9d8ada | 2016-01-13 11:01:50 -0800 | [diff] [blame] | 677 | mutex_lock(&dev->struct_mutex); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 678 | obj = guc_fw->guc_fw_obj; |
| 679 | if (obj) |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 680 | i915_gem_object_put(obj); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 681 | guc_fw->guc_fw_obj = NULL; |
Alex Dai | a9d8ada | 2016-01-13 11:01:50 -0800 | [diff] [blame] | 682 | mutex_unlock(&dev->struct_mutex); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 683 | |
| 684 | release_firmware(fw); /* OK even if fw is NULL */ |
| 685 | guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_FAIL; |
| 686 | } |
| 687 | |
| 688 | /** |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 689 | * intel_guc_init() - define parameters and fetch firmware |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 690 | * @dev: drm device |
| 691 | * |
| 692 | * Called early during driver load, but after GEM is initialised. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 693 | * |
| 694 | * The firmware will be transferred to the GuC's memory later, |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 695 | * when intel_guc_setup() is called. |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 696 | */ |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 697 | void intel_guc_init(struct drm_device *dev) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 698 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 699 | struct drm_i915_private *dev_priv = to_i915(dev); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 700 | struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; |
| 701 | const char *fw_path; |
| 702 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 703 | /* A negative value means "use platform default" */ |
| 704 | if (i915.enable_guc_loading < 0) |
| 705 | i915.enable_guc_loading = HAS_GUC_UCODE(dev); |
| 706 | if (i915.enable_guc_submission < 0) |
| 707 | i915.enable_guc_submission = HAS_GUC_SCHED(dev); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 708 | |
| 709 | if (!HAS_GUC_UCODE(dev)) { |
| 710 | fw_path = NULL; |
| 711 | } else if (IS_SKYLAKE(dev)) { |
| 712 | fw_path = I915_SKL_GUC_UCODE; |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 713 | guc_fw->guc_fw_major_wanted = SKL_FW_MAJOR; |
| 714 | guc_fw->guc_fw_minor_wanted = SKL_FW_MINOR; |
Nick Hoath | 57bf5c8 | 2016-05-06 11:42:53 +0100 | [diff] [blame] | 715 | } else if (IS_BROXTON(dev)) { |
| 716 | fw_path = I915_BXT_GUC_UCODE; |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 717 | guc_fw->guc_fw_major_wanted = BXT_FW_MAJOR; |
| 718 | guc_fw->guc_fw_minor_wanted = BXT_FW_MINOR; |
Peter Antoine | ff64cc1 | 2016-06-30 09:37:52 -0700 | [diff] [blame] | 719 | } else if (IS_KABYLAKE(dev)) { |
| 720 | fw_path = I915_KBL_GUC_UCODE; |
Tvrtko Ursulin | 5e334c1 | 2016-08-10 16:16:46 +0100 | [diff] [blame] | 721 | guc_fw->guc_fw_major_wanted = KBL_FW_MAJOR; |
| 722 | guc_fw->guc_fw_minor_wanted = KBL_FW_MINOR; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 723 | } else { |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 724 | fw_path = ""; /* unknown device */ |
| 725 | } |
| 726 | |
| 727 | guc_fw->guc_dev = dev; |
| 728 | guc_fw->guc_fw_path = fw_path; |
| 729 | guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_NONE; |
| 730 | guc_fw->guc_fw_load_status = GUC_FIRMWARE_NONE; |
| 731 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 732 | /* Early (and silent) return if GuC loading is disabled */ |
| 733 | if (!i915.enable_guc_loading) |
| 734 | return; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 735 | if (fw_path == NULL) |
| 736 | return; |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 737 | if (*fw_path == '\0') |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 738 | return; |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 739 | |
| 740 | guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_PENDING; |
| 741 | DRM_DEBUG_DRIVER("GuC firmware pending, path %s\n", fw_path); |
| 742 | guc_fw_fetch(dev, guc_fw); |
| 743 | /* status must now be FAIL or SUCCESS */ |
| 744 | } |
| 745 | |
| 746 | /** |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 747 | * intel_guc_fini() - clean up all allocated resources |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 748 | * @dev: drm device |
| 749 | */ |
Dave Gordon | f09d675 | 2016-05-13 15:36:29 +0100 | [diff] [blame] | 750 | void intel_guc_fini(struct drm_device *dev) |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 751 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 752 | struct drm_i915_private *dev_priv = to_i915(dev); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 753 | struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; |
| 754 | |
Alex Dai | a9d8ada | 2016-01-13 11:01:50 -0800 | [diff] [blame] | 755 | mutex_lock(&dev->struct_mutex); |
Dave Gordon | 4df001d | 2015-08-12 15:43:42 +0100 | [diff] [blame] | 756 | direct_interrupts_to_host(dev_priv); |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 757 | i915_guc_submission_disable(dev_priv); |
| 758 | i915_guc_submission_fini(dev_priv); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 759 | |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 760 | if (guc_fw->guc_fw_obj) |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 761 | i915_gem_object_put(guc_fw->guc_fw_obj); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 762 | guc_fw->guc_fw_obj = NULL; |
Daniel Stone | bf248ca | 2015-11-03 21:42:31 +0000 | [diff] [blame] | 763 | mutex_unlock(&dev->struct_mutex); |
Alex Dai | 33a732f | 2015-08-12 15:43:36 +0100 | [diff] [blame] | 764 | |
| 765 | guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_NONE; |
| 766 | } |