All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [Intel-xe] [PATCH 8/9] FIXME drm/i915/display: Minimal changes to fbdev to make xe work
Date: Thu,  9 Nov 2023 16:07:58 +0100	[thread overview]
Message-ID: <20231109150759.44549-9-maarten.lankhorst@linux.intel.com> (raw)
In-Reply-To: <20231109150759.44549-1-maarten.lankhorst@linux.intel.com>

BO creation, allocation and placement is slightly different from i915 vs xe.

This is one of the few times we cannot hide between macros,
so make the most of it. :)

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 drivers/gpu/drm/i915/display/intel_fbdev.c | 79 +++++++++++++++++++---
 1 file changed, 70 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_fbdev.c b/drivers/gpu/drm/i915/display/intel_fbdev.c
index 31d0d695d5671..f6cef1302cd20 100644
--- a/drivers/gpu/drm/i915/display/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/display/intel_fbdev.c
@@ -45,6 +45,7 @@
 
 #include "gem/i915_gem_lmem.h"
 #include "gem/i915_gem_mman.h"
+#include "gem/i915_gem_object.h"
 
 #include "i915_drv.h"
 #include "intel_display_types.h"
@@ -173,6 +174,7 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
 	size = PAGE_ALIGN(size);
 
 	obj = ERR_PTR(-ENODEV);
+#ifdef I915
 	if (HAS_LMEM(dev_priv)) {
 		obj = i915_gem_object_create_lmem(dev_priv, size,
 						  I915_BO_ALLOC_CONTIGUOUS |
@@ -185,11 +187,35 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
 		 *
 		 * Also skip stolen on MTL as Wa_22018444074 mitigation.
 		 */
-		if (!(IS_METEORLAKE(dev_priv)) && size * 2 < dev_priv->dsm.usable_size)
+		if (!(IS_METEORLAKE(dev_priv)) &&
+		    size * 2 < i915_gem_stolen_area_size(dev_priv))
 			obj = i915_gem_object_create_stolen(dev_priv, size);
 		if (IS_ERR(obj))
 			obj = i915_gem_object_create_shmem(dev_priv, size);
 	}
+#else
+	/*
+	 * The semantics for xe_bo_create_pin_map are different from those
+	 * of i915_gem_object_create_*(), and need to be destroyed with
+	 * xe_bo_unpin_map_no_vm().
+	 */
+	if (!IS_DGFX(dev_priv) && !IS_METEORLAKE(dev_priv) &&
+	    size * 2 < i915_gem_stolen_area_size(dev_priv)) {
+		obj = xe_bo_create_pin_map(dev_priv, xe_device_get_root_tile(dev_priv),
+					   NULL, size, ttm_bo_type_kernel,
+					   XE_BO_CREATE_STOLEN_BIT |
+					   XE_BO_CREATE_PINNED_BIT | XE_BO_SCANOUT_BIT);
+		if (!IS_ERR(obj))
+			drm_info(&dev_priv->drm, "Allocated fbdev into stolen\n");
+		else
+			drm_info(&dev_priv->drm, "Allocated fbdev into stolen failed: %li\n", PTR_ERR(obj));
+	}
+	if (IS_ERR(obj))
+		obj = xe_bo_create_pin_map(dev_priv, xe_device_get_root_tile(dev_priv),
+					   NULL, size, ttm_bo_type_kernel,
+					   XE_BO_CREATE_VRAM_IF_DGFX(xe_device_get_root_tile(dev_priv)) |
+					   XE_BO_CREATE_PINNED_BIT | XE_BO_SCANOUT_BIT);
+#endif
 
 	if (IS_ERR(obj)) {
 		drm_err(&dev_priv->drm, "failed to allocate framebuffer (%pe)\n", obj);
@@ -197,10 +223,18 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
 	}
 
 	fb = intel_framebuffer_create(obj, &mode_cmd);
-	i915_gem_object_put(obj);
-	if (IS_ERR(fb))
+	if (IS_ERR(fb)) {
+#ifdef I915
+		i915_gem_object_put(obj);
+#else
+		/* undo pin/map, or we get a WARN */
+		xe_bo_unpin_map_no_vm(obj);
+#endif
 		return PTR_ERR(fb);
+	}
 
+	/* reference transferred to fb */
+	drm_gem_object_put(intel_bo_to_drm_bo(obj));
 	ifbdev->fb = to_intel_framebuffer(fb);
 	return 0;
 }
