Skip to contentSkip to conversation

Clean-up Xe FBC additions

PATCH Superseded Jouni Högander 2 participants 12 messages May 30, 2023

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Clean-up Xe FBC additions

This patch set cleans up Xe FBC additions. All stolen memory details are moved to i915_gem_stolen header and source files. Also some fence handling details are move away from FBC code. This allows removing all ifdefs added into fbc code.

Cc Jani Nikula <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Rodrigo Vivi <[email protected]>

Jouni Högander (9):
fixup! drm/i915/display: Implement FBC support
drivers/xe: Add new type for compressed fb
drm/i915/fbc: Add common type for compressed fb to avoid ifdefs drm/xe: Add i915_gem.h compatibility header
drivers/xe: Move Xe stolen memory handling away form fbc code drm/i915: Move stolen memory handling into i915_gem_stolen drm/i915/fbc: Stolen initialize can be checked in plane check for i915
as well
drm/i915/fbc: Add function to get number of fences for gt Add new fence_id and fence count functions

 drivers/gpu/drm/i915/display/intel_fbc.c      | 134 ++++--------------
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |  37 +++++
 drivers/gpu/drm/i915/gem/i915_gem_stolen.h    |  13 ++
 drivers/gpu/drm/i915/gt/intel_gt_types.h      |   2 +
 drivers/gpu/drm/i915/i915_vma.h               |   5 +
 .../gpu/drm/xe/compat-i915-headers/i915_drv.h |   5 +
 .../gpu/drm/xe/compat-i915-headers/i915_gem.h |   9 ++
 .../xe/compat-i915-headers/i915_gem_stolen.h  |  76 ++++++++++
 .../gpu/drm/xe/compat-i915-headers/i915_vma.h |   2 +
 drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c        |   8 ++
 drivers/gpu/drm/xe/xe_ttm_stolen_mgr.h        |   1 +
 11 files changed, 183 insertions(+), 109 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/compat-i915-headers/i915_gem.h
 create mode 100644 drivers/gpu/drm/xe/compat-i915-headers/i915_gem_stolen.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/9 fixup! drm/i915/display: Implement FBC support

Unify naming convention. Now all functions to query information on stolen node are using prefix i915_gem_stolen_node.

---
 drivers/gpu/drm/i915/display/intel_fbc.c | 30 ++++++++++++------------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/display/intel_fbc.c +15 -15
index 9dc7083fe974..913db2ea5650 100644
@@ -57,9 +57,9 @@
 #ifdef I915
 
 #define i915_gem_stolen_initialized(i915) (drm_mm_initialized(&(i915)->mm.stolen))
-#define i915_gem_stolen_allocated(node) drm_mm_node_allocated(&(node))
-#define i915_gem_stolen_compressed_offset(node) ((node).start)
-#define i915_gem_stolen_compressed_size(node) ((node).size)
+#define i915_gem_stolen_node_allocated(node) drm_mm_node_allocated(&(node))
+#define i915_gem_stolen_node_offset(node) ((node).start)
+#define i915_gem_stolen_node_size(node) ((node).size)
 
 #else
 
@@ -103,9 +103,9 @@ static void i915_gem_stolen_remove_node(struct xe_device *xe, struct xe_bo **bo)
 }
 
 #define i915_gem_stolen_initialized(xe) (!!ttm_manager_type(&(xe)->ttm, XE_PL_STOLEN))
-#define i915_gem_stolen_allocated(bo) (!!(bo))
+#define i915_gem_stolen_node_allocated(bo) (!!(bo))
 
-static u32 i915_gem_stolen_compressed_offset(struct xe_bo *bo)
+static u32 i915_gem_stolen_node_offset(struct xe_bo *bo)
 {
 	struct xe_res_cursor res;
 
@@ -113,7 +113,7 @@ static u32 i915_gem_stolen_compressed_offset(struct xe_bo *bo)
 	return res.start;
 }
 
-#define i915_gem_stolen_compressed_size(fb) ((u64)((fb)->ttm.base.size))
+#define i915_gem_stolen_node_size(fb) ((u64)((fb)->ttm.base.size))
 #endif
 
 #define for_each_fbc_id(__dev_priv, __fbc_id) \
