blob: 3eb516e7c22561b54cb6c11c932eed653800095c [file] [log] [blame]
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +00001/*
2 * Copyright © 2014-2017 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
25#include "intel_guc.h"
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -080026#include "intel_guc_ads.h"
Sagar Arun Kamblea2695742017-11-16 19:02:41 +053027#include "intel_guc_submission.h"
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +000028#include "i915_drv.h"
29
30static void gen8_guc_raise_irq(struct intel_guc *guc)
31{
32 struct drm_i915_private *dev_priv = guc_to_i915(guc);
33
34 I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER);
35}
36
37static inline i915_reg_t guc_send_reg(struct intel_guc *guc, u32 i)
38{
39 GEM_BUG_ON(!guc->send_regs.base);
40 GEM_BUG_ON(!guc->send_regs.count);
41 GEM_BUG_ON(i >= guc->send_regs.count);
42
43 return _MMIO(guc->send_regs.base + 4 * i);
44}
45
46void intel_guc_init_send_regs(struct intel_guc *guc)
47{
48 struct drm_i915_private *dev_priv = guc_to_i915(guc);
49 enum forcewake_domains fw_domains = 0;
50 unsigned int i;
51
52 guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0));
53 guc->send_regs.count = SOFT_SCRATCH_COUNT - 1;
54
55 for (i = 0; i < guc->send_regs.count; i++) {
56 fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
57 guc_send_reg(guc, i),
58 FW_REG_READ | FW_REG_WRITE);
59 }
60 guc->send_regs.fw_domains = fw_domains;
61}
62
63void intel_guc_init_early(struct intel_guc *guc)
64{
Michal Wajdeczko0dd940c2017-12-06 13:53:11 +000065 intel_guc_fw_init_early(guc);
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +000066 intel_guc_ct_init_early(&guc->ct);
Sagar Arun Kamble70deead2018-01-24 21:16:58 +053067 intel_guc_log_init_early(guc);
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +000068
69 mutex_init(&guc->send_mutex);
70 guc->send = intel_guc_send_nop;
71 guc->notify = gen8_guc_raise_irq;
72}
73
Michał Winiarski3176ff42017-12-13 23:13:47 +010074int intel_guc_init_wq(struct intel_guc *guc)
75{
76 struct drm_i915_private *dev_priv = guc_to_i915(guc);
77
78 /*
79 * GuC log buffer flush work item has to do register access to
80 * send the ack to GuC and this work item, if not synced before
81 * suspend, can potentially get executed after the GFX device is
82 * suspended.
83 * By marking the WQ as freezable, we don't have to bother about
84 * flushing of this work item from the suspend hooks, the pending
85 * work item if any will be either executed before the suspend
86 * or scheduled later on resume. This way the handling of work
87 * item can be kept same between system suspend & rpm suspend.
88 */
89 guc->log.runtime.flush_wq = alloc_ordered_workqueue("i915-guc_log",
90 WQ_HIGHPRI | WQ_FREEZABLE);
Sagar Arun Kamble70deead2018-01-24 21:16:58 +053091 if (!guc->log.runtime.flush_wq) {
92 DRM_ERROR("Couldn't allocate workqueue for GuC log\n");
Michał Winiarski3176ff42017-12-13 23:13:47 +010093 return -ENOMEM;
Sagar Arun Kamble70deead2018-01-24 21:16:58 +053094 }
Michał Winiarski3176ff42017-12-13 23:13:47 +010095
96 /*
97 * Even though both sending GuC action, and adding a new workitem to
98 * GuC workqueue are serialized (each with its own locking), since
99 * we're using mutliple engines, it's possible that we're going to
100 * issue a preempt request with two (or more - each for different
101 * engine) workitems in GuC queue. In this situation, GuC may submit
102 * all of them, which will make us very confused.
103 * Our preemption contexts may even already be complete - before we
104 * even had the chance to sent the preempt action to GuC!. Rather
105 * than introducing yet another lock, we can just use ordered workqueue
106 * to make sure we're always sending a single preemption request with a
107 * single workitem.
108 */
109 if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) &&
110 USES_GUC_SUBMISSION(dev_priv)) {
111 guc->preempt_wq = alloc_ordered_workqueue("i915-guc_preempt",
112 WQ_HIGHPRI);
113 if (!guc->preempt_wq) {
114 destroy_workqueue(guc->log.runtime.flush_wq);
Sagar Arun Kamble70deead2018-01-24 21:16:58 +0530115 DRM_ERROR("Couldn't allocate workqueue for GuC "
116 "preemption\n");
Michał Winiarski3176ff42017-12-13 23:13:47 +0100117 return -ENOMEM;
118 }
119 }
120
121 return 0;
122}
123
124void intel_guc_fini_wq(struct intel_guc *guc)
125{
126 struct drm_i915_private *dev_priv = guc_to_i915(guc);
127
128 if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) &&
129 USES_GUC_SUBMISSION(dev_priv))
130 destroy_workqueue(guc->preempt_wq);
131
132 destroy_workqueue(guc->log.runtime.flush_wq);
133}
134
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100135static int guc_shared_data_create(struct intel_guc *guc)
136{
137 struct i915_vma *vma;
138 void *vaddr;
139
140 vma = intel_guc_allocate_vma(guc, PAGE_SIZE);
141 if (IS_ERR(vma))
142 return PTR_ERR(vma);
143
144 vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB);
145 if (IS_ERR(vaddr)) {
146 i915_vma_unpin_and_release(&vma);
147 return PTR_ERR(vaddr);
148 }
149
150 guc->shared_data = vma;
151 guc->shared_data_vaddr = vaddr;
152
153 return 0;
154}
155
156static void guc_shared_data_destroy(struct intel_guc *guc)
157{
158 i915_gem_object_unpin_map(guc->shared_data->obj);
159 i915_vma_unpin_and_release(&guc->shared_data);
160}
161
162int intel_guc_init(struct intel_guc *guc)
163{
164 struct drm_i915_private *dev_priv = guc_to_i915(guc);
165 int ret;
166
167 ret = guc_shared_data_create(guc);
168 if (ret)
169 return ret;
170 GEM_BUG_ON(!guc->shared_data);
171
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -0800172 ret = intel_guc_log_create(guc);
173 if (ret)
174 goto err_shared;
175
176 ret = intel_guc_ads_create(guc);
177 if (ret)
178 goto err_log;
179 GEM_BUG_ON(!guc->ads_vma);
180
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100181 /* We need to notify the guc whenever we change the GGTT */
182 i915_ggtt_enable_guc(dev_priv);
183
184 return 0;
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -0800185
186err_log:
187 intel_guc_log_destroy(guc);
188err_shared:
189 guc_shared_data_destroy(guc);
190 return ret;
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100191}
192
193void intel_guc_fini(struct intel_guc *guc)
194{
195 struct drm_i915_private *dev_priv = guc_to_i915(guc);
196
197 i915_ggtt_disable_guc(dev_priv);
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -0800198 intel_guc_ads_destroy(guc);
199 intel_guc_log_destroy(guc);
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100200 guc_shared_data_destroy(guc);
201}
202
Michal Wajdeczkofdc6d732017-10-16 14:47:12 +0000203static u32 get_gt_type(struct drm_i915_private *dev_priv)
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000204{
205 /* XXX: GT type based on PCI device ID? field seems unused by fw */
206 return 0;
207}
208
209static u32 get_core_family(struct drm_i915_private *dev_priv)
210{
211 u32 gen = INTEL_GEN(dev_priv);
212
213 switch (gen) {
214 case 9:
215 return GUC_CORE_FAMILY_GEN9;
216
217 default:
218 MISSING_CASE(gen);
219 return GUC_CORE_FAMILY_UNKNOWN;
220 }
221}
222
Michal Wajdeczko0ed87952018-01-11 15:24:40 +0000223static u32 get_log_verbosity_flags(void)
224{
225 if (i915_modparams.guc_log_level > 0) {
226 u32 verbosity = i915_modparams.guc_log_level - 1;
227
228 GEM_BUG_ON(verbosity > GUC_LOG_VERBOSITY_MAX);
229 return verbosity << GUC_LOG_VERBOSITY_SHIFT;
230 }
231
232 GEM_BUG_ON(i915_modparams.enable_guc < 0);
233 return GUC_LOG_DISABLED;
234}
235
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000236/*
237 * Initialise the GuC parameter block before starting the firmware
238 * transfer. These parameters are read by the firmware on startup
239 * and cannot be changed thereafter.
240 */
241void intel_guc_init_params(struct intel_guc *guc)
242{
243 struct drm_i915_private *dev_priv = guc_to_i915(guc);
244 u32 params[GUC_CTL_MAX_DWORDS];
245 int i;
246
Michal Wajdeczkofdc6d732017-10-16 14:47:12 +0000247 memset(params, 0, sizeof(params));
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000248
249 params[GUC_CTL_DEVICE_INFO] |=
Michal Wajdeczkofdc6d732017-10-16 14:47:12 +0000250 (get_gt_type(dev_priv) << GUC_CTL_GT_TYPE_SHIFT) |
251 (get_core_family(dev_priv) << GUC_CTL_CORE_FAMILY_SHIFT);
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000252
253 /*
254 * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one
255 * second. This ARAR is calculated by:
256 * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10
257 */
258 params[GUC_CTL_ARAT_HIGH] = 0;
259 params[GUC_CTL_ARAT_LOW] = 100000000;
260
261 params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER;
262
263 params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER |
264 GUC_CTL_VCS2_ENABLED;
265
266 params[GUC_CTL_LOG_PARAMS] = guc->log.flags;
267
Michal Wajdeczko0ed87952018-01-11 15:24:40 +0000268 params[GUC_CTL_DEBUG] = get_log_verbosity_flags();
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000269
270 /* If GuC submission is enabled, set up additional parameters here */
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000271 if (USES_GUC_SUBMISSION(dev_priv)) {
Jackie Li3c009e32018-03-13 17:32:49 -0700272 u32 ads = intel_guc_ggtt_offset(guc,
273 guc->ads_vma) >> PAGE_SHIFT;
274 u32 pgs = intel_guc_ggtt_offset(guc, guc->stage_desc_pool);
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000275 u32 ctx_in_16 = GUC_MAX_STAGE_DESCRIPTORS / 16;
276
277 params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
278 params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
279
280 pgs >>= PAGE_SHIFT;
281 params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) |
282 (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT);
283
284 params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS;
285
286 /* Unmask this bit to enable the GuC's internal scheduler */
287 params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER;
288 }
289
290 /*
291 * All SOFT_SCRATCH registers are in FORCEWAKE_BLITTER domain and
292 * they are power context saved so it's ok to release forcewake
293 * when we are done here and take it again at xfer time.
294 */
295 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_BLITTER);
296
297 I915_WRITE(SOFT_SCRATCH(0), 0);
298
299 for (i = 0; i < GUC_CTL_MAX_DWORDS; i++)
300 I915_WRITE(SOFT_SCRATCH(1 + i), params[i]);
301
302 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_BLITTER);
303}
304
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000305int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len)
306{
307 WARN(1, "Unexpected send: action=%#x\n", *action);
308 return -ENODEV;
309}
310
311/*
312 * This function implements the MMIO based host to GuC interface.
313 */
314int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len)
315{
316 struct drm_i915_private *dev_priv = guc_to_i915(guc);
317 u32 status;
318 int i;
319 int ret;
320
321 GEM_BUG_ON(!len);
322 GEM_BUG_ON(len > guc->send_regs.count);
323
324 /* If CT is available, we expect to use MMIO only during init/fini */
325 GEM_BUG_ON(HAS_GUC_CT(dev_priv) &&
326 *action != INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER &&
327 *action != INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER);
328
329 mutex_lock(&guc->send_mutex);
330 intel_uncore_forcewake_get(dev_priv, guc->send_regs.fw_domains);
331
332 for (i = 0; i < len; i++)
333 I915_WRITE(guc_send_reg(guc, i), action[i]);
334
335 POSTING_READ(guc_send_reg(guc, i - 1));
336
337 intel_guc_notify(guc);
338
339 /*
340 * No GuC command should ever take longer than 10ms.
341 * Fast commands should still complete in 10us.
342 */
343 ret = __intel_wait_for_register_fw(dev_priv,
344 guc_send_reg(guc, 0),
345 INTEL_GUC_RECV_MASK,
346 INTEL_GUC_RECV_MASK,
347 10, 10, &status);
348 if (status != INTEL_GUC_STATUS_SUCCESS) {
349 /*
350 * Either the GuC explicitly returned an error (which
351 * we convert to -EIO here) or no response at all was
352 * received within the timeout limit (-ETIMEDOUT)
353 */
354 if (ret != -ETIMEDOUT)
355 ret = -EIO;
356
357 DRM_WARN("INTEL_GUC_SEND: Action 0x%X failed;"
358 " ret=%d status=0x%08X response=0x%08X\n",
359 action[0], ret, status, I915_READ(SOFT_SCRATCH(15)));
360 }
361
362 intel_uncore_forcewake_put(dev_priv, guc->send_regs.fw_domains);
363 mutex_unlock(&guc->send_mutex);
364
365 return ret;
366}
367
Michal Wajdeczko93bf8092018-03-08 16:46:55 +0100368void intel_guc_to_host_event_handler(struct intel_guc *guc)
369{
370 struct drm_i915_private *dev_priv = guc_to_i915(guc);
371 u32 msg, flush;
372
373 /*
374 * Sample the log buffer flush related bits & clear them out now
375 * itself from the message identity register to minimize the
376 * probability of losing a flush interrupt, when there are back
377 * to back flush interrupts.
378 * There can be a new flush interrupt, for different log buffer
379 * type (like for ISR), whilst Host is handling one (for DPC).
380 * Since same bit is used in message register for ISR & DPC, it
381 * could happen that GuC sets the bit for 2nd interrupt but Host
382 * clears out the bit on handling the 1st interrupt.
383 */
384
385 msg = I915_READ(SOFT_SCRATCH(15));
386 flush = msg & (INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED |
387 INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER);
388 if (flush) {
389 /* Clear the message bits that are handled */
390 I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
391
392 /* Handle flush interrupt in bottom half */
393 queue_work(guc->log.runtime.flush_wq,
394 &guc->log.runtime.flush_work);
395
396 guc->log.flush_interrupt_count++;
397 } else {
398 /*
399 * Not clearing of unhandled event bits won't result in
400 * re-triggering of the interrupt.
401 */
402 }
403}
404
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000405int intel_guc_sample_forcewake(struct intel_guc *guc)
406{
407 struct drm_i915_private *dev_priv = guc_to_i915(guc);
408 u32 action[2];
409
410 action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE;
Rodrigo Vivid66047e42018-02-22 12:05:35 -0800411 /* WaRsDisableCoarsePowerGating:skl,cnl */
Chris Wilsonfb6db0f2017-12-01 11:30:30 +0000412 if (!HAS_RC6(dev_priv) || NEEDS_WaRsDisableCoarsePowerGating(dev_priv))
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000413 action[1] = 0;
414 else
415 /* bit 0 and 1 are for Render and Media domain separately */
416 action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA;
417
418 return intel_guc_send(guc, action, ARRAY_SIZE(action));
419}
420
421/**
422 * intel_guc_auth_huc() - Send action to GuC to authenticate HuC ucode
423 * @guc: intel_guc structure
424 * @rsa_offset: rsa offset w.r.t ggtt base of huc vma
425 *
426 * Triggers a HuC firmware authentication request to the GuC via intel_guc_send
427 * INTEL_GUC_ACTION_AUTHENTICATE_HUC interface. This function is invoked by
428 * intel_huc_auth().
429 *
430 * Return: non-zero code on error
431 */
432int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset)
433{
434 u32 action[] = {
435 INTEL_GUC_ACTION_AUTHENTICATE_HUC,
436 rsa_offset
437 };
438
439 return intel_guc_send(guc, action, ARRAY_SIZE(action));
440}
441
442/**
443 * intel_guc_suspend() - notify GuC entering suspend state
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000444 * @guc: the guc
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000445 */
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000446int intel_guc_suspend(struct intel_guc *guc)
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000447{
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000448 u32 data[] = {
449 INTEL_GUC_ACTION_ENTER_S_STATE,
450 GUC_POWER_D1, /* any value greater than GUC_POWER_D0 */
Jackie Li3c009e32018-03-13 17:32:49 -0700451 intel_guc_ggtt_offset(guc, guc->shared_data)
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000452 };
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000453
454 return intel_guc_send(guc, data, ARRAY_SIZE(data));
455}
456
457/**
Michel Thierry6acbea82017-10-31 15:53:09 -0700458 * intel_guc_reset_engine() - ask GuC to reset an engine
459 * @guc: intel_guc structure
460 * @engine: engine to be reset
461 */
462int intel_guc_reset_engine(struct intel_guc *guc,
463 struct intel_engine_cs *engine)
464{
465 u32 data[7];
466
467 GEM_BUG_ON(!guc->execbuf_client);
468
469 data[0] = INTEL_GUC_ACTION_REQUEST_ENGINE_RESET;
470 data[1] = engine->guc_id;
471 data[2] = 0;
472 data[3] = 0;
473 data[4] = 0;
474 data[5] = guc->execbuf_client->stage_id;
Jackie Li3c009e32018-03-13 17:32:49 -0700475 data[6] = intel_guc_ggtt_offset(guc, guc->shared_data);
Michel Thierry6acbea82017-10-31 15:53:09 -0700476
477 return intel_guc_send(guc, data, ARRAY_SIZE(data));
478}
479
480/**
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000481 * intel_guc_resume() - notify GuC resuming from suspend state
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000482 * @guc: the guc
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000483 */
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000484int intel_guc_resume(struct intel_guc *guc)
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000485{
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000486 u32 data[] = {
487 INTEL_GUC_ACTION_EXIT_S_STATE,
488 GUC_POWER_D0,
Jackie Li3c009e32018-03-13 17:32:49 -0700489 intel_guc_ggtt_offset(guc, guc->shared_data)
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000490 };
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000491
492 return intel_guc_send(guc, data, ARRAY_SIZE(data));
493}
494
495/**
Jackie Li6b0478f2018-03-13 17:32:50 -0700496 * DOC: GuC Address Space
497 *
498 * The layout of GuC address space is shown as below:
499 *
500 * +==============> +====================+ <== GUC_GGTT_TOP
501 * ^ | |
502 * | | |
503 * | | DRAM |
504 * | | Memory |
505 * | | |
506 * GuC | |
507 * Address +========> +====================+ <== WOPCM Top
508 * Space ^ | HW contexts RSVD |
509 * | | | WOPCM |
510 * | | +==> +--------------------+ <== GuC WOPCM Top
511 * | GuC ^ | |
512 * | GGTT | | |
513 * | Pin GuC | GuC |
514 * | Bias WOPCM | WOPCM |
515 * | | Size | |
516 * | | | | |
517 * v v v | |
518 * +=====+=====+==> +====================+ <== GuC WOPCM Base
519 * | Non-GuC WOPCM |
520 * | (HuC/Reserved) |
521 * +====================+ <== WOPCM Base
522 *
523 * The lower part [0, GuC ggtt_pin_bias) is mapped to WOPCM which consists of
524 * GuC WOPCM and WOPCM reserved for other usage (e.g.RC6 context). The value of
525 * the GuC ggtt_pin_bias is determined by the actually GuC WOPCM size which is
526 * set in GUC_WOPCM_SIZE register.
527 */
528
529/**
530 * intel_guc_init_ggtt_pin_bias() - Initialize the GuC ggtt_pin_bias value.
531 * @guc: intel_guc structure.
532 *
533 * This function will calculate and initialize the ggtt_pin_bias value based on
534 * overall WOPCM size and GuC WOPCM size.
535 */
536void intel_guc_init_ggtt_pin_bias(struct intel_guc *guc)
537{
538 struct drm_i915_private *i915 = guc_to_i915(guc);
539
540 GEM_BUG_ON(!i915->wopcm.size);
541 GEM_BUG_ON(i915->wopcm.size < i915->wopcm.guc.base);
542
543 guc->ggtt_pin_bias = i915->wopcm.size - i915->wopcm.guc.base;
544}
545
546/**
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000547 * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage
548 * @guc: the guc
549 * @size: size of area to allocate (both virtual space and memory)
550 *
551 * This is a wrapper to create an object for use with the GuC. In order to
552 * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
553 * both some backing storage and a range inside the Global GTT. We must pin
Jackie Li6b0478f2018-03-13 17:32:50 -0700554 * it in the GGTT somewhere other than than [0, GUC ggtt_pin_bias) because that
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000555 * range is reserved inside GuC.
556 *
557 * Return: A i915_vma if successful, otherwise an ERR_PTR.
558 */
559struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
560{
561 struct drm_i915_private *dev_priv = guc_to_i915(guc);
562 struct drm_i915_gem_object *obj;
563 struct i915_vma *vma;
564 int ret;
565
566 obj = i915_gem_object_create(dev_priv, size);
567 if (IS_ERR(obj))
568 return ERR_CAST(obj);
569
570 vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
571 if (IS_ERR(vma))
572 goto err;
573
574 ret = i915_vma_pin(vma, 0, PAGE_SIZE,
Jackie Li6b0478f2018-03-13 17:32:50 -0700575 PIN_GLOBAL | PIN_OFFSET_BIAS | guc->ggtt_pin_bias);
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000576 if (ret) {
577 vma = ERR_PTR(ret);
578 goto err;
579 }
580
581 return vma;
582
583err:
584 i915_gem_object_put(obj);
585 return vma;
586}