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