aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Bartmiński <jakub.bartminski@intel.com>2018-07-27 10:11:45 -0400
committerChris Wilson <chris@chris-wilson.co.uk>2018-07-27 11:03:41 -0400
commitdd18cedfa36fbbc19903aed12d6d94c06f5e6dea (patch)
treeeb7d98b1b43486d4b9c7f6d790adc7f43e567f46
parentb6445e17799d931c8c94e5d7acc59c9558f52df5 (diff)
drm/i915/guc: Move the pin bias value from GuC to GGTT
Removing the pin bias from GuC allows us to not check for GuC every time we pin a context, which fixes the assertion error on unresolved GuC platform default in mock contexts selftest. It also seems that we were using uninitialized WOPCM variables when setting the GuC pin bias. The pin bias has to be set after the WOPCM, but before the call to i915_gem_contexts_init where the first contexts are pinned. v2: This also makes it so that there's no need to set GuC variables from within the WOPCM init function or to move the WOPCM init, while keeping the correct initialization order. Also for mock tests the pin bias is left at 0 and we make sure that the pin bias with GuC will not be smaller than without GuC. v3: Avoid unused i915 in intel_guc_ggtt_offset if debug is disabled. v4: Squash with WOPCM init reordering. Moved the i915_ggtt_pin_bias helper to this patch, and made some functions use it instead of directly dereferencing i915->ggtt. v5: Since we now don't use wopcm.guc.base for the pin bias there's no need to validate it. It also has already been verified in WOPCM init. v6: Deleted the now unnecessarily introduced includes from previous versions. Dropped naming changes from dev_priv to i915 for better patch readability. v7: Changed some comments to make more sense in the context they're in. v8: Moved and renamed the function which now returns the wopcm.guc.size to intel_guc.c:intel_guc_reserved_gtt_size to avoid any possible confusion with the pin_bias in ggtt, which should be used for pinning. Fixed patch not applying or the most recent upstream. Fixes: f7dc0157e4b5 ("drm/i915/uc: Fetch GuC/HuC firmwares from guc/huc specific init") Testcase: igt/drv_selftest/mock_contexts #GuC Signed-off-by: Jakub Bartmiński <jakub.bartminski@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Michał Winiarski <michal.winiarski@intel.com> Cc: Michal Wajdeczko <michal.wajdeczko@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Link: https://patchwork.freedesktop.org/patch/msgid/20180727141148.30874-3-jakub.bartminski@intel.com
-rw-r--r--drivers/gpu/drm/i915/i915_gem_context.c10
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c9
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.h2
-rw-r--r--drivers/gpu/drm/i915/i915_vma.h5
-rw-r--r--drivers/gpu/drm/i915/intel_guc.c42
-rw-r--r--drivers/gpu/drm/i915/intel_guc.h12
-rw-r--r--drivers/gpu/drm/i915/intel_huc.c2
-rw-r--r--drivers/gpu/drm/i915/intel_uc_fw.c2
8 files changed, 44 insertions, 40 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index b10770cfccd2..32f96b8cd9c4 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -329,15 +329,7 @@ __create_hw_context(struct drm_i915_private *dev_priv,
329 ctx->desc_template = 329 ctx->desc_template =
330 default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt); 330 default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
331 331
332 /* 332 ctx->ggtt_offset_bias = dev_priv->ggtt.pin_bias;
333 * GuC requires the ring to be placed in Non-WOPCM memory. If GuC is not
334 * present or not in use we still need a small bias as ring wraparound
335 * at offset 0 sometimes hangs. No idea why.
336 */
337 if (USES_GUC(dev_priv))
338 ctx->ggtt_offset_bias = dev_priv->guc.ggtt_pin_bias;
339 else
340 ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
341 333
342 return ctx; 334 return ctx;
343 335
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 1b476423bfab..87219870d559 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -2929,6 +2929,15 @@ int i915_gem_init_ggtt(struct drm_i915_private *dev_priv)
2929 struct drm_mm_node *entry; 2929 struct drm_mm_node *entry;
2930 int ret; 2930 int ret;
2931 2931
2932 /*
2933 * GuC requires all resources that we're sharing with it to be placed in
2934 * non-WOPCM memory. If GuC is not present or not in use we still need a
2935 * small bias as ring wraparound at offset 0 sometimes hangs. No idea
2936 * why.
2937 */
2938 ggtt->pin_bias = max_t(u32, I915_GTT_PAGE_SIZE,
2939 intel_guc_reserved_gtt_size(&dev_priv->guc));
2940
2932 ret = intel_vgt_balloon(dev_priv); 2941 ret = intel_vgt_balloon(dev_priv);
2933 if (ret) 2942 if (ret)
2934 return ret; 2943 return ret;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 2a116a91420b..ce945bf78a89 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -401,6 +401,8 @@ struct i915_ggtt {
401 401
402 int mtrr; 402 int mtrr;
403 403
404 u32 pin_bias;
405
404 struct drm_mm_node error_capture; 406 struct drm_mm_node error_capture;
405}; 407};
406 408
diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h
index af5296b015f5..f1ba40bbe6f9 100644
--- a/drivers/gpu/drm/i915/i915_vma.h
+++ b/drivers/gpu/drm/i915/i915_vma.h
@@ -208,6 +208,11 @@ static inline u32 i915_ggtt_offset(const struct i915_vma *vma)
208 return lower_32_bits(vma->node.start); 208 return lower_32_bits(vma->node.start);
209} 209}
210 210
211static inline u32 i915_ggtt_pin_bias(struct i915_vma *vma)
212{
213 return i915_vm_to_ggtt(vma->vm)->pin_bias;
214}
215
211static inline struct i915_vma *i915_vma_get(struct i915_vma *vma) 216static inline struct i915_vma *i915_vma_get(struct i915_vma *vma)
212{ 217{
213 i915_gem_object_get(vma->obj); 218 i915_gem_object_get(vma->obj);
diff --git a/drivers/gpu/drm/i915/intel_guc.c b/drivers/gpu/drm/i915/intel_guc.c
index deb6a2053eaf..230aea69385d 100644
--- a/drivers/gpu/drm/i915/intel_guc.c
+++ b/drivers/gpu/drm/i915/intel_guc.c
@@ -27,8 +27,6 @@
27#include "intel_guc_submission.h" 27#include "intel_guc_submission.h"
28#include "i915_drv.h" 28#include "i915_drv.h"
29 29
30static void guc_init_ggtt_pin_bias(struct intel_guc *guc);
31
32static void gen8_guc_raise_irq(struct intel_guc *guc) 30static void gen8_guc_raise_irq(struct intel_guc *guc)
33{ 31{
34 struct drm_i915_private *dev_priv = guc_to_i915(guc); 32 struct drm_i915_private *dev_priv = guc_to_i915(guc);
@@ -144,8 +142,6 @@ int intel_guc_init_misc(struct intel_guc *guc)
144 struct drm_i915_private *i915 = guc_to_i915(guc); 142 struct drm_i915_private *i915 = guc_to_i915(guc);
145 int ret; 143 int ret;
146 144
147 guc_init_ggtt_pin_bias(guc);
148
149 ret = guc_init_wq(guc); 145 ret = guc_init_wq(guc);
150 if (ret) 146 if (ret)
151 return ret; 147 return ret;
@@ -607,22 +603,6 @@ int intel_guc_resume(struct intel_guc *guc)
607 */ 603 */
608 604
609/** 605/**
610 * guc_init_ggtt_pin_bias() - Initialize the GuC ggtt_pin_bias value.
611 * @guc: intel_guc structure.
612 *
613 * This function will calculate and initialize the ggtt_pin_bias value
614 * based on the GuC WOPCM size.
615 */
616static void guc_init_ggtt_pin_bias(struct intel_guc *guc)
617{
618 struct drm_i915_private *i915 = guc_to_i915(guc);
619
620 GEM_BUG_ON(!i915->wopcm.size);
621
622 guc->ggtt_pin_bias = i915->wopcm.guc.size;
623}
624
625/**
626 * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage 606 * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage
627 * @guc: the guc 607 * @guc: the guc
628 * @size: size of area to allocate (both virtual space and memory) 608 * @size: size of area to allocate (both virtual space and memory)
@@ -640,6 +620,7 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
640 struct drm_i915_private *dev_priv = guc_to_i915(guc); 620 struct drm_i915_private *dev_priv = guc_to_i915(guc);
641 struct drm_i915_gem_object *obj; 621 struct drm_i915_gem_object *obj;
642 struct i915_vma *vma; 622 struct i915_vma *vma;
623 u64 flags;
643 int ret; 624 int ret;
644 625
645 obj = i915_gem_object_create(dev_priv, size); 626 obj = i915_gem_object_create(dev_priv, size);
@@ -650,8 +631,8 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
650 if (IS_ERR(vma)) 631 if (IS_ERR(vma))
651 goto err; 632 goto err;
652 633
653 ret = i915_vma_pin(vma, 0, 0, 634 flags = PIN_GLOBAL | PIN_OFFSET_BIAS | i915_ggtt_pin_bias(vma);
654 PIN_GLOBAL | PIN_OFFSET_BIAS | guc->ggtt_pin_bias); 635 ret = i915_vma_pin(vma, 0, 0, flags);
655 if (ret) { 636 if (ret) {
656 vma = ERR_PTR(ret); 637 vma = ERR_PTR(ret);
657 goto err; 638 goto err;
@@ -663,3 +644,20 @@ err:
663 i915_gem_object_put(obj); 644 i915_gem_object_put(obj);
664 return vma; 645 return vma;
665} 646}
647
648/**
649 * intel_guc_reserved_gtt_size()
650 * @guc: intel_guc structure
651 *
652 * The GuC WOPCM mapping shadows the lower part of the GGTT, so if we are using
653 * GuC we can't have any objects pinned in that region. This function returns
654 * the size of the shadowed region.
655 *
656 * Returns:
657 * 0 if GuC is not present or not in use.
658 * Otherwise, the GuC WOPCM size.
659 */
660u32 intel_guc_reserved_gtt_size(struct intel_guc *guc)
661{
662 return guc_to_i915(guc)->wopcm.guc.size;
663}
diff --git a/drivers/gpu/drm/i915/intel_guc.h b/drivers/gpu/drm/i915/intel_guc.h
index 4121928a495e..ad42faf48c46 100644
--- a/drivers/gpu/drm/i915/intel_guc.h
+++ b/drivers/gpu/drm/i915/intel_guc.h
@@ -49,9 +49,6 @@ struct intel_guc {
49 struct intel_guc_log log; 49 struct intel_guc_log log;
50 struct intel_guc_ct ct; 50 struct intel_guc_ct ct;
51 51
52 /* Offset where Non-WOPCM memory starts. */
53 u32 ggtt_pin_bias;
54
55 /* Log snapshot if GuC errors during load */ 52 /* Log snapshot if GuC errors during load */
56 struct drm_i915_gem_object *load_err_log; 53 struct drm_i915_gem_object *load_err_log;
57 54
@@ -130,10 +127,10 @@ static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
130 * @vma: i915 graphics virtual memory area. 127 * @vma: i915 graphics virtual memory area.
131 * 128 *
132 * GuC does not allow any gfx GGTT address that falls into range 129 * GuC does not allow any gfx GGTT address that falls into range
133 * [0, GuC ggtt_pin_bias), which is reserved for Boot ROM, SRAM and WOPCM. 130 * [0, ggtt.pin_bias), which is reserved for Boot ROM, SRAM and WOPCM.
134 * Currently, in order to exclude [0, GuC ggtt_pin_bias) address space from 131 * Currently, in order to exclude [0, ggtt.pin_bias) address space from
135 * GGTT, all gfx objects used by GuC are allocated with intel_guc_allocate_vma() 132 * GGTT, all gfx objects used by GuC are allocated with intel_guc_allocate_vma()
136 * and pinned with PIN_OFFSET_BIAS along with the value of GuC ggtt_pin_bias. 133 * and pinned with PIN_OFFSET_BIAS along with the value of ggtt.pin_bias.
137 * 134 *
138 * Return: GGTT offset of the @vma. 135 * Return: GGTT offset of the @vma.
139 */ 136 */
@@ -142,7 +139,7 @@ static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc,
142{ 139{
143 u32 offset = i915_ggtt_offset(vma); 140 u32 offset = i915_ggtt_offset(vma);
144 141
145 GEM_BUG_ON(offset < guc->ggtt_pin_bias); 142 GEM_BUG_ON(offset < i915_ggtt_pin_bias(vma));
146 GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP)); 143 GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
147 144
148 return offset; 145 return offset;
@@ -168,6 +165,7 @@ int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
168int intel_guc_suspend(struct intel_guc *guc); 165int intel_guc_suspend(struct intel_guc *guc);
169int intel_guc_resume(struct intel_guc *guc); 166int intel_guc_resume(struct intel_guc *guc);
170struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size); 167struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
168u32 intel_guc_reserved_gtt_size(struct intel_guc *guc);
171 169
172static inline int intel_guc_sanitize(struct intel_guc *guc) 170static inline int intel_guc_sanitize(struct intel_guc *guc)
173{ 171{
diff --git a/drivers/gpu/drm/i915/intel_huc.c b/drivers/gpu/drm/i915/intel_huc.c
index ffcad5fad6a7..37ef540dd280 100644
--- a/drivers/gpu/drm/i915/intel_huc.c
+++ b/drivers/gpu/drm/i915/intel_huc.c
@@ -63,7 +63,7 @@ int intel_huc_auth(struct intel_huc *huc)
63 return -ENOEXEC; 63 return -ENOEXEC;
64 64
65 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0, 65 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
66 PIN_OFFSET_BIAS | guc->ggtt_pin_bias); 66 PIN_OFFSET_BIAS | i915->ggtt.pin_bias);
67 if (IS_ERR(vma)) { 67 if (IS_ERR(vma)) {
68 ret = PTR_ERR(vma); 68 ret = PTR_ERR(vma);
69 DRM_ERROR("HuC: Failed to pin huc fw object %d\n", ret); 69 DRM_ERROR("HuC: Failed to pin huc fw object %d\n", ret);
diff --git a/drivers/gpu/drm/i915/intel_uc_fw.c b/drivers/gpu/drm/i915/intel_uc_fw.c
index 6e8e0b546743..fd496416087c 100644
--- a/drivers/gpu/drm/i915/intel_uc_fw.c
+++ b/drivers/gpu/drm/i915/intel_uc_fw.c
@@ -222,7 +222,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
222 goto fail; 222 goto fail;
223 } 223 }
224 224
225 ggtt_pin_bias = to_i915(uc_fw->obj->base.dev)->guc.ggtt_pin_bias; 225 ggtt_pin_bias = to_i915(uc_fw->obj->base.dev)->ggtt.pin_bias;
226 vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0, 226 vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0,
227 PIN_OFFSET_BIAS | ggtt_pin_bias); 227 PIN_OFFSET_BIAS | ggtt_pin_bias);
228 if (IS_ERR(vma)) { 228 if (IS_ERR(vma)) {