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); |
Michal Wajdeczko | 56b9a8b | 2018-03-14 14:45:39 +0000 | [diff] [blame] | 67 | intel_guc_log_init_early(&guc->log); |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 68 | |
| 69 | mutex_init(&guc->send_mutex); |
Michał Winiarski | eacd839 | 2018-03-19 10:53:36 +0100 | [diff] [blame] | 70 | spin_lock_init(&guc->irq_lock); |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 71 | guc->send = intel_guc_send_nop; |
| 72 | guc->notify = gen8_guc_raise_irq; |
| 73 | } |
| 74 | |
Michał Winiarski | 3176ff4 | 2017-12-13 23:13:47 +0100 | [diff] [blame] | 75 | int intel_guc_init_wq(struct intel_guc *guc) |
| 76 | { |
| 77 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 78 | |
| 79 | /* |
| 80 | * GuC log buffer flush work item has to do register access to |
| 81 | * send the ack to GuC and this work item, if not synced before |
| 82 | * suspend, can potentially get executed after the GFX device is |
| 83 | * suspended. |
| 84 | * By marking the WQ as freezable, we don't have to bother about |
| 85 | * flushing of this work item from the suspend hooks, the pending |
| 86 | * work item if any will be either executed before the suspend |
| 87 | * or scheduled later on resume. This way the handling of work |
| 88 | * item can be kept same between system suspend & rpm suspend. |
| 89 | */ |
Michał Winiarski | 6a96be2 | 2018-03-19 10:53:42 +0100 | [diff] [blame] | 90 | guc->log.relay.flush_wq = |
| 91 | alloc_ordered_workqueue("i915-guc_log", |
| 92 | WQ_HIGHPRI | WQ_FREEZABLE); |
| 93 | if (!guc->log.relay.flush_wq) { |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 94 | DRM_ERROR("Couldn't allocate workqueue for GuC log\n"); |
Michał Winiarski | 3176ff4 | 2017-12-13 23:13:47 +0100 | [diff] [blame] | 95 | return -ENOMEM; |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 96 | } |
Michał Winiarski | 3176ff4 | 2017-12-13 23:13:47 +0100 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Even though both sending GuC action, and adding a new workitem to |
| 100 | * GuC workqueue are serialized (each with its own locking), since |
| 101 | * we're using mutliple engines, it's possible that we're going to |
| 102 | * issue a preempt request with two (or more - each for different |
| 103 | * engine) workitems in GuC queue. In this situation, GuC may submit |
| 104 | * all of them, which will make us very confused. |
| 105 | * Our preemption contexts may even already be complete - before we |
| 106 | * even had the chance to sent the preempt action to GuC!. Rather |
| 107 | * than introducing yet another lock, we can just use ordered workqueue |
| 108 | * to make sure we're always sending a single preemption request with a |
| 109 | * single workitem. |
| 110 | */ |
| 111 | if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) && |
| 112 | USES_GUC_SUBMISSION(dev_priv)) { |
| 113 | guc->preempt_wq = alloc_ordered_workqueue("i915-guc_preempt", |
| 114 | WQ_HIGHPRI); |
| 115 | if (!guc->preempt_wq) { |
Michał Winiarski | 6a96be2 | 2018-03-19 10:53:42 +0100 | [diff] [blame] | 116 | destroy_workqueue(guc->log.relay.flush_wq); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 117 | DRM_ERROR("Couldn't allocate workqueue for GuC " |
| 118 | "preemption\n"); |
Michał Winiarski | 3176ff4 | 2017-12-13 23:13:47 +0100 | [diff] [blame] | 119 | return -ENOMEM; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | void intel_guc_fini_wq(struct intel_guc *guc) |
| 127 | { |
| 128 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 129 | |
| 130 | if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) && |
| 131 | USES_GUC_SUBMISSION(dev_priv)) |
| 132 | destroy_workqueue(guc->preempt_wq); |
| 133 | |
Michał Winiarski | 6a96be2 | 2018-03-19 10:53:42 +0100 | [diff] [blame] | 134 | destroy_workqueue(guc->log.relay.flush_wq); |
Michał Winiarski | 3176ff4 | 2017-12-13 23:13:47 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 137 | static int guc_shared_data_create(struct intel_guc *guc) |
| 138 | { |
| 139 | struct i915_vma *vma; |
| 140 | void *vaddr; |
| 141 | |
| 142 | vma = intel_guc_allocate_vma(guc, PAGE_SIZE); |
| 143 | if (IS_ERR(vma)) |
| 144 | return PTR_ERR(vma); |
| 145 | |
| 146 | vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB); |
| 147 | if (IS_ERR(vaddr)) { |
| 148 | i915_vma_unpin_and_release(&vma); |
| 149 | return PTR_ERR(vaddr); |
| 150 | } |
| 151 | |
| 152 | guc->shared_data = vma; |
| 153 | guc->shared_data_vaddr = vaddr; |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static void guc_shared_data_destroy(struct intel_guc *guc) |
| 159 | { |
| 160 | i915_gem_object_unpin_map(guc->shared_data->obj); |
| 161 | i915_vma_unpin_and_release(&guc->shared_data); |
| 162 | } |
| 163 | |
| 164 | int intel_guc_init(struct intel_guc *guc) |
| 165 | { |
| 166 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 167 | int ret; |
| 168 | |
| 169 | ret = guc_shared_data_create(guc); |
| 170 | if (ret) |
| 171 | return ret; |
| 172 | GEM_BUG_ON(!guc->shared_data); |
| 173 | |
Michal Wajdeczko | 56b9a8b | 2018-03-14 14:45:39 +0000 | [diff] [blame] | 174 | ret = intel_guc_log_create(&guc->log); |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame] | 175 | if (ret) |
| 176 | goto err_shared; |
| 177 | |
| 178 | ret = intel_guc_ads_create(guc); |
| 179 | if (ret) |
| 180 | goto err_log; |
| 181 | GEM_BUG_ON(!guc->ads_vma); |
| 182 | |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 183 | /* We need to notify the guc whenever we change the GGTT */ |
| 184 | i915_ggtt_enable_guc(dev_priv); |
| 185 | |
| 186 | return 0; |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame] | 187 | |
| 188 | err_log: |
Michal Wajdeczko | 56b9a8b | 2018-03-14 14:45:39 +0000 | [diff] [blame] | 189 | intel_guc_log_destroy(&guc->log); |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame] | 190 | err_shared: |
| 191 | guc_shared_data_destroy(guc); |
| 192 | return ret; |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void intel_guc_fini(struct intel_guc *guc) |
| 196 | { |
| 197 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 198 | |
| 199 | i915_ggtt_disable_guc(dev_priv); |
Sujaritha Sundaresan | c24f0c1 | 2018-01-02 13:20:24 -0800 | [diff] [blame] | 200 | intel_guc_ads_destroy(guc); |
Michal Wajdeczko | 56b9a8b | 2018-03-14 14:45:39 +0000 | [diff] [blame] | 201 | intel_guc_log_destroy(&guc->log); |
Michał Winiarski | 1bbbca0 | 2017-12-13 23:13:46 +0100 | [diff] [blame] | 202 | guc_shared_data_destroy(guc); |
| 203 | } |
| 204 | |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 205 | static u32 get_gt_type(struct drm_i915_private *dev_priv) |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 206 | { |
| 207 | /* XXX: GT type based on PCI device ID? field seems unused by fw */ |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static u32 get_core_family(struct drm_i915_private *dev_priv) |
| 212 | { |
| 213 | u32 gen = INTEL_GEN(dev_priv); |
| 214 | |
| 215 | switch (gen) { |
| 216 | case 9: |
| 217 | return GUC_CORE_FAMILY_GEN9; |
| 218 | |
| 219 | default: |
| 220 | MISSING_CASE(gen); |
| 221 | return GUC_CORE_FAMILY_UNKNOWN; |
| 222 | } |
| 223 | } |
| 224 | |
Michał Winiarski | cb5d64e | 2018-03-19 10:53:45 +0100 | [diff] [blame] | 225 | static u32 get_log_control_flags(void) |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 226 | { |
Michał Winiarski | cb5d64e | 2018-03-19 10:53:45 +0100 | [diff] [blame] | 227 | u32 level = i915_modparams.guc_log_level; |
| 228 | u32 flags = 0; |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 229 | |
Michał Winiarski | cb5d64e | 2018-03-19 10:53:45 +0100 | [diff] [blame] | 230 | GEM_BUG_ON(level < 0); |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 231 | |
Michał Winiarski | 03380d1 | 2018-03-20 12:55:17 +0100 | [diff] [blame] | 232 | if (!GUC_LOG_LEVEL_IS_ENABLED(level)) |
Michał Winiarski | cb5d64e | 2018-03-19 10:53:45 +0100 | [diff] [blame] | 233 | flags |= GUC_LOG_DEFAULT_DISABLED; |
| 234 | |
Michał Winiarski | 03380d1 | 2018-03-20 12:55:17 +0100 | [diff] [blame] | 235 | if (!GUC_LOG_LEVEL_IS_VERBOSE(level)) |
Michał Winiarski | cb5d64e | 2018-03-19 10:53:45 +0100 | [diff] [blame] | 236 | flags |= GUC_LOG_DISABLED; |
| 237 | else |
| 238 | flags |= GUC_LOG_LEVEL_TO_VERBOSITY(level) << |
| 239 | GUC_LOG_VERBOSITY_SHIFT; |
| 240 | |
| 241 | return flags; |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 244 | /* |
| 245 | * Initialise the GuC parameter block before starting the firmware |
| 246 | * transfer. These parameters are read by the firmware on startup |
| 247 | * and cannot be changed thereafter. |
| 248 | */ |
| 249 | void intel_guc_init_params(struct intel_guc *guc) |
| 250 | { |
| 251 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 252 | u32 params[GUC_CTL_MAX_DWORDS]; |
| 253 | int i; |
| 254 | |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 255 | memset(params, 0, sizeof(params)); |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 256 | |
| 257 | params[GUC_CTL_DEVICE_INFO] |= |
Michal Wajdeczko | fdc6d73 | 2017-10-16 14:47:12 +0000 | [diff] [blame] | 258 | (get_gt_type(dev_priv) << GUC_CTL_GT_TYPE_SHIFT) | |
| 259 | (get_core_family(dev_priv) << GUC_CTL_CORE_FAMILY_SHIFT); |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one |
| 263 | * second. This ARAR is calculated by: |
| 264 | * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10 |
| 265 | */ |
| 266 | params[GUC_CTL_ARAT_HIGH] = 0; |
| 267 | params[GUC_CTL_ARAT_LOW] = 100000000; |
| 268 | |
| 269 | params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER; |
| 270 | |
| 271 | params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER | |
| 272 | GUC_CTL_VCS2_ENABLED; |
| 273 | |
| 274 | params[GUC_CTL_LOG_PARAMS] = guc->log.flags; |
| 275 | |
Michał Winiarski | cb5d64e | 2018-03-19 10:53:45 +0100 | [diff] [blame] | 276 | params[GUC_CTL_DEBUG] = get_log_control_flags(); |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 277 | |
| 278 | /* If GuC submission is enabled, set up additional parameters here */ |
Michal Wajdeczko | 93ffbe8 | 2017-12-06 13:53:12 +0000 | [diff] [blame] | 279 | if (USES_GUC_SUBMISSION(dev_priv)) { |
Jackie Li | 3c009e3 | 2018-03-13 17:32:49 -0700 | [diff] [blame] | 280 | u32 ads = intel_guc_ggtt_offset(guc, |
| 281 | guc->ads_vma) >> PAGE_SHIFT; |
| 282 | u32 pgs = intel_guc_ggtt_offset(guc, guc->stage_desc_pool); |
Michal Wajdeczko | 5d53be4 | 2017-10-16 14:47:11 +0000 | [diff] [blame] | 283 | u32 ctx_in_16 = GUC_MAX_STAGE_DESCRIPTORS / 16; |
| 284 | |
| 285 | params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT; |
| 286 | params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED; |
| 287 | |
| 288 | pgs >>= PAGE_SHIFT; |
| 289 | params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) | |
| 290 | (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT); |
| 291 | |
| 292 | params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS; |
| 293 | |
| 294 | /* Unmask this bit to enable the GuC's internal scheduler */ |
| 295 | params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * All SOFT_SCRATCH registers are in FORCEWAKE_BLITTER domain and |
| 300 | * they are power context saved so it's ok to release forcewake |
| 301 | * when we are done here and take it again at xfer time. |
| 302 | */ |
| 303 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_BLITTER); |
| 304 | |
| 305 | I915_WRITE(SOFT_SCRATCH(0), 0); |
| 306 | |
| 307 | for (i = 0; i < GUC_CTL_MAX_DWORDS; i++) |
| 308 | I915_WRITE(SOFT_SCRATCH(1 + i), params[i]); |
| 309 | |
| 310 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_BLITTER); |
| 311 | } |
| 312 | |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 313 | int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len) |
| 314 | { |
| 315 | WARN(1, "Unexpected send: action=%#x\n", *action); |
| 316 | return -ENODEV; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * This function implements the MMIO based host to GuC interface. |
| 321 | */ |
| 322 | int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len) |
| 323 | { |
| 324 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 325 | u32 status; |
| 326 | int i; |
| 327 | int ret; |
| 328 | |
| 329 | GEM_BUG_ON(!len); |
| 330 | GEM_BUG_ON(len > guc->send_regs.count); |
| 331 | |
| 332 | /* If CT is available, we expect to use MMIO only during init/fini */ |
| 333 | GEM_BUG_ON(HAS_GUC_CT(dev_priv) && |
| 334 | *action != INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER && |
| 335 | *action != INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER); |
| 336 | |
| 337 | mutex_lock(&guc->send_mutex); |
| 338 | intel_uncore_forcewake_get(dev_priv, guc->send_regs.fw_domains); |
| 339 | |
| 340 | for (i = 0; i < len; i++) |
| 341 | I915_WRITE(guc_send_reg(guc, i), action[i]); |
| 342 | |
| 343 | POSTING_READ(guc_send_reg(guc, i - 1)); |
| 344 | |
| 345 | intel_guc_notify(guc); |
| 346 | |
| 347 | /* |
| 348 | * No GuC command should ever take longer than 10ms. |
| 349 | * Fast commands should still complete in 10us. |
| 350 | */ |
| 351 | ret = __intel_wait_for_register_fw(dev_priv, |
| 352 | guc_send_reg(guc, 0), |
| 353 | INTEL_GUC_RECV_MASK, |
| 354 | INTEL_GUC_RECV_MASK, |
| 355 | 10, 10, &status); |
| 356 | if (status != INTEL_GUC_STATUS_SUCCESS) { |
| 357 | /* |
| 358 | * Either the GuC explicitly returned an error (which |
| 359 | * we convert to -EIO here) or no response at all was |
| 360 | * received within the timeout limit (-ETIMEDOUT) |
| 361 | */ |
| 362 | if (ret != -ETIMEDOUT) |
| 363 | ret = -EIO; |
| 364 | |
Michał Winiarski | feb06c1 | 2018-03-19 10:53:47 +0100 | [diff] [blame] | 365 | DRM_DEBUG_DRIVER("INTEL_GUC_SEND: Action 0x%X failed;" |
| 366 | " ret=%d status=0x%08X response=0x%08X\n", |
| 367 | action[0], ret, status, |
| 368 | I915_READ(SOFT_SCRATCH(15))); |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | intel_uncore_forcewake_put(dev_priv, guc->send_regs.fw_domains); |
| 372 | mutex_unlock(&guc->send_mutex); |
| 373 | |
| 374 | return ret; |
| 375 | } |
| 376 | |
Michal Wajdeczko | 93bf809 | 2018-03-08 16:46:55 +0100 | [diff] [blame] | 377 | void intel_guc_to_host_event_handler(struct intel_guc *guc) |
| 378 | { |
| 379 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Michał Winiarski | eacd839 | 2018-03-19 10:53:36 +0100 | [diff] [blame] | 380 | u32 msg, val; |
Michal Wajdeczko | 93bf809 | 2018-03-08 16:46:55 +0100 | [diff] [blame] | 381 | |
| 382 | /* |
| 383 | * Sample the log buffer flush related bits & clear them out now |
| 384 | * itself from the message identity register to minimize the |
| 385 | * probability of losing a flush interrupt, when there are back |
| 386 | * to back flush interrupts. |
| 387 | * There can be a new flush interrupt, for different log buffer |
| 388 | * type (like for ISR), whilst Host is handling one (for DPC). |
| 389 | * Since same bit is used in message register for ISR & DPC, it |
| 390 | * could happen that GuC sets the bit for 2nd interrupt but Host |
| 391 | * clears out the bit on handling the 1st interrupt. |
| 392 | */ |
Michał Winiarski | eacd839 | 2018-03-19 10:53:36 +0100 | [diff] [blame] | 393 | spin_lock(&guc->irq_lock); |
| 394 | val = I915_READ(SOFT_SCRATCH(15)); |
| 395 | msg = val & guc->msg_enabled_mask; |
| 396 | I915_WRITE(SOFT_SCRATCH(15), val & ~msg); |
| 397 | spin_unlock(&guc->irq_lock); |
Michal Wajdeczko | 93bf809 | 2018-03-08 16:46:55 +0100 | [diff] [blame] | 398 | |
Michał Winiarski | eacd839 | 2018-03-19 10:53:36 +0100 | [diff] [blame] | 399 | if (msg & (INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER | |
Michał Winiarski | 5e24e4a | 2018-03-19 10:53:44 +0100 | [diff] [blame] | 400 | INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED)) |
Michal Wajdeczko | e9c7e65 | 2018-03-19 12:50:49 +0000 | [diff] [blame^] | 401 | intel_guc_log_handle_flush_event(&guc->log); |
Michal Wajdeczko | 93bf809 | 2018-03-08 16:46:55 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 404 | int intel_guc_sample_forcewake(struct intel_guc *guc) |
| 405 | { |
| 406 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 407 | u32 action[2]; |
| 408 | |
| 409 | action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE; |
Rodrigo Vivi | d66047e4 | 2018-02-22 12:05:35 -0800 | [diff] [blame] | 410 | /* WaRsDisableCoarsePowerGating:skl,cnl */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 411 | if (!HAS_RC6(dev_priv) || NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 412 | action[1] = 0; |
| 413 | else |
| 414 | /* bit 0 and 1 are for Render and Media domain separately */ |
| 415 | action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA; |
| 416 | |
| 417 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * intel_guc_auth_huc() - Send action to GuC to authenticate HuC ucode |
| 422 | * @guc: intel_guc structure |
| 423 | * @rsa_offset: rsa offset w.r.t ggtt base of huc vma |
| 424 | * |
| 425 | * Triggers a HuC firmware authentication request to the GuC via intel_guc_send |
| 426 | * INTEL_GUC_ACTION_AUTHENTICATE_HUC interface. This function is invoked by |
| 427 | * intel_huc_auth(). |
| 428 | * |
| 429 | * Return: non-zero code on error |
| 430 | */ |
| 431 | int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset) |
| 432 | { |
| 433 | u32 action[] = { |
| 434 | INTEL_GUC_ACTION_AUTHENTICATE_HUC, |
| 435 | rsa_offset |
| 436 | }; |
| 437 | |
| 438 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * intel_guc_suspend() - notify GuC entering suspend state |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 443 | * @guc: the guc |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 444 | */ |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 445 | int intel_guc_suspend(struct intel_guc *guc) |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 446 | { |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 447 | u32 data[] = { |
| 448 | INTEL_GUC_ACTION_ENTER_S_STATE, |
| 449 | GUC_POWER_D1, /* any value greater than GUC_POWER_D0 */ |
Jackie Li | 3c009e3 | 2018-03-13 17:32:49 -0700 | [diff] [blame] | 450 | intel_guc_ggtt_offset(guc, guc->shared_data) |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 451 | }; |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 452 | |
| 453 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
| 454 | } |
| 455 | |
| 456 | /** |
Michel Thierry | 6acbea8 | 2017-10-31 15:53:09 -0700 | [diff] [blame] | 457 | * intel_guc_reset_engine() - ask GuC to reset an engine |
| 458 | * @guc: intel_guc structure |
| 459 | * @engine: engine to be reset |
| 460 | */ |
| 461 | int intel_guc_reset_engine(struct intel_guc *guc, |
| 462 | struct intel_engine_cs *engine) |
| 463 | { |
| 464 | u32 data[7]; |
| 465 | |
| 466 | GEM_BUG_ON(!guc->execbuf_client); |
| 467 | |
| 468 | data[0] = INTEL_GUC_ACTION_REQUEST_ENGINE_RESET; |
| 469 | data[1] = engine->guc_id; |
| 470 | data[2] = 0; |
| 471 | data[3] = 0; |
| 472 | data[4] = 0; |
| 473 | data[5] = guc->execbuf_client->stage_id; |
Jackie Li | 3c009e3 | 2018-03-13 17:32:49 -0700 | [diff] [blame] | 474 | data[6] = intel_guc_ggtt_offset(guc, guc->shared_data); |
Michel Thierry | 6acbea8 | 2017-10-31 15:53:09 -0700 | [diff] [blame] | 475 | |
| 476 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
| 477 | } |
| 478 | |
| 479 | /** |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 480 | * intel_guc_resume() - notify GuC resuming from suspend state |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 481 | * @guc: the guc |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 482 | */ |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 483 | int intel_guc_resume(struct intel_guc *guc) |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 484 | { |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 485 | u32 data[] = { |
| 486 | INTEL_GUC_ACTION_EXIT_S_STATE, |
| 487 | GUC_POWER_D0, |
Jackie Li | 3c009e3 | 2018-03-13 17:32:49 -0700 | [diff] [blame] | 488 | intel_guc_ggtt_offset(guc, guc->shared_data) |
Michal Wajdeczko | 7cfca4a | 2018-03-02 11:15:49 +0000 | [diff] [blame] | 489 | }; |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 490 | |
| 491 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
| 492 | } |
| 493 | |
| 494 | /** |
Jackie Li | 6b0478f | 2018-03-13 17:32:50 -0700 | [diff] [blame] | 495 | * DOC: GuC Address Space |
| 496 | * |
| 497 | * The layout of GuC address space is shown as below: |
| 498 | * |
| 499 | * +==============> +====================+ <== GUC_GGTT_TOP |
| 500 | * ^ | | |
| 501 | * | | | |
| 502 | * | | DRAM | |
| 503 | * | | Memory | |
| 504 | * | | | |
| 505 | * GuC | | |
| 506 | * Address +========> +====================+ <== WOPCM Top |
| 507 | * Space ^ | HW contexts RSVD | |
| 508 | * | | | WOPCM | |
| 509 | * | | +==> +--------------------+ <== GuC WOPCM Top |
| 510 | * | GuC ^ | | |
| 511 | * | GGTT | | | |
| 512 | * | Pin GuC | GuC | |
| 513 | * | Bias WOPCM | WOPCM | |
| 514 | * | | Size | | |
| 515 | * | | | | | |
| 516 | * v v v | | |
| 517 | * +=====+=====+==> +====================+ <== GuC WOPCM Base |
| 518 | * | Non-GuC WOPCM | |
| 519 | * | (HuC/Reserved) | |
| 520 | * +====================+ <== WOPCM Base |
| 521 | * |
| 522 | * The lower part [0, GuC ggtt_pin_bias) is mapped to WOPCM which consists of |
| 523 | * GuC WOPCM and WOPCM reserved for other usage (e.g.RC6 context). The value of |
| 524 | * the GuC ggtt_pin_bias is determined by the actually GuC WOPCM size which is |
| 525 | * set in GUC_WOPCM_SIZE register. |
| 526 | */ |
| 527 | |
| 528 | /** |
| 529 | * intel_guc_init_ggtt_pin_bias() - Initialize the GuC ggtt_pin_bias value. |
| 530 | * @guc: intel_guc structure. |
| 531 | * |
| 532 | * This function will calculate and initialize the ggtt_pin_bias value based on |
| 533 | * overall WOPCM size and GuC WOPCM size. |
| 534 | */ |
| 535 | void intel_guc_init_ggtt_pin_bias(struct intel_guc *guc) |
| 536 | { |
| 537 | struct drm_i915_private *i915 = guc_to_i915(guc); |
| 538 | |
| 539 | GEM_BUG_ON(!i915->wopcm.size); |
| 540 | GEM_BUG_ON(i915->wopcm.size < i915->wopcm.guc.base); |
| 541 | |
| 542 | guc->ggtt_pin_bias = i915->wopcm.size - i915->wopcm.guc.base; |
| 543 | } |
| 544 | |
| 545 | /** |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 546 | * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage |
| 547 | * @guc: the guc |
| 548 | * @size: size of area to allocate (both virtual space and memory) |
| 549 | * |
| 550 | * This is a wrapper to create an object for use with the GuC. In order to |
| 551 | * use it inside the GuC, an object needs to be pinned lifetime, so we allocate |
| 552 | * both some backing storage and a range inside the Global GTT. We must pin |
Jackie Li | 6b0478f | 2018-03-13 17:32:50 -0700 | [diff] [blame] | 553 | * it in the GGTT somewhere other than than [0, GUC ggtt_pin_bias) because that |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 554 | * range is reserved inside GuC. |
| 555 | * |
| 556 | * Return: A i915_vma if successful, otherwise an ERR_PTR. |
| 557 | */ |
| 558 | struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size) |
| 559 | { |
| 560 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 561 | struct drm_i915_gem_object *obj; |
| 562 | struct i915_vma *vma; |
| 563 | int ret; |
| 564 | |
| 565 | obj = i915_gem_object_create(dev_priv, size); |
| 566 | if (IS_ERR(obj)) |
| 567 | return ERR_CAST(obj); |
| 568 | |
| 569 | vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL); |
| 570 | if (IS_ERR(vma)) |
| 571 | goto err; |
| 572 | |
| 573 | ret = i915_vma_pin(vma, 0, PAGE_SIZE, |
Jackie Li | 6b0478f | 2018-03-13 17:32:50 -0700 | [diff] [blame] | 574 | PIN_GLOBAL | PIN_OFFSET_BIAS | guc->ggtt_pin_bias); |
Michal Wajdeczko | 9bf384c | 2017-10-04 18:13:41 +0000 | [diff] [blame] | 575 | if (ret) { |
| 576 | vma = ERR_PTR(ret); |
| 577 | goto err; |
| 578 | } |
| 579 | |
| 580 | return vma; |
| 581 | |
| 582 | err: |
| 583 | i915_gem_object_put(obj); |
| 584 | return vma; |
| 585 | } |