@@ -515,7 +515,7 @@ static void g4x_fbc_program_cfb(struct intel_fbc *fbc)
 	struct drm_i915_private *i915 = fbc->i915;
 
 	intel_de_write(i915, DPFC_CB_BASE,
-		       i915_gem_stolen_compressed_offset(fbc->compressed_fb));
+		       i915_gem_stolen_node_offset(fbc->compressed_fb));
 }
 
 static const struct intel_fbc_funcs g4x_fbc_funcs = {
@@ -567,7 +567,7 @@ static void ilk_fbc_program_cfb(struct intel_fbc *fbc)
 	struct drm_i915_private *i915 = fbc->i915;
 
 	intel_de_write(i915, ILK_DPFC_CB_BASE(fbc->id),
-		       i915_gem_stolen_compressed_offset(fbc->compressed_fb));
+		       i915_gem_stolen_node_offset(fbc->compressed_fb));
 }
 
 static const struct intel_fbc_funcs ilk_fbc_funcs = {
@@ -843,9 +843,9 @@ static int intel_fbc_alloc_cfb(struct intel_fbc *fbc,
 	int ret;
 
 	drm_WARN_ON(&i915->drm,
-		    i915_gem_stolen_allocated(fbc->compressed_fb));
+		    i915_gem_stolen_node_allocated(fbc->compressed_fb));
 	drm_WARN_ON(&i915->drm,
-		    i915_gem_stolen_allocated(fbc->compressed_llb));
+		    i915_gem_stolen_node_allocated(fbc->compressed_llb));
 
 	if (DISPLAY_VER(i915) < 5 && !IS_G4X(i915)) {
 		ret = i915_gem_stolen_insert_node(i915, &fbc->compressed_llb,
@@ -865,12 +865,12 @@ static int intel_fbc_alloc_cfb(struct intel_fbc *fbc,
 
 	drm_dbg_kms(&i915->drm,
 		    "reserved %llu bytes of contiguous stolen space for FBC, limit: %d\n",
-		    i915_gem_stolen_compressed_size(fbc->compressed_fb), fbc->limit);
+		    i915_gem_stolen_node_size(fbc->compressed_fb), fbc->limit);
 
 	return 0;
 
 err_llb:
-	if (i915_gem_stolen_allocated(fbc->compressed_llb))
+	if (i915_gem_stolen_node_allocated(fbc->compressed_llb))
 		i915_gem_stolen_remove_node(i915, &fbc->compressed_llb);
 err:
 	if (i915_gem_stolen_initialized(i915))
@@ -898,9 +898,9 @@ static void __intel_fbc_cleanup_cfb(struct intel_fbc *fbc)
 	if (WARN_ON(intel_fbc_hw_is_active(fbc)))
 		return;
 
-	if (i915_gem_stolen_allocated(fbc->compressed_llb))
+	if (i915_gem_stolen_node_allocated(fbc->compressed_llb))
 		i915_gem_stolen_remove_node(i915, &fbc->compressed_llb);
-	if (i915_gem_stolen_allocated(fbc->compressed_fb))
+	if (i915_gem_stolen_node_allocated(fbc->compressed_fb))
 		i915_gem_stolen_remove_node(i915, &fbc->compressed_fb);
 }
 
@@ -1109,7 +1109,7 @@ static bool intel_fbc_is_cfb_ok(const struct intel_plane_state *plane_state)
 
 	return intel_fbc_min_limit(plane_state) <= fbc->limit &&
 		intel_fbc_cfb_size(plane_state) <= fbc->limit *
-			i915_gem_stolen_compressed_size(fbc->compressed_fb);
+			i915_gem_stolen_node_size(fbc->compressed_fb);
 }
 
 static bool intel_fbc_is_ok(const struct intel_plane_state *plane_state)
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/9 drivers/xe: Add new type for compressed fb

In reply to Jouni Högander

We want to remove details of stolen memory handling from intel_fbc code. Add new type for compressed fb which will be the only common thing with i915 and Xe stolen memory handling.

---
 drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h      |  1 +
 .../gpu/drm/xe/compat-i915-headers/i915_gem_stolen.h   | 10 ++++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/compat-i915-headers/i915_gem_stolen.h
drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h +1 -0
index 74e6f063f741..89c718de0eab 100644
@@ -14,6 +14,7 @@
 #include "xe_bo.h"
 #include "xe_pm.h"
 #include "xe_step.h"
+#include "i915_gem_stolen.h"
 #include "i915_reg_defs.h"
 #include "intel_pch.h"
 #include "i915_utils.h"
drivers/gpu/drm/xe/compat-i915-headers/i915_gem_stolen.h new file +10 -0
new file mode 100644
index 000000000000..b6eeeba1087b
@@ -0,0 +1,10 @@
+#ifndef _I915_GEM_OBJECT_H_
+#define _I915_GEM_OBJECT_H_
+
+struct xe_bo;
+
+struct i915_stolen_fb {
+	struct xe_bo *bo;
+};
+
+#endif
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/9 drm/i915/fbc: Add common type for compressed fb to avoid ifdefs

In reply to Jouni Högander

Ass a preparation for Xe add a common type for fbc compressed fb and use it from fbc code instead of underlying type directly. This way we can have common type i915_stolen_fb which can be used for both i915 and Xe and we can remove related ifdefs.

---
 drivers/gpu/drm/i915/display/intel_fbc.c   | 61 ++++++++++++----------
 drivers/gpu/drm/i915/gem/i915_gem_stolen.h |  2 +
 2 files changed, 35 insertions(+), 28 deletions(-)
drivers/gpu/drm/i915/display/intel_fbc.c +33 -28
index 913db2ea5650..90c48ccce1a7 100644
@@ -58,62 +58,71 @@
 
 #define i915_gem_stolen_initialized(i915) (drm_mm_initialized(&(i915)->mm.stolen))
 #define i915_gem_stolen_node_allocated(node) drm_mm_node_allocated(&(node))
-#define i915_gem_stolen_node_offset(node) ((node).start)
-#define i915_gem_stolen_node_size(node) ((node).size)
+#define i915_gem_stolen_node_offset(node) ((node)->start)
+#define i915_gem_stolen_node_size(node) ((node)->size)
 
 #else
 
 #include "xe_ttm_stolen_mgr.h"
 #include "xe_res_cursor.h"
 
