Skip to contentSkip to conversation

Introduce a generic function to get the CSB buffer

PATCH Superseded Rodrigo Siqueira 2 participants 13 messages Apr 6, 2025 – Apr 13, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Introduce a generic function to get the CSB buffer

This patchset was inspired and made on top of the below series:

https://lore.kernel.org/amd-gfx/[email protected]/

In the above series, there is a bug fix in many functions named gfx_vX_0_get_csb_buffer (where X ranges from 6 to 11). After closely looking at those functions, it became clear that most of the code could be shared from gfx6 to gfx11. Aside from the code duplication removal, this also improves maintainability since a bug fix in a shared function can be propagated to all ASICs.

The first patch of this series created one dedicated file for encapsulating common GC registers (gc_common_offset.h); this series only adds registers associated with the CSB. In the future, this file can keep growing as we identify common registers to be shared in the gc_common_offset.h.

The second patch introduces the generic gfx_get_csb_buffer function, which has the same implementation found in gfx_v10_0_get_csb_buffer and gfx_v11_0_get_csb_buffer (these two functions have the same code). After that, every patch is dedicated to absorbing one of the csb_buffer functions from gfx from 9 to 6; notice that some adaptations were required.

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Create a headears to keep some common GC registers drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

 Documentation/gpu/amdgpu/amdgpu-glossary.rst  |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 101 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |   1 +
 drivers/gpu/drm/amd/amdgpu/cik.c              |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  53 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  46 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  70 +-----------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  43 +-------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |   1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |   2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |   2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_11_0_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_0_3_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_5_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_12_0_0_offset.h    |   2 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |   3 -
 .../amd/include/asic_reg/gc/gc_9_4_2_offset.h |   2 -
 .../amd/include/asic_reg/gc/gc_9_4_3_offset.h |   2 -
 .../include/asic_reg/gc/gc_common_offset.h    |  11 ++
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |   1 -
 30 files changed, 141 insertions(+), 328 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/6 drm/amd/amdgpu: Create a headears to keep some common GC registers

Some GC registers are duplicated across multiple instances of GC offset files. This commit creates a new file named gc_common_offset.h that centralizes some common registers in a single file. Aside from eliminating multiple duplications, this approach also avoids including specific registers in generic files (e.g., amdgpu_gfx) and reduces the number of includes.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c                   | 1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c                   | 4 +++-
 .../gpu/drm/amd/include/asic_reg/gc/gc_10_1_0_offset.h   | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_10_3_0_offset.h   | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_11_0_0_offset.h   | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_11_0_3_offset.h   | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_11_5_0_offset.h   | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_12_0_0_offset.h   | 2 --
 drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_0_offset.h  | 2 --
 drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_1_offset.h  | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_9_2_1_offset.h    | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_9_4_2_offset.h    | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_9_4_3_offset.h    | 2 --
 .../gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h   | 9 +++++++++
 14 files changed, 13 insertions(+), 23 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -0
index a1e3bb43babc..9f92acfdf00c 100644
@@ -32,6 +32,7 @@
 #include "nv.h"
 #include "nvd.h"
 
+#include "gc/gc_common_offset.h"
 #include "gc/gc_10_1_0_offset.h"
 #include "gc/gc_10_1_0_sh_mask.h"
 #include "smuio/smuio_11_0_0_offset.h"
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -1
index 58b10a72c0c9..2aea229ac4bb 100644
@@ -33,6 +33,8 @@
 #include "soc21.h"
 #include "nvd.h"
 
+#include "gc/gc_common_offset.h"
+
 #include "gc/gc_11_0_0_offset.h"
 #include "gc/gc_11_0_0_sh_mask.h"
 #include "smuio/smuio_13_0_6_offset.h"
@@ -3565,7 +3567,7 @@ static int gfx_v11_0_cp_gfx_start(struct amdgpu_device *adev)
 	}
 
 	ctx_reg_offset =
-		SOC15_REG_OFFSET(GC, 0, regPA_SC_TILE_STEERING_OVERRIDE) - PACKET3_SET_CONTEXT_REG_START;
+		SOC15_REG_OFFSET(GC, 0, mmPA_SC_TILE_STEERING_OVERRIDE) - PACKET3_SET_CONTEXT_REG_START;
 	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
 	amdgpu_ring_write(ring, ctx_reg_offset);
 	amdgpu_ring_write(ring, adev->gfx.config.pa_sc_tile_steering_override);
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_1_0_offset.h +0 -2
index 4c8e7fdb6976..1e92f71f12b8 100644
@@ -5974,8 +5974,6 @@
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define mmPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define mmPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define mmPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define mmCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define mmCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define mmCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_3_0_offset.h +0 -2
index 5e15ac14b63c..555a3bc26614 100644
@@ -5603,8 +5603,6 @@
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define mmPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define mmPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define mmPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define mmCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define mmCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define mmCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_11_0_0_offset.h +0 -2
index a3bcdf632066..b82c72d27cf9 100644
@@ -5393,8 +5393,6 @@
 #define regPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define regPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define regPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define regPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define regPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define regCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define regCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define regCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_11_0_3_offset.h +0 -2
index 56e00252bff8..82a795135f87 100644
@@ -5673,8 +5673,6 @@
 #define regPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define regPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define regPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define regPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define regPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define regCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define regCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define regCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_11_5_0_offset.h +0 -2
index d6c02cf815be..bf61fc0d3edd 100644
@@ -4204,8 +4204,6 @@
 #define regPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define regPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define regPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define regPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define regPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define regCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define regCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define regCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_12_0_0_offset.h +0 -2
index 645d10bfbc79..d0df8d0df4e3 100644
@@ -8404,8 +8404,6 @@
 #define regPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define regPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define regPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define regPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define regPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define regCB_CP_PIPEID                                                                                 0x00d9
 #define regCB_CP_PIPEID_BASE_IDX                                                                        1
 #define regCB_CP_VMID                                                                                   0x00da
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_0_offset.h +0 -2
index 12d451e5475b..d5c31df4cea7 100644
@@ -3584,8 +3584,6 @@
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define mmPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define mmPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define mmPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define mmCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define mmCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define mmCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_1_offset.h +0 -2
index d17d1e622e4f..a7d476b6c8e3 100644
@@ -3814,8 +3814,6 @@
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define mmPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define mmPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define mmPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define mmCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define mmCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define mmCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_2_1_offset.h +0 -2
index c30720277912..fc5c7abb35e7 100644
@@ -3764,8 +3764,6 @@
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define mmPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define mmPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define mmPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define mmCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define mmCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define mmCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_4_2_offset.h +0 -2
index 1a8a6a350789..e13fb8137820 100644
@@ -1755,8 +1755,6 @@
 #define regPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define regPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define regPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define regPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define regPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define regCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define regCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define regCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_4_3_offset.h +0 -2
