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