Skip to content

Commit efb0c9c

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/uncore: Factor out common MMIO init and ops functions
Some uncore PMON registers are located in the MMIO space. For the client machine, the MMIO space is usually located at D0:F0 but in a different BAR. For example, some uncore PMON registers are located in the SAF BAR, not the MCHBAR in the Lunar Lake. The current __uncore_imc_init_box() hard code the BAR information. Factor out the uncore_get_box_mmio_addr() which uses the BAR information as a parameter. The only change is the error output message. The hardcode name 'MCHBAR' is replaced by the offset of a BAR. Add a new macro, MMIO_UNCORE_COMMON_OPS(), since the MMIO ops functions are usually the same among different generations. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20240731141353.759643-2-kan.liang@linux.intel.com
1 parent e0f49f1 commit efb0c9c

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

arch/x86/events/intel/uncore_snb.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,33 +1481,35 @@ static struct pci_dev *tgl_uncore_get_mc_dev(void)
14811481
#define TGL_UNCORE_MMIO_IMC_MEM_OFFSET 0x10000
14821482
#define TGL_UNCORE_PCI_IMC_MAP_SIZE 0xe000
14831483

1484-
static void __uncore_imc_init_box(struct intel_uncore_box *box,
1485-
unsigned int base_offset)
1484+
static void
1485+
uncore_get_box_mmio_addr(struct intel_uncore_box *box,
1486+
unsigned int base_offset,
1487+
int bar_offset, int step)
14861488
{
14871489
struct pci_dev *pdev = tgl_uncore_get_mc_dev();
14881490
struct intel_uncore_pmu *pmu = box->pmu;
14891491
struct intel_uncore_type *type = pmu->type;
14901492
resource_size_t addr;
1491-
u32 mch_bar;
1493+
u32 bar;
14921494

14931495
if (!pdev) {
14941496
pr_warn("perf uncore: Cannot find matched IMC device.\n");
14951497
return;
14961498
}
14971499

1498-
pci_read_config_dword(pdev, SNB_UNCORE_PCI_IMC_BAR_OFFSET, &mch_bar);
1499-
/* MCHBAR is disabled */
1500-
if (!(mch_bar & BIT(0))) {
1501-
pr_warn("perf uncore: MCHBAR is disabled. Failed to map IMC free-running counters.\n");
1500+
pci_read_config_dword(pdev, bar_offset, &bar);
1501+
if (!(bar & BIT(0))) {
1502+
pr_warn("perf uncore: BAR 0x%x is disabled. Failed to map %s counters.\n",
1503+
bar_offset, type->name);
15021504
pci_dev_put(pdev);
15031505
return;
15041506
}
1505-
mch_bar &= ~BIT(0);
1506-
addr = (resource_size_t)(mch_bar + TGL_UNCORE_MMIO_IMC_MEM_OFFSET * pmu->pmu_idx);
1507+
bar &= ~BIT(0);
1508+
addr = (resource_size_t)(bar + step * pmu->pmu_idx);
15071509

15081510
#ifdef CONFIG_PHYS_ADDR_T_64BIT
1509-
pci_read_config_dword(pdev, SNB_UNCORE_PCI_IMC_BAR_OFFSET + 4, &mch_bar);
1510-
addr |= ((resource_size_t)mch_bar << 32);
1511+
pci_read_config_dword(pdev, bar_offset + 4, &bar);
1512+
addr |= ((resource_size_t)bar << 32);
15111513
#endif
15121514

15131515
addr += base_offset;
@@ -1518,6 +1520,14 @@ static void __uncore_imc_init_box(struct intel_uncore_box *box,
15181520
pci_dev_put(pdev);
15191521
}
15201522

1523+
static void __uncore_imc_init_box(struct intel_uncore_box *box,
1524+
unsigned int base_offset)
1525+
{
1526+
uncore_get_box_mmio_addr(box, base_offset,
1527+
SNB_UNCORE_PCI_IMC_BAR_OFFSET,
1528+
TGL_UNCORE_MMIO_IMC_MEM_OFFSET);
1529+
}
1530+
15211531
static void tgl_uncore_imc_freerunning_init_box(struct intel_uncore_box *box)
15221532
{
15231533
__uncore_imc_init_box(box, 0);
@@ -1612,14 +1622,17 @@ static void adl_uncore_mmio_enable_box(struct intel_uncore_box *box)
16121622
writel(0, box->io_addr + uncore_mmio_box_ctl(box));
16131623
}
16141624

1625+
#define MMIO_UNCORE_COMMON_OPS() \
1626+
.exit_box = uncore_mmio_exit_box, \
1627+
.disable_box = adl_uncore_mmio_disable_box, \
1628+
.enable_box = adl_uncore_mmio_enable_box, \
1629+
.disable_event = intel_generic_uncore_mmio_disable_event, \
1630+
.enable_event = intel_generic_uncore_mmio_enable_event, \
1631+
.read_counter = uncore_mmio_read_counter,
1632+
16151633
static struct intel_uncore_ops adl_uncore_mmio_ops = {
16161634
.init_box = adl_uncore_imc_init_box,
1617-
.exit_box = uncore_mmio_exit_box,
1618-
.disable_box = adl_uncore_mmio_disable_box,
1619-
.enable_box = adl_uncore_mmio_enable_box,
1620-
.disable_event = intel_generic_uncore_mmio_disable_event,
1621-
.enable_event = intel_generic_uncore_mmio_enable_event,
1622-
.read_counter = uncore_mmio_read_counter,
1635+
MMIO_UNCORE_COMMON_OPS()
16231636
};
16241637

16251638
#define ADL_UNC_CTL_CHMASK_MASK 0x00000f00

0 commit comments

Comments
 (0)