Alex Dai | bac427f | 2015-08-12 15:43:39 +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 | */ |
| 24 | #include <linux/firmware.h> |
| 25 | #include <linux/circ_buf.h> |
| 26 | #include "i915_drv.h" |
| 27 | #include "intel_guc.h" |
| 28 | |
| 29 | /** |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 30 | * DOC: GuC-based command submission |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 31 | * |
| 32 | * i915_guc_client: |
| 33 | * We use the term client to avoid confusion with contexts. A i915_guc_client is |
| 34 | * equivalent to GuC object guc_context_desc. This context descriptor is |
| 35 | * allocated from a pool of 1024 entries. Kernel driver will allocate doorbell |
| 36 | * and workqueue for it. Also the process descriptor (guc_process_desc), which |
| 37 | * is mapped to client space. So the client can write Work Item then ring the |
| 38 | * doorbell. |
| 39 | * |
| 40 | * To simplify the implementation, we allocate one gem object that contains all |
| 41 | * pages for doorbell, process descriptor and workqueue. |
| 42 | * |
| 43 | * The Scratch registers: |
| 44 | * There are 16 MMIO-based registers start from 0xC180. The kernel driver writes |
| 45 | * a value to the action register (SOFT_SCRATCH_0) along with any data. It then |
| 46 | * triggers an interrupt on the GuC via another register write (0xC4C8). |
| 47 | * Firmware writes a success/fail code back to the action register after |
| 48 | * processes the request. The kernel driver polls waiting for this update and |
| 49 | * then proceeds. |
| 50 | * See host2guc_action() |
| 51 | * |
| 52 | * Doorbells: |
| 53 | * Doorbells are interrupts to uKernel. A doorbell is a single cache line (QW) |
| 54 | * mapped into process space. |
| 55 | * |
| 56 | * Work Items: |
| 57 | * There are several types of work items that the host may place into a |
| 58 | * workqueue, each with its own requirements and limitations. Currently only |
| 59 | * WQ_TYPE_INORDER is needed to support legacy submission via GuC, which |
| 60 | * represents in-order queue. The kernel driver packs ring tail pointer and an |
| 61 | * ELSP context descriptor dword into Work Item. |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 62 | * See guc_wq_item_append() |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 63 | * |
| 64 | */ |
| 65 | |
| 66 | /* |
| 67 | * Read GuC command/status register (SOFT_SCRATCH_0) |
| 68 | * Return true if it contains a response rather than a command |
| 69 | */ |
| 70 | static inline bool host2guc_action_response(struct drm_i915_private *dev_priv, |
| 71 | u32 *status) |
| 72 | { |
| 73 | u32 val = I915_READ(SOFT_SCRATCH(0)); |
| 74 | *status = val; |
| 75 | return GUC2HOST_IS_RESPONSE(val); |
| 76 | } |
| 77 | |
| 78 | static int host2guc_action(struct intel_guc *guc, u32 *data, u32 len) |
| 79 | { |
| 80 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 81 | u32 status; |
| 82 | int i; |
| 83 | int ret; |
| 84 | |
| 85 | if (WARN_ON(len < 1 || len > 15)) |
| 86 | return -EINVAL; |
| 87 | |
| 88 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 89 | |
| 90 | dev_priv->guc.action_count += 1; |
| 91 | dev_priv->guc.action_cmd = data[0]; |
| 92 | |
| 93 | for (i = 0; i < len; i++) |
| 94 | I915_WRITE(SOFT_SCRATCH(i), data[i]); |
| 95 | |
| 96 | POSTING_READ(SOFT_SCRATCH(i - 1)); |
| 97 | |
| 98 | I915_WRITE(HOST2GUC_INTERRUPT, HOST2GUC_TRIGGER); |
| 99 | |
Dave Gordon | ab0e455 | 2016-07-06 15:30:11 +0100 | [diff] [blame] | 100 | /* |
| 101 | * Fast commands should complete in less than 10us, so sample quickly |
| 102 | * up to that length of time, then switch to a slower sleep-wait loop. |
| 103 | * No HOST2GUC command should ever take longer than 10ms. |
| 104 | */ |
| 105 | ret = wait_for_us(host2guc_action_response(dev_priv, &status), 10); |
| 106 | if (ret) |
| 107 | ret = wait_for(host2guc_action_response(dev_priv, &status), 10); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 108 | if (status != GUC2HOST_STATUS_SUCCESS) { |
| 109 | /* |
| 110 | * Either the GuC explicitly returned an error (which |
| 111 | * we convert to -EIO here) or no response at all was |
| 112 | * received within the timeout limit (-ETIMEDOUT) |
| 113 | */ |
| 114 | if (ret != -ETIMEDOUT) |
| 115 | ret = -EIO; |
| 116 | |
Dave Gordon | 535b2f5 | 2016-08-18 18:17:23 +0100 | [diff] [blame] | 117 | DRM_WARN("Action 0x%X failed; ret=%d status=0x%08X response=0x%08X\n", |
| 118 | data[0], ret, status, I915_READ(SOFT_SCRATCH(15))); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 119 | |
| 120 | dev_priv->guc.action_fail += 1; |
| 121 | dev_priv->guc.action_err = ret; |
| 122 | } |
| 123 | dev_priv->guc.action_status = status; |
| 124 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 125 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Tell the GuC to allocate or deallocate a specific doorbell |
| 132 | */ |
| 133 | |
| 134 | static int host2guc_allocate_doorbell(struct intel_guc *guc, |
| 135 | struct i915_guc_client *client) |
| 136 | { |
| 137 | u32 data[2]; |
| 138 | |
| 139 | data[0] = HOST2GUC_ACTION_ALLOCATE_DOORBELL; |
| 140 | data[1] = client->ctx_index; |
| 141 | |
| 142 | return host2guc_action(guc, data, 2); |
| 143 | } |
| 144 | |
| 145 | static int host2guc_release_doorbell(struct intel_guc *guc, |
| 146 | struct i915_guc_client *client) |
| 147 | { |
| 148 | u32 data[2]; |
| 149 | |
| 150 | data[0] = HOST2GUC_ACTION_DEALLOCATE_DOORBELL; |
| 151 | data[1] = client->ctx_index; |
| 152 | |
| 153 | return host2guc_action(guc, data, 2); |
| 154 | } |
| 155 | |
Alex Dai | f5d3c3e | 2015-08-18 14:34:47 -0700 | [diff] [blame] | 156 | static int host2guc_sample_forcewake(struct intel_guc *guc, |
| 157 | struct i915_guc_client *client) |
| 158 | { |
| 159 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 160 | u32 data[2]; |
| 161 | |
| 162 | data[0] = HOST2GUC_ACTION_SAMPLE_FORCEWAKE; |
Alex Dai | 93f2531 | 2015-09-25 11:46:56 -0700 | [diff] [blame] | 163 | /* WaRsDisableCoarsePowerGating:skl,bxt */ |
Tvrtko Ursulin | 6125151 | 2016-06-21 15:07:14 +0100 | [diff] [blame] | 164 | if (!intel_enable_rc6() || NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Alex Dai | 93f2531 | 2015-09-25 11:46:56 -0700 | [diff] [blame] | 165 | data[1] = 0; |
| 166 | else |
| 167 | /* bit 0 and 1 are for Render and Media domain separately */ |
| 168 | data[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA; |
Alex Dai | f5d3c3e | 2015-08-18 14:34:47 -0700 | [diff] [blame] | 169 | |
Alex Dai | 93f2531 | 2015-09-25 11:46:56 -0700 | [diff] [blame] | 170 | return host2guc_action(guc, data, ARRAY_SIZE(data)); |
Alex Dai | f5d3c3e | 2015-08-18 14:34:47 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Sagar Arun Kamble | 4100b2a | 2016-10-12 21:54:32 +0530 | [diff] [blame^] | 173 | static int host2guc_logbuffer_flush_complete(struct intel_guc *guc) |
| 174 | { |
| 175 | u32 data[1]; |
| 176 | |
| 177 | data[0] = HOST2GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE; |
| 178 | |
| 179 | return host2guc_action(guc, data, 1); |
| 180 | } |
| 181 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 182 | /* |
| 183 | * Initialise, update, or clear doorbell data shared with the GuC |
| 184 | * |
| 185 | * These functions modify shared data and so need access to the mapped |
| 186 | * client object which contains the page being used for the doorbell |
| 187 | */ |
| 188 | |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 189 | static int guc_update_doorbell_id(struct intel_guc *guc, |
| 190 | struct i915_guc_client *client, |
| 191 | u16 new_id) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 192 | { |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 193 | struct sg_table *sg = guc->ctx_pool_vma->pages; |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 194 | void *doorbell_bitmap = guc->doorbell_bitmap; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 195 | struct guc_doorbell_info *doorbell; |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 196 | struct guc_context_desc desc; |
| 197 | size_t len; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 198 | |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 199 | doorbell = client->client_base + client->doorbell_offset; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 200 | |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 201 | if (client->doorbell_id != GUC_INVALID_DOORBELL_ID && |
| 202 | test_bit(client->doorbell_id, doorbell_bitmap)) { |
| 203 | /* Deactivate the old doorbell */ |
| 204 | doorbell->db_status = GUC_DOORBELL_DISABLED; |
| 205 | (void)host2guc_release_doorbell(guc, client); |
| 206 | __clear_bit(client->doorbell_id, doorbell_bitmap); |
| 207 | } |
| 208 | |
| 209 | /* Update the GuC's idea of the doorbell ID */ |
| 210 | len = sg_pcopy_to_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 211 | sizeof(desc) * client->ctx_index); |
| 212 | if (len != sizeof(desc)) |
| 213 | return -EFAULT; |
| 214 | desc.db_id = new_id; |
| 215 | len = sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 216 | sizeof(desc) * client->ctx_index); |
| 217 | if (len != sizeof(desc)) |
| 218 | return -EFAULT; |
| 219 | |
| 220 | client->doorbell_id = new_id; |
| 221 | if (new_id == GUC_INVALID_DOORBELL_ID) |
| 222 | return 0; |
| 223 | |
| 224 | /* Activate the new doorbell */ |
| 225 | __set_bit(new_id, doorbell_bitmap); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 226 | doorbell->cookie = 0; |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 227 | doorbell->db_status = GUC_DOORBELL_ENABLED; |
| 228 | return host2guc_allocate_doorbell(guc, client); |
| 229 | } |
| 230 | |
| 231 | static int guc_init_doorbell(struct intel_guc *guc, |
| 232 | struct i915_guc_client *client, |
| 233 | uint16_t db_id) |
| 234 | { |
| 235 | return guc_update_doorbell_id(guc, client, db_id); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 238 | static void guc_disable_doorbell(struct intel_guc *guc, |
| 239 | struct i915_guc_client *client) |
| 240 | { |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 241 | (void)guc_update_doorbell_id(guc, client, GUC_INVALID_DOORBELL_ID); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 242 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 243 | /* XXX: wait for any interrupts */ |
| 244 | /* XXX: wait for workqueue to drain */ |
| 245 | } |
| 246 | |
Dave Gordon | f10d69a | 2016-06-13 17:57:33 +0100 | [diff] [blame] | 247 | static uint16_t |
| 248 | select_doorbell_register(struct intel_guc *guc, uint32_t priority) |
| 249 | { |
| 250 | /* |
| 251 | * The bitmap tracks which doorbell registers are currently in use. |
| 252 | * It is split into two halves; the first half is used for normal |
| 253 | * priority contexts, the second half for high-priority ones. |
| 254 | * Note that logically higher priorities are numerically less than |
| 255 | * normal ones, so the test below means "is it high-priority?" |
| 256 | */ |
| 257 | const bool hi_pri = (priority <= GUC_CTX_PRIORITY_HIGH); |
| 258 | const uint16_t half = GUC_MAX_DOORBELLS / 2; |
| 259 | const uint16_t start = hi_pri ? half : 0; |
| 260 | const uint16_t end = start + half; |
| 261 | uint16_t id; |
| 262 | |
| 263 | id = find_next_zero_bit(guc->doorbell_bitmap, end, start); |
| 264 | if (id == end) |
| 265 | id = GUC_INVALID_DOORBELL_ID; |
| 266 | |
| 267 | DRM_DEBUG_DRIVER("assigned %s priority doorbell id 0x%x\n", |
| 268 | hi_pri ? "high" : "normal", id); |
| 269 | |
| 270 | return id; |
| 271 | } |
| 272 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 273 | /* |
| 274 | * Select, assign and relase doorbell cachelines |
| 275 | * |
| 276 | * These functions track which doorbell cachelines are in use. |
| 277 | * The data they manipulate is protected by the host2guc lock. |
| 278 | */ |
| 279 | |
| 280 | static uint32_t select_doorbell_cacheline(struct intel_guc *guc) |
| 281 | { |
| 282 | const uint32_t cacheline_size = cache_line_size(); |
| 283 | uint32_t offset; |
| 284 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 285 | /* Doorbell uses a single cache line within a page */ |
| 286 | offset = offset_in_page(guc->db_cacheline); |
| 287 | |
| 288 | /* Moving to next cache line to reduce contention */ |
| 289 | guc->db_cacheline += cacheline_size; |
| 290 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 291 | DRM_DEBUG_DRIVER("selected doorbell cacheline 0x%x, next 0x%x, linesize %u\n", |
| 292 | offset, guc->db_cacheline, cacheline_size); |
| 293 | |
| 294 | return offset; |
| 295 | } |
| 296 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 297 | /* |
| 298 | * Initialise the process descriptor shared with the GuC firmware. |
| 299 | */ |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 300 | static void guc_proc_desc_init(struct intel_guc *guc, |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 301 | struct i915_guc_client *client) |
| 302 | { |
| 303 | struct guc_process_desc *desc; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 304 | |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 305 | desc = client->client_base + client->proc_desc_offset; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 306 | |
| 307 | memset(desc, 0, sizeof(*desc)); |
| 308 | |
| 309 | /* |
| 310 | * XXX: pDoorbell and WQVBaseAddress are pointers in process address |
| 311 | * space for ring3 clients (set them as in mmap_ioctl) or kernel |
| 312 | * space for kernel clients (map on demand instead? May make debug |
| 313 | * easier to have it mapped). |
| 314 | */ |
| 315 | desc->wq_base_addr = 0; |
| 316 | desc->db_base_addr = 0; |
| 317 | |
| 318 | desc->context_id = client->ctx_index; |
| 319 | desc->wq_size_bytes = client->wq_size; |
| 320 | desc->wq_status = WQ_STATUS_ACTIVE; |
| 321 | desc->priority = client->priority; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Initialise/clear the context descriptor shared with the GuC firmware. |
| 326 | * |
| 327 | * This descriptor tells the GuC where (in GGTT space) to find the important |
| 328 | * data structures relating to this client (doorbell, process descriptor, |
| 329 | * write queue, etc). |
| 330 | */ |
| 331 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 332 | static void guc_ctx_desc_init(struct intel_guc *guc, |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 333 | struct i915_guc_client *client) |
| 334 | { |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 335 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 336 | struct intel_engine_cs *engine; |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 337 | struct i915_gem_context *ctx = client->owner; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 338 | struct guc_context_desc desc; |
| 339 | struct sg_table *sg; |
Chris Wilson | bafb0fc | 2016-08-27 08:54:01 +0100 | [diff] [blame] | 340 | unsigned int tmp; |
Dave Gordon | 86e06cc | 2016-04-19 16:08:36 +0100 | [diff] [blame] | 341 | u32 gfx_addr; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 342 | |
| 343 | memset(&desc, 0, sizeof(desc)); |
| 344 | |
| 345 | desc.attribute = GUC_CTX_DESC_ATTR_ACTIVE | GUC_CTX_DESC_ATTR_KERNEL; |
| 346 | desc.context_id = client->ctx_index; |
| 347 | desc.priority = client->priority; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 348 | desc.db_id = client->doorbell_id; |
| 349 | |
Chris Wilson | bafb0fc | 2016-08-27 08:54:01 +0100 | [diff] [blame] | 350 | for_each_engine_masked(engine, dev_priv, client->engines, tmp) { |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 351 | struct intel_context *ce = &ctx->engine[engine->id]; |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 352 | uint32_t guc_engine_id = engine->guc_id; |
| 353 | struct guc_execlist_context *lrc = &desc.lrc[guc_engine_id]; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 354 | |
| 355 | /* TODO: We have a design issue to be solved here. Only when we |
| 356 | * receive the first batch, we know which engine is used by the |
| 357 | * user. But here GuC expects the lrc and ring to be pinned. It |
| 358 | * is not an issue for default context, which is the only one |
| 359 | * for now who owns a GuC client. But for future owner of GuC |
| 360 | * client, need to make sure lrc is pinned prior to enter here. |
| 361 | */ |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 362 | if (!ce->state) |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 363 | break; /* XXX: continue? */ |
| 364 | |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 365 | lrc->context_desc = lower_32_bits(ce->lrc_desc); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 366 | |
| 367 | /* The state page is after PPHWSP */ |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 368 | lrc->ring_lcra = |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 369 | i915_ggtt_offset(ce->state) + LRC_STATE_PN * PAGE_SIZE; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 370 | lrc->context_id = (client->ctx_index << GUC_ELC_CTXID_OFFSET) | |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 371 | (guc_engine_id << GUC_ELC_ENGINE_OFFSET); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 372 | |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 373 | lrc->ring_begin = i915_ggtt_offset(ce->ring->vma); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 374 | lrc->ring_end = lrc->ring_begin + ce->ring->size - 1; |
| 375 | lrc->ring_next_free_location = lrc->ring_begin; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 376 | lrc->ring_current_tail_pointer_value = 0; |
| 377 | |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 378 | desc.engines_used |= (1 << guc_engine_id); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 381 | DRM_DEBUG_DRIVER("Host engines 0x%x => GuC engines used 0x%x\n", |
| 382 | client->engines, desc.engines_used); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 383 | WARN_ON(desc.engines_used == 0); |
| 384 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 385 | /* |
Dave Gordon | 86e06cc | 2016-04-19 16:08:36 +0100 | [diff] [blame] | 386 | * The doorbell, process descriptor, and workqueue are all parts |
| 387 | * of the client object, which the GuC will reference via the GGTT |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 388 | */ |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 389 | gfx_addr = i915_ggtt_offset(client->vma); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 390 | desc.db_trigger_phy = sg_dma_address(client->vma->pages->sgl) + |
Dave Gordon | 86e06cc | 2016-04-19 16:08:36 +0100 | [diff] [blame] | 391 | client->doorbell_offset; |
| 392 | desc.db_trigger_cpu = (uintptr_t)client->client_base + |
| 393 | client->doorbell_offset; |
| 394 | desc.db_trigger_uk = gfx_addr + client->doorbell_offset; |
| 395 | desc.process_desc = gfx_addr + client->proc_desc_offset; |
| 396 | desc.wq_addr = gfx_addr + client->wq_offset; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 397 | desc.wq_size = client->wq_size; |
| 398 | |
| 399 | /* |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 400 | * XXX: Take LRCs from an existing context if this is not an |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 401 | * IsKMDCreatedContext client |
| 402 | */ |
| 403 | desc.desc_private = (uintptr_t)client; |
| 404 | |
| 405 | /* Pool context is pinned already */ |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 406 | sg = guc->ctx_pool_vma->pages; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 407 | sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 408 | sizeof(desc) * client->ctx_index); |
| 409 | } |
| 410 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 411 | static void guc_ctx_desc_fini(struct intel_guc *guc, |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 412 | struct i915_guc_client *client) |
| 413 | { |
| 414 | struct guc_context_desc desc; |
| 415 | struct sg_table *sg; |
| 416 | |
| 417 | memset(&desc, 0, sizeof(desc)); |
| 418 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 419 | sg = guc->ctx_pool_vma->pages; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 420 | sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 421 | sizeof(desc) * client->ctx_index); |
| 422 | } |
| 423 | |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 424 | /** |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 425 | * i915_guc_wq_reserve() - reserve space in the GuC's workqueue |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 426 | * @request: request associated with the commands |
| 427 | * |
| 428 | * Return: 0 if space is available |
| 429 | * -EAGAIN if space is not currently available |
| 430 | * |
| 431 | * This function must be called (and must return 0) before a request |
| 432 | * is submitted to the GuC via i915_guc_submit() below. Once a result |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 433 | * of 0 has been returned, it must be balanced by a corresponding |
| 434 | * call to submit(). |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 435 | * |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 436 | * Reservation allows the caller to determine in advance that space |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 437 | * will be available for the next submission before committing resources |
| 438 | * to it, and helps avoid late failures with complicated recovery paths. |
| 439 | */ |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 440 | int i915_guc_wq_reserve(struct drm_i915_gem_request *request) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 441 | { |
Dave Gordon | 551aaec | 2016-05-13 15:36:33 +0100 | [diff] [blame] | 442 | const size_t wqi_size = sizeof(struct guc_wq_item); |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 443 | struct i915_guc_client *gc = request->i915->guc.execbuf_client; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 444 | struct guc_process_desc *desc = gc->client_base + gc->proc_desc_offset; |
Dave Gordon | 551aaec | 2016-05-13 15:36:33 +0100 | [diff] [blame] | 445 | u32 freespace; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 446 | int ret; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 447 | |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 448 | spin_lock(&gc->wq_lock); |
Dave Gordon | 551aaec | 2016-05-13 15:36:33 +0100 | [diff] [blame] | 449 | freespace = CIRC_SPACE(gc->wq_tail, desc->head, gc->wq_size); |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 450 | freespace -= gc->wq_rsvd; |
| 451 | if (likely(freespace >= wqi_size)) { |
| 452 | gc->wq_rsvd += wqi_size; |
| 453 | ret = 0; |
| 454 | } else { |
| 455 | gc->no_wq_space++; |
| 456 | ret = -EAGAIN; |
| 457 | } |
| 458 | spin_unlock(&gc->wq_lock); |
Alex Dai | 5a84330 | 2015-12-02 16:56:29 -0800 | [diff] [blame] | 459 | |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 460 | return ret; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Chris Wilson | 5ba8990 | 2016-10-07 07:53:27 +0100 | [diff] [blame] | 463 | void i915_guc_wq_unreserve(struct drm_i915_gem_request *request) |
| 464 | { |
| 465 | const size_t wqi_size = sizeof(struct guc_wq_item); |
| 466 | struct i915_guc_client *gc = request->i915->guc.execbuf_client; |
| 467 | |
| 468 | GEM_BUG_ON(READ_ONCE(gc->wq_rsvd) < wqi_size); |
| 469 | |
| 470 | spin_lock(&gc->wq_lock); |
| 471 | gc->wq_rsvd -= wqi_size; |
| 472 | spin_unlock(&gc->wq_lock); |
| 473 | } |
| 474 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 475 | /* Construct a Work Item and append it to the GuC's Work Queue */ |
| 476 | static void guc_wq_item_append(struct i915_guc_client *gc, |
| 477 | struct drm_i915_gem_request *rq) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 478 | { |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 479 | /* wqi_len is in DWords, and does not include the one-word header */ |
| 480 | const size_t wqi_size = sizeof(struct guc_wq_item); |
| 481 | const u32 wqi_len = wqi_size/sizeof(u32) - 1; |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 482 | struct intel_engine_cs *engine = rq->engine; |
Alex Dai | a5916e8 | 2016-04-19 16:08:35 +0100 | [diff] [blame] | 483 | struct guc_process_desc *desc; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 484 | struct guc_wq_item *wqi; |
| 485 | void *base; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 486 | u32 freespace, tail, wq_off, wq_page; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 487 | |
Alex Dai | a5916e8 | 2016-04-19 16:08:35 +0100 | [diff] [blame] | 488 | desc = gc->client_base + gc->proc_desc_offset; |
Alex Dai | a7e0219 | 2015-12-16 11:45:55 -0800 | [diff] [blame] | 489 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 490 | /* Free space is guaranteed, see i915_guc_wq_reserve() above */ |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 491 | freespace = CIRC_SPACE(gc->wq_tail, desc->head, gc->wq_size); |
| 492 | GEM_BUG_ON(freespace < wqi_size); |
| 493 | |
| 494 | /* The GuC firmware wants the tail index in QWords, not bytes */ |
| 495 | tail = rq->tail; |
| 496 | GEM_BUG_ON(tail & 7); |
| 497 | tail >>= 3; |
| 498 | GEM_BUG_ON(tail > WQ_RING_TAIL_MAX); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 499 | |
| 500 | /* For now workqueue item is 4 DWs; workqueue buffer is 2 pages. So we |
| 501 | * should not have the case where structure wqi is across page, neither |
| 502 | * wrapped to the beginning. This simplifies the implementation below. |
| 503 | * |
| 504 | * XXX: if not the case, we need save data to a temp wqi and copy it to |
| 505 | * workqueue buffer dw by dw. |
| 506 | */ |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 507 | BUILD_BUG_ON(wqi_size != 16); |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 508 | GEM_BUG_ON(gc->wq_rsvd < wqi_size); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 509 | |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 510 | /* postincrement WQ tail for next time */ |
| 511 | wq_off = gc->wq_tail; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 512 | GEM_BUG_ON(wq_off & (wqi_size - 1)); |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 513 | gc->wq_tail += wqi_size; |
| 514 | gc->wq_tail &= gc->wq_size - 1; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 515 | gc->wq_rsvd -= wqi_size; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 516 | |
| 517 | /* WQ starts from the page after doorbell / process_desc */ |
| 518 | wq_page = (wq_off + GUC_DB_SIZE) >> PAGE_SHIFT; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 519 | wq_off &= PAGE_SIZE - 1; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 520 | base = kmap_atomic(i915_gem_object_get_page(gc->vma->obj, wq_page)); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 521 | wqi = (struct guc_wq_item *)((char *)base + wq_off); |
| 522 | |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 523 | /* Now fill in the 4-word work queue item */ |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 524 | wqi->header = WQ_TYPE_INORDER | |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 525 | (wqi_len << WQ_LEN_SHIFT) | |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 526 | (engine->guc_id << WQ_TARGET_SHIFT) | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 527 | WQ_NO_WCFLUSH_WAIT; |
| 528 | |
| 529 | /* The GuC wants only the low-order word of the context descriptor */ |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 530 | wqi->context_desc = (u32)intel_lr_context_descriptor(rq->ctx, engine); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 531 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 532 | wqi->ring_tail = tail << WQ_RING_TAIL_SHIFT; |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 533 | wqi->fence_id = rq->fence.seqno; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 534 | |
| 535 | kunmap_atomic(base); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 538 | static int guc_ring_doorbell(struct i915_guc_client *gc) |
| 539 | { |
| 540 | struct guc_process_desc *desc; |
| 541 | union guc_doorbell_qw db_cmp, db_exc, db_ret; |
| 542 | union guc_doorbell_qw *db; |
| 543 | int attempt = 2, ret = -EAGAIN; |
| 544 | |
| 545 | desc = gc->client_base + gc->proc_desc_offset; |
| 546 | |
| 547 | /* Update the tail so it is visible to GuC */ |
| 548 | desc->tail = gc->wq_tail; |
| 549 | |
| 550 | /* current cookie */ |
| 551 | db_cmp.db_status = GUC_DOORBELL_ENABLED; |
| 552 | db_cmp.cookie = gc->cookie; |
| 553 | |
| 554 | /* cookie to be updated */ |
| 555 | db_exc.db_status = GUC_DOORBELL_ENABLED; |
| 556 | db_exc.cookie = gc->cookie + 1; |
| 557 | if (db_exc.cookie == 0) |
| 558 | db_exc.cookie = 1; |
| 559 | |
| 560 | /* pointer of current doorbell cacheline */ |
| 561 | db = gc->client_base + gc->doorbell_offset; |
| 562 | |
| 563 | while (attempt--) { |
| 564 | /* lets ring the doorbell */ |
| 565 | db_ret.value_qw = atomic64_cmpxchg((atomic64_t *)db, |
| 566 | db_cmp.value_qw, db_exc.value_qw); |
| 567 | |
| 568 | /* if the exchange was successfully executed */ |
| 569 | if (db_ret.value_qw == db_cmp.value_qw) { |
| 570 | /* db was successfully rung */ |
| 571 | gc->cookie = db_exc.cookie; |
| 572 | ret = 0; |
| 573 | break; |
| 574 | } |
| 575 | |
| 576 | /* XXX: doorbell was lost and need to acquire it again */ |
| 577 | if (db_ret.db_status == GUC_DOORBELL_DISABLED) |
| 578 | break; |
| 579 | |
Dave Gordon | 535b2f5 | 2016-08-18 18:17:23 +0100 | [diff] [blame] | 580 | DRM_WARN("Cookie mismatch. Expected %d, found %d\n", |
| 581 | db_cmp.cookie, db_ret.cookie); |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 582 | |
| 583 | /* update the cookie to newly read cookie from GuC */ |
| 584 | db_cmp.cookie = db_ret.cookie; |
| 585 | db_exc.cookie = db_ret.cookie + 1; |
| 586 | if (db_exc.cookie == 0) |
| 587 | db_exc.cookie = 1; |
| 588 | } |
| 589 | |
| 590 | return ret; |
| 591 | } |
| 592 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 593 | /** |
| 594 | * i915_guc_submit() - Submit commands through GuC |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 595 | * @rq: request associated with the commands |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 596 | * |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 597 | * Return: 0 on success, otherwise an errno. |
| 598 | * (Note: nonzero really shouldn't happen!) |
| 599 | * |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 600 | * The caller must have already called i915_guc_wq_reserve() above with |
| 601 | * a result of 0 (success), guaranteeing that there is space in the work |
| 602 | * queue for the new request, so enqueuing the item cannot fail. |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 603 | * |
| 604 | * Bad Things Will Happen if the caller violates this protocol e.g. calls |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 605 | * submit() when _reserve() says there's no space, or calls _submit() |
| 606 | * a different number of times from (successful) calls to _reserve(). |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 607 | * |
| 608 | * The only error here arises if the doorbell hardware isn't functioning |
| 609 | * as expected, which really shouln't happen. |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 610 | */ |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 611 | static void i915_guc_submit(struct drm_i915_gem_request *rq) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 612 | { |
Dave Gordon | 0b63bb1 | 2016-06-20 15:18:07 +0100 | [diff] [blame] | 613 | unsigned int engine_id = rq->engine->id; |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 614 | struct intel_guc *guc = &rq->i915->guc; |
| 615 | struct i915_guc_client *client = guc->execbuf_client; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 616 | int b_ret; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 617 | |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 618 | spin_lock(&client->wq_lock); |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 619 | guc_wq_item_append(client, rq); |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 620 | b_ret = guc_ring_doorbell(client); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 621 | |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 622 | client->submissions[engine_id] += 1; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 623 | client->retcode = b_ret; |
| 624 | if (b_ret) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 625 | client->b_fail += 1; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 626 | |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 627 | guc->submissions[engine_id] += 1; |
Chris Wilson | 0476965 | 2016-07-20 09:21:11 +0100 | [diff] [blame] | 628 | guc->last_seqno[engine_id] = rq->fence.seqno; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 629 | spin_unlock(&client->wq_lock); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /* |
| 633 | * Everything below here is concerned with setup & teardown, and is |
| 634 | * therefore not part of the somewhat time-critical batch-submission |
| 635 | * path of i915_guc_submit() above. |
| 636 | */ |
| 637 | |
| 638 | /** |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 639 | * guc_allocate_vma() - Allocate a GGTT VMA for GuC usage |
| 640 | * @guc: the guc |
| 641 | * @size: size of area to allocate (both virtual space and memory) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 642 | * |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 643 | * This is a wrapper to create an object for use with the GuC. In order to |
| 644 | * use it inside the GuC, an object needs to be pinned lifetime, so we allocate |
| 645 | * both some backing storage and a range inside the Global GTT. We must pin |
| 646 | * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that |
| 647 | * range is reserved inside GuC. |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 648 | * |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 649 | * Return: A i915_vma if successful, otherwise an ERR_PTR. |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 650 | */ |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 651 | static struct i915_vma *guc_allocate_vma(struct intel_guc *guc, u32 size) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 652 | { |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 653 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 654 | struct drm_i915_gem_object *obj; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 655 | struct i915_vma *vma; |
| 656 | int ret; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 657 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 658 | obj = i915_gem_object_create(&dev_priv->drm, size); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 659 | if (IS_ERR(obj)) |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 660 | return ERR_CAST(obj); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 661 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 662 | vma = i915_vma_create(obj, &dev_priv->ggtt.base, NULL); |
| 663 | if (IS_ERR(vma)) |
| 664 | goto err; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 665 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 666 | ret = i915_vma_pin(vma, 0, PAGE_SIZE, |
| 667 | PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP); |
| 668 | if (ret) { |
| 669 | vma = ERR_PTR(ret); |
| 670 | goto err; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* Invalidate GuC TLB to let GuC take the latest updates to GTT. */ |
| 674 | I915_WRITE(GEN8_GTCR, GEN8_GTCR_INVALIDATE); |
| 675 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 676 | return vma; |
| 677 | |
| 678 | err: |
| 679 | i915_gem_object_put(obj); |
| 680 | return vma; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 683 | static void |
| 684 | guc_client_free(struct drm_i915_private *dev_priv, |
| 685 | struct i915_guc_client *client) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 686 | { |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 687 | struct intel_guc *guc = &dev_priv->guc; |
| 688 | |
| 689 | if (!client) |
| 690 | return; |
| 691 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 692 | /* |
| 693 | * XXX: wait for any outstanding submissions before freeing memory. |
| 694 | * Be sure to drop any locks |
| 695 | */ |
| 696 | |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 697 | if (client->client_base) { |
| 698 | /* |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 699 | * If we got as far as setting up a doorbell, make sure we |
| 700 | * shut it down before unmapping & deallocating the memory. |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 701 | */ |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 702 | guc_disable_doorbell(guc, client); |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 703 | |
| 704 | kunmap(kmap_to_page(client->client_base)); |
| 705 | } |
| 706 | |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 707 | i915_vma_unpin_and_release(&client->vma); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 708 | |
| 709 | if (client->ctx_index != GUC_INVALID_CTX_ID) { |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 710 | guc_ctx_desc_fini(guc, client); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 711 | ida_simple_remove(&guc->ctx_ids, client->ctx_index); |
| 712 | } |
| 713 | |
| 714 | kfree(client); |
| 715 | } |
| 716 | |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 717 | /* Check that a doorbell register is in the expected state */ |
| 718 | static bool guc_doorbell_check(struct intel_guc *guc, uint16_t db_id) |
| 719 | { |
| 720 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 721 | i915_reg_t drbreg = GEN8_DRBREGL(db_id); |
| 722 | uint32_t value = I915_READ(drbreg); |
| 723 | bool enabled = (value & GUC_DOORBELL_ENABLED) != 0; |
| 724 | bool expected = test_bit(db_id, guc->doorbell_bitmap); |
| 725 | |
| 726 | if (enabled == expected) |
| 727 | return true; |
| 728 | |
| 729 | DRM_DEBUG_DRIVER("Doorbell %d (reg 0x%x) 0x%x, should be %s\n", |
| 730 | db_id, drbreg.reg, value, |
| 731 | expected ? "active" : "inactive"); |
| 732 | |
| 733 | return false; |
| 734 | } |
| 735 | |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 736 | /* |
Dave Gordon | 8888cd0 | 2016-08-09 15:19:19 +0100 | [diff] [blame] | 737 | * Borrow the first client to set up & tear down each unused doorbell |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 738 | * in turn, to ensure that all doorbell h/w is (re)initialised. |
| 739 | */ |
| 740 | static void guc_init_doorbell_hw(struct intel_guc *guc) |
| 741 | { |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 742 | struct i915_guc_client *client = guc->execbuf_client; |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 743 | uint16_t db_id; |
| 744 | int i, err; |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 745 | |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 746 | /* Save client's original doorbell selection */ |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 747 | db_id = client->doorbell_id; |
| 748 | |
| 749 | for (i = 0; i < GUC_MAX_DOORBELLS; ++i) { |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 750 | /* Skip if doorbell is OK */ |
| 751 | if (guc_doorbell_check(guc, i)) |
Dave Gordon | 8888cd0 | 2016-08-09 15:19:19 +0100 | [diff] [blame] | 752 | continue; |
| 753 | |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 754 | err = guc_update_doorbell_id(guc, client, i); |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 755 | if (err) |
| 756 | DRM_DEBUG_DRIVER("Doorbell %d update failed, err %d\n", |
| 757 | i, err); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /* Restore to original value */ |
| 761 | err = guc_update_doorbell_id(guc, client, db_id); |
| 762 | if (err) |
Dave Gordon | 535b2f5 | 2016-08-18 18:17:23 +0100 | [diff] [blame] | 763 | DRM_WARN("Failed to restore doorbell to %d, err %d\n", |
| 764 | db_id, err); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 765 | |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 766 | /* Read back & verify all doorbell registers */ |
| 767 | for (i = 0; i < GUC_MAX_DOORBELLS; ++i) |
| 768 | (void)guc_doorbell_check(guc, i); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 769 | } |
| 770 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 771 | /** |
| 772 | * guc_client_alloc() - Allocate an i915_guc_client |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 773 | * @dev_priv: driver private data structure |
Chris Wilson | ceae531 | 2016-08-17 13:42:42 +0100 | [diff] [blame] | 774 | * @engines: The set of engines to enable for this client |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 775 | * @priority: four levels priority _CRITICAL, _HIGH, _NORMAL and _LOW |
| 776 | * The kernel client to replace ExecList submission is created with |
| 777 | * NORMAL priority. Priority of a client for scheduler can be HIGH, |
| 778 | * while a preemption context can use CRITICAL. |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 779 | * @ctx: the context that owns the client (we use the default render |
| 780 | * context) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 781 | * |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 782 | * Return: An i915_guc_client object if success, else NULL. |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 783 | */ |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 784 | static struct i915_guc_client * |
| 785 | guc_client_alloc(struct drm_i915_private *dev_priv, |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 786 | uint32_t engines, |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 787 | uint32_t priority, |
| 788 | struct i915_gem_context *ctx) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 789 | { |
| 790 | struct i915_guc_client *client; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 791 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 792 | struct i915_vma *vma; |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 793 | uint16_t db_id; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 794 | |
| 795 | client = kzalloc(sizeof(*client), GFP_KERNEL); |
| 796 | if (!client) |
| 797 | return NULL; |
| 798 | |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 799 | client->owner = ctx; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 800 | client->guc = guc; |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 801 | client->engines = engines; |
| 802 | client->priority = priority; |
| 803 | client->doorbell_id = GUC_INVALID_DOORBELL_ID; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 804 | |
| 805 | client->ctx_index = (uint32_t)ida_simple_get(&guc->ctx_ids, 0, |
| 806 | GUC_MAX_GPU_CONTEXTS, GFP_KERNEL); |
| 807 | if (client->ctx_index >= GUC_MAX_GPU_CONTEXTS) { |
| 808 | client->ctx_index = GUC_INVALID_CTX_ID; |
| 809 | goto err; |
| 810 | } |
| 811 | |
| 812 | /* The first page is doorbell/proc_desc. Two followed pages are wq. */ |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 813 | vma = guc_allocate_vma(guc, GUC_DB_SIZE + GUC_WQ_SIZE); |
| 814 | if (IS_ERR(vma)) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 815 | goto err; |
| 816 | |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 817 | /* We'll keep just the first (doorbell/proc) page permanently kmap'd. */ |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 818 | client->vma = vma; |
| 819 | client->client_base = kmap(i915_vma_first_page(vma)); |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 820 | |
| 821 | spin_lock_init(&client->wq_lock); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 822 | client->wq_offset = GUC_DB_SIZE; |
| 823 | client->wq_size = GUC_WQ_SIZE; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 824 | |
Dave Gordon | f10d69a | 2016-06-13 17:57:33 +0100 | [diff] [blame] | 825 | db_id = select_doorbell_register(guc, client->priority); |
| 826 | if (db_id == GUC_INVALID_DOORBELL_ID) |
| 827 | /* XXX: evict a doorbell instead? */ |
| 828 | goto err; |
| 829 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 830 | client->doorbell_offset = select_doorbell_cacheline(guc); |
| 831 | |
| 832 | /* |
| 833 | * Since the doorbell only requires a single cacheline, we can save |
| 834 | * space by putting the application process descriptor in the same |
| 835 | * page. Use the half of the page that doesn't include the doorbell. |
| 836 | */ |
| 837 | if (client->doorbell_offset >= (GUC_DB_SIZE / 2)) |
| 838 | client->proc_desc_offset = 0; |
| 839 | else |
| 840 | client->proc_desc_offset = (GUC_DB_SIZE / 2); |
| 841 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 842 | guc_proc_desc_init(guc, client); |
| 843 | guc_ctx_desc_init(guc, client); |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 844 | if (guc_init_doorbell(guc, client, db_id)) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 845 | goto err; |
| 846 | |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 847 | DRM_DEBUG_DRIVER("new priority %u client %p for engine(s) 0x%x: ctx_index %u\n", |
| 848 | priority, client, client->engines, client->ctx_index); |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 849 | DRM_DEBUG_DRIVER("doorbell id %u, cacheline offset 0x%x\n", |
| 850 | client->doorbell_id, client->doorbell_offset); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 851 | |
| 852 | return client; |
| 853 | |
| 854 | err: |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 855 | guc_client_free(dev_priv, client); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 856 | return NULL; |
| 857 | } |
| 858 | |
Sagar Arun Kamble | 4100b2a | 2016-10-12 21:54:32 +0530 | [diff] [blame^] | 859 | static void guc_move_to_next_buf(struct intel_guc *guc) |
| 860 | { |
| 861 | } |
| 862 | |
| 863 | static void *guc_get_write_buffer(struct intel_guc *guc) |
| 864 | { |
| 865 | return NULL; |
| 866 | } |
| 867 | |
| 868 | static unsigned int guc_get_log_buffer_size(enum guc_log_buffer_type type) |
| 869 | { |
| 870 | switch (type) { |
| 871 | case GUC_ISR_LOG_BUFFER: |
| 872 | return (GUC_LOG_ISR_PAGES + 1) * PAGE_SIZE; |
| 873 | case GUC_DPC_LOG_BUFFER: |
| 874 | return (GUC_LOG_DPC_PAGES + 1) * PAGE_SIZE; |
| 875 | case GUC_CRASH_DUMP_LOG_BUFFER: |
| 876 | return (GUC_LOG_CRASH_PAGES + 1) * PAGE_SIZE; |
| 877 | default: |
| 878 | MISSING_CASE(type); |
| 879 | } |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | static void guc_read_update_log_buffer(struct intel_guc *guc) |
| 885 | { |
| 886 | struct guc_log_buffer_state *log_buf_state, *log_buf_snapshot_state; |
| 887 | struct guc_log_buffer_state log_buf_state_local; |
| 888 | unsigned int buffer_size, write_offset; |
| 889 | enum guc_log_buffer_type type; |
| 890 | void *src_data, *dst_data; |
| 891 | |
| 892 | if (WARN_ON(!guc->log.buf_addr)) |
| 893 | return; |
| 894 | |
| 895 | /* Get the pointer to shared GuC log buffer */ |
| 896 | log_buf_state = src_data = guc->log.buf_addr; |
| 897 | |
| 898 | /* Get the pointer to local buffer to store the logs */ |
| 899 | log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc); |
| 900 | |
| 901 | /* Actual logs are present from the 2nd page */ |
| 902 | src_data += PAGE_SIZE; |
| 903 | dst_data += PAGE_SIZE; |
| 904 | |
| 905 | for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) { |
| 906 | /* Make a copy of the state structure, inside GuC log buffer |
| 907 | * (which is uncached mapped), on the stack to avoid reading |
| 908 | * from it multiple times. |
| 909 | */ |
| 910 | memcpy(&log_buf_state_local, log_buf_state, |
| 911 | sizeof(struct guc_log_buffer_state)); |
| 912 | buffer_size = guc_get_log_buffer_size(type); |
| 913 | write_offset = log_buf_state_local.sampled_write_ptr; |
| 914 | |
| 915 | /* Update the state of shared log buffer */ |
| 916 | log_buf_state->read_ptr = write_offset; |
| 917 | log_buf_state->flush_to_file = 0; |
| 918 | log_buf_state++; |
| 919 | |
| 920 | if (unlikely(!log_buf_snapshot_state)) |
| 921 | continue; |
| 922 | |
| 923 | /* First copy the state structure in snapshot buffer */ |
| 924 | memcpy(log_buf_snapshot_state, &log_buf_state_local, |
| 925 | sizeof(struct guc_log_buffer_state)); |
| 926 | |
| 927 | /* The write pointer could have been updated by GuC firmware, |
| 928 | * after sending the flush interrupt to Host, for consistency |
| 929 | * set write pointer value to same value of sampled_write_ptr |
| 930 | * in the snapshot buffer. |
| 931 | */ |
| 932 | log_buf_snapshot_state->write_ptr = write_offset; |
| 933 | log_buf_snapshot_state++; |
| 934 | |
| 935 | /* Now copy the actual logs. */ |
| 936 | memcpy(dst_data, src_data, buffer_size); |
| 937 | |
| 938 | src_data += buffer_size; |
| 939 | dst_data += buffer_size; |
| 940 | |
| 941 | /* FIXME: invalidate/flush for log buffer needed */ |
| 942 | } |
| 943 | |
| 944 | if (log_buf_snapshot_state) |
| 945 | guc_move_to_next_buf(guc); |
| 946 | } |
| 947 | |
| 948 | static void guc_capture_logs_work(struct work_struct *work) |
| 949 | { |
| 950 | struct drm_i915_private *dev_priv = |
| 951 | container_of(work, struct drm_i915_private, guc.log.flush_work); |
| 952 | |
| 953 | i915_guc_capture_logs(dev_priv); |
| 954 | } |
| 955 | |
| 956 | static void guc_log_cleanup(struct intel_guc *guc) |
| 957 | { |
| 958 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 959 | |
| 960 | lockdep_assert_held(&dev_priv->drm.struct_mutex); |
| 961 | |
| 962 | /* First disable the flush interrupt */ |
| 963 | gen9_disable_guc_interrupts(dev_priv); |
| 964 | |
| 965 | if (guc->log.flush_wq) |
| 966 | destroy_workqueue(guc->log.flush_wq); |
| 967 | |
| 968 | guc->log.flush_wq = NULL; |
| 969 | |
| 970 | if (guc->log.buf_addr) |
| 971 | i915_gem_object_unpin_map(guc->log.vma->obj); |
| 972 | |
| 973 | guc->log.buf_addr = NULL; |
| 974 | } |
| 975 | |
| 976 | static int guc_log_create_extras(struct intel_guc *guc) |
| 977 | { |
| 978 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 979 | void *vaddr; |
| 980 | int ret; |
| 981 | |
| 982 | lockdep_assert_held(&dev_priv->drm.struct_mutex); |
| 983 | |
| 984 | /* Nothing to do */ |
| 985 | if (i915.guc_log_level < 0) |
| 986 | return 0; |
| 987 | |
| 988 | if (!guc->log.buf_addr) { |
| 989 | /* Create a vmalloc mapping of log buffer pages */ |
| 990 | vaddr = i915_gem_object_pin_map(guc->log.vma->obj, I915_MAP_WB); |
| 991 | if (IS_ERR(vaddr)) { |
| 992 | ret = PTR_ERR(vaddr); |
| 993 | DRM_ERROR("Couldn't map log buffer pages %d\n", ret); |
| 994 | return ret; |
| 995 | } |
| 996 | |
| 997 | guc->log.buf_addr = vaddr; |
| 998 | } |
| 999 | |
| 1000 | if (!guc->log.flush_wq) { |
| 1001 | INIT_WORK(&guc->log.flush_work, guc_capture_logs_work); |
| 1002 | |
| 1003 | /* Need a dedicated wq to process log buffer flush interrupts |
| 1004 | * from GuC without much delay so as to avoid any loss of logs. |
| 1005 | */ |
| 1006 | guc->log.flush_wq = alloc_ordered_workqueue("i915-guc_log", WQ_HIGHPRI); |
| 1007 | if (guc->log.flush_wq == NULL) { |
| 1008 | DRM_ERROR("Couldn't allocate the wq for GuC logging\n"); |
| 1009 | return -ENOMEM; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1016 | static void guc_log_create(struct intel_guc *guc) |
Alex Dai | 4c7e77f | 2015-08-12 15:43:40 +0100 | [diff] [blame] | 1017 | { |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1018 | struct i915_vma *vma; |
Alex Dai | 4c7e77f | 2015-08-12 15:43:40 +0100 | [diff] [blame] | 1019 | unsigned long offset; |
| 1020 | uint32_t size, flags; |
| 1021 | |
Alex Dai | 4c7e77f | 2015-08-12 15:43:40 +0100 | [diff] [blame] | 1022 | if (i915.guc_log_level > GUC_LOG_VERBOSITY_MAX) |
| 1023 | i915.guc_log_level = GUC_LOG_VERBOSITY_MAX; |
| 1024 | |
| 1025 | /* The first page is to save log buffer state. Allocate one |
| 1026 | * extra page for others in case for overlap */ |
| 1027 | size = (1 + GUC_LOG_DPC_PAGES + 1 + |
| 1028 | GUC_LOG_ISR_PAGES + 1 + |
| 1029 | GUC_LOG_CRASH_PAGES + 1) << PAGE_SHIFT; |
| 1030 | |
Akash Goel | d6b40b4 | 2016-10-12 21:54:29 +0530 | [diff] [blame] | 1031 | vma = guc->log.vma; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1032 | if (!vma) { |
| 1033 | vma = guc_allocate_vma(guc, size); |
| 1034 | if (IS_ERR(vma)) { |
Alex Dai | 4c7e77f | 2015-08-12 15:43:40 +0100 | [diff] [blame] | 1035 | /* logging will be off */ |
| 1036 | i915.guc_log_level = -1; |
| 1037 | return; |
| 1038 | } |
| 1039 | |
Akash Goel | d6b40b4 | 2016-10-12 21:54:29 +0530 | [diff] [blame] | 1040 | guc->log.vma = vma; |
Sagar Arun Kamble | 4100b2a | 2016-10-12 21:54:32 +0530 | [diff] [blame^] | 1041 | |
| 1042 | if (guc_log_create_extras(guc)) { |
| 1043 | guc_log_cleanup(guc); |
| 1044 | i915_vma_unpin_and_release(&guc->log.vma); |
| 1045 | i915.guc_log_level = -1; |
| 1046 | return; |
| 1047 | } |
Alex Dai | 4c7e77f | 2015-08-12 15:43:40 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /* each allocated unit is a page */ |
| 1051 | flags = GUC_LOG_VALID | GUC_LOG_NOTIFY_ON_HALF_FULL | |
| 1052 | (GUC_LOG_DPC_PAGES << GUC_LOG_DPC_SHIFT) | |
| 1053 | (GUC_LOG_ISR_PAGES << GUC_LOG_ISR_SHIFT) | |
| 1054 | (GUC_LOG_CRASH_PAGES << GUC_LOG_CRASH_SHIFT); |
| 1055 | |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1056 | offset = i915_ggtt_offset(vma) >> PAGE_SHIFT; /* in pages */ |
Akash Goel | d6b40b4 | 2016-10-12 21:54:29 +0530 | [diff] [blame] | 1057 | guc->log.flags = (offset << GUC_LOG_BUF_ADDR_SHIFT) | flags; |
Alex Dai | 4c7e77f | 2015-08-12 15:43:40 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1060 | static void guc_policies_init(struct guc_policies *policies) |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 1061 | { |
| 1062 | struct guc_policy *policy; |
| 1063 | u32 p, i; |
| 1064 | |
| 1065 | policies->dpc_promote_time = 500000; |
| 1066 | policies->max_num_work_items = POLICY_MAX_NUM_WI; |
| 1067 | |
| 1068 | for (p = 0; p < GUC_CTX_PRIORITY_NUM; p++) { |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 1069 | for (i = GUC_RENDER_ENGINE; i < GUC_MAX_ENGINES_NUM; i++) { |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 1070 | policy = &policies->policy[p][i]; |
| 1071 | |
| 1072 | policy->execution_quantum = 1000000; |
| 1073 | policy->preemption_time = 500000; |
| 1074 | policy->fault_time = 250000; |
| 1075 | policy->policy_flags = 0; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | policies->is_valid = 1; |
| 1080 | } |
| 1081 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1082 | static void guc_addon_create(struct intel_guc *guc) |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1083 | { |
| 1084 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1085 | struct i915_vma *vma; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1086 | struct guc_ads *ads; |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 1087 | struct guc_policies *policies; |
Alex Dai | 5c148e0 | 2015-12-18 12:00:11 -0800 | [diff] [blame] | 1088 | struct guc_mmio_reg_state *reg_state; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 1089 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1090 | enum intel_engine_id id; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1091 | struct page *page; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 1092 | u32 size; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1093 | |
| 1094 | /* The ads obj includes the struct itself and buffers passed to GuC */ |
Alex Dai | 5c148e0 | 2015-12-18 12:00:11 -0800 | [diff] [blame] | 1095 | size = sizeof(struct guc_ads) + sizeof(struct guc_policies) + |
| 1096 | sizeof(struct guc_mmio_reg_state) + |
| 1097 | GUC_S3_SAVE_SPACE_PAGES * PAGE_SIZE; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1098 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1099 | vma = guc->ads_vma; |
| 1100 | if (!vma) { |
| 1101 | vma = guc_allocate_vma(guc, PAGE_ALIGN(size)); |
| 1102 | if (IS_ERR(vma)) |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1103 | return; |
| 1104 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1105 | guc->ads_vma = vma; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1106 | } |
| 1107 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1108 | page = i915_vma_first_page(vma); |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1109 | ads = kmap(page); |
| 1110 | |
| 1111 | /* |
| 1112 | * The GuC requires a "Golden Context" when it reinitialises |
| 1113 | * engines after a reset. Here we use the Render ring default |
| 1114 | * context, which must already exist and be pinned in the GGTT, |
| 1115 | * so its address won't change after we've told the GuC where |
| 1116 | * to find it. |
| 1117 | */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1118 | engine = dev_priv->engine[RCS]; |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1119 | ads->golden_context_lrca = engine->status_page.ggtt_offset; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1120 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1121 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 1122 | ads->eng_state_size[engine->guc_id] = intel_lr_context_size(engine); |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1123 | |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 1124 | /* GuC scheduling policies */ |
| 1125 | policies = (void *)ads + sizeof(struct guc_ads); |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1126 | guc_policies_init(policies); |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 1127 | |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1128 | ads->scheduler_policies = |
| 1129 | i915_ggtt_offset(vma) + sizeof(struct guc_ads); |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 1130 | |
Alex Dai | 5c148e0 | 2015-12-18 12:00:11 -0800 | [diff] [blame] | 1131 | /* MMIO reg state */ |
| 1132 | reg_state = (void *)policies + sizeof(struct guc_policies); |
| 1133 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1134 | for_each_engine(engine, dev_priv, id) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 1135 | reg_state->mmio_white_list[engine->guc_id].mmio_start = |
| 1136 | engine->mmio_base + GUC_MMIO_WHITE_LIST_START; |
Alex Dai | 5c148e0 | 2015-12-18 12:00:11 -0800 | [diff] [blame] | 1137 | |
| 1138 | /* Nothing to be saved or restored for now. */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 1139 | reg_state->mmio_white_list[engine->guc_id].count = 0; |
Alex Dai | 5c148e0 | 2015-12-18 12:00:11 -0800 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | ads->reg_state_addr = ads->scheduler_policies + |
| 1143 | sizeof(struct guc_policies); |
| 1144 | |
| 1145 | ads->reg_state_buffer = ads->reg_state_addr + |
| 1146 | sizeof(struct guc_mmio_reg_state); |
| 1147 | |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1148 | kunmap(page); |
| 1149 | } |
| 1150 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1151 | /* |
| 1152 | * Set up the memory resources to be shared with the GuC. At this point, |
| 1153 | * we require just one object that can be mapped through the GGTT. |
| 1154 | */ |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1155 | int i915_guc_submission_init(struct drm_i915_private *dev_priv) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1156 | { |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1157 | const size_t ctxsize = sizeof(struct guc_context_desc); |
| 1158 | const size_t poolsize = GUC_MAX_GPU_CONTEXTS * ctxsize; |
| 1159 | const size_t gemsize = round_up(poolsize, PAGE_SIZE); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1160 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1161 | struct i915_vma *vma; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1162 | |
Dave Gordon | 29fb72c | 2016-06-07 09:14:50 +0100 | [diff] [blame] | 1163 | /* Wipe bitmap & delete client in case of reinitialisation */ |
| 1164 | bitmap_clear(guc->doorbell_bitmap, 0, GUC_MAX_DOORBELLS); |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1165 | i915_guc_submission_disable(dev_priv); |
Dave Gordon | 29fb72c | 2016-06-07 09:14:50 +0100 | [diff] [blame] | 1166 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1167 | if (!i915.enable_guc_submission) |
| 1168 | return 0; /* not enabled */ |
| 1169 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1170 | if (guc->ctx_pool_vma) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1171 | return 0; /* already allocated */ |
| 1172 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1173 | vma = guc_allocate_vma(guc, gemsize); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1174 | if (IS_ERR(vma)) |
| 1175 | return PTR_ERR(vma); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1176 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1177 | guc->ctx_pool_vma = vma; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1178 | ida_init(&guc->ctx_ids); |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1179 | guc_log_create(guc); |
| 1180 | guc_addon_create(guc); |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1181 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1185 | int i915_guc_submission_enable(struct drm_i915_private *dev_priv) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1186 | { |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1187 | struct intel_guc *guc = &dev_priv->guc; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1188 | struct drm_i915_gem_request *request; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1189 | struct i915_guc_client *client; |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1190 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1191 | enum intel_engine_id id; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1192 | |
| 1193 | /* client for execbuf submission */ |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 1194 | client = guc_client_alloc(dev_priv, |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 1195 | INTEL_INFO(dev_priv)->ring_mask, |
Chris Wilson | 0ca5fa3 | 2016-05-24 14:53:40 +0100 | [diff] [blame] | 1196 | GUC_CTX_PRIORITY_KMD_NORMAL, |
| 1197 | dev_priv->kernel_context); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1198 | if (!client) { |
Dave Gordon | 535b2f5 | 2016-08-18 18:17:23 +0100 | [diff] [blame] | 1199 | DRM_ERROR("Failed to create normal GuC client!\n"); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1200 | return -ENOMEM; |
| 1201 | } |
| 1202 | |
| 1203 | guc->execbuf_client = client; |
Alex Dai | f5d3c3e | 2015-08-18 14:34:47 -0700 | [diff] [blame] | 1204 | host2guc_sample_forcewake(guc, client); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 1205 | guc_init_doorbell_hw(guc); |
Alex Dai | f5d3c3e | 2015-08-18 14:34:47 -0700 | [diff] [blame] | 1206 | |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1207 | /* Take over from manual control of ELSP (execlists) */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1208 | for_each_engine(engine, dev_priv, id) { |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1209 | engine->submit_request = i915_guc_submit; |
| 1210 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1211 | /* Replay the current set of previously submitted requests */ |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 1212 | list_for_each_entry(request, &engine->request_list, link) { |
| 1213 | client->wq_rsvd += sizeof(struct guc_wq_item); |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 1214 | if (i915_sw_fence_done(&request->submit)) |
| 1215 | i915_guc_submit(request); |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 1216 | } |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1219 | return 0; |
| 1220 | } |
| 1221 | |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1222 | void i915_guc_submission_disable(struct drm_i915_private *dev_priv) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1223 | { |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1224 | struct intel_guc *guc = &dev_priv->guc; |
| 1225 | |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1226 | if (!guc->execbuf_client) |
| 1227 | return; |
| 1228 | |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1229 | /* Revert back to manual ELSP submission */ |
| 1230 | intel_execlists_enable_submission(dev_priv); |
Chris Wilson | f4ea6bd | 2016-08-02 22:50:32 +0100 | [diff] [blame] | 1231 | |
| 1232 | guc_client_free(dev_priv, guc->execbuf_client); |
| 1233 | guc->execbuf_client = NULL; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1234 | } |
| 1235 | |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1236 | void i915_guc_submission_fini(struct drm_i915_private *dev_priv) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1237 | { |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1238 | struct intel_guc *guc = &dev_priv->guc; |
| 1239 | |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 1240 | i915_vma_unpin_and_release(&guc->ads_vma); |
Sagar Arun Kamble | 4100b2a | 2016-10-12 21:54:32 +0530 | [diff] [blame^] | 1241 | guc_log_cleanup(guc); |
Akash Goel | d6b40b4 | 2016-10-12 21:54:29 +0530 | [diff] [blame] | 1242 | i915_vma_unpin_and_release(&guc->log.vma); |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1243 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1244 | if (guc->ctx_pool_vma) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1245 | ida_destroy(&guc->ctx_ids); |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 1246 | i915_vma_unpin_and_release(&guc->ctx_pool_vma); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1247 | } |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1248 | |
| 1249 | /** |
| 1250 | * intel_guc_suspend() - notify GuC entering suspend state |
| 1251 | * @dev: drm device |
| 1252 | */ |
| 1253 | int intel_guc_suspend(struct drm_device *dev) |
| 1254 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1255 | struct drm_i915_private *dev_priv = to_i915(dev); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1256 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 1257 | struct i915_gem_context *ctx; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1258 | u32 data[3]; |
| 1259 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 1260 | if (guc->guc_fw.guc_fw_load_status != GUC_FIRMWARE_SUCCESS) |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1261 | return 0; |
| 1262 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame] | 1263 | gen9_disable_guc_interrupts(dev_priv); |
| 1264 | |
Dave Gordon | ed54c1a | 2016-01-19 19:02:54 +0000 | [diff] [blame] | 1265 | ctx = dev_priv->kernel_context; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1266 | |
| 1267 | data[0] = HOST2GUC_ACTION_ENTER_S_STATE; |
| 1268 | /* any value greater than GUC_POWER_D0 */ |
| 1269 | data[1] = GUC_POWER_D1; |
| 1270 | /* first page is shared data with GuC */ |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1271 | data[2] = i915_ggtt_offset(ctx->engine[RCS].state); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1272 | |
| 1273 | return host2guc_action(guc, data, ARRAY_SIZE(data)); |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | /** |
| 1278 | * intel_guc_resume() - notify GuC resuming from suspend state |
| 1279 | * @dev: drm device |
| 1280 | */ |
| 1281 | int intel_guc_resume(struct drm_device *dev) |
| 1282 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1283 | struct drm_i915_private *dev_priv = to_i915(dev); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1284 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 1285 | struct i915_gem_context *ctx; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1286 | u32 data[3]; |
| 1287 | |
Dave Gordon | fce91f2 | 2016-05-20 11:42:42 +0100 | [diff] [blame] | 1288 | if (guc->guc_fw.guc_fw_load_status != GUC_FIRMWARE_SUCCESS) |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1289 | return 0; |
| 1290 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame] | 1291 | if (i915.guc_log_level >= 0) |
| 1292 | gen9_enable_guc_interrupts(dev_priv); |
| 1293 | |
Dave Gordon | ed54c1a | 2016-01-19 19:02:54 +0000 | [diff] [blame] | 1294 | ctx = dev_priv->kernel_context; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1295 | |
| 1296 | data[0] = HOST2GUC_ACTION_EXIT_S_STATE; |
| 1297 | data[1] = GUC_POWER_D0; |
| 1298 | /* first page is shared data with GuC */ |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1299 | data[2] = i915_ggtt_offset(ctx->engine[RCS].state); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1300 | |
| 1301 | return host2guc_action(guc, data, ARRAY_SIZE(data)); |
| 1302 | } |
Sagar Arun Kamble | 4100b2a | 2016-10-12 21:54:32 +0530 | [diff] [blame^] | 1303 | |
| 1304 | void i915_guc_capture_logs(struct drm_i915_private *dev_priv) |
| 1305 | { |
| 1306 | guc_read_update_log_buffer(&dev_priv->guc); |
| 1307 | |
| 1308 | /* Generally device is expected to be active only at this |
| 1309 | * time, so get/put should be really quick. |
| 1310 | */ |
| 1311 | intel_runtime_pm_get(dev_priv); |
| 1312 | host2guc_logbuffer_flush_complete(&dev_priv->guc); |
| 1313 | intel_runtime_pm_put(dev_priv); |
| 1314 | } |