Skip to contentSkip to conversation

drm/amdgpu/mes: add mes mapping legacy queue switch

PATCH In review Jack Xiao 3 participants 3 messages Aug 22, 2024 – Aug 24, 2024

Subsystems (2)
lore
Share & tools
lore

Jack Xiao

author
#0 lore raw

PATCH 1/1 drm/amdgpu/mes: add mes mapping legacy queue switch

For mes11 old firmware has issue to map legacy queue, add a flag to switch mes to map legacy queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  1 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  | 49 +++++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  9 +++--
 4 files changed, 43 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -2
index 9be8cafdcecc..3ff39d3ec317 100644
@@ -657,7 +657,7 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev, int xcc_id)
 	uint64_t queue_mask = 0;
 	int r, i, j;
 
-	if (adev->enable_mes)
+	if (adev->mes.enable_legacy_queue_map)
 		return amdgpu_gfx_mes_enable_kcq(adev, xcc_id);
 
 	if (!kiq->pmf || !kiq->pmf->kiq_map_queues || !kiq->pmf->kiq_set_resources)
@@ -719,7 +719,7 @@ int amdgpu_gfx_enable_kgq(struct amdgpu_device *adev, int xcc_id)
 
 	amdgpu_device_flush_hdp(adev, NULL);
 