@@ -213,7 +247,6 @@ static int intelfb_create(struct drm_fb_helper *helper,
 	struct drm_device *dev = helper->dev;
 	struct drm_i915_private *dev_priv = to_i915(dev);
 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
-	struct i915_ggtt *ggtt = to_gt(dev_priv)->ggtt;
 	const struct i915_gtt_view view = {
 		.type = I915_GTT_VIEW_NORMAL,
 	};
@@ -224,8 +257,10 @@ static int intelfb_create(struct drm_fb_helper *helper,
 	bool prealloc = false;
 	void __iomem *vaddr;
 	struct drm_i915_gem_object *obj;
-	struct i915_gem_ww_ctx ww;
 	int ret;
+#ifdef I915
+	struct i915_gem_ww_ctx ww;
+#endif
 
 	mutex_lock(&ifbdev->hpd_lock);
 	ret = ifbdev->hpd_suspended ? -EAGAIN : 0;
@@ -283,6 +318,7 @@ static int intelfb_create(struct drm_fb_helper *helper,
 	info->fbops = &intelfb_ops;
 
 	obj = intel_fb_obj(&intel_fb->base);
+#ifdef I915
 	if (i915_gem_object_is_lmem(obj)) {
 		struct intel_memory_region *mem = obj->mm.region;
 
@@ -292,6 +328,8 @@ static int intelfb_create(struct drm_fb_helper *helper,
 					i915_gem_object_get_dma_address(obj, 0));
 		info->fix.smem_len = obj->base.size;
 	} else {
+		struct i915_ggtt *ggtt = to_gt(dev_priv)->ggtt;
+
 		/* Our framebuffer is the entirety of fbdev's system memory */
 		info->fix.smem_start =
 			(unsigned long)(ggtt->gmadr.start + i915_ggtt_offset(vma));
@@ -312,12 +350,35 @@ static int intelfb_create(struct drm_fb_helper *helper,
 			continue;
 		}
 	}
+#else
+	if (obj->flags & XE_BO_CREATE_STOLEN_BIT) {
+		info->fix.smem_start = xe_ttm_stolen_io_offset(obj, 0);
+	} else {
+		struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
+
+		info->fix.smem_start = pci_resource_start(pdev, 2);
+		if (obj->flags & XE_BO_CREATE_VRAM0_BIT)
+			info->fix.smem_start += xe_bo_addr(obj, 0, XE_PAGE_SIZE);
+		else
+			info->fix.smem_start += xe_bo_ggtt_addr(obj);
+	}
+	info->fix.smem_len = obj->ttm.base.size;
+
+	XE_WARN_ON(iosys_map_is_null(&obj->vmap));
+	vaddr = obj->vmap.vaddr_iomem;
+#endif
+	if (IS_ERR(vaddr)) {
+		drm_err(&dev_priv->drm,
+			"Failed to remap framebuffer into virtual memory (%pe)\n", vaddr);
+		ret = PTR_ERR(vaddr);
+		goto out_unpin;
+	}
 
 	if (ret)
 		goto out_unpin;
 
 	info->screen_base = vaddr;
-	info->screen_size = vma->size;
+	info->screen_size = intel_bo_to_drm_bo(obj)->size;
 
 	drm_fb_helper_fill_info(info, &ifbdev->helper, sizes);
 
@@ -325,7 +386,7 @@ static int intelfb_create(struct drm_fb_helper *helper,
 	 * If the object is stolen however, it will be full of whatever
 	 * garbage was left in there.
 	 */
-	if (!i915_gem_object_is_shmem(vma->obj) && !prealloc)
+	if (!i915_gem_object_is_shmem(obj) && !prealloc)
 		memset_io(info->screen_base, 0, info->screen_size);
 
 	/* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
@@ -424,12 +485,12 @@ static bool intel_fbdev_init_bios(struct drm_device *dev,
 			continue;
 		}
 
-		if (obj->base.size > max_size) {
+		if (intel_bo_to_drm_bo(obj)->size > max_size) {
 			drm_dbg_kms(&i915->drm,
 				    "found possible fb from [PLANE:%d:%s]\n",
 				    plane->base.base.id, plane->base.name);
 			fb = to_intel_framebuffer(plane_state->uapi.fb);
-			max_size = obj->base.size;
+			max_size = intel_bo_to_drm_bo(obj)->size;
 		}
 	}
 
-- 
2.39.2


  parent reply	other threads:[~2023-11-09 15:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 15:07 [Intel-xe] [PATCH 0/9] Break up remaining changes to make xe compile Maarten Lankhorst
2023-11-09 15:07 ` [Intel-xe] [PATCH 1/9] drm/i915: Use drm_atomic_helper_wait_for_fences helper Maarten Lankhorst
2023-11-10 11:33   ` [Intel-xe] [1/9] " Hogander, Jouni
2023-11-09 15:07 ` [Intel-xe] [PATCH 2/9] fixup! drm/xe/display: Implement display support Maarten Lankhorst
2023-11-09 15:07 ` [Intel-xe] [PATCH 3/9] drm/i915/display: Revert all before remaining changes to make xe compile Maarten Lankhorst
2023-11-10 11:41   ` [Intel-xe] [3/9] " Hogander, Jouni
2023-11-09 15:07 ` [Intel-xe] [PATCH 4/9] drm/i915/display: Revert " Maarten Lankhorst
2023-11-09 15:07 ` [Intel-xe] [PATCH 5/9] drm/xe: Update headers to be more compatible with i915 Maarten Lankhorst
2023-11-09 15:07 ` [Intel-xe] [PATCH 6/9] FIXME drm/i915/display: add_dma_resv_fences is i915 only Maarten Lankhorst
2023-11-10 11:56   ` [Intel-xe] [6/9] " Hogander, Jouni
2023-11-09 15:07 ` [Intel-xe] [PATCH 7/9] drm/i915/display: Use i915_gem_object_get_dma_address to get dma address Maarten Lankhorst
2023-11-10 12:02   ` [Intel-xe] [7/9] " Hogander, Jouni
2023-11-09 15:07 ` Maarten Lankhorst [this message]
2023-11-09 15:07 ` [Intel-xe] [PATCH 9/9] FIXME drm/i915/display: Make intel_fb.c code compatible with xe Maarten Lankhorst
2023-11-09 15:14 ` [Intel-xe] ✗ CI.Patch_applied: failure for Break up remaining changes to make xe compile Patchwork
2023-11-15 23:31 ` [Intel-xe] ✗ CI.Patch_applied: failure for Break up remaining changes to make xe compile. (rev2) Patchwork
2023-11-17 21:37 ` Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2023-10-27 11:34 [Intel-xe] [PATCH 0/9] Cleaned up revert of remaining changes Maarten Lankhorst
2023-10-27 11:34 ` [Intel-xe] [PATCH 8/9] FIXME drm/i915/display: Minimal changes to fbdev to make xe work Maarten Lankhorst

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=20231109150759.44549-9-maarten.lankhorst@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=intel-xe@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.