index 393963502b7a..845dbbbfd567 100644
@@ -3995,8 +3995,6 @@
 #define regPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
 #define regPA_SC_SCREEN_EXTENT_CONTROL                                                                  0x00d6
 #define regPA_SC_SCREEN_EXTENT_CONTROL_BASE_IDX                                                         1
-#define regPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
-#define regPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 #define regCP_PERFMON_CNTX_CNTL                                                                         0x00d8
 #define regCP_PERFMON_CNTX_CNTL_BASE_IDX                                                                1
 #define regCP_PIPEID                                                                                    0x00d9
drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h new file +9 -0
new file mode 100644
index 000000000000..1f7c5f597c05
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: MIT */
+
+#ifndef _gc_gc_common_offset
+#define _gc_gc_common_offset
+
+#define mmPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
+#define mmPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
+
+#endif
Signature · 1 line
2.49.0
#2 lore raw

PATCH 2/6 drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer

In reply to Rodrigo Siqueira

When inspecting gfx_v11_0_get_csb_buffer and gfx_v10_0_get_csb_buffer, it becomes clear that both functions are very similar (only the function name change). Since those operations are common between gfx11 and gfx10, this commit creates a dedicated function named gfx_get_csb_buffer and uses it for gfx11 and gfx10.

---
 Documentation/gpu/amdgpu/amdgpu-glossary.rst |  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c      | 57 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h      |  1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c       | 50 +----------------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c       | 49 +----------------
 5 files changed, 63 insertions(+), 97 deletions(-)
Documentation/gpu/amdgpu/amdgpu-glossary.rst +3 -0
index 1e9283e076ba..497fbc08a3fd 100644
@@ -12,6 +12,9 @@ we have a dedicated glossary for Display Core at
       The number of CUs that are active on the system.  The number of active
       CUs may be less than SE * SH * CU depending on the board configuration.
 
+    CSB
+      Clear State Indirect Buffer
+
     CE
       Constant Engine
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +57 -0

69 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
index 75af4f25a133..fe7dd5fd8b95 100644
@@ -594,6 +594,7 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+void gfx_get_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer);
 
 void amdgpu_gfx_profile_idle_work_handler(struct work_struct *work);
 void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring);
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -49

74 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -48

67 lines not on this page · raw message

Signature · 1 line
2.49.0
#3 lore raw

PATCH 3/6 drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into gfx_get_csb_buffer

In reply to Rodrigo Siqueira

The code implementation in gfx_get_csb_buffer is very similar to the gfx_v9_0_get_csb_buffer; the main difference is the fact that GFX9 does not have some of the specific operations for GFX11 and GFX10. This commit adds a check in the particular part of gfx_get_csb_buffer that should be skipped in the GFX9 code path. Finally, this commit eliminates the unnecessary gfx_v9_0_get_csb_buffer function in favor of gfx_get_csb_buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 13 +++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 43 ++-----------------------
 2 files changed, 11 insertions(+), 45 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +9 -4
index 24acb229367c..b26f9f053670 100644
@@ -2254,10 +2254,15 @@ void gfx_get_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)
 		}
 	}
 
-	ctx_reg_offset = SOC15_REG_OFFSET(GC, 0, mmPA_SC_TILE_STEERING_OVERRIDE) - PACKET3_SET_CONTEXT_REG_START;
-	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 1));
-	buffer[count++] = cpu_to_le32(ctx_reg_offset);
-	buffer[count++] = cpu_to_le32(adev->gfx.config.pa_sc_tile_steering_override);
+	// GFX10 and GFX11 requires the below operation, but GFX9 should skip
+	// it.
+	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(10, 0, 0) &&
+	    amdgpu_ip_version(adev, GC_HWIP, 0) <  IP_VERSION(12, 0, 0)) {
+		ctx_reg_offset = SOC15_REG_OFFSET(GC, 0, mmPA_SC_TILE_STEERING_OVERRIDE) - PACKET3_SET_CONTEXT_REG_START;
+		buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 1));
+		buffer[count++] = cpu_to_le32(ctx_reg_offset);
+		buffer[count++] = cpu_to_le32(adev->gfx.config.pa_sc_tile_steering_override);
+	}
 
 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
 	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -41

61 lines not on this page · raw message

Signature · 1 line
2.49.0
#4 lore raw

PATCH 4/6 drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer

In reply to Rodrigo Siqueira

The gfx_v8_0_get_csb_buffer only differs from gfx_get_csb_buffer in a sequence where some specific registers must be used. To assimilate gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer, it was necessary two modifications:

1. In gfx_get_csb_buffer, check for GFX8 and, based on that, execute the specific operation.
2. Move mmPA_SC_RASTER_CONFIG registers to the common register list.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 12 ++++-
 drivers/gpu/drm/amd/amdgpu/cik.c              |  2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         | 51 ++-----------------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |  1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |  2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |  2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |  1 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |  1 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |  1 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |  1 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |  1 -
 .../include/asic_reg/gc/gc_common_offset.h    |  2 +
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |  1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |  1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |  1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |  1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |  1 -
 19 files changed, 27 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -2
index b26f9f053670..71a25f626fee 100644
@@ -2254,8 +2254,16 @@ void gfx_get_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)
 		}
 	}
 
