All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 28/39] initial-plane-vma
Date: Fri, 14 Jun 2019 08:10:12 +0100	[thread overview]
Message-ID: <20190614071023.17929-29-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20190614071023.17929-1-chris@chris-wilson.co.uk>

---
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c |  88 +++----------
 drivers/gpu/drm/i915/i915_drv.h            |   1 -
 drivers/gpu/drm/i915/intel_display.c       | 146 +++++++++++++--------
 drivers/gpu/drm/i915/intel_drv.h           |   1 +
 drivers/gpu/drm/i915/intel_pm.c            |   1 -
 5 files changed, 109 insertions(+), 128 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
index e8bc9b46d4e8..7066044d63cf 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
@@ -604,29 +604,24 @@ i915_gem_object_create_stolen(struct drm_i915_private *dev_priv,
 }
 
 struct drm_i915_gem_object *
-i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv,
+i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *i915,
 					       resource_size_t stolen_offset,
-					       resource_size_t gtt_offset,
 					       resource_size_t size)
 {
-	struct i915_ggtt *ggtt = &dev_priv->ggtt;
 	struct drm_i915_gem_object *obj;
 	struct drm_mm_node *stolen;
-	struct i915_vma *vma;
 	int ret;
 
-	if (!drm_mm_initialized(&dev_priv->mm.stolen))
+	if (!drm_mm_initialized(&i915->mm.stolen))
 		return NULL;
 
-	lockdep_assert_held(&dev_priv->drm.struct_mutex);
-
-	DRM_DEBUG_DRIVER("creating preallocated stolen object: stolen_offset=%pa, gtt_offset=%pa, size=%pa\n",
-			 &stolen_offset, &gtt_offset, &size);
+	DRM_DEBUG_DRIVER("creating preallocated stolen object: stolen_offset=%pa, size=%pa\n",
+			 &stolen_offset, &size);
 
 	/* KISS and expect everything to be page-aligned */
-	if (WARN_ON(size == 0) ||
-	    WARN_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE)) ||
-	    WARN_ON(!IS_ALIGNED(stolen_offset, I915_GTT_MIN_ALIGNMENT)))
+	if (GEM_WARN_ON(size == 0) ||
+	    GEM_WARN_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE)) ||
+	    GEM_WARN_ON(!IS_ALIGNED(stolen_offset, I915_GTT_MIN_ALIGNMENT)))
 		return NULL;
 
 	stolen = kzalloc(sizeof(*stolen), GFP_KERNEL);
@@ -635,68 +630,21 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv
 
 	stolen->start = stolen_offset;
 	stolen->size = size;
-	mutex_lock(&dev_priv->mm.stolen_lock);
-	ret = drm_mm_reserve_node(&dev_priv->mm.stolen, stolen);
-	mutex_unlock(&dev_priv->mm.stolen_lock);
-	if (ret) {
-		DRM_DEBUG_DRIVER("failed to allocate stolen space\n");
-		kfree(stolen);
-		return NULL;
-	}
-
-	obj = _i915_gem_object_create_stolen(dev_priv, stolen);
-	if (obj == NULL) {
-		DRM_DEBUG_DRIVER("failed to allocate stolen object\n");
-		i915_gem_stolen_remove_node(dev_priv, stolen);
-		kfree(stolen);
-		return NULL;
-	}
-
-	/* Some objects just need physical mem from stolen space */
-	if (gtt_offset == I915_GTT_OFFSET_NONE)
-		return obj;
-
-	ret = i915_gem_object_pin_pages(obj);
+	mutex_lock(&i915->mm.stolen_lock);
+	ret = drm_mm_reserve_node(&i915->mm.stolen, stolen);
+	mutex_unlock(&i915->mm.stolen_lock);
 	if (ret)
-		goto err;
+		goto err_free;
 
