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