-static int i915_gem_stolen_insert_node_in_range(struct xe_device *xe, struct xe_bo **bo, u32 size, u32 align, u32 start, u32 end)
+static inline int i915_gem_stolen_insert_node_in_range(struct xe_device *xe,
+						       struct i915_stolen_fb *fb,
+						       u32 size, u32 align,
+						       u32 start, u32 end)
 {
+	struct xe_bo *bo;
 	int err;
 	u32 flags = XE_BO_CREATE_PINNED_BIT | XE_BO_CREATE_STOLEN_BIT;
 
-	*bo = xe_bo_create_locked_range(xe, to_gt(xe), NULL, size, start, end,
+	bo = xe_bo_create_locked_range(xe, to_gt(xe), NULL, size, start, end,
 					ttm_bo_type_kernel, flags);
-	if (IS_ERR(*bo)) {
-		err = PTR_ERR(*bo);
-		*bo = NULL;
+	if (IS_ERR(bo)) {
+		err = PTR_ERR(bo);
+		bo = NULL;
 		return err;
 	}
-	err = xe_bo_pin(*bo);
-	xe_bo_unlock_vm_held(*bo);
+	err = xe_bo_pin(bo);
+	xe_bo_unlock_vm_held(bo);
 
 	if (err) {
-		xe_bo_put(*bo);
-		*bo = NULL;
+		xe_bo_put(bo);
+		bo = NULL;
 	}
 
+	fb->bo = bo;
+
 	return err;
 }
 
-static int i915_gem_stolen_insert_node(struct xe_device *xe, struct xe_bo **bo, u32 size, u32 align)
+static int i915_gem_stolen_insert_node(struct xe_device *xe,
+				       struct i915_stolen_fb *fb, u32 size,
+				       u32 align)
 {
 	/* Not used on xe */
 	BUG_ON(1);
 	return -ENODEV;
 }
 
-static void i915_gem_stolen_remove_node(struct xe_device *xe, struct xe_bo **bo)
+static void i915_gem_stolen_remove_node(struct xe_device *xe,
+					struct i915_stolen_fb *fb)
 {
-	xe_bo_unpin_map_no_vm(*bo);
-	*bo = NULL;
+	xe_bo_unpin_map_no_vm(fb->bo);
+	fb->bo = NULL;
 }
 
 #define i915_gem_stolen_initialized(xe) (!!ttm_manager_type(&(xe)->ttm, XE_PL_STOLEN))
-#define i915_gem_stolen_node_allocated(bo) (!!(bo))
+#define i915_gem_stolen_node_allocated(fb) (!!(fb.bo))
 
-static u32 i915_gem_stolen_node_offset(struct xe_bo *bo)
+static inline u32 i915_gem_stolen_node_offset(struct i915_stolen_fb *fb)
 {
 	struct xe_res_cursor res;
 
-	xe_res_first(bo->ttm.resource, 0, 4096, &res);
+	xe_res_first(fb->bo->ttm.resource, 0, 4096, &res);
 	return res.start;
 }
 
-#define i915_gem_stolen_node_size(fb) ((u64)((fb)->ttm.base.size))
+#define i915_gem_stolen_node_size(fb) ((u64)((fb)->bo->ttm.base.size))
 #endif
 
 #define for_each_fbc_id(__dev_priv, __fbc_id) \
@@ -156,11 +165,7 @@ struct intel_fbc {
 	struct mutex lock;
 	unsigned int busy_bits;
 
-#ifdef I915
-	struct drm_mm_node compressed_fb, compressed_llb;
-#else
-	struct xe_bo *compressed_fb, *compressed_llb;
-#endif
+	struct i915_stolen_fb compressed_fb, compressed_llb;
 
 	enum intel_fbc_id id;
 
@@ -515,7 +520,7 @@ static void g4x_fbc_program_cfb(struct intel_fbc *fbc)
 	struct drm_i915_private *i915 = fbc->i915;
 
 	intel_de_write(i915, DPFC_CB_BASE,
-		       i915_gem_stolen_node_offset(fbc->compressed_fb));
+		       i915_gem_stolen_node_offset(&fbc->compressed_fb));
 }
 
 static const struct intel_fbc_funcs g4x_fbc_funcs = {
@@ -567,7 +572,7 @@ static void ilk_fbc_program_cfb(struct intel_fbc *fbc)
 	struct drm_i915_private *i915 = fbc->i915;
 
 	intel_de_write(i915, ILK_DPFC_CB_BASE(fbc->id),
-		       i915_gem_stolen_node_offset(fbc->compressed_fb));
+		       i915_gem_stolen_node_offset(&fbc->compressed_fb));
 }
 
 static const struct intel_fbc_funcs ilk_fbc_funcs = {
@@ -865,7 +870,7 @@ static int intel_fbc_alloc_cfb(struct intel_fbc *fbc,
 
 	drm_dbg_kms(&i915->drm,
 		    "reserved %llu bytes of contiguous stolen space for FBC, limit: %d\n",
-		    i915_gem_stolen_node_size(fbc->compressed_fb), fbc->limit);
+		    i915_gem_stolen_node_size(&fbc->compressed_fb), fbc->limit);
 
 	return 0;
 
@@ -1109,7 +1114,7 @@ static bool intel_fbc_is_cfb_ok(const struct intel_plane_state *plane_state)
 
 	return intel_fbc_min_limit(plane_state) <= fbc->limit &&
 		intel_fbc_cfb_size(plane_state) <= fbc->limit *
-			i915_gem_stolen_node_size(fbc->compressed_fb);
+			i915_gem_stolen_node_size(&fbc->compressed_fb);
 }
 
 static bool intel_fbc_is_ok(const struct intel_plane_state *plane_state)
drivers/gpu/drm/i915/gem/i915_gem_stolen.h +2 -0
index d5005a39d130..3c084a1fcc73 100644
@@ -12,6 +12,8 @@ struct drm_i915_private;
 struct drm_mm_node;
 struct drm_i915_gem_object;
 
+#define i915_stolen_fb drm_mm_node
+
 int i915_gem_stolen_insert_node(struct drm_i915_private *dev_priv,
 				struct drm_mm_node *node, u64 size,
 				unsigned alignment);
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/9 drm/xe: Add i915_gem.h compatibility header

In reply to Jouni Högander

Add i915_gem.h compatibility header and include it in i915_drv.h. Add GEM_BUG_ON definition for fbc code.

---
 drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h | 1 +
 drivers/gpu/drm/xe/compat-i915-headers/i915_gem.h | 9 +++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/compat-i915-headers/i915_gem.h
drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h +1 -0
index 89c718de0eab..0ccc97fb9e90 100644
@@ -14,6 +14,7 @@
 #include "xe_bo.h"
 #include "xe_pm.h"
 #include "xe_step.h"
+#include "i915_gem.h"
 #include "i915_gem_stolen.h"
 #include "i915_reg_defs.h"
 #include "intel_pch.h"
drivers/gpu/drm/xe/compat-i915-headers/i915_gem.h new file +9 -0
new file mode 100644
index 000000000000..4f1f5e175625
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef __I915_GEM_H__
+#define __I915_GEM_H__
+#define GEM_BUG_ON XE_BUG_ON
+#endif
Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/9 drivers/xe: Move Xe stolen memory handling away form fbc code

In reply to Jouni Högander

More correct place for Xe stolen memory handling details is in xe_ttm_stolen_mgr. Move it there and add necessary defines into i915_gem_stolen.h to satisfy fbc code.

---
 drivers/gpu/drm/i915/display/intel_fbc.c      | 62 -----------------
 .../xe/compat-i915-headers/i915_gem_stolen.h  | 66 +++++++++++++++++++
 drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c        |  8 +++
 drivers/gpu/drm/xe/xe_ttm_stolen_mgr.h        |  1 +
 4 files changed, 75 insertions(+), 62 deletions(-)
drivers/gpu/drm/i915/display/intel_fbc.c +0 -62
index 90c48ccce1a7..19698ab117a1 100644
@@ -61,68 +61,6 @@
 #define i915_gem_stolen_node_offset(node) ((node)->start)
 #define i915_gem_stolen_node_size(node) ((node)->size)
 
-#else
-
-#include "xe_ttm_stolen_mgr.h"
-#include "xe_res_cursor.h"
-
-static inline int i915_gem_stolen_insert_node_in_range(struct xe_device *xe,
-						       struct i915_stolen_fb *fb,
-						       u32 size, u32 align,
-						       u32 start, u32 end)
-{
-	struct xe_bo *bo;
-	int err;
-	u32 flags = XE_BO_CREATE_PINNED_BIT | XE_BO_CREATE_STOLEN_BIT;
-
-	bo = xe_bo_create_locked_range(xe, to_gt(xe), NULL, size, start, end,
-					ttm_bo_type_kernel, flags);
-	if (IS_ERR(bo)) {
-		err = PTR_ERR(bo);
-		bo = NULL;
-		return err;
-	}
-	err = xe_bo_pin(bo);
-	xe_bo_unlock_vm_held(bo);
-
-	if (err) {
-		xe_bo_put(bo);
-		bo = NULL;
-	}
-
-	fb->bo = bo;
-
-	return err;
-}
-
-static int i915_gem_stolen_insert_node(struct xe_device *xe,
-				       struct i915_stolen_fb *fb, u32 size,
-				       u32 align)
-{
-	/* Not used on xe */
-	BUG_ON(1);
-	return -ENODEV;
-}
-
-static void i915_gem_stolen_remove_node(struct xe_device *xe,
-					struct i915_stolen_fb *fb)
-{
-	xe_bo_unpin_map_no_vm(fb->bo);
-	fb->bo = NULL;
-}
-
-#define i915_gem_stolen_initialized(xe) (!!ttm_manager_type(&(xe)->ttm, XE_PL_STOLEN))
-#define i915_gem_stolen_node_allocated(fb) (!!(fb.bo))
-
-static inline u32 i915_gem_stolen_node_offset(struct i915_stolen_fb *fb)
-{
-	struct xe_res_cursor res;
-
-	xe_res_first(fb->bo->ttm.resource, 0, 4096, &res);
-	return res.start;
-}
-
-#define i915_gem_stolen_node_size(fb) ((u64)((fb)->bo->ttm.base.size))
 #endif
 
 #define for_each_fbc_id(__dev_priv, __fbc_id) \
drivers/gpu/drm/xe/compat-i915-headers/i915_gem_stolen.h +66 -0

76 lines not on this page · raw message

drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c +8 -0
index a3855870321f..2df059dd803b 100644
@@ -265,3 +265,11 @@ u64 xe_ttm_stolen_gpu_offset(struct xe_device *xe)
 
 	return mgr->stolen_base;
 }
+
+u64 xe_ttm_stolen_size(struct xe_device *xe)
+{
+	struct xe_ttm_stolen_mgr *mgr =
+		to_stolen_mgr(ttm_manager_type(&xe->ttm, XE_PL_STOLEN));
+
+	return mgr->base.visible_size;
+}
drivers/gpu/drm/xe/xe_ttm_stolen_mgr.h +1 -0
index 1777245ff810..48fed9a1ef95 100644
@@ -17,5 +17,6 @@ int xe_ttm_stolen_io_mem_reserve(struct xe_device *xe, struct ttm_resource *mem)
 bool xe_ttm_stolen_cpu_access_needs_ggtt(struct xe_device *xe);
 u64 xe_ttm_stolen_io_offset(struct xe_bo *bo, u32 offset);
 u64 xe_ttm_stolen_gpu_offset(struct xe_device *xe);
+u64 xe_ttm_stolen_size(struct xe_device *xe);
 
 #endif
Signature · 1 line
2.34.1
#6 lore raw

PATCH 6/9 drm/i915: Move stolen memory handling into i915_gem_stolen

In reply to Jouni Högander

We are preparing for Xe. As Xe stolen memory handling differs from i915 we want to move stolen memory handling details into i915_gem_stolen.

---
 drivers/gpu/drm/i915/display/intel_fbc.c   | 40 ++++++++--------------
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 37 ++++++++++++++++++++
 drivers/gpu/drm/i915/gem/i915_gem_stolen.h | 11 ++++++
 3 files changed, 62 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/display/intel_fbc.c +14 -26
index 19698ab117a1..b6fc993e6caf 100644
@@ -54,15 +54,6 @@
 #include "intel_fbc.h"
 #include "intel_frontbuffer.h"
 
-#ifdef I915
-
-#define i915_gem_stolen_initialized(i915) (drm_mm_initialized(&(i915)->mm.stolen))
-#define i915_gem_stolen_node_allocated(node) drm_mm_node_allocated(&(node))
-#define i915_gem_stolen_node_offset(node) ((node)->start)
-#define i915_gem_stolen_node_size(node) ((node)->size)
-
-#endif
-
 #define for_each_fbc_id(__dev_priv, __fbc_id) \
 	for ((__fbc_id) = INTEL_FBC_A; (__fbc_id) < I915_MAX_FBCS; (__fbc_id)++) \
 		for_each_if(RUNTIME_INFO(__dev_priv)->fbc_mask & BIT(__fbc_id))
