Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2014-2017 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 "intel_guc.h" |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame^] | 26 | #include "intel_guc_ads.h" |
Sagar Arun Kamble | a269574 | 2017-11-16 19:02:41 +0530 | [diff] [blame] | 27 | #include "intel_guc_submission.h" |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 28 | #include "i915_drv.h" |
| 29 | |
| 30 | static void gen8_guc_raise_irq(struct intel_guc *guc) |
| 31 | { |
| 32 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 33 | |
| 34 | I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER); |
| 35 | } |
| 36 | |
| 37 | static inline i915_reg_t guc_send_reg(struct intel_guc *guc, u32 i) |
| 38 | { |
| 39 | GEM_BUG_ON(!guc->send_regs.base); |
| 40 | GEM_BUG_ON(!guc->send_regs.count); |
| 41 | GEM_BUG_ON(i >= guc->send_regs.count); |
| 42 | |
| 43 | return _MMIO(guc->send_regs.base + 4 * i); |
| 44 | } |
| 45 | |
| 46 | void intel_guc_init_send_regs(struct intel_guc *guc) |
| 47 | { |
| 48 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 49 | enum forcewake_domains fw_domains = 0; |
| 50 | unsigned int i; |
| 51 | |
| 52 | guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0)); |
| 53 | guc->send_regs.count = SOFT_SCRATCH_COUNT - 1; |
| 54 | |
| 55 | for (i = 0; i < guc->send_regs.count; i++) { |
| 56 | fw_domains |= intel_uncore_forcewake_for_reg(dev_priv, |
| 57 | guc_send_reg(guc, i), |
| 58 | FW_REG_READ | FW_REG_WRITE); |
| 59 | } |
| 60 | guc->send_regs.fw_domains = fw_domains; |
| 61 | } |
| 62 | |
| 63 | void intel_guc_init_early(struct intel_guc *guc) |
| 64 | { |
Michal Wajdeczko | 0dd940c | 2017-12-06 13:53:11 +0000 | [diff] [blame] | 65 | intel_guc_fw_init_early(guc); |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 66 | intel_guc_ct_init_early(&guc->ct); |
| 67 | |
| 68 | mutex_init(&guc->send_mutex); |
| 69 | guc->send = intel_guc_send_nop; |
| 70 | guc->notify = gen8_guc_raise_irq; |
| 71 | } |
| 72 | |
Michał Winiarski | 3176ff4 | 2017-12-13 23:13:47 +0100 | [diff] [blame] | 73 | int intel_guc_init_wq(struct intel_guc *guc) |
| 74 | { |
| 75 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 76 | |
| 77 | /* |
| 78 | * GuC log buffer flush work item has to do register access to |
| 79 | * send the ack to GuC and this work item, if not synced before |
| 80 | * suspend, can potentially get executed after the GFX device is |
| 81 | * suspended. |
| 82 | * By marking the WQ as freezable, we don't have to bother about |
| 83 | * flushing of this work item from the suspend hooks, the pending |
| 84 | * work item if any will be either executed before the suspend |
| 85 | * or scheduled later on resume. This way the handling of work |
| 86 | * item can be kept same between system suspend & rpm suspend. |
| 87 | */ |
| 88 | guc->log.runtime.flush_wq = alloc_ordered_workqueue("i915-guc_log", |
| 89 | WQ_HIGHPRI | WQ_FREEZABLE); |
| 90 | if (!guc->log.runtime.flush_wq) |
| 91 | return -ENOMEM; |
| 92 | |
| 93 | /* |
| 94 | * Even though both sending GuC action, and adding a new workitem to |
| 95 | * GuC workqueue are serialized (each with its own locking), since |
| 96 | * we're using mutliple engines, it's possible that we're going to |
| 97 | * issue a preempt request with two (or more - each for different |
| 98 | * engine) workitems in GuC queue. In this situation, GuC may submit |
| 99 | * all of them, which will make us very confused. |
| 100 | * Our preemption contexts may even already be complete - before we |
| 101 | * even had the chance to sent the preempt action to GuC!. Rather |
| 102 | * than introducing yet another lock, we can just use ordered workqueue |
| 103 | * to make sure we're always sending a single preemption request with a |
| 104 | * single workitem. |
| 105 | */ |
| 106 | if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) && |
| 107 | USES_GUC_SUBMISSION(dev_priv)) { |
| 108 | guc->preempt_wq = alloc_ordered_workqueue("i915-guc_preempt", |
| 109 | WQ_HIGHPRI); |
| 110 | if (!guc->preempt_wq) { |
| 111 | destroy_workqueue(guc->log.runtime.flush_wq); |
| 112 | return -ENOMEM; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | void intel_guc_fini_wq(struct intel_guc *guc) |
| 120 | { |
| 121 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 122 | |
| 123 | if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) && |
| 124 | USES_GUC_SUBMISSION(dev_priv)) |
| 125 | destroy_workqueue(guc->preempt_wq); |
| 126 | |
| 127 | destroy_workqueue(guc->log.runtime.flush_wq); |
| 128 | } |
| 129 | |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 130 | static int guc_shared_data_create(struct intel_guc *guc) |
| 131 | { |
| 132 | struct i915_vma *vma; |
| 133 | void *vaddr; |
| 134 | |
| 135 | vma = intel_guc_allocate_vma(guc, PAGE_SIZE); |
| 136 | if (IS_ERR(vma)) |
| 137 | return PTR_ERR(vma); |
| 138 | |
| 139 | vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB); |
| 140 | if (IS_ERR(vaddr)) { |
| 141 | i915_vma_unpin_and_release(&vma); |
| 142 | return PTR_ERR(vaddr); |
| 143 | } |
| 144 | |
| 145 | guc->shared_data = vma; |
| 146 | guc->shared_data_vaddr = vaddr; |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static void guc_shared_data_destroy(struct intel_guc *guc) |
| 152 | { |
| 153 | i915_gem_object_unpin_map(guc->shared_data->obj); |
| 154 | i915_vma_unpin_and_release(&guc->shared_data); |
| 155 | } |
| 156 | |
| 157 | int intel_guc_init(struct intel_guc *guc) |
| 158 | { |
| 159 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 160 | int ret; |
| 161 | |
| 162 | ret = guc_shared_data_create(guc); |
| 163 | if (ret) |
| 164 | return ret; |
| 165 | GEM_BUG_ON(!guc->shared_data); |
| 166 | |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame^] | 167 | ret = intel_guc_log_create(guc); |
| 168 | if (ret) |
| 169 | goto err_shared; |
| 170 | |
| 171 | ret = intel_guc_ads_create(guc); |
| 172 | if (ret) |
| 173 | goto err_log; |
| 174 | GEM_BUG_ON(!guc->ads_vma); |
| 175 | |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 176 | /* We need to notify the guc whenever we change the GGTT */ |
| 177 | i915_ggtt_enable_guc(dev_priv); |
| 178 | |
| 179 | return 0; |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame^] | 180 | |
| 181 | err_log: |
| 182 | intel_guc_log_destroy(guc); |
| 183 | err_shared: |
| 184 | guc_shared_data_destroy(guc); |
| 185 | return ret; |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void intel_guc_fini(struct intel_guc *guc) |
| 189 | { |
| 190 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 191 | |
| 192 | i915_ggtt_disable_guc(dev_priv); |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame^] | 193 | intel_guc_ads_destroy(guc); |
| 194 | intel_guc_log_destroy(guc); |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 195 | guc_shared_data_destroy(guc); |
| 196 | } |
| 197 | |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 198 | static u32 get_gt_type(struct drm_i915_private *dev_priv) |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 199 | { |
| 200 | /* XXX: GT type based on PCI device ID? field seems unused by fw */ |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static u32 get_core_family(struct drm_i915_private *dev_priv) |
| 205 | { |
| 206 | u32 gen = INTEL_GEN(dev_priv); |
| 207 | |
| 208 | switch (gen) { |
| 209 | case 9: |
| 210 | return GUC_CORE_FAMILY_GEN9; |
| 211 | |
| 212 | default: |
| 213 | MISSING_CASE(gen); |
| 214 | return GUC_CORE_FAMILY_UNKNOWN; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * Initialise the GuC parameter block before starting the firmware |
| 220 | * transfer. These parameters are read by the firmware on startup |
| 221 | * and cannot be changed thereafter. |
| 222 | */ |
| 223 | void intel_guc_init_params(struct intel_guc *guc) |
| 224 | { |
| 225 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 226 | u32 params[GUC_CTL_MAX_DWORDS]; |
| 227 | int i; |
| 228 | |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 229 | memset(params, 0, sizeof(params)); |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 230 | |
| 231 | params[GUC_CTL_DEVICE_INFO] |= |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 232 | (get_gt_type(dev_priv) << GUC_CTL_GT_TYPE_SHIFT) | |
| 233 | (get_core_family(dev_priv) << GUC_CTL_CORE_FAMILY_SHIFT); |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 234 | |
| 235 | /* |
| 236 | * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one |
| 237 | * second. This ARAR is calculated by: |
| 238 | * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10 |
| 239 | */ |
| 240 | params[GUC_CTL_ARAT_HIGH] = 0; |
| 241 | params[GUC_CTL_ARAT_LOW] = 100000000; |
| 242 | |
| 243 | params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER; |
| 244 | |
| 245 | params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER | |
| 246 | GUC_CTL_VCS2_ENABLED; |
| 247 | |
| 248 | params[GUC_CTL_LOG_PARAMS] = guc->log.flags; |
| 249 | |
| 250 | if (i915_modparams.guc_log_level >= 0) { |
| 251 | params[GUC_CTL_DEBUG] = |
| 252 | i915_modparams.guc_log_level << GUC_LOG_VERBOSITY_SHIFT; |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 253 | } else { |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 254 | params[GUC_CTL_DEBUG] = GUC_LOG_DISABLED; |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 255 | } |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 256 | |
| 257 | /* If GuC submission is enabled, set up additional parameters here */ |
Michal Wajdeczko | 93ffbe8 | 2017-12-06 13:53:12 +0000 | [diff] [blame] | 258 | if (USES_GUC_SUBMISSION(dev_priv)) { |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 259 | u32 ads = guc_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT; |
| 260 | u32 pgs = guc_ggtt_offset(dev_priv->guc.stage_desc_pool); |
| 261 | u32 ctx_in_16 = GUC_MAX_STAGE_DESCRIPTORS / 16; |
| 262 | |
| 263 | params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT; |
| 264 | params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED; |
| 265 | |
| 266 | pgs >>= PAGE_SHIFT; |
| 267 | params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) | |
| 268 | (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT); |
| 269 | |
| 270 | params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS; |
| 271 | |
| 272 | /* Unmask this bit to enable the GuC's internal scheduler */ |
| 273 | params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER; |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * All SOFT_SCRATCH registers are in FORCEWAKE_BLITTER domain and |
| 278 | * they are power context saved so it's ok to release forcewake |
| 279 | * when we are done here and take it again at xfer time. |
| 280 | */ |
| 281 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_BLITTER); |
| 282 | |
| 283 | I915_WRITE(SOFT_SCRATCH(0), 0); |
| 284 | |
| 285 | for (i = 0; i < GUC_CTL_MAX_DWORDS; i++) |
| 286 | I915_WRITE(SOFT_SCRATCH(1 + i), params[i]); |
| 287 | |
| 288 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_BLITTER); |
| 289 | } |
| 290 | |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 291 | int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len) |
| 292 | { |
| 293 | WARN(1, "Unexpected send: action=%#x\n", *action); |
| 294 | return -ENODEV; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * This function implements the MMIO based host to GuC interface. |
| 299 | */ |
| 300 | int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len) |
| 301 | { |
| 302 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 303 | u32 status; |
| 304 | int i; |
| 305 | int ret; |
| 306 | |
| 307 | GEM_BUG_ON(!len); |
| 308 | GEM_BUG_ON(len > guc->send_regs.count); |
| 309 | |
| 310 | /* If CT is available, we expect to use MMIO only during init/fini */ |
| 311 | GEM_BUG_ON(HAS_GUC_CT(dev_priv) && |
| 312 | *action != INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER && |
| 313 | *action != INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER); |
| 314 | |
| 315 | mutex_lock(&guc->send_mutex); |
| 316 | intel_uncore_forcewake_get(dev_priv, guc->send_regs.fw_domains); |
| 317 | |
| 318 | for (i = 0; i < len; i++) |
| 319 | I915_WRITE(guc_send_reg(guc, i), action[i]); |
| 320 | |
| 321 | POSTING_READ(guc_send_reg(guc, i - 1)); |
| 322 | |
| 323 | intel_guc_notify(guc); |
| 324 | |
| 325 | /* |
| 326 | * No GuC command should ever take longer than 10ms. |
| 327 | * Fast commands should still complete in 10us. |
| 328 | */ |
| 329 | ret = __intel_wait_for_register_fw(dev_priv, |
| 330 | guc_send_reg(guc, 0), |
| 331 | INTEL_GUC_RECV_MASK, |
| 332 | INTEL_GUC_RECV_MASK, |
| 333 | 10, 10, &status); |
| 334 | if (status != INTEL_GUC_STATUS_SUCCESS) { |
| 335 | /* |
| 336 | * Either the GuC explicitly returned an error (which |
| 337 | * we convert to -EIO here) or no response at all was |
| 338 | * received within the timeout limit (-ETIMEDOUT) |
| 339 | */ |
| 340 | if (ret != -ETIMEDOUT) |
| 341 | ret = -EIO; |
| 342 | |
| 343 | DRM_WARN("INTEL_GUC_SEND: Action 0x%X failed;" |
| 344 | " ret=%d status=0x%08X response=0x%08X\n", |
| 345 | action[0], ret, status, I915_READ(SOFT_SCRATCH(15))); |
| 346 | } |
| 347 | |
| 348 | intel_uncore_forcewake_put(dev_priv, guc->send_regs.fw_domains); |
| 349 | mutex_unlock(&guc->send_mutex); |
| 350 | |
| 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | int intel_guc_sample_forcewake(struct intel_guc *guc) |
| 355 | { |
| 356 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 357 | u32 action[2]; |
| 358 | |
| 359 | action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE; |
| 360 | /* WaRsDisableCoarsePowerGating:skl,bxt */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 361 | if (!HAS_RC6(dev_priv) || NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 362 | action[1] = 0; |
| 363 | else |
| 364 | /* bit 0 and 1 are for Render and Media domain separately */ |
| 365 | action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA; |
| 366 | |
| 367 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * intel_guc_auth_huc() - Send action to GuC to authenticate HuC ucode |
| 372 | * @guc: intel_guc structure |
| 373 | * @rsa_offset: rsa offset w.r.t ggtt base of huc vma |
| 374 | * |
| 375 | * Triggers a HuC firmware authentication request to the GuC via intel_guc_send |
| 376 | * INTEL_GUC_ACTION_AUTHENTICATE_HUC interface. This function is invoked by |
| 377 | * intel_huc_auth(). |
| 378 | * |
| 379 | * Return: non-zero code on error |
| 380 | */ |
| 381 | int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset) |
| 382 | { |
| 383 | u32 action[] = { |
| 384 | INTEL_GUC_ACTION_AUTHENTICATE_HUC, |
| 385 | rsa_offset |
| 386 | }; |
| 387 | |
| 388 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * intel_guc_suspend() - notify GuC entering suspend state |
| 393 | * @dev_priv: i915 device private |
| 394 | */ |
| 395 | int intel_guc_suspend(struct drm_i915_private *dev_priv) |
| 396 | { |
| 397 | struct intel_guc *guc = &dev_priv->guc; |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 398 | u32 data[3]; |
| 399 | |
| 400 | if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) |
| 401 | return 0; |
| 402 | |
| 403 | gen9_disable_guc_interrupts(dev_priv); |
| 404 | |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 405 | data[0] = INTEL_GUC_ACTION_ENTER_S_STATE; |
| 406 | /* any value greater than GUC_POWER_D0 */ |
| 407 | data[1] = GUC_POWER_D1; |
Michał Winiarski | b8e5eb9 | 2017-10-25 22:00:11 +0200 | [diff] [blame] | 408 | data[2] = guc_ggtt_offset(guc->shared_data); |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 409 | |
| 410 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
| 411 | } |
| 412 | |
| 413 | /** |
Michel Thierry | 6acbea8 | 2017-10-31 15:53:09 -0700 | [diff] [blame] | 414 | * intel_guc_reset_engine() - ask GuC to reset an engine |
| 415 | * @guc: intel_guc structure |
| 416 | * @engine: engine to be reset |
| 417 | */ |
| 418 | int intel_guc_reset_engine(struct intel_guc *guc, |
| 419 | struct intel_engine_cs *engine) |
| 420 | { |
| 421 | u32 data[7]; |
| 422 | |
| 423 | GEM_BUG_ON(!guc->execbuf_client); |
| 424 | |
| 425 | data[0] = INTEL_GUC_ACTION_REQUEST_ENGINE_RESET; |
| 426 | data[1] = engine->guc_id; |
| 427 | data[2] = 0; |
| 428 | data[3] = 0; |
| 429 | data[4] = 0; |
| 430 | data[5] = guc->execbuf_client->stage_id; |
| 431 | data[6] = guc_ggtt_offset(guc->shared_data); |
| 432 | |
| 433 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
| 434 | } |
| 435 | |
| 436 | /** |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 437 | * intel_guc_resume() - notify GuC resuming from suspend state |
| 438 | * @dev_priv: i915 device private |
| 439 | */ |
| 440 | int intel_guc_resume(struct drm_i915_private *dev_priv) |
| 441 | { |
| 442 | struct intel_guc *guc = &dev_priv->guc; |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 443 | u32 data[3]; |
| 444 | |
| 445 | if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) |
| 446 | return 0; |
| 447 | |
| 448 | if (i915_modparams.guc_log_level >= 0) |
| 449 | gen9_enable_guc_interrupts(dev_priv); |
| 450 | |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 451 | data[0] = INTEL_GUC_ACTION_EXIT_S_STATE; |
| 452 | data[1] = GUC_POWER_D0; |
Michał Winiarski | b8e5eb9 | 2017-10-25 22:00:11 +0200 | [diff] [blame] | 453 | data[2] = guc_ggtt_offset(guc->shared_data); |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 454 | |
| 455 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage |
| 460 | * @guc: the guc |
| 461 | * @size: size of area to allocate (both virtual space and memory) |
| 462 | * |
| 463 | * This is a wrapper to create an object for use with the GuC. In order to |
| 464 | * use it inside the GuC, an object needs to be pinned lifetime, so we allocate |
| 465 | * both some backing storage and a range inside the Global GTT. We must pin |
| 466 | * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that |
| 467 | * range is reserved inside GuC. |
| 468 | * |
| 469 | * Return: A i915_vma if successful, otherwise an ERR_PTR. |
| 470 | */ |
| 471 | struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size) |
| 472 | { |
| 473 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 474 | struct drm_i915_gem_object *obj; |
| 475 | struct i915_vma *vma; |
| 476 | int ret; |
| 477 | |
| 478 | obj = i915_gem_object_create(dev_priv, size); |
| 479 | if (IS_ERR(obj)) |
| 480 | return ERR_CAST(obj); |
| 481 | |
| 482 | vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL); |
| 483 | if (IS_ERR(vma)) |
| 484 | goto err; |
| 485 | |
| 486 | ret = i915_vma_pin(vma, 0, PAGE_SIZE, |
| 487 | PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP); |
| 488 | if (ret) { |
| 489 | vma = ERR_PTR(ret); |
| 490 | goto err; |
| 491 | } |
| 492 | |
| 493 | return vma; |
| 494 | |
| 495 | err: |
| 496 | i915_gem_object_put(obj); |
| 497 | return vma; |
| 498 | } |
Michal Wajdeczko | 46f1e8b | 2017-10-16 14:47:10 +0000 | [diff] [blame] | 499 | |
| 500 | u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv) |
| 501 | { |
| 502 | u32 wopcm_size = GUC_WOPCM_TOP; |
| 503 | |
| 504 | /* On BXT, the top of WOPCM is reserved for RC6 context */ |
| 505 | if (IS_GEN9_LP(dev_priv)) |
| 506 | wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED; |
| 507 | |
| 508 | return wopcm_size; |
| 509 | } |