-	// GFX10 and GFX11 requires the below operation, but GFX9 should skip
-	// it.
+	// GFX8 specific operation
+	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(8, 0, 0) &&
+	    amdgpu_ip_version(adev, GC_HWIP, 0) <  IP_VERSION(9, 0, 0)) {
+		buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
+		buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
+		buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
+		buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config_1);
+	}
+
+	// GFX10 and GFX11 specific operation.
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(10, 0, 0) &&
 	    amdgpu_ip_version(adev, GC_HWIP, 0) <  IP_VERSION(12, 0, 0)) {
 		ctx_reg_offset = SOC15_REG_OFFSET(GC, 0, mmPA_SC_TILE_STEERING_OVERRIDE) - PACKET3_SET_CONTEXT_REG_START;
drivers/gpu/drm/amd/amdgpu/cik.c +2 -0
index 9cd63b4177bf..a83549273de3 100644
@@ -58,6 +58,8 @@
 #include "bif/bif_4_1_d.h"
 #include "bif/bif_4_1_sh_mask.h"
 
+#include "gc/gc_common_offset.h"
+
 #include "gca/gfx_7_2_d.h"
 #include "gca/gfx_7_2_enum.h"
 #include "gca/gfx_7_2_sh_mask.h"
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +2 -0
index d86620f38855..ff794410794d 100644
@@ -37,6 +37,8 @@
 #include "oss/oss_1_0_d.h"
 #include "oss/oss_1_0_sh_mask.h"
 
+#include "gc/gc_common_offset.h"
+
 #include "gca/gfx_6_0_d.h"
 #include "gca/gfx_6_0_sh_mask.h"
 #include "gca/gfx_7_2_enum.h"
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +2 -0
index 0fdc4362bbc0..6423b7a31e84 100644
@@ -40,6 +40,8 @@
 #include "bif/bif_4_1_d.h"
 #include "bif/bif_4_1_sh_mask.h"
 
+#include "gc/gc_common_offset.h"
+
 #include "gca/gfx_7_0_d.h"
 #include "gca/gfx_7_2_enum.h"
 #include "gca/gfx_7_2_sh_mask.h"
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +4 -47

75 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +1 -0
index e1d63bed84bf..72a35b108135 100644
@@ -33,6 +33,7 @@
 #include "gfx_v8_0.h"
 #include "sdma_v3_0.h"
 #include "tonga_ih.h"
+#include "gc/gc_common_offset.h"
 #include "gmc/gmc_8_2_d.h"
 #include "gmc/gmc_8_2_sh_mask.h"
 #include "oss/oss_3_0_d.h"
drivers/gpu/drm/amd/amdgpu/si.c +2 -0
index 94a6ec162640..be8d73419c23 100644
@@ -51,6 +51,8 @@
 #include "smu/smu_6_0_d.h"
 #include "smu/smu_6_0_sh_mask.h"
 
+#include "gc/gc_common_offset.h"
+
 #include "gca/gfx_6_0_d.h"
 #include "gca/gfx_6_0_sh_mask.h"
 
drivers/gpu/drm/amd/amdgpu/vi.c +2 -0
index 86d8bc10d90a..910984c27480 100644
@@ -44,6 +44,8 @@
 #include "bif/bif_5_0_d.h"
 #include "bif/bif_5_0_sh_mask.h"
 
+#include "gc/gc_common_offset.h"
+
 #include "gca/gfx_8_0_d.h"
 #include "gca/gfx_8_0_sh_mask.h"
 
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_1_0_offset.h +0 -1
index 1e92f71f12b8..96bb71a7d4df 100644
@@ -5968,7 +5968,6 @@
 #define mmPA_SC_VPORT_ZMIN_15_BASE_IDX                                                                 1
 #define mmPA_SC_VPORT_ZMAX_15                                                                          0x00d3
 #define mmPA_SC_VPORT_ZMAX_15_BASE_IDX                                                                 1
-#define mmPA_SC_RASTER_CONFIG                                                                          0x00d4
 #define mmPA_SC_RASTER_CONFIG_BASE_IDX                                                                 1
 #define mmPA_SC_RASTER_CONFIG_1                                                                        0x00d5
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_3_0_offset.h +0 -1
index 555a3bc26614..56f9233aa034 100644
@@ -5597,7 +5597,6 @@
 #define mmPA_SC_VPORT_ZMIN_15_BASE_IDX                                                                 1
 #define mmPA_SC_VPORT_ZMAX_15                                                                          0x00d3
 #define mmPA_SC_VPORT_ZMAX_15_BASE_IDX                                                                 1
-#define mmPA_SC_RASTER_CONFIG                                                                          0x00d4
 #define mmPA_SC_RASTER_CONFIG_BASE_IDX                                                                 1
 #define mmPA_SC_RASTER_CONFIG_1                                                                        0x00d5
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_0_offset.h +0 -1
index d5c31df4cea7..e9357cab9cfb 100644
@@ -3578,7 +3578,6 @@
 #define mmPA_SC_VPORT_ZMIN_15_BASE_IDX                                                                 1
 #define mmPA_SC_VPORT_ZMAX_15                                                                          0x00d3
 #define mmPA_SC_VPORT_ZMAX_15_BASE_IDX                                                                 1
-#define mmPA_SC_RASTER_CONFIG                                                                          0x00d4
 #define mmPA_SC_RASTER_CONFIG_BASE_IDX                                                                 1
 #define mmPA_SC_RASTER_CONFIG_1                                                                        0x00d5
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_1_offset.h +0 -1
index a7d476b6c8e3..21b43f102486 100644
@@ -3808,7 +3808,6 @@
 #define mmPA_SC_VPORT_ZMIN_15_BASE_IDX                                                                 1
 #define mmPA_SC_VPORT_ZMAX_15                                                                          0x00d3
 #define mmPA_SC_VPORT_ZMAX_15_BASE_IDX                                                                 1
-#define mmPA_SC_RASTER_CONFIG                                                                          0x00d4
 #define mmPA_SC_RASTER_CONFIG_BASE_IDX                                                                 1
 #define mmPA_SC_RASTER_CONFIG_1                                                                        0x00d5
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_2_1_offset.h +0 -1
index fc5c7abb35e7..4ba0e8ccfa12 100644
@@ -3758,7 +3758,6 @@
 #define mmPA_SC_VPORT_ZMIN_15_BASE_IDX                                                                 1
 #define mmPA_SC_VPORT_ZMAX_15                                                                          0x00d3
 #define mmPA_SC_VPORT_ZMAX_15_BASE_IDX                                                                 1
-#define mmPA_SC_RASTER_CONFIG                                                                          0x00d4
 #define mmPA_SC_RASTER_CONFIG_BASE_IDX                                                                 1
 #define mmPA_SC_RASTER_CONFIG_1                                                                        0x00d5
 #define mmPA_SC_RASTER_CONFIG_1_BASE_IDX                                                               1
drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h +2 -0
index 1f7c5f597c05..5fe3a031e379 100644
@@ -6,4 +6,6 @@
 #define mmPA_SC_TILE_STEERING_OVERRIDE                                                                 0x00d7
 #define mmPA_SC_TILE_STEERING_OVERRIDE_BASE_IDX                                                        1
 
+#define mmPA_SC_RASTER_CONFIG                                                   0xa0d4
+
 #endif
drivers/gpu/drm/amd/include/asic_reg/gca/gfx_6_0_d.h +0 -1
index 6f44345277af..1dba803b8bab 100644
@@ -1000,7 +1000,6 @@
 #define mmPA_SC_PERFCOUNTER7_HI 0x22B7
 #define mmPA_SC_PERFCOUNTER7_LO 0x22B6
 #define mmPA_SC_PERFCOUNTER7_SELECT 0x22A7
-#define mmPA_SC_RASTER_CONFIG 0xA0D4
 #define mmPA_SC_SCREEN_SCISSOR_BR 0xA00D
 #define mmPA_SC_SCREEN_SCISSOR_TL 0xA00C
 #define mmPA_SC_VPORT_SCISSOR_0_BR 0xA095
drivers/gpu/drm/amd/include/asic_reg/gca/gfx_7_0_d.h +0 -1
index b1d7cefb4bd1..d7fc5acb5ec7 100644
@@ -1016,7 +1016,6 @@
 #define mmPA_SC_LINE_STIPPLE                                                    0xa283
 #define mmPA_SC_MODE_CNTL_0                                                     0xa292
 #define mmPA_SC_MODE_CNTL_1                                                     0xa293
-#define mmPA_SC_RASTER_CONFIG                                                   0xa0d4
 #define mmPA_SC_RASTER_CONFIG_1                                                 0xa0d5
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                           0xa0d6
 #define mmPA_SC_GENERIC_SCISSOR_TL                                              0xa090
drivers/gpu/drm/amd/include/asic_reg/gca/gfx_7_2_d.h +0 -1
index 290ce6aa4b71..c189bff59969 100644
@@ -1029,7 +1029,6 @@
 #define mmPA_SC_LINE_STIPPLE                                                    0xa283
 #define mmPA_SC_MODE_CNTL_0                                                     0xa292
 #define mmPA_SC_MODE_CNTL_1                                                     0xa293
-#define mmPA_SC_RASTER_CONFIG                                                   0xa0d4
 #define mmPA_SC_RASTER_CONFIG_1                                                 0xa0d5
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                           0xa0d6
 #define mmPA_SC_GENERIC_SCISSOR_TL                                              0xa090
drivers/gpu/drm/amd/include/asic_reg/gca/gfx_8_0_d.h +0 -1
index 90ff7c8a6011..7c4b43d324e6 100644
@@ -1111,7 +1111,6 @@
 #define mmPA_SC_LINE_STIPPLE                                                    0xa283
 #define mmPA_SC_MODE_CNTL_0                                                     0xa292
 #define mmPA_SC_MODE_CNTL_1                                                     0xa293
-#define mmPA_SC_RASTER_CONFIG                                                   0xa0d4
 #define mmPA_SC_RASTER_CONFIG_1                                                 0xa0d5
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                           0xa0d6
 #define mmPA_SC_GENERIC_SCISSOR_TL                                              0xa090
drivers/gpu/drm/amd/include/asic_reg/gca/gfx_8_1_d.h +0 -1
index 2d672b3d2fed..eba388df8674 100644
@@ -1112,7 +1112,6 @@
 #define mmPA_SC_LINE_STIPPLE                                                    0xa283
 #define mmPA_SC_MODE_CNTL_0                                                     0xa292
 #define mmPA_SC_MODE_CNTL_1                                                     0xa293
-#define mmPA_SC_RASTER_CONFIG                                                   0xa0d4
 #define mmPA_SC_RASTER_CONFIG_1                                                 0xa0d5
 #define mmPA_SC_SCREEN_EXTENT_CONTROL                                           0xa0d6
 #define mmPA_SC_GENERIC_SCISSOR_TL                                              0xa090
Signature · 1 line
2.49.0
#5 lore raw

PATCH 5/6 drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into gfx_get_csb_buffer

In reply to Rodrigo Siqueira

The gfx_v7_0_get_csb_buffer function is incorporated into gfx_get_csb_buffer, but it required to port some specific ASIC operations to the function. Additionally, this transition also eliminates some unnecessary code from gfx_v7_0_get_csb_buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 31 +++++++++--
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   | 68 +------------------------
 2 files changed, 28 insertions(+), 71 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +27 -4
index 71a25f626fee..57bf3282e797 100644
@@ -2254,13 +2254,36 @@ void gfx_get_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)
 		}
 	}
 