@@ -338,19 +329,18 @@ static void i8xx_fbc_nuke(struct intel_fbc *fbc)
 
 static void i8xx_fbc_program_cfb(struct intel_fbc *fbc)
 {
-#ifdef I915
 	struct drm_i915_private *i915 = fbc->i915;
 
-	GEM_BUG_ON(range_overflows_end_t(u64, i915->dsm.stolen.start,
-					 fbc->compressed_fb.start, U32_MAX));
-	GEM_BUG_ON(range_overflows_end_t(u64, i915->dsm.stolen.start,
-					 fbc->compressed_llb.start, U32_MAX));
-
+	GEM_BUG_ON(range_overflows_end_t(u64, i915_gem_stolen_area_address(i915),
+					 i915_gem_stolen_node_offset(&fbc->compressed_fb),
+					 U32_MAX));
+	GEM_BUG_ON(range_overflows_end_t(u64, i915_gem_stolen_area_address(i915),
+					 i915_gem_stolen_node_offset(&fbc->compressed_llb),
+					 U32_MAX));
 	intel_de_write(i915, FBC_CFB_BASE,
-		       i915->dsm.stolen.start + fbc->compressed_fb.start);
+		       i915_gem_stolen_node_address(i915, &fbc->compressed_fb));
 	intel_de_write(i915, FBC_LL_BASE,
-		       i915->dsm.stolen.start + fbc->compressed_llb.start);
-#endif
+		       i915_gem_stolen_node_address(i915, &fbc->compressed_llb));
 }
 
 static const struct intel_fbc_funcs i8xx_fbc_funcs = {
@@ -725,12 +715,10 @@ static u64 intel_fbc_stolen_end(struct drm_i915_private *i915)
 	 * reserved range size, so it always assumes the maximum (8mb) is used.
 	 * If we enable FBC using a CFB on that memory range we'll get FIFO
 	 * underruns, even if that range is not reserved by the BIOS. */
-#ifdef I915
 	if (IS_BROADWELL(i915) ||
 	    (DISPLAY_VER(i915) == 9 && !IS_BROXTON(i915)))
-		end = resource_size(&i915->dsm.stolen) - 8 * 1024 * 1024;
+		end = i915_gem_stolen_area_size(i915) - 8 * 1024 * 1024;
 	else
-#endif
 		end = U64_MAX;
 
 	return min(end, intel_fbc_cfb_base_max(i915));
@@ -786,9 +774,9 @@ static int intel_fbc_alloc_cfb(struct intel_fbc *fbc,
 	int ret;
 
 	drm_WARN_ON(&i915->drm,
-		    i915_gem_stolen_node_allocated(fbc->compressed_fb));
+		    i915_gem_stolen_node_allocated(&fbc->compressed_fb));
 	drm_WARN_ON(&i915->drm,
-		    i915_gem_stolen_node_allocated(fbc->compressed_llb));
+		    i915_gem_stolen_node_allocated(&fbc->compressed_llb));
 
 	if (DISPLAY_VER(i915) < 5 && !IS_G4X(i915)) {
 		ret = i915_gem_stolen_insert_node(i915, &fbc->compressed_llb,
@@ -813,7 +801,7 @@ static int intel_fbc_alloc_cfb(struct intel_fbc *fbc,
 	return 0;
 
 err_llb:
-	if (i915_gem_stolen_node_allocated(fbc->compressed_llb))
+	if (i915_gem_stolen_node_allocated(&fbc->compressed_llb))
 		i915_gem_stolen_remove_node(i915, &fbc->compressed_llb);
 err:
 	if (i915_gem_stolen_initialized(i915))
@@ -841,9 +829,9 @@ static void __intel_fbc_cleanup_cfb(struct intel_fbc *fbc)
 	if (WARN_ON(intel_fbc_hw_is_active(fbc)))
 		return;
 
-	if (i915_gem_stolen_node_allocated(fbc->compressed_llb))
+	if (i915_gem_stolen_node_allocated(&fbc->compressed_llb))
 		i915_gem_stolen_remove_node(i915, &fbc->compressed_llb);
-	if (i915_gem_stolen_node_allocated(fbc->compressed_fb))
+	if (i915_gem_stolen_node_allocated(&fbc->compressed_fb))
 		i915_gem_stolen_remove_node(i915, &fbc->compressed_fb);
 }
 
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +37 -0
index ee492d823f1b..04cc6958cddf 100644
@@ -972,3 +972,40 @@ bool i915_gem_object_is_stolen(const struct drm_i915_gem_object *obj)
 {
 	return obj->ops == &i915_gem_object_stolen_ops;
 }
+
+bool i915_gem_stolen_initialized(const struct drm_i915_private *i915)
+{
+	return drm_mm_initialized(&i915->mm.stolen);
+}
+
+u64 i915_gem_stolen_area_address(const struct drm_i915_private *i915)
+{
+	return i915->dsm.stolen.start;
+}
+
+u64 i915_gem_stolen_area_size(const struct drm_i915_private *i915)
+{
+	return resource_size(&i915->dsm.stolen);
+}
+
+u64 i915_gem_stolen_node_address(const struct drm_i915_private *i915,
+			const struct drm_mm_node *node)
+{
+	return i915->dsm.stolen.start + i915_gem_stolen_node_offset(node);
+}
+
+
+bool i915_gem_stolen_node_allocated(const struct drm_mm_node *node)
+{
+	return drm_mm_node_allocated(node);
+}
+
+u64 i915_gem_stolen_node_offset(const struct drm_mm_node *node)
+{
+	return node->start;
+}
+
+u64 i915_gem_stolen_node_size(const struct drm_mm_node *node)
+{
+	return node->size;
+}
drivers/gpu/drm/i915/gem/i915_gem_stolen.h +11 -0
index 3c084a1fcc73..ccebd24d65a9 100644
@@ -38,4 +38,15 @@ bool i915_gem_object_is_stolen(const struct drm_i915_gem_object *obj);
 
 #define I915_GEM_STOLEN_BIAS SZ_128K
 
+bool i915_gem_stolen_initialized(const struct drm_i915_private *i915);
+u64 i915_gem_stolen_area_address(const struct drm_i915_private *i915);
+u64 i915_gem_stolen_area_size(const struct drm_i915_private *i915);
+
+u64 i915_gem_stolen_node_address(const struct drm_i915_private *i915,
+			    const struct drm_mm_node *node);
+
+bool i915_gem_stolen_node_allocated(const struct drm_mm_node *node);
+u64 i915_gem_stolen_node_offset(const struct drm_mm_node *node);
+u64 i915_gem_stolen_node_size(const struct drm_mm_node *node);
+
 #endif /* __I915_GEM_STOLEN_H__ */
Signature · 1 line
2.34.1
#7 lore raw

PATCH 7/9 drm/i915/fbc: Stolen initialize can be checked in plane check for i915 as well

In reply to Jouni Högander

There is no specific reason to differentiate i915 and Xe in stolen are initialization status. We can check it in plane check for i915 as well.

---
 drivers/gpu/drm/i915/display/intel_fbc.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/i915/display/intel_fbc.c +0 -7
index b6fc993e6caf..109f86bb19ef 100644
@@ -1064,12 +1064,10 @@ static int intel_fbc_check_plane(struct intel_atomic_state *state,
 	if (!fbc)
 		return 0;
 
-#ifndef I915
 	if (!i915_gem_stolen_initialized(i915)) {
 		plane_state->no_fbc_reason = "stolen memory not initialised";
 		return 0;
 	}
-#endif
 
 	if (intel_vgpu_active(i915)) {
 		plane_state->no_fbc_reason = "VGPU active";
@@ -1724,11 +1722,6 @@ void intel_fbc_init(struct drm_i915_private *i915)
 {
 	enum intel_fbc_id fbc_id;
 
-#ifdef I915
-	if (!i915_gem_stolen_initialized(i915))
-		RUNTIME_INFO(i915)->fbc_mask = 0;
-#endif
-
 	if (need_fbc_vtd_wa(i915))
 		RUNTIME_INFO(i915)->fbc_mask = 0;
 
Signature · 1 line
2.34.1
#8 lore raw

PATCH 8/9 drm/i915/fbc: Add function to get number of fences for gt

In reply to Jouni Högander

Add new function to get number of fences for gt. This allows removing couple of ifdefs.

---
 drivers/gpu/drm/i915/display/intel_fbc.c          | 4 +---
 drivers/gpu/drm/i915/gt/intel_gt_types.h          | 2 ++
 drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h | 3 +++
 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/display/intel_fbc.c +1 -3
index 109f86bb19ef..2cb537504c2f 100644
@@ -607,10 +607,8 @@ static void ivb_fbc_activate(struct intel_fbc *fbc)
 	else if (DISPLAY_VER(i915) == 9)
 		skl_fbc_program_cfb_stride(fbc);
 
-#ifdef I915
-	if (to_gt(i915)->ggtt->num_fences)
+	if (intel_gt_fence_count(to_gt(i915)))
 		snb_fbc_program_fence(fbc);
-#endif
 
 	intel_de_write(i915, ILK_DPFC_CONTROL(fbc->id),
 		       DPFC_CTL_EN | ivb_dpfc_ctl(fbc));
drivers/gpu/drm/i915/gt/intel_gt_types.h +2 -0
index f08c2556aa25..76bc88d974b2 100644
@@ -306,4 +306,6 @@ enum intel_gt_scratch_field {
 	INTEL_GT_SCRATCH_FIELD_COHERENTL3_WA = 256,
 };
 
+#define intel_gt_fence_count(gt) gt->ggtt->num_fences
+
 #endif /* __INTEL_GT_TYPES_H__ */
drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h +3 -0
index 0ccc97fb9e90..89ff4e984e6b 100644
@@ -19,9 +19,12 @@
 #include "i915_reg_defs.h"
 #include "intel_pch.h"
 #include "i915_utils.h"
+#include "intel_gt_types.h"
 #include "intel_uncore.h"
 #include <linux/pm_runtime.h>
 
+#define intel_gt_fence_count(gt) 0
+
 static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
 {
 	return container_of(dev, struct drm_i915_private, drm);
Signature · 1 line
2.34.1
#9 lore raw

PATCH 9/9 Add new fence_id and fence count functions

In reply to Jouni Högander

Add new fence id and fence count functions and use them instead of directly accessing struct members

---
 drivers/gpu/drm/i915/display/intel_fbc.c         | 16 +++++-----------
 drivers/gpu/drm/i915/i915_vma.h                  |  5 +++++
 .../gpu/drm/xe/compat-i915-headers/i915_vma.h    |  2 ++
 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/display/intel_fbc.c +5 -11
index 2cb537504c2f..7e4dcd747c02 100644
@@ -47,6 +47,7 @@
 #include "i915_reg.h"
 #include "i915_utils.h"
 #include "i915_vgpu.h"
+#include "i915_vma.h"
 #include "intel_cdclk.h"
 #include "intel_de.h"
 #include "intel_display_trace.h"
@@ -988,17 +989,14 @@ static void intel_fbc_update_state(struct intel_atomic_state *state,
 
 	/* FBC1 compression interval: arbitrary choice of 1 second */
 	fbc_state->interval = drm_mode_vrefresh(&crtc_state->hw.adjusted_mode);
-#ifdef I915
 	fbc_state->fence_y_offset = intel_plane_fence_y_offset(plane_state);
 
 	drm_WARN_ON(&i915->drm, plane_state->flags & PLANE_HAS_FENCE &&
-		    !plane_state->ggtt_vma->fence);
+		    !intel_gt_fence_count(to_gt(i915)));
 
-	if (plane_state->flags & PLANE_HAS_FENCE &&
-	    plane_state->ggtt_vma->fence)
-		fbc_state->fence_id = plane_state->ggtt_vma->fence->id;
+	if (plane_state->flags & PLANE_HAS_FENCE)
+		fbc_state->fence_id =  i915_vma_fence_id(plane_state->ggtt_vma);
 	else
-#endif
 		fbc_state->fence_id = -1;
 
 	fbc_state->cfb_stride = intel_fbc_cfb_stride(plane_state);
@@ -1008,7 +1006,6 @@ static void intel_fbc_update_state(struct intel_atomic_state *state,
 
 static bool intel_fbc_is_fence_ok(const struct intel_plane_state *plane_state)
 {
-#ifdef I915
 	struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
 
 	/*
@@ -1025,10 +1022,7 @@ static bool intel_fbc_is_fence_ok(const struct intel_plane_state *plane_state)
 	 */
 	return DISPLAY_VER(i915) >= 9 ||
 		(plane_state->flags & PLANE_HAS_FENCE &&
-		 plane_state->ggtt_vma->fence);
-#else
-	return true;
-#endif
+		 i915_vma_fence_id(plane_state->ggtt_vma) != -1);
 }
 
 static bool intel_fbc_is_cfb_ok(const struct intel_plane_state *plane_state)
drivers/gpu/drm/i915/i915_vma.h +5 -0
index ed5c9d682a1b..06e613752c55 100644
@@ -418,6 +418,11 @@ i915_vma_unpin_fence(struct i915_vma *vma)
 		__i915_vma_unpin_fence(vma);
 }
 
+static inline int i915_vma_fence_id(const struct i915_vma *vma)
+{
+	return vma->fence ? vma->fence->id : -1;
+}
+
 void i915_vma_parked(struct intel_gt *gt);
 
 static inline bool i915_vma_is_scanout(const struct i915_vma *vma)
drivers/gpu/drm/xe/compat-i915-headers/i915_vma.h +2 -0
index c40bb27ac72a..45ea0e44073d 100644
@@ -11,4 +11,6 @@ struct i915_vma {
 	struct drm_mm_node node;
 };
 
+#define i915_vma_fence_id(vma) -1
+
 #endif
Signature · 1 line
2.34.1
#10 lore raw

[Intel-xe] ✓ CI.Patch_applied: success for Clean-up Xe FBC additions

In reply to Jouni Högander
== Series Details ==

== Series Details ==

Series: Clean-up Xe FBC additions
URL : https://patchwork.freedesktop.org/series/118560/
State : success

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: ===
Base commit: d57bb4c83 fixup! drm/xe: Introduce a new DRM driver for Intel GPUs === git am output follows ===
Applying: fixup! drm/i915/display: Implement FBC support
Applying: drivers/xe: Add new type for compressed fb
Applying: drm/i915/fbc: Add common type for compressed fb to avoid ifdefs
Applying: drm/xe: Add i915_gem.h compatibility header
Applying: drivers/xe: Move Xe stolen memory handling away form fbc code
Applying: drm/i915: Move stolen memory handling into i915_gem_stolen
Applying: drm/i915/fbc: Stolen initialize can be checked in plane check for i915 as well
Applying: drm/i915/fbc: Add function to get number of fences for gt
Applying: Add new fence_id and fence count functions

#11 lore raw

[Intel-xe] ✗ CI.KUnit: failure for Clean-up Xe FBC additions

In reply to Jouni Högander
== Series Details ==

== Series Details ==

Series: Clean-up Xe FBC additions
URL : https://patchwork.freedesktop.org/series/118560/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:In file included from ../drivers/gpu/drm/xe/display/xe_fb_pin.c:6:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
22 | #include "intel_gt_types.h"

      |          ^~~~~~~~~~~~~~~~~~

compilation terminated.
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/xe_fb_pin.o] Error 1 make[6]: *** Waiting for unfinished jobs....
In file included from ../drivers/gpu/drm/i915/display/intel_hdcp_gsc.h:11,

                 from ../drivers/gpu/drm/xe/display/xe_hdcp_gsc.c:6:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
   22 | #include "intel_gt_types.h"
      |          ^~~~~~~~~~~~~~~~~~

compilation terminated.
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/xe_hdcp_gsc.o] Error 1
In file included from ../drivers/gpu/drm/xe/display/xe_plane_initial.c:11:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
22 | #include "intel_gt_types.h"

      |          ^~~~~~~~~~~~~~~~~~

compilation terminated.
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/xe_plane_initial.o] Error 1 In file included from ../drivers/gpu/drm/xe/display/ext/i915_irq.c:37:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
22 | #include "intel_gt_types.h"

      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/ext/i915_irq.o] Error 1
In file included from ../drivers/gpu/drm/i915/display/intel_de.h:9,
                 from ../drivers/gpu/drm/xe/display/ext/intel_device_info.c:26:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
   22 | #include "intel_gt_types.h"
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
In file included from ../drivers/gpu/drm/i915/display/intel_de.h:9,
                 from ../drivers/gpu/drm/xe/display/ext/intel_clock_gating.c:28:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
   22 | #include "intel_gt_types.h"
      |          ^~~~~~~~~~~~~~~~~~

compilation terminated.
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/ext/intel_device_info.o] Error 1 make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/ext/intel_clock_gating.o] Error 1 In file included from ../drivers/gpu/drm/xe/display/ext/intel_dram.c:8:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
22 | #include "intel_gt_types.h"

      |          ^~~~~~~~~~~~~~~~~~

compilation terminated.
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/ext/intel_dram.o] Error 1 In file included from ../drivers/gpu/drm/xe/display/ext/intel_pch.c:6:
../drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h:22:10: fatal error: intel_gt_types.h: No such file or directory
22 | #include "intel_gt_types.h"

      |          ^~~~~~~~~~~~~~~~~~

compilation terminated.
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/display/ext/intel_pch.o] Error 1 make[5]: *** [../scripts/Makefile.build:494: drivers/gpu/drm/xe] Error 2 make[5]: *** Waiting for unfinished jobs....
make[4]: *** [../scripts/Makefile.build:494: drivers/gpu/drm] Error 2
make[3]: *** [../scripts/Makefile.build:494: drivers/gpu] Error 2
make[2]: *** [../scripts/Makefile.build:494: drivers] Error 2
make[1]: *** [/kernel/Makefile:2025: .] Error 2
make: *** [Makefile:226: __sub-make] Error 2

[10:38:07] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[10:38:11] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make ARCH=um O=.kunit --jobs=48
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel