Skip to contentSkip to conversation

drm/amdgpu: Skip specific mmhub and sdma registers accessing under sriov

PATCH In review Yifan Zha 2 participants 2 messages Jan 11, 2023 – Jan 12, 2023

Subsystems (2)
lore
Share & tools
lore

Yifan Zha

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Skip specific mmhub and sdma registers accessing under sriov

[Why]
SDMA0_CNTL and MMHUB system aperture related registers are blocked by L1 Policy. Therefore, they cannot be accessed by VF and loged in violation.

[How]
For MMHUB registers, they will be programmed by PF. So VF will skip to program them in mmhubv3_0. For SDMA0_CNTL which is a PF_only register, VF don't need to program it in sdma_v6_0.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_0.c | 34 ++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c  | 10 +++++---
 2 files changed, 23 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_0.c +17 -17
index e9dcd6fcde7f..ae9cd1a4cfee 100644
@@ -169,23 +169,23 @@ static void mmhub_v3_0_init_system_aperture_regs(struct amdgpu_device *adev)
 	uint64_t value;
 	uint32_t tmp;
 
-	if (!amdgpu_sriov_vf(adev)) {
-		/*
-		 * the new L1 policy will block SRIOV guest from writing
-		 * these regs, and they will be programed at host.
-		 * so skip programing these regs.
-		 */
-		/* Disable AGP. */
-		WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BASE, 0);
-		WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_TOP, 0);
-		WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BOT, 0x00FFFFFF);
-
-		/* Program the system aperture low logical page number. */
-		WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_LOW_ADDR,
-			     adev->gmc.vram_start >> 18);
-		WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
-			     adev->gmc.vram_end >> 18);
-	}
+	if (amdgpu_sriov_vf(adev))
+		return;
+
+	/*
+	 * the new L1 policy will block SRIOV guest from writing
+	 * these regs, and they will be programed at host.
+	 * so skip programing these regs.
+	 */
+	/* Disable AGP. */
+	WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BASE, 0);
+	WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_TOP, 0);
+	WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BOT, 0x00FFFFFF);
+	/* Program the system aperture low logical page number. */
+	WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_LOW_ADDR,
+		     adev->gmc.vram_start >> 18);
+	WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
+		     adev->gmc.vram_end >> 18);
 
 	/* Set default page address. */
 	value = adev->mem_scratch.gpu_addr - adev->gmc.vram_start +
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +6 -4
index bf1fa5e8d2f9..6fe292a2486b 100644
@@ -1403,10 +1403,12 @@ static int sdma_v6_0_set_trap_irq_state(struct amdgpu_device *adev,
 
 	u32 reg_offset = sdma_v6_0_get_reg_offset(adev, type, regSDMA0_CNTL);
 
-	sdma_cntl = RREG32(reg_offset);
-	sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE,
-		       state == AMDGPU_IRQ_STATE_ENABLE ? 1 : 0);
-	WREG32(reg_offset, sdma_cntl);
+	if (!amdgpu_sriov_vf(adev)) {
+		sdma_cntl = RREG32(reg_offset);
+		sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE,
+				state == AMDGPU_IRQ_STATE_ENABLE ? 1 : 0);
+		WREG32(reg_offset, sdma_cntl);
+	}
 
 	return 0;
 }
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Yifan Zha

[Why]
SDMA0_CNTL and MMHUB system aperture related registers are blocked by L1 Policy. Therefore, they cannot be accessed by VF and loged in violation.

[How]
For MMHUB registers, they will be programmed by PF. So VF will skip to program them in mmhubv3_0. For SDMA0_CNTL which is a PF_only register, VF don't need to program it in sdma_v6_0.

Quoted 74 lines
---
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_0.c | 34 ++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c  | 10 +++++---
 2 files changed, 23 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_0.c +17 -17
index e9dcd6fcde7f..ae9cd1a4cfee 100644
@@ -169,23 +169,23 @@ static void mmhub_v3_0_init_system_aperture_regs(struct amdgpu_device *adev)
        uint64_t value;
        uint32_t tmp;
 
-       if (!amdgpu_sriov_vf(adev)) {
-               /*
-                * the new L1 policy will block SRIOV guest from writing
-                * these regs, and they will be programed at host.
-                * so skip programing these regs.
-                */
-               /* Disable AGP. */
-               WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BASE, 0);
-               WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_TOP, 0);
-               WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BOT, 0x00FFFFFF);
-
-               /* Program the system aperture low logical page number. */
-               WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_LOW_ADDR,
-                            adev->gmc.vram_start >> 18);
-               WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
-                            adev->gmc.vram_end >> 18);
-       }
+       if (amdgpu_sriov_vf(adev))
+               return;
+
+       /*
+        * the new L1 policy will block SRIOV guest from writing
+        * these regs, and they will be programed at host.
+        * so skip programing these regs.
+        */
+       /* Disable AGP. */
+       WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BASE, 0);
+       WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_TOP, 0);
+       WREG32_SOC15(MMHUB, 0, regMMMC_VM_AGP_BOT, 0x00FFFFFF);
+       /* Program the system aperture low logical page number. */
+       WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_LOW_ADDR,
+                    adev->gmc.vram_start >> 18);
+       WREG32_SOC15(MMHUB, 0, regMMMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
+                    adev->gmc.vram_end >> 18);
 
        /* Set default page address. */
        value = adev->mem_scratch.gpu_addr - adev->gmc.vram_start +
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +6 -5
index bf1fa5e8d2f9..6fe292a2486b 100644
@@ -1403,10 +1403,12 @@ static int sdma_v6_0_set_trap_irq_state(struct amdgpu_device *adev,
 
        u32 reg_offset = sdma_v6_0_get_reg_offset(adev, type, regSDMA0_CNTL);
 
-       sdma_cntl = RREG32(reg_offset);
-       sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE,
-                      state == AMDGPU_IRQ_STATE_ENABLE ? 1 : 0);
-       WREG32(reg_offset, sdma_cntl);
+       if (!amdgpu_sriov_vf(adev)) {
+               sdma_cntl = RREG32(reg_offset);
+               sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE,
+                               state == AMDGPU_IRQ_STATE_ENABLE ? 1 : 0);
+               WREG32(reg_offset, sdma_cntl);
+       }
 
        return 0;
 }
--

2.25.1