-	// GFX8 specific operation
-	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(8, 0, 0) &&
+	// GFX7 and GFX8
+	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(7, 0, 0) &&
 	    amdgpu_ip_version(adev, GC_HWIP, 0) <  IP_VERSION(9, 0, 0)) {
 		buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
 		buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
-		buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
-		buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config_1);
+
+		// GFX8
+		if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(8, 0, 0)) {
+			buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
+			buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config_1);
+		}
+
+		// GFX7 Specific ASICs
+		if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(7, 0, 0) &&
+		    amdgpu_ip_version(adev, GC_HWIP, 0) <  IP_VERSION(8, 0, 0)) {
+			switch (adev->asic_type) {
+			case CHIP_BONAIRE:
+				buffer[count++] = cpu_to_le32(0x16000012);
+				buffer[count++] = cpu_to_le32(0x00000000);
+				break;
+			case CHIP_HAWAII:
+				buffer[count++] = cpu_to_le32(0x3a00161a);
+				buffer[count++] = cpu_to_le32(0x0000002e);
+				break;
+			default:
+				buffer[count++] = cpu_to_le32(0x00000000);
+				buffer[count++] = cpu_to_le32(0x00000000);
+				break;
+			}
+		}
 	}
 
 	// GFX10 and GFX11 specific operation.
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +1 -67

92 lines not on this page · raw message

Signature · 1 line
2.49.0
#6 lore raw

PATCH 6/6 drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

In reply to Rodrigo Siqueira

Move the only specific GFX6 part from gfx_v6_0_get_csb_buffer to gfx_get_csb_buffer and remove the gfx6 version.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c |  8 +++++
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c   | 44 +------------------------
 2 files changed, 9 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -0
index 57bf3282e797..2c77408b7f0d 100644
@@ -2254,6 +2254,14 @@ void gfx_get_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)
 		}
 	}
 
+	// GFX6
+	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(6, 0, 0) &&
+	    amdgpu_ip_version(adev, GC_HWIP, 0) <  IP_VERSION(7, 0, 0)) {
+		buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 1));
+		buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
+		buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
+	}
+
 	// GFX7 and GFX8
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(7, 0, 0) &&
 	    amdgpu_ip_version(adev, GC_HWIP, 0) <  IP_VERSION(9, 0, 0)) {
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +1 -43

62 lines not on this page · raw message

Signature · 1 line
2.49.0
#7 lore raw
In reply to Rodrigo Siqueira
Quoted 18 lines · Rodrigo Siqueira

This patchset was inspired and made on top of the below series:

https://lore.kernel.org/amd-gfx/[email protected]/

In the above series, there is a bug fix in many functions named gfx_vX_0_get_csb_buffer (where X ranges from 6 to 11). After closely looking at those functions, it became clear that most of the code could be shared from gfx6 to gfx11. Aside from the code duplication removal, this also improves maintainability since a bug fix in a shared function can be propagated to all ASICs.

The first patch of this series created one dedicated file for encapsulating common GC registers (gc_common_offset.h); this series only adds registers associated with the CSB. In the future, this file can keep growing as we identify common registers to be shared in the gc_common_offset.h.

Quoted 6 lines

The second patch introduces the generic gfx_get_csb_buffer function, which has the same implementation found in gfx_v10_0_get_csb_buffer and gfx_v11_0_get_csb_buffer (these two functions have the same code). After that, every patch is dedicated to absorbing one of the csb_buffer functions from gfx from 9 to 6; notice that some adaptations were required.

I don't really like the register header changes and moving all of the IP version specific logic into the common code. These register headers are used in other places as well and moving some registers into a common header can get confusing and may lead to bugs later if other chips change the offset of these registers.

Alex

Quoted 49 lines

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Create a headears to keep some common GC registers drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

 Documentation/gpu/amdgpu/amdgpu-glossary.rst  |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 101 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |   1 +
 drivers/gpu/drm/amd/amdgpu/cik.c              |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  53 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  46 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  70 +-----------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  43 +-------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |   1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |   2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |   2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_11_0_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_0_3_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_5_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_12_0_0_offset.h    |   2 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |   3 -
 .../amd/include/asic_reg/gc/gc_9_4_2_offset.h |   2 -
 .../amd/include/asic_reg/gc/gc_9_4_3_offset.h |   2 -
 .../include/asic_reg/gc/gc_common_offset.h    |  11 ++
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |   1 -
 30 files changed, 141 insertions(+), 328 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h

--
2.49.0

#8 lore raw
Quoted 26 lines · Alex Deucher
Quoted 18 lines · Rodrigo Siqueira

This patchset was inspired and made on top of the below series:

https://lore.kernel.org/amd-gfx/[email protected]/

In the above series, there is a bug fix in many functions named gfx_vX_0_get_csb_buffer (where X ranges from 6 to 11). After closely looking at those functions, it became clear that most of the code could be shared from gfx6 to gfx11. Aside from the code duplication removal, this also improves maintainability since a bug fix in a shared function can be propagated to all ASICs.

The first patch of this series created one dedicated file for encapsulating common GC registers (gc_common_offset.h); this series only adds registers associated with the CSB. In the future, this file can keep growing as we identify common registers to be shared in the gc_common_offset.h.

Quoted 6 lines

The second patch introduces the generic gfx_get_csb_buffer function, which has the same implementation found in gfx_v10_0_get_csb_buffer and gfx_v11_0_get_csb_buffer (these two functions have the same code). After that, every patch is dedicated to absorbing one of the csb_buffer functions from gfx from 9 to 6; notice that some adaptations were required.

Quoted 5 lines

I don't really like the register header changes and moving all of the IP version specific logic into the common code. These register headers are used in other places as well and moving some registers into a common header can get confusing and may lead to bugs later if other chips change the offset of these registers.

In that case, what do you think if I just abstract the first part of the function for a V2? The first part is the same for all gfx from 6 to 11. Something like this:

int gfx_get_pre_setup_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)

{
       u32 count = 0, i;
       const struct cs_section_def *sect = NULL;
       const struct cs_extent_def *ext = NULL;
       int ctx_reg_offset;

       if (adev->gfx.rlc.cs_data == NULL)
               return 1;
       if (buffer == NULL)
               return 1;

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
       buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
       buffer[count++] = cpu_to_le32(0x80000000);
       buffer[count++] = cpu_to_le32(0x80000000);

       for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
               for (ext = sect->section; ext->extent != NULL; ++ext) {
                       if (sect->id == SECT_CONTEXT) {
                               buffer[count++] =
                                       cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                               buffer[count++] = cpu_to_le32(ext->reg_index -
                                               PACKET3_SET_CONTEXT_REG_START);
                               for (i = 0; i < ext->reg_count; i++)
                                       buffer[count++] = cpu_to_le32(ext->extent[i]);
                       }
               }
       }

       return 0;
}

Thanks

Quoted 52 lines

Alex

Quoted 49 lines

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Create a headears to keep some common GC registers drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

 Documentation/gpu/amdgpu/amdgpu-glossary.rst  |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 101 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |   1 +
 drivers/gpu/drm/amd/amdgpu/cik.c              |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  53 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  46 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  70 +-----------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  43 +-------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |   1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |   2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |   2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_11_0_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_0_3_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_5_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_12_0_0_offset.h    |   2 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |   3 -
 .../amd/include/asic_reg/gc/gc_9_4_2_offset.h |   2 -
 .../amd/include/asic_reg/gc/gc_9_4_3_offset.h |   2 -
 .../include/asic_reg/gc/gc_common_offset.h    |  11 ++
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |   1 -
 30 files changed, 141 insertions(+), 328 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h

--
2.49.0

Signature · 1 line
Rodrigo Siqueira
#9 lore raw
Quoted 64 lines · Rodrigo Siqueira
Quoted 26 lines · Alex Deucher
Quoted 18 lines · Rodrigo Siqueira

This patchset was inspired and made on top of the below series:

https://lore.kernel.org/amd-gfx/[email protected]/

In the above series, there is a bug fix in many functions named gfx_vX_0_get_csb_buffer (where X ranges from 6 to 11). After closely looking at those functions, it became clear that most of the code could be shared from gfx6 to gfx11. Aside from the code duplication removal, this also improves maintainability since a bug fix in a shared function can be propagated to all ASICs.

The first patch of this series created one dedicated file for encapsulating common GC registers (gc_common_offset.h); this series only adds registers associated with the CSB. In the future, this file can keep growing as we identify common registers to be shared in the gc_common_offset.h.

Quoted 6 lines

The second patch introduces the generic gfx_get_csb_buffer function, which has the same implementation found in gfx_v10_0_get_csb_buffer and gfx_v11_0_get_csb_buffer (these two functions have the same code). After that, every patch is dedicated to absorbing one of the csb_buffer functions from gfx from 9 to 6; notice that some adaptations were required.

Quoted 5 lines

I don't really like the register header changes and moving all of the IP version specific logic into the common code. These register headers are used in other places as well and moving some registers into a common header can get confusing and may lead to bugs later if other chips change the offset of these registers.

In that case, what do you think if I just abstract the first part of the function for a V2? The first part is the same for all gfx from 6 to 11. Something like this:

