drm: replace magic numbers
Subsystems (3)
v2 cover drm: replace magic numbers
From: Bjorn Helgaas <[email protected]>
amdgpu and radeon do a bit of mucking with the PCIe Link Control 2 register, some of it using hard-coded magic numbers. The idea here is to replace those with #defines.
I don't intend the Target Link Speed patch to change anything, so it should be straightforward to review.
Since v1:
- Add my signed-off-by and Alex's reviewed-by.
Bjorn Helgaas (2):
drm: replace incorrect Compliance/Margin magic numbers with
PCI_EXP_LNKCTL2 definitions
drm: replace Target Link Speed magic numbers with PCI_EXP_LNKCTL2
definitions
drivers/gpu/drm/amd/amdgpu/cik.c | 22 ++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/si.c | 18 +++++++++++------- drivers/gpu/drm/radeon/cik.c | 22 ++++++++++++++-------- drivers/gpu/drm/radeon/si.c | 22 ++++++++++++++-------- include/uapi/linux/pci_regs.h | 2 ++ 5 files changed, 55 insertions(+), 31 deletions(-)
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
PATCH v2 1/2 drm: replace incorrect Compliance/Margin magic numbers with PCI_EXP_LNKCTL2 definitions
From: Bjorn Helgaas <[email protected]>
Add definitions for these PCIe Link Control 2 register fields:
Enter Compliance
Transmit Margin
and use them in amdgpu and radeon.
NOTE: This is a functional change because "7 << 9" was apparently a typo. That mask included the high order bit of Transmit Margin, the Enter Modified Compliance bit, and the Compliance SOS bit, but I think what was intended was the 3-bit Transmit Margin field at bits 9:7.
--- drivers/gpu/drm/amd/amdgpu/cik.c | 14 ++++++++++---- drivers/gpu/drm/amd/amdgpu/si.c | 10 +++++++--- drivers/gpu/drm/radeon/cik.c | 14 ++++++++++---- drivers/gpu/drm/radeon/si.c | 14 ++++++++++---- include/uapi/linux/pci_regs.h | 2 ++ 5 files changed, 39 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik.c +10 -4
@@ -1498,13 +1498,19 @@ static void cik_pcie_gen3_enable(struct amdgpu_device *adev)/* linkctl2 */ pci_read_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); - tmp16 |= (bridge_cfg2 & ((1 <<4 ) | (7 <<9 ))); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); + tmp16 |= (bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ));pci_write_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , tmp16);pci_read_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); - tmp16 |= (gpu_cfg2 & ((1 <<4 ) | (7 <<9 ))); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); + tmp16 |= (gpu_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ));pci_write_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16); tmp =RREG32_PCIE (ixPCIE_LC_CNTL4);
drivers/gpu/drm/amd/amdgpu/si.c +7 -3
@@ -1737,12 +1737,16 @@ static void si_pcie_gen3_enable(struct amdgpu_device *adev)pci_write_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL , tmp16);pci_read_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); - tmp16 |= (bridge_cfg2 & ((1 <<4 ) | (7 <<9 ))); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); + tmp16 |= (bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ));pci_write_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , tmp16);pci_read_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); tmp16 |= (gpu_cfg2 & ((1 <<4 ) | (7 <<9 )));pci_write_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16);
drivers/gpu/drm/radeon/cik.c +10 -4
@@ -9619,13 +9619,19 @@ static void cik_pcie_gen3_enable(struct radeon_device *rdev)/* linkctl2 */ pci_read_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); - tmp16 |= (bridge_cfg2 & ((1 <<4 ) | (7 <<9 ))); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); + tmp16 |= (bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ));pci_write_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , tmp16);pci_read_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); - tmp16 |= (gpu_cfg2 & ((1 <<4 ) | (7 <<9 ))); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); + tmp16 |= (gpu_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ));pci_write_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16); tmp =RREG32_PCIE_PORT (PCIE_LC_CNTL4 );
drivers/gpu/drm/radeon/si.c +10 -4
@@ -7202,13 +7202,19 @@ static void si_pcie_gen3_enable(struct radeon_device *rdev)/* linkctl2 */ pci_read_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); - tmp16 |= (bridge_cfg2 & ((1 <<4 ) | (7 <<9 ))); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); + tmp16 |= (bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ));pci_write_config_word (root, bridge_pos +PCI_EXP_LNKCTL2 , tmp16);pci_read_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~((1 <<4 ) | (7 <<9 )); - tmp16 |= (gpu_cfg2 & ((1 <<4 ) | (7 <<9 ))); + tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ); + tmp16 |= (gpu_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN ));pci_write_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16); tmp =RREG32_PCIE_PORT (PCIE_LC_CNTL4 );
include/uapi/linux/pci_regs.h +2 -0
@@ -673,6 +673,8 @@#define PCI_EXP_LNKCTL2_TLS_8_0GT 0x0003/* Supported Speed 8GT/s */ #define PCI_EXP_LNKCTL2_TLS_16_0GT 0x0004/* Supported Speed 16GT/s */ #define PCI_EXP_LNKCTL2_TLS_32_0GT 0x0005/* Supported Speed 32GT/s */ +#define PCI_EXP_LNKCTL2_ENTER_COMP 0x0010/* Enter Compliance */ +#define PCI_EXP_LNKCTL2_TX_MARGIN 0x0380/* Transmit Margin */ #define PCI_EXP_LNKSTA2 50/* Link Status 2 */ #define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2 52/* v2 endpoints with link end here */ #define PCI_EXP_SLTCAP2 52/* Slot Capabilities 2 */
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Re: [PATCH 1/2] drm: replace incorrect Compliance/Margin magic numbers with PCI_EXP_LNKCTL2 definitions
Quoted 7 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Add definitions for these PCIe Link Control 2 register fields:
Enter Compliance
Transmit Margin
Quoted 6 lines
and use them in amdgpu and radeon.
NOTE: This is a functional change because "7 << 9" was apparently a typo. That mask included the high order bit of Transmit Margin, the Enter Modified Compliance bit, and the Compliance SOS bit, but I think what was intended was the 3-bit Transmit Margin field at bits 9:7.
Can you split out the functional change into a separate patch 1? That could make things easier for anyone who bisects the functional change for whatever reason.
Signature · 2 lines
Earthling Michel Dänzer | https://redhat.com Libre software enthusiast | Mesa and X developer
Re: [PATCH 1/2] drm: replace incorrect Compliance/Margin magic numbers with PCI_EXP_LNKCTL2 definitions
Quoted 10 lines · Michel Dänzer
Quoted 9 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Add definitions for these PCIe Link Control 2 register fields:
Enter Compliance
Transmit Marginand use them in amdgpu and radeon.
Quoted 8 lines
Quoted 4 lines
NOTE: This is a functional change because "7 << 9" was apparently a typo. That mask included the high order bit of Transmit Margin, the Enter Modified Compliance bit, and the Compliance SOS bit, but I think what was intended was the 3-bit Transmit Margin field at bits 9:7.
Can you split out the functional change into a separate patch 1? That could make things easier for anyone who bisects the functional change for whatever reason.
Great idea, thanks! Wish I'd thought of that.
While fixing that, I also noticed I missed one case in amdgpu/si.c. I'll post a v3.
PATCH v2 2/2 drm: replace Target Link Speed magic numbers with PCI_EXP_LNKCTL2 definitions
In reply to Bjorn HelgaasFrom: Bjorn Helgaas <[email protected]>
Replace hard-coded magic numbers with the descript PCI_EXP_LNKCTL2 definitions. No functional change intended.
--- drivers/gpu/drm/amd/amdgpu/cik.c | 8 ++++---- drivers/gpu/drm/amd/amdgpu/si.c | 8 ++++---- drivers/gpu/drm/radeon/cik.c | 8 ++++---- drivers/gpu/drm/radeon/si.c | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik.c +4 -4
@@ -1527,13 +1527,13 @@ static void cik_pcie_gen3_enable(struct amdgpu_device *adev)WREG32_PCIE (ixPCIE_LC_SPEED_CNTL, speed_cntl);pci_read_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~0xf ; + tmp16 &= ~PCI_EXP_LNKCTL2_TLS ;if (adev->pm.pcie_gen_mask &CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 ) - tmp16 |=3 ;/* gen3 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_8_0GT ;/* gen3 */ else if (adev->pm.pcie_gen_mask &CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 ) - tmp16 |=2 ;/* gen2 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_5_0GT ;/* gen2 */ else - tmp16 |=1 ;/* gen1 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_2_5GT ;/* gen1 */ pci_write_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16); speed_cntl =RREG32_PCIE (ixPCIE_LC_SPEED_CNTL);
drivers/gpu/drm/amd/amdgpu/si.c +4 -4
@@ -1762,13 +1762,13 @@ static void si_pcie_gen3_enable(struct amdgpu_device *adev)WREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL , speed_cntl);pci_read_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~0xf ; + tmp16 &= ~PCI_EXP_LNKCTL2_TLS ;if (adev->pm.pcie_gen_mask &CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 ) - tmp16 |=3 ; + tmp16 |=PCI_EXP_LNKCTL2_TLS_8_0GT ;/* gen3 */ else if (adev->pm.pcie_gen_mask &CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 ) - tmp16 |=2 ; + tmp16 |=PCI_EXP_LNKCTL2_TLS_5_0GT ;/* gen2 */ else - tmp16 |=1 ; + tmp16 |=PCI_EXP_LNKCTL2_TLS_2_5GT ;/* gen1 */ pci_write_config_word (adev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16); speed_cntl =RREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL );
drivers/gpu/drm/radeon/cik.c +4 -4
@@ -9647,13 +9647,13 @@ static void cik_pcie_gen3_enable(struct radeon_device *rdev)WREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL , speed_cntl);pci_read_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~0xf ; + tmp16 &= ~PCI_EXP_LNKCTL2_TLS ;if (speed_cap ==PCIE_SPEED_8_0GT ) - tmp16 |=3 ;/* gen3 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_8_0GT ;/* gen3 */ else if (speed_cap ==PCIE_SPEED_5_0GT ) - tmp16 |=2 ;/* gen2 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_5_0GT ;/* gen2 */ else - tmp16 |=1 ;/* gen1 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_2_5GT ;/* gen1 */ pci_write_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16); speed_cntl =RREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL );
drivers/gpu/drm/radeon/si.c +4 -4
@@ -7230,13 +7230,13 @@ static void si_pcie_gen3_enable(struct radeon_device *rdev)WREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL , speed_cntl);pci_read_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~0xf ; + tmp16 &= ~PCI_EXP_LNKCTL2_TLS ;if (speed_cap ==PCIE_SPEED_8_0GT ) - tmp16 |=3 ;/* gen3 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_8_0GT ;/* gen3 */ else if (speed_cap ==PCIE_SPEED_5_0GT ) - tmp16 |=2 ;/* gen2 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_5_0GT ;/* gen2 */ else - tmp16 |=1 ;/* gen1 */ + tmp16 |=PCI_EXP_LNKCTL2_TLS_2_5GT ;/* gen1 */ pci_write_config_word (rdev->pdev, gpu_pos +PCI_EXP_LNKCTL2 , tmp16); speed_cntl =RREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL );
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog