Skip to content

Commit 59070fd

Browse files
Asad Kamalalexdeucher
authored andcommitted
drm/amdgpu: Add pci usage to nbio v7.9
Add implementation to get pcie usage for nbio v7.9. Signed-off-by: Asad Kamal <[email protected]> Reviewed-by: Lijo Lazar <[email protected]> Reviewed-by: Shiwu Zhang <[email protected]> Reviewed-by: Hawking Zhang <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 8d759dc commit 59070fd

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
/* Core 0 Port 0 counter */
3636
#define smnPCIEP_NAK_COUNTER 0x1A340218
3737

38+
#define smnPCIE_PERF_CNTL_TXCLK3 0x1A38021c
39+
#define smnPCIE_PERF_CNTL_TXCLK7 0x1A380888
40+
#define smnPCIE_PERF_COUNT_CNTL 0x1A380200
41+
#define smnPCIE_PERF_COUNT0_TXCLK3 0x1A380220
42+
#define smnPCIE_PERF_COUNT0_TXCLK7 0x1A38088C
43+
#define smnPCIE_PERF_COUNT0_UPVAL_TXCLK3 0x1A3808F8
44+
#define smnPCIE_PERF_COUNT0_UPVAL_TXCLK7 0x1A380918
45+
46+
3847
static void nbio_v7_9_remap_hdp_registers(struct amdgpu_device *adev)
3948
{
4049
WREG32_SOC15(NBIO, 0, regBIF_BX0_REMAP_HDP_MEM_FLUSH_CNTL,
@@ -446,6 +455,59 @@ static u64 nbio_v7_9_get_pcie_replay_count(struct amdgpu_device *adev)
446455
return (nak_r + nak_g);
447456
}
448457

458+
static void nbio_v7_9_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
459+
uint64_t *count1)
460+
{
461+
uint32_t perfctrrx = 0;
462+
uint32_t perfctrtx = 0;
463+
464+
/* This reports 0 on APUs, so return to avoid writing/reading registers
465+
* that may or may not be different from their GPU counterparts
466+
*/
467+
if (adev->flags & AMD_IS_APU)
468+
return;
469+
470+
/* Use TXCLK3 counter group for rx event */
471+
/* Use TXCLK7 counter group for tx event */
472+
/* Set the 2 events that we wish to watch, defined above */
473+
/* 40 is event# for received msgs */
474+
/* 2 is event# of posted requests sent */
475+
perfctrrx = REG_SET_FIELD(perfctrrx, PCIE_PERF_CNTL_TXCLK3, EVENT0_SEL, 40);
476+
perfctrtx = REG_SET_FIELD(perfctrtx, PCIE_PERF_CNTL_TXCLK7, EVENT0_SEL, 2);
477+
478+
/* Write to enable desired perf counters */
479+
WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3, perfctrrx);
480+
WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK7, perfctrtx);
481+
482+
/* Zero out and enable SHADOW_WR
483+
* Write 0x6:
484+
* Bit 1 = Global Shadow wr(1)
485+
* Bit 2 = Global counter reset enable(1)
486+
*/
487+
WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000006);
488+
489+
/* Enable Gloabl Counter
490+
* Write 0x1:
491+
* Bit 0 = Global Counter Enable(1)
492+
*/
493+
WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000001);
494+
495+
msleep(1000);
496+
497+
/* Disable Global Counter, Reset and enable SHADOW_WR
498+
* Write 0x6:
499+
* Bit 1 = Global Shadow wr(1)
500+
* Bit 2 = Global counter reset enable(1)
501+
*/
502+
WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000006);
503+
504+
/* Get the upper and lower count */
505+
*count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK3) |
506+
((uint64_t)RREG32_PCIE(smnPCIE_PERF_COUNT0_UPVAL_TXCLK3) << 32);
507+
*count1 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK7) |
508+
((uint64_t)RREG32_PCIE(smnPCIE_PERF_COUNT0_UPVAL_TXCLK7) << 32);
509+
}
510+
449511
const struct amdgpu_nbio_funcs nbio_v7_9_funcs = {
450512
.get_hdp_flush_req_offset = nbio_v7_9_get_hdp_flush_req_offset,
451513
.get_hdp_flush_done_offset = nbio_v7_9_get_hdp_flush_done_offset,
@@ -470,6 +532,7 @@ const struct amdgpu_nbio_funcs nbio_v7_9_funcs = {
470532
.get_memory_partition_mode = nbio_v7_9_get_memory_partition_mode,
471533
.init_registers = nbio_v7_9_init_registers,
472534
.get_pcie_replay_count = nbio_v7_9_get_pcie_replay_count,
535+
.get_pcie_usage = nbio_v7_9_get_pcie_usage,
473536
};
474537

475538
static void nbio_v7_9_query_ras_error_count(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/soc15.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ static const struct amdgpu_asic_funcs aqua_vanjaram_asic_funcs =
893893
.get_config_memsize = &soc15_get_config_memsize,
894894
.need_full_reset = &soc15_need_full_reset,
895895
.init_doorbell_index = &aqua_vanjaram_doorbell_index_init,
896-
.get_pcie_usage = &vega20_get_pcie_usage,
896+
.get_pcie_usage = &amdgpu_nbio_get_pcie_usage,
897897
.need_reset_on_init = &soc15_need_reset_on_init,
898898
.get_pcie_replay_count = &amdgpu_nbio_get_pcie_replay_count,
899899
.supports_baco = &soc15_supports_baco,

drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_9_0_sh_mask.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38896,5 +38896,13 @@
3889638896
#define RCC_DEV0_EPF0_VF7_GFXMSIX_PBA__MSIX_PENDING_BITS_0_MASK 0x00000001L
3889738897
#define RCC_DEV0_EPF0_VF7_GFXMSIX_PBA__MSIX_PENDING_BITS_1_MASK 0x00000002L
3889838898

38899+
//PCIE_PERF_CNTL_TXCLK3
38900+
#define PCIE_PERF_CNTL_TXCLK3__EVENT0_SEL__SHIFT 0x0
38901+
#define PCIE_PERF_CNTL_TXCLK3__EVENT0_SEL_MASK 0x000000FFL
38902+
38903+
//PCIE_PERF_CNTL_TXCLK7
38904+
#define PCIE_PERF_CNTL_TXCLK7__EVENT0_SEL__SHIFT 0x0
38905+
#define PCIE_PERF_CNTL_TXCLK7__EVENT0_SEL_MASK 0x000000FFL
38906+
3889938907

3890038908
#endif

0 commit comments

Comments
 (0)