int gfx_get_pre_setup_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)

{
       u32 count = 0, i;
       const struct cs_section_def *sect = NULL;
       const struct cs_extent_def *ext = NULL;
       int ctx_reg_offset;

       if (adev->gfx.rlc.cs_data == NULL)
               return 1;
       if (buffer == NULL)
               return 1;

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
       buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
       buffer[count++] = cpu_to_le32(0x80000000);
       buffer[count++] = cpu_to_le32(0x80000000);

       for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
               for (ext = sect->section; ext->extent != NULL; ++ext) {
                       if (sect->id == SECT_CONTEXT) {
                               buffer[count++] =
                                       cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                               buffer[count++] = cpu_to_le32(ext->reg_index -
                                               PACKET3_SET_CONTEXT_REG_START);
Quoted 8 lines
                               for (i = 0; i < ext->reg_count; i++)
                                       buffer[count++] = cpu_to_le32(ext->extent[i]);
                       }
               }
       }

       return 0;
}

Sure helpers are fine. maybe a preamble_start helper

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
        buffer[count++] = cpu_to_le32(0x80000000);
        buffer[count++] = cpu_to_le32(0x80000000);
and a preamble_end helper:
        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
        buffer[count++] = cpu_to_le32(0);
and a cs_data parser helper:
        for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
            for (ext = sect->section; ext->extent != NULL; ++ext) {
                        if (sect->id == SECT_CONTEXT) {
                buffer[count++] =
cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                                buffer[count++] = cpu_to_le32(ext->reg_index -
                                                PACKET3_SET_CONTEXT_REG_START);
                                for (i = 0; i < ext->reg_count; i++)
                                        buffer[count++] =
cpu_to_le32(ext->extent[i]);
                        }
                }
    }

Also, while you are at it, you could clean up gfx_v9_0_cp_gfx_start(), etc. to use the cs buffer and cs size directly rather than re-parsing everything again.

Alex

Quoted 58 lines

Thanks

Quoted 52 lines

Alex

Quoted 49 lines

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Create a headears to keep some common GC registers drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

 Documentation/gpu/amdgpu/amdgpu-glossary.rst  |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 101 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |   1 +
 drivers/gpu/drm/amd/amdgpu/cik.c              |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  53 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  46 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  70 +-----------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  43 +-------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |   1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |   2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |   2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_11_0_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_0_3_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_5_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_12_0_0_offset.h    |   2 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |   3 -
 .../amd/include/asic_reg/gc/gc_9_4_2_offset.h |   2 -
 .../amd/include/asic_reg/gc/gc_9_4_3_offset.h |   2 -
 .../include/asic_reg/gc/gc_common_offset.h    |  11 ++
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |   1 -
 30 files changed, 141 insertions(+), 328 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h

--
2.49.0

--
Rodrigo Siqueira

#10 lore raw
Quoted 93 lines · Alex Deucher
Quoted 64 lines · Rodrigo Siqueira
Quoted 26 lines · Alex Deucher
Quoted 18 lines · Rodrigo Siqueira

This patchset was inspired and made on top of the below series:

https://lore.kernel.org/amd-gfx/[email protected]/

In the above series, there is a bug fix in many functions named gfx_vX_0_get_csb_buffer (where X ranges from 6 to 11). After closely looking at those functions, it became clear that most of the code could be shared from gfx6 to gfx11. Aside from the code duplication removal, this also improves maintainability since a bug fix in a shared function can be propagated to all ASICs.

The first patch of this series created one dedicated file for encapsulating common GC registers (gc_common_offset.h); this series only adds registers associated with the CSB. In the future, this file can keep growing as we identify common registers to be shared in the gc_common_offset.h.

Quoted 6 lines

The second patch introduces the generic gfx_get_csb_buffer function, which has the same implementation found in gfx_v10_0_get_csb_buffer and gfx_v11_0_get_csb_buffer (these two functions have the same code). After that, every patch is dedicated to absorbing one of the csb_buffer functions from gfx from 9 to 6; notice that some adaptations were required.

Quoted 5 lines

I don't really like the register header changes and moving all of the IP version specific logic into the common code. These register headers are used in other places as well and moving some registers into a common header can get confusing and may lead to bugs later if other chips change the offset of these registers.

In that case, what do you think if I just abstract the first part of the function for a V2? The first part is the same for all gfx from 6 to 11. Something like this:

int gfx_get_pre_setup_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)

{
       u32 count = 0, i;
       const struct cs_section_def *sect = NULL;
       const struct cs_extent_def *ext = NULL;
       int ctx_reg_offset;

       if (adev->gfx.rlc.cs_data == NULL)
               return 1;
       if (buffer == NULL)
               return 1;

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
       buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
       buffer[count++] = cpu_to_le32(0x80000000);
       buffer[count++] = cpu_to_le32(0x80000000);

       for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
               for (ext = sect->section; ext->extent != NULL; ++ext) {
                       if (sect->id == SECT_CONTEXT) {
                               buffer[count++] =
                                       cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                               buffer[count++] = cpu_to_le32(ext->reg_index -
                                               PACKET3_SET_CONTEXT_REG_START);
Quoted 8 lines
                               for (i = 0; i < ext->reg_count; i++)
                                       buffer[count++] = cpu_to_le32(ext->extent[i]);
                       }
               }
       }

       return 0;
}

Sure helpers are fine. maybe a preamble_start helper

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
        buffer[count++] = cpu_to_le32(0x80000000);
        buffer[count++] = cpu_to_le32(0x80000000);
and a preamble_end helper:
        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
        buffer[count++] = cpu_to_le32(0);
and a cs_data parser helper:
        for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
            for (ext = sect->section; ext->extent != NULL; ++ext) {
                        if (sect->id == SECT_CONTEXT) {
                buffer[count++] =
Quoted 9 lines
cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                                buffer[count++] = cpu_to_le32(ext->reg_index -
                                                PACKET3_SET_CONTEXT_REG_START);
                                for (i = 0; i < ext->reg_count; i++)
                                        buffer[count++] =
cpu_to_le32(ext->extent[i]);
                        }
                }
    }

Nice. I'll prepare a V2.

Quoted 4 lines

Also, while you are at it, you could clean up gfx_v9_0_cp_gfx_start(), etc. to use the cs buffer and cs size directly rather than re-parsing everything again.

Sure, I'll make it as a separate patchset.

Thanks

Quoted 61 lines

Alex

Quoted 58 lines

Thanks

Quoted 52 lines

Alex

