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 | */ |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 24 | #include <linux/circ_buf.h> |
| 25 | #include "i915_drv.h" |
Arkadiusz Hiler | 8c4f24f | 2016-11-25 18:59:33 +0100 | [diff] [blame] | 26 | #include "intel_uc.h" |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 27 | |
Chris Wilson | 31de735 | 2017-03-16 12:56:18 +0000 | [diff] [blame] | 28 | #include <trace/events/dma_fence.h> |
| 29 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 30 | /** |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 31 | * DOC: GuC-based command submission |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 32 | * |
| 33 | * i915_guc_client: |
| 34 | * We use the term client to avoid confusion with contexts. A i915_guc_client is |
| 35 | * equivalent to GuC object guc_context_desc. This context descriptor is |
| 36 | * allocated from a pool of 1024 entries. Kernel driver will allocate doorbell |
| 37 | * and workqueue for it. Also the process descriptor (guc_process_desc), which |
| 38 | * is mapped to client space. So the client can write Work Item then ring the |
| 39 | * doorbell. |
| 40 | * |
| 41 | * To simplify the implementation, we allocate one gem object that contains all |
| 42 | * pages for doorbell, process descriptor and workqueue. |
| 43 | * |
| 44 | * The Scratch registers: |
| 45 | * There are 16 MMIO-based registers start from 0xC180. The kernel driver writes |
| 46 | * a value to the action register (SOFT_SCRATCH_0) along with any data. It then |
| 47 | * triggers an interrupt on the GuC via another register write (0xC4C8). |
| 48 | * Firmware writes a success/fail code back to the action register after |
| 49 | * processes the request. The kernel driver polls waiting for this update and |
| 50 | * then proceeds. |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 51 | * See intel_guc_send() |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 52 | * |
| 53 | * Doorbells: |
| 54 | * Doorbells are interrupts to uKernel. A doorbell is a single cache line (QW) |
| 55 | * mapped into process space. |
| 56 | * |
| 57 | * Work Items: |
| 58 | * There are several types of work items that the host may place into a |
| 59 | * workqueue, each with its own requirements and limitations. Currently only |
| 60 | * WQ_TYPE_INORDER is needed to support legacy submission via GuC, which |
| 61 | * represents in-order queue. The kernel driver packs ring tail pointer and an |
| 62 | * ELSP context descriptor dword into Work Item. |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 63 | * See guc_wq_item_append() |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 64 | * |
| 65 | */ |
| 66 | |
| 67 | /* |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 68 | * Tell the GuC to allocate or deallocate a specific doorbell |
| 69 | */ |
| 70 | |
Arkadiusz Hiler | a80bc45 | 2016-11-25 18:59:34 +0100 | [diff] [blame] | 71 | static int guc_allocate_doorbell(struct intel_guc *guc, |
| 72 | struct i915_guc_client *client) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 73 | { |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 74 | u32 action[] = { |
| 75 | INTEL_GUC_ACTION_ALLOCATE_DOORBELL, |
| 76 | client->ctx_index |
| 77 | }; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 78 | |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 79 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Arkadiusz Hiler | a80bc45 | 2016-11-25 18:59:34 +0100 | [diff] [blame] | 82 | static int guc_release_doorbell(struct intel_guc *guc, |
| 83 | struct i915_guc_client *client) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 84 | { |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 85 | u32 action[] = { |
| 86 | INTEL_GUC_ACTION_DEALLOCATE_DOORBELL, |
| 87 | client->ctx_index |
| 88 | }; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 89 | |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 90 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
Sagar Arun Kamble | 685534e | 2016-10-12 21:54:41 +0530 | [diff] [blame] | 91 | } |
| 92 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 93 | /* |
| 94 | * Initialise, update, or clear doorbell data shared with the GuC |
| 95 | * |
| 96 | * These functions modify shared data and so need access to the mapped |
| 97 | * client object which contains the page being used for the doorbell |
| 98 | */ |
| 99 | |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 100 | static int guc_update_doorbell_id(struct intel_guc *guc, |
| 101 | struct i915_guc_client *client, |
| 102 | u16 new_id) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 103 | { |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 104 | struct sg_table *sg = guc->ctx_pool_vma->pages; |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 105 | void *doorbell_bitmap = guc->doorbell_bitmap; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 106 | struct guc_doorbell_info *doorbell; |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 107 | struct guc_context_desc desc; |
| 108 | size_t len; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 109 | |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 110 | doorbell = client->vaddr + client->doorbell_offset; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 111 | |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 112 | if (client->doorbell_id != GUC_INVALID_DOORBELL_ID && |
| 113 | test_bit(client->doorbell_id, doorbell_bitmap)) { |
| 114 | /* Deactivate the old doorbell */ |
| 115 | doorbell->db_status = GUC_DOORBELL_DISABLED; |
Arkadiusz Hiler | a80bc45 | 2016-11-25 18:59:34 +0100 | [diff] [blame] | 116 | (void)guc_release_doorbell(guc, client); |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 117 | __clear_bit(client->doorbell_id, doorbell_bitmap); |
| 118 | } |
| 119 | |
| 120 | /* Update the GuC's idea of the doorbell ID */ |
| 121 | len = sg_pcopy_to_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 122 | sizeof(desc) * client->ctx_index); |
| 123 | if (len != sizeof(desc)) |
| 124 | return -EFAULT; |
| 125 | desc.db_id = new_id; |
| 126 | len = sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 127 | sizeof(desc) * client->ctx_index); |
| 128 | if (len != sizeof(desc)) |
| 129 | return -EFAULT; |
| 130 | |
| 131 | client->doorbell_id = new_id; |
| 132 | if (new_id == GUC_INVALID_DOORBELL_ID) |
| 133 | return 0; |
| 134 | |
| 135 | /* Activate the new doorbell */ |
| 136 | __set_bit(new_id, doorbell_bitmap); |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 137 | doorbell->db_status = GUC_DOORBELL_ENABLED; |
Chris Wilson | 597bdc8 | 2016-11-29 12:10:22 +0000 | [diff] [blame] | 138 | doorbell->cookie = client->doorbell_cookie; |
Arkadiusz Hiler | a80bc45 | 2016-11-25 18:59:34 +0100 | [diff] [blame] | 139 | return guc_allocate_doorbell(guc, client); |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 142 | static void guc_disable_doorbell(struct intel_guc *guc, |
| 143 | struct i915_guc_client *client) |
| 144 | { |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 145 | (void)guc_update_doorbell_id(guc, client, GUC_INVALID_DOORBELL_ID); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 146 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 147 | /* XXX: wait for any interrupts */ |
| 148 | /* XXX: wait for workqueue to drain */ |
| 149 | } |
| 150 | |
Dave Gordon | f10d69a | 2016-06-13 17:57:33 +0100 | [diff] [blame] | 151 | static uint16_t |
| 152 | select_doorbell_register(struct intel_guc *guc, uint32_t priority) |
| 153 | { |
| 154 | /* |
| 155 | * The bitmap tracks which doorbell registers are currently in use. |
| 156 | * It is split into two halves; the first half is used for normal |
| 157 | * priority contexts, the second half for high-priority ones. |
| 158 | * Note that logically higher priorities are numerically less than |
| 159 | * normal ones, so the test below means "is it high-priority?" |
| 160 | */ |
| 161 | const bool hi_pri = (priority <= GUC_CTX_PRIORITY_HIGH); |
| 162 | const uint16_t half = GUC_MAX_DOORBELLS / 2; |
| 163 | const uint16_t start = hi_pri ? half : 0; |
| 164 | const uint16_t end = start + half; |
| 165 | uint16_t id; |
| 166 | |
| 167 | id = find_next_zero_bit(guc->doorbell_bitmap, end, start); |
| 168 | if (id == end) |
| 169 | id = GUC_INVALID_DOORBELL_ID; |
| 170 | |
| 171 | DRM_DEBUG_DRIVER("assigned %s priority doorbell id 0x%x\n", |
| 172 | hi_pri ? "high" : "normal", id); |
| 173 | |
| 174 | return id; |
| 175 | } |
| 176 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 177 | /* |
| 178 | * Select, assign and relase doorbell cachelines |
| 179 | * |
| 180 | * These functions track which doorbell cachelines are in use. |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 181 | * The data they manipulate is protected by the intel_guc_send lock. |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 182 | */ |
| 183 | |
| 184 | static uint32_t select_doorbell_cacheline(struct intel_guc *guc) |
| 185 | { |
| 186 | const uint32_t cacheline_size = cache_line_size(); |
| 187 | uint32_t offset; |
| 188 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 189 | /* Doorbell uses a single cache line within a page */ |
| 190 | offset = offset_in_page(guc->db_cacheline); |
| 191 | |
| 192 | /* Moving to next cache line to reduce contention */ |
| 193 | guc->db_cacheline += cacheline_size; |
| 194 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 195 | DRM_DEBUG_DRIVER("selected doorbell cacheline 0x%x, next 0x%x, linesize %u\n", |
| 196 | offset, guc->db_cacheline, cacheline_size); |
| 197 | |
| 198 | return offset; |
| 199 | } |
| 200 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 201 | /* |
| 202 | * Initialise the process descriptor shared with the GuC firmware. |
| 203 | */ |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 204 | static void guc_proc_desc_init(struct intel_guc *guc, |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 205 | struct i915_guc_client *client) |
| 206 | { |
| 207 | struct guc_process_desc *desc; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 208 | |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 209 | desc = client->vaddr + client->proc_desc_offset; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 210 | |
| 211 | memset(desc, 0, sizeof(*desc)); |
| 212 | |
| 213 | /* |
| 214 | * XXX: pDoorbell and WQVBaseAddress are pointers in process address |
| 215 | * space for ring3 clients (set them as in mmap_ioctl) or kernel |
| 216 | * space for kernel clients (map on demand instead? May make debug |
| 217 | * easier to have it mapped). |
| 218 | */ |
| 219 | desc->wq_base_addr = 0; |
| 220 | desc->db_base_addr = 0; |
| 221 | |
| 222 | desc->context_id = client->ctx_index; |
| 223 | desc->wq_size_bytes = client->wq_size; |
| 224 | desc->wq_status = WQ_STATUS_ACTIVE; |
| 225 | desc->priority = client->priority; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Initialise/clear the context descriptor shared with the GuC firmware. |
| 230 | * |
| 231 | * This descriptor tells the GuC where (in GGTT space) to find the important |
| 232 | * data structures relating to this client (doorbell, process descriptor, |
| 233 | * write queue, etc). |
| 234 | */ |
| 235 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 236 | static void guc_ctx_desc_init(struct intel_guc *guc, |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 237 | struct i915_guc_client *client) |
| 238 | { |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 239 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 240 | struct intel_engine_cs *engine; |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 241 | struct i915_gem_context *ctx = client->owner; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 242 | struct guc_context_desc desc; |
| 243 | struct sg_table *sg; |
Chris Wilson | bafb0fc | 2016-08-27 08:54:01 +0100 | [diff] [blame] | 244 | unsigned int tmp; |
Dave Gordon | 86e06cc | 2016-04-19 16:08:36 +0100 | [diff] [blame] | 245 | u32 gfx_addr; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 246 | |
| 247 | memset(&desc, 0, sizeof(desc)); |
| 248 | |
| 249 | desc.attribute = GUC_CTX_DESC_ATTR_ACTIVE | GUC_CTX_DESC_ATTR_KERNEL; |
| 250 | desc.context_id = client->ctx_index; |
| 251 | desc.priority = client->priority; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 252 | desc.db_id = client->doorbell_id; |
| 253 | |
Chris Wilson | bafb0fc | 2016-08-27 08:54:01 +0100 | [diff] [blame] | 254 | for_each_engine_masked(engine, dev_priv, client->engines, tmp) { |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 255 | struct intel_context *ce = &ctx->engine[engine->id]; |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 256 | uint32_t guc_engine_id = engine->guc_id; |
| 257 | struct guc_execlist_context *lrc = &desc.lrc[guc_engine_id]; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 258 | |
| 259 | /* TODO: We have a design issue to be solved here. Only when we |
| 260 | * receive the first batch, we know which engine is used by the |
| 261 | * user. But here GuC expects the lrc and ring to be pinned. It |
| 262 | * is not an issue for default context, which is the only one |
| 263 | * for now who owns a GuC client. But for future owner of GuC |
| 264 | * client, need to make sure lrc is pinned prior to enter here. |
| 265 | */ |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 266 | if (!ce->state) |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 267 | break; /* XXX: continue? */ |
| 268 | |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 269 | lrc->context_desc = lower_32_bits(ce->lrc_desc); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 270 | |
| 271 | /* The state page is after PPHWSP */ |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 272 | lrc->ring_lcra = |
Chris Wilson | 4741da9 | 2016-12-24 19:31:46 +0000 | [diff] [blame] | 273 | guc_ggtt_offset(ce->state) + LRC_STATE_PN * PAGE_SIZE; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 274 | lrc->context_id = (client->ctx_index << GUC_ELC_CTXID_OFFSET) | |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 275 | (guc_engine_id << GUC_ELC_ENGINE_OFFSET); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 276 | |
Chris Wilson | 4741da9 | 2016-12-24 19:31:46 +0000 | [diff] [blame] | 277 | lrc->ring_begin = guc_ggtt_offset(ce->ring->vma); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 278 | lrc->ring_end = lrc->ring_begin + ce->ring->size - 1; |
| 279 | lrc->ring_next_free_location = lrc->ring_begin; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 280 | lrc->ring_current_tail_pointer_value = 0; |
| 281 | |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 282 | desc.engines_used |= (1 << guc_engine_id); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 285 | DRM_DEBUG_DRIVER("Host engines 0x%x => GuC engines used 0x%x\n", |
| 286 | client->engines, desc.engines_used); |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 287 | WARN_ON(desc.engines_used == 0); |
| 288 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 289 | /* |
Dave Gordon | 86e06cc | 2016-04-19 16:08:36 +0100 | [diff] [blame] | 290 | * The doorbell, process descriptor, and workqueue are all parts |
| 291 | * of the client object, which the GuC will reference via the GGTT |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 292 | */ |
Chris Wilson | 4741da9 | 2016-12-24 19:31:46 +0000 | [diff] [blame] | 293 | gfx_addr = guc_ggtt_offset(client->vma); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 294 | desc.db_trigger_phy = sg_dma_address(client->vma->pages->sgl) + |
Dave Gordon | 86e06cc | 2016-04-19 16:08:36 +0100 | [diff] [blame] | 295 | client->doorbell_offset; |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 296 | desc.db_trigger_cpu = |
| 297 | (uintptr_t)client->vaddr + client->doorbell_offset; |
Dave Gordon | 86e06cc | 2016-04-19 16:08:36 +0100 | [diff] [blame] | 298 | desc.db_trigger_uk = gfx_addr + client->doorbell_offset; |
| 299 | desc.process_desc = gfx_addr + client->proc_desc_offset; |
| 300 | desc.wq_addr = gfx_addr + client->wq_offset; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 301 | desc.wq_size = client->wq_size; |
| 302 | |
| 303 | /* |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 304 | * XXX: Take LRCs from an existing context if this is not an |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 305 | * IsKMDCreatedContext client |
| 306 | */ |
| 307 | desc.desc_private = (uintptr_t)client; |
| 308 | |
| 309 | /* Pool context is pinned already */ |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 310 | sg = guc->ctx_pool_vma->pages; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 311 | sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 312 | sizeof(desc) * client->ctx_index); |
| 313 | } |
| 314 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 315 | static void guc_ctx_desc_fini(struct intel_guc *guc, |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 316 | struct i915_guc_client *client) |
| 317 | { |
| 318 | struct guc_context_desc desc; |
| 319 | struct sg_table *sg; |
| 320 | |
| 321 | memset(&desc, 0, sizeof(desc)); |
| 322 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 323 | sg = guc->ctx_pool_vma->pages; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 324 | sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), |
| 325 | sizeof(desc) * client->ctx_index); |
| 326 | } |
| 327 | |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 328 | /** |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 329 | * i915_guc_wq_reserve() - reserve space in the GuC's workqueue |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 330 | * @request: request associated with the commands |
| 331 | * |
| 332 | * Return: 0 if space is available |
| 333 | * -EAGAIN if space is not currently available |
| 334 | * |
| 335 | * This function must be called (and must return 0) before a request |
| 336 | * 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] | 337 | * of 0 has been returned, it must be balanced by a corresponding |
| 338 | * call to submit(). |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 339 | * |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 340 | * Reservation allows the caller to determine in advance that space |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 341 | * will be available for the next submission before committing resources |
| 342 | * to it, and helps avoid late failures with complicated recovery paths. |
| 343 | */ |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 344 | int i915_guc_wq_reserve(struct drm_i915_gem_request *request) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 345 | { |
Dave Gordon | 551aaec | 2016-05-13 15:36:33 +0100 | [diff] [blame] | 346 | const size_t wqi_size = sizeof(struct guc_wq_item); |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 347 | struct i915_guc_client *client = request->i915->guc.execbuf_client; |
| 348 | struct guc_process_desc *desc = client->vaddr + |
| 349 | client->proc_desc_offset; |
Dave Gordon | 551aaec | 2016-05-13 15:36:33 +0100 | [diff] [blame] | 350 | u32 freespace; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 351 | int ret; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 352 | |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 353 | spin_lock_irq(&client->wq_lock); |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 354 | freespace = CIRC_SPACE(client->wq_tail, desc->head, client->wq_size); |
| 355 | freespace -= client->wq_rsvd; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 356 | if (likely(freespace >= wqi_size)) { |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 357 | client->wq_rsvd += wqi_size; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 358 | ret = 0; |
| 359 | } else { |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 360 | client->no_wq_space++; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 361 | ret = -EAGAIN; |
| 362 | } |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 363 | spin_unlock_irq(&client->wq_lock); |
Alex Dai | 5a84330 | 2015-12-02 16:56:29 -0800 | [diff] [blame] | 364 | |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 365 | return ret; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 366 | } |
| 367 | |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 368 | static void guc_client_update_wq_rsvd(struct i915_guc_client *client, int size) |
| 369 | { |
| 370 | unsigned long flags; |
| 371 | |
| 372 | spin_lock_irqsave(&client->wq_lock, flags); |
| 373 | client->wq_rsvd += size; |
| 374 | spin_unlock_irqrestore(&client->wq_lock, flags); |
| 375 | } |
| 376 | |
Chris Wilson | 5ba8990 | 2016-10-07 07:53:27 +0100 | [diff] [blame] | 377 | void i915_guc_wq_unreserve(struct drm_i915_gem_request *request) |
| 378 | { |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 379 | const int wqi_size = sizeof(struct guc_wq_item); |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 380 | struct i915_guc_client *client = request->i915->guc.execbuf_client; |
Chris Wilson | 5ba8990 | 2016-10-07 07:53:27 +0100 | [diff] [blame] | 381 | |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 382 | GEM_BUG_ON(READ_ONCE(client->wq_rsvd) < wqi_size); |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 383 | guc_client_update_wq_rsvd(client, -wqi_size); |
Chris Wilson | 5ba8990 | 2016-10-07 07:53:27 +0100 | [diff] [blame] | 384 | } |
| 385 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 386 | /* Construct a Work Item and append it to the GuC's Work Queue */ |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 387 | static void guc_wq_item_append(struct i915_guc_client *client, |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 388 | struct drm_i915_gem_request *rq) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 389 | { |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 390 | /* wqi_len is in DWords, and does not include the one-word header */ |
| 391 | const size_t wqi_size = sizeof(struct guc_wq_item); |
| 392 | const u32 wqi_len = wqi_size/sizeof(u32) - 1; |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 393 | struct intel_engine_cs *engine = rq->engine; |
Alex Dai | a5916e8 | 2016-04-19 16:08:35 +0100 | [diff] [blame] | 394 | struct guc_process_desc *desc; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 395 | struct guc_wq_item *wqi; |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 396 | u32 freespace, tail, wq_off; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 397 | |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 398 | desc = client->vaddr + client->proc_desc_offset; |
Alex Dai | a7e0219 | 2015-12-16 11:45:55 -0800 | [diff] [blame] | 399 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 400 | /* Free space is guaranteed, see i915_guc_wq_reserve() above */ |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 401 | freespace = CIRC_SPACE(client->wq_tail, desc->head, client->wq_size); |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 402 | GEM_BUG_ON(freespace < wqi_size); |
| 403 | |
| 404 | /* The GuC firmware wants the tail index in QWords, not bytes */ |
| 405 | tail = rq->tail; |
| 406 | GEM_BUG_ON(tail & 7); |
| 407 | tail >>= 3; |
| 408 | GEM_BUG_ON(tail > WQ_RING_TAIL_MAX); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 409 | |
| 410 | /* For now workqueue item is 4 DWs; workqueue buffer is 2 pages. So we |
| 411 | * should not have the case where structure wqi is across page, neither |
| 412 | * wrapped to the beginning. This simplifies the implementation below. |
| 413 | * |
| 414 | * XXX: if not the case, we need save data to a temp wqi and copy it to |
| 415 | * workqueue buffer dw by dw. |
| 416 | */ |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 417 | BUILD_BUG_ON(wqi_size != 16); |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 418 | GEM_BUG_ON(client->wq_rsvd < wqi_size); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 419 | |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 420 | /* postincrement WQ tail for next time */ |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 421 | wq_off = client->wq_tail; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 422 | GEM_BUG_ON(wq_off & (wqi_size - 1)); |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 423 | client->wq_tail += wqi_size; |
| 424 | client->wq_tail &= client->wq_size - 1; |
| 425 | client->wq_rsvd -= wqi_size; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 426 | |
| 427 | /* WQ starts from the page after doorbell / process_desc */ |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 428 | wqi = client->vaddr + wq_off + GUC_DB_SIZE; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 429 | |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 430 | /* Now fill in the 4-word work queue item */ |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 431 | wqi->header = WQ_TYPE_INORDER | |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 432 | (wqi_len << WQ_LEN_SHIFT) | |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 433 | (engine->guc_id << WQ_TARGET_SHIFT) | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 434 | WQ_NO_WCFLUSH_WAIT; |
| 435 | |
| 436 | /* The GuC wants only the low-order word of the context descriptor */ |
Dave Gordon | c18468c | 2016-08-09 15:19:22 +0100 | [diff] [blame] | 437 | wqi->context_desc = (u32)intel_lr_context_descriptor(rq->ctx, engine); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 438 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 439 | wqi->ring_tail = tail << WQ_RING_TAIL_SHIFT; |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 440 | wqi->fence_id = rq->global_seqno; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 441 | } |
| 442 | |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 443 | static int guc_ring_doorbell(struct i915_guc_client *client) |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 444 | { |
| 445 | struct guc_process_desc *desc; |
| 446 | union guc_doorbell_qw db_cmp, db_exc, db_ret; |
| 447 | union guc_doorbell_qw *db; |
| 448 | int attempt = 2, ret = -EAGAIN; |
| 449 | |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 450 | desc = client->vaddr + client->proc_desc_offset; |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 451 | |
| 452 | /* Update the tail so it is visible to GuC */ |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 453 | desc->tail = client->wq_tail; |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 454 | |
| 455 | /* current cookie */ |
| 456 | db_cmp.db_status = GUC_DOORBELL_ENABLED; |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 457 | db_cmp.cookie = client->doorbell_cookie; |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 458 | |
| 459 | /* cookie to be updated */ |
| 460 | db_exc.db_status = GUC_DOORBELL_ENABLED; |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 461 | db_exc.cookie = client->doorbell_cookie + 1; |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 462 | if (db_exc.cookie == 0) |
| 463 | db_exc.cookie = 1; |
| 464 | |
| 465 | /* pointer of current doorbell cacheline */ |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 466 | db = client->vaddr + client->doorbell_offset; |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 467 | |
| 468 | while (attempt--) { |
| 469 | /* lets ring the doorbell */ |
| 470 | db_ret.value_qw = atomic64_cmpxchg((atomic64_t *)db, |
| 471 | db_cmp.value_qw, db_exc.value_qw); |
| 472 | |
| 473 | /* if the exchange was successfully executed */ |
| 474 | if (db_ret.value_qw == db_cmp.value_qw) { |
| 475 | /* db was successfully rung */ |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 476 | client->doorbell_cookie = db_exc.cookie; |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 477 | ret = 0; |
| 478 | break; |
| 479 | } |
| 480 | |
| 481 | /* XXX: doorbell was lost and need to acquire it again */ |
| 482 | if (db_ret.db_status == GUC_DOORBELL_DISABLED) |
| 483 | break; |
| 484 | |
Dave Gordon | 535b2f5 | 2016-08-18 18:17:23 +0100 | [diff] [blame] | 485 | DRM_WARN("Cookie mismatch. Expected %d, found %d\n", |
| 486 | db_cmp.cookie, db_ret.cookie); |
Dave Gordon | 10d2c3e | 2016-06-13 17:57:31 +0100 | [diff] [blame] | 487 | |
| 488 | /* update the cookie to newly read cookie from GuC */ |
| 489 | db_cmp.cookie = db_ret.cookie; |
| 490 | db_exc.cookie = db_ret.cookie + 1; |
| 491 | if (db_exc.cookie == 0) |
| 492 | db_exc.cookie = 1; |
| 493 | } |
| 494 | |
| 495 | return ret; |
| 496 | } |
| 497 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 498 | /** |
Chris Wilson | 34ba5a8 | 2016-11-29 12:10:24 +0000 | [diff] [blame] | 499 | * __i915_guc_submit() - Submit commands through GuC |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 500 | * @rq: request associated with the commands |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 501 | * |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 502 | * The caller must have already called i915_guc_wq_reserve() above with |
| 503 | * a result of 0 (success), guaranteeing that there is space in the work |
| 504 | * queue for the new request, so enqueuing the item cannot fail. |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 505 | * |
| 506 | * 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] | 507 | * submit() when _reserve() says there's no space, or calls _submit() |
| 508 | * a different number of times from (successful) calls to _reserve(). |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 509 | * |
| 510 | * The only error here arises if the doorbell hardware isn't functioning |
| 511 | * as expected, which really shouln't happen. |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 512 | */ |
Chris Wilson | 34ba5a8 | 2016-11-29 12:10:24 +0000 | [diff] [blame] | 513 | static void __i915_guc_submit(struct drm_i915_gem_request *rq) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 514 | { |
Akash Goel | ed4596ea | 2016-10-25 22:05:23 +0530 | [diff] [blame] | 515 | struct drm_i915_private *dev_priv = rq->i915; |
Chris Wilson | d55ac5b | 2016-11-14 20:40:59 +0000 | [diff] [blame] | 516 | struct intel_engine_cs *engine = rq->engine; |
| 517 | unsigned int engine_id = engine->id; |
Dave Gordon | 7c2c270 | 2016-05-13 15:36:32 +0100 | [diff] [blame] | 518 | struct intel_guc *guc = &rq->i915->guc; |
| 519 | struct i915_guc_client *client = guc->execbuf_client; |
Chris Wilson | 25afdf89 | 2017-03-02 14:53:23 +0000 | [diff] [blame] | 520 | unsigned long flags; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 521 | int b_ret; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 522 | |
Akash Goel | ed4596ea | 2016-10-25 22:05:23 +0530 | [diff] [blame] | 523 | /* WA to flush out the pending GMADR writes to ring buffer. */ |
| 524 | if (i915_vma_is_map_and_fenceable(rq->ring->vma)) |
| 525 | POSTING_READ_FW(GUC_STATUS); |
| 526 | |
Chris Wilson | 25afdf89 | 2017-03-02 14:53:23 +0000 | [diff] [blame] | 527 | spin_lock_irqsave(&client->wq_lock, flags); |
Chris Wilson | 0c33518 | 2017-02-28 11:28:03 +0000 | [diff] [blame] | 528 | |
| 529 | guc_wq_item_append(client, rq); |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 530 | b_ret = guc_ring_doorbell(client); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 531 | |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 532 | client->submissions[engine_id] += 1; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 533 | client->retcode = b_ret; |
| 534 | if (b_ret) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 535 | client->b_fail += 1; |
Dave Gordon | 0a31afb | 2016-05-13 15:36:34 +0100 | [diff] [blame] | 536 | |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 537 | guc->submissions[engine_id] += 1; |
Chris Wilson | 65e4760 | 2016-10-28 13:58:49 +0100 | [diff] [blame] | 538 | guc->last_seqno[engine_id] = rq->global_seqno; |
Chris Wilson | 0c33518 | 2017-02-28 11:28:03 +0000 | [diff] [blame] | 539 | |
Chris Wilson | 25afdf89 | 2017-03-02 14:53:23 +0000 | [diff] [blame] | 540 | spin_unlock_irqrestore(&client->wq_lock, flags); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Chris Wilson | 34ba5a8 | 2016-11-29 12:10:24 +0000 | [diff] [blame] | 543 | static void i915_guc_submit(struct drm_i915_gem_request *rq) |
| 544 | { |
Chris Wilson | 31de735 | 2017-03-16 12:56:18 +0000 | [diff] [blame] | 545 | __i915_gem_request_submit(rq); |
Chris Wilson | 34ba5a8 | 2016-11-29 12:10:24 +0000 | [diff] [blame] | 546 | __i915_guc_submit(rq); |
| 547 | } |
| 548 | |
Chris Wilson | 31de735 | 2017-03-16 12:56:18 +0000 | [diff] [blame] | 549 | static void nested_enable_signaling(struct drm_i915_gem_request *rq) |
| 550 | { |
| 551 | /* If we use dma_fence_enable_sw_signaling() directly, lockdep |
| 552 | * detects an ordering issue between the fence lockclass and the |
| 553 | * global_timeline. This circular dependency can only occur via 2 |
| 554 | * different fences (but same fence lockclass), so we use the nesting |
| 555 | * annotation here to prevent the warn, equivalent to the nesting |
| 556 | * inside i915_gem_request_submit() for when we also enable the |
| 557 | * signaler. |
| 558 | */ |
| 559 | |
| 560 | if (test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, |
| 561 | &rq->fence.flags)) |
| 562 | return; |
| 563 | |
| 564 | GEM_BUG_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &rq->fence.flags)); |
| 565 | trace_dma_fence_enable_signal(&rq->fence); |
| 566 | |
| 567 | spin_lock_nested(&rq->lock, SINGLE_DEPTH_NESTING); |
| 568 | intel_engine_enable_signaling(rq); |
| 569 | spin_unlock(&rq->lock); |
| 570 | } |
| 571 | |
| 572 | static bool i915_guc_dequeue(struct intel_engine_cs *engine) |
| 573 | { |
| 574 | struct execlist_port *port = engine->execlist_port; |
| 575 | struct drm_i915_gem_request *last = port[0].request; |
| 576 | unsigned long flags; |
| 577 | struct rb_node *rb; |
| 578 | bool submit = false; |
| 579 | |
Chris Wilson | 6c943de | 2017-03-17 12:07:16 +0000 | [diff] [blame^] | 580 | /* After execlist_first is updated, the tasklet will be rescheduled. |
| 581 | * |
| 582 | * If we are currently running (inside the tasklet) and a third |
| 583 | * party queues a request and so updates engine->execlist_first under |
| 584 | * the spinlock (which we have elided), it will atomically set the |
| 585 | * TASKLET_SCHED flag causing the us to be re-executed and pick up |
| 586 | * the change in state (the update to TASKLET_SCHED incurs a memory |
| 587 | * barrier making this cross-cpu checking safe). |
| 588 | */ |
| 589 | if (!READ_ONCE(engine->execlist_first)) |
| 590 | return false; |
| 591 | |
Chris Wilson | 31de735 | 2017-03-16 12:56:18 +0000 | [diff] [blame] | 592 | spin_lock_irqsave(&engine->timeline->lock, flags); |
| 593 | rb = engine->execlist_first; |
| 594 | while (rb) { |
| 595 | struct drm_i915_gem_request *rq = |
| 596 | rb_entry(rb, typeof(*rq), priotree.node); |
| 597 | |
| 598 | if (last && rq->ctx != last->ctx) { |
| 599 | if (port != engine->execlist_port) |
| 600 | break; |
| 601 | |
| 602 | i915_gem_request_assign(&port->request, last); |
| 603 | nested_enable_signaling(last); |
| 604 | port++; |
| 605 | } |
| 606 | |
| 607 | rb = rb_next(rb); |
| 608 | rb_erase(&rq->priotree.node, &engine->execlist_queue); |
| 609 | RB_CLEAR_NODE(&rq->priotree.node); |
| 610 | rq->priotree.priority = INT_MAX; |
| 611 | |
| 612 | trace_i915_gem_request_in(rq, port - engine->execlist_port); |
| 613 | i915_guc_submit(rq); |
| 614 | last = rq; |
| 615 | submit = true; |
| 616 | } |
| 617 | if (submit) { |
| 618 | i915_gem_request_assign(&port->request, last); |
| 619 | nested_enable_signaling(last); |
| 620 | engine->execlist_first = rb; |
| 621 | } |
| 622 | spin_unlock_irqrestore(&engine->timeline->lock, flags); |
| 623 | |
| 624 | return submit; |
| 625 | } |
| 626 | |
| 627 | static void i915_guc_irq_handler(unsigned long data) |
| 628 | { |
| 629 | struct intel_engine_cs *engine = (struct intel_engine_cs *)data; |
| 630 | struct execlist_port *port = engine->execlist_port; |
| 631 | struct drm_i915_gem_request *rq; |
| 632 | bool submit; |
| 633 | |
| 634 | do { |
| 635 | rq = port[0].request; |
| 636 | while (rq && i915_gem_request_completed(rq)) { |
| 637 | trace_i915_gem_request_out(rq); |
| 638 | i915_gem_request_put(rq); |
| 639 | port[0].request = port[1].request; |
| 640 | port[1].request = NULL; |
| 641 | rq = port[0].request; |
| 642 | } |
| 643 | |
| 644 | submit = false; |
| 645 | if (!port[1].request) |
| 646 | submit = i915_guc_dequeue(engine); |
| 647 | } while (submit); |
| 648 | } |
| 649 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 650 | /* |
| 651 | * Everything below here is concerned with setup & teardown, and is |
| 652 | * therefore not part of the somewhat time-critical batch-submission |
| 653 | * path of i915_guc_submit() above. |
| 654 | */ |
| 655 | |
| 656 | /** |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 657 | * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 658 | * @guc: the guc |
| 659 | * @size: size of area to allocate (both virtual space and memory) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 660 | * |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 661 | * This is a wrapper to create an object for use with the GuC. In order to |
| 662 | * use it inside the GuC, an object needs to be pinned lifetime, so we allocate |
| 663 | * both some backing storage and a range inside the Global GTT. We must pin |
| 664 | * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that |
| 665 | * range is reserved inside GuC. |
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 | * Return: A i915_vma if successful, otherwise an ERR_PTR. |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 668 | */ |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 669 | struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 670 | { |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 671 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 672 | struct drm_i915_gem_object *obj; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 673 | struct i915_vma *vma; |
| 674 | int ret; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 675 | |
Tvrtko Ursulin | 12d79d7 | 2016-12-01 14:16:37 +0000 | [diff] [blame] | 676 | obj = i915_gem_object_create(dev_priv, size); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 677 | if (IS_ERR(obj)) |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 678 | return ERR_CAST(obj); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 679 | |
Chris Wilson | a01cb37 | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 680 | vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 681 | if (IS_ERR(vma)) |
| 682 | goto err; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 683 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 684 | ret = i915_vma_pin(vma, 0, PAGE_SIZE, |
| 685 | PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP); |
| 686 | if (ret) { |
| 687 | vma = ERR_PTR(ret); |
| 688 | goto err; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 691 | return vma; |
| 692 | |
| 693 | err: |
| 694 | i915_gem_object_put(obj); |
| 695 | return vma; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 696 | } |
| 697 | |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 698 | static void |
| 699 | guc_client_free(struct drm_i915_private *dev_priv, |
| 700 | struct i915_guc_client *client) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 701 | { |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 702 | struct intel_guc *guc = &dev_priv->guc; |
| 703 | |
| 704 | if (!client) |
| 705 | return; |
| 706 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 707 | /* |
| 708 | * XXX: wait for any outstanding submissions before freeing memory. |
| 709 | * Be sure to drop any locks |
| 710 | */ |
| 711 | |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 712 | if (client->vaddr) { |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 713 | /* |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 714 | * If we got as far as setting up a doorbell, make sure we |
| 715 | * shut it down before unmapping & deallocating the memory. |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 716 | */ |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 717 | guc_disable_doorbell(guc, client); |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 718 | |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 719 | i915_gem_object_unpin_map(client->vma->obj); |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 720 | } |
| 721 | |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 722 | i915_vma_unpin_and_release(&client->vma); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 723 | |
| 724 | if (client->ctx_index != GUC_INVALID_CTX_ID) { |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 725 | guc_ctx_desc_fini(guc, client); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 726 | ida_simple_remove(&guc->ctx_ids, client->ctx_index); |
| 727 | } |
| 728 | |
| 729 | kfree(client); |
| 730 | } |
| 731 | |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 732 | /* Check that a doorbell register is in the expected state */ |
| 733 | static bool guc_doorbell_check(struct intel_guc *guc, uint16_t db_id) |
| 734 | { |
| 735 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 736 | i915_reg_t drbreg = GEN8_DRBREGL(db_id); |
| 737 | uint32_t value = I915_READ(drbreg); |
| 738 | bool enabled = (value & GUC_DOORBELL_ENABLED) != 0; |
| 739 | bool expected = test_bit(db_id, guc->doorbell_bitmap); |
| 740 | |
| 741 | if (enabled == expected) |
| 742 | return true; |
| 743 | |
| 744 | DRM_DEBUG_DRIVER("Doorbell %d (reg 0x%x) 0x%x, should be %s\n", |
| 745 | db_id, drbreg.reg, value, |
| 746 | expected ? "active" : "inactive"); |
| 747 | |
| 748 | return false; |
| 749 | } |
| 750 | |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 751 | /* |
Dave Gordon | 8888cd0 | 2016-08-09 15:19:19 +0100 | [diff] [blame] | 752 | * Borrow the first client to set up & tear down each unused doorbell |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 753 | * in turn, to ensure that all doorbell h/w is (re)initialised. |
| 754 | */ |
| 755 | static void guc_init_doorbell_hw(struct intel_guc *guc) |
| 756 | { |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 757 | struct i915_guc_client *client = guc->execbuf_client; |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 758 | uint16_t db_id; |
| 759 | int i, err; |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 760 | |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 761 | guc_disable_doorbell(guc, client); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 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 | |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 774 | db_id = select_doorbell_register(guc, client->priority); |
| 775 | WARN_ON(db_id == GUC_INVALID_DOORBELL_ID); |
| 776 | |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 777 | err = guc_update_doorbell_id(guc, client, db_id); |
| 778 | if (err) |
Dave Gordon | 535b2f5 | 2016-08-18 18:17:23 +0100 | [diff] [blame] | 779 | DRM_WARN("Failed to restore doorbell to %d, err %d\n", |
| 780 | db_id, err); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 781 | |
Dave Gordon | 84b7f88 | 2016-08-09 15:19:20 +0100 | [diff] [blame] | 782 | /* Read back & verify all doorbell registers */ |
| 783 | for (i = 0; i < GUC_MAX_DOORBELLS; ++i) |
| 784 | (void)guc_doorbell_check(guc, i); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 787 | /** |
| 788 | * guc_client_alloc() - Allocate an i915_guc_client |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 789 | * @dev_priv: driver private data structure |
Chris Wilson | ceae531 | 2016-08-17 13:42:42 +0100 | [diff] [blame] | 790 | * @engines: The set of engines to enable for this client |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 791 | * @priority: four levels priority _CRITICAL, _HIGH, _NORMAL and _LOW |
| 792 | * The kernel client to replace ExecList submission is created with |
| 793 | * NORMAL priority. Priority of a client for scheduler can be HIGH, |
| 794 | * while a preemption context can use CRITICAL. |
Alex Dai | feda33e | 2015-10-19 16:10:54 -0700 | [diff] [blame] | 795 | * @ctx: the context that owns the client (we use the default render |
| 796 | * context) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 797 | * |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 798 | * Return: An i915_guc_client object if success, else NULL. |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 799 | */ |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 800 | static struct i915_guc_client * |
| 801 | guc_client_alloc(struct drm_i915_private *dev_priv, |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 802 | uint32_t engines, |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 803 | uint32_t priority, |
| 804 | struct i915_gem_context *ctx) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 805 | { |
| 806 | struct i915_guc_client *client; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 807 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 808 | struct i915_vma *vma; |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 809 | void *vaddr; |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 810 | uint16_t db_id; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 811 | |
| 812 | client = kzalloc(sizeof(*client), GFP_KERNEL); |
| 813 | if (!client) |
| 814 | return NULL; |
| 815 | |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 816 | client->owner = ctx; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 817 | client->guc = guc; |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 818 | client->engines = engines; |
| 819 | client->priority = priority; |
| 820 | client->doorbell_id = GUC_INVALID_DOORBELL_ID; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 821 | |
| 822 | client->ctx_index = (uint32_t)ida_simple_get(&guc->ctx_ids, 0, |
| 823 | GUC_MAX_GPU_CONTEXTS, GFP_KERNEL); |
| 824 | if (client->ctx_index >= GUC_MAX_GPU_CONTEXTS) { |
| 825 | client->ctx_index = GUC_INVALID_CTX_ID; |
| 826 | goto err; |
| 827 | } |
| 828 | |
| 829 | /* The first page is doorbell/proc_desc. Two followed pages are wq. */ |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 830 | vma = intel_guc_allocate_vma(guc, GUC_DB_SIZE + GUC_WQ_SIZE); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 831 | if (IS_ERR(vma)) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 832 | goto err; |
| 833 | |
Dave Gordon | 0d92a6a | 2016-04-19 16:08:34 +0100 | [diff] [blame] | 834 | /* We'll keep just the first (doorbell/proc) page permanently kmap'd. */ |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 835 | client->vma = vma; |
Chris Wilson | 72aa0d8 | 2016-11-02 17:50:47 +0000 | [diff] [blame] | 836 | |
| 837 | vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB); |
| 838 | if (IS_ERR(vaddr)) |
| 839 | goto err; |
| 840 | |
| 841 | client->vaddr = vaddr; |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 842 | |
| 843 | spin_lock_init(&client->wq_lock); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 844 | client->wq_offset = GUC_DB_SIZE; |
| 845 | client->wq_size = GUC_WQ_SIZE; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 846 | |
Dave Gordon | f10d69a | 2016-06-13 17:57:33 +0100 | [diff] [blame] | 847 | db_id = select_doorbell_register(guc, client->priority); |
| 848 | if (db_id == GUC_INVALID_DOORBELL_ID) |
| 849 | /* XXX: evict a doorbell instead? */ |
| 850 | goto err; |
| 851 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 852 | client->doorbell_offset = select_doorbell_cacheline(guc); |
| 853 | |
| 854 | /* |
| 855 | * Since the doorbell only requires a single cacheline, we can save |
| 856 | * space by putting the application process descriptor in the same |
| 857 | * page. Use the half of the page that doesn't include the doorbell. |
| 858 | */ |
| 859 | if (client->doorbell_offset >= (GUC_DB_SIZE / 2)) |
| 860 | client->proc_desc_offset = 0; |
| 861 | else |
| 862 | client->proc_desc_offset = (GUC_DB_SIZE / 2); |
| 863 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 864 | guc_proc_desc_init(guc, client); |
| 865 | guc_ctx_desc_init(guc, client); |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 866 | |
| 867 | /* For runtime client allocation we need to enable the doorbell. Not |
| 868 | * required yet for the static execbuf_client as this special kernel |
| 869 | * client is enabled from i915_guc_submission_enable(). |
| 870 | * |
| 871 | * guc_update_doorbell_id(guc, client, db_id); |
| 872 | */ |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 873 | |
Dave Gordon | e02757d | 2016-08-09 15:19:21 +0100 | [diff] [blame] | 874 | DRM_DEBUG_DRIVER("new priority %u client %p for engine(s) 0x%x: ctx_index %u\n", |
| 875 | priority, client, client->engines, client->ctx_index); |
Dave Gordon | a667429 | 2016-06-13 17:57:32 +0100 | [diff] [blame] | 876 | DRM_DEBUG_DRIVER("doorbell id %u, cacheline offset 0x%x\n", |
| 877 | client->doorbell_id, client->doorbell_offset); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 878 | |
| 879 | return client; |
| 880 | |
| 881 | err: |
Dave Gordon | 0daf556 | 2016-06-10 18:29:25 +0100 | [diff] [blame] | 882 | guc_client_free(dev_priv, client); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 883 | return NULL; |
| 884 | } |
| 885 | |
Akash Goel | f824083 | 2016-10-12 21:54:34 +0530 | [diff] [blame] | 886 | |
Akash Goel | f824083 | 2016-10-12 21:54:34 +0530 | [diff] [blame] | 887 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 888 | static void guc_policies_init(struct guc_policies *policies) |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 889 | { |
| 890 | struct guc_policy *policy; |
| 891 | u32 p, i; |
| 892 | |
| 893 | policies->dpc_promote_time = 500000; |
| 894 | policies->max_num_work_items = POLICY_MAX_NUM_WI; |
| 895 | |
| 896 | for (p = 0; p < GUC_CTX_PRIORITY_NUM; p++) { |
Alex Dai | 397097b | 2016-01-23 11:58:14 -0800 | [diff] [blame] | 897 | for (i = GUC_RENDER_ENGINE; i < GUC_MAX_ENGINES_NUM; i++) { |
Alex Dai | 463704d | 2015-12-18 12:00:10 -0800 | [diff] [blame] | 898 | policy = &policies->policy[p][i]; |
| 899 | |
| 900 | policy->execution_quantum = 1000000; |
| 901 | policy->preemption_time = 500000; |
| 902 | policy->fault_time = 250000; |
| 903 | policy->policy_flags = 0; |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | policies->is_valid = 1; |
| 908 | } |
| 909 | |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 910 | static void guc_addon_create(struct intel_guc *guc) |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 911 | { |
| 912 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 913 | struct i915_vma *vma; |
Michal Wajdeczko | 16f11f4 | 2017-03-14 13:33:09 +0000 | [diff] [blame] | 914 | struct page *page; |
| 915 | /* The ads obj includes the struct itself and buffers passed to GuC */ |
| 916 | struct { |
| 917 | struct guc_ads ads; |
| 918 | struct guc_policies policies; |
| 919 | struct guc_mmio_reg_state reg_state; |
| 920 | u8 reg_state_buffer[GUC_S3_SAVE_SPACE_PAGES * PAGE_SIZE]; |
| 921 | } __packed *blob; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 922 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 923 | enum intel_engine_id id; |
Michal Wajdeczko | 16f11f4 | 2017-03-14 13:33:09 +0000 | [diff] [blame] | 924 | u32 base; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 925 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 926 | vma = guc->ads_vma; |
| 927 | if (!vma) { |
Michal Wajdeczko | 16f11f4 | 2017-03-14 13:33:09 +0000 | [diff] [blame] | 928 | vma = intel_guc_allocate_vma(guc, PAGE_ALIGN(sizeof(*blob))); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 929 | if (IS_ERR(vma)) |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 930 | return; |
| 931 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 932 | guc->ads_vma = vma; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 935 | page = i915_vma_first_page(vma); |
Michal Wajdeczko | 16f11f4 | 2017-03-14 13:33:09 +0000 | [diff] [blame] | 936 | blob = kmap(page); |
| 937 | |
| 938 | /* GuC scheduling policies */ |
| 939 | guc_policies_init(&blob->policies); |
| 940 | |
| 941 | /* MMIO reg state */ |
| 942 | for_each_engine(engine, dev_priv, id) { |
| 943 | blob->reg_state.mmio_white_list[engine->guc_id].mmio_start = |
| 944 | engine->mmio_base + GUC_MMIO_WHITE_LIST_START; |
| 945 | |
| 946 | /* Nothing to be saved or restored for now. */ |
| 947 | blob->reg_state.mmio_white_list[engine->guc_id].count = 0; |
| 948 | } |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 949 | |
| 950 | /* |
| 951 | * The GuC requires a "Golden Context" when it reinitialises |
| 952 | * engines after a reset. Here we use the Render ring default |
| 953 | * context, which must already exist and be pinned in the GGTT, |
| 954 | * so its address won't change after we've told the GuC where |
| 955 | * to find it. |
| 956 | */ |
Michal Wajdeczko | 16f11f4 | 2017-03-14 13:33:09 +0000 | [diff] [blame] | 957 | blob->ads.golden_context_lrca = |
| 958 | dev_priv->engine[RCS]->status_page.ggtt_offset; |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 959 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 960 | for_each_engine(engine, dev_priv, id) |
Michal Wajdeczko | 16f11f4 | 2017-03-14 13:33:09 +0000 | [diff] [blame] | 961 | blob->ads.eng_state_size[engine->guc_id] = |
| 962 | intel_lr_context_size(engine); |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 963 | |
Michal Wajdeczko | 16f11f4 | 2017-03-14 13:33:09 +0000 | [diff] [blame] | 964 | base = guc_ggtt_offset(vma); |
| 965 | blob->ads.scheduler_policies = base + ptr_offset(blob, policies); |
| 966 | blob->ads.reg_state_buffer = base + ptr_offset(blob, reg_state_buffer); |
| 967 | blob->ads.reg_state_addr = base + ptr_offset(blob, reg_state); |
Alex Dai | 5c148e0 | 2015-12-18 12:00:11 -0800 | [diff] [blame] | 968 | |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 969 | kunmap(page); |
| 970 | } |
| 971 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 972 | /* |
| 973 | * Set up the memory resources to be shared with the GuC. At this point, |
| 974 | * we require just one object that can be mapped through the GGTT. |
| 975 | */ |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 976 | int i915_guc_submission_init(struct drm_i915_private *dev_priv) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 977 | { |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 978 | const size_t ctxsize = sizeof(struct guc_context_desc); |
| 979 | const size_t poolsize = GUC_MAX_GPU_CONTEXTS * ctxsize; |
| 980 | const size_t gemsize = round_up(poolsize, PAGE_SIZE); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 981 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 982 | struct i915_vma *vma; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 983 | |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 984 | if (!HAS_GUC_SCHED(dev_priv)) |
| 985 | return 0; |
| 986 | |
Dave Gordon | 29fb72c | 2016-06-07 09:14:50 +0100 | [diff] [blame] | 987 | /* Wipe bitmap & delete client in case of reinitialisation */ |
| 988 | bitmap_clear(guc->doorbell_bitmap, 0, GUC_MAX_DOORBELLS); |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 989 | i915_guc_submission_disable(dev_priv); |
Dave Gordon | 29fb72c | 2016-06-07 09:14:50 +0100 | [diff] [blame] | 990 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 991 | if (!i915.enable_guc_submission) |
| 992 | return 0; /* not enabled */ |
| 993 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 994 | if (guc->ctx_pool_vma) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 995 | return 0; /* already allocated */ |
| 996 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 997 | vma = intel_guc_allocate_vma(guc, gemsize); |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 998 | if (IS_ERR(vma)) |
| 999 | return PTR_ERR(vma); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1000 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1001 | guc->ctx_pool_vma = vma; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1002 | ida_init(&guc->ctx_ids); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 1003 | intel_guc_log_create(guc); |
Dave Gordon | 7a9347f | 2016-09-12 21:19:37 +0100 | [diff] [blame] | 1004 | guc_addon_create(guc); |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1005 | |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1006 | guc->execbuf_client = guc_client_alloc(dev_priv, |
| 1007 | INTEL_INFO(dev_priv)->ring_mask, |
| 1008 | GUC_CTX_PRIORITY_KMD_NORMAL, |
| 1009 | dev_priv->kernel_context); |
| 1010 | if (!guc->execbuf_client) { |
| 1011 | DRM_ERROR("Failed to create GuC client for execbuf!\n"); |
| 1012 | goto err; |
| 1013 | } |
| 1014 | |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1015 | return 0; |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1016 | |
| 1017 | err: |
| 1018 | i915_guc_submission_fini(dev_priv); |
| 1019 | return -ENOMEM; |
| 1020 | } |
| 1021 | |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 1022 | static void guc_reset_wq(struct i915_guc_client *client) |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1023 | { |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 1024 | struct guc_process_desc *desc = client->vaddr + |
| 1025 | client->proc_desc_offset; |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1026 | |
| 1027 | desc->head = 0; |
| 1028 | desc->tail = 0; |
| 1029 | |
Michal Wajdeczko | 776594d | 2016-12-15 19:53:21 +0000 | [diff] [blame] | 1030 | client->wq_tail = 0; |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
Tvrtko Ursulin | cbf4b77 | 2017-03-09 13:20:04 +0000 | [diff] [blame] | 1033 | static void guc_interrupts_capture(struct drm_i915_private *dev_priv) |
| 1034 | { |
| 1035 | struct intel_engine_cs *engine; |
| 1036 | enum intel_engine_id id; |
| 1037 | int irqs; |
| 1038 | |
| 1039 | /* tell all command streamers to forward interrupts (but not vblank) to GuC */ |
| 1040 | irqs = _MASKED_BIT_ENABLE(GFX_INTERRUPT_STEERING); |
| 1041 | for_each_engine(engine, dev_priv, id) |
| 1042 | I915_WRITE(RING_MODE_GEN7(engine), irqs); |
| 1043 | |
| 1044 | /* route USER_INTERRUPT to Host, all others are sent to GuC. */ |
| 1045 | irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | |
| 1046 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT; |
| 1047 | /* These three registers have the same bit definitions */ |
| 1048 | I915_WRITE(GUC_BCS_RCS_IER, ~irqs); |
| 1049 | I915_WRITE(GUC_VCS2_VCS1_IER, ~irqs); |
| 1050 | I915_WRITE(GUC_WD_VECS_IER, ~irqs); |
Sagar Arun Kamble | 1f3b1fd | 2017-03-11 08:07:01 +0530 | [diff] [blame] | 1051 | |
| 1052 | /* |
| 1053 | * The REDIRECT_TO_GUC bit of the PMINTRMSK register directs all |
| 1054 | * (unmasked) PM interrupts to the GuC. All other bits of this |
| 1055 | * register *disable* generation of a specific interrupt. |
| 1056 | * |
| 1057 | * 'pm_intrmsk_mbz' indicates bits that are NOT to be set when |
| 1058 | * writing to the PM interrupt mask register, i.e. interrupts |
| 1059 | * that must not be disabled. |
| 1060 | * |
| 1061 | * If the GuC is handling these interrupts, then we must not let |
| 1062 | * the PM code disable ANY interrupt that the GuC is expecting. |
| 1063 | * So for each ENABLED (0) bit in this register, we must SET the |
| 1064 | * bit in pm_intrmsk_mbz so that it's left enabled for the GuC. |
| 1065 | * GuC needs ARAT expired interrupt unmasked hence it is set in |
| 1066 | * pm_intrmsk_mbz. |
| 1067 | * |
| 1068 | * Here we CLEAR REDIRECT_TO_GUC bit in pm_intrmsk_mbz, which will |
| 1069 | * result in the register bit being left SET! |
| 1070 | */ |
| 1071 | dev_priv->rps.pm_intrmsk_mbz |= ARAT_EXPIRED_INTRMSK; |
Chris Wilson | 655d49e | 2017-03-12 13:27:45 +0000 | [diff] [blame] | 1072 | dev_priv->rps.pm_intrmsk_mbz &= ~GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC; |
Tvrtko Ursulin | cbf4b77 | 2017-03-09 13:20:04 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1075 | int i915_guc_submission_enable(struct drm_i915_private *dev_priv) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1076 | { |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1077 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1078 | struct i915_guc_client *client = guc->execbuf_client; |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1079 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1080 | enum intel_engine_id id; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1081 | |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1082 | if (!client) |
| 1083 | return -ENODEV; |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1084 | |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 1085 | intel_guc_sample_forcewake(guc); |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1086 | |
| 1087 | guc_reset_wq(client); |
Dave Gordon | 4d75787 | 2016-06-13 17:57:34 +0100 | [diff] [blame] | 1088 | guc_init_doorbell_hw(guc); |
Alex Dai | f5d3c3e | 2015-08-18 14:34:47 -0700 | [diff] [blame] | 1089 | |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1090 | /* Take over from manual control of ELSP (execlists) */ |
Tvrtko Ursulin | cbf4b77 | 2017-03-09 13:20:04 +0000 | [diff] [blame] | 1091 | guc_interrupts_capture(dev_priv); |
| 1092 | |
Tvrtko Ursulin | cbf4b77 | 2017-03-09 13:20:04 +0000 | [diff] [blame] | 1093 | for_each_engine(engine, dev_priv, id) { |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 1094 | const int wqi_size = sizeof(struct guc_wq_item); |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1095 | struct drm_i915_gem_request *rq; |
| 1096 | |
Chris Wilson | 31de735 | 2017-03-16 12:56:18 +0000 | [diff] [blame] | 1097 | /* The tasklet was initialised by execlists, and may be in |
| 1098 | * a state of flux (across a reset) and so we just want to |
| 1099 | * take over the callback without changing any other state |
| 1100 | * in the tasklet. |
| 1101 | */ |
| 1102 | engine->irq_tasklet.func = i915_guc_irq_handler; |
| 1103 | clear_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted); |
| 1104 | |
| 1105 | /* Replay the current set of previously submitted requests */ |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 1106 | spin_lock_irq(&engine->timeline->lock); |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1107 | list_for_each_entry(rq, &engine->timeline->requests, link) { |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 1108 | guc_client_update_wq_rsvd(client, wqi_size); |
Chris Wilson | 34ba5a8 | 2016-11-29 12:10:24 +0000 | [diff] [blame] | 1109 | __i915_guc_submit(rq); |
Chris Wilson | dadd481 | 2016-09-09 14:11:57 +0100 | [diff] [blame] | 1110 | } |
Chris Wilson | 349ab91 | 2017-02-28 11:28:02 +0000 | [diff] [blame] | 1111 | spin_unlock_irq(&engine->timeline->lock); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1114 | return 0; |
| 1115 | } |
| 1116 | |
Sagar Arun Kamble | 7762ebb | 2017-03-11 08:06:59 +0530 | [diff] [blame] | 1117 | static void guc_interrupts_release(struct drm_i915_private *dev_priv) |
| 1118 | { |
| 1119 | struct intel_engine_cs *engine; |
| 1120 | enum intel_engine_id id; |
| 1121 | int irqs; |
| 1122 | |
| 1123 | /* |
| 1124 | * tell all command streamers NOT to forward interrupts or vblank |
| 1125 | * to GuC. |
| 1126 | */ |
| 1127 | irqs = _MASKED_FIELD(GFX_FORWARD_VBLANK_MASK, GFX_FORWARD_VBLANK_NEVER); |
| 1128 | irqs |= _MASKED_BIT_DISABLE(GFX_INTERRUPT_STEERING); |
| 1129 | for_each_engine(engine, dev_priv, id) |
| 1130 | I915_WRITE(RING_MODE_GEN7(engine), irqs); |
| 1131 | |
| 1132 | /* route all GT interrupts to the host */ |
| 1133 | I915_WRITE(GUC_BCS_RCS_IER, 0); |
| 1134 | I915_WRITE(GUC_VCS2_VCS1_IER, 0); |
| 1135 | I915_WRITE(GUC_WD_VECS_IER, 0); |
Sagar Arun Kamble | 1f3b1fd | 2017-03-11 08:07:01 +0530 | [diff] [blame] | 1136 | |
Chris Wilson | 655d49e | 2017-03-12 13:27:45 +0000 | [diff] [blame] | 1137 | dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC; |
Sagar Arun Kamble | 1f3b1fd | 2017-03-11 08:07:01 +0530 | [diff] [blame] | 1138 | dev_priv->rps.pm_intrmsk_mbz &= ~ARAT_EXPIRED_INTRMSK; |
Sagar Arun Kamble | 7762ebb | 2017-03-11 08:06:59 +0530 | [diff] [blame] | 1139 | } |
| 1140 | |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1141 | void i915_guc_submission_disable(struct drm_i915_private *dev_priv) |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1142 | { |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1143 | struct intel_guc *guc = &dev_priv->guc; |
| 1144 | |
Sagar Arun Kamble | 7762ebb | 2017-03-11 08:06:59 +0530 | [diff] [blame] | 1145 | guc_interrupts_release(dev_priv); |
| 1146 | |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1147 | if (!guc->execbuf_client) |
| 1148 | return; |
| 1149 | |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1150 | /* Revert back to manual ELSP submission */ |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 1151 | intel_engines_reset_default_submission(dev_priv); |
Dave Gordon | 44a28b1 | 2015-08-12 15:43:41 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
Dave Gordon | beffa51 | 2016-06-10 18:29:26 +0100 | [diff] [blame] | 1154 | void i915_guc_submission_fini(struct drm_i915_private *dev_priv) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1155 | { |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1156 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | 4d357af | 2016-11-29 12:10:23 +0000 | [diff] [blame] | 1157 | struct i915_guc_client *client; |
| 1158 | |
| 1159 | client = fetch_and_zero(&guc->execbuf_client); |
| 1160 | if (!client) |
| 1161 | return; |
| 1162 | |
| 1163 | guc_client_free(dev_priv, client); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1164 | |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 1165 | i915_vma_unpin_and_release(&guc->ads_vma); |
Akash Goel | d6b40b4 | 2016-10-12 21:54:29 +0530 | [diff] [blame] | 1166 | i915_vma_unpin_and_release(&guc->log.vma); |
Alex Dai | 68371a9 | 2015-12-18 12:00:09 -0800 | [diff] [blame] | 1167 | |
Chris Wilson | 8b797af | 2016-08-15 10:48:51 +0100 | [diff] [blame] | 1168 | if (guc->ctx_pool_vma) |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1169 | ida_destroy(&guc->ctx_ids); |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 1170 | i915_vma_unpin_and_release(&guc->ctx_pool_vma); |
Alex Dai | bac427f | 2015-08-12 15:43:39 +0100 | [diff] [blame] | 1171 | } |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1172 | |
| 1173 | /** |
| 1174 | * intel_guc_suspend() - notify GuC entering suspend state |
Tvrtko Ursulin | bf9e842 | 2016-12-01 14:16:38 +0000 | [diff] [blame] | 1175 | * @dev_priv: i915 device private |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1176 | */ |
Tvrtko Ursulin | bf9e842 | 2016-12-01 14:16:38 +0000 | [diff] [blame] | 1177 | int intel_guc_suspend(struct drm_i915_private *dev_priv) |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1178 | { |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1179 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 1180 | struct i915_gem_context *ctx; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1181 | u32 data[3]; |
| 1182 | |
Anusha Srivatsa | db0a091 | 2017-01-13 17:17:04 -0800 | [diff] [blame] | 1183 | if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1184 | return 0; |
| 1185 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame] | 1186 | gen9_disable_guc_interrupts(dev_priv); |
| 1187 | |
Dave Gordon | ed54c1a | 2016-01-19 19:02:54 +0000 | [diff] [blame] | 1188 | ctx = dev_priv->kernel_context; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1189 | |
Arkadiusz Hiler | a80bc45 | 2016-11-25 18:59:34 +0100 | [diff] [blame] | 1190 | data[0] = INTEL_GUC_ACTION_ENTER_S_STATE; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1191 | /* any value greater than GUC_POWER_D0 */ |
| 1192 | data[1] = GUC_POWER_D1; |
| 1193 | /* first page is shared data with GuC */ |
Chris Wilson | 4741da9 | 2016-12-24 19:31:46 +0000 | [diff] [blame] | 1194 | data[2] = guc_ggtt_offset(ctx->engine[RCS].state); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1195 | |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 1196 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | |
| 1200 | /** |
| 1201 | * intel_guc_resume() - notify GuC resuming from suspend state |
Tvrtko Ursulin | bf9e842 | 2016-12-01 14:16:38 +0000 | [diff] [blame] | 1202 | * @dev_priv: i915 device private |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1203 | */ |
Tvrtko Ursulin | bf9e842 | 2016-12-01 14:16:38 +0000 | [diff] [blame] | 1204 | int intel_guc_resume(struct drm_i915_private *dev_priv) |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1205 | { |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1206 | struct intel_guc *guc = &dev_priv->guc; |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 1207 | struct i915_gem_context *ctx; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1208 | u32 data[3]; |
| 1209 | |
Anusha Srivatsa | db0a091 | 2017-01-13 17:17:04 -0800 | [diff] [blame] | 1210 | if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1211 | return 0; |
| 1212 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame] | 1213 | if (i915.guc_log_level >= 0) |
| 1214 | gen9_enable_guc_interrupts(dev_priv); |
| 1215 | |
Dave Gordon | ed54c1a | 2016-01-19 19:02:54 +0000 | [diff] [blame] | 1216 | ctx = dev_priv->kernel_context; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1217 | |
Arkadiusz Hiler | a80bc45 | 2016-11-25 18:59:34 +0100 | [diff] [blame] | 1218 | data[0] = INTEL_GUC_ACTION_EXIT_S_STATE; |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1219 | data[1] = GUC_POWER_D0; |
| 1220 | /* first page is shared data with GuC */ |
Chris Wilson | 4741da9 | 2016-12-24 19:31:46 +0000 | [diff] [blame] | 1221 | data[2] = guc_ggtt_offset(ctx->engine[RCS].state); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1222 | |
Arkadiusz Hiler | 2d803c2 | 2016-11-25 18:59:35 +0100 | [diff] [blame] | 1223 | return intel_guc_send(guc, data, ARRAY_SIZE(data)); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1224 | } |
Sagar Arun Kamble | 4100b2a | 2016-10-12 21:54:32 +0530 | [diff] [blame] | 1225 | |
Sagar Arun Kamble | 4100b2a | 2016-10-12 21:54:32 +0530 | [diff] [blame] | 1226 | |