Commit | Line | Data |
---|---|---|
bac427f8 AD |
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 | */ | |
24 | #include <linux/firmware.h> | |
25 | #include <linux/circ_buf.h> | |
26 | #include "i915_drv.h" | |
27 | #include "intel_guc.h" | |
28 | ||
44a28b1d | 29 | /** |
feda33ef | 30 | * DOC: GuC-based command submission |
44a28b1d DG |
31 | * |
32 | * i915_guc_client: | |
33 | * We use the term client to avoid confusion with contexts. A i915_guc_client is | |
34 | * equivalent to GuC object guc_context_desc. This context descriptor is | |
35 | * allocated from a pool of 1024 entries. Kernel driver will allocate doorbell | |
36 | * and workqueue for it. Also the process descriptor (guc_process_desc), which | |
37 | * is mapped to client space. So the client can write Work Item then ring the | |
38 | * doorbell. | |
39 | * | |
40 | * To simplify the implementation, we allocate one gem object that contains all | |
41 | * pages for doorbell, process descriptor and workqueue. | |
42 | * | |
43 | * The Scratch registers: | |
44 | * There are 16 MMIO-based registers start from 0xC180. The kernel driver writes | |
45 | * a value to the action register (SOFT_SCRATCH_0) along with any data. It then | |
46 | * triggers an interrupt on the GuC via another register write (0xC4C8). | |
47 | * Firmware writes a success/fail code back to the action register after | |
48 | * processes the request. The kernel driver polls waiting for this update and | |
49 | * then proceeds. | |
50 | * See host2guc_action() | |
51 | * | |
52 | * Doorbells: | |
53 | * Doorbells are interrupts to uKernel. A doorbell is a single cache line (QW) | |
54 | * mapped into process space. | |
55 | * | |
56 | * Work Items: | |
57 | * There are several types of work items that the host may place into a | |
58 | * workqueue, each with its own requirements and limitations. Currently only | |
59 | * WQ_TYPE_INORDER is needed to support legacy submission via GuC, which | |
60 | * represents in-order queue. The kernel driver packs ring tail pointer and an | |
61 | * ELSP context descriptor dword into Work Item. | |
62 | * See guc_add_workqueue_item() | |
63 | * | |
64 | */ | |
65 | ||
66 | /* | |
67 | * Read GuC command/status register (SOFT_SCRATCH_0) | |
68 | * Return true if it contains a response rather than a command | |
69 | */ | |
70 | static inline bool host2guc_action_response(struct drm_i915_private *dev_priv, | |
71 | u32 *status) | |
72 | { | |
73 | u32 val = I915_READ(SOFT_SCRATCH(0)); | |
74 | *status = val; | |
75 | return GUC2HOST_IS_RESPONSE(val); | |
76 | } | |
77 | ||
78 | static int host2guc_action(struct intel_guc *guc, u32 *data, u32 len) | |
79 | { | |
80 | struct drm_i915_private *dev_priv = guc_to_i915(guc); | |
81 | u32 status; | |
82 | int i; | |
83 | int ret; | |
84 | ||
85 | if (WARN_ON(len < 1 || len > 15)) | |
86 | return -EINVAL; | |
87 | ||
88 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); | |
44a28b1d DG |
89 | |
90 | dev_priv->guc.action_count += 1; | |
91 | dev_priv->guc.action_cmd = data[0]; | |
92 | ||
93 | for (i = 0; i < len; i++) | |
94 | I915_WRITE(SOFT_SCRATCH(i), data[i]); | |
95 | ||
96 | POSTING_READ(SOFT_SCRATCH(i - 1)); | |
97 | ||
98 | I915_WRITE(HOST2GUC_INTERRUPT, HOST2GUC_TRIGGER); | |
99 | ||
100 | /* No HOST2GUC command should take longer than 10ms */ | |
101 | ret = wait_for_atomic(host2guc_action_response(dev_priv, &status), 10); | |
102 | if (status != GUC2HOST_STATUS_SUCCESS) { | |
103 | /* | |
104 | * Either the GuC explicitly returned an error (which | |
105 | * we convert to -EIO here) or no response at all was | |
106 | * received within the timeout limit (-ETIMEDOUT) | |
107 | */ | |
108 | if (ret != -ETIMEDOUT) | |
109 | ret = -EIO; | |
110 | ||
111 | DRM_ERROR("GUC: host2guc action 0x%X failed. ret=%d " | |
112 | "status=0x%08X response=0x%08X\n", | |
113 | data[0], ret, status, | |
114 | I915_READ(SOFT_SCRATCH(15))); | |
115 | ||
116 | dev_priv->guc.action_fail += 1; | |
117 | dev_priv->guc.action_err = ret; | |
118 | } | |
119 | dev_priv->guc.action_status = status; | |
120 | ||
44a28b1d DG |
121 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
122 | ||
123 | return ret; | |
124 | } | |
125 | ||
126 | /* | |
127 | * Tell the GuC to allocate or deallocate a specific doorbell | |
128 | */ | |
129 | ||
130 | static int host2guc_allocate_doorbell(struct intel_guc *guc, | |
131 | struct i915_guc_client *client) | |
132 | { | |
133 | u32 data[2]; | |
134 | ||
135 | data[0] = HOST2GUC_ACTION_ALLOCATE_DOORBELL; | |
136 | data[1] = client->ctx_index; | |
137 | ||
138 | return host2guc_action(guc, data, 2); | |
139 | } | |
140 | ||
141 | static int host2guc_release_doorbell(struct intel_guc *guc, | |
142 | struct i915_guc_client *client) | |
143 | { | |
144 | u32 data[2]; | |
145 | ||
146 | data[0] = HOST2GUC_ACTION_DEALLOCATE_DOORBELL; | |
147 | data[1] = client->ctx_index; | |
148 | ||
149 | return host2guc_action(guc, data, 2); | |
150 | } | |
151 | ||
f5d3c3ea AD |
152 | static int host2guc_sample_forcewake(struct intel_guc *guc, |
153 | struct i915_guc_client *client) | |
154 | { | |
155 | struct drm_i915_private *dev_priv = guc_to_i915(guc); | |
93f25318 | 156 | struct drm_device *dev = dev_priv->dev; |
f5d3c3ea AD |
157 | u32 data[2]; |
158 | ||
159 | data[0] = HOST2GUC_ACTION_SAMPLE_FORCEWAKE; | |
93f25318 | 160 | /* WaRsDisableCoarsePowerGating:skl,bxt */ |
dc97997a | 161 | if (!intel_enable_rc6() || NEEDS_WaRsDisableCoarsePowerGating(dev)) |
93f25318 AD |
162 | data[1] = 0; |
163 | else | |
164 | /* bit 0 and 1 are for Render and Media domain separately */ | |
165 | data[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA; | |
166 | ||
167 | return host2guc_action(guc, data, ARRAY_SIZE(data)); | |
f5d3c3ea AD |
168 | } |
169 | ||
44a28b1d DG |
170 | /* |
171 | * Initialise, update, or clear doorbell data shared with the GuC | |
172 | * | |
173 | * These functions modify shared data and so need access to the mapped | |
174 | * client object which contains the page being used for the doorbell | |
175 | */ | |
176 | ||
177 | static void guc_init_doorbell(struct intel_guc *guc, | |
178 | struct i915_guc_client *client) | |
179 | { | |
180 | struct guc_doorbell_info *doorbell; | |
44a28b1d | 181 | |
0d92a6a4 | 182 | doorbell = client->client_base + client->doorbell_offset; |
44a28b1d | 183 | |
0d92a6a4 | 184 | doorbell->db_status = GUC_DOORBELL_ENABLED; |
44a28b1d | 185 | doorbell->cookie = 0; |
44a28b1d DG |
186 | } |
187 | ||
188 | static int guc_ring_doorbell(struct i915_guc_client *gc) | |
189 | { | |
190 | struct guc_process_desc *desc; | |
191 | union guc_doorbell_qw db_cmp, db_exc, db_ret; | |
192 | union guc_doorbell_qw *db; | |
44a28b1d DG |
193 | int attempt = 2, ret = -EAGAIN; |
194 | ||
0d92a6a4 | 195 | desc = gc->client_base + gc->proc_desc_offset; |
44a28b1d DG |
196 | |
197 | /* Update the tail so it is visible to GuC */ | |
198 | desc->tail = gc->wq_tail; | |
199 | ||
200 | /* current cookie */ | |
201 | db_cmp.db_status = GUC_DOORBELL_ENABLED; | |
202 | db_cmp.cookie = gc->cookie; | |
203 | ||
204 | /* cookie to be updated */ | |
205 | db_exc.db_status = GUC_DOORBELL_ENABLED; | |
206 | db_exc.cookie = gc->cookie + 1; | |
207 | if (db_exc.cookie == 0) | |
208 | db_exc.cookie = 1; | |
209 | ||
210 | /* pointer of current doorbell cacheline */ | |
0d92a6a4 | 211 | db = gc->client_base + gc->doorbell_offset; |
44a28b1d DG |
212 | |
213 | while (attempt--) { | |
214 | /* lets ring the doorbell */ | |
215 | db_ret.value_qw = atomic64_cmpxchg((atomic64_t *)db, | |
216 | db_cmp.value_qw, db_exc.value_qw); | |
217 | ||
218 | /* if the exchange was successfully executed */ | |
219 | if (db_ret.value_qw == db_cmp.value_qw) { | |
220 | /* db was successfully rung */ | |
221 | gc->cookie = db_exc.cookie; | |
222 | ret = 0; | |
223 | break; | |
224 | } | |
225 | ||
226 | /* XXX: doorbell was lost and need to acquire it again */ | |
227 | if (db_ret.db_status == GUC_DOORBELL_DISABLED) | |
228 | break; | |
229 | ||
230 | DRM_ERROR("Cookie mismatch. Expected %d, returned %d\n", | |
231 | db_cmp.cookie, db_ret.cookie); | |
232 | ||
233 | /* update the cookie to newly read cookie from GuC */ | |
234 | db_cmp.cookie = db_ret.cookie; | |
235 | db_exc.cookie = db_ret.cookie + 1; | |
236 | if (db_exc.cookie == 0) | |
237 | db_exc.cookie = 1; | |
238 | } | |
239 | ||
44a28b1d DG |
240 | return ret; |
241 | } | |
242 | ||
243 | static void guc_disable_doorbell(struct intel_guc *guc, | |
244 | struct i915_guc_client *client) | |
245 | { | |
246 | struct drm_i915_private *dev_priv = guc_to_i915(guc); | |
247 | struct guc_doorbell_info *doorbell; | |
f0f59a00 | 248 | i915_reg_t drbreg = GEN8_DRBREGL(client->doorbell_id); |
44a28b1d DG |
249 | int value; |
250 | ||
0d92a6a4 | 251 | doorbell = client->client_base + client->doorbell_offset; |
44a28b1d | 252 | |
0d92a6a4 | 253 | doorbell->db_status = GUC_DOORBELL_DISABLED; |
44a28b1d DG |
254 | |
255 | I915_WRITE(drbreg, I915_READ(drbreg) & ~GEN8_DRB_VALID); | |
256 | ||
257 | value = I915_READ(drbreg); | |
258 | WARN_ON((value & GEN8_DRB_VALID) != 0); | |
259 | ||
260 | I915_WRITE(GEN8_DRBREGU(client->doorbell_id), 0); | |
261 | I915_WRITE(drbreg, 0); | |
262 | ||
263 | /* XXX: wait for any interrupts */ | |
264 | /* XXX: wait for workqueue to drain */ | |
265 | } | |
266 | ||
267 | /* | |
268 | * Select, assign and relase doorbell cachelines | |
269 | * | |
270 | * These functions track which doorbell cachelines are in use. | |
271 | * The data they manipulate is protected by the host2guc lock. | |
272 | */ | |
273 | ||
274 | static uint32_t select_doorbell_cacheline(struct intel_guc *guc) | |
275 | { | |
276 | const uint32_t cacheline_size = cache_line_size(); | |
277 | uint32_t offset; | |
278 | ||
44a28b1d DG |
279 | /* Doorbell uses a single cache line within a page */ |
280 | offset = offset_in_page(guc->db_cacheline); | |
281 | ||
282 | /* Moving to next cache line to reduce contention */ | |
283 | guc->db_cacheline += cacheline_size; | |
284 | ||
44a28b1d DG |
285 | DRM_DEBUG_DRIVER("selected doorbell cacheline 0x%x, next 0x%x, linesize %u\n", |
286 | offset, guc->db_cacheline, cacheline_size); | |
287 | ||
288 | return offset; | |
289 | } | |
290 | ||
291 | static uint16_t assign_doorbell(struct intel_guc *guc, uint32_t priority) | |
292 | { | |
293 | /* | |
294 | * The bitmap is split into two halves; the first half is used for | |
295 | * normal priority contexts, the second half for high-priority ones. | |
296 | * Note that logically higher priorities are numerically less than | |
297 | * normal ones, so the test below means "is it high-priority?" | |
298 | */ | |
299 | const bool hi_pri = (priority <= GUC_CTX_PRIORITY_HIGH); | |
300 | const uint16_t half = GUC_MAX_DOORBELLS / 2; | |
301 | const uint16_t start = hi_pri ? half : 0; | |
302 | const uint16_t end = start + half; | |
303 | uint16_t id; | |
304 | ||
44a28b1d DG |
305 | id = find_next_zero_bit(guc->doorbell_bitmap, end, start); |
306 | if (id == end) | |
307 | id = GUC_INVALID_DOORBELL_ID; | |
308 | else | |
309 | bitmap_set(guc->doorbell_bitmap, id, 1); | |
44a28b1d DG |
310 | |
311 | DRM_DEBUG_DRIVER("assigned %s priority doorbell id 0x%x\n", | |
312 | hi_pri ? "high" : "normal", id); | |
313 | ||
314 | return id; | |
315 | } | |
316 | ||
317 | static void release_doorbell(struct intel_guc *guc, uint16_t id) | |
318 | { | |
44a28b1d | 319 | bitmap_clear(guc->doorbell_bitmap, id, 1); |
44a28b1d DG |
320 | } |
321 | ||
322 | /* | |
323 | * Initialise the process descriptor shared with the GuC firmware. | |
324 | */ | |
325 | static void guc_init_proc_desc(struct intel_guc *guc, | |
326 | struct i915_guc_client *client) | |
327 | { | |
328 | struct guc_process_desc *desc; | |
44a28b1d | 329 | |
0d92a6a4 | 330 | desc = client->client_base + client->proc_desc_offset; |
44a28b1d DG |
331 | |
332 | memset(desc, 0, sizeof(*desc)); | |
333 | ||
334 | /* | |
335 | * XXX: pDoorbell and WQVBaseAddress are pointers in process address | |
336 | * space for ring3 clients (set them as in mmap_ioctl) or kernel | |
337 | * space for kernel clients (map on demand instead? May make debug | |
338 | * easier to have it mapped). | |
339 | */ | |
340 | desc->wq_base_addr = 0; | |
341 | desc->db_base_addr = 0; | |
342 | ||
343 | desc->context_id = client->ctx_index; | |
344 | desc->wq_size_bytes = client->wq_size; | |
345 | desc->wq_status = WQ_STATUS_ACTIVE; | |
346 | desc->priority = client->priority; | |
44a28b1d DG |
347 | } |
348 | ||
349 | /* | |
350 | * Initialise/clear the context descriptor shared with the GuC firmware. | |
351 | * | |
352 | * This descriptor tells the GuC where (in GGTT space) to find the important | |
353 | * data structures relating to this client (doorbell, process descriptor, | |
354 | * write queue, etc). | |
355 | */ | |
356 | ||
357 | static void guc_init_ctx_desc(struct intel_guc *guc, | |
358 | struct i915_guc_client *client) | |
359 | { | |
86e06cc0 | 360 | struct drm_i915_gem_object *client_obj = client->client_obj; |
397097b0 | 361 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
e2f80391 | 362 | struct intel_engine_cs *engine; |
e2efd130 | 363 | struct i915_gem_context *ctx = client->owner; |
44a28b1d DG |
364 | struct guc_context_desc desc; |
365 | struct sg_table *sg; | |
86e06cc0 | 366 | u32 gfx_addr; |
44a28b1d DG |
367 | |
368 | memset(&desc, 0, sizeof(desc)); | |
369 | ||
370 | desc.attribute = GUC_CTX_DESC_ATTR_ACTIVE | GUC_CTX_DESC_ATTR_KERNEL; | |
371 | desc.context_id = client->ctx_index; | |
372 | desc.priority = client->priority; | |
44a28b1d DG |
373 | desc.db_id = client->doorbell_id; |
374 | ||
9021ad03 CW |
375 | for_each_engine(engine, dev_priv) { |
376 | struct intel_context *ce = &ctx->engine[engine->id]; | |
e2f80391 | 377 | struct guc_execlist_context *lrc = &desc.lrc[engine->guc_id]; |
d1675198 | 378 | struct drm_i915_gem_object *obj; |
d1675198 AD |
379 | |
380 | /* TODO: We have a design issue to be solved here. Only when we | |
381 | * receive the first batch, we know which engine is used by the | |
382 | * user. But here GuC expects the lrc and ring to be pinned. It | |
383 | * is not an issue for default context, which is the only one | |
384 | * for now who owns a GuC client. But for future owner of GuC | |
385 | * client, need to make sure lrc is pinned prior to enter here. | |
386 | */ | |
9021ad03 | 387 | if (!ce->state) |
d1675198 AD |
388 | break; /* XXX: continue? */ |
389 | ||
9021ad03 | 390 | lrc->context_desc = lower_32_bits(ce->lrc_desc); |
d1675198 AD |
391 | |
392 | /* The state page is after PPHWSP */ | |
9021ad03 | 393 | gfx_addr = i915_gem_obj_ggtt_offset(ce->state); |
86e06cc0 | 394 | lrc->ring_lcra = gfx_addr + LRC_STATE_PN * PAGE_SIZE; |
d1675198 | 395 | lrc->context_id = (client->ctx_index << GUC_ELC_CTXID_OFFSET) | |
e2f80391 | 396 | (engine->guc_id << GUC_ELC_ENGINE_OFFSET); |
d1675198 | 397 | |
9021ad03 | 398 | obj = ce->ringbuf->obj; |
86e06cc0 | 399 | gfx_addr = i915_gem_obj_ggtt_offset(obj); |
d1675198 | 400 | |
86e06cc0 DG |
401 | lrc->ring_begin = gfx_addr; |
402 | lrc->ring_end = gfx_addr + obj->base.size - 1; | |
403 | lrc->ring_next_free_location = gfx_addr; | |
d1675198 AD |
404 | lrc->ring_current_tail_pointer_value = 0; |
405 | ||
e2f80391 | 406 | desc.engines_used |= (1 << engine->guc_id); |
d1675198 AD |
407 | } |
408 | ||
409 | WARN_ON(desc.engines_used == 0); | |
410 | ||
44a28b1d | 411 | /* |
86e06cc0 DG |
412 | * The doorbell, process descriptor, and workqueue are all parts |
413 | * of the client object, which the GuC will reference via the GGTT | |
44a28b1d | 414 | */ |
86e06cc0 DG |
415 | gfx_addr = i915_gem_obj_ggtt_offset(client_obj); |
416 | desc.db_trigger_phy = sg_dma_address(client_obj->pages->sgl) + | |
417 | client->doorbell_offset; | |
418 | desc.db_trigger_cpu = (uintptr_t)client->client_base + | |
419 | client->doorbell_offset; | |
420 | desc.db_trigger_uk = gfx_addr + client->doorbell_offset; | |
421 | desc.process_desc = gfx_addr + client->proc_desc_offset; | |
422 | desc.wq_addr = gfx_addr + client->wq_offset; | |
44a28b1d DG |
423 | desc.wq_size = client->wq_size; |
424 | ||
425 | /* | |
e2efd130 | 426 | * XXX: Take LRCs from an existing context if this is not an |
44a28b1d DG |
427 | * IsKMDCreatedContext client |
428 | */ | |
429 | desc.desc_private = (uintptr_t)client; | |
430 | ||
431 | /* Pool context is pinned already */ | |
432 | sg = guc->ctx_pool_obj->pages; | |
433 | sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), | |
434 | sizeof(desc) * client->ctx_index); | |
435 | } | |
436 | ||
437 | static void guc_fini_ctx_desc(struct intel_guc *guc, | |
438 | struct i915_guc_client *client) | |
439 | { | |
440 | struct guc_context_desc desc; | |
441 | struct sg_table *sg; | |
442 | ||
443 | memset(&desc, 0, sizeof(desc)); | |
444 | ||
445 | sg = guc->ctx_pool_obj->pages; | |
446 | sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc), | |
447 | sizeof(desc) * client->ctx_index); | |
448 | } | |
449 | ||
7c2c270d DG |
450 | /** |
451 | * i915_guc_wq_check_space() - check that the GuC can accept a request | |
452 | * @request: request associated with the commands | |
453 | * | |
454 | * Return: 0 if space is available | |
455 | * -EAGAIN if space is not currently available | |
456 | * | |
457 | * This function must be called (and must return 0) before a request | |
458 | * is submitted to the GuC via i915_guc_submit() below. Once a result | |
459 | * of 0 has been returned, it remains valid until (but only until) | |
460 | * the next call to submit(). | |
461 | * | |
462 | * This precheck allows the caller to determine in advance that space | |
463 | * will be available for the next submission before committing resources | |
464 | * to it, and helps avoid late failures with complicated recovery paths. | |
465 | */ | |
466 | int i915_guc_wq_check_space(struct drm_i915_gem_request *request) | |
44a28b1d | 467 | { |
551aaecd | 468 | const size_t wqi_size = sizeof(struct guc_wq_item); |
7c2c270d | 469 | struct i915_guc_client *gc = request->i915->guc.execbuf_client; |
44a28b1d | 470 | struct guc_process_desc *desc; |
551aaecd | 471 | u32 freespace; |
44a28b1d | 472 | |
7c2c270d | 473 | GEM_BUG_ON(gc == NULL); |
a7e02199 | 474 | |
0d92a6a4 | 475 | desc = gc->client_base + gc->proc_desc_offset; |
44a28b1d | 476 | |
551aaecd DG |
477 | freespace = CIRC_SPACE(gc->wq_tail, desc->head, gc->wq_size); |
478 | if (likely(freespace >= wqi_size)) | |
479 | return 0; | |
5a843307 | 480 | |
551aaecd | 481 | gc->no_wq_space += 1; |
44a28b1d | 482 | |
551aaecd | 483 | return -EAGAIN; |
44a28b1d DG |
484 | } |
485 | ||
0a31afbc DG |
486 | static void guc_add_workqueue_item(struct i915_guc_client *gc, |
487 | struct drm_i915_gem_request *rq) | |
44a28b1d | 488 | { |
0a31afbc DG |
489 | /* wqi_len is in DWords, and does not include the one-word header */ |
490 | const size_t wqi_size = sizeof(struct guc_wq_item); | |
491 | const u32 wqi_len = wqi_size/sizeof(u32) - 1; | |
a5916e8f | 492 | struct guc_process_desc *desc; |
44a28b1d DG |
493 | struct guc_wq_item *wqi; |
494 | void *base; | |
0a31afbc | 495 | u32 freespace, tail, wq_off, wq_page; |
a7e02199 | 496 | |
a5916e8f | 497 | desc = gc->client_base + gc->proc_desc_offset; |
44a28b1d | 498 | |
0a31afbc DG |
499 | /* Free space is guaranteed, see i915_guc_wq_check_space() above */ |
500 | freespace = CIRC_SPACE(gc->wq_tail, desc->head, gc->wq_size); | |
501 | GEM_BUG_ON(freespace < wqi_size); | |
502 | ||
503 | /* The GuC firmware wants the tail index in QWords, not bytes */ | |
504 | tail = rq->tail; | |
505 | GEM_BUG_ON(tail & 7); | |
506 | tail >>= 3; | |
507 | GEM_BUG_ON(tail > WQ_RING_TAIL_MAX); | |
44a28b1d DG |
508 | |
509 | /* For now workqueue item is 4 DWs; workqueue buffer is 2 pages. So we | |
510 | * should not have the case where structure wqi is across page, neither | |
511 | * wrapped to the beginning. This simplifies the implementation below. | |
512 | * | |
513 | * XXX: if not the case, we need save data to a temp wqi and copy it to | |
514 | * workqueue buffer dw by dw. | |
515 | */ | |
0a31afbc | 516 | BUILD_BUG_ON(wqi_size != 16); |
44a28b1d | 517 | |
0a31afbc DG |
518 | /* postincrement WQ tail for next time */ |
519 | wq_off = gc->wq_tail; | |
520 | gc->wq_tail += wqi_size; | |
521 | gc->wq_tail &= gc->wq_size - 1; | |
522 | GEM_BUG_ON(wq_off & (wqi_size - 1)); | |
523 | ||
524 | /* WQ starts from the page after doorbell / process_desc */ | |
525 | wq_page = (wq_off + GUC_DB_SIZE) >> PAGE_SHIFT; | |
44a28b1d | 526 | wq_off &= PAGE_SIZE - 1; |
0a31afbc | 527 | base = kmap_atomic(i915_gem_object_get_page(gc->client_obj, wq_page)); |
44a28b1d DG |
528 | wqi = (struct guc_wq_item *)((char *)base + wq_off); |
529 | ||
0a31afbc | 530 | /* Now fill in the 4-word work queue item */ |
44a28b1d | 531 | wqi->header = WQ_TYPE_INORDER | |
0a31afbc | 532 | (wqi_len << WQ_LEN_SHIFT) | |
4a570db5 | 533 | (rq->engine->guc_id << WQ_TARGET_SHIFT) | |
44a28b1d DG |
534 | WQ_NO_WCFLUSH_WAIT; |
535 | ||
536 | /* The GuC wants only the low-order word of the context descriptor */ | |
4a570db5 TU |
537 | wqi->context_desc = (u32)intel_lr_context_descriptor(rq->ctx, |
538 | rq->engine); | |
44a28b1d | 539 | |
44a28b1d | 540 | wqi->ring_tail = tail << WQ_RING_TAIL_SHIFT; |
0a31afbc | 541 | wqi->fence_id = rq->seqno; |
44a28b1d DG |
542 | |
543 | kunmap_atomic(base); | |
44a28b1d DG |
544 | } |
545 | ||
546 | /** | |
547 | * i915_guc_submit() - Submit commands through GuC | |
feda33ef | 548 | * @rq: request associated with the commands |
44a28b1d | 549 | * |
7c2c270d DG |
550 | * Return: 0 on success, otherwise an errno. |
551 | * (Note: nonzero really shouldn't happen!) | |
552 | * | |
553 | * The caller must have already called i915_guc_wq_check_space() above | |
554 | * with a result of 0 (success) since the last request submission. This | |
555 | * guarantees that there is space in the work queue for the new request, | |
556 | * so enqueuing the item cannot fail. | |
557 | * | |
558 | * Bad Things Will Happen if the caller violates this protocol e.g. calls | |
559 | * submit() when check() says there's no space, or calls submit() multiple | |
560 | * times with no intervening check(). | |
561 | * | |
562 | * The only error here arises if the doorbell hardware isn't functioning | |
563 | * as expected, which really shouln't happen. | |
44a28b1d | 564 | */ |
7c2c270d | 565 | int i915_guc_submit(struct drm_i915_gem_request *rq) |
44a28b1d | 566 | { |
4a570db5 | 567 | unsigned int engine_id = rq->engine->guc_id; |
7c2c270d DG |
568 | struct intel_guc *guc = &rq->i915->guc; |
569 | struct i915_guc_client *client = guc->execbuf_client; | |
0a31afbc | 570 | int b_ret; |
44a28b1d | 571 | |
0a31afbc DG |
572 | guc_add_workqueue_item(client, rq); |
573 | b_ret = guc_ring_doorbell(client); | |
44a28b1d | 574 | |
397097b0 | 575 | client->submissions[engine_id] += 1; |
0a31afbc DG |
576 | client->retcode = b_ret; |
577 | if (b_ret) | |
44a28b1d | 578 | client->b_fail += 1; |
0a31afbc | 579 | |
397097b0 AD |
580 | guc->submissions[engine_id] += 1; |
581 | guc->last_seqno[engine_id] = rq->seqno; | |
44a28b1d | 582 | |
0a31afbc | 583 | return b_ret; |
44a28b1d DG |
584 | } |
585 | ||
586 | /* | |
587 | * Everything below here is concerned with setup & teardown, and is | |
588 | * therefore not part of the somewhat time-critical batch-submission | |
589 | * path of i915_guc_submit() above. | |
590 | */ | |
591 | ||
bac427f8 AD |
592 | /** |
593 | * gem_allocate_guc_obj() - Allocate gem object for GuC usage | |
0daf556c | 594 | * @dev_priv: driver private data structure |
bac427f8 AD |
595 | * @size: size of object |
596 | * | |
597 | * This is a wrapper to create a gem obj. In order to use it inside GuC, the | |
598 | * object needs to be pinned lifetime. Also we must pin it to gtt space other | |
599 | * than [0, GUC_WOPCM_TOP) because this range is reserved inside GuC. | |
600 | * | |
601 | * Return: A drm_i915_gem_object if successful, otherwise NULL. | |
602 | */ | |
0daf556c DG |
603 | static struct drm_i915_gem_object * |
604 | gem_allocate_guc_obj(struct drm_i915_private *dev_priv, u32 size) | |
bac427f8 | 605 | { |
bac427f8 AD |
606 | struct drm_i915_gem_object *obj; |
607 | ||
0daf556c | 608 | obj = i915_gem_object_create(dev_priv->dev, size); |
fe3db79b | 609 | if (IS_ERR(obj)) |
bac427f8 AD |
610 | return NULL; |
611 | ||
612 | if (i915_gem_object_get_pages(obj)) { | |
613 | drm_gem_object_unreference(&obj->base); | |
614 | return NULL; | |
615 | } | |
616 | ||
617 | if (i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, | |
618 | PIN_OFFSET_BIAS | GUC_WOPCM_TOP)) { | |
619 | drm_gem_object_unreference(&obj->base); | |
620 | return NULL; | |
621 | } | |
622 | ||
623 | /* Invalidate GuC TLB to let GuC take the latest updates to GTT. */ | |
624 | I915_WRITE(GEN8_GTCR, GEN8_GTCR_INVALIDATE); | |
625 | ||
626 | return obj; | |
627 | } | |
628 | ||
629 | /** | |
630 | * gem_release_guc_obj() - Release gem object allocated for GuC usage | |
631 | * @obj: gem obj to be released | |
81fd874e | 632 | */ |
bac427f8 AD |
633 | static void gem_release_guc_obj(struct drm_i915_gem_object *obj) |
634 | { | |
635 | if (!obj) | |
636 | return; | |
637 | ||
638 | if (i915_gem_obj_is_pinned(obj)) | |
639 | i915_gem_object_ggtt_unpin(obj); | |
640 | ||
641 | drm_gem_object_unreference(&obj->base); | |
642 | } | |
643 | ||
0daf556c DG |
644 | static void |
645 | guc_client_free(struct drm_i915_private *dev_priv, | |
646 | struct i915_guc_client *client) | |
44a28b1d | 647 | { |
44a28b1d DG |
648 | struct intel_guc *guc = &dev_priv->guc; |
649 | ||
650 | if (!client) | |
651 | return; | |
652 | ||
44a28b1d DG |
653 | /* |
654 | * XXX: wait for any outstanding submissions before freeing memory. | |
655 | * Be sure to drop any locks | |
656 | */ | |
657 | ||
0d92a6a4 | 658 | if (client->client_base) { |
29fb72c7 DG |
659 | uint16_t db_id = client->doorbell_id; |
660 | ||
0d92a6a4 DG |
661 | /* |
662 | * If we got as far as setting up a doorbell, make sure | |
663 | * we shut it down before unmapping & deallocating the | |
664 | * memory. So first disable the doorbell, then tell the | |
665 | * GuC that we've finished with it, finally deallocate | |
666 | * it in our bitmap | |
667 | */ | |
29fb72c7 | 668 | if (db_id != GUC_INVALID_DOORBELL_ID) { |
0d92a6a4 | 669 | guc_disable_doorbell(guc, client); |
29fb72c7 DG |
670 | if (test_bit(db_id, guc->doorbell_bitmap)) |
671 | host2guc_release_doorbell(guc, client); | |
672 | release_doorbell(guc, db_id); | |
0d92a6a4 DG |
673 | } |
674 | ||
675 | kunmap(kmap_to_page(client->client_base)); | |
676 | } | |
677 | ||
44a28b1d DG |
678 | gem_release_guc_obj(client->client_obj); |
679 | ||
680 | if (client->ctx_index != GUC_INVALID_CTX_ID) { | |
681 | guc_fini_ctx_desc(guc, client); | |
682 | ida_simple_remove(&guc->ctx_ids, client->ctx_index); | |
683 | } | |
684 | ||
685 | kfree(client); | |
686 | } | |
687 | ||
688 | /** | |
689 | * guc_client_alloc() - Allocate an i915_guc_client | |
0daf556c | 690 | * @dev_priv: driver private data structure |
44a28b1d DG |
691 | * @priority: four levels priority _CRITICAL, _HIGH, _NORMAL and _LOW |
692 | * The kernel client to replace ExecList submission is created with | |
693 | * NORMAL priority. Priority of a client for scheduler can be HIGH, | |
694 | * while a preemption context can use CRITICAL. | |
feda33ef AD |
695 | * @ctx: the context that owns the client (we use the default render |
696 | * context) | |
44a28b1d | 697 | * |
0d92a6a4 | 698 | * Return: An i915_guc_client object if success, else NULL. |
44a28b1d | 699 | */ |
0daf556c DG |
700 | static struct i915_guc_client * |
701 | guc_client_alloc(struct drm_i915_private *dev_priv, | |
702 | uint32_t priority, | |
703 | struct i915_gem_context *ctx) | |
44a28b1d DG |
704 | { |
705 | struct i915_guc_client *client; | |
44a28b1d DG |
706 | struct intel_guc *guc = &dev_priv->guc; |
707 | struct drm_i915_gem_object *obj; | |
708 | ||
709 | client = kzalloc(sizeof(*client), GFP_KERNEL); | |
710 | if (!client) | |
711 | return NULL; | |
712 | ||
713 | client->doorbell_id = GUC_INVALID_DOORBELL_ID; | |
714 | client->priority = priority; | |
d1675198 | 715 | client->owner = ctx; |
44a28b1d DG |
716 | client->guc = guc; |
717 | ||
718 | client->ctx_index = (uint32_t)ida_simple_get(&guc->ctx_ids, 0, | |
719 | GUC_MAX_GPU_CONTEXTS, GFP_KERNEL); | |
720 | if (client->ctx_index >= GUC_MAX_GPU_CONTEXTS) { | |
721 | client->ctx_index = GUC_INVALID_CTX_ID; | |
722 | goto err; | |
723 | } | |
724 | ||
725 | /* The first page is doorbell/proc_desc. Two followed pages are wq. */ | |
0daf556c | 726 | obj = gem_allocate_guc_obj(dev_priv, GUC_DB_SIZE + GUC_WQ_SIZE); |
44a28b1d DG |
727 | if (!obj) |
728 | goto err; | |
729 | ||
0d92a6a4 | 730 | /* We'll keep just the first (doorbell/proc) page permanently kmap'd. */ |
44a28b1d | 731 | client->client_obj = obj; |
0d92a6a4 | 732 | client->client_base = kmap(i915_gem_object_get_page(obj, 0)); |
44a28b1d DG |
733 | client->wq_offset = GUC_DB_SIZE; |
734 | client->wq_size = GUC_WQ_SIZE; | |
44a28b1d DG |
735 | |
736 | client->doorbell_offset = select_doorbell_cacheline(guc); | |
737 | ||
738 | /* | |
739 | * Since the doorbell only requires a single cacheline, we can save | |
740 | * space by putting the application process descriptor in the same | |
741 | * page. Use the half of the page that doesn't include the doorbell. | |
742 | */ | |
743 | if (client->doorbell_offset >= (GUC_DB_SIZE / 2)) | |
744 | client->proc_desc_offset = 0; | |
745 | else | |
746 | client->proc_desc_offset = (GUC_DB_SIZE / 2); | |
747 | ||
748 | client->doorbell_id = assign_doorbell(guc, client->priority); | |
749 | if (client->doorbell_id == GUC_INVALID_DOORBELL_ID) | |
750 | /* XXX: evict a doorbell instead */ | |
751 | goto err; | |
752 | ||
753 | guc_init_proc_desc(guc, client); | |
754 | guc_init_ctx_desc(guc, client); | |
755 | guc_init_doorbell(guc, client); | |
756 | ||
757 | /* XXX: Any cache flushes needed? General domain mgmt calls? */ | |
758 | ||
759 | if (host2guc_allocate_doorbell(guc, client)) | |
760 | goto err; | |
761 | ||
762 | DRM_DEBUG_DRIVER("new priority %u client %p: ctx_index %u db_id %u\n", | |
763 | priority, client, client->ctx_index, client->doorbell_id); | |
764 | ||
765 | return client; | |
766 | ||
767 | err: | |
768 | DRM_ERROR("FAILED to create priority %u GuC client!\n", priority); | |
769 | ||
0daf556c | 770 | guc_client_free(dev_priv, client); |
44a28b1d DG |
771 | return NULL; |
772 | } | |
773 | ||
4c7e77fc AD |
774 | static void guc_create_log(struct intel_guc *guc) |
775 | { | |
776 | struct drm_i915_private *dev_priv = guc_to_i915(guc); | |
777 | struct drm_i915_gem_object *obj; | |
778 | unsigned long offset; | |
779 | uint32_t size, flags; | |
780 | ||
781 | if (i915.guc_log_level < GUC_LOG_VERBOSITY_MIN) | |
782 | return; | |
783 | ||
784 | if (i915.guc_log_level > GUC_LOG_VERBOSITY_MAX) | |
785 | i915.guc_log_level = GUC_LOG_VERBOSITY_MAX; | |
786 | ||
787 | /* The first page is to save log buffer state. Allocate one | |
788 | * extra page for others in case for overlap */ | |
789 | size = (1 + GUC_LOG_DPC_PAGES + 1 + | |
790 | GUC_LOG_ISR_PAGES + 1 + | |
791 | GUC_LOG_CRASH_PAGES + 1) << PAGE_SHIFT; | |
792 | ||
793 | obj = guc->log_obj; | |
794 | if (!obj) { | |
0daf556c | 795 | obj = gem_allocate_guc_obj(dev_priv, size); |
4c7e77fc AD |
796 | if (!obj) { |
797 | /* logging will be off */ | |
798 | i915.guc_log_level = -1; | |
799 | return; | |
800 | } | |
801 | ||
802 | guc->log_obj = obj; | |
803 | } | |
804 | ||
805 | /* each allocated unit is a page */ | |
806 | flags = GUC_LOG_VALID | GUC_LOG_NOTIFY_ON_HALF_FULL | | |
807 | (GUC_LOG_DPC_PAGES << GUC_LOG_DPC_SHIFT) | | |
808 | (GUC_LOG_ISR_PAGES << GUC_LOG_ISR_SHIFT) | | |
809 | (GUC_LOG_CRASH_PAGES << GUC_LOG_CRASH_SHIFT); | |
810 | ||
811 | offset = i915_gem_obj_ggtt_offset(obj) >> PAGE_SHIFT; /* in pages */ | |
812 | guc->log_flags = (offset << GUC_LOG_BUF_ADDR_SHIFT) | flags; | |
813 | } | |
814 | ||
463704d0 AD |
815 | static void init_guc_policies(struct guc_policies *policies) |
816 | { | |
817 | struct guc_policy *policy; | |
818 | u32 p, i; | |
819 | ||
820 | policies->dpc_promote_time = 500000; | |
821 | policies->max_num_work_items = POLICY_MAX_NUM_WI; | |
822 | ||
823 | for (p = 0; p < GUC_CTX_PRIORITY_NUM; p++) { | |
397097b0 | 824 | for (i = GUC_RENDER_ENGINE; i < GUC_MAX_ENGINES_NUM; i++) { |
463704d0 AD |
825 | policy = &policies->policy[p][i]; |
826 | ||
827 | policy->execution_quantum = 1000000; | |
828 | policy->preemption_time = 500000; | |
829 | policy->fault_time = 250000; | |
830 | policy->policy_flags = 0; | |
831 | } | |
832 | } | |
833 | ||
834 | policies->is_valid = 1; | |
835 | } | |
836 | ||
68371a95 AD |
837 | static void guc_create_ads(struct intel_guc *guc) |
838 | { | |
839 | struct drm_i915_private *dev_priv = guc_to_i915(guc); | |
840 | struct drm_i915_gem_object *obj; | |
841 | struct guc_ads *ads; | |
463704d0 | 842 | struct guc_policies *policies; |
5c148e04 | 843 | struct guc_mmio_reg_state *reg_state; |
e2f80391 | 844 | struct intel_engine_cs *engine; |
68371a95 | 845 | struct page *page; |
b4ac5afc | 846 | u32 size; |
68371a95 AD |
847 | |
848 | /* The ads obj includes the struct itself and buffers passed to GuC */ | |
5c148e04 AD |
849 | size = sizeof(struct guc_ads) + sizeof(struct guc_policies) + |
850 | sizeof(struct guc_mmio_reg_state) + | |
851 | GUC_S3_SAVE_SPACE_PAGES * PAGE_SIZE; | |
68371a95 AD |
852 | |
853 | obj = guc->ads_obj; | |
854 | if (!obj) { | |
0daf556c | 855 | obj = gem_allocate_guc_obj(dev_priv, PAGE_ALIGN(size)); |
68371a95 AD |
856 | if (!obj) |
857 | return; | |
858 | ||
859 | guc->ads_obj = obj; | |
860 | } | |
861 | ||
862 | page = i915_gem_object_get_page(obj, 0); | |
863 | ads = kmap(page); | |
864 | ||
865 | /* | |
866 | * The GuC requires a "Golden Context" when it reinitialises | |
867 | * engines after a reset. Here we use the Render ring default | |
868 | * context, which must already exist and be pinned in the GGTT, | |
869 | * so its address won't change after we've told the GuC where | |
870 | * to find it. | |
871 | */ | |
4a570db5 | 872 | engine = &dev_priv->engine[RCS]; |
e2f80391 | 873 | ads->golden_context_lrca = engine->status_page.gfx_addr; |
68371a95 | 874 | |
b4ac5afc | 875 | for_each_engine(engine, dev_priv) |
e2f80391 | 876 | ads->eng_state_size[engine->guc_id] = intel_lr_context_size(engine); |
68371a95 | 877 | |
463704d0 AD |
878 | /* GuC scheduling policies */ |
879 | policies = (void *)ads + sizeof(struct guc_ads); | |
880 | init_guc_policies(policies); | |
881 | ||
882 | ads->scheduler_policies = i915_gem_obj_ggtt_offset(obj) + | |
883 | sizeof(struct guc_ads); | |
884 | ||
5c148e04 AD |
885 | /* MMIO reg state */ |
886 | reg_state = (void *)policies + sizeof(struct guc_policies); | |
887 | ||
b4ac5afc | 888 | for_each_engine(engine, dev_priv) { |
e2f80391 TU |
889 | reg_state->mmio_white_list[engine->guc_id].mmio_start = |
890 | engine->mmio_base + GUC_MMIO_WHITE_LIST_START; | |
5c148e04 AD |
891 | |
892 | /* Nothing to be saved or restored for now. */ | |
e2f80391 | 893 | reg_state->mmio_white_list[engine->guc_id].count = 0; |
5c148e04 AD |
894 | } |
895 | ||
896 | ads->reg_state_addr = ads->scheduler_policies + | |
897 | sizeof(struct guc_policies); | |
898 | ||
899 | ads->reg_state_buffer = ads->reg_state_addr + | |
900 | sizeof(struct guc_mmio_reg_state); | |
901 | ||
68371a95 AD |
902 | kunmap(page); |
903 | } | |
904 | ||
bac427f8 AD |
905 | /* |
906 | * Set up the memory resources to be shared with the GuC. At this point, | |
907 | * we require just one object that can be mapped through the GGTT. | |
908 | */ | |
beffa517 | 909 | int i915_guc_submission_init(struct drm_i915_private *dev_priv) |
bac427f8 | 910 | { |
bac427f8 AD |
911 | const size_t ctxsize = sizeof(struct guc_context_desc); |
912 | const size_t poolsize = GUC_MAX_GPU_CONTEXTS * ctxsize; | |
913 | const size_t gemsize = round_up(poolsize, PAGE_SIZE); | |
914 | struct intel_guc *guc = &dev_priv->guc; | |
915 | ||
29fb72c7 DG |
916 | /* Wipe bitmap & delete client in case of reinitialisation */ |
917 | bitmap_clear(guc->doorbell_bitmap, 0, GUC_MAX_DOORBELLS); | |
beffa517 | 918 | i915_guc_submission_disable(dev_priv); |
29fb72c7 | 919 | |
bac427f8 AD |
920 | if (!i915.enable_guc_submission) |
921 | return 0; /* not enabled */ | |
922 | ||
923 | if (guc->ctx_pool_obj) | |
924 | return 0; /* already allocated */ | |
925 | ||
0daf556c | 926 | guc->ctx_pool_obj = gem_allocate_guc_obj(dev_priv, gemsize); |
bac427f8 AD |
927 | if (!guc->ctx_pool_obj) |
928 | return -ENOMEM; | |
929 | ||
930 | ida_init(&guc->ctx_ids); | |
4c7e77fc | 931 | guc_create_log(guc); |
68371a95 AD |
932 | guc_create_ads(guc); |
933 | ||
bac427f8 AD |
934 | return 0; |
935 | } | |
936 | ||
beffa517 | 937 | int i915_guc_submission_enable(struct drm_i915_private *dev_priv) |
44a28b1d | 938 | { |
44a28b1d DG |
939 | struct intel_guc *guc = &dev_priv->guc; |
940 | struct i915_guc_client *client; | |
941 | ||
942 | /* client for execbuf submission */ | |
0daf556c | 943 | client = guc_client_alloc(dev_priv, |
0ca5fa3a CW |
944 | GUC_CTX_PRIORITY_KMD_NORMAL, |
945 | dev_priv->kernel_context); | |
44a28b1d DG |
946 | if (!client) { |
947 | DRM_ERROR("Failed to create execbuf guc_client\n"); | |
948 | return -ENOMEM; | |
949 | } | |
950 | ||
951 | guc->execbuf_client = client; | |
f5d3c3ea AD |
952 | |
953 | host2guc_sample_forcewake(guc, client); | |
954 | ||
44a28b1d DG |
955 | return 0; |
956 | } | |
957 | ||
beffa517 | 958 | void i915_guc_submission_disable(struct drm_i915_private *dev_priv) |
44a28b1d | 959 | { |
44a28b1d DG |
960 | struct intel_guc *guc = &dev_priv->guc; |
961 | ||
0daf556c | 962 | guc_client_free(dev_priv, guc->execbuf_client); |
44a28b1d DG |
963 | guc->execbuf_client = NULL; |
964 | } | |
965 | ||
beffa517 | 966 | void i915_guc_submission_fini(struct drm_i915_private *dev_priv) |
bac427f8 | 967 | { |
bac427f8 AD |
968 | struct intel_guc *guc = &dev_priv->guc; |
969 | ||
68371a95 AD |
970 | gem_release_guc_obj(dev_priv->guc.ads_obj); |
971 | guc->ads_obj = NULL; | |
972 | ||
4c7e77fc AD |
973 | gem_release_guc_obj(dev_priv->guc.log_obj); |
974 | guc->log_obj = NULL; | |
975 | ||
bac427f8 AD |
976 | if (guc->ctx_pool_obj) |
977 | ida_destroy(&guc->ctx_ids); | |
978 | gem_release_guc_obj(guc->ctx_pool_obj); | |
979 | guc->ctx_pool_obj = NULL; | |
980 | } | |
a1c41994 AD |
981 | |
982 | /** | |
983 | * intel_guc_suspend() - notify GuC entering suspend state | |
984 | * @dev: drm device | |
985 | */ | |
986 | int intel_guc_suspend(struct drm_device *dev) | |
987 | { | |
988 | struct drm_i915_private *dev_priv = dev->dev_private; | |
989 | struct intel_guc *guc = &dev_priv->guc; | |
e2efd130 | 990 | struct i915_gem_context *ctx; |
a1c41994 AD |
991 | u32 data[3]; |
992 | ||
fce91f22 | 993 | if (guc->guc_fw.guc_fw_load_status != GUC_FIRMWARE_SUCCESS) |
a1c41994 AD |
994 | return 0; |
995 | ||
ed54c1a1 | 996 | ctx = dev_priv->kernel_context; |
a1c41994 AD |
997 | |
998 | data[0] = HOST2GUC_ACTION_ENTER_S_STATE; | |
999 | /* any value greater than GUC_POWER_D0 */ | |
1000 | data[1] = GUC_POWER_D1; | |
1001 | /* first page is shared data with GuC */ | |
1002 | data[2] = i915_gem_obj_ggtt_offset(ctx->engine[RCS].state); | |
1003 | ||
1004 | return host2guc_action(guc, data, ARRAY_SIZE(data)); | |
1005 | } | |
1006 | ||
1007 | ||
1008 | /** | |
1009 | * intel_guc_resume() - notify GuC resuming from suspend state | |
1010 | * @dev: drm device | |
1011 | */ | |
1012 | int intel_guc_resume(struct drm_device *dev) | |
1013 | { | |
1014 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1015 | struct intel_guc *guc = &dev_priv->guc; | |
e2efd130 | 1016 | struct i915_gem_context *ctx; |
a1c41994 AD |
1017 | u32 data[3]; |
1018 | ||
fce91f22 | 1019 | if (guc->guc_fw.guc_fw_load_status != GUC_FIRMWARE_SUCCESS) |
a1c41994 AD |
1020 | return 0; |
1021 | ||
ed54c1a1 | 1022 | ctx = dev_priv->kernel_context; |
a1c41994 AD |
1023 | |
1024 | data[0] = HOST2GUC_ACTION_EXIT_S_STATE; | |
1025 | data[1] = GUC_POWER_D0; | |
1026 | /* first page is shared data with GuC */ | |
1027 | data[2] = i915_gem_obj_ggtt_offset(ctx->engine[RCS].state); | |
1028 | ||
1029 | return host2guc_action(guc, data, ARRAY_SIZE(data)); | |
1030 | } |