Skip to contentSkip to conversation

drm/i915/dsb: DSB code refactoring

PATCH In review Animesh Manna 4 participants 12 messages Sep 22, 2023 – Sep 27, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/dsb: DSB code refactoring

Refactor DSB implementation to be compatible with Xe driver.

---
 drivers/gpu/drm/i915/Makefile                |   1 +
 drivers/gpu/drm/i915/display/intel_dsb.c     | 115 ++++---------------
 drivers/gpu/drm/i915/display/intel_dsb.h     |  41 ++++++-
 drivers/gpu/drm/i915/display/intel_dsb_ops.c |  67 +++++++++++
 4 files changed, 130 insertions(+), 94 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/display/intel_dsb_ops.c
drivers/gpu/drm/i915/Makefile +1 -0
index 1b2e02e9d92c..7fbb5055b85b 100644
@@ -256,6 +256,7 @@ i915-y += \
 	display/intel_dpt.o \
 	display/intel_drrs.o \
 	display/intel_dsb.o \
+	display/intel_dsb_ops.o \
 	display/intel_fb.o \
 	display/intel_fb_pin.o \
 	display/intel_fbc.o \
drivers/gpu/drm/i915/display/intel_dsb.c +22 -93

211 lines not on this page · raw message

drivers/gpu/drm/i915/display/intel_dsb.h +40 -1

52 lines not on this page · raw message

drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.29.0
#1 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915/dsb: DSB code refactoring

== Series Details ==

== Series Details ==

Series: drm/i915/dsb: DSB code refactoring
URL : https://patchwork.freedesktop.org/series/124141/
State : warning

== Summary ==

Error: dim checkpatch failed
c1292402cc6a drm/i915/dsb: DSB code refactoring
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:308: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #308:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 324 lines checked

#2 lore raw

[Intel-gfx] ✗ Fi.CI.SPARSE: warning for drm/i915/dsb: DSB code refactoring

In reply to Animesh Manna
== Series Details ==

== Series Details ==

Series: drm/i915/dsb: DSB code refactoring
URL : https://patchwork.freedesktop.org/series/124141/
State : warning

== Summary ==

Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately. +./arch/x86/include/asm/bitops.h:117:1: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:148:1: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:150:9: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:154:26: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:156:16: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:156:9: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:174:1: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:176:9: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:180:35: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:182:16: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:182:9: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:186:1: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:188:9: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:192:35: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:195:16: warning: unreplaced symbol 'oldbit' +./arch/x86/include/asm/bitops.h:195:9: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:237:1: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:239:9: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:66:1: warning: unreplaced symbol 'return' +./arch/x86/include/asm/bitops.h:92:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:100:17: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:100:23: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:100:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:105:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:107:9: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:108:9: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:109:9: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:111:10: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:111:14: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:111:20: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:112:17: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:112:23: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:112:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:121:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:128:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:166:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:168:9: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:169:9: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:170:9: warning: unreplaced symbol 'val' +./include/asm-generic/bitops/generic-non-atomic.h:172:19: warning: unreplaced symbol 'val' +./include/asm-generic/bitops/generic-non-atomic.h:172:25: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:172:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:28:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:30:9: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:31:9: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:33:10: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:33:16: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:37:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:39:9: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:40:9: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:42:10: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:42:16: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:55:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:57:9: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:58:9: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:60:10: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:60:15: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:73:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:75:9: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:76:9: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:77:9: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:79:10: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:79:14: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:79:20: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:80:17: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:80:23: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:80:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:93:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/generic-non-atomic.h:95:9: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/generic-non-atomic.h:96:9: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:97:9: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:99:10: warning: unreplaced symbol 'p' +./include/asm-generic/bitops/generic-non-atomic.h:99:14: warning: unreplaced symbol 'old' +./include/asm-generic/bitops/generic-non-atomic.h:99:21: warning: unreplaced symbol 'mask' +./include/asm-generic/bitops/instrumented-non-atomic.h:100:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:112:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:115:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:127:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:130:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:139:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:142:9: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:26:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:42:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:58:1: warning: unreplaced symbol 'return' +./include/asm-generic/bitops/instrumented-non-atomic.h:97:1: warning: unreplaced symbol 'return'

#3 lore raw