-	vma = i915_vma_instance(obj, &ggtt->vm, NULL);
-	if (IS_ERR(vma)) {
-		ret = PTR_ERR(vma);
-		goto err_pages;
-	}
-
-	/* To simplify the initialisation sequence between KMS and GTT,
-	 * we allow construction of the stolen object prior to
-	 * setting up the GTT space. The actual reservation will occur
-	 * later.
-	 */
-	ret = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
-				   size, gtt_offset, obj->cache_level,
-				   0);
-	if (ret) {
-		DRM_DEBUG_DRIVER("failed to allocate stolen GTT space\n");
-		goto err_pages;
-	}
-
-	GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
-
-	vma->pages = obj->mm.pages;
-	vma->flags |= I915_VMA_GLOBAL_BIND;
-	__i915_vma_set_map_and_fenceable(vma);
-
-	mutex_lock(&ggtt->vm.mutex);
-	list_add_tail(&vma->vm_link, &ggtt->vm.bound_list);
-	mutex_unlock(&ggtt->vm.mutex);
-
-	GEM_BUG_ON(i915_gem_object_is_shrinkable(obj));
-	atomic_inc(&obj->bind_count);
+	obj = _i915_gem_object_create_stolen(i915, stolen);
+	if (!obj)
+		goto err_stolen;
 
 	return obj;
 
-err_pages:
-	i915_gem_object_unpin_pages(obj);
-err:
-	i915_gem_object_put(obj);
+err_stolen:
+	i915_gem_stolen_remove_node(i915, stolen);
+err_free:
+	kfree(stolen);
 	return NULL;
 }
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 3c9317592729..9a1ec487e8b1 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2703,7 +2703,6 @@ i915_gem_object_create_stolen(struct drm_i915_private *dev_priv,
 struct drm_i915_gem_object *
 i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv,
 					       resource_size_t stolen_offset,
-					       resource_size_t gtt_offset,
 					       resource_size_t size);
 
 /* i915_gem_internal.c */
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 039536625bbf..74fc6d696540 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -3041,6 +3041,71 @@ int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
 	}
 }
 
+static struct i915_vma *
+initial_plane_vma(struct drm_i915_private *i915,
+		  struct intel_initial_plane_config *plane_config)
+{
+	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
+	u32 base, size;
+	int err;
+
+	if (plane_config->size == 0)
+		return NULL;
+
+	base = round_down(plane_config->base, PAGE_SIZE);
+	size = round_up(plane_config->base + plane_config->size, PAGE_SIZE);
+	size -= base;
+
+	/*
+	 * If the FB is too big, just don't use it since fbdev is not very
+	 * important and we should probably use that space with FBC or other
+	 * features.
+	 */
+	if (size * 2 > i915->stolen_usable_size)
+		return NULL;
+
+	obj = i915_gem_object_create_stolen_for_preallocated(i915, base, size);
+	if (!obj)
+		return NULL;
+
+	switch (plane_config->tiling) {
+	case I915_TILING_NONE:
+		break;
+	case I915_TILING_X:
+	case I915_TILING_Y:
+		obj->tiling_and_stride =
+			plane_config->fb->base.pitches[0] |
+			plane_config->tiling;
+		break;
+	default:
+		MISSING_CASE(plane_config->tiling);
+		goto err_obj;
+	}
+
+	vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL);
+	if (IS_ERR(vma))
+		goto err_obj;
+
+	mutex_lock(&i915->drm.struct_mutex);
+	err = i915_vma_pin(vma, 0, 0,
+			   PIN_GLOBAL | PIN_MAPPABLE |
+			   base | PIN_OFFSET_FIXED);
+	mutex_unlock(&i915->drm.struct_mutex);
+	if (err)
+		goto err_obj;
+
+	if (i915_gem_object_is_tiled(obj) &&
+	    !i915_vma_is_map_and_fenceable(vma))
+		goto err_obj;
+
+	return vma;
+
+err_obj:
+	i915_gem_object_put(obj);
+	return NULL;
+}
+
 static bool
 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
 			      struct intel_initial_plane_config *plane_config)