Quoted 49 lines

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Create a headears to keep some common GC registers drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

 Documentation/gpu/amdgpu/amdgpu-glossary.rst  |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 101 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |   1 +
 drivers/gpu/drm/amd/amdgpu/cik.c              |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  53 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  46 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  70 +-----------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  43 +-------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |   1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |   2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |   2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_11_0_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_0_3_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_5_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_12_0_0_offset.h    |   2 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |   3 -
 .../amd/include/asic_reg/gc/gc_9_4_2_offset.h |   2 -
 .../amd/include/asic_reg/gc/gc_9_4_3_offset.h |   2 -
 .../include/asic_reg/gc/gc_common_offset.h    |  11 ++
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |   1 -
 30 files changed, 141 insertions(+), 328 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h

--
2.49.0

--
Rodrigo Siqueira

Signature · 1 line
Rodrigo Siqueira
#11 lore raw
Quoted 104 lines · Rodrigo Siqueira
Quoted 93 lines · Alex Deucher
Quoted 64 lines · Rodrigo Siqueira
Quoted 26 lines · Alex Deucher
Quoted 18 lines · Rodrigo Siqueira

This patchset was inspired and made on top of the below series:

https://lore.kernel.org/amd-gfx/[email protected]/

In the above series, there is a bug fix in many functions named gfx_vX_0_get_csb_buffer (where X ranges from 6 to 11). After closely looking at those functions, it became clear that most of the code could be shared from gfx6 to gfx11. Aside from the code duplication removal, this also improves maintainability since a bug fix in a shared function can be propagated to all ASICs.

The first patch of this series created one dedicated file for encapsulating common GC registers (gc_common_offset.h); this series only adds registers associated with the CSB. In the future, this file can keep growing as we identify common registers to be shared in the gc_common_offset.h.

Quoted 6 lines

The second patch introduces the generic gfx_get_csb_buffer function, which has the same implementation found in gfx_v10_0_get_csb_buffer and gfx_v11_0_get_csb_buffer (these two functions have the same code). After that, every patch is dedicated to absorbing one of the csb_buffer functions from gfx from 9 to 6; notice that some adaptations were required.

Quoted 5 lines

I don't really like the register header changes and moving all of the IP version specific logic into the common code. These register headers are used in other places as well and moving some registers into a common header can get confusing and may lead to bugs later if other chips change the offset of these registers.

In that case, what do you think if I just abstract the first part of the function for a V2? The first part is the same for all gfx from 6 to 11. Something like this:

int gfx_get_pre_setup_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)

{
       u32 count = 0, i;
       const struct cs_section_def *sect = NULL;
       const struct cs_extent_def *ext = NULL;
       int ctx_reg_offset;

       if (adev->gfx.rlc.cs_data == NULL)
               return 1;
       if (buffer == NULL)
               return 1;

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
       buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
       buffer[count++] = cpu_to_le32(0x80000000);
       buffer[count++] = cpu_to_le32(0x80000000);

       for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
               for (ext = sect->section; ext->extent != NULL; ++ext) {
                       if (sect->id == SECT_CONTEXT) {
                               buffer[count++] =
                                       cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                               buffer[count++] = cpu_to_le32(ext->reg_index -
                                               PACKET3_SET_CONTEXT_REG_START);
Quoted 8 lines
                               for (i = 0; i < ext->reg_count; i++)
                                       buffer[count++] = cpu_to_le32(ext->extent[i]);
                       }
               }
       }

       return 0;
}

Sure helpers are fine. maybe a preamble_start helper

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
        buffer[count++] = cpu_to_le32(0x80000000);
        buffer[count++] = cpu_to_le32(0x80000000);
and a preamble_end helper:
        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
        buffer[count++] = cpu_to_le32(0);
and a cs_data parser helper:
        for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
            for (ext = sect->section; ext->extent != NULL; ++ext) {
                        if (sect->id == SECT_CONTEXT) {
                buffer[count++] =
Quoted 9 lines
cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                                buffer[count++] = cpu_to_le32(ext->reg_index -
                                                PACKET3_SET_CONTEXT_REG_START);
                                for (i = 0; i < ext->reg_count; i++)
                                        buffer[count++] =
cpu_to_le32(ext->extent[i]);
                        }
                }
    }
Quoted 6 lines

Nice. I'll prepare a V2.

Quoted 4 lines

Also, while you are at it, you could clean up gfx_v9_0_cp_gfx_start(), etc. to use the cs buffer and cs size directly rather than re-parsing everything again.

I was looking into the gfx_vX_0_cp_gfx_start() functions, but I was slightly confused about how to approach this part. I can see from gfx_vX_0_cp_gfx_start() that a preamble start, parser, and preamble end are common parts, but I felt I could not re-use some of the helpers created in the V2 of this series because gfx_vX_0_cp_gfx_start() writes directly in the ring buffer and it has some special checks. Should I create a dedicated helper for those parts?  Or did I misunderstand what you suggested?

Quoted 69 lines

Sure, I'll make it as a separate patchset.

Thanks

Quoted 61 lines

Alex

Quoted 58 lines

Thanks

Quoted 52 lines

Alex

Quoted 49 lines

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Create a headears to keep some common GC registers drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

 Documentation/gpu/amdgpu/amdgpu-glossary.rst  |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 101 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |   1 +
 drivers/gpu/drm/amd/amdgpu/cik.c              |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  53 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  46 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  70 +-----------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  43 +-------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |   1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |   2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |   2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_11_0_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_0_3_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_5_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_12_0_0_offset.h    |   2 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |   3 -
 .../amd/include/asic_reg/gc/gc_9_4_2_offset.h |   2 -
 .../amd/include/asic_reg/gc/gc_9_4_3_offset.h |   2 -
 .../include/asic_reg/gc/gc_common_offset.h    |  11 ++
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |   1 -
 30 files changed, 141 insertions(+), 328 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h

--
2.49.0

--
Rodrigo Siqueira

Signature · 1 line
Rodrigo Siqueira
Signature · 1 line
Rodrigo Siqueira
#12 lore raw
Quoted 113 lines · Rodrigo Siqueira
Quoted 104 lines · Rodrigo Siqueira
Quoted 93 lines · Alex Deucher
Quoted 64 lines · Rodrigo Siqueira
Quoted 26 lines · Alex Deucher
Quoted 18 lines · Rodrigo Siqueira

This patchset was inspired and made on top of the below series:

https://lore.kernel.org/amd-gfx/[email protected]/

In the above series, there is a bug fix in many functions named gfx_vX_0_get_csb_buffer (where X ranges from 6 to 11). After closely looking at those functions, it became clear that most of the code could be shared from gfx6 to gfx11. Aside from the code duplication removal, this also improves maintainability since a bug fix in a shared function can be propagated to all ASICs.

The first patch of this series created one dedicated file for encapsulating common GC registers (gc_common_offset.h); this series only adds registers associated with the CSB. In the future, this file can keep growing as we identify common registers to be shared in the gc_common_offset.h.

Quoted 6 lines

The second patch introduces the generic gfx_get_csb_buffer function, which has the same implementation found in gfx_v10_0_get_csb_buffer and gfx_v11_0_get_csb_buffer (these two functions have the same code). After that, every patch is dedicated to absorbing one of the csb_buffer functions from gfx from 9 to 6; notice that some adaptations were required.

Quoted 5 lines

I don't really like the register header changes and moving all of the IP version specific logic into the common code. These register headers are used in other places as well and moving some registers into a common header can get confusing and may lead to bugs later if other chips change the offset of these registers.

In that case, what do you think if I just abstract the first part of the function for a V2? The first part is the same for all gfx from 6 to 11. Something like this:

int gfx_get_pre_setup_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer)

{
       u32 count = 0, i;
       const struct cs_section_def *sect = NULL;
       const struct cs_extent_def *ext = NULL;
       int ctx_reg_offset;

       if (adev->gfx.rlc.cs_data == NULL)
               return 1;
       if (buffer == NULL)
               return 1;

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
       buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

       buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
       buffer[count++] = cpu_to_le32(0x80000000);
       buffer[count++] = cpu_to_le32(0x80000000);

       for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
               for (ext = sect->section; ext->extent != NULL; ++ext) {
                       if (sect->id == SECT_CONTEXT) {
                               buffer[count++] =
                                       cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                               buffer[count++] = cpu_to_le32(ext->reg_index -
                                               PACKET3_SET_CONTEXT_REG_START);
Quoted 8 lines
                               for (i = 0; i < ext->reg_count; i++)
                                       buffer[count++] = cpu_to_le32(ext->extent[i]);
                       }
               }
       }

       return 0;
}

Sure helpers are fine. maybe a preamble_start helper

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
        buffer[count++] = cpu_to_le32(0x80000000);
        buffer[count++] = cpu_to_le32(0x80000000);
and a preamble_end helper:
        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
        buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);

        buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
        buffer[count++] = cpu_to_le32(0);
and a cs_data parser helper:
        for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
            for (ext = sect->section; ext->extent != NULL; ++ext) {
                        if (sect->id == SECT_CONTEXT) {
                buffer[count++] =
Quoted 9 lines
cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
                                buffer[count++] = cpu_to_le32(ext->reg_index -
                                                PACKET3_SET_CONTEXT_REG_START);
                                for (i = 0; i < ext->reg_count; i++)
                                        buffer[count++] =
cpu_to_le32(ext->extent[i]);
                        }
                }
    }
Quoted 6 lines

Nice. I'll prepare a V2.

Quoted 4 lines

Also, while you are at it, you could clean up gfx_v9_0_cp_gfx_start(), etc. to use the cs buffer and cs size directly rather than re-parsing everything again.

Quoted 8 lines

I was looking into the gfx_vX_0_cp_gfx_start() functions, but I was slightly confused about how to approach this part. I can see from gfx_vX_0_cp_gfx_start() that a preamble start, parser, and preamble end are common parts, but I felt I could not re-use some of the helpers created in the V2 of this series because gfx_vX_0_cp_gfx_start() writes directly in the ring buffer and it has some special checks. Should I create a dedicated helper for those parts? Or did I misunderstand what you suggested?

We already have the contents of the csb buffer stored in adev->gfx.rlc.cs_ptr when we call get_csb_buffer(). So in the gfx_vX_0_cp_gfx_start() functions we can just walk that buffer to submit the csb to the firmware rather than parsing everything again. E.g.,

u32 *csb_buffer = adev->gfx.rlc.cs_ptr;
u32 csb_size = get_csb_size();

amdgpu_ring_alloc(ring, csb_size + 4 + 3);

for (i = 0; i < csb_size; i++)

    amdgpu_ring_write(ring, csb_buffer[i]);

amdgpu_ring_write(ring, ...);
...
amdgpu_ring_commit(ring);

Alex

Quoted 73 lines
Quoted 65 lines

Sure, I'll make it as a separate patchset.

Thanks

Quoted 59 lines

Alex

Quoted 56 lines

Thanks

Quoted 52 lines

Alex

Quoted 49 lines

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Create a headears to keep some common GC registers drm/amdgpu/gfx: Introduce generic gfx_get_csb_buffer drm/amdgpu/gfx: Integrate gfx_v9_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Absorb gfx_v8_0_get_csb_buffer into gfx_get_csb_buffer drm/amdgpu/gfx: Assimilate gfx_v7_0_get_csb_buffer into
gfx_get_csb_buffer
drm/amdgpu/gfx: Merge gfx_v6_0_get_csb_buffer into gfx_get_csb_buffer

 Documentation/gpu/amdgpu/amdgpu-glossary.rst  |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 101 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |   1 +
 drivers/gpu/drm/amd/amdgpu/cik.c              |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  53 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  46 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  70 +-----------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  51 +--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  43 +-------
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |   1 +
 drivers/gpu/drm/amd/amdgpu/si.c               |   2 +
 drivers/gpu/drm/amd/amdgpu/vi.c               |   2 +
 .../include/asic_reg/gc/gc_10_1_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_10_3_0_offset.h    |   3 -
 .../include/asic_reg/gc/gc_11_0_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_0_3_offset.h    |   2 -
 .../include/asic_reg/gc/gc_11_5_0_offset.h    |   2 -
 .../include/asic_reg/gc/gc_12_0_0_offset.h    |   2 -
 .../amd/include/asic_reg/gc/gc_9_0_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_1_offset.h   |   3 -
 .../amd/include/asic_reg/gc/gc_9_2_1_offset.h |   3 -
 .../amd/include/asic_reg/gc/gc_9_4_2_offset.h |   2 -
 .../amd/include/asic_reg/gc/gc_9_4_3_offset.h |   2 -
 .../include/asic_reg/gc/gc_common_offset.h    |  11 ++
 .../drm/amd/include/asic_reg/gca/gfx_6_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_7_2_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_0_d.h  |   1 -
 .../drm/amd/include/asic_reg/gca/gfx_8_1_d.h  |   1 -
 30 files changed, 141 insertions(+), 328 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/gc/gc_common_offset.h

--
2.49.0

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

--
Rodrigo Siqueira

--
Rodrigo Siqueira

--
Rodrigo Siqueira