-	if (adev->enable_mes) {
+	if (adev->mes.enable_legacy_queue_map) {
 		for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
 			j = i + xcc_id * adev->gfx.num_gfx_rings;
 			r = amdgpu_mes_map_legacy_queue(adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
index 548e724e3a75..a509dbed858e 100644
@@ -75,6 +75,7 @@ struct amdgpu_mes {
 
 	uint32_t			sched_version;
 	uint32_t			kiq_version;
+	bool                            enable_legacy_queue_map;
 
 	uint32_t                        total_max_queue;
 	uint32_t                        max_doorbell_slices;
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +34 -15

73 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +6 -3
index 0f1702a78170..f0d58295d31d 100644
@@ -1300,6 +1300,7 @@ static int mes_v12_0_sw_init(void *handle)
 	adev->mes.funcs = &mes_v12_0_funcs;
 	adev->mes.kiq_hw_init = &mes_v12_0_kiq_hw_init;
 	adev->mes.kiq_hw_fini = &mes_v12_0_kiq_hw_fini;
+	adev->mes.enable_legacy_queue_map = true;
 
 	adev->mes.event_log_size = AMDGPU_MES_LOG_BUFFER_SIZE;
 
@@ -1456,9 +1457,11 @@ static int mes_v12_0_kiq_hw_init(struct amdgpu_device *adev)
 		mes_v12_0_set_hw_resources_1(&adev->mes, AMDGPU_MES_KIQ_PIPE);
 	}
 
-	r = mes_v12_0_hw_init(adev);
-	if (r)
-		goto failure;
+	if (adev->mes.enable_legacy_queue_map) {
+		r = mes_v12_0_hw_init(adev);
+		if (r)
+			goto failure;
+	}
 
 	return r;
 
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jack Xiao

For mes11 old firmware has issue to map legacy queue, add a flag to switch mes to map legacy queue.

Quoted 61 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  1 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  | 49 +++++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  9 +++--
 4 files changed, 43 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -2
index 9be8cafdcecc..3ff39d3ec317 100644
@@ -657,7 +657,7 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev, int xcc_id)
        uint64_t queue_mask = 0;
        int r, i, j;
 
-       if (adev->enable_mes)
+       if (adev->mes.enable_legacy_queue_map)
                return amdgpu_gfx_mes_enable_kcq(adev, xcc_id);
 
        if (!kiq->pmf || !kiq->pmf->kiq_map_queues || !kiq->pmf->kiq_set_resources)
@@ -719,7 +719,7 @@ int amdgpu_gfx_enable_kgq(struct amdgpu_device *adev, int xcc_id)
 
        amdgpu_device_flush_hdp(adev, NULL);
 
-       if (adev->enable_mes) {
+       if (adev->mes.enable_legacy_queue_map) {
                for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
                        j = i + xcc_id * adev->gfx.num_gfx_rings;
                        r = amdgpu_mes_map_legacy_queue(adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
index 548e724e3a75..a509dbed858e 100644
@@ -75,6 +75,7 @@ struct amdgpu_mes {
 
        uint32_t                        sched_version;
        uint32_t                        kiq_version;
+       bool                            enable_legacy_queue_map;
 
        uint32_t                        total_max_queue;
        uint32_t                        max_doorbell_slices;
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +11 -0
index c0340ee3dec0..dfe51e41504a 100644
@@ -726,6 +726,28 @@ static void mes_v11_0_free_ucode_buffers(struct amdgpu_device *adev,
                              (void **)&adev->mes.ucode_fw_ptr[pipe]);
 }
 
+static void mes_v11_0_get_fw_version(struct amdgpu_device *adev)
+{
+       int pipe;
+
+       /* get MES scheduler/KIQ versions */
+       mutex_lock(&adev->srbm_mutex);
+
+       for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
+               soc21_grbm_select(adev, 3, pipe, 0, 0);
+
+               if (pipe == AMDGPU_MES_SCHED_PIPE)

drivers/gpu/drm/amd/amdgpu/mes_v11_0.c static void mes_v11_0_free_ucode_buffers(struct amdgpu_device *adev, · line 749

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +10 -0
+                       adev->mes.sched_version =
+                               RREG32_SOC15(GC, 0, regCP_MES_GP3_LO);
+               else if (pipe == AMDGPU_MES_KIQ_PIPE && adev->enable_mes_kiq)
+                       adev->mes.kiq_version =
+                               RREG32_SOC15(GC, 0, regCP_MES_GP3_LO);
+       }
+
+       soc21_grbm_select(adev, 0, 0, 0, 0);
+       mutex_unlock(&adev->srbm_mutex);
+}

I think we can also get this from the firmware binary? Either way the patch is:

Quoted 81 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +13 -15
+
 static void mes_v11_0_enable(struct amdgpu_device *adev, bool enable)
 {
        uint64_t ucode_addr;
@@ -1095,18 +1117,6 @@ static int mes_v11_0_queue_init(struct amdgpu_device *adev,
                mes_v11_0_queue_init_register(ring);
        }
 
-       /* get MES scheduler/KIQ versions */
-       mutex_lock(&adev->srbm_mutex);
-       soc21_grbm_select(adev, 3, pipe, 0, 0);
-
-       if (pipe == AMDGPU_MES_SCHED_PIPE)
-               adev->mes.sched_version = RREG32_SOC15(GC, 0, regCP_MES_GP3_LO);
-       else if (pipe == AMDGPU_MES_KIQ_PIPE && adev->enable_mes_kiq)
-               adev->mes.kiq_version = RREG32_SOC15(GC, 0, regCP_MES_GP3_LO);
-
-       soc21_grbm_select(adev, 0, 0, 0, 0);
-       mutex_unlock(&adev->srbm_mutex);
-
        return 0;
 }
 
@@ -1353,15 +1363,24 @@ static int mes_v11_0_kiq_hw_init(struct amdgpu_device *adev)
 
        mes_v11_0_enable(adev, true);
 
+       mes_v11_0_get_fw_version(adev);
+
        mes_v11_0_kiq_setting(&adev->gfx.kiq[0].ring);
 
        r = mes_v11_0_queue_init(adev, AMDGPU_MES_KIQ_PIPE);
        if (r)
                goto failure;
 
-       r = mes_v11_0_hw_init(adev);
-       if (r)
-               goto failure;
+       if ((adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >= 0x47)
+               adev->mes.enable_legacy_queue_map = true;
+       else
+               adev->mes.enable_legacy_queue_map = false;
+
+       if (adev->mes.enable_legacy_queue_map) {
+               r = mes_v11_0_hw_init(adev);
+               if (r)
+                       goto failure;
+       }
 
        return r;
 
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +6 -4
index 0f1702a78170..f0d58295d31d 100644
@@ -1300,6 +1300,7 @@ static int mes_v12_0_sw_init(void *handle)
        adev->mes.funcs = &mes_v12_0_funcs;
        adev->mes.kiq_hw_init = &mes_v12_0_kiq_hw_init;
        adev->mes.kiq_hw_fini = &mes_v12_0_kiq_hw_fini;
+       adev->mes.enable_legacy_queue_map = true;
 
        adev->mes.event_log_size = AMDGPU_MES_LOG_BUFFER_SIZE;
 
@@ -1456,9 +1457,11 @@ static int mes_v12_0_kiq_hw_init(struct amdgpu_device *adev)
                mes_v12_0_set_hw_resources_1(&adev->mes, AMDGPU_MES_KIQ_PIPE);
        }
 
-       r = mes_v12_0_hw_init(adev);
-       if (r)
-               goto failure;
+       if (adev->mes.enable_legacy_queue_map) {
+               r = mes_v12_0_hw_init(adev);
+               if (r)
+                       goto failure;
+       }
 
        return r;
 
--

2.41.0

#2 lore raw
In reply to Jack Xiao

I tested this patch

Quoted 4 lines · Jack Xiao

For mes11 old firmware has issue to map legacy queue, add a flag to switch mes to map legacy queue.

Quoted 8 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  1 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  | 49 +++++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  9 +++--
 4 files changed, 43 insertions(+), 20 deletions(-)

...
with the older firmware on the v6.11-rc4 kernel and it seems to work fine on my laptop:

% grep amdgpu dmesg-6.11.0-rc4-jack-amw+.txt

[    2.556631] [drm] amdgpu kernel modesetting enabled.
[    2.562758] amdgpu: Virtual CRAT table created for CPU
[    2.563277] amdgpu: Topology: Add CPU node
[    2.575279] amdgpu 0000:c1:00.0: amdgpu: Fetched VBIOS from VFCT
[    2.575756] amdgpu: ATOM BIOS: 113-PHXGENERIC-001
[    2.577651] amdgpu 0000:c1:00.0: Direct firmware load for
amdgpu/gc_11_0_1_mes_2.bin failed with error -2
[    2.578177] amdgpu 0000:c1:00.0: amdgpu: try to fall back to
gc_11_0_1_mes.bin
[    2.579118] amdgpu 0000:c1:00.0: vgaarb: deactivate vga console
[    2.579122] amdgpu 0000:c1:00.0: amdgpu: Trusted Memory Zone (TMZ)
feature enabled
[    2.579197] amdgpu 0000:c1:00.0: amdgpu: VRAM: 2048M
0x0000008000000000 - 0x000000807FFFFFFF (2048M used)
[    2.579202] amdgpu 0000:c1:00.0: amdgpu: GART: 512M
0x00007FFF00000000 - 0x00007FFF1FFFFFFF
[    2.579384] [drm] amdgpu: 2048M of VRAM memory ready
[    2.579389] [drm] amdgpu: 31048M of GTT memory ready.
[    2.605229] amdgpu 0000:c1:00.0: amdgpu: reserve 0x4000000 from
0x8078000000 for PSP TMR
[    3.128536] amdgpu 0000:c1:00.0: amdgpu: RAS: optional ras ta ucode
is not available
[    3.136355] amdgpu 0000:c1:00.0: amdgpu: RAP: optional rap ta ucode
is not available
[    3.136365] amdgpu 0000:c1:00.0: amdgpu: SECUREDISPLAY:
securedisplay ta ucode is not available
[    3.146193] amdgpu 0000:c1:00.0: amdgpu: SMU is initialized successfully!
[    3.258706] kfd kfd: amdgpu: Allocated 3969056 bytes on gart
[    3.258723] kfd kfd: amdgpu: Total number of KFD nodes to be created: 1
[    3.258838] amdgpu: Virtual CRAT table created for GPU
[    3.258978] amdgpu: Topology: Add dGPU node [0x15bf:0x1002]
[    3.258982] kfd kfd: amdgpu: added device 1002:15bf
[    3.258995] amdgpu 0000:c1:00.0: amdgpu: SE 1, SH per SE 2, CU per
SH 6, active_cu_number 12
[    3.259002] amdgpu 0000:c1:00.0: amdgpu: ring gfx_0.0.0 uses VM inv
eng 0 on hub 0
[    3.259006] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.0.0 uses VM
inv eng 1 on hub 0
[    3.259009] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.1.0 uses VM
inv eng 4 on hub 0
[    3.259013] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.2.0 uses VM
inv eng 6 on hub 0
[    3.259016] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.3.0 uses VM
inv eng 7 on hub 0
[    3.259019] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.0.1 uses VM
inv eng 8 on hub 0
[    3.259022] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.1.1 uses VM
inv eng 9 on hub 0
[    3.259026] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.2.1 uses VM
inv eng 10 on hub 0
[    3.259029] amdgpu 0000:c1:00.0: amdgpu: ring comp_1.3.1 uses VM
inv eng 11 on hub 0
[    3.259032] amdgpu 0000:c1:00.0: amdgpu: ring sdma0 uses VM inv eng
12 on hub 0
[    3.259035] amdgpu 0000:c1:00.0: amdgpu: ring vcn_unified_0 uses VM
inv eng 0 on hub 8
[    3.259038] amdgpu 0000:c1:00.0: amdgpu: ring jpeg_dec uses VM inv
eng 1 on hub 8
[    3.259041] amdgpu 0000:c1:00.0: amdgpu: ring mes_kiq_3.1.0 uses VM
inv eng 13 on hub 0
[    3.267498] amdgpu 0000:c1:00.0: amdgpu: Runtime PM not available
[    3.268055] [drm] Initialized amdgpu 3.58.0 for 0000:c1:00.0 on minor 0
[    3.280095] fbcon: amdgpudrmfb (fb0) is primary device
[    4.194462] amdgpu 0000:c1:00.0: [drm] fb0: amdgpudrmfb frame buffer device
[   22.685627] snd_hda_intel 0000:c1:00.1: bound 0000:c1:00.0 (ops

amdgpu_dm_audio_component_bind_ops [amdgpu])

Thanks Jack

Andrew