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