[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915/dsb: DSB code refactoring

In reply to Animesh Manna
== Series Details ==

== Series Details ==

Series: drm/i915/dsb: DSB code refactoring
URL : https://patchwork.freedesktop.org/series/124141/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_13671 -> Patchwork_124141v1
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_124141v1 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes
introduced in Patchwork_124141v1, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/index.html

Participating hosts (39 -> 38)
------------------------------

Additional (1): fi-hsw-4770
Missing (2): fi-snb-2520m fi-pnv-d510

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_124141v1:

### IGT changes ###

#### Possible regressions ####

* igt@i915_selftest@live@hangcheck:
- fi-skl-guc: [PASS][1] -> [DMESG-FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13671/fi-skl-guc/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/fi-skl-guc/igt@i915_selftest@[email protected]

Known issues
------------

Here are the changes found in Patchwork_124141v1 that come from known issues:

### CI changes ###

#### Issues hit ####

* boot:
- fi-hsw-4770: NOTRUN -> [FAIL][3] ([i915#8293])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/fi-hsw-4770/boot.html

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_suspend@basic-s0@smem:
- bat-dg2-9: [PASS][4] -> [INCOMPLETE][5] ([i915#9275])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13671/bat-dg2-9/igt@gem_exec_suspend@[email protected]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/bat-dg2-9/igt@gem_exec_suspend@[email protected]

* igt@kms_hdmi_inject@inject-audio:
- fi-kbl-guc: [PASS][6] -> [FAIL][7] ([IGT#3])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13671/fi-kbl-guc/igt@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/fi-kbl-guc/igt@[email protected]

#### Possible fixes ####

* igt@kms_chamelium_edid@hdmi-edid-read:
- {bat-dg2-13}: [DMESG-WARN][8] ([i915#7952]) -> [PASS][9]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13671/bat-dg2-13/igt@[email protected]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/bat-dg2-13/igt@[email protected]

* igt@kms_frontbuffer_tracking@basic:
- fi-bsw-nick: [FAIL][10] ([i915#9276]) -> [PASS][11]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13671/fi-bsw-nick/igt@[email protected]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/fi-bsw-nick/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[IGT#3]: https://gitlab.freedesktop.org/drm/igt-gpu-tools/issues/3
[i915#7952]: https://gitlab.freedesktop.org/drm/intel/issues/7952
[i915#8293]: https://gitlab.freedesktop.org/drm/intel/issues/8293
[i915#9275]: https://gitlab.freedesktop.org/drm/intel/issues/9275
[i915#9276]: https://gitlab.freedesktop.org/drm/intel/issues/9276

Build changes
-------------

* Linux: CI_DRM_13671 -> Patchwork_124141v1

CI-20190529: 20190529
CI_DRM_13671: e1973de2c4516e9130157e538014e79c8aa57b41 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7498: 05d14fd260a3cf9dc00ed24733d5589eee32ec08 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_124141v1: e1973de2c4516e9130157e538014e79c8aa57b41 @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

e337ef763336 drm/i915/dsb: DSB code refactoring

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_124141v1/index.html

maintainer
#4 lore raw
In reply to Animesh Manna
Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

BR,
Jani.

Quoted 380 lines
---
 drivers/gpu/drm/i915/Makefile                |   1 +
 drivers/gpu/drm/i915/display/intel_dsb.c     | 115 ++++---------------
 drivers/gpu/drm/i915/display/intel_dsb.h     |  41 ++++++-
 drivers/gpu/drm/i915/display/intel_dsb_ops.c |  67 +++++++++++
 4 files changed, 130 insertions(+), 94 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/display/intel_dsb_ops.c
drivers/gpu/drm/i915/Makefile +1 -0
index 1b2e02e9d92c..7fbb5055b85b 100644
@@ -256,6 +256,7 @@ i915-y += \
 	display/intel_dpt.o \
 	display/intel_drrs.o \
 	display/intel_dsb.o \
+	display/intel_dsb_ops.o \
 	display/intel_fb.o \
 	display/intel_fb_pin.o \
 	display/intel_fbc.o \
drivers/gpu/drm/i915/display/intel_dsb.c +22 -93
index 9a507b9ad82c..f7c6b9aa130f 100644
@@ -4,8 +4,6 @@
  *
  */
 
-#include "gem/i915_gem_internal.h"
-
 #include "i915_drv.h"
 #include "i915_reg.h"
 #include "intel_de.h"
@@ -13,41 +11,7 @@
 #include "intel_dsb.h"
 #include "intel_dsb_regs.h"
 
-struct i915_vma;
-
-enum dsb_id {
-	INVALID_DSB = -1,
-	DSB1,
-	DSB2,
-	DSB3,
-	MAX_DSB_PER_PIPE
-};
-
-struct intel_dsb {
-	enum dsb_id id;
-
-	u32 *cmd_buf;
-	struct i915_vma *vma;
-	struct intel_crtc *crtc;
-
-	/*
-	 * maximum number of dwords the buffer will hold.
-	 */
-	unsigned int size;
-
-	/*
-	 * free_pos will point the first free dword and
-	 * help in calculating tail of command buffer.
-	 */
-	unsigned int free_pos;
-
-	/*
-	 * ins_start_offset will help to store start dword of the dsb
-	 * instuction and help in identifying the batch of auto-increment
-	 * register.
-	 */
-	unsigned int ins_start_offset;
-};
+#define CACHELINE_BYTES 64
 
 /**
  * DOC: DSB
@@ -117,8 +81,6 @@ static bool is_dsb_busy(struct drm_i915_private *i915, enum pipe pipe,
 
 static void intel_dsb_emit(struct intel_dsb *dsb, u32 ldw, u32 udw)
 {
-	u32 *buf = dsb->cmd_buf;
-
 	if (!assert_dsb_has_room(dsb))
 		return;
 
@@ -127,14 +89,13 @@ static void intel_dsb_emit(struct intel_dsb *dsb, u32 ldw, u32 udw)
 
 	dsb->ins_start_offset = dsb->free_pos;
 
-	buf[dsb->free_pos++] = ldw;
-	buf[dsb->free_pos++] = udw;
+	intel_dsb_write(dsb, dsb->free_pos++, ldw);
+	intel_dsb_write(dsb, dsb->free_pos++, udw);
 }
 
 static bool intel_dsb_prev_ins_is_write(struct intel_dsb *dsb,
 					u32 opcode, i915_reg_t reg)
 {
-	const u32 *buf = dsb->cmd_buf;
 	u32 prev_opcode, prev_reg;
 
 	/*
@@ -145,8 +106,8 @@ static bool intel_dsb_prev_ins_is_write(struct intel_dsb *dsb,
 	if (dsb->free_pos == 0)
 		return false;
 
-	prev_opcode = buf[dsb->ins_start_offset + 1] & ~DSB_REG_VALUE_MASK;
-	prev_reg = buf[dsb->ins_start_offset + 1] & DSB_REG_VALUE_MASK;
+	prev_opcode = intel_dsb_read(dsb, dsb->ins_start_offset + 1) >> DSB_OPCODE_SHIFT;
+	prev_reg =  intel_dsb_read(dsb, dsb->ins_start_offset + 1) & DSB_REG_VALUE_MASK;
 
 	return prev_opcode == opcode && prev_reg == i915_mmio_reg_offset(reg);
 }
@@ -179,6 +140,8 @@ static bool intel_dsb_prev_ins_is_indexed_write(struct intel_dsb *dsb, i915_reg_
 void intel_dsb_reg_write(struct intel_dsb *dsb,
 			 i915_reg_t reg, u32 val)
 {
+	u32 old_val;
+
 	/*
 	 * For example the buffer will look like below for 3 dwords for auto
 	 * increment register:
@@ -202,31 +165,30 @@ void intel_dsb_reg_write(struct intel_dsb *dsb,
 			       (DSB_BYTE_EN << DSB_BYTE_EN_SHIFT) |
 			       i915_mmio_reg_offset(reg));
 	} else {
-		u32 *buf = dsb->cmd_buf;
-
 		if (!assert_dsb_has_room(dsb))
 			return;
 
 		/* convert to indexed write? */
 		if (intel_dsb_prev_ins_is_mmio_write(dsb, reg)) {
-			u32 prev_val = buf[dsb->ins_start_offset + 0];
+			u32 prev_val = intel_dsb_read(dsb, dsb->ins_start_offset + 0);
 
-			buf[dsb->ins_start_offset + 0] = 1; /* count */
-			buf[dsb->ins_start_offset + 1] =
-				(DSB_OPCODE_INDEXED_WRITE << DSB_OPCODE_SHIFT) |
-				i915_mmio_reg_offset(reg);
-			buf[dsb->ins_start_offset + 2] = prev_val;
+			intel_dsb_write(dsb, dsb->ins_start_offset + 0, 1); /* count */
+			intel_dsb_write(dsb, dsb->ins_start_offset + 1,
+					(DSB_OPCODE_INDEXED_WRITE << DSB_OPCODE_SHIFT) |
+					i915_mmio_reg_offset(reg));
+			intel_dsb_write(dsb, dsb->ins_start_offset + 2, prev_val);
 
 			dsb->free_pos++;
 		}
 
-		buf[dsb->free_pos++] = val;
+		intel_dsb_write(dsb, dsb->free_pos++, val);
 		/* Update the count */
-		buf[dsb->ins_start_offset]++;
+		old_val = intel_dsb_read(dsb, dsb->ins_start_offset);
+		intel_dsb_write(dsb, dsb->ins_start_offset, old_val + 1);
 
 		/* if number of data words is odd, then the last dword should be 0.*/
 		if (dsb->free_pos & 0x1)
-			buf[dsb->free_pos] = 0;
+			intel_dsb_write(dsb, dsb->free_pos, 0);
 	}
 }
 
@@ -238,8 +200,8 @@ static void intel_dsb_align_tail(struct intel_dsb *dsb)
 	aligned_tail = ALIGN(tail, CACHELINE_BYTES);
 
 	if (aligned_tail > tail)
-		memset(&dsb->cmd_buf[dsb->free_pos], 0,
-		       aligned_tail - tail);
+		intel_dsb_memset(dsb, dsb->free_pos, 0,
+				 aligned_tail - tail);
 
 	dsb->free_pos = aligned_tail / 4;
 }
@@ -277,9 +239,9 @@ void intel_dsb_commit(struct intel_dsb *dsb, bool wait_for_vblank)
 		       (wait_for_vblank ? DSB_WAIT_FOR_VBLANK : 0) |
 		       DSB_ENABLE);
 	intel_de_write(dev_priv, DSB_HEAD(pipe, dsb->id),
-		       i915_ggtt_offset(dsb->vma));
+		       intel_dsb_ggtt_offset(dsb));
 	intel_de_write(dev_priv, DSB_TAIL(pipe, dsb->id),
-		       i915_ggtt_offset(dsb->vma) + tail);
+		       intel_dsb_ggtt_offset(dsb) + tail);
 }
 
 void intel_dsb_wait(struct intel_dsb *dsb)
@@ -325,12 +287,9 @@ struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,
 				    unsigned int max_cmds)
 {
 	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
-	struct drm_i915_gem_object *obj;
 	intel_wakeref_t wakeref;
 	struct intel_dsb *dsb;
-	struct i915_vma *vma;
 	unsigned int size;
-	u32 *buf;
 
 	if (!HAS_DSB(i915))
 		return NULL;
@@ -344,28 +303,11 @@ struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,
 	/* ~1 qword per instruction, full cachelines */
 	size = ALIGN(max_cmds * 8, CACHELINE_BYTES);
 
-	obj = i915_gem_object_create_internal(i915, PAGE_ALIGN(size));
-	if (IS_ERR(obj))
-		goto out_put_rpm;
-
-	vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
-	if (IS_ERR(vma)) {
-		i915_gem_object_put(obj);
+	if (!intel_dsb_buffer_create(crtc, dsb, size))
 		goto out_put_rpm;
-	}
-
-	buf = i915_gem_object_pin_map_unlocked(vma->obj, I915_MAP_WC);
-	if (IS_ERR(buf)) {
-		i915_vma_unpin_and_release(&vma, I915_VMA_RELEASE_MAP);
-		goto out_put_rpm;
-	}
 
 	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
 
-	dsb->id = DSB1;
-	dsb->vma = vma;
-	dsb->crtc = crtc;
-	dsb->cmd_buf = buf;
 	dsb->size = size / 4; /* in dwords */
 	dsb->free_pos = 0;
 	dsb->ins_start_offset = 0;
@@ -382,16 +324,3 @@ struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,
 
 	return NULL;
 }
-
-/**
- * intel_dsb_cleanup() - To cleanup DSB context.
- * @dsb: DSB context
- *
- * This function cleanup the DSB context by unpinning and releasing
- * the VMA object associated with it.
- */
-void intel_dsb_cleanup(struct intel_dsb *dsb)
-{
-	i915_vma_unpin_and_release(&dsb->vma, I915_VMA_RELEASE_MAP);
-	kfree(dsb);
-}
drivers/gpu/drm/i915/display/intel_dsb.h +40 -1
index b8148b47022d..7feeb37e00a5 100644
@@ -11,7 +11,41 @@
 #include "i915_reg_defs.h"
 
 struct intel_crtc;
-struct intel_dsb;
+struct i915_vma;
+
+enum dsb_id {
+	INVALID_DSB = -1,
+	DSB1,
+	DSB2,
+	DSB3,
+	MAX_DSB_PER_PIPE
+};
+
+struct intel_dsb {
+	enum dsb_id id;
+
+	u32 *cmd_buf;
+	struct i915_vma *vma;
+	struct intel_crtc *crtc;
+
+	/*
+	 * maximum number of dwords the buffer will hold.
+	 */
+	unsigned int size;
+
+	/*
+	 * free_pos will point the first free dword and
+	 * help in calculating tail of command buffer.
+	 */
+	unsigned int free_pos;
+
+	/*
+	 * ins_start_offset will help to store start dword of the dsb
+	 * instuction and help in identifying the batch of auto-increment
+	 * register.
+	 */
+	unsigned int ins_start_offset;
+};
 
 struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,
 				    unsigned int max_cmds);
@@ -22,5 +56,10 @@ void intel_dsb_reg_write(struct intel_dsb *dsb,
 void intel_dsb_commit(struct intel_dsb *dsb,
 		      bool wait_for_vblank);
 void intel_dsb_wait(struct intel_dsb *dsb);
+u32 intel_dsb_ggtt_offset(struct intel_dsb *dsb);
+void intel_dsb_write(struct intel_dsb *dsb, u32 idx, u32 val);
+u32 intel_dsb_read(struct intel_dsb *dsb, u32 idx);
+void intel_dsb_memset(struct intel_dsb *dsb, u32 idx, u32 val, u32 sz);
+bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct intel_dsb *dsb, u32 size);
 
 #endif
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +67 -0
new file mode 100644
index 000000000000..9fe125abb890
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2023, Intel Corporation.
+ */
+
+#include "gem/i915_gem_internal.h"
+#include "i915_drv.h"
+#include "i915_vma.h"
+#include "intel_display_types.h"
+#include "intel_dsb.h"
+
+u32 intel_dsb_ggtt_offset(struct intel_dsb *dsb)
+{
+	return i915_ggtt_offset(dsb->vma);
+}
+
+void intel_dsb_write(struct intel_dsb *dsb, u32 idx, u32 val)
+{
+	dsb->cmd_buf[idx] = val;
+}
+
+u32 intel_dsb_read(struct intel_dsb *dsb, u32 idx)
+{
+	return dsb->cmd_buf[idx];
+}
+
+void intel_dsb_memset(struct intel_dsb *dsb, u32 idx, u32 val, u32 sz)
+{
+	memset(&dsb->cmd_buf[idx], val, sz);
+}
+
+bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct intel_dsb *dsb, u32 size)
+{
+	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
+	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
+	u32 *buf;
+
+	obj = i915_gem_object_create_internal(i915, PAGE_ALIGN(size));
+	if (IS_ERR(obj))
+		return false;
+
+	vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
+	if (IS_ERR(vma)) {
+		i915_gem_object_put(obj);
+		return false;
+	}
+
+	buf = i915_gem_object_pin_map_unlocked(vma->obj, I915_MAP_WC);
+	if (IS_ERR(buf)) {
+		i915_vma_unpin_and_release(&vma, I915_VMA_RELEASE_MAP);
+		return false;
+	}
+
+	dsb->id = DSB1;
+	dsb->vma = vma;
+	dsb->crtc = crtc;
+	dsb->cmd_buf = buf;
+
+	return true;
+}
+
+void intel_dsb_cleanup(struct intel_dsb *dsb)
+{
+	i915_vma_unpin_and_release(&dsb->vma, I915_VMA_RELEASE_MAP);
+	kfree(dsb);
+}
Signature · 1 line
Jani Nikula, Intel
#5 lore raw
Quoted 9 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, September 25, 2023 6:00 PM
To: Manna, Animesh <[email protected]>; intel- [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915/dsb: DSB code refactoring

Quoted 8 lines
Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

Hi Jani,

Xe driver need access to intel_dsb structure, so I can create a new header file intel_dsb_ops.h and keep intel_dsb structure in it. Is it ok?

Regards,
Animesh

Quoted 408 lines

BR,
Jani.

drivers/gpu/drm/i915/display/intel_dsb.c static bool intel_dsb_prev_ins_is_write(struct

Quoted 109 lines
---
 drivers/gpu/drm/i915/Makefile                |   1 +
 drivers/gpu/drm/i915/display/intel_dsb.c     | 115 ++++---------------
 drivers/gpu/drm/i915/display/intel_dsb.h     |  41 ++++++-
 drivers/gpu/drm/i915/display/intel_dsb_ops.c |  67 +++++++++++
 4 files changed, 130 insertions(+), 94 deletions(-)  create mode

100644 drivers/gpu/drm/i915/display/intel_dsb_ops.c

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile index 1b2e02e9d92c..7fbb5055b85b 100644

drivers/gpu/drm/i915/Makefile +1 -0
@@ -256,6 +256,7 @@ i915-y += \
 	display/intel_dpt.o \
 	display/intel_drrs.o \
 	display/intel_dsb.o \
+	display/intel_dsb_ops.o \
 	display/intel_fb.o \
 	display/intel_fb_pin.o \
 	display/intel_fbc.o \
drivers/gpu/drm/i915/display/intel_dsb.c +3 -42
index 9a507b9ad82c..f7c6b9aa130f 100644
@@ -4,8 +4,6 @@
  *
  */
 
-#include "gem/i915_gem_internal.h"
-
 #include "i915_drv.h"
 #include "i915_reg.h"
 #include "intel_de.h"
@@ -13,41 +11,7 @@
 #include "intel_dsb.h"
 #include "intel_dsb_regs.h"
 
-struct i915_vma;
-
-enum dsb_id {
-	INVALID_DSB = -1,
-	DSB1,
-	DSB2,
-	DSB3,
-	MAX_DSB_PER_PIPE
-};
-
-struct intel_dsb {
-	enum dsb_id id;
-
-	u32 *cmd_buf;
-	struct i915_vma *vma;
-	struct intel_crtc *crtc;
-
-	/*
-	 * maximum number of dwords the buffer will hold.
-	 */
-	unsigned int size;
-
-	/*
-	 * free_pos will point the first free dword and
-	 * help in calculating tail of command buffer.
-	 */
-	unsigned int free_pos;
-
-	/*
-	 * ins_start_offset will help to store start dword of the dsb
-	 * instuction and help in identifying the batch of auto-increment
-	 * register.
-	 */
-	unsigned int ins_start_offset;
-};
+#define CACHELINE_BYTES 64
 
 /**
  * DOC: DSB
@@ -117,8 +81,6 @@ static bool is_dsb_busy(struct drm_i915_private
 *i915, enum pipe pipe,
 
 static void intel_dsb_emit(struct intel_dsb *dsb, u32 ldw, u32 udw)
 {
-	u32 *buf = dsb->cmd_buf;
-
 	if (!assert_dsb_has_room(dsb))
 		return;
@@ -127,14 +89,13 @@ static void intel_dsb_emit(struct intel_dsb *dsb,
 u32 ldw, u32 udw)
 
 	dsb->ins_start_offset = dsb->free_pos;
 
-	buf[dsb->free_pos++] = ldw;
-	buf[dsb->free_pos++] = udw;
+	intel_dsb_write(dsb, dsb->free_pos++, ldw);
+	intel_dsb_write(dsb, dsb->free_pos++, udw);
 }
 
 static bool intel_dsb_prev_ins_is_write(struct intel_dsb *dsb,
 					u32 opcode, i915_reg_t reg)
 {
-	const u32 *buf = dsb->cmd_buf;
 	u32 prev_opcode, prev_reg;
 
drivers/gpu/drm/i915/display/intel_dsb.c +0 -0
 	/*
@@ -145,8 +106,8 @@ static bool intel_dsb_prev_ins_is_write(struct

intel_dsb *dsb,

drivers/gpu/drm/i915/display/intel_dsb.c static bool intel_dsb_prev_ins_is_write(struct intel_dsb *dsb,

Quoted 4 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -1
 	if (dsb->free_pos == 0)
 		return false;
 
-	prev_opcode = buf[dsb->ins_start_offset + 1] &

~DSB_REG_VALUE_MASK;

drivers/gpu/drm/i915/display/intel_dsb.c static bool intel_dsb_prev_ins_is_write(struct · line 109

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -1
-	prev_reg = buf[dsb->ins_start_offset + 1] & DSB_REG_VALUE_MASK;
+	prev_opcode = intel_dsb_read(dsb, dsb->ins_start_offset + 1) >>

DSB_OPCODE_SHIFT;

Quoted 22 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -0
+	prev_reg =  intel_dsb_read(dsb, dsb->ins_start_offset + 1) &
+DSB_REG_VALUE_MASK;
 
 	return prev_opcode == opcode && prev_reg ==

i915_mmio_reg_offset(reg); } @@ -179,6 +140,8 @@ static bool intel_dsb_prev_ins_is_indexed_write(struct intel_dsb *dsb, i915_reg_ void intel_dsb_reg_write(struct intel_dsb *dsb,

drivers/gpu/drm/i915/display/intel_dsb.c +2 -2
 			 i915_reg_t reg, u32 val)
 {
+	u32 old_val;
+
 	/*
 	 * For example the buffer will look like below for 3 dwords for auto
 	 * increment register:
@@ -202,31 +165,30 @@ void intel_dsb_reg_write(struct intel_dsb *dsb,
 			       (DSB_BYTE_EN << DSB_BYTE_EN_SHIFT) |
 			       i915_mmio_reg_offset(reg));
 	} else {
-		u32 *buf = dsb->cmd_buf;
-
 		if (!assert_dsb_has_room(dsb))
 			return;

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb, · line 217

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -4
 
 		/* convert to indexed write? */
 		if (intel_dsb_prev_ins_is_mmio_write(dsb, reg)) {
-			u32 prev_val = buf[dsb->ins_start_offset + 0];
+			u32 prev_val = intel_dsb_read(dsb, dsb-
 ins_start_offset + 0);
 
-			buf[dsb->ins_start_offset + 0] = 1; /* count */
-			buf[dsb->ins_start_offset + 1] =
-				(DSB_OPCODE_INDEXED_WRITE <<

DSB_OPCODE_SHIFT) |

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb,

Quoted 3 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -2
-				i915_mmio_reg_offset(reg);
-			buf[dsb->ins_start_offset + 2] = prev_val;
+			intel_dsb_write(dsb, dsb->ins_start_offset + 0, 1); /*

count */

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb, · line 178

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -0
+			intel_dsb_write(dsb, dsb->ins_start_offset + 1,
+					(DSB_OPCODE_INDEXED_WRITE <<

DSB_OPCODE_SHIFT) |

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb, · line 180

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -0
+					i915_mmio_reg_offset(reg));
+			intel_dsb_write(dsb, dsb->ins_start_offset + 2,

prev_val);

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb,

Quoted 12 lines
drivers/gpu/drm/i915/display/intel_dsb.c +3 -2
 			dsb->free_pos++;
 		}
 
-		buf[dsb->free_pos++] = val;
+		intel_dsb_write(dsb, dsb->free_pos++, val);
 		/* Update the count */
-		buf[dsb->ins_start_offset]++;
+		old_val = intel_dsb_read(dsb, dsb->ins_start_offset);
+		intel_dsb_write(dsb, dsb->ins_start_offset, old_val + 1);
 
 		/* if number of data words is odd, then the last dword

should be 0.*/

drivers/gpu/drm/i915/display/intel_dsb.c static void intel_dsb_align_tail(struct intel_dsb

Quoted 7 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -1
 		if (dsb->free_pos & 0x1)
-			buf[dsb->free_pos] = 0;
+			intel_dsb_write(dsb, dsb->free_pos, 0);
 	}
 }
 
@@ -238,8 +200,8 @@ static void intel_dsb_align_tail(struct intel_dsb

*dsb)

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_commit(struct intel_dsb *dsb, bool

Quoted 11 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -2
 	aligned_tail = ALIGN(tail, CACHELINE_BYTES);
 
 	if (aligned_tail > tail)
-		memset(&dsb->cmd_buf[dsb->free_pos], 0,
-		       aligned_tail - tail);
+		intel_dsb_memset(dsb, dsb->free_pos, 0,
+				 aligned_tail - tail);
 
 	dsb->free_pos = aligned_tail / 4;
 }
@@ -277,9 +239,9 @@ void intel_dsb_commit(struct intel_dsb *dsb, bool

wait_for_vblank)

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct

Quoted 25 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -2
 		       (wait_for_vblank ? DSB_WAIT_FOR_VBLANK : 0) |
 		       DSB_ENABLE);
 	intel_de_write(dev_priv, DSB_HEAD(pipe, dsb->id),
-		       i915_ggtt_offset(dsb->vma));
+		       intel_dsb_ggtt_offset(dsb));
 	intel_de_write(dev_priv, DSB_TAIL(pipe, dsb->id),
-		       i915_ggtt_offset(dsb->vma) + tail);
+		       intel_dsb_ggtt_offset(dsb) + tail);
 }
 
 void intel_dsb_wait(struct intel_dsb *dsb) @@ -325,12 +287,9 @@

struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,

drivers/gpu/drm/i915/display/intel_dsb.c +0 -3
 				    unsigned int max_cmds)
 {
 	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
-	struct drm_i915_gem_object *obj;
 	intel_wakeref_t wakeref;
 	struct intel_dsb *dsb;
-	struct i915_vma *vma;
 	unsigned int size;
-	u32 *buf;
 
 	if (!HAS_DSB(i915))
 		return NULL;
@@ -344,28 +303,11 @@ struct intel_dsb *intel_dsb_prepare(struct

intel_crtc *crtc,

Quoted 5 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -2
 	/* ~1 qword per instruction, full cachelines */
 	size = ALIGN(max_cmds * 8, CACHELINE_BYTES);
 
-	obj = i915_gem_object_create_internal(i915, PAGE_ALIGN(size));
-	if (IS_ERR(obj))

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -8
-		goto out_put_rpm;
-
-	vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
-	if (IS_ERR(vma)) {
-		i915_gem_object_put(obj);
+	if (!intel_dsb_buffer_create(crtc, dsb, size))
 		goto out_put_rpm;
-	}
-
-	buf = i915_gem_object_pin_map_unlocked(vma->obj,

I915_MAP_WC);

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct · line 359

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -2
-	if (IS_ERR(buf)) {
-		i915_vma_unpin_and_release(&vma,

I915_VMA_RELEASE_MAP);

Quoted 17 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -6
-		goto out_put_rpm;
-	}
 
 	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
 
-	dsb->id = DSB1;
-	dsb->vma = vma;
-	dsb->crtc = crtc;
-	dsb->cmd_buf = buf;
 	dsb->size = size / 4; /* in dwords */
 	dsb->free_pos = 0;
 	dsb->ins_start_offset = 0;
@@ -382,16 +324,3 @@ struct intel_dsb *intel_dsb_prepare(struct
 intel_crtc *crtc,
 
 	return NULL;
 }

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -10
-
-/**
- * intel_dsb_cleanup() - To cleanup DSB context.
- * @dsb: DSB context
- *
- * This function cleanup the DSB context by unpinning and releasing
- * the VMA object associated with it.
- */
-void intel_dsb_cleanup(struct intel_dsb *dsb) -{
-	i915_vma_unpin_and_release(&dsb->vma,

I915_VMA_RELEASE_MAP);

Quoted 104 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -2
-	kfree(dsb);
-}
drivers/gpu/drm/i915/display/intel_dsb.h +41 -1
index b8148b47022d..7feeb37e00a5 100644
@@ -11,7 +11,41 @@
 #include "i915_reg_defs.h"
 
 struct intel_crtc;
-struct intel_dsb;
+struct i915_vma;
+
+enum dsb_id {
+	INVALID_DSB = -1,
+	DSB1,
+	DSB2,
+	DSB3,
+	MAX_DSB_PER_PIPE
+};
+
+struct intel_dsb {
+	enum dsb_id id;
+
+	u32 *cmd_buf;
+	struct i915_vma *vma;
+	struct intel_crtc *crtc;
+
+	/*
+	 * maximum number of dwords the buffer will hold.
+	 */
+	unsigned int size;
+
+	/*
+	 * free_pos will point the first free dword and
+	 * help in calculating tail of command buffer.
+	 */
+	unsigned int free_pos;
+
+	/*
+	 * ins_start_offset will help to store start dword of the dsb
+	 * instuction and help in identifying the batch of auto-increment
+	 * register.
+	 */
+	unsigned int ins_start_offset;
+};
 
 struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,
 				    unsigned int max_cmds);
@@ -22,5 +56,10 @@ void intel_dsb_reg_write(struct intel_dsb *dsb,
 void intel_dsb_commit(struct intel_dsb *dsb,
 		      bool wait_for_vblank);
 void intel_dsb_wait(struct intel_dsb *dsb);
+u32 intel_dsb_ggtt_offset(struct intel_dsb *dsb); void
+intel_dsb_write(struct intel_dsb *dsb, u32 idx, u32 val);
+u32 intel_dsb_read(struct intel_dsb *dsb, u32 idx); void
+intel_dsb_memset(struct intel_dsb *dsb, u32 idx, u32 val, u32 sz);
+bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct
+intel_dsb *dsb, u32 size);
 
 #endif
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +35 -0
new file mode 100644
index 000000000000..9fe125abb890
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2023, Intel Corporation.
+ */
+
+#include "gem/i915_gem_internal.h"
+#include "i915_drv.h"
+#include "i915_vma.h"
+#include "intel_display_types.h"
+#include "intel_dsb.h"
+
+u32 intel_dsb_ggtt_offset(struct intel_dsb *dsb) {
+	return i915_ggtt_offset(dsb->vma);
+}
+
+void intel_dsb_write(struct intel_dsb *dsb, u32 idx, u32 val) {
+	dsb->cmd_buf[idx] = val;
+}
+
+u32 intel_dsb_read(struct intel_dsb *dsb, u32 idx) {
+	return dsb->cmd_buf[idx];
+}
+
+void intel_dsb_memset(struct intel_dsb *dsb, u32 idx, u32 val, u32
+sz) {
+	memset(&dsb->cmd_buf[idx], val, sz); }
+
+bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct
+intel_dsb *dsb, u32 size) {
+	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
+	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
+	u32 *buf;
+
+	obj = i915_gem_object_create_internal(i915, PAGE_ALIGN(size));

drivers/gpu/drm/i915/display/intel_dsb_ops.c line 45

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +10 -0
+	if (IS_ERR(obj))
+		return false;
+
+	vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
+	if (IS_ERR(vma)) {
+		i915_gem_object_put(obj);
+		return false;
+	}
+
+	buf = i915_gem_object_pin_map_unlocked(vma->obj,

I915_MAP_WC);

drivers/gpu/drm/i915/display/intel_dsb_ops.c line 47

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +2 -0
+	if (IS_ERR(buf)) {
+		i915_vma_unpin_and_release(&vma,

I915_VMA_RELEASE_MAP);

drivers/gpu/drm/i915/display/intel_dsb_ops.c

Quoted 13 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +13 -0
+		return false;
+	}
+
+	dsb->id = DSB1;
+	dsb->vma = vma;
+	dsb->crtc = crtc;
+	dsb->cmd_buf = buf;
+
+	return true;
+}
+
+void intel_dsb_cleanup(struct intel_dsb *dsb) {
+	i915_vma_unpin_and_release(&dsb->vma,

I915_VMA_RELEASE_MAP);

drivers/gpu/drm/i915/display/intel_dsb_ops.c line 67

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +2 -0
+	kfree(dsb);
+}

--
Jani Nikula, Intel

maintainer
#6 lore raw
Quoted 12 lines · Animesh
Quoted 12 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, September 25, 2023 6:00 PM
To: Manna, Animesh <[email protected]>; intel- [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915/dsb: DSB code refactoring

Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

Quoted 7 lines
Quoted 3 lines

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

Hi Jani,

Xe driver need access to intel_dsb structure, so I can create a new header file intel_dsb_ops.h and keep intel_dsb structure in it. Is it ok?

I just think you need to find a different abstraction level that doesn't involve exposing struct intel_dsb.

The stuff you're putting in intel_dsb_ops.[ch] don't really need to operate on intel_dsb at all.

BR,
Jani.

Quoted 411 lines

Regards,
Animesh

Quoted 408 lines

BR,
Jani.

drivers/gpu/drm/i915/display/intel_dsb.c static bool intel_dsb_prev_ins_is_write(struct

Quoted 109 lines
---
 drivers/gpu/drm/i915/Makefile                |   1 +
 drivers/gpu/drm/i915/display/intel_dsb.c     | 115 ++++---------------
 drivers/gpu/drm/i915/display/intel_dsb.h     |  41 ++++++-
 drivers/gpu/drm/i915/display/intel_dsb_ops.c |  67 +++++++++++
 4 files changed, 130 insertions(+), 94 deletions(-)  create mode

100644 drivers/gpu/drm/i915/display/intel_dsb_ops.c

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile index 1b2e02e9d92c..7fbb5055b85b 100644

drivers/gpu/drm/i915/Makefile +1 -0
@@ -256,6 +256,7 @@ i915-y += \
 	display/intel_dpt.o \
 	display/intel_drrs.o \
 	display/intel_dsb.o \
+	display/intel_dsb_ops.o \
 	display/intel_fb.o \
 	display/intel_fb_pin.o \
 	display/intel_fbc.o \
drivers/gpu/drm/i915/display/intel_dsb.c +3 -42
index 9a507b9ad82c..f7c6b9aa130f 100644
@@ -4,8 +4,6 @@
  *
  */
 
-#include "gem/i915_gem_internal.h"
-
 #include "i915_drv.h"
 #include "i915_reg.h"
 #include "intel_de.h"
@@ -13,41 +11,7 @@
 #include "intel_dsb.h"
 #include "intel_dsb_regs.h"
 
-struct i915_vma;
-
-enum dsb_id {
-	INVALID_DSB = -1,
-	DSB1,
-	DSB2,
-	DSB3,
-	MAX_DSB_PER_PIPE
-};
-
-struct intel_dsb {
-	enum dsb_id id;
-
-	u32 *cmd_buf;
-	struct i915_vma *vma;
-	struct intel_crtc *crtc;
-
-	/*
-	 * maximum number of dwords the buffer will hold.
-	 */
-	unsigned int size;
-
-	/*
-	 * free_pos will point the first free dword and
-	 * help in calculating tail of command buffer.
-	 */
-	unsigned int free_pos;
-
-	/*
-	 * ins_start_offset will help to store start dword of the dsb
-	 * instuction and help in identifying the batch of auto-increment
-	 * register.
-	 */
-	unsigned int ins_start_offset;
-};
+#define CACHELINE_BYTES 64
 
 /**
  * DOC: DSB
@@ -117,8 +81,6 @@ static bool is_dsb_busy(struct drm_i915_private
 *i915, enum pipe pipe,
 
 static void intel_dsb_emit(struct intel_dsb *dsb, u32 ldw, u32 udw)
 {
-	u32 *buf = dsb->cmd_buf;
-
 	if (!assert_dsb_has_room(dsb))
 		return;
@@ -127,14 +89,13 @@ static void intel_dsb_emit(struct intel_dsb *dsb,
 u32 ldw, u32 udw)
 
 	dsb->ins_start_offset = dsb->free_pos;
 
-	buf[dsb->free_pos++] = ldw;
-	buf[dsb->free_pos++] = udw;
+	intel_dsb_write(dsb, dsb->free_pos++, ldw);
+	intel_dsb_write(dsb, dsb->free_pos++, udw);
 }
 
 static bool intel_dsb_prev_ins_is_write(struct intel_dsb *dsb,
 					u32 opcode, i915_reg_t reg)
 {
-	const u32 *buf = dsb->cmd_buf;
 	u32 prev_opcode, prev_reg;
 
drivers/gpu/drm/i915/display/intel_dsb.c +0 -0
 	/*
@@ -145,8 +106,8 @@ static bool intel_dsb_prev_ins_is_write(struct

intel_dsb *dsb,

drivers/gpu/drm/i915/display/intel_dsb.c static bool intel_dsb_prev_ins_is_write(struct intel_dsb *dsb,

Quoted 4 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -1
 	if (dsb->free_pos == 0)
 		return false;
 
-	prev_opcode = buf[dsb->ins_start_offset + 1] &

~DSB_REG_VALUE_MASK;

drivers/gpu/drm/i915/display/intel_dsb.c static bool intel_dsb_prev_ins_is_write(struct · line 109

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -1
-	prev_reg = buf[dsb->ins_start_offset + 1] & DSB_REG_VALUE_MASK;
+	prev_opcode = intel_dsb_read(dsb, dsb->ins_start_offset + 1) >>

DSB_OPCODE_SHIFT;

Quoted 22 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -0
+	prev_reg =  intel_dsb_read(dsb, dsb->ins_start_offset + 1) &
+DSB_REG_VALUE_MASK;
 
 	return prev_opcode == opcode && prev_reg ==

i915_mmio_reg_offset(reg); } @@ -179,6 +140,8 @@ static bool intel_dsb_prev_ins_is_indexed_write(struct intel_dsb *dsb, i915_reg_ void intel_dsb_reg_write(struct intel_dsb *dsb,

drivers/gpu/drm/i915/display/intel_dsb.c +2 -2
 			 i915_reg_t reg, u32 val)
 {
+	u32 old_val;
+
 	/*
 	 * For example the buffer will look like below for 3 dwords for auto
 	 * increment register:
@@ -202,31 +165,30 @@ void intel_dsb_reg_write(struct intel_dsb *dsb,
 			       (DSB_BYTE_EN << DSB_BYTE_EN_SHIFT) |
 			       i915_mmio_reg_offset(reg));
 	} else {
-		u32 *buf = dsb->cmd_buf;
-
 		if (!assert_dsb_has_room(dsb))
 			return;

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb, · line 217

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -4
 
 		/* convert to indexed write? */
 		if (intel_dsb_prev_ins_is_mmio_write(dsb, reg)) {
-			u32 prev_val = buf[dsb->ins_start_offset + 0];
+			u32 prev_val = intel_dsb_read(dsb, dsb-
 ins_start_offset + 0);
 
-			buf[dsb->ins_start_offset + 0] = 1; /* count */
-			buf[dsb->ins_start_offset + 1] =
-				(DSB_OPCODE_INDEXED_WRITE <<

DSB_OPCODE_SHIFT) |

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb,

Quoted 3 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -2
-				i915_mmio_reg_offset(reg);
-			buf[dsb->ins_start_offset + 2] = prev_val;
+			intel_dsb_write(dsb, dsb->ins_start_offset + 0, 1); /*

count */

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb, · line 178

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -0
+			intel_dsb_write(dsb, dsb->ins_start_offset + 1,
+					(DSB_OPCODE_INDEXED_WRITE <<

DSB_OPCODE_SHIFT) |

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb, · line 180

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -0
+					i915_mmio_reg_offset(reg));
+			intel_dsb_write(dsb, dsb->ins_start_offset + 2,

prev_val);

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_reg_write(struct intel_dsb *dsb,

Quoted 12 lines
drivers/gpu/drm/i915/display/intel_dsb.c +3 -2
 			dsb->free_pos++;
 		}
 
-		buf[dsb->free_pos++] = val;
+		intel_dsb_write(dsb, dsb->free_pos++, val);
 		/* Update the count */
-		buf[dsb->ins_start_offset]++;
+		old_val = intel_dsb_read(dsb, dsb->ins_start_offset);
+		intel_dsb_write(dsb, dsb->ins_start_offset, old_val + 1);
 
 		/* if number of data words is odd, then the last dword

should be 0.*/

drivers/gpu/drm/i915/display/intel_dsb.c static void intel_dsb_align_tail(struct intel_dsb

Quoted 7 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -1
 		if (dsb->free_pos & 0x1)
-			buf[dsb->free_pos] = 0;
+			intel_dsb_write(dsb, dsb->free_pos, 0);
 	}
 }
 
@@ -238,8 +200,8 @@ static void intel_dsb_align_tail(struct intel_dsb

*dsb)

drivers/gpu/drm/i915/display/intel_dsb.c void intel_dsb_commit(struct intel_dsb *dsb, bool

Quoted 11 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -2
 	aligned_tail = ALIGN(tail, CACHELINE_BYTES);
 
 	if (aligned_tail > tail)
-		memset(&dsb->cmd_buf[dsb->free_pos], 0,
-		       aligned_tail - tail);
+		intel_dsb_memset(dsb, dsb->free_pos, 0,
+				 aligned_tail - tail);
 
 	dsb->free_pos = aligned_tail / 4;
 }
@@ -277,9 +239,9 @@ void intel_dsb_commit(struct intel_dsb *dsb, bool

wait_for_vblank)

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct

Quoted 25 lines
drivers/gpu/drm/i915/display/intel_dsb.c +2 -2
 		       (wait_for_vblank ? DSB_WAIT_FOR_VBLANK : 0) |
 		       DSB_ENABLE);
 	intel_de_write(dev_priv, DSB_HEAD(pipe, dsb->id),
-		       i915_ggtt_offset(dsb->vma));
+		       intel_dsb_ggtt_offset(dsb));
 	intel_de_write(dev_priv, DSB_TAIL(pipe, dsb->id),
-		       i915_ggtt_offset(dsb->vma) + tail);
+		       intel_dsb_ggtt_offset(dsb) + tail);
 }
 
 void intel_dsb_wait(struct intel_dsb *dsb) @@ -325,12 +287,9 @@

struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,

drivers/gpu/drm/i915/display/intel_dsb.c +0 -3
 				    unsigned int max_cmds)
 {
 	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
-	struct drm_i915_gem_object *obj;
 	intel_wakeref_t wakeref;
 	struct intel_dsb *dsb;
-	struct i915_vma *vma;
 	unsigned int size;
-	u32 *buf;
 
 	if (!HAS_DSB(i915))
 		return NULL;
@@ -344,28 +303,11 @@ struct intel_dsb *intel_dsb_prepare(struct

intel_crtc *crtc,

Quoted 5 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -2
 	/* ~1 qword per instruction, full cachelines */
 	size = ALIGN(max_cmds * 8, CACHELINE_BYTES);
 
-	obj = i915_gem_object_create_internal(i915, PAGE_ALIGN(size));
-	if (IS_ERR(obj))

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb.c +1 -8
-		goto out_put_rpm;
-
-	vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
-	if (IS_ERR(vma)) {
-		i915_gem_object_put(obj);
+	if (!intel_dsb_buffer_create(crtc, dsb, size))
 		goto out_put_rpm;
-	}
-
-	buf = i915_gem_object_pin_map_unlocked(vma->obj,

I915_MAP_WC);

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct · line 359

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -2
-	if (IS_ERR(buf)) {
-		i915_vma_unpin_and_release(&vma,

I915_VMA_RELEASE_MAP);

Quoted 17 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -6
-		goto out_put_rpm;
-	}
 
 	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
 
-	dsb->id = DSB1;
-	dsb->vma = vma;
-	dsb->crtc = crtc;
-	dsb->cmd_buf = buf;
 	dsb->size = size / 4; /* in dwords */
 	dsb->free_pos = 0;
 	dsb->ins_start_offset = 0;
@@ -382,16 +324,3 @@ struct intel_dsb *intel_dsb_prepare(struct
 intel_crtc *crtc,
 
 	return NULL;
 }

drivers/gpu/drm/i915/display/intel_dsb.c struct intel_dsb *intel_dsb_prepare(struct

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -10
-
-/**
- * intel_dsb_cleanup() - To cleanup DSB context.
- * @dsb: DSB context
- *
- * This function cleanup the DSB context by unpinning and releasing
- * the VMA object associated with it.
- */
-void intel_dsb_cleanup(struct intel_dsb *dsb) -{
-	i915_vma_unpin_and_release(&dsb->vma,

I915_VMA_RELEASE_MAP);

Quoted 104 lines
drivers/gpu/drm/i915/display/intel_dsb.c +0 -2
-	kfree(dsb);
-}
drivers/gpu/drm/i915/display/intel_dsb.h +41 -1
index b8148b47022d..7feeb37e00a5 100644
@@ -11,7 +11,41 @@
 #include "i915_reg_defs.h"
 
 struct intel_crtc;
-struct intel_dsb;
+struct i915_vma;
+
+enum dsb_id {
+	INVALID_DSB = -1,
+	DSB1,
+	DSB2,
+	DSB3,
+	MAX_DSB_PER_PIPE
+};
+
+struct intel_dsb {
+	enum dsb_id id;
+
+	u32 *cmd_buf;
+	struct i915_vma *vma;
+	struct intel_crtc *crtc;
+
+	/*
+	 * maximum number of dwords the buffer will hold.
+	 */
+	unsigned int size;
+
+	/*
+	 * free_pos will point the first free dword and
+	 * help in calculating tail of command buffer.
+	 */
+	unsigned int free_pos;
+
+	/*
+	 * ins_start_offset will help to store start dword of the dsb
+	 * instuction and help in identifying the batch of auto-increment
+	 * register.
+	 */
+	unsigned int ins_start_offset;
+};
 
 struct intel_dsb *intel_dsb_prepare(struct intel_crtc *crtc,
 				    unsigned int max_cmds);
@@ -22,5 +56,10 @@ void intel_dsb_reg_write(struct intel_dsb *dsb,
 void intel_dsb_commit(struct intel_dsb *dsb,
 		      bool wait_for_vblank);
 void intel_dsb_wait(struct intel_dsb *dsb);
+u32 intel_dsb_ggtt_offset(struct intel_dsb *dsb); void
+intel_dsb_write(struct intel_dsb *dsb, u32 idx, u32 val);
+u32 intel_dsb_read(struct intel_dsb *dsb, u32 idx); void
+intel_dsb_memset(struct intel_dsb *dsb, u32 idx, u32 val, u32 sz);
+bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct
+intel_dsb *dsb, u32 size);
 
 #endif
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +35 -0
new file mode 100644
index 000000000000..9fe125abb890
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2023, Intel Corporation.
+ */
+
+#include "gem/i915_gem_internal.h"
+#include "i915_drv.h"
+#include "i915_vma.h"
+#include "intel_display_types.h"
+#include "intel_dsb.h"
+
+u32 intel_dsb_ggtt_offset(struct intel_dsb *dsb) {
+	return i915_ggtt_offset(dsb->vma);
+}
+
+void intel_dsb_write(struct intel_dsb *dsb, u32 idx, u32 val) {
+	dsb->cmd_buf[idx] = val;
+}
+
+u32 intel_dsb_read(struct intel_dsb *dsb, u32 idx) {
+	return dsb->cmd_buf[idx];
+}
+
+void intel_dsb_memset(struct intel_dsb *dsb, u32 idx, u32 val, u32
+sz) {
+	memset(&dsb->cmd_buf[idx], val, sz); }
+
+bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct
+intel_dsb *dsb, u32 size) {
+	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
+	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
+	u32 *buf;
+
+	obj = i915_gem_object_create_internal(i915, PAGE_ALIGN(size));

drivers/gpu/drm/i915/display/intel_dsb_ops.c line 45

Quoted 10 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +10 -0
+	if (IS_ERR(obj))
+		return false;
+
+	vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
+	if (IS_ERR(vma)) {
+		i915_gem_object_put(obj);
+		return false;
+	}
+
+	buf = i915_gem_object_pin_map_unlocked(vma->obj,

I915_MAP_WC);

drivers/gpu/drm/i915/display/intel_dsb_ops.c line 47

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +2 -0
+	if (IS_ERR(buf)) {
+		i915_vma_unpin_and_release(&vma,

I915_VMA_RELEASE_MAP);

drivers/gpu/drm/i915/display/intel_dsb_ops.c

Quoted 13 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +13 -0
+		return false;
+	}
+
+	dsb->id = DSB1;
+	dsb->vma = vma;
+	dsb->crtc = crtc;
+	dsb->cmd_buf = buf;
+
+	return true;
+}
+
+void intel_dsb_cleanup(struct intel_dsb *dsb) {
+	i915_vma_unpin_and_release(&dsb->vma,

I915_VMA_RELEASE_MAP);

drivers/gpu/drm/i915/display/intel_dsb_ops.c line 67

Quoted 2 lines
drivers/gpu/drm/i915/display/intel_dsb_ops.c new file +2 -0
+	kfree(dsb);
+}

--
Jani Nikula, Intel

Signature · 1 line
Jani Nikula, Intel
#7 lore raw
Quoted 17 lines · Jani Nikula
Quoted 16 lines · Animesh
Quoted 15 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, September 25, 2023 6:00 PM
To: Manna, Animesh <[email protected]>; intel- [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915/dsb: DSB code refactoring

Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

Quoted 6 lines
Quoted 3 lines

Hi Jani,

Xe driver need access to intel_dsb structure, so I can create a new header file intel_dsb_ops.h and keep intel_dsb structure in it. Is it ok?

I just think you need to find a different abstraction level that doesn't involve exposing struct intel_dsb.

I hate the fact that we seem to be adding these ad-hoc wrappers all over the place. Someone should just fix xe to give us the same API as i915, or a single wrapper should do whatever conversion is needed.

Signature · 2 lines
Ville Syrjälä
Intel
maintainer
#8 lore raw
Quoted 20 lines · Ville Syrjälä
Quoted 19 lines · Jani Nikula
Quoted 18 lines · Animesh
Quoted 7 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, September 25, 2023 6:00 PM
To: Manna, Animesh <[email protected]>; intel- [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915/dsb: DSB code refactoring

Quoted 8 lines
Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

Hi Jani,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Xe driver need access to intel_dsb structure, so I can create a new header file intel_dsb_ops.h and keep intel_dsb structure in it. Is it ok?

I just think you need to find a different abstraction level that doesn't involve exposing struct intel_dsb.

I hate the fact that we seem to be adding these ad-hoc wrappers all over the place. Someone should just fix xe to give us the same API as i915, or a single wrapper should do whatever conversion is needed.

I think one of the problems is that i915 doesn't really give us a proper API either, but requires us to fiddle with the objects' guts, and thus have access to the struct definitions. In i915, with the include hierarchies, that effectively means including absolutely everything. Can't have that in xe.

Having the same API for both i915 and xe requires turning it into an actual API that doesn't depend on either i915 or xe specific types. But that's kind of tough before xe is upstream. Catch-22.

Part of the reason we have these ad-hoc wrappers is that they also serve as the todo list of stuff to fix properly.

BR,
Jani.

Signature · 1 line
Jani Nikula, Intel
#9 lore raw
Quoted 30 lines · Jani Nikula
Quoted 20 lines · Ville Syrjälä
Quoted 19 lines · Jani Nikula
Quoted 18 lines · Animesh
Quoted 7 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, September 25, 2023 6:00 PM
To: Manna, Animesh <[email protected]>; intel- [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915/dsb: DSB code refactoring

Quoted 8 lines
Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

Hi Jani,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Xe driver need access to intel_dsb structure, so I can create a new header file intel_dsb_ops.h and keep intel_dsb structure in it. Is it ok?

I just think you need to find a different abstraction level that doesn't involve exposing struct intel_dsb.

I hate the fact that we seem to be adding these ad-hoc wrappers all over the place. Someone should just fix xe to give us the same API as i915, or a single wrapper should do whatever conversion is needed.

Quoted 5 lines

I think one of the problems is that i915 doesn't really give us a proper API either, but requires us to fiddle with the objects' guts, and thus have access to the struct definitions. In i915, with the include hierarchies, that effectively means including absolutely everything. Can't have that in xe.

obj+vma is a pretty reasonable API IMO. And we're not doing anything weird with their guts IIRC. But apparently xe decided to not give us that, and instead of adding a single wrapper to bridge the gap we now have several different ad-hoc wrappers for whatever reason.

Quoted 4 lines

Having the same API for both i915 and xe requires turning it into an actual API that doesn't depend on either i915 or xe specific types. But that's kind of tough before xe is upstream. Catch-22.

Nothing preventing anyone from coming up with the single wrapper and upstreaming the i915 side (assuming we even want some kind of extra wrapper for i915 given it already uses a reasonable approach).

Quoted 3 lines

Part of the reason we have these ad-hoc wrappers is that they also serve as the todo list of stuff to fix properly.

Feels more like we are trying to polish these to the point where they are supposed to be permanent solutions.

Signature · 2 lines
Ville Syrjälä
Intel
maintainer
#10 lore raw
Quoted 31 lines · Ville Syrjälä
Quoted 30 lines · Jani Nikula
Quoted 28 lines · Ville Syrjälä
Quoted 17 lines · Jani Nikula
Quoted 16 lines · Animesh
Quoted 15 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, September 25, 2023 6:00 PM
To: Manna, Animesh <[email protected]>; intel- [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915/dsb: DSB code refactoring

Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

Quoted 6 lines
Quoted 3 lines

Hi Jani,

Xe driver need access to intel_dsb structure, so I can create a new header file intel_dsb_ops.h and keep intel_dsb structure in it. Is it ok?

I just think you need to find a different abstraction level that doesn't involve exposing struct intel_dsb.

I hate the fact that we seem to be adding these ad-hoc wrappers all over the place. Someone should just fix xe to give us the same API as i915, or a single wrapper should do whatever conversion is needed.

Quoted 8 lines
Quoted 5 lines

I think one of the problems is that i915 doesn't really give us a proper API either, but requires us to fiddle with the objects' guts, and thus have access to the struct definitions. In i915, with the include hierarchies, that effectively means including absolutely everything. Can't have that in xe.

obj+vma is a pretty reasonable API IMO. And we're not doing anything weird with their guts IIRC.

Okay, I'll take your word for it.

Quoted 3 lines

But apparently xe decided to not give us
that, and instead of adding a single wrapper to bridge the gap we now have several different ad-hoc wrappers for whatever reason.

For this specific thing? Do we really have several? Or do you mean all the different things that bridge the gap between xe and i915-display?

Quoted 8 lines
Quoted 4 lines

Having the same API for both i915 and xe requires turning it into an actual API that doesn't depend on either i915 or xe specific types. But that's kind of tough before xe is upstream. Catch-22.

Nothing preventing anyone from coming up with the single wrapper and upstreaming the i915 side (assuming we even want some kind of extra wrapper for i915 given it already uses a reasonable approach).

Well, so far nobody has stepped up to do that. Needs knowledge of i915-gem, i915-display, and xe. It seems like someone else's problem for everyone working on each of those components. And yeah, I'm not volunteering either.

Quoted 5 lines
Quoted 2 lines

Part of the reason we have these ad-hoc wrappers is that they also serve as the todo list of stuff to fix properly.

Feels more like we are trying to polish these to the point where they are supposed to be permanent solutions.

I'm trying to flesh out ideas how to separate i915-display from the rest of i915.ko better [1]. Eventually that'll require very clearly defining the interfaces to/from i915-display as well. Maybe via aux-bus function pointers.

Funny thing is, currently the only way to even check what interfaces i915-display needs is to build it as part of xe, where those i915 interfaces aren't available.

BR,
Jani.

[1] https://patchwork.freedesktop.org/series/124286/

Signature · 1 line
Jani Nikula, Intel
#11 lore raw
Quoted 41 lines · Jani Nikula
Quoted 31 lines · Ville Syrjälä
Quoted 30 lines · Jani Nikula
Quoted 28 lines · Ville Syrjälä
Quoted 17 lines · Jani Nikula
Quoted 16 lines · Animesh
Quoted 15 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, September 25, 2023 6:00 PM
To: Manna, Animesh <[email protected]>; intel- [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915/dsb: DSB code refactoring

Quoted 1 line · Animesh Manna

Refactor DSB implementation to be compatible with Xe driver.

Sad trombone.

struct intel_dsb should remain an opaque type. I put effort into hiding its definition, so its guts wouldn't be accessed nilly-willy all over the place. If it's not hidden, it just will get accessed.

Quoted 6 lines
Quoted 3 lines

Hi Jani,

Xe driver need access to intel_dsb structure, so I can create a new header file intel_dsb_ops.h and keep intel_dsb structure in it. Is it ok?

I just think you need to find a different abstraction level that doesn't involve exposing struct intel_dsb.

I hate the fact that we seem to be adding these ad-hoc wrappers all over the place. Someone should just fix xe to give us the same API as i915, or a single wrapper should do whatever conversion is needed.

Quoted 8 lines
Quoted 5 lines

I think one of the problems is that i915 doesn't really give us a proper API either, but requires us to fiddle with the objects' guts, and thus have access to the struct definitions. In i915, with the include hierarchies, that effectively means including absolutely everything. Can't have that in xe.

obj+vma is a pretty reasonable API IMO. And we're not doing anything weird with their guts IIRC.

Quoted 8 lines

Okay, I'll take your word for it.

Quoted 3 lines

But apparently xe decided to not give us
that, and instead of adding a single wrapper to bridge the gap we now have several different ad-hoc wrappers for whatever reason.

For this specific thing? Do we really have several? Or do you mean all the different things that bridge the gap between xe and i915-display?

I'm just referring to the all the things where we need to give a piece of memory to the hardware. So far that seems to be normal fb scanout, fbdev, dsb, fbc, and apparently hdcp also needs GPU accessible memory. And flip queue will be another case somewhere down the line.

Signature · 2 lines
Ville Syrjälä
Intel