Skip to content

Commit 1583971

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/uncore: Factor out snr_uncore_mmio_map()
The IMC free-running counters on Sapphire Rapids server are also accessed by MMIO, which is similar to the previous platforms, SNR and ICX. The only difference is the device ID of the device which contains BAR address. Factor out snr_uncore_mmio_map() which ioremap the MMIO space. It can be reused in the following patch for SPR. Use the snr_uncore_mmio_map() in the icx_uncore_imc_freerunning_init_box(). There is no box_ctl for the free-running counters. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8053f2d commit 1583971

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

arch/x86/events/intel/uncore_snbep.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,13 +4792,15 @@ int snr_uncore_pci_init(void)
47924792
return 0;
47934793
}
47944794

4795-
static struct pci_dev *snr_uncore_get_mc_dev(int id)
4795+
#define SNR_MC_DEVICE_ID 0x3451
4796+
4797+
static struct pci_dev *snr_uncore_get_mc_dev(unsigned int device, int id)
47964798
{
47974799
struct pci_dev *mc_dev = NULL;
47984800
int pkg;
47994801

48004802
while (1) {
4801-
mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x3451, mc_dev);
4803+
mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, device, mc_dev);
48024804
if (!mc_dev)
48034805
break;
48044806
pkg = uncore_pcibus_to_dieid(mc_dev->bus);
@@ -4808,16 +4810,17 @@ static struct pci_dev *snr_uncore_get_mc_dev(int id)
48084810
return mc_dev;
48094811
}
48104812

4811-
static void __snr_uncore_mmio_init_box(struct intel_uncore_box *box,
4812-
unsigned int box_ctl, int mem_offset)
4813+
static int snr_uncore_mmio_map(struct intel_uncore_box *box,
4814+
unsigned int box_ctl, int mem_offset,
4815+
unsigned int device)
48134816
{
4814-
struct pci_dev *pdev = snr_uncore_get_mc_dev(box->dieid);
4817+
struct pci_dev *pdev = snr_uncore_get_mc_dev(device, box->dieid);
48154818
struct intel_uncore_type *type = box->pmu->type;
48164819
resource_size_t addr;
48174820
u32 pci_dword;
48184821

48194822
if (!pdev)
4820-
return;
4823+
return -ENODEV;
48214824

48224825
pci_read_config_dword(pdev, SNR_IMC_MMIO_BASE_OFFSET, &pci_dword);
48234826
addr = (pci_dword & SNR_IMC_MMIO_BASE_MASK) << 23;
@@ -4830,16 +4833,25 @@ static void __snr_uncore_mmio_init_box(struct intel_uncore_box *box,
48304833
box->io_addr = ioremap(addr, type->mmio_map_size);
48314834
if (!box->io_addr) {
48324835
pr_warn("perf uncore: Failed to ioremap for %s.\n", type->name);
4833-
return;
4836+
return -EINVAL;
48344837
}
48354838

4836-
writel(IVBEP_PMON_BOX_CTL_INT, box->io_addr);
4839+
return 0;
4840+
}
4841+
4842+
static void __snr_uncore_mmio_init_box(struct intel_uncore_box *box,
4843+
unsigned int box_ctl, int mem_offset,
4844+
unsigned int device)
4845+
{
4846+
if (!snr_uncore_mmio_map(box, box_ctl, mem_offset, device))
4847+
writel(IVBEP_PMON_BOX_CTL_INT, box->io_addr);
48374848
}
48384849

48394850
static void snr_uncore_mmio_init_box(struct intel_uncore_box *box)
48404851
{
48414852
__snr_uncore_mmio_init_box(box, uncore_mmio_box_ctl(box),
4842-
SNR_IMC_MMIO_MEM0_OFFSET);
4853+
SNR_IMC_MMIO_MEM0_OFFSET,
4854+
SNR_MC_DEVICE_ID);
48434855
}
48444856

48454857
static void snr_uncore_mmio_disable_box(struct intel_uncore_box *box)
@@ -5413,7 +5425,8 @@ static void icx_uncore_imc_init_box(struct intel_uncore_box *box)
54135425
int mem_offset = (box->pmu->pmu_idx / ICX_NUMBER_IMC_CHN) * ICX_IMC_MEM_STRIDE +
54145426
SNR_IMC_MMIO_MEM0_OFFSET;
54155427

5416-
__snr_uncore_mmio_init_box(box, box_ctl, mem_offset);
5428+
__snr_uncore_mmio_init_box(box, box_ctl, mem_offset,
5429+
SNR_MC_DEVICE_ID);
54175430
}
54185431

54195432
static struct intel_uncore_ops icx_uncore_mmio_ops = {
@@ -5483,7 +5496,8 @@ static void icx_uncore_imc_freerunning_init_box(struct intel_uncore_box *box)
54835496
int mem_offset = box->pmu->pmu_idx * ICX_IMC_MEM_STRIDE +
54845497
SNR_IMC_MMIO_MEM0_OFFSET;
54855498

5486-
__snr_uncore_mmio_init_box(box, uncore_mmio_box_ctl(box), mem_offset);
5499+
snr_uncore_mmio_map(box, uncore_mmio_box_ctl(box),
5500+
mem_offset, SNR_MC_DEVICE_ID);
54875501
}
54885502

54895503
static struct intel_uncore_ops icx_uncore_imc_freerunning_ops = {

0 commit comments

Comments
 (0)