@@ -3049,22 +3114,7 @@ intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
 	struct drm_i915_private *dev_priv = to_i915(dev);
 	struct drm_mode_fb_cmd2 mode_cmd = { 0 };
 	struct drm_framebuffer *fb = &plane_config->fb->base;
-	u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
-	u32 size_aligned = round_up(plane_config->base + plane_config->size,
-				    PAGE_SIZE);
-	struct drm_i915_gem_object *obj;
-	bool ret = false;
-
-	size_aligned -= base_aligned;
-
-	if (plane_config->size == 0)
-		return false;
-
-	/* If the FB is too big, just don't use it since fbdev is not very
-	 * important and we should probably use that space with FBC or other
-	 * features. */
-	if (size_aligned * 2 > dev_priv->stolen_usable_size)
-		return false;
+	struct i915_vma *vma;
 
 	switch (fb->modifier) {
 	case DRM_FORMAT_MOD_LINEAR:
@@ -3077,27 +3127,10 @@ intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
 		return false;
 	}
 
-	mutex_lock(&dev->struct_mutex);
-	obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
-							     base_aligned,
-							     base_aligned,
-							     size_aligned);
-	mutex_unlock(&dev->struct_mutex);
-	if (!obj)
+	vma = initial_plane_vma(dev_priv, plane_config);
+	if (!vma)
 		return false;
 
-	switch (plane_config->tiling) {
-	case I915_TILING_NONE:
-		break;
-	case I915_TILING_X:
-	case I915_TILING_Y:
-		obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
-		break;
-	default:
-		MISSING_CASE(plane_config->tiling);
-		goto out;
-	}
-
 	mode_cmd.pixel_format = fb->format->format;
 	mode_cmd.width = fb->width;
 	mode_cmd.height = fb->height;
@@ -3105,17 +3138,18 @@ intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
 	mode_cmd.modifier[0] = fb->modifier;
 	mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
 
-	if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
+	if (intel_framebuffer_init(to_intel_framebuffer(fb),
+				   vma->obj, &mode_cmd)) {
 		DRM_DEBUG_KMS("intel fb init failed\n");
-		goto out;
+		goto err_vma;
 	}
 
+	plane_config->vma = vma;
+	return true;
 
-	DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
-	ret = true;
-out:
-	i915_gem_object_put(obj);
-	return ret;
+err_vma:
+	i915_vma_put(vma);
+	return false;
 }
 
 static void
@@ -3191,12 +3225,14 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
 	struct intel_plane_state *intel_state =
 		to_intel_plane_state(plane_state);
 	struct drm_framebuffer *fb;
+	struct i915_vma *vma;
 
 	if (!plane_config->fb)
 		return;
 
 	if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
 		fb = &plane_config->fb->base;
+		vma = plane_config->vma;
 		goto valid_fb;
 	}
 
@@ -3219,6 +3255,7 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
 
 		if (intel_plane_ggtt_offset(state) == plane_config->base) {
 			fb = state->base.fb;
+			vma = state->vma;
 			goto valid_fb;
 		}
 	}
@@ -3242,21 +3279,13 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
 		intel_fb_pitch(fb, 0, intel_state->base.rotation);
 
 	mutex_lock(&dev->struct_mutex);
-	intel_state->vma =
-		intel_pin_and_fence_fb_obj(fb,
-					   &intel_state->view,
-					   intel_plane_uses_fence(intel_state),
-					   &intel_state->flags);
+	intel_state->vma = i915_vma_get(plane_config->vma);
+	__i915_vma_pin(intel_state->vma);
+	if (intel_plane_uses_fence(intel_state) &&
+	    i915_vma_pin_fence(intel_state->vma) == 0)
+		intel_state->flags |= PLANE_HAS_FENCE;
+	vma->obj->pin_global++;
 	mutex_unlock(&dev->struct_mutex);
-	if (IS_ERR(intel_state->vma)) {
-		DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
-			  intel_crtc->pipe, PTR_ERR(intel_state->vma));
-
-		intel_state->vma = NULL;
-		return;
-	}
-
-	intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
 
 	plane_state->src_x = 0;
 	plane_state->src_y = 0;
@@ -3278,6 +3307,8 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
 	plane_state->fb = fb;
 	drm_framebuffer_get(fb);
 
+	intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
+
 	atomic_or(to_intel_plane(primary)->frontbuffer_bit,
 		  &to_intel_frontbuffer(fb)->bits);
 }
@@ -15918,6 +15949,9 @@ static void plane_config_fini(struct intel_initial_plane_config *plane_config)
 		else
 			kfree(fb);
 	}
+
+	if (plane_config->vma)
+		i915_vma_put(plane_config->vma);
 }
 
 int intel_modeset_init(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index a5253fd838bc..3a119d0105b5 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -548,6 +548,7 @@ struct intel_plane_state {
 
 struct intel_initial_plane_config {
 	struct intel_framebuffer *fb;
+	struct i915_vma *vma;
 	unsigned int tiling;
 	int size;
 	u32 base;
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index 2c7f3ebc0117..62416798d5fe 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -7722,7 +7722,6 @@ static void valleyview_setup_pctx(struct drm_i915_private *dev_priv)
 		pcbr_offset = (pcbr & (~4095)) - dev_priv->dsm.start;
 		pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv,
 								      pcbr_offset,
-								      I915_GTT_OFFSET_NONE,
 								      pctx_size);
 		goto out;
 	}
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-06-14  7:10 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14  7:09 WIP glance towards struct_mutex removal Chris Wilson
2019-06-14  7:09 ` [PATCH 01/39] drm/i915: Discard some redundant cache domain flushes Chris Wilson
2019-06-14  9:12   ` Matthew Auld
2019-06-14  7:09 ` [PATCH 02/39] drm/i915: Refine i915_reset.lock_map Chris Wilson
2019-06-14 14:10   ` Mika Kuoppala
2019-06-14 14:17     ` Chris Wilson
2019-06-14  7:09 ` [PATCH 03/39] drm/i915: Avoid tainting i915_gem_park() with wakeref.lock Chris Wilson
2019-06-14 14:47   ` Mika Kuoppala
2019-06-14 14:51     ` Chris Wilson
2019-06-14  7:09 ` [PATCH 04/39] drm/i915: Enable refcount debugging for default debug levels Chris Wilson
2019-06-14 15:11   ` Mika Kuoppala
2019-06-14 15:11   ` Mika Kuoppala
2019-06-14  7:09 ` [PATCH 05/39] drm/i915: Keep contexts pinned until after the next kernel context switch Chris Wilson
2019-06-14  7:09 ` [PATCH 06/39] drm/i915: Stop retiring along engine Chris Wilson
2019-06-14  7:09 ` [PATCH 07/39] drm/i915: Replace engine->timeline with a plain list Chris Wilson
2019-06-14  7:09 ` [PATCH 08/39] drm/i915: Flush the execution-callbacks on retiring Chris Wilson
2019-06-14  7:09 ` [PATCH 09/39] drm/i915/execlists: Preempt-to-busy Chris Wilson
2019-06-14  7:09 ` [PATCH 10/39] drm/i915/execlists: Minimalistic timeslicing Chris Wilson
2019-06-14  7:09 ` [PATCH 11/39] drm/i915/execlists: Force preemption Chris Wilson
2019-06-14  7:09 ` [PATCH 12/39] dma-fence: Propagate errors to dma-fence-array container Chris Wilson
2019-06-14  7:09 ` [PATCH 13/39] dma-fence: Report the composite sync_file status Chris Wilson
2019-06-14  7:09 ` [PATCH 14/39] dma-fence: Refactor signaling for manual invocation Chris Wilson
2019-06-14  7:09 ` [PATCH 15/39] dma-fence: Always execute signal callbacks Chris Wilson
2019-06-14  7:10 ` [PATCH 16/39] drm/i915: Execute signal callbacks from no-op i915_request_wait Chris Wilson
2019-06-14 10:45   ` Tvrtko Ursulin
2019-06-14  7:10 ` [PATCH 17/39] drm/i915: Make the semaphore saturation mask global Chris Wilson
2019-06-14  7:10 ` [PATCH 18/39] drm/i915: Throw away the active object retirement complexity Chris Wilson
2019-06-14  7:10 ` [PATCH 19/39] drm/i915: Provide an i915_active.acquire callback Chris Wilson
2019-06-14  7:10 ` [PATCH 20/39] drm/i915: Push the i915_active.retire into a worker Chris Wilson
2019-06-14  7:10 ` [PATCH 21/39] drm/i915/overlay: Switch to using i915_active tracking Chris Wilson
2019-06-14  7:10 ` [PATCH 22/39] drm/i915: Forgo last_fence active request tracking Chris Wilson
2019-06-14  7:10 ` [PATCH 23/39] drm/i915: Extract intel_frontbuffer active tracking Chris Wilson
2019-06-14  7:10 ` [PATCH 24/39] drm/i915: Coordinate i915_active with its own mutex Chris Wilson
2019-06-14  7:10 ` [PATCH 25/39] drm/i915: Track ggtt fence reservations under " Chris Wilson
2019-06-14  7:10 ` [PATCH 26/39] drm/i915: Only track bound elements of the GTT Chris Wilson
2019-06-14  7:10 ` [PATCH 27/39] drm/i915: Explicitly cleanup initial_plane_config Chris Wilson
2019-06-14  7:10 ` Chris Wilson [this message]
2019-06-14  7:10 ` [PATCH 29/39] drm/i915: Make i915_vma track its own kref Chris Wilson
2019-06-14 11:15   ` Matthew Auld
2019-06-14 11:18     ` Chris Wilson
2019-06-14  7:10 ` [PATCH 30/39] drm/i915: Propagate fence errors Chris Wilson
2019-06-14  7:10 ` [PATCH 31/39] drm/i915: Allow page pinning to be in the background Chris Wilson
2019-06-14  7:10 ` [PATCH 32/39] drm/i915: Allow vma binding to occur asynchronously Chris Wilson
2019-08-05 20:35   ` Kumar Valsan, Prathap
2019-06-14  7:10 ` [PATCH 33/39] revoke-fence Chris Wilson
2019-06-14  7:10 ` [PATCH 34/39] drm/i915: Use vm->mutex for serialising GTT insertion Chris Wilson
2019-06-14 19:14   ` Matthew Auld
2019-06-14 19:20     ` Chris Wilson
2019-06-14  7:10 ` [PATCH 35/39] drm/i915: Pin pages before waiting Chris Wilson
2019-06-14 19:53   ` Matthew Auld
2019-06-14 19:58     ` Chris Wilson
2019-06-14 20:13       ` Chris Wilson
2019-06-14 20:18         ` Matthew Auld
2019-06-14  7:10 ` [PATCH 36/39] drm/i915: Use reservation_object to coordinate userptr get_pages() Chris Wilson
2019-08-07 20:49   ` Daniel Vetter
2019-08-08  7:30     ` [Intel-gfx] " Daniel Vetter
2019-06-14  7:10 ` [PATCH 37/39] drm/i915: Use forced preemptions in preference over hangcheck Chris Wilson
2019-06-14  7:10 ` [PATCH 38/39] drm/i915: Remove logical HW ID Chris Wilson
2019-06-14  7:10 ` [PATCH 39/39] active-rings Chris Wilson
2019-06-14  7:22 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/39] drm/i915: Discard some redundant cache domain flushes Patchwork
2019-06-14  7:35 ` ✗ Fi.CI.SPARSE: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190614071023.17929-29-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.