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